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