Merge branch 'wip-MDL-25454-master' of git://github.com/marinaglancy/moodle
[moodle.git] / lib / deprecatedlib.php
blobd822bda4a784509d5926164d1b9a19939eb55cb4
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
24 * @package core
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @deprecated
31 defined('MOODLE_INTERNAL') || die();
33 /**
34 * Unsupported session id rewriting.
35 * @deprecated
36 * @param string $buffer
38 function sid_ob_rewrite($buffer) {
39 throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
42 /**
43 * Insert or update log display entry. Entry may already exist.
44 * $module, $action must be unique
45 * @deprecated
47 * @param string $module
48 * @param string $action
49 * @param string $mtable
50 * @param string $field
51 * @return void
54 function update_log_display_entry($module, $action, $mtable, $field) {
55 global $DB;
57 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
60 /**
61 * Given some text in HTML format, this function will pass it
62 * through any filters that have been configured for this context.
64 * @deprecated use the text formatting in a standard way instead,
65 * this was abused mostly for embedding of attachments
67 * @param string $text The text to be passed through format filters
68 * @param int $courseid The current course.
69 * @return string the filtered string.
71 function filter_text($text, $courseid = NULL) {
72 global $CFG, $COURSE;
74 if (!$courseid) {
75 $courseid = $COURSE->id;
78 if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
79 return $text;
82 return filter_manager::instance()->filter_text($text, $context);
85 /**
86 * This function indicates that current page requires the https
87 * when $CFG->loginhttps enabled.
89 * By using this function properly, we can ensure 100% https-ized pages
90 * at our entire discretion (login, forgot_password, change_password)
91 * @deprecated use $PAGE->https_required() instead
93 function httpsrequired() {
94 global $PAGE;
95 $PAGE->https_required();
98 /**
99 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
101 * @deprecated use moodle_url factory methods instead
103 * @param string $path Physical path to a file
104 * @param array $options associative array of GET variables to append to the URL
105 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
106 * @return string URL to file
108 function get_file_url($path, $options=null, $type='coursefile') {
109 global $CFG;
111 $path = str_replace('//', '/', $path);
112 $path = trim($path, '/'); // no leading and trailing slashes
114 // type of file
115 switch ($type) {
116 case 'questionfile':
117 $url = $CFG->wwwroot."/question/exportfile.php";
118 break;
119 case 'rssfile':
120 $url = $CFG->wwwroot."/rss/file.php";
121 break;
122 case 'httpscoursefile':
123 $url = $CFG->httpswwwroot."/file.php";
124 break;
125 case 'coursefile':
126 default:
127 $url = $CFG->wwwroot."/file.php";
130 if ($CFG->slasharguments) {
131 $parts = explode('/', $path);
132 foreach ($parts as $key => $part) {
133 /// anchor dash character should not be encoded
134 $subparts = explode('#', $part);
135 $subparts = array_map('rawurlencode', $subparts);
136 $parts[$key] = implode('#', $subparts);
138 $path = implode('/', $parts);
139 $ffurl = $url.'/'.$path;
140 $separator = '?';
141 } else {
142 $path = rawurlencode('/'.$path);
143 $ffurl = $url.'?file='.$path;
144 $separator = '&amp;';
147 if ($options) {
148 foreach ($options as $name=>$value) {
149 $ffurl = $ffurl.$separator.$name.'='.$value;
150 $separator = '&amp;';
154 return $ffurl;
158 * If there has been an error uploading a file, print the appropriate error message
159 * Numerical constants used as constant definitions not added until PHP version 4.2.0
160 * @deprecated removed - use new file api
162 function print_file_upload_error($filearray = '', $returnerror = false) {
163 throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
167 * Handy function for resolving file conflicts
168 * @deprecated removed - use new file api
171 function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
172 throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
176 * Checks a file name for any conflicts
177 * @deprecated removed - use new file api
179 function check_potential_filename($destination,$filename,$files) {
180 throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
184 * This function prints out a number of upload form elements.
185 * @deprecated removed - use new file api
187 function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
188 throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
192 * Return the authentication plugin title
194 * @param string $authtype plugin type
195 * @return string
197 function auth_get_plugin_title($authtype) {
198 debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
199 return get_string('pluginname', "auth_{$authtype}");
205 * Enrol someone without using the default role in a course
206 * @deprecated
208 function enrol_into_course($course, $user, $enrol) {
209 error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
213 * Returns a role object that is the default role for new enrolments in a given course
215 * @deprecated
216 * @param object $course
217 * @return object returns a role or NULL if none set
219 function get_default_course_role($course) {
220 debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
222 $student = get_archetype_roles('student');
223 $student = reset($student);
225 return $student;
229 * Extremely slow enrolled courses query.
230 * @deprecated
232 function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
233 error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
237 * Was returning list of translations, use new string_manager instead
239 * @deprecated
240 * @param bool $refreshcache force refreshing of lang cache
241 * @param bool $returnall ignore langlist, return all languages available
242 * @return array An associative array with contents in the form of LanguageCode => LanguageName
244 function get_list_of_languages($refreshcache=false, $returnall=false) {
245 debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
246 if ($refreshcache) {
247 get_string_manager()->reset_caches();
249 return get_string_manager()->get_list_of_translations($returnall);
253 * Returns a list of currencies in the current language
254 * @deprecated
255 * @return array
257 function get_list_of_currencies() {
258 debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
259 return get_string_manager()->get_list_of_currencies();
263 * Returns a list of all enabled country names in the current translation
264 * @deprecated
265 * @return array two-letter country code => translated name.
267 function get_list_of_countries() {
268 debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
269 return get_string_manager()->get_list_of_countries(false);
273 * @deprecated
275 function isteacher() {
276 error('Function isteacher() was removed, please use capabilities instead!');
280 * @deprecated
282 function isteacherinanycourse() {
283 error('Function isteacherinanycourse() was removed, please use capabilities instead!');
287 * @deprecated
289 function get_guest() {
290 error('Function get_guest() was removed, please use capabilities instead!');
294 * @deprecated
296 function isguest() {
297 error('Function isguest() was removed, please use capabilities instead!');
301 * @deprecated
303 function get_teacher() {
304 error('Function get_teacher() was removed, please use capabilities instead!');
308 * Return all course participant for a given course
310 * @deprecated
311 * @param integer $courseid
312 * @return array of user
314 function get_course_participants($courseid) {
315 return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid));
319 * Return true if the user is a participant for a given course
321 * @deprecated
322 * @param integer $userid
323 * @param integer $courseid
324 * @return boolean
326 function is_course_participant($userid, $courseid) {
327 return is_enrolled(get_context_instance(CONTEXT_COURSE, $courseid), $userid);
331 * Searches logs to find all enrolments since a certain date
333 * used to print recent activity
335 * @global object
336 * @uses CONTEXT_COURSE
337 * @param int $courseid The course in question.
338 * @param int $timestart The date to check forward of
339 * @return object|false {@link $USER} records or false if error.
341 function get_recent_enrolments($courseid, $timestart) {
342 global $DB;
344 $context = get_context_instance(CONTEXT_COURSE, $courseid);
346 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
347 FROM {user} u, {role_assignments} ra, {log} l
348 WHERE l.time > ?
349 AND l.course = ?
350 AND l.module = 'course'
351 AND l.action = 'enrol'
352 AND ".$DB->sql_cast_char2int('l.info')." = u.id
353 AND u.id = ra.userid
354 AND ra.contextid ".get_related_contexts_string($context)."
355 GROUP BY u.id, u.firstname, u.lastname
356 ORDER BY MAX(l.time) ASC";
357 $params = array($timestart, $courseid);
358 return $DB->get_records_sql($sql, $params);
363 * Turn the ctx* fields in an objectlike record into a context subobject
364 * This allows us to SELECT from major tables JOINing with
365 * context at no cost, saving a ton of context lookups...
367 * Use context_instance_preload() instead.
369 * @deprecated since 2.0
370 * @param object $rec
371 * @return object
373 function make_context_subobj($rec) {
374 $ctx = new StdClass;
375 $ctx->id = $rec->ctxid; unset($rec->ctxid);
376 $ctx->path = $rec->ctxpath; unset($rec->ctxpath);
377 $ctx->depth = $rec->ctxdepth; unset($rec->ctxdepth);
378 $ctx->contextlevel = $rec->ctxlevel; unset($rec->ctxlevel);
379 $ctx->instanceid = $rec->id;
381 $rec->context = $ctx;
382 return $rec;
386 * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
388 * Use context_instance_preload() instead.
390 * @deprecated since 2.0
391 * @param object $rec a think that has a context, for example a course,
392 * course category, course modules, etc.
393 * @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
394 * @return bool whether $rec->context looks like the correct context object
395 * for this thing.
397 function is_context_subobj_valid($rec, $contextlevel) {
398 return isset($rec->context) && isset($rec->context->id) &&
399 isset($rec->context->path) && isset($rec->context->depth) &&
400 isset($rec->context->contextlevel) && isset($rec->context->instanceid) &&
401 $rec->context->contextlevel == $contextlevel && $rec->context->instanceid == $rec->id;
405 * Ensure that $rec->context is present and correct before you continue
407 * When you have a record (for example a $category, $course, $user or $cm that may,
408 * or may not, have come from a place that does make_context_subobj, you can use
409 * this method to ensure that $rec->context is present and correct before you continue.
411 * Use context_instance_preload() instead.
413 * @deprecated since 2.0
414 * @param object $rec a thing that has an associated context.
415 * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
417 function ensure_context_subobj_present(&$rec, $contextlevel) {
418 if (!is_context_subobj_valid($rec, $contextlevel)) {
419 $rec->context = get_context_instance($contextlevel, $rec->id);
423 ########### FROM weblib.php ##########################################################################
427 * Print a message in a standard themed box.
428 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
429 * parameters remain. If possible, $align, $width and $color should not be defined at all.
430 * Preferably just use print_box() in weblib.php
432 * @deprecated
433 * @param string $message The message to display
434 * @param string $align alignment of the box, not the text (default center, left, right).
435 * @param string $width width of the box, including units %, for example '100%'.
436 * @param string $color background colour of the box, for example '#eee'.
437 * @param int $padding padding in pixels, specified without units.
438 * @param string $class space-separated class names.
439 * @param string $id space-separated id names.
440 * @param boolean $return return as string or just print it
441 * @return string|void Depending on $return
443 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
444 $output = '';
445 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
446 $output .= $message;
447 $output .= print_simple_box_end(true);
449 if ($return) {
450 return $output;
451 } else {
452 echo $output;
459 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
460 * parameters remain. If possible, $align, $width and $color should not be defined at all.
461 * Even better, please use print_box_start() in weblib.php
463 * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
464 * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
465 * @param string $color background colour of the box, for example '#eee'. DEPRECATED
466 * @param int $padding padding in pixels, specified without units. OBSOLETE
467 * @param string $class space-separated class names.
468 * @param string $id space-separated id names.
469 * @param boolean $return return as string or just print it
470 * @return string|void Depending on $return
472 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
473 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
475 $output = '';
477 $divclasses = 'box '.$class.' '.$class.'content';
478 $divstyles = '';
480 if ($align) {
481 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
483 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
484 if (substr($width, -1, 1) == '%') { // Width is a % value
485 $width = (int) substr($width, 0, -1); // Extract just the number
486 if ($width < 40) {
487 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
488 } else if ($width > 60) {
489 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
490 } else {
491 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
493 } else {
494 $divstyles .= ' width:'.$width.';'; // Last resort
497 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
498 $divstyles .= ' background:'.$color.';';
500 if ($divstyles) {
501 $divstyles = ' style="'.$divstyles.'"';
504 if ($id) {
505 $id = ' id="'.$id.'"';
508 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
510 if ($return) {
511 return $output;
512 } else {
513 echo $output;
519 * Print the end portion of a standard themed box.
520 * Preferably just use print_box_end() in weblib.php
522 * @param boolean $return return as string or just print it
523 * @return string|void Depending on $return
525 function print_simple_box_end($return=false) {
526 $output = '</div>';
527 if ($return) {
528 return $output;
529 } else {
530 echo $output;
535 * Given some text this function converted any URLs it found into HTML links
537 * This core function has been replaced with filter_urltolink since Moodle 2.0
539 * @param string $text Passed in by reference. The string to be searched for urls.
541 function convert_urls_into_links($text) {
542 debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
546 * Used to be called from help.php to inject a list of smilies into the
547 * emoticons help file.
549 * @return string HTML
551 function get_emoticons_list_for_help_file() {
552 debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
553 return '';
557 * Was used to replace all known smileys in the text with image equivalents
559 * This core function has been replaced with filter_emoticon since Moodle 2.0
561 function replace_smilies(&$text) {
562 debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
566 * deprecated - use clean_param($string, PARAM_FILE); instead
567 * Check for bad characters ?
569 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
571 * @param string $string ?
572 * @param int $allowdots ?
573 * @return bool
575 function detect_munged_arguments($string, $allowdots=1) {
576 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
577 return true;
579 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
580 return true;
582 if (empty($string) or $string == '/') {
583 return true;
586 return false;
591 * Unzip one zip file to a destination dir
592 * Both parameters must be FULL paths
593 * If destination isn't specified, it will be the
594 * SAME directory where the zip file resides.
596 * @global object
597 * @param string $zipfile The zip file to unzip
598 * @param string $destination The location to unzip to
599 * @param bool $showstatus_ignored Unused
601 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
602 global $CFG;
604 //Extract everything from zipfile
605 $path_parts = pathinfo(cleardoubleslashes($zipfile));
606 $zippath = $path_parts["dirname"]; //The path of the zip file
607 $zipfilename = $path_parts["basename"]; //The name of the zip file
608 $extension = $path_parts["extension"]; //The extension of the file
610 //If no file, error
611 if (empty($zipfilename)) {
612 return false;
615 //If no extension, error
616 if (empty($extension)) {
617 return false;
620 //Clear $zipfile
621 $zipfile = cleardoubleslashes($zipfile);
623 //Check zipfile exists
624 if (!file_exists($zipfile)) {
625 return false;
628 //If no destination, passed let's go with the same directory
629 if (empty($destination)) {
630 $destination = $zippath;
633 //Clear $destination
634 $destpath = rtrim(cleardoubleslashes($destination), "/");
636 //Check destination path exists
637 if (!is_dir($destpath)) {
638 return false;
641 $packer = get_file_packer('application/zip');
643 $result = $packer->extract_to_pathname($zipfile, $destpath);
645 if ($result === false) {
646 return false;
649 foreach ($result as $status) {
650 if ($status !== true) {
651 return false;
655 return true;
659 * Zip an array of files/dirs to a destination zip file
660 * Both parameters must be FULL paths to the files/dirs
662 * @global object
663 * @param array $originalfiles Files to zip
664 * @param string $destination The destination path
665 * @return bool Outcome
667 function zip_files ($originalfiles, $destination) {
668 global $CFG;
670 //Extract everything from destination
671 $path_parts = pathinfo(cleardoubleslashes($destination));
672 $destpath = $path_parts["dirname"]; //The path of the zip file
673 $destfilename = $path_parts["basename"]; //The name of the zip file
674 $extension = $path_parts["extension"]; //The extension of the file
676 //If no file, error
677 if (empty($destfilename)) {
678 return false;
681 //If no extension, add it
682 if (empty($extension)) {
683 $extension = 'zip';
684 $destfilename = $destfilename.'.'.$extension;
687 //Check destination path exists
688 if (!is_dir($destpath)) {
689 return false;
692 //Check destination path is writable. TODO!!
694 //Clean destination filename
695 $destfilename = clean_filename($destfilename);
697 //Now check and prepare every file
698 $files = array();
699 $origpath = NULL;
701 foreach ($originalfiles as $file) { //Iterate over each file
702 //Check for every file
703 $tempfile = cleardoubleslashes($file); // no doubleslashes!
704 //Calculate the base path for all files if it isn't set
705 if ($origpath === NULL) {
706 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
708 //See if the file is readable
709 if (!is_readable($tempfile)) { //Is readable
710 continue;
712 //See if the file/dir is in the same directory than the rest
713 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
714 continue;
716 //Add the file to the array
717 $files[] = $tempfile;
720 $zipfiles = array();
721 $start = strlen($origpath)+1;
722 foreach($files as $file) {
723 $zipfiles[substr($file, $start)] = $file;
726 $packer = get_file_packer('application/zip');
728 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
731 /////////////////////////////////////////////////////////////
732 /// Old functions not used anymore - candidates for removal
733 /////////////////////////////////////////////////////////////
736 /** various deprecated groups function **/
740 * Get the IDs for the user's groups in the given course.
742 * @global object
743 * @param int $courseid The course being examined - the 'course' table id field.
744 * @return array|bool An _array_ of groupids, or false
745 * (Was return $groupids[0] - consequences!)
747 function mygroupid($courseid) {
748 global $USER;
749 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
750 return array_keys($groups);
751 } else {
752 return false;
758 * Returns the current group mode for a given course or activity module
760 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
762 * @param object $course Course Object
763 * @param object $cm Course Manager Object
764 * @return mixed $course->groupmode
766 function groupmode($course, $cm=null) {
768 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
769 return $cm->groupmode;
771 return $course->groupmode;
775 * Sets the current group in the session variable
776 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
777 * Sets currentgroup[$courseid] in the session variable appropriately.
778 * Does not do any permission checking.
780 * @global object
781 * @param int $courseid The course being examined - relates to id field in
782 * 'course' table.
783 * @param int $groupid The group being examined.
784 * @return int Current group id which was set by this function
786 function set_current_group($courseid, $groupid) {
787 global $SESSION;
788 return $SESSION->currentgroup[$courseid] = $groupid;
793 * Gets the current group - either from the session variable or from the database.
795 * @global object
796 * @param int $courseid The course being examined - relates to id field in
797 * 'course' table.
798 * @param bool $full If true, the return value is a full record object.
799 * If false, just the id of the record.
800 * @return int|bool
802 function get_current_group($courseid, $full = false) {
803 global $SESSION;
805 if (isset($SESSION->currentgroup[$courseid])) {
806 if ($full) {
807 return groups_get_group($SESSION->currentgroup[$courseid]);
808 } else {
809 return $SESSION->currentgroup[$courseid];
813 $mygroupid = mygroupid($courseid);
814 if (is_array($mygroupid)) {
815 $mygroupid = array_shift($mygroupid);
816 set_current_group($courseid, $mygroupid);
817 if ($full) {
818 return groups_get_group($mygroupid);
819 } else {
820 return $mygroupid;
824 if ($full) {
825 return false;
826 } else {
827 return 0;
833 * Inndicates fatal error. This function was originally printing the
834 * error message directly, since 2.0 it is throwing exception instead.
835 * The error printing is handled in default exception handler.
837 * Old method, don't call directly in new code - use print_error instead.
839 * @param string $message The message to display to the user about the error.
840 * @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.
841 * @return void, always throws moodle_exception
843 function error($message, $link='') {
844 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
848 /// Deprecated DDL functions, to be removed soon ///
850 * @deprecated
851 * @global object
852 * @param string $table
853 * @return bool
855 function table_exists($table) {
856 global $DB;
857 debugging('Deprecated ddllib function used!');
858 return $DB->get_manager()->table_exists($table);
862 * @deprecated
863 * @global object
864 * @param string $table
865 * @param string $field
866 * @return bool
868 function field_exists($table, $field) {
869 global $DB;
870 debugging('Deprecated ddllib function used!');
871 return $DB->get_manager()->field_exists($table, $field);
875 * @deprecated
876 * @global object
877 * @param string $table
878 * @param string $index
879 * @return bool
881 function find_index_name($table, $index) {
882 global $DB;
883 debugging('Deprecated ddllib function used!');
884 return $DB->get_manager()->find_index_name($table, $index);
888 * @deprecated
889 * @global object
890 * @param string $table
891 * @param string $index
892 * @return bool
894 function index_exists($table, $index) {
895 global $DB;
896 debugging('Deprecated ddllib function used!');
897 return $DB->get_manager()->index_exists($table, $index);
901 * @deprecated
902 * @global object
903 * @param string $table
904 * @param string $field
905 * @return bool
907 function find_check_constraint_name($table, $field) {
908 global $DB;
909 debugging('Deprecated ddllib function used!');
910 return $DB->get_manager()->find_check_constraint_name($table, $field);
914 * @deprecated
915 * @global object
917 function check_constraint_exists($table, $field) {
918 global $DB;
919 debugging('Deprecated ddllib function used!');
920 return $DB->get_manager()->check_constraint_exists($table, $field);
924 * @deprecated
925 * @global object
926 * @param string $table
927 * @param string $xmldb_key
928 * @return bool
930 function find_key_name($table, $xmldb_key) {
931 global $DB;
932 debugging('Deprecated ddllib function used!');
933 return $DB->get_manager()->find_key_name($table, $xmldb_key);
937 * @deprecated
938 * @global object
939 * @param string $table
940 * @return bool
942 function drop_table($table) {
943 global $DB;
944 debugging('Deprecated ddllib function used!');
945 $DB->get_manager()->drop_table($table);
946 return true;
950 * @deprecated
951 * @global object
952 * @param string $file
953 * @return bool
955 function install_from_xmldb_file($file) {
956 global $DB;
957 debugging('Deprecated ddllib function used!');
958 $DB->get_manager()->install_from_xmldb_file($file);
959 return true;
963 * @deprecated
964 * @global object
965 * @param string $table
966 * @return bool
968 function create_table($table) {
969 global $DB;
970 debugging('Deprecated ddllib function used!');
971 $DB->get_manager()->create_table($table);
972 return true;
976 * @deprecated
977 * @global object
978 * @param string $table
979 * @return bool
981 function create_temp_table($table) {
982 global $DB;
983 debugging('Deprecated ddllib function used!');
984 $DB->get_manager()->create_temp_table($table);
985 return true;
989 * @deprecated
990 * @global object
991 * @param string $table
992 * @param string $newname
993 * @return bool
995 function rename_table($table, $newname) {
996 global $DB;
997 debugging('Deprecated ddllib function used!');
998 $DB->get_manager()->rename_table($table, $newname);
999 return true;
1003 * @deprecated
1004 * @global object
1005 * @param string $table
1006 * @param string $field
1007 * @return bool
1009 function add_field($table, $field) {
1010 global $DB;
1011 debugging('Deprecated ddllib function used!');
1012 $DB->get_manager()->add_field($table, $field);
1013 return true;
1017 * @deprecated
1018 * @global object
1019 * @param string $table
1020 * @param string $field
1021 * @return bool
1023 function drop_field($table, $field) {
1024 global $DB;
1025 debugging('Deprecated ddllib function used!');
1026 $DB->get_manager()->drop_field($table, $field);
1027 return true;
1031 * @deprecated
1032 * @global object
1033 * @param string $table
1034 * @param string $field
1035 * @return bool
1037 function change_field_type($table, $field) {
1038 global $DB;
1039 debugging('Deprecated ddllib function used!');
1040 $DB->get_manager()->change_field_type($table, $field);
1041 return true;
1045 * @deprecated
1046 * @global object
1047 * @param string $table
1048 * @param string $field
1049 * @return bool
1051 function change_field_precision($table, $field) {
1052 global $DB;
1053 debugging('Deprecated ddllib function used!');
1054 $DB->get_manager()->change_field_precision($table, $field);
1055 return true;
1059 * @deprecated
1060 * @global object
1061 * @param string $table
1062 * @param string $field
1063 * @return bool
1065 function change_field_unsigned($table, $field) {
1066 global $DB;
1067 debugging('Deprecated ddllib function used!');
1068 $DB->get_manager()->change_field_unsigned($table, $field);
1069 return true;
1073 * @deprecated
1074 * @global object
1075 * @param string $table
1076 * @param string $field
1077 * @return bool
1079 function change_field_notnull($table, $field) {
1080 global $DB;
1081 debugging('Deprecated ddllib function used!');
1082 $DB->get_manager()->change_field_notnull($table, $field);
1083 return true;
1087 * @deprecated
1088 * @global object
1089 * @param string $table
1090 * @param string $field
1091 * @return bool
1093 function change_field_enum($table, $field) {
1094 global $DB;
1095 debugging('Deprecated ddllib function used! Only dropping of enums is allowed.');
1096 $DB->get_manager()->drop_enum_from_field($table, $field);
1097 return true;
1101 * @deprecated
1102 * @global object
1103 * @param string $table
1104 * @param string $field
1105 * @return bool
1107 function change_field_default($table, $field) {
1108 global $DB;
1109 debugging('Deprecated ddllib function used!');
1110 $DB->get_manager()->change_field_default($table, $field);
1111 return true;
1115 * @deprecated
1116 * @global object
1117 * @param string $table
1118 * @param string $field
1119 * @param string $newname
1120 * @return bool
1122 function rename_field($table, $field, $newname) {
1123 global $DB;
1124 debugging('Deprecated ddllib function used!');
1125 $DB->get_manager()->rename_field($table, $field, $newname);
1126 return true;
1130 * @deprecated
1131 * @global object
1132 * @param string $table
1133 * @param string $key
1134 * @return bool
1136 function add_key($table, $key) {
1137 global $DB;
1138 debugging('Deprecated ddllib function used!');
1139 $DB->get_manager()->add_key($table, $key);
1140 return true;
1144 * @deprecated
1145 * @global object
1146 * @param string $table
1147 * @param string $key
1148 * @return bool
1150 function drop_key($table, $key) {
1151 global $DB;
1152 debugging('Deprecated ddllib function used!');
1153 $DB->get_manager()->drop_key($table, $key);
1154 return true;
1158 * @deprecated
1159 * @global object
1160 * @param string $table
1161 * @param string $key
1162 * @param string $newname
1163 * @return bool
1165 function rename_key($table, $key, $newname) {
1166 global $DB;
1167 debugging('Deprecated ddllib function used!');
1168 $DB->get_manager()->rename_key($table, $key, $newname);
1169 return true;
1173 * @deprecated
1174 * @global object
1175 * @param string $table
1176 * @param string $index
1177 * @return bool
1179 function add_index($table, $index) {
1180 global $DB;
1181 debugging('Deprecated ddllib function used!');
1182 $DB->get_manager()->add_index($table, $index);
1183 return true;
1187 * @deprecated
1188 * @global object
1189 * @param string $table
1190 * @param string $index
1191 * @return bool
1193 function drop_index($table, $index) {
1194 global $DB;
1195 debugging('Deprecated ddllib function used!');
1196 $DB->get_manager()->drop_index($table, $index);
1197 return true;
1201 * @deprecated
1202 * @global object
1203 * @param string $table
1204 * @param string $index
1205 * @param string $newname
1206 * @return bool
1208 function rename_index($table, $index, $newname) {
1209 global $DB;
1210 debugging('Deprecated ddllib function used!');
1211 $DB->get_manager()->rename_index($table, $index, $newname);
1212 return true;
1216 //////////////////////////
1217 /// removed functions ////
1218 //////////////////////////
1221 * @deprecated
1222 * @param mixed $mixed
1223 * @return void Throws an error and does nothing
1225 function stripslashes_safe($mixed) {
1226 error('stripslashes_safe() not available anymore');
1229 * @deprecated
1230 * @param mixed $var
1231 * @return void Throws an error and does nothing
1233 function stripslashes_recursive($var) {
1234 error('stripslashes_recursive() not available anymore');
1237 * @deprecated
1238 * @param mixed $dataobject
1239 * @return void Throws an error and does nothing
1241 function addslashes_object($dataobject) {
1242 error('addslashes_object() not available anymore');
1245 * @deprecated
1246 * @param mixed $var
1247 * @return void Throws an error and does nothing
1249 function addslashes_recursive($var) {
1250 error('addslashes_recursive() not available anymore');
1253 * @deprecated
1254 * @param mixed $command
1255 * @param bool $feedback
1256 * @return void Throws an error and does nothing
1258 function execute_sql($command, $feedback=true) {
1259 error('execute_sql() not available anymore');
1262 * @deprecated use $DB->record_exists_select() instead
1263 * @see moodle_database::record_exists_select()
1264 * @param mixed $table
1265 * @param mixed $select
1266 * @return void Throws an error and does nothing
1268 function record_exists_select($table, $select='') {
1269 error('record_exists_select() not available anymore');
1272 * @deprecated use $DB->record_exists_sql() instead
1273 * @see moodle_database::record_exists_sql()
1274 * @param mixed $sql
1275 * @return void Throws an error and does nothing
1277 function record_exists_sql($sql) {
1278 error('record_exists_sql() not available anymore');
1281 * @deprecated use $DB->count_records_select() instead
1282 * @see moodle_database::count_records_select()
1283 * @param mixed $table
1284 * @param mixed $select
1285 * @param mixed $countitem
1286 * @return void Throws an error and does nothing
1288 function count_records_select($table, $select='', $countitem='COUNT(*)') {
1289 error('count_records_select() not available anymore');
1292 * @deprecated use $DB->count_records_sql() instead
1293 * @see moodle_database::count_records_sql()
1294 * @param mixed $sql
1295 * @return void Throws an error and does nothing
1297 function count_records_sql($sql) {
1298 error('count_records_sql() not available anymore');
1301 * @deprecated use $DB->get_record_sql() instead
1302 * @see moodle_database::get_record_sql()
1303 * @param mixed $sql
1304 * @param bool $expectmultiple
1305 * @param bool $nolimit
1306 * @return void Throws an error and does nothing
1308 function get_record_sql($sql, $expectmultiple=false, $nolimit=false) {
1309 error('get_record_sql() not available anymore');
1312 * @deprecated use $DB->get_record_select() instead
1313 * @see moodle_database::get_record_select()
1314 * @param mixed $table
1315 * @param mixed $select
1316 * @param mixed $fields
1317 * @return void Throws an error and does nothing
1319 function get_record_select($table, $select='', $fields='*') {
1320 error('get_record_select() not available anymore');
1323 * @deprecated use $DB->get_recordset() instead
1324 * @see moodle_database::get_recordset()
1325 * @param mixed $table
1326 * @param mixed $field
1327 * @param mixed $value
1328 * @param mixed $sort
1329 * @param mixed $fields
1330 * @param mixed $limitfrom
1331 * @param mixed $limitnum
1332 * @return void Throws an error and does nothing
1334 function get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1335 error('get_recordset() not available anymore');
1338 * @deprecated use $DB->get_recordset_sql() instead
1339 * @see moodle_database::get_recordset_sql()
1340 * @param mixed $sql
1341 * @param mixed $limitfrom
1342 * @param mixed $limitnum
1343 * @return void Throws an error and does nothing
1345 function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) {
1346 error('get_recordset_sql() not available anymore');
1349 * @deprecated
1350 * @param mixed $rs
1351 * @return void Throws an error and does nothing
1353 function rs_fetch_record(&$rs) {
1354 error('rs_fetch_record() not available anymore');
1357 * @deprecated
1358 * @param mixed $rs
1359 * @return void Throws an error and does nothing
1361 function rs_next_record(&$rs) {
1362 error('rs_next_record() not available anymore');
1365 * @deprecated
1366 * @param mixed $rs
1367 * @return void Throws an error and does nothing
1369 function rs_fetch_next_record(&$rs) {
1370 error('rs_fetch_next_record() not available anymore');
1373 * @deprecated
1374 * @param mixed $rs
1375 * @return void Throws an error and does nothing
1377 function rs_EOF($rs) {
1378 error('rs_EOF() not available anymore');
1381 * @deprecated
1382 * @param mixed $rs
1383 * @return void Throws an error and does nothing
1385 function rs_close(&$rs) {
1386 error('rs_close() not available anymore');
1389 * @deprecated use $DB->get_records_select() instead
1390 * @see moodle_database::get_records_select()
1391 * @param mixed $table
1392 * @param mixed $select
1393 * @param mixed $sort
1394 * @param mixed $fields
1395 * @param mixed $limitfrom
1396 * @param mixed $limitnum
1397 * @return void Throws an error and does nothing
1399 function get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1400 error('get_records_select() not available anymore');
1403 * @deprecated use $DB->get_field_select() instead
1404 * @see moodle_database::get_field_select()
1405 * @param mixed $table
1406 * @param mixed $return
1407 * @param mixed $select
1408 * @return void Throws an error and does nothing
1410 function get_field_select($table, $return, $select) {
1411 error('get_field_select() not available anymore');
1414 * @deprecated use $DB->get_field_sql() instead
1415 * @see moodle_database::get_field_sql()
1416 * @param mixed $sql
1417 * @return void Throws an error and does nothing
1419 function get_field_sql($sql) {
1420 error('get_field_sql() not available anymore');
1423 * @deprecated use $DB->delete_records_select() instead
1424 * @see moodle_database::delete_records_select()
1425 * @param mixed $sql
1426 * @param mixed $select
1427 * @return void Throws an error and does nothing
1429 function delete_records_select($table, $select='') {
1430 error('get_field_sql() not available anymore');
1433 * @deprecated
1434 * @return void Throws an error and does nothing
1436 function configure_dbconnection() {
1437 error('configure_dbconnection() removed');
1440 * @deprecated
1441 * @param mixed $field
1442 * @return void Throws an error and does nothing
1444 function sql_max($field) {
1445 error('sql_max() removed - use normal sql MAX() instead');
1448 * @deprecated
1449 * @return void Throws an error and does nothing
1451 function sql_as() {
1452 error('sql_as() removed - do not use AS for tables at all');
1455 * @deprecated
1456 * @param mixed $page
1457 * @param mixed $recordsperpage
1458 * @return void Throws an error and does nothing
1460 function sql_paging_limit($page, $recordsperpage) {
1461 error('Function sql_paging_limit() is deprecated. Replace it with the correct use of limitfrom, limitnum parameters');
1464 * @deprecated
1465 * @return void Throws an error and does nothing
1467 function db_uppercase() {
1468 error('upper() removed - use normal sql UPPER()');
1471 * @deprecated
1472 * @return void Throws an error and does nothing
1474 function db_lowercase() {
1475 error('upper() removed - use normal sql LOWER()');
1478 * @deprecated
1479 * @param mixed $sqlfile
1480 * @param mixed $sqlstring
1481 * @return void Throws an error and does nothing
1483 function modify_database($sqlfile='', $sqlstring='') {
1484 error('modify_database() removed - use new XMLDB functions');
1487 * @deprecated
1488 * @param mixed $field1
1489 * @param mixed $value1
1490 * @param mixed $field2
1491 * @param mixed $value2
1492 * @param mixed $field3
1493 * @param mixed $value3
1494 * @return void Throws an error and does nothing
1496 function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1497 error('where_clause() removed - use new functions with $conditions parameter');
1500 * @deprecated
1501 * @param mixed $sqlarr
1502 * @param mixed $continue
1503 * @param mixed $feedback
1504 * @return void Throws an error and does nothing
1506 function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
1507 error('execute_sql_arr() removed');
1510 * @deprecated use $DB->get_records_list() instead
1511 * @see moodle_database::get_records_list()
1512 * @param mixed $table
1513 * @param mixed $field
1514 * @param mixed $values
1515 * @param mixed $sort
1516 * @param mixed $fields
1517 * @param mixed $limitfrom
1518 * @param mixed $limitnum
1519 * @return void Throws an error and does nothing
1521 function get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1522 error('get_records_list() removed');
1525 * @deprecated use $DB->get_recordset_list() instead
1526 * @see moodle_database::get_recordset_list()
1527 * @param mixed $table
1528 * @param mixed $field
1529 * @param mixed $values
1530 * @param mixed $sort
1531 * @param mixed $fields
1532 * @param mixed $limitfrom
1533 * @param mixed $limitnum
1534 * @return void Throws an error and does nothing
1536 function get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1537 error('get_recordset_list() removed');
1540 * @deprecated use $DB->get_records_menu() instead
1541 * @see moodle_database::get_records_menu()
1542 * @param mixed $table
1543 * @param mixed $field
1544 * @param mixed $value
1545 * @param mixed $sort
1546 * @param mixed $fields
1547 * @param mixed $limitfrom
1548 * @param mixed $limitnum
1549 * @return void Throws an error and does nothing
1551 function get_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1552 error('get_records_menu() removed');
1555 * @deprecated use $DB->get_records_select_menu() instead
1556 * @see moodle_database::get_records_select_menu()
1557 * @param mixed $table
1558 * @param mixed $select
1559 * @param mixed $sort
1560 * @param mixed $fields
1561 * @param mixed $limitfrom
1562 * @param mixed $limitnum
1563 * @return void Throws an error and does nothing
1565 function get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1566 error('get_records_select_menu() removed');
1569 * @deprecated use $DB->get_records_sql_menu() instead
1570 * @see moodle_database::get_records_sql_menu()
1571 * @param mixed $sql
1572 * @param mixed $limitfrom
1573 * @param mixed $limitnum
1574 * @return void Throws an error and does nothing
1576 function get_records_sql_menu($sql, $limitfrom='', $limitnum='') {
1577 error('get_records_sql_menu() removed');
1580 * @deprecated
1581 * @param mixed $table
1582 * @param mixed $column
1583 * @return void Throws an error and does nothing
1585 function column_type($table, $column) {
1586 error('column_type() removed');
1589 * @deprecated
1590 * @param mixed $rs
1591 * @return void Throws an error and does nothing
1593 function recordset_to_menu($rs) {
1594 error('recordset_to_menu() removed');
1597 * @deprecated
1598 * @param mixed $records
1599 * @param mixed $field1
1600 * @param mixed $field2
1601 * @return void Throws an error and does nothing
1603 function records_to_menu($records, $field1, $field2) {
1604 error('records_to_menu() removed');
1607 * @deprecated use $DB->set_field_select() instead
1608 * @see moodle_database::set_field_select()
1609 * @param mixed $table
1610 * @param mixed $newfield
1611 * @param mixed $newvalue
1612 * @param mixed $select
1613 * @param mixed $localcall
1614 * @return void Throws an error and does nothing
1616 function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) {
1617 error('set_field_select() removed');
1620 * @deprecated use $DB->get_fieldset_select() instead
1621 * @see moodle_database::get_fieldset_select()
1622 * @param mixed $table
1623 * @param mixed $return
1624 * @param mixed $select
1625 * @return void Throws an error and does nothing
1627 function get_fieldset_select($table, $return, $select) {
1628 error('get_fieldset_select() removed');
1631 * @deprecated use $DB->get_fieldset_sql() instead
1632 * @see moodle_database::get_fieldset_sql()
1633 * @param mixed $sql
1634 * @return void Throws an error and does nothing
1636 function get_fieldset_sql($sql) {
1637 error('get_fieldset_sql() removed');
1640 * @deprecated use $DB->sql_like() instead
1641 * @see moodle_database::sql_like()
1642 * @return void Throws an error and does nothing
1644 function sql_ilike() {
1645 error('sql_ilike() not available anymore');
1648 * @deprecated
1649 * @param mixed $first
1650 * @param mixed $last
1651 * @return void Throws an error and does nothing
1653 function sql_fullname($first='firstname', $last='lastname') {
1654 error('sql_fullname() not available anymore');
1657 * @deprecated
1658 * @return void Throws an error and does nothing
1660 function sql_concat() {
1661 error('sql_concat() not available anymore');
1664 * @deprecated
1665 * @return void Throws an error and does nothing
1667 function sql_empty() {
1668 error('sql_empty() not available anymore');
1671 * @deprecated
1672 * @return void Throws an error and does nothing
1674 function sql_substr() {
1675 error('sql_substr() not available anymore');
1678 * @deprecated
1679 * @param mixed $int1
1680 * @param mixed $int2
1681 * @return void Throws an error and does nothing
1683 function sql_bitand($int1, $int2) {
1684 error('sql_bitand() not available anymore');
1687 * @deprecated
1688 * @param mixed $int1
1689 * @return void Throws an error and does nothing
1691 function sql_bitnot($int1) {
1692 error('sql_bitnot() not available anymore');
1695 * @deprecated
1696 * @param mixed $int1
1697 * @param mixed $int2
1698 * @return void Throws an error and does nothing
1700 function sql_bitor($int1, $int2) {
1701 error('sql_bitor() not available anymore');
1704 * @deprecated
1705 * @param mixed $int1
1706 * @param mixed $int2
1707 * @return void Throws an error and does nothing
1709 function sql_bitxor($int1, $int2) {
1710 error('sql_bitxor() not available anymore');
1713 * @deprecated
1714 * @param mixed $fieldname
1715 * @param mixed $text
1716 * @return void Throws an error and does nothing
1718 function sql_cast_char2int($fieldname, $text=false) {
1719 error('sql_cast_char2int() not available anymore');
1722 * @deprecated
1723 * @param mixed $fieldname
1724 * @param mixed $numchars
1725 * @return void Throws an error and does nothing
1727 function sql_compare_text($fieldname, $numchars=32) {
1728 error('sql_compare_text() not available anymore');
1731 * @deprecated
1732 * @param mixed $fieldname
1733 * @param mixed $numchars
1734 * @return void Throws an error and does nothing
1736 function sql_order_by_text($fieldname, $numchars=32) {
1737 error('sql_order_by_text() not available anymore');
1740 * @deprecated
1741 * @param mixed $fieldname
1742 * @return void Throws an error and does nothing
1744 function sql_length($fieldname) {
1745 error('sql_length() not available anymore');
1748 * @deprecated
1749 * @param mixed $separator
1750 * @param mixed $elements
1751 * @return void Throws an error and does nothing
1753 function sql_concat_join($separator="' '", $elements=array()) {
1754 error('sql_concat_join() not available anymore');
1757 * @deprecated
1758 * @param mixed $tablename
1759 * @param mixed $fieldname
1760 * @param mixed $nullablefield
1761 * @param mixed $textfield
1762 * @return void Throws an error and does nothing
1764 function sql_isempty($tablename, $fieldname, $nullablefield, $textfield) {
1765 error('sql_isempty() not available anymore');
1768 * @deprecated
1769 * @param mixed $tablename
1770 * @param mixed $fieldname
1771 * @param mixed $nullablefield
1772 * @param mixed $textfield
1773 * @return void Throws an error and does nothing
1775 function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) {
1776 error('sql_isnotempty() not available anymore');
1779 * @deprecated
1780 * @return void Throws an error and does nothing
1782 function begin_sql() {
1783 error('begin_sql() not available anymore');
1786 * @deprecated
1787 * @return void Throws an error and does nothing
1789 function commit_sql() {
1790 error('commit_sql() not available anymore');
1793 * @deprecated
1794 * @return void Throws an error and does nothing
1796 function rollback_sql() {
1797 error('rollback_sql() not available anymore');
1800 * @deprecated use $DB->insert_record() instead
1801 * @see moodle_database::insert_record()
1802 * @param mixed $table
1803 * @param mixed $dataobject
1804 * @param mixed $returnid
1805 * @param mixed $primarykey
1806 * @return void Throws an error and does nothing
1808 function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
1809 error('insert_record() not available anymore');
1812 * @deprecated use $DB->update_record() instead
1813 * @see moodle_database::update_record()
1814 * @param mixed $table
1815 * @param mixed $dataobject
1816 * @return void Throws an error and does nothing
1818 function update_record($table, $dataobject) {
1819 error('update_record() not available anymore');
1822 * @deprecated use $DB->get_records() instead
1823 * @see moodle_database::get_records()
1824 * @param mixed $table
1825 * @param mixed $field
1826 * @param mixed $value
1827 * @param mixed $sort
1828 * @param mixed $fields
1829 * @param mixed $limitfrom
1830 * @param mixed $limitnum
1832 * @return void Throws an error and does nothing
1834 function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1835 error('get_records() not available anymore');
1838 * @deprecated use $DB->get_record() instead
1839 * @see moodle_database::get_record()
1840 * @param mixed $table
1841 * @param mixed $field1
1842 * @param mixed $value1
1843 * @param mixed $field2
1844 * @param mixed $value2
1845 * @param mixed $field3
1846 * @param mixed $value3
1847 * @param mixed $fields
1848 * @return void Throws an error and does nothing
1850 function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') {
1851 error('get_record() not available anymore');
1854 * @deprecated use $DB->set_field() instead
1855 * @see moodle_database::set_field()
1856 * @param mixed $table
1857 * @param mixed $newfield
1858 * @param mixed $newvalue
1859 * @param mixed $field1
1860 * @param mixed $value1
1861 * @param mixed $field2
1862 * @param mixed $value2
1863 * @param mixed $field3
1864 * @param mixed $value3
1865 * @return void Throws an error and does nothing
1867 function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1868 error('set_field() not available anymore');
1871 * @deprecated use $DB->count_records() instead
1872 * @see moodle_database::count_records()
1873 * @param mixed $table
1874 * @param mixed $field1
1875 * @param mixed $value1
1876 * @param mixed $field2
1877 * @param mixed $value2
1878 * @param mixed $field3
1879 * @param mixed $value3
1880 * @return void Throws an error and does nothing
1882 function count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1883 error('count_records() not available anymore');
1886 * @deprecated use $DB->record_exists() instead
1887 * @see moodle_database::record_exists()
1888 * @param mixed $table
1889 * @param mixed $field1
1890 * @param mixed $value1
1891 * @param mixed $field2
1892 * @param mixed $value2
1893 * @param mixed $field3
1894 * @param mixed $value3
1895 * @return void Throws an error and does nothing
1897 function record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1898 error('record_exists() not available anymore');
1901 * @deprecated use $DB->delete_records() instead
1902 * @see moodle_database::delete_records()
1903 * @param mixed $table
1904 * @param mixed $field1
1905 * @param mixed $value1
1906 * @param mixed $field2
1907 * @param mixed $value2
1908 * @param mixed $field3
1909 * @param mixed $value3
1910 * @return void Throws an error and does nothing
1912 function delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1913 error('delete_records() not available anymore');
1916 * @deprecated use $DB->get_field() instead
1917 * @see moodle_database::get_field()
1918 * @param mixed $table
1919 * @param mixed $return
1920 * @param mixed $field1
1921 * @param mixed $value1
1922 * @param mixed $field2
1923 * @param mixed $value2
1924 * @param mixed $field3
1925 * @param mixed $value3
1926 * @return void Throws an error and does nothing
1928 function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1929 error('get_field() not available anymore');
1932 * @deprecated
1933 * @param mixed $table
1934 * @param mixed $oldfield
1935 * @param mixed $field
1936 * @param mixed $type
1937 * @param mixed $size
1938 * @param mixed $signed
1939 * @param mixed $default
1940 * @param mixed $null
1941 * @param mixed $after
1942 * @return void Throws an error and does nothing
1944 function table_column($table, $oldfield, $field, $type='integer', $size='10',
1945 $signed='unsigned', $default='0', $null='not null', $after='') {
1946 error('table_column() was removed, please use new ddl functions');
1949 * @deprecated
1950 * @param mixed $name
1951 * @param mixed $editorhidebuttons
1952 * @param mixed $id
1953 * @return void Throws an error and does nothing
1955 function use_html_editor($name='', $editorhidebuttons='', $id='') {
1956 error('use_html_editor() not available anymore');
1960 * The old method that was used to include JavaScript libraries.
1961 * Please use $PAGE->requires->js_module() instead.
1963 * @param mixed $lib The library or libraries to load (a string or array of strings)
1964 * There are three way to specify the library:
1965 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
1966 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
1967 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
1968 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
1970 function require_js($lib) {
1971 global $CFG, $PAGE;
1972 // Add the lib to the list of libs to be loaded, if it isn't already
1973 // in the list.
1974 if (is_array($lib)) {
1975 foreach($lib as $singlelib) {
1976 require_js($singlelib);
1978 return;
1981 debugging('Call to deprecated function require_js. Please use $PAGE->requires->js_module() instead.', DEBUG_DEVELOPER);
1983 if (strpos($lib, 'yui_') === 0) {
1984 $PAGE->requires->yui2_lib(substr($lib, 4));
1985 } else {
1986 if ($PAGE->requires->is_head_done()) {
1987 echo html_writer::script('', $lib);
1988 } else {
1989 $PAGE->requires->js(new moodle_url($lib));
1995 * Makes an upload directory for a particular module.
1997 * This function has been deprecated by the file API changes in Moodle 2.0.
1999 * @deprecated
2000 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
2001 * @return string|false Returns full path to directory if successful, false if not
2003 function make_mod_upload_directory($courseid) {
2004 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
2008 * Used to be used for setting up the theme. No longer used by core code, and
2009 * should not have been used elsewhere.
2011 * The theme is now automatically initialised before it is first used. If you really need
2012 * to force this to happen, just reference $PAGE->theme.
2014 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
2015 * However, I can't think of any valid reason to do that outside the theme selector UI.
2017 * @deprecated
2018 * @param string $theme The theme to use defaults to current theme
2019 * @param array $params An array of parameters to use
2021 function theme_setup($theme = '', $params=NULL) {
2022 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
2023 'The current theme gets initialised automatically before it is first used.');
2027 * @deprecated use $PAGE->theme->name instead.
2028 * @return string the name of the current theme.
2030 function current_theme() {
2031 global $PAGE;
2032 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
2033 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
2034 return $PAGE->theme->name;
2038 * @todo Remove this deprecated function when no longer used
2039 * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
2041 * @param string $getid used to return $PAGE->pagetype.
2042 * @param string $getclass used to return $PAGE->legacyclass.
2044 function page_id_and_class(&$getid, &$getclass) {
2045 global $PAGE;
2046 debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
2047 $getid = $PAGE->pagetype;
2048 $getclass = $PAGE->legacyclass;
2052 * Prints some red text using echo
2054 * @deprecated
2055 * @param string $error The text to be displayed in red
2057 function formerr($error) {
2058 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
2059 global $OUTPUT;
2060 echo $OUTPUT->error_text($error);
2064 * Return the markup for the destination of the 'Skip to main content' links.
2065 * Accessibility improvement for keyboard-only users.
2067 * Used in course formats, /index.php and /course/index.php
2069 * @deprecated use $OUTPUT->skip_link_target() in instead.
2070 * @return string HTML element.
2072 function skip_main_destination() {
2073 global $OUTPUT;
2074 return $OUTPUT->skip_link_target();
2078 * Prints a string in a specified size (retained for backward compatibility)
2080 * @deprecated
2081 * @param string $text The text to be displayed
2082 * @param int $size The size to set the font for text display.
2083 * @param bool $return If set to true output is returned rather than echoed Default false
2084 * @return string|void String if return is true
2086 function print_headline($text, $size=2, $return=false) {
2087 global $OUTPUT;
2088 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
2089 $output = $OUTPUT->heading($text, $size);
2090 if ($return) {
2091 return $output;
2092 } else {
2093 echo $output;
2098 * Prints text in a format for use in headings.
2100 * @deprecated
2101 * @param string $text The text to be displayed
2102 * @param string $deprecated No longer used. (Use to do alignment.)
2103 * @param int $size The size to set the font for text display.
2104 * @param string $class
2105 * @param bool $return If set to true output is returned rather than echoed, default false
2106 * @param string $id The id to use in the element
2107 * @return string|void String if return=true nothing otherwise
2109 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
2110 global $OUTPUT;
2111 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
2112 if (!empty($deprecated)) {
2113 debugging('Use of deprecated align attribute of print_heading. ' .
2114 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
2116 $output = $OUTPUT->heading($text, $size, $class, $id);
2117 if ($return) {
2118 return $output;
2119 } else {
2120 echo $output;
2125 * Output a standard heading block
2127 * @deprecated
2128 * @param string $heading The text to write into the heading
2129 * @param string $class An additional Class Attr to use for the heading
2130 * @param bool $return If set to true output is returned rather than echoed, default false
2131 * @return string|void HTML String if return=true nothing otherwise
2133 function print_heading_block($heading, $class='', $return=false) {
2134 global $OUTPUT;
2135 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
2136 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
2137 if ($return) {
2138 return $output;
2139 } else {
2140 echo $output;
2145 * Print a message in a standard themed box.
2146 * Replaces print_simple_box (see deprecatedlib.php)
2148 * @deprecated
2149 * @param string $message, the content of the box
2150 * @param string $classes, space-separated class names.
2151 * @param string $ids
2152 * @param boolean $return, return as string or just print it
2153 * @return string|void mixed string or void
2155 function print_box($message, $classes='generalbox', $ids='', $return=false) {
2156 global $OUTPUT;
2157 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
2158 $output = $OUTPUT->box($message, $classes, $ids);
2159 if ($return) {
2160 return $output;
2161 } else {
2162 echo $output;
2167 * Starts a box using divs
2168 * Replaces print_simple_box_start (see deprecatedlib.php)
2170 * @deprecated
2171 * @param string $classes, space-separated class names.
2172 * @param string $ids
2173 * @param boolean $return, return as string or just print it
2174 * @return string|void string or void
2176 function print_box_start($classes='generalbox', $ids='', $return=false) {
2177 global $OUTPUT;
2178 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
2179 $output = $OUTPUT->box_start($classes, $ids);
2180 if ($return) {
2181 return $output;
2182 } else {
2183 echo $output;
2188 * Simple function to end a box (see above)
2189 * Replaces print_simple_box_end (see deprecatedlib.php)
2191 * @deprecated
2192 * @param boolean $return, return as string or just print it
2193 * @return string|void Depending on value of return
2195 function print_box_end($return=false) {
2196 global $OUTPUT;
2197 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
2198 $output = $OUTPUT->box_end();
2199 if ($return) {
2200 return $output;
2201 } else {
2202 echo $output;
2207 * Print a message in a standard themed container.
2209 * @deprecated
2210 * @param string $message, the content of the container
2211 * @param boolean $clearfix clear both sides
2212 * @param string $classes, space-separated class names.
2213 * @param string $idbase
2214 * @param boolean $return, return as string or just print it
2215 * @return string|void Depending on value of $return
2217 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
2218 global $OUTPUT;
2219 if ($clearfix) {
2220 $classes .= ' clearfix';
2222 $output = $OUTPUT->container($message, $classes, $idbase);
2223 if ($return) {
2224 return $output;
2225 } else {
2226 echo $output;
2231 * Starts a container using divs
2233 * @deprecated
2234 * @param boolean $clearfix clear both sides
2235 * @param string $classes, space-separated class names.
2236 * @param string $idbase
2237 * @param boolean $return, return as string or just print it
2238 * @return string|void Based on value of $return
2240 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
2241 global $OUTPUT;
2242 if ($clearfix) {
2243 $classes .= ' clearfix';
2245 $output = $OUTPUT->container_start($classes, $idbase);
2246 if ($return) {
2247 return $output;
2248 } else {
2249 echo $output;
2254 * Deprecated, now handled automatically in themes
2256 function check_theme_arrows() {
2257 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
2261 * Simple function to end a container (see above)
2263 * @deprecated
2264 * @param boolean $return, return as string or just print it
2265 * @return string|void Based on $return
2267 function print_container_end($return=false) {
2268 global $OUTPUT;
2269 $output = $OUTPUT->container_end();
2270 if ($return) {
2271 return $output;
2272 } else {
2273 echo $output;
2278 * Print a bold message in an optional color.
2280 * @deprecated use $OUTPUT->notification instead.
2281 * @param string $message The message to print out
2282 * @param string $style Optional style to display message text in
2283 * @param string $align Alignment option
2284 * @param bool $return whether to return an output string or echo now
2285 * @return string|bool Depending on $result
2287 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
2288 global $OUTPUT;
2290 if ($classes == 'green') {
2291 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
2292 $classes = 'notifysuccess'; // Backward compatible with old color system
2295 $output = $OUTPUT->notification($message, $classes);
2296 if ($return) {
2297 return $output;
2298 } else {
2299 echo $output;
2304 * Print a continue button that goes to a particular URL.
2306 * @deprecated since Moodle 2.0
2308 * @param string $link The url to create a link to.
2309 * @param bool $return If set to true output is returned rather than echoed, default false
2310 * @return string|void HTML String if return=true nothing otherwise
2312 function print_continue($link, $return = false) {
2313 global $CFG, $OUTPUT;
2315 if ($link == '') {
2316 if (!empty($_SERVER['HTTP_REFERER'])) {
2317 $link = $_SERVER['HTTP_REFERER'];
2318 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
2319 } else {
2320 $link = $CFG->wwwroot .'/';
2324 $output = $OUTPUT->continue_button($link);
2325 if ($return) {
2326 return $output;
2327 } else {
2328 echo $output;
2333 * Print a standard header
2335 * @param string $title Appears at the top of the window
2336 * @param string $heading Appears at the top of the page
2337 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
2338 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2339 * @param string $meta Meta tags to be added to the header
2340 * @param boolean $cache Should this page be cacheable?
2341 * @param string $button HTML code for a button (usually for module editing)
2342 * @param string $menu HTML code for a popup menu
2343 * @param boolean $usexml use XML for this page
2344 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2345 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2346 * @return string|void If return=true then string else void
2348 function print_header($title='', $heading='', $navigation='', $focus='',
2349 $meta='', $cache=true, $button='&nbsp;', $menu=null,
2350 $usexml=false, $bodytags='', $return=false) {
2351 global $PAGE, $OUTPUT;
2353 $PAGE->set_title($title);
2354 $PAGE->set_heading($heading);
2355 $PAGE->set_cacheable($cache);
2356 if ($button == '') {
2357 $button = '&nbsp;';
2359 $PAGE->set_button($button);
2360 $PAGE->set_headingmenu($menu);
2362 // TODO $menu
2364 if ($meta) {
2365 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2366 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2368 if ($usexml) {
2369 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2371 if ($bodytags) {
2372 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2375 $output = $OUTPUT->header();
2377 if ($return) {
2378 return $output;
2379 } else {
2380 echo $output;
2385 * This version of print_header is simpler because the course name does not have to be
2386 * provided explicitly in the strings. It can be used on the site page as in courses
2387 * Eventually all print_header could be replaced by print_header_simple
2389 * @deprecated since Moodle 2.0
2390 * @param string $title Appears at the top of the window
2391 * @param string $heading Appears at the top of the page
2392 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
2393 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2394 * @param string $meta Meta tags to be added to the header
2395 * @param boolean $cache Should this page be cacheable?
2396 * @param string $button HTML code for a button (usually for module editing)
2397 * @param string $menu HTML code for a popup menu
2398 * @param boolean $usexml use XML for this page
2399 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2400 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2401 * @return string|void If $return=true the return string else nothing
2403 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
2404 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
2406 global $COURSE, $CFG, $PAGE, $OUTPUT;
2408 if ($meta) {
2409 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2410 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2412 if ($usexml) {
2413 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2415 if ($bodytags) {
2416 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2419 $PAGE->set_title($title);
2420 $PAGE->set_heading($heading);
2421 $PAGE->set_cacheable(true);
2422 $PAGE->set_button($button);
2424 $output = $OUTPUT->header();
2426 if ($return) {
2427 return $output;
2428 } else {
2429 echo $output;
2433 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
2434 global $PAGE, $OUTPUT;
2435 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
2436 // TODO check arguments.
2437 if (is_string($course)) {
2438 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
2439 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
2440 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
2441 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
2443 if (!is_null($usercourse)) {
2444 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
2445 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
2447 $output = $OUTPUT->footer();
2448 if ($return) {
2449 return $output;
2450 } else {
2451 echo $output;
2456 * Returns text to be displayed to the user which reflects their login status
2458 * @global object
2459 * @global object
2460 * @global object
2461 * @global object
2462 * @uses CONTEXT_COURSE
2463 * @param course $course {@link $COURSE} object containing course information
2464 * @param user $user {@link $USER} object containing user information
2465 * @return string HTML
2467 function user_login_string($course='ignored', $user='ignored') {
2468 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
2469 return '';
2473 * Prints a nice side block with an optional header. The content can either
2474 * be a block of HTML or a list of text with optional icons.
2476 * @todo Finish documenting this function. Show example of various attributes, etc.
2478 * @static int $block_id Increments for each call to the function
2479 * @param string $heading HTML for the heading. Can include full HTML or just
2480 * plain text - plain text will automatically be enclosed in the appropriate
2481 * heading tags.
2482 * @param string $content HTML for the content
2483 * @param array $list an alternative to $content, it you want a list of things with optional icons.
2484 * @param array $icons optional icons for the things in $list.
2485 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
2486 * @param array $attributes an array of attribute => value pairs that are put on the
2487 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
2488 * already a class, class='block' is used.
2489 * @param string $title Plain text title, as embedded in the $heading.
2490 * @deprecated
2492 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
2493 global $OUTPUT;
2495 // We don't use $heading, becuse it often contains HTML that we don't want.
2496 // However, sometimes $title is not set, but $heading is.
2497 if (empty($title)) {
2498 $title = strip_tags($heading);
2501 // Render list contents to HTML if required.
2502 if (empty($content) && $list) {
2503 $content = $OUTPUT->list_block_contents($icons, $list);
2506 $bc = new block_contents();
2507 $bc->content = $content;
2508 $bc->footer = $footer;
2509 $bc->title = $title;
2511 if (isset($attributes['id'])) {
2512 $bc->id = $attributes['id'];
2513 unset($attributes['id']);
2515 $bc->attributes = $attributes;
2517 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
2521 * Starts a nice side block with an optional header.
2523 * @todo Finish documenting this function
2525 * @global object
2526 * @global object
2527 * @param string $heading HTML for the heading. Can include full HTML or just
2528 * plain text - plain text will automatically be enclosed in the appropriate
2529 * heading tags.
2530 * @param array $attributes HTML attributes to apply if possible
2531 * @deprecated
2533 function print_side_block_start($heading='', $attributes = array()) {
2534 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
2538 * Print table ending tags for a side block box.
2540 * @global object
2541 * @global object
2542 * @param array $attributes HTML attributes to apply if possible [id]
2543 * @param string $title
2544 * @deprecated
2546 function print_side_block_end($attributes = array(), $title='') {
2547 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
2551 * This was used by old code to see whether a block region had anything in it,
2552 * and hence wether that region should be printed.
2554 * We don't ever want old code to print blocks, so we now always return false.
2555 * The function only exists to avoid fatal errors in old code.
2557 * @deprecated since Moodle 2.0. always returns false.
2559 * @param object $blockmanager
2560 * @param string $region
2561 * @return bool
2563 function blocks_have_content(&$blockmanager, $region) {
2564 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
2565 return false;
2569 * This was used by old code to print the blocks in a region.
2571 * We don't ever want old code to print blocks, so this is now a no-op.
2572 * The function only exists to avoid fatal errors in old code.
2574 * @deprecated since Moodle 2.0. does nothing.
2576 * @param object $page
2577 * @param object $blockmanager
2578 * @param string $region
2580 function blocks_print_group($page, $blockmanager, $region) {
2581 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2585 * This used to be the old entry point for anyone that wants to use blocks.
2586 * Since we don't want people people dealing with blocks this way any more,
2587 * just return a suitable empty array.
2589 * @deprecated since Moodle 2.0.
2591 * @param object $page
2592 * @return array
2594 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
2595 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2596 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
2600 * This iterates over an array of blocks and calculates the preferred width
2601 * Parameter passed by reference for speed; it's not modified.
2603 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
2605 * @param mixed $instances
2607 function blocks_preferred_width($instances) {
2608 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2609 $width = 210;
2613 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2615 * @param object $page The page object
2616 * @param object $blockmanager The block manager object
2617 * @param string $blockaction One of [config, add, delete]
2618 * @param int|object $instanceorid The instance id or a block_instance object
2619 * @param bool $pinned
2620 * @param bool $redirect To redirect or not to that is the question but you should stick with true
2622 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
2623 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.');
2627 * You can use this to get the blocks to respond to URL actions without much hassle
2629 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
2631 * @param object $PAGE
2632 * @param object $blockmanager
2633 * @param bool $pinned
2635 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
2636 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
2640 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
2641 * in order to reduce code repetition.
2643 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2645 * @param $instance
2646 * @param $newpos
2647 * @param string|int $newweight
2648 * @param bool $pinned
2650 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
2651 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.');
2656 * Moves a block to the new position (column) and weight (sort order).
2658 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2660 * @param object $instance The block instance to be moved.
2661 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
2662 * @param string $destweight The destination sort order. If NULL, we add to the end
2663 * of the destination column.
2664 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
2665 * to a new position withing the pinned list. Likewise, we
2666 * can only moved non-pinned blocks to a new position within
2667 * the non-pinned list.
2668 * @return boolean success or failure
2670 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
2671 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.');
2675 * Print a nicely formatted table.
2677 * @deprecated since Moodle 2.0
2679 * @param array $table is an object with several properties.
2681 function print_table($table, $return=false) {
2682 global $OUTPUT;
2683 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
2684 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
2685 $newtable = new html_table();
2686 foreach ($table as $property => $value) {
2687 if (property_exists($newtable, $property)) {
2688 $newtable->{$property} = $value;
2691 if (isset($table->class)) {
2692 $newtable->attributes['class'] = $table->class;
2694 if (isset($table->rowclass) && is_array($table->rowclass)) {
2695 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
2696 $newtable->rowclasses = $table->rowclass;
2698 $output = html_writer::table($newtable);
2699 if ($return) {
2700 return $output;
2701 } else {
2702 echo $output;
2703 return true;
2708 * Creates and displays (or returns) a link to a popup window
2710 * @deprecated since Moodle 2.0
2712 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2713 * @param string $name Name to be assigned to the popup window (this is used by
2714 * client-side scripts to "talk" to the popup window)
2715 * @param string $linkname Text to be displayed as web link
2716 * @param int $height Height to assign to popup window
2717 * @param int $width Height to assign to popup window
2718 * @param string $title Text to be displayed as popup page title
2719 * @param string $options List of additional options for popup window
2720 * @param bool $return If true, return as a string, otherwise print
2721 * @param string $id id added to the element
2722 * @param string $class class added to the element
2723 * @return string html code to display a link to a popup window.
2725 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
2726 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');
2728 return html_writer::link($url, $name);
2732 * Creates and displays (or returns) a buttons to a popup window.
2734 * @deprecated since Moodle 2.0
2736 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2737 * @param string $name Name to be assigned to the popup window (this is used by
2738 * client-side scripts to "talk" to the popup window)
2739 * @param string $linkname Text to be displayed as web link
2740 * @param int $height Height to assign to popup window
2741 * @param int $width Height to assign to popup window
2742 * @param string $title Text to be displayed as popup page title
2743 * @param string $options List of additional options for popup window
2744 * @param bool $return If true, return as a string, otherwise print
2745 * @param string $id id added to the element
2746 * @param string $class class added to the element
2747 * @return string html code to display a link to a popup window.
2749 function button_to_popup_window ($url, $name=null, $linkname=null,
2750 $height=400, $width=500, $title=null, $options=null, $return=false,
2751 $id=null, $class=null) {
2752 global $OUTPUT;
2754 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2756 if ($options == 'none') {
2757 $options = null;
2760 if (empty($linkname)) {
2761 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
2764 // Create a single_button object
2765 $form = new single_button($url, $linkname, 'post');
2766 $form->button->title = $title;
2767 $form->button->id = $id;
2769 // Parse the $options string
2770 $popupparams = array();
2771 if (!empty($options)) {
2772 $optionsarray = explode(',', $options);
2773 foreach ($optionsarray as $option) {
2774 if (strstr($option, '=')) {
2775 $parts = explode('=', $option);
2776 if ($parts[1] == '0') {
2777 $popupparams[$parts[0]] = false;
2778 } else {
2779 $popupparams[$parts[0]] = $parts[1];
2781 } else {
2782 $popupparams[$option] = true;
2787 if (!empty($height)) {
2788 $popupparams['height'] = $height;
2790 if (!empty($width)) {
2791 $popupparams['width'] = $width;
2794 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
2795 $output = $OUTPUT->render($form);
2797 if ($return) {
2798 return $output;
2799 } else {
2800 echo $output;
2805 * Print a self contained form with a single submit button.
2807 * @deprecated since Moodle 2.0
2809 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
2810 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
2811 * @param string $label the caption that appears on the button.
2812 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
2813 * @param string $notusedanymore no longer used.
2814 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
2815 * @param string $tooltip a tooltip to add to the button as a title attribute.
2816 * @param boolean $disabled if true, the button will be disabled.
2817 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
2818 * @param string $formid The id attribute to use for the form
2819 * @return string|void Depending on the $return paramter.
2821 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
2822 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
2823 global $OUTPUT;
2825 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2827 // Cast $options to array
2828 $options = (array) $options;
2830 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
2832 if ($jsconfirmmessage) {
2833 $button->button->add_confirm_action($jsconfirmmessage);
2836 $output = $OUTPUT->render($button);
2838 if ($return) {
2839 return $output;
2840 } else {
2841 echo $output;
2846 * Print a spacer image with the option of including a line break.
2848 * @deprecated since Moodle 2.0
2850 * @global object
2851 * @param int $height The height in pixels to make the spacer
2852 * @param int $width The width in pixels to make the spacer
2853 * @param boolean $br If set to true a BR is written after the spacer
2855 function print_spacer($height=1, $width=1, $br=true, $return=false) {
2856 global $CFG, $OUTPUT;
2858 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
2860 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
2862 if ($return) {
2863 return $output;
2864 } else {
2865 echo $output;
2870 * Given the path to a picture file in a course, or a URL,
2871 * this function includes the picture in the page.
2873 * @deprecated since Moodle 2.0
2875 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
2876 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
2880 * Print the specified user's avatar.
2882 * @deprecated since Moodle 2.0
2884 * @global object
2885 * @global object
2886 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
2887 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
2888 * if at all possible, particularly for reports. It is very bad for performance.
2889 * @param int $courseid The course id. Used when constructing the link to the user's profile.
2890 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
2891 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
2892 * @param boolean $return If false print picture to current page, otherwise return the output as string
2893 * @param boolean $link enclose printed image in a link the user's profile (default true).
2894 * @param string $target link target attribute. Makes the profile open in a popup window.
2895 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
2896 * decorative images, or where the username will be printed anyway.)
2897 * @return string|void String or nothing, depending on $return.
2899 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
2900 global $OUTPUT;
2902 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
2904 if (!is_object($user)) {
2905 $userid = $user;
2906 $user = new stdClass();
2907 $user->id = $userid;
2910 if (empty($user->picture) and $picture) {
2911 $user->picture = $picture;
2914 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
2916 $output = $OUTPUT->user_picture($user, $options);
2918 if ($return) {
2919 return $output;
2920 } else {
2921 echo $output;
2926 * Print a png image.
2928 * @deprecated since Moodle 2.0: no replacement
2931 function print_png() {
2932 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
2937 * Prints a basic textarea field.
2939 * @deprecated since Moodle 2.0
2941 * When using this function, you should
2943 * @global object
2944 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
2945 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
2946 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
2947 * @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.
2948 * @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.
2949 * @param string $name Name to use for the textarea element.
2950 * @param string $value Initial content to display in the textarea.
2951 * @param int $obsolete deprecated
2952 * @param bool $return If false, will output string. If true, will return string value.
2953 * @param string $id CSS ID to add to the textarea element.
2954 * @return string|void depending on the value of $return
2956 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
2957 /// $width and height are legacy fields and no longer used as pixels like they used to be.
2958 /// However, you can set them to zero to override the mincols and minrows values below.
2960 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
2961 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
2963 global $CFG;
2965 $mincols = 65;
2966 $minrows = 10;
2967 $str = '';
2969 if ($id === '') {
2970 $id = 'edit-'.$name;
2973 if ($usehtmleditor) {
2974 if ($height && ($rows < $minrows)) {
2975 $rows = $minrows;
2977 if ($width && ($cols < $mincols)) {
2978 $cols = $mincols;
2982 if ($usehtmleditor) {
2983 editors_head_setup();
2984 $editor = editors_get_preferred_editor(FORMAT_HTML);
2985 $editor->use_editor($id, array('legacy'=>true));
2986 } else {
2987 $editorclass = '';
2990 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
2991 if ($usehtmleditor) {
2992 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
2993 } else {
2994 $str .= s($value);
2996 $str .= '</textarea>'."\n";
2998 if ($return) {
2999 return $str;
3001 echo $str;
3006 * Print a help button.
3008 * @deprecated since Moodle 2.0
3010 * @param string $page The keyword that defines a help page
3011 * @param string $title The title of links, rollover tips, alt tags etc
3012 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
3013 * @param string $module Which module is the page defined in
3014 * @param mixed $image Use a help image for the link? (true/false/"both")
3015 * @param boolean $linktext If true, display the title next to the help icon.
3016 * @param string $text If defined then this text is used in the page, and
3017 * the $page variable is ignored. DEPRECATED!
3018 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
3019 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
3020 * @return string|void Depending on value of $return
3022 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
3023 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
3025 global $OUTPUT;
3027 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
3029 // hide image with CSS if needed
3031 if ($return) {
3032 return $output;
3033 } else {
3034 echo $output;
3039 * Print a help button.
3041 * Prints a special help button that is a link to the "live" emoticon popup
3043 * @todo Finish documenting this function
3045 * @global object
3046 * @global object
3047 * @param string $form ?
3048 * @param string $field ?
3049 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
3050 * @return string|void Depending on value of $return
3052 function emoticonhelpbutton($form, $field, $return = false) {
3053 /// TODO: MDL-21215
3055 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
3059 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
3060 * Should be used only with htmleditor or textarea.
3062 * @global object
3063 * @global object
3064 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
3065 * helpbutton.
3066 * @return string Link to help button
3068 function editorhelpbutton(){
3069 return '';
3071 /// TODO: MDL-21215
3075 * Print a help button.
3077 * Prints a special help button for html editors (htmlarea in this case)
3079 * @todo Write code into this function! detect current editor and print correct info
3080 * @global object
3081 * @return string Only returns an empty string at the moment
3083 function editorshortcutshelpbutton() {
3084 /// TODO: MDL-21215
3086 global $CFG;
3087 //TODO: detect current editor and print correct info
3088 /* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
3089 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
3091 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
3092 return '';
3097 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
3098 * provide this function with the language strings for sortasc and sortdesc.
3100 * @deprecated since Moodle 2.0
3102 * TODO migrate to outputlib
3103 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
3105 * @global object
3106 * @param string $direction 'up' or 'down'
3107 * @param string $strsort The language string used for the alt attribute of this image
3108 * @param bool $return Whether to print directly or return the html string
3109 * @return string|void depending on $return
3112 function print_arrow($direction='up', $strsort=null, $return=false) {
3113 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
3115 global $OUTPUT;
3117 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
3118 return null;
3121 $return = null;
3123 switch ($direction) {
3124 case 'up':
3125 $sortdir = 'asc';
3126 break;
3127 case 'down':
3128 $sortdir = 'desc';
3129 break;
3130 case 'move':
3131 $sortdir = 'asc';
3132 break;
3133 default:
3134 $sortdir = null;
3135 break;
3138 // Prepare language string
3139 $strsort = '';
3140 if (empty($strsort) && !empty($sortdir)) {
3141 $strsort = get_string('sort' . $sortdir, 'grades');
3144 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
3146 if ($return) {
3147 return $return;
3148 } else {
3149 echo $return;
3154 * Returns a string containing a link to the user documentation.
3155 * Also contains an icon by default. Shown to teachers and admin only.
3157 * @deprecated since Moodle 2.0
3159 * @global object
3160 * @param string $path The page link after doc root and language, no leading slash.
3161 * @param string $text The text to be displayed for the link
3162 * @param string $iconpath The path to the icon to be displayed
3163 * @return string Either the link or an empty string
3165 function doc_link($path='', $text='', $iconpath='ignored') {
3166 global $CFG, $OUTPUT;
3168 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
3170 if (empty($CFG->docroot)) {
3171 return '';
3174 return $OUTPUT->doc_link($path, $text);
3178 * Prints a single paging bar to provide access to other pages (usually in a search)
3180 * @deprecated since Moodle 2.0
3182 * @param int $totalcount Thetotal number of entries available to be paged through
3183 * @param int $page The page you are currently viewing
3184 * @param int $perpage The number of entries that should be shown per page
3185 * @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.
3186 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
3187 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
3188 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
3189 * @param bool $return whether to return an output string or echo now
3190 * @return bool|string depending on $result
3192 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
3193 global $OUTPUT;
3195 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
3197 if (empty($nocurr)) {
3198 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
3201 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
3202 $pagingbar->pagevar = $pagevar;
3203 $output = $OUTPUT->render($pagingbar);
3205 if ($return) {
3206 return $output;
3209 echo $output;
3210 return true;
3214 * Print a message along with "Yes" and "No" links for the user to continue.
3216 * @deprecated since Moodle 2.0
3218 * @global object
3219 * @param string $message The text to display
3220 * @param string $linkyes The link to take the user to if they choose "Yes"
3221 * @param string $linkno The link to take the user to if they choose "No"
3222 * @param string $optionyes The yes option to show on the notice
3223 * @param string $optionsno The no option to show
3224 * @param string $methodyes Form action method to use if yes [post, get]
3225 * @param string $methodno Form action method to use if no [post, get]
3226 * @return void Output is echo'd
3228 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
3230 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
3232 global $OUTPUT;
3234 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
3235 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
3237 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
3241 * Prints a scale menu (as part of an existing form) including help button
3242 * @deprecated since Moodle 2.0
3244 function print_scale_menu() {
3245 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
3249 * Given an array of values, output the HTML for a select element with those options.
3251 * @deprecated since Moodle 2.0
3253 * Normally, you only need to use the first few parameters.
3255 * @param array $options The options to offer. An array of the form
3256 * $options[{value}] = {text displayed for that option};
3257 * @param string $name the name of this form control, as in &lt;select name="..." ...
3258 * @param string $selected the option to select initially, default none.
3259 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
3260 * Set this to '' if you don't want a 'nothing is selected' option.
3261 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3262 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
3263 * @param boolean $return if false (the default) the the output is printed directly, If true, the
3264 * generated HTML is returned as a string.
3265 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
3266 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
3267 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
3268 * then a suitable one is constructed.
3269 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
3270 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
3271 * $listbox is an integer, that number is used for size instead.
3272 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
3273 * when $listbox display is enabled
3274 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
3275 * then a suitable one is constructed.
3276 * @return string|void If $return=true returns string, else echo's and returns void
3278 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
3279 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
3280 $id='', $listbox=false, $multiple=false, $class='') {
3282 global $OUTPUT;
3283 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
3285 if ($script) {
3286 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3288 $attributes = array();
3289 $attributes['disabled'] = $disabled ? 'disabled' : null;
3290 $attributes['tabindex'] = $tabindex ? $tabindex : null;
3291 $attributes['multiple'] = $multiple ? $multiple : null;
3292 $attributes['class'] = $class ? $class : null;
3293 $attributes['id'] = $id ? $id : null;
3295 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
3297 if ($return) {
3298 return $output;
3299 } else {
3300 echo $output;
3305 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
3306 * Other options like choose_from_menu.
3308 * @deprecated since Moodle 2.0
3310 * Calls {@link choose_from_menu()} with preset arguments
3311 * @see choose_from_menu()
3313 * @param string $name the name of this form control, as in &lt;select name="..." ...
3314 * @param string $selected the option to select initially, default none.
3315 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3316 * @param boolean $return Whether this function should return a string or output it (defaults to false)
3317 * @param boolean $disabled (defaults to false)
3318 * @param int $tabindex
3319 * @return string|void If $return=true returns string, else echo's and returns void
3321 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
3322 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
3323 global $OUTPUT;
3325 if ($script) {
3326 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3329 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
3331 if ($return) {
3332 return $output;
3333 } else {
3334 echo $output;
3339 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
3340 * including option headings with the first level.
3342 * @deprecated since Moodle 2.0
3344 * This function is very similar to {@link choose_from_menu_yesno()}
3345 * and {@link choose_from_menu()}
3347 * @todo Add datatype handling to make sure $options is an array
3349 * @param array $options An array of objects to choose from
3350 * @param string $name The XHTML field name
3351 * @param string $selected The value to select by default
3352 * @param string $nothing The label for the 'nothing is selected' option.
3353 * Defaults to get_string('choose').
3354 * @param string $script If not '', then this is added to the &lt;select> element
3355 * as an onchange handler.
3356 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
3357 * @param bool $return Whether this function should return a string or output
3358 * it (defaults to false)
3359 * @param bool $disabled Is the field disabled by default
3360 * @param int|string $tabindex Override the tabindex attribute [numeric]
3361 * @return string|void If $return=true returns string, else echo's and returns void
3363 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
3364 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
3366 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
3367 global $OUTPUT;
3371 * Prints a help button about a scale
3373 * @deprecated since Moodle 2.0
3375 * @global object
3376 * @param id $courseid
3377 * @param object $scale
3378 * @param boolean $return If set to true returns rather than echo's
3379 * @return string|bool Depending on value of $return
3381 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
3382 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
3383 global $OUTPUT;
3385 $output = $OUTPUT->help_icon_scale($courseid, $scale);
3387 if ($return) {
3388 return $output;
3389 } else {
3390 echo $output;
3396 * Prints time limit value selector
3398 * @deprecated since Moodle 2.0
3400 * Uses {@link choose_from_menu()} to generate HTML
3401 * @see choose_from_menu()
3403 * @global object
3404 * @param int $timelimit default
3405 * @param string $unit
3406 * @param string $name
3407 * @param boolean $return If set to true returns rather than echo's
3408 * @return string|bool Depending on value of $return
3410 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
3411 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
3415 * Prints form items with the names $hour and $minute
3417 * @deprecated since Moodle 2.0
3419 * @param string $hour fieldname
3420 * @param string $minute fieldname
3421 * @param int $currenttime A default timestamp in GMT
3422 * @param int $step minute spacing
3423 * @param boolean $return If set to true returns rather than echo's
3424 * @return string|bool Depending on value of $return
3426 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
3427 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
3429 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
3430 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
3432 $output = $hourselector . $$minuteselector;
3434 if ($return) {
3435 return $output;
3436 } else {
3437 echo $output;
3442 * Prints form items with the names $day, $month and $year
3444 * @deprecated since Moodle 2.0
3446 * @param string $day fieldname
3447 * @param string $month fieldname
3448 * @param string $year fieldname
3449 * @param int $currenttime A default timestamp in GMT
3450 * @param boolean $return If set to true returns rather than echo's
3451 * @return string|bool Depending on value of $return
3453 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
3454 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
3456 $dayselector = html_writer::select_time('days', $day, $currenttime);
3457 $monthselector = html_writer::select_time('months', $month, $currenttime);
3458 $yearselector = html_writer::select_time('years', $year, $currenttime);
3460 $output = $dayselector . $monthselector . $yearselector;
3462 if ($return) {
3463 return $output;
3464 } else {
3465 echo $output;
3470 * Implements a complete little form with a dropdown menu.
3472 * @deprecated since Moodle 2.0
3474 * When JavaScript is on selecting an option from the dropdown automatically
3475 * submits the form (while avoiding the usual acessibility problems with this appoach).
3476 * With JavaScript off, a 'Go' button is printed.
3478 * @global object
3479 * @global object
3480 * @param string $baseurl The target URL up to the point of the variable that changes
3481 * @param array $options A list of value-label pairs for the popup list
3482 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
3483 * @param string $selected The option that is initially selected
3484 * @param string $nothing The label for the "no choice" option
3485 * @param string $help The name of a help page if help is required
3486 * @param string $helptext The name of the label for the help button
3487 * @param boolean $return Indicates whether the function should return the HTML
3488 * as a string or echo it directly to the page being rendered
3489 * @param string $targetwindow The name of the target page to open the linked page in.
3490 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
3491 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
3492 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
3493 * @param boolean $disabled If true, the menu will be displayed disabled.
3494 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
3495 * @return string|void If $return=true returns string, else echo's and returns void
3497 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
3498 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
3499 global $OUTPUT, $CFG;
3501 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
3503 if (empty($options)) {
3504 return '';
3507 $urls = array();
3509 foreach ($options as $value=>$label) {
3510 $url = $baseurl.$value;
3511 $url = str_replace($CFG->wwwroot, '', $url);
3512 $url = str_replace('&amp;', '&', $url);
3513 $urls[$url] = $label;
3514 if ($selected == $value) {
3515 $active = $url;
3519 $nothing = $nothing ? array(''=>$nothing) : null;
3521 $select = new url_select($urls, $active, $nothing, $formid);
3522 $select->disabled = $disabled;
3524 $select->set_label($selectlabel);
3525 $select->set_old_help_icon($help, $helptext);
3527 $output = $OUTPUT->render($select);
3529 if ($return) {
3530 return $output;
3531 } else {
3532 echo $output;
3537 * Prints a simple button to close a window
3539 * @deprecated since Moodle 2.0
3541 * @global object
3542 * @param string $name Name of the window to close
3543 * @param boolean $return whether this function should return a string or output it.
3544 * @param boolean $reloadopener if true, clicking the button will also reload
3545 * the page that opend this popup window.
3546 * @return string|void if $return is true, void otherwise
3548 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
3549 global $OUTPUT;
3551 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
3552 $output = $OUTPUT->close_window_button(get_string($name));
3554 if ($return) {
3555 return $output;
3556 } else {
3557 echo $output;
3562 * Given an array of values, creates a group of radio buttons to be part of a form
3564 * @deprecated since Moodle 2.0
3566 * @staticvar int $idcounter
3567 * @param array $options An array of value-label pairs for the radio group (values as keys)
3568 * @param string $name Name of the radiogroup (unique in the form)
3569 * @param string $checked The value that is already checked
3570 * @param bool $return Whether this function should return a string or output
3571 * it (defaults to false)
3572 * @return string|void If $return=true returns string, else echo's and returns void
3574 function choose_from_radio ($options, $name, $checked='', $return=false) {
3575 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
3579 * Display an standard html checkbox with an optional label
3581 * @deprecated since Moodle 2.0
3583 * @staticvar int $idcounter
3584 * @param string $name The name of the checkbox
3585 * @param string $value The valus that the checkbox will pass when checked
3586 * @param bool $checked The flag to tell the checkbox initial state
3587 * @param string $label The label to be showed near the checkbox
3588 * @param string $alt The info to be inserted in the alt tag
3589 * @param string $script If not '', then this is added to the checkbox element
3590 * as an onchange handler.
3591 * @param bool $return Whether this function should return a string or output
3592 * it (defaults to false)
3593 * @return string|void If $return=true returns string, else echo's and returns void
3595 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
3597 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
3598 global $OUTPUT;
3600 if (!empty($script)) {
3601 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
3604 $output = html_writer::checkbox($name, $value, $checked, $label);
3606 if (empty($return)) {
3607 echo $output;
3608 } else {
3609 return $output;
3616 * Display an standard html text field with an optional label
3618 * @deprecated since Moodle 2.0
3620 * @param string $name The name of the text field
3621 * @param string $value The value of the text field
3622 * @param string $alt The info to be inserted in the alt tag
3623 * @param int $size Sets the size attribute of the field. Defaults to 50
3624 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
3625 * @param bool $return Whether this function should return a string or output
3626 * it (defaults to false)
3627 * @return string|void If $return=true returns string, else echo's and returns void
3629 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
3630 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
3632 if ($alt === '') {
3633 $alt = null;
3636 $style = "width: {$size}px;";
3637 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
3638 if ($maxlength) {
3639 $attributes['maxlength'] = $maxlength;
3642 $output = html_writer::empty_tag('input', $attributes);
3644 if (empty($return)) {
3645 echo $output;
3646 } else {
3647 return $output;
3653 * Centered heading with attached help button (same title text)
3654 * and optional icon attached
3656 * @deprecated since Moodle 2.0
3658 * @param string $text The text to be displayed
3659 * @param string $helppage The help page to link to
3660 * @param string $module The module whose help should be linked to
3661 * @param string $icon Image to display if needed
3662 * @param bool $return If set to true output is returned rather than echoed, default false
3663 * @return string|void String if return=true nothing otherwise
3665 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
3667 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
3669 global $OUTPUT;
3671 // Extract the src from $icon if it exists
3672 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
3673 $icon = $matches[1];
3674 $icon = new moodle_url($icon);
3675 } else {
3676 $icon = '';
3679 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
3681 if ($return) {
3682 return $output;
3683 } else {
3684 echo $output;
3689 * Returns a turn edit on/off button for course in a self contained form.
3690 * Used to be an icon, but it's now a simple form button
3691 * @deprecated since Moodle 2.0
3693 function update_mymoodle_icon() {
3694 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
3698 * Returns a turn edit on/off button for tag in a self contained form.
3699 * @deprecated since Moodle 2.0
3700 * @param string $tagid The ID attribute
3701 * @return string
3703 function update_tag_button($tagid) {
3704 global $OUTPUT;
3705 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3706 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
3711 * Prints the 'update this xxx' button that appears on module pages.
3713 * @deprecated since Moodle 2.0
3715 * @param string $cmid the course_module id.
3716 * @param string $ignored not used any more. (Used to be courseid.)
3717 * @param string $string the module name - get_string('modulename', 'xxx')
3718 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
3720 function update_module_button($cmid, $ignored, $string) {
3721 global $CFG, $OUTPUT;
3723 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
3725 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
3727 if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
3728 $string = get_string('updatethis', '', $string);
3730 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
3731 return $OUTPUT->single_button($url, $string);
3732 } else {
3733 return '';
3738 * Prints the editing button on search results listing
3739 * For bulk move courses to another category
3740 * @deprecated since Moodle 2.0
3742 function update_categories_search_button($search,$page,$perpage) {
3743 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
3747 * Prints a summary of a user in a nice little box.
3748 * @deprecated since Moodle 2.0
3750 function print_user($user, $course, $messageselect=false, $return=false) {
3751 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
3755 * Returns a turn edit on/off button for course in a self contained form.
3756 * Used to be an icon, but it's now a simple form button
3758 * Note that the caller is responsible for capchecks.
3760 * @global object
3761 * @global object
3762 * @param int $courseid The course to update by id as found in 'course' table
3763 * @return string
3765 function update_course_icon($courseid) {
3766 global $CFG, $OUTPUT;
3768 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3770 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
3774 * Prints breadcrumb trail of links, called in theme/-/header.html
3776 * This function has now been deprecated please use output's navbar method instead
3777 * as shown below
3779 * <code php>
3780 * echo $OUTPUT->navbar();
3781 * </code>
3783 * @deprecated since 2.0
3784 * @param mixed $navigation deprecated
3785 * @param string $separator OBSOLETE, and now deprecated
3786 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
3787 * @return string|void String or null, depending on $return.
3789 function print_navigation ($navigation, $separator=0, $return=false) {
3790 global $OUTPUT,$PAGE;
3792 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
3794 $output = $OUTPUT->navbar();
3796 if ($return) {
3797 return $output;
3798 } else {
3799 echo $output;
3804 * This function will build the navigation string to be used by print_header
3805 * and others.
3807 * It automatically generates the site and course level (if appropriate) links.
3809 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
3810 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
3812 * If you want to add any further navigation links after the ones this function generates,
3813 * the pass an array of extra link arrays like this:
3814 * array(
3815 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
3816 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
3818 * The normal case is to just add one further link, for example 'Editing forum' after
3819 * 'General Developer Forum', with no link.
3820 * To do that, you need to pass
3821 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
3822 * However, becuase this is a very common case, you can use a shortcut syntax, and just
3823 * pass the string 'Editing forum', instead of an array as $extranavlinks.
3825 * At the moment, the link types only have limited significance. Type 'activity' is
3826 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
3827 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
3828 * This really needs to be documented better. In the mean time, try to be consistent, it will
3829 * enable people to customise the navigation more in future.
3831 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
3832 * If you get the $cm object using the function get_coursemodule_from_instance or
3833 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
3834 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
3835 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
3836 * warning is printed in developer debug mode.
3838 * @deprecated since 2.0
3839 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
3840 * only want one extra item with no link, you can pass a string instead. If you don't want
3841 * any extra links, pass an empty string.
3842 * @param mixed $cm deprecated
3843 * @return array Navigation array
3845 function build_navigation($extranavlinks, $cm = null) {
3846 global $CFG, $COURSE, $DB, $SITE, $PAGE;
3848 if (is_array($extranavlinks) && count($extranavlinks)>0) {
3849 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
3850 foreach ($extranavlinks as $nav) {
3851 if (array_key_exists('name', $nav)) {
3852 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
3853 $link = $nav['link'];
3854 } else {
3855 $link = null;
3857 $PAGE->navbar->add($nav['name'],$link);
3862 return(array('newnav' => true, 'navlinks' => array()));
3866 * Returns a small popup menu of course activity modules
3868 * Given a course and a (current) coursemodule
3869 * his function returns a small popup menu with all the
3870 * course activity modules in it, as a navigation menu
3871 * The data is taken from the serialised array stored in
3872 * the course record
3874 * @global object
3875 * @global object
3876 * @global object
3877 * @global object
3878 * @uses CONTEXT_COURSE
3879 * @param object $course A {@link $COURSE} object.
3880 * @param object $cm A {@link $COURSE} object.
3881 * @param string $targetwindow The target window attribute to us
3882 * @return string
3884 function navmenu($course, $cm=NULL, $targetwindow='self') {
3885 // This function has been deprecated with the creation of the global nav in
3886 // moodle 2.0
3888 return '';
3892 * Returns a little popup menu for switching roles
3894 * @deprecated in Moodle 2.0
3895 * @param int $courseid The course to update by id as found in 'course' table
3896 * @return string
3898 function switchroles_form($courseid) {
3899 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
3900 return '';
3904 * Print header for admin page
3905 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
3906 * @param string $focus focus element
3908 function admin_externalpage_print_header($focus='') {
3909 global $OUTPUT;
3911 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
3913 echo $OUTPUT->header();
3917 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
3919 function admin_externalpage_print_footer() {
3920 // TODO Still 103 referernces in core code. Don't do debugging output yet.
3921 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
3922 global $OUTPUT;
3923 echo $OUTPUT->footer();
3926 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
3930 * Call this function to add an event to the calendar table and to call any calendar plugins
3932 * @param object $event An object representing an event from the calendar table.
3933 * The event will be identified by the id field. The object event should include the following:
3934 * <ul>
3935 * <li><b>$event->name</b> - Name for the event
3936 * <li><b>$event->description</b> - Description of the event (defaults to '')
3937 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
3938 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
3939 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
3940 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
3941 * <li><b>$event->modulename</b> - Name of the module that creates this event
3942 * <li><b>$event->instance</b> - Instance of the module that owns this event
3943 * <li><b>$event->eventtype</b> - The type info together with the module info could
3944 * be used by calendar plugins to decide how to display event
3945 * <li><b>$event->timestart</b>- Timestamp for start of event
3946 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
3947 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
3948 * </ul>
3949 * @return int|false The id number of the resulting record or false if failed
3951 function add_event($event) {
3952 global $CFG;
3953 require_once($CFG->dirroot.'/calendar/lib.php');
3954 $event = calendar_event::create($event);
3955 if ($event !== false) {
3956 return $event->id;
3958 return false;
3962 * Call this function to update an event in the calendar table
3963 * the event will be identified by the id field of the $event object.
3965 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3966 * @return bool Success
3968 function update_event($event) {
3969 global $CFG;
3970 require_once($CFG->dirroot.'/calendar/lib.php');
3971 $event = (object)$event;
3972 $calendarevent = calendar_event::load($event->id);
3973 return $calendarevent->update($event);
3977 * Call this function to delete the event with id $id from calendar table.
3979 * @param int $id The id of an event from the 'event' table.
3980 * @return bool
3982 function delete_event($id) {
3983 global $CFG;
3984 require_once($CFG->dirroot.'/calendar/lib.php');
3985 $event = calendar_event::load($id);
3986 return $event->delete();
3990 * Call this function to hide an event in the calendar table
3991 * the event will be identified by the id field of the $event object.
3993 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3994 * @return true
3996 function hide_event($event) {
3997 global $CFG;
3998 require_once($CFG->dirroot.'/calendar/lib.php');
3999 $event = new calendar_event($event);
4000 return $event->toggle_visibility(false);
4004 * Call this function to unhide an event in the calendar table
4005 * the event will be identified by the id field of the $event object.
4007 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
4008 * @return true
4010 function show_event($event) {
4011 global $CFG;
4012 require_once($CFG->dirroot.'/calendar/lib.php');
4013 $event = new calendar_event($event);
4014 return $event->toggle_visibility(true);