3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
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.
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
31 defined('MOODLE_INTERNAL') || die();
34 * Hack to find out the GD version by parsing phpinfo output
36 * @return int GD version (1, 2, or 0)
38 function check_gd_version() {
39 // TODO: delete function in Moodle 2.7
40 debugging('check_gd_version() is deprecated, GD extension is always available now');
44 if (function_exists('gd_info')){
46 if (substr_count($gd_info['GD Version'], '2.')) {
48 } else if (substr_count($gd_info['GD Version'], '1.')) {
54 phpinfo(INFO_MODULES);
55 $phpinfo = ob_get_contents();
58 $phpinfo = explode("\n", $phpinfo);
61 foreach ($phpinfo as $text) {
62 $parts = explode('</td>', $text);
63 foreach ($parts as $key => $val) {
64 $parts[$key] = trim(strip_tags($val));
66 if ($parts[0] == 'GD Version') {
67 if (substr_count($parts[1], '2.0')) {
70 $gdversion = intval($parts[1]);
75 return $gdversion; // 1, 2 or 0
79 * Not used any more, the account lockout handling is now
80 * part of authenticate_user_login().
83 function update_login_count() {
84 // TODO: delete function in Moodle 2.6
85 debugging('update_login_count() is deprecated, all calls need to be removed');
89 * Not used any more, replaced by proper account lockout.
92 function reset_login_count() {
93 // TODO: delete function in Moodle 2.6
94 debugging('reset_login_count() is deprecated, all calls need to be removed');
98 * Unsupported session id rewriting.
100 * @param string $buffer
102 function sid_ob_rewrite($buffer) {
103 throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
107 * Insert or update log display entry. Entry may already exist.
108 * $module, $action must be unique
111 * @param string $module
112 * @param string $action
113 * @param string $mtable
114 * @param string $field
118 function update_log_display_entry($module, $action, $mtable, $field) {
121 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
125 * Given some text in HTML format, this function will pass it
126 * through any filters that have been configured for this context.
128 * @deprecated use the text formatting in a standard way instead,
129 * this was abused mostly for embedding of attachments
131 * @param string $text The text to be passed through format filters
132 * @param int $courseid The current course.
133 * @return string the filtered string.
135 function filter_text($text, $courseid = NULL) {
136 global $CFG, $COURSE;
139 $courseid = $COURSE->id;
142 if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
146 return filter_manager::instance()->filter_text($text, $context);
150 * This function indicates that current page requires the https
151 * when $CFG->loginhttps enabled.
153 * By using this function properly, we can ensure 100% https-ized pages
154 * at our entire discretion (login, forgot_password, change_password)
155 * @deprecated use $PAGE->https_required() instead
157 function httpsrequired() {
159 $PAGE->https_required();
163 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
165 * @deprecated use moodle_url factory methods instead
167 * @param string $path Physical path to a file
168 * @param array $options associative array of GET variables to append to the URL
169 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
170 * @return string URL to file
172 function get_file_url($path, $options=null, $type='coursefile') {
175 $path = str_replace('//', '/', $path);
176 $path = trim($path, '/'); // no leading and trailing slashes
181 $url = $CFG->wwwroot."/question/exportfile.php";
184 $url = $CFG->wwwroot."/rss/file.php";
186 case 'httpscoursefile':
187 $url = $CFG->httpswwwroot."/file.php";
191 $url = $CFG->wwwroot."/file.php";
194 if ($CFG->slasharguments) {
195 $parts = explode('/', $path);
196 foreach ($parts as $key => $part) {
197 /// anchor dash character should not be encoded
198 $subparts = explode('#', $part);
199 $subparts = array_map('rawurlencode', $subparts);
200 $parts[$key] = implode('#', $subparts);
202 $path = implode('/', $parts);
203 $ffurl = $url.'/'.$path;
206 $path = rawurlencode('/'.$path);
207 $ffurl = $url.'?file='.$path;
208 $separator = '&';
212 foreach ($options as $name=>$value) {
213 $ffurl = $ffurl.$separator.$name.'='.$value;
214 $separator = '&';
222 * If there has been an error uploading a file, print the appropriate error message
223 * Numerical constants used as constant definitions not added until PHP version 4.2.0
224 * @deprecated removed - use new file api
226 function print_file_upload_error($filearray = '', $returnerror = false) {
227 throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
231 * Handy function for resolving file conflicts
232 * @deprecated removed - use new file api
235 function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
236 throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
240 * Checks a file name for any conflicts
241 * @deprecated removed - use new file api
243 function check_potential_filename($destination,$filename,$files) {
244 throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
248 * This function prints out a number of upload form elements.
249 * @deprecated removed - use new file api
251 function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
252 throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
256 * Return the authentication plugin title
258 * @param string $authtype plugin type
261 function auth_get_plugin_title($authtype) {
262 debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
263 return get_string('pluginname', "auth_{$authtype}");
269 * Enrol someone without using the default role in a course
272 function enrol_into_course($course, $user, $enrol) {
273 error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
277 * Returns a role object that is the default role for new enrolments in a given course
280 * @param object $course
281 * @return object returns a role or NULL if none set
283 function get_default_course_role($course) {
284 debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
286 $student = get_archetype_roles('student');
287 $student = reset($student);
293 * Extremely slow enrolled courses query.
296 function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
297 error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
301 * Was returning list of translations, use new string_manager instead
304 * @param bool $refreshcache force refreshing of lang cache
305 * @param bool $returnall ignore langlist, return all languages available
306 * @return array An associative array with contents in the form of LanguageCode => LanguageName
308 function get_list_of_languages($refreshcache=false, $returnall=false) {
309 debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
311 get_string_manager()->reset_caches();
313 return get_string_manager()->get_list_of_translations($returnall);
317 * Returns a list of currencies in the current language
321 function get_list_of_currencies() {
322 debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
323 return get_string_manager()->get_list_of_currencies();
327 * Returns a list of all enabled country names in the current translation
329 * @return array two-letter country code => translated name.
331 function get_list_of_countries() {
332 debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
333 return get_string_manager()->get_list_of_countries(false);
339 function isteacher() {
340 error('Function isteacher() was removed, please use capabilities instead!');
346 function isteacherinanycourse() {
347 throw new coding_Exception('Function isteacherinanycourse() was removed, please use capabilities instead!');
353 function get_guest() {
354 throw new coding_Exception('Function get_guest() was removed, please use capabilities instead!');
361 throw new coding_Exception('Function isguest() was removed, please use capabilities instead!');
367 function get_teacher() {
368 throw new coding_Exception('Function get_teacher() was removed, please use capabilities instead!');
372 * Return all course participant for a given course
375 * @param integer $courseid
376 * @return array of user
378 function get_course_participants($courseid) {
379 return get_enrolled_users(context_course::instance($courseid));
383 * Return true if the user is a participant for a given course
386 * @param integer $userid
387 * @param integer $courseid
390 function is_course_participant($userid, $courseid) {
391 return is_enrolled(context_course::instance($courseid), $userid);
395 * Searches logs to find all enrolments since a certain date
397 * used to print recent activity
399 * @todo MDL-36993 this function is still used in block_recent_activity, deprecate properly
401 * @uses CONTEXT_COURSE
402 * @param int $courseid The course in question.
403 * @param int $timestart The date to check forward of
404 * @return object|false {@link $USER} records or false if error.
406 function get_recent_enrolments($courseid, $timestart) {
409 $context = context_course::instance($courseid);
411 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
412 FROM {user} u, {role_assignments} ra, {log} l
415 AND l.module = 'course'
416 AND l.action = 'enrol'
417 AND ".$DB->sql_cast_char2int('l.info')." = u.id
419 AND ra.contextid ".get_related_contexts_string($context)."
420 GROUP BY u.id, u.firstname, u.lastname
421 ORDER BY MAX(l.time) ASC";
422 $params = array($timestart, $courseid);
423 return $DB->get_records_sql($sql, $params);
428 * Turn the ctx* fields in an objectlike record into a context subobject
429 * This allows us to SELECT from major tables JOINing with
430 * context at no cost, saving a ton of context lookups...
432 * Use context_instance_preload() instead.
434 * @deprecated since 2.0
438 function make_context_subobj($rec) {
439 throw new coding_Exception('make_context_subobj() was removed, use new context preloading');
443 * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
445 * Use context_instance_preload() instead.
447 * @deprecated since 2.0
448 * @param object $rec a think that has a context, for example a course,
449 * course category, course modules, etc.
450 * @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
451 * @return bool whether $rec->context looks like the correct context object
454 function is_context_subobj_valid($rec, $contextlevel) {
455 throw new coding_Exception('is_context_subobj_valid() was removed, use new context preloading');
459 * Ensure that $rec->context is present and correct before you continue
461 * When you have a record (for example a $category, $course, $user or $cm that may,
462 * or may not, have come from a place that does make_context_subobj, you can use
463 * this method to ensure that $rec->context is present and correct before you continue.
465 * Use context_instance_preload() instead.
467 * @deprecated since 2.0
468 * @param object $rec a thing that has an associated context.
469 * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
471 function ensure_context_subobj_present(&$rec, $contextlevel) {
472 throw new coding_Exception('ensure_context_subobj_present() was removed, use new context preloading');
475 ########### FROM weblib.php ##########################################################################
479 * Print a message in a standard themed box.
480 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
481 * parameters remain. If possible, $align, $width and $color should not be defined at all.
482 * Preferably just use print_box() in weblib.php
485 * @param string $message The message to display
486 * @param string $align alignment of the box, not the text (default center, left, right).
487 * @param string $width width of the box, including units %, for example '100%'.
488 * @param string $color background colour of the box, for example '#eee'.
489 * @param int $padding padding in pixels, specified without units.
490 * @param string $class space-separated class names.
491 * @param string $id space-separated id names.
492 * @param boolean $return return as string or just print it
493 * @return string|void Depending on $return
495 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
497 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
499 $output .= print_simple_box_end(true);
511 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
512 * parameters remain. If possible, $align, $width and $color should not be defined at all.
513 * Even better, please use print_box_start() in weblib.php
515 * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
516 * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
517 * @param string $color background colour of the box, for example '#eee'. DEPRECATED
518 * @param int $padding padding in pixels, specified without units. OBSOLETE
519 * @param string $class space-separated class names.
520 * @param string $id space-separated id names.
521 * @param boolean $return return as string or just print it
522 * @return string|void Depending on $return
524 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
525 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
529 $divclasses = 'box '.$class.' '.$class.'content';
533 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
535 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
536 if (substr($width, -1, 1) == '%') { // Width is a % value
537 $width = (int) substr($width, 0, -1); // Extract just the number
539 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
540 } else if ($width > 60) {
541 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
543 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
546 $divstyles .= ' width:'.$width.';'; // Last resort
549 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
550 $divstyles .= ' background:'.$color.';';
553 $divstyles = ' style="'.$divstyles.'"';
557 $id = ' id="'.$id.'"';
560 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
571 * Print the end portion of a standard themed box.
572 * Preferably just use print_box_end() in weblib.php
574 * @param boolean $return return as string or just print it
575 * @return string|void Depending on $return
577 function print_simple_box_end($return=false) {
587 * Given some text this function converted any URLs it found into HTML links
589 * This core function has been replaced with filter_urltolink since Moodle 2.0
591 * @param string $text Passed in by reference. The string to be searched for urls.
593 function convert_urls_into_links($text) {
594 debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
598 * Used to be called from help.php to inject a list of smilies into the
599 * emoticons help file.
601 * @return string HTML
603 function get_emoticons_list_for_help_file() {
604 debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
609 * Was used to replace all known smileys in the text with image equivalents
611 * This core function has been replaced with filter_emoticon since Moodle 2.0
613 function replace_smilies(&$text) {
614 debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
618 * deprecated - use clean_param($string, PARAM_FILE); instead
619 * Check for bad characters ?
621 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
623 * @param string $string ?
624 * @param int $allowdots ?
627 function detect_munged_arguments($string, $allowdots=1) {
628 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
631 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
634 if (empty($string) or $string == '/') {
643 * Unzip one zip file to a destination dir
644 * Both parameters must be FULL paths
645 * If destination isn't specified, it will be the
646 * SAME directory where the zip file resides.
649 * @param string $zipfile The zip file to unzip
650 * @param string $destination The location to unzip to
651 * @param bool $showstatus_ignored Unused
653 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
656 //Extract everything from zipfile
657 $path_parts = pathinfo(cleardoubleslashes($zipfile));
658 $zippath = $path_parts["dirname"]; //The path of the zip file
659 $zipfilename = $path_parts["basename"]; //The name of the zip file
660 $extension = $path_parts["extension"]; //The extension of the file
663 if (empty($zipfilename)) {
667 //If no extension, error
668 if (empty($extension)) {
673 $zipfile = cleardoubleslashes($zipfile);
675 //Check zipfile exists
676 if (!file_exists($zipfile)) {
680 //If no destination, passed let's go with the same directory
681 if (empty($destination)) {
682 $destination = $zippath;
686 $destpath = rtrim(cleardoubleslashes($destination), "/");
688 //Check destination path exists
689 if (!is_dir($destpath)) {
693 $packer = get_file_packer('application/zip');
695 $result = $packer->extract_to_pathname($zipfile, $destpath);
697 if ($result === false) {
701 foreach ($result as $status) {
702 if ($status !== true) {
711 * Zip an array of files/dirs to a destination zip file
712 * Both parameters must be FULL paths to the files/dirs
715 * @param array $originalfiles Files to zip
716 * @param string $destination The destination path
717 * @return bool Outcome
719 function zip_files ($originalfiles, $destination) {
722 //Extract everything from destination
723 $path_parts = pathinfo(cleardoubleslashes($destination));
724 $destpath = $path_parts["dirname"]; //The path of the zip file
725 $destfilename = $path_parts["basename"]; //The name of the zip file
726 $extension = $path_parts["extension"]; //The extension of the file
729 if (empty($destfilename)) {
733 //If no extension, add it
734 if (empty($extension)) {
736 $destfilename = $destfilename.'.'.$extension;
739 //Check destination path exists
740 if (!is_dir($destpath)) {
744 //Check destination path is writable. TODO!!
746 //Clean destination filename
747 $destfilename = clean_filename($destfilename);
749 //Now check and prepare every file
753 foreach ($originalfiles as $file) { //Iterate over each file
754 //Check for every file
755 $tempfile = cleardoubleslashes($file); // no doubleslashes!
756 //Calculate the base path for all files if it isn't set
757 if ($origpath === NULL) {
758 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
760 //See if the file is readable
761 if (!is_readable($tempfile)) { //Is readable
764 //See if the file/dir is in the same directory than the rest
765 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
768 //Add the file to the array
769 $files[] = $tempfile;
773 $start = strlen($origpath)+1;
774 foreach($files as $file) {
775 $zipfiles[substr($file, $start)] = $file;
778 $packer = get_file_packer('application/zip');
780 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
783 /////////////////////////////////////////////////////////////
784 /// Old functions not used anymore - candidates for removal
785 /////////////////////////////////////////////////////////////
788 /** various deprecated groups function **/
792 * Get the IDs for the user's groups in the given course.
795 * @param int $courseid The course being examined - the 'course' table id field.
796 * @return array|bool An _array_ of groupids, or false
797 * (Was return $groupids[0] - consequences!)
799 function mygroupid($courseid) {
801 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
802 return array_keys($groups);
810 * Returns the current group mode for a given course or activity module
812 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
814 * @param object $course Course Object
815 * @param object $cm Course Manager Object
816 * @return mixed $course->groupmode
818 function groupmode($course, $cm=null) {
820 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
821 return $cm->groupmode;
823 return $course->groupmode;
827 * Sets the current group in the session variable
828 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
829 * Sets currentgroup[$courseid] in the session variable appropriately.
830 * Does not do any permission checking.
833 * @param int $courseid The course being examined - relates to id field in
835 * @param int $groupid The group being examined.
836 * @return int Current group id which was set by this function
838 function set_current_group($courseid, $groupid) {
840 return $SESSION->currentgroup[$courseid] = $groupid;
845 * Gets the current group - either from the session variable or from the database.
848 * @param int $courseid The course being examined - relates to id field in
850 * @param bool $full If true, the return value is a full record object.
851 * If false, just the id of the record.
854 function get_current_group($courseid, $full = false) {
857 if (isset($SESSION->currentgroup[$courseid])) {
859 return groups_get_group($SESSION->currentgroup[$courseid]);
861 return $SESSION->currentgroup[$courseid];
865 $mygroupid = mygroupid($courseid);
866 if (is_array($mygroupid)) {
867 $mygroupid = array_shift($mygroupid);
868 set_current_group($courseid, $mygroupid);
870 return groups_get_group($mygroupid);
885 * Inndicates fatal error. This function was originally printing the
886 * error message directly, since 2.0 it is throwing exception instead.
887 * The error printing is handled in default exception handler.
889 * Old method, don't call directly in new code - use print_error instead.
891 * @param string $message The message to display to the user about the error.
892 * @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.
893 * @return void, always throws moodle_exception
895 function error($message, $link='') {
896 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
900 //////////////////////////
901 /// removed functions ////
902 //////////////////////////
907 * @param mixed $editorhidebuttons
909 * @return void Throws an error and does nothing
911 function use_html_editor($name='', $editorhidebuttons='', $id='') {
912 error('use_html_editor() not available anymore');
916 * The old method that was used to include JavaScript libraries.
917 * Please use $PAGE->requires->js_module() instead.
919 * @param mixed $lib The library or libraries to load (a string or array of strings)
920 * There are three way to specify the library:
921 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
922 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
923 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
924 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
926 function require_js($lib) {
927 throw new coding_exception('require_js() was removed, use new JS api');
931 * Makes an upload directory for a particular module.
933 * This function has been deprecated by the file API changes in Moodle 2.0.
936 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
937 * @return string|false Returns full path to directory if successful, false if not
939 function make_mod_upload_directory($courseid) {
940 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
944 * Used to be used for setting up the theme. No longer used by core code, and
945 * should not have been used elsewhere.
947 * The theme is now automatically initialised before it is first used. If you really need
948 * to force this to happen, just reference $PAGE->theme.
950 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
951 * However, I can't think of any valid reason to do that outside the theme selector UI.
954 * @param string $theme The theme to use defaults to current theme
955 * @param array $params An array of parameters to use
957 function theme_setup($theme = '', $params=NULL) {
958 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
959 'The current theme gets initialised automatically before it is first used.');
963 * @deprecated use $PAGE->theme->name instead.
964 * @return string the name of the current theme.
966 function current_theme() {
968 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
969 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
970 return $PAGE->theme->name;
974 * Prints some red text using echo
977 * @param string $error The text to be displayed in red
979 function formerr($error) {
980 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
982 echo $OUTPUT->error_text($error);
986 * Return the markup for the destination of the 'Skip to main content' links.
987 * Accessibility improvement for keyboard-only users.
989 * Used in course formats, /index.php and /course/index.php
991 * @deprecated use $OUTPUT->skip_link_target() in instead.
992 * @return string HTML element.
994 function skip_main_destination() {
996 return $OUTPUT->skip_link_target();
1000 * Prints a string in a specified size (retained for backward compatibility)
1003 * @param string $text The text to be displayed
1004 * @param int $size The size to set the font for text display.
1005 * @param bool $return If set to true output is returned rather than echoed Default false
1006 * @return string|void String if return is true
1008 function print_headline($text, $size=2, $return=false) {
1010 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
1011 $output = $OUTPUT->heading($text, $size);
1020 * Prints text in a format for use in headings.
1023 * @param string $text The text to be displayed
1024 * @param string $deprecated No longer used. (Use to do alignment.)
1025 * @param int $size The size to set the font for text display.
1026 * @param string $class
1027 * @param bool $return If set to true output is returned rather than echoed, default false
1028 * @param string $id The id to use in the element
1029 * @return string|void String if return=true nothing otherwise
1031 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
1033 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
1034 if (!empty($deprecated)) {
1035 debugging('Use of deprecated align attribute of print_heading. ' .
1036 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
1038 $output = $OUTPUT->heading($text, $size, $class, $id);
1047 * Output a standard heading block
1050 * @param string $heading The text to write into the heading
1051 * @param string $class An additional Class Attr to use for the heading
1052 * @param bool $return If set to true output is returned rather than echoed, default false
1053 * @return string|void HTML String if return=true nothing otherwise
1055 function print_heading_block($heading, $class='', $return=false) {
1057 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
1058 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
1067 * Print a message in a standard themed box.
1068 * Replaces print_simple_box (see deprecatedlib.php)
1071 * @param string $message, the content of the box
1072 * @param string $classes, space-separated class names.
1073 * @param string $ids
1074 * @param boolean $return, return as string or just print it
1075 * @return string|void mixed string or void
1077 function print_box($message, $classes='generalbox', $ids='', $return=false) {
1079 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
1080 $output = $OUTPUT->box($message, $classes, $ids);
1089 * Starts a box using divs
1090 * Replaces print_simple_box_start (see deprecatedlib.php)
1093 * @param string $classes, space-separated class names.
1094 * @param string $ids
1095 * @param boolean $return, return as string or just print it
1096 * @return string|void string or void
1098 function print_box_start($classes='generalbox', $ids='', $return=false) {
1100 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
1101 $output = $OUTPUT->box_start($classes, $ids);
1110 * Simple function to end a box (see above)
1111 * Replaces print_simple_box_end (see deprecatedlib.php)
1114 * @param boolean $return, return as string or just print it
1115 * @return string|void Depending on value of return
1117 function print_box_end($return=false) {
1119 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
1120 $output = $OUTPUT->box_end();
1129 * Print a message in a standard themed container.
1132 * @param string $message, the content of the container
1133 * @param boolean $clearfix clear both sides
1134 * @param string $classes, space-separated class names.
1135 * @param string $idbase
1136 * @param boolean $return, return as string or just print it
1137 * @return string|void Depending on value of $return
1139 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1142 $classes .= ' clearfix';
1144 $output = $OUTPUT->container($message, $classes, $idbase);
1153 * Starts a container using divs
1156 * @param boolean $clearfix clear both sides
1157 * @param string $classes, space-separated class names.
1158 * @param string $idbase
1159 * @param boolean $return, return as string or just print it
1160 * @return string|void Based on value of $return
1162 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1165 $classes .= ' clearfix';
1167 $output = $OUTPUT->container_start($classes, $idbase);
1176 * Deprecated, now handled automatically in themes
1178 function check_theme_arrows() {
1179 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
1183 * Simple function to end a container (see above)
1186 * @param boolean $return, return as string or just print it
1187 * @return string|void Based on $return
1189 function print_container_end($return=false) {
1191 $output = $OUTPUT->container_end();
1200 * Print a bold message in an optional color.
1202 * @deprecated use $OUTPUT->notification instead.
1203 * @param string $message The message to print out
1204 * @param string $style Optional style to display message text in
1205 * @param string $align Alignment option
1206 * @param bool $return whether to return an output string or echo now
1207 * @return string|bool Depending on $result
1209 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1212 if ($classes == 'green') {
1213 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1214 $classes = 'notifysuccess'; // Backward compatible with old color system
1217 $output = $OUTPUT->notification($message, $classes);
1226 * Print a continue button that goes to a particular URL.
1228 * @deprecated since Moodle 2.0
1230 * @param string $link The url to create a link to.
1231 * @param bool $return If set to true output is returned rather than echoed, default false
1232 * @return string|void HTML String if return=true nothing otherwise
1234 function print_continue($link, $return = false) {
1235 global $CFG, $OUTPUT;
1238 if (!empty($_SERVER['HTTP_REFERER'])) {
1239 $link = $_SERVER['HTTP_REFERER'];
1240 $link = str_replace('&', '&', $link); // make it valid XHTML
1242 $link = $CFG->wwwroot .'/';
1246 $output = $OUTPUT->continue_button($link);
1255 * Print a standard header
1257 * @param string $title Appears at the top of the window
1258 * @param string $heading Appears at the top of the page
1259 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1260 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1261 * @param string $meta Meta tags to be added to the header
1262 * @param boolean $cache Should this page be cacheable?
1263 * @param string $button HTML code for a button (usually for module editing)
1264 * @param string $menu HTML code for a popup menu
1265 * @param boolean $usexml use XML for this page
1266 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1267 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1268 * @return string|void If return=true then string else void
1270 function print_header($title='', $heading='', $navigation='', $focus='',
1271 $meta='', $cache=true, $button=' ', $menu=null,
1272 $usexml=false, $bodytags='', $return=false) {
1273 global $PAGE, $OUTPUT;
1275 $PAGE->set_title($title);
1276 $PAGE->set_heading($heading);
1277 $PAGE->set_cacheable($cache);
1278 if ($button == '') {
1281 $PAGE->set_button($button);
1282 $PAGE->set_headingmenu($menu);
1287 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1288 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1291 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1294 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1297 $output = $OUTPUT->header();
1307 * This version of print_header is simpler because the course name does not have to be
1308 * provided explicitly in the strings. It can be used on the site page as in courses
1309 * Eventually all print_header could be replaced by print_header_simple
1311 * @deprecated since Moodle 2.0
1312 * @param string $title Appears at the top of the window
1313 * @param string $heading Appears at the top of the page
1314 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1315 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1316 * @param string $meta Meta tags to be added to the header
1317 * @param boolean $cache Should this page be cacheable?
1318 * @param string $button HTML code for a button (usually for module editing)
1319 * @param string $menu HTML code for a popup menu
1320 * @param boolean $usexml use XML for this page
1321 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1322 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1323 * @return string|void If $return=true the return string else nothing
1325 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1326 $cache=true, $button=' ', $menu='', $usexml=false, $bodytags='', $return=false) {
1328 global $COURSE, $CFG, $PAGE, $OUTPUT;
1331 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1332 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1335 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1338 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1341 $PAGE->set_title($title);
1342 $PAGE->set_heading($heading);
1343 $PAGE->set_cacheable(true);
1344 $PAGE->set_button($button);
1346 $output = $OUTPUT->header();
1355 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
1356 global $PAGE, $OUTPUT;
1357 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
1358 // TODO check arguments.
1359 if (is_string($course)) {
1360 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
1361 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
1362 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
1363 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
1365 if (!is_null($usercourse)) {
1366 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
1367 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
1369 $output = $OUTPUT->footer();
1378 * Returns text to be displayed to the user which reflects their login status
1384 * @uses CONTEXT_COURSE
1385 * @param course $course {@link $COURSE} object containing course information
1386 * @param user $user {@link $USER} object containing user information
1387 * @return string HTML
1389 function user_login_string($course='ignored', $user='ignored') {
1390 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
1395 * Prints a nice side block with an optional header. The content can either
1396 * be a block of HTML or a list of text with optional icons.
1398 * @todo Finish documenting this function. Show example of various attributes, etc.
1400 * @static int $block_id Increments for each call to the function
1401 * @param string $heading HTML for the heading. Can include full HTML or just
1402 * plain text - plain text will automatically be enclosed in the appropriate
1404 * @param string $content HTML for the content
1405 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1406 * @param array $icons optional icons for the things in $list.
1407 * @param string $footer Extra HTML content that gets output at the end, inside a <div class="footer">
1408 * @param array $attributes an array of attribute => value pairs that are put on the
1409 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1410 * already a class, class='block' is used.
1411 * @param string $title Plain text title, as embedded in the $heading.
1414 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1417 // We don't use $heading, becuse it often contains HTML that we don't want.
1418 // However, sometimes $title is not set, but $heading is.
1419 if (empty($title)) {
1420 $title = strip_tags($heading);
1423 // Render list contents to HTML if required.
1424 if (empty($content) && $list) {
1425 $content = $OUTPUT->list_block_contents($icons, $list);
1428 $bc = new block_contents();
1429 $bc->content = $content;
1430 $bc->footer = $footer;
1431 $bc->title = $title;
1433 if (isset($attributes['id'])) {
1434 $bc->id = $attributes['id'];
1435 unset($attributes['id']);
1437 $bc->attributes = $attributes;
1439 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1443 * Starts a nice side block with an optional header.
1445 * @todo Finish documenting this function
1449 * @param string $heading HTML for the heading. Can include full HTML or just
1450 * plain text - plain text will automatically be enclosed in the appropriate
1452 * @param array $attributes HTML attributes to apply if possible
1455 function print_side_block_start($heading='', $attributes = array()) {
1456 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
1460 * Print table ending tags for a side block box.
1464 * @param array $attributes HTML attributes to apply if possible [id]
1465 * @param string $title
1468 function print_side_block_end($attributes = array(), $title='') {
1469 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
1473 * This was used by old code to see whether a block region had anything in it,
1474 * and hence wether that region should be printed.
1476 * We don't ever want old code to print blocks, so we now always return false.
1477 * The function only exists to avoid fatal errors in old code.
1479 * @deprecated since Moodle 2.0. always returns false.
1481 * @param object $blockmanager
1482 * @param string $region
1485 function blocks_have_content(&$blockmanager, $region) {
1486 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
1491 * This was used by old code to print the blocks in a region.
1493 * We don't ever want old code to print blocks, so this is now a no-op.
1494 * The function only exists to avoid fatal errors in old code.
1496 * @deprecated since Moodle 2.0. does nothing.
1498 * @param object $page
1499 * @param object $blockmanager
1500 * @param string $region
1502 function blocks_print_group($page, $blockmanager, $region) {
1503 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1507 * This used to be the old entry point for anyone that wants to use blocks.
1508 * Since we don't want people people dealing with blocks this way any more,
1509 * just return a suitable empty array.
1511 * @deprecated since Moodle 2.0.
1513 * @param object $page
1516 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
1517 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1518 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
1522 * This iterates over an array of blocks and calculates the preferred width
1523 * Parameter passed by reference for speed; it's not modified.
1525 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
1527 * @param mixed $instances
1529 function blocks_preferred_width($instances) {
1530 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1535 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1537 * @param object $page The page object
1538 * @param object $blockmanager The block manager object
1539 * @param string $blockaction One of [config, add, delete]
1540 * @param int|object $instanceorid The instance id or a block_instance object
1541 * @param bool $pinned
1542 * @param bool $redirect To redirect or not to that is the question but you should stick with true
1544 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
1545 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.');
1549 * You can use this to get the blocks to respond to URL actions without much hassle
1551 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
1553 * @param object $PAGE
1554 * @param object $blockmanager
1555 * @param bool $pinned
1557 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
1558 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
1562 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
1563 * in order to reduce code repetition.
1565 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1569 * @param string|int $newweight
1570 * @param bool $pinned
1572 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
1573 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.');
1578 * Moves a block to the new position (column) and weight (sort order).
1580 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1582 * @param object $instance The block instance to be moved.
1583 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
1584 * @param string $destweight The destination sort order. If NULL, we add to the end
1585 * of the destination column.
1586 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
1587 * to a new position withing the pinned list. Likewise, we
1588 * can only moved non-pinned blocks to a new position within
1589 * the non-pinned list.
1590 * @return boolean success or failure
1592 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
1593 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.');
1597 * Print a nicely formatted table.
1599 * @deprecated since Moodle 2.0
1601 * @param array $table is an object with several properties.
1603 function print_table($table, $return=false) {
1605 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
1606 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
1607 $newtable = new html_table();
1608 foreach ($table as $property => $value) {
1609 if (property_exists($newtable, $property)) {
1610 $newtable->{$property} = $value;
1613 if (isset($table->class)) {
1614 $newtable->attributes['class'] = $table->class;
1616 if (isset($table->rowclass) && is_array($table->rowclass)) {
1617 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
1618 $newtable->rowclasses = $table->rowclass;
1620 $output = html_writer::table($newtable);
1630 * Creates and displays (or returns) a link to a popup window
1632 * @deprecated since Moodle 2.0
1634 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1635 * @param string $name Name to be assigned to the popup window (this is used by
1636 * client-side scripts to "talk" to the popup window)
1637 * @param string $linkname Text to be displayed as web link
1638 * @param int $height Height to assign to popup window
1639 * @param int $width Height to assign to popup window
1640 * @param string $title Text to be displayed as popup page title
1641 * @param string $options List of additional options for popup window
1642 * @param bool $return If true, return as a string, otherwise print
1643 * @param string $id id added to the element
1644 * @param string $class class added to the element
1645 * @return string html code to display a link to a popup window.
1647 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
1648 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');
1650 return html_writer::link($url, $name);
1654 * Creates and displays (or returns) a buttons to a popup window.
1656 * @deprecated since Moodle 2.0
1658 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1659 * @param string $name Name to be assigned to the popup window (this is used by
1660 * client-side scripts to "talk" to the popup window)
1661 * @param string $linkname Text to be displayed as web link
1662 * @param int $height Height to assign to popup window
1663 * @param int $width Height to assign to popup window
1664 * @param string $title Text to be displayed as popup page title
1665 * @param string $options List of additional options for popup window
1666 * @param bool $return If true, return as a string, otherwise print
1667 * @param string $id id added to the element
1668 * @param string $class class added to the element
1669 * @return string html code to display a link to a popup window.
1671 function button_to_popup_window ($url, $name=null, $linkname=null,
1672 $height=400, $width=500, $title=null, $options=null, $return=false,
1673 $id=null, $class=null) {
1676 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1678 if ($options == 'none') {
1682 if (empty($linkname)) {
1683 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
1686 // Create a single_button object
1687 $form = new single_button($url, $linkname, 'post');
1688 $form->button->title = $title;
1689 $form->button->id = $id;
1691 // Parse the $options string
1692 $popupparams = array();
1693 if (!empty($options)) {
1694 $optionsarray = explode(',', $options);
1695 foreach ($optionsarray as $option) {
1696 if (strstr($option, '=')) {
1697 $parts = explode('=', $option);
1698 if ($parts[1] == '0') {
1699 $popupparams[$parts[0]] = false;
1701 $popupparams[$parts[0]] = $parts[1];
1704 $popupparams[$option] = true;
1709 if (!empty($height)) {
1710 $popupparams['height'] = $height;
1712 if (!empty($width)) {
1713 $popupparams['width'] = $width;
1716 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
1717 $output = $OUTPUT->render($form);
1727 * Print a self contained form with a single submit button.
1729 * @deprecated since Moodle 2.0
1731 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
1732 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
1733 * @param string $label the caption that appears on the button.
1734 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
1735 * @param string $notusedanymore no longer used.
1736 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
1737 * @param string $tooltip a tooltip to add to the button as a title attribute.
1738 * @param boolean $disabled if true, the button will be disabled.
1739 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
1740 * @param string $formid The id attribute to use for the form
1741 * @return string|void Depending on the $return paramter.
1743 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
1744 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
1747 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1749 // Cast $options to array
1750 $options = (array) $options;
1752 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
1754 if ($jsconfirmmessage) {
1755 $button->button->add_confirm_action($jsconfirmmessage);
1758 $output = $OUTPUT->render($button);
1768 * Print a spacer image with the option of including a line break.
1770 * @deprecated since Moodle 2.0
1773 * @param int $height The height in pixels to make the spacer
1774 * @param int $width The width in pixels to make the spacer
1775 * @param boolean $br If set to true a BR is written after the spacer
1777 function print_spacer($height=1, $width=1, $br=true, $return=false) {
1778 global $CFG, $OUTPUT;
1780 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
1782 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
1792 * Given the path to a picture file in a course, or a URL,
1793 * this function includes the picture in the page.
1795 * @deprecated since Moodle 2.0
1797 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
1798 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
1802 * Print the specified user's avatar.
1804 * @deprecated since Moodle 2.0
1808 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
1809 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
1810 * if at all possible, particularly for reports. It is very bad for performance.
1811 * @param int $courseid The course id. Used when constructing the link to the user's profile.
1812 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
1813 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
1814 * @param boolean $return If false print picture to current page, otherwise return the output as string
1815 * @param boolean $link enclose printed image in a link the user's profile (default true).
1816 * @param string $target link target attribute. Makes the profile open in a popup window.
1817 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
1818 * decorative images, or where the username will be printed anyway.)
1819 * @return string|void String or nothing, depending on $return.
1821 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
1824 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
1826 if (!is_object($user)) {
1828 $user = new stdClass();
1829 $user->id = $userid;
1832 if (empty($user->picture) and $picture) {
1833 $user->picture = $picture;
1836 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
1838 $output = $OUTPUT->user_picture($user, $options);
1848 * Print a png image.
1850 * @deprecated since Moodle 2.0: no replacement
1853 function print_png() {
1854 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
1859 * Prints a basic textarea field.
1861 * @deprecated since Moodle 2.0
1863 * When using this function, you should
1866 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
1867 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1868 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1869 * @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.
1870 * @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.
1871 * @param string $name Name to use for the textarea element.
1872 * @param string $value Initial content to display in the textarea.
1873 * @param int $obsolete deprecated
1874 * @param bool $return If false, will output string. If true, will return string value.
1875 * @param string $id CSS ID to add to the textarea element.
1876 * @return string|void depending on the value of $return
1878 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1879 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1880 /// However, you can set them to zero to override the mincols and minrows values below.
1882 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1883 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1892 $id = 'edit-'.$name;
1895 if ($usehtmleditor) {
1896 if ($height && ($rows < $minrows)) {
1899 if ($width && ($cols < $mincols)) {
1904 if ($usehtmleditor) {
1905 editors_head_setup();
1906 $editor = editors_get_preferred_editor(FORMAT_HTML);
1907 $editor->use_editor($id, array('legacy'=>true));
1912 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
1913 if ($usehtmleditor) {
1914 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1918 $str .= '</textarea>'."\n";
1928 * Print a help button.
1930 * @deprecated since Moodle 2.0
1932 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
1933 throw new coding_exception('helpbutton() can not be used any more, please see $OUTPUT->help_icon().');
1937 * Print a help button.
1939 * Prints a special help button that is a link to the "live" emoticon popup
1941 * @todo Finish documenting this function
1945 * @param string $form ?
1946 * @param string $field ?
1947 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
1948 * @return string|void Depending on value of $return
1950 function emoticonhelpbutton($form, $field, $return = false) {
1953 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
1957 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1958 * Should be used only with htmleditor or textarea.
1962 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1964 * @return string Link to help button
1966 function editorhelpbutton(){
1973 * Print a help button.
1975 * Prints a special help button for html editors (htmlarea in this case)
1977 * @todo Write code into this function! detect current editor and print correct info
1979 * @return string Only returns an empty string at the moment
1981 function editorshortcutshelpbutton() {
1985 //TODO: detect current editor and print correct info
1991 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1992 * provide this function with the language strings for sortasc and sortdesc.
1994 * @deprecated since Moodle 2.0
1996 * TODO migrate to outputlib
1997 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
2000 * @param string $direction 'up' or 'down'
2001 * @param string $strsort The language string used for the alt attribute of this image
2002 * @param bool $return Whether to print directly or return the html string
2003 * @return string|void depending on $return
2006 function print_arrow($direction='up', $strsort=null, $return=false) {
2007 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
2011 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
2017 switch ($direction) {
2032 // Prepare language string
2034 if (empty($strsort) && !empty($sortdir)) {
2035 $strsort = get_string('sort' . $sortdir, 'grades');
2038 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
2048 * Returns a string containing a link to the user documentation.
2049 * Also contains an icon by default. Shown to teachers and admin only.
2051 * @deprecated since Moodle 2.0
2053 function doc_link($path='', $text='', $iconpath='ignored') {
2054 throw new coding_exception('doc_link() can not be used any more, please see $OUTPUT->doc_link().');
2058 * Prints a single paging bar to provide access to other pages (usually in a search)
2060 * @deprecated since Moodle 2.0
2062 * @param int $totalcount Thetotal number of entries available to be paged through
2063 * @param int $page The page you are currently viewing
2064 * @param int $perpage The number of entries that should be shown per page
2065 * @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.
2066 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
2067 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
2068 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
2069 * @param bool $return whether to return an output string or echo now
2070 * @return bool|string depending on $result
2072 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
2075 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
2077 if (empty($nocurr)) {
2078 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
2081 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
2082 $pagingbar->pagevar = $pagevar;
2083 $output = $OUTPUT->render($pagingbar);
2094 * Print a message along with "Yes" and "No" links for the user to continue.
2096 * @deprecated since Moodle 2.0
2099 * @param string $message The text to display
2100 * @param string $linkyes The link to take the user to if they choose "Yes"
2101 * @param string $linkno The link to take the user to if they choose "No"
2102 * @param string $optionyes The yes option to show on the notice
2103 * @param string $optionsno The no option to show
2104 * @param string $methodyes Form action method to use if yes [post, get]
2105 * @param string $methodno Form action method to use if no [post, get]
2106 * @return void Output is echo'd
2108 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
2110 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
2114 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
2115 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
2117 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
2121 * Prints a scale menu (as part of an existing form) including help button
2122 * @deprecated since Moodle 2.0
2124 function print_scale_menu() {
2125 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
2129 * Given an array of values, output the HTML for a select element with those options.
2131 * @deprecated since Moodle 2.0
2133 * Normally, you only need to use the first few parameters.
2135 * @param array $options The options to offer. An array of the form
2136 * $options[{value}] = {text displayed for that option};
2137 * @param string $name the name of this form control, as in <select name="..." ...
2138 * @param string $selected the option to select initially, default none.
2139 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
2140 * Set this to '' if you don't want a 'nothing is selected' option.
2141 * @param string $script if not '', then this is added to the <select> element as an onchange handler.
2142 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
2143 * @param boolean $return if false (the default) the the output is printed directly, If true, the
2144 * generated HTML is returned as a string.
2145 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
2146 * @param int $tabindex if give, sets the tabindex attribute on the <select> element. Default none.
2147 * @param string $id value to use for the id attribute of the <select> element. If none is given,
2148 * then a suitable one is constructed.
2149 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
2150 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
2151 * $listbox is an integer, that number is used for size instead.
2152 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
2153 * when $listbox display is enabled
2154 * @param string $class value to use for the class attribute of the <select> element. If none is given,
2155 * then a suitable one is constructed.
2156 * @return string|void If $return=true returns string, else echo's and returns void
2158 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
2159 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
2160 $id='', $listbox=false, $multiple=false, $class='') {
2163 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
2166 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2168 $attributes = array();
2169 $attributes['disabled'] = $disabled ? 'disabled' : null;
2170 $attributes['tabindex'] = $tabindex ? $tabindex : null;
2171 $attributes['multiple'] = $multiple ? $multiple : null;
2172 $attributes['class'] = $class ? $class : null;
2173 $attributes['id'] = $id ? $id : null;
2175 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
2185 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
2186 * Other options like choose_from_menu.
2188 * @deprecated since Moodle 2.0
2190 * Calls {@link choose_from_menu()} with preset arguments
2191 * @see choose_from_menu()
2193 * @param string $name the name of this form control, as in <select name="..." ...
2194 * @param string $selected the option to select initially, default none.
2195 * @param string $script if not '', then this is added to the <select> element as an onchange handler.
2196 * @param boolean $return Whether this function should return a string or output it (defaults to false)
2197 * @param boolean $disabled (defaults to false)
2198 * @param int $tabindex
2199 * @return string|void If $return=true returns string, else echo's and returns void
2201 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
2202 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
2206 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2209 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
2219 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
2220 * including option headings with the first level.
2222 * @deprecated since Moodle 2.0
2224 * This function is very similar to {@link choose_from_menu_yesno()}
2225 * and {@link choose_from_menu()}
2227 * @todo Add datatype handling to make sure $options is an array
2229 * @param array $options An array of objects to choose from
2230 * @param string $name The XHTML field name
2231 * @param string $selected The value to select by default
2232 * @param string $nothing The label for the 'nothing is selected' option.
2233 * Defaults to get_string('choose').
2234 * @param string $script If not '', then this is added to the <select> element
2235 * as an onchange handler.
2236 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
2237 * @param bool $return Whether this function should return a string or output
2238 * it (defaults to false)
2239 * @param bool $disabled Is the field disabled by default
2240 * @param int|string $tabindex Override the tabindex attribute [numeric]
2241 * @return string|void If $return=true returns string, else echo's and returns void
2243 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
2244 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
2246 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
2251 * Prints a help button about a scale
2253 * @deprecated since Moodle 2.0
2256 * @param id $courseid
2257 * @param object $scale
2258 * @param boolean $return If set to true returns rather than echo's
2259 * @return string|bool Depending on value of $return
2261 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
2262 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
2265 $output = $OUTPUT->help_icon_scale($courseid, $scale);
2276 * Prints time limit value selector
2278 * @deprecated since Moodle 2.0
2280 * Uses {@link choose_from_menu()} to generate HTML
2281 * @see choose_from_menu()
2284 * @param int $timelimit default
2285 * @param string $unit
2286 * @param string $name
2287 * @param boolean $return If set to true returns rather than echo's
2288 * @return string|bool Depending on value of $return
2290 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
2291 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
2295 * Prints form items with the names $hour and $minute
2297 * @deprecated since Moodle 2.0
2299 * @param string $hour fieldname
2300 * @param string $minute fieldname
2301 * @param int $currenttime A default timestamp in GMT
2302 * @param int $step minute spacing
2303 * @param boolean $return If set to true returns rather than echo's
2304 * @return string|bool Depending on value of $return
2306 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
2307 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
2309 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
2310 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
2312 $output = $hourselector . $$minuteselector;
2322 * Prints form items with the names $day, $month and $year
2324 * @deprecated since Moodle 2.0
2326 * @param string $day fieldname
2327 * @param string $month fieldname
2328 * @param string $year fieldname
2329 * @param int $currenttime A default timestamp in GMT
2330 * @param boolean $return If set to true returns rather than echo's
2331 * @return string|bool Depending on value of $return
2333 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
2334 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
2336 $dayselector = html_writer::select_time('days', $day, $currenttime);
2337 $monthselector = html_writer::select_time('months', $month, $currenttime);
2338 $yearselector = html_writer::select_time('years', $year, $currenttime);
2340 $output = $dayselector . $monthselector . $yearselector;
2350 * Implements a complete little form with a dropdown menu.
2352 * @deprecated since Moodle 2.0
2354 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
2355 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
2356 throw new coding_exception('popup_form() can not be used any more, please see $OUTPUT->single_select or $OUTPUT->url_select().');
2360 * Prints a simple button to close a window
2362 * @deprecated since Moodle 2.0
2365 * @param string $name Name of the window to close
2366 * @param boolean $return whether this function should return a string or output it.
2367 * @param boolean $reloadopener if true, clicking the button will also reload
2368 * the page that opend this popup window.
2369 * @return string|void if $return is true, void otherwise
2371 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
2374 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
2375 $output = $OUTPUT->close_window_button(get_string($name));
2385 * Given an array of values, creates a group of radio buttons to be part of a form
2387 * @deprecated since Moodle 2.0
2389 * @staticvar int $idcounter
2390 * @param array $options An array of value-label pairs for the radio group (values as keys)
2391 * @param string $name Name of the radiogroup (unique in the form)
2392 * @param string $checked The value that is already checked
2393 * @param bool $return Whether this function should return a string or output
2394 * it (defaults to false)
2395 * @return string|void If $return=true returns string, else echo's and returns void
2397 function choose_from_radio ($options, $name, $checked='', $return=false) {
2398 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
2402 * Display an standard html checkbox with an optional label
2404 * @deprecated since Moodle 2.0
2406 * @staticvar int $idcounter
2407 * @param string $name The name of the checkbox
2408 * @param string $value The valus that the checkbox will pass when checked
2409 * @param bool $checked The flag to tell the checkbox initial state
2410 * @param string $label The label to be showed near the checkbox
2411 * @param string $alt The info to be inserted in the alt tag
2412 * @param string $script If not '', then this is added to the checkbox element
2413 * as an onchange handler.
2414 * @param bool $return Whether this function should return a string or output
2415 * it (defaults to false)
2416 * @return string|void If $return=true returns string, else echo's and returns void
2418 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
2420 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
2423 if (!empty($script)) {
2424 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
2427 $output = html_writer::checkbox($name, $value, $checked, $label);
2429 if (empty($return)) {
2439 * Display an standard html text field with an optional label
2441 * @deprecated since Moodle 2.0
2443 * @param string $name The name of the text field
2444 * @param string $value The value of the text field
2445 * @param string $alt The info to be inserted in the alt tag
2446 * @param int $size Sets the size attribute of the field. Defaults to 50
2447 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
2448 * @param bool $return Whether this function should return a string or output
2449 * it (defaults to false)
2450 * @return string|void If $return=true returns string, else echo's and returns void
2452 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
2453 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
2459 $style = "width: {$size}px;";
2460 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
2462 $attributes['maxlength'] = $maxlength;
2465 $output = html_writer::empty_tag('input', $attributes);
2467 if (empty($return)) {
2476 * Centered heading with attached help button (same title text)
2477 * and optional icon attached
2479 * @deprecated since Moodle 2.0
2481 * @param string $text The text to be displayed
2482 * @param string $helppage The help page to link to
2483 * @param string $module The module whose help should be linked to
2484 * @param string $icon Image to display if needed
2485 * @param bool $return If set to true output is returned rather than echoed, default false
2486 * @return string|void String if return=true nothing otherwise
2488 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
2490 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
2494 // Extract the src from $icon if it exists
2495 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
2496 $icon = $matches[1];
2497 $icon = new moodle_url($icon);
2502 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
2512 * Returns a turn edit on/off button for course in a self contained form.
2513 * Used to be an icon, but it's now a simple form button
2514 * @deprecated since Moodle 2.0
2516 function update_mymoodle_icon() {
2517 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
2521 * Returns a turn edit on/off button for tag in a self contained form.
2522 * @deprecated since Moodle 2.0
2523 * @param string $tagid The ID attribute
2526 function update_tag_button($tagid) {
2528 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2529 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
2534 * Prints the 'update this xxx' button that appears on module pages.
2536 * @deprecated since Moodle 2.0
2538 * @param string $cmid the course_module id.
2539 * @param string $ignored not used any more. (Used to be courseid.)
2540 * @param string $string the module name - get_string('modulename', 'xxx')
2541 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
2543 function update_module_button($cmid, $ignored, $string) {
2544 global $CFG, $OUTPUT;
2546 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
2548 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
2550 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
2551 $string = get_string('updatethis', '', $string);
2553 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
2554 return $OUTPUT->single_button($url, $string);
2561 * Prints the editing button on search results listing
2562 * For bulk move courses to another category
2563 * @deprecated since Moodle 2.0
2565 function update_categories_search_button($search,$page,$perpage) {
2566 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
2570 * Prints a summary of a user in a nice little box.
2571 * @deprecated since Moodle 2.0
2573 function print_user($user, $course, $messageselect=false, $return=false) {
2574 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
2578 * Returns a turn edit on/off button for course in a self contained form.
2579 * Used to be an icon, but it's now a simple form button
2581 * Note that the caller is responsible for capchecks.
2585 * @param int $courseid The course to update by id as found in 'course' table
2588 function update_course_icon($courseid) {
2589 global $CFG, $OUTPUT;
2591 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2593 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
2597 * Prints breadcrumb trail of links, called in theme/-/header.html
2599 * This function has now been deprecated please use output's navbar method instead
2603 * echo $OUTPUT->navbar();
2606 * @deprecated since 2.0
2607 * @param mixed $navigation deprecated
2608 * @param string $separator OBSOLETE, and now deprecated
2609 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
2610 * @return string|void String or null, depending on $return.
2612 function print_navigation ($navigation, $separator=0, $return=false) {
2613 global $OUTPUT,$PAGE;
2615 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
2617 $output = $OUTPUT->navbar();
2627 * This function will build the navigation string to be used by print_header
2630 * It automatically generates the site and course level (if appropriate) links.
2632 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
2633 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
2635 * If you want to add any further navigation links after the ones this function generates,
2636 * the pass an array of extra link arrays like this:
2638 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
2639 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
2641 * The normal case is to just add one further link, for example 'Editing forum' after
2642 * 'General Developer Forum', with no link.
2643 * To do that, you need to pass
2644 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
2645 * However, becuase this is a very common case, you can use a shortcut syntax, and just
2646 * pass the string 'Editing forum', instead of an array as $extranavlinks.
2648 * At the moment, the link types only have limited significance. Type 'activity' is
2649 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
2650 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
2651 * This really needs to be documented better. In the mean time, try to be consistent, it will
2652 * enable people to customise the navigation more in future.
2654 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
2655 * If you get the $cm object using the function get_coursemodule_from_instance or
2656 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
2657 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
2658 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
2659 * warning is printed in developer debug mode.
2661 * @deprecated since 2.0
2662 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
2663 * only want one extra item with no link, you can pass a string instead. If you don't want
2664 * any extra links, pass an empty string.
2665 * @param mixed $cm deprecated
2666 * @return array Navigation array
2668 function build_navigation($extranavlinks, $cm = null) {
2669 global $CFG, $COURSE, $DB, $SITE, $PAGE;
2671 if (is_array($extranavlinks) && count($extranavlinks)>0) {
2672 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
2673 foreach ($extranavlinks as $nav) {
2674 if (array_key_exists('name', $nav)) {
2675 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
2676 $link = $nav['link'];
2680 $PAGE->navbar->add($nav['name'],$link);
2685 return(array('newnav' => true, 'navlinks' => array()));
2689 * Returns a small popup menu of course activity modules
2691 * Given a course and a (current) coursemodule
2692 * his function returns a small popup menu with all the
2693 * course activity modules in it, as a navigation menu
2694 * The data is taken from the serialised array stored in
2701 * @uses CONTEXT_COURSE
2702 * @param object $course A {@link $COURSE} object.
2703 * @param object $cm A {@link $COURSE} object.
2704 * @param string $targetwindow The target window attribute to us
2707 function navmenu($course, $cm=NULL, $targetwindow='self') {
2708 // This function has been deprecated with the creation of the global nav in
2715 * Returns a little popup menu for switching roles
2717 * @deprecated in Moodle 2.0
2718 * @param int $courseid The course to update by id as found in 'course' table
2721 function switchroles_form($courseid) {
2722 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
2727 * Print header for admin page
2728 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
2729 * @param string $focus focus element
2731 function admin_externalpage_print_header($focus='') {
2734 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
2736 echo $OUTPUT->header();
2740 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
2742 function admin_externalpage_print_footer() {
2743 // TODO Still 103 referernces in core code. Don't do debugging output yet.
2744 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
2746 echo $OUTPUT->footer();
2749 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
2753 * Call this function to add an event to the calendar table and to call any calendar plugins
2755 * @param object $event An object representing an event from the calendar table.
2756 * The event will be identified by the id field. The object event should include the following:
2758 * <li><b>$event->name</b> - Name for the event
2759 * <li><b>$event->description</b> - Description of the event (defaults to '')
2760 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
2761 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
2762 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
2763 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
2764 * <li><b>$event->modulename</b> - Name of the module that creates this event
2765 * <li><b>$event->instance</b> - Instance of the module that owns this event
2766 * <li><b>$event->eventtype</b> - The type info together with the module info could
2767 * be used by calendar plugins to decide how to display event
2768 * <li><b>$event->timestart</b>- Timestamp for start of event
2769 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
2770 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
2772 * @return int|false The id number of the resulting record or false if failed
2774 function add_event($event) {
2776 require_once($CFG->dirroot.'/calendar/lib.php');
2777 $event = calendar_event::create($event);
2778 if ($event !== false) {
2785 * Call this function to update an event in the calendar table
2786 * the event will be identified by the id field of the $event object.
2788 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2789 * @return bool Success
2791 function update_event($event) {
2793 require_once($CFG->dirroot.'/calendar/lib.php');
2794 $event = (object)$event;
2795 $calendarevent = calendar_event::load($event->id);
2796 return $calendarevent->update($event);
2800 * Call this function to delete the event with id $id from calendar table.
2802 * @param int $id The id of an event from the 'event' table.
2805 function delete_event($id) {
2807 require_once($CFG->dirroot.'/calendar/lib.php');
2808 $event = calendar_event::load($id);
2809 return $event->delete();
2813 * Call this function to hide an event in the calendar table
2814 * the event will be identified by the id field of the $event object.
2816 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2819 function hide_event($event) {
2821 require_once($CFG->dirroot.'/calendar/lib.php');
2822 $event = new calendar_event($event);
2823 return $event->toggle_visibility(false);
2827 * Call this function to unhide an event in the calendar table
2828 * the event will be identified by the id field of the $event object.
2830 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2833 function show_event($event) {
2835 require_once($CFG->dirroot.'/calendar/lib.php');
2836 $event = new calendar_event($event);
2837 return $event->toggle_visibility(true);
2841 * Converts string to lowercase using most compatible function available.
2843 * @deprecated Use textlib::strtolower($text) instead.
2845 * @param string $string The string to convert to all lowercase characters.
2846 * @param string $encoding The encoding on the string.
2849 function moodle_strtolower($string, $encoding='') {
2851 debugging('moodle_strtolower() is deprecated. Please use textlib::strtolower() instead.', DEBUG_DEVELOPER);
2853 //If not specified use utf8
2854 if (empty($encoding)) {
2855 $encoding = 'UTF-8';
2858 return textlib::strtolower($string, $encoding);
2862 * Original singleton helper function, please use static methods instead,
2863 * ex: textlib::convert()
2865 * @deprecated since Moodle 2.2 use textlib::xxxx() instead
2867 * @return textlib instance
2869 function textlib_get_instance() {
2871 debugging('textlib_get_instance() is deprecated. Please use static calling textlib::functioname() instead.', DEBUG_DEVELOPER);
2873 return new textlib();
2877 * Gets the generic section name for a courses section
2879 * The global function is deprecated. Each course format can define their own generic section name
2881 * @deprecated since 2.4
2882 * @see get_section_name()
2883 * @see format_base::get_section_name()
2885 * @param string $format Course format ID e.g. 'weeks' $course->format
2886 * @param stdClass $section Section object from database
2887 * @return Display name that the course format prefers, e.g. "Week 2"
2889 function get_generic_section_name($format, stdClass $section) {
2890 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
2891 return get_string('sectionname', "format_$format") . ' ' . $section->section;
2895 * Returns an array of sections for the requested course id
2897 * It is usually not recommended to display the list of sections used
2898 * in course because the course format may have it's own way to do it.
2900 * If you need to just display the name of the section please call:
2901 * get_section_name($course, $section)
2902 * {@link get_section_name()}
2903 * from 2.4 $section may also be just the field course_sections.section
2905 * If you need the list of all sections it is more efficient to get this data by calling
2906 * $modinfo = get_fast_modinfo($courseorid);
2907 * $sections = $modinfo->get_section_info_all()
2908 * {@link get_fast_modinfo()}
2909 * {@link course_modinfo::get_section_info_all()}
2911 * Information about one section (instance of section_info):
2912 * get_fast_modinfo($courseorid)->get_sections_info($section)
2913 * {@link course_modinfo::get_section_info()}
2915 * @deprecated since 2.4
2917 * @param int $courseid
2918 * @return array Array of section_info objects
2920 function get_all_sections($courseid) {
2922 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
2923 return get_fast_modinfo($courseid)->get_section_info_all();
2927 * Given a full mod object with section and course already defined, adds this module to that section.
2929 * This function is deprecated, please use {@link course_add_cm_to_section()}
2930 * Note that course_add_cm_to_section() also updates field course_modules.section and
2931 * calls rebuild_course_cache()
2933 * @deprecated since 2.4
2935 * @param object $mod
2936 * @param int $beforemod An existing ID which we will insert the new module before
2937 * @return int The course_sections ID where the mod is inserted
2939 function add_mod_to_section($mod, $beforemod = null) {
2940 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
2942 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
2946 * Returns a number of useful structures for course displays
2948 * Function get_all_mods() is deprecated in 2.4
2951 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
2955 * $mods = get_fast_modinfo($courseorid)->get_cms();
2956 * $modnames = get_module_types_names();
2957 * $modnamesplural = get_module_types_names(true);
2958 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
2961 * @deprecated since 2.4
2963 * @param int $courseid id of the course to get info about
2964 * @param array $mods (return) list of course modules
2965 * @param array $modnames (return) list of names of all module types installed and available
2966 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
2967 * @param array $modnamesused (return) list of names of all module types used in the course
2969 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
2970 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
2973 $modnames = get_module_types_names();
2974 $modnamesplural= get_module_types_names(true);
2975 $modinfo = get_fast_modinfo($courseid);
2976 $mods = $modinfo->get_cms();
2977 $modnamesused = $modinfo->get_used_module_names();
2981 * Returns course section - creates new if does not exist yet
2983 * This function is deprecated. To create a course section call:
2984 * course_create_sections_if_missing($courseorid, $sections);
2985 * to get the section call:
2986 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
2988 * @see course_create_sections_if_missing()
2989 * @see get_fast_modinfo()
2990 * @deprecated since 2.4
2992 * @param int $section relative section number (field course_sections.section)
2993 * @param int $courseid
2994 * @return stdClass record from table {course_sections}
2996 function get_course_section($section, $courseid) {
2998 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
3000 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
3003 $cw = new stdClass();
3004 $cw->course = $courseid;
3005 $cw->section = $section;
3007 $cw->summaryformat = FORMAT_HTML;
3009 $id = $DB->insert_record("course_sections", $cw);
3010 rebuild_course_cache($courseid, true);
3011 return $DB->get_record("course_sections", array("id"=>$id));
3015 * Return the start and end date of the week in Weekly course format
3017 * It is not recommended to use this function outside of format_weeks plugin
3019 * @deprecated since 2.4
3020 * @see format_weeks::get_section_dates()
3022 * @param stdClass $section The course_section entry from the DB
3023 * @param stdClass $course The course entry from DB
3024 * @return stdClass property start for startdate, property end for enddate
3026 function format_weeks_get_section_dates($section, $course) {
3027 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
3028 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
3029 if (isset($course->format) && $course->format === 'weeks') {
3030 return course_get_format($course)->get_section_dates($section);
3036 * Obtains shared data that is used in print_section when displaying a
3037 * course-module entry.
3039 * Deprecated. Instead of:
3040 * list($content, $name) = get_print_section_cm_text($cm, $course);
3042 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
3043 * $name = $cm->get_formatted_name();
3045 * @deprecated since 2.5
3046 * @see cm_info::get_formatted_content()
3047 * @see cm_info::get_formatted_name()
3049 * This data is also used in other areas of the code.
3050 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
3051 * @param object $course (argument not used)
3052 * @return array An array with the following values in this order:
3053 * $content (optional extra content for after link),
3054 * $instancename (text of link)
3056 function get_print_section_cm_text(cm_info $cm, $course) {
3057 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
3058 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
3060 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
3061 $cm->get_formatted_name());
3065 * Prints the menus to add activities and resources.
3067 * Deprecated. Please use:
3068 * $courserenderer = $PAGE->get_renderer('core', 'course');
3069 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
3070 * array('inblock' => $vertical));
3071 * echo $output; // if $return argument in print_section_add_menus() set to false
3073 * @deprecated since 2.5
3074 * @see core_course_renderer::course_section_add_cm_control()
3076 * @param stdClass $course course object, must be the same as set on the page
3077 * @param int $section relative section number (field course_sections.section)
3078 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
3079 * @param bool $vertical Vertical orientation
3080 * @param bool $return Return the menus or send them to output
3081 * @param int $sectionreturn The section to link back to
3082 * @return void|string depending on $return
3084 function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
3086 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
3087 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
3089 $courserenderer = $PAGE->get_renderer('core', 'course');
3090 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
3091 array('inblock' => $vertical));
3096 return !empty($output);
3101 * Produces the editing buttons for a module
3103 * Deprecated. Please use:
3104 * $courserenderer = $PAGE->get_renderer('core', 'course');
3105 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
3106 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
3108 * @deprecated since 2.5
3109 * @see course_get_cm_edit_actions()
3110 * @see core_course_renderer->course_section_cm_edit_actions()
3112 * @param stdClass $mod The module to produce editing buttons for
3113 * @param bool $absolute_ignored (argument ignored) - all links are absolute
3114 * @param bool $moveselect (argument ignored)
3115 * @param int $indent The current indenting
3116 * @param int $section The section to link back to
3117 * @return string XHTML for the editing buttons
3119 function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
3121 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
3122 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
3123 if (!($mod instanceof cm_info)) {
3124 $modinfo = get_fast_modinfo($mod->course);
3125 $mod = $modinfo->get_cm($mod->id);
3127 $actions = course_get_cm_edit_actions($mod, $indent, $section);
3129 $courserenderer = $PAGE->get_renderer('core', 'course');
3130 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
3131 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
3132 // the course page HTML will allow this to be removed.
3133 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
3137 * Prints a section full of activity modules
3139 * Deprecated. Please use:
3140 * $courserenderer = $PAGE->get_renderer('core', 'course');
3141 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
3142 * array('hidecompletion' => $hidecompletion));
3144 * @deprecated since 2.5
3145 * @see core_course_renderer::course_section_cm_list()
3147 * @param stdClass $course The course
3148 * @param stdClass|section_info $section The section object containing properties id and section
3149 * @param array $mods (argument not used)
3150 * @param array $modnamesused (argument not used)
3151 * @param bool $absolute (argument not used)
3152 * @param string $width (argument not used)
3153 * @param bool $hidecompletion Hide completion status
3154 * @param int $sectionreturn The section to return to
3157 function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
3159 debugging('Function print_section() is deprecated. Please use course renderer function '.
3160 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
3161 $displayoptions = array('hidecompletion' => $hidecompletion);
3162 $courserenderer = $PAGE->get_renderer('core', 'course');
3163 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
3167 * Displays the list of courses with user notes
3169 * This function is not used in core. It was replaced by block course_overview
3171 * @deprecated since 2.5
3173 * @param array $courses
3174 * @param array $remote_courses
3176 function print_overview($courses, array $remote_courses=array()) {
3177 global $CFG, $USER, $DB, $OUTPUT;
3178 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
3180 $htmlarray = array();
3181 if ($modules = $DB->get_records('modules')) {
3182 foreach ($modules as $mod) {
3183 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
3184 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
3185 $fname = $mod->name.'_print_overview';
3186 if (function_exists($fname)) {
3187 $fname($courses,$htmlarray);
3192 foreach ($courses as $course) {
3193 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
3194 echo $OUTPUT->box_start('coursebox');
3195 $attributes = array('title' => s($fullname));
3196 if (empty($course->visible)) {
3197 $attributes['class'] = 'dimmed';
3199 echo $OUTPUT->heading(html_writer::link(
3200 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
3201 if (array_key_exists($course->id,$htmlarray)) {
3202 foreach ($htmlarray[$course->id] as $modname => $html) {
3206 echo $OUTPUT->box_end();
3209 if (!empty($remote_courses)) {
3210 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
3212 foreach ($remote_courses as $course) {
3213 echo $OUTPUT->box_start('coursebox');
3214 $attributes = array('title' => s($course->fullname));
3215 echo $OUTPUT->heading(html_writer::link(
3216 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
3217 format_string($course->shortname),
3218 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
3219 echo $OUTPUT->box_end();
3224 * This function trawls through the logs looking for
3225 * anything new since the user's last login
3227 * This function was only used to print the content of block recent_activity
3228 * All functionality is moved into class {@link block_recent_activity}
3229 * and renderer {@link block_recent_activity_renderer}
3231 * @deprecated since 2.5
3232 * @param stdClass $course
3234 function print_recent_activity($course) {
3235 // $course is an object
3236 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
3237 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
3238 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
3240 $context = context_course::instance($course->id);
3242 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
3244 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
3246 if (!isguestuser()) {
3247 if (!empty($USER->lastcourseaccess[$course->id])) {
3248 if ($USER->lastcourseaccess[$course->id] > $timestart) {
3249 $timestart = $USER->lastcourseaccess[$course->id];
3254 echo '<div class="activitydate">';
3255 echo get_string('activitysince', '', userdate($timestart));
3257 echo '<div class="activityhead">';
3259 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
3265 /// Firstly, have there been any new enrolments?
3267 $users = get_recent_enrolments($course->id, $timestart);
3269 //Accessibility: new users now appear in an <OL> list.
3271 echo '<div class="newusers">';
3272 echo $OUTPUT->heading(get_string("newusers").':', 3);
3274 echo "<ol class=\"list\">\n";
3275 foreach ($users as $user) {
3276 $fullname = fullname($user, $viewfullnames);
3277 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\">$fullname</a></li>\n";
3279 echo "</ol>\n</div>\n";
3282 /// Next, have there been any modifications to the course structure?
3284 $modinfo = get_fast_modinfo($course);
3286 $changelist = array();
3288 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
3289 module = 'course' AND
3290 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
3291 array($timestart, $course->id), "id ASC");
3294 $actions = array('add mod', 'update mod', 'delete mod');
3295 $newgones = array(); // added and later deleted items
3296 foreach ($logs as $key => $log) {
3297 if (!in_array($log->action, $actions)) {
3300 $info = explode(' ', $log->info);
3302 // note: in most cases I replaced hardcoding of label with use of
3303 // $cm->has_view() but it was not possible to do this here because
3304 // we don't necessarily have the $cm for it
3305 if ($info[0] == 'label') { // Labels are ignored in recent activity
3309 if (count($info) != 2) {
3310 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
3314 $modname = $info[0];
3315 $instanceid = $info[1];
3317 if ($log->action == 'delete mod') {
3318 // unfortunately we do not know if the mod was visible
3319 if (!array_key_exists($log->info, $newgones)) {
3320 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
3321 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
3324 if (!isset($modinfo->instances[$modname][$instanceid])) {
3325 if ($log->action == 'add mod') {
3326 // do not display added and later deleted activities
3327 $newgones[$log->info] = true;
3331 $cm = $modinfo->instances[$modname][$instanceid];
3332 if (!$cm->uservisible) {
3336 if ($log->action == 'add mod') {
3337 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
3338 $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>");
3340 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
3341 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
3342 $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>");
3348 if (!empty($changelist)) {
3349 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
3351 foreach ($changelist as $changeinfo => $change) {
3352 echo '<p class="activity">'.$change['text'].'</p>';
3356 /// Now display new things from each module
3358 $usedmodules = array();
3359 foreach($modinfo->cms as $cm) {
3360 if (isset($usedmodules[$cm->modname])) {
3363 if (!$cm->uservisible) {
3366 $usedmodules[$cm->modname] = $cm->modname;
3369 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
3370 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
3371 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
3372 $print_recent_activity = $modname.'_print_recent_activity';
3373 if (function_exists($print_recent_activity)) {
3374 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
3375 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
3378 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
3383 echo '<p class="message">'.get_string('nothingnew').'</p>';
3388 * Delete a course module and any associated data at the course level (events)
3389 * Until 1.5 this function simply marked a deleted flag ... now it
3390 * deletes it completely.
3392 * @deprecated since 2.5
3394 * @param int $id the course module id
3395 * @return boolean true on success, false on failure
3397 function delete_course_module($id) {
3398 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
3402 require_once($CFG->libdir.'/gradelib.php');
3403 require_once($CFG->dirroot.'/blog/lib.php');
3405 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
3408 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
3409 //delete events from calendar
3410 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
3411 foreach($events as $event) {
3412 delete_event($event->id);
3415 //delete grade items, outcome items and grades attached to modules
3416 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
3417 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
3418 foreach ($grade_items as $grade_item) {
3419 $grade_item->delete('moddelete');
3422 // Delete completion and availability data; it is better to do this even if the
3423 // features are not turned on, in case they were turned on previously (these will be
3424 // very quick on an empty table)
3425 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
3426 $DB->delete_records('course_modules_availability', array('coursemoduleid'=> $cm->id));
3427 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
3428 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
3430 delete_context(CONTEXT_MODULE, $cm->id);
3431 return $DB->delete_records('course_modules', array('id'=>$cm->id));
3435 * Prints the turn editing on/off button on course/index.php or course/category.php.
3437 * @deprecated since 2.5
3439 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
3440 * @return string HTML of the editing button, or empty string, if this user is not allowed
3443 function update_category_button($categoryid = 0) {
3444 global $CFG, $PAGE, $OUTPUT;
3445 debugging('Function update_category_button() is deprecated. Pages to view '.
3446 'and edit courses are now separate and no longer depend on editing mode.',
3449 // Check permissions.
3450 if (!can_edit_in_category($categoryid)) {
3454 // Work out the appropriate action.
3455 if ($PAGE->user_is_editing()) {
3456 $label = get_string('turneditingoff');
3459 $label = get_string('turneditingon');
3463 // Generate the button HTML.
3464 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
3466 $options['id'] = $categoryid;
3467 $page = 'category.php';
3469 $page = 'index.php';
3471 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
3475 * This function recursively travels the categories, building up a nice list
3476 * for display. It also makes an array that list all the parents for each
3479 * For example, if you have a tree of categories like:
3480 * Miscellaneous (id = 1)
3481 * Subcategory (id = 2)
3482 * Sub-subcategory (id = 4)
3483 * Other category (id = 3)
3484 * Then after calling this function you will have
3485 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
3486 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
3487 * 3 => 'Other category');
3488 * $parents = array(2 => array(1), 4 => array(1, 2));
3490 * If you specify $requiredcapability, then only categories where the current
3491 * user has that capability will be added to $list, although all categories
3492 * will still be added to $parents, and if you only have $requiredcapability
3493 * in a child category, not the parent, then the child catgegory will still be
3496 * If you specify the option $excluded, then that category, and all its children,
3497 * are omitted from the tree. This is useful when you are doing something like
3498 * moving categories, where you do not want to allow people to move a category
3499 * to be the child of itself.
3501 * This function is deprecated! For list of categories use
3502 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
3503 * For parents of one particular category use
3504 * coursecat::get($id)->get_parents()
3506 * @deprecated since 2.5
3508 * @param array $list For output, accumulates an array categoryid => full category path name
3509 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
3510 * @param string/array $requiredcapability if given, only categories where the current
3511 * user has this capability will be added to $list. Can also be an array of capabilities,
3512 * in which case they are all required.
3513 * @param integer $excludeid Omit this category and its children from the lists built.
3514 * @param object $category Not used
3515 * @param string $path Not used
3517 function make_categories_list(&$list, &$parents, $requiredcapability = '',
3518 $excludeid = 0, $category = NULL, $path = "") {
3520 require_once($CFG->libdir.'/coursecatlib.php');
3522 debugging('Global function make_categories_list() is deprecated. Please use '.
3523 'coursecat::make_categories_list() and coursecat::get_parents()',
3526 // For categories list use just this one function:
3530 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
3532 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
3533 // Usually user needs only parents for one particular category, in which case should be used:
3534 // coursecat::get($categoryid)->get_parents()
3535 if (empty($parents)) {
3538 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
3539 foreach ($all as $record) {
3540 if ($record->parent) {
3541 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
3543 $parents[$record->id] = array();
3549 * Delete category, but move contents to another category.
3551 * This function is deprecated. Please use
3552 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
3554 * @see coursecat::delete_move()
3555 * @deprecated since 2.5
3557 * @param object $category
3558 * @param int $newparentid category id
3559 * @return bool status
3561 function category_delete_move($category, $newparentid, $showfeedback=true) {
3563 require_once($CFG->libdir.'/coursecatlib.php');
3565 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
3567 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
3571 * Recursively delete category including all subcategories and courses.
3573 * This function is deprecated. Please use
3574 * coursecat::get($category->id)->delete_full($showfeedback);
3576 * @see coursecat::delete_full()
3577 * @deprecated since 2.5
3579 * @param stdClass $category
3580 * @param boolean $showfeedback display some notices
3581 * @return array return deleted courses
3583 function category_delete_full($category, $showfeedback=true) {
3585 require_once($CFG->libdir.'/coursecatlib.php');
3587 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
3589 return coursecat::get($category->id)->delete_full($showfeedback);
3593 * Efficiently moves a category - NOTE that this can have
3594 * a huge impact access-control-wise...
3596 * This function is deprecated. Please use
3597 * $coursecat = coursecat::get($category->id);
3598 * if ($coursecat->can_change_parent($newparentcat->id)) {
3599 * $coursecat->change_parent($newparentcat->id);
3602 * Alternatively you can use
3603 * $coursecat->update(array('parent' => $newparentcat->id));
3605 * Function update() also updates field course_categories.timemodified
3607 * @see coursecat::change_parent()
3608 * @see coursecat::update()
3609 * @deprecated since 2.5
3611 * @param stdClass|coursecat $category
3612 * @param stdClass|coursecat $newparentcat
3614 function move_category($category, $newparentcat) {
3616 require_once($CFG->libdir.'/coursecatlib.php');
3618 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
3620 return coursecat::get($category->id)->change_parent($newparentcat->id);
3624 * Hide course category and child course and subcategories
3626 * This function is deprecated. Please use
3627 * coursecat::get($category->id)->hide();
3629 * @see coursecat::hide()
3630 * @deprecated since 2.5
3632 * @param stdClass $category
3635 function course_category_hide($category) {
3637 require_once($CFG->libdir.'/coursecatlib.php');
3639 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
3641 coursecat::get($category->id)->hide();
3645 * Show course category and child course and subcategories
3647 * This function is deprecated. Please use
3648 * coursecat::get($category->id)->show();
3650 * @see coursecat::show()
3651 * @deprecated since 2.5
3653 * @param stdClass $category
3656 function course_category_show($category) {
3658 require_once($CFG->libdir.'/coursecatlib.php');
3660 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
3662 coursecat::get($category->id)->show();
3666 * Return specified category, default if given does not exist
3668 * This function is deprecated.
3669 * To get the category with the specified it please use:
3670 * coursecat::get($catid, IGNORE_MISSING);
3672 * coursecat::get($catid, MUST_EXIST);
3674 * To get the first available category please use
3675 * coursecat::get_default();
3677 * class coursecat will also make sure that at least one category exists in DB
3679 * @deprecated since 2.5
3680 * @see coursecat::get()
3681 * @see coursecat::get_default()
3683 * @param int $catid course category id
3684 * @return object caregory
3686 function get_course_category($catid=0) {
3689 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
3693 if (!empty($catid)) {
3694 $category = $DB->get_record('course_categories', array('id'=>$catid));
3698 // the first category is considered default for now
3699 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
3700 $category = reset($category);
3703 $cat = new stdClass();
3704 $cat->name = get_string('miscellaneous');
3706 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
3707 $cat->timemodified = time();
3708 $catid = $DB->insert_record('course_categories', $cat);
3709 // make sure category context exists
3710 context_coursecat::instance($catid);
3711 mark_context_dirty('/'.SYSCONTEXTID);
3712 fix_course_sortorder(); // Required to build course_categories.depth and .path.
3713 $category = $DB->get_record('course_categories', array('id'=>$catid));