Merge branch 'wip-MDL-26747' of git://github.com/sammarshallou/moodle
[moodle.git] / lib / deprecatedlib.php
blobc70aaf2d5e9218e96d6aa2b15b55d5b8c845a701
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
1255 * @param mixed $table
1256 * @param mixed $select
1257 * @return void Throws an error and does nothing
1259 function record_exists_select($table, $select='') {
1260 error('record_exists_select() not available anymore');
1263 * @deprecated
1264 * @param mixed $sql
1265 * @return void Throws an error and does nothing
1267 function record_exists_sql($sql) {
1268 error('record_exists_sql() not available anymore');
1271 * @deprecated
1272 * @param mixed $table
1273 * @param mixed $select
1274 * @param mixed $countitem
1275 * @return void Throws an error and does nothing
1277 function count_records_select($table, $select='', $countitem='COUNT(*)') {
1278 error('count_records_select() not available anymore');
1281 * @deprecated
1282 * @param mixed $sql
1283 * @return void Throws an error and does nothing
1285 function count_records_sql($sql) {
1286 error('count_records_sql() not available anymore');
1289 * @deprecated
1290 * @param mixed $sql
1291 * @param bool $expectmultiple
1292 * @param bool $nolimit
1293 * @return void Throws an error and does nothing
1295 function get_record_sql($sql, $expectmultiple=false, $nolimit=false) {
1296 error('get_record_sql() not available anymore');
1299 * @deprecated
1300 * @param mixed $table
1301 * @param mixed $select
1302 * @param mixed $fields
1303 * @return void Throws an error and does nothing
1305 function get_record_select($table, $select='', $fields='*') {
1306 error('get_record_select() not available anymore');
1309 * @deprecated
1310 * @param mixed $table
1311 * @param mixed $field
1312 * @param mixed $value
1313 * @param mixed $sort
1314 * @param mixed $fields
1315 * @param mixed $limitfrom
1316 * @param mixed $limitnum
1317 * @return void Throws an error and does nothing
1319 function get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1320 error('get_recordset() not available anymore');
1323 * @deprecated
1324 * @param mixed $sql
1325 * @param mixed $limitfrom
1326 * @param mixed $limitnum
1327 * @return void Throws an error and does nothing
1329 function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) {
1330 error('get_recordset_sql() not available anymore');
1333 * @deprecated
1334 * @param mixed $rs
1335 * @return void Throws an error and does nothing
1337 function rs_fetch_record(&$rs) {
1338 error('rs_fetch_record() not available anymore');
1341 * @deprecated
1342 * @param mixed $rs
1343 * @return void Throws an error and does nothing
1345 function rs_next_record(&$rs) {
1346 error('rs_next_record() not available anymore');
1349 * @deprecated
1350 * @param mixed $rs
1351 * @return void Throws an error and does nothing
1353 function rs_fetch_next_record(&$rs) {
1354 error('rs_fetch_next_record() not available anymore');
1357 * @deprecated
1358 * @param mixed $rs
1359 * @return void Throws an error and does nothing
1361 function rs_EOF($rs) {
1362 error('rs_EOF() not available anymore');
1365 * @deprecated
1366 * @param mixed $rs
1367 * @return void Throws an error and does nothing
1369 function rs_close(&$rs) {
1370 error('rs_close() not available anymore');
1373 * @deprecated
1374 * @param mixed $table
1375 * @param mixed $select
1376 * @param mixed $sort
1377 * @param mixed $fields
1378 * @param mixed $limitfrom
1379 * @param mixed $limitnum
1380 * @return void Throws an error and does nothing
1382 function get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1383 error('get_records_select() not available anymore');
1386 * @deprecated
1387 * @param mixed $table
1388 * @param mixed $return
1389 * @param mixed $select
1390 * @return void Throws an error and does nothing
1392 function get_field_select($table, $return, $select) {
1393 error('get_field_select() not available anymore');
1396 * @deprecated
1397 * @param mixed $sql
1398 * @return void Throws an error and does nothing
1400 function get_field_sql($sql) {
1401 error('get_field_sql() not available anymore');
1404 * @deprecated
1405 * @param mixed $sql
1406 * @param mixed $select
1407 * @return void Throws an error and does nothing
1409 function delete_records_select($table, $select='') {
1410 error('get_field_sql() not available anymore');
1413 * @deprecated
1414 * @return void Throws an error and does nothing
1416 function configure_dbconnection() {
1417 error('configure_dbconnection() removed');
1420 * @deprecated
1421 * @param mixed $field
1422 * @return void Throws an error and does nothing
1424 function sql_max($field) {
1425 error('sql_max() removed - use normal sql MAX() instead');
1428 * @deprecated
1429 * @return void Throws an error and does nothing
1431 function sql_as() {
1432 error('sql_as() removed - do not use AS for tables at all');
1435 * @deprecated
1436 * @param mixed $page
1437 * @param mixed $recordsperpage
1438 * @return void Throws an error and does nothing
1440 function sql_paging_limit($page, $recordsperpage) {
1441 error('Function sql_paging_limit() is deprecated. Replace it with the correct use of limitfrom, limitnum parameters');
1444 * @deprecated
1445 * @return void Throws an error and does nothing
1447 function db_uppercase() {
1448 error('upper() removed - use normal sql UPPER()');
1451 * @deprecated
1452 * @return void Throws an error and does nothing
1454 function db_lowercase() {
1455 error('upper() removed - use normal sql LOWER()');
1458 * @deprecated
1459 * @param mixed $sqlfile
1460 * @param mixed $sqlstring
1461 * @return void Throws an error and does nothing
1463 function modify_database($sqlfile='', $sqlstring='') {
1464 error('modify_database() removed - use new XMLDB functions');
1467 * @deprecated
1468 * @param mixed $field1
1469 * @param mixed $value1
1470 * @param mixed $field2
1471 * @param mixed $value2
1472 * @param mixed $field3
1473 * @param mixed $value3
1474 * @return void Throws an error and does nothing
1476 function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1477 error('where_clause() removed - use new functions with $conditions parameter');
1480 * @deprecated
1481 * @param mixed $sqlarr
1482 * @param mixed $continue
1483 * @param mixed $feedback
1484 * @return void Throws an error and does nothing
1486 function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
1487 error('execute_sql_arr() removed');
1490 * @deprecated
1491 * @param mixed $table
1492 * @param mixed $field
1493 * @param mixed $values
1494 * @param mixed $sort
1495 * @param mixed $fields
1496 * @param mixed $limitfrom
1497 * @param mixed $limitnum
1498 * @return void Throws an error and does nothing
1500 function get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1501 error('get_records_list() removed');
1504 * @deprecated
1505 * @param mixed $table
1506 * @param mixed $field
1507 * @param mixed $values
1508 * @param mixed $sort
1509 * @param mixed $fields
1510 * @param mixed $limitfrom
1511 * @param mixed $limitnum
1512 * @return void Throws an error and does nothing
1514 function get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1515 error('get_recordset_list() removed');
1518 * @deprecated
1519 * @param mixed $table
1520 * @param mixed $field
1521 * @param mixed $value
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_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1529 error('get_records_menu() removed');
1532 * @deprecated
1533 * @param mixed $table
1534 * @param mixed $select
1535 * @param mixed $sort
1536 * @param mixed $fields
1537 * @param mixed $limitfrom
1538 * @param mixed $limitnum
1539 * @return void Throws an error and does nothing
1541 function get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1542 error('get_records_select_menu() removed');
1545 * @deprecated
1546 * @param mixed $sql
1547 * @param mixed $limitfrom
1548 * @param mixed $limitnum
1549 * @return void Throws an error and does nothing
1551 function get_records_sql_menu($sql, $limitfrom='', $limitnum='') {
1552 error('get_records_sql_menu() removed');
1555 * @deprecated
1556 * @param mixed $table
1557 * @param mixed $column
1558 * @return void Throws an error and does nothing
1560 function column_type($table, $column) {
1561 error('column_type() removed');
1564 * @deprecated
1565 * @param mixed $rs
1566 * @return void Throws an error and does nothing
1568 function recordset_to_menu($rs) {
1569 error('recordset_to_menu() removed');
1572 * @deprecated
1573 * @param mixed $records
1574 * @param mixed $field1
1575 * @param mixed $field2
1576 * @return void Throws an error and does nothing
1578 function records_to_menu($records, $field1, $field2) {
1579 error('records_to_menu() removed');
1582 * @deprecated
1583 * @param mixed $table
1584 * @param mixed $newfield
1585 * @param mixed $newvalue
1586 * @param mixed $select
1587 * @param mixed $localcall
1588 * @return void Throws an error and does nothing
1590 function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) {
1591 error('set_field_select() removed');
1594 * @deprecated
1595 * @param mixed $table
1596 * @param mixed $return
1597 * @param mixed $select
1598 * @return void Throws an error and does nothing
1600 function get_fieldset_select($table, $return, $select) {
1601 error('get_fieldset_select() removed');
1604 * @deprecated
1605 * @param mixed $sql
1606 * @return void Throws an error and does nothing
1608 function get_fieldset_sql($sql) {
1609 error('get_fieldset_sql() removed');
1612 * @deprecated
1613 * @return void Throws an error and does nothing
1615 function sql_ilike() {
1616 error('sql_ilike() not available anymore');
1619 * @deprecated
1620 * @param mixed $first
1621 * @param mixed $last
1622 * @return void Throws an error and does nothing
1624 function sql_fullname($first='firstname', $last='lastname') {
1625 error('sql_fullname() not available anymore');
1628 * @deprecated
1629 * @return void Throws an error and does nothing
1631 function sql_concat() {
1632 error('sql_concat() not available anymore');
1635 * @deprecated
1636 * @return void Throws an error and does nothing
1638 function sql_empty() {
1639 error('sql_empty() not available anymore');
1642 * @deprecated
1643 * @return void Throws an error and does nothing
1645 function sql_substr() {
1646 error('sql_substr() not available anymore');
1649 * @deprecated
1650 * @param mixed $int1
1651 * @param mixed $int2
1652 * @return void Throws an error and does nothing
1654 function sql_bitand($int1, $int2) {
1655 error('sql_bitand() not available anymore');
1658 * @deprecated
1659 * @param mixed $int1
1660 * @return void Throws an error and does nothing
1662 function sql_bitnot($int1) {
1663 error('sql_bitnot() not available anymore');
1666 * @deprecated
1667 * @param mixed $int1
1668 * @param mixed $int2
1669 * @return void Throws an error and does nothing
1671 function sql_bitor($int1, $int2) {
1672 error('sql_bitor() not available anymore');
1675 * @deprecated
1676 * @param mixed $int1
1677 * @param mixed $int2
1678 * @return void Throws an error and does nothing
1680 function sql_bitxor($int1, $int2) {
1681 error('sql_bitxor() not available anymore');
1684 * @deprecated
1685 * @param mixed $fieldname
1686 * @param mixed $text
1687 * @return void Throws an error and does nothing
1689 function sql_cast_char2int($fieldname, $text=false) {
1690 error('sql_cast_char2int() not available anymore');
1693 * @deprecated
1694 * @param mixed $fieldname
1695 * @param mixed $numchars
1696 * @return void Throws an error and does nothing
1698 function sql_compare_text($fieldname, $numchars=32) {
1699 error('sql_compare_text() not available anymore');
1702 * @deprecated
1703 * @param mixed $fieldname
1704 * @param mixed $numchars
1705 * @return void Throws an error and does nothing
1707 function sql_order_by_text($fieldname, $numchars=32) {
1708 error('sql_order_by_text() not available anymore');
1711 * @deprecated
1712 * @param mixed $fieldname
1713 * @return void Throws an error and does nothing
1715 function sql_length($fieldname) {
1716 error('sql_length() not available anymore');
1719 * @deprecated
1720 * @param mixed $separator
1721 * @param mixed $elements
1722 * @return void Throws an error and does nothing
1724 function sql_concat_join($separator="' '", $elements=array()) {
1725 error('sql_concat_join() not available anymore');
1728 * @deprecated
1729 * @param mixed $tablename
1730 * @param mixed $fieldname
1731 * @param mixed $nullablefield
1732 * @param mixed $textfield
1733 * @return void Throws an error and does nothing
1735 function sql_isempty($tablename, $fieldname, $nullablefield, $textfield) {
1736 error('sql_isempty() not available anymore');
1739 * @deprecated
1740 * @param mixed $tablename
1741 * @param mixed $fieldname
1742 * @param mixed $nullablefield
1743 * @param mixed $textfield
1744 * @return void Throws an error and does nothing
1746 function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) {
1747 error('sql_isnotempty() not available anymore');
1750 * @deprecated
1751 * @return void Throws an error and does nothing
1753 function begin_sql() {
1754 error('begin_sql() not available anymore');
1757 * @deprecated
1758 * @return void Throws an error and does nothing
1760 function commit_sql() {
1761 error('commit_sql() not available anymore');
1764 * @deprecated
1765 * @return void Throws an error and does nothing
1767 function rollback_sql() {
1768 error('rollback_sql() not available anymore');
1771 * @deprecated
1772 * @param mixed $table
1773 * @param mixed $dataobject
1774 * @param mixed $returnid
1775 * @param mixed $primarykey
1776 * @return void Throws an error and does nothing
1778 function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
1779 error('insert_record() not available anymore');
1782 * @deprecated
1783 * @param mixed $table
1784 * @param mixed $dataobject
1785 * @return void Throws an error and does nothing
1787 function update_record($table, $dataobject) {
1788 error('update_record() not available anymore');
1791 * @deprecated
1792 * @param mixed $table
1793 * @param mixed $field
1794 * @param mixed $value
1795 * @param mixed $sort
1796 * @param mixed $fields
1797 * @param mixed $limitfrom
1798 * @param mixed $limitnum
1800 * @return void Throws an error and does nothing
1802 function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1803 error('get_records() not available anymore');
1806 * @deprecated
1807 * @param mixed $table
1808 * @param mixed $field1
1809 * @param mixed $value1
1810 * @param mixed $field2
1811 * @param mixed $value2
1812 * @param mixed $field3
1813 * @param mixed $value3
1814 * @param mixed $fields
1815 * @return void Throws an error and does nothing
1817 function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') {
1818 error('get_record() not available anymore');
1821 * @deprecated
1822 * @param mixed $table
1823 * @param mixed $newfield
1824 * @param mixed $newvalue
1825 * @param mixed $field1
1826 * @param mixed $value1
1827 * @param mixed $field2
1828 * @param mixed $value2
1829 * @param mixed $field3
1830 * @param mixed $value3
1831 * @return void Throws an error and does nothing
1833 function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1834 error('set_field() not available anymore');
1837 * @deprecated
1838 * @param mixed $table
1839 * @param mixed $field1
1840 * @param mixed $value1
1841 * @param mixed $field2
1842 * @param mixed $value2
1843 * @param mixed $field3
1844 * @param mixed $value3
1845 * @return void Throws an error and does nothing
1847 function count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1848 error('count_records() not available anymore');
1851 * @deprecated
1852 * @param mixed $table
1853 * @param mixed $field1
1854 * @param mixed $value1
1855 * @param mixed $field2
1856 * @param mixed $value2
1857 * @param mixed $field3
1858 * @param mixed $value3
1859 * @return void Throws an error and does nothing
1861 function record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1862 error('record_exists() not available anymore');
1865 * @deprecated
1866 * @param mixed $table
1867 * @param mixed $field1
1868 * @param mixed $value1
1869 * @param mixed $field2
1870 * @param mixed $value2
1871 * @param mixed $field3
1872 * @param mixed $value3
1873 * @return void Throws an error and does nothing
1875 function delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1876 error('delete_records() not available anymore');
1879 * @deprecated
1880 * @param mixed $table
1881 * @param mixed $return
1882 * @param mixed $field1
1883 * @param mixed $value1
1884 * @param mixed $field2
1885 * @param mixed $value2
1886 * @param mixed $field3
1887 * @param mixed $value3
1888 * @return void Throws an error and does nothing
1890 function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1891 error('get_field() not available anymore');
1894 * @deprecated
1895 * @param mixed $table
1896 * @param mixed $oldfield
1897 * @param mixed $field
1898 * @param mixed $type
1899 * @param mixed $size
1900 * @param mixed $signed
1901 * @param mixed $default
1902 * @param mixed $null
1903 * @param mixed $after
1904 * @return void Throws an error and does nothing
1906 function table_column($table, $oldfield, $field, $type='integer', $size='10',
1907 $signed='unsigned', $default='0', $null='not null', $after='') {
1908 error('table_column() was removed, please use new ddl functions');
1911 * @deprecated
1912 * @param mixed $name
1913 * @param mixed $editorhidebuttons
1914 * @param mixed $id
1915 * @return void Throws an error and does nothing
1917 function use_html_editor($name='', $editorhidebuttons='', $id='') {
1918 error('use_html_editor() not available anymore');
1922 * The old method that was used to include JavaScript libraries.
1923 * Please use $PAGE->requires->js_module() instead.
1925 * @param mixed $lib The library or libraries to load (a string or array of strings)
1926 * There are three way to specify the library:
1927 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
1928 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
1929 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
1930 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
1932 function require_js($lib) {
1933 global $CFG, $PAGE;
1934 // Add the lib to the list of libs to be loaded, if it isn't already
1935 // in the list.
1936 if (is_array($lib)) {
1937 foreach($lib as $singlelib) {
1938 require_js($singlelib);
1940 return;
1943 debugging('Call to deprecated function require_js. Please use $PAGE->requires->js_module() instead.', DEBUG_DEVELOPER);
1945 if (strpos($lib, 'yui_') === 0) {
1946 $PAGE->requires->yui2_lib(substr($lib, 4));
1947 } else {
1948 if ($PAGE->requires->is_head_done()) {
1949 echo html_writer::script('', $lib);
1950 } else {
1951 $PAGE->requires->js(new moodle_url($lib));
1957 * Makes an upload directory for a particular module.
1959 * This function has been deprecated by the file API changes in Moodle 2.0.
1961 * @deprecated
1962 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
1963 * @return string|false Returns full path to directory if successful, false if not
1965 function make_mod_upload_directory($courseid) {
1966 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
1970 * Used to be used for setting up the theme. No longer used by core code, and
1971 * should not have been used elsewhere.
1973 * The theme is now automatically initialised before it is first used. If you really need
1974 * to force this to happen, just reference $PAGE->theme.
1976 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
1977 * However, I can't think of any valid reason to do that outside the theme selector UI.
1979 * @deprecated
1980 * @param string $theme The theme to use defaults to current theme
1981 * @param array $params An array of parameters to use
1983 function theme_setup($theme = '', $params=NULL) {
1984 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
1985 'The current theme gets initialised automatically before it is first used.');
1989 * @deprecated use $PAGE->theme->name instead.
1990 * @return string the name of the current theme.
1992 function current_theme() {
1993 global $PAGE;
1994 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
1995 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
1996 return $PAGE->theme->name;
2000 * @todo Remove this deprecated function when no longer used
2001 * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
2003 * @param string $getid used to return $PAGE->pagetype.
2004 * @param string $getclass used to return $PAGE->legacyclass.
2006 function page_id_and_class(&$getid, &$getclass) {
2007 global $PAGE;
2008 debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
2009 $getid = $PAGE->pagetype;
2010 $getclass = $PAGE->legacyclass;
2014 * Prints some red text using echo
2016 * @deprecated
2017 * @param string $error The text to be displayed in red
2019 function formerr($error) {
2020 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
2021 global $OUTPUT;
2022 echo $OUTPUT->error_text($error);
2026 * Return the markup for the destination of the 'Skip to main content' links.
2027 * Accessibility improvement for keyboard-only users.
2029 * Used in course formats, /index.php and /course/index.php
2031 * @deprecated use $OUTPUT->skip_link_target() in instead.
2032 * @return string HTML element.
2034 function skip_main_destination() {
2035 global $OUTPUT;
2036 return $OUTPUT->skip_link_target();
2040 * Prints a string in a specified size (retained for backward compatibility)
2042 * @deprecated
2043 * @param string $text The text to be displayed
2044 * @param int $size The size to set the font for text display.
2045 * @param bool $return If set to true output is returned rather than echoed Default false
2046 * @return string|void String if return is true
2048 function print_headline($text, $size=2, $return=false) {
2049 global $OUTPUT;
2050 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
2051 $output = $OUTPUT->heading($text, $size);
2052 if ($return) {
2053 return $output;
2054 } else {
2055 echo $output;
2060 * Prints text in a format for use in headings.
2062 * @deprecated
2063 * @param string $text The text to be displayed
2064 * @param string $deprecated No longer used. (Use to do alignment.)
2065 * @param int $size The size to set the font for text display.
2066 * @param string $class
2067 * @param bool $return If set to true output is returned rather than echoed, default false
2068 * @param string $id The id to use in the element
2069 * @return string|void String if return=true nothing otherwise
2071 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
2072 global $OUTPUT;
2073 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
2074 if (!empty($deprecated)) {
2075 debugging('Use of deprecated align attribute of print_heading. ' .
2076 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
2078 $output = $OUTPUT->heading($text, $size, $class, $id);
2079 if ($return) {
2080 return $output;
2081 } else {
2082 echo $output;
2087 * Output a standard heading block
2089 * @deprecated
2090 * @param string $heading The text to write into the heading
2091 * @param string $class An additional Class Attr to use for the heading
2092 * @param bool $return If set to true output is returned rather than echoed, default false
2093 * @return string|void HTML String if return=true nothing otherwise
2095 function print_heading_block($heading, $class='', $return=false) {
2096 global $OUTPUT;
2097 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
2098 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
2099 if ($return) {
2100 return $output;
2101 } else {
2102 echo $output;
2107 * Print a message in a standard themed box.
2108 * Replaces print_simple_box (see deprecatedlib.php)
2110 * @deprecated
2111 * @param string $message, the content of the box
2112 * @param string $classes, space-separated class names.
2113 * @param string $ids
2114 * @param boolean $return, return as string or just print it
2115 * @return string|void mixed string or void
2117 function print_box($message, $classes='generalbox', $ids='', $return=false) {
2118 global $OUTPUT;
2119 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
2120 $output = $OUTPUT->box($message, $classes, $ids);
2121 if ($return) {
2122 return $output;
2123 } else {
2124 echo $output;
2129 * Starts a box using divs
2130 * Replaces print_simple_box_start (see deprecatedlib.php)
2132 * @deprecated
2133 * @param string $classes, space-separated class names.
2134 * @param string $ids
2135 * @param boolean $return, return as string or just print it
2136 * @return string|void string or void
2138 function print_box_start($classes='generalbox', $ids='', $return=false) {
2139 global $OUTPUT;
2140 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
2141 $output = $OUTPUT->box_start($classes, $ids);
2142 if ($return) {
2143 return $output;
2144 } else {
2145 echo $output;
2150 * Simple function to end a box (see above)
2151 * Replaces print_simple_box_end (see deprecatedlib.php)
2153 * @deprecated
2154 * @param boolean $return, return as string or just print it
2155 * @return string|void Depending on value of return
2157 function print_box_end($return=false) {
2158 global $OUTPUT;
2159 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
2160 $output = $OUTPUT->box_end();
2161 if ($return) {
2162 return $output;
2163 } else {
2164 echo $output;
2169 * Print a message in a standard themed container.
2171 * @deprecated
2172 * @param string $message, the content of the container
2173 * @param boolean $clearfix clear both sides
2174 * @param string $classes, space-separated class names.
2175 * @param string $idbase
2176 * @param boolean $return, return as string or just print it
2177 * @return string|void Depending on value of $return
2179 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
2180 global $OUTPUT;
2181 if ($clearfix) {
2182 $classes .= ' clearfix';
2184 $output = $OUTPUT->container($message, $classes, $idbase);
2185 if ($return) {
2186 return $output;
2187 } else {
2188 echo $output;
2193 * Starts a container using divs
2195 * @deprecated
2196 * @param boolean $clearfix clear both sides
2197 * @param string $classes, space-separated class names.
2198 * @param string $idbase
2199 * @param boolean $return, return as string or just print it
2200 * @return string|void Based on value of $return
2202 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
2203 global $OUTPUT;
2204 if ($clearfix) {
2205 $classes .= ' clearfix';
2207 $output = $OUTPUT->container_start($classes, $idbase);
2208 if ($return) {
2209 return $output;
2210 } else {
2211 echo $output;
2216 * Deprecated, now handled automatically in themes
2218 function check_theme_arrows() {
2219 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
2223 * Simple function to end a container (see above)
2225 * @deprecated
2226 * @param boolean $return, return as string or just print it
2227 * @return string|void Based on $return
2229 function print_container_end($return=false) {
2230 global $OUTPUT;
2231 $output = $OUTPUT->container_end();
2232 if ($return) {
2233 return $output;
2234 } else {
2235 echo $output;
2240 * Print a bold message in an optional color.
2242 * @deprecated use $OUTPUT->notification instead.
2243 * @param string $message The message to print out
2244 * @param string $style Optional style to display message text in
2245 * @param string $align Alignment option
2246 * @param bool $return whether to return an output string or echo now
2247 * @return string|bool Depending on $result
2249 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
2250 global $OUTPUT;
2252 if ($classes == 'green') {
2253 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
2254 $classes = 'notifysuccess'; // Backward compatible with old color system
2257 $output = $OUTPUT->notification($message, $classes);
2258 if ($return) {
2259 return $output;
2260 } else {
2261 echo $output;
2266 * Print a continue button that goes to a particular URL.
2268 * @deprecated since Moodle 2.0
2270 * @param string $link The url to create a link to.
2271 * @param bool $return If set to true output is returned rather than echoed, default false
2272 * @return string|void HTML String if return=true nothing otherwise
2274 function print_continue($link, $return = false) {
2275 global $CFG, $OUTPUT;
2277 if ($link == '') {
2278 if (!empty($_SERVER['HTTP_REFERER'])) {
2279 $link = $_SERVER['HTTP_REFERER'];
2280 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
2281 } else {
2282 $link = $CFG->wwwroot .'/';
2286 $output = $OUTPUT->continue_button($link);
2287 if ($return) {
2288 return $output;
2289 } else {
2290 echo $output;
2295 * Print a standard header
2297 * @param string $title Appears at the top of the window
2298 * @param string $heading Appears at the top of the page
2299 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
2300 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2301 * @param string $meta Meta tags to be added to the header
2302 * @param boolean $cache Should this page be cacheable?
2303 * @param string $button HTML code for a button (usually for module editing)
2304 * @param string $menu HTML code for a popup menu
2305 * @param boolean $usexml use XML for this page
2306 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2307 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2308 * @return string|void If return=true then string else void
2310 function print_header($title='', $heading='', $navigation='', $focus='',
2311 $meta='', $cache=true, $button='&nbsp;', $menu=null,
2312 $usexml=false, $bodytags='', $return=false) {
2313 global $PAGE, $OUTPUT;
2315 $PAGE->set_title($title);
2316 $PAGE->set_heading($heading);
2317 $PAGE->set_cacheable($cache);
2318 if ($button == '') {
2319 $button = '&nbsp;';
2321 $PAGE->set_button($button);
2322 $PAGE->set_headingmenu($menu);
2324 // TODO $menu
2326 if ($meta) {
2327 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2328 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2330 if ($usexml) {
2331 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2333 if ($bodytags) {
2334 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2337 $output = $OUTPUT->header();
2339 if ($return) {
2340 return $output;
2341 } else {
2342 echo $output;
2347 * This version of print_header is simpler because the course name does not have to be
2348 * provided explicitly in the strings. It can be used on the site page as in courses
2349 * Eventually all print_header could be replaced by print_header_simple
2351 * @deprecated since Moodle 2.0
2352 * @param string $title Appears at the top of the window
2353 * @param string $heading Appears at the top of the page
2354 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
2355 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2356 * @param string $meta Meta tags to be added to the header
2357 * @param boolean $cache Should this page be cacheable?
2358 * @param string $button HTML code for a button (usually for module editing)
2359 * @param string $menu HTML code for a popup menu
2360 * @param boolean $usexml use XML for this page
2361 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2362 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2363 * @return string|void If $return=true the return string else nothing
2365 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
2366 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
2368 global $COURSE, $CFG, $PAGE, $OUTPUT;
2370 if ($meta) {
2371 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2372 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2374 if ($usexml) {
2375 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2377 if ($bodytags) {
2378 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2381 $PAGE->set_title($title);
2382 $PAGE->set_heading($heading);
2383 $PAGE->set_cacheable(true);
2384 $PAGE->set_button($button);
2386 $output = $OUTPUT->header();
2388 if ($return) {
2389 return $output;
2390 } else {
2391 echo $output;
2395 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
2396 global $PAGE, $OUTPUT;
2397 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
2398 // TODO check arguments.
2399 if (is_string($course)) {
2400 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
2401 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
2402 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
2403 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
2405 if (!is_null($usercourse)) {
2406 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
2407 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
2409 $output = $OUTPUT->footer();
2410 if ($return) {
2411 return $output;
2412 } else {
2413 echo $output;
2418 * Returns text to be displayed to the user which reflects their login status
2420 * @global object
2421 * @global object
2422 * @global object
2423 * @global object
2424 * @uses CONTEXT_COURSE
2425 * @param course $course {@link $COURSE} object containing course information
2426 * @param user $user {@link $USER} object containing user information
2427 * @return string HTML
2429 function user_login_string($course='ignored', $user='ignored') {
2430 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
2431 return '';
2435 * Prints a nice side block with an optional header. The content can either
2436 * be a block of HTML or a list of text with optional icons.
2438 * @todo Finish documenting this function. Show example of various attributes, etc.
2440 * @static int $block_id Increments for each call to the function
2441 * @param string $heading HTML for the heading. Can include full HTML or just
2442 * plain text - plain text will automatically be enclosed in the appropriate
2443 * heading tags.
2444 * @param string $content HTML for the content
2445 * @param array $list an alternative to $content, it you want a list of things with optional icons.
2446 * @param array $icons optional icons for the things in $list.
2447 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
2448 * @param array $attributes an array of attribute => value pairs that are put on the
2449 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
2450 * already a class, class='block' is used.
2451 * @param string $title Plain text title, as embedded in the $heading.
2452 * @deprecated
2454 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
2455 global $OUTPUT;
2457 // We don't use $heading, becuse it often contains HTML that we don't want.
2458 // However, sometimes $title is not set, but $heading is.
2459 if (empty($title)) {
2460 $title = strip_tags($heading);
2463 // Render list contents to HTML if required.
2464 if (empty($content) && $list) {
2465 $content = $OUTPUT->list_block_contents($icons, $list);
2468 $bc = new block_contents();
2469 $bc->content = $content;
2470 $bc->footer = $footer;
2471 $bc->title = $title;
2473 if (isset($attributes['id'])) {
2474 $bc->id = $attributes['id'];
2475 unset($attributes['id']);
2477 $bc->attributes = $attributes;
2479 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
2483 * Starts a nice side block with an optional header.
2485 * @todo Finish documenting this function
2487 * @global object
2488 * @global object
2489 * @param string $heading HTML for the heading. Can include full HTML or just
2490 * plain text - plain text will automatically be enclosed in the appropriate
2491 * heading tags.
2492 * @param array $attributes HTML attributes to apply if possible
2493 * @deprecated
2495 function print_side_block_start($heading='', $attributes = array()) {
2496 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
2500 * Print table ending tags for a side block box.
2502 * @global object
2503 * @global object
2504 * @param array $attributes HTML attributes to apply if possible [id]
2505 * @param string $title
2506 * @deprecated
2508 function print_side_block_end($attributes = array(), $title='') {
2509 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
2513 * This was used by old code to see whether a block region had anything in it,
2514 * and hence wether that region should be printed.
2516 * We don't ever want old code to print blocks, so we now always return false.
2517 * The function only exists to avoid fatal errors in old code.
2519 * @deprecated since Moodle 2.0. always returns false.
2521 * @param object $blockmanager
2522 * @param string $region
2523 * @return bool
2525 function blocks_have_content(&$blockmanager, $region) {
2526 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
2527 return false;
2531 * This was used by old code to print the blocks in a region.
2533 * We don't ever want old code to print blocks, so this is now a no-op.
2534 * The function only exists to avoid fatal errors in old code.
2536 * @deprecated since Moodle 2.0. does nothing.
2538 * @param object $page
2539 * @param object $blockmanager
2540 * @param string $region
2542 function blocks_print_group($page, $blockmanager, $region) {
2543 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2547 * This used to be the old entry point for anyone that wants to use blocks.
2548 * Since we don't want people people dealing with blocks this way any more,
2549 * just return a suitable empty array.
2551 * @deprecated since Moodle 2.0.
2553 * @param object $page
2554 * @return array
2556 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
2557 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2558 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
2562 * This iterates over an array of blocks and calculates the preferred width
2563 * Parameter passed by reference for speed; it's not modified.
2565 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
2567 * @param mixed $instances
2569 function blocks_preferred_width($instances) {
2570 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2571 $width = 210;
2575 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2577 * @param object $page The page object
2578 * @param object $blockmanager The block manager object
2579 * @param string $blockaction One of [config, add, delete]
2580 * @param int|object $instanceorid The instance id or a block_instance object
2581 * @param bool $pinned
2582 * @param bool $redirect To redirect or not to that is the question but you should stick with true
2584 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
2585 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.');
2589 * You can use this to get the blocks to respond to URL actions without much hassle
2591 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
2593 * @param object $PAGE
2594 * @param object $blockmanager
2595 * @param bool $pinned
2597 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
2598 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
2602 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
2603 * in order to reduce code repetition.
2605 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2607 * @param $instance
2608 * @param $newpos
2609 * @param string|int $newweight
2610 * @param bool $pinned
2612 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
2613 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.');
2618 * Moves a block to the new position (column) and weight (sort order).
2620 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2622 * @param object $instance The block instance to be moved.
2623 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
2624 * @param string $destweight The destination sort order. If NULL, we add to the end
2625 * of the destination column.
2626 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
2627 * to a new position withing the pinned list. Likewise, we
2628 * can only moved non-pinned blocks to a new position within
2629 * the non-pinned list.
2630 * @return boolean success or failure
2632 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
2633 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.');
2637 * Print a nicely formatted table.
2639 * @deprecated since Moodle 2.0
2641 * @param array $table is an object with several properties.
2643 function print_table($table, $return=false) {
2644 global $OUTPUT;
2645 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
2646 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
2647 $newtable = new html_table();
2648 foreach ($table as $property => $value) {
2649 if (property_exists($newtable, $property)) {
2650 $newtable->{$property} = $value;
2653 if (isset($table->class)) {
2654 $newtable->attributes['class'] = $table->class;
2656 if (isset($table->rowclass) && is_array($table->rowclass)) {
2657 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
2658 $newtable->rowclasses = $table->rowclass;
2660 $output = html_writer::table($newtable);
2661 if ($return) {
2662 return $output;
2663 } else {
2664 echo $output;
2665 return true;
2670 * Creates and displays (or returns) a link to a popup window
2672 * @deprecated since Moodle 2.0
2674 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2675 * @param string $name Name to be assigned to the popup window (this is used by
2676 * client-side scripts to "talk" to the popup window)
2677 * @param string $linkname Text to be displayed as web link
2678 * @param int $height Height to assign to popup window
2679 * @param int $width Height to assign to popup window
2680 * @param string $title Text to be displayed as popup page title
2681 * @param string $options List of additional options for popup window
2682 * @param bool $return If true, return as a string, otherwise print
2683 * @param string $id id added to the element
2684 * @param string $class class added to the element
2685 * @return string html code to display a link to a popup window.
2687 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
2688 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');
2690 return html_writer::link($url, $name);
2694 * Creates and displays (or returns) a buttons to a popup window.
2696 * @deprecated since Moodle 2.0
2698 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2699 * @param string $name Name to be assigned to the popup window (this is used by
2700 * client-side scripts to "talk" to the popup window)
2701 * @param string $linkname Text to be displayed as web link
2702 * @param int $height Height to assign to popup window
2703 * @param int $width Height to assign to popup window
2704 * @param string $title Text to be displayed as popup page title
2705 * @param string $options List of additional options for popup window
2706 * @param bool $return If true, return as a string, otherwise print
2707 * @param string $id id added to the element
2708 * @param string $class class added to the element
2709 * @return string html code to display a link to a popup window.
2711 function button_to_popup_window ($url, $name=null, $linkname=null,
2712 $height=400, $width=500, $title=null, $options=null, $return=false,
2713 $id=null, $class=null) {
2714 global $OUTPUT;
2716 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2718 if ($options == 'none') {
2719 $options = null;
2722 if (empty($linkname)) {
2723 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
2726 // Create a single_button object
2727 $form = new single_button($url, $linkname, 'post');
2728 $form->button->title = $title;
2729 $form->button->id = $id;
2731 // Parse the $options string
2732 $popupparams = array();
2733 if (!empty($options)) {
2734 $optionsarray = explode(',', $options);
2735 foreach ($optionsarray as $option) {
2736 if (strstr($option, '=')) {
2737 $parts = explode('=', $option);
2738 if ($parts[1] == '0') {
2739 $popupparams[$parts[0]] = false;
2740 } else {
2741 $popupparams[$parts[0]] = $parts[1];
2743 } else {
2744 $popupparams[$option] = true;
2749 if (!empty($height)) {
2750 $popupparams['height'] = $height;
2752 if (!empty($width)) {
2753 $popupparams['width'] = $width;
2756 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
2757 $output = $OUTPUT->render($form);
2759 if ($return) {
2760 return $output;
2761 } else {
2762 echo $output;
2767 * Print a self contained form with a single submit button.
2769 * @deprecated since Moodle 2.0
2771 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
2772 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
2773 * @param string $label the caption that appears on the button.
2774 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
2775 * @param string $notusedanymore no longer used.
2776 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
2777 * @param string $tooltip a tooltip to add to the button as a title attribute.
2778 * @param boolean $disabled if true, the button will be disabled.
2779 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
2780 * @param string $formid The id attribute to use for the form
2781 * @return string|void Depending on the $return paramter.
2783 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
2784 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
2785 global $OUTPUT;
2787 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2789 // Cast $options to array
2790 $options = (array) $options;
2792 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
2794 if ($jsconfirmmessage) {
2795 $button->button->add_confirm_action($jsconfirmmessage);
2798 $output = $OUTPUT->render($button);
2800 if ($return) {
2801 return $output;
2802 } else {
2803 echo $output;
2808 * Print a spacer image with the option of including a line break.
2810 * @deprecated since Moodle 2.0
2812 * @global object
2813 * @param int $height The height in pixels to make the spacer
2814 * @param int $width The width in pixels to make the spacer
2815 * @param boolean $br If set to true a BR is written after the spacer
2817 function print_spacer($height=1, $width=1, $br=true, $return=false) {
2818 global $CFG, $OUTPUT;
2820 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
2822 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
2824 if ($return) {
2825 return $output;
2826 } else {
2827 echo $output;
2832 * Given the path to a picture file in a course, or a URL,
2833 * this function includes the picture in the page.
2835 * @deprecated since Moodle 2.0
2837 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
2838 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
2842 * Print the specified user's avatar.
2844 * @deprecated since Moodle 2.0
2846 * @global object
2847 * @global object
2848 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
2849 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
2850 * if at all possible, particularly for reports. It is very bad for performance.
2851 * @param int $courseid The course id. Used when constructing the link to the user's profile.
2852 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
2853 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
2854 * @param boolean $return If false print picture to current page, otherwise return the output as string
2855 * @param boolean $link enclose printed image in a link the user's profile (default true).
2856 * @param string $target link target attribute. Makes the profile open in a popup window.
2857 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
2858 * decorative images, or where the username will be printed anyway.)
2859 * @return string|void String or nothing, depending on $return.
2861 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
2862 global $OUTPUT;
2864 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
2866 if (!is_object($user)) {
2867 $userid = $user;
2868 $user = new stdClass();
2869 $user->id = $userid;
2872 if (empty($user->picture) and $picture) {
2873 $user->picture = $picture;
2876 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
2878 $output = $OUTPUT->user_picture($user, $options);
2880 if ($return) {
2881 return $output;
2882 } else {
2883 echo $output;
2888 * Print a png image.
2890 * @deprecated since Moodle 2.0: no replacement
2893 function print_png() {
2894 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
2899 * Prints a basic textarea field.
2901 * @deprecated since Moodle 2.0
2903 * When using this function, you should
2905 * @global object
2906 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
2907 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
2908 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
2909 * @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.
2910 * @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.
2911 * @param string $name Name to use for the textarea element.
2912 * @param string $value Initial content to display in the textarea.
2913 * @param int $obsolete deprecated
2914 * @param bool $return If false, will output string. If true, will return string value.
2915 * @param string $id CSS ID to add to the textarea element.
2916 * @return string|void depending on the value of $return
2918 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
2919 /// $width and height are legacy fields and no longer used as pixels like they used to be.
2920 /// However, you can set them to zero to override the mincols and minrows values below.
2922 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
2923 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
2925 global $CFG;
2927 $mincols = 65;
2928 $minrows = 10;
2929 $str = '';
2931 if ($id === '') {
2932 $id = 'edit-'.$name;
2935 if ($usehtmleditor) {
2936 if ($height && ($rows < $minrows)) {
2937 $rows = $minrows;
2939 if ($width && ($cols < $mincols)) {
2940 $cols = $mincols;
2944 if ($usehtmleditor) {
2945 editors_head_setup();
2946 $editor = editors_get_preferred_editor(FORMAT_HTML);
2947 $editor->use_editor($id, array('legacy'=>true));
2948 } else {
2949 $editorclass = '';
2952 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
2953 if ($usehtmleditor) {
2954 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
2955 } else {
2956 $str .= s($value);
2958 $str .= '</textarea>'."\n";
2960 if ($return) {
2961 return $str;
2963 echo $str;
2968 * Print a help button.
2970 * @deprecated since Moodle 2.0
2972 * @param string $page The keyword that defines a help page
2973 * @param string $title The title of links, rollover tips, alt tags etc
2974 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
2975 * @param string $module Which module is the page defined in
2976 * @param mixed $image Use a help image for the link? (true/false/"both")
2977 * @param boolean $linktext If true, display the title next to the help icon.
2978 * @param string $text If defined then this text is used in the page, and
2979 * the $page variable is ignored. DEPRECATED!
2980 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
2981 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
2982 * @return string|void Depending on value of $return
2984 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
2985 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
2987 global $OUTPUT;
2989 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
2991 // hide image with CSS if needed
2993 if ($return) {
2994 return $output;
2995 } else {
2996 echo $output;
3001 * Print a help button.
3003 * Prints a special help button that is a link to the "live" emoticon popup
3005 * @todo Finish documenting this function
3007 * @global object
3008 * @global object
3009 * @param string $form ?
3010 * @param string $field ?
3011 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
3012 * @return string|void Depending on value of $return
3014 function emoticonhelpbutton($form, $field, $return = false) {
3015 /// TODO: MDL-21215
3017 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
3021 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
3022 * Should be used only with htmleditor or textarea.
3024 * @global object
3025 * @global object
3026 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
3027 * helpbutton.
3028 * @return string Link to help button
3030 function editorhelpbutton(){
3031 return '';
3033 /// TODO: MDL-21215
3037 * Print a help button.
3039 * Prints a special help button for html editors (htmlarea in this case)
3041 * @todo Write code into this function! detect current editor and print correct info
3042 * @global object
3043 * @return string Only returns an empty string at the moment
3045 function editorshortcutshelpbutton() {
3046 /// TODO: MDL-21215
3048 global $CFG;
3049 //TODO: detect current editor and print correct info
3050 /* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
3051 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
3053 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
3054 return '';
3059 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
3060 * provide this function with the language strings for sortasc and sortdesc.
3062 * @deprecated since Moodle 2.0
3064 * TODO migrate to outputlib
3065 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
3067 * @global object
3068 * @param string $direction 'up' or 'down'
3069 * @param string $strsort The language string used for the alt attribute of this image
3070 * @param bool $return Whether to print directly or return the html string
3071 * @return string|void depending on $return
3074 function print_arrow($direction='up', $strsort=null, $return=false) {
3075 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
3077 global $OUTPUT;
3079 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
3080 return null;
3083 $return = null;
3085 switch ($direction) {
3086 case 'up':
3087 $sortdir = 'asc';
3088 break;
3089 case 'down':
3090 $sortdir = 'desc';
3091 break;
3092 case 'move':
3093 $sortdir = 'asc';
3094 break;
3095 default:
3096 $sortdir = null;
3097 break;
3100 // Prepare language string
3101 $strsort = '';
3102 if (empty($strsort) && !empty($sortdir)) {
3103 $strsort = get_string('sort' . $sortdir, 'grades');
3106 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
3108 if ($return) {
3109 return $return;
3110 } else {
3111 echo $return;
3116 * Returns a string containing a link to the user documentation.
3117 * Also contains an icon by default. Shown to teachers and admin only.
3119 * @deprecated since Moodle 2.0
3121 * @global object
3122 * @param string $path The page link after doc root and language, no leading slash.
3123 * @param string $text The text to be displayed for the link
3124 * @param string $iconpath The path to the icon to be displayed
3125 * @return string Either the link or an empty string
3127 function doc_link($path='', $text='', $iconpath='ignored') {
3128 global $CFG, $OUTPUT;
3130 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
3132 if (empty($CFG->docroot)) {
3133 return '';
3136 return $OUTPUT->doc_link($path, $text);
3140 * Prints a single paging bar to provide access to other pages (usually in a search)
3142 * @deprecated since Moodle 2.0
3144 * @param int $totalcount Thetotal number of entries available to be paged through
3145 * @param int $page The page you are currently viewing
3146 * @param int $perpage The number of entries that should be shown per page
3147 * @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.
3148 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
3149 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
3150 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
3151 * @param bool $return whether to return an output string or echo now
3152 * @return bool|string depending on $result
3154 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
3155 global $OUTPUT;
3157 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
3159 if (empty($nocurr)) {
3160 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
3163 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
3164 $pagingbar->pagevar = $pagevar;
3165 $output = $OUTPUT->render($pagingbar);
3167 if ($return) {
3168 return $output;
3171 echo $output;
3172 return true;
3176 * Print a message along with "Yes" and "No" links for the user to continue.
3178 * @deprecated since Moodle 2.0
3180 * @global object
3181 * @param string $message The text to display
3182 * @param string $linkyes The link to take the user to if they choose "Yes"
3183 * @param string $linkno The link to take the user to if they choose "No"
3184 * @param string $optionyes The yes option to show on the notice
3185 * @param string $optionsno The no option to show
3186 * @param string $methodyes Form action method to use if yes [post, get]
3187 * @param string $methodno Form action method to use if no [post, get]
3188 * @return void Output is echo'd
3190 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
3192 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
3194 global $OUTPUT;
3196 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
3197 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
3199 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
3203 * Prints a scale menu (as part of an existing form) including help button
3204 * @deprecated since Moodle 2.0
3206 function print_scale_menu() {
3207 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
3211 * Given an array of values, output the HTML for a select element with those options.
3213 * @deprecated since Moodle 2.0
3215 * Normally, you only need to use the first few parameters.
3217 * @param array $options The options to offer. An array of the form
3218 * $options[{value}] = {text displayed for that option};
3219 * @param string $name the name of this form control, as in &lt;select name="..." ...
3220 * @param string $selected the option to select initially, default none.
3221 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
3222 * Set this to '' if you don't want a 'nothing is selected' option.
3223 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3224 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
3225 * @param boolean $return if false (the default) the the output is printed directly, If true, the
3226 * generated HTML is returned as a string.
3227 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
3228 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
3229 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
3230 * then a suitable one is constructed.
3231 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
3232 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
3233 * $listbox is an integer, that number is used for size instead.
3234 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
3235 * when $listbox display is enabled
3236 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
3237 * then a suitable one is constructed.
3238 * @return string|void If $return=true returns string, else echo's and returns void
3240 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
3241 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
3242 $id='', $listbox=false, $multiple=false, $class='') {
3244 global $OUTPUT;
3245 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
3247 if ($script) {
3248 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3250 $attributes = array();
3251 $attributes['disabled'] = $disabled ? 'disabled' : null;
3252 $attributes['tabindex'] = $tabindex ? $tabindex : null;
3253 $attributes['multiple'] = $multiple ? $multiple : null;
3254 $attributes['class'] = $class ? $class : null;
3255 $attributes['id'] = $id ? $id : null;
3257 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
3259 if ($return) {
3260 return $output;
3261 } else {
3262 echo $output;
3267 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
3268 * Other options like choose_from_menu.
3270 * @deprecated since Moodle 2.0
3272 * Calls {@link choose_from_menu()} with preset arguments
3273 * @see choose_from_menu()
3275 * @param string $name the name of this form control, as in &lt;select name="..." ...
3276 * @param string $selected the option to select initially, default none.
3277 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3278 * @param boolean $return Whether this function should return a string or output it (defaults to false)
3279 * @param boolean $disabled (defaults to false)
3280 * @param int $tabindex
3281 * @return string|void If $return=true returns string, else echo's and returns void
3283 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
3284 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
3285 global $OUTPUT;
3287 if ($script) {
3288 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3291 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
3293 if ($return) {
3294 return $output;
3295 } else {
3296 echo $output;
3301 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
3302 * including option headings with the first level.
3304 * @deprecated since Moodle 2.0
3306 * This function is very similar to {@link choose_from_menu_yesno()}
3307 * and {@link choose_from_menu()}
3309 * @todo Add datatype handling to make sure $options is an array
3311 * @param array $options An array of objects to choose from
3312 * @param string $name The XHTML field name
3313 * @param string $selected The value to select by default
3314 * @param string $nothing The label for the 'nothing is selected' option.
3315 * Defaults to get_string('choose').
3316 * @param string $script If not '', then this is added to the &lt;select> element
3317 * as an onchange handler.
3318 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
3319 * @param bool $return Whether this function should return a string or output
3320 * it (defaults to false)
3321 * @param bool $disabled Is the field disabled by default
3322 * @param int|string $tabindex Override the tabindex attribute [numeric]
3323 * @return string|void If $return=true returns string, else echo's and returns void
3325 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
3326 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
3328 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
3329 global $OUTPUT;
3333 * Prints a help button about a scale
3335 * @deprecated since Moodle 2.0
3337 * @global object
3338 * @param id $courseid
3339 * @param object $scale
3340 * @param boolean $return If set to true returns rather than echo's
3341 * @return string|bool Depending on value of $return
3343 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
3344 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
3345 global $OUTPUT;
3347 $output = $OUTPUT->help_icon_scale($courseid, $scale);
3349 if ($return) {
3350 return $output;
3351 } else {
3352 echo $output;
3358 * Prints time limit value selector
3360 * @deprecated since Moodle 2.0
3362 * Uses {@link choose_from_menu()} to generate HTML
3363 * @see choose_from_menu()
3365 * @global object
3366 * @param int $timelimit default
3367 * @param string $unit
3368 * @param string $name
3369 * @param boolean $return If set to true returns rather than echo's
3370 * @return string|bool Depending on value of $return
3372 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
3373 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
3377 * Prints form items with the names $hour and $minute
3379 * @deprecated since Moodle 2.0
3381 * @param string $hour fieldname
3382 * @param string $minute fieldname
3383 * @param int $currenttime A default timestamp in GMT
3384 * @param int $step minute spacing
3385 * @param boolean $return If set to true returns rather than echo's
3386 * @return string|bool Depending on value of $return
3388 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
3389 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
3391 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
3392 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
3394 $output = $hourselector . $$minuteselector;
3396 if ($return) {
3397 return $output;
3398 } else {
3399 echo $output;
3404 * Prints form items with the names $day, $month and $year
3406 * @deprecated since Moodle 2.0
3408 * @param string $day fieldname
3409 * @param string $month fieldname
3410 * @param string $year fieldname
3411 * @param int $currenttime A default timestamp in GMT
3412 * @param boolean $return If set to true returns rather than echo's
3413 * @return string|bool Depending on value of $return
3415 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
3416 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
3418 $dayselector = html_writer::select_time('days', $day, $currenttime);
3419 $monthselector = html_writer::select_time('months', $month, $currenttime);
3420 $yearselector = html_writer::select_time('years', $year, $currenttime);
3422 $output = $dayselector . $monthselector . $yearselector;
3424 if ($return) {
3425 return $output;
3426 } else {
3427 echo $output;
3432 * Implements a complete little form with a dropdown menu.
3434 * @deprecated since Moodle 2.0
3436 * When JavaScript is on selecting an option from the dropdown automatically
3437 * submits the form (while avoiding the usual acessibility problems with this appoach).
3438 * With JavaScript off, a 'Go' button is printed.
3440 * @global object
3441 * @global object
3442 * @param string $baseurl The target URL up to the point of the variable that changes
3443 * @param array $options A list of value-label pairs for the popup list
3444 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
3445 * @param string $selected The option that is initially selected
3446 * @param string $nothing The label for the "no choice" option
3447 * @param string $help The name of a help page if help is required
3448 * @param string $helptext The name of the label for the help button
3449 * @param boolean $return Indicates whether the function should return the HTML
3450 * as a string or echo it directly to the page being rendered
3451 * @param string $targetwindow The name of the target page to open the linked page in.
3452 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
3453 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
3454 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
3455 * @param boolean $disabled If true, the menu will be displayed disabled.
3456 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
3457 * @return string|void If $return=true returns string, else echo's and returns void
3459 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
3460 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
3461 global $OUTPUT, $CFG;
3463 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
3465 if (empty($options)) {
3466 return '';
3469 $urls = array();
3471 foreach ($options as $value=>$label) {
3472 $url = $baseurl.$value;
3473 $url = str_replace($CFG->wwwroot, '', $url);
3474 $url = str_replace('&amp;', '&', $url);
3475 $urls[$url] = $label;
3476 if ($selected == $value) {
3477 $active = $url;
3481 $nothing = $nothing ? array(''=>$nothing) : null;
3483 $select = new url_select($urls, $active, $nothing, $formid);
3484 $select->disabled = $disabled;
3486 $select->set_label($selectlabel);
3487 $select->set_old_help_icon($help, $helptext);
3489 $output = $OUTPUT->render($select);
3491 if ($return) {
3492 return $output;
3493 } else {
3494 echo $output;
3499 * Prints a simple button to close a window
3501 * @deprecated since Moodle 2.0
3503 * @global object
3504 * @param string $name Name of the window to close
3505 * @param boolean $return whether this function should return a string or output it.
3506 * @param boolean $reloadopener if true, clicking the button will also reload
3507 * the page that opend this popup window.
3508 * @return string|void if $return is true, void otherwise
3510 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
3511 global $OUTPUT;
3513 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
3514 $output = $OUTPUT->close_window_button(get_string($name));
3516 if ($return) {
3517 return $output;
3518 } else {
3519 echo $output;
3524 * Given an array of values, creates a group of radio buttons to be part of a form
3526 * @deprecated since Moodle 2.0
3528 * @staticvar int $idcounter
3529 * @param array $options An array of value-label pairs for the radio group (values as keys)
3530 * @param string $name Name of the radiogroup (unique in the form)
3531 * @param string $checked The value that is already checked
3532 * @param bool $return Whether this function should return a string or output
3533 * it (defaults to false)
3534 * @return string|void If $return=true returns string, else echo's and returns void
3536 function choose_from_radio ($options, $name, $checked='', $return=false) {
3537 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
3541 * Display an standard html checkbox with an optional label
3543 * @deprecated since Moodle 2.0
3545 * @staticvar int $idcounter
3546 * @param string $name The name of the checkbox
3547 * @param string $value The valus that the checkbox will pass when checked
3548 * @param bool $checked The flag to tell the checkbox initial state
3549 * @param string $label The label to be showed near the checkbox
3550 * @param string $alt The info to be inserted in the alt tag
3551 * @param string $script If not '', then this is added to the checkbox element
3552 * as an onchange handler.
3553 * @param bool $return Whether this function should return a string or output
3554 * it (defaults to false)
3555 * @return string|void If $return=true returns string, else echo's and returns void
3557 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
3559 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
3560 global $OUTPUT;
3562 if (!empty($script)) {
3563 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
3566 $output = html_writer::checkbox($name, $value, $checked, $label);
3568 if (empty($return)) {
3569 echo $output;
3570 } else {
3571 return $output;
3578 * Display an standard html text field with an optional label
3580 * @deprecated since Moodle 2.0
3582 * @param string $name The name of the text field
3583 * @param string $value The value of the text field
3584 * @param string $alt The info to be inserted in the alt tag
3585 * @param int $size Sets the size attribute of the field. Defaults to 50
3586 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
3587 * @param bool $return Whether this function should return a string or output
3588 * it (defaults to false)
3589 * @return string|void If $return=true returns string, else echo's and returns void
3591 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
3592 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
3594 if ($alt === '') {
3595 $alt = null;
3598 $style = "width: {$size}px;";
3599 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
3600 if ($maxlength) {
3601 $attributes['maxlength'] = $maxlength;
3604 $output = html_writer::empty_tag('input', $attributes);
3606 if (empty($return)) {
3607 echo $output;
3608 } else {
3609 return $output;
3615 * Centered heading with attached help button (same title text)
3616 * and optional icon attached
3618 * @deprecated since Moodle 2.0
3620 * @param string $text The text to be displayed
3621 * @param string $helppage The help page to link to
3622 * @param string $module The module whose help should be linked to
3623 * @param string $icon Image to display if needed
3624 * @param bool $return If set to true output is returned rather than echoed, default false
3625 * @return string|void String if return=true nothing otherwise
3627 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
3629 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
3631 global $OUTPUT;
3633 // Extract the src from $icon if it exists
3634 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
3635 $icon = $matches[1];
3636 $icon = new moodle_url($icon);
3637 } else {
3638 $icon = '';
3641 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
3643 if ($return) {
3644 return $output;
3645 } else {
3646 echo $output;
3651 * Returns a turn edit on/off button for course in a self contained form.
3652 * Used to be an icon, but it's now a simple form button
3653 * @deprecated since Moodle 2.0
3655 function update_mymoodle_icon() {
3656 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
3660 * Returns a turn edit on/off button for tag in a self contained form.
3661 * @deprecated since Moodle 2.0
3662 * @param string $tagid The ID attribute
3663 * @return string
3665 function update_tag_button($tagid) {
3666 global $OUTPUT;
3667 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3668 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
3673 * Prints the 'update this xxx' button that appears on module pages.
3675 * @deprecated since Moodle 2.0
3677 * @param string $cmid the course_module id.
3678 * @param string $ignored not used any more. (Used to be courseid.)
3679 * @param string $string the module name - get_string('modulename', 'xxx')
3680 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
3682 function update_module_button($cmid, $ignored, $string) {
3683 global $CFG, $OUTPUT;
3685 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
3687 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
3689 if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
3690 $string = get_string('updatethis', '', $string);
3692 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
3693 return $OUTPUT->single_button($url, $string);
3694 } else {
3695 return '';
3700 * Prints the editing button on search results listing
3701 * For bulk move courses to another category
3702 * @deprecated since Moodle 2.0
3704 function update_categories_search_button($search,$page,$perpage) {
3705 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
3709 * Prints a summary of a user in a nice little box.
3710 * @deprecated since Moodle 2.0
3712 function print_user($user, $course, $messageselect=false, $return=false) {
3713 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
3717 * Returns a turn edit on/off button for course in a self contained form.
3718 * Used to be an icon, but it's now a simple form button
3720 * Note that the caller is responsible for capchecks.
3722 * @global object
3723 * @global object
3724 * @param int $courseid The course to update by id as found in 'course' table
3725 * @return string
3727 function update_course_icon($courseid) {
3728 global $CFG, $OUTPUT;
3730 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3732 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
3736 * Prints breadcrumb trail of links, called in theme/-/header.html
3738 * This function has now been deprecated please use output's navbar method instead
3739 * as shown below
3741 * <code php>
3742 * echo $OUTPUT->navbar();
3743 * </code>
3745 * @deprecated since 2.0
3746 * @param mixed $navigation deprecated
3747 * @param string $separator OBSOLETE, and now deprecated
3748 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
3749 * @return string|void String or null, depending on $return.
3751 function print_navigation ($navigation, $separator=0, $return=false) {
3752 global $OUTPUT,$PAGE;
3754 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
3756 $output = $OUTPUT->navbar();
3758 if ($return) {
3759 return $output;
3760 } else {
3761 echo $output;
3766 * This function will build the navigation string to be used by print_header
3767 * and others.
3769 * It automatically generates the site and course level (if appropriate) links.
3771 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
3772 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
3774 * If you want to add any further navigation links after the ones this function generates,
3775 * the pass an array of extra link arrays like this:
3776 * array(
3777 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
3778 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
3780 * The normal case is to just add one further link, for example 'Editing forum' after
3781 * 'General Developer Forum', with no link.
3782 * To do that, you need to pass
3783 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
3784 * However, becuase this is a very common case, you can use a shortcut syntax, and just
3785 * pass the string 'Editing forum', instead of an array as $extranavlinks.
3787 * At the moment, the link types only have limited significance. Type 'activity' is
3788 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
3789 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
3790 * This really needs to be documented better. In the mean time, try to be consistent, it will
3791 * enable people to customise the navigation more in future.
3793 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
3794 * If you get the $cm object using the function get_coursemodule_from_instance or
3795 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
3796 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
3797 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
3798 * warning is printed in developer debug mode.
3800 * @deprecated since 2.0
3801 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
3802 * only want one extra item with no link, you can pass a string instead. If you don't want
3803 * any extra links, pass an empty string.
3804 * @param mixed $cm deprecated
3805 * @return array Navigation array
3807 function build_navigation($extranavlinks, $cm = null) {
3808 global $CFG, $COURSE, $DB, $SITE, $PAGE;
3810 if (is_array($extranavlinks) && count($extranavlinks)>0) {
3811 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
3812 foreach ($extranavlinks as $nav) {
3813 if (array_key_exists('name', $nav)) {
3814 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
3815 $link = $nav['link'];
3816 } else {
3817 $link = null;
3819 $PAGE->navbar->add($nav['name'],$link);
3824 return(array('newnav' => true, 'navlinks' => array()));
3828 * Returns a small popup menu of course activity modules
3830 * Given a course and a (current) coursemodule
3831 * his function returns a small popup menu with all the
3832 * course activity modules in it, as a navigation menu
3833 * The data is taken from the serialised array stored in
3834 * the course record
3836 * @global object
3837 * @global object
3838 * @global object
3839 * @global object
3840 * @uses CONTEXT_COURSE
3841 * @param object $course A {@link $COURSE} object.
3842 * @param object $cm A {@link $COURSE} object.
3843 * @param string $targetwindow The target window attribute to us
3844 * @return string
3846 function navmenu($course, $cm=NULL, $targetwindow='self') {
3847 // This function has been deprecated with the creation of the global nav in
3848 // moodle 2.0
3850 return '';
3854 * Returns a little popup menu for switching roles
3856 * @deprecated in Moodle 2.0
3857 * @param int $courseid The course to update by id as found in 'course' table
3858 * @return string
3860 function switchroles_form($courseid) {
3861 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
3862 return '';
3866 * Print header for admin page
3867 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
3868 * @param string $focus focus element
3870 function admin_externalpage_print_header($focus='') {
3871 global $OUTPUT;
3873 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
3875 echo $OUTPUT->header();
3879 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
3881 function admin_externalpage_print_footer() {
3882 // TODO Still 103 referernces in core code. Don't do debugging output yet.
3883 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
3884 global $OUTPUT;
3885 echo $OUTPUT->footer();
3888 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
3892 * Call this function to add an event to the calendar table and to call any calendar plugins
3894 * @param object $event An object representing an event from the calendar table.
3895 * The event will be identified by the id field. The object event should include the following:
3896 * <ul>
3897 * <li><b>$event->name</b> - Name for the event
3898 * <li><b>$event->description</b> - Description of the event (defaults to '')
3899 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
3900 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
3901 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
3902 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
3903 * <li><b>$event->modulename</b> - Name of the module that creates this event
3904 * <li><b>$event->instance</b> - Instance of the module that owns this event
3905 * <li><b>$event->eventtype</b> - The type info together with the module info could
3906 * be used by calendar plugins to decide how to display event
3907 * <li><b>$event->timestart</b>- Timestamp for start of event
3908 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
3909 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
3910 * </ul>
3911 * @return int|false The id number of the resulting record or false if failed
3913 function add_event($event) {
3914 global $CFG;
3915 require_once($CFG->dirroot.'/calendar/lib.php');
3916 $event = calendar_event::create($event);
3917 if ($event !== false) {
3918 return $event->id;
3920 return false;
3924 * Call this function to update an event in the calendar table
3925 * the event will be identified by the id field of the $event object.
3927 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3928 * @return bool Success
3930 function update_event($event) {
3931 global $CFG;
3932 require_once($CFG->dirroot.'/calendar/lib.php');
3933 $event = (object)$event;
3934 $calendarevent = calendar_event::load($event->id);
3935 return $calendarevent->update($event);
3939 * Call this function to delete the event with id $id from calendar table.
3941 * @param int $id The id of an event from the 'event' table.
3942 * @return bool
3944 function delete_event($id) {
3945 global $CFG;
3946 require_once($CFG->dirroot.'/calendar/lib.php');
3947 $event = calendar_event::load($id);
3948 return $event->delete();
3952 * Call this function to hide an event in the calendar table
3953 * the event will be identified by the id field of the $event object.
3955 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3956 * @return true
3958 function hide_event($event) {
3959 global $CFG;
3960 require_once($CFG->dirroot.'/calendar/lib.php');
3961 $event = new calendar_event($event);
3962 return $event->toggle_visibility(false);
3966 * Call this function to unhide an event in the calendar table
3967 * the event will be identified by the id field of the $event object.
3969 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3970 * @return true
3972 function show_event($event) {
3973 global $CFG;
3974 require_once($CFG->dirroot.'/calendar/lib.php');
3975 $event = new calendar_event($event);
3976 return $event->toggle_visibility(true);