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