MDL-50049 deprecation: Group together long term deprecated apis
[moodle.git] / lib / deprecatedlib.php
CommitLineData
c861fe2f 1<?php
2
a5cb8d69 3// This file is part of Moodle - http://moodle.org/
4//
c861fe2f 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.
a5cb8d69 14//
c861fe2f 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/>.
c4d0753b 17
18/**
19 * deprecatedlib.php - Old functions retained only for backward compatibility
20 *
21 * Old functions retained only for backward compatibility. New code should not
22 * use any of these functions.
23 *
78bfb562 24 * @package core
c861fe2f 25 * @subpackage deprecated
78bfb562
PS
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
c861fe2f 28 * @deprecated
c4d0753b 29 */
30
78bfb562
PS
31defined('MOODLE_INTERNAL') || die();
32
33c46db5
AA
33/* === Functions that needs to be kept longer in deprecated lib than normal time period === */
34
35/**
36 * Add an entry to the legacy log table.
37 *
38 * @deprecated since 2.7 use new events instead
39 *
40 * @param int $courseid The course id
41 * @param string $module The module name e.g. forum, journal, resource, course, user etc
42 * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
43 * @param string $url The file and parameters used to see the results of the action
44 * @param string $info Additional description information
45 * @param int $cm The course_module->id if there is one
46 * @param int|stdClass $user If log regards $user other than $USER
47 * @return void
48 */
49function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
50 debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);
51
52 // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
53 // this way we may move all the legacy settings there too.
54 $manager = get_log_manager();
55 if (method_exists($manager, 'legacy_add_to_log')) {
56 $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
57 }
58}
59
60/**
61 * Function to call all event handlers when triggering an event
62 *
63 * @deprecated since 2.6
64 *
65 * @param string $eventname name of the event
66 * @param mixed $eventdata event data object
67 * @return int number of failed events
68 */
69function events_trigger($eventname, $eventdata) {
70 debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
71 return events_trigger_legacy($eventname, $eventdata);
72}
73
74/**
75 * List all core subsystems and their location
76 *
77 * This is a whitelist of components that are part of the core and their
78 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
79 * plugin is not listed here and it does not have proper plugintype prefix,
80 * then it is considered as course activity module.
81 *
82 * The location is optionally dirroot relative path. NULL means there is no special
83 * directory for this subsystem. If the location is set, the subsystem's
84 * renderer.php is expected to be there.
85 *
86 * @deprecated since 2.6, use core_component::get_core_subsystems()
87 *
88 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
89 * @return array of (string)name => (string|null)location
90 */
91function get_core_subsystems($fullpaths = false) {
92 global $CFG;
93
94 // NOTE: do not add any other debugging here, keep forever.
95
96 $subsystems = core_component::get_core_subsystems();
97
98 if ($fullpaths) {
99 return $subsystems;
100 }
101
102 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
103
104 $dlength = strlen($CFG->dirroot);
105
106 foreach ($subsystems as $k => $v) {
107 if ($v === null) {
108 continue;
109 }
110 $subsystems[$k] = substr($v, $dlength+1);
111 }
112
113 return $subsystems;
114}
115
116/**
117 * Lists all plugin types.
118 *
119 * @deprecated since 2.6, use core_component::get_plugin_types()
120 *
121 * @param bool $fullpaths false means relative paths from dirroot
122 * @return array Array of strings - name=>location
123 */
124function get_plugin_types($fullpaths = true) {
125 global $CFG;
126
127 // NOTE: do not add any other debugging here, keep forever.
128
129 $types = core_component::get_plugin_types();
130
131 if ($fullpaths) {
132 return $types;
133 }
134
135 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
136
137 $dlength = strlen($CFG->dirroot);
138
139 foreach ($types as $k => $v) {
140 if ($k === 'theme') {
141 $types[$k] = 'theme';
142 continue;
143 }
144 $types[$k] = substr($v, $dlength+1);
145 }
146
147 return $types;
148}
149
150/**
151 * Use when listing real plugins of one type.
152 *
153 * @deprecated since 2.6, use core_component::get_plugin_list()
154 *
155 * @param string $plugintype type of plugin
156 * @return array name=>fulllocation pairs of plugins of given type
157 */
158function get_plugin_list($plugintype) {
159
160 // NOTE: do not add any other debugging here, keep forever.
161
162 if ($plugintype === '') {
163 $plugintype = 'mod';
164 }
165
166 return core_component::get_plugin_list($plugintype);
167}
168
169/**
170 * Get a list of all the plugins of a given type that define a certain class
171 * in a certain file. The plugin component names and class names are returned.
172 *
173 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
174 *
175 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
176 * @param string $class the part of the name of the class after the
177 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
178 * names like report_courselist_thing. If you are looking for classes with
179 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
180 * @param string $file the name of file within the plugin that defines the class.
181 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
182 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
183 */
184function get_plugin_list_with_class($plugintype, $class, $file) {
185
186 // NOTE: do not add any other debugging here, keep forever.
187
188 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
189}
190
191/**
192 * Returns the exact absolute path to plugin directory.
193 *
194 * @deprecated since 2.6, use core_component::get_plugin_directory()
195 *
196 * @param string $plugintype type of plugin
197 * @param string $name name of the plugin
198 * @return string full path to plugin directory; NULL if not found
199 */
200function get_plugin_directory($plugintype, $name) {
201
202 // NOTE: do not add any other debugging here, keep forever.
203
204 if ($plugintype === '') {
205 $plugintype = 'mod';
206 }
207
208 return core_component::get_plugin_directory($plugintype, $name);
209}
210
211/**
212 * Normalize the component name using the "frankenstyle" names.
213 *
214 * @deprecated since 2.6, use core_component::normalize_component()
215 *
216 * @param string $component
217 * @return array as (string)$type => (string)$plugin
218 */
219function normalize_component($component) {
220
221 // NOTE: do not add any other debugging here, keep forever.
222
223 return core_component::normalize_component($component);
224}
225
226/**
227 * Return exact absolute path to a plugin directory.
228 *
229 * @deprecated since 2.6, use core_component::normalize_component()
230 *
231 * @param string $component name such as 'moodle', 'mod_forum'
232 * @return string full path to component directory; NULL if not found
233 */
234function get_component_directory($component) {
235
236 // NOTE: do not add any other debugging here, keep forever.
237
238 return core_component::get_component_directory($component);
239}
240
241/**
242 * Get the context instance as an object. This function will create the
243 * context instance if it does not exist yet.
244 *
245 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
246 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
247 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
248 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
249 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
250 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
251 * MUST_EXIST means throw exception if no record or multiple records found
252 * @return context The context object.
253 */
254function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
255
256 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
257
258 $instances = (array)$instance;
259 $contexts = array();
260
261 $classname = context_helper::get_class_for_level($contextlevel);
262
263 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
264 foreach ($instances as $inst) {
265 $contexts[$inst] = $classname::instance($inst, $strictness);
266 }
267
268 if (is_array($instance)) {
269 return $contexts;
270 } else {
271 return $contexts[$instance];
272 }
273}
274/* === End of long term deprecated api list === */
275
d6e7a63d
PS
276/**
277 * Convert region timezone to php supported timezone
278 *
279 * @deprecated since Moodle 2.9
280 * @param string $tz value from ical file
281 * @return string $tz php supported timezone
282 */
283function calendar_normalize_tz($tz) {
284 debugging('calendar_normalize_tz() is deprecated, use core_date::normalise_timezone() instead', DEBUG_DEVELOPER);
285 return core_date::normalise_timezone($tz);
286}
287
288/**
289 * Returns a float which represents the user's timezone difference from GMT in hours
290 * Checks various settings and picks the most dominant of those which have a value
291 * @deprecated since Moodle 2.9
292 * @param float|int|string $tz timezone user timezone
293 * @return float
294 */
295function get_user_timezone_offset($tz = 99) {
296 debugging('get_user_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER);
297 $tz = core_date::get_user_timezone($tz);
298 $date = new DateTime('now', new DateTimeZone($tz));
299 return ($date->getOffset() - dst_offset_on(time(), $tz)) / (3600.0);
300}
301
302/**
303 * Returns an int which represents the systems's timezone difference from GMT in seconds
304 * @deprecated since Moodle 2.9
305 * @param float|int|string $tz timezone for which offset is required.
306 * {@link http://docs.moodle.org/dev/Time_API#Timezone}
307 * @return int|bool if found, false is timezone 99 or error
308 */
309function get_timezone_offset($tz) {
310 debugging('get_timezone_offset() is deprecated, use PHP DateTimeZone instead', DEBUG_DEVELOPER);
311 $date = new DateTime('now', new DateTimeZone(core_date::normalise_timezone($tz)));
312 return $date->getOffset() - dst_offset_on(time(), $tz);
313}
314
315/**
316 * Returns a list of timezones in the current language.
317 * @deprecated since Moodle 2.9
318 * @return array
319 */
320function get_list_of_timezones() {
e49cb057 321 debugging('get_list_of_timezones() is deprecated, use core_date::get_list_of_timezones() instead', DEBUG_DEVELOPER);
d6e7a63d
PS
322 return core_date::get_list_of_timezones();
323}
324
325/**
326 * Previous internal API, it was not supposed to be used anywhere.
327 * @deprecated since Moodle 2.9
328 * @param array $timezones
329 */
330function update_timezone_records($timezones) {
331 debugging('update_timezone_records() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
332}
333
334/**
335 * Previous internal API, it was not supposed to be used anywhere.
336 * @deprecated since Moodle 2.9
337 * @param int $fromyear
338 * @param int $toyear
339 * @param mixed $strtimezone
340 * @return bool
341 */
342function calculate_user_dst_table($fromyear = null, $toyear = null, $strtimezone = null) {
343 debugging('calculate_user_dst_table() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
344 return false;
345}
346
347/**
348 * Previous internal API, it was not supposed to be used anywhere.
349 * @deprecated since Moodle 2.9
350 * @param int|string $year
351 * @param mixed $timezone
352 * @return null
353 */
354function dst_changes_for_year($year, $timezone) {
355 debugging('dst_changes_for_year() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
356 return null;
357}
358
359/**
360 * Previous internal API, it was not supposed to be used anywhere.
361 * @deprecated since Moodle 2.9
362 * @param string $timezonename
363 * @return array
364 */
365function get_timezone_record($timezonename) {
366 debugging('get_timezone_record() is not available any more, use standard PHP date/time code', DEBUG_DEVELOPER);
367 return array();
368}
369
7eaca5a8 370
7eaca5a8 371
114e3209
372/**
373 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
374 *
375 * @deprecated since 2.7 - use new file picker instead
376 *
114e3209
377 */
378function clam_log_upload($newfilepath, $course=null, $nourl=false) {
6dd7175a 379 throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
114e3209
380}
381
382/**
383 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
384 *
385 * @deprecated since 2.7 - use new file picker instead
386 *
114e3209
387 */
388function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
6dd7175a 389 throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
114e3209
390}
391
392/**
393 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
394 *
395 * @deprecated since 2.7 - use new file picker instead
396 *
114e3209
397 */
398function clam_change_log($oldpath, $newpath, $update=true) {
6dd7175a 399 throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
114e3209
400}
401
402/**
403 * Replaces the given file with a string.
404 *
405 * @deprecated since 2.7 - infected files are now deleted in file picker
406 *
114e3209
407 */
408function clam_replace_infected_file($file) {
6dd7175a 409 throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
114e3209
410}
411
7293a1aa
DP
412/**
413 * Deals with an infected file - either moves it to a quarantinedir
414 * (specified in CFG->quarantinedir) or deletes it.
415 *
416 * If moving it fails, it deletes it.
417 *
418 * @deprecated since 2.7
419 */
420function clam_handle_infected_file($file, $userid=0, $basiconly=false) {
421 throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
422}
423
424/**
425 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
426 *
427 * @deprecated since 2.7
428 */
429function clam_scan_moodle_file(&$file, $course) {
430 throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
431}
432
433
6780a1d3
434/**
435 * Checks whether the password compatibility library will work with the current
436 * version of PHP. This cannot be done using PHP version numbers since the fix
437 * has been backported to earlier versions in some distributions.
438 *
439 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
440 *
441 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
442 *
6780a1d3
443 */
444function password_compat_not_supported() {
1ac1d29b 445 throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available');
6780a1d3
446}
447
d79d5ac2
PS
448/**
449 * Factory method that was returning moodle_session object.
450 *
451 * @deprecated since 2.6
d79d5ac2
PS
452 */
453function session_get_instance() {
1ac1d29b 454 throw new coding_exception('session_get_instance() is deprecated, use \core\session\manager instead');
d79d5ac2
PS
455}
456
457/**
458 * Returns true if legacy session used.
459 *
460 * @deprecated since 2.6
d79d5ac2
PS
461 */
462function session_is_legacy() {
1ac1d29b 463 throw new coding_exception('session_is_legacy() is deprecated, do not use any more');
d79d5ac2
PS
464}
465
466/**
467 * Terminates all sessions, auth hooks are not executed.
d79d5ac2
PS
468 *
469 * @deprecated since 2.6
470 */
471function session_kill_all() {
1ac1d29b 472 throw new coding_exception('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead');
d79d5ac2
PS
473}
474
475/**
476 * Mark session as accessed, prevents timeouts.
477 *
478 * @deprecated since 2.6
d79d5ac2
PS
479 */
480function session_touch($sid) {
1ac1d29b 481 throw new coding_exception('session_touch() is deprecated, use \core\session\manager::touch_session() instead');
d79d5ac2
PS
482}
483
484/**
485 * Terminates one sessions, auth hooks are not executed.
486 *
487 * @deprecated since 2.6
d79d5ac2
PS
488 */
489function session_kill($sid) {
1ac1d29b 490 throw new coding_exception('session_kill() is deprecated, use \core\session\manager::kill_session() instead');
d79d5ac2
PS
491}
492
493/**
494 * Terminates all sessions of one user, auth hooks are not executed.
d79d5ac2
PS
495 *
496 * @deprecated since 2.6
d79d5ac2
PS
497 */
498function session_kill_user($userid) {
1ac1d29b 499 throw new coding_exception('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead');
d79d5ac2
PS
500}
501
d79d5ac2
PS
502/**
503 * Setup $USER object - called during login, loginas, etc.
504 *
505 * Call sync_user_enrolments() manually after log-in, or log-in-as.
506 *
507 * @deprecated since 2.6
d79d5ac2
PS
508 */
509function session_set_user($user) {
1ac1d29b 510 throw new coding_exception('session_set_user() is deprecated, use \core\session\manager::set_user() instead');
d79d5ac2
PS
511}
512
513/**
514 * Is current $USER logged-in-as somebody else?
515 * @deprecated since 2.6
d79d5ac2
PS
516 */
517function session_is_loggedinas() {
1ac1d29b 518 throw new coding_exception('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead');
d79d5ac2
PS
519}
520
521/**
522 * Returns the $USER object ignoring current login-as session
523 * @deprecated since 2.6
d79d5ac2
PS
524 */
525function session_get_realuser() {
1ac1d29b 526 throw new coding_exception('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead');
d79d5ac2
PS
527}
528
529/**
530 * Login as another user - no security checks here.
531 * @deprecated since 2.6
d79d5ac2
PS
532 */
533function session_loginas($userid, $context) {
1ac1d29b 534 throw new coding_exception('session_loginas() is deprecated, use \core\session\manager::loginas() instead');
d79d5ac2
PS
535}
536
6b32d6bc
PS
537/**
538 * Minify JavaScript files.
539 *
540 * @deprecated since 2.6
6b32d6bc
PS
541 */
542function js_minify($files) {
1ac1d29b 543 throw new coding_exception('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
6b32d6bc
PS
544}
545
546/**
547 * Minify CSS files.
548 *
549 * @deprecated since 2.6
6b32d6bc
PS
550 */
551function css_minify_css($files) {
1ac1d29b 552 throw new coding_exception('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
6b32d6bc
PS
553}
554
9e19a0f0
PS
555
556
557// === Deprecated before 2.6.0 ===
558
689096bc
PS
559/**
560 * Hack to find out the GD version by parsing phpinfo output
689096bc
PS
561 */
562function check_gd_version() {
1ac1d29b 563 throw new coding_exception('check_gd_version() is deprecated, GD extension is always available now');
689096bc
PS
564}
565
b28247fe
PS
566/**
567 * Not used any more, the account lockout handling is now
568 * part of authenticate_user_login().
569 * @deprecated
570 */
571function update_login_count() {
1ac1d29b 572 throw new coding_exception('update_login_count() is deprecated, all calls need to be removed');
b28247fe
PS
573}
574
575/**
576 * Not used any more, replaced by proper account lockout.
577 * @deprecated
578 */
579function reset_login_count() {
1ac1d29b 580 throw new coding_exception('reset_login_count() is deprecated, all calls need to be removed');
b28247fe
PS
581}
582
c6d75bff 583/**
c6d75bff 584 * @deprecated
c6d75bff
PS
585 */
586function update_log_display_entry($module, $action, $mtable, $field) {
c6d75bff 587
1ac1d29b 588 throw new coding_exception('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
c6d75bff
PS
589}
590
35716b86 591/**
05226d76 592 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
35716b86 593 * this was abused mostly for embedding of attachments
35716b86
PS
594 */
595function filter_text($text, $courseid = NULL) {
e4d9185e 596 throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
35716b86
PS
597}
598
17c70aa0 599/**
17c70aa0
PS
600 * @deprecated use $PAGE->https_required() instead
601 */
602function httpsrequired() {
e4d9185e 603 throw new coding_exception('httpsrequired() can not be used any more use $PAGE->https_required() instead.');
17c70aa0
PS
604}
605
50a8bd6c
PS
606/**
607 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
608 *
609 * @deprecated use moodle_url factory methods instead
610 *
611 * @param string $path Physical path to a file
612 * @param array $options associative array of GET variables to append to the URL
613 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
614 * @return string URL to file
615 */
616function get_file_url($path, $options=null, $type='coursefile') {
17c70aa0 617 global $CFG;
50a8bd6c
PS
618
619 $path = str_replace('//', '/', $path);
620 $path = trim($path, '/'); // no leading and trailing slashes
621
622 // type of file
623 switch ($type) {
624 case 'questionfile':
625 $url = $CFG->wwwroot."/question/exportfile.php";
626 break;
627 case 'rssfile':
628 $url = $CFG->wwwroot."/rss/file.php";
629 break;
630 case 'httpscoursefile':
631 $url = $CFG->httpswwwroot."/file.php";
632 break;
633 case 'coursefile':
634 default:
635 $url = $CFG->wwwroot."/file.php";
636 }
637
638 if ($CFG->slasharguments) {
639 $parts = explode('/', $path);
640 foreach ($parts as $key => $part) {
641 /// anchor dash character should not be encoded
642 $subparts = explode('#', $part);
643 $subparts = array_map('rawurlencode', $subparts);
644 $parts[$key] = implode('#', $subparts);
645 }
646 $path = implode('/', $parts);
647 $ffurl = $url.'/'.$path;
648 $separator = '?';
649 } else {
650 $path = rawurlencode('/'.$path);
651 $ffurl = $url.'?file='.$path;
652 $separator = '&amp;';
653 }
654
655 if ($options) {
656 foreach ($options as $name=>$value) {
657 $ffurl = $ffurl.$separator.$name.'='.$value;
658 $separator = '&amp;';
659 }
660 }
661
662 return $ffurl;
663}
664
613bbd7c 665/**
05226d76 666 * @deprecated use get_enrolled_users($context) instead.
613bbd7c 667 */
4f0c2d00 668function get_course_participants($courseid) {
e4d9185e 669 throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
613bbd7c 670}
671
613bbd7c 672/**
05226d76 673 * @deprecated use is_enrolled($context, $userid) instead.
613bbd7c 674 */
4f0c2d00 675function is_course_participant($userid, $courseid) {
e4d9185e 676 throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
613bbd7c 677}
678
679/**
1ac1d29b 680 * @deprecated
613bbd7c 681 */
682function get_recent_enrolments($courseid, $timestart) {
1ac1d29b 683 throw new coding_exception('get_recent_enrolments() is deprecated as it returned inaccurate results.');
613bbd7c 684}
685
ed5dd29f 686/**
05226d76 687 * @deprecated use clean_param($string, PARAM_FILE) instead.
ed5dd29f 688 */
689function detect_munged_arguments($string, $allowdots=1) {
e4d9185e 690 throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
ed5dd29f 691}
692
9152fc99 693
0c6d2dd4 694/**
695 * Unzip one zip file to a destination dir
696 * Both parameters must be FULL paths
697 * If destination isn't specified, it will be the
698 * SAME directory where the zip file resides.
c861fe2f 699 *
700 * @global object
701 * @param string $zipfile The zip file to unzip
702 * @param string $destination The location to unzip to
703 * @param bool $showstatus_ignored Unused
0c6d2dd4 704 */
705function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
706 global $CFG;
707
708 //Extract everything from zipfile
709 $path_parts = pathinfo(cleardoubleslashes($zipfile));
710 $zippath = $path_parts["dirname"]; //The path of the zip file
711 $zipfilename = $path_parts["basename"]; //The name of the zip file
712 $extension = $path_parts["extension"]; //The extension of the file
713
714 //If no file, error
715 if (empty($zipfilename)) {
716 return false;
717 }
718
719 //If no extension, error
720 if (empty($extension)) {
721 return false;
722 }
723
724 //Clear $zipfile
725 $zipfile = cleardoubleslashes($zipfile);
726
727 //Check zipfile exists
728 if (!file_exists($zipfile)) {
729 return false;
730 }
731
732 //If no destination, passed let's go with the same directory
733 if (empty($destination)) {
734 $destination = $zippath;
735 }
736
737 //Clear $destination
738 $destpath = rtrim(cleardoubleslashes($destination), "/");
739
740 //Check destination path exists
741 if (!is_dir($destpath)) {
742 return false;
743 }
744
0b0bfa93 745 $packer = get_file_packer('application/zip');
746
747 $result = $packer->extract_to_pathname($zipfile, $destpath);
0c6d2dd4 748
749 if ($result === false) {
750 return false;
751 }
752
753 foreach ($result as $status) {
754 if ($status !== true) {
755 return false;
756 }
757 }
758
759 return true;
760}
761
ed94cb66 762/**
763 * Zip an array of files/dirs to a destination zip file
764 * Both parameters must be FULL paths to the files/dirs
c861fe2f 765 *
766 * @global object
767 * @param array $originalfiles Files to zip
768 * @param string $destination The destination path
769 * @return bool Outcome
ed94cb66 770 */
771function zip_files ($originalfiles, $destination) {
772 global $CFG;
773
774 //Extract everything from destination
775 $path_parts = pathinfo(cleardoubleslashes($destination));
776 $destpath = $path_parts["dirname"]; //The path of the zip file
777 $destfilename = $path_parts["basename"]; //The name of the zip file
778 $extension = $path_parts["extension"]; //The extension of the file
779
780 //If no file, error
781 if (empty($destfilename)) {
782 return false;
783 }
784
785 //If no extension, add it
786 if (empty($extension)) {
787 $extension = 'zip';
788 $destfilename = $destfilename.'.'.$extension;
789 }
790
791 //Check destination path exists
792 if (!is_dir($destpath)) {
793 return false;
794 }
795
796 //Check destination path is writable. TODO!!
797
798 //Clean destination filename
799 $destfilename = clean_filename($destfilename);
800
801 //Now check and prepare every file
802 $files = array();
803 $origpath = NULL;
804
805 foreach ($originalfiles as $file) { //Iterate over each file
806 //Check for every file
807 $tempfile = cleardoubleslashes($file); // no doubleslashes!
808 //Calculate the base path for all files if it isn't set
809 if ($origpath === NULL) {
810 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
811 }
812 //See if the file is readable
813 if (!is_readable($tempfile)) { //Is readable
814 continue;
815 }
816 //See if the file/dir is in the same directory than the rest
817 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
818 continue;
819 }
820 //Add the file to the array
821 $files[] = $tempfile;
822 }
823
824 $zipfiles = array();
825 $start = strlen($origpath)+1;
826 foreach($files as $file) {
827 $zipfiles[substr($file, $start)] = $file;
828 }
829
0b0bfa93 830 $packer = get_file_packer('application/zip');
ed94cb66 831
3ed22f1a 832 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
ed94cb66 833}
834
5bf243d1 835/**
05226d76 836 * @deprecated use groups_get_all_groups() instead.
5bf243d1 837 */
838function mygroupid($courseid) {
e4d9185e 839 throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
5bf243d1 840}
841
5bf243d1 842
5bf243d1 843/**
844 * Returns the current group mode for a given course or activity module
364fffda 845 *
5bf243d1 846 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
c861fe2f 847 *
848 * @param object $course Course Object
849 * @param object $cm Course Manager Object
850 * @return mixed $course->groupmode
5bf243d1 851 */
852function groupmode($course, $cm=null) {
853
854 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
855 return $cm->groupmode;
856 }
857 return $course->groupmode;
858}
859
c584346c 860/**
861 * Sets the current group in the session variable
862 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
863 * Sets currentgroup[$courseid] in the session variable appropriately.
864 * Does not do any permission checking.
c861fe2f 865 *
866 * @global object
c584346c 867 * @param int $courseid The course being examined - relates to id field in
868 * 'course' table.
869 * @param int $groupid The group being examined.
870 * @return int Current group id which was set by this function
871 */
872function set_current_group($courseid, $groupid) {
873 global $SESSION;
874 return $SESSION->currentgroup[$courseid] = $groupid;
875}
876
5bf243d1 877/**
364fffda 878 * Gets the current group - either from the session variable or from the database.
5bf243d1 879 *
c861fe2f 880 * @global object
364fffda 881 * @param int $courseid The course being examined - relates to id field in
5bf243d1 882 * 'course' table.
364fffda 883 * @param bool $full If true, the return value is a full record object.
5bf243d1 884 * If false, just the id of the record.
c861fe2f 885 * @return int|bool
5bf243d1 886 */
887function get_current_group($courseid, $full = false) {
888 global $SESSION;
889
890 if (isset($SESSION->currentgroup[$courseid])) {
891 if ($full) {
892 return groups_get_group($SESSION->currentgroup[$courseid]);
893 } else {
894 return $SESSION->currentgroup[$courseid];
895 }
896 }
897
898 $mygroupid = mygroupid($courseid);
899 if (is_array($mygroupid)) {
900 $mygroupid = array_shift($mygroupid);
901 set_current_group($courseid, $mygroupid);
902 if ($full) {
903 return groups_get_group($mygroupid);
904 } else {
905 return $mygroupid;
906 }
907 }
908
909 if ($full) {
910 return false;
911 } else {
912 return 0;
913 }
914}
915
061e6b28 916/**
061e6b28 917 * @deprecated Since Moodle 2.8
918 */
919function groups_filter_users_by_course_module_visible($cm, $users) {
1ac1d29b 920 throw new coding_exception('groups_filter_users_by_course_module_visible() is deprecated. ' .
061e6b28 921 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
922 'which does basically the same thing but includes other restrictions such ' .
1ac1d29b 923 'as profile restrictions.');
061e6b28 924}
925
926/**
061e6b28 927 * @deprecated Since Moodle 2.8
928 */
929function groups_course_module_visible($cm, $userid=null) {
1ac1d29b 930 throw new coding_exception('groups_course_module_visible() is deprecated and always returns ' .
061e6b28 931 'true; use $cm->uservisible to decide whether the current user can ' .
932 'access an activity.', DEBUG_DEVELOPER);
061e6b28 933}
5bf243d1 934
8ec50604 935/**
1ac1d29b 936 * @deprecated since 2.0
8ec50604 937 */
245ac557 938function error($message, $link='') {
1ac1d29b
AA
939 throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call
940 print_error() instead of error()');
251387d0 941}
8ec50604 942
8ec50604 943
b7009474 944/**
945 * @deprecated use $PAGE->theme->name instead.
b7009474 946 */
947function current_theme() {
e4d9185e 948 throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
b7009474 949}
950
8954245a 951/**
8954245a 952 * @deprecated
8954245a 953 */
954function formerr($error) {
1ac1d29b 955 throw new coding_exception('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
8954245a 956}
957
34a2777c 958/**
34a2777c 959 * @deprecated use $OUTPUT->skip_link_target() in instead.
34a2777c 960 */
961function skip_main_destination() {
e4d9185e 962 throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
34a2777c 963}
964
34a2777c 965/**
05226d76 966 * @deprecated use $OUTPUT->container() instead.
34a2777c 967 */
968function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
e4d9185e 969 throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
34a2777c 970}
971
972/**
05226d76 973 * @deprecated use $OUTPUT->container_start() instead.
34a2777c 974 */
975function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
e4d9185e 976 throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
34a2777c 977}
978
979/**
05226d76 980 * @deprecated use $OUTPUT->container_end() instead.
34a2777c 981 */
982function print_container_end($return=false) {
e4d9185e 983 throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
34a2777c 984}
985
986/**
987 * Print a bold message in an optional color.
988 *
989 * @deprecated use $OUTPUT->notification instead.
990 * @param string $message The message to print out
991 * @param string $style Optional style to display message text in
992 * @param string $align Alignment option
993 * @param bool $return whether to return an output string or echo now
a5cb8d69 994 * @return string|bool Depending on $result
34a2777c 995 */
996function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
997 global $OUTPUT;
998
999 if ($classes == 'green') {
1000 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1001 $classes = 'notifysuccess'; // Backward compatible with old color system
1002 }
1003
1004 $output = $OUTPUT->notification($message, $classes);
1005 if ($return) {
1006 return $output;
1007 } else {
1008 echo $output;
1009 }
1010}
1011
1012/**
05226d76 1013 * @deprecated use $OUTPUT->continue_button() instead.
34a2777c 1014 */
1015function print_continue($link, $return = false) {
e4d9185e 1016 throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
34a2777c 1017}
1018
34a2777c 1019/**
05226d76 1020 * @deprecated use $PAGE methods instead.
34a2777c 1021 */
1022function print_header($title='', $heading='', $navigation='', $focus='',
e120c61d 1023 $meta='', $cache=true, $button='&nbsp;', $menu=null,
34a2777c 1024 $usexml=false, $bodytags='', $return=false) {
34a2777c 1025
e4d9185e 1026 throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
34a2777c 1027}
1028
47a1aa45 1029/**
05226d76 1030 * @deprecated use $PAGE methods instead.
47a1aa45 1031 */
1032function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1033 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1034
e4d9185e 1035 throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
47a1aa45 1036}
1037
a5cb8d69 1038/**
05226d76 1039 * @deprecated use $OUTPUT->block() instead.
a5cb8d69 1040 */
1041function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
e4d9185e 1042 throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
a5cb8d69 1043}
1044
f8065dd2 1045/**
1046 * Prints a basic textarea field.
1047 *
1048 * @deprecated since Moodle 2.0
1049 *
1050 * When using this function, you should
1051 *
1052 * @global object
3d27180e 1053 * @param bool $unused No longer used.
f8065dd2 1054 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1055 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1056 * @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.
1057 * @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.
1058 * @param string $name Name to use for the textarea element.
1059 * @param string $value Initial content to display in the textarea.
1060 * @param int $obsolete deprecated
1061 * @param bool $return If false, will output string. If true, will return string value.
1062 * @param string $id CSS ID to add to the textarea element.
1063 * @return string|void depending on the value of $return
1064 */
3d27180e 1065function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
f8065dd2 1066 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1067 /// However, you can set them to zero to override the mincols and minrows values below.
1068
3d8a479b
MD
1069 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1070 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
f8065dd2 1071
1072 global $CFG;
1073
1074 $mincols = 65;
1075 $minrows = 10;
1076 $str = '';
1077
1078 if ($id === '') {
1079 $id = 'edit-'.$name;
1080 }
1081
3d27180e
DW
1082 if ($height && ($rows < $minrows)) {
1083 $rows = $minrows;
f8065dd2 1084 }
3d27180e
DW
1085 if ($width && ($cols < $mincols)) {
1086 $cols = $mincols;
f8065dd2 1087 }
1088
3d27180e
DW
1089 editors_head_setup();
1090 $editor = editors_get_preferred_editor(FORMAT_HTML);
1091 $editor->use_editor($id, array('legacy'=>true));
1092
0ac97084 1093 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
3d27180e 1094 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
f8065dd2 1095 $str .= '</textarea>'."\n";
1096
1097 if ($return) {
1098 return $str;
1099 }
1100 echo $str;
1101}
1102
f8065dd2 1103/**
1104 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1105 * provide this function with the language strings for sortasc and sortdesc.
1106 *
05226d76 1107 * @deprecated use $OUTPUT->arrow() instead.
e4d9185e 1108 * @todo final deprecation of this function once MDL-45448 is resolved
f8065dd2 1109 *
f8065dd2 1110 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1111 *
1112 * @global object
1113 * @param string $direction 'up' or 'down'
1114 * @param string $strsort The language string used for the alt attribute of this image
1115 * @param bool $return Whether to print directly or return the html string
1116 * @return string|void depending on $return
1117 *
1118 */
1119function print_arrow($direction='up', $strsort=null, $return=false) {
f8065dd2 1120 global $OUTPUT;
1121
05226d76
DP
1122 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1123
f8065dd2 1124 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1125 return null;
1126 }
1127
1128 $return = null;
1129
1130 switch ($direction) {
1131 case 'up':
1132 $sortdir = 'asc';
1133 break;
1134 case 'down':
1135 $sortdir = 'desc';
1136 break;
1137 case 'move':
1138 $sortdir = 'asc';
1139 break;
1140 default:
1141 $sortdir = null;
1142 break;
1143 }
1144
1145 // Prepare language string
1146 $strsort = '';
1147 if (empty($strsort) && !empty($sortdir)) {
1148 $strsort = get_string('sort' . $sortdir, 'grades');
1149 }
1150
b5d0cafc 1151 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
f8065dd2 1152
1153 if ($return) {
1154 return $return;
1155 } else {
1156 echo $return;
1157 }
1158}
1159
8100c169 1160/**
8100c169 1161 * @deprecated since Moodle 2.0
8100c169 1162 */
1163function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1164 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1165 $id='', $listbox=false, $multiple=false, $class='') {
1ac1d29b 1166 throw new coding_exception('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
053203a8 1167
053203a8 1168}
1169
c68e4098 1170/**
05226d76 1171 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
c68e4098 1172 */
1173function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
e4d9185e
DP
1174 throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
1175 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
c68e4098 1176}
1177
49c8c8d2 1178/**
05226d76 1179 * @deprecated use html_writer::checkbox() instead.
49c8c8d2 1180 */
916276fc 1181function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
e4d9185e 1182 throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
49c8c8d2 1183}
6a5c71b9 1184
c351150f 1185/**
1186 * Prints the 'update this xxx' button that appears on module pages.
1187 *
1188 * @deprecated since Moodle 2.0
1189 *
1190 * @param string $cmid the course_module id.
1191 * @param string $ignored not used any more. (Used to be courseid.)
1192 * @param string $string the module name - get_string('modulename', 'xxx')
1193 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1194 */
1195function update_module_button($cmid, $ignored, $string) {
d1f06fb5 1196 global $CFG, $OUTPUT;
c351150f 1197
bc2e0484 1198 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
c351150f 1199
d1f06fb5 1200 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1201
b0c6dc1c 1202 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
d1f06fb5 1203 $string = get_string('updatethis', '', $string);
1204
5c2ed7e2
PS
1205 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1206 return $OUTPUT->single_button($url, $string);
d1f06fb5 1207 } else {
1208 return '';
1209 }
c351150f 1210}
1211
7d2a0492 1212/**
05226d76 1213 * @deprecated use $OUTPUT->navbar() instead
7d2a0492 1214 */
1215function print_navigation ($navigation, $separator=0, $return=false) {
e4d9185e 1216 throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
7d2a0492 1217}
1218
1219/**
05226d76 1220 * @deprecated Please use $PAGE->navabar methods instead.
7d2a0492 1221 */
1222function build_navigation($extranavlinks, $cm = null) {
e4d9185e 1223 throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
7d2a0492 1224}
1225
1226/**
05226d76 1227 * @deprecated not relevant with global navigation in Moodle 2.x+
7d2a0492 1228 */
1229function navmenu($course, $cm=NULL, $targetwindow='self') {
e4d9185e 1230 throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
f43cdceb 1231}
76d9df3f
SH
1232
1233/// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1234
1235
1236/**
05226d76 1237 * @deprecated please use calendar_event::create() instead.
76d9df3f
SH
1238 */
1239 function add_event($event) {
e4d9185e 1240 throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
76d9df3f
SH
1241}
1242
1243/**
05226d76 1244 * @deprecated please calendar_event->update() instead.
76d9df3f
SH
1245 */
1246function update_event($event) {
1ac1d29b 1247 throw new coding_exception('update_event() is deprecated, please use calendar_event->update() instead.');
76d9df3f
SH
1248}
1249
1250/**
05226d76 1251 * @deprecated please use calendar_event->delete() instead.
76d9df3f
SH
1252 */
1253function delete_event($id) {
e4d9185e
DP
1254 throw new coding_exception('delete_event() can not be used any more, please use '.
1255 'calendar_event->delete() instead.');
76d9df3f
SH
1256}
1257
1258/**
05226d76 1259 * @deprecated please use calendar_event->toggle_visibility(false) instead.
76d9df3f
SH
1260 */
1261function hide_event($event) {
e4d9185e
DP
1262 throw new coding_exception('hide_event() can not be used any more, please use '.
1263 'calendar_event->toggle_visibility(false) instead.');
76d9df3f
SH
1264}
1265
1266/**
05226d76 1267 * @deprecated please use calendar_event->toggle_visibility(true) instead.
76d9df3f
SH
1268 */
1269function show_event($event) {
e4d9185e
DP
1270 throw new coding_exception('show_event() can not be used any more, please use '.
1271 'calendar_event->toggle_visibility(true) instead.');
0189bf77 1272}
6f3451e5 1273
3fed29a7 1274/**
6b61c2c4
FM
1275 * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
1276 * @see core_text
3fed29a7
PS
1277 */
1278function textlib_get_instance() {
6b61c2c4
FM
1279 throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
1280 'core_text::functioname() instead.');
3fed29a7
PS
1281}
1282
ee7084e9 1283/**
ee7084e9
MG
1284 * @deprecated since 2.4
1285 * @see get_section_name()
1286 * @see format_base::get_section_name()
1ac1d29b 1287
ee7084e9
MG
1288 */
1289function get_generic_section_name($format, stdClass $section) {
1ac1d29b 1290 throw new coding_exception('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base');
ee7084e9 1291}
99e9f9a6
MG
1292
1293/**
1294 * Returns an array of sections for the requested course id
1295 *
1296 * It is usually not recommended to display the list of sections used
1297 * in course because the course format may have it's own way to do it.
1298 *
1299 * If you need to just display the name of the section please call:
1300 * get_section_name($course, $section)
1301 * {@link get_section_name()}
1302 * from 2.4 $section may also be just the field course_sections.section
1303 *
1304 * If you need the list of all sections it is more efficient to get this data by calling
b46be6ad 1305 * $modinfo = get_fast_modinfo($courseorid);
99e9f9a6
MG
1306 * $sections = $modinfo->get_section_info_all()
1307 * {@link get_fast_modinfo()}
1308 * {@link course_modinfo::get_section_info_all()}
1309 *
1310 * Information about one section (instance of section_info):
b46be6ad 1311 * get_fast_modinfo($courseorid)->get_sections_info($section)
99e9f9a6
MG
1312 * {@link course_modinfo::get_section_info()}
1313 *
1314 * @deprecated since 2.4
99e9f9a6
MG
1315 */
1316function get_all_sections($courseid) {
1ac1d29b
AA
1317
1318 throw new coding_exception('get_all_sections() is deprecated. See phpdocs for this function');
99e9f9a6 1319}
722e6ba9
MG
1320
1321/**
722e6ba9
MG
1322 * This function is deprecated, please use {@link course_add_cm_to_section()}
1323 * Note that course_add_cm_to_section() also updates field course_modules.section and
1324 * calls rebuild_course_cache()
1325 *
1326 * @deprecated since 2.4
722e6ba9 1327 */
44aa854e 1328function add_mod_to_section($mod, $beforemod = null) {
1ac1d29b 1329 throw new coding_exception('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()');
722e6ba9 1330}
d57aa283
MG
1331
1332/**
1333 * Returns a number of useful structures for course displays
1334 *
1335 * Function get_all_mods() is deprecated in 2.4
1336 * Instead of:
1337 * <code>
b46be6ad 1338 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
d57aa283
MG
1339 * </code>
1340 * please use:
1341 * <code>
b46be6ad 1342 * $mods = get_fast_modinfo($courseorid)->get_cms();
d57aa283
MG
1343 * $modnames = get_module_types_names();
1344 * $modnamesplural = get_module_types_names(true);
b46be6ad 1345 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
d57aa283
MG
1346 * </code>
1347 *
1348 * @deprecated since 2.4
d57aa283
MG
1349 */
1350function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1ac1d29b 1351 throw new coding_exception('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details');
d57aa283 1352}
4ede27b2
MG
1353
1354/**
1355 * Returns course section - creates new if does not exist yet
1356 *
1357 * This function is deprecated. To create a course section call:
b46be6ad 1358 * course_create_sections_if_missing($courseorid, $sections);
4ede27b2 1359 * to get the section call:
b46be6ad 1360 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
4ede27b2
MG
1361 *
1362 * @see course_create_sections_if_missing()
1363 * @see get_fast_modinfo()
1364 * @deprecated since 2.4
4ede27b2
MG
1365 */
1366function get_course_section($section, $courseid) {
1367 global $DB;
1ac1d29b 1368 throw new coding_exception('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.');
4ede27b2 1369}
1b2581f4
MG
1370
1371/**
1b2581f4
MG
1372 * @deprecated since 2.4
1373 * @see format_weeks::get_section_dates()
1b2581f4
MG
1374 */
1375function format_weeks_get_section_dates($section, $course) {
1ac1d29b
AA
1376 throw new coding_exception('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
1377 ' use it outside of format_weeks plugin');
1b2581f4 1378}
9a36be73
MG
1379
1380/**
9a36be73
MG
1381 * Deprecated. Instead of:
1382 * list($content, $name) = get_print_section_cm_text($cm, $course);
1383 * use:
1384 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
1385 * $name = $cm->get_formatted_name();
1386 *
1387 * @deprecated since 2.5
1388 * @see cm_info::get_formatted_content()
1389 * @see cm_info::get_formatted_name()
9a36be73
MG
1390 */
1391function get_print_section_cm_text(cm_info $cm, $course) {
1ac1d29b
AA
1392 throw new coding_exception('Function get_print_section_cm_text() is deprecated. Please use '.
1393 'cm_info::get_formatted_content() and cm_info::get_formatted_name()');
9a36be73
MG
1394}
1395
1396/**
9a36be73
MG
1397 * Deprecated. Please use:
1398 * $courserenderer = $PAGE->get_renderer('core', 'course');
1399 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1400 * array('inblock' => $vertical));
1401 * echo $output; // if $return argument in print_section_add_menus() set to false
1402 *
1403 * @deprecated since 2.5
1404 * @see core_course_renderer::course_section_add_cm_control()
9a36be73
MG
1405 */
1406function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
1ac1d29b
AA
1407 throw new coding_exception('Function print_section_add_menus() is deprecated. Please use course renderer '.
1408 'function course_section_add_cm_control()');
9a36be73
MG
1409}
1410
1411/**
9a36be73
MG
1412 * Deprecated. Please use:
1413 * $courserenderer = $PAGE->get_renderer('core', 'course');
1414 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1415 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1416 *
1417 * @deprecated since 2.5
1418 * @see course_get_cm_edit_actions()
1419 * @see core_course_renderer->course_section_cm_edit_actions()
9a36be73
MG
1420 */
1421function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
1ac1d29b
AA
1422 throw new coding_exception('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
1423 'lib/deprecatedlib.php on how to replace it');
9a36be73
MG
1424}
1425
1426/**
9a36be73
MG
1427 * Deprecated. Please use:
1428 * $courserenderer = $PAGE->get_renderer('core', 'course');
1429 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
1430 * array('hidecompletion' => $hidecompletion));
1431 *
1432 * @deprecated since 2.5
1433 * @see core_course_renderer::course_section_cm_list()
9a36be73
MG
1434 */
1435function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
1ac1d29b
AA
1436 throw new coding_exception('Function print_section() is deprecated. Please use course renderer function '.
1437 'course_section_cm_list() instead.');
9a36be73 1438}
00ba185d 1439
ff233851 1440/**
ff233851 1441 * @deprecated since 2.5
ff233851
MG
1442 */
1443function print_overview($courses, array $remote_courses=array()) {
1ac1d29b 1444 throw new coding_exception('Function print_overview() is deprecated. Use block course_overview to display this information');
ff233851 1445}
a3f66bde
MG
1446
1447/**
a3f66bde 1448 * @deprecated since 2.5
a3f66bde
MG
1449 */
1450function print_recent_activity($course) {
1ac1d29b
AA
1451 throw new coding_exception('Function print_recent_activity() is deprecated. It is not recommended to'.
1452 ' use it outside of block_recent_activity');
a3f66bde 1453}
a347aee3
MN
1454
1455/**
a347aee3 1456 * @deprecated since 2.5
a347aee3
MN
1457 */
1458function delete_course_module($id) {
1ac1d29b 1459 throw new coding_exception('Function delete_course_module() is deprecated. Please use course_delete_module() instead.');
a347aee3 1460}
2c49fb4c
MG
1461
1462/**
2c49fb4c 1463 * @deprecated since 2.5
2c49fb4c
MG
1464 */
1465function update_category_button($categoryid = 0) {
1ac1d29b
AA
1466 throw new coding_exception('Function update_category_button() is deprecated. Pages to view '.
1467 'and edit courses are now separate and no longer depend on editing mode.');
2c49fb4c 1468}
4e0b6025
MG
1469
1470/**
4e0b6025
MG
1471 * This function is deprecated! For list of categories use
1472 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
1473 * For parents of one particular category use
1474 * coursecat::get($id)->get_parents()
1475 *
1476 * @deprecated since 2.5
4e0b6025
MG
1477 */
1478function make_categories_list(&$list, &$parents, $requiredcapability = '',
1479 $excludeid = 0, $category = NULL, $path = "") {
1ac1d29b
AA
1480 throw new coding_exception('Global function make_categories_list() is deprecated. Please use '.
1481 'coursecat::make_categories_list() and coursecat::get_parents()');
4e0b6025 1482}
deb65ced
MG
1483
1484/**
deb65ced 1485 * @deprecated since 2.5
deb65ced
MG
1486 */
1487function category_delete_move($category, $newparentid, $showfeedback=true) {
1ac1d29b 1488 throw new coding_exception('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
deb65ced
MG
1489}
1490
1491/**
deb65ced 1492 * @deprecated since 2.5
deb65ced
MG
1493 */
1494function category_delete_full($category, $showfeedback=true) {
1ac1d29b 1495 throw new coding_exception('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
deb65ced 1496}
6e1d1ee0
MG
1497
1498/**
6e1d1ee0
MG
1499 * This function is deprecated. Please use
1500 * $coursecat = coursecat::get($category->id);
1501 * if ($coursecat->can_change_parent($newparentcat->id)) {
1502 * $coursecat->change_parent($newparentcat->id);
1503 * }
1504 *
1505 * Alternatively you can use
1506 * $coursecat->update(array('parent' => $newparentcat->id));
1507 *
6e1d1ee0
MG
1508 * @see coursecat::change_parent()
1509 * @see coursecat::update()
1510 * @deprecated since 2.5
6e1d1ee0
MG
1511 */
1512function move_category($category, $newparentcat) {
1ac1d29b 1513 throw new coding_exception('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
6e1d1ee0
MG
1514}
1515
1516/**
6e1d1ee0
MG
1517 * This function is deprecated. Please use
1518 * coursecat::get($category->id)->hide();
1519 *
1520 * @see coursecat::hide()
1521 * @deprecated since 2.5
6e1d1ee0
MG
1522 */
1523function course_category_hide($category) {
1ac1d29b 1524 throw new coding_exception('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
6e1d1ee0
MG
1525}
1526
1527/**
6e1d1ee0
MG
1528 * This function is deprecated. Please use
1529 * coursecat::get($category->id)->show();
1530 *
1531 * @see coursecat::show()
1532 * @deprecated since 2.5
6e1d1ee0
MG
1533 */
1534function course_category_show($category) {
1ac1d29b 1535 throw new coding_exception('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
6e1d1ee0 1536}
2d8a275b
MG
1537
1538/**
2d8a275b
MG
1539 * This function is deprecated.
1540 * To get the category with the specified it please use:
1541 * coursecat::get($catid, IGNORE_MISSING);
1542 * or
1543 * coursecat::get($catid, MUST_EXIST);
1544 *
1545 * To get the first available category please use
1546 * coursecat::get_default();
1547 *
2d8a275b 1548 * @deprecated since 2.5
2d8a275b
MG
1549 */
1550function get_course_category($catid=0) {
1ac1d29b 1551 throw new coding_exception('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2d8a275b 1552}
9bad61db
MG
1553
1554/**
9bad61db
MG
1555 * This function is deprecated. It is replaced with the method create() in class coursecat.
1556 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
1557 *
1558 * @deprecated since 2.5
9bad61db
MG
1559 */
1560function create_course_category($category) {
1ac1d29b 1561 throw new coding_exception('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details');
9bad61db 1562}
bc81b006
MG
1563
1564/**
bc81b006
MG
1565 * This function is deprecated.
1566 *
1567 * To get visible children categories of the given category use:
1568 * coursecat::get($categoryid)->get_children();
1569 * This function will return the array or coursecat objects, on each of them
1570 * you can call get_children() again
1571 *
1572 * @see coursecat::get()
1573 * @see coursecat::get_children()
1574 *
1575 * @deprecated since 2.5
bc81b006
MG
1576 */
1577function get_all_subcategories($catid) {
1ac1d29b
AA
1578 throw new coding_exception('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat
1579 class. See phpdocs for more details');
bc81b006 1580}
8db5dcb7
MG
1581
1582/**
8db5dcb7
MG
1583 * This function is deprecated. Please use functions in class coursecat:
1584 * - coursecat::get($parentid)->has_children()
1585 * tells if the category has children (visible or not to the current user)
1586 *
1587 * - coursecat::get($parentid)->get_children()
1588 * returns an array of coursecat objects, each of them represents a children category visible
1589 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
1590 *
1591 * - coursecat::get($parentid)->get_children_count()
1592 * returns number of children categories visible to the current user
1593 *
1594 * - coursecat::count_all()
1595 * returns total count of all categories in the system (both visible and not)
1596 *
1597 * - coursecat::get_default()
1598 * returns the first category (usually to be used if count_all() == 1)
1599 *
1600 * @deprecated since 2.5
8db5dcb7
MG
1601 */
1602function get_child_categories($parentid) {
1ac1d29b
AA
1603 throw new coding_exception('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for
1604 more details.');
8db5dcb7 1605}
e1d54562
MG
1606
1607/**
e1d54562
MG
1608 *
1609 * @deprecated since 2.5
1610 *
1611 * This function is deprecated. Use appropriate functions from class coursecat.
1612 * Examples:
1613 *
1614 * coursecat::get($categoryid)->get_children()
1615 * - returns all children of the specified category as instances of class
0198b4a5
MG
1616 * coursecat, which means on each of them method get_children() can be called again.
1617 * Only categories visible to the current user are returned.
e1d54562 1618 *
0198b4a5
MG
1619 * coursecat::get(0)->get_children()
1620 * - returns all top-level categories visible to the current user.
e1d54562
MG
1621 *
1622 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
1623 *
0198b4a5
MG
1624 * coursecat::make_categories_list()
1625 * - returns an array of all categories id/names in the system.
1626 * Also only returns categories visible to current user and can additionally be
1627 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
1628 *
1629 * make_categories_options()
1630 * - Returns full course categories tree to be used in html_writer::select()
1631 *
e1d54562
MG
1632 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
1633 * {@link coursecat::get_default()}
e1d54562
MG
1634 */
1635function get_categories($parent='none', $sort=NULL, $shallow=true) {
1ac1d29b 1636 throw new coding_exception('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives');
e1d54562 1637}
a8d683ca
MG
1638
1639/**
a8d683ca
MG
1640* This function is deprecated, please use course renderer:
1641* $renderer = $PAGE->get_renderer('core', 'course');
1642* echo $renderer->course_search_form($value, $format);
1643*
1644* @deprecated since 2.5
a8d683ca
MG
1645*/
1646function print_course_search($value="", $return=false, $format="plain") {
1ac1d29b 1647 throw new coding_exception('Function print_course_search() is deprecated, please use course renderer');
a8d683ca 1648}
09ae7ee0
MG
1649
1650/**
09ae7ee0
MG
1651 * This function is deprecated, please use:
1652 * $renderer = $PAGE->get_renderer('core', 'course');
1653 * echo $renderer->frontpage_my_courses()
1654 *
1655 * @deprecated since 2.5
1656 */
1657function print_my_moodle() {
1ac1d29b 1658 throw new coding_exception('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()');
09ae7ee0
MG
1659}
1660
1661/**
09ae7ee0
MG
1662 * This function is deprecated, it is replaced with protected function
1663 * {@link core_course_renderer::frontpage_remote_course()}
1664 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
1665 *
1666 * @deprecated since 2.5
1667 */
1668function print_remote_course($course, $width="100%") {
1ac1d29b 1669 throw new coding_exception('Function print_remote_course() is deprecated, please use course renderer');
09ae7ee0
MG
1670}
1671
1672/**
09ae7ee0
MG
1673 * This function is deprecated, it is replaced with protected function
1674 * {@link core_course_renderer::frontpage_remote_host()}
1675 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
1676 *
1677 * @deprecated since 2.5
1678 */
1679function print_remote_host($host, $width="100%") {
1ac1d29b 1680 throw new coding_exception('Function print_remote_host() is deprecated, please use course renderer');
09ae7ee0
MG
1681}
1682
1683/**
09ae7ee0
MG
1684 * @deprecated since 2.5
1685 *
1686 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
1687 */
1688function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
1689 global $PAGE;
1ac1d29b 1690 throw new coding_exception('Function print_whole_category_list() is deprecated, please use course renderer');
09ae7ee0
MG
1691}
1692
1693/**
09ae7ee0 1694 * @deprecated since 2.5
09ae7ee0
MG
1695 */
1696function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
1ac1d29b 1697 throw new coding_exception('Function print_category_info() is deprecated, please use course renderer');
09ae7ee0
MG
1698}
1699
1700/**
09ae7ee0
MG
1701 * @deprecated since 2.5
1702 *
1703 * This function is not used any more in moodle core and course renderer does not have render function for it.
1704 * Combo list on the front page is displayed as:
1705 * $renderer = $PAGE->get_renderer('core', 'course');
1706 * echo $renderer->frontpage_combo_list()
1707 *
1708 * The new class {@link coursecat} stores the information about course category tree
1709 * To get children categories use:
1710 * coursecat::get($id)->get_children()
1711 * To get list of courses use:
1712 * coursecat::get($id)->get_courses()
1713 *
1714 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
09ae7ee0
MG
1715 */
1716function get_course_category_tree($id = 0, $depth = 0) {
1ac1d29b
AA
1717 throw new coding_exception('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class,
1718 see function phpdocs for more info');
09ae7ee0
MG
1719}
1720
1721/**
09ae7ee0
MG
1722 * @deprecated since 2.5
1723 *
1724 * To print a generic list of courses use:
1725 * $renderer = $PAGE->get_renderer('core', 'course');
1726 * echo $renderer->courses_list($courses);
1727 *
1728 * To print list of all courses:
1729 * $renderer = $PAGE->get_renderer('core', 'course');
1730 * echo $renderer->frontpage_available_courses();
1731 *
1732 * To print list of courses inside category:
1733 * $renderer = $PAGE->get_renderer('core', 'course');
1734 * echo $renderer->course_category($category); // this will also print subcategories
09ae7ee0
MG
1735 */
1736function print_courses($category) {
1ac1d29b 1737 throw new coding_exception('Function print_courses() is deprecated, please use course renderer');
09ae7ee0
MG
1738}
1739
1740/**
09ae7ee0
MG
1741 * @deprecated since 2.5
1742 *
1743 * Please use course renderer to display a course information box.
1744 * $renderer = $PAGE->get_renderer('core', 'course');
1745 * echo $renderer->courses_list($courses); // will print list of courses
1746 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
09ae7ee0
MG
1747 */
1748function print_course($course, $highlightterms = '') {
1ac1d29b 1749 throw new coding_exception('Function print_course() is deprecated, please use course renderer');
09ae7ee0
MG
1750}
1751
1752/**
09ae7ee0
MG
1753 * @deprecated since 2.5
1754 *
1755 * This function is not used any more in moodle core and course renderer does not have render function for it.
1756 * Combo list on the front page is displayed as:
1757 * $renderer = $PAGE->get_renderer('core', 'course');
1758 * echo $renderer->frontpage_combo_list()
1759 *
1760 * The new class {@link coursecat} stores the information about course category tree
1761 * To get children categories use:
1762 * coursecat::get($id)->get_children()
1763 * To get list of courses use:
1764 * coursecat::get($id)->get_courses()
09ae7ee0
MG
1765 */
1766function get_category_courses_array($categoryid = 0) {
1ac1d29b 1767 throw new coding_exception('Function get_category_courses_array() is deprecated, please use methods of coursecat class');
09ae7ee0
MG
1768}
1769
1770/**
09ae7ee0 1771 * @deprecated since 2.5
09ae7ee0
MG
1772 */
1773function get_category_courses_array_recursively(array &$flattened, $category) {
1ac1d29b 1774 throw new coding_exception('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
09ae7ee0
MG
1775}
1776
7ac18cf9 1777/**
7ac18cf9 1778 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
7ac18cf9
AA
1779 */
1780function blog_get_context_url($context=null) {
1ac1d29b 1781 throw new coding_exception('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.');
7ac18cf9
AA
1782}
1783
09ae7ee0 1784/**
09ae7ee0
MG
1785 * @deprecated since 2.5
1786 *
1787 * To get list of all courses with course contacts ('managers') use
1788 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
1789 *
1790 * To get list of courses inside particular category use
1791 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
1792 *
1793 * Additionally you can specify sort order, offset and maximum number of courses,
1794 * see {@link coursecat::get_courses()}
09ae7ee0
MG
1795 */
1796function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
1ac1d29b 1797 throw new coding_exception('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()');
09ae7ee0 1798}
c269b9d1
MG
1799
1800/**
c269b9d1 1801 * @deprecated since 2.5
c269b9d1
MG
1802 */
1803function convert_tree_to_html($tree, $row=0) {
1ac1d29b 1804 throw new coding_exception('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()');
c269b9d1
MG
1805}
1806
1807/**
c269b9d1 1808 * @deprecated since 2.5
c269b9d1
MG
1809 */
1810function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
1ac1d29b 1811 throw new coding_exception('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree');
c269b9d1 1812}
9052fc44 1813
8ef3a222 1814/**
8ef3a222 1815 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
8ef3a222
DP
1816 */
1817function can_use_rotated_text() {
1ac1d29b 1818 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.');
8ef3a222 1819}
61a0299a 1820
ce2b2150 1821/**
ce2b2150 1822 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
ce2b2150 1823 * @see context::instance_by_id($id)
ce2b2150
RT
1824 */
1825function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
f9b7be4f 1826 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
ce2b2150 1827}
85b2e46f 1828
492ba9de
AA
1829/**
1830 * Returns system context or null if can not be created yet.
1831 *
1832 * @see context_system::instance()
01546175 1833 * @deprecated since 2.2
492ba9de
AA
1834 * @param bool $cache use caching
1835 * @return context system context (null if context table not created yet)
1836 */
1837function get_system_context($cache = true) {
1838 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
1839 return context_system::instance(0, IGNORE_MISSING, $cache);
1840}
8e8891b7
FM
1841
1842/**
8e8891b7
FM
1843 * @see context::get_parent_context_ids()
1844 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
8e8891b7
FM
1845 */
1846function get_parent_contexts(context $context, $includeself = false) {
1ac1d29b 1847 throw new coding_exception('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.');
8e8891b7 1848}
766fd0d9
AD
1849
1850/**
7f5b51c4
RT
1851 * @deprecated since Moodle 2.2
1852 * @see context::get_parent_context()
766fd0d9 1853 */
7f5b51c4 1854function get_parent_contextid(context $context) {
1ac1d29b 1855 throw new coding_exception('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.');
766fd0d9 1856}
f9aa8016
FM
1857
1858/**
f9aa8016
FM
1859 * @see context::get_child_contexts()
1860 * @deprecated since 2.2
f9aa8016
FM
1861 */
1862function get_child_contexts(context $context) {
1ac1d29b 1863 throw new coding_exception('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.');
f9aa8016 1864}
9fdbf620
FM
1865
1866/**
9fdbf620
FM
1867 * @see context_helper::create_instances()
1868 * @deprecated since 2.2
9fdbf620
FM
1869 */
1870function create_contexts($contextlevel = null, $buildpaths = true) {
1ac1d29b 1871 throw new coding_exception('create_contexts() is deprecated, please use context_helper::create_instances() instead.');
9fdbf620 1872}
84378a57
FM
1873
1874/**
84378a57
FM
1875 * @see context_helper::cleanup_instances()
1876 * @deprecated since 2.2
84378a57
FM
1877 */
1878function cleanup_contexts() {
1ac1d29b 1879 throw new coding_exception('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.');
84378a57 1880}
79f6b384
FM
1881
1882/**
1883 * Populate context.path and context.depth where missing.
1884 *
79f6b384 1885 * @deprecated since 2.2
79f6b384
FM
1886 */
1887function build_context_path($force = false) {
1ac1d29b 1888 throw new coding_exception('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.');
79f6b384 1889}
cc4de415
FM
1890
1891/**
cc4de415 1892 * @deprecated since 2.2
cc4de415
FM
1893 */
1894function rebuild_contexts(array $fixcontexts) {
1ac1d29b 1895 throw new coding_exception('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.');
cc4de415 1896}
8f7d3d12
RT
1897
1898/**
8f7d3d12
RT
1899 * @deprecated since Moodle 2.2
1900 * @see context_helper::preload_course()
8f7d3d12
RT
1901 */
1902function preload_course_contexts($courseid) {
1ac1d29b 1903 throw new coding_exception('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.');
8f7d3d12 1904}
2c5b0eb7
RT
1905
1906/**
2c5b0eb7
RT
1907 * @deprecated since Moodle 2.2
1908 * @see context::update_moved()
2c5b0eb7
RT
1909 */
1910function context_moved(context $context, context $newparent) {
1ac1d29b 1911 throw new coding_exception('context_moved() is deprecated, please use context::update_moved() instead.');
c5dcd25d
AA
1912}
1913
a439b2f9 1914/**
a439b2f9
FM
1915 * @see context::get_capabilities()
1916 * @deprecated since 2.2
a439b2f9
FM
1917 */
1918function fetch_context_capabilities(context $context) {
1ac1d29b 1919 throw new coding_exception('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.');
a439b2f9
FM
1920}
1921
c5dcd25d 1922/**
c5dcd25d
AA
1923 * @deprecated since 2.2
1924 * @see context_helper::preload_from_record()
c5dcd25d
AA
1925 */
1926function context_instance_preload(stdClass $rec) {
1ac1d29b 1927 throw new coding_exception('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.');
c5dcd25d 1928}
b4482dfe
AG
1929
1930/**
1931 * Returns context level name
1932 *
1933 * @deprecated since 2.2
1934 * @see context_helper::get_level_name()
b4482dfe
AG
1935 */
1936function get_contextlevel_name($contextlevel) {
1ac1d29b 1937 throw new coding_exception('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.');
b4482dfe 1938}
329846f1
AG
1939
1940/**
329846f1
AG
1941 * @deprecated since 2.2
1942 * @see context::get_context_name()
329846f1
AG
1943 */
1944function print_context_name(context $context, $withprefix = true, $short = false) {
1ac1d29b 1945 throw new coding_exception('print_context_name() is deprecated, please use $context->get_context_name() instead.');
329846f1 1946}
1de02d62
AG
1947
1948/**
1de02d62
AG
1949 * @deprecated since 2.2, use $context->mark_dirty() instead
1950 * @see context::mark_dirty()
1de02d62
AG
1951 */
1952function mark_context_dirty($path) {
1ac1d29b 1953 throw new coding_exception('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.');
1de02d62 1954}
c592eea2
RT
1955
1956/**
c592eea2
RT
1957 * @deprecated since Moodle 2.2
1958 * @see context_helper::delete_instance() or context::delete_content()
c592eea2
RT
1959 */
1960function delete_context($contextlevel, $instanceid, $deleterecord = true) {
1961 if ($deleterecord) {
1ac1d29b 1962 throw new coding_exception('delete_context() is deprecated, please use context_helper::delete_instance() instead.');
c592eea2 1963 } else {
1ac1d29b 1964 throw new coding_exception('delete_context() is deprecated, please use $context->delete_content() instead.');
c592eea2 1965 }
c592eea2 1966}
6c89d4e1
MN
1967
1968/**
6c89d4e1
MN
1969 * @deprecated since 2.2
1970 * @see context::get_url()
6c89d4e1
MN
1971 */
1972function get_context_url(context $context) {
1ac1d29b 1973 throw new coding_exception('get_context_url() is deprecated, please use $context->get_url() instead.');
6c89d4e1
MN
1974}
1975
dd33f4af 1976/**
dd33f4af
MN
1977 * @deprecated since 2.2
1978 * @see context::get_course_context()
dd33f4af
MN
1979 */
1980function get_course_context(context $context) {
1ac1d29b 1981 throw new coding_exception('get_course_context() is deprecated, please use $context->get_course_context(true) instead.');
dd33f4af 1982}
6acc54b3
AA
1983
1984/**
6acc54b3
AA
1985 * @deprecated since 2.2
1986 * @see enrol_get_users_courses()
6acc54b3
AA
1987 */
1988function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
1989
1ac1d29b 1990 throw new coding_exception('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.');
6acc54b3 1991}
ae38dcb1
RT
1992
1993/**
ae38dcb1 1994 * @deprecated since Moodle 2.2
ae38dcb1
RT
1995 */
1996function get_role_context_caps($roleid, context $context) {
1ac1d29b 1997 throw new coding_exception('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.');
ae38dcb1 1998}
b123a543
FM
1999
2000/**
b123a543
FM
2001 * @see context::get_course_context()
2002 * @deprecated since 2.2
b123a543
FM
2003 */
2004function get_courseid_from_context(context $context) {
1ac1d29b 2005 throw new coding_exception('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.');
6a30b48d 2006}
2e4c0c91
FM
2007
2008/**
2e4c0c91
FM
2009 * If you are using this methid, you should have something like this:
2010 *
2011 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
2012 *
2013 * To prevent the use of this deprecated function, replace the line above with something similar to this:
2014 *
2015 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
2016 * ^
2017 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
2018 * ^ ^ ^ ^
2019 * $params = array('contextlevel' => CONTEXT_COURSE);
2020 * ^
2021 * @see context_helper:;get_preload_record_columns_sql()
2022 * @deprecated since 2.2
2e4c0c91
FM
2023 */
2024function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
1ac1d29b 2025 throw new coding_exception('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.');
b123a543 2026}
b6452844
MN
2027
2028/**
b6452844
MN
2029 * @deprecated since 2.2
2030 * @see context::get_parent_context_ids()
b6452844
MN
2031 */
2032function get_related_contexts_string(context $context) {
1ac1d29b 2033 throw new coding_exception('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.');
b6452844 2034}
0142523d 2035
d0cac8b5 2036/**
d0cac8b5
FM
2037 * @deprecated since 2.6
2038 * @see core_component::get_plugin_list_with_file()
2039 */
2040function get_plugin_list_with_file($plugintype, $file, $include = false) {
1ac1d29b 2041 throw new coding_exception('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.');
d0cac8b5 2042}
c3d2fbf9
SH
2043
2044/**
c3d2fbf9 2045 * @deprecated since 2.6
c3d2fbf9
SH
2046 */
2047function check_browser_operating_system($brand) {
1ac1d29b 2048 throw new coding_exception('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2049}
2050
2051/**
c3d2fbf9 2052 * @deprecated since 2.6
c3d2fbf9
SH
2053 */
2054function check_browser_version($brand, $version = null) {
1ac1d29b 2055 throw new coding_exception('check_browser_version has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2056}
2057
2058/**
c3d2fbf9 2059 * @deprecated since 2.6
c3d2fbf9
SH
2060 */
2061function get_device_type() {
1ac1d29b 2062 throw new coding_exception('get_device_type has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2063}
2064
2065/**
c3d2fbf9 2066 * @deprecated since 2.6
c3d2fbf9
SH
2067 */
2068function get_device_type_list($incusertypes = true) {
1ac1d29b 2069 throw new coding_exception('get_device_type_list has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2070}
2071
2072/**
c3d2fbf9 2073 * @deprecated since 2.6
c3d2fbf9
SH
2074 */
2075function get_selected_theme_for_device_type($devicetype = null) {
1ac1d29b 2076 throw new coding_exception('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2077}
2078
2079/**
c3d2fbf9 2080 * @deprecated since 2.6
c3d2fbf9
SH
2081 */
2082function get_device_cfg_var_name($devicetype = null) {
1ac1d29b 2083 throw new coding_exception('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2084}
2085
2086/**
c3d2fbf9 2087 * @deprecated since 2.6
c3d2fbf9
SH
2088 */
2089function set_user_device_type($newdevice) {
1ac1d29b 2090 throw new coding_exception('set_user_device_type has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2091}
2092
2093/**
c3d2fbf9 2094 * @deprecated since 2.6
c3d2fbf9
SH
2095 */
2096function get_user_device_type() {
1ac1d29b 2097 throw new coding_exception('get_user_device_type has been deprecated, please update your code to use core_useragent instead.');
c3d2fbf9
SH
2098}
2099
2100/**
c3d2fbf9 2101 * @deprecated since 2.6
c3d2fbf9
SH
2102 */
2103function get_browser_version_classes() {
1ac1d29b 2104 throw new coding_exception('get_browser_version_classes has been deprecated, please update your code to use core_useragent instead.');
2b503e40
RT
2105}
2106
2107/**
2b503e40
RT
2108 * @deprecated since Moodle 2.6
2109 * @see core_user::get_support_user()
2b503e40
RT
2110 */
2111function generate_email_supportuser() {
1ac1d29b 2112 throw new coding_exception('generate_email_supportuser is deprecated, please use core_user::get_support_user');
853e506a
Y
2113}
2114
2115/**
853e506a 2116 * @deprecated since Moodle 2.6
853e506a
Y
2117 */
2118function badges_get_issued_badge_info($hash) {
1ac1d29b 2119 throw new coding_exception('Function badges_get_issued_badge_info() is deprecated. Please use core_badges_assertion class and methods to generate badge assertion.');
853e506a 2120}
3d27180e
DW
2121
2122/**
3d27180e 2123 * @deprecated since 2.6
3d27180e
DW
2124 */
2125function can_use_html_editor() {
1ac1d29b 2126 throw new coding_exception('can_use_html_editor has been deprecated please update your code to assume it returns true.');
3d27180e 2127}
52dc1de7
AA
2128
2129
2130/**
26e4b0ca 2131 * @deprecated since Moodle 2.7, use {@link user_count_login_failures()} instead.
52dc1de7
AA
2132 */
2133function count_login_failures($mode, $username, $lastlogin) {
26e4b0ca 2134 throw new coding_exception('count_login_failures() can not be used any more, please use user_count_login_failures().');
52dc1de7 2135}
de878a38 2136
6538153b 2137/**
44ab05b3 2138 * @deprecated since 2.7 MDL-33099/MDL-44088 - please do not use this function any more.
6538153b
FM
2139 */
2140function ajaxenabled(array $browsers = null) {
44ab05b3 2141 throw new coding_exception('ajaxenabled() can not be used anymore. Update your code to work with JS at all times.');
6538153b 2142}
8d1f33e1 2143
2144/**
e56e8e3a 2145 * @deprecated Since Moodle 2.7 MDL-44070
8d1f33e1 2146 */
2147function coursemodule_visible_for_user($cm, $userid=0) {
e56e8e3a
AA
2148 throw new coding_exception('coursemodule_visible_for_user() can not be used any more,
2149 please use \core_availability\info_module::is_user_visible()');
8d1f33e1 2150}
80f98467
MG
2151
2152/**
58b5b04d 2153 * @deprecated since Moodle 2.8 MDL-36014, MDL-35618 this functionality is removed
80f98467
MG
2154 */
2155function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
1ac1d29b
AA
2156 throw new coding_exception('Function enrol_cohort_get_cohorts() is deprecated, use enrol_cohort_search_cohorts() or '.
2157 'cohort_get_available_cohorts() instead');
80f98467
MG
2158}
2159
2160/**
80f98467
MG
2161 * This function is deprecated, use {@link cohort_can_view_cohort()} instead since it also
2162 * takes into account current context
2163 *
2164 * @deprecated since Moodle 2.8 MDL-36014 please use cohort_can_view_cohort()
80f98467
MG
2165 */
2166function enrol_cohort_can_view_cohort($cohortid) {
1ac1d29b 2167 throw new coding_exception('Function enrol_cohort_can_view_cohort() is deprecated, use cohort_can_view_cohort() instead');
80f98467
MG
2168}
2169
2170/**
80f98467
MG
2171 * It is advisable to use {@link cohort_get_available_cohorts()} instead.
2172 *
2173 * @deprecated since Moodle 2.8 MDL-36014 use cohort_get_available_cohorts() instead
80f98467
MG
2174 */
2175function cohort_get_visible_list($course, $onlyenrolled=true) {
1ac1d29b
AA
2176 throw new coding_exception('Function cohort_get_visible_list() is deprecated. Please use function cohort_get_available_cohorts() ".
2177 "that correctly checks capabilities.');
80f98467 2178}
58b5b04d
MG
2179
2180/**
58b5b04d 2181 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
58b5b04d
MG
2182 */
2183function enrol_cohort_enrol_all_users(course_enrolment_manager $manager, $cohortid, $roleid) {
1ac1d29b 2184 throw new coding_exception('enrol_cohort_enrol_all_users() is deprecated. This functionality is moved to enrol_manual.');
58b5b04d
MG
2185}
2186
2187/**
58b5b04d 2188 * @deprecated since Moodle 2.8 MDL-35618 this functionality is removed
58b5b04d
MG
2189 */
2190function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset = 0, $limit = 25, $search = '') {
1ac1d29b 2191 throw new coding_exception('enrol_cohort_search_cohorts() is deprecated. This functionality is moved to enrol_manual.');
58b5b04d 2192}
bdc83277
DM
2193
2194/**
2195 * Is $USER one of the supplied users?
2196 *
2197 * $user2 will be null if viewing a user's recent conversations
2198 *
2199 * @deprecated since Moodle 2.9 MDL-49371 - please do not use this function any more.
2200 * @todo MDL-49290 This will be deleted in Moodle 3.1.
2201 * @param stdClass the first user
2202 * @param stdClass the second user or null
2203 * @return bool True if the current user is one of either $user1 or $user2
2204 */
2205function message_current_user_is_involved($user1, $user2) {
2206 global $USER;
2207
2208 debugging('message_current_user_is_involved() is deprecated, please do not use this function.', DEBUG_DEVELOPER);
2209
2210 if (empty($user1->id) || (!empty($user2) && empty($user2->id))) {
2211 throw new coding_exception('Invalid user object detected. Missing id.');
2212 }
2213
2214 if ($user1->id != $USER->id && (empty($user2) || $user2->id != $USER->id)) {
2215 return false;
2216 }
2217 return true;
2218}
b19cc4ef
AA
2219
2220/**
2221 * Print badges on user profile page.
2222 *
2223 * @deprecated since Moodle 2.9 MDL-45898 - please do not use this function any more.
2224 * @param int $userid User ID.
2225 * @param int $courseid Course if we need to filter badges (optional).
2226 */
2227function profile_display_badges($userid, $courseid = 0) {
2228 global $CFG, $PAGE, $USER, $SITE;
2229 require_once($CFG->dirroot . '/badges/renderer.php');
2230
2231 debugging('profile_display_badges() is deprecated.', DEBUG_DEVELOPER);
2232
2233 // Determine context.
2234 if (isloggedin()) {
2235 $context = context_user::instance($USER->id);
2236 } else {
2237 $context = context_system::instance();
2238 }
2239
2240 if ($USER->id == $userid || has_capability('moodle/badges:viewotherbadges', $context)) {
2241 $records = badges_get_user_badges($userid, $courseid, null, null, null, true);
2242 $renderer = new core_badges_renderer($PAGE, '');
2243
2244 // Print local badges.
2245 if ($records) {
2246 $left = get_string('localbadgesp', 'badges', format_string($SITE->fullname));
2247 $right = $renderer->print_badges_list($records, $userid, true);
2248 echo html_writer::tag('dt', $left);
2249 echo html_writer::tag('dd', $right);
2250 }
2251
2252 // Print external badges.
2253 if ($courseid == 0 && !empty($CFG->badges_allowexternalbackpack)) {
2254 $backpack = get_backpack_settings($userid);
2255 if (isset($backpack->totalbadges) && $backpack->totalbadges !== 0) {
2256 $left = get_string('externalbadgesp', 'badges');
2257 $right = $renderer->print_badges_list($backpack->badges, $userid, true, true);
2258 echo html_writer::tag('dt', $left);
2259 echo html_writer::tag('dd', $right);
2260 }
2261 }
2262 }
2263}
efd32edb
AG
2264
2265/**
2266 * Adds user preferences elements to user edit form.
2267 *
2268 * @deprecated since Moodle 2.9 MDL-45774 - Please do not use this function any more.
2269 * @todo MDL-49784 Remove this function in Moodle 3.1
2270 * @param stdClass $user
2271 * @param moodleform $mform
2272 * @param array|null $editoroptions
2273 * @param array|null $filemanageroptions
2274 */
2275function useredit_shared_definition_preferences($user, &$mform, $editoroptions = null, $filemanageroptions = null) {
2276 global $CFG;
2277
2278 debugging('useredit_shared_definition_preferences() is deprecated.', DEBUG_DEVELOPER, backtrace);
2279
2280 $choices = array();
2281 $choices['0'] = get_string('emaildisplayno');
2282 $choices['1'] = get_string('emaildisplayyes');
2283 $choices['2'] = get_string('emaildisplaycourse');
2284 $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
2285 $mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay);
2286
2287 $choices = array();
2288 $choices['0'] = get_string('textformat');
2289 $choices['1'] = get_string('htmlformat');
2290 $mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
2291 $mform->setDefault('mailformat', $CFG->defaultpreference_mailformat);
2292
2293 if (!empty($CFG->allowusermailcharset)) {
2294 $choices = array();
2295 $charsets = get_list_of_charsets();
2296 if (!empty($CFG->sitemailcharset)) {
2297 $choices['0'] = get_string('site').' ('.$CFG->sitemailcharset.')';
2298 } else {
2299 $choices['0'] = get_string('site').' (UTF-8)';
2300 }
2301 $choices = array_merge($choices, $charsets);
2302 $mform->addElement('select', 'preference_mailcharset', get_string('emailcharset'), $choices);
2303 }
2304
2305 $choices = array();
2306 $choices['0'] = get_string('emaildigestoff');
2307 $choices['1'] = get_string('emaildigestcomplete');
2308 $choices['2'] = get_string('emaildigestsubjects');
2309 $mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
2310 $mform->setDefault('maildigest', $CFG->defaultpreference_maildigest);
2311 $mform->addHelpButton('maildigest', 'emaildigest');
2312
2313 $choices = array();
2314 $choices['1'] = get_string('autosubscribeyes');
2315 $choices['0'] = get_string('autosubscribeno');
2316 $mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
2317 $mform->setDefault('autosubscribe', $CFG->defaultpreference_autosubscribe);
2318
2319 if (!empty($CFG->forum_trackreadposts)) {
2320 $choices = array();
2321 $choices['0'] = get_string('trackforumsno');
2322 $choices['1'] = get_string('trackforumsyes');
2323 $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices);
2324 $mform->setDefault('trackforums', $CFG->defaultpreference_trackforums);
2325 }
2326
2327 $editors = editors_get_enabled();
2328 if (count($editors) > 1) {
2329 $choices = array('' => get_string('defaulteditor'));
2330 $firsteditor = '';
2331 foreach (array_keys($editors) as $editor) {
2332 if (!$firsteditor) {
2333 $firsteditor = $editor;
2334 }
2335 $choices[$editor] = get_string('pluginname', 'editor_' . $editor);
2336 }
2337 $mform->addElement('select', 'preference_htmleditor', get_string('textediting'), $choices);
2338 $mform->setDefault('preference_htmleditor', '');
2339 } else {
2340 // Empty string means use the first chosen text editor.
2341 $mform->addElement('hidden', 'preference_htmleditor');
2342 $mform->setDefault('preference_htmleditor', '');
2343 $mform->setType('preference_htmleditor', PARAM_PLUGIN);
2344 }
2345
2346 $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations());
2347 $mform->setDefault('lang', $CFG->lang);
2348
2349}