MDL-39416 do not try to get detailed perflog info before PAGE int
[moodle.git] / lib / deprecatedlib.php
blob714efb884f04e320ece7364a9fc3a8991104f146
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
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/>.
18 /**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
24 * @package core
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @deprecated
31 defined('MOODLE_INTERNAL') || die();
33 /**
34 * Unsupported session id rewriting.
35 * @deprecated
36 * @param string $buffer
38 function sid_ob_rewrite($buffer) {
39 throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
42 /**
43 * Insert or update log display entry. Entry may already exist.
44 * $module, $action must be unique
45 * @deprecated
47 * @param string $module
48 * @param string $action
49 * @param string $mtable
50 * @param string $field
51 * @return void
54 function update_log_display_entry($module, $action, $mtable, $field) {
55 global $DB;
57 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
60 /**
61 * Given some text in HTML format, this function will pass it
62 * through any filters that have been configured for this context.
64 * @deprecated use the text formatting in a standard way instead,
65 * this was abused mostly for embedding of attachments
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.
71 function filter_text($text, $courseid = NULL) {
72 global $CFG, $COURSE;
74 if (!$courseid) {
75 $courseid = $COURSE->id;
78 if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
79 return $text;
82 return filter_manager::instance()->filter_text($text, $context);
85 /**
86 * This function indicates that current page requires the https
87 * when $CFG->loginhttps enabled.
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
93 function httpsrequired() {
94 global $PAGE;
95 $PAGE->https_required();
98 /**
99 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
101 * @deprecated use moodle_url factory methods instead
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
108 function get_file_url($path, $options=null, $type='coursefile') {
109 global $CFG;
111 $path = str_replace('//', '/', $path);
112 $path = trim($path, '/'); // no leading and trailing slashes
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";
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);
138 $path = implode('/', $parts);
139 $ffurl = $url.'/'.$path;
140 $separator = '?';
141 } else {
142 $path = rawurlencode('/'.$path);
143 $ffurl = $url.'?file='.$path;
144 $separator = '&amp;';
147 if ($options) {
148 foreach ($options as $name=>$value) {
149 $ffurl = $ffurl.$separator.$name.'='.$value;
150 $separator = '&amp;';
154 return $ffurl;
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
162 function print_file_upload_error($filearray = '', $returnerror = false) {
163 throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
167 * Handy function for resolving file conflicts
168 * @deprecated removed - use new file api
171 function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
172 throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
176 * Checks a file name for any conflicts
177 * @deprecated removed - use new file api
179 function check_potential_filename($destination,$filename,$files) {
180 throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
184 * This function prints out a number of upload form elements.
185 * @deprecated removed - use new file api
187 function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
188 throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
192 * Return the authentication plugin title
194 * @param string $authtype plugin type
195 * @return string
197 function 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}");
205 * Enrol someone without using the default role in a course
206 * @deprecated
208 function enrol_into_course($course, $user, $enrol) {
209 error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
213 * Returns a role object that is the default role for new enrolments in a given course
215 * @deprecated
216 * @param object $course
217 * @return object returns a role or NULL if none set
219 function get_default_course_role($course) {
220 debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
222 $student = get_archetype_roles('student');
223 $student = reset($student);
225 return $student;
229 * Extremely slow enrolled courses query.
230 * @deprecated
232 function 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()!');
237 * Was returning list of translations, use new string_manager instead
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
244 function get_list_of_languages($refreshcache=false, $returnall=false) {
245 debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
246 if ($refreshcache) {
247 get_string_manager()->reset_caches();
249 return get_string_manager()->get_list_of_translations($returnall);
253 * Returns a list of currencies in the current language
254 * @deprecated
255 * @return array
257 function 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();
263 * Returns a list of all enabled country names in the current translation
264 * @deprecated
265 * @return array two-letter country code => translated name.
267 function 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);
273 * @deprecated
275 function isteacher() {
276 error('Function isteacher() was removed, please use capabilities instead!');
280 * @deprecated
282 function isteacherinanycourse() {
283 throw new coding_Exception('Function isteacherinanycourse() was removed, please use capabilities instead!');
287 * @deprecated
289 function get_guest() {
290 throw new coding_Exception('Function get_guest() was removed, please use capabilities instead!');
294 * @deprecated
296 function isguest() {
297 throw new coding_Exception('Function isguest() was removed, please use capabilities instead!');
301 * @deprecated
303 function get_teacher() {
304 throw new coding_Exception('Function get_teacher() was removed, please use capabilities instead!');
308 * Return all course participant for a given course
310 * @deprecated
311 * @param integer $courseid
312 * @return array of user
314 function get_course_participants($courseid) {
315 return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid));
319 * Return true if the user is a participant for a given course
321 * @deprecated
322 * @param integer $userid
323 * @param integer $courseid
324 * @return boolean
326 function is_course_participant($userid, $courseid) {
327 return is_enrolled(get_context_instance(CONTEXT_COURSE, $courseid), $userid);
331 * Searches logs to find all enrolments since a certain date
333 * used to print recent activity
335 * @global object
336 * @uses CONTEXT_COURSE
337 * @param int $courseid The course in question.
338 * @param int $timestart The date to check forward of
339 * @return object|false {@link $USER} records or false if error.
341 function get_recent_enrolments($courseid, $timestart) {
342 global $DB;
344 $context = get_context_instance(CONTEXT_COURSE, $courseid);
346 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
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'
352 AND ".$DB->sql_cast_char2int('l.info')." = u.id
353 AND u.id = ra.userid
354 AND ra.contextid ".get_related_contexts_string($context)."
355 GROUP BY u.id, u.firstname, u.lastname
356 ORDER BY MAX(l.time) ASC";
357 $params = array($timestart, $courseid);
358 return $DB->get_records_sql($sql, $params);
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...
367 * Use context_instance_preload() instead.
369 * @deprecated since 2.0
370 * @param object $rec
371 * @return object
373 function make_context_subobj($rec) {
374 throw new coding_Exception('make_context_subobj() was removed, use new context preloading');
378 * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
380 * Use context_instance_preload() instead.
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.
389 function is_context_subobj_valid($rec, $contextlevel) {
390 throw new coding_Exception('is_context_subobj_valid() was removed, use new context preloading');
394 * Ensure that $rec->context is present and correct before you continue
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.
400 * Use context_instance_preload() instead.
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.
406 function ensure_context_subobj_present(&$rec, $contextlevel) {
407 throw new coding_Exception('ensure_context_subobj_present() was removed, use new context preloading');
410 ########### FROM weblib.php ##########################################################################
414 * Print a message in a standard themed box.
415 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
416 * parameters remain. If possible, $align, $width and $color should not be defined at all.
417 * Preferably just use print_box() in weblib.php
419 * @deprecated
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
430 function 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);
433 $output .= $message;
434 $output .= print_simple_box_end(true);
436 if ($return) {
437 return $output;
438 } else {
439 echo $output;
446 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
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
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
459 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
460 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
462 $output = '';
464 $divclasses = 'box '.$class.' '.$class.'content';
465 $divstyles = '';
467 if ($align) {
468 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
470 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
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
480 } else {
481 $divstyles .= ' width:'.$width.';'; // Last resort
484 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
485 $divstyles .= ' background:'.$color.';';
487 if ($divstyles) {
488 $divstyles = ' style="'.$divstyles.'"';
491 if ($id) {
492 $id = ' id="'.$id.'"';
495 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
497 if ($return) {
498 return $output;
499 } else {
500 echo $output;
506 * Print the end portion of a standard themed box.
507 * Preferably just use print_box_end() in weblib.php
509 * @param boolean $return return as string or just print it
510 * @return string|void Depending on $return
512 function print_simple_box_end($return=false) {
513 $output = '</div>';
514 if ($return) {
515 return $output;
516 } else {
517 echo $output;
522 * Given some text this function converted any URLs it found into HTML links
524 * This core function has been replaced with filter_urltolink since Moodle 2.0
526 * @param string $text Passed in by reference. The string to be searched for urls.
528 function convert_urls_into_links($text) {
529 debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
533 * Used to be called from help.php to inject a list of smilies into the
534 * emoticons help file.
536 * @return string HTML
538 function 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 '';
544 * Was used to replace all known smileys in the text with image equivalents
546 * This core function has been replaced with filter_emoticon since Moodle 2.0
548 function replace_smilies(&$text) {
549 debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
553 * deprecated - use clean_param($string, PARAM_FILE); instead
554 * Check for bad characters ?
556 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
558 * @param string $string ?
559 * @param int $allowdots ?
560 * @return bool
562 function detect_munged_arguments($string, $allowdots=1) {
563 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
564 return true;
566 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
567 return true;
569 if (empty($string) or $string == '/') {
570 return true;
573 return false;
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.
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
588 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
589 global $CFG;
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
597 //If no file, error
598 if (empty($zipfilename)) {
599 return false;
602 //If no extension, error
603 if (empty($extension)) {
604 return false;
607 //Clear $zipfile
608 $zipfile = cleardoubleslashes($zipfile);
610 //Check zipfile exists
611 if (!file_exists($zipfile)) {
612 return false;
615 //If no destination, passed let's go with the same directory
616 if (empty($destination)) {
617 $destination = $zippath;
620 //Clear $destination
621 $destpath = rtrim(cleardoubleslashes($destination), "/");
623 //Check destination path exists
624 if (!is_dir($destpath)) {
625 return false;
628 $packer = get_file_packer('application/zip');
630 $result = $packer->extract_to_pathname($zipfile, $destpath);
632 if ($result === false) {
633 return false;
636 foreach ($result as $status) {
637 if ($status !== true) {
638 return false;
642 return true;
646 * Zip an array of files/dirs to a destination zip file
647 * Both parameters must be FULL paths to the files/dirs
649 * @global object
650 * @param array $originalfiles Files to zip
651 * @param string $destination The destination path
652 * @return bool Outcome
654 function zip_files ($originalfiles, $destination) {
655 global $CFG;
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
663 //If no file, error
664 if (empty($destfilename)) {
665 return false;
668 //If no extension, add it
669 if (empty($extension)) {
670 $extension = 'zip';
671 $destfilename = $destfilename.'.'.$extension;
674 //Check destination path exists
675 if (!is_dir($destpath)) {
676 return false;
679 //Check destination path is writable. TODO!!
681 //Clean destination filename
682 $destfilename = clean_filename($destfilename);
684 //Now check and prepare every file
685 $files = array();
686 $origpath = NULL;
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)), "/");
695 //See if the file is readable
696 if (!is_readable($tempfile)) { //Is readable
697 continue;
699 //See if the file/dir is in the same directory than the rest
700 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
701 continue;
703 //Add the file to the array
704 $files[] = $tempfile;
707 $zipfiles = array();
708 $start = strlen($origpath)+1;
709 foreach($files as $file) {
710 $zipfiles[substr($file, $start)] = $file;
713 $packer = get_file_packer('application/zip');
715 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
718 /////////////////////////////////////////////////////////////
719 /// Old functions not used anymore - candidates for removal
720 /////////////////////////////////////////////////////////////
723 /** various deprecated groups function **/
727 * Get the IDs for the user's groups in the given course.
729 * @global object
730 * @param int $courseid The course being examined - the 'course' table id field.
731 * @return array|bool An _array_ of groupids, or false
732 * (Was return $groupids[0] - consequences!)
734 function 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;
745 * Returns the current group mode for a given course or activity module
747 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
749 * @param object $course Course Object
750 * @param object $cm Course Manager Object
751 * @return mixed $course->groupmode
753 function groupmode($course, $cm=null) {
755 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
756 return $cm->groupmode;
758 return $course->groupmode;
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.
767 * @global object
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
773 function set_current_group($courseid, $groupid) {
774 global $SESSION;
775 return $SESSION->currentgroup[$courseid] = $groupid;
780 * Gets the current group - either from the session variable or from the database.
782 * @global object
783 * @param int $courseid The course being examined - relates to id field in
784 * 'course' table.
785 * @param bool $full If true, the return value is a full record object.
786 * If false, just the id of the record.
787 * @return int|bool
789 function get_current_group($courseid, $full = false) {
790 global $SESSION;
792 if (isset($SESSION->currentgroup[$courseid])) {
793 if ($full) {
794 return groups_get_group($SESSION->currentgroup[$courseid]);
795 } else {
796 return $SESSION->currentgroup[$courseid];
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;
811 if ($full) {
812 return false;
813 } else {
814 return 0;
820 * Inndicates fatal error. This function was originally printing the
821 * error message directly, since 2.0 it is throwing exception instead.
822 * The error printing is handled in default exception handler.
824 * Old method, don't call directly in new code - use print_error instead.
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.
828 * @return void, always throws moodle_exception
830 function error($message, $link='') {
831 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
835 //////////////////////////
836 /// removed functions ////
837 //////////////////////////
840 * @deprecated
841 * @param mixed $name
842 * @param mixed $editorhidebuttons
843 * @param mixed $id
844 * @return void Throws an error and does nothing
846 function use_html_editor($name='', $editorhidebuttons='', $id='') {
847 error('use_html_editor() not available anymore');
851 * The old method that was used to include JavaScript libraries.
852 * Please use $PAGE->requires->js_module() instead.
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:
856 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
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').
861 function require_js($lib) {
862 global $CFG, $PAGE;
863 // Add the lib to the list of libs to be loaded, if it isn't already
864 // in the list.
865 if (is_array($lib)) {
866 foreach($lib as $singlelib) {
867 require_js($singlelib);
869 return;
872 debugging('Call to deprecated function require_js. Please use $PAGE->requires->js_module() instead.', DEBUG_DEVELOPER);
874 if (strpos($lib, 'yui_') === 0) {
875 $PAGE->requires->yui2_lib(substr($lib, 4));
876 } else {
877 if ($PAGE->requires->is_head_done()) {
878 echo html_writer::script('', $lib);
879 } else {
880 $PAGE->requires->js(new moodle_url($lib));
886 * Makes an upload directory for a particular module.
888 * This function has been deprecated by the file API changes in Moodle 2.0.
890 * @deprecated
891 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
892 * @return string|false Returns full path to directory if successful, false if not
894 function make_mod_upload_directory($courseid) {
895 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
899 * Used to be used for setting up the theme. No longer used by core code, and
900 * should not have been used elsewhere.
902 * The theme is now automatically initialised before it is first used. If you really need
903 * to force this to happen, just reference $PAGE->theme.
905 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
906 * However, I can't think of any valid reason to do that outside the theme selector UI.
908 * @deprecated
909 * @param string $theme The theme to use defaults to current theme
910 * @param array $params An array of parameters to use
912 function theme_setup($theme = '', $params=NULL) {
913 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
914 'The current theme gets initialised automatically before it is first used.');
918 * @deprecated use $PAGE->theme->name instead.
919 * @return string the name of the current theme.
921 function current_theme() {
922 global $PAGE;
923 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
924 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
925 return $PAGE->theme->name;
929 * @todo Remove this deprecated function when no longer used
930 * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
932 * @param string $getid used to return $PAGE->pagetype.
933 * @param string $getclass used to return $PAGE->legacyclass.
935 function page_id_and_class(&$getid, &$getclass) {
936 global $PAGE;
937 debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
938 $getid = $PAGE->pagetype;
939 $getclass = $PAGE->legacyclass;
943 * Prints some red text using echo
945 * @deprecated
946 * @param string $error The text to be displayed in red
948 function formerr($error) {
949 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
950 global $OUTPUT;
951 echo $OUTPUT->error_text($error);
955 * Return the markup for the destination of the 'Skip to main content' links.
956 * Accessibility improvement for keyboard-only users.
958 * Used in course formats, /index.php and /course/index.php
960 * @deprecated use $OUTPUT->skip_link_target() in instead.
961 * @return string HTML element.
963 function skip_main_destination() {
964 global $OUTPUT;
965 return $OUTPUT->skip_link_target();
969 * Prints a string in a specified size (retained for backward compatibility)
971 * @deprecated
972 * @param string $text The text to be displayed
973 * @param int $size The size to set the font for text display.
974 * @param bool $return If set to true output is returned rather than echoed Default false
975 * @return string|void String if return is true
977 function print_headline($text, $size=2, $return=false) {
978 global $OUTPUT;
979 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
980 $output = $OUTPUT->heading($text, $size);
981 if ($return) {
982 return $output;
983 } else {
984 echo $output;
989 * Prints text in a format for use in headings.
991 * @deprecated
992 * @param string $text The text to be displayed
993 * @param string $deprecated No longer used. (Use to do alignment.)
994 * @param int $size The size to set the font for text display.
995 * @param string $class
996 * @param bool $return If set to true output is returned rather than echoed, default false
997 * @param string $id The id to use in the element
998 * @return string|void String if return=true nothing otherwise
1000 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
1001 global $OUTPUT;
1002 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
1003 if (!empty($deprecated)) {
1004 debugging('Use of deprecated align attribute of print_heading. ' .
1005 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
1007 $output = $OUTPUT->heading($text, $size, $class, $id);
1008 if ($return) {
1009 return $output;
1010 } else {
1011 echo $output;
1016 * Output a standard heading block
1018 * @deprecated
1019 * @param string $heading The text to write into the heading
1020 * @param string $class An additional Class Attr to use for the heading
1021 * @param bool $return If set to true output is returned rather than echoed, default false
1022 * @return string|void HTML String if return=true nothing otherwise
1024 function print_heading_block($heading, $class='', $return=false) {
1025 global $OUTPUT;
1026 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
1027 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
1028 if ($return) {
1029 return $output;
1030 } else {
1031 echo $output;
1036 * Print a message in a standard themed box.
1037 * Replaces print_simple_box (see deprecatedlib.php)
1039 * @deprecated
1040 * @param string $message, the content of the box
1041 * @param string $classes, space-separated class names.
1042 * @param string $ids
1043 * @param boolean $return, return as string or just print it
1044 * @return string|void mixed string or void
1046 function print_box($message, $classes='generalbox', $ids='', $return=false) {
1047 global $OUTPUT;
1048 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
1049 $output = $OUTPUT->box($message, $classes, $ids);
1050 if ($return) {
1051 return $output;
1052 } else {
1053 echo $output;
1058 * Starts a box using divs
1059 * Replaces print_simple_box_start (see deprecatedlib.php)
1061 * @deprecated
1062 * @param string $classes, space-separated class names.
1063 * @param string $ids
1064 * @param boolean $return, return as string or just print it
1065 * @return string|void string or void
1067 function print_box_start($classes='generalbox', $ids='', $return=false) {
1068 global $OUTPUT;
1069 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
1070 $output = $OUTPUT->box_start($classes, $ids);
1071 if ($return) {
1072 return $output;
1073 } else {
1074 echo $output;
1079 * Simple function to end a box (see above)
1080 * Replaces print_simple_box_end (see deprecatedlib.php)
1082 * @deprecated
1083 * @param boolean $return, return as string or just print it
1084 * @return string|void Depending on value of return
1086 function print_box_end($return=false) {
1087 global $OUTPUT;
1088 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
1089 $output = $OUTPUT->box_end();
1090 if ($return) {
1091 return $output;
1092 } else {
1093 echo $output;
1098 * Print a message in a standard themed container.
1100 * @deprecated
1101 * @param string $message, the content of the container
1102 * @param boolean $clearfix clear both sides
1103 * @param string $classes, space-separated class names.
1104 * @param string $idbase
1105 * @param boolean $return, return as string or just print it
1106 * @return string|void Depending on value of $return
1108 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1109 global $OUTPUT;
1110 if ($clearfix) {
1111 $classes .= ' clearfix';
1113 $output = $OUTPUT->container($message, $classes, $idbase);
1114 if ($return) {
1115 return $output;
1116 } else {
1117 echo $output;
1122 * Starts a container using divs
1124 * @deprecated
1125 * @param boolean $clearfix clear both sides
1126 * @param string $classes, space-separated class names.
1127 * @param string $idbase
1128 * @param boolean $return, return as string or just print it
1129 * @return string|void Based on value of $return
1131 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1132 global $OUTPUT;
1133 if ($clearfix) {
1134 $classes .= ' clearfix';
1136 $output = $OUTPUT->container_start($classes, $idbase);
1137 if ($return) {
1138 return $output;
1139 } else {
1140 echo $output;
1145 * Deprecated, now handled automatically in themes
1147 function check_theme_arrows() {
1148 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
1152 * Simple function to end a container (see above)
1154 * @deprecated
1155 * @param boolean $return, return as string or just print it
1156 * @return string|void Based on $return
1158 function print_container_end($return=false) {
1159 global $OUTPUT;
1160 $output = $OUTPUT->container_end();
1161 if ($return) {
1162 return $output;
1163 } else {
1164 echo $output;
1169 * Print a bold message in an optional color.
1171 * @deprecated use $OUTPUT->notification instead.
1172 * @param string $message The message to print out
1173 * @param string $style Optional style to display message text in
1174 * @param string $align Alignment option
1175 * @param bool $return whether to return an output string or echo now
1176 * @return string|bool Depending on $result
1178 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1179 global $OUTPUT;
1181 if ($classes == 'green') {
1182 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1183 $classes = 'notifysuccess'; // Backward compatible with old color system
1186 $output = $OUTPUT->notification($message, $classes);
1187 if ($return) {
1188 return $output;
1189 } else {
1190 echo $output;
1195 * Print a continue button that goes to a particular URL.
1197 * @deprecated since Moodle 2.0
1199 * @param string $link The url to create a link to.
1200 * @param bool $return If set to true output is returned rather than echoed, default false
1201 * @return string|void HTML String if return=true nothing otherwise
1203 function print_continue($link, $return = false) {
1204 global $CFG, $OUTPUT;
1206 if ($link == '') {
1207 if (!empty($_SERVER['HTTP_REFERER'])) {
1208 $link = $_SERVER['HTTP_REFERER'];
1209 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1210 } else {
1211 $link = $CFG->wwwroot .'/';
1215 $output = $OUTPUT->continue_button($link);
1216 if ($return) {
1217 return $output;
1218 } else {
1219 echo $output;
1224 * Print a standard header
1226 * @param string $title Appears at the top of the window
1227 * @param string $heading Appears at the top of the page
1228 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1229 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1230 * @param string $meta Meta tags to be added to the header
1231 * @param boolean $cache Should this page be cacheable?
1232 * @param string $button HTML code for a button (usually for module editing)
1233 * @param string $menu HTML code for a popup menu
1234 * @param boolean $usexml use XML for this page
1235 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1236 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1237 * @return string|void If return=true then string else void
1239 function print_header($title='', $heading='', $navigation='', $focus='',
1240 $meta='', $cache=true, $button='&nbsp;', $menu=null,
1241 $usexml=false, $bodytags='', $return=false) {
1242 global $PAGE, $OUTPUT;
1244 $PAGE->set_title($title);
1245 $PAGE->set_heading($heading);
1246 $PAGE->set_cacheable($cache);
1247 if ($button == '') {
1248 $button = '&nbsp;';
1250 $PAGE->set_button($button);
1251 $PAGE->set_headingmenu($menu);
1253 // TODO $menu
1255 if ($meta) {
1256 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1257 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1259 if ($usexml) {
1260 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1262 if ($bodytags) {
1263 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1266 $output = $OUTPUT->header();
1268 if ($return) {
1269 return $output;
1270 } else {
1271 echo $output;
1276 * This version of print_header is simpler because the course name does not have to be
1277 * provided explicitly in the strings. It can be used on the site page as in courses
1278 * Eventually all print_header could be replaced by print_header_simple
1280 * @deprecated since Moodle 2.0
1281 * @param string $title Appears at the top of the window
1282 * @param string $heading Appears at the top of the page
1283 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1284 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1285 * @param string $meta Meta tags to be added to the header
1286 * @param boolean $cache Should this page be cacheable?
1287 * @param string $button HTML code for a button (usually for module editing)
1288 * @param string $menu HTML code for a popup menu
1289 * @param boolean $usexml use XML for this page
1290 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1291 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1292 * @return string|void If $return=true the return string else nothing
1294 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1295 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1297 global $COURSE, $CFG, $PAGE, $OUTPUT;
1299 if ($meta) {
1300 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1301 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1303 if ($usexml) {
1304 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1306 if ($bodytags) {
1307 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1310 $PAGE->set_title($title);
1311 $PAGE->set_heading($heading);
1312 $PAGE->set_cacheable(true);
1313 $PAGE->set_button($button);
1315 $output = $OUTPUT->header();
1317 if ($return) {
1318 return $output;
1319 } else {
1320 echo $output;
1324 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
1325 global $PAGE, $OUTPUT;
1326 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
1327 // TODO check arguments.
1328 if (is_string($course)) {
1329 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
1330 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
1331 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
1332 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
1334 if (!is_null($usercourse)) {
1335 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
1336 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
1338 $output = $OUTPUT->footer();
1339 if ($return) {
1340 return $output;
1341 } else {
1342 echo $output;
1347 * Returns text to be displayed to the user which reflects their login status
1349 * @global object
1350 * @global object
1351 * @global object
1352 * @global object
1353 * @uses CONTEXT_COURSE
1354 * @param course $course {@link $COURSE} object containing course information
1355 * @param user $user {@link $USER} object containing user information
1356 * @return string HTML
1358 function user_login_string($course='ignored', $user='ignored') {
1359 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
1360 return '';
1364 * Prints a nice side block with an optional header. The content can either
1365 * be a block of HTML or a list of text with optional icons.
1367 * @todo Finish documenting this function. Show example of various attributes, etc.
1369 * @static int $block_id Increments for each call to the function
1370 * @param string $heading HTML for the heading. Can include full HTML or just
1371 * plain text - plain text will automatically be enclosed in the appropriate
1372 * heading tags.
1373 * @param string $content HTML for the content
1374 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1375 * @param array $icons optional icons for the things in $list.
1376 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
1377 * @param array $attributes an array of attribute => value pairs that are put on the
1378 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1379 * already a class, class='block' is used.
1380 * @param string $title Plain text title, as embedded in the $heading.
1381 * @deprecated
1383 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1384 global $OUTPUT;
1386 // We don't use $heading, becuse it often contains HTML that we don't want.
1387 // However, sometimes $title is not set, but $heading is.
1388 if (empty($title)) {
1389 $title = strip_tags($heading);
1392 // Render list contents to HTML if required.
1393 if (empty($content) && $list) {
1394 $content = $OUTPUT->list_block_contents($icons, $list);
1397 $bc = new block_contents();
1398 $bc->content = $content;
1399 $bc->footer = $footer;
1400 $bc->title = $title;
1402 if (isset($attributes['id'])) {
1403 $bc->id = $attributes['id'];
1404 unset($attributes['id']);
1406 $bc->attributes = $attributes;
1408 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1412 * Starts a nice side block with an optional header.
1414 * @todo Finish documenting this function
1416 * @global object
1417 * @global object
1418 * @param string $heading HTML for the heading. Can include full HTML or just
1419 * plain text - plain text will automatically be enclosed in the appropriate
1420 * heading tags.
1421 * @param array $attributes HTML attributes to apply if possible
1422 * @deprecated
1424 function print_side_block_start($heading='', $attributes = array()) {
1425 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
1429 * Print table ending tags for a side block box.
1431 * @global object
1432 * @global object
1433 * @param array $attributes HTML attributes to apply if possible [id]
1434 * @param string $title
1435 * @deprecated
1437 function print_side_block_end($attributes = array(), $title='') {
1438 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
1442 * This was used by old code to see whether a block region had anything in it,
1443 * and hence wether that region should be printed.
1445 * We don't ever want old code to print blocks, so we now always return false.
1446 * The function only exists to avoid fatal errors in old code.
1448 * @deprecated since Moodle 2.0. always returns false.
1450 * @param object $blockmanager
1451 * @param string $region
1452 * @return bool
1454 function blocks_have_content(&$blockmanager, $region) {
1455 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
1456 return false;
1460 * This was used by old code to print the blocks in a region.
1462 * We don't ever want old code to print blocks, so this is now a no-op.
1463 * The function only exists to avoid fatal errors in old code.
1465 * @deprecated since Moodle 2.0. does nothing.
1467 * @param object $page
1468 * @param object $blockmanager
1469 * @param string $region
1471 function blocks_print_group($page, $blockmanager, $region) {
1472 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1476 * This used to be the old entry point for anyone that wants to use blocks.
1477 * Since we don't want people people dealing with blocks this way any more,
1478 * just return a suitable empty array.
1480 * @deprecated since Moodle 2.0.
1482 * @param object $page
1483 * @return array
1485 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
1486 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1487 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
1491 * This iterates over an array of blocks and calculates the preferred width
1492 * Parameter passed by reference for speed; it's not modified.
1494 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
1496 * @param mixed $instances
1498 function blocks_preferred_width($instances) {
1499 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1500 $width = 210;
1504 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1506 * @param object $page The page object
1507 * @param object $blockmanager The block manager object
1508 * @param string $blockaction One of [config, add, delete]
1509 * @param int|object $instanceorid The instance id or a block_instance object
1510 * @param bool $pinned
1511 * @param bool $redirect To redirect or not to that is the question but you should stick with true
1513 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
1514 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.');
1518 * You can use this to get the blocks to respond to URL actions without much hassle
1520 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
1522 * @param object $PAGE
1523 * @param object $blockmanager
1524 * @param bool $pinned
1526 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
1527 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
1531 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
1532 * in order to reduce code repetition.
1534 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1536 * @param $instance
1537 * @param $newpos
1538 * @param string|int $newweight
1539 * @param bool $pinned
1541 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
1542 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.');
1547 * Moves a block to the new position (column) and weight (sort order).
1549 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1551 * @param object $instance The block instance to be moved.
1552 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
1553 * @param string $destweight The destination sort order. If NULL, we add to the end
1554 * of the destination column.
1555 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
1556 * to a new position withing the pinned list. Likewise, we
1557 * can only moved non-pinned blocks to a new position within
1558 * the non-pinned list.
1559 * @return boolean success or failure
1561 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
1562 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.');
1566 * Print a nicely formatted table.
1568 * @deprecated since Moodle 2.0
1570 * @param array $table is an object with several properties.
1572 function print_table($table, $return=false) {
1573 global $OUTPUT;
1574 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
1575 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
1576 $newtable = new html_table();
1577 foreach ($table as $property => $value) {
1578 if (property_exists($newtable, $property)) {
1579 $newtable->{$property} = $value;
1582 if (isset($table->class)) {
1583 $newtable->attributes['class'] = $table->class;
1585 if (isset($table->rowclass) && is_array($table->rowclass)) {
1586 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
1587 $newtable->rowclasses = $table->rowclass;
1589 $output = html_writer::table($newtable);
1590 if ($return) {
1591 return $output;
1592 } else {
1593 echo $output;
1594 return true;
1599 * Creates and displays (or returns) a link to a popup window
1601 * @deprecated since Moodle 2.0
1603 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1604 * @param string $name Name to be assigned to the popup window (this is used by
1605 * client-side scripts to "talk" to the popup window)
1606 * @param string $linkname Text to be displayed as web link
1607 * @param int $height Height to assign to popup window
1608 * @param int $width Height to assign to popup window
1609 * @param string $title Text to be displayed as popup page title
1610 * @param string $options List of additional options for popup window
1611 * @param bool $return If true, return as a string, otherwise print
1612 * @param string $id id added to the element
1613 * @param string $class class added to the element
1614 * @return string html code to display a link to a popup window.
1616 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
1617 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');
1619 return html_writer::link($url, $name);
1623 * Creates and displays (or returns) a buttons to a popup window.
1625 * @deprecated since Moodle 2.0
1627 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1628 * @param string $name Name to be assigned to the popup window (this is used by
1629 * client-side scripts to "talk" to the popup window)
1630 * @param string $linkname Text to be displayed as web link
1631 * @param int $height Height to assign to popup window
1632 * @param int $width Height to assign to popup window
1633 * @param string $title Text to be displayed as popup page title
1634 * @param string $options List of additional options for popup window
1635 * @param bool $return If true, return as a string, otherwise print
1636 * @param string $id id added to the element
1637 * @param string $class class added to the element
1638 * @return string html code to display a link to a popup window.
1640 function button_to_popup_window ($url, $name=null, $linkname=null,
1641 $height=400, $width=500, $title=null, $options=null, $return=false,
1642 $id=null, $class=null) {
1643 global $OUTPUT;
1645 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1647 if ($options == 'none') {
1648 $options = null;
1651 if (empty($linkname)) {
1652 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
1655 // Create a single_button object
1656 $form = new single_button($url, $linkname, 'post');
1657 $form->button->title = $title;
1658 $form->button->id = $id;
1660 // Parse the $options string
1661 $popupparams = array();
1662 if (!empty($options)) {
1663 $optionsarray = explode(',', $options);
1664 foreach ($optionsarray as $option) {
1665 if (strstr($option, '=')) {
1666 $parts = explode('=', $option);
1667 if ($parts[1] == '0') {
1668 $popupparams[$parts[0]] = false;
1669 } else {
1670 $popupparams[$parts[0]] = $parts[1];
1672 } else {
1673 $popupparams[$option] = true;
1678 if (!empty($height)) {
1679 $popupparams['height'] = $height;
1681 if (!empty($width)) {
1682 $popupparams['width'] = $width;
1685 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
1686 $output = $OUTPUT->render($form);
1688 if ($return) {
1689 return $output;
1690 } else {
1691 echo $output;
1696 * Print a self contained form with a single submit button.
1698 * @deprecated since Moodle 2.0
1700 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
1701 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
1702 * @param string $label the caption that appears on the button.
1703 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
1704 * @param string $notusedanymore no longer used.
1705 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
1706 * @param string $tooltip a tooltip to add to the button as a title attribute.
1707 * @param boolean $disabled if true, the button will be disabled.
1708 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
1709 * @param string $formid The id attribute to use for the form
1710 * @return string|void Depending on the $return paramter.
1712 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
1713 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
1714 global $OUTPUT;
1716 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1718 // Cast $options to array
1719 $options = (array) $options;
1721 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
1723 if ($jsconfirmmessage) {
1724 $button->button->add_confirm_action($jsconfirmmessage);
1727 $output = $OUTPUT->render($button);
1729 if ($return) {
1730 return $output;
1731 } else {
1732 echo $output;
1737 * Print a spacer image with the option of including a line break.
1739 * @deprecated since Moodle 2.0
1741 * @global object
1742 * @param int $height The height in pixels to make the spacer
1743 * @param int $width The width in pixels to make the spacer
1744 * @param boolean $br If set to true a BR is written after the spacer
1746 function print_spacer($height=1, $width=1, $br=true, $return=false) {
1747 global $CFG, $OUTPUT;
1749 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
1751 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
1753 if ($return) {
1754 return $output;
1755 } else {
1756 echo $output;
1761 * Given the path to a picture file in a course, or a URL,
1762 * this function includes the picture in the page.
1764 * @deprecated since Moodle 2.0
1766 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
1767 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
1771 * Print the specified user's avatar.
1773 * @deprecated since Moodle 2.0
1775 * @global object
1776 * @global object
1777 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
1778 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
1779 * if at all possible, particularly for reports. It is very bad for performance.
1780 * @param int $courseid The course id. Used when constructing the link to the user's profile.
1781 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
1782 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
1783 * @param boolean $return If false print picture to current page, otherwise return the output as string
1784 * @param boolean $link enclose printed image in a link the user's profile (default true).
1785 * @param string $target link target attribute. Makes the profile open in a popup window.
1786 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
1787 * decorative images, or where the username will be printed anyway.)
1788 * @return string|void String or nothing, depending on $return.
1790 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
1791 global $OUTPUT;
1793 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
1795 if (!is_object($user)) {
1796 $userid = $user;
1797 $user = new stdClass();
1798 $user->id = $userid;
1801 if (empty($user->picture) and $picture) {
1802 $user->picture = $picture;
1805 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
1807 $output = $OUTPUT->user_picture($user, $options);
1809 if ($return) {
1810 return $output;
1811 } else {
1812 echo $output;
1817 * Print a png image.
1819 * @deprecated since Moodle 2.0: no replacement
1822 function print_png() {
1823 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
1828 * Prints a basic textarea field.
1830 * @deprecated since Moodle 2.0
1832 * When using this function, you should
1834 * @global object
1835 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
1836 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1837 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1838 * @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.
1839 * @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.
1840 * @param string $name Name to use for the textarea element.
1841 * @param string $value Initial content to display in the textarea.
1842 * @param int $obsolete deprecated
1843 * @param bool $return If false, will output string. If true, will return string value.
1844 * @param string $id CSS ID to add to the textarea element.
1845 * @return string|void depending on the value of $return
1847 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1848 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1849 /// However, you can set them to zero to override the mincols and minrows values below.
1851 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1852 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1854 global $CFG;
1856 $mincols = 65;
1857 $minrows = 10;
1858 $str = '';
1860 if ($id === '') {
1861 $id = 'edit-'.$name;
1864 if ($usehtmleditor) {
1865 if ($height && ($rows < $minrows)) {
1866 $rows = $minrows;
1868 if ($width && ($cols < $mincols)) {
1869 $cols = $mincols;
1873 if ($usehtmleditor) {
1874 editors_head_setup();
1875 $editor = editors_get_preferred_editor(FORMAT_HTML);
1876 $editor->use_editor($id, array('legacy'=>true));
1877 } else {
1878 $editorclass = '';
1881 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
1882 if ($usehtmleditor) {
1883 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1884 } else {
1885 $str .= s($value);
1887 $str .= '</textarea>'."\n";
1889 if ($return) {
1890 return $str;
1892 echo $str;
1897 * Print a help button.
1899 * @deprecated since Moodle 2.0
1901 * @param string $page The keyword that defines a help page
1902 * @param string $title The title of links, rollover tips, alt tags etc
1903 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
1904 * @param string $module Which module is the page defined in
1905 * @param mixed $image Use a help image for the link? (true/false/"both")
1906 * @param boolean $linktext If true, display the title next to the help icon.
1907 * @param string $text If defined then this text is used in the page, and
1908 * the $page variable is ignored. DEPRECATED!
1909 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
1910 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
1911 * @return string|void Depending on value of $return
1913 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
1914 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
1916 global $OUTPUT;
1918 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
1920 // hide image with CSS if needed
1922 if ($return) {
1923 return $output;
1924 } else {
1925 echo $output;
1930 * Print a help button.
1932 * Prints a special help button that is a link to the "live" emoticon popup
1934 * @todo Finish documenting this function
1936 * @global object
1937 * @global object
1938 * @param string $form ?
1939 * @param string $field ?
1940 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
1941 * @return string|void Depending on value of $return
1943 function emoticonhelpbutton($form, $field, $return = false) {
1944 /// TODO: MDL-21215
1946 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
1950 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1951 * Should be used only with htmleditor or textarea.
1953 * @global object
1954 * @global object
1955 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1956 * helpbutton.
1957 * @return string Link to help button
1959 function editorhelpbutton(){
1960 return '';
1962 /// TODO: MDL-21215
1966 * Print a help button.
1968 * Prints a special help button for html editors (htmlarea in this case)
1970 * @todo Write code into this function! detect current editor and print correct info
1971 * @global object
1972 * @return string Only returns an empty string at the moment
1974 function editorshortcutshelpbutton() {
1975 /// TODO: MDL-21215
1977 global $CFG;
1978 //TODO: detect current editor and print correct info
1979 /* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
1980 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
1982 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
1983 return '';
1988 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1989 * provide this function with the language strings for sortasc and sortdesc.
1991 * @deprecated since Moodle 2.0
1993 * TODO migrate to outputlib
1994 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1996 * @global object
1997 * @param string $direction 'up' or 'down'
1998 * @param string $strsort The language string used for the alt attribute of this image
1999 * @param bool $return Whether to print directly or return the html string
2000 * @return string|void depending on $return
2003 function print_arrow($direction='up', $strsort=null, $return=false) {
2004 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
2006 global $OUTPUT;
2008 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
2009 return null;
2012 $return = null;
2014 switch ($direction) {
2015 case 'up':
2016 $sortdir = 'asc';
2017 break;
2018 case 'down':
2019 $sortdir = 'desc';
2020 break;
2021 case 'move':
2022 $sortdir = 'asc';
2023 break;
2024 default:
2025 $sortdir = null;
2026 break;
2029 // Prepare language string
2030 $strsort = '';
2031 if (empty($strsort) && !empty($sortdir)) {
2032 $strsort = get_string('sort' . $sortdir, 'grades');
2035 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
2037 if ($return) {
2038 return $return;
2039 } else {
2040 echo $return;
2045 * Returns a string containing a link to the user documentation.
2046 * Also contains an icon by default. Shown to teachers and admin only.
2048 * @deprecated since Moodle 2.0
2050 * @global object
2051 * @param string $path The page link after doc root and language, no leading slash.
2052 * @param string $text The text to be displayed for the link
2053 * @param string $iconpath The path to the icon to be displayed
2054 * @return string Either the link or an empty string
2056 function doc_link($path='', $text='', $iconpath='ignored') {
2057 global $CFG, $OUTPUT;
2059 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
2061 if (empty($CFG->docroot)) {
2062 return '';
2065 return $OUTPUT->doc_link($path, $text);
2069 * Prints a single paging bar to provide access to other pages (usually in a search)
2071 * @deprecated since Moodle 2.0
2073 * @param int $totalcount Thetotal number of entries available to be paged through
2074 * @param int $page The page you are currently viewing
2075 * @param int $perpage The number of entries that should be shown per page
2076 * @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.
2077 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
2078 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
2079 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
2080 * @param bool $return whether to return an output string or echo now
2081 * @return bool|string depending on $result
2083 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
2084 global $OUTPUT;
2086 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
2088 if (empty($nocurr)) {
2089 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
2092 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
2093 $pagingbar->pagevar = $pagevar;
2094 $output = $OUTPUT->render($pagingbar);
2096 if ($return) {
2097 return $output;
2100 echo $output;
2101 return true;
2105 * Print a message along with "Yes" and "No" links for the user to continue.
2107 * @deprecated since Moodle 2.0
2109 * @global object
2110 * @param string $message The text to display
2111 * @param string $linkyes The link to take the user to if they choose "Yes"
2112 * @param string $linkno The link to take the user to if they choose "No"
2113 * @param string $optionyes The yes option to show on the notice
2114 * @param string $optionsno The no option to show
2115 * @param string $methodyes Form action method to use if yes [post, get]
2116 * @param string $methodno Form action method to use if no [post, get]
2117 * @return void Output is echo'd
2119 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
2121 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
2123 global $OUTPUT;
2125 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
2126 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
2128 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
2132 * Prints a scale menu (as part of an existing form) including help button
2133 * @deprecated since Moodle 2.0
2135 function print_scale_menu() {
2136 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
2140 * Given an array of values, output the HTML for a select element with those options.
2142 * @deprecated since Moodle 2.0
2144 * Normally, you only need to use the first few parameters.
2146 * @param array $options The options to offer. An array of the form
2147 * $options[{value}] = {text displayed for that option};
2148 * @param string $name the name of this form control, as in &lt;select name="..." ...
2149 * @param string $selected the option to select initially, default none.
2150 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
2151 * Set this to '' if you don't want a 'nothing is selected' option.
2152 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
2153 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
2154 * @param boolean $return if false (the default) the the output is printed directly, If true, the
2155 * generated HTML is returned as a string.
2156 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
2157 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
2158 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
2159 * then a suitable one is constructed.
2160 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
2161 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
2162 * $listbox is an integer, that number is used for size instead.
2163 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
2164 * when $listbox display is enabled
2165 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
2166 * then a suitable one is constructed.
2167 * @return string|void If $return=true returns string, else echo's and returns void
2169 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
2170 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
2171 $id='', $listbox=false, $multiple=false, $class='') {
2173 global $OUTPUT;
2174 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
2176 if ($script) {
2177 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2179 $attributes = array();
2180 $attributes['disabled'] = $disabled ? 'disabled' : null;
2181 $attributes['tabindex'] = $tabindex ? $tabindex : null;
2182 $attributes['multiple'] = $multiple ? $multiple : null;
2183 $attributes['class'] = $class ? $class : null;
2184 $attributes['id'] = $id ? $id : null;
2186 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
2188 if ($return) {
2189 return $output;
2190 } else {
2191 echo $output;
2196 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
2197 * Other options like choose_from_menu.
2199 * @deprecated since Moodle 2.0
2201 * Calls {@link choose_from_menu()} with preset arguments
2202 * @see choose_from_menu()
2204 * @param string $name the name of this form control, as in &lt;select name="..." ...
2205 * @param string $selected the option to select initially, default none.
2206 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
2207 * @param boolean $return Whether this function should return a string or output it (defaults to false)
2208 * @param boolean $disabled (defaults to false)
2209 * @param int $tabindex
2210 * @return string|void If $return=true returns string, else echo's and returns void
2212 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
2213 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
2214 global $OUTPUT;
2216 if ($script) {
2217 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2220 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
2222 if ($return) {
2223 return $output;
2224 } else {
2225 echo $output;
2230 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
2231 * including option headings with the first level.
2233 * @deprecated since Moodle 2.0
2235 * This function is very similar to {@link choose_from_menu_yesno()}
2236 * and {@link choose_from_menu()}
2238 * @todo Add datatype handling to make sure $options is an array
2240 * @param array $options An array of objects to choose from
2241 * @param string $name The XHTML field name
2242 * @param string $selected The value to select by default
2243 * @param string $nothing The label for the 'nothing is selected' option.
2244 * Defaults to get_string('choose').
2245 * @param string $script If not '', then this is added to the &lt;select> element
2246 * as an onchange handler.
2247 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
2248 * @param bool $return Whether this function should return a string or output
2249 * it (defaults to false)
2250 * @param bool $disabled Is the field disabled by default
2251 * @param int|string $tabindex Override the tabindex attribute [numeric]
2252 * @return string|void If $return=true returns string, else echo's and returns void
2254 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
2255 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
2257 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
2258 global $OUTPUT;
2262 * Prints a help button about a scale
2264 * @deprecated since Moodle 2.0
2266 * @global object
2267 * @param id $courseid
2268 * @param object $scale
2269 * @param boolean $return If set to true returns rather than echo's
2270 * @return string|bool Depending on value of $return
2272 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
2273 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
2274 global $OUTPUT;
2276 $output = $OUTPUT->help_icon_scale($courseid, $scale);
2278 if ($return) {
2279 return $output;
2280 } else {
2281 echo $output;
2287 * Prints time limit value selector
2289 * @deprecated since Moodle 2.0
2291 * Uses {@link choose_from_menu()} to generate HTML
2292 * @see choose_from_menu()
2294 * @global object
2295 * @param int $timelimit default
2296 * @param string $unit
2297 * @param string $name
2298 * @param boolean $return If set to true returns rather than echo's
2299 * @return string|bool Depending on value of $return
2301 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
2302 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
2306 * Prints form items with the names $hour and $minute
2308 * @deprecated since Moodle 2.0
2310 * @param string $hour fieldname
2311 * @param string $minute fieldname
2312 * @param int $currenttime A default timestamp in GMT
2313 * @param int $step minute spacing
2314 * @param boolean $return If set to true returns rather than echo's
2315 * @return string|bool Depending on value of $return
2317 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
2318 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
2320 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
2321 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
2323 $output = $hourselector . $$minuteselector;
2325 if ($return) {
2326 return $output;
2327 } else {
2328 echo $output;
2333 * Prints form items with the names $day, $month and $year
2335 * @deprecated since Moodle 2.0
2337 * @param string $day fieldname
2338 * @param string $month fieldname
2339 * @param string $year fieldname
2340 * @param int $currenttime A default timestamp in GMT
2341 * @param boolean $return If set to true returns rather than echo's
2342 * @return string|bool Depending on value of $return
2344 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
2345 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
2347 $dayselector = html_writer::select_time('days', $day, $currenttime);
2348 $monthselector = html_writer::select_time('months', $month, $currenttime);
2349 $yearselector = html_writer::select_time('years', $year, $currenttime);
2351 $output = $dayselector . $monthselector . $yearselector;
2353 if ($return) {
2354 return $output;
2355 } else {
2356 echo $output;
2361 * Implements a complete little form with a dropdown menu.
2363 * @deprecated since Moodle 2.0
2365 * When JavaScript is on selecting an option from the dropdown automatically
2366 * submits the form (while avoiding the usual acessibility problems with this appoach).
2367 * With JavaScript off, a 'Go' button is printed.
2369 * @global object
2370 * @global object
2371 * @param string $baseurl The target URL up to the point of the variable that changes
2372 * @param array $options A list of value-label pairs for the popup list
2373 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
2374 * @param string $selected The option that is initially selected
2375 * @param string $nothing The label for the "no choice" option
2376 * @param string $help The name of a help page if help is required
2377 * @param string $helptext The name of the label for the help button
2378 * @param boolean $return Indicates whether the function should return the HTML
2379 * as a string or echo it directly to the page being rendered
2380 * @param string $targetwindow The name of the target page to open the linked page in.
2381 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
2382 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
2383 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
2384 * @param boolean $disabled If true, the menu will be displayed disabled.
2385 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
2386 * @return string|void If $return=true returns string, else echo's and returns void
2388 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
2389 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
2390 global $OUTPUT, $CFG;
2392 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
2394 if (empty($options)) {
2395 return '';
2398 $urls = array();
2400 foreach ($options as $value=>$label) {
2401 $url = $baseurl.$value;
2402 $url = str_replace($CFG->wwwroot, '', $url);
2403 $url = str_replace('&amp;', '&', $url);
2404 $urls[$url] = $label;
2405 if ($selected == $value) {
2406 $active = $url;
2410 $nothing = $nothing ? array(''=>$nothing) : null;
2412 $select = new url_select($urls, $active, $nothing, $formid);
2413 $select->disabled = $disabled;
2415 $select->set_label($selectlabel);
2416 $select->set_old_help_icon($help, $helptext);
2418 $output = $OUTPUT->render($select);
2420 if ($return) {
2421 return $output;
2422 } else {
2423 echo $output;
2428 * Prints a simple button to close a window
2430 * @deprecated since Moodle 2.0
2432 * @global object
2433 * @param string $name Name of the window to close
2434 * @param boolean $return whether this function should return a string or output it.
2435 * @param boolean $reloadopener if true, clicking the button will also reload
2436 * the page that opend this popup window.
2437 * @return string|void if $return is true, void otherwise
2439 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
2440 global $OUTPUT;
2442 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
2443 $output = $OUTPUT->close_window_button(get_string($name));
2445 if ($return) {
2446 return $output;
2447 } else {
2448 echo $output;
2453 * Given an array of values, creates a group of radio buttons to be part of a form
2455 * @deprecated since Moodle 2.0
2457 * @staticvar int $idcounter
2458 * @param array $options An array of value-label pairs for the radio group (values as keys)
2459 * @param string $name Name of the radiogroup (unique in the form)
2460 * @param string $checked The value that is already checked
2461 * @param bool $return Whether this function should return a string or output
2462 * it (defaults to false)
2463 * @return string|void If $return=true returns string, else echo's and returns void
2465 function choose_from_radio ($options, $name, $checked='', $return=false) {
2466 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
2470 * Display an standard html checkbox with an optional label
2472 * @deprecated since Moodle 2.0
2474 * @staticvar int $idcounter
2475 * @param string $name The name of the checkbox
2476 * @param string $value The valus that the checkbox will pass when checked
2477 * @param bool $checked The flag to tell the checkbox initial state
2478 * @param string $label The label to be showed near the checkbox
2479 * @param string $alt The info to be inserted in the alt tag
2480 * @param string $script If not '', then this is added to the checkbox element
2481 * as an onchange handler.
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
2486 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
2488 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
2489 global $OUTPUT;
2491 if (!empty($script)) {
2492 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
2495 $output = html_writer::checkbox($name, $value, $checked, $label);
2497 if (empty($return)) {
2498 echo $output;
2499 } else {
2500 return $output;
2507 * Display an standard html text field with an optional label
2509 * @deprecated since Moodle 2.0
2511 * @param string $name The name of the text field
2512 * @param string $value The value of the text field
2513 * @param string $alt The info to be inserted in the alt tag
2514 * @param int $size Sets the size attribute of the field. Defaults to 50
2515 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
2516 * @param bool $return Whether this function should return a string or output
2517 * it (defaults to false)
2518 * @return string|void If $return=true returns string, else echo's and returns void
2520 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
2521 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
2523 if ($alt === '') {
2524 $alt = null;
2527 $style = "width: {$size}px;";
2528 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
2529 if ($maxlength) {
2530 $attributes['maxlength'] = $maxlength;
2533 $output = html_writer::empty_tag('input', $attributes);
2535 if (empty($return)) {
2536 echo $output;
2537 } else {
2538 return $output;
2544 * Centered heading with attached help button (same title text)
2545 * and optional icon attached
2547 * @deprecated since Moodle 2.0
2549 * @param string $text The text to be displayed
2550 * @param string $helppage The help page to link to
2551 * @param string $module The module whose help should be linked to
2552 * @param string $icon Image to display if needed
2553 * @param bool $return If set to true output is returned rather than echoed, default false
2554 * @return string|void String if return=true nothing otherwise
2556 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
2558 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
2560 global $OUTPUT;
2562 // Extract the src from $icon if it exists
2563 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
2564 $icon = $matches[1];
2565 $icon = new moodle_url($icon);
2566 } else {
2567 $icon = '';
2570 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
2572 if ($return) {
2573 return $output;
2574 } else {
2575 echo $output;
2580 * Returns a turn edit on/off button for course in a self contained form.
2581 * Used to be an icon, but it's now a simple form button
2582 * @deprecated since Moodle 2.0
2584 function update_mymoodle_icon() {
2585 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
2589 * Returns a turn edit on/off button for tag in a self contained form.
2590 * @deprecated since Moodle 2.0
2591 * @param string $tagid The ID attribute
2592 * @return string
2594 function update_tag_button($tagid) {
2595 global $OUTPUT;
2596 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2597 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
2602 * Prints the 'update this xxx' button that appears on module pages.
2604 * @deprecated since Moodle 2.0
2606 * @param string $cmid the course_module id.
2607 * @param string $ignored not used any more. (Used to be courseid.)
2608 * @param string $string the module name - get_string('modulename', 'xxx')
2609 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
2611 function update_module_button($cmid, $ignored, $string) {
2612 global $CFG, $OUTPUT;
2614 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
2616 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
2618 if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
2619 $string = get_string('updatethis', '', $string);
2621 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
2622 return $OUTPUT->single_button($url, $string);
2623 } else {
2624 return '';
2629 * Prints the editing button on search results listing
2630 * For bulk move courses to another category
2631 * @deprecated since Moodle 2.0
2633 function update_categories_search_button($search,$page,$perpage) {
2634 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
2638 * Prints a summary of a user in a nice little box.
2639 * @deprecated since Moodle 2.0
2641 function print_user($user, $course, $messageselect=false, $return=false) {
2642 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
2646 * Returns a turn edit on/off button for course in a self contained form.
2647 * Used to be an icon, but it's now a simple form button
2649 * Note that the caller is responsible for capchecks.
2651 * @global object
2652 * @global object
2653 * @param int $courseid The course to update by id as found in 'course' table
2654 * @return string
2656 function update_course_icon($courseid) {
2657 global $CFG, $OUTPUT;
2659 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2661 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
2665 * Prints breadcrumb trail of links, called in theme/-/header.html
2667 * This function has now been deprecated please use output's navbar method instead
2668 * as shown below
2670 * <code php>
2671 * echo $OUTPUT->navbar();
2672 * </code>
2674 * @deprecated since 2.0
2675 * @param mixed $navigation deprecated
2676 * @param string $separator OBSOLETE, and now deprecated
2677 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
2678 * @return string|void String or null, depending on $return.
2680 function print_navigation ($navigation, $separator=0, $return=false) {
2681 global $OUTPUT,$PAGE;
2683 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
2685 $output = $OUTPUT->navbar();
2687 if ($return) {
2688 return $output;
2689 } else {
2690 echo $output;
2695 * This function will build the navigation string to be used by print_header
2696 * and others.
2698 * It automatically generates the site and course level (if appropriate) links.
2700 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
2701 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
2703 * If you want to add any further navigation links after the ones this function generates,
2704 * the pass an array of extra link arrays like this:
2705 * array(
2706 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
2707 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
2709 * The normal case is to just add one further link, for example 'Editing forum' after
2710 * 'General Developer Forum', with no link.
2711 * To do that, you need to pass
2712 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
2713 * However, becuase this is a very common case, you can use a shortcut syntax, and just
2714 * pass the string 'Editing forum', instead of an array as $extranavlinks.
2716 * At the moment, the link types only have limited significance. Type 'activity' is
2717 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
2718 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
2719 * This really needs to be documented better. In the mean time, try to be consistent, it will
2720 * enable people to customise the navigation more in future.
2722 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
2723 * If you get the $cm object using the function get_coursemodule_from_instance or
2724 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
2725 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
2726 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
2727 * warning is printed in developer debug mode.
2729 * @deprecated since 2.0
2730 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
2731 * only want one extra item with no link, you can pass a string instead. If you don't want
2732 * any extra links, pass an empty string.
2733 * @param mixed $cm deprecated
2734 * @return array Navigation array
2736 function build_navigation($extranavlinks, $cm = null) {
2737 global $CFG, $COURSE, $DB, $SITE, $PAGE;
2739 if (is_array($extranavlinks) && count($extranavlinks)>0) {
2740 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
2741 foreach ($extranavlinks as $nav) {
2742 if (array_key_exists('name', $nav)) {
2743 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
2744 $link = $nav['link'];
2745 } else {
2746 $link = null;
2748 $PAGE->navbar->add($nav['name'],$link);
2753 return(array('newnav' => true, 'navlinks' => array()));
2757 * Returns a small popup menu of course activity modules
2759 * Given a course and a (current) coursemodule
2760 * his function returns a small popup menu with all the
2761 * course activity modules in it, as a navigation menu
2762 * The data is taken from the serialised array stored in
2763 * the course record
2765 * @global object
2766 * @global object
2767 * @global object
2768 * @global object
2769 * @uses CONTEXT_COURSE
2770 * @param object $course A {@link $COURSE} object.
2771 * @param object $cm A {@link $COURSE} object.
2772 * @param string $targetwindow The target window attribute to us
2773 * @return string
2775 function navmenu($course, $cm=NULL, $targetwindow='self') {
2776 // This function has been deprecated with the creation of the global nav in
2777 // moodle 2.0
2779 return '';
2783 * Returns a little popup menu for switching roles
2785 * @deprecated in Moodle 2.0
2786 * @param int $courseid The course to update by id as found in 'course' table
2787 * @return string
2789 function switchroles_form($courseid) {
2790 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
2791 return '';
2795 * Print header for admin page
2796 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
2797 * @param string $focus focus element
2799 function admin_externalpage_print_header($focus='') {
2800 global $OUTPUT;
2802 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
2804 echo $OUTPUT->header();
2808 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
2810 function admin_externalpage_print_footer() {
2811 // TODO Still 103 referernces in core code. Don't do debugging output yet.
2812 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
2813 global $OUTPUT;
2814 echo $OUTPUT->footer();
2817 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
2821 * Call this function to add an event to the calendar table and to call any calendar plugins
2823 * @param object $event An object representing an event from the calendar table.
2824 * The event will be identified by the id field. The object event should include the following:
2825 * <ul>
2826 * <li><b>$event->name</b> - Name for the event
2827 * <li><b>$event->description</b> - Description of the event (defaults to '')
2828 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
2829 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
2830 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
2831 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
2832 * <li><b>$event->modulename</b> - Name of the module that creates this event
2833 * <li><b>$event->instance</b> - Instance of the module that owns this event
2834 * <li><b>$event->eventtype</b> - The type info together with the module info could
2835 * be used by calendar plugins to decide how to display event
2836 * <li><b>$event->timestart</b>- Timestamp for start of event
2837 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
2838 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
2839 * </ul>
2840 * @return int|false The id number of the resulting record or false if failed
2842 function add_event($event) {
2843 global $CFG;
2844 require_once($CFG->dirroot.'/calendar/lib.php');
2845 $event = calendar_event::create($event);
2846 if ($event !== false) {
2847 return $event->id;
2849 return false;
2853 * Call this function to update an event in the calendar table
2854 * the event will be identified by the id field of the $event object.
2856 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2857 * @return bool Success
2859 function update_event($event) {
2860 global $CFG;
2861 require_once($CFG->dirroot.'/calendar/lib.php');
2862 $event = (object)$event;
2863 $calendarevent = calendar_event::load($event->id);
2864 return $calendarevent->update($event);
2868 * Call this function to delete the event with id $id from calendar table.
2870 * @param int $id The id of an event from the 'event' table.
2871 * @return bool
2873 function delete_event($id) {
2874 global $CFG;
2875 require_once($CFG->dirroot.'/calendar/lib.php');
2876 $event = calendar_event::load($id);
2877 return $event->delete();
2881 * Call this function to hide an event in the calendar table
2882 * the event will be identified by the id field of the $event object.
2884 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2885 * @return true
2887 function hide_event($event) {
2888 global $CFG;
2889 require_once($CFG->dirroot.'/calendar/lib.php');
2890 $event = new calendar_event($event);
2891 return $event->toggle_visibility(false);
2895 * Call this function to unhide an event in the calendar table
2896 * the event will be identified by the id field of the $event object.
2898 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2899 * @return true
2901 function show_event($event) {
2902 global $CFG;
2903 require_once($CFG->dirroot.'/calendar/lib.php');
2904 $event = new calendar_event($event);
2905 return $event->toggle_visibility(true);
2909 * Converts string to lowercase using most compatible function available.
2911 * @deprecated Use textlib::strtolower($text) instead.
2913 * @param string $string The string to convert to all lowercase characters.
2914 * @param string $encoding The encoding on the string.
2915 * @return string
2917 function moodle_strtolower($string, $encoding='') {
2919 debugging('moodle_strtolower() is deprecated. Please use textlib::strtolower() instead.', DEBUG_DEVELOPER);
2921 //If not specified use utf8
2922 if (empty($encoding)) {
2923 $encoding = 'UTF-8';
2925 //Use text services
2926 return textlib::strtolower($string, $encoding);
2930 * Original singleton helper function, please use static methods instead,
2931 * ex: textlib::convert()
2933 * @deprecated since Moodle 2.2 use textlib::xxxx() instead
2934 * @see textlib
2935 * @return textlib instance
2937 function textlib_get_instance() {
2939 debugging('textlib_get_instance() is deprecated. Please use static calling textlib::functioname() instead.', DEBUG_DEVELOPER);
2941 return new textlib();