weekly release 2.1.7+
[moodle.git] / lib / deprecatedlib.php
blob95b7c543fbd118a3eb8c3969f365bdd0e5eee5b1
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();
34 /**
35 * Insert or update log display entry. Entry may already exist.
36 * $module, $action must be unique
37 * @deprecated
39 * @param string $module
40 * @param string $action
41 * @param string $mtable
42 * @param string $field
43 * @return void
46 function update_log_display_entry($module, $action, $mtable, $field) {
47 global $DB;
49 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
52 /**
53 * Given some text in HTML format, this function will pass it
54 * through any filters that have been configured for this context.
56 * @deprecated use the text formatting in a standard way instead,
57 * this was abused mostly for embedding of attachments
59 * @param string $text The text to be passed through format filters
60 * @param int $courseid The current course.
61 * @return string the filtered string.
63 function filter_text($text, $courseid = NULL) {
64 global $CFG, $COURSE;
66 if (!$courseid) {
67 $courseid = $COURSE->id;
70 if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
71 return $text;
74 return filter_manager::instance()->filter_text($text, $context);
77 /**
78 * This function indicates that current page requires the https
79 * when $CFG->loginhttps enabled.
81 * By using this function properly, we can ensure 100% https-ized pages
82 * at our entire discretion (login, forgot_password, change_password)
83 * @deprecated use $PAGE->https_required() instead
85 function httpsrequired() {
86 global $PAGE;
87 $PAGE->https_required();
90 /**
91 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
93 * @deprecated use moodle_url factory methods instead
95 * @param string $path Physical path to a file
96 * @param array $options associative array of GET variables to append to the URL
97 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
98 * @return string URL to file
100 function get_file_url($path, $options=null, $type='coursefile') {
101 global $CFG;
103 $path = str_replace('//', '/', $path);
104 $path = trim($path, '/'); // no leading and trailing slashes
106 // type of file
107 switch ($type) {
108 case 'questionfile':
109 $url = $CFG->wwwroot."/question/exportfile.php";
110 break;
111 case 'rssfile':
112 $url = $CFG->wwwroot."/rss/file.php";
113 break;
114 case 'httpscoursefile':
115 $url = $CFG->httpswwwroot."/file.php";
116 break;
117 case 'coursefile':
118 default:
119 $url = $CFG->wwwroot."/file.php";
122 if ($CFG->slasharguments) {
123 $parts = explode('/', $path);
124 foreach ($parts as $key => $part) {
125 /// anchor dash character should not be encoded
126 $subparts = explode('#', $part);
127 $subparts = array_map('rawurlencode', $subparts);
128 $parts[$key] = implode('#', $subparts);
130 $path = implode('/', $parts);
131 $ffurl = $url.'/'.$path;
132 $separator = '?';
133 } else {
134 $path = rawurlencode('/'.$path);
135 $ffurl = $url.'?file='.$path;
136 $separator = '&amp;';
139 if ($options) {
140 foreach ($options as $name=>$value) {
141 $ffurl = $ffurl.$separator.$name.'='.$value;
142 $separator = '&amp;';
146 return $ffurl;
150 * If there has been an error uploading a file, print the appropriate error message
151 * Numerical constants used as constant definitions not added until PHP version 4.2.0
152 * @deprecated removed - use new file api
154 function print_file_upload_error($filearray = '', $returnerror = false) {
155 throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
159 * Handy function for resolving file conflicts
160 * @deprecated removed - use new file api
163 function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
164 throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
168 * Checks a file name for any conflicts
169 * @deprecated removed - use new file api
171 function check_potential_filename($destination,$filename,$files) {
172 throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
176 * This function prints out a number of upload form elements.
177 * @deprecated removed - use new file api
179 function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
180 throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
184 * Return the authentication plugin title
186 * @param string $authtype plugin type
187 * @return string
189 function auth_get_plugin_title($authtype) {
190 debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
191 return get_string('pluginname', "auth_{$authtype}");
197 * Enrol someone without using the default role in a course
198 * @deprecated
200 function enrol_into_course($course, $user, $enrol) {
201 error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
205 * Returns a role object that is the default role for new enrolments in a given course
207 * @deprecated
208 * @param object $course
209 * @return object returns a role or NULL if none set
211 function get_default_course_role($course) {
212 debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
214 $student = get_archetype_roles('student');
215 $student = reset($student);
217 return $student;
221 * Extremely slow enrolled courses query.
222 * @deprecated
224 function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
225 error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
229 * Was returning list of translations, use new string_manager instead
231 * @deprecated
232 * @param bool $refreshcache force refreshing of lang cache
233 * @param bool $returnall ignore langlist, return all languages available
234 * @return array An associative array with contents in the form of LanguageCode => LanguageName
236 function get_list_of_languages($refreshcache=false, $returnall=false) {
237 debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
238 if ($refreshcache) {
239 get_string_manager()->reset_caches();
241 return get_string_manager()->get_list_of_translations($returnall);
245 * Returns a list of currencies in the current language
246 * @deprecated
247 * @return array
249 function get_list_of_currencies() {
250 debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
251 return get_string_manager()->get_list_of_currencies();
255 * Returns a list of all enabled country names in the current translation
256 * @deprecated
257 * @return array two-letter country code => translated name.
259 function get_list_of_countries() {
260 debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
261 return get_string_manager()->get_list_of_countries(false);
265 * @deprecated
267 function isteacher() {
268 error('Function isteacher() was removed, please use capabilities instead!');
272 * @deprecated
274 function isteacherinanycourse() {
275 error('Function isteacherinanycourse() was removed, please use capabilities instead!');
279 * @deprecated
281 function get_guest() {
282 error('Function get_guest() was removed, please use capabilities instead!');
286 * @deprecated
288 function isguest() {
289 error('Function isguest() was removed, please use capabilities instead!');
293 * @deprecated
295 function get_teacher() {
296 error('Function get_teacher() was removed, please use capabilities instead!');
300 * Return all course participant for a given course
302 * @deprecated
303 * @param integer $courseid
304 * @return array of user
306 function get_course_participants($courseid) {
307 return get_enrolled_users(get_context_instance(CONTEXT_COURSE, $courseid));
311 * Return true if the user is a participant for a given course
313 * @deprecated
314 * @param integer $userid
315 * @param integer $courseid
316 * @return boolean
318 function is_course_participant($userid, $courseid) {
319 return is_enrolled(get_context_instance(CONTEXT_COURSE, $courseid), $userid);
323 * Searches logs to find all enrolments since a certain date
325 * used to print recent activity
327 * @global object
328 * @uses CONTEXT_COURSE
329 * @param int $courseid The course in question.
330 * @param int $timestart The date to check forward of
331 * @return object|false {@link $USER} records or false if error.
333 function get_recent_enrolments($courseid, $timestart) {
334 global $DB;
336 $context = get_context_instance(CONTEXT_COURSE, $courseid);
338 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
339 FROM {user} u, {role_assignments} ra, {log} l
340 WHERE l.time > ?
341 AND l.course = ?
342 AND l.module = 'course'
343 AND l.action = 'enrol'
344 AND ".$DB->sql_cast_char2int('l.info')." = u.id
345 AND u.id = ra.userid
346 AND ra.contextid ".get_related_contexts_string($context)."
347 GROUP BY u.id, u.firstname, u.lastname
348 ORDER BY MAX(l.time) ASC";
349 $params = array($timestart, $courseid);
350 return $DB->get_records_sql($sql, $params);
355 * Turn the ctx* fields in an objectlike record into a context subobject
356 * This allows us to SELECT from major tables JOINing with
357 * context at no cost, saving a ton of context lookups...
359 * Use context_instance_preload() instead.
361 * @deprecated since 2.0
362 * @param object $rec
363 * @return object
365 function make_context_subobj($rec) {
366 $ctx = new StdClass;
367 $ctx->id = $rec->ctxid; unset($rec->ctxid);
368 $ctx->path = $rec->ctxpath; unset($rec->ctxpath);
369 $ctx->depth = $rec->ctxdepth; unset($rec->ctxdepth);
370 $ctx->contextlevel = $rec->ctxlevel; unset($rec->ctxlevel);
371 $ctx->instanceid = $rec->id;
373 $rec->context = $ctx;
374 return $rec;
378 * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
380 * Use context_instance_preload() instead.
382 * @deprecated since 2.0
383 * @param object $rec a think that has a context, for example a course,
384 * course category, course modules, etc.
385 * @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
386 * @return bool whether $rec->context looks like the correct context object
387 * for this thing.
389 function is_context_subobj_valid($rec, $contextlevel) {
390 return isset($rec->context) && isset($rec->context->id) &&
391 isset($rec->context->path) && isset($rec->context->depth) &&
392 isset($rec->context->contextlevel) && isset($rec->context->instanceid) &&
393 $rec->context->contextlevel == $contextlevel && $rec->context->instanceid == $rec->id;
397 * Ensure that $rec->context is present and correct before you continue
399 * When you have a record (for example a $category, $course, $user or $cm that may,
400 * or may not, have come from a place that does make_context_subobj, you can use
401 * this method to ensure that $rec->context is present and correct before you continue.
403 * Use context_instance_preload() instead.
405 * @deprecated since 2.0
406 * @param object $rec a thing that has an associated context.
407 * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
409 function ensure_context_subobj_present(&$rec, $contextlevel) {
410 if (!is_context_subobj_valid($rec, $contextlevel)) {
411 $rec->context = get_context_instance($contextlevel, $rec->id);
415 ########### FROM weblib.php ##########################################################################
419 * Print a message in a standard themed box.
420 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
421 * parameters remain. If possible, $align, $width and $color should not be defined at all.
422 * Preferably just use print_box() in weblib.php
424 * @deprecated
425 * @param string $message The message to display
426 * @param string $align alignment of the box, not the text (default center, left, right).
427 * @param string $width width of the box, including units %, for example '100%'.
428 * @param string $color background colour of the box, for example '#eee'.
429 * @param int $padding padding in pixels, specified without units.
430 * @param string $class space-separated class names.
431 * @param string $id space-separated id names.
432 * @param boolean $return return as string or just print it
433 * @return string|void Depending on $return
435 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
436 $output = '';
437 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
438 $output .= $message;
439 $output .= print_simple_box_end(true);
441 if ($return) {
442 return $output;
443 } else {
444 echo $output;
451 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
452 * parameters remain. If possible, $align, $width and $color should not be defined at all.
453 * Even better, please use print_box_start() in weblib.php
455 * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
456 * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
457 * @param string $color background colour of the box, for example '#eee'. DEPRECATED
458 * @param int $padding padding in pixels, specified without units. OBSOLETE
459 * @param string $class space-separated class names.
460 * @param string $id space-separated id names.
461 * @param boolean $return return as string or just print it
462 * @return string|void Depending on $return
464 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
465 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
467 $output = '';
469 $divclasses = 'box '.$class.' '.$class.'content';
470 $divstyles = '';
472 if ($align) {
473 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
475 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
476 if (substr($width, -1, 1) == '%') { // Width is a % value
477 $width = (int) substr($width, 0, -1); // Extract just the number
478 if ($width < 40) {
479 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
480 } else if ($width > 60) {
481 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
482 } else {
483 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
485 } else {
486 $divstyles .= ' width:'.$width.';'; // Last resort
489 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
490 $divstyles .= ' background:'.$color.';';
492 if ($divstyles) {
493 $divstyles = ' style="'.$divstyles.'"';
496 if ($id) {
497 $id = ' id="'.$id.'"';
500 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
502 if ($return) {
503 return $output;
504 } else {
505 echo $output;
511 * Print the end portion of a standard themed box.
512 * Preferably just use print_box_end() in weblib.php
514 * @param boolean $return return as string or just print it
515 * @return string|void Depending on $return
517 function print_simple_box_end($return=false) {
518 $output = '</div>';
519 if ($return) {
520 return $output;
521 } else {
522 echo $output;
527 * Given some text this function converted any URLs it found into HTML links
529 * This core function has been replaced with filter_urltolink since Moodle 2.0
531 * @param string $text Passed in by reference. The string to be searched for urls.
533 function convert_urls_into_links($text) {
534 debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
538 * Used to be called from help.php to inject a list of smilies into the
539 * emoticons help file.
541 * @return string HTML
543 function get_emoticons_list_for_help_file() {
544 debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
545 return '';
549 * Was used to replace all known smileys in the text with image equivalents
551 * This core function has been replaced with filter_emoticon since Moodle 2.0
553 function replace_smilies(&$text) {
554 debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
558 * deprecated - use clean_param($string, PARAM_FILE); instead
559 * Check for bad characters ?
561 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
563 * @param string $string ?
564 * @param int $allowdots ?
565 * @return bool
567 function detect_munged_arguments($string, $allowdots=1) {
568 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
569 return true;
571 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
572 return true;
574 if (empty($string) or $string == '/') {
575 return true;
578 return false;
583 * Unzip one zip file to a destination dir
584 * Both parameters must be FULL paths
585 * If destination isn't specified, it will be the
586 * SAME directory where the zip file resides.
588 * @global object
589 * @param string $zipfile The zip file to unzip
590 * @param string $destination The location to unzip to
591 * @param bool $showstatus_ignored Unused
593 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
594 global $CFG;
596 //Extract everything from zipfile
597 $path_parts = pathinfo(cleardoubleslashes($zipfile));
598 $zippath = $path_parts["dirname"]; //The path of the zip file
599 $zipfilename = $path_parts["basename"]; //The name of the zip file
600 $extension = $path_parts["extension"]; //The extension of the file
602 //If no file, error
603 if (empty($zipfilename)) {
604 return false;
607 //If no extension, error
608 if (empty($extension)) {
609 return false;
612 //Clear $zipfile
613 $zipfile = cleardoubleslashes($zipfile);
615 //Check zipfile exists
616 if (!file_exists($zipfile)) {
617 return false;
620 //If no destination, passed let's go with the same directory
621 if (empty($destination)) {
622 $destination = $zippath;
625 //Clear $destination
626 $destpath = rtrim(cleardoubleslashes($destination), "/");
628 //Check destination path exists
629 if (!is_dir($destpath)) {
630 return false;
633 $packer = get_file_packer('application/zip');
635 $result = $packer->extract_to_pathname($zipfile, $destpath);
637 if ($result === false) {
638 return false;
641 foreach ($result as $status) {
642 if ($status !== true) {
643 return false;
647 return true;
651 * Zip an array of files/dirs to a destination zip file
652 * Both parameters must be FULL paths to the files/dirs
654 * @global object
655 * @param array $originalfiles Files to zip
656 * @param string $destination The destination path
657 * @return bool Outcome
659 function zip_files ($originalfiles, $destination) {
660 global $CFG;
662 //Extract everything from destination
663 $path_parts = pathinfo(cleardoubleslashes($destination));
664 $destpath = $path_parts["dirname"]; //The path of the zip file
665 $destfilename = $path_parts["basename"]; //The name of the zip file
666 $extension = $path_parts["extension"]; //The extension of the file
668 //If no file, error
669 if (empty($destfilename)) {
670 return false;
673 //If no extension, add it
674 if (empty($extension)) {
675 $extension = 'zip';
676 $destfilename = $destfilename.'.'.$extension;
679 //Check destination path exists
680 if (!is_dir($destpath)) {
681 return false;
684 //Check destination path is writable. TODO!!
686 //Clean destination filename
687 $destfilename = clean_filename($destfilename);
689 //Now check and prepare every file
690 $files = array();
691 $origpath = NULL;
693 foreach ($originalfiles as $file) { //Iterate over each file
694 //Check for every file
695 $tempfile = cleardoubleslashes($file); // no doubleslashes!
696 //Calculate the base path for all files if it isn't set
697 if ($origpath === NULL) {
698 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
700 //See if the file is readable
701 if (!is_readable($tempfile)) { //Is readable
702 continue;
704 //See if the file/dir is in the same directory than the rest
705 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
706 continue;
708 //Add the file to the array
709 $files[] = $tempfile;
712 $zipfiles = array();
713 $start = strlen($origpath)+1;
714 foreach($files as $file) {
715 $zipfiles[substr($file, $start)] = $file;
718 $packer = get_file_packer('application/zip');
720 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
723 /////////////////////////////////////////////////////////////
724 /// Old functions not used anymore - candidates for removal
725 /////////////////////////////////////////////////////////////
728 /** various deprecated groups function **/
732 * Get the IDs for the user's groups in the given course.
734 * @global object
735 * @param int $courseid The course being examined - the 'course' table id field.
736 * @return array|bool An _array_ of groupids, or false
737 * (Was return $groupids[0] - consequences!)
739 function mygroupid($courseid) {
740 global $USER;
741 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
742 return array_keys($groups);
743 } else {
744 return false;
750 * Returns the current group mode for a given course or activity module
752 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
754 * @param object $course Course Object
755 * @param object $cm Course Manager Object
756 * @return mixed $course->groupmode
758 function groupmode($course, $cm=null) {
760 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
761 return $cm->groupmode;
763 return $course->groupmode;
767 * Sets the current group in the session variable
768 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
769 * Sets currentgroup[$courseid] in the session variable appropriately.
770 * Does not do any permission checking.
772 * @global object
773 * @param int $courseid The course being examined - relates to id field in
774 * 'course' table.
775 * @param int $groupid The group being examined.
776 * @return int Current group id which was set by this function
778 function set_current_group($courseid, $groupid) {
779 global $SESSION;
780 return $SESSION->currentgroup[$courseid] = $groupid;
785 * Gets the current group - either from the session variable or from the database.
787 * @global object
788 * @param int $courseid The course being examined - relates to id field in
789 * 'course' table.
790 * @param bool $full If true, the return value is a full record object.
791 * If false, just the id of the record.
792 * @return int|bool
794 function get_current_group($courseid, $full = false) {
795 global $SESSION;
797 if (isset($SESSION->currentgroup[$courseid])) {
798 if ($full) {
799 return groups_get_group($SESSION->currentgroup[$courseid]);
800 } else {
801 return $SESSION->currentgroup[$courseid];
805 $mygroupid = mygroupid($courseid);
806 if (is_array($mygroupid)) {
807 $mygroupid = array_shift($mygroupid);
808 set_current_group($courseid, $mygroupid);
809 if ($full) {
810 return groups_get_group($mygroupid);
811 } else {
812 return $mygroupid;
816 if ($full) {
817 return false;
818 } else {
819 return 0;
825 * Inndicates fatal error. This function was originally printing the
826 * error message directly, since 2.0 it is throwing exception instead.
827 * The error printing is handled in default exception handler.
829 * Old method, don't call directly in new code - use print_error instead.
831 * @param string $message The message to display to the user about the error.
832 * @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.
833 * @return void, always throws moodle_exception
835 function error($message, $link='') {
836 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
840 /// Deprecated DDL functions, to be removed soon ///
842 * @deprecated
843 * @global object
844 * @param string $table
845 * @return bool
847 function table_exists($table) {
848 global $DB;
849 debugging('Deprecated ddllib function used!');
850 return $DB->get_manager()->table_exists($table);
854 * @deprecated
855 * @global object
856 * @param string $table
857 * @param string $field
858 * @return bool
860 function field_exists($table, $field) {
861 global $DB;
862 debugging('Deprecated ddllib function used!');
863 return $DB->get_manager()->field_exists($table, $field);
867 * @deprecated
868 * @global object
869 * @param string $table
870 * @param string $index
871 * @return bool
873 function find_index_name($table, $index) {
874 global $DB;
875 debugging('Deprecated ddllib function used!');
876 return $DB->get_manager()->find_index_name($table, $index);
880 * @deprecated
881 * @global object
882 * @param string $table
883 * @param string $index
884 * @return bool
886 function index_exists($table, $index) {
887 global $DB;
888 debugging('Deprecated ddllib function used!');
889 return $DB->get_manager()->index_exists($table, $index);
893 * @deprecated
894 * @global object
895 * @param string $table
896 * @param string $field
897 * @return bool
899 function find_check_constraint_name($table, $field) {
900 global $DB;
901 debugging('Deprecated ddllib function used!');
902 return $DB->get_manager()->find_check_constraint_name($table, $field);
906 * @deprecated
907 * @global object
909 function check_constraint_exists($table, $field) {
910 global $DB;
911 debugging('Deprecated ddllib function used!');
912 return $DB->get_manager()->check_constraint_exists($table, $field);
916 * @deprecated
917 * @global object
918 * @param string $table
919 * @param string $xmldb_key
920 * @return bool
922 function find_key_name($table, $xmldb_key) {
923 global $DB;
924 debugging('Deprecated ddllib function used!');
925 return $DB->get_manager()->find_key_name($table, $xmldb_key);
929 * @deprecated
930 * @global object
931 * @param string $table
932 * @return bool
934 function drop_table($table) {
935 global $DB;
936 debugging('Deprecated ddllib function used!');
937 $DB->get_manager()->drop_table($table);
938 return true;
942 * @deprecated
943 * @global object
944 * @param string $file
945 * @return bool
947 function install_from_xmldb_file($file) {
948 global $DB;
949 debugging('Deprecated ddllib function used!');
950 $DB->get_manager()->install_from_xmldb_file($file);
951 return true;
955 * @deprecated
956 * @global object
957 * @param string $table
958 * @return bool
960 function create_table($table) {
961 global $DB;
962 debugging('Deprecated ddllib function used!');
963 $DB->get_manager()->create_table($table);
964 return true;
968 * @deprecated
969 * @global object
970 * @param string $table
971 * @return bool
973 function create_temp_table($table) {
974 global $DB;
975 debugging('Deprecated ddllib function used!');
976 $DB->get_manager()->create_temp_table($table);
977 return true;
981 * @deprecated
982 * @global object
983 * @param string $table
984 * @param string $newname
985 * @return bool
987 function rename_table($table, $newname) {
988 global $DB;
989 debugging('Deprecated ddllib function used!');
990 $DB->get_manager()->rename_table($table, $newname);
991 return true;
995 * @deprecated
996 * @global object
997 * @param string $table
998 * @param string $field
999 * @return bool
1001 function add_field($table, $field) {
1002 global $DB;
1003 debugging('Deprecated ddllib function used!');
1004 $DB->get_manager()->add_field($table, $field);
1005 return true;
1009 * @deprecated
1010 * @global object
1011 * @param string $table
1012 * @param string $field
1013 * @return bool
1015 function drop_field($table, $field) {
1016 global $DB;
1017 debugging('Deprecated ddllib function used!');
1018 $DB->get_manager()->drop_field($table, $field);
1019 return true;
1023 * @deprecated
1024 * @global object
1025 * @param string $table
1026 * @param string $field
1027 * @return bool
1029 function change_field_type($table, $field) {
1030 global $DB;
1031 debugging('Deprecated ddllib function used!');
1032 $DB->get_manager()->change_field_type($table, $field);
1033 return true;
1037 * @deprecated
1038 * @global object
1039 * @param string $table
1040 * @param string $field
1041 * @return bool
1043 function change_field_precision($table, $field) {
1044 global $DB;
1045 debugging('Deprecated ddllib function used!');
1046 $DB->get_manager()->change_field_precision($table, $field);
1047 return true;
1051 * @deprecated
1052 * @global object
1053 * @param string $table
1054 * @param string $field
1055 * @return bool
1057 function change_field_unsigned($table, $field) {
1058 global $DB;
1059 debugging('Deprecated ddllib function used!');
1060 $DB->get_manager()->change_field_unsigned($table, $field);
1061 return true;
1065 * @deprecated
1066 * @global object
1067 * @param string $table
1068 * @param string $field
1069 * @return bool
1071 function change_field_notnull($table, $field) {
1072 global $DB;
1073 debugging('Deprecated ddllib function used!');
1074 $DB->get_manager()->change_field_notnull($table, $field);
1075 return true;
1079 * @deprecated
1080 * @global object
1081 * @param string $table
1082 * @param string $field
1083 * @return bool
1085 function change_field_enum($table, $field) {
1086 global $DB;
1087 debugging('Deprecated ddllib function used! Only dropping of enums is allowed.');
1088 $DB->get_manager()->drop_enum_from_field($table, $field);
1089 return true;
1093 * @deprecated
1094 * @global object
1095 * @param string $table
1096 * @param string $field
1097 * @return bool
1099 function change_field_default($table, $field) {
1100 global $DB;
1101 debugging('Deprecated ddllib function used!');
1102 $DB->get_manager()->change_field_default($table, $field);
1103 return true;
1107 * @deprecated
1108 * @global object
1109 * @param string $table
1110 * @param string $field
1111 * @param string $newname
1112 * @return bool
1114 function rename_field($table, $field, $newname) {
1115 global $DB;
1116 debugging('Deprecated ddllib function used!');
1117 $DB->get_manager()->rename_field($table, $field, $newname);
1118 return true;
1122 * @deprecated
1123 * @global object
1124 * @param string $table
1125 * @param string $key
1126 * @return bool
1128 function add_key($table, $key) {
1129 global $DB;
1130 debugging('Deprecated ddllib function used!');
1131 $DB->get_manager()->add_key($table, $key);
1132 return true;
1136 * @deprecated
1137 * @global object
1138 * @param string $table
1139 * @param string $key
1140 * @return bool
1142 function drop_key($table, $key) {
1143 global $DB;
1144 debugging('Deprecated ddllib function used!');
1145 $DB->get_manager()->drop_key($table, $key);
1146 return true;
1150 * @deprecated
1151 * @global object
1152 * @param string $table
1153 * @param string $key
1154 * @param string $newname
1155 * @return bool
1157 function rename_key($table, $key, $newname) {
1158 global $DB;
1159 debugging('Deprecated ddllib function used!');
1160 $DB->get_manager()->rename_key($table, $key, $newname);
1161 return true;
1165 * @deprecated
1166 * @global object
1167 * @param string $table
1168 * @param string $index
1169 * @return bool
1171 function add_index($table, $index) {
1172 global $DB;
1173 debugging('Deprecated ddllib function used!');
1174 $DB->get_manager()->add_index($table, $index);
1175 return true;
1179 * @deprecated
1180 * @global object
1181 * @param string $table
1182 * @param string $index
1183 * @return bool
1185 function drop_index($table, $index) {
1186 global $DB;
1187 debugging('Deprecated ddllib function used!');
1188 $DB->get_manager()->drop_index($table, $index);
1189 return true;
1193 * @deprecated
1194 * @global object
1195 * @param string $table
1196 * @param string $index
1197 * @param string $newname
1198 * @return bool
1200 function rename_index($table, $index, $newname) {
1201 global $DB;
1202 debugging('Deprecated ddllib function used!');
1203 $DB->get_manager()->rename_index($table, $index, $newname);
1204 return true;
1208 //////////////////////////
1209 /// removed functions ////
1210 //////////////////////////
1213 * @deprecated
1214 * @param mixed $mixed
1215 * @return void Throws an error and does nothing
1217 function stripslashes_safe($mixed) {
1218 error('stripslashes_safe() not available anymore');
1221 * @deprecated
1222 * @param mixed $var
1223 * @return void Throws an error and does nothing
1225 function stripslashes_recursive($var) {
1226 error('stripslashes_recursive() not available anymore');
1229 * @deprecated
1230 * @param mixed $dataobject
1231 * @return void Throws an error and does nothing
1233 function addslashes_object($dataobject) {
1234 error('addslashes_object() not available anymore');
1237 * @deprecated
1238 * @param mixed $var
1239 * @return void Throws an error and does nothing
1241 function addslashes_recursive($var) {
1242 error('addslashes_recursive() not available anymore');
1245 * @deprecated
1246 * @param mixed $command
1247 * @param bool $feedback
1248 * @return void Throws an error and does nothing
1250 function execute_sql($command, $feedback=true) {
1251 error('execute_sql() not available anymore');
1254 * @deprecated use $DB->record_exists_select() instead
1255 * @see moodle_database::record_exists_select()
1256 * @param mixed $table
1257 * @param mixed $select
1258 * @return void Throws an error and does nothing
1260 function record_exists_select($table, $select='') {
1261 error('record_exists_select() not available anymore');
1264 * @deprecated use $DB->record_exists_sql() instead
1265 * @see moodle_database::record_exists_sql()
1266 * @param mixed $sql
1267 * @return void Throws an error and does nothing
1269 function record_exists_sql($sql) {
1270 error('record_exists_sql() not available anymore');
1273 * @deprecated use $DB->count_records_select() instead
1274 * @see moodle_database::count_records_select()
1275 * @param mixed $table
1276 * @param mixed $select
1277 * @param mixed $countitem
1278 * @return void Throws an error and does nothing
1280 function count_records_select($table, $select='', $countitem='COUNT(*)') {
1281 error('count_records_select() not available anymore');
1284 * @deprecated use $DB->count_records_sql() instead
1285 * @see moodle_database::count_records_sql()
1286 * @param mixed $sql
1287 * @return void Throws an error and does nothing
1289 function count_records_sql($sql) {
1290 error('count_records_sql() not available anymore');
1293 * @deprecated use $DB->get_record_sql() instead
1294 * @see moodle_database::get_record_sql()
1295 * @param mixed $sql
1296 * @param bool $expectmultiple
1297 * @param bool $nolimit
1298 * @return void Throws an error and does nothing
1300 function get_record_sql($sql, $expectmultiple=false, $nolimit=false) {
1301 error('get_record_sql() not available anymore');
1304 * @deprecated use $DB->get_record_select() instead
1305 * @see moodle_database::get_record_select()
1306 * @param mixed $table
1307 * @param mixed $select
1308 * @param mixed $fields
1309 * @return void Throws an error and does nothing
1311 function get_record_select($table, $select='', $fields='*') {
1312 error('get_record_select() not available anymore');
1315 * @deprecated use $DB->get_recordset() instead
1316 * @see moodle_database::get_recordset()
1317 * @param mixed $table
1318 * @param mixed $field
1319 * @param mixed $value
1320 * @param mixed $sort
1321 * @param mixed $fields
1322 * @param mixed $limitfrom
1323 * @param mixed $limitnum
1324 * @return void Throws an error and does nothing
1326 function get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1327 error('get_recordset() not available anymore');
1330 * @deprecated use $DB->get_recordset_sql() instead
1331 * @see moodle_database::get_recordset_sql()
1332 * @param mixed $sql
1333 * @param mixed $limitfrom
1334 * @param mixed $limitnum
1335 * @return void Throws an error and does nothing
1337 function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) {
1338 error('get_recordset_sql() not available anymore');
1341 * @deprecated
1342 * @param mixed $rs
1343 * @return void Throws an error and does nothing
1345 function rs_fetch_record(&$rs) {
1346 error('rs_fetch_record() not available anymore');
1349 * @deprecated
1350 * @param mixed $rs
1351 * @return void Throws an error and does nothing
1353 function rs_next_record(&$rs) {
1354 error('rs_next_record() not available anymore');
1357 * @deprecated
1358 * @param mixed $rs
1359 * @return void Throws an error and does nothing
1361 function rs_fetch_next_record(&$rs) {
1362 error('rs_fetch_next_record() not available anymore');
1365 * @deprecated
1366 * @param mixed $rs
1367 * @return void Throws an error and does nothing
1369 function rs_EOF($rs) {
1370 error('rs_EOF() not available anymore');
1373 * @deprecated
1374 * @param mixed $rs
1375 * @return void Throws an error and does nothing
1377 function rs_close(&$rs) {
1378 error('rs_close() not available anymore');
1381 * @deprecated use $DB->get_records_select() instead
1382 * @see moodle_database::get_records_select()
1383 * @param mixed $table
1384 * @param mixed $select
1385 * @param mixed $sort
1386 * @param mixed $fields
1387 * @param mixed $limitfrom
1388 * @param mixed $limitnum
1389 * @return void Throws an error and does nothing
1391 function get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1392 error('get_records_select() not available anymore');
1395 * @deprecated use $DB->get_field_select() instead
1396 * @see moodle_database::get_field_select()
1397 * @param mixed $table
1398 * @param mixed $return
1399 * @param mixed $select
1400 * @return void Throws an error and does nothing
1402 function get_field_select($table, $return, $select) {
1403 error('get_field_select() not available anymore');
1406 * @deprecated use $DB->get_field_sql() instead
1407 * @see moodle_database::get_field_sql()
1408 * @param mixed $sql
1409 * @return void Throws an error and does nothing
1411 function get_field_sql($sql) {
1412 error('get_field_sql() not available anymore');
1415 * @deprecated use $DB->delete_records_select() instead
1416 * @see moodle_database::delete_records_select()
1417 * @param mixed $sql
1418 * @param mixed $select
1419 * @return void Throws an error and does nothing
1421 function delete_records_select($table, $select='') {
1422 error('get_field_sql() not available anymore');
1425 * @deprecated
1426 * @return void Throws an error and does nothing
1428 function configure_dbconnection() {
1429 error('configure_dbconnection() removed');
1432 * @deprecated
1433 * @param mixed $field
1434 * @return void Throws an error and does nothing
1436 function sql_max($field) {
1437 error('sql_max() removed - use normal sql MAX() instead');
1440 * @deprecated
1441 * @return void Throws an error and does nothing
1443 function sql_as() {
1444 error('sql_as() removed - do not use AS for tables at all');
1447 * @deprecated
1448 * @param mixed $page
1449 * @param mixed $recordsperpage
1450 * @return void Throws an error and does nothing
1452 function sql_paging_limit($page, $recordsperpage) {
1453 error('Function sql_paging_limit() is deprecated. Replace it with the correct use of limitfrom, limitnum parameters');
1456 * @deprecated
1457 * @return void Throws an error and does nothing
1459 function db_uppercase() {
1460 error('upper() removed - use normal sql UPPER()');
1463 * @deprecated
1464 * @return void Throws an error and does nothing
1466 function db_lowercase() {
1467 error('upper() removed - use normal sql LOWER()');
1470 * @deprecated
1471 * @param mixed $sqlfile
1472 * @param mixed $sqlstring
1473 * @return void Throws an error and does nothing
1475 function modify_database($sqlfile='', $sqlstring='') {
1476 error('modify_database() removed - use new XMLDB functions');
1479 * @deprecated
1480 * @param mixed $field1
1481 * @param mixed $value1
1482 * @param mixed $field2
1483 * @param mixed $value2
1484 * @param mixed $field3
1485 * @param mixed $value3
1486 * @return void Throws an error and does nothing
1488 function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1489 error('where_clause() removed - use new functions with $conditions parameter');
1492 * @deprecated
1493 * @param mixed $sqlarr
1494 * @param mixed $continue
1495 * @param mixed $feedback
1496 * @return void Throws an error and does nothing
1498 function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
1499 error('execute_sql_arr() removed');
1502 * @deprecated use $DB->get_records_list() instead
1503 * @see moodle_database::get_records_list()
1504 * @param mixed $table
1505 * @param mixed $field
1506 * @param mixed $values
1507 * @param mixed $sort
1508 * @param mixed $fields
1509 * @param mixed $limitfrom
1510 * @param mixed $limitnum
1511 * @return void Throws an error and does nothing
1513 function get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1514 error('get_records_list() removed');
1517 * @deprecated use $DB->get_recordset_list() instead
1518 * @see moodle_database::get_recordset_list()
1519 * @param mixed $table
1520 * @param mixed $field
1521 * @param mixed $values
1522 * @param mixed $sort
1523 * @param mixed $fields
1524 * @param mixed $limitfrom
1525 * @param mixed $limitnum
1526 * @return void Throws an error and does nothing
1528 function get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1529 error('get_recordset_list() removed');
1532 * @deprecated use $DB->get_records_menu() instead
1533 * @see moodle_database::get_records_menu()
1534 * @param mixed $table
1535 * @param mixed $field
1536 * @param mixed $value
1537 * @param mixed $sort
1538 * @param mixed $fields
1539 * @param mixed $limitfrom
1540 * @param mixed $limitnum
1541 * @return void Throws an error and does nothing
1543 function get_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1544 error('get_records_menu() removed');
1547 * @deprecated use $DB->get_records_select_menu() instead
1548 * @see moodle_database::get_records_select_menu()
1549 * @param mixed $table
1550 * @param mixed $select
1551 * @param mixed $sort
1552 * @param mixed $fields
1553 * @param mixed $limitfrom
1554 * @param mixed $limitnum
1555 * @return void Throws an error and does nothing
1557 function get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1558 error('get_records_select_menu() removed');
1561 * @deprecated use $DB->get_records_sql_menu() instead
1562 * @see moodle_database::get_records_sql_menu()
1563 * @param mixed $sql
1564 * @param mixed $limitfrom
1565 * @param mixed $limitnum
1566 * @return void Throws an error and does nothing
1568 function get_records_sql_menu($sql, $limitfrom='', $limitnum='') {
1569 error('get_records_sql_menu() removed');
1572 * @deprecated
1573 * @param mixed $table
1574 * @param mixed $column
1575 * @return void Throws an error and does nothing
1577 function column_type($table, $column) {
1578 error('column_type() removed');
1581 * @deprecated
1582 * @param mixed $rs
1583 * @return void Throws an error and does nothing
1585 function recordset_to_menu($rs) {
1586 error('recordset_to_menu() removed');
1589 * @deprecated
1590 * @param mixed $records
1591 * @param mixed $field1
1592 * @param mixed $field2
1593 * @return void Throws an error and does nothing
1595 function records_to_menu($records, $field1, $field2) {
1596 error('records_to_menu() removed');
1599 * @deprecated use $DB->set_field_select() instead
1600 * @see moodle_database::set_field_select()
1601 * @param mixed $table
1602 * @param mixed $newfield
1603 * @param mixed $newvalue
1604 * @param mixed $select
1605 * @param mixed $localcall
1606 * @return void Throws an error and does nothing
1608 function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) {
1609 error('set_field_select() removed');
1612 * @deprecated use $DB->get_fieldset_select() instead
1613 * @see moodle_database::get_fieldset_select()
1614 * @param mixed $table
1615 * @param mixed $return
1616 * @param mixed $select
1617 * @return void Throws an error and does nothing
1619 function get_fieldset_select($table, $return, $select) {
1620 error('get_fieldset_select() removed');
1623 * @deprecated use $DB->get_fieldset_sql() instead
1624 * @see moodle_database::get_fieldset_sql()
1625 * @param mixed $sql
1626 * @return void Throws an error and does nothing
1628 function get_fieldset_sql($sql) {
1629 error('get_fieldset_sql() removed');
1632 * @deprecated use $DB->sql_like() instead
1633 * @see moodle_database::sql_like()
1634 * @return void Throws an error and does nothing
1636 function sql_ilike() {
1637 error('sql_ilike() not available anymore');
1640 * @deprecated
1641 * @param mixed $first
1642 * @param mixed $last
1643 * @return void Throws an error and does nothing
1645 function sql_fullname($first='firstname', $last='lastname') {
1646 error('sql_fullname() not available anymore');
1649 * @deprecated
1650 * @return void Throws an error and does nothing
1652 function sql_concat() {
1653 error('sql_concat() not available anymore');
1656 * @deprecated
1657 * @return void Throws an error and does nothing
1659 function sql_empty() {
1660 error('sql_empty() not available anymore');
1663 * @deprecated
1664 * @return void Throws an error and does nothing
1666 function sql_substr() {
1667 error('sql_substr() not available anymore');
1670 * @deprecated
1671 * @param mixed $int1
1672 * @param mixed $int2
1673 * @return void Throws an error and does nothing
1675 function sql_bitand($int1, $int2) {
1676 error('sql_bitand() not available anymore');
1679 * @deprecated
1680 * @param mixed $int1
1681 * @return void Throws an error and does nothing
1683 function sql_bitnot($int1) {
1684 error('sql_bitnot() not available anymore');
1687 * @deprecated
1688 * @param mixed $int1
1689 * @param mixed $int2
1690 * @return void Throws an error and does nothing
1692 function sql_bitor($int1, $int2) {
1693 error('sql_bitor() not available anymore');
1696 * @deprecated
1697 * @param mixed $int1
1698 * @param mixed $int2
1699 * @return void Throws an error and does nothing
1701 function sql_bitxor($int1, $int2) {
1702 error('sql_bitxor() not available anymore');
1705 * @deprecated
1706 * @param mixed $fieldname
1707 * @param mixed $text
1708 * @return void Throws an error and does nothing
1710 function sql_cast_char2int($fieldname, $text=false) {
1711 error('sql_cast_char2int() not available anymore');
1714 * @deprecated
1715 * @param mixed $fieldname
1716 * @param mixed $numchars
1717 * @return void Throws an error and does nothing
1719 function sql_compare_text($fieldname, $numchars=32) {
1720 error('sql_compare_text() not available anymore');
1723 * @deprecated
1724 * @param mixed $fieldname
1725 * @param mixed $numchars
1726 * @return void Throws an error and does nothing
1728 function sql_order_by_text($fieldname, $numchars=32) {
1729 error('sql_order_by_text() not available anymore');
1732 * @deprecated
1733 * @param mixed $fieldname
1734 * @return void Throws an error and does nothing
1736 function sql_length($fieldname) {
1737 error('sql_length() not available anymore');
1740 * @deprecated
1741 * @param mixed $separator
1742 * @param mixed $elements
1743 * @return void Throws an error and does nothing
1745 function sql_concat_join($separator="' '", $elements=array()) {
1746 error('sql_concat_join() not available anymore');
1749 * @deprecated
1750 * @param mixed $tablename
1751 * @param mixed $fieldname
1752 * @param mixed $nullablefield
1753 * @param mixed $textfield
1754 * @return void Throws an error and does nothing
1756 function sql_isempty($tablename, $fieldname, $nullablefield, $textfield) {
1757 error('sql_isempty() not available anymore');
1760 * @deprecated
1761 * @param mixed $tablename
1762 * @param mixed $fieldname
1763 * @param mixed $nullablefield
1764 * @param mixed $textfield
1765 * @return void Throws an error and does nothing
1767 function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) {
1768 error('sql_isnotempty() not available anymore');
1771 * @deprecated
1772 * @return void Throws an error and does nothing
1774 function begin_sql() {
1775 error('begin_sql() not available anymore');
1778 * @deprecated
1779 * @return void Throws an error and does nothing
1781 function commit_sql() {
1782 error('commit_sql() not available anymore');
1785 * @deprecated
1786 * @return void Throws an error and does nothing
1788 function rollback_sql() {
1789 error('rollback_sql() not available anymore');
1792 * @deprecated use $DB->insert_record() instead
1793 * @see moodle_database::insert_record()
1794 * @param mixed $table
1795 * @param mixed $dataobject
1796 * @param mixed $returnid
1797 * @param mixed $primarykey
1798 * @return void Throws an error and does nothing
1800 function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
1801 error('insert_record() not available anymore');
1804 * @deprecated use $DB->update_record() instead
1805 * @see moodle_database::update_record()
1806 * @param mixed $table
1807 * @param mixed $dataobject
1808 * @return void Throws an error and does nothing
1810 function update_record($table, $dataobject) {
1811 error('update_record() not available anymore');
1814 * @deprecated use $DB->get_records() instead
1815 * @see moodle_database::get_records()
1816 * @param mixed $table
1817 * @param mixed $field
1818 * @param mixed $value
1819 * @param mixed $sort
1820 * @param mixed $fields
1821 * @param mixed $limitfrom
1822 * @param mixed $limitnum
1824 * @return void Throws an error and does nothing
1826 function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1827 error('get_records() not available anymore');
1830 * @deprecated use $DB->get_record() instead
1831 * @see moodle_database::get_record()
1832 * @param mixed $table
1833 * @param mixed $field1
1834 * @param mixed $value1
1835 * @param mixed $field2
1836 * @param mixed $value2
1837 * @param mixed $field3
1838 * @param mixed $value3
1839 * @param mixed $fields
1840 * @return void Throws an error and does nothing
1842 function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') {
1843 error('get_record() not available anymore');
1846 * @deprecated use $DB->set_field() instead
1847 * @see moodle_database::set_field()
1848 * @param mixed $table
1849 * @param mixed $newfield
1850 * @param mixed $newvalue
1851 * @param mixed $field1
1852 * @param mixed $value1
1853 * @param mixed $field2
1854 * @param mixed $value2
1855 * @param mixed $field3
1856 * @param mixed $value3
1857 * @return void Throws an error and does nothing
1859 function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1860 error('set_field() not available anymore');
1863 * @deprecated use $DB->count_records() instead
1864 * @see moodle_database::count_records()
1865 * @param mixed $table
1866 * @param mixed $field1
1867 * @param mixed $value1
1868 * @param mixed $field2
1869 * @param mixed $value2
1870 * @param mixed $field3
1871 * @param mixed $value3
1872 * @return void Throws an error and does nothing
1874 function count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1875 error('count_records() not available anymore');
1878 * @deprecated use $DB->record_exists() instead
1879 * @see moodle_database::record_exists()
1880 * @param mixed $table
1881 * @param mixed $field1
1882 * @param mixed $value1
1883 * @param mixed $field2
1884 * @param mixed $value2
1885 * @param mixed $field3
1886 * @param mixed $value3
1887 * @return void Throws an error and does nothing
1889 function record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1890 error('record_exists() not available anymore');
1893 * @deprecated use $DB->delete_records() instead
1894 * @see moodle_database::delete_records()
1895 * @param mixed $table
1896 * @param mixed $field1
1897 * @param mixed $value1
1898 * @param mixed $field2
1899 * @param mixed $value2
1900 * @param mixed $field3
1901 * @param mixed $value3
1902 * @return void Throws an error and does nothing
1904 function delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1905 error('delete_records() not available anymore');
1908 * @deprecated use $DB->get_field() instead
1909 * @see moodle_database::get_field()
1910 * @param mixed $table
1911 * @param mixed $return
1912 * @param mixed $field1
1913 * @param mixed $value1
1914 * @param mixed $field2
1915 * @param mixed $value2
1916 * @param mixed $field3
1917 * @param mixed $value3
1918 * @return void Throws an error and does nothing
1920 function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1921 error('get_field() not available anymore');
1924 * @deprecated
1925 * @param mixed $table
1926 * @param mixed $oldfield
1927 * @param mixed $field
1928 * @param mixed $type
1929 * @param mixed $size
1930 * @param mixed $signed
1931 * @param mixed $default
1932 * @param mixed $null
1933 * @param mixed $after
1934 * @return void Throws an error and does nothing
1936 function table_column($table, $oldfield, $field, $type='integer', $size='10',
1937 $signed='unsigned', $default='0', $null='not null', $after='') {
1938 error('table_column() was removed, please use new ddl functions');
1941 * @deprecated
1942 * @param mixed $name
1943 * @param mixed $editorhidebuttons
1944 * @param mixed $id
1945 * @return void Throws an error and does nothing
1947 function use_html_editor($name='', $editorhidebuttons='', $id='') {
1948 error('use_html_editor() not available anymore');
1952 * The old method that was used to include JavaScript libraries.
1953 * Please use $PAGE->requires->js_module() instead.
1955 * @param mixed $lib The library or libraries to load (a string or array of strings)
1956 * There are three way to specify the library:
1957 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
1958 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
1959 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
1960 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
1962 function require_js($lib) {
1963 global $CFG, $PAGE;
1964 // Add the lib to the list of libs to be loaded, if it isn't already
1965 // in the list.
1966 if (is_array($lib)) {
1967 foreach($lib as $singlelib) {
1968 require_js($singlelib);
1970 return;
1973 debugging('Call to deprecated function require_js. Please use $PAGE->requires->js_module() instead.', DEBUG_DEVELOPER);
1975 if (strpos($lib, 'yui_') === 0) {
1976 $PAGE->requires->yui2_lib(substr($lib, 4));
1977 } else {
1978 if ($PAGE->requires->is_head_done()) {
1979 echo html_writer::script('', $lib);
1980 } else {
1981 $PAGE->requires->js(new moodle_url($lib));
1987 * Makes an upload directory for a particular module.
1989 * This function has been deprecated by the file API changes in Moodle 2.0.
1991 * @deprecated
1992 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
1993 * @return string|false Returns full path to directory if successful, false if not
1995 function make_mod_upload_directory($courseid) {
1996 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
2000 * Used to be used for setting up the theme. No longer used by core code, and
2001 * should not have been used elsewhere.
2003 * The theme is now automatically initialised before it is first used. If you really need
2004 * to force this to happen, just reference $PAGE->theme.
2006 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
2007 * However, I can't think of any valid reason to do that outside the theme selector UI.
2009 * @deprecated
2010 * @param string $theme The theme to use defaults to current theme
2011 * @param array $params An array of parameters to use
2013 function theme_setup($theme = '', $params=NULL) {
2014 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
2015 'The current theme gets initialised automatically before it is first used.');
2019 * @deprecated use $PAGE->theme->name instead.
2020 * @return string the name of the current theme.
2022 function current_theme() {
2023 global $PAGE;
2024 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
2025 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
2026 return $PAGE->theme->name;
2030 * @todo Remove this deprecated function when no longer used
2031 * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
2033 * @param string $getid used to return $PAGE->pagetype.
2034 * @param string $getclass used to return $PAGE->legacyclass.
2036 function page_id_and_class(&$getid, &$getclass) {
2037 global $PAGE;
2038 debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
2039 $getid = $PAGE->pagetype;
2040 $getclass = $PAGE->legacyclass;
2044 * Prints some red text using echo
2046 * @deprecated
2047 * @param string $error The text to be displayed in red
2049 function formerr($error) {
2050 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
2051 global $OUTPUT;
2052 echo $OUTPUT->error_text($error);
2056 * Return the markup for the destination of the 'Skip to main content' links.
2057 * Accessibility improvement for keyboard-only users.
2059 * Used in course formats, /index.php and /course/index.php
2061 * @deprecated use $OUTPUT->skip_link_target() in instead.
2062 * @return string HTML element.
2064 function skip_main_destination() {
2065 global $OUTPUT;
2066 return $OUTPUT->skip_link_target();
2070 * Prints a string in a specified size (retained for backward compatibility)
2072 * @deprecated
2073 * @param string $text The text to be displayed
2074 * @param int $size The size to set the font for text display.
2075 * @param bool $return If set to true output is returned rather than echoed Default false
2076 * @return string|void String if return is true
2078 function print_headline($text, $size=2, $return=false) {
2079 global $OUTPUT;
2080 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
2081 $output = $OUTPUT->heading($text, $size);
2082 if ($return) {
2083 return $output;
2084 } else {
2085 echo $output;
2090 * Prints text in a format for use in headings.
2092 * @deprecated
2093 * @param string $text The text to be displayed
2094 * @param string $deprecated No longer used. (Use to do alignment.)
2095 * @param int $size The size to set the font for text display.
2096 * @param string $class
2097 * @param bool $return If set to true output is returned rather than echoed, default false
2098 * @param string $id The id to use in the element
2099 * @return string|void String if return=true nothing otherwise
2101 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
2102 global $OUTPUT;
2103 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
2104 if (!empty($deprecated)) {
2105 debugging('Use of deprecated align attribute of print_heading. ' .
2106 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
2108 $output = $OUTPUT->heading($text, $size, $class, $id);
2109 if ($return) {
2110 return $output;
2111 } else {
2112 echo $output;
2117 * Output a standard heading block
2119 * @deprecated
2120 * @param string $heading The text to write into the heading
2121 * @param string $class An additional Class Attr to use for the heading
2122 * @param bool $return If set to true output is returned rather than echoed, default false
2123 * @return string|void HTML String if return=true nothing otherwise
2125 function print_heading_block($heading, $class='', $return=false) {
2126 global $OUTPUT;
2127 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
2128 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
2129 if ($return) {
2130 return $output;
2131 } else {
2132 echo $output;
2137 * Print a message in a standard themed box.
2138 * Replaces print_simple_box (see deprecatedlib.php)
2140 * @deprecated
2141 * @param string $message, the content of the box
2142 * @param string $classes, space-separated class names.
2143 * @param string $ids
2144 * @param boolean $return, return as string or just print it
2145 * @return string|void mixed string or void
2147 function print_box($message, $classes='generalbox', $ids='', $return=false) {
2148 global $OUTPUT;
2149 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
2150 $output = $OUTPUT->box($message, $classes, $ids);
2151 if ($return) {
2152 return $output;
2153 } else {
2154 echo $output;
2159 * Starts a box using divs
2160 * Replaces print_simple_box_start (see deprecatedlib.php)
2162 * @deprecated
2163 * @param string $classes, space-separated class names.
2164 * @param string $ids
2165 * @param boolean $return, return as string or just print it
2166 * @return string|void string or void
2168 function print_box_start($classes='generalbox', $ids='', $return=false) {
2169 global $OUTPUT;
2170 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
2171 $output = $OUTPUT->box_start($classes, $ids);
2172 if ($return) {
2173 return $output;
2174 } else {
2175 echo $output;
2180 * Simple function to end a box (see above)
2181 * Replaces print_simple_box_end (see deprecatedlib.php)
2183 * @deprecated
2184 * @param boolean $return, return as string or just print it
2185 * @return string|void Depending on value of return
2187 function print_box_end($return=false) {
2188 global $OUTPUT;
2189 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
2190 $output = $OUTPUT->box_end();
2191 if ($return) {
2192 return $output;
2193 } else {
2194 echo $output;
2199 * Print a message in a standard themed container.
2201 * @deprecated
2202 * @param string $message, the content of the container
2203 * @param boolean $clearfix clear both sides
2204 * @param string $classes, space-separated class names.
2205 * @param string $idbase
2206 * @param boolean $return, return as string or just print it
2207 * @return string|void Depending on value of $return
2209 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
2210 global $OUTPUT;
2211 if ($clearfix) {
2212 $classes .= ' clearfix';
2214 $output = $OUTPUT->container($message, $classes, $idbase);
2215 if ($return) {
2216 return $output;
2217 } else {
2218 echo $output;
2223 * Starts a container using divs
2225 * @deprecated
2226 * @param boolean $clearfix clear both sides
2227 * @param string $classes, space-separated class names.
2228 * @param string $idbase
2229 * @param boolean $return, return as string or just print it
2230 * @return string|void Based on value of $return
2232 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
2233 global $OUTPUT;
2234 if ($clearfix) {
2235 $classes .= ' clearfix';
2237 $output = $OUTPUT->container_start($classes, $idbase);
2238 if ($return) {
2239 return $output;
2240 } else {
2241 echo $output;
2246 * Deprecated, now handled automatically in themes
2248 function check_theme_arrows() {
2249 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
2253 * Simple function to end a container (see above)
2255 * @deprecated
2256 * @param boolean $return, return as string or just print it
2257 * @return string|void Based on $return
2259 function print_container_end($return=false) {
2260 global $OUTPUT;
2261 $output = $OUTPUT->container_end();
2262 if ($return) {
2263 return $output;
2264 } else {
2265 echo $output;
2270 * Print a bold message in an optional color.
2272 * @deprecated use $OUTPUT->notification instead.
2273 * @param string $message The message to print out
2274 * @param string $style Optional style to display message text in
2275 * @param string $align Alignment option
2276 * @param bool $return whether to return an output string or echo now
2277 * @return string|bool Depending on $result
2279 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
2280 global $OUTPUT;
2282 if ($classes == 'green') {
2283 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
2284 $classes = 'notifysuccess'; // Backward compatible with old color system
2287 $output = $OUTPUT->notification($message, $classes);
2288 if ($return) {
2289 return $output;
2290 } else {
2291 echo $output;
2296 * Print a continue button that goes to a particular URL.
2298 * @deprecated since Moodle 2.0
2300 * @param string $link The url to create a link to.
2301 * @param bool $return If set to true output is returned rather than echoed, default false
2302 * @return string|void HTML String if return=true nothing otherwise
2304 function print_continue($link, $return = false) {
2305 global $CFG, $OUTPUT;
2307 if ($link == '') {
2308 if (!empty($_SERVER['HTTP_REFERER'])) {
2309 $link = $_SERVER['HTTP_REFERER'];
2310 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
2311 } else {
2312 $link = $CFG->wwwroot .'/';
2316 $output = $OUTPUT->continue_button($link);
2317 if ($return) {
2318 return $output;
2319 } else {
2320 echo $output;
2325 * Print a standard header
2327 * @param string $title Appears at the top of the window
2328 * @param string $heading Appears at the top of the page
2329 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
2330 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2331 * @param string $meta Meta tags to be added to the header
2332 * @param boolean $cache Should this page be cacheable?
2333 * @param string $button HTML code for a button (usually for module editing)
2334 * @param string $menu HTML code for a popup menu
2335 * @param boolean $usexml use XML for this page
2336 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2337 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2338 * @return string|void If return=true then string else void
2340 function print_header($title='', $heading='', $navigation='', $focus='',
2341 $meta='', $cache=true, $button='&nbsp;', $menu=null,
2342 $usexml=false, $bodytags='', $return=false) {
2343 global $PAGE, $OUTPUT;
2345 $PAGE->set_title($title);
2346 $PAGE->set_heading($heading);
2347 $PAGE->set_cacheable($cache);
2348 if ($button == '') {
2349 $button = '&nbsp;';
2351 $PAGE->set_button($button);
2352 $PAGE->set_headingmenu($menu);
2354 // TODO $menu
2356 if ($meta) {
2357 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2358 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2360 if ($usexml) {
2361 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2363 if ($bodytags) {
2364 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2367 $output = $OUTPUT->header();
2369 if ($return) {
2370 return $output;
2371 } else {
2372 echo $output;
2377 * This version of print_header is simpler because the course name does not have to be
2378 * provided explicitly in the strings. It can be used on the site page as in courses
2379 * Eventually all print_header could be replaced by print_header_simple
2381 * @deprecated since Moodle 2.0
2382 * @param string $title Appears at the top of the window
2383 * @param string $heading Appears at the top of the page
2384 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
2385 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2386 * @param string $meta Meta tags to be added to the header
2387 * @param boolean $cache Should this page be cacheable?
2388 * @param string $button HTML code for a button (usually for module editing)
2389 * @param string $menu HTML code for a popup menu
2390 * @param boolean $usexml use XML for this page
2391 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2392 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2393 * @return string|void If $return=true the return string else nothing
2395 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
2396 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
2398 global $COURSE, $CFG, $PAGE, $OUTPUT;
2400 if ($meta) {
2401 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2402 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2404 if ($usexml) {
2405 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2407 if ($bodytags) {
2408 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2411 $PAGE->set_title($title);
2412 $PAGE->set_heading($heading);
2413 $PAGE->set_cacheable(true);
2414 $PAGE->set_button($button);
2416 $output = $OUTPUT->header();
2418 if ($return) {
2419 return $output;
2420 } else {
2421 echo $output;
2425 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
2426 global $PAGE, $OUTPUT;
2427 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
2428 // TODO check arguments.
2429 if (is_string($course)) {
2430 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
2431 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
2432 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
2433 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
2435 if (!is_null($usercourse)) {
2436 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
2437 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
2439 $output = $OUTPUT->footer();
2440 if ($return) {
2441 return $output;
2442 } else {
2443 echo $output;
2448 * Returns text to be displayed to the user which reflects their login status
2450 * @global object
2451 * @global object
2452 * @global object
2453 * @global object
2454 * @uses CONTEXT_COURSE
2455 * @param course $course {@link $COURSE} object containing course information
2456 * @param user $user {@link $USER} object containing user information
2457 * @return string HTML
2459 function user_login_string($course='ignored', $user='ignored') {
2460 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
2461 return '';
2465 * Prints a nice side block with an optional header. The content can either
2466 * be a block of HTML or a list of text with optional icons.
2468 * @todo Finish documenting this function. Show example of various attributes, etc.
2470 * @static int $block_id Increments for each call to the function
2471 * @param string $heading HTML for the heading. Can include full HTML or just
2472 * plain text - plain text will automatically be enclosed in the appropriate
2473 * heading tags.
2474 * @param string $content HTML for the content
2475 * @param array $list an alternative to $content, it you want a list of things with optional icons.
2476 * @param array $icons optional icons for the things in $list.
2477 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
2478 * @param array $attributes an array of attribute => value pairs that are put on the
2479 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
2480 * already a class, class='block' is used.
2481 * @param string $title Plain text title, as embedded in the $heading.
2482 * @deprecated
2484 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
2485 global $OUTPUT;
2487 // We don't use $heading, becuse it often contains HTML that we don't want.
2488 // However, sometimes $title is not set, but $heading is.
2489 if (empty($title)) {
2490 $title = strip_tags($heading);
2493 // Render list contents to HTML if required.
2494 if (empty($content) && $list) {
2495 $content = $OUTPUT->list_block_contents($icons, $list);
2498 $bc = new block_contents();
2499 $bc->content = $content;
2500 $bc->footer = $footer;
2501 $bc->title = $title;
2503 if (isset($attributes['id'])) {
2504 $bc->id = $attributes['id'];
2505 unset($attributes['id']);
2507 $bc->attributes = $attributes;
2509 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
2513 * Starts a nice side block with an optional header.
2515 * @todo Finish documenting this function
2517 * @global object
2518 * @global object
2519 * @param string $heading HTML for the heading. Can include full HTML or just
2520 * plain text - plain text will automatically be enclosed in the appropriate
2521 * heading tags.
2522 * @param array $attributes HTML attributes to apply if possible
2523 * @deprecated
2525 function print_side_block_start($heading='', $attributes = array()) {
2526 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
2530 * Print table ending tags for a side block box.
2532 * @global object
2533 * @global object
2534 * @param array $attributes HTML attributes to apply if possible [id]
2535 * @param string $title
2536 * @deprecated
2538 function print_side_block_end($attributes = array(), $title='') {
2539 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
2543 * This was used by old code to see whether a block region had anything in it,
2544 * and hence wether that region should be printed.
2546 * We don't ever want old code to print blocks, so we now always return false.
2547 * The function only exists to avoid fatal errors in old code.
2549 * @deprecated since Moodle 2.0. always returns false.
2551 * @param object $blockmanager
2552 * @param string $region
2553 * @return bool
2555 function blocks_have_content(&$blockmanager, $region) {
2556 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
2557 return false;
2561 * This was used by old code to print the blocks in a region.
2563 * We don't ever want old code to print blocks, so this is now a no-op.
2564 * The function only exists to avoid fatal errors in old code.
2566 * @deprecated since Moodle 2.0. does nothing.
2568 * @param object $page
2569 * @param object $blockmanager
2570 * @param string $region
2572 function blocks_print_group($page, $blockmanager, $region) {
2573 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2577 * This used to be the old entry point for anyone that wants to use blocks.
2578 * Since we don't want people people dealing with blocks this way any more,
2579 * just return a suitable empty array.
2581 * @deprecated since Moodle 2.0.
2583 * @param object $page
2584 * @return array
2586 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
2587 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2588 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
2592 * This iterates over an array of blocks and calculates the preferred width
2593 * Parameter passed by reference for speed; it's not modified.
2595 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
2597 * @param mixed $instances
2599 function blocks_preferred_width($instances) {
2600 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2601 $width = 210;
2605 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2607 * @param object $page The page object
2608 * @param object $blockmanager The block manager object
2609 * @param string $blockaction One of [config, add, delete]
2610 * @param int|object $instanceorid The instance id or a block_instance object
2611 * @param bool $pinned
2612 * @param bool $redirect To redirect or not to that is the question but you should stick with true
2614 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
2615 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.');
2619 * You can use this to get the blocks to respond to URL actions without much hassle
2621 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
2623 * @param object $PAGE
2624 * @param object $blockmanager
2625 * @param bool $pinned
2627 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
2628 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
2632 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
2633 * in order to reduce code repetition.
2635 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2637 * @param $instance
2638 * @param $newpos
2639 * @param string|int $newweight
2640 * @param bool $pinned
2642 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
2643 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.');
2648 * Moves a block to the new position (column) and weight (sort order).
2650 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2652 * @param object $instance The block instance to be moved.
2653 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
2654 * @param string $destweight The destination sort order. If NULL, we add to the end
2655 * of the destination column.
2656 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
2657 * to a new position withing the pinned list. Likewise, we
2658 * can only moved non-pinned blocks to a new position within
2659 * the non-pinned list.
2660 * @return boolean success or failure
2662 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
2663 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.');
2667 * Print a nicely formatted table.
2669 * @deprecated since Moodle 2.0
2671 * @param array $table is an object with several properties.
2673 function print_table($table, $return=false) {
2674 global $OUTPUT;
2675 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
2676 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
2677 $newtable = new html_table();
2678 foreach ($table as $property => $value) {
2679 if (property_exists($newtable, $property)) {
2680 $newtable->{$property} = $value;
2683 if (isset($table->class)) {
2684 $newtable->attributes['class'] = $table->class;
2686 if (isset($table->rowclass) && is_array($table->rowclass)) {
2687 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
2688 $newtable->rowclasses = $table->rowclass;
2690 $output = html_writer::table($newtable);
2691 if ($return) {
2692 return $output;
2693 } else {
2694 echo $output;
2695 return true;
2700 * Creates and displays (or returns) a link to a popup window
2702 * @deprecated since Moodle 2.0
2704 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2705 * @param string $name Name to be assigned to the popup window (this is used by
2706 * client-side scripts to "talk" to the popup window)
2707 * @param string $linkname Text to be displayed as web link
2708 * @param int $height Height to assign to popup window
2709 * @param int $width Height to assign to popup window
2710 * @param string $title Text to be displayed as popup page title
2711 * @param string $options List of additional options for popup window
2712 * @param bool $return If true, return as a string, otherwise print
2713 * @param string $id id added to the element
2714 * @param string $class class added to the element
2715 * @return string html code to display a link to a popup window.
2717 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
2718 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');
2720 return html_writer::link($url, $name);
2724 * Creates and displays (or returns) a buttons to a popup window.
2726 * @deprecated since Moodle 2.0
2728 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2729 * @param string $name Name to be assigned to the popup window (this is used by
2730 * client-side scripts to "talk" to the popup window)
2731 * @param string $linkname Text to be displayed as web link
2732 * @param int $height Height to assign to popup window
2733 * @param int $width Height to assign to popup window
2734 * @param string $title Text to be displayed as popup page title
2735 * @param string $options List of additional options for popup window
2736 * @param bool $return If true, return as a string, otherwise print
2737 * @param string $id id added to the element
2738 * @param string $class class added to the element
2739 * @return string html code to display a link to a popup window.
2741 function button_to_popup_window ($url, $name=null, $linkname=null,
2742 $height=400, $width=500, $title=null, $options=null, $return=false,
2743 $id=null, $class=null) {
2744 global $OUTPUT;
2746 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2748 if ($options == 'none') {
2749 $options = null;
2752 if (empty($linkname)) {
2753 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
2756 // Create a single_button object
2757 $form = new single_button($url, $linkname, 'post');
2758 $form->button->title = $title;
2759 $form->button->id = $id;
2761 // Parse the $options string
2762 $popupparams = array();
2763 if (!empty($options)) {
2764 $optionsarray = explode(',', $options);
2765 foreach ($optionsarray as $option) {
2766 if (strstr($option, '=')) {
2767 $parts = explode('=', $option);
2768 if ($parts[1] == '0') {
2769 $popupparams[$parts[0]] = false;
2770 } else {
2771 $popupparams[$parts[0]] = $parts[1];
2773 } else {
2774 $popupparams[$option] = true;
2779 if (!empty($height)) {
2780 $popupparams['height'] = $height;
2782 if (!empty($width)) {
2783 $popupparams['width'] = $width;
2786 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
2787 $output = $OUTPUT->render($form);
2789 if ($return) {
2790 return $output;
2791 } else {
2792 echo $output;
2797 * Print a self contained form with a single submit button.
2799 * @deprecated since Moodle 2.0
2801 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
2802 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
2803 * @param string $label the caption that appears on the button.
2804 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
2805 * @param string $notusedanymore no longer used.
2806 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
2807 * @param string $tooltip a tooltip to add to the button as a title attribute.
2808 * @param boolean $disabled if true, the button will be disabled.
2809 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
2810 * @param string $formid The id attribute to use for the form
2811 * @return string|void Depending on the $return paramter.
2813 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
2814 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
2815 global $OUTPUT;
2817 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2819 // Cast $options to array
2820 $options = (array) $options;
2822 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
2824 if ($jsconfirmmessage) {
2825 $button->button->add_confirm_action($jsconfirmmessage);
2828 $output = $OUTPUT->render($button);
2830 if ($return) {
2831 return $output;
2832 } else {
2833 echo $output;
2838 * Print a spacer image with the option of including a line break.
2840 * @deprecated since Moodle 2.0
2842 * @global object
2843 * @param int $height The height in pixels to make the spacer
2844 * @param int $width The width in pixels to make the spacer
2845 * @param boolean $br If set to true a BR is written after the spacer
2847 function print_spacer($height=1, $width=1, $br=true, $return=false) {
2848 global $CFG, $OUTPUT;
2850 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
2852 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
2854 if ($return) {
2855 return $output;
2856 } else {
2857 echo $output;
2862 * Given the path to a picture file in a course, or a URL,
2863 * this function includes the picture in the page.
2865 * @deprecated since Moodle 2.0
2867 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
2868 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
2872 * Print the specified user's avatar.
2874 * @deprecated since Moodle 2.0
2876 * @global object
2877 * @global object
2878 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
2879 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
2880 * if at all possible, particularly for reports. It is very bad for performance.
2881 * @param int $courseid The course id. Used when constructing the link to the user's profile.
2882 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
2883 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
2884 * @param boolean $return If false print picture to current page, otherwise return the output as string
2885 * @param boolean $link enclose printed image in a link the user's profile (default true).
2886 * @param string $target link target attribute. Makes the profile open in a popup window.
2887 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
2888 * decorative images, or where the username will be printed anyway.)
2889 * @return string|void String or nothing, depending on $return.
2891 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
2892 global $OUTPUT;
2894 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
2896 if (!is_object($user)) {
2897 $userid = $user;
2898 $user = new stdClass();
2899 $user->id = $userid;
2902 if (empty($user->picture) and $picture) {
2903 $user->picture = $picture;
2906 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
2908 $output = $OUTPUT->user_picture($user, $options);
2910 if ($return) {
2911 return $output;
2912 } else {
2913 echo $output;
2918 * Print a png image.
2920 * @deprecated since Moodle 2.0: no replacement
2923 function print_png() {
2924 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
2929 * Prints a basic textarea field.
2931 * @deprecated since Moodle 2.0
2933 * When using this function, you should
2935 * @global object
2936 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
2937 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
2938 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
2939 * @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.
2940 * @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.
2941 * @param string $name Name to use for the textarea element.
2942 * @param string $value Initial content to display in the textarea.
2943 * @param int $obsolete deprecated
2944 * @param bool $return If false, will output string. If true, will return string value.
2945 * @param string $id CSS ID to add to the textarea element.
2946 * @return string|void depending on the value of $return
2948 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
2949 /// $width and height are legacy fields and no longer used as pixels like they used to be.
2950 /// However, you can set them to zero to override the mincols and minrows values below.
2952 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
2953 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
2955 global $CFG;
2957 $mincols = 65;
2958 $minrows = 10;
2959 $str = '';
2961 if ($id === '') {
2962 $id = 'edit-'.$name;
2965 if ($usehtmleditor) {
2966 if ($height && ($rows < $minrows)) {
2967 $rows = $minrows;
2969 if ($width && ($cols < $mincols)) {
2970 $cols = $mincols;
2974 if ($usehtmleditor) {
2975 editors_head_setup();
2976 $editor = editors_get_preferred_editor(FORMAT_HTML);
2977 $editor->use_editor($id, array('legacy'=>true));
2978 } else {
2979 $editorclass = '';
2982 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
2983 if ($usehtmleditor) {
2984 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
2985 } else {
2986 $str .= s($value);
2988 $str .= '</textarea>'."\n";
2990 if ($return) {
2991 return $str;
2993 echo $str;
2998 * Print a help button.
3000 * @deprecated since Moodle 2.0
3002 * @param string $page The keyword that defines a help page
3003 * @param string $title The title of links, rollover tips, alt tags etc
3004 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
3005 * @param string $module Which module is the page defined in
3006 * @param mixed $image Use a help image for the link? (true/false/"both")
3007 * @param boolean $linktext If true, display the title next to the help icon.
3008 * @param string $text If defined then this text is used in the page, and
3009 * the $page variable is ignored. DEPRECATED!
3010 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
3011 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
3012 * @return string|void Depending on value of $return
3014 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
3015 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
3017 global $OUTPUT;
3019 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
3021 // hide image with CSS if needed
3023 if ($return) {
3024 return $output;
3025 } else {
3026 echo $output;
3031 * Print a help button.
3033 * Prints a special help button that is a link to the "live" emoticon popup
3035 * @todo Finish documenting this function
3037 * @global object
3038 * @global object
3039 * @param string $form ?
3040 * @param string $field ?
3041 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
3042 * @return string|void Depending on value of $return
3044 function emoticonhelpbutton($form, $field, $return = false) {
3045 /// TODO: MDL-21215
3047 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
3051 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
3052 * Should be used only with htmleditor or textarea.
3054 * @global object
3055 * @global object
3056 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
3057 * helpbutton.
3058 * @return string Link to help button
3060 function editorhelpbutton(){
3061 return '';
3063 /// TODO: MDL-21215
3067 * Print a help button.
3069 * Prints a special help button for html editors (htmlarea in this case)
3071 * @todo Write code into this function! detect current editor and print correct info
3072 * @global object
3073 * @return string Only returns an empty string at the moment
3075 function editorshortcutshelpbutton() {
3076 /// TODO: MDL-21215
3078 global $CFG;
3079 //TODO: detect current editor and print correct info
3080 /* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
3081 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
3083 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
3084 return '';
3089 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
3090 * provide this function with the language strings for sortasc and sortdesc.
3092 * @deprecated since Moodle 2.0
3094 * TODO migrate to outputlib
3095 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
3097 * @global object
3098 * @param string $direction 'up' or 'down'
3099 * @param string $strsort The language string used for the alt attribute of this image
3100 * @param bool $return Whether to print directly or return the html string
3101 * @return string|void depending on $return
3104 function print_arrow($direction='up', $strsort=null, $return=false) {
3105 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
3107 global $OUTPUT;
3109 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
3110 return null;
3113 $return = null;
3115 switch ($direction) {
3116 case 'up':
3117 $sortdir = 'asc';
3118 break;
3119 case 'down':
3120 $sortdir = 'desc';
3121 break;
3122 case 'move':
3123 $sortdir = 'asc';
3124 break;
3125 default:
3126 $sortdir = null;
3127 break;
3130 // Prepare language string
3131 $strsort = '';
3132 if (empty($strsort) && !empty($sortdir)) {
3133 $strsort = get_string('sort' . $sortdir, 'grades');
3136 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
3138 if ($return) {
3139 return $return;
3140 } else {
3141 echo $return;
3146 * Returns a string containing a link to the user documentation.
3147 * Also contains an icon by default. Shown to teachers and admin only.
3149 * @deprecated since Moodle 2.0
3151 * @global object
3152 * @param string $path The page link after doc root and language, no leading slash.
3153 * @param string $text The text to be displayed for the link
3154 * @param string $iconpath The path to the icon to be displayed
3155 * @return string Either the link or an empty string
3157 function doc_link($path='', $text='', $iconpath='ignored') {
3158 global $CFG, $OUTPUT;
3160 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
3162 if (empty($CFG->docroot)) {
3163 return '';
3166 return $OUTPUT->doc_link($path, $text);
3170 * Prints a single paging bar to provide access to other pages (usually in a search)
3172 * @deprecated since Moodle 2.0
3174 * @param int $totalcount Thetotal number of entries available to be paged through
3175 * @param int $page The page you are currently viewing
3176 * @param int $perpage The number of entries that should be shown per page
3177 * @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.
3178 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
3179 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
3180 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
3181 * @param bool $return whether to return an output string or echo now
3182 * @return bool|string depending on $result
3184 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
3185 global $OUTPUT;
3187 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
3189 if (empty($nocurr)) {
3190 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
3193 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
3194 $pagingbar->pagevar = $pagevar;
3195 $output = $OUTPUT->render($pagingbar);
3197 if ($return) {
3198 return $output;
3201 echo $output;
3202 return true;
3206 * Print a message along with "Yes" and "No" links for the user to continue.
3208 * @deprecated since Moodle 2.0
3210 * @global object
3211 * @param string $message The text to display
3212 * @param string $linkyes The link to take the user to if they choose "Yes"
3213 * @param string $linkno The link to take the user to if they choose "No"
3214 * @param string $optionyes The yes option to show on the notice
3215 * @param string $optionsno The no option to show
3216 * @param string $methodyes Form action method to use if yes [post, get]
3217 * @param string $methodno Form action method to use if no [post, get]
3218 * @return void Output is echo'd
3220 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
3222 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
3224 global $OUTPUT;
3226 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
3227 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
3229 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
3233 * Prints a scale menu (as part of an existing form) including help button
3234 * @deprecated since Moodle 2.0
3236 function print_scale_menu() {
3237 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
3241 * Given an array of values, output the HTML for a select element with those options.
3243 * @deprecated since Moodle 2.0
3245 * Normally, you only need to use the first few parameters.
3247 * @param array $options The options to offer. An array of the form
3248 * $options[{value}] = {text displayed for that option};
3249 * @param string $name the name of this form control, as in &lt;select name="..." ...
3250 * @param string $selected the option to select initially, default none.
3251 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
3252 * Set this to '' if you don't want a 'nothing is selected' option.
3253 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3254 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
3255 * @param boolean $return if false (the default) the the output is printed directly, If true, the
3256 * generated HTML is returned as a string.
3257 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
3258 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
3259 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
3260 * then a suitable one is constructed.
3261 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
3262 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
3263 * $listbox is an integer, that number is used for size instead.
3264 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
3265 * when $listbox display is enabled
3266 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
3267 * then a suitable one is constructed.
3268 * @return string|void If $return=true returns string, else echo's and returns void
3270 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
3271 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
3272 $id='', $listbox=false, $multiple=false, $class='') {
3274 global $OUTPUT;
3275 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
3277 if ($script) {
3278 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3280 $attributes = array();
3281 $attributes['disabled'] = $disabled ? 'disabled' : null;
3282 $attributes['tabindex'] = $tabindex ? $tabindex : null;
3283 $attributes['multiple'] = $multiple ? $multiple : null;
3284 $attributes['class'] = $class ? $class : null;
3285 $attributes['id'] = $id ? $id : null;
3287 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
3289 if ($return) {
3290 return $output;
3291 } else {
3292 echo $output;
3297 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
3298 * Other options like choose_from_menu.
3300 * @deprecated since Moodle 2.0
3302 * Calls {@link choose_from_menu()} with preset arguments
3303 * @see choose_from_menu()
3305 * @param string $name the name of this form control, as in &lt;select name="..." ...
3306 * @param string $selected the option to select initially, default none.
3307 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3308 * @param boolean $return Whether this function should return a string or output it (defaults to false)
3309 * @param boolean $disabled (defaults to false)
3310 * @param int $tabindex
3311 * @return string|void If $return=true returns string, else echo's and returns void
3313 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
3314 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
3315 global $OUTPUT;
3317 if ($script) {
3318 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3321 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
3323 if ($return) {
3324 return $output;
3325 } else {
3326 echo $output;
3331 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
3332 * including option headings with the first level.
3334 * @deprecated since Moodle 2.0
3336 * This function is very similar to {@link choose_from_menu_yesno()}
3337 * and {@link choose_from_menu()}
3339 * @todo Add datatype handling to make sure $options is an array
3341 * @param array $options An array of objects to choose from
3342 * @param string $name The XHTML field name
3343 * @param string $selected The value to select by default
3344 * @param string $nothing The label for the 'nothing is selected' option.
3345 * Defaults to get_string('choose').
3346 * @param string $script If not '', then this is added to the &lt;select> element
3347 * as an onchange handler.
3348 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
3349 * @param bool $return Whether this function should return a string or output
3350 * it (defaults to false)
3351 * @param bool $disabled Is the field disabled by default
3352 * @param int|string $tabindex Override the tabindex attribute [numeric]
3353 * @return string|void If $return=true returns string, else echo's and returns void
3355 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
3356 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
3358 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
3359 global $OUTPUT;
3363 * Prints a help button about a scale
3365 * @deprecated since Moodle 2.0
3367 * @global object
3368 * @param id $courseid
3369 * @param object $scale
3370 * @param boolean $return If set to true returns rather than echo's
3371 * @return string|bool Depending on value of $return
3373 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
3374 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
3375 global $OUTPUT;
3377 $output = $OUTPUT->help_icon_scale($courseid, $scale);
3379 if ($return) {
3380 return $output;
3381 } else {
3382 echo $output;
3388 * Prints time limit value selector
3390 * @deprecated since Moodle 2.0
3392 * Uses {@link choose_from_menu()} to generate HTML
3393 * @see choose_from_menu()
3395 * @global object
3396 * @param int $timelimit default
3397 * @param string $unit
3398 * @param string $name
3399 * @param boolean $return If set to true returns rather than echo's
3400 * @return string|bool Depending on value of $return
3402 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
3403 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
3407 * Prints form items with the names $hour and $minute
3409 * @deprecated since Moodle 2.0
3411 * @param string $hour fieldname
3412 * @param string $minute fieldname
3413 * @param int $currenttime A default timestamp in GMT
3414 * @param int $step minute spacing
3415 * @param boolean $return If set to true returns rather than echo's
3416 * @return string|bool Depending on value of $return
3418 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
3419 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
3421 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
3422 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
3424 $output = $hourselector . $$minuteselector;
3426 if ($return) {
3427 return $output;
3428 } else {
3429 echo $output;
3434 * Prints form items with the names $day, $month and $year
3436 * @deprecated since Moodle 2.0
3438 * @param string $day fieldname
3439 * @param string $month fieldname
3440 * @param string $year fieldname
3441 * @param int $currenttime A default timestamp in GMT
3442 * @param boolean $return If set to true returns rather than echo's
3443 * @return string|bool Depending on value of $return
3445 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
3446 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
3448 $dayselector = html_writer::select_time('days', $day, $currenttime);
3449 $monthselector = html_writer::select_time('months', $month, $currenttime);
3450 $yearselector = html_writer::select_time('years', $year, $currenttime);
3452 $output = $dayselector . $monthselector . $yearselector;
3454 if ($return) {
3455 return $output;
3456 } else {
3457 echo $output;
3462 * Implements a complete little form with a dropdown menu.
3464 * @deprecated since Moodle 2.0
3466 * When JavaScript is on selecting an option from the dropdown automatically
3467 * submits the form (while avoiding the usual acessibility problems with this appoach).
3468 * With JavaScript off, a 'Go' button is printed.
3470 * @global object
3471 * @global object
3472 * @param string $baseurl The target URL up to the point of the variable that changes
3473 * @param array $options A list of value-label pairs for the popup list
3474 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
3475 * @param string $selected The option that is initially selected
3476 * @param string $nothing The label for the "no choice" option
3477 * @param string $help The name of a help page if help is required
3478 * @param string $helptext The name of the label for the help button
3479 * @param boolean $return Indicates whether the function should return the HTML
3480 * as a string or echo it directly to the page being rendered
3481 * @param string $targetwindow The name of the target page to open the linked page in.
3482 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
3483 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
3484 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
3485 * @param boolean $disabled If true, the menu will be displayed disabled.
3486 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
3487 * @return string|void If $return=true returns string, else echo's and returns void
3489 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
3490 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
3491 global $OUTPUT, $CFG;
3493 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
3495 if (empty($options)) {
3496 return '';
3499 $urls = array();
3501 foreach ($options as $value=>$label) {
3502 $url = $baseurl.$value;
3503 $url = str_replace($CFG->wwwroot, '', $url);
3504 $url = str_replace('&amp;', '&', $url);
3505 $urls[$url] = $label;
3506 if ($selected == $value) {
3507 $active = $url;
3511 $nothing = $nothing ? array(''=>$nothing) : null;
3513 $select = new url_select($urls, $active, $nothing, $formid);
3514 $select->disabled = $disabled;
3516 $select->set_label($selectlabel);
3517 $select->set_old_help_icon($help, $helptext);
3519 $output = $OUTPUT->render($select);
3521 if ($return) {
3522 return $output;
3523 } else {
3524 echo $output;
3529 * Prints a simple button to close a window
3531 * @deprecated since Moodle 2.0
3533 * @global object
3534 * @param string $name Name of the window to close
3535 * @param boolean $return whether this function should return a string or output it.
3536 * @param boolean $reloadopener if true, clicking the button will also reload
3537 * the page that opend this popup window.
3538 * @return string|void if $return is true, void otherwise
3540 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
3541 global $OUTPUT;
3543 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
3544 $output = $OUTPUT->close_window_button(get_string($name));
3546 if ($return) {
3547 return $output;
3548 } else {
3549 echo $output;
3554 * Given an array of values, creates a group of radio buttons to be part of a form
3556 * @deprecated since Moodle 2.0
3558 * @staticvar int $idcounter
3559 * @param array $options An array of value-label pairs for the radio group (values as keys)
3560 * @param string $name Name of the radiogroup (unique in the form)
3561 * @param string $checked The value that is already checked
3562 * @param bool $return Whether this function should return a string or output
3563 * it (defaults to false)
3564 * @return string|void If $return=true returns string, else echo's and returns void
3566 function choose_from_radio ($options, $name, $checked='', $return=false) {
3567 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
3571 * Display an standard html checkbox with an optional label
3573 * @deprecated since Moodle 2.0
3575 * @staticvar int $idcounter
3576 * @param string $name The name of the checkbox
3577 * @param string $value The valus that the checkbox will pass when checked
3578 * @param bool $checked The flag to tell the checkbox initial state
3579 * @param string $label The label to be showed near the checkbox
3580 * @param string $alt The info to be inserted in the alt tag
3581 * @param string $script If not '', then this is added to the checkbox element
3582 * as an onchange handler.
3583 * @param bool $return Whether this function should return a string or output
3584 * it (defaults to false)
3585 * @return string|void If $return=true returns string, else echo's and returns void
3587 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
3589 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
3590 global $OUTPUT;
3592 if (!empty($script)) {
3593 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
3596 $output = html_writer::checkbox($name, $value, $checked, $label);
3598 if (empty($return)) {
3599 echo $output;
3600 } else {
3601 return $output;
3608 * Display an standard html text field with an optional label
3610 * @deprecated since Moodle 2.0
3612 * @param string $name The name of the text field
3613 * @param string $value The value of the text field
3614 * @param string $alt The info to be inserted in the alt tag
3615 * @param int $size Sets the size attribute of the field. Defaults to 50
3616 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
3617 * @param bool $return Whether this function should return a string or output
3618 * it (defaults to false)
3619 * @return string|void If $return=true returns string, else echo's and returns void
3621 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
3622 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
3624 if ($alt === '') {
3625 $alt = null;
3628 $style = "width: {$size}px;";
3629 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
3630 if ($maxlength) {
3631 $attributes['maxlength'] = $maxlength;
3634 $output = html_writer::empty_tag('input', $attributes);
3636 if (empty($return)) {
3637 echo $output;
3638 } else {
3639 return $output;
3645 * Centered heading with attached help button (same title text)
3646 * and optional icon attached
3648 * @deprecated since Moodle 2.0
3650 * @param string $text The text to be displayed
3651 * @param string $helppage The help page to link to
3652 * @param string $module The module whose help should be linked to
3653 * @param string $icon Image to display if needed
3654 * @param bool $return If set to true output is returned rather than echoed, default false
3655 * @return string|void String if return=true nothing otherwise
3657 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
3659 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
3661 global $OUTPUT;
3663 // Extract the src from $icon if it exists
3664 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
3665 $icon = $matches[1];
3666 $icon = new moodle_url($icon);
3667 } else {
3668 $icon = '';
3671 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
3673 if ($return) {
3674 return $output;
3675 } else {
3676 echo $output;
3681 * Returns a turn edit on/off button for course in a self contained form.
3682 * Used to be an icon, but it's now a simple form button
3683 * @deprecated since Moodle 2.0
3685 function update_mymoodle_icon() {
3686 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
3690 * Returns a turn edit on/off button for tag in a self contained form.
3691 * @deprecated since Moodle 2.0
3692 * @param string $tagid The ID attribute
3693 * @return string
3695 function update_tag_button($tagid) {
3696 global $OUTPUT;
3697 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3698 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
3703 * Prints the 'update this xxx' button that appears on module pages.
3705 * @deprecated since Moodle 2.0
3707 * @param string $cmid the course_module id.
3708 * @param string $ignored not used any more. (Used to be courseid.)
3709 * @param string $string the module name - get_string('modulename', 'xxx')
3710 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
3712 function update_module_button($cmid, $ignored, $string) {
3713 global $CFG, $OUTPUT;
3715 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
3717 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
3719 if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
3720 $string = get_string('updatethis', '', $string);
3722 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
3723 return $OUTPUT->single_button($url, $string);
3724 } else {
3725 return '';
3730 * Prints the editing button on search results listing
3731 * For bulk move courses to another category
3732 * @deprecated since Moodle 2.0
3734 function update_categories_search_button($search,$page,$perpage) {
3735 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
3739 * Prints a summary of a user in a nice little box.
3740 * @deprecated since Moodle 2.0
3742 function print_user($user, $course, $messageselect=false, $return=false) {
3743 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
3747 * Returns a turn edit on/off button for course in a self contained form.
3748 * Used to be an icon, but it's now a simple form button
3750 * Note that the caller is responsible for capchecks.
3752 * @global object
3753 * @global object
3754 * @param int $courseid The course to update by id as found in 'course' table
3755 * @return string
3757 function update_course_icon($courseid) {
3758 global $CFG, $OUTPUT;
3760 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3762 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
3766 * Prints breadcrumb trail of links, called in theme/-/header.html
3768 * This function has now been deprecated please use output's navbar method instead
3769 * as shown below
3771 * <code php>
3772 * echo $OUTPUT->navbar();
3773 * </code>
3775 * @deprecated since 2.0
3776 * @param mixed $navigation deprecated
3777 * @param string $separator OBSOLETE, and now deprecated
3778 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
3779 * @return string|void String or null, depending on $return.
3781 function print_navigation ($navigation, $separator=0, $return=false) {
3782 global $OUTPUT,$PAGE;
3784 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
3786 $output = $OUTPUT->navbar();
3788 if ($return) {
3789 return $output;
3790 } else {
3791 echo $output;
3796 * This function will build the navigation string to be used by print_header
3797 * and others.
3799 * It automatically generates the site and course level (if appropriate) links.
3801 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
3802 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
3804 * If you want to add any further navigation links after the ones this function generates,
3805 * the pass an array of extra link arrays like this:
3806 * array(
3807 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
3808 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
3810 * The normal case is to just add one further link, for example 'Editing forum' after
3811 * 'General Developer Forum', with no link.
3812 * To do that, you need to pass
3813 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
3814 * However, becuase this is a very common case, you can use a shortcut syntax, and just
3815 * pass the string 'Editing forum', instead of an array as $extranavlinks.
3817 * At the moment, the link types only have limited significance. Type 'activity' is
3818 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
3819 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
3820 * This really needs to be documented better. In the mean time, try to be consistent, it will
3821 * enable people to customise the navigation more in future.
3823 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
3824 * If you get the $cm object using the function get_coursemodule_from_instance or
3825 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
3826 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
3827 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
3828 * warning is printed in developer debug mode.
3830 * @deprecated since 2.0
3831 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
3832 * only want one extra item with no link, you can pass a string instead. If you don't want
3833 * any extra links, pass an empty string.
3834 * @param mixed $cm deprecated
3835 * @return array Navigation array
3837 function build_navigation($extranavlinks, $cm = null) {
3838 global $CFG, $COURSE, $DB, $SITE, $PAGE;
3840 if (is_array($extranavlinks) && count($extranavlinks)>0) {
3841 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
3842 foreach ($extranavlinks as $nav) {
3843 if (array_key_exists('name', $nav)) {
3844 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
3845 $link = $nav['link'];
3846 } else {
3847 $link = null;
3849 $PAGE->navbar->add($nav['name'],$link);
3854 return(array('newnav' => true, 'navlinks' => array()));
3858 * Returns a small popup menu of course activity modules
3860 * Given a course and a (current) coursemodule
3861 * his function returns a small popup menu with all the
3862 * course activity modules in it, as a navigation menu
3863 * The data is taken from the serialised array stored in
3864 * the course record
3866 * @global object
3867 * @global object
3868 * @global object
3869 * @global object
3870 * @uses CONTEXT_COURSE
3871 * @param object $course A {@link $COURSE} object.
3872 * @param object $cm A {@link $COURSE} object.
3873 * @param string $targetwindow The target window attribute to us
3874 * @return string
3876 function navmenu($course, $cm=NULL, $targetwindow='self') {
3877 // This function has been deprecated with the creation of the global nav in
3878 // moodle 2.0
3880 return '';
3884 * Returns a little popup menu for switching roles
3886 * @deprecated in Moodle 2.0
3887 * @param int $courseid The course to update by id as found in 'course' table
3888 * @return string
3890 function switchroles_form($courseid) {
3891 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
3892 return '';
3896 * Print header for admin page
3897 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
3898 * @param string $focus focus element
3900 function admin_externalpage_print_header($focus='') {
3901 global $OUTPUT;
3903 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
3905 echo $OUTPUT->header();
3909 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
3911 function admin_externalpage_print_footer() {
3912 // TODO Still 103 referernces in core code. Don't do debugging output yet.
3913 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
3914 global $OUTPUT;
3915 echo $OUTPUT->footer();
3918 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
3922 * Call this function to add an event to the calendar table and to call any calendar plugins
3924 * @param object $event An object representing an event from the calendar table.
3925 * The event will be identified by the id field. The object event should include the following:
3926 * <ul>
3927 * <li><b>$event->name</b> - Name for the event
3928 * <li><b>$event->description</b> - Description of the event (defaults to '')
3929 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
3930 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
3931 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
3932 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
3933 * <li><b>$event->modulename</b> - Name of the module that creates this event
3934 * <li><b>$event->instance</b> - Instance of the module that owns this event
3935 * <li><b>$event->eventtype</b> - The type info together with the module info could
3936 * be used by calendar plugins to decide how to display event
3937 * <li><b>$event->timestart</b>- Timestamp for start of event
3938 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
3939 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
3940 * </ul>
3941 * @return int|false The id number of the resulting record or false if failed
3943 function add_event($event) {
3944 global $CFG;
3945 require_once($CFG->dirroot.'/calendar/lib.php');
3946 $event = calendar_event::create($event);
3947 if ($event !== false) {
3948 return $event->id;
3950 return false;
3954 * Call this function to update an event in the calendar table
3955 * the event will be identified by the id field of the $event object.
3957 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3958 * @return bool Success
3960 function update_event($event) {
3961 global $CFG;
3962 require_once($CFG->dirroot.'/calendar/lib.php');
3963 $event = (object)$event;
3964 $calendarevent = calendar_event::load($event->id);
3965 return $calendarevent->update($event);
3969 * Call this function to delete the event with id $id from calendar table.
3971 * @param int $id The id of an event from the 'event' table.
3972 * @return bool
3974 function delete_event($id) {
3975 global $CFG;
3976 require_once($CFG->dirroot.'/calendar/lib.php');
3977 $event = calendar_event::load($id);
3978 return $event->delete();
3982 * Call this function to hide an event in the calendar table
3983 * the event will be identified by the id field of the $event object.
3985 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3986 * @return true
3988 function hide_event($event) {
3989 global $CFG;
3990 require_once($CFG->dirroot.'/calendar/lib.php');
3991 $event = new calendar_event($event);
3992 return $event->toggle_visibility(false);
3996 * Call this function to unhide an event in the calendar table
3997 * the event will be identified by the id field of the $event object.
3999 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
4000 * @return true
4002 function show_event($event) {
4003 global $CFG;
4004 require_once($CFG->dirroot.'/calendar/lib.php');
4005 $event = new calendar_event($event);
4006 return $event->toggle_visibility(true);