deprecatedlib NOBUG fix typo.
[moodle.git] / lib / deprecatedlib.php
CommitLineData
c861fe2f 1<?php
2
a5cb8d69 3// This file is part of Moodle - http://moodle.org/
4//
c861fe2f 5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
a5cb8d69 14//
c861fe2f 15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
c4d0753b 17
18/**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
20 *
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
23 *
78bfb562 24 * @package core
c861fe2f 25 * @subpackage deprecated
78bfb562
PS
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
c861fe2f 28 * @deprecated
c4d0753b 29 */
30
78bfb562
PS
31defined('MOODLE_INTERNAL') || die();
32
35716b86 33
c6d75bff
PS
34/**
35 * Insert or update log display entry. Entry may already exist.
36 * $module, $action must be unique
37 * @deprecated
38 *
39 * @param string $module
40 * @param string $action
41 * @param string $mtable
42 * @param string $field
43 * @return void
44 *
45 */
46function update_log_display_entry($module, $action, $mtable, $field) {
47 global $DB;
48
49 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
50}
51
35716b86
PS
52/**
53 * Given some text in HTML format, this function will pass it
54 * through any filters that have been configured for this context.
55 *
56 * @deprecated use the text formatting in a standard way instead,
57 * this was abused mostly for embedding of attachments
58 *
59 * @param string $text The text to be passed through format filters
60 * @param int $courseid The current course.
61 * @return string the filtered string.
62 */
63function filter_text($text, $courseid = NULL) {
64 global $CFG, $COURSE;
65
66 if (!$courseid) {
67 $courseid = $COURSE->id;
68 }
69
70 if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
71 return $text;
72 }
73
74 return filter_manager::instance()->filter_text($text, $context);
75}
76
17c70aa0
PS
77/**
78 * This function indicates that current page requires the https
79 * when $CFG->loginhttps enabled.
80 *
81 * By using this function properly, we can ensure 100% https-ized pages
82 * at our entire discretion (login, forgot_password, change_password)
83 * @deprecated use $PAGE->https_required() instead
84 */
85function httpsrequired() {
86 global $PAGE;
87 $PAGE->https_required();
88}
89
50a8bd6c
PS
90/**
91 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
92 *
93 * @deprecated use moodle_url factory methods instead
94 *
95 * @param string $path Physical path to a file
96 * @param array $options associative array of GET variables to append to the URL
97 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
98 * @return string URL to file
99 */
100function get_file_url($path, $options=null, $type='coursefile') {
17c70aa0 101 global $CFG;
50a8bd6c
PS
102
103 $path = str_replace('//', '/', $path);
104 $path = trim($path, '/'); // no leading and trailing slashes
105
106 // type of file
107 switch ($type) {
108 case 'questionfile':
109 $url = $CFG->wwwroot."/question/exportfile.php";
110 break;
111 case 'rssfile':
112 $url = $CFG->wwwroot."/rss/file.php";
113 break;
114 case 'httpscoursefile':
115 $url = $CFG->httpswwwroot."/file.php";
116 break;
117 case 'coursefile':
118 default:
119 $url = $CFG->wwwroot."/file.php";
120 }
121
122 if ($CFG->slasharguments) {
123 $parts = explode('/', $path);
124 foreach ($parts as $key => $part) {
125 /// anchor dash character should not be encoded
126 $subparts = explode('#', $part);
127 $subparts = array_map('rawurlencode', $subparts);
128 $parts[$key] = implode('#', $subparts);
129 }
130 $path = implode('/', $parts);
131 $ffurl = $url.'/'.$path;
132 $separator = '?';
133 } else {
134 $path = rawurlencode('/'.$path);
135 $ffurl = $url.'?file='.$path;
136 $separator = '&amp;';
137 }
138
139 if ($options) {
140 foreach ($options as $name=>$value) {
141 $ffurl = $ffurl.$separator.$name.'='.$value;
142 $separator = '&amp;';
143 }
144 }
145
146 return $ffurl;
147}
148
f728d49b
PS
149/**
150 * If there has been an error uploading a file, print the appropriate error message
151 * Numerical constants used as constant definitions not added until PHP version 4.2.0
152 * @deprecated removed - use new file api
153 */
154function print_file_upload_error($filearray = '', $returnerror = false) {
cdefaa86 155 throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
f728d49b
PS
156}
157
158/**
159 * Handy function for resolving file conflicts
160 * @deprecated removed - use new file api
161 */
162
163function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
cdefaa86 164 throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
f728d49b
PS
165}
166
167/**
168 * Checks a file name for any conflicts
169 * @deprecated removed - use new file api
170 */
171function check_potential_filename($destination,$filename,$files) {
cdefaa86 172 throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
f728d49b
PS
173}
174
175/**
176 * This function prints out a number of upload form elements.
177 * @deprecated removed - use new file api
178 */
179function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
cdefaa86 180 throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
f728d49b
PS
181}
182
370f10b7
PS
183/**
184 * Return the authentication plugin title
185 *
186 * @param string $authtype plugin type
187 * @return string
188 */
189function auth_get_plugin_title($authtype) {
190 debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
191 return get_string('pluginname', "auth_{$authtype}");
192}
193
df997f84 194
f728d49b 195
df997f84
PS
196/**
197 * Enrol someone without using the default role in a course
198 * @deprecated
199 */
200function enrol_into_course($course, $user, $enrol) {
201 error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
202}
203
204/**
205 * Returns a role object that is the default role for new enrolments in a given course
206 *
207 * @deprecated
208 * @param object $course
209 * @return object returns a role or NULL if none set
210 */
211function get_default_course_role($course) {
212 debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
213
214 $student = get_archetype_roles('student');
215 $student = reset($student);
216
217 return $student;
218}
219
220/**
221 * Extremely slow enrolled courses query.
222 * @deprecated
223 */
224function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
225 error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
226}
227
1f96e907
PS
228/**
229 * Was returning list of translations, use new string_manager instead
230 *
231 * @deprecated
232 * @param bool $refreshcache force refreshing of lang cache
233 * @param bool $returnall ignore langlist, return all languages available
234 * @return array An associative array with contents in the form of LanguageCode => LanguageName
235 */
236function get_list_of_languages($refreshcache=false, $returnall=false) {
97b7d149 237 debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
1f96e907 238 if ($refreshcache) {
3fdcc0a0 239 get_string_manager()->reset_caches();
1f96e907
PS
240 }
241 return get_string_manager()->get_list_of_translations($returnall);
242}
370f10b7 243
97b7d149
PS
244/**
245 * Returns a list of currencies in the current language
246 * @deprecated
247 * @return array
248 */
249function get_list_of_currencies() {
250 debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
251 return get_string_manager()->get_list_of_currencies();
252}
253
0aa759b0
PS
254/**
255 * Returns a list of all enabled country names in the current translation
256 * @deprecated
257 * @return array two-letter country code => translated name.
258 */
259function get_list_of_countries() {
260 debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
261 return get_string_manager()->get_list_of_countries(false);
262}
263
c4d0753b 264/**
4f0c2d00 265 * @deprecated
c4d0753b 266 */
4f0c2d00
PS
267function isteacher() {
268 error('Function isteacher() was removed, please use capabilities instead!');
c4d0753b 269}
270
271/**
4f0c2d00 272 * @deprecated
c4d0753b 273 */
4f0c2d00
PS
274function isteacherinanycourse() {
275 error('Function isteacherinanycourse() was removed, please use capabilities instead!');
c4d0753b 276}
277
c4d0753b 278/**
ceebb2ec 279 * @deprecated
c4d0753b 280 */
4f0c2d00
PS
281function get_guest() {
282 error('Function get_guest() was removed, please use capabilities instead!');
283}
c4d0753b 284
4f0c2d00
PS
285/**
286 * @deprecated
287 */
288function isguest() {
289 error('Function isguest() was removed, please use capabilities instead!');
c4d0753b 290}
291
4f0c2d00
PS
292/**
293 * @deprecated
294 */
295function get_teacher() {
296 error('Function get_teacher() was removed, please use capabilities instead!');
297}
613bbd7c 298
299/**
4f0c2d00 300 * Return all course participant for a given course
613bbd7c 301 *
4f0c2d00
PS
302 * @deprecated
303 * @param integer $courseid
304 * @return array of user
613bbd7c 305 */
4f0c2d00
PS
306function get_course_participants($courseid) {
307 return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid));
613bbd7c 308}
309
613bbd7c 310/**
4f0c2d00 311 * Return true if the user is a participant for a given course
613bbd7c 312 *
4f0c2d00
PS
313 * @deprecated
314 * @param integer $userid
315 * @param integer $courseid
316 * @return boolean
613bbd7c 317 */
4f0c2d00
PS
318function is_course_participant($userid, $courseid) {
319 return is_enrolled(get_context_instance(CONTEXT_COURSE, $courseid), $userid);
613bbd7c 320}
321
322/**
323 * Searches logs to find all enrolments since a certain date
324 *
325 * used to print recent activity
326 *
c861fe2f 327 * @global object
328 * @uses CONTEXT_COURSE
613bbd7c 329 * @param int $courseid The course in question.
c861fe2f 330 * @param int $timestart The date to check forward of
613bbd7c 331 * @return object|false {@link $USER} records or false if error.
613bbd7c 332 */
333function get_recent_enrolments($courseid, $timestart) {
10df888a 334 global $DB;
364fffda 335
71dea306 336 $context = get_context_instance(CONTEXT_COURSE, $courseid);
613bbd7c 337
210751f6 338 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
10df888a 339 FROM {user} u, {role_assignments} ra, {log} l
340 WHERE l.time > ?
341 AND l.course = ?
342 AND l.module = 'course'
343 AND l.action = 'enrol'
9f43d70d 344 AND ".$DB->sql_cast_char2int('l.info')." = u.id
10df888a 345 AND u.id = ra.userid
346 AND ra.contextid ".get_related_contexts_string($context)."
210751f6
PS
347 GROUP BY u.id, u.firstname, u.lastname
348 ORDER BY MAX(l.time) ASC";
10df888a 349 $params = array($timestart, $courseid);
350 return $DB->get_records_sql($sql, $params);
613bbd7c 351}
352
4f0c2d00
PS
353
354/**
355 * Turn the ctx* fields in an objectlike record into a context subobject
356 * This allows us to SELECT from major tables JOINing with
357 * context at no cost, saving a ton of context lookups...
358 *
359 * Use context_instance_preload() instead.
360 *
361 * @deprecated since 2.0
362 * @param object $rec
363 * @return object
364 */
365function make_context_subobj($rec) {
366 $ctx = new StdClass;
367 $ctx->id = $rec->ctxid; unset($rec->ctxid);
368 $ctx->path = $rec->ctxpath; unset($rec->ctxpath);
369 $ctx->depth = $rec->ctxdepth; unset($rec->ctxdepth);
370 $ctx->contextlevel = $rec->ctxlevel; unset($rec->ctxlevel);
371 $ctx->instanceid = $rec->id;
372
373 $rec->context = $ctx;
374 return $rec;
375}
376
377/**
378 * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
379 *
380 * Use context_instance_preload() instead.
381 *
382 * @deprecated since 2.0
383 * @param object $rec a think that has a context, for example a course,
384 * course category, course modules, etc.
385 * @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
386 * @return bool whether $rec->context looks like the correct context object
387 * for this thing.
388 */
389function is_context_subobj_valid($rec, $contextlevel) {
390 return isset($rec->context) && isset($rec->context->id) &&
391 isset($rec->context->path) && isset($rec->context->depth) &&
392 isset($rec->context->contextlevel) && isset($rec->context->instanceid) &&
393 $rec->context->contextlevel == $contextlevel && $rec->context->instanceid == $rec->id;
394}
395
396/**
397 * Ensure that $rec->context is present and correct before you continue
398 *
399 * When you have a record (for example a $category, $course, $user or $cm that may,
400 * or may not, have come from a place that does make_context_subobj, you can use
401 * this method to ensure that $rec->context is present and correct before you continue.
402 *
403 * Use context_instance_preload() instead.
404 *
405 * @deprecated since 2.0
406 * @param object $rec a thing that has an associated context.
407 * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
408 */
409function ensure_context_subobj_present(&$rec, $contextlevel) {
410 if (!is_context_subobj_valid($rec, $contextlevel)) {
411 $rec->context = get_context_instance($contextlevel, $rec->id);
412 }
413}
414
2123b644 415########### FROM weblib.php ##########################################################################
416
417
418/**
419 * Print a message in a standard themed box.
364fffda 420 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
2123b644 421 * parameters remain. If possible, $align, $width and $color should not be defined at all.
422 * Preferably just use print_box() in weblib.php
423 *
34a2777c 424 * @deprecated
c861fe2f 425 * @param string $message The message to display
426 * @param string $align alignment of the box, not the text (default center, left, right).
427 * @param string $width width of the box, including units %, for example '100%'.
428 * @param string $color background colour of the box, for example '#eee'.
429 * @param int $padding padding in pixels, specified without units.
430 * @param string $class space-separated class names.
431 * @param string $id space-separated id names.
432 * @param boolean $return return as string or just print it
433 * @return string|void Depending on $return
2123b644 434 */
435function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
436 $output = '';
437 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
294ce987 438 $output .= $message;
2123b644 439 $output .= print_simple_box_end(true);
440
441 if ($return) {
442 return $output;
443 } else {
444 echo $output;
445 }
446}
447
448
449
450/**
364fffda 451 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
2123b644 452 * parameters remain. If possible, $align, $width and $color should not be defined at all.
453 * Even better, please use print_box_start() in weblib.php
454 *
c861fe2f 455 * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
456 * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
457 * @param string $color background colour of the box, for example '#eee'. DEPRECATED
458 * @param int $padding padding in pixels, specified without units. OBSOLETE
459 * @param string $class space-separated class names.
460 * @param string $id space-separated id names.
461 * @param boolean $return return as string or just print it
462 * @return string|void Depending on $return
2123b644 463 */
464function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
600313b9 465 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
2123b644 466
467 $output = '';
468
8f36e33e 469 $divclasses = 'box '.$class.' '.$class.'content';
2123b644 470 $divstyles = '';
471
472 if ($align) {
473 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
474 }
475 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
8f36e33e 476 if (substr($width, -1, 1) == '%') { // Width is a % value
477 $width = (int) substr($width, 0, -1); // Extract just the number
478 if ($width < 40) {
479 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
480 } else if ($width > 60) {
481 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
482 } else {
483 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
484 }
485 } else {
486 $divstyles .= ' width:'.$width.';'; // Last resort
487 }
2123b644 488 }
489 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
490 $divstyles .= ' background:'.$color.';';
491 }
492 if ($divstyles) {
493 $divstyles = ' style="'.$divstyles.'"';
494 }
495
496 if ($id) {
497 $id = ' id="'.$id.'"';
498 }
499
500 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
501
502 if ($return) {
503 return $output;
504 } else {
505 echo $output;
506 }
507}
508
509
510/**
511 * Print the end portion of a standard themed box.
512 * Preferably just use print_box_end() in weblib.php
c861fe2f 513 *
514 * @param boolean $return return as string or just print it
515 * @return string|void Depending on $return
2123b644 516 */
517function print_simple_box_end($return=false) {
518 $output = '</div>';
519 if ($return) {
520 return $output;
521 } else {
522 echo $output;
523 }
524}
525
e0ebc88e
DM
526/**
527 * Given some text this function converted any URLs it found into HTML links
528 *
529 * This core function has been replaced with filter_urltolink since Moodle 2.0
530 *
531 * @param string $text Passed in by reference. The string to be searched for urls.
532 */
533function convert_urls_into_links($text) {
534 debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
535}
536
18097238
DM
537/**
538 * Used to be called from help.php to inject a list of smilies into the
539 * emoticons help file.
540 *
541 * @return string HTML
542 */
543function get_emoticons_list_for_help_file() {
544 debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
545 return '';
546}
547
015ba71a
DM
548/**
549 * Was used to replace all known smileys in the text with image equivalents
550 *
551 * This core function has been replaced with filter_emoticon since Moodle 2.0
552 */
553function replace_smilies(&$text) {
554 debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
555}
556
ed5dd29f 557/**
558 * deprecated - use clean_param($string, PARAM_FILE); instead
559 * Check for bad characters ?
560 *
c861fe2f 561 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
562 *
ed5dd29f 563 * @param string $string ?
564 * @param int $allowdots ?
c861fe2f 565 * @return bool
ed5dd29f 566 */
567function detect_munged_arguments($string, $allowdots=1) {
568 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
569 return true;
570 }
69593309 571 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
ed5dd29f 572 return true;
573 }
574 if (empty($string) or $string == '/') {
575 return true;
576 }
577
578 return false;
579}
580
9152fc99 581
0c6d2dd4 582/**
583 * Unzip one zip file to a destination dir
584 * Both parameters must be FULL paths
585 * If destination isn't specified, it will be the
586 * SAME directory where the zip file resides.
c861fe2f 587 *
588 * @global object
589 * @param string $zipfile The zip file to unzip
590 * @param string $destination The location to unzip to
591 * @param bool $showstatus_ignored Unused
0c6d2dd4 592 */
593function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
594 global $CFG;
595
596 //Extract everything from zipfile
597 $path_parts = pathinfo(cleardoubleslashes($zipfile));
598 $zippath = $path_parts["dirname"]; //The path of the zip file
599 $zipfilename = $path_parts["basename"]; //The name of the zip file
600 $extension = $path_parts["extension"]; //The extension of the file
601
602 //If no file, error
603 if (empty($zipfilename)) {
604 return false;
605 }
606
607 //If no extension, error
608 if (empty($extension)) {
609 return false;
610 }
611
612 //Clear $zipfile
613 $zipfile = cleardoubleslashes($zipfile);
614
615 //Check zipfile exists
616 if (!file_exists($zipfile)) {
617 return false;
618 }
619
620 //If no destination, passed let's go with the same directory
621 if (empty($destination)) {
622 $destination = $zippath;
623 }
624
625 //Clear $destination
626 $destpath = rtrim(cleardoubleslashes($destination), "/");
627
628 //Check destination path exists
629 if (!is_dir($destpath)) {
630 return false;
631 }
632
0b0bfa93 633 $packer = get_file_packer('application/zip');
634
635 $result = $packer->extract_to_pathname($zipfile, $destpath);
0c6d2dd4 636
637 if ($result === false) {
638 return false;
639 }
640
641 foreach ($result as $status) {
642 if ($status !== true) {
643 return false;
644 }
645 }
646
647 return true;
648}
649
ed94cb66 650/**
651 * Zip an array of files/dirs to a destination zip file
652 * Both parameters must be FULL paths to the files/dirs
c861fe2f 653 *
654 * @global object
655 * @param array $originalfiles Files to zip
656 * @param string $destination The destination path
657 * @return bool Outcome
ed94cb66 658 */
659function zip_files ($originalfiles, $destination) {
660 global $CFG;
661
662 //Extract everything from destination
663 $path_parts = pathinfo(cleardoubleslashes($destination));
664 $destpath = $path_parts["dirname"]; //The path of the zip file
665 $destfilename = $path_parts["basename"]; //The name of the zip file
666 $extension = $path_parts["extension"]; //The extension of the file
667
668 //If no file, error
669 if (empty($destfilename)) {
670 return false;
671 }
672
673 //If no extension, add it
674 if (empty($extension)) {
675 $extension = 'zip';
676 $destfilename = $destfilename.'.'.$extension;
677 }
678
679 //Check destination path exists
680 if (!is_dir($destpath)) {
681 return false;
682 }
683
684 //Check destination path is writable. TODO!!
685
686 //Clean destination filename
687 $destfilename = clean_filename($destfilename);
688
689 //Now check and prepare every file
690 $files = array();
691 $origpath = NULL;
692
693 foreach ($originalfiles as $file) { //Iterate over each file
694 //Check for every file
695 $tempfile = cleardoubleslashes($file); // no doubleslashes!
696 //Calculate the base path for all files if it isn't set
697 if ($origpath === NULL) {
698 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
699 }
700 //See if the file is readable
701 if (!is_readable($tempfile)) { //Is readable
702 continue;
703 }
704 //See if the file/dir is in the same directory than the rest
705 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
706 continue;
707 }
708 //Add the file to the array
709 $files[] = $tempfile;
710 }
711
712 $zipfiles = array();
713 $start = strlen($origpath)+1;
714 foreach($files as $file) {
715 $zipfiles[substr($file, $start)] = $file;
716 }
717
0b0bfa93 718 $packer = get_file_packer('application/zip');
ed94cb66 719
3ed22f1a 720 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
ed94cb66 721}
722
ed5dd29f 723/////////////////////////////////////////////////////////////
724/// Old functions not used anymore - candidates for removal
725/////////////////////////////////////////////////////////////
726
ed5dd29f 727
1d684195 728/** various deprecated groups function **/
729
730
5bf243d1 731/**
732 * Get the IDs for the user's groups in the given course.
733 *
c861fe2f 734 * @global object
5bf243d1 735 * @param int $courseid The course being examined - the 'course' table id field.
c861fe2f 736 * @return array|bool An _array_ of groupids, or false
5bf243d1 737 * (Was return $groupids[0] - consequences!)
738 */
739function mygroupid($courseid) {
740 global $USER;
741 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
742 return array_keys($groups);
743 } else {
744 return false;
745 }
746}
747
5bf243d1 748
5bf243d1 749/**
750 * Returns the current group mode for a given course or activity module
364fffda 751 *
5bf243d1 752 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
c861fe2f 753 *
754 * @param object $course Course Object
755 * @param object $cm Course Manager Object
756 * @return mixed $course->groupmode
5bf243d1 757 */
758function groupmode($course, $cm=null) {
759
760 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
761 return $cm->groupmode;
762 }
763 return $course->groupmode;
764}
765
c584346c 766/**
767 * Sets the current group in the session variable
768 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
769 * Sets currentgroup[$courseid] in the session variable appropriately.
770 * Does not do any permission checking.
c861fe2f 771 *
772 * @global object
c584346c 773 * @param int $courseid The course being examined - relates to id field in
774 * 'course' table.
775 * @param int $groupid The group being examined.
776 * @return int Current group id which was set by this function
777 */
778function set_current_group($courseid, $groupid) {
779 global $SESSION;
780 return $SESSION->currentgroup[$courseid] = $groupid;
781}
782
5bf243d1 783
5bf243d1 784/**
364fffda 785 * Gets the current group - either from the session variable or from the database.
5bf243d1 786 *
c861fe2f 787 * @global object
364fffda 788 * @param int $courseid The course being examined - relates to id field in
5bf243d1 789 * 'course' table.
364fffda 790 * @param bool $full If true, the return value is a full record object.
5bf243d1 791 * If false, just the id of the record.
c861fe2f 792 * @return int|bool
5bf243d1 793 */
794function get_current_group($courseid, $full = false) {
795 global $SESSION;
796
797 if (isset($SESSION->currentgroup[$courseid])) {
798 if ($full) {
799 return groups_get_group($SESSION->currentgroup[$courseid]);
800 } else {
801 return $SESSION->currentgroup[$courseid];
802 }
803 }
804
805 $mygroupid = mygroupid($courseid);
806 if (is_array($mygroupid)) {
807 $mygroupid = array_shift($mygroupid);
808 set_current_group($courseid, $mygroupid);
809 if ($full) {
810 return groups_get_group($mygroupid);
811 } else {
812 return $mygroupid;
813 }
814 }
815
816 if ($full) {
817 return false;
818 } else {
819 return 0;
820 }
821}
822
823
8ec50604 824/**
a8ab8de9
PS
825 * Inndicates fatal error. This function was originally printing the
826 * error message directly, since 2.0 it is throwing exception instead.
3400bf6c 827 * The error printing is handled in default exception handler.
a8ab8de9 828 *
8ec50604 829 * Old method, don't call directly in new code - use print_error instead.
830 *
8ec50604 831 * @param string $message The message to display to the user about the error.
832 * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
a8ab8de9 833 * @return void, always throws moodle_exception
8ec50604 834 */
245ac557 835function error($message, $link='') {
78946b9b 836 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
251387d0 837}
8ec50604 838
8ec50604 839
b1f93b15 840/// Deprecated DDL functions, to be removed soon ///
c861fe2f 841/**
842 * @deprecated
843 * @global object
844 * @param string $table
845 * @return bool
846 */
b1f93b15 847function table_exists($table) {
848 global $DB;
849 debugging('Deprecated ddllib function used!');
850 return $DB->get_manager()->table_exists($table);
851}
852
c861fe2f 853/**
854 * @deprecated
855 * @global object
856 * @param string $table
857 * @param string $field
858 * @return bool
859 */
b1f93b15 860function field_exists($table, $field) {
861 global $DB;
862 debugging('Deprecated ddllib function used!');
863 return $DB->get_manager()->field_exists($table, $field);
864}
865
c861fe2f 866/**
867 * @deprecated
868 * @global object
869 * @param string $table
870 * @param string $index
871 * @return bool
872 */
b1f93b15 873function find_index_name($table, $index) {
874 global $DB;
875 debugging('Deprecated ddllib function used!');
876 return $DB->get_manager()->find_index_name($table, $index);
877}
878
c861fe2f 879/**
880 * @deprecated
881 * @global object
882 * @param string $table
883 * @param string $index
884 * @return bool
885 */
b1f93b15 886function index_exists($table, $index) {
887 global $DB;
888 debugging('Deprecated ddllib function used!');
889 return $DB->get_manager()->index_exists($table, $index);
890}
891
c861fe2f 892/**
893 * @deprecated
894 * @global object
895 * @param string $table
896 * @param string $field
897 * @return bool
898 */
b1f93b15 899function find_check_constraint_name($table, $field) {
900 global $DB;
901 debugging('Deprecated ddllib function used!');
902 return $DB->get_manager()->find_check_constraint_name($table, $field);
903}
904
c861fe2f 905/**
906 * @deprecated
907 * @global object
908 */
b1f93b15 909function check_constraint_exists($table, $field) {
910 global $DB;
911 debugging('Deprecated ddllib function used!');
912 return $DB->get_manager()->check_constraint_exists($table, $field);
913}
914
c861fe2f 915/**
916 * @deprecated
917 * @global object
918 * @param string $table
919 * @param string $xmldb_key
920 * @return bool
921 */
b1f93b15 922function find_key_name($table, $xmldb_key) {
923 global $DB;
924 debugging('Deprecated ddllib function used!');
925 return $DB->get_manager()->find_key_name($table, $xmldb_key);
926}
927
c861fe2f 928/**
929 * @deprecated
930 * @global object
931 * @param string $table
932 * @return bool
933 */
eee5d9bb 934function drop_table($table) {
b1f93b15 935 global $DB;
936 debugging('Deprecated ddllib function used!');
eee5d9bb 937 $DB->get_manager()->drop_table($table);
938 return true;
b1f93b15 939}
940
c861fe2f 941/**
942 * @deprecated
943 * @global object
944 * @param string $file
945 * @return bool
946 */
b1f93b15 947function install_from_xmldb_file($file) {
948 global $DB;
949 debugging('Deprecated ddllib function used!');
eee5d9bb 950 $DB->get_manager()->install_from_xmldb_file($file);
951 return true;
b1f93b15 952}
953
c861fe2f 954/**
955 * @deprecated
956 * @global object
957 * @param string $table
958 * @return bool
959 */
eee5d9bb 960function create_table($table) {
b1f93b15 961 global $DB;
962 debugging('Deprecated ddllib function used!');
eee5d9bb 963 $DB->get_manager()->create_table($table);
964 return true;
b1f93b15 965}
966
c861fe2f 967/**
968 * @deprecated
969 * @global object
970 * @param string $table
971 * @return bool
972 */
eee5d9bb 973function create_temp_table($table) {
b1f93b15 974 global $DB;
975 debugging('Deprecated ddllib function used!');
eee5d9bb 976 $DB->get_manager()->create_temp_table($table);
977 return true;
b1f93b15 978}
979
c861fe2f 980/**
981 * @deprecated
982 * @global object
983 * @param string $table
984 * @param string $newname
985 * @return bool
986 */
eee5d9bb 987function rename_table($table, $newname) {
b1f93b15 988 global $DB;
989 debugging('Deprecated ddllib function used!');
eee5d9bb 990 $DB->get_manager()->rename_table($table, $newname);
991 return true;
b1f93b15 992}
993
c861fe2f 994/**
995 * @deprecated
996 * @global object
997 * @param string $table
998 * @param string $field
999 * @return bool
1000 */
eee5d9bb 1001function add_field($table, $field) {
b1f93b15 1002 global $DB;
1003 debugging('Deprecated ddllib function used!');
eee5d9bb 1004 $DB->get_manager()->add_field($table, $field);
1005 return true;
b1f93b15 1006}
1007
c861fe2f 1008/**
1009 * @deprecated
1010 * @global object
1011 * @param string $table
1012 * @param string $field
1013 * @return bool
1014 */
eee5d9bb 1015function drop_field($table, $field) {
b1f93b15 1016 global $DB;
1017 debugging('Deprecated ddllib function used!');
eee5d9bb 1018 $DB->get_manager()->drop_field($table, $field);
1019 return true;
b1f93b15 1020}
1021
c861fe2f 1022/**
1023 * @deprecated
1024 * @global object
1025 * @param string $table
1026 * @param string $field
1027 * @return bool
1028 */
eee5d9bb 1029function change_field_type($table, $field) {
b1f93b15 1030 global $DB;
1031 debugging('Deprecated ddllib function used!');
eee5d9bb 1032 $DB->get_manager()->change_field_type($table, $field);
1033 return true;
b1f93b15 1034}
1035
c861fe2f 1036/**
1037 * @deprecated
1038 * @global object
1039 * @param string $table
1040 * @param string $field
1041 * @return bool
1042 */
eee5d9bb 1043function change_field_precision($table, $field) {
b1f93b15 1044 global $DB;
1045 debugging('Deprecated ddllib function used!');
eee5d9bb 1046 $DB->get_manager()->change_field_precision($table, $field);
1047 return true;
b1f93b15 1048}
1049
c861fe2f 1050/**
1051 * @deprecated
1052 * @global object
1053 * @param string $table
1054 * @param string $field
1055 * @return bool
1056 */
eee5d9bb 1057function change_field_unsigned($table, $field) {
b1f93b15 1058 global $DB;
1059 debugging('Deprecated ddllib function used!');
eee5d9bb 1060 $DB->get_manager()->change_field_unsigned($table, $field);
1061 return true;
b1f93b15 1062}
1063
c861fe2f 1064/**
1065 * @deprecated
1066 * @global object
1067 * @param string $table
1068 * @param string $field
1069 * @return bool
1070 */
eee5d9bb 1071function change_field_notnull($table, $field) {
b1f93b15 1072 global $DB;
1073 debugging('Deprecated ddllib function used!');
eee5d9bb 1074 $DB->get_manager()->change_field_notnull($table, $field);
1075 return true;
b1f93b15 1076}
1077
c861fe2f 1078/**
1079 * @deprecated
1080 * @global object
1081 * @param string $table
1082 * @param string $field
1083 * @return bool
1084 */
eee5d9bb 1085function change_field_enum($table, $field) {
b1f93b15 1086 global $DB;
526fe7d8 1087 debugging('Deprecated ddllib function used! Only dropping of enums is allowed.');
1088 $DB->get_manager()->drop_enum_from_field($table, $field);
eee5d9bb 1089 return true;
b1f93b15 1090}
1091
c861fe2f 1092/**
1093 * @deprecated
1094 * @global object
1095 * @param string $table
1096 * @param string $field
1097 * @return bool
1098 */
eee5d9bb 1099function change_field_default($table, $field) {
b1f93b15 1100 global $DB;
1101 debugging('Deprecated ddllib function used!');
eee5d9bb 1102 $DB->get_manager()->change_field_default($table, $field);
1103 return true;
b1f93b15 1104}
1105
c861fe2f 1106/**
1107 * @deprecated
1108 * @global object
1109 * @param string $table
1110 * @param string $field
1111 * @param string $newname
1112 * @return bool
1113 */
eee5d9bb 1114function rename_field($table, $field, $newname) {
b1f93b15 1115 global $DB;
1116 debugging('Deprecated ddllib function used!');
fe772c2a 1117 $DB->get_manager()->rename_field($table, $field, $newname);
eee5d9bb 1118 return true;
b1f93b15 1119}
1120
c861fe2f 1121/**
1122 * @deprecated
1123 * @global object
1124 * @param string $table
1125 * @param string $key
1126 * @return bool
1127 */
eee5d9bb 1128function add_key($table, $key) {
b1f93b15 1129 global $DB;
1130 debugging('Deprecated ddllib function used!');
eee5d9bb 1131 $DB->get_manager()->add_key($table, $key);
1132 return true;
b1f93b15 1133}
1134
c861fe2f 1135/**
1136 * @deprecated
1137 * @global object
1138 * @param string $table
1139 * @param string $key
1140 * @return bool
1141 */
eee5d9bb 1142function drop_key($table, $key) {
b1f93b15 1143 global $DB;
1144 debugging('Deprecated ddllib function used!');
eee5d9bb 1145 $DB->get_manager()->drop_key($table, $key);
1146 return true;
b1f93b15 1147}
1148
c861fe2f 1149/**
1150 * @deprecated
1151 * @global object
1152 * @param string $table
1153 * @param string $key
1154 * @param string $newname
1155 * @return bool
1156 */
eee5d9bb 1157function rename_key($table, $key, $newname) {
b1f93b15 1158 global $DB;
1159 debugging('Deprecated ddllib function used!');
eee5d9bb 1160 $DB->get_manager()->rename_key($table, $key, $newname);
1161 return true;
b1f93b15 1162}
1163
c861fe2f 1164/**
1165 * @deprecated
1166 * @global object
1167 * @param string $table
1168 * @param string $index
1169 * @return bool
1170 */
eee5d9bb 1171function add_index($table, $index) {
b1f93b15 1172 global $DB;
1173 debugging('Deprecated ddllib function used!');
eee5d9bb 1174 $DB->get_manager()->add_index($table, $index);
1175 return true;
b1f93b15 1176}
1177
c861fe2f 1178/**
1179 * @deprecated
1180 * @global object
1181 * @param string $table
1182 * @param string $index
1183 * @return bool
1184 */
eee5d9bb 1185function drop_index($table, $index) {
b1f93b15 1186 global $DB;
1187 debugging('Deprecated ddllib function used!');
eee5d9bb 1188 $DB->get_manager()->drop_index($table, $index);
1189 return true;
b1f93b15 1190}
1191
c861fe2f 1192/**
1193 * @deprecated
1194 * @global object
1195 * @param string $table
1196 * @param string $index
1197 * @param string $newname
1198 * @return bool
1199 */
eee5d9bb 1200function rename_index($table, $index, $newname) {
b1f93b15 1201 global $DB;
1202 debugging('Deprecated ddllib function used!');
eee5d9bb 1203 $DB->get_manager()->rename_index($table, $index, $newname);
1204 return true;
b1f93b15 1205}
1206
8ec50604 1207
251387d0 1208//////////////////////////
1209/// removed functions ////
1210//////////////////////////
294ce987 1211
c861fe2f 1212/**
1213 * @deprecated
1214 * @param mixed $mixed
1215 * @return void Throws an error and does nothing
1216 */
2fd0e9fe 1217function stripslashes_safe($mixed) {
1218 error('stripslashes_safe() not available anymore');
1219}
c861fe2f 1220/**
1221 * @deprecated
1222 * @param mixed $var
1223 * @return void Throws an error and does nothing
1224 */
2fd0e9fe 1225function stripslashes_recursive($var) {
1226 error('stripslashes_recursive() not available anymore');
1227}
c861fe2f 1228/**
1229 * @deprecated
1230 * @param mixed $dataobject
1231 * @return void Throws an error and does nothing
1232 */
245ac557 1233function addslashes_object($dataobject) {
6795800d 1234 error('addslashes_object() not available anymore');
294ce987 1235}
c861fe2f 1236/**
1237 * @deprecated
1238 * @param mixed $var
1239 * @return void Throws an error and does nothing
1240 */
294ce987 1241function addslashes_recursive($var) {
1242 error('addslashes_recursive() not available anymore');
1243}
c861fe2f 1244/**
1245 * @deprecated
1246 * @param mixed $command
1247 * @param bool $feedback
1248 * @return void Throws an error and does nothing
1249 */
245ac557 1250function execute_sql($command, $feedback=true) {
1251 error('execute_sql() not available anymore');
1252}
c861fe2f 1253/**
1254 * @deprecated
1255 * @param mixed $table
1256 * @param mixed $select
1257 * @return void Throws an error and does nothing
1258 */
245ac557 1259function record_exists_select($table, $select='') {
1260 error('record_exists_select() not available anymore');
1261}
c861fe2f 1262/**
1263 * @deprecated
1264 * @param mixed $sql
1265 * @return void Throws an error and does nothing
1266 */
245ac557 1267function record_exists_sql($sql) {
1268 error('record_exists_sql() not available anymore');
1269}
c861fe2f 1270/**
1271 * @deprecated
1272 * @param mixed $table
1273 * @param mixed $select
1274 * @param mixed $countitem
1275 * @return void Throws an error and does nothing
1276 */
245ac557 1277function count_records_select($table, $select='', $countitem='COUNT(*)') {
1278 error('count_records_select() not available anymore');
1279}
c861fe2f 1280/**
1281 * @deprecated
1282 * @param mixed $sql
1283 * @return void Throws an error and does nothing
1284 */
245ac557 1285function count_records_sql($sql) {
1286 error('count_records_sql() not available anymore');
1287}
c861fe2f 1288/**
1289 * @deprecated
1290 * @param mixed $sql
1291 * @param bool $expectmultiple
1292 * @param bool $nolimit
1293 * @return void Throws an error and does nothing
1294 */
245ac557 1295function get_record_sql($sql, $expectmultiple=false, $nolimit=false) {
1296 error('get_record_sql() not available anymore');
1297}
c861fe2f 1298/**
1299 * @deprecated
1300 * @param mixed $table
1301 * @param mixed $select
1302 * @param mixed $fields
1303 * @return void Throws an error and does nothing
1304 */
245ac557 1305function get_record_select($table, $select='', $fields='*') {
1306 error('get_record_select() not available anymore');
1307}
c861fe2f 1308/**
1309 * @deprecated
1310 * @param mixed $table
1311 * @param mixed $field
1312 * @param mixed $value
1313 * @param mixed $sort
1314 * @param mixed $fields
1315 * @param mixed $limitfrom
1316 * @param mixed $limitnum
1317 * @return void Throws an error and does nothing
1318 */
245ac557 1319function get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1320 error('get_recordset() not available anymore');
1321}
c861fe2f 1322/**
1323 * @deprecated
1324 * @param mixed $sql
1325 * @param mixed $limitfrom
1326 * @param mixed $limitnum
1327 * @return void Throws an error and does nothing
1328 */
245ac557 1329function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) {
1330 error('get_recordset_sql() not available anymore');
1331}
c861fe2f 1332/**
1333 * @deprecated
1334 * @param mixed $rs
1335 * @return void Throws an error and does nothing
1336 */
245ac557 1337function rs_fetch_record(&$rs) {
1338 error('rs_fetch_record() not available anymore');
1339}
c861fe2f 1340/**
1341 * @deprecated
1342 * @param mixed $rs
1343 * @return void Throws an error and does nothing
1344 */
245ac557 1345function rs_next_record(&$rs) {
1346 error('rs_next_record() not available anymore');
1347}
c861fe2f 1348/**
1349 * @deprecated
1350 * @param mixed $rs
1351 * @return void Throws an error and does nothing
1352 */
245ac557 1353function rs_fetch_next_record(&$rs) {
1354 error('rs_fetch_next_record() not available anymore');
1355}
c861fe2f 1356/**
1357 * @deprecated
1358 * @param mixed $rs
1359 * @return void Throws an error and does nothing
1360 */
245ac557 1361function rs_EOF($rs) {
1362 error('rs_EOF() not available anymore');
1363}
c861fe2f 1364/**
1365 * @deprecated
1366 * @param mixed $rs
1367 * @return void Throws an error and does nothing
1368 */
245ac557 1369function rs_close(&$rs) {
1370 error('rs_close() not available anymore');
1371}
c861fe2f 1372/**
1373 * @deprecated
1374 * @param mixed $table
1375 * @param mixed $select
1376 * @param mixed $sort
1377 * @param mixed $fields
1378 * @param mixed $limitfrom
1379 * @param mixed $limitnum
1380 * @return void Throws an error and does nothing
1381 */
245ac557 1382function get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1383 error('get_records_select() not available anymore');
1384}
c861fe2f 1385/**
1386 * @deprecated
1387 * @param mixed $table
1388 * @param mixed $return
1389 * @param mixed $select
1390 * @return void Throws an error and does nothing
1391 */
245ac557 1392function get_field_select($table, $return, $select) {
1393 error('get_field_select() not available anymore');
1394}
c861fe2f 1395/**
1396 * @deprecated
1397 * @param mixed $sql
1398 * @return void Throws an error and does nothing
1399 */
245ac557 1400function get_field_sql($sql) {
1401 error('get_field_sql() not available anymore');
1402}
c861fe2f 1403/**
1404 * @deprecated
1405 * @param mixed $sql
1406 * @param mixed $select
1407 * @return void Throws an error and does nothing
1408 */
245ac557 1409function delete_records_select($table, $select='') {
165a2c9e 1410 error('get_field_sql() not available anymore');
245ac557 1411}
c861fe2f 1412/**
1413 * @deprecated
1414 * @return void Throws an error and does nothing
1415 */
245ac557 1416function configure_dbconnection() {
1417 error('configure_dbconnection() removed');
1418}
c861fe2f 1419/**
1420 * @deprecated
1421 * @param mixed $field
1422 * @return void Throws an error and does nothing
1423 */
245ac557 1424function sql_max($field) {
1425 error('sql_max() removed - use normal sql MAX() instead');
1426}
c861fe2f 1427/**
1428 * @deprecated
1429 * @return void Throws an error and does nothing
1430 */
245ac557 1431function sql_as() {
1432 error('sql_as() removed - do not use AS for tables at all');
1433}
c861fe2f 1434/**
1435 * @deprecated
1436 * @param mixed $page
1437 * @param mixed $recordsperpage
1438 * @return void Throws an error and does nothing
1439 */
245ac557 1440function sql_paging_limit($page, $recordsperpage) {
1441 error('Function sql_paging_limit() is deprecated. Replace it with the correct use of limitfrom, limitnum parameters');
1442}
c861fe2f 1443/**
1444 * @deprecated
1445 * @return void Throws an error and does nothing
1446 */
245ac557 1447function db_uppercase() {
1448 error('upper() removed - use normal sql UPPER()');
1449}
c861fe2f 1450/**
1451 * @deprecated
1452 * @return void Throws an error and does nothing
1453 */
245ac557 1454function db_lowercase() {
1455 error('upper() removed - use normal sql LOWER()');
1456}
c861fe2f 1457/**
1458 * @deprecated
1459 * @param mixed $sqlfile
1460 * @param mixed $sqlstring
1461 * @return void Throws an error and does nothing
1462 */
245ac557 1463function modify_database($sqlfile='', $sqlstring='') {
1464 error('modify_database() removed - use new XMLDB functions');
1465}
c861fe2f 1466/**
1467 * @deprecated
1468 * @param mixed $field1
1469 * @param mixed $value1
1470 * @param mixed $field2
1471 * @param mixed $value2
1472 * @param mixed $field3
1473 * @param mixed $value3
1474 * @return void Throws an error and does nothing
1475 */
245ac557 1476function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1477 error('where_clause() removed - use new functions with $conditions parameter');
1478}
c861fe2f 1479/**
1480 * @deprecated
1481 * @param mixed $sqlarr
1482 * @param mixed $continue
1483 * @param mixed $feedback
1484 * @return void Throws an error and does nothing
1485 */
245ac557 1486function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
1487 error('execute_sql_arr() removed');
1488}
c861fe2f 1489/**
1490 * @deprecated
1491 * @param mixed $table
1492 * @param mixed $field
1493 * @param mixed $values
1494 * @param mixed $sort
1495 * @param mixed $fields
1496 * @param mixed $limitfrom
1497 * @param mixed $limitnum
1498 * @return void Throws an error and does nothing
1499 */
245ac557 1500function get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1501 error('get_records_list() removed');
1502}
c861fe2f 1503/**
1504 * @deprecated
1505 * @param mixed $table
1506 * @param mixed $field
1507 * @param mixed $values
1508 * @param mixed $sort
1509 * @param mixed $fields
1510 * @param mixed $limitfrom
1511 * @param mixed $limitnum
1512 * @return void Throws an error and does nothing
1513 */
245ac557 1514function get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1515 error('get_recordset_list() removed');
1516}
c861fe2f 1517/**
1518 * @deprecated
1519 * @param mixed $table
1520 * @param mixed $field
1521 * @param mixed $value
1522 * @param mixed $sort
1523 * @param mixed $fields
1524 * @param mixed $limitfrom
1525 * @param mixed $limitnum
1526 * @return void Throws an error and does nothing
1527 */
245ac557 1528function get_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1529 error('get_records_menu() removed');
1530}
c861fe2f 1531/**
1532 * @deprecated
1533 * @param mixed $table
1534 * @param mixed $select
1535 * @param mixed $sort
1536 * @param mixed $fields
1537 * @param mixed $limitfrom
1538 * @param mixed $limitnum
1539 * @return void Throws an error and does nothing
1540 */
245ac557 1541function get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1542 error('get_records_select_menu() removed');
1543}
c861fe2f 1544/**
1545 * @deprecated
1546 * @param mixed $sql
1547 * @param mixed $limitfrom
1548 * @param mixed $limitnum
1549 * @return void Throws an error and does nothing
1550 */
245ac557 1551function get_records_sql_menu($sql, $limitfrom='', $limitnum='') {
1552 error('get_records_sql_menu() removed');
1553}
c861fe2f 1554/**
1555 * @deprecated
1556 * @param mixed $table
1557 * @param mixed $column
1558 * @return void Throws an error and does nothing
1559 */
245ac557 1560function column_type($table, $column) {
1561 error('column_type() removed');
1562}
c861fe2f 1563/**
1564 * @deprecated
1565 * @param mixed $rs
1566 * @return void Throws an error and does nothing
1567 */
245ac557 1568function recordset_to_menu($rs) {
1569 error('recordset_to_menu() removed');
1570}
c861fe2f 1571/**
1572 * @deprecated
1573 * @param mixed $records
1574 * @param mixed $field1
1575 * @param mixed $field2
1576 * @return void Throws an error and does nothing
1577 */
245ac557 1578function records_to_menu($records, $field1, $field2) {
1579 error('records_to_menu() removed');
1580}
c861fe2f 1581/**
1582 * @deprecated
1583 * @param mixed $table
1584 * @param mixed $newfield
1585 * @param mixed $newvalue
1586 * @param mixed $select
1587 * @param mixed $localcall
1588 * @return void Throws an error and does nothing
1589 */
245ac557 1590function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) {
1591 error('set_field_select() removed');
1592}
c861fe2f 1593/**
1594 * @deprecated
1595 * @param mixed $table
1596 * @param mixed $return
1597 * @param mixed $select
1598 * @return void Throws an error and does nothing
1599 */
245ac557 1600function get_fieldset_select($table, $return, $select) {
1601 error('get_fieldset_select() removed');
1602}
c861fe2f 1603/**
1604 * @deprecated
1605 * @param mixed $sql
1606 * @return void Throws an error and does nothing
1607 */
245ac557 1608function get_fieldset_sql($sql) {
1609 error('get_fieldset_sql() removed');
1610}
c861fe2f 1611/**
1612 * @deprecated
1613 * @return void Throws an error and does nothing
1614 */
245ac557 1615function sql_ilike() {
1616 error('sql_ilike() not available anymore');
1617}
c861fe2f 1618/**
1619 * @deprecated
1620 * @param mixed $first
1621 * @param mixed $last
1622 * @return void Throws an error and does nothing
1623 */
245ac557 1624function sql_fullname($first='firstname', $last='lastname') {
1625 error('sql_fullname() not available anymore');
1626}
c861fe2f 1627/**
1628 * @deprecated
1629 * @return void Throws an error and does nothing
1630 */
245ac557 1631function sql_concat() {
1632 error('sql_concat() not available anymore');
1633}
c861fe2f 1634/**
1635 * @deprecated
1636 * @return void Throws an error and does nothing
1637 */
245ac557 1638function sql_empty() {
1639 error('sql_empty() not available anymore');
1640}
c861fe2f 1641/**
1642 * @deprecated
1643 * @return void Throws an error and does nothing
1644 */
245ac557 1645function sql_substr() {
1646 error('sql_substr() not available anymore');
1647}
c861fe2f 1648/**
1649 * @deprecated
1650 * @param mixed $int1
1651 * @param mixed $int2
1652 * @return void Throws an error and does nothing
1653 */
245ac557 1654function sql_bitand($int1, $int2) {
1655 error('sql_bitand() not available anymore');
1656}
c861fe2f 1657/**
1658 * @deprecated
1659 * @param mixed $int1
1660 * @return void Throws an error and does nothing
1661 */
245ac557 1662function sql_bitnot($int1) {
1663 error('sql_bitnot() not available anymore');
1664}
c861fe2f 1665/**
1666 * @deprecated
1667 * @param mixed $int1
1668 * @param mixed $int2
1669 * @return void Throws an error and does nothing
1670 */
245ac557 1671function sql_bitor($int1, $int2) {
1672 error('sql_bitor() not available anymore');
1673}
c861fe2f 1674/**
1675 * @deprecated
1676 * @param mixed $int1
1677 * @param mixed $int2
1678 * @return void Throws an error and does nothing
1679 */
245ac557 1680function sql_bitxor($int1, $int2) {
1681 error('sql_bitxor() not available anymore');
1682}
c861fe2f 1683/**
1684 * @deprecated
1685 * @param mixed $fieldname
1686 * @param mixed $text
1687 * @return void Throws an error and does nothing
1688 */
245ac557 1689function sql_cast_char2int($fieldname, $text=false) {
1690 error('sql_cast_char2int() not available anymore');
1691}
c861fe2f 1692/**
1693 * @deprecated
1694 * @param mixed $fieldname
1695 * @param mixed $numchars
1696 * @return void Throws an error and does nothing
1697 */
245ac557 1698function sql_compare_text($fieldname, $numchars=32) {
1699 error('sql_compare_text() not available anymore');
1700}
c861fe2f 1701/**
1702 * @deprecated
1703 * @param mixed $fieldname
1704 * @param mixed $numchars
1705 * @return void Throws an error and does nothing
1706 */
245ac557 1707function sql_order_by_text($fieldname, $numchars=32) {
1708 error('sql_order_by_text() not available anymore');
1709}
c861fe2f 1710/**
1711 * @deprecated
1712 * @param mixed $fieldname
1713 * @return void Throws an error and does nothing
1714 */
7b837bc3 1715function sql_length($fieldname) {
1716 error('sql_length() not available anymore');
1717}
c861fe2f 1718/**
1719 * @deprecated
1720 * @param mixed $separator
1721 * @param mixed $elements
1722 * @return void Throws an error and does nothing
1723 */
245ac557 1724function sql_concat_join($separator="' '", $elements=array()) {
1725 error('sql_concat_join() not available anymore');
1726}
c861fe2f 1727/**
1728 * @deprecated
1729 * @param mixed $tablename
1730 * @param mixed $fieldname
1731 * @param mixed $nullablefield
1732 * @param mixed $textfield
1733 * @return void Throws an error and does nothing
1734 */
245ac557 1735function sql_isempty($tablename, $fieldname, $nullablefield, $textfield) {
1736 error('sql_isempty() not available anymore');
1737}
c861fe2f 1738/**
1739 * @deprecated
1740 * @param mixed $tablename
1741 * @param mixed $fieldname
1742 * @param mixed $nullablefield
1743 * @param mixed $textfield
1744 * @return void Throws an error and does nothing
1745 */
245ac557 1746function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) {
1747 error('sql_isnotempty() not available anymore');
1748}
c861fe2f 1749/**
1750 * @deprecated
1751 * @return void Throws an error and does nothing
1752 */
245ac557 1753function begin_sql() {
1754 error('begin_sql() not available anymore');
1755}
c861fe2f 1756/**
1757 * @deprecated
1758 * @return void Throws an error and does nothing
1759 */
245ac557 1760function commit_sql() {
1761 error('commit_sql() not available anymore');
1762}
c861fe2f 1763/**
1764 * @deprecated
1765 * @return void Throws an error and does nothing
1766 */
245ac557 1767function rollback_sql() {
1768 error('rollback_sql() not available anymore');
1769}
c861fe2f 1770/**
1771 * @deprecated
1772 * @param mixed $table
1773 * @param mixed $dataobject
1774 * @param mixed $returnid
1775 * @param mixed $primarykey
1776 * @return void Throws an error and does nothing
1777 */
245ac557 1778function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
1779 error('insert_record() not available anymore');
1780}
c861fe2f 1781/**
1782 * @deprecated
1783 * @param mixed $table
1784 * @param mixed $dataobject
1785 * @return void Throws an error and does nothing
1786 */
245ac557 1787function update_record($table, $dataobject) {
1788 error('update_record() not available anymore');
1789}
c861fe2f 1790/**
1791 * @deprecated
1792 * @param mixed $table
1793 * @param mixed $field
1794 * @param mixed $value
1795 * @param mixed $sort
1796 * @param mixed $fields
1797 * @param mixed $limitfrom
1798 * @param mixed $limitnum
a5cb8d69 1799 *
c861fe2f 1800 * @return void Throws an error and does nothing
1801 */
245ac557 1802function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1803 error('get_records() not available anymore');
1804}
c861fe2f 1805/**
1806 * @deprecated
1807 * @param mixed $table
1808 * @param mixed $field1
1809 * @param mixed $value1
1810 * @param mixed $field2
1811 * @param mixed $value2
1812 * @param mixed $field3
1813 * @param mixed $value3
1814 * @param mixed $fields
1815 * @return void Throws an error and does nothing
1816 */
245ac557 1817function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') {
1818 error('get_record() not available anymore');
1819}
c861fe2f 1820/**
1821 * @deprecated
1822 * @param mixed $table
1823 * @param mixed $newfield
1824 * @param mixed $newvalue
1825 * @param mixed $field1
1826 * @param mixed $value1
1827 * @param mixed $field2
1828 * @param mixed $value2
1829 * @param mixed $field3
1830 * @param mixed $value3
1831 * @return void Throws an error and does nothing
1832 */
245ac557 1833function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1834 error('set_field() not available anymore');
1835}
c861fe2f 1836/**
1837 * @deprecated
1838 * @param mixed $table
1839 * @param mixed $field1
1840 * @param mixed $value1
1841 * @param mixed $field2
1842 * @param mixed $value2
1843 * @param mixed $field3
1844 * @param mixed $value3
1845 * @return void Throws an error and does nothing
1846 */
245ac557 1847function count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1848 error('count_records() not available anymore');
1849}
c861fe2f 1850/**
1851 * @deprecated
1852 * @param mixed $table
1853 * @param mixed $field1
1854 * @param mixed $value1
1855 * @param mixed $field2
1856 * @param mixed $value2
1857 * @param mixed $field3
1858 * @param mixed $value3
1859 * @return void Throws an error and does nothing
1860 */
245ac557 1861function record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1862 error('record_exists() not available anymore');
1863}
c861fe2f 1864/**
1865 * @deprecated
1866 * @param mixed $table
1867 * @param mixed $field1
1868 * @param mixed $value1
1869 * @param mixed $field2
1870 * @param mixed $value2
1871 * @param mixed $field3
1872 * @param mixed $value3
1873 * @return void Throws an error and does nothing
1874 */
245ac557 1875function delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1876 error('delete_records() not available anymore');
1877}
c861fe2f 1878/**
1879 * @deprecated
1880 * @param mixed $table
1881 * @param mixed $return
1882 * @param mixed $field1
1883 * @param mixed $value1
1884 * @param mixed $field2
1885 * @param mixed $value2
1886 * @param mixed $field3
1887 * @param mixed $value3
1888 * @return void Throws an error and does nothing
1889 */
245ac557 1890function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1891 error('get_field() not available anymore');
1892}
c861fe2f 1893/**
1894 * @deprecated
1895 * @param mixed $table
1896 * @param mixed $oldfield
1897 * @param mixed $field
1898 * @param mixed $type
1899 * @param mixed $size
1900 * @param mixed $signed
1901 * @param mixed $default
1902 * @param mixed $null
1903 * @param mixed $after
1904 * @return void Throws an error and does nothing
1905 */
e6b4f00e 1906function table_column($table, $oldfield, $field, $type='integer', $size='10',
1907 $signed='unsigned', $default='0', $null='not null', $after='') {
1908 error('table_column() was removed, please use new ddl functions');
1909}
c861fe2f 1910/**
1911 * @deprecated
1912 * @param mixed $name
1913 * @param mixed $editorhidebuttons
1914 * @param mixed $id
1915 * @return void Throws an error and does nothing
1916 */
88c8d161 1917function use_html_editor($name='', $editorhidebuttons='', $id='') {
1918 error('use_html_editor() not available anymore');
1919}
cf615522 1920
1921/**
1922 * The old method that was used to include JavaScript libraries.
28b6fe73 1923 * Please use $PAGE->requires->js_module() instead.
cf615522 1924 *
1925 * @param mixed $lib The library or libraries to load (a string or array of strings)
1926 * There are three way to specify the library:
985d1d1d 1927 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
cf615522 1928 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
1929 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
1930 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
1931 */
1932function require_js($lib) {
1933 global $CFG, $PAGE;
1934 // Add the lib to the list of libs to be loaded, if it isn't already
1935 // in the list.
1936 if (is_array($lib)) {
1937 foreach($lib as $singlelib) {
1938 require_js($singlelib);
1939 }
1940 return;
1941 }
1942
28b6fe73 1943 debugging('Call to deprecated function require_js. Please use $PAGE->requires->js_module() instead.', DEBUG_DEVELOPER);
cf615522 1944
1945 if (strpos($lib, 'yui_') === 0) {
985d1d1d 1946 $PAGE->requires->yui2_lib(substr($lib, 4));
cf615522 1947 } else {
88515081
PS
1948 if ($PAGE->requires->is_head_done()) {
1949 echo html_writer::script('', $lib);
1950 } else {
1951 $PAGE->requires->js(new moodle_url($lib));
1952 }
cf615522 1953 }
1954}
5af6ec1b 1955
1956/**
1957 * Makes an upload directory for a particular module.
1958 *
a5cb8d69 1959 * This function has been deprecated by the file API changes in Moodle 2.0.
5af6ec1b 1960 *
1961 * @deprecated
1962 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
1963 * @return string|false Returns full path to directory if successful, false if not
1964 */
1965function make_mod_upload_directory($courseid) {
28326b2a 1966 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
5af6ec1b 1967}
1968
b7009474 1969/**
1970 * Used to be used for setting up the theme. No longer used by core code, and
1971 * should not have been used elsewhere.
1972 *
1973 * The theme is now automatically initialised before it is first used. If you really need
1974 * to force this to happen, just reference $PAGE->theme.
1975 *
1976 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
1977 * However, I can't think of any valid reason to do that outside the theme selector UI.
1978 *
1979 * @deprecated
1980 * @param string $theme The theme to use defaults to current theme
1981 * @param array $params An array of parameters to use
1982 */
1983function theme_setup($theme = '', $params=NULL) {
1984 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
1985 'The current theme gets initialised automatically before it is first used.');
1986}
1987
1988/**
1989 * @deprecated use $PAGE->theme->name instead.
1990 * @return string the name of the current theme.
1991 */
1992function current_theme() {
1993 global $PAGE;
1994 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
1995 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
1996 return $PAGE->theme->name;
1997}
1998
a64e25f6 1999/**
2000 * @todo Remove this deprecated function when no longer used
2001 * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
2002 *
2003 * @param string $getid used to return $PAGE->pagetype.
2004 * @param string $getclass used to return $PAGE->legacyclass.
2005 */
2006function page_id_and_class(&$getid, &$getclass) {
2007 global $PAGE;
2008 debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
2009 $getid = $PAGE->pagetype;
2010 $getclass = $PAGE->legacyclass;
2011}
2012
8954245a 2013/**
2014 * Prints some red text using echo
2015 *
2016 * @deprecated
2017 * @param string $error The text to be displayed in red
2018 */
2019function formerr($error) {
3bd6b994 2020 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
8954245a 2021 global $OUTPUT;
2022 echo $OUTPUT->error_text($error);
2023}
2024
34a2777c 2025/**
2026 * Return the markup for the destination of the 'Skip to main content' links.
2027 * Accessibility improvement for keyboard-only users.
2028 *
2029 * Used in course formats, /index.php and /course/index.php
2030 *
2031 * @deprecated use $OUTPUT->skip_link_target() in instead.
2032 * @return string HTML element.
2033 */
2034function skip_main_destination() {
2035 global $OUTPUT;
2036 return $OUTPUT->skip_link_target();
2037}
2038
2039/**
2040 * Prints a string in a specified size (retained for backward compatibility)
2041 *
2042 * @deprecated
2043 * @param string $text The text to be displayed
2044 * @param int $size The size to set the font for text display.
2045 * @param bool $return If set to true output is returned rather than echoed Default false
2046 * @return string|void String if return is true
2047 */
2048function print_headline($text, $size=2, $return=false) {
2049 global $OUTPUT;
db49be13 2050 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
34a2777c 2051 $output = $OUTPUT->heading($text, $size);
2052 if ($return) {
2053 return $output;
2054 } else {
2055 echo $output;
2056 }
2057}
2058
2059/**
2060 * Prints text in a format for use in headings.
2061 *
2062 * @deprecated
2063 * @param string $text The text to be displayed
2064 * @param string $deprecated No longer used. (Use to do alignment.)
2065 * @param int $size The size to set the font for text display.
2066 * @param string $class
2067 * @param bool $return If set to true output is returned rather than echoed, default false
2068 * @param string $id The id to use in the element
2069 * @return string|void String if return=true nothing otherwise
2070 */
2071function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
2072 global $OUTPUT;
db49be13 2073 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
34a2777c 2074 if (!empty($deprecated)) {
2075 debugging('Use of deprecated align attribute of print_heading. ' .
2076 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
2077 }
2078 $output = $OUTPUT->heading($text, $size, $class, $id);
2079 if ($return) {
2080 return $output;
2081 } else {
2082 echo $output;
2083 }
2084}
2085
2086/**
2087 * Output a standard heading block
2088 *
2089 * @deprecated
2090 * @param string $heading The text to write into the heading
2091 * @param string $class An additional Class Attr to use for the heading
2092 * @param bool $return If set to true output is returned rather than echoed, default false
2093 * @return string|void HTML String if return=true nothing otherwise
2094 */
2095function print_heading_block($heading, $class='', $return=false) {
2096 global $OUTPUT;
db49be13 2097 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
78946b9b 2098 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
34a2777c 2099 if ($return) {
2100 return $output;
2101 } else {
2102 echo $output;
2103 }
2104}
2105
2106/**
2107 * Print a message in a standard themed box.
2108 * Replaces print_simple_box (see deprecatedlib.php)
2109 *
2110 * @deprecated
2111 * @param string $message, the content of the box
2112 * @param string $classes, space-separated class names.
2113 * @param string $ids
2114 * @param boolean $return, return as string or just print it
2115 * @return string|void mixed string or void
2116 */
2117function print_box($message, $classes='generalbox', $ids='', $return=false) {
2118 global $OUTPUT;
db49be13 2119 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
34a2777c 2120 $output = $OUTPUT->box($message, $classes, $ids);
2121 if ($return) {
2122 return $output;
2123 } else {
2124 echo $output;
2125 }
2126}
2127
2128/**
2129 * Starts a box using divs
2130 * Replaces print_simple_box_start (see deprecatedlib.php)
2131 *
2132 * @deprecated
2133 * @param string $classes, space-separated class names.
2134 * @param string $ids
2135 * @param boolean $return, return as string or just print it
2136 * @return string|void string or void
2137 */
2138function print_box_start($classes='generalbox', $ids='', $return=false) {
2139 global $OUTPUT;
db49be13 2140 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
34a2777c 2141 $output = $OUTPUT->box_start($classes, $ids);
2142 if ($return) {
2143 return $output;
2144 } else {
2145 echo $output;
2146 }
2147}
2148
2149/**
2150 * Simple function to end a box (see above)
2151 * Replaces print_simple_box_end (see deprecatedlib.php)
2152 *
2153 * @deprecated
2154 * @param boolean $return, return as string or just print it
2155 * @return string|void Depending on value of return
2156 */
2157function print_box_end($return=false) {
2158 global $OUTPUT;
db49be13 2159 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
34a2777c 2160 $output = $OUTPUT->box_end();
2161 if ($return) {
2162 return $output;
2163 } else {
2164 echo $output;
2165 }
2166}
2167
2168/**
2169 * Print a message in a standard themed container.
2170 *
2171 * @deprecated
2172 * @param string $message, the content of the container
2173 * @param boolean $clearfix clear both sides
2174 * @param string $classes, space-separated class names.
2175 * @param string $idbase
2176 * @param boolean $return, return as string or just print it
2177 * @return string|void Depending on value of $return
2178 */
2179function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
2180 global $OUTPUT;
2181 if ($clearfix) {
2182 $classes .= ' clearfix';
2183 }
2184 $output = $OUTPUT->container($message, $classes, $idbase);
2185 if ($return) {
2186 return $output;
2187 } else {
2188 echo $output;
2189 }
2190}
2191
2192/**
2193 * Starts a container using divs
2194 *
2195 * @deprecated
2196 * @param boolean $clearfix clear both sides
2197 * @param string $classes, space-separated class names.
2198 * @param string $idbase
2199 * @param boolean $return, return as string or just print it
2200 * @return string|void Based on value of $return
2201 */
2202function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
2203 global $OUTPUT;
2204 if ($clearfix) {
2205 $classes .= ' clearfix';
2206 }
2207 $output = $OUTPUT->container_start($classes, $idbase);
2208 if ($return) {
2209 return $output;
2210 } else {
2211 echo $output;
2212 }
2213}
2214
78946b9b
PS
2215/**
2216 * Deprecated, now handled automatically in themes
2217 */
2218function check_theme_arrows() {
2219 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
2220}
2221
34a2777c 2222/**
2223 * Simple function to end a container (see above)
2224 *
2225 * @deprecated
2226 * @param boolean $return, return as string or just print it
2227 * @return string|void Based on $return
2228 */
2229function print_container_end($return=false) {
2230 global $OUTPUT;
2231 $output = $OUTPUT->container_end();
2232 if ($return) {
2233 return $output;
2234 } else {
2235 echo $output;
2236 }
2237}
2238
2239/**
2240 * Print a bold message in an optional color.
2241 *
2242 * @deprecated use $OUTPUT->notification instead.
2243 * @param string $message The message to print out
2244 * @param string $style Optional style to display message text in
2245 * @param string $align Alignment option
2246 * @param bool $return whether to return an output string or echo now
a5cb8d69 2247 * @return string|bool Depending on $result
34a2777c 2248 */
2249function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
2250 global $OUTPUT;
2251
2252 if ($classes == 'green') {
2253 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
2254 $classes = 'notifysuccess'; // Backward compatible with old color system
2255 }
2256
2257 $output = $OUTPUT->notification($message, $classes);
2258 if ($return) {
2259 return $output;
2260 } else {
2261 echo $output;
2262 }
2263}
2264
2265/**
2266 * Print a continue button that goes to a particular URL.
2267 *
74623e0a 2268 * @deprecated since Moodle 2.0
2269 *
34a2777c 2270 * @param string $link The url to create a link to.
2271 * @param bool $return If set to true output is returned rather than echoed, default false
2272 * @return string|void HTML String if return=true nothing otherwise
2273 */
2274function print_continue($link, $return = false) {
2275 global $CFG, $OUTPUT;
2276
2277 if ($link == '') {
2278 if (!empty($_SERVER['HTTP_REFERER'])) {
2279 $link = $_SERVER['HTTP_REFERER'];
2280 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
2281 } else {
2282 $link = $CFG->wwwroot .'/';
2283 }
2284 }
2285
2286 $output = $OUTPUT->continue_button($link);
2287 if ($return) {
2288 return $output;
2289 } else {
2290 echo $output;
2291 }
2292}
2293
34a2777c 2294/**
2295 * Print a standard header
2296 *
2297 * @param string $title Appears at the top of the window
2298 * @param string $heading Appears at the top of the page
2299 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
2300 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2301 * @param string $meta Meta tags to be added to the header
2302 * @param boolean $cache Should this page be cacheable?
2303 * @param string $button HTML code for a button (usually for module editing)
2304 * @param string $menu HTML code for a popup menu
2305 * @param boolean $usexml use XML for this page
2306 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2307 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2308 * @return string|void If return=true then string else void
2309 */
2310function print_header($title='', $heading='', $navigation='', $focus='',
e120c61d 2311 $meta='', $cache=true, $button='&nbsp;', $menu=null,
34a2777c 2312 $usexml=false, $bodytags='', $return=false) {
2313 global $PAGE, $OUTPUT;
2314
2315 $PAGE->set_title($title);
2316 $PAGE->set_heading($heading);
3a11c09f 2317 $PAGE->set_cacheable($cache);
34a2777c 2318 if ($button == '') {
2319 $button = '&nbsp;';
2320 }
2321 $PAGE->set_button($button);
e120c61d 2322 $PAGE->set_headingmenu($menu);
34a2777c 2323
34a2777c 2324 // TODO $menu
2325
2326 if ($meta) {
2327 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
e29380f3 2328 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
34a2777c 2329 }
2330 if ($usexml) {
2331 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2332 }
2333 if ($bodytags) {
2334 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2335 }
2336
e120c61d 2337 $output = $OUTPUT->header();
34a2777c 2338
2339 if ($return) {
2340 return $output;
2341 } else {
2342 echo $output;
2343 }
2344}
2345
47a1aa45 2346/**
2347 * This version of print_header is simpler because the course name does not have to be
2348 * provided explicitly in the strings. It can be used on the site page as in courses
2349 * Eventually all print_header could be replaced by print_header_simple
2350 *
2351 * @deprecated since Moodle 2.0
2352 * @param string $title Appears at the top of the window
2353 * @param string $heading Appears at the top of the page
2354 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
2355 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2356 * @param string $meta Meta tags to be added to the header
2357 * @param boolean $cache Should this page be cacheable?
2358 * @param string $button HTML code for a button (usually for module editing)
2359 * @param string $menu HTML code for a popup menu
2360 * @param boolean $usexml use XML for this page
2361 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2362 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2363 * @return string|void If $return=true the return string else nothing
2364 */
2365function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
2366 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
2367
2368 global $COURSE, $CFG, $PAGE, $OUTPUT;
2369
2370 if ($meta) {
2371 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2372 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2373 }
2374 if ($usexml) {
2375 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2376 }
2377 if ($bodytags) {
2378 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2379 }
2380
2381 $PAGE->set_title($title);
3a11c09f 2382 $PAGE->set_heading($heading);
47a1aa45 2383 $PAGE->set_cacheable(true);
2384 $PAGE->set_button($button);
2385
2386 $output = $OUTPUT->header();
2387
2388 if ($return) {
2389 return $output;
2390 } else {
2391 echo $output;
2392 }
2393}
2394
34a2777c 2395function print_footer($course = NULL, $usercourse = NULL, $return = false) {
2396 global $PAGE, $OUTPUT;
db49be13 2397 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
34a2777c 2398 // TODO check arguments.
2399 if (is_string($course)) {
2400 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
78946b9b 2401 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
34a2777c 2402 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
2403 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
2404 }
2405 if (!is_null($usercourse)) {
2406 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
2407 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
2408 }
2409 $output = $OUTPUT->footer();
2410 if ($return) {
2411 return $output;
2412 } else {
2413 echo $output;
2414 }
a5cb8d69 2415}
2416
244a32c6
PS
2417/**
2418 * Returns text to be displayed to the user which reflects their login status
2419 *
2420 * @global object
2421 * @global object
2422 * @global object
2423 * @global object
2424 * @uses CONTEXT_COURSE
2425 * @param course $course {@link $COURSE} object containing course information
2426 * @param user $user {@link $USER} object containing user information
2427 * @return string HTML
2428 */
2429function user_login_string($course='ignored', $user='ignored') {
2430 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
2431 return '';
2432}
2433
a5cb8d69 2434/**
2435 * Prints a nice side block with an optional header. The content can either
2436 * be a block of HTML or a list of text with optional icons.
2437 *
2438 * @todo Finish documenting this function. Show example of various attributes, etc.
2439 *
2440 * @static int $block_id Increments for each call to the function
2441 * @param string $heading HTML for the heading. Can include full HTML or just
2442 * plain text - plain text will automatically be enclosed in the appropriate
2443 * heading tags.
2444 * @param string $content HTML for the content
2445 * @param array $list an alternative to $content, it you want a list of things with optional icons.
2446 * @param array $icons optional icons for the things in $list.
2447 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
2448 * @param array $attributes an array of attribute => value pairs that are put on the
6605ff8c
SH
2449 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
2450 * already a class, class='block' is used.
a5cb8d69 2451 * @param string $title Plain text title, as embedded in the $heading.
2452 * @deprecated
2453 */
2454function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
2455 global $OUTPUT;
d4a03c00 2456
2457 // We don't use $heading, becuse it often contains HTML that we don't want.
2458 // However, sometimes $title is not set, but $heading is.
2459 if (empty($title)) {
2460 $title = strip_tags($heading);
2461 }
2462
2463 // Render list contents to HTML if required.
2464 if (empty($content) && $list) {
2465 $content = $OUTPUT->list_block_contents($icons, $list);
2466 }
2467
a5cb8d69 2468 $bc = new block_contents();
a5cb8d69 2469 $bc->content = $content;
a5cb8d69 2470 $bc->footer = $footer;
2471 $bc->title = $title;
2472
2473 if (isset($attributes['id'])) {
2474 $bc->id = $attributes['id'];
2475 unset($attributes['id']);
2476 }
a5cb8d69 2477 $bc->attributes = $attributes;
2478
3ceb6910 2479 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
a5cb8d69 2480}
2481
2482/**
2483 * Starts a nice side block with an optional header.
2484 *
2485 * @todo Finish documenting this function
2486 *
2487 * @global object
2488 * @global object
2489 * @param string $heading HTML for the heading. Can include full HTML or just
2490 * plain text - plain text will automatically be enclosed in the appropriate
2491 * heading tags.
2492 * @param array $attributes HTML attributes to apply if possible
2493 * @deprecated
2494 */
2495function print_side_block_start($heading='', $attributes = array()) {
3ceb6910 2496 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
a5cb8d69 2497}
2498
2499/**
2500 * Print table ending tags for a side block box.
2501 *
2502 * @global object
2503 * @global object
2504 * @param array $attributes HTML attributes to apply if possible [id]
2505 * @param string $title
2506 * @deprecated
2507 */
2508function print_side_block_end($attributes = array(), $title='') {
3ceb6910 2509 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
a5cb8d69 2510}
d4a03c00 2511
2512/**
2513 * This was used by old code to see whether a block region had anything in it,
2514 * and hence wether that region should be printed.
2515 *
2516 * We don't ever want old code to print blocks, so we now always return false.
2517 * The function only exists to avoid fatal errors in old code.
2518 *
2519 * @deprecated since Moodle 2.0. always returns false.
2520 *
2521 * @param object $blockmanager
2522 * @param string $region
2523 * @return bool
2524 */
2525function blocks_have_content(&$blockmanager, $region) {
2526 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
2527 return false;
2528}
2529
2530/**
2531 * This was used by old code to print the blocks in a region.
053203a8 2532 *
d4a03c00 2533 * We don't ever want old code to print blocks, so this is now a no-op.
2534 * The function only exists to avoid fatal errors in old code.
2535 *
2536 * @deprecated since Moodle 2.0. does nothing.
2537 *
2538 * @param object $page
2539 * @param object $blockmanager
2540 * @param string $region
2541 */
2542function blocks_print_group($page, $blockmanager, $region) {
2543 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2544}
2545
2546/**
2547 * This used to be the old entry point for anyone that wants to use blocks.
2548 * Since we don't want people people dealing with blocks this way any more,
2549 * just return a suitable empty array.
2550 *
2551 * @deprecated since Moodle 2.0.
2552 *
2553 * @param object $page
2554 * @return array
2555 */
2556function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
2557 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2558 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
2559}
2560
2561/**
2562 * This iterates over an array of blocks and calculates the preferred width
2563 * Parameter passed by reference for speed; it's not modified.
2564 *
2565 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
2566 *
2567 * @param mixed $instances
2568 */
2569function blocks_preferred_width($instances) {
2570 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2571 $width = 210;
2572}
2573
a19f419d 2574/**
2575 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2576 *
2577 * @param object $page The page object
2578 * @param object $blockmanager The block manager object
2579 * @param string $blockaction One of [config, add, delete]
2580 * @param int|object $instanceorid The instance id or a block_instance object
2581 * @param bool $pinned
2582 * @param bool $redirect To redirect or not to that is the question but you should stick with true
2583 */
2584function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
2585 throw new coding_exception('blocks_execute_action is no longer used. The way blocks work has been changed. See the new code in blocklib.php.');
2586}
2587
2588/**
2589 * You can use this to get the blocks to respond to URL actions without much hassle
2590 *
2591 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
2592 *
2593 * @param object $PAGE
2594 * @param object $blockmanager
2595 * @param bool $pinned
2596 */
2597function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
2598 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
2599}
2600
2601/**
2602 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
2603 * in order to reduce code repetition.
2604 *
2605 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2606 *
2607 * @param $instance
2608 * @param $newpos
2609 * @param string|int $newweight
2610 * @param bool $pinned
2611 */
2612function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
2613 throw new coding_exception('blocks_execute_repositioning is no longer used. The way blocks work has been changed. See the new code in blocklib.php.');
2614}
2615
2616
2617/**
2618 * Moves a block to the new position (column) and weight (sort order).
2619 *
2620 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2621 *
2622 * @param object $instance The block instance to be moved.
2623 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
2624 * @param string $destweight The destination sort order. If NULL, we add to the end
2625 * of the destination column.
2626 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
2627 * to a new position withing the pinned list. Likewise, we
2628 * can only moved non-pinned blocks to a new position within
2629 * the non-pinned list.
2630 * @return boolean success or failure
2631 */
2632function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
2633 throw new coding_exception('blocks_move_block is no longer used. The way blocks work has been changed. See the new code in blocklib.php.');
2634}
2635
480b0720 2636/**
2637 * Print a nicely formatted table.
2638 *
2639 * @deprecated since Moodle 2.0
2640 *
2641 * @param array $table is an object with several properties.
2642 */
2643function print_table($table, $return=false) {
2644 global $OUTPUT;
2645 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
16be8974 2646 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
480b0720 2647 $newtable = new html_table();
2648 foreach ($table as $property => $value) {
2649 if (property_exists($newtable, $property)) {
2650 $newtable->{$property} = $value;
2651 }
2652 }
2653 if (isset($table->class)) {
16be8974 2654 $newtable->attributes['class'] = $table->class;
480b0720 2655 }
2656 if (isset($table->rowclass) && is_array($table->rowclass)) {
2657 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
2658 $newtable->rowclasses = $table->rowclass;
2659 }
16be8974 2660 $output = html_writer::table($newtable);
480b0720 2661 if ($return) {
2662 return $output;
2663 } else {
2664 echo $output;
2665 return true;
2666 }
2667}
f8065dd2 2668
2669/**
2670 * Creates and displays (or returns) a link to a popup window
2671 *
2672 * @deprecated since Moodle 2.0
2673 *
2674 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2675 * @param string $name Name to be assigned to the popup window (this is used by
2676 * client-side scripts to "talk" to the popup window)
2677 * @param string $linkname Text to be displayed as web link
2678 * @param int $height Height to assign to popup window
2679 * @param int $width Height to assign to popup window
2680 * @param string $title Text to be displayed as popup page title
2681 * @param string $options List of additional options for popup window
2682 * @param bool $return If true, return as a string, otherwise print
2683 * @param string $id id added to the element
2684 * @param string $class class added to the element
2685 * @return string html code to display a link to a popup window.
2686 */
4bcc5118 2687function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
75015e5f 2688 debugging('link_to_popup_window() has been removed. Please change your code to use $OUTPUT->action_link(). Please note popups are discouraged for accessibility reasons');
f8065dd2 2689
75015e5f 2690 return html_writer::link($url, $name);
f8065dd2 2691}
2692
2693/**
2694 * Creates and displays (or returns) a buttons to a popup window.
2695 *
2696 * @deprecated since Moodle 2.0
2697 *
2698 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2699 * @param string $name Name to be assigned to the popup window (this is used by
2700 * client-side scripts to "talk" to the popup window)
2701 * @param string $linkname Text to be displayed as web link
2702 * @param int $height Height to assign to popup window
2703 * @param int $width Height to assign to popup window
2704 * @param string $title Text to be displayed as popup page title
2705 * @param string $options List of additional options for popup window
2706 * @param bool $return If true, return as a string, otherwise print
2707 * @param string $id id added to the element
2708 * @param string $class class added to the element
2709 * @return string html code to display a link to a popup window.
2710 */
2711function button_to_popup_window ($url, $name=null, $linkname=null,
2712 $height=400, $width=500, $title=null, $options=null, $return=false,
2713 $id=null, $class=null) {
2714 global $OUTPUT;
2715
5c2ed7e2 2716 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
f8065dd2 2717
2718 if ($options == 'none') {
2719 $options = null;
2720 }
2721
2722 if (empty($linkname)) {
75015e5f 2723 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
f8065dd2 2724 }
2725
ce0110bf 2726 // Create a single_button object
3757b59f 2727 $form = new single_button($url, $linkname, 'post');
28fbce88 2728 $form->button->title = $title;
2729 $form->button->id = $id;
f8065dd2 2730
2731 // Parse the $options string
2732 $popupparams = array();
053203a8 2733 if (!empty($options)) {
f8065dd2 2734 $optionsarray = explode(',', $options);
2735 foreach ($optionsarray as $option) {
2736 if (strstr($option, '=')) {
2737 $parts = explode('=', $option);
2738 if ($parts[1] == '0') {
2739 $popupparams[$parts[0]] = false;
2740 } else {
2741 $popupparams[$parts[0]] = $parts[1];
2742 }
2743 } else {
2744 $popupparams[$option] = true;
2745 }
2746 }
2747 }
2748
2749 if (!empty($height)) {
2750 $popupparams['height'] = $height;
2751 }
2752 if (!empty($width)) {
2753 $popupparams['width'] = $width;
2754 }
2755
28fbce88 2756 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
3757b59f 2757 $output = $OUTPUT->render($form);
f8065dd2 2758
2759 if ($return) {
2760 return $output;
2761 } else {
053203a8 2762 echo $output;
f8065dd2 2763 }
2764}
2765
2766/**
2767 * Print a self contained form with a single submit button.
2768 *
2769 * @deprecated since Moodle 2.0
2770 *
2771 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
2772 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
2773 * @param string $label the caption that appears on the button.
2774 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
2775 * @param string $notusedanymore no longer used.
2776 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
2777 * @param string $tooltip a tooltip to add to the button as a title attribute.
2778 * @param boolean $disabled if true, the button will be disabled.
2779 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
2780 * @param string $formid The id attribute to use for the form
2781 * @return string|void Depending on the $return paramter.
2782 */
2783function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
2784 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
2785 global $OUTPUT;
2786
5c2ed7e2 2787 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
f8065dd2 2788
2789 // Cast $options to array
2790 $options = (array) $options;
d894edd4 2791
b2db46ec 2792 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
f8065dd2 2793
2794 if ($jsconfirmmessage) {
d894edd4 2795 $button->button->add_confirm_action($jsconfirmmessage);
f8065dd2 2796 }
2797
3757b59f 2798 $output = $OUTPUT->render($button);
49c8c8d2 2799
f8065dd2 2800 if ($return) {
2801 return $output;
2802 } else {
2803 echo $output;
2804 }
2805}
2806
2807/**
2808 * Print a spacer image with the option of including a line break.
2809 *
2810 * @deprecated since Moodle 2.0
2811 *
2812 * @global object
2813 * @param int $height The height in pixels to make the spacer
2814 * @param int $width The width in pixels to make the spacer
2815 * @param boolean $br If set to true a BR is written after the spacer
2816 */
2817function print_spacer($height=1, $width=1, $br=true, $return=false) {
2818 global $CFG, $OUTPUT;
2819
db49be13 2820 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
f8065dd2 2821
1ba862ec 2822 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
bef1011e 2823
f8065dd2 2824 if ($return) {
2825 return $output;
2826 } else {
2827 echo $output;
2828 }
2829}
2830
2831/**
2832 * Given the path to a picture file in a course, or a URL,
2833 * this function includes the picture in the page.
2834 *
2835 * @deprecated since Moodle 2.0
2836 */
2837function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
2838 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
2839}
2840
2841/**
2842 * Print the specified user's avatar.
2843 *
2844 * @deprecated since Moodle 2.0
2845 *
2846 * @global object
2847 * @global object
3a11c09f 2848 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
f8065dd2 2849 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
2850 * if at all possible, particularly for reports. It is very bad for performance.
2851 * @param int $courseid The course id. Used when constructing the link to the user's profile.
2852 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
2853 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
2854 * @param boolean $return If false print picture to current page, otherwise return the output as string
2855 * @param boolean $link enclose printed image in a link the user's profile (default true).
2856 * @param string $target link target attribute. Makes the profile open in a popup window.
2857 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
2858 * decorative images, or where the username will be printed anyway.)
2859 * @return string|void String or nothing, depending on $return.
2860 */
2861function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
812dbaf7 2862 global $OUTPUT;
f8065dd2 2863
812dbaf7 2864 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
f8065dd2 2865
812dbaf7
PS
2866 if (!is_object($user)) {
2867 $userid = $user;
365a5941 2868 $user = new stdClass();
812dbaf7 2869 $user->id = $userid;
f8065dd2 2870 }
2871
812dbaf7
PS
2872 if (empty($user->picture) and $picture) {
2873 $user->picture = $picture;
f8065dd2 2874 }
2875
812dbaf7
PS
2876 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
2877
2878 $output = $OUTPUT->user_picture($user, $options);
f8065dd2 2879
2880 if ($return) {
2881 return $output;
2882 } else {
2883 echo $output;
2884 }
2885}
2886
2887/**
2888 * Print a png image.
2889 *
2890 * @deprecated since Moodle 2.0: no replacement
2891 *
2892 */
2893function print_png() {
000c278c 2894 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
f8065dd2 2895}
2896
2897
2898/**
2899 * Prints a basic textarea field.
2900 *
2901 * @deprecated since Moodle 2.0
2902 *
2903 * When using this function, you should
2904 *
2905 * @global object
2906 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
2907 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
2908 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
2909 * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
2910 * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
2911 * @param string $name Name to use for the textarea element.
2912 * @param string $value Initial content to display in the textarea.
2913 * @param int $obsolete deprecated
2914 * @param bool $return If false, will output string. If true, will return string value.
2915 * @param string $id CSS ID to add to the textarea element.
2916 * @return string|void depending on the value of $return
2917 */
2918function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
2919 /// $width and height are legacy fields and no longer used as pixels like they used to be.
2920 /// However, you can set them to zero to override the mincols and minrows values below.
2921
3d8a479b
MD
2922 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
2923 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
f8065dd2 2924
2925 global $CFG;
2926
2927 $mincols = 65;
2928 $minrows = 10;
2929 $str = '';
2930
2931 if ($id === '') {
2932 $id = 'edit-'.$name;
2933 }
2934
2935 if ($usehtmleditor) {
2936 if ($height && ($rows < $minrows)) {
2937 $rows = $minrows;
2938 }
2939 if ($width && ($cols < $mincols)) {
2940 $cols = $mincols;
2941 }
2942 }
2943
2944 if ($usehtmleditor) {
2945 editors_head_setup();
20e5da7d 2946 $editor = editors_get_preferred_editor(FORMAT_HTML);
f8065dd2 2947 $editor->use_editor($id, array('legacy'=>true));
2948 } else {
2949 $editorclass = '';
2950 }
2951
2952 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
2953 if ($usehtmleditor) {
2954 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
2955 } else {
2956 $str .= s($value);
2957 }
2958 $str .= '</textarea>'."\n";
2959
2960 if ($return) {
2961 return $str;
2962 }
2963 echo $str;
2964}
2965
2966
2967/**
2968 * Print a help button.
2969 *
2970 * @deprecated since Moodle 2.0
2971 *
2972 * @param string $page The keyword that defines a help page
2973 * @param string $title The title of links, rollover tips, alt tags etc
2974 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
2975 * @param string $module Which module is the page defined in
2976 * @param mixed $image Use a help image for the link? (true/false/"both")
2977 * @param boolean $linktext If true, display the title next to the help icon.
2978 * @param string $text If defined then this text is used in the page, and
2979 * the $page variable is ignored. DEPRECATED!
2980 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
2981 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
2982 * @return string|void Depending on value of $return
2983 */
2984function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
cb616be8 2985 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
f8065dd2 2986
2987 global $OUTPUT;
2988
596509e4 2989 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
f8065dd2 2990
4bcc5118 2991 // hide image with CSS if needed
f8065dd2 2992
2993 if ($return) {
2994 return $output;
2995 } else {
2996 echo $output;
2997 }
4bcc5118
PS
2998}
2999
3000/**
3001 * Print a help button.
3002 *
3003 * Prints a special help button that is a link to the "live" emoticon popup
3004 *
3005 * @todo Finish documenting this function
3006 *
3007 * @global object
3008 * @global object
3009 * @param string $form ?
3010 * @param string $field ?
3011 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
3012 * @return string|void Depending on value of $return
3013 */
3014function emoticonhelpbutton($form, $field, $return = false) {
3015 /// TODO: MDL-21215
3016
3017 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
3018}
3019
3020/**
3021 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
3022 * Should be used only with htmleditor or textarea.
3023 *
3024 * @global object
3025 * @global object
3026 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
3027 * helpbutton.
3028 * @return string Link to help button
3029 */
3030function editorhelpbutton(){
3031 return '';
3032
3033 /// TODO: MDL-21215
f8065dd2 3034}
3035
4bcc5118
PS
3036/**
3037 * Print a help button.
3038 *
3039 * Prints a special help button for html editors (htmlarea in this case)
3040 *
3041 * @todo Write code into this function! detect current editor and print correct info
3042 * @global object
3043 * @return string Only returns an empty string at the moment
3044 */
3045function editorshortcutshelpbutton() {
3046 /// TODO: MDL-21215
3047
3048 global $CFG;
3049 //TODO: detect current editor and print correct info
3050/* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
3051 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
3052
3053 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
3054 return '';
3055}
3056
3057
f8065dd2 3058/**
3059 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
3060 * provide this function with the language strings for sortasc and sortdesc.
3061 *
3062 * @deprecated since Moodle 2.0
3063 *
3064 * TODO migrate to outputlib
3065 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
3066 *
3067 * @global object
3068 * @param string $direction 'up' or 'down'
3069 * @param string $strsort The language string used for the alt attribute of this image
3070 * @param bool $return Whether to print directly or return the html string
3071 * @return string|void depending on $return
3072 *
3073 */
3074function print_arrow($direction='up', $strsort=null, $return=false) {
3075 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
3076
3077 global $OUTPUT;
3078
3079 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
3080 return null;
3081 }
3082
3083 $return = null;
3084
3085 switch ($direction) {
3086 case 'up':
3087 $sortdir = 'asc';
3088 break;
3089 case 'down':
3090 $sortdir = 'desc';
3091 break;
3092 case 'move':
3093 $sortdir = 'asc';
3094 break;
3095 default:
3096 $sortdir = null;
3097 break;
3098 }
3099
3100 // Prepare language string
3101 $strsort = '';
3102 if (empty($strsort) && !empty($sortdir)) {
3103 $strsort = get_string('sort' . $sortdir, 'grades');
3104 }
3105
b5d0cafc 3106 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
f8065dd2 3107
3108 if ($return) {
3109 return $return;
3110 } else {
3111 echo $return;
3112 }
3113}
3114
3115/**
3116 * Returns a string containing a link to the user documentation.
3117 * Also contains an icon by default. Shown to teachers and admin only.
3118 *
3119 * @deprecated since Moodle 2.0
3120 *
3121 * @global object
3122 * @param string $path The page link after doc root and language, no leading slash.
3123 * @param string $text The text to be displayed for the link
3124 * @param string $iconpath The path to the icon to be displayed
3125 * @return string Either the link or an empty string
3126 */
8ae8bf8a 3127function doc_link($path='', $text='', $iconpath='ignored') {
f8065dd2 3128 global $CFG, $OUTPUT;
3129
db49be13 3130 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
f8065dd2 3131
3132 if (empty($CFG->docroot)) {
3133 return '';
3134 }
3135
8ae8bf8a 3136 return $OUTPUT->doc_link($path, $text);
f8065dd2 3137}
3138
3139/**
3140 * Prints a single paging bar to provide access to other pages (usually in a search)
3141 *
3142 * @deprecated since Moodle 2.0
3143 *
3144 * @param int $totalcount Thetotal number of entries available to be paged through
3145 * @param int $page The page you are currently viewing
3146 * @param int $perpage The number of entries that should be shown per page
3147 * @param mixed $baseurl If this is a string then it is the url which will be appended with $pagevar, an equals sign and the page number.
3148 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
3149 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
f43cdceb 3150 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
f8065dd2 3151 * @param bool $return whether to return an output string or echo now
3152 * @return bool|string depending on $result
3153 */
3154function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
3155 global $OUTPUT;
3156
929d7a83 3157 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
f8065dd2 3158
f43cdceb 3159 if (empty($nocurr)) {
929d7a83 3160 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
f43cdceb 3161 }
3162
929d7a83 3163 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
f8065dd2 3164 $pagingbar->pagevar = $pagevar;
929d7a83 3165 $output = $OUTPUT->render($pagingbar);
f8065dd2 3166
3167 if ($return) {
3168 return $output;
3169 }
3170
3171 echo $output;
3172 return true;
3173}
3174
3175/**
3176 * Print a message along with "Yes" and "No" links for the user to continue.
3177 *
3178 * @deprecated since Moodle 2.0
3179 *
3180 * @global object
3181 * @param string $message The text to display
3182 * @param string $linkyes The link to take the user to if they choose "Yes"
3183 * @param string $linkno The link to take the user to if they choose "No"
3184 * @param string $optionyes The yes option to show on the notice
3185 * @param string $optionsno The no option to show
3186 * @param string $methodyes Form action method to use if yes [post, get]
3187 * @param string $methodno Form action method to use if no [post, get]
3188 * @return void Output is echo'd
3189 */
3190function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
3191
642816a6 3192 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
f8065dd2 3193
3194 global $OUTPUT;
da65c538 3195
01a2ce80
PS
3196 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
3197 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
da65c538 3198
642816a6 3199 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
f8065dd2 3200}
3201
3202/**
3203 * Prints a scale menu (as part of an existing form) including help button
3204 * @deprecated since Moodle 2.0
3205 */
3206function print_scale_menu() {
3207 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
3208}
3209
8100c169 3210/**
3211 * Given an array of values, output the HTML for a select element with those options.
3212 *
3213 * @deprecated since Moodle 2.0
3214 *
3215 * Normally, you only need to use the first few parameters.
3216 *
3217 * @param array $options The options to offer. An array of the form
3218 * $options[{value}] = {text displayed for that option};
3219 * @param string $name the name of this form control, as in &lt;select name="..." ...
3220 * @param string $selected the option to select initially, default none.
3221 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
3222 * Set this to '' if you don't want a 'nothing is selected' option.
3223 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3224 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
3225 * @param boolean $return if false (the default) the the output is printed directly, If true, the
3226 * generated HTML is returned as a string.
3227 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
3228 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
3229 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
3230 * then a suitable one is constructed.
3231 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
3232 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
3233 * $listbox is an integer, that number is used for size instead.
3234 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
3235 * when $listbox display is enabled
3236 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
3237 * then a suitable one is constructed.
3238 * @return string|void If $return=true returns string, else echo's and returns void
3239 */
3240function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
3241 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
3242 $id='', $listbox=false, $multiple=false, $class='') {
053203a8 3243
8100c169 3244 global $OUTPUT;
4461cc60 3245 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
053203a8 3246
3247 if ($script) {
3248 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3249 }
4461cc60
PS
3250 $attributes = array();
3251 $attributes['disabled'] = $disabled ? 'disabled' : null;
3252 $attributes['tabindex'] = $tabindex ? $tabindex : null;
3253 $attributes['multiple'] = $multiple ? $multiple : null;
3254 $attributes['class'] = $class ? $class : null;
3255 $attributes['id'] = $id ? $id : null;
053203a8 3256
4461cc60 3257 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
053203a8 3258
3259 if ($return) {
3260 return $output;
3261 } else {
3262 echo $output;
8100c169 3263 }
053203a8 3264}
3265
3266/**
3267 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
3268 * Other options like choose_from_menu.
3269 *
3270 * @deprecated since Moodle 2.0
3271 *
3272 * Calls {@link choose_from_menu()} with preset arguments
3273 * @see choose_from_menu()
3274 *
3275 * @param string $name the name of this form control, as in &lt;select name="..." ...
3276 * @param string $selected the option to select initially, default none.
3277 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3278 * @param boolean $return Whether this function should return a string or output it (defaults to false)
3279 * @param boolean $disabled (defaults to false)
3280 * @param int $tabindex
3281 * @return string|void If $return=true returns string, else echo's and returns void
3282 */
28fbce88 3283function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
4461cc60 3284 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
053203a8 3285 global $OUTPUT;
3286
3287 if ($script) {
3288 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3289 }
3290
78bdac64 3291 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
053203a8 3292
3293 if ($return) {
3294 return $output;
3295 } else {
3296 echo $output;
3297 }
3298}
3299
3300/**
3301 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
3302 * including option headings with the first level.
3303 *
3304 * @deprecated since Moodle 2.0
3305 *
3306 * This function is very similar to {@link choose_from_menu_yesno()}
3307 * and {@link choose_from_menu()}
3308 *
3309 * @todo Add datatype handling to make sure $options is an array
3310 *
3311 * @param array $options An array of objects to choose from
3312 * @param string $name The XHTML field name
3313 * @param string $selected The value to select by default
3314 * @param string $nothing The label for the 'nothing is selected' option.
3315 * Defaults to get_string('choose').
3316 * @param string $script If not '', then this is added to the &lt;select> element
3317 * as an onchange handler.
3318 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
3319 * @param bool $return Whether this function should return a string or output
3320 * it (defaults to false)
3321 * @param bool $disabled Is the field disabled by default
3322 * @param int|string $tabindex Override the tabindex attribute [numeric]
3323 * @return string|void If $return=true returns string, else echo's and returns void
3324 */
3325function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
3326 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
3327
6eee65e4 3328 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
053203a8 3329 global $OUTPUT;
8100c169 3330}
053203a8 3331
c68e4098 3332/**
3333 * Prints a help button about a scale
3334 *
3335 * @deprecated since Moodle 2.0
3336 *
3337 * @global object
3338 * @param id $courseid
3339 * @param object $scale
3340 * @param boolean $return If set to true returns rather than echo's
3341 * @return string|bool Depending on value of $return
3342 */
3343function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
4bcc5118 3344 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
c68e4098 3345 global $OUTPUT;
3346
4bcc5118 3347 $output = $OUTPUT->help_icon_scale($courseid, $scale);
c68e4098 3348
3349 if ($return) {
3350 return $output;
3351 } else {
3352 echo $output;
3353 }
3354}
3355
3356
3357/**
3358 * Prints time limit value selector
3359 *
3360 * @deprecated since Moodle 2.0
3361 *
3362 * Uses {@link choose_from_menu()} to generate HTML
3363 * @see choose_from_menu()
3364 *
3365 * @global object
3366 * @param int $timelimit default
3367 * @param string $unit
3368 * @param string $name
3369 * @param boolean $return If set to true returns rather than echo's
3370 * @return string|bool Depending on value of $return
3371 */
3372function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
4461cc60 3373 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
c68e4098 3374}
3375
3376/**
3377 * Prints form items with the names $hour and $minute
3378 *
3379 * @deprecated since Moodle 2.0
3380 *
3381 * @param string $hour fieldname
3382 * @param string $minute fieldname
3383 * @param int $currenttime A default timestamp in GMT
3384 * @param int $step minute spacing
3385 * @param boolean $return If set to true returns rather than echo's
49690843 3386 * @return string|bool Depending on value of $return
c68e4098 3387 */
3388function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
4461cc60 3389 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
49690843 3390
f83b9b63
PS
3391 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
3392 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
3393
3394 $output = $hourselector . $$minuteselector;
49690843 3395
c68e4098 3396 if ($return) {
3397 return $output;
3398 } else {
3399 echo $output;
3400 }
3401}
3402
3403/**
3404 * Prints form items with the names $day, $month and $year
3405 *
3406 * @deprecated since Moodle 2.0
3407 *
3408 * @param string $day fieldname
3409 * @param string $month fieldname
3410 * @param string $year fieldname
3411 * @param int $currenttime A default timestamp in GMT
3412 * @param boolean $return If set to true returns rather than echo's
3413 * @return string|bool Depending on value of $return
3414 */
3415function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
4461cc60 3416 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
49690843 3417
f83b9b63
PS
3418 $dayselector = html_writer::select_time('days', $day, $currenttime);
3419 $monthselector = html_writer::select_time('months', $month, $currenttime);
3420 $yearselector = html_writer::select_time('years', $year, $currenttime);
49690843 3421
f83b9b63 3422 $output = $dayselector . $monthselector . $yearselector;
49690843 3423
3424 if ($return) {
3425 return $output;
3426 } else {
3427 echo $output;
3428 }
3429}
3430
3431/**
3432 * Implements a complete little form with a dropdown menu.
3433 *
3434 * @deprecated since Moodle 2.0
3435 *
3436 * When JavaScript is on selecting an option from the dropdown automatically
3437 * submits the form (while avoiding the usual acessibility problems with this appoach).
3438 * With JavaScript off, a 'Go' button is printed.
3439 *
49690843 3440 * @global object
3441 * @global object
3442 * @param string $baseurl The target URL up to the point of the variable that changes
3443 * @param array $options A list of value-label pairs for the popup list
3444 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
3445 * @param string $selected The option that is initially selected
3446 * @param string $nothing The label for the "no choice" option
3447 * @param string $help The name of a help page if help is required
3448 * @param string $helptext The name of the label for the help button
3449 * @param boolean $return Indicates whether the function should return the HTML
3450 * as a string or echo it directly to the page being rendered
3451 * @param string $targetwindow The name of the target page to open the linked page in.
3452 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
3453 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
3454 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
3455 * @param boolean $disabled If true, the menu will be displayed disabled.
3456 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
3457 * @return string|void If $return=true returns string, else echo's and returns void
3458 */
3459function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
3460 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
81aba78d 3461 global $OUTPUT, $CFG;
49690843 3462
81aba78d 3463 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
49690843 3464
49690843 3465 if (empty($options)) {
3466 return '';
3467 }
49c8c8d2 3468
81aba78d 3469 $urls = array();
beb56299 3470
81aba78d
PS
3471 foreach ($options as $value=>$label) {
3472 $url = $baseurl.$value;
3473 $url = str_replace($CFG->wwwroot, '', $url);
3474 $url = str_replace('&amp;', '&', $url);
3475 $urls[$url] = $label;
3476 if ($selected == $value) {
3477 $active = $url;
3478 }
0b139298 3479 }
0affac4d 3480
81aba78d 3481 $nothing = $nothing ? array(''=>$nothing) : null;
43a228b3 3482
81aba78d
PS
3483 $select = new url_select($urls, $active, $nothing, $formid);
3484 $select->disabled = $disabled;
49690843 3485
43a228b3 3486 $select->set_label($selectlabel);
596509e4 3487 $select->set_old_help_icon($help, $helptext);
49690843 3488
81aba78d 3489 $output = $OUTPUT->render($select);
49690843 3490
c68e4098 3491 if ($return) {
3492 return $output;
3493 } else {
3494 echo $output;
3495 }
3496}
3497
ce60cbc8 3498/**
3499 * Prints a simple button to close a window
3500 *
3501 * @deprecated since Moodle 2.0
3502 *
3503 * @global object
3504 * @param string $name Name of the window to close
3505 * @param boolean $return whether this function should return a string or output it.
3506 * @param boolean $reloadopener if true, clicking the button will also reload
3507 * the page that opend this popup window.
3508 * @return string|void if $return is true, void otherwise
3509 */
3510function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
3511 global $OUTPUT;
49c8c8d2 3512
db49be13 3513 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
ce60cbc8 3514 $output = $OUTPUT->close_window_button(get_string($name));
49c8c8d2 3515
ce60cbc8 3516 if ($return) {
3517 return $output;
3518 } else {
3519 echo $output;
3520 }
3521}
49c8c8d2 3522
3523/**
3524 * Given an array of values, creates a group of radio buttons to be part of a form
3525 *
3526 * @deprecated since Moodle 2.0
3527 *
3528 * @staticvar int $idcounter
3529 * @param array $options An array of value-label pairs for the radio group (values as keys)
3530 * @param string $name Name of the radiogroup (unique in the form)
3531 * @param string $checked The value that is already checked
3532 * @param bool $return Whether this function should return a string or output
3533 * it (defaults to false)
3534 * @return string|void If $return=true returns string, else echo's and returns void
3535 */
3536function choose_from_radio ($options, $name, $checked='', $return=false) {
4461cc60 3537 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
49c8c8d2 3538}
3539
3540/**
3541 * Display an standard html checkbox with an optional label
3542 *
3543 * @deprecated since Moodle 2.0
3544 *
3545 * @staticvar int $idcounter
3546 * @param string $name The name of the checkbox
3547 * @param string $value The valus that the checkbox will pass when checked
3548 * @param bool $checked The flag to tell the checkbox initial state
3549 * @param string $label The label to be showed near the checkbox
3550 * @param string $alt The info to be inserted in the alt tag
3551 * @param string $script If not '', then this is added to the checkbox element
3552 * as an onchange handler.
3553 * @param bool $return Whether this function should return a string or output
3554 * it (defaults to false)
3555 * @return string|void If $return=true returns string, else echo's and returns void
3556 */
916276fc 3557function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
49c8c8d2 3558
7de13103 3559 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
49c8c8d2 3560 global $OUTPUT;
6a5c71b9 3561
49c8c8d2 3562 if (!empty($script)) {
7de13103 3563 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
49c8c8d2 3564 }
3565
2f0e96e4 3566 $output = html_writer::checkbox($name, $value, $checked, $label);
49c8c8d2 3567
3568 if (empty($return)) {
3569 echo $output;
3570 } else {
3571 return $output;
3572 }
3573
3574}
6a5c71b9 3575
3576
3577/**
3578 * Display an standard html text field with an optional label
3579 *
3580 * @deprecated since Moodle 2.0
3581 *
3582 * @param string $name The name of the text field
3583 * @param string $value The value of the text field
3584 * @param string $alt The info to be inserted in the alt tag
3585 * @param int $size Sets the size attribute of the field. Defaults to 50
3586 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
3587 * @param bool $return Whether this function should return a string or output
3588 * it (defaults to false)
3589 * @return string|void If $return=true returns string, else echo's and returns void
3590 */
916276fc
PS
3591function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
3592 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
6a5c71b9 3593
b2db46ec 3594 if ($alt === '') {
916276fc
PS
3595 $alt = null;
3596 }
6a5c71b9 3597
916276fc
PS
3598 $style = "width: {$size}px;";
3599 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
3600 if ($maxlength) {
3601 $attributes['maxlength'] = $maxlength;
3602 }
6a5c71b9 3603
916276fc 3604 $output = html_writer::empty_tag('input', $attributes);
6a5c71b9 3605
3606 if (empty($return)) {
3607 echo $output;
3608 } else {
3609 return $output;
3610 }
6a5c71b9 3611}
3612
e1cc8840 3613
3614/**
3615 * Centered heading with attached help button (same title text)
3616 * and optional icon attached
3617 *
3618 * @deprecated since Moodle 2.0
3619 *
3620 * @param string $text The text to be displayed
3621 * @param string $helppage The help page to link to
3622 * @param string $module The module whose help should be linked to
3623 * @param string $icon Image to display if needed
3624 * @param bool $return If set to true output is returned rather than echoed, default false
3625 * @return string|void String if return=true nothing otherwise
3626 */
3627function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
3628
4f4eda40 3629 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
e1cc8840 3630
3631 global $OUTPUT;
3632
e1cc8840 3633 // Extract the src from $icon if it exists
3634 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
3635 $icon = $matches[1];
1028ffe1 3636 $icon = new moodle_url($icon);
4bcc5118
PS
3637 } else {
3638 $icon = '';
e1cc8840 3639 }
3640
4bcc5118 3641 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
e1cc8840 3642
3643 if ($return) {
3644 return $output;
3645 } else {
3646 echo $output;
3647 }
3648}
7527a2f0 3649
3650/**
3651 * Returns a turn edit on/off button for course in a self contained form.
3652 * Used to be an icon, but it's now a simple form button
7527a2f0 3653 * @deprecated since Moodle 2.0
7527a2f0 3654 */
3655function update_mymoodle_icon() {
3656 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
3657}
c351150f 3658
3659/**
3660 * Returns a turn edit on/off button for tag in a self contained form.
3661 * @deprecated since Moodle 2.0
cf132980 3662 * @param string $tagid The ID attribute
3663 * @return string
c351150f 3664 */
cf132980 3665function update_tag_button($tagid) {
b2db46ec 3666 global $OUTPUT;
db49be13 3667 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
a6855934 3668 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
c351150f 3669}
3670
3671
3672/**
3673 * Prints the 'update this xxx' button that appears on module pages.
3674