NOMDL fixed typo in variable name
[moodle.git] / lib / deprecatedlib.php
blob15da1f93ed6b9988bd4b52c4eb4d38eb0ccb2e33
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 * deprecated - use clean_param($string, PARAM_FILE); instead
539 * Check for bad characters ?
541 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
543 * @param string $string ?
544 * @param int $allowdots ?
545 * @return bool
547 function detect_munged_arguments($string, $allowdots=1) {
548 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
549 return true;
551 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
552 return true;
554 if (empty($string) or $string == '/') {
555 return true;
558 return false;
563 * Unzip one zip file to a destination dir
564 * Both parameters must be FULL paths
565 * If destination isn't specified, it will be the
566 * SAME directory where the zip file resides.
568 * @global object
569 * @param string $zipfile The zip file to unzip
570 * @param string $destination The location to unzip to
571 * @param bool $showstatus_ignored Unused
573 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
574 global $CFG;
576 //Extract everything from zipfile
577 $path_parts = pathinfo(cleardoubleslashes($zipfile));
578 $zippath = $path_parts["dirname"]; //The path of the zip file
579 $zipfilename = $path_parts["basename"]; //The name of the zip file
580 $extension = $path_parts["extension"]; //The extension of the file
582 //If no file, error
583 if (empty($zipfilename)) {
584 return false;
587 //If no extension, error
588 if (empty($extension)) {
589 return false;
592 //Clear $zipfile
593 $zipfile = cleardoubleslashes($zipfile);
595 //Check zipfile exists
596 if (!file_exists($zipfile)) {
597 return false;
600 //If no destination, passed let's go with the same directory
601 if (empty($destination)) {
602 $destination = $zippath;
605 //Clear $destination
606 $destpath = rtrim(cleardoubleslashes($destination), "/");
608 //Check destination path exists
609 if (!is_dir($destpath)) {
610 return false;
613 $packer = get_file_packer('application/zip');
615 $result = $packer->extract_to_pathname($zipfile, $destpath);
617 if ($result === false) {
618 return false;
621 foreach ($result as $status) {
622 if ($status !== true) {
623 return false;
627 return true;
631 * Zip an array of files/dirs to a destination zip file
632 * Both parameters must be FULL paths to the files/dirs
634 * @global object
635 * @param array $originalfiles Files to zip
636 * @param string $destination The destination path
637 * @return bool Outcome
639 function zip_files ($originalfiles, $destination) {
640 global $CFG;
642 //Extract everything from destination
643 $path_parts = pathinfo(cleardoubleslashes($destination));
644 $destpath = $path_parts["dirname"]; //The path of the zip file
645 $destfilename = $path_parts["basename"]; //The name of the zip file
646 $extension = $path_parts["extension"]; //The extension of the file
648 //If no file, error
649 if (empty($destfilename)) {
650 return false;
653 //If no extension, add it
654 if (empty($extension)) {
655 $extension = 'zip';
656 $destfilename = $destfilename.'.'.$extension;
659 //Check destination path exists
660 if (!is_dir($destpath)) {
661 return false;
664 //Check destination path is writable. TODO!!
666 //Clean destination filename
667 $destfilename = clean_filename($destfilename);
669 //Now check and prepare every file
670 $files = array();
671 $origpath = NULL;
673 foreach ($originalfiles as $file) { //Iterate over each file
674 //Check for every file
675 $tempfile = cleardoubleslashes($file); // no doubleslashes!
676 //Calculate the base path for all files if it isn't set
677 if ($origpath === NULL) {
678 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
680 //See if the file is readable
681 if (!is_readable($tempfile)) { //Is readable
682 continue;
684 //See if the file/dir is in the same directory than the rest
685 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
686 continue;
688 //Add the file to the array
689 $files[] = $tempfile;
692 $zipfiles = array();
693 $start = strlen($origpath)+1;
694 foreach($files as $file) {
695 $zipfiles[substr($file, $start)] = $file;
698 $packer = get_file_packer('application/zip');
700 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
703 /////////////////////////////////////////////////////////////
704 /// Old functions not used anymore - candidates for removal
705 /////////////////////////////////////////////////////////////
708 /** various deprecated groups function **/
712 * Get the IDs for the user's groups in the given course.
714 * @global object
715 * @param int $courseid The course being examined - the 'course' table id field.
716 * @return array|bool An _array_ of groupids, or false
717 * (Was return $groupids[0] - consequences!)
719 function mygroupid($courseid) {
720 global $USER;
721 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
722 return array_keys($groups);
723 } else {
724 return false;
730 * Returns the current group mode for a given course or activity module
732 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
734 * @param object $course Course Object
735 * @param object $cm Course Manager Object
736 * @return mixed $course->groupmode
738 function groupmode($course, $cm=null) {
740 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
741 return $cm->groupmode;
743 return $course->groupmode;
747 * Sets the current group in the session variable
748 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
749 * Sets currentgroup[$courseid] in the session variable appropriately.
750 * Does not do any permission checking.
752 * @global object
753 * @param int $courseid The course being examined - relates to id field in
754 * 'course' table.
755 * @param int $groupid The group being examined.
756 * @return int Current group id which was set by this function
758 function set_current_group($courseid, $groupid) {
759 global $SESSION;
760 return $SESSION->currentgroup[$courseid] = $groupid;
765 * Gets the current group - either from the session variable or from the database.
767 * @global object
768 * @param int $courseid The course being examined - relates to id field in
769 * 'course' table.
770 * @param bool $full If true, the return value is a full record object.
771 * If false, just the id of the record.
772 * @return int|bool
774 function get_current_group($courseid, $full = false) {
775 global $SESSION;
777 if (isset($SESSION->currentgroup[$courseid])) {
778 if ($full) {
779 return groups_get_group($SESSION->currentgroup[$courseid]);
780 } else {
781 return $SESSION->currentgroup[$courseid];
785 $mygroupid = mygroupid($courseid);
786 if (is_array($mygroupid)) {
787 $mygroupid = array_shift($mygroupid);
788 set_current_group($courseid, $mygroupid);
789 if ($full) {
790 return groups_get_group($mygroupid);
791 } else {
792 return $mygroupid;
796 if ($full) {
797 return false;
798 } else {
799 return 0;
805 * Inndicates fatal error. This function was originally printing the
806 * error message directly, since 2.0 it is throwing exception instead.
807 * The error printing is handled in default exception handler.
809 * Old method, don't call directly in new code - use print_error instead.
811 * @param string $message The message to display to the user about the error.
812 * @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.
813 * @return void, always throws moodle_exception
815 function error($message, $link='') {
816 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
820 /// Deprecated DDL functions, to be removed soon ///
822 * @deprecated
823 * @global object
824 * @param string $table
825 * @return bool
827 function table_exists($table) {
828 global $DB;
829 debugging('Deprecated ddllib function used!');
830 return $DB->get_manager()->table_exists($table);
834 * @deprecated
835 * @global object
836 * @param string $table
837 * @param string $field
838 * @return bool
840 function field_exists($table, $field) {
841 global $DB;
842 debugging('Deprecated ddllib function used!');
843 return $DB->get_manager()->field_exists($table, $field);
847 * @deprecated
848 * @global object
849 * @param string $table
850 * @param string $index
851 * @return bool
853 function find_index_name($table, $index) {
854 global $DB;
855 debugging('Deprecated ddllib function used!');
856 return $DB->get_manager()->find_index_name($table, $index);
860 * @deprecated
861 * @global object
862 * @param string $table
863 * @param string $index
864 * @return bool
866 function index_exists($table, $index) {
867 global $DB;
868 debugging('Deprecated ddllib function used!');
869 return $DB->get_manager()->index_exists($table, $index);
873 * @deprecated
874 * @global object
875 * @param string $table
876 * @param string $field
877 * @return bool
879 function find_check_constraint_name($table, $field) {
880 global $DB;
881 debugging('Deprecated ddllib function used!');
882 return $DB->get_manager()->find_check_constraint_name($table, $field);
886 * @deprecated
887 * @global object
889 function check_constraint_exists($table, $field) {
890 global $DB;
891 debugging('Deprecated ddllib function used!');
892 return $DB->get_manager()->check_constraint_exists($table, $field);
896 * @deprecated
897 * @global object
898 * @param string $table
899 * @param string $xmldb_key
900 * @return bool
902 function find_key_name($table, $xmldb_key) {
903 global $DB;
904 debugging('Deprecated ddllib function used!');
905 return $DB->get_manager()->find_key_name($table, $xmldb_key);
909 * @deprecated
910 * @global object
911 * @param string $table
912 * @return bool
914 function drop_table($table) {
915 global $DB;
916 debugging('Deprecated ddllib function used!');
917 $DB->get_manager()->drop_table($table);
918 return true;
922 * @deprecated
923 * @global object
924 * @param string $file
925 * @return bool
927 function install_from_xmldb_file($file) {
928 global $DB;
929 debugging('Deprecated ddllib function used!');
930 $DB->get_manager()->install_from_xmldb_file($file);
931 return true;
935 * @deprecated
936 * @global object
937 * @param string $table
938 * @return bool
940 function create_table($table) {
941 global $DB;
942 debugging('Deprecated ddllib function used!');
943 $DB->get_manager()->create_table($table);
944 return true;
948 * @deprecated
949 * @global object
950 * @param string $table
951 * @return bool
953 function create_temp_table($table) {
954 global $DB;
955 debugging('Deprecated ddllib function used!');
956 $DB->get_manager()->create_temp_table($table);
957 return true;
961 * @deprecated
962 * @global object
963 * @param string $table
964 * @param string $newname
965 * @return bool
967 function rename_table($table, $newname) {
968 global $DB;
969 debugging('Deprecated ddllib function used!');
970 $DB->get_manager()->rename_table($table, $newname);
971 return true;
975 * @deprecated
976 * @global object
977 * @param string $table
978 * @param string $field
979 * @return bool
981 function add_field($table, $field) {
982 global $DB;
983 debugging('Deprecated ddllib function used!');
984 $DB->get_manager()->add_field($table, $field);
985 return true;
989 * @deprecated
990 * @global object
991 * @param string $table
992 * @param string $field
993 * @return bool
995 function drop_field($table, $field) {
996 global $DB;
997 debugging('Deprecated ddllib function used!');
998 $DB->get_manager()->drop_field($table, $field);
999 return true;
1003 * @deprecated
1004 * @global object
1005 * @param string $table
1006 * @param string $field
1007 * @return bool
1009 function change_field_type($table, $field) {
1010 global $DB;
1011 debugging('Deprecated ddllib function used!');
1012 $DB->get_manager()->change_field_type($table, $field);
1013 return true;
1017 * @deprecated
1018 * @global object
1019 * @param string $table
1020 * @param string $field
1021 * @return bool
1023 function change_field_precision($table, $field) {
1024 global $DB;
1025 debugging('Deprecated ddllib function used!');
1026 $DB->get_manager()->change_field_precision($table, $field);
1027 return true;
1031 * @deprecated
1032 * @global object
1033 * @param string $table
1034 * @param string $field
1035 * @return bool
1037 function change_field_unsigned($table, $field) {
1038 global $DB;
1039 debugging('Deprecated ddllib function used!');
1040 $DB->get_manager()->change_field_unsigned($table, $field);
1041 return true;
1045 * @deprecated
1046 * @global object
1047 * @param string $table
1048 * @param string $field
1049 * @return bool
1051 function change_field_notnull($table, $field) {
1052 global $DB;
1053 debugging('Deprecated ddllib function used!');
1054 $DB->get_manager()->change_field_notnull($table, $field);
1055 return true;
1059 * @deprecated
1060 * @global object
1061 * @param string $table
1062 * @param string $field
1063 * @return bool
1065 function change_field_enum($table, $field) {
1066 global $DB;
1067 debugging('Deprecated ddllib function used! Only dropping of enums is allowed.');
1068 $DB->get_manager()->drop_enum_from_field($table, $field);
1069 return true;
1073 * @deprecated
1074 * @global object
1075 * @param string $table
1076 * @param string $field
1077 * @return bool
1079 function change_field_default($table, $field) {
1080 global $DB;
1081 debugging('Deprecated ddllib function used!');
1082 $DB->get_manager()->change_field_default($table, $field);
1083 return true;
1087 * @deprecated
1088 * @global object
1089 * @param string $table
1090 * @param string $field
1091 * @param string $newname
1092 * @return bool
1094 function rename_field($table, $field, $newname) {
1095 global $DB;
1096 debugging('Deprecated ddllib function used!');
1097 $DB->get_manager()->rename_field($table, $field, $newname);
1098 return true;
1102 * @deprecated
1103 * @global object
1104 * @param string $table
1105 * @param string $key
1106 * @return bool
1108 function add_key($table, $key) {
1109 global $DB;
1110 debugging('Deprecated ddllib function used!');
1111 $DB->get_manager()->add_key($table, $key);
1112 return true;
1116 * @deprecated
1117 * @global object
1118 * @param string $table
1119 * @param string $key
1120 * @return bool
1122 function drop_key($table, $key) {
1123 global $DB;
1124 debugging('Deprecated ddllib function used!');
1125 $DB->get_manager()->drop_key($table, $key);
1126 return true;
1130 * @deprecated
1131 * @global object
1132 * @param string $table
1133 * @param string $key
1134 * @param string $newname
1135 * @return bool
1137 function rename_key($table, $key, $newname) {
1138 global $DB;
1139 debugging('Deprecated ddllib function used!');
1140 $DB->get_manager()->rename_key($table, $key, $newname);
1141 return true;
1145 * @deprecated
1146 * @global object
1147 * @param string $table
1148 * @param string $index
1149 * @return bool
1151 function add_index($table, $index) {
1152 global $DB;
1153 debugging('Deprecated ddllib function used!');
1154 $DB->get_manager()->add_index($table, $index);
1155 return true;
1159 * @deprecated
1160 * @global object
1161 * @param string $table
1162 * @param string $index
1163 * @return bool
1165 function drop_index($table, $index) {
1166 global $DB;
1167 debugging('Deprecated ddllib function used!');
1168 $DB->get_manager()->drop_index($table, $index);
1169 return true;
1173 * @deprecated
1174 * @global object
1175 * @param string $table
1176 * @param string $index
1177 * @param string $newname
1178 * @return bool
1180 function rename_index($table, $index, $newname) {
1181 global $DB;
1182 debugging('Deprecated ddllib function used!');
1183 $DB->get_manager()->rename_index($table, $index, $newname);
1184 return true;
1188 //////////////////////////
1189 /// removed functions ////
1190 //////////////////////////
1193 * @deprecated
1194 * @param mixed $mixed
1195 * @return void Throws an error and does nothing
1197 function stripslashes_safe($mixed) {
1198 error('stripslashes_safe() not available anymore');
1201 * @deprecated
1202 * @param mixed $var
1203 * @return void Throws an error and does nothing
1205 function stripslashes_recursive($var) {
1206 error('stripslashes_recursive() not available anymore');
1209 * @deprecated
1210 * @param mixed $dataobject
1211 * @return void Throws an error and does nothing
1213 function addslashes_object($dataobject) {
1214 error('addslashes_object() not available anymore');
1217 * @deprecated
1218 * @param mixed $var
1219 * @return void Throws an error and does nothing
1221 function addslashes_recursive($var) {
1222 error('addslashes_recursive() not available anymore');
1225 * @deprecated
1226 * @param mixed $command
1227 * @param bool $feedback
1228 * @return void Throws an error and does nothing
1230 function execute_sql($command, $feedback=true) {
1231 error('execute_sql() not available anymore');
1234 * @deprecated
1235 * @param mixed $table
1236 * @param mixed $select
1237 * @return void Throws an error and does nothing
1239 function record_exists_select($table, $select='') {
1240 error('record_exists_select() not available anymore');
1243 * @deprecated
1244 * @param mixed $sql
1245 * @return void Throws an error and does nothing
1247 function record_exists_sql($sql) {
1248 error('record_exists_sql() not available anymore');
1251 * @deprecated
1252 * @param mixed $table
1253 * @param mixed $select
1254 * @param mixed $countitem
1255 * @return void Throws an error and does nothing
1257 function count_records_select($table, $select='', $countitem='COUNT(*)') {
1258 error('count_records_select() not available anymore');
1261 * @deprecated
1262 * @param mixed $sql
1263 * @return void Throws an error and does nothing
1265 function count_records_sql($sql) {
1266 error('count_records_sql() not available anymore');
1269 * @deprecated
1270 * @param mixed $sql
1271 * @param bool $expectmultiple
1272 * @param bool $nolimit
1273 * @return void Throws an error and does nothing
1275 function get_record_sql($sql, $expectmultiple=false, $nolimit=false) {
1276 error('get_record_sql() not available anymore');
1279 * @deprecated
1280 * @param mixed $table
1281 * @param mixed $select
1282 * @param mixed $fields
1283 * @return void Throws an error and does nothing
1285 function get_record_select($table, $select='', $fields='*') {
1286 error('get_record_select() not available anymore');
1289 * @deprecated
1290 * @param mixed $table
1291 * @param mixed $field
1292 * @param mixed $value
1293 * @param mixed $sort
1294 * @param mixed $fields
1295 * @param mixed $limitfrom
1296 * @param mixed $limitnum
1297 * @return void Throws an error and does nothing
1299 function get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1300 error('get_recordset() not available anymore');
1303 * @deprecated
1304 * @param mixed $sql
1305 * @param mixed $limitfrom
1306 * @param mixed $limitnum
1307 * @return void Throws an error and does nothing
1309 function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) {
1310 error('get_recordset_sql() not available anymore');
1313 * @deprecated
1314 * @param mixed $rs
1315 * @return void Throws an error and does nothing
1317 function rs_fetch_record(&$rs) {
1318 error('rs_fetch_record() not available anymore');
1321 * @deprecated
1322 * @param mixed $rs
1323 * @return void Throws an error and does nothing
1325 function rs_next_record(&$rs) {
1326 error('rs_next_record() not available anymore');
1329 * @deprecated
1330 * @param mixed $rs
1331 * @return void Throws an error and does nothing
1333 function rs_fetch_next_record(&$rs) {
1334 error('rs_fetch_next_record() not available anymore');
1337 * @deprecated
1338 * @param mixed $rs
1339 * @return void Throws an error and does nothing
1341 function rs_EOF($rs) {
1342 error('rs_EOF() not available anymore');
1345 * @deprecated
1346 * @param mixed $rs
1347 * @return void Throws an error and does nothing
1349 function rs_close(&$rs) {
1350 error('rs_close() not available anymore');
1353 * @deprecated
1354 * @param mixed $table
1355 * @param mixed $select
1356 * @param mixed $sort
1357 * @param mixed $fields
1358 * @param mixed $limitfrom
1359 * @param mixed $limitnum
1360 * @return void Throws an error and does nothing
1362 function get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1363 error('get_records_select() not available anymore');
1366 * @deprecated
1367 * @param mixed $table
1368 * @param mixed $return
1369 * @param mixed $select
1370 * @return void Throws an error and does nothing
1372 function get_field_select($table, $return, $select) {
1373 error('get_field_select() not available anymore');
1376 * @deprecated
1377 * @param mixed $sql
1378 * @return void Throws an error and does nothing
1380 function get_field_sql($sql) {
1381 error('get_field_sql() not available anymore');
1384 * @deprecated
1385 * @param mixed $sql
1386 * @param mixed $select
1387 * @return void Throws an error and does nothing
1389 function delete_records_select($table, $select='') {
1390 error('get_field_sql() not available anymore');
1393 * @deprecated
1394 * @return void Throws an error and does nothing
1396 function configure_dbconnection() {
1397 error('configure_dbconnection() removed');
1400 * @deprecated
1401 * @param mixed $field
1402 * @return void Throws an error and does nothing
1404 function sql_max($field) {
1405 error('sql_max() removed - use normal sql MAX() instead');
1408 * @deprecated
1409 * @return void Throws an error and does nothing
1411 function sql_as() {
1412 error('sql_as() removed - do not use AS for tables at all');
1415 * @deprecated
1416 * @param mixed $page
1417 * @param mixed $recordsperpage
1418 * @return void Throws an error and does nothing
1420 function sql_paging_limit($page, $recordsperpage) {
1421 error('Function sql_paging_limit() is deprecated. Replace it with the correct use of limitfrom, limitnum parameters');
1424 * @deprecated
1425 * @return void Throws an error and does nothing
1427 function db_uppercase() {
1428 error('upper() removed - use normal sql UPPER()');
1431 * @deprecated
1432 * @return void Throws an error and does nothing
1434 function db_lowercase() {
1435 error('upper() removed - use normal sql LOWER()');
1438 * @deprecated
1439 * @param mixed $sqlfile
1440 * @param mixed $sqlstring
1441 * @return void Throws an error and does nothing
1443 function modify_database($sqlfile='', $sqlstring='') {
1444 error('modify_database() removed - use new XMLDB functions');
1447 * @deprecated
1448 * @param mixed $field1
1449 * @param mixed $value1
1450 * @param mixed $field2
1451 * @param mixed $value2
1452 * @param mixed $field3
1453 * @param mixed $value3
1454 * @return void Throws an error and does nothing
1456 function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1457 error('where_clause() removed - use new functions with $conditions parameter');
1460 * @deprecated
1461 * @param mixed $sqlarr
1462 * @param mixed $continue
1463 * @param mixed $feedback
1464 * @return void Throws an error and does nothing
1466 function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
1467 error('execute_sql_arr() removed');
1470 * @deprecated
1471 * @param mixed $table
1472 * @param mixed $field
1473 * @param mixed $values
1474 * @param mixed $sort
1475 * @param mixed $fields
1476 * @param mixed $limitfrom
1477 * @param mixed $limitnum
1478 * @return void Throws an error and does nothing
1480 function get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1481 error('get_records_list() removed');
1484 * @deprecated
1485 * @param mixed $table
1486 * @param mixed $field
1487 * @param mixed $values
1488 * @param mixed $sort
1489 * @param mixed $fields
1490 * @param mixed $limitfrom
1491 * @param mixed $limitnum
1492 * @return void Throws an error and does nothing
1494 function get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1495 error('get_recordset_list() removed');
1498 * @deprecated
1499 * @param mixed $table
1500 * @param mixed $field
1501 * @param mixed $value
1502 * @param mixed $sort
1503 * @param mixed $fields
1504 * @param mixed $limitfrom
1505 * @param mixed $limitnum
1506 * @return void Throws an error and does nothing
1508 function get_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1509 error('get_records_menu() removed');
1512 * @deprecated
1513 * @param mixed $table
1514 * @param mixed $select
1515 * @param mixed $sort
1516 * @param mixed $fields
1517 * @param mixed $limitfrom
1518 * @param mixed $limitnum
1519 * @return void Throws an error and does nothing
1521 function get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1522 error('get_records_select_menu() removed');
1525 * @deprecated
1526 * @param mixed $sql
1527 * @param mixed $limitfrom
1528 * @param mixed $limitnum
1529 * @return void Throws an error and does nothing
1531 function get_records_sql_menu($sql, $limitfrom='', $limitnum='') {
1532 error('get_records_sql_menu() removed');
1535 * @deprecated
1536 * @param mixed $table
1537 * @param mixed $column
1538 * @return void Throws an error and does nothing
1540 function column_type($table, $column) {
1541 error('column_type() removed');
1544 * @deprecated
1545 * @param mixed $rs
1546 * @return void Throws an error and does nothing
1548 function recordset_to_menu($rs) {
1549 error('recordset_to_menu() removed');
1552 * @deprecated
1553 * @param mixed $records
1554 * @param mixed $field1
1555 * @param mixed $field2
1556 * @return void Throws an error and does nothing
1558 function records_to_menu($records, $field1, $field2) {
1559 error('records_to_menu() removed');
1562 * @deprecated
1563 * @param mixed $table
1564 * @param mixed $newfield
1565 * @param mixed $newvalue
1566 * @param mixed $select
1567 * @param mixed $localcall
1568 * @return void Throws an error and does nothing
1570 function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) {
1571 error('set_field_select() removed');
1574 * @deprecated
1575 * @param mixed $table
1576 * @param mixed $return
1577 * @param mixed $select
1578 * @return void Throws an error and does nothing
1580 function get_fieldset_select($table, $return, $select) {
1581 error('get_fieldset_select() removed');
1584 * @deprecated
1585 * @param mixed $sql
1586 * @return void Throws an error and does nothing
1588 function get_fieldset_sql($sql) {
1589 error('get_fieldset_sql() removed');
1592 * @deprecated
1593 * @return void Throws an error and does nothing
1595 function sql_ilike() {
1596 error('sql_ilike() not available anymore');
1599 * @deprecated
1600 * @param mixed $first
1601 * @param mixed $last
1602 * @return void Throws an error and does nothing
1604 function sql_fullname($first='firstname', $last='lastname') {
1605 error('sql_fullname() not available anymore');
1608 * @deprecated
1609 * @return void Throws an error and does nothing
1611 function sql_concat() {
1612 error('sql_concat() not available anymore');
1615 * @deprecated
1616 * @return void Throws an error and does nothing
1618 function sql_empty() {
1619 error('sql_empty() not available anymore');
1622 * @deprecated
1623 * @return void Throws an error and does nothing
1625 function sql_substr() {
1626 error('sql_substr() not available anymore');
1629 * @deprecated
1630 * @param mixed $int1
1631 * @param mixed $int2
1632 * @return void Throws an error and does nothing
1634 function sql_bitand($int1, $int2) {
1635 error('sql_bitand() not available anymore');
1638 * @deprecated
1639 * @param mixed $int1
1640 * @return void Throws an error and does nothing
1642 function sql_bitnot($int1) {
1643 error('sql_bitnot() not available anymore');
1646 * @deprecated
1647 * @param mixed $int1
1648 * @param mixed $int2
1649 * @return void Throws an error and does nothing
1651 function sql_bitor($int1, $int2) {
1652 error('sql_bitor() not available anymore');
1655 * @deprecated
1656 * @param mixed $int1
1657 * @param mixed $int2
1658 * @return void Throws an error and does nothing
1660 function sql_bitxor($int1, $int2) {
1661 error('sql_bitxor() not available anymore');
1664 * @deprecated
1665 * @param mixed $fieldname
1666 * @param mixed $text
1667 * @return void Throws an error and does nothing
1669 function sql_cast_char2int($fieldname, $text=false) {
1670 error('sql_cast_char2int() not available anymore');
1673 * @deprecated
1674 * @param mixed $fieldname
1675 * @param mixed $numchars
1676 * @return void Throws an error and does nothing
1678 function sql_compare_text($fieldname, $numchars=32) {
1679 error('sql_compare_text() not available anymore');
1682 * @deprecated
1683 * @param mixed $fieldname
1684 * @param mixed $numchars
1685 * @return void Throws an error and does nothing
1687 function sql_order_by_text($fieldname, $numchars=32) {
1688 error('sql_order_by_text() not available anymore');
1691 * @deprecated
1692 * @param mixed $fieldname
1693 * @return void Throws an error and does nothing
1695 function sql_length($fieldname) {
1696 error('sql_length() not available anymore');
1699 * @deprecated
1700 * @param mixed $separator
1701 * @param mixed $elements
1702 * @return void Throws an error and does nothing
1704 function sql_concat_join($separator="' '", $elements=array()) {
1705 error('sql_concat_join() not available anymore');
1708 * @deprecated
1709 * @param mixed $tablename
1710 * @param mixed $fieldname
1711 * @param mixed $nullablefield
1712 * @param mixed $textfield
1713 * @return void Throws an error and does nothing
1715 function sql_isempty($tablename, $fieldname, $nullablefield, $textfield) {
1716 error('sql_isempty() not available anymore');
1719 * @deprecated
1720 * @param mixed $tablename
1721 * @param mixed $fieldname
1722 * @param mixed $nullablefield
1723 * @param mixed $textfield
1724 * @return void Throws an error and does nothing
1726 function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) {
1727 error('sql_isnotempty() not available anymore');
1730 * @deprecated
1731 * @return void Throws an error and does nothing
1733 function begin_sql() {
1734 error('begin_sql() not available anymore');
1737 * @deprecated
1738 * @return void Throws an error and does nothing
1740 function commit_sql() {
1741 error('commit_sql() not available anymore');
1744 * @deprecated
1745 * @return void Throws an error and does nothing
1747 function rollback_sql() {
1748 error('rollback_sql() not available anymore');
1751 * @deprecated
1752 * @param mixed $table
1753 * @param mixed $dataobject
1754 * @param mixed $returnid
1755 * @param mixed $primarykey
1756 * @return void Throws an error and does nothing
1758 function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
1759 error('insert_record() not available anymore');
1762 * @deprecated
1763 * @param mixed $table
1764 * @param mixed $dataobject
1765 * @return void Throws an error and does nothing
1767 function update_record($table, $dataobject) {
1768 error('update_record() not available anymore');
1771 * @deprecated
1772 * @param mixed $table
1773 * @param mixed $field
1774 * @param mixed $value
1775 * @param mixed $sort
1776 * @param mixed $fields
1777 * @param mixed $limitfrom
1778 * @param mixed $limitnum
1780 * @return void Throws an error and does nothing
1782 function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1783 error('get_records() not available anymore');
1786 * @deprecated
1787 * @param mixed $table
1788 * @param mixed $field1
1789 * @param mixed $value1
1790 * @param mixed $field2
1791 * @param mixed $value2
1792 * @param mixed $field3
1793 * @param mixed $value3
1794 * @param mixed $fields
1795 * @return void Throws an error and does nothing
1797 function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') {
1798 error('get_record() not available anymore');
1801 * @deprecated
1802 * @param mixed $table
1803 * @param mixed $newfield
1804 * @param mixed $newvalue
1805 * @param mixed $field1
1806 * @param mixed $value1
1807 * @param mixed $field2
1808 * @param mixed $value2
1809 * @param mixed $field3
1810 * @param mixed $value3
1811 * @return void Throws an error and does nothing
1813 function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1814 error('set_field() not available anymore');
1817 * @deprecated
1818 * @param mixed $table
1819 * @param mixed $field1
1820 * @param mixed $value1
1821 * @param mixed $field2
1822 * @param mixed $value2
1823 * @param mixed $field3
1824 * @param mixed $value3
1825 * @return void Throws an error and does nothing
1827 function count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1828 error('count_records() not available anymore');
1831 * @deprecated
1832 * @param mixed $table
1833 * @param mixed $field1
1834 * @param mixed $value1
1835 * @param mixed $field2
1836 * @param mixed $value2
1837 * @param mixed $field3
1838 * @param mixed $value3
1839 * @return void Throws an error and does nothing
1841 function record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1842 error('record_exists() not available anymore');
1845 * @deprecated
1846 * @param mixed $table
1847 * @param mixed $field1
1848 * @param mixed $value1
1849 * @param mixed $field2
1850 * @param mixed $value2
1851 * @param mixed $field3
1852 * @param mixed $value3
1853 * @return void Throws an error and does nothing
1855 function delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1856 error('delete_records() not available anymore');
1859 * @deprecated
1860 * @param mixed $table
1861 * @param mixed $return
1862 * @param mixed $field1
1863 * @param mixed $value1
1864 * @param mixed $field2
1865 * @param mixed $value2
1866 * @param mixed $field3
1867 * @param mixed $value3
1868 * @return void Throws an error and does nothing
1870 function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1871 error('get_field() not available anymore');
1874 * @deprecated
1875 * @param mixed $table
1876 * @param mixed $oldfield
1877 * @param mixed $field
1878 * @param mixed $type
1879 * @param mixed $size
1880 * @param mixed $signed
1881 * @param mixed $default
1882 * @param mixed $null
1883 * @param mixed $after
1884 * @return void Throws an error and does nothing
1886 function table_column($table, $oldfield, $field, $type='integer', $size='10',
1887 $signed='unsigned', $default='0', $null='not null', $after='') {
1888 error('table_column() was removed, please use new ddl functions');
1891 * @deprecated
1892 * @param mixed $name
1893 * @param mixed $editorhidebuttons
1894 * @param mixed $id
1895 * @return void Throws an error and does nothing
1897 function use_html_editor($name='', $editorhidebuttons='', $id='') {
1898 error('use_html_editor() not available anymore');
1902 * The old method that was used to include JavaScript libraries.
1903 * Please use $PAGE->requires->js_module() instead.
1905 * @param mixed $lib The library or libraries to load (a string or array of strings)
1906 * There are three way to specify the library:
1907 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
1908 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
1909 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
1910 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
1912 function require_js($lib) {
1913 global $CFG, $PAGE;
1914 // Add the lib to the list of libs to be loaded, if it isn't already
1915 // in the list.
1916 if (is_array($lib)) {
1917 foreach($lib as $singlelib) {
1918 require_js($singlelib);
1920 return;
1923 debugging('Call to deprecated function require_js. Please use $PAGE->requires->js_module() instead.', DEBUG_DEVELOPER);
1925 if (strpos($lib, 'yui_') === 0) {
1926 $PAGE->requires->yui2_lib(substr($lib, 4));
1927 } else {
1928 if ($PAGE->requires->is_head_done()) {
1929 echo html_writer::script('', $lib);
1930 } else {
1931 $PAGE->requires->js(new moodle_url($lib));
1937 * Makes an upload directory for a particular module.
1939 * This function has been deprecated by the file API changes in Moodle 2.0.
1941 * @deprecated
1942 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
1943 * @return string|false Returns full path to directory if successful, false if not
1945 function make_mod_upload_directory($courseid) {
1946 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
1950 * Used to be used for setting up the theme. No longer used by core code, and
1951 * should not have been used elsewhere.
1953 * The theme is now automatically initialised before it is first used. If you really need
1954 * to force this to happen, just reference $PAGE->theme.
1956 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
1957 * However, I can't think of any valid reason to do that outside the theme selector UI.
1959 * @deprecated
1960 * @param string $theme The theme to use defaults to current theme
1961 * @param array $params An array of parameters to use
1963 function theme_setup($theme = '', $params=NULL) {
1964 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
1965 'The current theme gets initialised automatically before it is first used.');
1969 * @deprecated use $PAGE->theme->name instead.
1970 * @return string the name of the current theme.
1972 function current_theme() {
1973 global $PAGE;
1974 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
1975 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
1976 return $PAGE->theme->name;
1980 * @todo Remove this deprecated function when no longer used
1981 * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
1983 * @param string $getid used to return $PAGE->pagetype.
1984 * @param string $getclass used to return $PAGE->legacyclass.
1986 function page_id_and_class(&$getid, &$getclass) {
1987 global $PAGE;
1988 debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
1989 $getid = $PAGE->pagetype;
1990 $getclass = $PAGE->legacyclass;
1994 * Prints some red text using echo
1996 * @deprecated
1997 * @param string $error The text to be displayed in red
1999 function formerr($error) {
2000 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
2001 global $OUTPUT;
2002 echo $OUTPUT->error_text($error);
2006 * Return the markup for the destination of the 'Skip to main content' links.
2007 * Accessibility improvement for keyboard-only users.
2009 * Used in course formats, /index.php and /course/index.php
2011 * @deprecated use $OUTPUT->skip_link_target() in instead.
2012 * @return string HTML element.
2014 function skip_main_destination() {
2015 global $OUTPUT;
2016 return $OUTPUT->skip_link_target();
2020 * Prints a string in a specified size (retained for backward compatibility)
2022 * @deprecated
2023 * @param string $text The text to be displayed
2024 * @param int $size The size to set the font for text display.
2025 * @param bool $return If set to true output is returned rather than echoed Default false
2026 * @return string|void String if return is true
2028 function print_headline($text, $size=2, $return=false) {
2029 global $OUTPUT;
2030 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
2031 $output = $OUTPUT->heading($text, $size);
2032 if ($return) {
2033 return $output;
2034 } else {
2035 echo $output;
2040 * Prints text in a format for use in headings.
2042 * @deprecated
2043 * @param string $text The text to be displayed
2044 * @param string $deprecated No longer used. (Use to do alignment.)
2045 * @param int $size The size to set the font for text display.
2046 * @param string $class
2047 * @param bool $return If set to true output is returned rather than echoed, default false
2048 * @param string $id The id to use in the element
2049 * @return string|void String if return=true nothing otherwise
2051 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
2052 global $OUTPUT;
2053 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
2054 if (!empty($deprecated)) {
2055 debugging('Use of deprecated align attribute of print_heading. ' .
2056 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
2058 $output = $OUTPUT->heading($text, $size, $class, $id);
2059 if ($return) {
2060 return $output;
2061 } else {
2062 echo $output;
2067 * Output a standard heading block
2069 * @deprecated
2070 * @param string $heading The text to write into the heading
2071 * @param string $class An additional Class Attr to use for the heading
2072 * @param bool $return If set to true output is returned rather than echoed, default false
2073 * @return string|void HTML String if return=true nothing otherwise
2075 function print_heading_block($heading, $class='', $return=false) {
2076 global $OUTPUT;
2077 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
2078 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
2079 if ($return) {
2080 return $output;
2081 } else {
2082 echo $output;
2087 * Print a message in a standard themed box.
2088 * Replaces print_simple_box (see deprecatedlib.php)
2090 * @deprecated
2091 * @param string $message, the content of the box
2092 * @param string $classes, space-separated class names.
2093 * @param string $ids
2094 * @param boolean $return, return as string or just print it
2095 * @return string|void mixed string or void
2097 function print_box($message, $classes='generalbox', $ids='', $return=false) {
2098 global $OUTPUT;
2099 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
2100 $output = $OUTPUT->box($message, $classes, $ids);
2101 if ($return) {
2102 return $output;
2103 } else {
2104 echo $output;
2109 * Starts a box using divs
2110 * Replaces print_simple_box_start (see deprecatedlib.php)
2112 * @deprecated
2113 * @param string $classes, space-separated class names.
2114 * @param string $ids
2115 * @param boolean $return, return as string or just print it
2116 * @return string|void string or void
2118 function print_box_start($classes='generalbox', $ids='', $return=false) {
2119 global $OUTPUT;
2120 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
2121 $output = $OUTPUT->box_start($classes, $ids);
2122 if ($return) {
2123 return $output;
2124 } else {
2125 echo $output;
2130 * Simple function to end a box (see above)
2131 * Replaces print_simple_box_end (see deprecatedlib.php)
2133 * @deprecated
2134 * @param boolean $return, return as string or just print it
2135 * @return string|void Depending on value of return
2137 function print_box_end($return=false) {
2138 global $OUTPUT;
2139 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
2140 $output = $OUTPUT->box_end();
2141 if ($return) {
2142 return $output;
2143 } else {
2144 echo $output;
2149 * Print a message in a standard themed container.
2151 * @deprecated
2152 * @param string $message, the content of the container
2153 * @param boolean $clearfix clear both sides
2154 * @param string $classes, space-separated class names.
2155 * @param string $idbase
2156 * @param boolean $return, return as string or just print it
2157 * @return string|void Depending on value of $return
2159 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
2160 global $OUTPUT;
2161 if ($clearfix) {
2162 $classes .= ' clearfix';
2164 $output = $OUTPUT->container($message, $classes, $idbase);
2165 if ($return) {
2166 return $output;
2167 } else {
2168 echo $output;
2173 * Starts a container using divs
2175 * @deprecated
2176 * @param boolean $clearfix clear both sides
2177 * @param string $classes, space-separated class names.
2178 * @param string $idbase
2179 * @param boolean $return, return as string or just print it
2180 * @return string|void Based on value of $return
2182 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
2183 global $OUTPUT;
2184 if ($clearfix) {
2185 $classes .= ' clearfix';
2187 $output = $OUTPUT->container_start($classes, $idbase);
2188 if ($return) {
2189 return $output;
2190 } else {
2191 echo $output;
2196 * Deprecated, now handled automatically in themes
2198 function check_theme_arrows() {
2199 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
2203 * Simple function to end a container (see above)
2205 * @deprecated
2206 * @param boolean $return, return as string or just print it
2207 * @return string|void Based on $return
2209 function print_container_end($return=false) {
2210 global $OUTPUT;
2211 $output = $OUTPUT->container_end();
2212 if ($return) {
2213 return $output;
2214 } else {
2215 echo $output;
2220 * Print a bold message in an optional color.
2222 * @deprecated use $OUTPUT->notification instead.
2223 * @param string $message The message to print out
2224 * @param string $style Optional style to display message text in
2225 * @param string $align Alignment option
2226 * @param bool $return whether to return an output string or echo now
2227 * @return string|bool Depending on $result
2229 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
2230 global $OUTPUT;
2232 if ($classes == 'green') {
2233 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
2234 $classes = 'notifysuccess'; // Backward compatible with old color system
2237 $output = $OUTPUT->notification($message, $classes);
2238 if ($return) {
2239 return $output;
2240 } else {
2241 echo $output;
2246 * Print a continue button that goes to a particular URL.
2248 * @deprecated since Moodle 2.0
2250 * @param string $link The url to create a link to.
2251 * @param bool $return If set to true output is returned rather than echoed, default false
2252 * @return string|void HTML String if return=true nothing otherwise
2254 function print_continue($link, $return = false) {
2255 global $CFG, $OUTPUT;
2257 if ($link == '') {
2258 if (!empty($_SERVER['HTTP_REFERER'])) {
2259 $link = $_SERVER['HTTP_REFERER'];
2260 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
2261 } else {
2262 $link = $CFG->wwwroot .'/';
2266 $output = $OUTPUT->continue_button($link);
2267 if ($return) {
2268 return $output;
2269 } else {
2270 echo $output;
2275 * Print a standard header
2277 * @param string $title Appears at the top of the window
2278 * @param string $heading Appears at the top of the page
2279 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
2280 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2281 * @param string $meta Meta tags to be added to the header
2282 * @param boolean $cache Should this page be cacheable?
2283 * @param string $button HTML code for a button (usually for module editing)
2284 * @param string $menu HTML code for a popup menu
2285 * @param boolean $usexml use XML for this page
2286 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2287 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2288 * @return string|void If return=true then string else void
2290 function print_header($title='', $heading='', $navigation='', $focus='',
2291 $meta='', $cache=true, $button='&nbsp;', $menu=null,
2292 $usexml=false, $bodytags='', $return=false) {
2293 global $PAGE, $OUTPUT;
2295 $PAGE->set_title($title);
2296 $PAGE->set_heading($heading);
2297 $PAGE->set_cacheable($cache);
2298 if ($button == '') {
2299 $button = '&nbsp;';
2301 $PAGE->set_button($button);
2302 $PAGE->set_headingmenu($menu);
2304 // TODO $menu
2306 if ($meta) {
2307 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2308 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2310 if ($usexml) {
2311 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2313 if ($bodytags) {
2314 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2317 $output = $OUTPUT->header();
2319 if ($return) {
2320 return $output;
2321 } else {
2322 echo $output;
2327 * This version of print_header is simpler because the course name does not have to be
2328 * provided explicitly in the strings. It can be used on the site page as in courses
2329 * Eventually all print_header could be replaced by print_header_simple
2331 * @deprecated since Moodle 2.0
2332 * @param string $title Appears at the top of the window
2333 * @param string $heading Appears at the top of the page
2334 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
2335 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2336 * @param string $meta Meta tags to be added to the header
2337 * @param boolean $cache Should this page be cacheable?
2338 * @param string $button HTML code for a button (usually for module editing)
2339 * @param string $menu HTML code for a popup menu
2340 * @param boolean $usexml use XML for this page
2341 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2342 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2343 * @return string|void If $return=true the return string else nothing
2345 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
2346 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
2348 global $COURSE, $CFG, $PAGE, $OUTPUT;
2350 if ($meta) {
2351 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
2352 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
2354 if ($usexml) {
2355 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2357 if ($bodytags) {
2358 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2361 $PAGE->set_title($title);
2362 $PAGE->set_heading($heading);
2363 $PAGE->set_cacheable(true);
2364 $PAGE->set_button($button);
2366 $output = $OUTPUT->header();
2368 if ($return) {
2369 return $output;
2370 } else {
2371 echo $output;
2375 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
2376 global $PAGE, $OUTPUT;
2377 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
2378 // TODO check arguments.
2379 if (is_string($course)) {
2380 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
2381 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
2382 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
2383 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
2385 if (!is_null($usercourse)) {
2386 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
2387 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
2389 $output = $OUTPUT->footer();
2390 if ($return) {
2391 return $output;
2392 } else {
2393 echo $output;
2398 * Returns text to be displayed to the user which reflects their login status
2400 * @global object
2401 * @global object
2402 * @global object
2403 * @global object
2404 * @uses CONTEXT_COURSE
2405 * @param course $course {@link $COURSE} object containing course information
2406 * @param user $user {@link $USER} object containing user information
2407 * @return string HTML
2409 function user_login_string($course='ignored', $user='ignored') {
2410 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
2411 return '';
2415 * Prints a nice side block with an optional header. The content can either
2416 * be a block of HTML or a list of text with optional icons.
2418 * @todo Finish documenting this function. Show example of various attributes, etc.
2420 * @static int $block_id Increments for each call to the function
2421 * @param string $heading HTML for the heading. Can include full HTML or just
2422 * plain text - plain text will automatically be enclosed in the appropriate
2423 * heading tags.
2424 * @param string $content HTML for the content
2425 * @param array $list an alternative to $content, it you want a list of things with optional icons.
2426 * @param array $icons optional icons for the things in $list.
2427 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
2428 * @param array $attributes an array of attribute => value pairs that are put on the
2429 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
2430 * already a class, class='block' is used.
2431 * @param string $title Plain text title, as embedded in the $heading.
2432 * @deprecated
2434 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
2435 global $OUTPUT;
2437 // We don't use $heading, becuse it often contains HTML that we don't want.
2438 // However, sometimes $title is not set, but $heading is.
2439 if (empty($title)) {
2440 $title = strip_tags($heading);
2443 // Render list contents to HTML if required.
2444 if (empty($content) && $list) {
2445 $content = $OUTPUT->list_block_contents($icons, $list);
2448 $bc = new block_contents();
2449 $bc->content = $content;
2450 $bc->footer = $footer;
2451 $bc->title = $title;
2453 if (isset($attributes['id'])) {
2454 $bc->id = $attributes['id'];
2455 unset($attributes['id']);
2457 $bc->attributes = $attributes;
2459 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
2463 * Starts a nice side block with an optional header.
2465 * @todo Finish documenting this function
2467 * @global object
2468 * @global object
2469 * @param string $heading HTML for the heading. Can include full HTML or just
2470 * plain text - plain text will automatically be enclosed in the appropriate
2471 * heading tags.
2472 * @param array $attributes HTML attributes to apply if possible
2473 * @deprecated
2475 function print_side_block_start($heading='', $attributes = array()) {
2476 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
2480 * Print table ending tags for a side block box.
2482 * @global object
2483 * @global object
2484 * @param array $attributes HTML attributes to apply if possible [id]
2485 * @param string $title
2486 * @deprecated
2488 function print_side_block_end($attributes = array(), $title='') {
2489 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
2493 * This was used by old code to see whether a block region had anything in it,
2494 * and hence wether that region should be printed.
2496 * We don't ever want old code to print blocks, so we now always return false.
2497 * The function only exists to avoid fatal errors in old code.
2499 * @deprecated since Moodle 2.0. always returns false.
2501 * @param object $blockmanager
2502 * @param string $region
2503 * @return bool
2505 function blocks_have_content(&$blockmanager, $region) {
2506 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
2507 return false;
2511 * This was used by old code to print the blocks in a region.
2513 * We don't ever want old code to print blocks, so this is now a no-op.
2514 * The function only exists to avoid fatal errors in old code.
2516 * @deprecated since Moodle 2.0. does nothing.
2518 * @param object $page
2519 * @param object $blockmanager
2520 * @param string $region
2522 function blocks_print_group($page, $blockmanager, $region) {
2523 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2527 * This used to be the old entry point for anyone that wants to use blocks.
2528 * Since we don't want people people dealing with blocks this way any more,
2529 * just return a suitable empty array.
2531 * @deprecated since Moodle 2.0.
2533 * @param object $page
2534 * @return array
2536 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
2537 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2538 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
2542 * This iterates over an array of blocks and calculates the preferred width
2543 * Parameter passed by reference for speed; it's not modified.
2545 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
2547 * @param mixed $instances
2549 function blocks_preferred_width($instances) {
2550 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2551 $width = 210;
2555 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2557 * @param object $page The page object
2558 * @param object $blockmanager The block manager object
2559 * @param string $blockaction One of [config, add, delete]
2560 * @param int|object $instanceorid The instance id or a block_instance object
2561 * @param bool $pinned
2562 * @param bool $redirect To redirect or not to that is the question but you should stick with true
2564 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
2565 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.');
2569 * You can use this to get the blocks to respond to URL actions without much hassle
2571 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
2573 * @param object $PAGE
2574 * @param object $blockmanager
2575 * @param bool $pinned
2577 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
2578 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
2582 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
2583 * in order to reduce code repetition.
2585 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2587 * @param $instance
2588 * @param $newpos
2589 * @param string|int $newweight
2590 * @param bool $pinned
2592 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
2593 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.');
2598 * Moves a block to the new position (column) and weight (sort order).
2600 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
2602 * @param object $instance The block instance to be moved.
2603 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
2604 * @param string $destweight The destination sort order. If NULL, we add to the end
2605 * of the destination column.
2606 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
2607 * to a new position withing the pinned list. Likewise, we
2608 * can only moved non-pinned blocks to a new position within
2609 * the non-pinned list.
2610 * @return boolean success or failure
2612 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
2613 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.');
2617 * Print a nicely formatted table.
2619 * @deprecated since Moodle 2.0
2621 * @param array $table is an object with several properties.
2623 function print_table($table, $return=false) {
2624 global $OUTPUT;
2625 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
2626 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
2627 $newtable = new html_table();
2628 foreach ($table as $property => $value) {
2629 if (property_exists($newtable, $property)) {
2630 $newtable->{$property} = $value;
2633 if (isset($table->class)) {
2634 $newtable->attributes['class'] = $table->class;
2636 if (isset($table->rowclass) && is_array($table->rowclass)) {
2637 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
2638 $newtable->rowclasses = $table->rowclass;
2640 $output = html_writer::table($newtable);
2641 if ($return) {
2642 return $output;
2643 } else {
2644 echo $output;
2645 return true;
2650 * Creates and displays (or returns) a link to a popup window
2652 * @deprecated since Moodle 2.0
2654 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2655 * @param string $name Name to be assigned to the popup window (this is used by
2656 * client-side scripts to "talk" to the popup window)
2657 * @param string $linkname Text to be displayed as web link
2658 * @param int $height Height to assign to popup window
2659 * @param int $width Height to assign to popup window
2660 * @param string $title Text to be displayed as popup page title
2661 * @param string $options List of additional options for popup window
2662 * @param bool $return If true, return as a string, otherwise print
2663 * @param string $id id added to the element
2664 * @param string $class class added to the element
2665 * @return string html code to display a link to a popup window.
2667 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
2668 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');
2670 return html_writer::link($url, $name);
2674 * Creates and displays (or returns) a buttons to a popup window.
2676 * @deprecated since Moodle 2.0
2678 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
2679 * @param string $name Name to be assigned to the popup window (this is used by
2680 * client-side scripts to "talk" to the popup window)
2681 * @param string $linkname Text to be displayed as web link
2682 * @param int $height Height to assign to popup window
2683 * @param int $width Height to assign to popup window
2684 * @param string $title Text to be displayed as popup page title
2685 * @param string $options List of additional options for popup window
2686 * @param bool $return If true, return as a string, otherwise print
2687 * @param string $id id added to the element
2688 * @param string $class class added to the element
2689 * @return string html code to display a link to a popup window.
2691 function button_to_popup_window ($url, $name=null, $linkname=null,
2692 $height=400, $width=500, $title=null, $options=null, $return=false,
2693 $id=null, $class=null) {
2694 global $OUTPUT;
2696 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2698 if ($options == 'none') {
2699 $options = null;
2702 if (empty($linkname)) {
2703 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
2706 // Create a single_button object
2707 $form = new single_button($url, $linkname, 'post');
2708 $form->button->title = $title;
2709 $form->button->id = $id;
2711 // Parse the $options string
2712 $popupparams = array();
2713 if (!empty($options)) {
2714 $optionsarray = explode(',', $options);
2715 foreach ($optionsarray as $option) {
2716 if (strstr($option, '=')) {
2717 $parts = explode('=', $option);
2718 if ($parts[1] == '0') {
2719 $popupparams[$parts[0]] = false;
2720 } else {
2721 $popupparams[$parts[0]] = $parts[1];
2723 } else {
2724 $popupparams[$option] = true;
2729 if (!empty($height)) {
2730 $popupparams['height'] = $height;
2732 if (!empty($width)) {
2733 $popupparams['width'] = $width;
2736 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
2737 $output = $OUTPUT->render($form);
2739 if ($return) {
2740 return $output;
2741 } else {
2742 echo $output;
2747 * Print a self contained form with a single submit button.
2749 * @deprecated since Moodle 2.0
2751 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
2752 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
2753 * @param string $label the caption that appears on the button.
2754 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
2755 * @param string $notusedanymore no longer used.
2756 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
2757 * @param string $tooltip a tooltip to add to the button as a title attribute.
2758 * @param boolean $disabled if true, the button will be disabled.
2759 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
2760 * @param string $formid The id attribute to use for the form
2761 * @return string|void Depending on the $return paramter.
2763 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
2764 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
2765 global $OUTPUT;
2767 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
2769 // Cast $options to array
2770 $options = (array) $options;
2772 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
2774 if ($jsconfirmmessage) {
2775 $button->button->add_confirm_action($jsconfirmmessage);
2778 $output = $OUTPUT->render($button);
2780 if ($return) {
2781 return $output;
2782 } else {
2783 echo $output;
2788 * Print a spacer image with the option of including a line break.
2790 * @deprecated since Moodle 2.0
2792 * @global object
2793 * @param int $height The height in pixels to make the spacer
2794 * @param int $width The width in pixels to make the spacer
2795 * @param boolean $br If set to true a BR is written after the spacer
2797 function print_spacer($height=1, $width=1, $br=true, $return=false) {
2798 global $CFG, $OUTPUT;
2800 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
2802 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
2804 if ($return) {
2805 return $output;
2806 } else {
2807 echo $output;
2812 * Given the path to a picture file in a course, or a URL,
2813 * this function includes the picture in the page.
2815 * @deprecated since Moodle 2.0
2817 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
2818 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
2822 * Print the specified user's avatar.
2824 * @deprecated since Moodle 2.0
2826 * @global object
2827 * @global object
2828 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
2829 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
2830 * if at all possible, particularly for reports. It is very bad for performance.
2831 * @param int $courseid The course id. Used when constructing the link to the user's profile.
2832 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
2833 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
2834 * @param boolean $return If false print picture to current page, otherwise return the output as string
2835 * @param boolean $link enclose printed image in a link the user's profile (default true).
2836 * @param string $target link target attribute. Makes the profile open in a popup window.
2837 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
2838 * decorative images, or where the username will be printed anyway.)
2839 * @return string|void String or nothing, depending on $return.
2841 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
2842 global $OUTPUT;
2844 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
2846 if (!is_object($user)) {
2847 $userid = $user;
2848 $user = new stdClass();
2849 $user->id = $userid;
2852 if (empty($user->picture) and $picture) {
2853 $user->picture = $picture;
2856 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
2858 $output = $OUTPUT->user_picture($user, $options);
2860 if ($return) {
2861 return $output;
2862 } else {
2863 echo $output;
2868 * Print a png image.
2870 * @deprecated since Moodle 2.0: no replacement
2873 function print_png() {
2874 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
2879 * Prints a basic textarea field.
2881 * @deprecated since Moodle 2.0
2883 * When using this function, you should
2885 * @global object
2886 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
2887 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
2888 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
2889 * @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.
2890 * @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.
2891 * @param string $name Name to use for the textarea element.
2892 * @param string $value Initial content to display in the textarea.
2893 * @param int $obsolete deprecated
2894 * @param bool $return If false, will output string. If true, will return string value.
2895 * @param string $id CSS ID to add to the textarea element.
2896 * @return string|void depending on the value of $return
2898 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
2899 /// $width and height are legacy fields and no longer used as pixels like they used to be.
2900 /// However, you can set them to zero to override the mincols and minrows values below.
2902 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
2903 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
2905 global $CFG;
2907 $mincols = 65;
2908 $minrows = 10;
2909 $str = '';
2911 if ($id === '') {
2912 $id = 'edit-'.$name;
2915 if ($usehtmleditor) {
2916 if ($height && ($rows < $minrows)) {
2917 $rows = $minrows;
2919 if ($width && ($cols < $mincols)) {
2920 $cols = $mincols;
2924 if ($usehtmleditor) {
2925 editors_head_setup();
2926 $editor = editors_get_preferred_editor(FORMAT_HTML);
2927 $editor->use_editor($id, array('legacy'=>true));
2928 } else {
2929 $editorclass = '';
2932 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
2933 if ($usehtmleditor) {
2934 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
2935 } else {
2936 $str .= s($value);
2938 $str .= '</textarea>'."\n";
2940 if ($return) {
2941 return $str;
2943 echo $str;
2948 * Print a help button.
2950 * @deprecated since Moodle 2.0
2952 * @param string $page The keyword that defines a help page
2953 * @param string $title The title of links, rollover tips, alt tags etc
2954 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
2955 * @param string $module Which module is the page defined in
2956 * @param mixed $image Use a help image for the link? (true/false/"both")
2957 * @param boolean $linktext If true, display the title next to the help icon.
2958 * @param string $text If defined then this text is used in the page, and
2959 * the $page variable is ignored. DEPRECATED!
2960 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
2961 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
2962 * @return string|void Depending on value of $return
2964 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
2965 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
2967 global $OUTPUT;
2969 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
2971 // hide image with CSS if needed
2973 if ($return) {
2974 return $output;
2975 } else {
2976 echo $output;
2981 * Print a help button.
2983 * Prints a special help button that is a link to the "live" emoticon popup
2985 * @todo Finish documenting this function
2987 * @global object
2988 * @global object
2989 * @param string $form ?
2990 * @param string $field ?
2991 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
2992 * @return string|void Depending on value of $return
2994 function emoticonhelpbutton($form, $field, $return = false) {
2995 /// TODO: MDL-21215
2997 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
3001 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
3002 * Should be used only with htmleditor or textarea.
3004 * @global object
3005 * @global object
3006 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
3007 * helpbutton.
3008 * @return string Link to help button
3010 function editorhelpbutton(){
3011 return '';
3013 /// TODO: MDL-21215
3017 * Print a help button.
3019 * Prints a special help button for html editors (htmlarea in this case)
3021 * @todo Write code into this function! detect current editor and print correct info
3022 * @global object
3023 * @return string Only returns an empty string at the moment
3025 function editorshortcutshelpbutton() {
3026 /// TODO: MDL-21215
3028 global $CFG;
3029 //TODO: detect current editor and print correct info
3030 /* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
3031 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
3033 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
3034 return '';
3039 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
3040 * provide this function with the language strings for sortasc and sortdesc.
3042 * @deprecated since Moodle 2.0
3044 * TODO migrate to outputlib
3045 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
3047 * @global object
3048 * @param string $direction 'up' or 'down'
3049 * @param string $strsort The language string used for the alt attribute of this image
3050 * @param bool $return Whether to print directly or return the html string
3051 * @return string|void depending on $return
3054 function print_arrow($direction='up', $strsort=null, $return=false) {
3055 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
3057 global $OUTPUT;
3059 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
3060 return null;
3063 $return = null;
3065 switch ($direction) {
3066 case 'up':
3067 $sortdir = 'asc';
3068 break;
3069 case 'down':
3070 $sortdir = 'desc';
3071 break;
3072 case 'move':
3073 $sortdir = 'asc';
3074 break;
3075 default:
3076 $sortdir = null;
3077 break;
3080 // Prepare language string
3081 $strsort = '';
3082 if (empty($strsort) && !empty($sortdir)) {
3083 $strsort = get_string('sort' . $sortdir, 'grades');
3086 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
3088 if ($return) {
3089 return $return;
3090 } else {
3091 echo $return;
3096 * Returns a string containing a link to the user documentation.
3097 * Also contains an icon by default. Shown to teachers and admin only.
3099 * @deprecated since Moodle 2.0
3101 * @global object
3102 * @param string $path The page link after doc root and language, no leading slash.
3103 * @param string $text The text to be displayed for the link
3104 * @param string $iconpath The path to the icon to be displayed
3105 * @return string Either the link or an empty string
3107 function doc_link($path='', $text='', $iconpath='ignored') {
3108 global $CFG, $OUTPUT;
3110 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
3112 if (empty($CFG->docroot)) {
3113 return '';
3116 return $OUTPUT->doc_link($path, $text);
3120 * Prints a single paging bar to provide access to other pages (usually in a search)
3122 * @deprecated since Moodle 2.0
3124 * @param int $totalcount Thetotal number of entries available to be paged through
3125 * @param int $page The page you are currently viewing
3126 * @param int $perpage The number of entries that should be shown per page
3127 * @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.
3128 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
3129 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
3130 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
3131 * @param bool $return whether to return an output string or echo now
3132 * @return bool|string depending on $result
3134 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
3135 global $OUTPUT;
3137 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
3139 if (empty($nocurr)) {
3140 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
3143 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
3144 $pagingbar->pagevar = $pagevar;
3145 $output = $OUTPUT->render($pagingbar);
3147 if ($return) {
3148 return $output;
3151 echo $output;
3152 return true;
3156 * Print a message along with "Yes" and "No" links for the user to continue.
3158 * @deprecated since Moodle 2.0
3160 * @global object
3161 * @param string $message The text to display
3162 * @param string $linkyes The link to take the user to if they choose "Yes"
3163 * @param string $linkno The link to take the user to if they choose "No"
3164 * @param string $optionyes The yes option to show on the notice
3165 * @param string $optionsno The no option to show
3166 * @param string $methodyes Form action method to use if yes [post, get]
3167 * @param string $methodno Form action method to use if no [post, get]
3168 * @return void Output is echo'd
3170 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
3172 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
3174 global $OUTPUT;
3176 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
3177 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
3179 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
3183 * Prints a scale menu (as part of an existing form) including help button
3184 * @deprecated since Moodle 2.0
3186 function print_scale_menu() {
3187 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
3191 * Given an array of values, output the HTML for a select element with those options.
3193 * @deprecated since Moodle 2.0
3195 * Normally, you only need to use the first few parameters.
3197 * @param array $options The options to offer. An array of the form
3198 * $options[{value}] = {text displayed for that option};
3199 * @param string $name the name of this form control, as in &lt;select name="..." ...
3200 * @param string $selected the option to select initially, default none.
3201 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
3202 * Set this to '' if you don't want a 'nothing is selected' option.
3203 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3204 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
3205 * @param boolean $return if false (the default) the the output is printed directly, If true, the
3206 * generated HTML is returned as a string.
3207 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
3208 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
3209 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
3210 * then a suitable one is constructed.
3211 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
3212 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
3213 * $listbox is an integer, that number is used for size instead.
3214 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
3215 * when $listbox display is enabled
3216 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
3217 * then a suitable one is constructed.
3218 * @return string|void If $return=true returns string, else echo's and returns void
3220 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
3221 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
3222 $id='', $listbox=false, $multiple=false, $class='') {
3224 global $OUTPUT;
3225 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
3227 if ($script) {
3228 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3230 $attributes = array();
3231 $attributes['disabled'] = $disabled ? 'disabled' : null;
3232 $attributes['tabindex'] = $tabindex ? $tabindex : null;
3233 $attributes['multiple'] = $multiple ? $multiple : null;
3234 $attributes['class'] = $class ? $class : null;
3235 $attributes['id'] = $id ? $id : null;
3237 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
3239 if ($return) {
3240 return $output;
3241 } else {
3242 echo $output;
3247 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
3248 * Other options like choose_from_menu.
3250 * @deprecated since Moodle 2.0
3252 * Calls {@link choose_from_menu()} with preset arguments
3253 * @see choose_from_menu()
3255 * @param string $name the name of this form control, as in &lt;select name="..." ...
3256 * @param string $selected the option to select initially, default none.
3257 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
3258 * @param boolean $return Whether this function should return a string or output it (defaults to false)
3259 * @param boolean $disabled (defaults to false)
3260 * @param int $tabindex
3261 * @return string|void If $return=true returns string, else echo's and returns void
3263 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
3264 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
3265 global $OUTPUT;
3267 if ($script) {
3268 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
3271 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
3273 if ($return) {
3274 return $output;
3275 } else {
3276 echo $output;
3281 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
3282 * including option headings with the first level.
3284 * @deprecated since Moodle 2.0
3286 * This function is very similar to {@link choose_from_menu_yesno()}
3287 * and {@link choose_from_menu()}
3289 * @todo Add datatype handling to make sure $options is an array
3291 * @param array $options An array of objects to choose from
3292 * @param string $name The XHTML field name
3293 * @param string $selected The value to select by default
3294 * @param string $nothing The label for the 'nothing is selected' option.
3295 * Defaults to get_string('choose').
3296 * @param string $script If not '', then this is added to the &lt;select> element
3297 * as an onchange handler.
3298 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
3299 * @param bool $return Whether this function should return a string or output
3300 * it (defaults to false)
3301 * @param bool $disabled Is the field disabled by default
3302 * @param int|string $tabindex Override the tabindex attribute [numeric]
3303 * @return string|void If $return=true returns string, else echo's and returns void
3305 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
3306 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
3308 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer:.select().');
3309 global $OUTPUT;
3313 * Prints a help button about a scale
3315 * @deprecated since Moodle 2.0
3317 * @global object
3318 * @param id $courseid
3319 * @param object $scale
3320 * @param boolean $return If set to true returns rather than echo's
3321 * @return string|bool Depending on value of $return
3323 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
3324 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
3325 global $OUTPUT;
3327 $output = $OUTPUT->help_icon_scale($courseid, $scale);
3329 if ($return) {
3330 return $output;
3331 } else {
3332 echo $output;
3338 * Prints time limit value selector
3340 * @deprecated since Moodle 2.0
3342 * Uses {@link choose_from_menu()} to generate HTML
3343 * @see choose_from_menu()
3345 * @global object
3346 * @param int $timelimit default
3347 * @param string $unit
3348 * @param string $name
3349 * @param boolean $return If set to true returns rather than echo's
3350 * @return string|bool Depending on value of $return
3352 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
3353 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
3357 * Prints form items with the names $hour and $minute
3359 * @deprecated since Moodle 2.0
3361 * @param string $hour fieldname
3362 * @param string $minute fieldname
3363 * @param int $currenttime A default timestamp in GMT
3364 * @param int $step minute spacing
3365 * @param boolean $return If set to true returns rather than echo's
3366 * @return string|bool Depending on value of $return
3368 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
3369 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
3371 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
3372 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
3374 $output = $hourselector . $$minuteselector;
3376 if ($return) {
3377 return $output;
3378 } else {
3379 echo $output;
3384 * Prints form items with the names $day, $month and $year
3386 * @deprecated since Moodle 2.0
3388 * @param string $day fieldname
3389 * @param string $month fieldname
3390 * @param string $year fieldname
3391 * @param int $currenttime A default timestamp in GMT
3392 * @param boolean $return If set to true returns rather than echo's
3393 * @return string|bool Depending on value of $return
3395 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
3396 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
3398 $dayselector = html_writer::select_time('days', $day, $currenttime);
3399 $monthselector = html_writer::select_time('months', $month, $currenttime);
3400 $yearselector = html_writer::select_time('years', $year, $currenttime);
3402 $output = $dayselector . $monthselector . $yearselector;
3404 if ($return) {
3405 return $output;
3406 } else {
3407 echo $output;
3412 * Implements a complete little form with a dropdown menu.
3414 * @deprecated since Moodle 2.0
3416 * When JavaScript is on selecting an option from the dropdown automatically
3417 * submits the form (while avoiding the usual acessibility problems with this appoach).
3418 * With JavaScript off, a 'Go' button is printed.
3420 * @global object
3421 * @global object
3422 * @param string $baseurl The target URL up to the point of the variable that changes
3423 * @param array $options A list of value-label pairs for the popup list
3424 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
3425 * @param string $selected The option that is initially selected
3426 * @param string $nothing The label for the "no choice" option
3427 * @param string $help The name of a help page if help is required
3428 * @param string $helptext The name of the label for the help button
3429 * @param boolean $return Indicates whether the function should return the HTML
3430 * as a string or echo it directly to the page being rendered
3431 * @param string $targetwindow The name of the target page to open the linked page in.
3432 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
3433 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
3434 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
3435 * @param boolean $disabled If true, the menu will be displayed disabled.
3436 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
3437 * @return string|void If $return=true returns string, else echo's and returns void
3439 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
3440 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
3441 global $OUTPUT, $CFG;
3443 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
3445 if (empty($options)) {
3446 return '';
3449 $urls = array();
3451 foreach ($options as $value=>$label) {
3452 $url = $baseurl.$value;
3453 $url = str_replace($CFG->wwwroot, '', $url);
3454 $url = str_replace('&amp;', '&', $url);
3455 $urls[$url] = $label;
3456 if ($selected == $value) {
3457 $active = $url;
3461 $nothing = $nothing ? array(''=>$nothing) : null;
3463 $select = new url_select($urls, $active, $nothing, $formid);
3464 $select->disabled = $disabled;
3466 $select->set_label($selectlabel);
3467 $select->set_old_help_icon($help, $helptext);
3469 $output = $OUTPUT->render($select);
3471 if ($return) {
3472 return $output;
3473 } else {
3474 echo $output;
3479 * Prints a simple button to close a window
3481 * @deprecated since Moodle 2.0
3483 * @global object
3484 * @param string $name Name of the window to close
3485 * @param boolean $return whether this function should return a string or output it.
3486 * @param boolean $reloadopener if true, clicking the button will also reload
3487 * the page that opend this popup window.
3488 * @return string|void if $return is true, void otherwise
3490 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
3491 global $OUTPUT;
3493 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
3494 $output = $OUTPUT->close_window_button(get_string($name));
3496 if ($return) {
3497 return $output;
3498 } else {
3499 echo $output;
3504 * Given an array of values, creates a group of radio buttons to be part of a form
3506 * @deprecated since Moodle 2.0
3508 * @staticvar int $idcounter
3509 * @param array $options An array of value-label pairs for the radio group (values as keys)
3510 * @param string $name Name of the radiogroup (unique in the form)
3511 * @param string $checked The value that is already checked
3512 * @param bool $return Whether this function should return a string or output
3513 * it (defaults to false)
3514 * @return string|void If $return=true returns string, else echo's and returns void
3516 function choose_from_radio ($options, $name, $checked='', $return=false) {
3517 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
3521 * Display an standard html checkbox with an optional label
3523 * @deprecated since Moodle 2.0
3525 * @staticvar int $idcounter
3526 * @param string $name The name of the checkbox
3527 * @param string $value The valus that the checkbox will pass when checked
3528 * @param bool $checked The flag to tell the checkbox initial state
3529 * @param string $label The label to be showed near the checkbox
3530 * @param string $alt The info to be inserted in the alt tag
3531 * @param string $script If not '', then this is added to the checkbox element
3532 * as an onchange handler.
3533 * @param bool $return Whether this function should return a string or output
3534 * it (defaults to false)
3535 * @return string|void If $return=true returns string, else echo's and returns void
3537 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
3539 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
3540 global $OUTPUT;
3542 if (!empty($script)) {
3543 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
3546 $output = html_writer::checkbox($name, $value, $checked, $label);
3548 if (empty($return)) {
3549 echo $output;
3550 } else {
3551 return $output;
3558 * Display an standard html text field with an optional label
3560 * @deprecated since Moodle 2.0
3562 * @param string $name The name of the text field
3563 * @param string $value The value of the text field
3564 * @param string $alt The info to be inserted in the alt tag
3565 * @param int $size Sets the size attribute of the field. Defaults to 50
3566 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
3567 * @param bool $return Whether this function should return a string or output
3568 * it (defaults to false)
3569 * @return string|void If $return=true returns string, else echo's and returns void
3571 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
3572 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
3574 if ($alt === '') {
3575 $alt = null;
3578 $style = "width: {$size}px;";
3579 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
3580 if ($maxlength) {
3581 $attributes['maxlength'] = $maxlength;
3584 $output = html_writer::empty_tag('input', $attributes);
3586 if (empty($return)) {
3587 echo $output;
3588 } else {
3589 return $output;
3595 * Centered heading with attached help button (same title text)
3596 * and optional icon attached
3598 * @deprecated since Moodle 2.0
3600 * @param string $text The text to be displayed
3601 * @param string $helppage The help page to link to
3602 * @param string $module The module whose help should be linked to
3603 * @param string $icon Image to display if needed
3604 * @param bool $return If set to true output is returned rather than echoed, default false
3605 * @return string|void String if return=true nothing otherwise
3607 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
3609 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
3611 global $OUTPUT;
3613 // Extract the src from $icon if it exists
3614 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
3615 $icon = $matches[1];
3616 $icon = new moodle_url($icon);
3617 } else {
3618 $icon = '';
3621 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
3623 if ($return) {
3624 return $output;
3625 } else {
3626 echo $output;
3631 * Returns a turn edit on/off button for course in a self contained form.
3632 * Used to be an icon, but it's now a simple form button
3633 * @deprecated since Moodle 2.0
3635 function update_mymoodle_icon() {
3636 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
3640 * Returns a turn edit on/off button for tag in a self contained form.
3641 * @deprecated since Moodle 2.0
3642 * @param string $tagid The ID attribute
3643 * @return string
3645 function update_tag_button($tagid) {
3646 global $OUTPUT;
3647 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3648 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
3653 * Prints the 'update this xxx' button that appears on module pages.
3655 * @deprecated since Moodle 2.0
3657 * @param string $cmid the course_module id.
3658 * @param string $ignored not used any more. (Used to be courseid.)
3659 * @param string $string the module name - get_string('modulename', 'xxx')
3660 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
3662 function update_module_button($cmid, $ignored, $string) {
3663 global $CFG, $OUTPUT;
3665 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
3667 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
3669 if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
3670 $string = get_string('updatethis', '', $string);
3672 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
3673 return $OUTPUT->single_button($url, $string);
3674 } else {
3675 return '';
3680 * Prints the editing button on search results listing
3681 * For bulk move courses to another category
3682 * @deprecated since Moodle 2.0
3684 function update_categories_search_button($search,$page,$perpage) {
3685 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
3689 * Prints a summary of a user in a nice little box.
3690 * @deprecated since Moodle 2.0
3692 function print_user($user, $course, $messageselect=false, $return=false) {
3693 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
3697 * Returns a turn edit on/off button for course in a self contained form.
3698 * Used to be an icon, but it's now a simple form button
3700 * Note that the caller is responsible for capchecks.
3702 * @global object
3703 * @global object
3704 * @param int $courseid The course to update by id as found in 'course' table
3705 * @return string
3707 function update_course_icon($courseid) {
3708 global $CFG, $OUTPUT;
3710 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
3712 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
3716 * Prints breadcrumb trail of links, called in theme/-/header.html
3718 * This function has now been deprecated please use output's navbar method instead
3719 * as shown below
3721 * <code php>
3722 * echo $OUTPUT->navbar();
3723 * </code>
3725 * @deprecated since 2.0
3726 * @param mixed $navigation deprecated
3727 * @param string $separator OBSOLETE, and now deprecated
3728 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
3729 * @return string|void String or null, depending on $return.
3731 function print_navigation ($navigation, $separator=0, $return=false) {
3732 global $OUTPUT,$PAGE;
3734 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
3736 $output = $OUTPUT->navbar();
3738 if ($return) {
3739 return $output;
3740 } else {
3741 echo $output;
3746 * This function will build the navigation string to be used by print_header
3747 * and others.
3749 * It automatically generates the site and course level (if appropriate) links.
3751 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
3752 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
3754 * If you want to add any further navigation links after the ones this function generates,
3755 * the pass an array of extra link arrays like this:
3756 * array(
3757 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
3758 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
3760 * The normal case is to just add one further link, for example 'Editing forum' after
3761 * 'General Developer Forum', with no link.
3762 * To do that, you need to pass
3763 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
3764 * However, becuase this is a very common case, you can use a shortcut syntax, and just
3765 * pass the string 'Editing forum', instead of an array as $extranavlinks.
3767 * At the moment, the link types only have limited significance. Type 'activity' is
3768 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
3769 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
3770 * This really needs to be documented better. In the mean time, try to be consistent, it will
3771 * enable people to customise the navigation more in future.
3773 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
3774 * If you get the $cm object using the function get_coursemodule_from_instance or
3775 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
3776 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
3777 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
3778 * warning is printed in developer debug mode.
3780 * @deprecated since 2.0
3781 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
3782 * only want one extra item with no link, you can pass a string instead. If you don't want
3783 * any extra links, pass an empty string.
3784 * @param mixed $cm deprecated
3785 * @return array Navigation array
3787 function build_navigation($extranavlinks, $cm = null) {
3788 global $CFG, $COURSE, $DB, $SITE, $PAGE;
3790 if (is_array($extranavlinks) && count($extranavlinks)>0) {
3791 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
3792 foreach ($extranavlinks as $nav) {
3793 if (array_key_exists('name', $nav)) {
3794 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
3795 $link = $nav['link'];
3796 } else {
3797 $link = null;
3799 $PAGE->navbar->add($nav['name'],$link);
3804 return(array('newnav' => true, 'navlinks' => array()));
3808 * Returns a small popup menu of course activity modules
3810 * Given a course and a (current) coursemodule
3811 * his function returns a small popup menu with all the
3812 * course activity modules in it, as a navigation menu
3813 * The data is taken from the serialised array stored in
3814 * the course record
3816 * @global object
3817 * @global object
3818 * @global object
3819 * @global object
3820 * @uses CONTEXT_COURSE
3821 * @param object $course A {@link $COURSE} object.
3822 * @param object $cm A {@link $COURSE} object.
3823 * @param string $targetwindow The target window attribute to us
3824 * @return string
3826 function navmenu($course, $cm=NULL, $targetwindow='self') {
3827 // This function has been deprecated with the creation of the global nav in
3828 // moodle 2.0
3830 return '';
3834 * Returns a little popup menu for switching roles
3836 * @deprecated in Moodle 2.0
3837 * @param int $courseid The course to update by id as found in 'course' table
3838 * @return string
3840 function switchroles_form($courseid) {
3841 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
3842 return '';
3846 * Print header for admin page
3847 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
3848 * @param string $focus focus element
3850 function admin_externalpage_print_header($focus='') {
3851 global $OUTPUT;
3853 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
3855 echo $OUTPUT->header();
3859 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
3861 function admin_externalpage_print_footer() {
3862 // TODO Still 103 referernces in core code. Don't do debugging output yet.
3863 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
3864 global $OUTPUT;
3865 echo $OUTPUT->footer();
3868 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
3872 * Call this function to add an event to the calendar table and to call any calendar plugins
3874 * @param object $event An object representing an event from the calendar table.
3875 * The event will be identified by the id field. The object event should include the following:
3876 * <ul>
3877 * <li><b>$event->name</b> - Name for the event
3878 * <li><b>$event->description</b> - Description of the event (defaults to '')
3879 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
3880 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
3881 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
3882 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
3883 * <li><b>$event->modulename</b> - Name of the module that creates this event
3884 * <li><b>$event->instance</b> - Instance of the module that owns this event
3885 * <li><b>$event->eventtype</b> - The type info together with the module info could
3886 * be used by calendar plugins to decide how to display event
3887 * <li><b>$event->timestart</b>- Timestamp for start of event
3888 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
3889 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
3890 * </ul>
3891 * @return int|false The id number of the resulting record or false if failed
3893 function add_event($event) {
3894 global $CFG;
3895 require_once($CFG->dirroot.'/calendar/lib.php');
3896 $event = calendar_event::create($event);
3897 if ($event !== false) {
3898 return $event->id;
3900 return false;
3904 * Call this function to update an event in the calendar table
3905 * the event will be identified by the id field of the $event object.
3907 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3908 * @return bool Success
3910 function update_event($event) {
3911 global $CFG;
3912 require_once($CFG->dirroot.'/calendar/lib.php');
3913 $event = (object)$event;
3914 $calendarevent = calendar_event::load($event->id);
3915 return $calendarevent->update($event);
3919 * Call this function to delete the event with id $id from calendar table.
3921 * @param int $id The id of an event from the 'event' table.
3922 * @return bool
3924 function delete_event($id) {
3925 global $CFG;
3926 require_once($CFG->dirroot.'/calendar/lib.php');
3927 $event = calendar_event::load($id);
3928 return $event->delete();
3932 * Call this function to hide an event in the calendar table
3933 * the event will be identified by the id field of the $event object.
3935 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3936 * @return true
3938 function hide_event($event) {
3939 global $CFG;
3940 require_once($CFG->dirroot.'/calendar/lib.php');
3941 $event = new calendar_event($event);
3942 return $event->toggle_visibility(false);
3946 * Call this function to unhide an event in the calendar table
3947 * the event will be identified by the id field of the $event object.
3949 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
3950 * @return true
3952 function show_event($event) {
3953 global $CFG;
3954 require_once($CFG->dirroot.'/calendar/lib.php');
3955 $event = new calendar_event($event);
3956 return $event->toggle_visibility(true);