Merge branch 'MDL-37668-m24' of git://github.com/sammarshallou/moodle into MOODLE_24_...
[moodle.git] / lib / deprecatedlib.php
blob900b6e72b93e63ca02039fac65f11184edd7a4ea
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
24 * @package core
25 * @subpackage deprecated
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @deprecated
31 defined('MOODLE_INTERNAL') || die();
33 /**
34 * Unsupported session id rewriting.
35 * @deprecated
36 * @param string $buffer
38 function sid_ob_rewrite($buffer) {
39 throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
42 /**
43 * Insert or update log display entry. Entry may already exist.
44 * $module, $action must be unique
45 * @deprecated
47 * @param string $module
48 * @param string $action
49 * @param string $mtable
50 * @param string $field
51 * @return void
54 function update_log_display_entry($module, $action, $mtable, $field) {
55 global $DB;
57 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
60 /**
61 * Given some text in HTML format, this function will pass it
62 * through any filters that have been configured for this context.
64 * @deprecated use the text formatting in a standard way instead,
65 * this was abused mostly for embedding of attachments
67 * @param string $text The text to be passed through format filters
68 * @param int $courseid The current course.
69 * @return string the filtered string.
71 function filter_text($text, $courseid = NULL) {
72 global $CFG, $COURSE;
74 if (!$courseid) {
75 $courseid = $COURSE->id;
78 if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
79 return $text;
82 return filter_manager::instance()->filter_text($text, $context);
85 /**
86 * This function indicates that current page requires the https
87 * when $CFG->loginhttps enabled.
89 * By using this function properly, we can ensure 100% https-ized pages
90 * at our entire discretion (login, forgot_password, change_password)
91 * @deprecated use $PAGE->https_required() instead
93 function httpsrequired() {
94 global $PAGE;
95 $PAGE->https_required();
98 /**
99 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
101 * @deprecated use moodle_url factory methods instead
103 * @param string $path Physical path to a file
104 * @param array $options associative array of GET variables to append to the URL
105 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
106 * @return string URL to file
108 function get_file_url($path, $options=null, $type='coursefile') {
109 global $CFG;
111 $path = str_replace('//', '/', $path);
112 $path = trim($path, '/'); // no leading and trailing slashes
114 // type of file
115 switch ($type) {
116 case 'questionfile':
117 $url = $CFG->wwwroot."/question/exportfile.php";
118 break;
119 case 'rssfile':
120 $url = $CFG->wwwroot."/rss/file.php";
121 break;
122 case 'httpscoursefile':
123 $url = $CFG->httpswwwroot."/file.php";
124 break;
125 case 'coursefile':
126 default:
127 $url = $CFG->wwwroot."/file.php";
130 if ($CFG->slasharguments) {
131 $parts = explode('/', $path);
132 foreach ($parts as $key => $part) {
133 /// anchor dash character should not be encoded
134 $subparts = explode('#', $part);
135 $subparts = array_map('rawurlencode', $subparts);
136 $parts[$key] = implode('#', $subparts);
138 $path = implode('/', $parts);
139 $ffurl = $url.'/'.$path;
140 $separator = '?';
141 } else {
142 $path = rawurlencode('/'.$path);
143 $ffurl = $url.'?file='.$path;
144 $separator = '&amp;';
147 if ($options) {
148 foreach ($options as $name=>$value) {
149 $ffurl = $ffurl.$separator.$name.'='.$value;
150 $separator = '&amp;';
154 return $ffurl;
158 * If there has been an error uploading a file, print the appropriate error message
159 * Numerical constants used as constant definitions not added until PHP version 4.2.0
160 * @deprecated removed - use new file api
162 function print_file_upload_error($filearray = '', $returnerror = false) {
163 throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
167 * Handy function for resolving file conflicts
168 * @deprecated removed - use new file api
171 function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
172 throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
176 * Checks a file name for any conflicts
177 * @deprecated removed - use new file api
179 function check_potential_filename($destination,$filename,$files) {
180 throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
184 * This function prints out a number of upload form elements.
185 * @deprecated removed - use new file api
187 function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
188 throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
192 * Return the authentication plugin title
194 * @param string $authtype plugin type
195 * @return string
197 function auth_get_plugin_title($authtype) {
198 debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
199 return get_string('pluginname', "auth_{$authtype}");
205 * Enrol someone without using the default role in a course
206 * @deprecated
208 function enrol_into_course($course, $user, $enrol) {
209 error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
213 * Returns a role object that is the default role for new enrolments in a given course
215 * @deprecated
216 * @param object $course
217 * @return object returns a role or NULL if none set
219 function get_default_course_role($course) {
220 debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
222 $student = get_archetype_roles('student');
223 $student = reset($student);
225 return $student;
229 * Extremely slow enrolled courses query.
230 * @deprecated
232 function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
233 error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
237 * Was returning list of translations, use new string_manager instead
239 * @deprecated
240 * @param bool $refreshcache force refreshing of lang cache
241 * @param bool $returnall ignore langlist, return all languages available
242 * @return array An associative array with contents in the form of LanguageCode => LanguageName
244 function get_list_of_languages($refreshcache=false, $returnall=false) {
245 debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
246 if ($refreshcache) {
247 get_string_manager()->reset_caches();
249 return get_string_manager()->get_list_of_translations($returnall);
253 * Returns a list of currencies in the current language
254 * @deprecated
255 * @return array
257 function get_list_of_currencies() {
258 debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
259 return get_string_manager()->get_list_of_currencies();
263 * Returns a list of all enabled country names in the current translation
264 * @deprecated
265 * @return array two-letter country code => translated name.
267 function get_list_of_countries() {
268 debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
269 return get_string_manager()->get_list_of_countries(false);
273 * @deprecated
275 function isteacher() {
276 error('Function isteacher() was removed, please use capabilities instead!');
280 * @deprecated
282 function isteacherinanycourse() {
283 throw new coding_Exception('Function isteacherinanycourse() was removed, please use capabilities instead!');
287 * @deprecated
289 function get_guest() {
290 throw new coding_Exception('Function get_guest() was removed, please use capabilities instead!');
294 * @deprecated
296 function isguest() {
297 throw new coding_Exception('Function isguest() was removed, please use capabilities instead!');
301 * @deprecated
303 function get_teacher() {
304 throw new coding_Exception('Function get_teacher() was removed, please use capabilities instead!');
308 * Return all course participant for a given course
310 * @deprecated
311 * @param integer $courseid
312 * @return array of user
314 function get_course_participants($courseid) {
315 return get_enrolled_users(context_course::instance($courseid));
319 * Return true if the user is a participant for a given course
321 * @deprecated
322 * @param integer $userid
323 * @param integer $courseid
324 * @return boolean
326 function is_course_participant($userid, $courseid) {
327 return is_enrolled(context_course::instance($courseid), $userid);
331 * Searches logs to find all enrolments since a certain date
333 * used to print recent activity
335 * @global object
336 * @uses CONTEXT_COURSE
337 * @param int $courseid The course in question.
338 * @param int $timestart The date to check forward of
339 * @return object|false {@link $USER} records or false if error.
341 function get_recent_enrolments($courseid, $timestart) {
342 global $DB;
344 $context = context_course::instance($courseid);
346 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
347 FROM {user} u, {role_assignments} ra, {log} l
348 WHERE l.time > ?
349 AND l.course = ?
350 AND l.module = 'course'
351 AND l.action = 'enrol'
352 AND ".$DB->sql_cast_char2int('l.info')." = u.id
353 AND u.id = ra.userid
354 AND ra.contextid ".get_related_contexts_string($context)."
355 GROUP BY u.id, u.firstname, u.lastname
356 ORDER BY MAX(l.time) ASC";
357 $params = array($timestart, $courseid);
358 return $DB->get_records_sql($sql, $params);
363 * Turn the ctx* fields in an objectlike record into a context subobject
364 * This allows us to SELECT from major tables JOINing with
365 * context at no cost, saving a ton of context lookups...
367 * Use context_instance_preload() instead.
369 * @deprecated since 2.0
370 * @param object $rec
371 * @return object
373 function make_context_subobj($rec) {
374 throw new coding_Exception('make_context_subobj() was removed, use new context preloading');
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 throw new coding_Exception('is_context_subobj_valid() was removed, use new context preloading');
394 * Ensure that $rec->context is present and correct before you continue
396 * When you have a record (for example a $category, $course, $user or $cm that may,
397 * or may not, have come from a place that does make_context_subobj, you can use
398 * this method to ensure that $rec->context is present and correct before you continue.
400 * Use context_instance_preload() instead.
402 * @deprecated since 2.0
403 * @param object $rec a thing that has an associated context.
404 * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
406 function ensure_context_subobj_present(&$rec, $contextlevel) {
407 throw new coding_Exception('ensure_context_subobj_present() was removed, use new context preloading');
410 ########### FROM weblib.php ##########################################################################
414 * Print a message in a standard themed box.
415 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
416 * parameters remain. If possible, $align, $width and $color should not be defined at all.
417 * Preferably just use print_box() in weblib.php
419 * @deprecated
420 * @param string $message The message to display
421 * @param string $align alignment of the box, not the text (default center, left, right).
422 * @param string $width width of the box, including units %, for example '100%'.
423 * @param string $color background colour of the box, for example '#eee'.
424 * @param int $padding padding in pixels, specified without units.
425 * @param string $class space-separated class names.
426 * @param string $id space-separated id names.
427 * @param boolean $return return as string or just print it
428 * @return string|void Depending on $return
430 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
431 $output = '';
432 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
433 $output .= $message;
434 $output .= print_simple_box_end(true);
436 if ($return) {
437 return $output;
438 } else {
439 echo $output;
446 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
447 * parameters remain. If possible, $align, $width and $color should not be defined at all.
448 * Even better, please use print_box_start() in weblib.php
450 * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
451 * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
452 * @param string $color background colour of the box, for example '#eee'. DEPRECATED
453 * @param int $padding padding in pixels, specified without units. OBSOLETE
454 * @param string $class space-separated class names.
455 * @param string $id space-separated id names.
456 * @param boolean $return return as string or just print it
457 * @return string|void Depending on $return
459 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
460 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
462 $output = '';
464 $divclasses = 'box '.$class.' '.$class.'content';
465 $divstyles = '';
467 if ($align) {
468 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
470 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
471 if (substr($width, -1, 1) == '%') { // Width is a % value
472 $width = (int) substr($width, 0, -1); // Extract just the number
473 if ($width < 40) {
474 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
475 } else if ($width > 60) {
476 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
477 } else {
478 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
480 } else {
481 $divstyles .= ' width:'.$width.';'; // Last resort
484 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
485 $divstyles .= ' background:'.$color.';';
487 if ($divstyles) {
488 $divstyles = ' style="'.$divstyles.'"';
491 if ($id) {
492 $id = ' id="'.$id.'"';
495 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
497 if ($return) {
498 return $output;
499 } else {
500 echo $output;
506 * Print the end portion of a standard themed box.
507 * Preferably just use print_box_end() in weblib.php
509 * @param boolean $return return as string or just print it
510 * @return string|void Depending on $return
512 function print_simple_box_end($return=false) {
513 $output = '</div>';
514 if ($return) {
515 return $output;
516 } else {
517 echo $output;
522 * Given some text this function converted any URLs it found into HTML links
524 * This core function has been replaced with filter_urltolink since Moodle 2.0
526 * @param string $text Passed in by reference. The string to be searched for urls.
528 function convert_urls_into_links($text) {
529 debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
533 * Used to be called from help.php to inject a list of smilies into the
534 * emoticons help file.
536 * @return string HTML
538 function get_emoticons_list_for_help_file() {
539 debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
540 return '';
544 * Was used to replace all known smileys in the text with image equivalents
546 * This core function has been replaced with filter_emoticon since Moodle 2.0
548 function replace_smilies(&$text) {
549 debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
553 * deprecated - use clean_param($string, PARAM_FILE); instead
554 * Check for bad characters ?
556 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
558 * @param string $string ?
559 * @param int $allowdots ?
560 * @return bool
562 function detect_munged_arguments($string, $allowdots=1) {
563 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
564 return true;
566 if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
567 return true;
569 if (empty($string) or $string == '/') {
570 return true;
573 return false;
578 * Unzip one zip file to a destination dir
579 * Both parameters must be FULL paths
580 * If destination isn't specified, it will be the
581 * SAME directory where the zip file resides.
583 * @global object
584 * @param string $zipfile The zip file to unzip
585 * @param string $destination The location to unzip to
586 * @param bool $showstatus_ignored Unused
588 function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
589 global $CFG;
591 //Extract everything from zipfile
592 $path_parts = pathinfo(cleardoubleslashes($zipfile));
593 $zippath = $path_parts["dirname"]; //The path of the zip file
594 $zipfilename = $path_parts["basename"]; //The name of the zip file
595 $extension = $path_parts["extension"]; //The extension of the file
597 //If no file, error
598 if (empty($zipfilename)) {
599 return false;
602 //If no extension, error
603 if (empty($extension)) {
604 return false;
607 //Clear $zipfile
608 $zipfile = cleardoubleslashes($zipfile);
610 //Check zipfile exists
611 if (!file_exists($zipfile)) {
612 return false;
615 //If no destination, passed let's go with the same directory
616 if (empty($destination)) {
617 $destination = $zippath;
620 //Clear $destination
621 $destpath = rtrim(cleardoubleslashes($destination), "/");
623 //Check destination path exists
624 if (!is_dir($destpath)) {
625 return false;
628 $packer = get_file_packer('application/zip');
630 $result = $packer->extract_to_pathname($zipfile, $destpath);
632 if ($result === false) {
633 return false;
636 foreach ($result as $status) {
637 if ($status !== true) {
638 return false;
642 return true;
646 * Zip an array of files/dirs to a destination zip file
647 * Both parameters must be FULL paths to the files/dirs
649 * @global object
650 * @param array $originalfiles Files to zip
651 * @param string $destination The destination path
652 * @return bool Outcome
654 function zip_files ($originalfiles, $destination) {
655 global $CFG;
657 //Extract everything from destination
658 $path_parts = pathinfo(cleardoubleslashes($destination));
659 $destpath = $path_parts["dirname"]; //The path of the zip file
660 $destfilename = $path_parts["basename"]; //The name of the zip file
661 $extension = $path_parts["extension"]; //The extension of the file
663 //If no file, error
664 if (empty($destfilename)) {
665 return false;
668 //If no extension, add it
669 if (empty($extension)) {
670 $extension = 'zip';
671 $destfilename = $destfilename.'.'.$extension;
674 //Check destination path exists
675 if (!is_dir($destpath)) {
676 return false;
679 //Check destination path is writable. TODO!!
681 //Clean destination filename
682 $destfilename = clean_filename($destfilename);
684 //Now check and prepare every file
685 $files = array();
686 $origpath = NULL;
688 foreach ($originalfiles as $file) { //Iterate over each file
689 //Check for every file
690 $tempfile = cleardoubleslashes($file); // no doubleslashes!
691 //Calculate the base path for all files if it isn't set
692 if ($origpath === NULL) {
693 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
695 //See if the file is readable
696 if (!is_readable($tempfile)) { //Is readable
697 continue;
699 //See if the file/dir is in the same directory than the rest
700 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
701 continue;
703 //Add the file to the array
704 $files[] = $tempfile;
707 $zipfiles = array();
708 $start = strlen($origpath)+1;
709 foreach($files as $file) {
710 $zipfiles[substr($file, $start)] = $file;
713 $packer = get_file_packer('application/zip');
715 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
718 /////////////////////////////////////////////////////////////
719 /// Old functions not used anymore - candidates for removal
720 /////////////////////////////////////////////////////////////
723 /** various deprecated groups function **/
727 * Get the IDs for the user's groups in the given course.
729 * @global object
730 * @param int $courseid The course being examined - the 'course' table id field.
731 * @return array|bool An _array_ of groupids, or false
732 * (Was return $groupids[0] - consequences!)
734 function mygroupid($courseid) {
735 global $USER;
736 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
737 return array_keys($groups);
738 } else {
739 return false;
745 * Returns the current group mode for a given course or activity module
747 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
749 * @param object $course Course Object
750 * @param object $cm Course Manager Object
751 * @return mixed $course->groupmode
753 function groupmode($course, $cm=null) {
755 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
756 return $cm->groupmode;
758 return $course->groupmode;
762 * Sets the current group in the session variable
763 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
764 * Sets currentgroup[$courseid] in the session variable appropriately.
765 * Does not do any permission checking.
767 * @global object
768 * @param int $courseid The course being examined - relates to id field in
769 * 'course' table.
770 * @param int $groupid The group being examined.
771 * @return int Current group id which was set by this function
773 function set_current_group($courseid, $groupid) {
774 global $SESSION;
775 return $SESSION->currentgroup[$courseid] = $groupid;
780 * Gets the current group - either from the session variable or from the database.
782 * @global object
783 * @param int $courseid The course being examined - relates to id field in
784 * 'course' table.
785 * @param bool $full If true, the return value is a full record object.
786 * If false, just the id of the record.
787 * @return int|bool
789 function get_current_group($courseid, $full = false) {
790 global $SESSION;
792 if (isset($SESSION->currentgroup[$courseid])) {
793 if ($full) {
794 return groups_get_group($SESSION->currentgroup[$courseid]);
795 } else {
796 return $SESSION->currentgroup[$courseid];
800 $mygroupid = mygroupid($courseid);
801 if (is_array($mygroupid)) {
802 $mygroupid = array_shift($mygroupid);
803 set_current_group($courseid, $mygroupid);
804 if ($full) {
805 return groups_get_group($mygroupid);
806 } else {
807 return $mygroupid;
811 if ($full) {
812 return false;
813 } else {
814 return 0;
820 * Inndicates fatal error. This function was originally printing the
821 * error message directly, since 2.0 it is throwing exception instead.
822 * The error printing is handled in default exception handler.
824 * Old method, don't call directly in new code - use print_error instead.
826 * @param string $message The message to display to the user about the error.
827 * @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.
828 * @return void, always throws moodle_exception
830 function error($message, $link='') {
831 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
835 //////////////////////////
836 /// removed functions ////
837 //////////////////////////
840 * @deprecated
841 * @param mixed $name
842 * @param mixed $editorhidebuttons
843 * @param mixed $id
844 * @return void Throws an error and does nothing
846 function use_html_editor($name='', $editorhidebuttons='', $id='') {
847 error('use_html_editor() not available anymore');
851 * The old method that was used to include JavaScript libraries.
852 * Please use $PAGE->requires->js_module() instead.
854 * @param mixed $lib The library or libraries to load (a string or array of strings)
855 * There are three way to specify the library:
856 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
857 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
858 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
859 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
861 function require_js($lib) {
862 throw new coding_exception('require_js() was removed, use new JS api');
866 * Makes an upload directory for a particular module.
868 * This function has been deprecated by the file API changes in Moodle 2.0.
870 * @deprecated
871 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
872 * @return string|false Returns full path to directory if successful, false if not
874 function make_mod_upload_directory($courseid) {
875 throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
879 * Used to be used for setting up the theme. No longer used by core code, and
880 * should not have been used elsewhere.
882 * The theme is now automatically initialised before it is first used. If you really need
883 * to force this to happen, just reference $PAGE->theme.
885 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
886 * However, I can't think of any valid reason to do that outside the theme selector UI.
888 * @deprecated
889 * @param string $theme The theme to use defaults to current theme
890 * @param array $params An array of parameters to use
892 function theme_setup($theme = '', $params=NULL) {
893 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
894 'The current theme gets initialised automatically before it is first used.');
898 * @deprecated use $PAGE->theme->name instead.
899 * @return string the name of the current theme.
901 function current_theme() {
902 global $PAGE;
903 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
904 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
905 return $PAGE->theme->name;
909 * Prints some red text using echo
911 * @deprecated
912 * @param string $error The text to be displayed in red
914 function formerr($error) {
915 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
916 global $OUTPUT;
917 echo $OUTPUT->error_text($error);
921 * Return the markup for the destination of the 'Skip to main content' links.
922 * Accessibility improvement for keyboard-only users.
924 * Used in course formats, /index.php and /course/index.php
926 * @deprecated use $OUTPUT->skip_link_target() in instead.
927 * @return string HTML element.
929 function skip_main_destination() {
930 global $OUTPUT;
931 return $OUTPUT->skip_link_target();
935 * Prints a string in a specified size (retained for backward compatibility)
937 * @deprecated
938 * @param string $text The text to be displayed
939 * @param int $size The size to set the font for text display.
940 * @param bool $return If set to true output is returned rather than echoed Default false
941 * @return string|void String if return is true
943 function print_headline($text, $size=2, $return=false) {
944 global $OUTPUT;
945 debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
946 $output = $OUTPUT->heading($text, $size);
947 if ($return) {
948 return $output;
949 } else {
950 echo $output;
955 * Prints text in a format for use in headings.
957 * @deprecated
958 * @param string $text The text to be displayed
959 * @param string $deprecated No longer used. (Use to do alignment.)
960 * @param int $size The size to set the font for text display.
961 * @param string $class
962 * @param bool $return If set to true output is returned rather than echoed, default false
963 * @param string $id The id to use in the element
964 * @return string|void String if return=true nothing otherwise
966 function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
967 global $OUTPUT;
968 debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
969 if (!empty($deprecated)) {
970 debugging('Use of deprecated align attribute of print_heading. ' .
971 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
973 $output = $OUTPUT->heading($text, $size, $class, $id);
974 if ($return) {
975 return $output;
976 } else {
977 echo $output;
982 * Output a standard heading block
984 * @deprecated
985 * @param string $heading The text to write into the heading
986 * @param string $class An additional Class Attr to use for the heading
987 * @param bool $return If set to true output is returned rather than echoed, default false
988 * @return string|void HTML String if return=true nothing otherwise
990 function print_heading_block($heading, $class='', $return=false) {
991 global $OUTPUT;
992 debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
993 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
994 if ($return) {
995 return $output;
996 } else {
997 echo $output;
1002 * Print a message in a standard themed box.
1003 * Replaces print_simple_box (see deprecatedlib.php)
1005 * @deprecated
1006 * @param string $message, the content of the box
1007 * @param string $classes, space-separated class names.
1008 * @param string $ids
1009 * @param boolean $return, return as string or just print it
1010 * @return string|void mixed string or void
1012 function print_box($message, $classes='generalbox', $ids='', $return=false) {
1013 global $OUTPUT;
1014 debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
1015 $output = $OUTPUT->box($message, $classes, $ids);
1016 if ($return) {
1017 return $output;
1018 } else {
1019 echo $output;
1024 * Starts a box using divs
1025 * Replaces print_simple_box_start (see deprecatedlib.php)
1027 * @deprecated
1028 * @param string $classes, space-separated class names.
1029 * @param string $ids
1030 * @param boolean $return, return as string or just print it
1031 * @return string|void string or void
1033 function print_box_start($classes='generalbox', $ids='', $return=false) {
1034 global $OUTPUT;
1035 debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
1036 $output = $OUTPUT->box_start($classes, $ids);
1037 if ($return) {
1038 return $output;
1039 } else {
1040 echo $output;
1045 * Simple function to end a box (see above)
1046 * Replaces print_simple_box_end (see deprecatedlib.php)
1048 * @deprecated
1049 * @param boolean $return, return as string or just print it
1050 * @return string|void Depending on value of return
1052 function print_box_end($return=false) {
1053 global $OUTPUT;
1054 debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
1055 $output = $OUTPUT->box_end();
1056 if ($return) {
1057 return $output;
1058 } else {
1059 echo $output;
1064 * Print a message in a standard themed container.
1066 * @deprecated
1067 * @param string $message, the content of the container
1068 * @param boolean $clearfix clear both sides
1069 * @param string $classes, space-separated class names.
1070 * @param string $idbase
1071 * @param boolean $return, return as string or just print it
1072 * @return string|void Depending on value of $return
1074 function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1075 global $OUTPUT;
1076 if ($clearfix) {
1077 $classes .= ' clearfix';
1079 $output = $OUTPUT->container($message, $classes, $idbase);
1080 if ($return) {
1081 return $output;
1082 } else {
1083 echo $output;
1088 * Starts a container using divs
1090 * @deprecated
1091 * @param boolean $clearfix clear both sides
1092 * @param string $classes, space-separated class names.
1093 * @param string $idbase
1094 * @param boolean $return, return as string or just print it
1095 * @return string|void Based on value of $return
1097 function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1098 global $OUTPUT;
1099 if ($clearfix) {
1100 $classes .= ' clearfix';
1102 $output = $OUTPUT->container_start($classes, $idbase);
1103 if ($return) {
1104 return $output;
1105 } else {
1106 echo $output;
1111 * Deprecated, now handled automatically in themes
1113 function check_theme_arrows() {
1114 debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
1118 * Simple function to end a container (see above)
1120 * @deprecated
1121 * @param boolean $return, return as string or just print it
1122 * @return string|void Based on $return
1124 function print_container_end($return=false) {
1125 global $OUTPUT;
1126 $output = $OUTPUT->container_end();
1127 if ($return) {
1128 return $output;
1129 } else {
1130 echo $output;
1135 * Print a bold message in an optional color.
1137 * @deprecated use $OUTPUT->notification instead.
1138 * @param string $message The message to print out
1139 * @param string $style Optional style to display message text in
1140 * @param string $align Alignment option
1141 * @param bool $return whether to return an output string or echo now
1142 * @return string|bool Depending on $result
1144 function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1145 global $OUTPUT;
1147 if ($classes == 'green') {
1148 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1149 $classes = 'notifysuccess'; // Backward compatible with old color system
1152 $output = $OUTPUT->notification($message, $classes);
1153 if ($return) {
1154 return $output;
1155 } else {
1156 echo $output;
1161 * Print a continue button that goes to a particular URL.
1163 * @deprecated since Moodle 2.0
1165 * @param string $link The url to create a link to.
1166 * @param bool $return If set to true output is returned rather than echoed, default false
1167 * @return string|void HTML String if return=true nothing otherwise
1169 function print_continue($link, $return = false) {
1170 global $CFG, $OUTPUT;
1172 if ($link == '') {
1173 if (!empty($_SERVER['HTTP_REFERER'])) {
1174 $link = $_SERVER['HTTP_REFERER'];
1175 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1176 } else {
1177 $link = $CFG->wwwroot .'/';
1181 $output = $OUTPUT->continue_button($link);
1182 if ($return) {
1183 return $output;
1184 } else {
1185 echo $output;
1190 * Print a standard header
1192 * @param string $title Appears at the top of the window
1193 * @param string $heading Appears at the top of the page
1194 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
1195 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1196 * @param string $meta Meta tags to be added to the header
1197 * @param boolean $cache Should this page be cacheable?
1198 * @param string $button HTML code for a button (usually for module editing)
1199 * @param string $menu HTML code for a popup menu
1200 * @param boolean $usexml use XML for this page
1201 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1202 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1203 * @return string|void If return=true then string else void
1205 function print_header($title='', $heading='', $navigation='', $focus='',
1206 $meta='', $cache=true, $button='&nbsp;', $menu=null,
1207 $usexml=false, $bodytags='', $return=false) {
1208 global $PAGE, $OUTPUT;
1210 $PAGE->set_title($title);
1211 $PAGE->set_heading($heading);
1212 $PAGE->set_cacheable($cache);
1213 if ($button == '') {
1214 $button = '&nbsp;';
1216 $PAGE->set_button($button);
1217 $PAGE->set_headingmenu($menu);
1219 // TODO $menu
1221 if ($meta) {
1222 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1223 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1225 if ($usexml) {
1226 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1228 if ($bodytags) {
1229 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1232 $output = $OUTPUT->header();
1234 if ($return) {
1235 return $output;
1236 } else {
1237 echo $output;
1242 * This version of print_header is simpler because the course name does not have to be
1243 * provided explicitly in the strings. It can be used on the site page as in courses
1244 * Eventually all print_header could be replaced by print_header_simple
1246 * @deprecated since Moodle 2.0
1247 * @param string $title Appears at the top of the window
1248 * @param string $heading Appears at the top of the page
1249 * @param string $navigation Premade navigation string (for use as breadcrumbs links)
1250 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
1251 * @param string $meta Meta tags to be added to the header
1252 * @param boolean $cache Should this page be cacheable?
1253 * @param string $button HTML code for a button (usually for module editing)
1254 * @param string $menu HTML code for a popup menu
1255 * @param boolean $usexml use XML for this page
1256 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
1257 * @param bool $return If true, return the visible elements of the header instead of echoing them.
1258 * @return string|void If $return=true the return string else nothing
1260 function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1261 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1263 global $COURSE, $CFG, $PAGE, $OUTPUT;
1265 if ($meta) {
1266 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
1267 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
1269 if ($usexml) {
1270 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
1272 if ($bodytags) {
1273 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
1276 $PAGE->set_title($title);
1277 $PAGE->set_heading($heading);
1278 $PAGE->set_cacheable(true);
1279 $PAGE->set_button($button);
1281 $output = $OUTPUT->header();
1283 if ($return) {
1284 return $output;
1285 } else {
1286 echo $output;
1290 function print_footer($course = NULL, $usercourse = NULL, $return = false) {
1291 global $PAGE, $OUTPUT;
1292 debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
1293 // TODO check arguments.
1294 if (is_string($course)) {
1295 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
1296 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
1297 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
1298 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
1300 if (!is_null($usercourse)) {
1301 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
1302 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
1304 $output = $OUTPUT->footer();
1305 if ($return) {
1306 return $output;
1307 } else {
1308 echo $output;
1313 * Returns text to be displayed to the user which reflects their login status
1315 * @global object
1316 * @global object
1317 * @global object
1318 * @global object
1319 * @uses CONTEXT_COURSE
1320 * @param course $course {@link $COURSE} object containing course information
1321 * @param user $user {@link $USER} object containing user information
1322 * @return string HTML
1324 function user_login_string($course='ignored', $user='ignored') {
1325 debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
1326 return '';
1330 * Prints a nice side block with an optional header. The content can either
1331 * be a block of HTML or a list of text with optional icons.
1333 * @todo Finish documenting this function. Show example of various attributes, etc.
1335 * @static int $block_id Increments for each call to the function
1336 * @param string $heading HTML for the heading. Can include full HTML or just
1337 * plain text - plain text will automatically be enclosed in the appropriate
1338 * heading tags.
1339 * @param string $content HTML for the content
1340 * @param array $list an alternative to $content, it you want a list of things with optional icons.
1341 * @param array $icons optional icons for the things in $list.
1342 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
1343 * @param array $attributes an array of attribute => value pairs that are put on the
1344 * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
1345 * already a class, class='block' is used.
1346 * @param string $title Plain text title, as embedded in the $heading.
1347 * @deprecated
1349 function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
1350 global $OUTPUT;
1352 // We don't use $heading, becuse it often contains HTML that we don't want.
1353 // However, sometimes $title is not set, but $heading is.
1354 if (empty($title)) {
1355 $title = strip_tags($heading);
1358 // Render list contents to HTML if required.
1359 if (empty($content) && $list) {
1360 $content = $OUTPUT->list_block_contents($icons, $list);
1363 $bc = new block_contents();
1364 $bc->content = $content;
1365 $bc->footer = $footer;
1366 $bc->title = $title;
1368 if (isset($attributes['id'])) {
1369 $bc->id = $attributes['id'];
1370 unset($attributes['id']);
1372 $bc->attributes = $attributes;
1374 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
1378 * Starts a nice side block with an optional header.
1380 * @todo Finish documenting this function
1382 * @global object
1383 * @global object
1384 * @param string $heading HTML for the heading. Can include full HTML or just
1385 * plain text - plain text will automatically be enclosed in the appropriate
1386 * heading tags.
1387 * @param array $attributes HTML attributes to apply if possible
1388 * @deprecated
1390 function print_side_block_start($heading='', $attributes = array()) {
1391 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
1395 * Print table ending tags for a side block box.
1397 * @global object
1398 * @global object
1399 * @param array $attributes HTML attributes to apply if possible [id]
1400 * @param string $title
1401 * @deprecated
1403 function print_side_block_end($attributes = array(), $title='') {
1404 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
1408 * This was used by old code to see whether a block region had anything in it,
1409 * and hence wether that region should be printed.
1411 * We don't ever want old code to print blocks, so we now always return false.
1412 * The function only exists to avoid fatal errors in old code.
1414 * @deprecated since Moodle 2.0. always returns false.
1416 * @param object $blockmanager
1417 * @param string $region
1418 * @return bool
1420 function blocks_have_content(&$blockmanager, $region) {
1421 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
1422 return false;
1426 * This was used by old code to print the blocks in a region.
1428 * We don't ever want old code to print blocks, so this is now a no-op.
1429 * The function only exists to avoid fatal errors in old code.
1431 * @deprecated since Moodle 2.0. does nothing.
1433 * @param object $page
1434 * @param object $blockmanager
1435 * @param string $region
1437 function blocks_print_group($page, $blockmanager, $region) {
1438 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1442 * This used to be the old entry point for anyone that wants to use blocks.
1443 * Since we don't want people people dealing with blocks this way any more,
1444 * just return a suitable empty array.
1446 * @deprecated since Moodle 2.0.
1448 * @param object $page
1449 * @return array
1451 function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
1452 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1453 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
1457 * This iterates over an array of blocks and calculates the preferred width
1458 * Parameter passed by reference for speed; it's not modified.
1460 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
1462 * @param mixed $instances
1464 function blocks_preferred_width($instances) {
1465 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
1466 $width = 210;
1470 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1472 * @param object $page The page object
1473 * @param object $blockmanager The block manager object
1474 * @param string $blockaction One of [config, add, delete]
1475 * @param int|object $instanceorid The instance id or a block_instance object
1476 * @param bool $pinned
1477 * @param bool $redirect To redirect or not to that is the question but you should stick with true
1479 function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceorid, $pinned=false, $redirect=true) {
1480 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.');
1484 * You can use this to get the blocks to respond to URL actions without much hassle
1486 * @deprecated since Moodle 2.0. Blocks have been changed. {@link block_manager::process_url_actions} is the closest replacement.
1488 * @param object $PAGE
1489 * @param object $blockmanager
1490 * @param bool $pinned
1492 function blocks_execute_url_action(&$PAGE, &$blockmanager,$pinned=false) {
1493 throw new coding_exception('blocks_execute_url_action is no longer used. It has been replaced by methods of block_manager.');
1497 * This shouldn't be used externally at all, it's here for use by blocks_execute_action()
1498 * in order to reduce code repetition.
1500 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1502 * @param $instance
1503 * @param $newpos
1504 * @param string|int $newweight
1505 * @param bool $pinned
1507 function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=false) {
1508 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.');
1513 * Moves a block to the new position (column) and weight (sort order).
1515 * @deprecated since Moodle 2.0. See the replacements in blocklib.php.
1517 * @param object $instance The block instance to be moved.
1518 * @param string $destpos BLOCK_POS_LEFT or BLOCK_POS_RIGHT. The destination column.
1519 * @param string $destweight The destination sort order. If NULL, we add to the end
1520 * of the destination column.
1521 * @param bool $pinned Are we moving pinned blocks? We can only move pinned blocks
1522 * to a new position withing the pinned list. Likewise, we
1523 * can only moved non-pinned blocks to a new position within
1524 * the non-pinned list.
1525 * @return boolean success or failure
1527 function blocks_move_block($page, &$instance, $destpos, $destweight=NULL, $pinned=false) {
1528 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.');
1532 * Print a nicely formatted table.
1534 * @deprecated since Moodle 2.0
1536 * @param array $table is an object with several properties.
1538 function print_table($table, $return=false) {
1539 global $OUTPUT;
1540 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
1541 debugging('print_table() has been deprecated. Please change your code to use html_writer::table().');
1542 $newtable = new html_table();
1543 foreach ($table as $property => $value) {
1544 if (property_exists($newtable, $property)) {
1545 $newtable->{$property} = $value;
1548 if (isset($table->class)) {
1549 $newtable->attributes['class'] = $table->class;
1551 if (isset($table->rowclass) && is_array($table->rowclass)) {
1552 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
1553 $newtable->rowclasses = $table->rowclass;
1555 $output = html_writer::table($newtable);
1556 if ($return) {
1557 return $output;
1558 } else {
1559 echo $output;
1560 return true;
1565 * Creates and displays (or returns) a link to a popup window
1567 * @deprecated since Moodle 2.0
1569 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1570 * @param string $name Name to be assigned to the popup window (this is used by
1571 * client-side scripts to "talk" to the popup window)
1572 * @param string $linkname Text to be displayed as web link
1573 * @param int $height Height to assign to popup window
1574 * @param int $width Height to assign to popup window
1575 * @param string $title Text to be displayed as popup page title
1576 * @param string $options List of additional options for popup window
1577 * @param bool $return If true, return as a string, otherwise print
1578 * @param string $id id added to the element
1579 * @param string $class class added to the element
1580 * @return string html code to display a link to a popup window.
1582 function link_to_popup_window ($url, $name=null, $linkname=null, $height=400, $width=500, $title=null, $options=null, $return=false) {
1583 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');
1585 return html_writer::link($url, $name);
1589 * Creates and displays (or returns) a buttons to a popup window.
1591 * @deprecated since Moodle 2.0
1593 * @param string $url Web link. Either relative to $CFG->wwwroot, or a full URL.
1594 * @param string $name Name to be assigned to the popup window (this is used by
1595 * client-side scripts to "talk" to the popup window)
1596 * @param string $linkname Text to be displayed as web link
1597 * @param int $height Height to assign to popup window
1598 * @param int $width Height to assign to popup window
1599 * @param string $title Text to be displayed as popup page title
1600 * @param string $options List of additional options for popup window
1601 * @param bool $return If true, return as a string, otherwise print
1602 * @param string $id id added to the element
1603 * @param string $class class added to the element
1604 * @return string html code to display a link to a popup window.
1606 function button_to_popup_window ($url, $name=null, $linkname=null,
1607 $height=400, $width=500, $title=null, $options=null, $return=false,
1608 $id=null, $class=null) {
1609 global $OUTPUT;
1611 debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1613 if ($options == 'none') {
1614 $options = null;
1617 if (empty($linkname)) {
1618 throw new coding_exception('A link must have a descriptive text value! See $OUTPUT->action_link() for usage.');
1621 // Create a single_button object
1622 $form = new single_button($url, $linkname, 'post');
1623 $form->button->title = $title;
1624 $form->button->id = $id;
1626 // Parse the $options string
1627 $popupparams = array();
1628 if (!empty($options)) {
1629 $optionsarray = explode(',', $options);
1630 foreach ($optionsarray as $option) {
1631 if (strstr($option, '=')) {
1632 $parts = explode('=', $option);
1633 if ($parts[1] == '0') {
1634 $popupparams[$parts[0]] = false;
1635 } else {
1636 $popupparams[$parts[0]] = $parts[1];
1638 } else {
1639 $popupparams[$option] = true;
1644 if (!empty($height)) {
1645 $popupparams['height'] = $height;
1647 if (!empty($width)) {
1648 $popupparams['width'] = $width;
1651 $form->button->add_action(new popup_action('click', $url, $name, $popupparams));
1652 $output = $OUTPUT->render($form);
1654 if ($return) {
1655 return $output;
1656 } else {
1657 echo $output;
1662 * Print a self contained form with a single submit button.
1664 * @deprecated since Moodle 2.0
1666 * @param string $link used as the action attribute on the form, so the URL that will be hit if the button is clicked.
1667 * @param array $options these become hidden form fields, so these options get passed to the script at $link.
1668 * @param string $label the caption that appears on the button.
1669 * @param string $method HTTP method used on the request of the button is clicked. 'get' or 'post'.
1670 * @param string $notusedanymore no longer used.
1671 * @param boolean $return if false, output the form directly, otherwise return the HTML as a string.
1672 * @param string $tooltip a tooltip to add to the button as a title attribute.
1673 * @param boolean $disabled if true, the button will be disabled.
1674 * @param string $jsconfirmmessage if not empty then display a confirm dialogue with this string as the question.
1675 * @param string $formid The id attribute to use for the form
1676 * @return string|void Depending on the $return paramter.
1678 function print_single_button($link, $options, $label='OK', $method='get', $notusedanymore='',
1679 $return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
1680 global $OUTPUT;
1682 debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
1684 // Cast $options to array
1685 $options = (array) $options;
1687 $button = new single_button(new moodle_url($link, $options), $label, $method, array('disabled'=>$disabled, 'title'=>$tooltip, 'id'=>$formid));
1689 if ($jsconfirmmessage) {
1690 $button->button->add_confirm_action($jsconfirmmessage);
1693 $output = $OUTPUT->render($button);
1695 if ($return) {
1696 return $output;
1697 } else {
1698 echo $output;
1703 * Print a spacer image with the option of including a line break.
1705 * @deprecated since Moodle 2.0
1707 * @global object
1708 * @param int $height The height in pixels to make the spacer
1709 * @param int $width The width in pixels to make the spacer
1710 * @param boolean $br If set to true a BR is written after the spacer
1712 function print_spacer($height=1, $width=1, $br=true, $return=false) {
1713 global $CFG, $OUTPUT;
1715 debugging('print_spacer() has been deprecated. Please change your code to use $OUTPUT->spacer().');
1717 $output = $OUTPUT->spacer(array('height'=>$height, 'width'=>$width, 'br'=>$br));
1719 if ($return) {
1720 return $output;
1721 } else {
1722 echo $output;
1727 * Given the path to a picture file in a course, or a URL,
1728 * this function includes the picture in the page.
1730 * @deprecated since Moodle 2.0
1732 function print_file_picture($path, $courseid=0, $height='', $width='', $link='', $return=false) {
1733 throw new coding_exception('print_file_picture() has been deprecated since Moodle 2.0. Please use $OUTPUT->action_icon() instead.');
1737 * Print the specified user's avatar.
1739 * @deprecated since Moodle 2.0
1741 * @global object
1742 * @global object
1743 * @param mixed $user Should be a $user object with at least fields id, picture, imagealt, firstname, lastname, email
1744 * If any of these are missing, or if a userid is passed, the the database is queried. Avoid this
1745 * if at all possible, particularly for reports. It is very bad for performance.
1746 * @param int $courseid The course id. Used when constructing the link to the user's profile.
1747 * @param boolean $picture The picture to print. By default (or if NULL is passed) $user->picture is used.
1748 * @param int $size Size in pixels. Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility
1749 * @param boolean $return If false print picture to current page, otherwise return the output as string
1750 * @param boolean $link enclose printed image in a link the user's profile (default true).
1751 * @param string $target link target attribute. Makes the profile open in a popup window.
1752 * @param boolean $alttext add non-blank alt-text to the image. (Default true, set to false for purely
1753 * decorative images, or where the username will be printed anyway.)
1754 * @return string|void String or nothing, depending on $return.
1756 function print_user_picture($user, $courseid, $picture=NULL, $size=0, $return=false, $link=true, $target='', $alttext=true) {
1757 global $OUTPUT;
1759 debugging('print_user_picture() has been deprecated. Please change your code to use $OUTPUT->user_picture($user, array(\'courseid\'=>$courseid).');
1761 if (!is_object($user)) {
1762 $userid = $user;
1763 $user = new stdClass();
1764 $user->id = $userid;
1767 if (empty($user->picture) and $picture) {
1768 $user->picture = $picture;
1771 $options = array('size'=>$size, 'link'=>$link, 'alttext'=>$alttext, 'courseid'=>$courseid, 'popup'=>!empty($target));
1773 $output = $OUTPUT->user_picture($user, $options);
1775 if ($return) {
1776 return $output;
1777 } else {
1778 echo $output;
1783 * Print a png image.
1785 * @deprecated since Moodle 2.0: no replacement
1788 function print_png() {
1789 throw new coding_exception('print_png() has been deprecated since Moodle 2.0. Please use $OUTPUT->pix_icon() instead.');
1794 * Prints a basic textarea field.
1796 * @deprecated since Moodle 2.0
1798 * When using this function, you should
1800 * @global object
1801 * @param bool $usehtmleditor Enables the use of the htmleditor for this field.
1802 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1803 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1804 * @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.
1805 * @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.
1806 * @param string $name Name to use for the textarea element.
1807 * @param string $value Initial content to display in the textarea.
1808 * @param int $obsolete deprecated
1809 * @param bool $return If false, will output string. If true, will return string value.
1810 * @param string $id CSS ID to add to the textarea element.
1811 * @return string|void depending on the value of $return
1813 function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
1814 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1815 /// However, you can set them to zero to override the mincols and minrows values below.
1817 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1818 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
1820 global $CFG;
1822 $mincols = 65;
1823 $minrows = 10;
1824 $str = '';
1826 if ($id === '') {
1827 $id = 'edit-'.$name;
1830 if ($usehtmleditor) {
1831 if ($height && ($rows < $minrows)) {
1832 $rows = $minrows;
1834 if ($width && ($cols < $mincols)) {
1835 $cols = $mincols;
1839 if ($usehtmleditor) {
1840 editors_head_setup();
1841 $editor = editors_get_preferred_editor(FORMAT_HTML);
1842 $editor->use_editor($id, array('legacy'=>true));
1843 } else {
1844 $editorclass = '';
1847 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'">'."\n";
1848 if ($usehtmleditor) {
1849 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
1850 } else {
1851 $str .= s($value);
1853 $str .= '</textarea>'."\n";
1855 if ($return) {
1856 return $str;
1858 echo $str;
1863 * Print a help button.
1865 * @deprecated since Moodle 2.0
1867 * @param string $page The keyword that defines a help page
1868 * @param string $title The title of links, rollover tips, alt tags etc
1869 * 'Help with' (or the language equivalent) will be prefixed and '...' will be stripped.
1870 * @param string $module Which module is the page defined in
1871 * @param mixed $image Use a help image for the link? (true/false/"both")
1872 * @param boolean $linktext If true, display the title next to the help icon.
1873 * @param string $text If defined then this text is used in the page, and
1874 * the $page variable is ignored. DEPRECATED!
1875 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
1876 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif
1877 * @return string|void Depending on value of $return
1879 function helpbutton($page, $title, $module='moodle', $image=true, $linktext=false, $text='', $return=false, $imagetext='') {
1880 debugging('helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_icon().');
1882 global $OUTPUT;
1884 $output = $OUTPUT->old_help_icon($page, $title, $module, $linktext);
1886 // hide image with CSS if needed
1888 if ($return) {
1889 return $output;
1890 } else {
1891 echo $output;
1896 * Print a help button.
1898 * Prints a special help button that is a link to the "live" emoticon popup
1900 * @todo Finish documenting this function
1902 * @global object
1903 * @global object
1904 * @param string $form ?
1905 * @param string $field ?
1906 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.
1907 * @return string|void Depending on value of $return
1909 function emoticonhelpbutton($form, $field, $return = false) {
1910 /// TODO: MDL-21215
1912 debugging('emoticonhelpbutton() was removed, new text editors will implement this feature');
1916 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1917 * Should be used only with htmleditor or textarea.
1919 * @global object
1920 * @global object
1921 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1922 * helpbutton.
1923 * @return string Link to help button
1925 function editorhelpbutton(){
1926 return '';
1928 /// TODO: MDL-21215
1932 * Print a help button.
1934 * Prints a special help button for html editors (htmlarea in this case)
1936 * @todo Write code into this function! detect current editor and print correct info
1937 * @global object
1938 * @return string Only returns an empty string at the moment
1940 function editorshortcutshelpbutton() {
1941 /// TODO: MDL-21215
1943 global $CFG;
1944 //TODO: detect current editor and print correct info
1945 /* $imagetext = '<img src="' . $CFG->httpswwwroot . '/lib/editor/htmlarea/images/kbhelp.gif" alt="'.
1946 get_string('editorshortcutkeys').'" class="iconkbhelp" />';
1948 return helpbutton('editorshortcuts', get_string('editorshortcutkeys'), 'moodle', true, false, '', true, $imagetext);*/
1949 return '';
1954 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1955 * provide this function with the language strings for sortasc and sortdesc.
1957 * @deprecated since Moodle 2.0
1959 * TODO migrate to outputlib
1960 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1962 * @global object
1963 * @param string $direction 'up' or 'down'
1964 * @param string $strsort The language string used for the alt attribute of this image
1965 * @param bool $return Whether to print directly or return the html string
1966 * @return string|void depending on $return
1969 function print_arrow($direction='up', $strsort=null, $return=false) {
1970 // debugging('print_arrow() has been deprecated. Please change your code to use $OUTPUT->arrow().');
1972 global $OUTPUT;
1974 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1975 return null;
1978 $return = null;
1980 switch ($direction) {
1981 case 'up':
1982 $sortdir = 'asc';
1983 break;
1984 case 'down':
1985 $sortdir = 'desc';
1986 break;
1987 case 'move':
1988 $sortdir = 'asc';
1989 break;
1990 default:
1991 $sortdir = null;
1992 break;
1995 // Prepare language string
1996 $strsort = '';
1997 if (empty($strsort) && !empty($sortdir)) {
1998 $strsort = get_string('sort' . $sortdir, 'grades');
2001 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
2003 if ($return) {
2004 return $return;
2005 } else {
2006 echo $return;
2011 * Returns a string containing a link to the user documentation.
2012 * Also contains an icon by default. Shown to teachers and admin only.
2014 * @deprecated since Moodle 2.0
2016 * @global object
2017 * @param string $path The page link after doc root and language, no leading slash.
2018 * @param string $text The text to be displayed for the link
2019 * @param string $iconpath The path to the icon to be displayed
2020 * @return string Either the link or an empty string
2022 function doc_link($path='', $text='', $iconpath='ignored') {
2023 global $CFG, $OUTPUT;
2025 debugging('doc_link() has been deprecated. Please change your code to use $OUTPUT->doc_link().');
2027 if (empty($CFG->docroot)) {
2028 return '';
2031 return $OUTPUT->doc_link($path, $text);
2035 * Prints a single paging bar to provide access to other pages (usually in a search)
2037 * @deprecated since Moodle 2.0
2039 * @param int $totalcount Thetotal number of entries available to be paged through
2040 * @param int $page The page you are currently viewing
2041 * @param int $perpage The number of entries that should be shown per page
2042 * @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.
2043 * If this is a moodle_url object then the pagevar param will be replaced by the page no, for each page.
2044 * @param string $pagevar This is the variable name that you use for the page number in your code (ie. 'tablepage', 'blogpage', etc)
2045 * @param bool $nocurr do not display the current page as a link (dropped, link is never displayed for the current page)
2046 * @param bool $return whether to return an output string or echo now
2047 * @return bool|string depending on $result
2049 function print_paging_bar($totalcount, $page, $perpage, $baseurl, $pagevar='page',$nocurr=false, $return=false) {
2050 global $OUTPUT;
2052 debugging('print_paging_bar() has been deprecated. Please change your code to use $OUTPUT->render($pagingbar).');
2054 if (empty($nocurr)) {
2055 debugging('the feature of parameter $nocurr has been removed from the paging_bar');
2058 $pagingbar = new paging_bar($totalcount, $page, $perpage, $baseurl);
2059 $pagingbar->pagevar = $pagevar;
2060 $output = $OUTPUT->render($pagingbar);
2062 if ($return) {
2063 return $output;
2066 echo $output;
2067 return true;
2071 * Print a message along with "Yes" and "No" links for the user to continue.
2073 * @deprecated since Moodle 2.0
2075 * @global object
2076 * @param string $message The text to display
2077 * @param string $linkyes The link to take the user to if they choose "Yes"
2078 * @param string $linkno The link to take the user to if they choose "No"
2079 * @param string $optionyes The yes option to show on the notice
2080 * @param string $optionsno The no option to show
2081 * @param string $methodyes Form action method to use if yes [post, get]
2082 * @param string $methodno Form action method to use if no [post, get]
2083 * @return void Output is echo'd
2085 function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=NULL, $methodyes='post', $methodno='post') {
2087 debugging('notice_yesno() has been deprecated. Please change your code to use $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel).');
2089 global $OUTPUT;
2091 $buttoncontinue = new single_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
2092 $buttoncancel = new single_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);
2094 echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
2098 * Prints a scale menu (as part of an existing form) including help button
2099 * @deprecated since Moodle 2.0
2101 function print_scale_menu() {
2102 throw new coding_exception('print_scale_menu() has been deprecated since the Jurassic period. Get with the times!.');
2106 * Given an array of values, output the HTML for a select element with those options.
2108 * @deprecated since Moodle 2.0
2110 * Normally, you only need to use the first few parameters.
2112 * @param array $options The options to offer. An array of the form
2113 * $options[{value}] = {text displayed for that option};
2114 * @param string $name the name of this form control, as in &lt;select name="..." ...
2115 * @param string $selected the option to select initially, default none.
2116 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
2117 * Set this to '' if you don't want a 'nothing is selected' option.
2118 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
2119 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
2120 * @param boolean $return if false (the default) the the output is printed directly, If true, the
2121 * generated HTML is returned as a string.
2122 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
2123 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
2124 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
2125 * then a suitable one is constructed.
2126 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
2127 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
2128 * $listbox is an integer, that number is used for size instead.
2129 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
2130 * when $listbox display is enabled
2131 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
2132 * then a suitable one is constructed.
2133 * @return string|void If $return=true returns string, else echo's and returns void
2135 function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
2136 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
2137 $id='', $listbox=false, $multiple=false, $class='') {
2139 global $OUTPUT;
2140 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
2142 if ($script) {
2143 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2145 $attributes = array();
2146 $attributes['disabled'] = $disabled ? 'disabled' : null;
2147 $attributes['tabindex'] = $tabindex ? $tabindex : null;
2148 $attributes['multiple'] = $multiple ? $multiple : null;
2149 $attributes['class'] = $class ? $class : null;
2150 $attributes['id'] = $id ? $id : null;
2152 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
2154 if ($return) {
2155 return $output;
2156 } else {
2157 echo $output;
2162 * Choose value 0 or 1 from a menu with options 'No' and 'Yes'.
2163 * Other options like choose_from_menu.
2165 * @deprecated since Moodle 2.0
2167 * Calls {@link choose_from_menu()} with preset arguments
2168 * @see choose_from_menu()
2170 * @param string $name the name of this form control, as in &lt;select name="..." ...
2171 * @param string $selected the option to select initially, default none.
2172 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
2173 * @param boolean $return Whether this function should return a string or output it (defaults to false)
2174 * @param boolean $disabled (defaults to false)
2175 * @param int $tabindex
2176 * @return string|void If $return=true returns string, else echo's and returns void
2178 function choose_from_menu_yesno($name, $selected, $script = '', $return = false, $disabled = false, $tabindex = 0) {
2179 debugging('choose_from_menu_yesno() has been deprecated. Please change your code to use html_writer.');
2180 global $OUTPUT;
2182 if ($script) {
2183 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
2186 $output = html_writer::select_yes_no($name, $selected, array('disabled'=>($disabled ? 'disabled' : null), 'tabindex'=>$tabindex));
2188 if ($return) {
2189 return $output;
2190 } else {
2191 echo $output;
2196 * Just like choose_from_menu, but takes a nested array (2 levels) and makes a dropdown menu
2197 * including option headings with the first level.
2199 * @deprecated since Moodle 2.0
2201 * This function is very similar to {@link choose_from_menu_yesno()}
2202 * and {@link choose_from_menu()}
2204 * @todo Add datatype handling to make sure $options is an array
2206 * @param array $options An array of objects to choose from
2207 * @param string $name The XHTML field name
2208 * @param string $selected The value to select by default
2209 * @param string $nothing The label for the 'nothing is selected' option.
2210 * Defaults to get_string('choose').
2211 * @param string $script If not '', then this is added to the &lt;select> element
2212 * as an onchange handler.
2213 * @param string $nothingvalue The value for the first `nothing` option if $nothing is set
2214 * @param bool $return Whether this function should return a string or output
2215 * it (defaults to false)
2216 * @param bool $disabled Is the field disabled by default
2217 * @param int|string $tabindex Override the tabindex attribute [numeric]
2218 * @return string|void If $return=true returns string, else echo's and returns void
2220 function choose_from_menu_nested($options,$name,$selected='',$nothing='choose',$script = '',
2221 $nothingvalue=0,$return=false,$disabled=false,$tabindex=0) {
2223 debugging('choose_from_menu_nested() has been removed. Please change your code to use html_writer::select().');
2224 global $OUTPUT;
2228 * Prints a help button about a scale
2230 * @deprecated since Moodle 2.0
2232 * @global object
2233 * @param id $courseid
2234 * @param object $scale
2235 * @param boolean $return If set to true returns rather than echo's
2236 * @return string|bool Depending on value of $return
2238 function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
2239 // debugging('print_scale_menu_helpbutton() has been deprecated. Please change your code to use $OUTPUT->help_scale($courseid, $scale).');
2240 global $OUTPUT;
2242 $output = $OUTPUT->help_icon_scale($courseid, $scale);
2244 if ($return) {
2245 return $output;
2246 } else {
2247 echo $output;
2253 * Prints time limit value selector
2255 * @deprecated since Moodle 2.0
2257 * Uses {@link choose_from_menu()} to generate HTML
2258 * @see choose_from_menu()
2260 * @global object
2261 * @param int $timelimit default
2262 * @param string $unit
2263 * @param string $name
2264 * @param boolean $return If set to true returns rather than echo's
2265 * @return string|bool Depending on value of $return
2267 function print_timer_selector($timelimit = 0, $unit = '', $name = 'timelimit', $return=false) {
2268 throw new coding_exception('print_timer_selector is completely removed. Please use html_writer instead');
2272 * Prints form items with the names $hour and $minute
2274 * @deprecated since Moodle 2.0
2276 * @param string $hour fieldname
2277 * @param string $minute fieldname
2278 * @param int $currenttime A default timestamp in GMT
2279 * @param int $step minute spacing
2280 * @param boolean $return If set to true returns rather than echo's
2281 * @return string|bool Depending on value of $return
2283 function print_time_selector($hour, $minute, $currenttime=0, $step=5, $return=false) {
2284 debugging('print_time_selector() has been deprecated. Please change your code to use html_writer.');
2286 $hourselector = html_writer::select_time('hours', $hour, $currenttime);
2287 $minuteselector = html_writer::select_time('minutes', $minute, $currenttime, $step);
2289 $output = $hourselector . $$minuteselector;
2291 if ($return) {
2292 return $output;
2293 } else {
2294 echo $output;
2299 * Prints form items with the names $day, $month and $year
2301 * @deprecated since Moodle 2.0
2303 * @param string $day fieldname
2304 * @param string $month fieldname
2305 * @param string $year fieldname
2306 * @param int $currenttime A default timestamp in GMT
2307 * @param boolean $return If set to true returns rather than echo's
2308 * @return string|bool Depending on value of $return
2310 function print_date_selector($day, $month, $year, $currenttime=0, $return=false) {
2311 debugging('print_date_selector() has been deprecated. Please change your code to use html_writer.');
2313 $dayselector = html_writer::select_time('days', $day, $currenttime);
2314 $monthselector = html_writer::select_time('months', $month, $currenttime);
2315 $yearselector = html_writer::select_time('years', $year, $currenttime);
2317 $output = $dayselector . $monthselector . $yearselector;
2319 if ($return) {
2320 return $output;
2321 } else {
2322 echo $output;
2327 * Implements a complete little form with a dropdown menu.
2329 * @deprecated since Moodle 2.0
2331 * When JavaScript is on selecting an option from the dropdown automatically
2332 * submits the form (while avoiding the usual acessibility problems with this appoach).
2333 * With JavaScript off, a 'Go' button is printed.
2335 * @global object
2336 * @global object
2337 * @param string $baseurl The target URL up to the point of the variable that changes
2338 * @param array $options A list of value-label pairs for the popup list
2339 * @param string $formid id for the control. Must be unique on the page. Used in the HTML.
2340 * @param string $selected The option that is initially selected
2341 * @param string $nothing The label for the "no choice" option
2342 * @param string $help The name of a help page if help is required
2343 * @param string $helptext The name of the label for the help button
2344 * @param boolean $return Indicates whether the function should return the HTML
2345 * as a string or echo it directly to the page being rendered
2346 * @param string $targetwindow The name of the target page to open the linked page in.
2347 * @param string $selectlabel Text to place in a [label] element - preferred for accessibility.
2348 * @param array $optionsextra an array with the same keys as $options. The values are added within the corresponding <option ...> tag.
2349 * @param string $submitvalue Optional label for the 'Go' button. Defaults to get_string('go').
2350 * @param boolean $disabled If true, the menu will be displayed disabled.
2351 * @param boolean $showbutton If true, the button will always be shown even if JavaScript is available
2352 * @return string|void If $return=true returns string, else echo's and returns void
2354 function popup_form($baseurl, $options, $formid, $selected='', $nothing='choose', $help='', $helptext='', $return=false,
2355 $targetwindow='self', $selectlabel='', $optionsextra=NULL, $submitvalue='', $disabled=false, $showbutton=false) {
2356 global $OUTPUT, $CFG;
2358 debugging('popup_form() has been deprecated. Please change your code to use $OUTPUT->single_select() or $OUTPUT->url_select().');
2360 if (empty($options)) {
2361 return '';
2364 $urls = array();
2366 foreach ($options as $value=>$label) {
2367 $url = $baseurl.$value;
2368 $url = str_replace($CFG->wwwroot, '', $url);
2369 $url = str_replace('&amp;', '&', $url);
2370 $urls[$url] = $label;
2371 if ($selected == $value) {
2372 $active = $url;
2376 $nothing = $nothing ? array(''=>$nothing) : null;
2378 $select = new url_select($urls, $active, $nothing, $formid);
2379 $select->disabled = $disabled;
2381 $select->set_label($selectlabel);
2382 $select->set_old_help_icon($help, $helptext);
2384 $output = $OUTPUT->render($select);
2386 if ($return) {
2387 return $output;
2388 } else {
2389 echo $output;
2394 * Prints a simple button to close a window
2396 * @deprecated since Moodle 2.0
2398 * @global object
2399 * @param string $name Name of the window to close
2400 * @param boolean $return whether this function should return a string or output it.
2401 * @param boolean $reloadopener if true, clicking the button will also reload
2402 * the page that opend this popup window.
2403 * @return string|void if $return is true, void otherwise
2405 function close_window_button($name='closewindow', $return=false, $reloadopener = false) {
2406 global $OUTPUT;
2408 debugging('close_window_button() has been deprecated. Please change your code to use $OUTPUT->close_window_button().');
2409 $output = $OUTPUT->close_window_button(get_string($name));
2411 if ($return) {
2412 return $output;
2413 } else {
2414 echo $output;
2419 * Given an array of values, creates a group of radio buttons to be part of a form
2421 * @deprecated since Moodle 2.0
2423 * @staticvar int $idcounter
2424 * @param array $options An array of value-label pairs for the radio group (values as keys)
2425 * @param string $name Name of the radiogroup (unique in the form)
2426 * @param string $checked The value that is already checked
2427 * @param bool $return Whether this function should return a string or output
2428 * it (defaults to false)
2429 * @return string|void If $return=true returns string, else echo's and returns void
2431 function choose_from_radio ($options, $name, $checked='', $return=false) {
2432 debugging('choose_from_radio() has been removed. Please change your code to use html_writer.');
2436 * Display an standard html checkbox with an optional label
2438 * @deprecated since Moodle 2.0
2440 * @staticvar int $idcounter
2441 * @param string $name The name of the checkbox
2442 * @param string $value The valus that the checkbox will pass when checked
2443 * @param bool $checked The flag to tell the checkbox initial state
2444 * @param string $label The label to be showed near the checkbox
2445 * @param string $alt The info to be inserted in the alt tag
2446 * @param string $script If not '', then this is added to the checkbox element
2447 * as an onchange handler.
2448 * @param bool $return Whether this function should return a string or output
2449 * it (defaults to false)
2450 * @return string|void If $return=true returns string, else echo's and returns void
2452 function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
2454 // debugging('print_checkbox() has been deprecated. Please change your code to use html_writer::checkbox().');
2455 global $OUTPUT;
2457 if (!empty($script)) {
2458 debugging('The use of the $script param in print_checkbox has not been migrated into html_writer::checkbox().', DEBUG_DEVELOPER);
2461 $output = html_writer::checkbox($name, $value, $checked, $label);
2463 if (empty($return)) {
2464 echo $output;
2465 } else {
2466 return $output;
2473 * Display an standard html text field with an optional label
2475 * @deprecated since Moodle 2.0
2477 * @param string $name The name of the text field
2478 * @param string $value The value of the text field
2479 * @param string $alt The info to be inserted in the alt tag
2480 * @param int $size Sets the size attribute of the field. Defaults to 50
2481 * @param int $maxlength Sets the maxlength attribute of the field. Not set by default
2482 * @param bool $return Whether this function should return a string or output
2483 * it (defaults to false)
2484 * @return string|void If $return=true returns string, else echo's and returns void
2486 function print_textfield($name, $value, $alt = '', $size=50, $maxlength=0, $return=false) {
2487 debugging('print_textfield() has been deprecated. Please use mforms or html_writer.');
2489 if ($alt === '') {
2490 $alt = null;
2493 $style = "width: {$size}px;";
2494 $attributes = array('type'=>'text', 'name'=>$name, 'alt'=>$alt, 'style'=>$style, 'value'=>$value);
2495 if ($maxlength) {
2496 $attributes['maxlength'] = $maxlength;
2499 $output = html_writer::empty_tag('input', $attributes);
2501 if (empty($return)) {
2502 echo $output;
2503 } else {
2504 return $output;
2510 * Centered heading with attached help button (same title text)
2511 * and optional icon attached
2513 * @deprecated since Moodle 2.0
2515 * @param string $text The text to be displayed
2516 * @param string $helppage The help page to link to
2517 * @param string $module The module whose help should be linked to
2518 * @param string $icon Image to display if needed
2519 * @param bool $return If set to true output is returned rather than echoed, default false
2520 * @return string|void String if return=true nothing otherwise
2522 function print_heading_with_help($text, $helppage, $module='moodle', $icon=false, $return=false) {
2524 debugging('print_heading_with_help() has been deprecated. Please change your code to use $OUTPUT->heading().');
2526 global $OUTPUT;
2528 // Extract the src from $icon if it exists
2529 if (preg_match('/src="([^"]*)"/', $icon, $matches)) {
2530 $icon = $matches[1];
2531 $icon = new moodle_url($icon);
2532 } else {
2533 $icon = '';
2536 $output = $OUTPUT->heading_with_help($text, $helppage, $module, $icon);
2538 if ($return) {
2539 return $output;
2540 } else {
2541 echo $output;
2546 * Returns a turn edit on/off button for course in a self contained form.
2547 * Used to be an icon, but it's now a simple form button
2548 * @deprecated since Moodle 2.0
2550 function update_mymoodle_icon() {
2551 throw new coding_exception('update_mymoodle_icon() has been completely deprecated.');
2555 * Returns a turn edit on/off button for tag in a self contained form.
2556 * @deprecated since Moodle 2.0
2557 * @param string $tagid The ID attribute
2558 * @return string
2560 function update_tag_button($tagid) {
2561 global $OUTPUT;
2562 debugging('update_tag_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2563 return $OUTPUT->edit_button(new moodle_url('/tag/index.php', array('id' => $tagid)));
2568 * Prints the 'update this xxx' button that appears on module pages.
2570 * @deprecated since Moodle 2.0
2572 * @param string $cmid the course_module id.
2573 * @param string $ignored not used any more. (Used to be courseid.)
2574 * @param string $string the module name - get_string('modulename', 'xxx')
2575 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
2577 function update_module_button($cmid, $ignored, $string) {
2578 global $CFG, $OUTPUT;
2580 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
2582 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
2584 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
2585 $string = get_string('updatethis', '', $string);
2587 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
2588 return $OUTPUT->single_button($url, $string);
2589 } else {
2590 return '';
2595 * Prints the editing button on search results listing
2596 * For bulk move courses to another category
2597 * @deprecated since Moodle 2.0
2599 function update_categories_search_button($search,$page,$perpage) {
2600 throw new coding_exception('update_categories_search_button() has been completely deprecated.');
2604 * Prints a summary of a user in a nice little box.
2605 * @deprecated since Moodle 2.0
2607 function print_user($user, $course, $messageselect=false, $return=false) {
2608 throw new coding_exception('print_user() has been completely deprecated. See user/index.php for new usage.');
2612 * Returns a turn edit on/off button for course in a self contained form.
2613 * Used to be an icon, but it's now a simple form button
2615 * Note that the caller is responsible for capchecks.
2617 * @global object
2618 * @global object
2619 * @param int $courseid The course to update by id as found in 'course' table
2620 * @return string
2622 function update_course_icon($courseid) {
2623 global $CFG, $OUTPUT;
2625 debugging('update_course_button() has been deprecated. Please change your code to use $OUTPUT->edit_button(moodle_url).');
2627 return $OUTPUT->edit_button(new moodle_url('/course/view.php', array('id' => $courseid)));
2631 * Prints breadcrumb trail of links, called in theme/-/header.html
2633 * This function has now been deprecated please use output's navbar method instead
2634 * as shown below
2636 * <code php>
2637 * echo $OUTPUT->navbar();
2638 * </code>
2640 * @deprecated since 2.0
2641 * @param mixed $navigation deprecated
2642 * @param string $separator OBSOLETE, and now deprecated
2643 * @param boolean $return False to echo the breadcrumb string (default), true to return it.
2644 * @return string|void String or null, depending on $return.
2646 function print_navigation ($navigation, $separator=0, $return=false) {
2647 global $OUTPUT,$PAGE;
2649 # debugging('print_navigation has been deprecated please update your theme to use $OUTPUT->navbar() instead', DEBUG_DEVELOPER);
2651 $output = $OUTPUT->navbar();
2653 if ($return) {
2654 return $output;
2655 } else {
2656 echo $output;
2661 * This function will build the navigation string to be used by print_header
2662 * and others.
2664 * It automatically generates the site and course level (if appropriate) links.
2666 * If you pass in a $cm object, the method will also generate the activity (e.g. 'Forums')
2667 * and activityinstances (e.g. 'General Developer Forum') navigation levels.
2669 * If you want to add any further navigation links after the ones this function generates,
2670 * the pass an array of extra link arrays like this:
2671 * array(
2672 * array('name' => $linktext1, 'link' => $url1, 'type' => $linktype1),
2673 * array('name' => $linktext2, 'link' => $url2, 'type' => $linktype2)
2675 * The normal case is to just add one further link, for example 'Editing forum' after
2676 * 'General Developer Forum', with no link.
2677 * To do that, you need to pass
2678 * array(array('name' => $linktext, 'link' => '', 'type' => 'title'))
2679 * However, becuase this is a very common case, you can use a shortcut syntax, and just
2680 * pass the string 'Editing forum', instead of an array as $extranavlinks.
2682 * At the moment, the link types only have limited significance. Type 'activity' is
2683 * recognised in order to implement the $CFG->hideactivitytypenavlink feature. Types
2684 * that are known to appear are 'home', 'course', 'activity', 'activityinstance' and 'title'.
2685 * This really needs to be documented better. In the mean time, try to be consistent, it will
2686 * enable people to customise the navigation more in future.
2688 * When passing a $cm object, the fields used are $cm->modname, $cm->name and $cm->course.
2689 * If you get the $cm object using the function get_coursemodule_from_instance or
2690 * get_coursemodule_from_id (as recommended) then this will be done for you automatically.
2691 * If you don't have $cm->modname or $cm->name, this fuction will attempt to find them using
2692 * the $cm->module and $cm->instance fields, but this takes extra database queries, so a
2693 * warning is printed in developer debug mode.
2695 * @deprecated since 2.0
2696 * @param mixed $extranavlinks - Normally an array of arrays, keys: name, link, type. If you
2697 * only want one extra item with no link, you can pass a string instead. If you don't want
2698 * any extra links, pass an empty string.
2699 * @param mixed $cm deprecated
2700 * @return array Navigation array
2702 function build_navigation($extranavlinks, $cm = null) {
2703 global $CFG, $COURSE, $DB, $SITE, $PAGE;
2705 if (is_array($extranavlinks) && count($extranavlinks)>0) {
2706 # debugging('build_navigation() has been deprecated, please replace with $PAGE->navbar methods', DEBUG_DEVELOPER);
2707 foreach ($extranavlinks as $nav) {
2708 if (array_key_exists('name', $nav)) {
2709 if (array_key_exists('link', $nav) && !empty($nav['link'])) {
2710 $link = $nav['link'];
2711 } else {
2712 $link = null;
2714 $PAGE->navbar->add($nav['name'],$link);
2719 return(array('newnav' => true, 'navlinks' => array()));
2723 * Returns a small popup menu of course activity modules
2725 * Given a course and a (current) coursemodule
2726 * his function returns a small popup menu with all the
2727 * course activity modules in it, as a navigation menu
2728 * The data is taken from the serialised array stored in
2729 * the course record
2731 * @global object
2732 * @global object
2733 * @global object
2734 * @global object
2735 * @uses CONTEXT_COURSE
2736 * @param object $course A {@link $COURSE} object.
2737 * @param object $cm A {@link $COURSE} object.
2738 * @param string $targetwindow The target window attribute to us
2739 * @return string
2741 function navmenu($course, $cm=NULL, $targetwindow='self') {
2742 // This function has been deprecated with the creation of the global nav in
2743 // moodle 2.0
2745 return '';
2749 * Returns a little popup menu for switching roles
2751 * @deprecated in Moodle 2.0
2752 * @param int $courseid The course to update by id as found in 'course' table
2753 * @return string
2755 function switchroles_form($courseid) {
2756 debugging('switchroles_form() has been deprecated and replaced by an item in the global settings block');
2757 return '';
2761 * Print header for admin page
2762 * @deprecated since Moodle 20. Please use normal $OUTPUT->header() instead
2763 * @param string $focus focus element
2765 function admin_externalpage_print_header($focus='') {
2766 global $OUTPUT;
2768 debugging('admin_externalpage_print_header is deprecated. Please $OUTPUT->header() instead.', DEBUG_DEVELOPER);
2770 echo $OUTPUT->header();
2774 * @deprecated since Moodle 1.9. Please use normal $OUTPUT->footer() instead
2776 function admin_externalpage_print_footer() {
2777 // TODO Still 103 referernces in core code. Don't do debugging output yet.
2778 debugging('admin_externalpage_print_footer is deprecated. Please $OUTPUT->footer() instead.', DEBUG_DEVELOPER);
2779 global $OUTPUT;
2780 echo $OUTPUT->footer();
2783 /// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
2787 * Call this function to add an event to the calendar table and to call any calendar plugins
2789 * @param object $event An object representing an event from the calendar table.
2790 * The event will be identified by the id field. The object event should include the following:
2791 * <ul>
2792 * <li><b>$event->name</b> - Name for the event
2793 * <li><b>$event->description</b> - Description of the event (defaults to '')
2794 * <li><b>$event->format</b> - Format for the description (using formatting types defined at the top of weblib.php)
2795 * <li><b>$event->courseid</b> - The id of the course this event belongs to (0 = all courses)
2796 * <li><b>$event->groupid</b> - The id of the group this event belongs to (0 = no group)
2797 * <li><b>$event->userid</b> - The id of the user this event belongs to (0 = no user)
2798 * <li><b>$event->modulename</b> - Name of the module that creates this event
2799 * <li><b>$event->instance</b> - Instance of the module that owns this event
2800 * <li><b>$event->eventtype</b> - The type info together with the module info could
2801 * be used by calendar plugins to decide how to display event
2802 * <li><b>$event->timestart</b>- Timestamp for start of event
2803 * <li><b>$event->timeduration</b> - Duration (defaults to zero)
2804 * <li><b>$event->visible</b> - 0 if the event should be hidden (e.g. because the activity that created it is hidden)
2805 * </ul>
2806 * @return int|false The id number of the resulting record or false if failed
2808 function add_event($event) {
2809 global $CFG;
2810 require_once($CFG->dirroot.'/calendar/lib.php');
2811 $event = calendar_event::create($event);
2812 if ($event !== false) {
2813 return $event->id;
2815 return false;
2819 * Call this function to update an event in the calendar table
2820 * the event will be identified by the id field of the $event object.
2822 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2823 * @return bool Success
2825 function update_event($event) {
2826 global $CFG;
2827 require_once($CFG->dirroot.'/calendar/lib.php');
2828 $event = (object)$event;
2829 $calendarevent = calendar_event::load($event->id);
2830 return $calendarevent->update($event);
2834 * Call this function to delete the event with id $id from calendar table.
2836 * @param int $id The id of an event from the 'event' table.
2837 * @return bool
2839 function delete_event($id) {
2840 global $CFG;
2841 require_once($CFG->dirroot.'/calendar/lib.php');
2842 $event = calendar_event::load($id);
2843 return $event->delete();
2847 * Call this function to hide an event in the calendar table
2848 * the event will be identified by the id field of the $event object.
2850 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2851 * @return true
2853 function hide_event($event) {
2854 global $CFG;
2855 require_once($CFG->dirroot.'/calendar/lib.php');
2856 $event = new calendar_event($event);
2857 return $event->toggle_visibility(false);
2861 * Call this function to unhide an event in the calendar table
2862 * the event will be identified by the id field of the $event object.
2864 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
2865 * @return true
2867 function show_event($event) {
2868 global $CFG;
2869 require_once($CFG->dirroot.'/calendar/lib.php');
2870 $event = new calendar_event($event);
2871 return $event->toggle_visibility(true);
2875 * Converts string to lowercase using most compatible function available.
2877 * @deprecated Use textlib::strtolower($text) instead.
2879 * @param string $string The string to convert to all lowercase characters.
2880 * @param string $encoding The encoding on the string.
2881 * @return string
2883 function moodle_strtolower($string, $encoding='') {
2885 debugging('moodle_strtolower() is deprecated. Please use textlib::strtolower() instead.', DEBUG_DEVELOPER);
2887 //If not specified use utf8
2888 if (empty($encoding)) {
2889 $encoding = 'UTF-8';
2891 //Use text services
2892 return textlib::strtolower($string, $encoding);
2896 * Original singleton helper function, please use static methods instead,
2897 * ex: textlib::convert()
2899 * @deprecated since Moodle 2.2 use textlib::xxxx() instead
2900 * @see textlib
2901 * @return textlib instance
2903 function textlib_get_instance() {
2905 debugging('textlib_get_instance() is deprecated. Please use static calling textlib::functioname() instead.', DEBUG_DEVELOPER);
2907 return new textlib();
2911 * Gets the generic section name for a courses section
2913 * The global function is deprecated. Each course format can define their own generic section name
2915 * @deprecated since 2.4
2916 * @see get_section_name()
2917 * @see format_base::get_section_name()
2919 * @param string $format Course format ID e.g. 'weeks' $course->format
2920 * @param stdClass $section Section object from database
2921 * @return Display name that the course format prefers, e.g. "Week 2"
2923 function get_generic_section_name($format, stdClass $section) {
2924 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
2925 return get_string('sectionname', "format_$format") . ' ' . $section->section;
2929 * Returns an array of sections for the requested course id
2931 * It is usually not recommended to display the list of sections used
2932 * in course because the course format may have it's own way to do it.
2934 * If you need to just display the name of the section please call:
2935 * get_section_name($course, $section)
2936 * {@link get_section_name()}
2937 * from 2.4 $section may also be just the field course_sections.section
2939 * If you need the list of all sections it is more efficient to get this data by calling
2940 * $modinfo = get_fast_modinfo($courseorid);
2941 * $sections = $modinfo->get_section_info_all()
2942 * {@link get_fast_modinfo()}
2943 * {@link course_modinfo::get_section_info_all()}
2945 * Information about one section (instance of section_info):
2946 * get_fast_modinfo($courseorid)->get_sections_info($section)
2947 * {@link course_modinfo::get_section_info()}
2949 * @deprecated since 2.4
2951 * @param int $courseid
2952 * @return array Array of section_info objects
2954 function get_all_sections($courseid) {
2955 global $DB;
2956 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
2957 return get_fast_modinfo($courseid)->get_section_info_all();
2961 * Given a full mod object with section and course already defined, adds this module to that section.
2963 * This function is deprecated, please use {@link course_add_cm_to_section()}
2964 * Note that course_add_cm_to_section() also updates field course_modules.section and
2965 * calls rebuild_course_cache()
2967 * @deprecated since 2.4
2969 * @param object $mod
2970 * @param int $beforemod An existing ID which we will insert the new module before
2971 * @return int The course_sections ID where the mod is inserted
2973 function add_mod_to_section($mod, $beforemod = null) {
2974 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
2975 global $DB;
2976 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
2980 * Returns a number of useful structures for course displays
2982 * Function get_all_mods() is deprecated in 2.4
2983 * Instead of:
2984 * <code>
2985 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
2986 * </code>
2987 * please use:
2988 * <code>
2989 * $mods = get_fast_modinfo($courseorid)->get_cms();
2990 * $modnames = get_module_types_names();
2991 * $modnamesplural = get_module_types_names(true);
2992 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
2993 * </code>
2995 * @deprecated since 2.4
2997 * @param int $courseid id of the course to get info about
2998 * @param array $mods (return) list of course modules
2999 * @param array $modnames (return) list of names of all module types installed and available
3000 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
3001 * @param array $modnamesused (return) list of names of all module types used in the course
3003 function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
3004 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
3006 global $COURSE;
3007 $modnames = get_module_types_names();
3008 $modnamesplural= get_module_types_names(true);
3009 $modinfo = get_fast_modinfo($courseid);
3010 $mods = $modinfo->get_cms();
3011 $modnamesused = $modinfo->get_used_module_names();
3015 * Returns course section - creates new if does not exist yet
3017 * This function is deprecated. To create a course section call:
3018 * course_create_sections_if_missing($courseorid, $sections);
3019 * to get the section call:
3020 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
3022 * @see course_create_sections_if_missing()
3023 * @see get_fast_modinfo()
3024 * @deprecated since 2.4
3026 * @param int $section relative section number (field course_sections.section)
3027 * @param int $courseid
3028 * @return stdClass record from table {course_sections}
3030 function get_course_section($section, $courseid) {
3031 global $DB;
3032 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
3034 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
3035 return $cw;
3037 $cw = new stdClass();
3038 $cw->course = $courseid;
3039 $cw->section = $section;
3040 $cw->summary = "";
3041 $cw->summaryformat = FORMAT_HTML;
3042 $cw->sequence = "";
3043 $id = $DB->insert_record("course_sections", $cw);
3044 rebuild_course_cache($courseid, true);
3045 return $DB->get_record("course_sections", array("id"=>$id));
3049 * Return the start and end date of the week in Weekly course format
3051 * It is not recommended to use this function outside of format_weeks plugin
3053 * @deprecated since 2.4
3054 * @see format_weeks::get_section_dates()
3056 * @param stdClass $section The course_section entry from the DB
3057 * @param stdClass $course The course entry from DB
3058 * @return stdClass property start for startdate, property end for enddate
3060 function format_weeks_get_section_dates($section, $course) {
3061 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
3062 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
3063 if (isset($course->format) && $course->format === 'weeks') {
3064 return course_get_format($course)->get_section_dates($section);
3066 return null;