MDL-35823 - Accessibility - Readding Focus to header in the help popup
[moodle.git] / lib / deprecatedlib.php
blob21087709721a0593988f762679216869354d34d1
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 * Not used any more, the account lockout handling is now
35 * part of authenticate_user_login().
36 * @deprecated
38 function update_login_count() {
39 // TODO: delete function in Moodle 2.6
40 debugging('update_login_count() is deprecated, all calls need to be removed');
43 /**
44 * Not used any more, replaced by proper account lockout.
45 * @deprecated
47 function reset_login_count() {
48 // TODO: delete function in Moodle 2.6
49 debugging('reset_login_count() is deprecated, all calls need to be removed');
52 /**
53 * Unsupported session id rewriting.
54 * @deprecated
55 * @param string $buffer
57 function sid_ob_rewrite($buffer) {
58 throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
61 /**
62 * Insert or update log display entry. Entry may already exist.
63 * $module, $action must be unique
64 * @deprecated
66 * @param string $module
67 * @param string $action
68 * @param string $mtable
69 * @param string $field
70 * @return void
73 function update_log_display_entry($module, $action, $mtable, $field) {
74 global $DB;
76 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
79 /**
80 * Given some text in HTML format, this function will pass it
81 * through any filters that have been configured for this context.
83 * @deprecated use the text formatting in a standard way instead,
84 * this was abused mostly for embedding of attachments
86 * @param string $text The text to be passed through format filters
87 * @param int $courseid The current course.
88 * @return string the filtered string.
90 function filter_text($text, $courseid = NULL) {
91 global $CFG, $COURSE;
93 if (!$courseid) {
94 $courseid = $COURSE->id;
97 if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
98 return $text;
101 return filter_manager::instance()->filter_text($text, $context);
105 * This function indicates that current page requires the https
106 * when $CFG->loginhttps enabled.
108 * By using this function properly, we can ensure 100% https-ized pages
109 * at our entire discretion (login, forgot_password, change_password)
110 * @deprecated use $PAGE->https_required() instead
112 function httpsrequired() {
113 global $PAGE;
114 $PAGE->https_required();
118 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
120 * @deprecated use moodle_url factory methods instead
122 * @param string $path Physical path to a file
123 * @param array $options associative array of GET variables to append to the URL
124 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
125 * @return string URL to file
127 function get_file_url($path, $options=null, $type='coursefile') {
128 global $CFG;
130 $path = str_replace('//', '/', $path);
131 $path = trim($path, '/'); // no leading and trailing slashes
133 // type of file
134 switch ($type) {
135 case 'questionfile':
136 $url = $CFG->wwwroot."/question/exportfile.php";
137 break;
138 case 'rssfile':
139 $url = $CFG->wwwroot."/rss/file.php";
140 break;
141 case 'httpscoursefile':
142 $url = $CFG->httpswwwroot."/file.php";
143 break;
144 case 'coursefile':
145 default:
146 $url = $CFG->wwwroot."/file.php";
149 if ($CFG->slasharguments) {
150 $parts = explode('/', $path);
151 foreach ($parts as $key => $part) {
152 /// anchor dash character should not be encoded
153 $subparts = explode('#', $part);
154 $subparts = array_map('rawurlencode', $subparts);
155 $parts[$key] = implode('#', $subparts);
157 $path = implode('/', $parts);
158 $ffurl = $url.'/'.$path;
159 $separator = '?';
160 } else {
161 $path = rawurlencode('/'.$path);
162 $ffurl = $url.'?file='.$path;
163 $separator = '&amp;';
166 if ($options) {
167 foreach ($options as $name=>$value) {
168 $ffurl = $ffurl.$separator.$name.'='.$value;
169 $separator = '&amp;';
173 return $ffurl;
177 * If there has been an error uploading a file, print the appropriate error message
178 * Numerical constants used as constant definitions not added until PHP version 4.2.0
179 * @deprecated removed - use new file api
181 function print_file_upload_error($filearray = '', $returnerror = false) {
182 throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
186 * Handy function for resolving file conflicts
187 * @deprecated removed - use new file api
190 function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
191 throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
195 * Checks a file name for any conflicts
196 * @deprecated removed - use new file api
198 function check_potential_filename($destination,$filename,$files) {
199 throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
203 * This function prints out a number of upload form elements.
204 * @deprecated removed - use new file api
206 function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
207 throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
211 * Return the authentication plugin title
213 * @param string $authtype plugin type
214 * @return string
216 function auth_get_plugin_title($authtype) {
217 debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
218 return get_string('pluginname', "auth_{$authtype}");
224 * Enrol someone without using the default role in a course
225 * @deprecated
227 function enrol_into_course($course, $user, $enrol) {
228 error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
232 * Returns a role object that is the default role for new enrolments in a given course
234 * @deprecated
235 * @param object $course
236 * @return object returns a role or NULL if none set
238 function get_default_course_role($course) {
239 debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
241 $student = get_archetype_roles('student');
242 $student = reset($student);
244 return $student;
248 * Extremely slow enrolled courses query.
249 * @deprecated
251 function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
252 error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
256 * Was returning list of translations, use new string_manager instead
258 * @deprecated
259 * @param bool $refreshcache force refreshing of lang cache
260 * @param bool $returnall ignore langlist, return all languages available
261 * @return array An associative array with contents in the form of LanguageCode => LanguageName
263 function get_list_of_languages($refreshcache=false, $returnall=false) {
264 debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
265 if ($refreshcache) {
266 get_string_manager()->reset_caches();
268 return get_string_manager()->get_list_of_translations($returnall);
272 * Returns a list of currencies in the current language
273 * @deprecated
274 * @return array
276 function get_list_of_currencies() {
277 debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
278 return get_string_manager()->get_list_of_currencies();
282 * Returns a list of all enabled country names in the current translation
283 * @deprecated
284 * @return array two-letter country code => translated name.
286 function get_list_of_countries() {
287 debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
288 return get_string_manager()->get_list_of_countries(false);
292 * @deprecated
294 function isteacher() {
295 error('Function isteacher() was removed, please use capabilities instead!');
299 * @deprecated
301 function isteacherinanycourse() {
302 throw new coding_Exception('Function isteacherinanycourse() was removed, please use capabilities instead!');
306 * @deprecated
308 function get_guest() {
309 throw new coding_Exception('Function get_guest() was removed, please use capabilities instead!');
313 * @deprecated
315 function isguest() {
316 throw new coding_Exception('Function isguest() was removed, please use capabilities instead!');
320 * @deprecated
322 function get_teacher() {
323 throw new coding_Exception('Function get_teacher() was removed, please use capabilities instead!');
327 * Return all course participant for a given course
329 * @deprecated
330 * @param integer $courseid
331 * @return array of user
333 function get_course_participants($courseid) {
334 return get_enrolled_users(context_course::instance($courseid));
338 * Return true if the user is a participant for a given course
340 * @deprecated
341 * @param integer $userid
342 * @param integer $courseid
343 * @return boolean
345 function is_course_participant($userid, $courseid) {
346 return is_enrolled(context_course::instance($courseid), $userid);
350 * Searches logs to find all enrolments since a certain date
352 * used to print recent activity
354 * @todo MDL-36993 this function is still used in block_recent_activity, deprecate properly
355 * @global object
356 * @uses CONTEXT_COURSE
357 * @param int $courseid The course in question.
358 * @param int $timestart The date to check forward of
359 * @return object|false {@link $USER} records or false if error.
361 function get_recent_enrolments($courseid, $timestart) {
362 global $DB;
364 $context = context_course::instance($courseid);
366 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
367 FROM {user} u, {role_assignments} ra, {log} l
368 WHERE l.time > ?
369 AND l.course = ?
370 AND l.module = 'course'
371 AND l.action = 'enrol'
372 AND ".$DB->sql_cast_char2int('l.info')." = u.id
373 AND u.id = ra.userid
374 AND ra.contextid ".get_related_contexts_string($context)."
375 GROUP BY u.id, u.firstname, u.lastname
376 ORDER BY MAX(l.time) ASC";
377 $params = array($timestart, $courseid);
378 return $DB->get_records_sql($sql, $params);
383 * Turn the ctx* fields in an objectlike record into a context subobject
384 * This allows us to SELECT from major tables JOINing with
385 * context at no cost, saving a ton of context lookups...
387 * Use context_instance_preload() instead.
389 * @deprecated since 2.0
390 * @param object $rec
391 * @return object
393 function make_context_subobj($rec) {
394 throw new coding_Exception('make_context_subobj() was removed, use new context preloading');
398 * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
400 * Use context_instance_preload() instead.
402 * @deprecated since 2.0
403 * @param object $rec a think that has a context, for example a course,
404 * course category, course modules, etc.
405 * @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
406 * @return bool whether $rec->context looks like the correct context object
407 * for this thing.
409 function is_context_subobj_valid($rec, $contextlevel) {
410 throw new coding_Exception('is_context_subobj_valid() was removed, use new context preloading');
414 * Ensure that $rec->context is present and correct before you continue
416 * When you have a record (for example a $category, $course, $user or $cm that may,
417 * or may not, have come from a place that does make_context_subobj, you can use
418 * this method to ensure that $rec->context is present and correct before you continue.
420 * Use context_instance_preload() instead.
422 * @deprecated since 2.0
423 * @param object $rec a thing that has an associated context.
424 * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
426 function ensure_context_subobj_present(&$rec, $contextlevel) {
427 throw new coding_Exception('ensure_context_subobj_present() was removed, use new context preloading');
430 ########### FROM weblib.php ##########################################################################
434 * Print a message in a standard themed box.
435 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
436 * parameters remain. If possible, $align, $width and $color should not be defined at all.
437 * Preferably just use print_box() in weblib.php
439 * @deprecated
440 * @param string $message The message to display
441 * @param string $align alignment of the box, not the text (default center, left, right).
442 * @param string $width width of the box, including units %, for example '100%'.
443 * @param string $color background colour of the box, for example '#eee'.
444 * @param int $padding padding in pixels, specified without units.
445 * @param string $class space-separated class names.
446 * @param string $id space-separated id names.
447 * @param boolean $return return as string or just print it
448 * @return string|void Depending on $return
450 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
451 $output = '';
452 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
453 $output .= $message;
454 $output .= print_simple_box_end(true);
456 if ($return) {
457 return $output;
458 } else {
459 echo $output;
466 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
467 * parameters remain. If possible, $align, $width and $color should not be defined at all.
468 * Even better, please use print_box_start() in weblib.php
470 * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
471 * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
472 * @param string $color background colour of the box, for example '#eee'. DEPRECATED
473 * @param int $padding padding in pixels, specified without units. OBSOLETE
474 * @param string $class space-separated class names.
475 * @param string $id space-separated id names.
476 * @param boolean $return return as string or just print it
477 * @return string|void Depending on $return
479 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
480 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
482 $output = '';
484 $divclasses = 'box '.$class.' '.$class.'content';
485 $divstyles = '';
487 if ($align) {
488 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
490 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
491 if (substr($width, -1, 1) == '%') { // Width is a % value
492 $width = (int) substr($width, 0, -1); // Extract just the number
493 if ($width < 40) {
494 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
495 } else if ($width > 60) {
496 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
497 } else {
498 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
500 } else {
501 $divstyles .= ' width:'.$width.';'; // Last resort
504 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
505 $divstyles .= ' background:'.$color.';';
507 if ($divstyles) {
508 $divstyles = ' style="'.$divstyles.'"';
511 if ($id) {
512 $id = ' id="'.$id.'"';
515 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
517 if ($return) {
518 return $output;
519 } else {
520 echo $output;
526 * Print the end portion of a standard themed box.
527 * Preferably just use print_box_end() in weblib.php
529 * @param boolean $return return as string or just print it
530 * @return string|void Depending on $return
532 function print_simple_box_end($return=false) {
533 $output = '</div>';
534 if ($return) {
535 return $output;
536 } else {
537 echo $output;
542 * Given some text this function converted any URLs it found into HTML links
544 * This core function has been replaced with filter_urltolink since Moodle 2.0
546 * @param string $text Passed in by reference. The string to be searched for urls.
548 function convert_urls_into_links($text) {
549 debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
553 * Used to be called from help.php to inject a list of smilies into the
554 * emoticons help file.
556 * @return string HTML
558 function get_emoticons_list_for_help_file() {
559 debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
560 return '';
564 * Was used to replace all known smileys in the text with image equivalents
566 * This core function has been replaced with filter_emoticon since Moodle 2.0
568 function replace_smilies(&$text) {
569 debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
573 * deprecated - use clean_param($string, PARAM_FILE); instead
574 * Check for bad characters ?
576 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
578 * @param string $string ?
579 * @param int $allowdots ?
580 * @return bool
582 function detect_munged_arguments($string, $allowdots=1) {
583 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
584 return true;
586 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
587 return true;
589 if (empty($string) or $string == '/') {
590 return true;
593 return false;
598 * Unzip one zip file to a destination dir
599 * Both parameters must be FULL paths
600 * If destination isn't specified, it will be the
601 * SAME directory where the zip file resides.
603 * @global object
604 * @param string $zipfile The zip file to unzip
605 * @param string $destination The location to unzip to
606 * @param bool $showstatus_ignored Unused
608 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
609 global $CFG;
611 //Extract everything from zipfile
612 $path_parts = pathinfo(cleardoubleslashes($zipfile));
613 $zippath = $path_parts["dirname"]; //The path of the zip file
614 $zipfilename = $path_parts["basename"]; //The name of the zip file
615 $extension = $path_parts["extension"]; //The extension of the file
617 //If no file, error
618 if (empty($zipfilename)) {
619 return false;
622 //If no extension, error
623 if (empty($extension)) {
624 return false;
627 //Clear $zipfile
628 $zipfile = cleardoubleslashes($zipfile);
630 //Check zipfile exists
631 if (!file_exists($zipfile)) {
632 return false;
635 //If no destination, passed let's go with the same directory
636 if (empty($destination)) {
637 $destination = $zippath;
640 //Clear $destination
641 $destpath = rtrim(cleardoubleslashes($destination), "/");
643 //Check destination path exists
644 if (!is_dir($destpath)) {
645 return false;
648 $packer = get_file_packer('application/zip');
650 $result = $packer->extract_to_pathname($zipfile, $destpath);
652 if ($result === false) {
653 return false;
656 foreach ($result as $status) {
657 if ($status !== true) {
658 return false;
662 return true;
666 * Zip an array of files/dirs to a destination zip file
667 * Both parameters must be FULL paths to the files/dirs
669 * @global object
670 * @param array $originalfiles Files to zip
671 * @param string $destination The destination path
672 * @return bool Outcome
674 function zip_files ($originalfiles, $destination) {
675 global $CFG;
677 //Extract everything from destination
678 $path_parts = pathinfo(cleardoubleslashes($destination));
679 $destpath = $path_parts["dirname"]; //The path of the zip file
680 $destfilename = $path_parts["basename"]; //The name of the zip file
681 $extension = $path_parts["extension"]; //The extension of the file
683 //If no file, error
684 if (empty($destfilename)) {
685 return false;
688 //If no extension, add it
689 if (empty($extension)) {
690 $extension = 'zip';
691 $destfilename = $destfilename.'.'.$extension;
694 //Check destination path exists
695 if (!is_dir($destpath)) {
696 return false;
699 //Check destination path is writable. TODO!!
701 //Clean destination filename
702 $destfilename = clean_filename($destfilename);
704 //Now check and prepare every file
705 $files = array();
706 $origpath = NULL;
708 foreach ($originalfiles as $file) { //Iterate over each file
709 //Check for every file
710 $tempfile = cleardoubleslashes($file); // no doubleslashes!
711 //Calculate the base path for all files if it isn't set
712 if ($origpath === NULL) {
713 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
715 //See if the file is readable
716 if (!is_readable($tempfile)) { //Is readable
717 continue;
719 //See if the file/dir is in the same directory than the rest
720 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
721 continue;
723 //Add the file to the array
724 $files[] = $tempfile;
727 $zipfiles = array();
728 $start = strlen($origpath)+1;
729 foreach($files as $file) {
730 $zipfiles[substr($file, $start)] = $file;
733 $packer = get_file_packer('application/zip');
735 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
738 /////////////////////////////////////////////////////////////
739 /// Old functions not used anymore - candidates for removal
740 /////////////////////////////////////////////////////////////
743 /** various deprecated groups function **/
747 * Get the IDs for the user's groups in the given course.
749 * @global object
750 * @param int $courseid The course being examined - the 'course' table id field.
751 * @return array|bool An _array_ of groupids, or false
752 * (Was return $groupids[0] - consequences!)
754 function mygroupid($courseid) {
755 global $USER;
756 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
757 return array_keys($groups);
758 } else {
759 return false;
765 * Returns the current group mode for a given course or activity module
767 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
769 * @param object $course Course Object
770 * @param object $cm Course Manager Object
771 * @return mixed $course->groupmode
773 function groupmode($course, $cm=null) {
775 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
776 return $cm->groupmode;
778 return $course->groupmode;
782 * Sets the current group in the session variable
783 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
784 * Sets currentgroup[$courseid] in the session variable appropriately.
785 * Does not do any permission checking.
787 * @global object
788 * @param int $courseid The course being examined - relates to id field in
789 * 'course' table.
790 * @param int $groupid The group being examined.
791 * @return int Current group id which was set by this function
793 function set_current_group($courseid, $groupid) {
794 global $SESSION;
795 return $SESSION->currentgroup[$courseid] = $groupid;
800 * Gets the current group - either from the session variable or from the database.
802 * @global object
803 * @param int $courseid The course being examined - relates to id field in
804 * 'course' table.
805 * @param bool $full If true, the return value is a full record object.
806 * If false, just the id of the record.
807 * @return int|bool
809 function get_current_group($courseid, $full = false) {
810 global $SESSION;
812 if (isset($SESSION->currentgroup[$courseid])) {
813 if ($full) {
814 return groups_get_group($SESSION->currentgroup[$courseid]);
815 } else {
816 return $SESSION->currentgroup[$courseid];
820 $mygroupid = mygroupid($courseid);
821 if (is_array($mygroupid)) {
822 $mygroupid = array_shift($mygroupid);
823 set_current_group($courseid, $mygroupid);
824 if ($full) {
825 return groups_get_group($mygroupid);
826 } else {
827 return $mygroupid;
831 if ($full) {
832 return false;
833 } else {
834 return 0;
840 * Inndicates fatal error. This function was originally printing the
841 * error message directly, since 2.0 it is throwing exception instead.
842 * The error printing is handled in default exception handler.
844 * Old method, don't call directly in new code - use print_error instead.
846 * @param string $message The message to display to the user about the error.
847 * @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.
848 * @return void, always throws moodle_exception
850 function error($message, $link='') {
851 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
855 //////////////////////////
856 /// removed functions ////
857 //////////////////////////
860 * @deprecated
861 * @param mixed $name
862 * @param mixed $editorhidebuttons
863 * @param mixed $id
864 * @return void Throws an error and does nothing
866 function use_html_editor($name='', $editorhidebuttons='', $id='') {
867 error('use_html_editor() not available anymore');
871 * The old method that was used to include JavaScript libraries.
872 * Please use $PAGE->requires->js_module() instead.
874 * @param mixed $lib The library or libraries to load (a string or array of strings)
875 * There are three way to specify the library:
876 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
877 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
878 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
879 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
881 function require_js($lib) {
882 throw new coding_exception('require_js() was removed, use new JS api');
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 * Prints some red text using echo
931 * @deprecated
932 * @param string $error The text to be displayed in red
934 function formerr($error) {
935 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
936 global $OUTPUT;
937 echo $OUTPUT->error_text($error);
941 * Return the markup for the destination of the 'Skip to main content' links.
942 * Accessibility improvement for keyboard-only users.
944 * Used in course formats, /index.php and /course/index.php
946 * @deprecated use $OUTPUT->skip_link_target() in instead.
947 * @return string HTML element.
949 function skip_main_destination() {
950 global $OUTPUT;
951 return $OUTPUT->skip_link_target();
955 * Prints a string in a specified size (retained for backward compatibility)
957 * @deprecated
958 * @param string $text The text to be displayed
959 * @param int $size The size to set the font for text display.
960 * @param bool $return If set to true output is returned rather than echoed Default false
961 * @return string|void String if return is true
963 function print_headline($text, $size=2, $return=false) {
964 global $OUTPUT;
965 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
966 $output = $OUTPUT->heading($text, $size);
967 if ($return) {
968 return $output;
969 } else {
970 echo $output;
975 * Prints text in a format for use in headings.
977 * @deprecated
978 * @param string $text The text to be displayed
979 * @param string $deprecated No longer used. (Use to do alignment.)
980 * @param int $size The size to set the font for text display.
981 * @param string $class
982 * @param bool $return If set to true output is returned rather than echoed, default false
983 * @param string $id The id to use in the element
984 * @return string|void String if return=true nothing otherwise
986 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
987 global $OUTPUT;
988 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
989 if (!empty($deprecated)) {
990 debugging('Use of deprecated align attribute of print_heading. ' .
991 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
993 $output = $OUTPUT->heading($text, $size, $class, $id);
994 if ($return) {
995 return $output;
996 } else {
997 echo $output;
1002 * Output a standard heading block
1004 * @deprecated
1005 * @param string $heading The text to write into the heading
1006 * @param string $class An additional Class Attr to use for the heading
1007 * @param bool $return If set to true output is returned rather than echoed, default false
1008 * @return string|void HTML String if return=true nothing otherwise
1010 function print_heading_block($heading, $class='', $return=false) {
1011 global $OUTPUT;
1012 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
1013 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
1014 if ($return) {
1015 return $output;
1016 } else {
1017 echo $output;
1022 * Print a message in a standard themed box.
1023 * Replaces print_simple_box (see deprecatedlib.php)
1025 * @deprecated
1026 * @param string $message, the content of the box
1027 * @param string $classes, space-separated class names.
1028 * @param string $ids
1029 * @param boolean $return, return as string or just print it
1030 * @return string|void mixed string or void
1032 function print_box($message, $classes='generalbox', $ids='', $return=false) {
1033 global $OUTPUT;
1034 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
1035 $output = $OUTPUT->box($message, $classes, $ids);
1036 if ($return) {
1037 return $output;
1038 } else {
1039 echo $output;
1044 * Starts a box using divs
1045 * Replaces print_simple_box_start (see deprecatedlib.php)
1047 * @deprecated
1048 * @param string $classes, space-separated class names.
1049 * @param string $ids
1050 * @param boolean $return, return as string or just print it
1051 * @return string|void string or void
1053 function print_box_start($classes='generalbox', $ids='', $return=false) {
1054 global $OUTPUT;
1055 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
1056 $output = $OUTPUT->box_start($classes, $ids);
1057 if ($return) {
1058 return $output;
1059 } else {
1060 echo $output;
1065 * Simple function to end a box (see above)
1066 * Replaces print_simple_box_end (see deprecatedlib.php)
1068 * @deprecated
1069 * @param boolean $return, return as string or just print it
1070 * @return string|void Depending on value of return
1072 function print_box_end($return=false) {
1073 global $OUTPUT;
1074 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
1075 $output = $OUTPUT->box_end();
1076 if ($return) {
1077 return $output;
1078 } else {
1079 echo $output;
1084 * Print a message in a standard themed container.
1086 * @deprecated
1087 * @param string $message, the content of the container
1088 * @param boolean $clearfix clear both sides
1089 * @param string $classes, space-separated class names.
1090 * @param string $idbase
1091 * @param boolean $return, return as string or just print it
1092 * @return string|void Depending on value of $return
1094 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1095 global $OUTPUT;
1096 if ($clearfix) {
1097 $classes .= ' clearfix';
1099 $output = $OUTPUT->container($message, $classes, $idbase);
1100 if ($return) {
1101 return $output;
1102 } else {
1103 echo $output;
1108 * Starts a container using divs
1110 * @deprecated
1111 * @param boolean $clearfix clear both sides
1112 * @param string $classes, space-separated class names.
1113 * @param string $idbase
1114 * @param boolean $return, return as string or just print it
1115 * @return string|void Based on value of $return
1117 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1118 global $OUTPUT;
1119 if ($clearfix) {
1120 $classes .= ' clearfix';
1122 $output = $OUTPUT->container_start($classes, $idbase);
1123 if ($return) {
1124 return $output;
1125 } else {
1126 echo $output;
1131 * Deprecated, now handled automatically in themes
1133 function check_theme_arrows() {
1134 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
1138 * Simple function to end a container (see above)
1140 * @deprecated
1141 * @param boolean $return, return as string or just print it
1142 * @return string|void Based on $return
1144 function print_container_end($return=false) {
1145 global $OUTPUT;
1146 $output = $OUTPUT->container_end();
1147 if ($return) {
1148 return $output;
1149 } else {
1150 echo $output;
1155 * Print a bold message in an optional color.
1157 * @deprecated use $OUTPUT->notification instead.
1158 * @param string $message The message to print out
1159 * @param string $style Optional style to display message text in
1160 * @param string $align Alignment option
1161 * @param bool $return whether to return an output string or echo now
1162 * @return string|bool Depending on $result
1164 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1165 global $OUTPUT;
1167 if ($classes == 'green') {
1168 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1169 $classes = 'notifysuccess'; // Backward compatible with old color system
1172 $output = $OUTPUT->notification($message, $classes);
1173 if ($return) {
1174 return $output;
1175 } else {
1176 echo $output;
1181 * Print a continue button that goes to a particular URL.
1183 * @deprecated since Moodle 2.0
1185 * @param string $link The url to create a link to.
1186 * @param bool $return If set to true output is returned rather than echoed, default false
1187 * @return string|void HTML String if return=true nothing otherwise
1189 function print_continue($link, $return = false) {
1190 global $CFG, $OUTPUT;
1192 if ($link == '') {
1193 if (!empty($_SERVER['HTTP_REFERER'])) {
1194 $link = $_SERVER['HTTP_REFERER'];
1195 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1196 } else {
1197 $link = $CFG->wwwroot .'/';
1201 $output = $OUTPUT->continue_button($link);
1202 if ($return) {
1203 return $output;
1204 } else {
1205 echo $output;
1210 * Print a standard header
1212 * @param string $title Appears at the top of the window
1213 * @param string $heading Appears at the top of the page
1214 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1215 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1216 * @param string $meta Meta tags to be added to the header
1217 * @param boolean $cache Should this page be cacheable?
1218 * @param string $button HTML code for a button (usually for module editing)
1219 * @param string $menu HTML code for a popup menu
1220 * @param boolean $usexml use XML for this page
1221 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1222 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1223 * @return string|void If return=true then string else void
1225 function print_header($title='', $heading='', $navigation='', $focus='',
1226 $meta='', $cache=true, $button='&nbsp;', $menu=null,
1227 $usexml=false, $bodytags='', $return=false) {
1228 global $PAGE, $OUTPUT;
1230 $PAGE->set_title($title);
1231 $PAGE->set_heading($heading);
1232 $PAGE->set_cacheable($cache);
1233 if ($button == '') {
1234 $button = '&nbsp;';
1236 $PAGE->set_button($button);
1237 $PAGE->set_headingmenu($menu);
1239 // TODO $menu
1241 if ($meta) {
1242 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1243 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1245 if ($usexml) {
1246 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1248 if ($bodytags) {
1249 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1252 $output = $OUTPUT->header();
1254 if ($return) {
1255 return $output;
1256 } else {
1257 echo $output;
1262 * This version of print_header is simpler because the course name does not have to be
1263 * provided explicitly in the strings. It can be used on the site page as in courses
1264 * Eventually all print_header could be replaced by print_header_simple
1266 * @deprecated since Moodle 2.0
1267 * @param string $title Appears at the top of the window
1268 * @param string $heading Appears at the top of the page
1269 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1270 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1271 * @param string $meta Meta tags to be added to the header
1272 * @param boolean $cache Should this page be cacheable?
1273 * @param string $button HTML code for a button (usually for module editing)
1274 * @param string $menu HTML code for a popup menu
1275 * @param boolean $usexml use XML for this page
1276 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1277 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1278 * @return string|void If $return=true the return string else nothing
1280 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1281 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1283 global $COURSE, $CFG, $PAGE, $OUTPUT;
1285 if ($meta) {
1286 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1287 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1289 if ($usexml) {
1290 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1292 if ($bodytags) {
1293 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1296 $PAGE->set_title($title);
1297 $PAGE->set_heading($heading);
1298 $PAGE->set_cacheable(true);
1299 $PAGE->set_button($button);
1301 $output = $OUTPUT->header();
1303 if ($return) {
1304 return $output;
1305 } else {
1306 echo $output;
1310 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
1311 global $PAGE, $OUTPUT;
1312 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
1313 // TODO check arguments.
1314 if (is_string($course)) {
1315 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
1316 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
1317 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
1318 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
1320 if (!is_null($usercourse)) {
1321 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
1322 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
1324 $output = $OUTPUT->footer();
1325 if ($return) {
1326 return $output;
1327 } else {
1328 echo $output;
1333 * Returns text to be displayed to the user which reflects their login status
1335 * @global object
1336 * @global object
1337 * @global object
1338 * @global object
1339 * @uses CONTEXT_COURSE
1340 * @param course $course {@link $COURSE} object containing course information
1341 * @param user $user {@link $USER} object containing user information
1342 * @return string HTML
1344 function user_login_string($course='ignored', $user='ignored') {
1345 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
1346 return '';
1350 * Prints a nice side block with an optional header. The content can either
1351 * be a block of HTML or a list of text with optional icons.
1353 * @todo Finish documenting this function. Show example of various attributes, etc.
1355 * @static int $block_id Increments for each call to the function
1356 * @param string $heading HTML for the heading. Can include full HTML or just
1357 * plain text - plain text will automatically be enclosed in the appropriate
1358 * heading tags.
1359 * @param string $content HTML for the content
1360 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1361 * @param array $icons optional icons for the things in $list.
1362 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
1363 * @param array $attributes an array of attribute => value pairs that are put on the
1364 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1365 * already a class, class='block' is used.
1366 * @param string $title Plain text title, as embedded in the $heading.
1367 * @deprecated
1369 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1370 global $OUTPUT;
1372 // We don't use $heading, becuse it often contains HTML that we don't want.
1373 // However, sometimes $title is not set, but $heading is.
1374 if (empty($title)) {
1375 $title = strip_tags($heading);
1378 // Render list contents to HTML if required.
1379 if (empty($content) && $list) {
1380 $content = $OUTPUT->list_block_contents($icons, $list);
1383 $bc = new block_contents();
1384 $bc->content = $content;
1385 $bc->footer = $footer;
1386 $bc->title = $title;
1388 if (isset($attributes['id'])) {
1389 $bc->id = $attributes['id'];
1390 unset($attributes['id']);
1392 $bc->attributes = $attributes;
1394 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1398 * Starts a nice side block with an optional header.
1400 * @todo Finish documenting this function
1402 * @global object
1403 * @global object
1404 * @param string $heading HTML for the heading. Can include full HTML or just
1405 * plain text - plain text will automatically be enclosed in the appropriate
1406 * heading tags.
1407 * @param array $attributes HTML attributes to apply if possible
1408 * @deprecated
1410 function print_side_block_start($heading='', $attributes = array()) {
1411 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
1415 * Print table ending tags for a side block box.
1417 * @global object
1418 * @global object
1419 * @param array $attributes HTML attributes to apply if possible [id]
1420 * @param string $title
1421 * @deprecated
1423 function print_side_block_end($attributes = array(), $title='') {
1424 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
1428 * This was used by old code to see whether a block region had anything in it,
1429 * and hence wether that region should be printed.
1431 * We don't ever want old code to print blocks, so we now always return false.
1432 * The function only exists to avoid fatal errors in old code.
1434 * @deprecated since Moodle 2.0. always returns false.
1436 * @param object $blockmanager
1437 * @param string $region
1438 * @return bool
1440 function blocks_have_content(&$blockmanager, $region) {
1441 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
1442 return false;
1446 * This was used by old code to print the blocks in a region.
1448 * We don't ever want old code to print blocks, so this is now a no-op.
1449 * The function only exists to avoid fatal errors in old code.
1451 * @deprecated since Moodle 2.0. does nothing.
1453 * @param object $page
1454 * @param object $blockmanager
1455 * @param string $region
1457 function blocks_print_group($page, $blockmanager, $region) {
1458 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1462 * This used to be the old entry point for anyone that wants to use blocks.
1463 * Since we don't want people people dealing with blocks this way any more,
1464 * just return a suitable empty array.
1466 * @deprecated since Moodle 2.0.
1468 * @param object $page
1469 * @return array
1471 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
1472 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1473 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
1477 * This iterates over an array of blocks and calculates the preferred width
1478 * Parameter passed by reference for speed; it's not modified.
1480 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
1482 * @param mixed $instances
1484 function blocks_preferred_width($instances) {
1485 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1486 $width = 210;
1490 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1492 * @param object $page The page object
1493 * @param object $blockmanager The block manager object
1494 * @param string $blockaction One of [config, add, delete]
1495 * @param int|object $instanceorid The instance id or a block_instance object
1496 * @param bool $pinned
1497 * @param bool $redirect To redirect or not to that is the question but you should stick with true
1499 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
1500 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.');
1504 * You can use this to get the blocks to respond to URL actions without much hassle
1506 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
1508 * @param object $PAGE
1509 * @param object $blockmanager
1510 * @param bool $pinned
1512 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
1513 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
1517 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
1518 * in order to reduce code repetition.
1520 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1522 * @param $instance
1523 * @param $newpos
1524 * @param string|int $newweight
1525 * @param bool $pinned
1527 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
1528 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.');
1533 * Moves a block to the new position (column) and weight (sort order).
1535 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1537 * @param object $instance The block instance to be moved.
1538 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
1539 * @param string $destweight The destination sort order. If NULL, we add to the end
1540 * of the destination column.
1541 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
1542 * to a new position withing the pinned list. Likewise, we
1543 * can only moved non-pinned blocks to a new position within
1544 * the non-pinned list.
1545 * @return boolean success or failure
1547 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
1548 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.');
1552 * Print a nicely formatted table.
1554 * @deprecated since Moodle 2.0
1556 * @param array $table is an object with several properties.
1558 function print_table($table, $return=false) {
1559 global $OUTPUT;
1560 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
1561 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
1562 $newtable = new html_table();
1563 foreach ($table as $property => $value) {
1564 if (property_exists($newtable, $property)) {
1565 $newtable->{$property} = $value;
1568 if (isset($table->class)) {
1569 $newtable->attributes['class'] = $table->class;
1571 if (isset($table->rowclass) && is_array($table->rowclass)) {
1572 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
1573 $newtable->rowclasses = $table->rowclass;
1575 $output = html_writer::table($newtable);
1576 if ($return) {
1577 return $output;
1578 } else {
1579 echo $output;
1580 return true;
1585 * Creates and displays (or returns) a link to a popup window
1587 * @deprecated since Moodle 2.0
1589 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1590 * @param string $name Name to be assigned to the popup window (this is used by
1591 * client-side scripts to "talk" to the popup window)
1592 * @param string $linkname Text to be displayed as web link
1593 * @param int $height Height to assign to popup window
1594 * @param int $width Height to assign to popup window
1595 * @param string $title Text to be displayed as popup page title
1596 * @param string $options List of additional options for popup window
1597 * @param bool $return If true, return as a string, otherwise print
1598 * @param string $id id added to the element
1599 * @param string $class class added to the element
1600 * @return string html code to display a link to a popup window.
1602 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
1603 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');
1605 return html_writer::link($url, $name);
1609 * Creates and displays (or returns) a buttons to a popup window.
1611 * @deprecated since Moodle 2.0
1613 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1614 * @param string $name Name to be assigned to the popup window (this is used by
1615 * client-side scripts to "talk" to the popup window)
1616 * @param string $linkname Text to be displayed as web link
1617 * @param int $height Height to assign to popup window
1618 * @param int $width Height to assign to popup window
1619 * @param string $title Text to be displayed as popup page title
1620 * @param string $options List of additional options for popup window
1621 * @param bool $return If true, return as a string, otherwise print
1622 * @param string $id id added to the element
1623 * @param string $class class added to the element
1624 * @return string html code to display a link to a popup window.
1626 function button_to_popup_window ($url, $name=null, $linkname=null,
1627 $height=400, $width=500, $title=null, $options=null, $return=false,
1628 $id=null, $class=null) {
1629 global $OUTPUT;
1631 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1633 if ($options == 'none') {
1634 $options = null;
1637 if (empty($linkname)) {
1638 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
1641 // Create a single_button object
1642 $form = new single_button($url, $linkname, 'post');
1643 $form->button->title = $title;
1644 $form->button->id = $id;
1646 // Parse the $options string
1647 $popupparams = array();
1648 if (!empty($options)) {
1649 $optionsarray = explode(',', $options);
1650 foreach ($optionsarray as $option) {
1651 if (strstr($option, '=')) {
1652 $parts = explode('=', $option);
1653 if ($parts[1] == '0') {
1654 $popupparams[$parts[0]] = false;
1655 } else {
1656 $popupparams[$parts[0]] = $parts[1];
1658 } else {
1659 $popupparams[$option] = true;
1664 if (!empty($height)) {
1665 $popupparams['height'] = $height;
1667 if (!empty($width)) {
1668 $popupparams['width'] = $width;
1671 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
1672 $output = $OUTPUT->render($form);
1674 if ($return) {
1675 return $output;
1676 } else {
1677 echo $output;
1682 * Print a self contained form with a single submit button.
1684 * @deprecated since Moodle 2.0
1686 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
1687 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
1688 * @param string $label the caption that appears on the button.
1689 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
1690 * @param string $notusedanymore no longer used.
1691 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
1692 * @param string $tooltip a tooltip to add to the button as a title attribute.
1693 * @param boolean $disabled if true, the button will be disabled.
1694 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
1695 * @param string $formid The id attribute to use for the form
1696 * @return string|void Depending on the $return paramter.
1698 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
1699 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
1700 global $OUTPUT;
1702 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1704 // Cast $options to array
1705 $options = (array) $options;
1707 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
1709 if ($jsconfirmmessage) {
1710 $button->button->add_confirm_action($jsconfirmmessage);
1713 $output = $OUTPUT->render($button);
1715 if ($return) {
1716 return $output;
1717 } else {
1718 echo $output;
1723 * Print a spacer image with the option of including a line break.
1725 * @deprecated since Moodle 2.0
1727 * @global object
1728 * @param int $height The height in pixels to make the spacer
1729 * @param int $width The width in pixels to make the spacer
1730 * @param boolean $br If set to true a BR is written after the spacer
1732 function print_spacer($height=1, $width=1, $br=true, $return=false) {
1733 global $CFG, $OUTPUT;
1735 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
1737 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
1739 if ($return) {
1740 return $output;
1741 } else {
1742 echo $output;
1747 * Given the path to a picture file in a course, or a URL,
1748 * this function includes the picture in the page.
1750 * @deprecated since Moodle 2.0
1752 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
1753 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
1757 * Print the specified user's avatar.
1759 * @deprecated since Moodle 2.0
1761 * @global object
1762 * @global object
1763 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
1764 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
1765 * if at all possible, particularly for reports. It is very bad for performance.
1766 * @param int $courseid The course id. Used when constructing the link to the user's profile.
1767 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
1768 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
1769 * @param boolean $return If false print picture to current page, otherwise return the output as string
1770 * @param boolean $link enclose printed image in a link the user's profile (default true).
1771 * @param string $target link target attribute. Makes the profile open in a popup window.
1772 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
1773 * decorative images, or where the username will be printed anyway.)
1774 * @return string|void String or nothing, depending on $return.
1776 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
1777 global $OUTPUT;
1779 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
1781 if (!is_object($user)) {
1782 $userid = $user;
1783 $user = new stdClass();
1784 $user->id = $userid;
1787 if (empty($user->picture) and $picture) {
1788 $user->picture = $picture;
1791 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
1793 $output = $OUTPUT->user_picture($user, $options);
1795 if ($return) {
1796 return $output;
1797 } else {
1798 echo $output;
1803 * Print a png image.
1805 * @deprecated since Moodle 2.0: no replacement
1808 function print_png() {
1809 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
1814 * Prints a basic textarea field.
1816 * @deprecated since Moodle 2.0
1818 * When using this function, you should
1820 * @global object
1821 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
1822 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1823 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1824 * @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.
1825 * @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.
1826 * @param string $name Name to use for the textarea element.
1827 * @param string $value Initial content to display in the textarea.
1828 * @param int $obsolete deprecated
1829 * @param bool $return If false, will output string. If true, will return string value.
1830 * @param string $id CSS ID to add to the textarea element.
1831 * @return string|void depending on the value of $return
1833 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1834 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1835 /// However, you can set them to zero to override the mincols and minrows values below.
1837 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1838 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1840 global $CFG;
1842 $mincols = 65;
1843 $minrows = 10;
1844 $str = '';
1846 if ($id === '') {
1847 $id = 'edit-'.$name;
1850 if ($usehtmleditor) {
1851 if ($height && ($rows < $minrows)) {
1852 $rows = $minrows;
1854 if ($width && ($cols < $mincols)) {
1855 $cols = $mincols;
1859 if ($usehtmleditor) {
1860 editors_head_setup();
1861 $editor = editors_get_preferred_editor(FORMAT_HTML);
1862 $editor->use_editor($id, array('legacy'=>true));
1863 } else {
1864 $editorclass = '';
1867 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
1868 if ($usehtmleditor) {
1869 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1870 } else {
1871 $str .= s($value);
1873 $str .= '</textarea>'."\n";
1875 if ($return) {
1876 return $str;
1878 echo $str;
1883 * Print a help button.
1885 * @deprecated since Moodle 2.0
1887 * @param string $page The keyword that defines a help page
1888 * @param string $title The title of links, rollover tips, alt tags etc
1889 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
1890 * @param string $module Which module is the page defined in
1891 * @param mixed $image Use a help image for the link? (true/false/"both")
1892 * @param boolean $linktext If true, display the title next to the help icon.
1893 * @param string $text If defined then this text is used in the page, and
1894 * the $page variable is ignored. DEPRECATED!
1895 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
1896 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
1897 * @return string|void Depending on value of $return
1899 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
1900 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
1902 global $OUTPUT;
1904 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
1906 // hide image with CSS if needed
1908 if ($return) {
1909 return $output;
1910 } else {
1911 echo $output;
1916 * Print a help button.
1918 * Prints a special help button that is a link to the "live" emoticon popup
1920 * @todo Finish documenting this function
1922 * @global object
1923 * @global object
1924 * @param string $form ?
1925 * @param string $field ?
1926 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
1927 * @return string|void Depending on value of $return
1929 function emoticonhelpbutton($form, $field, $return = false) {
1930 /// TODO: MDL-21215
1932 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
1936 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1937 * Should be used only with htmleditor or textarea.
1939 * @global object
1940 * @global object
1941 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1942 * helpbutton.
1943 * @return string Link to help button
1945 function editorhelpbutton(){
1946 return '';
1948 /// TODO: MDL-21215
1952 * Print a help button.
1954 * Prints a special help button for html editors (htmlarea in this case)
1956 * @todo Write code into this function! detect current editor and print correct info
1957 * @global object
1958 * @return string Only returns an empty string at the moment
1960 function editorshortcutshelpbutton() {
1961 /// TODO: MDL-21215
1963 global $CFG;
1964 //TODO: detect current editor and print correct info
1965 /* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
1966 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
1968 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
1969 return '';
1974 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1975 * provide this function with the language strings for sortasc and sortdesc.
1977 * @deprecated since Moodle 2.0
1979 * TODO migrate to outputlib
1980 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1982 * @global object
1983 * @param string $direction 'up' or 'down'
1984 * @param string $strsort The language string used for the alt attribute of this image
1985 * @param bool $return Whether to print directly or return the html string
1986 * @return string|void depending on $return
1989 function print_arrow($direction='up', $strsort=null, $return=false) {
1990 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
1992 global $OUTPUT;
1994 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1995 return null;
1998 $return = null;
2000 switch ($direction) {
2001 case 'up':
2002 $sortdir = 'asc';
2003 break;
2004 case 'down':
2005 $sortdir = 'desc';
2006 break;
2007 case 'move':
2008 $sortdir = 'asc';
2009 break;
2010 default:
2011 $sortdir = null;
2012 break;
2015 // Prepare language string
2016 $strsort = '';
2017 if (empty($strsort) && !empty($sortdir)) {
2018 $strsort = get_string('sort' . $sortdir, 'grades');
2021 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
2023 if ($return) {
2024 return $return;
2025 } else {
2026 echo $return;
2031 * Returns a string containing a link to the user documentation.
2032 * Also contains an icon by default. Shown to teachers and admin only.
2034 * @deprecated since Moodle 2.0
2036 * @global object
2037 * @param string $path The page link after doc root and language, no leading slash.
2038 * @param string $text The text to be displayed for the link
2039 * @param string $iconpath The path to the icon to be displayed
2040 * @return string Either the link or an empty string
2042 function doc_link($path='', $text='', $iconpath='ignored') {
2043 global $CFG, $OUTPUT;
2045 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
2047 if (empty($CFG->docroot)) {
2048 return '';
2051 return $OUTPUT->doc_link($path, $text);
2055 * Prints a single paging bar to provide access to other pages (usually in a search)
2057 * @deprecated since Moodle 2.0
2059 * @param int $totalcount Thetotal number of entries available to be paged through
2060 * @param int $page The page you are currently viewing
2061 * @param int $perpage The number of entries that should be shown per page
2062 * @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.
2063 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
2064 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
2065 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
2066 * @param bool $return whether to return an output string or echo now
2067 * @return bool|string depending on $result
2069 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
2070 global $OUTPUT;
2072 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
2074 if (empty($nocurr)) {
2075 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
2078 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
2079 $pagingbar->pagevar = $pagevar;
2080 $output = $OUTPUT->render($pagingbar);
2082 if ($return) {
2083 return $output;
2086 echo $output;
2087 return true;
2091 * Print a message along with "Yes" and "No" links for the user to continue.
2093 * @deprecated since Moodle 2.0
2095 * @global object
2096 * @param string $message The text to display
2097 * @param string $linkyes The link to take the user to if they choose "Yes"
2098 * @param string $linkno The link to take the user to if they choose "No"
2099 * @param string $optionyes The yes option to show on the notice
2100 * @param string $optionsno The no option to show
2101 * @param string $methodyes Form action method to use if yes [post, get]
2102 * @param string $methodno Form action method to use if no [post, get]
2103 * @return void Output is echo'd
2105 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
2107 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
2109 global $OUTPUT;
2111 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
2112 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
2114 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
2118 * Prints a scale menu (as part of an existing form) including help button
2119 * @deprecated since Moodle 2.0
2121 function print_scale_menu() {
2122 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
2126 * Given an array of values, output the HTML for a select element with those options.
2128 * @deprecated since Moodle 2.0
2130 * Normally, you only need to use the first few parameters.
2132 * @param array $options The options to offer. An array of the form
2133 * $options[{value}] = {text displayed for that option};
2134 * @param string $name the name of this form control, as in &lt;select name="..." ...
2135 * @param string $selected the option to select initially, default none.
2136 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
2137 * Set this to '' if you don't want a 'nothing is selected' option.
2138 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
2139 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
2140 * @param boolean $return if false (the default) the the output is printed directly, If true, the
2141 * generated HTML is returned as a string.
2142 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
2143 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
2144 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
2145 * then a suitable one is constructed.
2146 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
2147 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
2148 * $listbox is an integer, that number is used for size instead.
2149 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
2150 * when $listbox display is enabled
2151 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
2152 * then a suitable one is constructed.
2153 * @return string|void If $return=true returns string, else echo's and returns void
2155 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
2156 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
2157 $id='', $listbox=false, $multiple=false, $class='') {
2159 global $OUTPUT;
2160 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
2162 if ($script) {
2163 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2165 $attributes = array();
2166 $attributes['disabled'] = $disabled ? 'disabled' : null;
2167 $attributes['tabindex'] = $tabindex ? $tabindex : null;
2168 $attributes['multiple'] = $multiple ? $multiple : null;
2169 $attributes['class'] = $class ? $class : null;
2170 $attributes['id'] = $id ? $id : null;
2172 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
2174 if ($return) {
2175 return $output;
2176 } else {
2177 echo $output;
2182 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
2183 * Other options like choose_from_menu.
2185 * @deprecated since Moodle 2.0
2187 * Calls {@link choose_from_menu()} with preset arguments
2188 * @see choose_from_menu()
2190 * @param string $name the name of this form control, as in &lt;select name="..." ...
2191 * @param string $selected the option to select initially, default none.
2192 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
2193 * @param boolean $return Whether this function should return a string or output it (defaults to false)
2194 * @param boolean $disabled (defaults to false)
2195 * @param int $tabindex
2196 * @return string|void If $return=true returns string, else echo's and returns void
2198 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
2199 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
2200 global $OUTPUT;
2202 if ($script) {
2203 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2206 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
2208 if ($return) {
2209 return $output;
2210 } else {
2211 echo $output;
2216 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
2217 * including option headings with the first level.
2219 * @deprecated since Moodle 2.0
2221 * This function is very similar to {@link choose_from_menu_yesno()}
2222 * and {@link choose_from_menu()}
2224 * @todo Add datatype handling to make sure $options is an array
2226 * @param array $options An array of objects to choose from
2227 * @param string $name The XHTML field name
2228 * @param string $selected The value to select by default
2229 * @param string $nothing The label for the 'nothing is selected' option.
2230 * Defaults to get_string('choose').
2231 * @param string $script If not '', then this is added to the &lt;select> element
2232 * as an onchange handler.
2233 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
2234 * @param bool $return Whether this function should return a string or output
2235 * it (defaults to false)
2236 * @param bool $disabled Is the field disabled by default
2237 * @param int|string $tabindex Override the tabindex attribute [numeric]
2238 * @return string|void If $return=true returns string, else echo's and returns void
2240 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
2241 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
2243 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
2244 global $OUTPUT;
2248 * Prints a help button about a scale
2250 * @deprecated since Moodle 2.0
2252 * @global object
2253 * @param id $courseid
2254 * @param object $scale
2255 * @param boolean $return If set to true returns rather than echo's
2256 * @return string|bool Depending on value of $return
2258 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
2259 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
2260 global $OUTPUT;
2262 $output = $OUTPUT->help_icon_scale($courseid, $scale);
2264 if ($return) {
2265 return $output;
2266 } else {
2267 echo $output;
2273 * Prints time limit value selector
2275 * @deprecated since Moodle 2.0
2277 * Uses {@link choose_from_menu()} to generate HTML
2278 * @see choose_from_menu()
2280 * @global object
2281 * @param int $timelimit default
2282 * @param string $unit
2283 * @param string $name
2284 * @param boolean $return If set to true returns rather than echo's
2285 * @return string|bool Depending on value of $return
2287 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
2288 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
2292 * Prints form items with the names $hour and $minute
2294 * @deprecated since Moodle 2.0
2296 * @param string $hour fieldname
2297 * @param string $minute fieldname
2298 * @param int $currenttime A default timestamp in GMT
2299 * @param int $step minute spacing
2300 * @param boolean $return If set to true returns rather than echo's
2301 * @return string|bool Depending on value of $return
2303 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
2304 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
2306 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
2307 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
2309 $output = $hourselector . $$minuteselector;
2311 if ($return) {
2312 return $output;
2313 } else {
2314 echo $output;
2319 * Prints form items with the names $day, $month and $year
2321 * @deprecated since Moodle 2.0
2323 * @param string $day fieldname
2324 * @param string $month fieldname
2325 * @param string $year fieldname
2326 * @param int $currenttime A default timestamp in GMT
2327 * @param boolean $return If set to true returns rather than echo's
2328 * @return string|bool Depending on value of $return
2330 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
2331 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
2333 $dayselector = html_writer::select_time('days', $day, $currenttime);
2334 $monthselector = html_writer::select_time('months', $month, $currenttime);
2335 $yearselector = html_writer::select_time('years', $year, $currenttime);
2337 $output = $dayselector . $monthselector . $yearselector;
2339 if ($return) {
2340 return $output;
2341 } else {
2342 echo $output;
2347 * Implements a complete little form with a dropdown menu.
2349 * @deprecated since Moodle 2.0
2351 * When JavaScript is on selecting an option from the dropdown automatically
2352 * submits the form (while avoiding the usual acessibility problems with this appoach).
2353 * With JavaScript off, a 'Go' button is printed.
2355 * @global object
2356 * @global object
2357 * @param string $baseurl The target URL up to the point of the variable that changes
2358 * @param array $options A list of value-label pairs for the popup list
2359 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
2360 * @param string $selected The option that is initially selected
2361 * @param string $nothing The label for the "no choice" option
2362 * @param string $help The name of a help page if help is required
2363 * @param string $helptext The name of the label for the help button
2364 * @param boolean $return Indicates whether the function should return the HTML
2365 * as a string or echo it directly to the page being rendered
2366 * @param string $targetwindow The name of the target page to open the linked page in.
2367 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
2368 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
2369 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
2370 * @param boolean $disabled If true, the menu will be displayed disabled.
2371 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
2372 * @return string|void If $return=true returns string, else echo's and returns void
2374 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
2375 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
2376 global $OUTPUT, $CFG;
2378 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
2380 if (empty($options)) {
2381 return '';
2384 $urls = array();
2386 foreach ($options as $value=>$label) {
2387 $url = $baseurl.$value;
2388 $url = str_replace($CFG->wwwroot, '', $url);
2389 $url = str_replace('&amp;', '&', $url);
2390 $urls[$url] = $label;
2391 if ($selected == $value) {
2392 $active = $url;
2396 $nothing = $nothing ? array(''=>$nothing) : null;
2398 $select = new url_select($urls, $active, $nothing, $formid);
2399 $select->disabled = $disabled;
2401 $select->set_label($selectlabel);
2402 $select->set_old_help_icon($help, $helptext);
2404 $output = $OUTPUT->render($select);
2406 if ($return) {
2407 return $output;
2408 } else {
2409 echo $output;
2414 * Prints a simple button to close a window
2416 * @deprecated since Moodle 2.0
2418 * @global object
2419 * @param string $name Name of the window to close
2420 * @param boolean $return whether this function should return a string or output it.
2421 * @param boolean $reloadopener if true, clicking the button will also reload
2422 * the page that opend this popup window.
2423 * @return string|void if $return is true, void otherwise
2425 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
2426 global $OUTPUT;
2428 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
2429 $output = $OUTPUT->close_window_button(get_string($name));
2431 if ($return) {
2432 return $output;
2433 } else {
2434 echo $output;
2439 * Given an array of values, creates a group of radio buttons to be part of a form
2441 * @deprecated since Moodle 2.0
2443 * @staticvar int $idcounter
2444 * @param array $options An array of value-label pairs for the radio group (values as keys)
2445 * @param string $name Name of the radiogroup (unique in the form)
2446 * @param string $checked The value that is already checked
2447 * @param bool $return Whether this function should return a string or output
2448 * it (defaults to false)
2449 * @return string|void If $return=true returns string, else echo's and returns void
2451 function choose_from_radio ($options, $name, $checked='', $return=false) {
2452 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
2456 * Display an standard html checkbox with an optional label
2458 * @deprecated since Moodle 2.0
2460 * @staticvar int $idcounter
2461 * @param string $name The name of the checkbox
2462 * @param string $value The valus that the checkbox will pass when checked
2463 * @param bool $checked The flag to tell the checkbox initial state
2464 * @param string $label The label to be showed near the checkbox
2465 * @param string $alt The info to be inserted in the alt tag
2466 * @param string $script If not '', then this is added to the checkbox element
2467 * as an onchange handler.
2468 * @param bool $return Whether this function should return a string or output
2469 * it (defaults to false)
2470 * @return string|void If $return=true returns string, else echo's and returns void
2472 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
2474 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
2475 global $OUTPUT;
2477 if (!empty($script)) {
2478 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
2481 $output = html_writer::checkbox($name, $value, $checked, $label);
2483 if (empty($return)) {
2484 echo $output;
2485 } else {
2486 return $output;
2493 * Display an standard html text field with an optional label
2495 * @deprecated since Moodle 2.0
2497 * @param string $name The name of the text field
2498 * @param string $value The value of the text field
2499 * @param string $alt The info to be inserted in the alt tag
2500 * @param int $size Sets the size attribute of the field. Defaults to 50
2501 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
2502 * @param bool $return Whether this function should return a string or output
2503 * it (defaults to false)
2504 * @return string|void If $return=true returns string, else echo's and returns void
2506 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
2507 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
2509 if ($alt === '') {
2510 $alt = null;
2513 $style = "width: {$size}px;";
2514 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
2515 if ($maxlength) {
2516 $attributes['maxlength'] = $maxlength;
2519 $output = html_writer::empty_tag('input', $attributes);
2521 if (empty($return)) {
2522 echo $output;
2523 } else {
2524 return $output;
2530 * Centered heading with attached help button (same title text)
2531 * and optional icon attached
2533 * @deprecated since Moodle 2.0
2535 * @param string $text The text to be displayed
2536 * @param string $helppage The help page to link to
2537 * @param string $module The module whose help should be linked to
2538 * @param string $icon Image to display if needed
2539 * @param bool $return If set to true output is returned rather than echoed, default false
2540 * @return string|void String if return=true nothing otherwise
2542 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
2544 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
2546 global $OUTPUT;
2548 // Extract the src from $icon if it exists
2549 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
2550 $icon = $matches[1];
2551 $icon = new moodle_url($icon);
2552 } else {
2553 $icon = '';
2556 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
2558 if ($return) {
2559 return $output;
2560 } else {
2561 echo $output;
2566 * Returns a turn edit on/off button for course in a self contained form.
2567 * Used to be an icon, but it's now a simple form button
2568 * @deprecated since Moodle 2.0
2570 function update_mymoodle_icon() {
2571 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
2575 * Returns a turn edit on/off button for tag in a self contained form.
2576 * @deprecated since Moodle 2.0
2577 * @param string $tagid The ID attribute
2578 * @return string
2580 function update_tag_button($tagid) {
2581 global $OUTPUT;
2582 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2583 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
2588 * Prints the 'update this xxx' button that appears on module pages.
2590 * @deprecated since Moodle 2.0
2592 * @param string $cmid the course_module id.
2593 * @param string $ignored not used any more. (Used to be courseid.)
2594 * @param string $string the module name - get_string('modulename', 'xxx')
2595 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
2597 function update_module_button($cmid, $ignored, $string) {
2598 global $CFG, $OUTPUT;
2600 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
2602 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
2604 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
2605 $string = get_string('updatethis', '', $string);
2607 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
2608 return $OUTPUT->single_button($url, $string);
2609 } else {
2610 return '';
2615 * Prints the editing button on search results listing
2616 * For bulk move courses to another category
2617 * @deprecated since Moodle 2.0
2619 function update_categories_search_button($search,$page,$perpage) {
2620 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
2624 * Prints a summary of a user in a nice little box.
2625 * @deprecated since Moodle 2.0
2627 function print_user($user, $course, $messageselect=false, $return=false) {
2628 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
2632 * Returns a turn edit on/off button for course in a self contained form.
2633 * Used to be an icon, but it's now a simple form button
2635 * Note that the caller is responsible for capchecks.
2637 * @global object
2638 * @global object
2639 * @param int $courseid The course to update by id as found in 'course' table
2640 * @return string
2642 function update_course_icon($courseid) {
2643 global $CFG, $OUTPUT;
2645 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2647 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
2651 * Prints breadcrumb trail of links, called in theme/-/header.html
2653 * This function has now been deprecated please use output's navbar method instead
2654 * as shown below
2656 * <code php>
2657 * echo $OUTPUT->navbar();
2658 * </code>
2660 * @deprecated since 2.0
2661 * @param mixed $navigation deprecated
2662 * @param string $separator OBSOLETE, and now deprecated
2663 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
2664 * @return string|void String or null, depending on $return.
2666 function print_navigation ($navigation, $separator=0, $return=false) {
2667 global $OUTPUT,$PAGE;
2669 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
2671 $output = $OUTPUT->navbar();
2673 if ($return) {
2674 return $output;
2675 } else {
2676 echo $output;
2681 * This function will build the navigation string to be used by print_header
2682 * and others.
2684 * It automatically generates the site and course level (if appropriate) links.
2686 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
2687 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
2689 * If you want to add any further navigation links after the ones this function generates,
2690 * the pass an array of extra link arrays like this:
2691 * array(
2692 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
2693 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
2695 * The normal case is to just add one further link, for example 'Editing forum' after
2696 * 'General Developer Forum', with no link.
2697 * To do that, you need to pass
2698 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
2699 * However, becuase this is a very common case, you can use a shortcut syntax, and just
2700 * pass the string 'Editing forum', instead of an array as $extranavlinks.
2702 * At the moment, the link types only have limited significance. Type 'activity' is
2703 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
2704 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
2705 * This really needs to be documented better. In the mean time, try to be consistent, it will
2706 * enable people to customise the navigation more in future.
2708 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
2709 * If you get the $cm object using the function get_coursemodule_from_instance or
2710 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
2711 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
2712 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
2713 * warning is printed in developer debug mode.
2715 * @deprecated since 2.0
2716 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
2717 * only want one extra item with no link, you can pass a string instead. If you don't want
2718 * any extra links, pass an empty string.
2719 * @param mixed $cm deprecated
2720 * @return array Navigation array
2722 function build_navigation($extranavlinks, $cm = null) {
2723 global $CFG, $COURSE, $DB, $SITE, $PAGE;
2725 if (is_array($extranavlinks) && count($extranavlinks)>0) {
2726 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
2727 foreach ($extranavlinks as $nav) {
2728 if (array_key_exists('name', $nav)) {
2729 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
2730 $link = $nav['link'];
2731 } else {
2732 $link = null;
2734 $PAGE->navbar->add($nav['name'],$link);
2739 return(array('newnav' => true, 'navlinks' => array()));
2743 * Returns a small popup menu of course activity modules
2745 * Given a course and a (current) coursemodule
2746 * his function returns a small popup menu with all the
2747 * course activity modules in it, as a navigation menu
2748 * The data is taken from the serialised array stored in
2749 * the course record
2751 * @global object
2752 * @global object
2753 * @global object
2754 * @global object
2755 * @uses CONTEXT_COURSE
2756 * @param object $course A {@link $COURSE} object.
2757 * @param object $cm A {@link $COURSE} object.
2758 * @param string $targetwindow The target window attribute to us
2759 * @return string
2761 function navmenu($course, $cm=NULL, $targetwindow='self') {
2762 // This function has been deprecated with the creation of the global nav in
2763 // moodle 2.0
2765 return '';
2769 * Returns a little popup menu for switching roles
2771 * @deprecated in Moodle 2.0
2772 * @param int $courseid The course to update by id as found in 'course' table
2773 * @return string
2775 function switchroles_form($courseid) {
2776 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
2777 return '';
2781 * Print header for admin page
2782 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
2783 * @param string $focus focus element
2785 function admin_externalpage_print_header($focus='') {
2786 global $OUTPUT;
2788 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
2790 echo $OUTPUT->header();
2794 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
2796 function admin_externalpage_print_footer() {
2797 // TODO Still 103 referernces in core code. Don't do debugging output yet.
2798 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
2799 global $OUTPUT;
2800 echo $OUTPUT->footer();
2803 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
2807 * Call this function to add an event to the calendar table and to call any calendar plugins
2809 * @param object $event An object representing an event from the calendar table.
2810 * The event will be identified by the id field. The object event should include the following:
2811 * <ul>
2812 * <li><b>$event->name</b> - Name for the event
2813 * <li><b>$event->description</b> - Description of the event (defaults to '')
2814 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
2815 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
2816 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
2817 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
2818 * <li><b>$event->modulename</b> - Name of the module that creates this event
2819 * <li><b>$event->instance</b> - Instance of the module that owns this event
2820 * <li><b>$event->eventtype</b> - The type info together with the module info could
2821 * be used by calendar plugins to decide how to display event
2822 * <li><b>$event->timestart</b>- Timestamp for start of event
2823 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
2824 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
2825 * </ul>
2826 * @return int|false The id number of the resulting record or false if failed
2828 function add_event($event) {
2829 global $CFG;
2830 require_once($CFG->dirroot.'/calendar/lib.php');
2831 $event = calendar_event::create($event);
2832 if ($event !== false) {
2833 return $event->id;
2835 return false;
2839 * Call this function to update an event in the calendar table
2840 * the event will be identified by the id field of the $event object.
2842 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2843 * @return bool Success
2845 function update_event($event) {
2846 global $CFG;
2847 require_once($CFG->dirroot.'/calendar/lib.php');
2848 $event = (object)$event;
2849 $calendarevent = calendar_event::load($event->id);
2850 return $calendarevent->update($event);
2854 * Call this function to delete the event with id $id from calendar table.
2856 * @param int $id The id of an event from the 'event' table.
2857 * @return bool
2859 function delete_event($id) {
2860 global $CFG;
2861 require_once($CFG->dirroot.'/calendar/lib.php');
2862 $event = calendar_event::load($id);
2863 return $event->delete();
2867 * Call this function to hide an event in the calendar table
2868 * the event will be identified by the id field of the $event object.
2870 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2871 * @return true
2873 function hide_event($event) {
2874 global $CFG;
2875 require_once($CFG->dirroot.'/calendar/lib.php');
2876 $event = new calendar_event($event);
2877 return $event->toggle_visibility(false);
2881 * Call this function to unhide 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 show_event($event) {
2888 global $CFG;
2889 require_once($CFG->dirroot.'/calendar/lib.php');
2890 $event = new calendar_event($event);
2891 return $event->toggle_visibility(true);
2895 * Converts string to lowercase using most compatible function available.
2897 * @deprecated Use textlib::strtolower($text) instead.
2899 * @param string $string The string to convert to all lowercase characters.
2900 * @param string $encoding The encoding on the string.
2901 * @return string
2903 function moodle_strtolower($string, $encoding='') {
2905 debugging('moodle_strtolower() is deprecated. Please use textlib::strtolower() instead.', DEBUG_DEVELOPER);
2907 //If not specified use utf8
2908 if (empty($encoding)) {
2909 $encoding = 'UTF-8';
2911 //Use text services
2912 return textlib::strtolower($string, $encoding);
2916 * Original singleton helper function, please use static methods instead,
2917 * ex: textlib::convert()
2919 * @deprecated since Moodle 2.2 use textlib::xxxx() instead
2920 * @see textlib
2921 * @return textlib instance
2923 function textlib_get_instance() {
2925 debugging('textlib_get_instance() is deprecated. Please use static calling textlib::functioname() instead.', DEBUG_DEVELOPER);
2927 return new textlib();
2931 * Gets the generic section name for a courses section
2933 * The global function is deprecated. Each course format can define their own generic section name
2935 * @deprecated since 2.4
2936 * @see get_section_name()
2937 * @see format_base::get_section_name()
2939 * @param string $format Course format ID e.g. 'weeks' $course->format
2940 * @param stdClass $section Section object from database
2941 * @return Display name that the course format prefers, e.g. "Week 2"
2943 function get_generic_section_name($format, stdClass $section) {
2944 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
2945 return get_string('sectionname', "format_$format") . ' ' . $section->section;
2949 * Returns an array of sections for the requested course id
2951 * It is usually not recommended to display the list of sections used
2952 * in course because the course format may have it's own way to do it.
2954 * If you need to just display the name of the section please call:
2955 * get_section_name($course, $section)
2956 * {@link get_section_name()}
2957 * from 2.4 $section may also be just the field course_sections.section
2959 * If you need the list of all sections it is more efficient to get this data by calling
2960 * $modinfo = get_fast_modinfo($courseorid);
2961 * $sections = $modinfo->get_section_info_all()
2962 * {@link get_fast_modinfo()}
2963 * {@link course_modinfo::get_section_info_all()}
2965 * Information about one section (instance of section_info):
2966 * get_fast_modinfo($courseorid)->get_sections_info($section)
2967 * {@link course_modinfo::get_section_info()}
2969 * @deprecated since 2.4
2971 * @param int $courseid
2972 * @return array Array of section_info objects
2974 function get_all_sections($courseid) {
2975 global $DB;
2976 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
2977 return get_fast_modinfo($courseid)->get_section_info_all();
2981 * Given a full mod object with section and course already defined, adds this module to that section.
2983 * This function is deprecated, please use {@link course_add_cm_to_section()}
2984 * Note that course_add_cm_to_section() also updates field course_modules.section and
2985 * calls rebuild_course_cache()
2987 * @deprecated since 2.4
2989 * @param object $mod
2990 * @param int $beforemod An existing ID which we will insert the new module before
2991 * @return int The course_sections ID where the mod is inserted
2993 function add_mod_to_section($mod, $beforemod = null) {
2994 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
2995 global $DB;
2996 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
3000 * Returns a number of useful structures for course displays
3002 * Function get_all_mods() is deprecated in 2.4
3003 * Instead of:
3004 * <code>
3005 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
3006 * </code>
3007 * please use:
3008 * <code>
3009 * $mods = get_fast_modinfo($courseorid)->get_cms();
3010 * $modnames = get_module_types_names();
3011 * $modnamesplural = get_module_types_names(true);
3012 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
3013 * </code>
3015 * @deprecated since 2.4
3017 * @param int $courseid id of the course to get info about
3018 * @param array $mods (return) list of course modules
3019 * @param array $modnames (return) list of names of all module types installed and available
3020 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
3021 * @param array $modnamesused (return) list of names of all module types used in the course
3023 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
3024 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
3026 global $COURSE;
3027 $modnames = get_module_types_names();
3028 $modnamesplural= get_module_types_names(true);
3029 $modinfo = get_fast_modinfo($courseid);
3030 $mods = $modinfo->get_cms();
3031 $modnamesused = $modinfo->get_used_module_names();
3035 * Returns course section - creates new if does not exist yet
3037 * This function is deprecated. To create a course section call:
3038 * course_create_sections_if_missing($courseorid, $sections);
3039 * to get the section call:
3040 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
3042 * @see course_create_sections_if_missing()
3043 * @see get_fast_modinfo()
3044 * @deprecated since 2.4
3046 * @param int $section relative section number (field course_sections.section)
3047 * @param int $courseid
3048 * @return stdClass record from table {course_sections}
3050 function get_course_section($section, $courseid) {
3051 global $DB;
3052 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
3054 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
3055 return $cw;
3057 $cw = new stdClass();
3058 $cw->course = $courseid;
3059 $cw->section = $section;
3060 $cw->summary = "";
3061 $cw->summaryformat = FORMAT_HTML;
3062 $cw->sequence = "";
3063 $id = $DB->insert_record("course_sections", $cw);
3064 rebuild_course_cache($courseid, true);
3065 return $DB->get_record("course_sections", array("id"=>$id));
3069 * Return the start and end date of the week in Weekly course format
3071 * It is not recommended to use this function outside of format_weeks plugin
3073 * @deprecated since 2.4
3074 * @see format_weeks::get_section_dates()
3076 * @param stdClass $section The course_section entry from the DB
3077 * @param stdClass $course The course entry from DB
3078 * @return stdClass property start for startdate, property end for enddate
3080 function format_weeks_get_section_dates($section, $course) {
3081 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
3082 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
3083 if (isset($course->format) && $course->format === 'weeks') {
3084 return course_get_format($course)->get_section_dates($section);
3086 return null;
3090 * Obtains shared data that is used in print_section when displaying a
3091 * course-module entry.
3093 * Deprecated. Instead of:
3094 * list($content, $name) = get_print_section_cm_text($cm, $course);
3095 * use:
3096 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
3097 * $name = $cm->get_formatted_name();
3099 * @deprecated since 2.5
3100 * @see cm_info::get_formatted_content()
3101 * @see cm_info::get_formatted_name()
3103 * This data is also used in other areas of the code.
3104 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
3105 * @param object $course (argument not used)
3106 * @return array An array with the following values in this order:
3107 * $content (optional extra content for after link),
3108 * $instancename (text of link)
3110 function get_print_section_cm_text(cm_info $cm, $course) {
3111 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
3112 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
3113 DEBUG_DEVELOPER);
3114 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
3115 $cm->get_formatted_name());
3119 * Prints the menus to add activities and resources.
3121 * Deprecated. Please use:
3122 * $courserenderer = $PAGE->get_renderer('core', 'course');
3123 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
3124 * array('inblock' => $vertical));
3125 * echo $output; // if $return argument in print_section_add_menus() set to false
3127 * @deprecated since 2.5
3128 * @see core_course_renderer::course_section_add_cm_control()
3130 * @param stdClass $course course object, must be the same as set on the page
3131 * @param int $section relative section number (field course_sections.section)
3132 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
3133 * @param bool $vertical Vertical orientation
3134 * @param bool $return Return the menus or send them to output
3135 * @param int $sectionreturn The section to link back to
3136 * @return void|string depending on $return
3138 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
3139 global $PAGE;
3140 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
3141 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
3142 $output = '';
3143 $courserenderer = $PAGE->get_renderer('core', 'course');
3144 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
3145 array('inblock' => $vertical));
3146 if ($return) {
3147 return $output;
3148 } else {
3149 echo $output;
3150 return !empty($output);
3155 * Produces the editing buttons for a module
3157 * Deprecated. Please use:
3158 * $courserenderer = $PAGE->get_renderer('core', 'course');
3159 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
3160 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
3162 * @deprecated since 2.5
3163 * @see course_get_cm_edit_actions()
3164 * @see core_course_renderer->course_section_cm_edit_actions()
3166 * @param stdClass $mod The module to produce editing buttons for
3167 * @param bool $absolute_ignored (argument ignored) - all links are absolute
3168 * @param bool $moveselect (argument ignored)
3169 * @param int $indent The current indenting
3170 * @param int $section The section to link back to
3171 * @return string XHTML for the editing buttons
3173 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
3174 global $PAGE;
3175 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
3176 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
3177 if (!($mod instanceof cm_info)) {
3178 $modinfo = get_fast_modinfo($mod->course);
3179 $mod = $modinfo->get_cm($mod->id);
3181 $actions = course_get_cm_edit_actions($mod, $indent, $section);
3183 $courserenderer = $PAGE->get_renderer('core', 'course');
3184 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
3185 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
3186 // the course page HTML will allow this to be removed.
3187 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
3191 * Prints a section full of activity modules
3193 * Deprecated. Please use:
3194 * $courserenderer = $PAGE->get_renderer('core', 'course');
3195 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
3196 * array('hidecompletion' => $hidecompletion));
3198 * @deprecated since 2.5
3199 * @see core_course_renderer::course_section_cm_list()
3201 * @param stdClass $course The course
3202 * @param stdClass|section_info $section The section object containing properties id and section
3203 * @param array $mods (argument not used)
3204 * @param array $modnamesused (argument not used)
3205 * @param bool $absolute (argument not used)
3206 * @param string $width (argument not used)
3207 * @param bool $hidecompletion Hide completion status
3208 * @param int $sectionreturn The section to return to
3209 * @return void
3211 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
3212 global $PAGE;
3213 debugging('Function print_section() is deprecated. Please use course renderer function '.
3214 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
3215 $displayoptions = array('hidecompletion' => $hidecompletion);
3216 $courserenderer = $PAGE->get_renderer('core', 'course');
3217 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
3221 * Displays the list of courses with user notes
3223 * This function is not used in core. It was replaced by block course_overview
3225 * @deprecated since 2.5
3227 * @param array $courses
3228 * @param array $remote_courses
3230 function print_overview($courses, array $remote_courses=array()) {
3231 global $CFG, $USER, $DB, $OUTPUT;
3232 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
3234 $htmlarray = array();
3235 if ($modules = $DB->get_records('modules')) {
3236 foreach ($modules as $mod) {
3237 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
3238 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
3239 $fname = $mod->name.'_print_overview';
3240 if (function_exists($fname)) {
3241 $fname($courses,$htmlarray);
3246 foreach ($courses as $course) {
3247 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
3248 echo $OUTPUT->box_start('coursebox');
3249 $attributes = array('title' => s($fullname));
3250 if (empty($course->visible)) {
3251 $attributes['class'] = 'dimmed';
3253 echo $OUTPUT->heading(html_writer::link(
3254 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
3255 if (array_key_exists($course->id,$htmlarray)) {
3256 foreach ($htmlarray[$course->id] as $modname => $html) {
3257 echo $html;
3260 echo $OUTPUT->box_end();
3263 if (!empty($remote_courses)) {
3264 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
3266 foreach ($remote_courses as $course) {
3267 echo $OUTPUT->box_start('coursebox');
3268 $attributes = array('title' => s($course->fullname));
3269 echo $OUTPUT->heading(html_writer::link(
3270 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
3271 format_string($course->shortname),
3272 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
3273 echo $OUTPUT->box_end();
3278 * This function trawls through the logs looking for
3279 * anything new since the user's last login
3281 * This function was only used to print the content of block recent_activity
3282 * All functionality is moved into class {@link block_recent_activity}
3283 * and renderer {@link block_recent_activity_renderer}
3285 * @deprecated since 2.5
3286 * @param stdClass $course
3288 function print_recent_activity($course) {
3289 // $course is an object
3290 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
3291 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
3292 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
3294 $context = context_course::instance($course->id);
3296 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
3298 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
3300 if (!isguestuser()) {
3301 if (!empty($USER->lastcourseaccess[$course->id])) {
3302 if ($USER->lastcourseaccess[$course->id] > $timestart) {
3303 $timestart = $USER->lastcourseaccess[$course->id];
3308 echo '<div class="activitydate">';
3309 echo get_string('activitysince', '', userdate($timestart));
3310 echo '</div>';
3311 echo '<div class="activityhead">';
3313 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
3315 echo "</div>\n";
3317 $content = false;
3319 /// Firstly, have there been any new enrolments?
3321 $users = get_recent_enrolments($course->id, $timestart);
3323 //Accessibility: new users now appear in an <OL> list.
3324 if ($users) {
3325 echo '<div class="newusers">';
3326 echo $OUTPUT->heading(get_string("newusers").':', 3);
3327 $content = true;
3328 echo "<ol class=\"list\">\n";
3329 foreach ($users as $user) {
3330 $fullname = fullname($user, $viewfullnames);
3331 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
3333 echo "</ol>\n</div>\n";
3336 /// Next, have there been any modifications to the course structure?
3338 $modinfo = get_fast_modinfo($course);
3340 $changelist = array();
3342 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
3343 module = 'course' AND
3344 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
3345 array($timestart, $course->id), "id ASC");
3347 if ($logs) {
3348 $actions = array('add mod', 'update mod', 'delete mod');
3349 $newgones = array(); // added and later deleted items
3350 foreach ($logs as $key => $log) {
3351 if (!in_array($log->action, $actions)) {
3352 continue;
3354 $info = explode(' ', $log->info);
3356 // note: in most cases I replaced hardcoding of label with use of
3357 // $cm->has_view() but it was not possible to do this here because
3358 // we don't necessarily have the $cm for it
3359 if ($info[0] == 'label') { // Labels are ignored in recent activity
3360 continue;
3363 if (count($info) != 2) {
3364 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
3365 continue;
3368 $modname = $info[0];
3369 $instanceid = $info[1];
3371 if ($log->action == 'delete mod') {
3372 // unfortunately we do not know if the mod was visible
3373 if (!array_key_exists($log->info, $newgones)) {
3374 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
3375 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
3377 } else {
3378 if (!isset($modinfo->instances[$modname][$instanceid])) {
3379 if ($log->action == 'add mod') {
3380 // do not display added and later deleted activities
3381 $newgones[$log->info] = true;
3383 continue;
3385 $cm = $modinfo->instances[$modname][$instanceid];
3386 if (!$cm->uservisible) {
3387 continue;
3390 if ($log->action == 'add mod') {
3391 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
3392 $changelist[$log->info] = array('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
3394 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
3395 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
3396 $changelist[$log->info] = array('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
3402 if (!empty($changelist)) {
3403 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
3404 $content = true;
3405 foreach ($changelist as $changeinfo => $change) {
3406 echo '<p class="activity">'.$change['text'].'</p>';
3410 /// Now display new things from each module
3412 $usedmodules = array();
3413 foreach($modinfo->cms as $cm) {
3414 if (isset($usedmodules[$cm->modname])) {
3415 continue;
3417 if (!$cm->uservisible) {
3418 continue;
3420 $usedmodules[$cm->modname] = $cm->modname;
3423 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
3424 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
3425 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
3426 $print_recent_activity = $modname.'_print_recent_activity';
3427 if (function_exists($print_recent_activity)) {
3428 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
3429 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
3431 } else {
3432 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
3436 if (! $content) {
3437 echo '<p class="message">'.get_string('nothingnew').'</p>';
3442 * Delete a course module and any associated data at the course level (events)
3443 * Until 1.5 this function simply marked a deleted flag ... now it
3444 * deletes it completely.
3446 * @deprecated since 2.5
3448 * @param int $id the course module id
3449 * @return boolean true on success, false on failure
3451 function delete_course_module($id) {
3452 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
3454 global $CFG, $DB;
3456 require_once($CFG->libdir.'/gradelib.php');
3457 require_once($CFG->dirroot.'/blog/lib.php');
3459 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
3460 return true;
3462 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
3463 //delete events from calendar
3464 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
3465 foreach($events as $event) {
3466 delete_event($event->id);
3469 //delete grade items, outcome items and grades attached to modules
3470 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
3471 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
3472 foreach ($grade_items as $grade_item) {
3473 $grade_item->delete('moddelete');
3476 // Delete completion and availability data; it is better to do this even if the
3477 // features are not turned on, in case they were turned on previously (these will be
3478 // very quick on an empty table)
3479 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
3480 $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id));
3481 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
3482 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
3484 delete_context(CONTEXT_MODULE, $cm->id);
3485 return $DB->delete_records('course_modules', array('id'=>$cm->id));