MDL-49684 timezones: add BC unit test first
[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
7eaca5a8 33/**
b33da4bf 34 * Add an entry to the legacy log table.
7eaca5a8
35 *
36 * @deprecated since 2.7 use new events instead
37 *
38 * @param int $courseid The course id
39 * @param string $module The module name e.g. forum, journal, resource, course, user etc
40 * @param string $action 'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
41 * @param string $url The file and parameters used to see the results of the action
42 * @param string $info Additional description information
43 * @param int $cm The course_module->id if there is one
44 * @param int|stdClass $user If log regards $user other than $USER
45 * @return void
46 */
47function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
b33da4bf 48 debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);
7eaca5a8
49
50 // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
51 // this way we may move all the legacy settings there too.
52 $manager = get_log_manager();
53 if (method_exists($manager, 'legacy_add_to_log')) {
54 $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
55 }
56}
57
114e3209
58/**
59 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
60 *
61 * @deprecated since 2.7 - use new file picker instead
62 *
114e3209
63 */
64function clam_log_upload($newfilepath, $course=null, $nourl=false) {
6dd7175a 65 throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
114e3209
66}
67
68/**
69 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
70 *
71 * @deprecated since 2.7 - use new file picker instead
72 *
114e3209
73 */
74function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
6dd7175a 75 throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
114e3209
76}
77
78/**
79 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
80 *
81 * @deprecated since 2.7 - use new file picker instead
82 *
114e3209
83 */
84function clam_change_log($oldpath, $newpath, $update=true) {
6dd7175a 85 throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
114e3209
86}
87
88/**
89 * Replaces the given file with a string.
90 *
91 * @deprecated since 2.7 - infected files are now deleted in file picker
92 *
114e3209
93 */
94function clam_replace_infected_file($file) {
6dd7175a 95 throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
114e3209
96}
97
7293a1aa
DP
98/**
99 * Deals with an infected file - either moves it to a quarantinedir
100 * (specified in CFG->quarantinedir) or deletes it.
101 *
102 * If moving it fails, it deletes it.
103 *
104 * @deprecated since 2.7
105 */
106function clam_handle_infected_file($file, $userid=0, $basiconly=false) {
107 throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
108}
109
110/**
111 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
112 *
113 * @deprecated since 2.7
114 */
115function clam_scan_moodle_file(&$file, $course) {
116 throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
117}
118
119
6780a1d3
120/**
121 * Checks whether the password compatibility library will work with the current
122 * version of PHP. This cannot be done using PHP version numbers since the fix
123 * has been backported to earlier versions in some distributions.
124 *
125 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
126 *
127 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
128 *
129 * @return bool always returns false
130 */
131function password_compat_not_supported() {
132 debugging('Do not use password_compat_not_supported() - bcrypt is now always available', DEBUG_DEVELOPER);
133 return false;
134}
135
d79d5ac2
PS
136/**
137 * Factory method that was returning moodle_session object.
138 *
139 * @deprecated since 2.6
140 * @return \core\session\manager
141 */
142function session_get_instance() {
143 // Note: the new session manager includes all methods from the original session class.
144 static $deprecatedinstance = null;
145
146 debugging('session_get_instance() is deprecated, use \core\session\manager instead', DEBUG_DEVELOPER);
147
148 if (!$deprecatedinstance) {
149 $deprecatedinstance = new \core\session\manager();
150 }
151
152 return $deprecatedinstance;
153}
154
155/**
156 * Returns true if legacy session used.
157 *
158 * @deprecated since 2.6
159 * @return bool
160 */
161function session_is_legacy() {
162 debugging('session_is_legacy() is deprecated, do not use any more', DEBUG_DEVELOPER);
163 return false;
164}
165
166/**
167 * Terminates all sessions, auth hooks are not executed.
168 * Useful in upgrade scripts.
169 *
170 * @deprecated since 2.6
171 */
172function session_kill_all() {
173 debugging('session_kill_all() is deprecated, use \core\session\manager::kill_all_sessions() instead', DEBUG_DEVELOPER);
174 \core\session\manager::kill_all_sessions();
175}
176
177/**
178 * Mark session as accessed, prevents timeouts.
179 *
180 * @deprecated since 2.6
181 * @param string $sid
182 */
183function session_touch($sid) {
184 debugging('session_touch() is deprecated, use \core\session\manager::touch_session() instead', DEBUG_DEVELOPER);
185 \core\session\manager::touch_session($sid);
186}
187
188/**
189 * Terminates one sessions, auth hooks are not executed.
190 *
191 * @deprecated since 2.6
192 * @param string $sid session id
193 */
194function session_kill($sid) {
195 debugging('session_kill() is deprecated, use \core\session\manager::kill_session() instead', DEBUG_DEVELOPER);
196 \core\session\manager::kill_session($sid);
197}
198
199/**
200 * Terminates all sessions of one user, auth hooks are not executed.
201 * NOTE: This can not work for file based sessions!
202 *
203 * @deprecated since 2.6
204 * @param int $userid user id
205 */
206function session_kill_user($userid) {
207 debugging('session_kill_user() is deprecated, use \core\session\manager::kill_user_sessions() instead', DEBUG_DEVELOPER);
208 \core\session\manager::kill_user_sessions($userid);
209}
210
d79d5ac2
PS
211/**
212 * Setup $USER object - called during login, loginas, etc.
213 *
214 * Call sync_user_enrolments() manually after log-in, or log-in-as.
215 *
216 * @deprecated since 2.6
217 * @param stdClass $user full user record object
218 * @return void
219 */
220function session_set_user($user) {
221 debugging('session_set_user() is deprecated, use \core\session\manager::set_user() instead', DEBUG_DEVELOPER);
222 \core\session\manager::set_user($user);
223}
224
225/**
226 * Is current $USER logged-in-as somebody else?
227 * @deprecated since 2.6
228 * @return bool
229 */
230function session_is_loggedinas() {
231 debugging('session_is_loggedinas() is deprecated, use \core\session\manager::is_loggedinas() instead', DEBUG_DEVELOPER);
232 return \core\session\manager::is_loggedinas();
233}
234
235/**
236 * Returns the $USER object ignoring current login-as session
237 * @deprecated since 2.6
238 * @return stdClass user object
239 */
240function session_get_realuser() {
241 debugging('session_get_realuser() is deprecated, use \core\session\manager::get_realuser() instead', DEBUG_DEVELOPER);
242 return \core\session\manager::get_realuser();
243}
244
245/**
246 * Login as another user - no security checks here.
247 * @deprecated since 2.6
248 * @param int $userid
249 * @param stdClass $context
250 * @return void
251 */
252function session_loginas($userid, $context) {
253 debugging('session_loginas() is deprecated, use \core\session\manager::loginas() instead', DEBUG_DEVELOPER);
254 \core\session\manager::loginas($userid, $context);
255}
256
6b32d6bc
PS
257/**
258 * Minify JavaScript files.
259 *
260 * @deprecated since 2.6
261 *
262 * @param array $files
263 * @return string
264 */
265function js_minify($files) {
266 debugging('js_minify() is deprecated, use core_minify::js_files() or core_minify::js() instead.');
267 return core_minify::js_files($files);
268}
269
270/**
271 * Minify CSS files.
272 *
273 * @deprecated since 2.6
274 *
275 * @param array $files
276 * @return string
277 */
278function css_minify_css($files) {
279 debugging('css_minify_css() is deprecated, use core_minify::css_files() or core_minify::css() instead.');
280 return core_minify::css_files($files);
281}
282
f0f0e1fe
PS
283/**
284 * Function to call all event handlers when triggering an event
285 *
286 * @deprecated since 2.6
287 *
288 * @param string $eventname name of the event
289 * @param mixed $eventdata event data object
290 * @return int number of failed events
291 */
292function events_trigger($eventname, $eventdata) {
9634712a 293 debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
f0f0e1fe
PS
294 return events_trigger_legacy($eventname, $eventdata);
295}
296
9e19a0f0
PS
297/**
298 * List all core subsystems and their location
299 *
300 * This is a whitelist of components that are part of the core and their
301 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
302 * plugin is not listed here and it does not have proper plugintype prefix,
303 * then it is considered as course activity module.
304 *
305 * The location is optionally dirroot relative path. NULL means there is no special
306 * directory for this subsystem. If the location is set, the subsystem's
307 * renderer.php is expected to be there.
308 *
309 * @deprecated since 2.6, use core_component::get_core_subsystems()
310 *
311 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
312 * @return array of (string)name => (string|null)location
313 */
314function get_core_subsystems($fullpaths = false) {
315 global $CFG;
316
317 // NOTE: do not add any other debugging here, keep forever.
318
319 $subsystems = core_component::get_core_subsystems();
320
321 if ($fullpaths) {
322 return $subsystems;
323 }
324
325 debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
326
327 $dlength = strlen($CFG->dirroot);
328
329 foreach ($subsystems as $k => $v) {
330 if ($v === null) {
331 continue;
332 }
333 $subsystems[$k] = substr($v, $dlength+1);
334 }
335
336 return $subsystems;
337}
338
339/**
340 * Lists all plugin types.
341 *
342 * @deprecated since 2.6, use core_component::get_plugin_types()
343 *
344 * @param bool $fullpaths false means relative paths from dirroot
345 * @return array Array of strings - name=>location
346 */
347function get_plugin_types($fullpaths = true) {
348 global $CFG;
349
350 // NOTE: do not add any other debugging here, keep forever.
351
352 $types = core_component::get_plugin_types();
353
354 if ($fullpaths) {
355 return $types;
356 }
357
358 debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);
359
360 $dlength = strlen($CFG->dirroot);
361
362 foreach ($types as $k => $v) {
363 if ($k === 'theme') {
364 $types[$k] = 'theme';
365 continue;
366 }
367 $types[$k] = substr($v, $dlength+1);
368 }
369
370 return $types;
371}
372
373/**
374 * Use when listing real plugins of one type.
375 *
376 * @deprecated since 2.6, use core_component::get_plugin_list()
377 *
378 * @param string $plugintype type of plugin
379 * @return array name=>fulllocation pairs of plugins of given type
380 */
381function get_plugin_list($plugintype) {
382
383 // NOTE: do not add any other debugging here, keep forever.
384
385 if ($plugintype === '') {
386 $plugintype = 'mod';
387 }
388
389 return core_component::get_plugin_list($plugintype);
390}
391
392/**
393 * Get a list of all the plugins of a given type that define a certain class
394 * in a certain file. The plugin component names and class names are returned.
395 *
396 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
397 *
398 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
399 * @param string $class the part of the name of the class after the
400 * frankenstyle prefix. e.g 'thing' if you are looking for classes with
401 * names like report_courselist_thing. If you are looking for classes with
402 * the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
403 * @param string $file the name of file within the plugin that defines the class.
404 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
405 * and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
406 */
407function get_plugin_list_with_class($plugintype, $class, $file) {
408
409 // NOTE: do not add any other debugging here, keep forever.
410
411 return core_component::get_plugin_list_with_class($plugintype, $class, $file);
412}
413
414/**
415 * Returns the exact absolute path to plugin directory.
416 *
417 * @deprecated since 2.6, use core_component::get_plugin_directory()
418 *
419 * @param string $plugintype type of plugin
420 * @param string $name name of the plugin
421 * @return string full path to plugin directory; NULL if not found
422 */
423function get_plugin_directory($plugintype, $name) {
424
425 // NOTE: do not add any other debugging here, keep forever.
426
427 if ($plugintype === '') {
428 $plugintype = 'mod';
429 }
430
431 return core_component::get_plugin_directory($plugintype, $name);
432}
433
434/**
435 * Normalize the component name using the "frankenstyle" names.
436 *
437 * @deprecated since 2.6, use core_component::normalize_component()
438 *
439 * @param string $component
440 * @return array as (string)$type => (string)$plugin
441 */
442function normalize_component($component) {
443
444 // NOTE: do not add any other debugging here, keep forever.
445
446 return core_component::normalize_component($component);
447}
448
449/**
450 * Return exact absolute path to a plugin directory.
451 *
452 * @deprecated since 2.6, use core_component::normalize_component()
453 *
454 * @param string $component name such as 'moodle', 'mod_forum'
455 * @return string full path to component directory; NULL if not found
456 */
457function get_component_directory($component) {
458
459 // NOTE: do not add any other debugging here, keep forever.
460
461 return core_component::get_component_directory($component);
462}
463
464
465// === Deprecated before 2.6.0 ===
466
689096bc
PS
467/**
468 * Hack to find out the GD version by parsing phpinfo output
469 *
470 * @return int GD version (1, 2, or 0)
471 */
472function check_gd_version() {
473 // TODO: delete function in Moodle 2.7
474 debugging('check_gd_version() is deprecated, GD extension is always available now');
475
476 $gdversion = 0;
477
478 if (function_exists('gd_info')){
479 $gd_info = gd_info();
480 if (substr_count($gd_info['GD Version'], '2.')) {
481 $gdversion = 2;
482 } else if (substr_count($gd_info['GD Version'], '1.')) {
483 $gdversion = 1;
484 }
485
486 } else {
487 ob_start();
488 phpinfo(INFO_MODULES);
489 $phpinfo = ob_get_contents();
490 ob_end_clean();
491
492 $phpinfo = explode("\n", $phpinfo);
493
494
495 foreach ($phpinfo as $text) {
496 $parts = explode('</td>', $text);
497 foreach ($parts as $key => $val) {
498 $parts[$key] = trim(strip_tags($val));
499 }
500 if ($parts[0] == 'GD Version') {
501 if (substr_count($parts[1], '2.0')) {
502 $parts[1] = '2.0';
503 }
504 $gdversion = intval($parts[1]);
505 }
506 }
507 }
508
509 return $gdversion; // 1, 2 or 0
510}
511
b28247fe
PS
512/**
513 * Not used any more, the account lockout handling is now
514 * part of authenticate_user_login().
515 * @deprecated
516 */
517function update_login_count() {
c4844bf4
PS
518 // TODO: delete function in Moodle 2.6
519 debugging('update_login_count() is deprecated, all calls need to be removed');
b28247fe
PS
520}
521
522/**
523 * Not used any more, replaced by proper account lockout.
524 * @deprecated
525 */
526function reset_login_count() {
c4844bf4
PS
527 // TODO: delete function in Moodle 2.6
528 debugging('reset_login_count() is deprecated, all calls need to be removed');
b28247fe
PS
529}
530
c6d75bff
PS
531/**
532 * Insert or update log display entry. Entry may already exist.
533 * $module, $action must be unique
534 * @deprecated
535 *
536 * @param string $module
537 * @param string $action
538 * @param string $mtable
539 * @param string $field
540 * @return void
541 *
542 */
543function update_log_display_entry($module, $action, $mtable, $field) {
544 global $DB;
545
546 debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
547}
548
35716b86 549/**
05226d76 550 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
35716b86 551 * this was abused mostly for embedding of attachments
35716b86
PS
552 */
553function filter_text($text, $courseid = NULL) {
e4d9185e 554 throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
35716b86
PS
555}
556
17c70aa0 557/**
17c70aa0
PS
558 * @deprecated use $PAGE->https_required() instead
559 */
560function httpsrequired() {
e4d9185e 561 throw new coding_exception('httpsrequired() can not be used any more use $PAGE->https_required() instead.');
17c70aa0
PS
562}
563
50a8bd6c
PS
564/**
565 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
566 *
567 * @deprecated use moodle_url factory methods instead
568 *
569 * @param string $path Physical path to a file
570 * @param array $options associative array of GET variables to append to the URL
571 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
572 * @return string URL to file
573 */
574function get_file_url($path, $options=null, $type='coursefile') {
17c70aa0 575 global $CFG;
50a8bd6c
PS
576
577 $path = str_replace('//', '/', $path);
578 $path = trim($path, '/'); // no leading and trailing slashes
579
580 // type of file
581 switch ($type) {
582 case 'questionfile':
583 $url = $CFG->wwwroot."/question/exportfile.php";
584 break;
585 case 'rssfile':
586 $url = $CFG->wwwroot."/rss/file.php";
587 break;
588 case 'httpscoursefile':
589 $url = $CFG->httpswwwroot."/file.php";
590 break;
591 case 'coursefile':
592 default:
593 $url = $CFG->wwwroot."/file.php";
594 }
595
596 if ($CFG->slasharguments) {
597 $parts = explode('/', $path);
598 foreach ($parts as $key => $part) {
599 /// anchor dash character should not be encoded
600 $subparts = explode('#', $part);
601 $subparts = array_map('rawurlencode', $subparts);
602 $parts[$key] = implode('#', $subparts);
603 }
604 $path = implode('/', $parts);
605 $ffurl = $url.'/'.$path;
606 $separator = '?';
607 } else {
608 $path = rawurlencode('/'.$path);
609 $ffurl = $url.'?file='.$path;
610 $separator = '&amp;';
611 }
612
613 if ($options) {
614 foreach ($options as $name=>$value) {
615 $ffurl = $ffurl.$separator.$name.'='.$value;
616 $separator = '&amp;';
617 }
618 }
619
620 return $ffurl;
621}
622
613bbd7c 623/**
05226d76 624 * @deprecated use get_enrolled_users($context) instead.
613bbd7c 625 */
4f0c2d00 626function get_course_participants($courseid) {
e4d9185e 627 throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
613bbd7c 628}
629
613bbd7c 630/**
05226d76 631 * @deprecated use is_enrolled($context, $userid) instead.
613bbd7c 632 */
4f0c2d00 633function is_course_participant($userid, $courseid) {
e4d9185e 634 throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
613bbd7c 635}
636
637/**
638 * Searches logs to find all enrolments since a certain date
639 *
640 * used to print recent activity
641 *
613bbd7c 642 * @param int $courseid The course in question.
c861fe2f 643 * @param int $timestart The date to check forward of
613bbd7c 644 * @return object|false {@link $USER} records or false if error.
613bbd7c 645 */
646function get_recent_enrolments($courseid, $timestart) {
10df888a 647 global $DB;
364fffda 648
02ca2cad 649 debugging('get_recent_enrolments() is deprecated as it returned inaccurate results.', DEBUG_DEVELOPER);
613bbd7c 650
02ca2cad 651 $context = context_course::instance($courseid);
210751f6 652 $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
10df888a 653 FROM {user} u, {role_assignments} ra, {log} l
654 WHERE l.time > ?
655 AND l.course = ?
656 AND l.module = 'course'
657 AND l.action = 'enrol'
9f43d70d 658 AND ".$DB->sql_cast_char2int('l.info')." = u.id
10df888a 659 AND u.id = ra.userid
660 AND ra.contextid ".get_related_contexts_string($context)."
210751f6
PS
661 GROUP BY u.id, u.firstname, u.lastname
662 ORDER BY MAX(l.time) ASC";
10df888a 663 $params = array($timestart, $courseid);
664 return $DB->get_records_sql($sql, $params);
613bbd7c 665}
666
ed5dd29f 667/**
05226d76 668 * @deprecated use clean_param($string, PARAM_FILE) instead.
ed5dd29f 669 */
670function detect_munged_arguments($string, $allowdots=1) {
e4d9185e 671 throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
ed5dd29f 672}
673
9152fc99 674
0c6d2dd4 675/**
676 * Unzip one zip file to a destination dir
677 * Both parameters must be FULL paths
678 * If destination isn't specified, it will be the
679 * SAME directory where the zip file resides.
c861fe2f 680 *
681 * @global object
682 * @param string $zipfile The zip file to unzip
683 * @param string $destination The location to unzip to
684 * @param bool $showstatus_ignored Unused
0c6d2dd4 685 */
686function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
687 global $CFG;
688
689 //Extract everything from zipfile
690 $path_parts = pathinfo(cleardoubleslashes($zipfile));
691 $zippath = $path_parts["dirname"]; //The path of the zip file
692 $zipfilename = $path_parts["basename"]; //The name of the zip file
693 $extension = $path_parts["extension"]; //The extension of the file
694
695 //If no file, error
696 if (empty($zipfilename)) {
697 return false;
698 }
699
700 //If no extension, error
701 if (empty($extension)) {
702 return false;
703 }
704
705 //Clear $zipfile
706 $zipfile = cleardoubleslashes($zipfile);
707
708 //Check zipfile exists
709 if (!file_exists($zipfile)) {
710 return false;
711 }
712
713 //If no destination, passed let's go with the same directory
714 if (empty($destination)) {
715 $destination = $zippath;
716 }
717
718 //Clear $destination
719 $destpath = rtrim(cleardoubleslashes($destination), "/");
720
721 //Check destination path exists
722 if (!is_dir($destpath)) {
723 return false;
724 }
725
0b0bfa93 726 $packer = get_file_packer('application/zip');
727
728 $result = $packer->extract_to_pathname($zipfile, $destpath);
0c6d2dd4 729
730 if ($result === false) {
731 return false;
732 }
733
734 foreach ($result as $status) {
735 if ($status !== true) {
736 return false;
737 }
738 }
739
740 return true;
741}
742
ed94cb66 743/**
744 * Zip an array of files/dirs to a destination zip file
745 * Both parameters must be FULL paths to the files/dirs
c861fe2f 746 *
747 * @global object
748 * @param array $originalfiles Files to zip
749 * @param string $destination The destination path
750 * @return bool Outcome
ed94cb66 751 */
752function zip_files ($originalfiles, $destination) {
753 global $CFG;
754
755 //Extract everything from destination
756 $path_parts = pathinfo(cleardoubleslashes($destination));
757 $destpath = $path_parts["dirname"]; //The path of the zip file
758 $destfilename = $path_parts["basename"]; //The name of the zip file
759 $extension = $path_parts["extension"]; //The extension of the file
760
761 //If no file, error
762 if (empty($destfilename)) {
763 return false;
764 }
765
766 //If no extension, add it
767 if (empty($extension)) {
768 $extension = 'zip';
769 $destfilename = $destfilename.'.'.$extension;
770 }
771
772 //Check destination path exists
773 if (!is_dir($destpath)) {
774 return false;
775 }
776
777 //Check destination path is writable. TODO!!
778
779 //Clean destination filename
780 $destfilename = clean_filename($destfilename);
781
782 //Now check and prepare every file
783 $files = array();
784 $origpath = NULL;
785
786 foreach ($originalfiles as $file) { //Iterate over each file
787 //Check for every file
788 $tempfile = cleardoubleslashes($file); // no doubleslashes!
789 //Calculate the base path for all files if it isn't set
790 if ($origpath === NULL) {
791 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
792 }
793 //See if the file is readable
794 if (!is_readable($tempfile)) { //Is readable
795 continue;
796 }
797 //See if the file/dir is in the same directory than the rest
798 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
799 continue;
800 }
801 //Add the file to the array
802 $files[] = $tempfile;
803 }
804
805 $zipfiles = array();
806 $start = strlen($origpath)+1;
807 foreach($files as $file) {
808 $zipfiles[substr($file, $start)] = $file;
809 }
810
0b0bfa93 811 $packer = get_file_packer('application/zip');
ed94cb66 812
3ed22f1a 813 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
ed94cb66 814}
815
5bf243d1 816/**
05226d76 817 * @deprecated use groups_get_all_groups() instead.
5bf243d1 818 */
819function mygroupid($courseid) {
e4d9185e 820 throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
5bf243d1 821}
822
5bf243d1 823
5bf243d1 824/**
825 * Returns the current group mode for a given course or activity module
364fffda 826 *
5bf243d1 827 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
c861fe2f 828 *
829 * @param object $course Course Object
830 * @param object $cm Course Manager Object
831 * @return mixed $course->groupmode
5bf243d1 832 */
833function groupmode($course, $cm=null) {
834
835 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
836 return $cm->groupmode;
837 }
838 return $course->groupmode;
839}
840
c584346c 841/**
842 * Sets the current group in the session variable
843 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
844 * Sets currentgroup[$courseid] in the session variable appropriately.
845 * Does not do any permission checking.
c861fe2f 846 *
847 * @global object
c584346c 848 * @param int $courseid The course being examined - relates to id field in
849 * 'course' table.
850 * @param int $groupid The group being examined.
851 * @return int Current group id which was set by this function
852 */
853function set_current_group($courseid, $groupid) {
854 global $SESSION;
855 return $SESSION->currentgroup[$courseid] = $groupid;
856}
857
5bf243d1 858
5bf243d1 859/**
364fffda 860 * Gets the current group - either from the session variable or from the database.
5bf243d1 861 *
c861fe2f 862 * @global object
364fffda 863 * @param int $courseid The course being examined - relates to id field in
5bf243d1 864 * 'course' table.
364fffda 865 * @param bool $full If true, the return value is a full record object.
5bf243d1 866 * If false, just the id of the record.
c861fe2f 867 * @return int|bool
5bf243d1 868 */
869function get_current_group($courseid, $full = false) {
870 global $SESSION;
871
872 if (isset($SESSION->currentgroup[$courseid])) {
873 if ($full) {
874 return groups_get_group($SESSION->currentgroup[$courseid]);
875 } else {
876 return $SESSION->currentgroup[$courseid];
877 }
878 }
879
880 $mygroupid = mygroupid($courseid);
881 if (is_array($mygroupid)) {
882 $mygroupid = array_shift($mygroupid);
883 set_current_group($courseid, $mygroupid);
884 if ($full) {
885 return groups_get_group($mygroupid);
886 } else {
887 return $mygroupid;
888 }
889 }
890
891 if ($full) {
892 return false;
893 } else {
894 return 0;
895 }
896}
897
061e6b28 898/**
899 * Filter a user list and return only the users that can see the course module based on
900 * groups/permissions etc. It is assumed that the users are pre-filtered to those who are enrolled in the course.
901 *
902 * @category group
903 * @param stdClass|cm_info $cm The course module
904 * @param array $users An array of users, indexed by userid
905 * @return array A filtered list of users that can see the module, indexed by userid.
906 * @deprecated Since Moodle 2.8
907 */
908function groups_filter_users_by_course_module_visible($cm, $users) {
909 debugging('groups_filter_users_by_course_module_visible() is deprecated. ' .
910 'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
911 'which does basically the same thing but includes other restrictions such ' .
912 'as profile restrictions.', DEBUG_DEVELOPER);
913 if (empty($users)) {
914 return $users;
915 }
916 // Since this function allows stdclass, let's play it safe and ensure we
917 // do have a cm_info.
918 if (!($cm instanceof cm_info)) {
919 $modinfo = get_fast_modinfo($cm->course);
920 $cm = $modinfo->get_cm($cm->id);
921 }
922 $info = new \core_availability\info_module($cm);
923 return $info->filter_user_list($users);
924}
925
926/**
927 * Determine if a course module is currently visible to a user
928 *
929 * Deprecated (it was never very useful as it only took into account the
930 * groupmembersonly option and no other way of hiding activities). Always
931 * returns true.
932 *
933 * @category group
934 * @param stdClass|cm_info $cm The course module
935 * @param int $userid The user to check against the group.
936 * @return bool True
937 * @deprecated Since Moodle 2.8
938 */
939function groups_course_module_visible($cm, $userid=null) {
940 debugging('groups_course_module_visible() is deprecated and always returns ' .
941 'true; use $cm->uservisible to decide whether the current user can ' .
942 'access an activity.', DEBUG_DEVELOPER);
943 return true;
944}
5bf243d1 945
8ec50604 946/**
a8ab8de9
PS
947 * Inndicates fatal error. This function was originally printing the
948 * error message directly, since 2.0 it is throwing exception instead.
3400bf6c 949 * The error printing is handled in default exception handler.
a8ab8de9 950 *
8ec50604 951 * Old method, don't call directly in new code - use print_error instead.
952 *
8ec50604 953 * @param string $message The message to display to the user about the error.
954 * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
a8ab8de9 955 * @return void, always throws moodle_exception
8ec50604 956 */
245ac557 957function error($message, $link='') {
78946b9b 958 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
251387d0 959}
8ec50604 960
8ec50604 961
b7009474 962/**
963 * @deprecated use $PAGE->theme->name instead.
b7009474 964 */
965function current_theme() {
e4d9185e 966 throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
b7009474 967}
968
8954245a 969/**
970 * Prints some red text using echo
971 *
972 * @deprecated
973 * @param string $error The text to be displayed in red
974 */
975function formerr($error) {
3bd6b994 976 debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
8954245a 977 global $OUTPUT;
978 echo $OUTPUT->error_text($error);
979}
980
34a2777c 981/**
34a2777c 982 * @deprecated use $OUTPUT->skip_link_target() in instead.
34a2777c 983 */
984function skip_main_destination() {
e4d9185e 985 throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
34a2777c 986}
987
34a2777c 988/**
05226d76 989 * @deprecated use $OUTPUT->container() instead.
34a2777c 990 */
991function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
e4d9185e 992 throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
34a2777c 993}
994
995/**
05226d76 996 * @deprecated use $OUTPUT->container_start() instead.
34a2777c 997 */
998function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
e4d9185e 999 throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
34a2777c 1000}
1001
1002/**
05226d76 1003 * @deprecated use $OUTPUT->container_end() instead.
34a2777c 1004 */
1005function print_container_end($return=false) {
e4d9185e 1006 throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
34a2777c 1007}
1008
1009/**
1010 * Print a bold message in an optional color.
1011 *
1012 * @deprecated use $OUTPUT->notification instead.
1013 * @param string $message The message to print out
1014 * @param string $style Optional style to display message text in
1015 * @param string $align Alignment option
1016 * @param bool $return whether to return an output string or echo now
a5cb8d69 1017 * @return string|bool Depending on $result
34a2777c 1018 */
1019function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1020 global $OUTPUT;
1021
1022 if ($classes == 'green') {
1023 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1024 $classes = 'notifysuccess'; // Backward compatible with old color system
1025 }
1026
1027 $output = $OUTPUT->notification($message, $classes);
1028 if ($return) {
1029 return $output;
1030 } else {
1031 echo $output;
1032 }
1033}
1034
1035/**
05226d76 1036 * @deprecated use $OUTPUT->continue_button() instead.
34a2777c 1037 */
1038function print_continue($link, $return = false) {
e4d9185e 1039 throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
34a2777c 1040}
1041
34a2777c 1042/**
05226d76 1043 * @deprecated use $PAGE methods instead.
34a2777c 1044 */
1045function print_header($title='', $heading='', $navigation='', $focus='',
e120c61d 1046 $meta='', $cache=true, $button='&nbsp;', $menu=null,
34a2777c 1047 $usexml=false, $bodytags='', $return=false) {
34a2777c 1048
e4d9185e 1049 throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
34a2777c 1050}
1051
47a1aa45 1052/**
05226d76 1053 * @deprecated use $PAGE methods instead.
47a1aa45 1054 */
1055function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
1056 $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
1057
e4d9185e 1058 throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
47a1aa45 1059}
1060
a5cb8d69 1061/**
05226d76 1062 * @deprecated use $OUTPUT->block() instead.
a5cb8d69 1063 */
1064function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
e4d9185e 1065 throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
a5cb8d69 1066}
1067
f8065dd2 1068/**
1069 * Prints a basic textarea field.
1070 *
1071 * @deprecated since Moodle 2.0
1072 *
1073 * When using this function, you should
1074 *
1075 * @global object
3d27180e 1076 * @param bool $unused No longer used.
f8065dd2 1077 * @param int $rows Number of rows to display (minimum of 10 when $height is non-null)
1078 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
1079 * @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.
1080 * @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.
1081 * @param string $name Name to use for the textarea element.
1082 * @param string $value Initial content to display in the textarea.
1083 * @param int $obsolete deprecated
1084 * @param bool $return If false, will output string. If true, will return string value.
1085 * @param string $id CSS ID to add to the textarea element.
1086 * @return string|void depending on the value of $return
1087 */
3d27180e 1088function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
f8065dd2 1089 /// $width and height are legacy fields and no longer used as pixels like they used to be.
1090 /// However, you can set them to zero to override the mincols and minrows values below.
1091
3d8a479b
MD
1092 // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
1093 // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
f8065dd2 1094
1095 global $CFG;
1096
1097 $mincols = 65;
1098 $minrows = 10;
1099 $str = '';
1100
1101 if ($id === '') {
1102 $id = 'edit-'.$name;
1103 }
1104
3d27180e
DW
1105 if ($height && ($rows < $minrows)) {
1106 $rows = $minrows;
f8065dd2 1107 }
3d27180e
DW
1108 if ($width && ($cols < $mincols)) {
1109 $cols = $mincols;
f8065dd2 1110 }
1111
3d27180e
DW
1112 editors_head_setup();
1113 $editor = editors_get_preferred_editor(FORMAT_HTML);
1114 $editor->use_editor($id, array('legacy'=>true));
1115
0ac97084 1116 $str .= "\n".'<textarea class="form-textarea" id="'. $id .'" name="'. $name .'" rows="'. $rows .'" cols="'. $cols .'" spellcheck="true">'."\n";
3d27180e 1117 $str .= htmlspecialchars($value); // needed for editing of cleaned text!
f8065dd2 1118 $str .= '</textarea>'."\n";
1119
1120 if ($return) {
1121 return $str;
1122 }
1123 echo $str;
1124}
1125
4bcc5118
PS
1126/**
1127 * Returns a string of html with an image of a help icon linked to a help page on a number of help topics.
1128 * Should be used only with htmleditor or textarea.
1129 *
1130 * @global object
1131 * @global object
1132 * @param mixed $helptopics variable amount of params accepted. Each param may be a string or an array of arguments for
1133 * helpbutton.
1134 * @return string Link to help button
1135 */
1136function editorhelpbutton(){
1137 return '';
1138
1139 /// TODO: MDL-21215
f8065dd2 1140}
1141
4bcc5118
PS
1142/**
1143 * Print a help button.
1144 *
1145 * Prints a special help button for html editors (htmlarea in this case)
1146 *
1147 * @todo Write code into this function! detect current editor and print correct info
1148 * @global object
1149 * @return string Only returns an empty string at the moment
1150 */
1151function editorshortcutshelpbutton() {
1152 /// TODO: MDL-21215
1153
1154 global $CFG;
1155 //TODO: detect current editor and print correct info
4bcc5118
PS
1156 return '';
1157}
1158
1159
f8065dd2 1160/**
1161 * Returns an image of an up or down arrow, used for column sorting. To avoid unnecessary DB accesses, please
1162 * provide this function with the language strings for sortasc and sortdesc.
1163 *
05226d76 1164 * @deprecated use $OUTPUT->arrow() instead.
e4d9185e 1165 * @todo final deprecation of this function once MDL-45448 is resolved
f8065dd2 1166 *
f8065dd2 1167 * If no sort string is associated with the direction, an arrow with no alt text will be printed/returned.
1168 *
1169 * @global object
1170 * @param string $direction 'up' or 'down'
1171 * @param string $strsort The language string used for the alt attribute of this image
1172 * @param bool $return Whether to print directly or return the html string
1173 * @return string|void depending on $return
1174 *
1175 */
1176function print_arrow($direction='up', $strsort=null, $return=false) {
f8065dd2 1177 global $OUTPUT;
1178
05226d76
DP
1179 debugging('print_arrow() is deprecated. Please use $OUTPUT->arrow() instead.', DEBUG_DEVELOPER);
1180
f8065dd2 1181 if (!in_array($direction, array('up', 'down', 'right', 'left', 'move'))) {
1182 return null;
1183 }
1184
1185 $return = null;
1186
1187 switch ($direction) {
1188 case 'up':
1189 $sortdir = 'asc';
1190 break;
1191 case 'down':
1192 $sortdir = 'desc';
1193 break;
1194 case 'move':
1195 $sortdir = 'asc';
1196 break;
1197 default:
1198 $sortdir = null;
1199 break;
1200 }
1201
1202 // Prepare language string
1203 $strsort = '';
1204 if (empty($strsort) && !empty($sortdir)) {
1205 $strsort = get_string('sort' . $sortdir, 'grades');
1206 }
1207
b5d0cafc 1208 $return = ' <img src="'.$OUTPUT->pix_url('t/' . $direction) . '" alt="'.$strsort.'" /> ';
f8065dd2 1209
1210 if ($return) {
1211 return $return;
1212 } else {
1213 echo $return;
1214 }
1215}
1216
8100c169 1217/**
1218 * Given an array of values, output the HTML for a select element with those options.
1219 *
1220 * @deprecated since Moodle 2.0
1221 *
1222 * Normally, you only need to use the first few parameters.
1223 *
1224 * @param array $options The options to offer. An array of the form
1225 * $options[{value}] = {text displayed for that option};
1226 * @param string $name the name of this form control, as in &lt;select name="..." ...
1227 * @param string $selected the option to select initially, default none.
1228 * @param string $nothing The label for the 'nothing is selected' option. Defaults to get_string('choose').
1229 * Set this to '' if you don't want a 'nothing is selected' option.
1230 * @param string $script if not '', then this is added to the &lt;select> element as an onchange handler.
1231 * @param string $nothingvalue The value corresponding to the $nothing option. Defaults to 0.
1232 * @param boolean $return if false (the default) the the output is printed directly, If true, the
1233 * generated HTML is returned as a string.
1234 * @param boolean $disabled if true, the select is generated in a disabled state. Default, false.
1235 * @param int $tabindex if give, sets the tabindex attribute on the &lt;select> element. Default none.
1236 * @param string $id value to use for the id attribute of the &lt;select> element. If none is given,
1237 * then a suitable one is constructed.
1238 * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box.
1239 * By default, the list box will have a number of rows equal to min(10, count($options)), but if
1240 * $listbox is an integer, that number is used for size instead.
1241 * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used
1242 * when $listbox display is enabled
1243 * @param string $class value to use for the class attribute of the &lt;select> element. If none is given,
1244 * then a suitable one is constructed.
1245 * @return string|void If $return=true returns string, else echo's and returns void
1246 */
1247function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='',
1248 $nothingvalue='0', $return=false, $disabled=false, $tabindex=0,
1249 $id='', $listbox=false, $multiple=false, $class='') {
053203a8 1250
8100c169 1251 global $OUTPUT;
4461cc60 1252 debugging('choose_from_menu() has been deprecated. Please change your code to use html_writer::select().');
053203a8 1253
1254 if ($script) {
1255 debugging('The $script parameter has been deprecated. You must use component_actions instead', DEBUG_DEVELOPER);
1256 }
4461cc60
PS
1257 $attributes = array();
1258 $attributes['disabled'] = $disabled ? 'disabled' : null;
1259 $attributes['tabindex'] = $tabindex ? $tabindex : null;
1260 $attributes['multiple'] = $multiple ? $multiple : null;
1261 $attributes['class'] = $class ? $class : null;
1262 $attributes['id'] = $id ? $id : null;
053203a8 1263
4461cc60 1264 $output = html_writer::select($options, $name, $selected, array($nothingvalue=>$nothing), $attributes);
053203a8 1265
1266 if ($return) {
1267 return $output;
1268 } else {
1269 echo $output;
8100c169 1270 }
053203a8 1271}
1272
c68e4098 1273/**
05226d76 1274 * @deprecated use $OUTPUT->help_icon_scale($courseid, $scale) instead.
c68e4098 1275 */
1276function print_scale_menu_helpbutton($courseid, $scale, $return=false) {
e4d9185e
DP
1277 throw new coding_exception('print_scale_menu_helpbutton() can not be used any more. '.
1278 'Please use $OUTPUT->help_icon_scale($courseid, $scale) instead.');
c68e4098 1279}
1280
49c8c8d2 1281/**
05226d76 1282 * @deprecated use html_writer::checkbox() instead.
49c8c8d2 1283 */
916276fc 1284function print_checkbox($name, $value, $checked = true, $label = '', $alt = '', $script='', $return=false) {
e4d9185e 1285 throw new coding_exception('print_checkbox() can not be used any more. Please use html_writer::checkbox() instead.');
49c8c8d2 1286}
6a5c71b9 1287
c351150f 1288/**
1289 * Prints the 'update this xxx' button that appears on module pages.
1290 *
1291 * @deprecated since Moodle 2.0
1292 *
1293 * @param string $cmid the course_module id.
1294 * @param string $ignored not used any more. (Used to be courseid.)
1295 * @param string $string the module name - get_string('modulename', 'xxx')
1296 * @return string the HTML for the button, if this user has permission to edit it, else an empty string.
1297 */
1298function update_module_button($cmid, $ignored, $string) {
d1f06fb5 1299 global $CFG, $OUTPUT;
c351150f 1300
bc2e0484 1301 // debugging('update_module_button() has been deprecated. Please change your code to use $OUTPUT->update_module_button().');
c351150f 1302
d1f06fb5 1303 //NOTE: DO NOT call new output method because it needs the module name we do not have here!
1304
b0c6dc1c 1305 if (has_capability('moodle/course:manageactivities', context_module::instance($cmid))) {
d1f06fb5 1306 $string = get_string('updatethis', '', $string);
1307
5c2ed7e2
PS
1308 $url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
1309 return $OUTPUT->single_button($url, $string);
d1f06fb5 1310 } else {
1311 return '';
1312 }
c351150f 1313}
1314
7d2a0492 1315/**
05226d76 1316 * @deprecated use $OUTPUT->navbar() instead
7d2a0492 1317 */
1318function print_navigation ($navigation, $separator=0, $return=false) {
e4d9185e 1319 throw new coding_exception('print_navigation() can not be used any more, please update use $OUTPUT->navbar() instead.');
7d2a0492 1320}
1321
1322/**
05226d76 1323 * @deprecated Please use $PAGE->navabar methods instead.
7d2a0492 1324 */
1325function build_navigation($extranavlinks, $cm = null) {
e4d9185e 1326 throw new coding_exception('build_navigation() can not be used any more, please use $PAGE->navbar methods instead.');
7d2a0492 1327}
1328
1329/**
05226d76 1330 * @deprecated not relevant with global navigation in Moodle 2.x+
7d2a0492 1331 */
1332function navmenu($course, $cm=NULL, $targetwindow='self') {
e4d9185e 1333 throw new coding_exception('navmenu() can not be used any more, it is no longer relevant with global navigation.');
f43cdceb 1334}
76d9df3f
SH
1335
1336/// CALENDAR MANAGEMENT ////////////////////////////////////////////////////////////////
1337
1338
1339/**
05226d76 1340 * @deprecated please use calendar_event::create() instead.
76d9df3f
SH
1341 */
1342 function add_event($event) {
e4d9185e 1343 throw new coding_exception('add_event() can not be used any more, please use calendar_event::create() instead.');
76d9df3f
SH
1344}
1345
1346/**
1347 * Call this function to update an event in the calendar table
1348 * the event will be identified by the id field of the $event object.
1349 *
1350 * @param object $event An object representing an event from the calendar table. The event will be identified by the id field.
1351 * @return bool Success
05226d76 1352 * @deprecated please calendar_event->update() instead.
76d9df3f
SH
1353 */
1354function update_event($event) {
1355 global $CFG;
1356 require_once($CFG->dirroot.'/calendar/lib.php');
05226d76
DP
1357
1358 debugging('update_event() is deprecated, please use calendar_event->update() instead.', DEBUG_DEVELOPER);
76d9df3f
SH
1359 $event = (object)$event;
1360 $calendarevent = calendar_event::load($event->id);
1361 return $calendarevent->update($event);
1362}
1363
1364/**
05226d76 1365 * @deprecated please use calendar_event->delete() instead.
76d9df3f
SH
1366 */
1367function delete_event($id) {
e4d9185e
DP
1368 throw new coding_exception('delete_event() can not be used any more, please use '.
1369 'calendar_event->delete() instead.');
76d9df3f
SH
1370}
1371
1372/**
05226d76 1373 * @deprecated please use calendar_event->toggle_visibility(false) instead.
76d9df3f
SH
1374 */
1375function hide_event($event) {
e4d9185e
DP
1376 throw new coding_exception('hide_event() can not be used any more, please use '.
1377 'calendar_event->toggle_visibility(false) instead.');
76d9df3f
SH
1378}
1379
1380/**
05226d76 1381 * @deprecated please use calendar_event->toggle_visibility(true) instead.
76d9df3f
SH
1382 */
1383function show_event($event) {
e4d9185e
DP
1384 throw new coding_exception('show_event() can not be used any more, please use '.
1385 'calendar_event->toggle_visibility(true) instead.');
0189bf77 1386}
6f3451e5 1387
3fed29a7
PS
1388/**
1389 * Original singleton helper function, please use static methods instead,
6b61c2c4 1390 * ex: core_text::convert().
3fed29a7 1391 *
6b61c2c4
FM
1392 * @deprecated since Moodle 2.2 use core_text::xxxx() instead.
1393 * @see core_text
3fed29a7
PS
1394 */
1395function textlib_get_instance() {
6b61c2c4
FM
1396 throw new coding_exception('textlib_get_instance() can not be used any more, please use '.
1397 'core_text::functioname() instead.');
3fed29a7
PS
1398}
1399
ee7084e9
MG
1400/**
1401 * Gets the generic section name for a courses section
1402 *
1403 * The global function is deprecated. Each course format can define their own generic section name
1404 *
1405 * @deprecated since 2.4
1406 * @see get_section_name()
1407 * @see format_base::get_section_name()
1408 *
1409 * @param string $format Course format ID e.g. 'weeks' $course->format
1410 * @param stdClass $section Section object from database
1411 * @return Display name that the course format prefers, e.g. "Week 2"
1412 */
1413function get_generic_section_name($format, stdClass $section) {
1414 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
1415 return get_string('sectionname', "format_$format") . ' ' . $section->section;
1416}
99e9f9a6
MG
1417
1418/**
1419 * Returns an array of sections for the requested course id
1420 *
1421 * It is usually not recommended to display the list of sections used
1422 * in course because the course format may have it's own way to do it.
1423 *
1424 * If you need to just display the name of the section please call:
1425 * get_section_name($course, $section)
1426 * {@link get_section_name()}
1427 * from 2.4 $section may also be just the field course_sections.section
1428 *
1429 * If you need the list of all sections it is more efficient to get this data by calling
b46be6ad 1430 * $modinfo = get_fast_modinfo($courseorid);
99e9f9a6
MG
1431 * $sections = $modinfo->get_section_info_all()
1432 * {@link get_fast_modinfo()}
1433 * {@link course_modinfo::get_section_info_all()}
1434 *
1435 * Information about one section (instance of section_info):
b46be6ad 1436 * get_fast_modinfo($courseorid)->get_sections_info($section)
99e9f9a6
MG
1437 * {@link course_modinfo::get_section_info()}
1438 *
1439 * @deprecated since 2.4
1440 *
1441 * @param int $courseid
1442 * @return array Array of section_info objects
1443 */
1444function get_all_sections($courseid) {
1445 global $DB;
1446 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
b46be6ad 1447 return get_fast_modinfo($courseid)->get_section_info_all();
99e9f9a6 1448}
722e6ba9
MG
1449
1450/**
1451 * Given a full mod object with section and course already defined, adds this module to that section.
1452 *
1453 * This function is deprecated, please use {@link course_add_cm_to_section()}
1454 * Note that course_add_cm_to_section() also updates field course_modules.section and
1455 * calls rebuild_course_cache()
1456 *
1457 * @deprecated since 2.4
1458 *
1459 * @param object $mod
1460 * @param int $beforemod An existing ID which we will insert the new module before
1461 * @return int The course_sections ID where the mod is inserted
1462 */
44aa854e 1463function add_mod_to_section($mod, $beforemod = null) {
722e6ba9
MG
1464 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
1465 global $DB;
b46be6ad 1466 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
722e6ba9 1467}
d57aa283
MG
1468
1469/**
1470 * Returns a number of useful structures for course displays
1471 *
1472 * Function get_all_mods() is deprecated in 2.4
1473 * Instead of:
1474 * <code>
b46be6ad 1475 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
d57aa283
MG
1476 * </code>
1477 * please use:
1478 * <code>
b46be6ad 1479 * $mods = get_fast_modinfo($courseorid)->get_cms();
d57aa283
MG
1480 * $modnames = get_module_types_names();
1481 * $modnamesplural = get_module_types_names(true);
b46be6ad 1482 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
d57aa283
MG
1483 * </code>
1484 *
1485 * @deprecated since 2.4
1486 *
1487 * @param int $courseid id of the course to get info about
1488 * @param array $mods (return) list of course modules
1489 * @param array $modnames (return) list of names of all module types installed and available
1490 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
1491 * @param array $modnamesused (return) list of names of all module types used in the course
1492 */
1493function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1494 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
1495
1496 global $COURSE;
1497 $modnames = get_module_types_names();
1498 $modnamesplural= get_module_types_names(true);
b46be6ad 1499 $modinfo = get_fast_modinfo($courseid);
d57aa283
MG
1500 $mods = $modinfo->get_cms();
1501 $modnamesused = $modinfo->get_used_module_names();
1502}
4ede27b2
MG
1503
1504/**
1505 * Returns course section - creates new if does not exist yet
1506 *
1507 * This function is deprecated. To create a course section call:
b46be6ad 1508 * course_create_sections_if_missing($courseorid, $sections);
4ede27b2 1509 * to get the section call:
b46be6ad 1510 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
4ede27b2
MG
1511 *
1512 * @see course_create_sections_if_missing()
1513 * @see get_fast_modinfo()
1514 * @deprecated since 2.4
1515 *
1516 * @param int $section relative section number (field course_sections.section)
1517 * @param int $courseid
1518 * @return stdClass record from table {course_sections}
1519 */
1520function get_course_section($section, $courseid) {
1521 global $DB;
1522 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
1523
1524 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
1525 return $cw;
1526 }
1527 $cw = new stdClass();
1528 $cw->course = $courseid;
1529 $cw->section = $section;
1530 $cw->summary = "";
1531 $cw->summaryformat = FORMAT_HTML;
1532 $cw->sequence = "";
1533 $id = $DB->insert_record("course_sections", $cw);
1534 rebuild_course_cache($courseid, true);
1535 return $DB->get_record("course_sections", array("id"=>$id));
1536}
1b2581f4
MG
1537
1538/**
1539 * Return the start and end date of the week in Weekly course format
1540 *
1541 * It is not recommended to use this function outside of format_weeks plugin
1542 *
1543 * @deprecated since 2.4
1544 * @see format_weeks::get_section_dates()
1545 *
1546 * @param stdClass $section The course_section entry from the DB
1547 * @param stdClass $course The course entry from DB
1548 * @return stdClass property start for startdate, property end for enddate
1549 */
1550function format_weeks_get_section_dates($section, $course) {
1551 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
1552 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
1553 if (isset($course->format) && $course->format === 'weeks') {
1554 return course_get_format($course)->get_section_dates($section);
1555 }
1556 return null;
1557}
9a36be73
MG
1558
1559/**
1560 * Obtains shared data that is used in print_section when displaying a
1561 * course-module entry.
1562 *
1563 * Deprecated. Instead of:
1564 * list($content, $name) = get_print_section_cm_text($cm, $course);
1565 * use:
1566 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
1567 * $name = $cm->get_formatted_name();
1568 *
1569 * @deprecated since 2.5
1570 * @see cm_info::get_formatted_content()
1571 * @see cm_info::get_formatted_name()
1572 *
1573 * This data is also used in other areas of the code.
1574 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
1575 * @param object $course (argument not used)
1576 * @return array An array with the following values in this order:
1577 * $content (optional extra content for after link),
1578 * $instancename (text of link)
1579 */
1580function get_print_section_cm_text(cm_info $cm, $course) {
1581 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
1582 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
1583 DEBUG_DEVELOPER);
1584 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
1585 $cm->get_formatted_name());
1586}
1587
1588/**
1589 * Prints the menus to add activities and resources.
1590 *
1591 * Deprecated. Please use:
1592 * $courserenderer = $PAGE->get_renderer('core', 'course');
1593 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1594 * array('inblock' => $vertical));
1595 * echo $output; // if $return argument in print_section_add_menus() set to false
1596 *
1597 * @deprecated since 2.5
1598 * @see core_course_renderer::course_section_add_cm_control()
1599 *
1600 * @param stdClass $course course object, must be the same as set on the page
1601 * @param int $section relative section number (field course_sections.section)
1602 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
1603 * @param bool $vertical Vertical orientation
1604 * @param bool $return Return the menus or send them to output
1605 * @param int $sectionreturn The section to link back to
1606 * @return void|string depending on $return
1607 */
1608function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
1609 global $PAGE;
1610 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
1611 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
1612 $output = '';
1613 $courserenderer = $PAGE->get_renderer('core', 'course');
1614 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1615 array('inblock' => $vertical));
1616 if ($return) {
1617 return $output;
1618 } else {
1619 echo $output;
1620 return !empty($output);
1621 }
1622}
1623
1624/**
1625 * Produces the editing buttons for a module
1626 *
1627 * Deprecated. Please use:
1628 * $courserenderer = $PAGE->get_renderer('core', 'course');
1629 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1630 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1631 *
1632 * @deprecated since 2.5
1633 * @see course_get_cm_edit_actions()
1634 * @see core_course_renderer->course_section_cm_edit_actions()
1635 *
1636 * @param stdClass $mod The module to produce editing buttons for
1637 * @param bool $absolute_ignored (argument ignored) - all links are absolute
1638 * @param bool $moveselect (argument ignored)
1639 * @param int $indent The current indenting
1640 * @param int $section The section to link back to
1641 * @return string XHTML for the editing buttons
1642 */
1643function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
1644 global $PAGE;
1645 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
1646 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
1647 if (!($mod instanceof cm_info)) {
1648 $modinfo = get_fast_modinfo($mod->course);
1649 $mod = $modinfo->get_cm($mod->id);
1650 }
1651 $actions = course_get_cm_edit_actions($mod, $indent, $section);
1652
1653 $courserenderer = $PAGE->get_renderer('core', 'course');
1654 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
1655 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
1656 // the course page HTML will allow this to be removed.
1657 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1658}
1659
1660/**
1661 * Prints a section full of activity modules
1662 *
1663 * Deprecated. Please use:
1664 * $courserenderer = $PAGE->get_renderer('core', 'course');
1665 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
1666 * array('hidecompletion' => $hidecompletion));
1667 *
1668 * @deprecated since 2.5
1669 * @see core_course_renderer::course_section_cm_list()
1670 *
1671 * @param stdClass $course The course
1672 * @param stdClass|section_info $section The section object containing properties id and section
1673 * @param array $mods (argument not used)
1674 * @param array $modnamesused (argument not used)
1675 * @param bool $absolute (argument not used)
1676 * @param string $width (argument not used)
1677 * @param bool $hidecompletion Hide completion status
1678 * @param int $sectionreturn The section to return to
1679 * @return void
1680 */
1681function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
1682 global $PAGE;
1683 debugging('Function print_section() is deprecated. Please use course renderer function '.
1684 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
1685 $displayoptions = array('hidecompletion' => $hidecompletion);
1686 $courserenderer = $PAGE->get_renderer('core', 'course');
1687 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
1688}
00ba185d 1689
ff233851
MG
1690/**
1691 * Displays the list of courses with user notes
1692 *
1693 * This function is not used in core. It was replaced by block course_overview
1694 *
1695 * @deprecated since 2.5
1696 *
1697 * @param array $courses
1698 * @param array $remote_courses
1699 */
1700function print_overview($courses, array $remote_courses=array()) {
1701 global $CFG, $USER, $DB, $OUTPUT;
1702 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
1703
1704 $htmlarray = array();
1705 if ($modules = $DB->get_records('modules')) {
1706 foreach ($modules as $mod) {
1707 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
1708 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
1709 $fname = $mod->name.'_print_overview';
1710 if (function_exists($fname)) {
1711 $fname($courses,$htmlarray);
1712 }
1713 }
1714 }
1715 }
1716 foreach ($courses as $course) {
1717 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
1718 echo $OUTPUT->box_start('coursebox');
1719 $attributes = array('title' => s($fullname));
1720 if (empty($course->visible)) {
1721 $attributes['class'] = 'dimmed';
1722 }
1723 echo $OUTPUT->heading(html_writer::link(
1724 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
1725 if (array_key_exists($course->id,$htmlarray)) {
1726 foreach ($htmlarray[$course->id] as $modname => $html) {
1727 echo $html;
1728 }
1729 }
1730 echo $OUTPUT->box_end();
1731 }
1732
1733 if (!empty($remote_courses)) {
1734 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
1735 }
1736 foreach ($remote_courses as $course) {
1737 echo $OUTPUT->box_start('coursebox');
1738 $attributes = array('title' => s($course->fullname));
1739 echo $OUTPUT->heading(html_writer::link(
1740 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
1741 format_string($course->shortname),
1742 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
1743 echo $OUTPUT->box_end();
1744 }
1745}
a3f66bde
MG
1746
1747/**
1748 * This function trawls through the logs looking for
1749 * anything new since the user's last login
1750 *
1751 * This function was only used to print the content of block recent_activity
1752 * All functionality is moved into class {@link block_recent_activity}
1753 * and renderer {@link block_recent_activity_renderer}
1754 *
1755 * @deprecated since 2.5
1756 * @param stdClass $course
1757 */
1758function print_recent_activity($course) {
1759 // $course is an object
1760 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
1761 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
1762 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
1763
1764 $context = context_course::instance($course->id);
1765
1766 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
1767
1768 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
1769
1770 if (!isguestuser()) {
1771 if (!empty($USER->lastcourseaccess[$course->id])) {
1772 if ($USER->lastcourseaccess[$course->id] > $timestart) {
1773 $timestart = $USER->lastcourseaccess[$course->id];
1774 }
1775 }
1776 }
1777
1778 echo '<div class="activitydate">';
1779 echo get_string('activitysince', '', userdate($timestart));
1780 echo '</div>';
1781 echo '<div class="activityhead">';
1782
1783 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
1784
1785 echo "</div>\n";
1786
1787 $content = false;
1788
1789/// Firstly, have there been any new enrolments?
1790
1791 $users = get_recent_enrolments($course->id, $timestart);
1792
1793 //Accessibility: new users now appear in an <OL> list.
1794 if ($users) {
1795 echo '<div class="newusers">';
1796 echo $OUTPUT->heading(get_string("newusers").':', 3);
1797 $content = true;
1798 echo "<ol class=\"list\">\n";
1799 foreach ($users as $user) {
1800 $fullname = fullname($user, $viewfullnames);
1801 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
1802 }
1803 echo "</ol>\n</div>\n";
1804 }
1805
1806/// Next, have there been any modifications to the course structure?
1807
1808 $modinfo = get_fast_modinfo($course);
1809
1810 $changelist = array();
1811
1812 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
1813 module = 'course' AND
1814 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
1815 array($timestart, $course->id), "id ASC");
1816
1817 if ($logs) {
1818 $actions = array('add mod', 'update mod', 'delete mod');
1819 $newgones = array(); // added and later deleted items
1820 foreach ($logs as $key => $log) {
1821 if (!in_array($log->action, $actions)) {
1822 continue;
1823 }
1824 $info = explode(' ', $log->info);
1825
1826 // note: in most cases I replaced hardcoding of label with use of
1827 // $cm->has_view() but it was not possible to do this here because
1828 // we don't necessarily have the $cm for it
1829 if ($info[0] == 'label') { // Labels are ignored in recent activity
1830 continue;
1831 }
1832
1833 if (count($info) != 2) {
1834 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
1835 continue;
1836 }
1837
1838 $modname = $info[0];
1839 $instanceid = $info[1];
1840
1841 if ($log->action == 'delete mod') {
1842 // unfortunately we do not know if the mod was visible
1843 if (!array_key_exists($log->info, $newgones)) {
1844 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
1845 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
1846 }
1847 } else {
1848 if (!isset($modinfo->instances[$modname][$instanceid])) {
1849 if ($log->action == 'add mod') {
1850 // do not display added and later deleted activities
1851 $newgones[$log->info] = true;
1852 }
1853 continue;
1854 }
1855 $cm = $modinfo->instances[$modname][$instanceid];
1856 if (!$cm->uservisible) {
1857 continue;
1858 }
1859
1860 if ($log->action == 'add mod') {
1861 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
1862 $changelist[$log->info] = array('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
1863
1864 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
1865 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
1866 $changelist[$log->info] = array('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id={$cm->id}\">".format_string($cm->name, true)."</a>");
1867 }
1868 }
1869 }
1870 }
1871
1872 if (!empty($changelist)) {
1873 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
1874 $content = true;
1875 foreach ($changelist as $changeinfo => $change) {
1876 echo '<p class="activity">'.$change['text'].'</p>';
1877 }
1878 }
1879
1880/// Now display new things from each module
1881
1882 $usedmodules = array();
1883 foreach($modinfo->cms as $cm) {
1884 if (isset($usedmodules[$cm->modname])) {
1885 continue;
1886 }
1887 if (!$cm->uservisible) {
1888 continue;
1889 }
1890 $usedmodules[$cm->modname] = $cm->modname;
1891 }
1892
1893 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
1894 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
1895 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
1896 $print_recent_activity = $modname.'_print_recent_activity';
1897 if (function_exists($print_recent_activity)) {
1898 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
1899 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
1900 }
1901 } else {
1902 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
1903 }
1904 }
1905
1906 if (! $content) {
1907 echo '<p class="message">'.get_string('nothingnew').'</p>';
1908 }
1909}
a347aee3
MN
1910
1911/**
1912 * Delete a course module and any associated data at the course level (events)
1913 * Until 1.5 this function simply marked a deleted flag ... now it
1914 * deletes it completely.
1915 *
1916 * @deprecated since 2.5
1917 *
1918 * @param int $id the course module id
1919 * @return boolean true on success, false on failure
1920 */
1921function delete_course_module($id) {
1922 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
1923
1924 global $CFG, $DB;
1925
1926 require_once($CFG->libdir.'/gradelib.php');
1927 require_once($CFG->dirroot.'/blog/lib.php');
1928
1929 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
1930 return true;
1931 }
1932 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
1933 //delete events from calendar
1934 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
1935 foreach($events as $event) {
1936 delete_event($event->id);
1937 }
1938 }
1939 //delete grade items, outcome items and grades attached to modules
1940 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
1941 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
1942 foreach ($grade_items as $grade_item) {
1943 $grade_item->delete('moddelete');
1944 }
1945 }
1946 // Delete completion and availability data; it is better to do this even if the
1947 // features are not turned on, in case they were turned on previously (these will be
1948 // very quick on an empty table)
1949 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
a347aee3
MN
1950 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
1951 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
1952
1953 delete_context(CONTEXT_MODULE, $cm->id);
1954 return $DB->delete_records('course_modules', array('id'=>$cm->id));
1955}
2c49fb4c
MG
1956
1957/**
1958 * Prints the turn editing on/off button on course/index.php or course/category.php.
1959 *
1960 * @deprecated since 2.5
1961 *
1962 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
1963 * @return string HTML of the editing button, or empty string, if this user is not allowed
1964 * to see it.
1965 */
1966function update_category_button($categoryid = 0) {
1967 global $CFG, $PAGE, $OUTPUT;
1968 debugging('Function update_category_button() is deprecated. Pages to view '.
1969 'and edit courses are now separate and no longer depend on editing mode.',
1970 DEBUG_DEVELOPER);
1971
1972 // Check permissions.
1973 if (!can_edit_in_category($categoryid)) {
1974 return '';
1975 }
1976
1977 // Work out the appropriate action.
1978 if ($PAGE->user_is_editing()) {
1979 $label = get_string('turneditingoff');
1980 $edit = 'off';
1981 } else {
1982 $label = get_string('turneditingon');
1983 $edit = 'on';
1984 }
1985
1986 // Generate the button HTML.
1987 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
1988 if ($categoryid) {
1989 $options['id'] = $categoryid;
1990 $page = 'category.php';
1991 } else {
1992 $page = 'index.php';
1993 }
1994 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
1995}
4e0b6025
MG
1996
1997/**
1998 * This function recursively travels the categories, building up a nice list
1999 * for display. It also makes an array that list all the parents for each
2000 * category.
2001 *
2002 * For example, if you have a tree of categories like:
2003 * Miscellaneous (id = 1)
2004 * Subcategory (id = 2)
2005 * Sub-subcategory (id = 4)
2006 * Other category (id = 3)
2007 * Then after calling this function you will have
2008 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2009 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2010 * 3 => 'Other category');
2011 * $parents = array(2 => array(1), 4 => array(1, 2));
2012 *
2013 * If you specify $requiredcapability, then only categories where the current
2014 * user has that capability will be added to $list, although all categories
2015 * will still be added to $parents, and if you only have $requiredcapability
2016 * in a child category, not the parent, then the child catgegory will still be
2017 * included.
2018 *
2019 * If you specify the option $excluded, then that category, and all its children,
2020 * are omitted from the tree. This is useful when you are doing something like
2021 * moving categories, where you do not want to allow people to move a category
2022 * to be the child of itself.
2023 *
2024 * This function is deprecated! For list of categories use
2025 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2026 * For parents of one particular category use
2027 * coursecat::get($id)->get_parents()
2028 *
2029 * @deprecated since 2.5
2030 *
2031 * @param array $list For output, accumulates an array categoryid => full category path name
2032 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2033 * @param string/array $requiredcapability if given, only categories where the current
2034 * user has this capability will be added to $list. Can also be an array of capabilities,
2035 * in which case they are all required.
2036 * @param integer $excludeid Omit this category and its children from the lists built.
2037 * @param object $category Not used
2038 * @param string $path Not used
2039 */
2040function make_categories_list(&$list, &$parents, $requiredcapability = '',
2041 $excludeid = 0, $category = NULL, $path = "") {
2042 global $CFG, $DB;
2043 require_once($CFG->libdir.'/coursecatlib.php');
2044
2045 debugging('Global function make_categories_list() is deprecated. Please use '.
2046 'coursecat::make_categories_list() and coursecat::get_parents()',
2047 DEBUG_DEVELOPER);
2048
2049 // For categories list use just this one function:
2050 if (empty($list)) {
2051 $list = array();
2052 }
2053 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2054
2055 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2056 // Usually user needs only parents for one particular category, in which case should be used:
2057 // coursecat::get($categoryid)->get_parents()
2058 if (empty($parents)) {
2059 $parents = array();
2060 }
2061 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2062 foreach ($all as $record) {
2063 if ($record->parent) {
2064 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2065 } else {
2066 $parents[$record->id] = array();
2067 }
2068 }
2069}
deb65ced
MG
2070
2071/**
2072 * Delete category, but move contents to another category.
2073 *
2074 * This function is deprecated. Please use
2075 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2076 *
2077 * @see coursecat::delete_move()
2078 * @deprecated since 2.5
2079 *
2080 * @param object $category
2081 * @param int $newparentid category id
2082 * @return bool status
2083 */
2084function category_delete_move($category, $newparentid, $showfeedback=true) {
2085 global $CFG;
2086 require_once($CFG->libdir.'/coursecatlib.php');
2087
2088 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2089
2090 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2091}
2092
2093/**
2094 * Recursively delete category including all subcategories and courses.
2095 *
2096 * This function is deprecated. Please use
2097 * coursecat::get($category->id)->delete_full($showfeedback);
2098 *
2099 * @see coursecat::delete_full()
2100 * @deprecated since 2.5
2101 *
2102 * @param stdClass $category
2103 * @param boolean $showfeedback display some notices
2104 * @return array return deleted courses
2105 */
2106function category_delete_full($category, $showfeedback=true) {
2107 global $CFG, $DB;
2108 require_once($CFG->libdir.'/coursecatlib.php');
2109
2110 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2111
2112 return coursecat::get($category->id)->delete_full($showfeedback);
2113}
6e1d1ee0
MG
2114
2115/**
2116 * Efficiently moves a category - NOTE that this can have
2117 * a huge impact access-control-wise...
2118 *
2119 * This function is deprecated. Please use
2120 * $coursecat = coursecat::get($category->id);
2121 * if ($coursecat->can_change_parent($newparentcat->id)) {
2122 * $coursecat->change_parent($newparentcat->id);
2123 * }
2124 *
2125 * Alternatively you can use
2126 * $coursecat->update(array('parent' => $newparentcat->id));
2127 *
2128 * Function update() also updates field course_categories.timemodified
2129 *
2130 * @see coursecat::change_parent()
2131 * @see coursecat::update()
2132 * @deprecated since 2.5
2133 *
2134 * @param stdClass|coursecat $category
2135 * @param stdClass|coursecat $newparentcat
2136 */
2137function move_category($category, $newparentcat) {
2138 global $CFG;
2139 require_once($CFG->libdir.'/coursecatlib.php');
2140
2141 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2142
2143 return coursecat::get($category->id)->change_parent($newparentcat->id);
2144}
2145
2146/**
2147 * Hide course category and child course and subcategories
2148 *
2149 * This function is deprecated. Please use
2150 * coursecat::get($category->id)->hide();
2151 *
2152 * @see coursecat::hide()
2153 * @deprecated since 2.5
2154 *
2155 * @param stdClass $category
2156 * @return void
2157 */
2158function course_category_hide($category) {
2159 global $CFG;
2160 require_once($CFG->libdir.'/coursecatlib.php');
2161
2162 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2163
2164 coursecat::get($category->id)->hide();
2165}
2166
2167/**
2168 * Show course category and child course and subcategories
2169 *
2170 * This function is deprecated. Please use
2171 * coursecat::get($category->id)->show();
2172 *
2173 * @see coursecat::show()
2174 * @deprecated since 2.5
2175 *
2176 * @param stdClass $category
2177 * @return void
2178 */
2179function course_category_show($category) {
2180 global $CFG;
2181 require_once($CFG->libdir.'/coursecatlib.php');
2182
2183 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2184
2185 coursecat::get($category->id)->show();
2186}
2d8a275b
MG
2187
2188/**
2189 * Return specified category, default if given does not exist
2190 *
2191 * This function is deprecated.
2192 * To get the category with the specified it please use:
2193 * coursecat::get($catid, IGNORE_MISSING);
2194 * or
2195 * coursecat::get($catid, MUST_EXIST);
2196 *
2197 * To get the first available category please use
2198 * coursecat::get_default();
2199 *
2200 * class coursecat will also make sure that at least one category exists in DB
2201 *
2202 * @deprecated since 2.5
2203 * @see coursecat::get()
2204 * @see coursecat::get_default()
2205 *
2206 * @param int $catid course category id
2207 * @return object caregory
2208 */
2209function get_course_category($catid=0) {
2210 global $DB;
2211
2212 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2213
2214 $category = false;
2215
2216 if (!empty($catid)) {
2217 $category = $DB->get_record('course_categories', array('id'=>$catid));
2218 }
2219
2220 if (!$category) {
2221 // the first category is considered default for now
2222 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
2223 $category = reset($category);
2224
2225 } else {
2226 $cat = new stdClass();
2227 $cat->name = get_string('miscellaneous');
2228 $cat->depth = 1;
2229 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
2230 $cat->timemodified = time();
2231 $catid = $DB->insert_record('course_categories', $cat);
2232 // make sure category context exists
2233 context_coursecat::instance($catid);
2234 mark_context_dirty('/'.SYSCONTEXTID);
2235 fix_course_sortorder(); // Required to build course_categories.depth and .path.
2236 $category = $DB->get_record('course_categories', array('id'=>$catid));
2237 }
2238 }
2239
2240 return $category;
2241}
9bad61db
MG
2242
2243/**
2244 * Create a new course category and marks the context as dirty
2245 *
2246 * This function does not set the sortorder for the new category and
2247 * {@link fix_course_sortorder()} should be called after creating a new course
2248 * category
2249 *
2250 * Please note that this function does not verify access control.
2251 *
2252 * This function is deprecated. It is replaced with the method create() in class coursecat.
2253 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
2254 *
2255 * @deprecated since 2.5
2256 *
2257 * @param object $category All of the data required for an entry in the course_categories table
2258 * @return object new course category
2259 */
2260function create_course_category($category) {
2261 global $DB;
2262
2263 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
2264
2265 $category->timemodified = time();
2266 $category->id = $DB->insert_record('course_categories', $category);
2267 $category = $DB->get_record('course_categories', array('id' => $category->id));
2268
2269 // We should mark the context as dirty
2270 $category->context = context_coursecat::instance($category->id);
2271 $category->context->mark_dirty();
2272
2273 return $category;
2274}
bc81b006
MG
2275
2276/**
2277 * Returns an array of category ids of all the subcategories for a given
2278 * category.
2279 *
2280 * This function is deprecated.
2281 *
2282 * To get visible children categories of the given category use:
2283 * coursecat::get($categoryid)->get_children();
2284 * This function will return the array or coursecat objects, on each of them
2285 * you can call get_children() again
2286 *
2287 * @see coursecat::get()
2288 * @see coursecat::get_children()
2289 *
2290 * @deprecated since 2.5
2291 *
2292 * @global object
2293 * @param int $catid - The id of the category whose subcategories we want to find.
2294 * @return array of category ids.
2295 */
2296function get_all_subcategories($catid) {
2297 global $DB;
2298
2299 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
2300 DEBUG_DEVELOPER);
2301
2302 $subcats = array();
2303
2304 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
2305 foreach ($categories as $cat) {
2306 array_push($subcats, $cat->id);
2307 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
2308 }
2309 }
2310 return $subcats;
2311}
8db5dcb7
MG
2312
2313/**
2314 * Gets the child categories of a given courses category
2315 *
2316 * This function is deprecated. Please use functions in class coursecat:
2317 * - coursecat::get($parentid)->has_children()
2318 * tells if the category has children (visible or not to the current user)
2319 *
2320 * - coursecat::get($parentid)->get_children()
2321 * returns an array of coursecat objects, each of them represents a children category visible
2322 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
2323 *
2324 * - coursecat::get($parentid)->get_children_count()
2325 * returns number of children categories visible to the current user
2326 *
2327 * - coursecat::count_all()
2328 * returns total count of all categories in the system (both visible and not)
2329 *
2330 * - coursecat::get_default()
2331 * returns the first category (usually to be used if count_all() == 1)
2332 *
2333 * @deprecated since 2.5
2334 *
2335 * @param int $parentid the id of a course category.
2336 * @return array all the child course categories.
2337 */
2338function get_child_categories($parentid) {
2339 global $DB;
2340 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
2341 DEBUG_DEVELOPER);
2342
2343 $rv = array();
2344 $sql = context_helper::get_preload_record_columns_sql('ctx');
2345 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2346 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2347 array(CONTEXT_COURSECAT, $parentid));
2348 foreach ($records as $category) {
2349 context_helper::preload_from_record($category);
2350 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2351 continue;
2352 }
2353 $rv[] = $category;
2354 }
2355 return $rv;
2356}
e1d54562
MG
2357
2358/**
2359 * Returns a sorted list of categories.
2360 *
2361 * When asking for $parent='none' it will return all the categories, regardless
2362 * of depth. Wheen asking for a specific parent, the default is to return
2363 * a "shallow" resultset. Pass false to $shallow and it will return all
2364 * the child categories as well.
2365 *
2366 * @deprecated since 2.5
2367 *
2368 * This function is deprecated. Use appropriate functions from class coursecat.
2369 * Examples:
2370 *
2371 * coursecat::get($categoryid)->get_children()
2372 * - returns all children of the specified category as instances of class
0198b4a5
MG
2373 * coursecat, which means on each of them method get_children() can be called again.
2374 * Only categories visible to the current user are returned.
e1d54562 2375 *
0198b4a5
MG
2376 * coursecat::get(0)->get_children()
2377 * - returns all top-level categories visible to the current user.
e1d54562
MG
2378 *
2379 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
2380 *
0198b4a5
MG
2381 * coursecat::make_categories_list()
2382 * - returns an array of all categories id/names in the system.
2383 * Also only returns categories visible to current user and can additionally be
2384 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
2385 *
2386 * make_categories_options()
2387 * - Returns full course categories tree to be used in html_writer::select()
2388 *
e1d54562
MG
2389 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
2390 * {@link coursecat::get_default()}
2391 *
2392 * The code of this deprecated function is left as it is because coursecat::get_children()
0198b4a5
MG
2393 * returns categories as instances of coursecat and not stdClass. Also there is no
2394 * substitute for retrieving the category with all it's subcategories. Plugin developers
2395 * may re-use the code/queries from this function in their plugins if really necessary.
e1d54562
MG
2396 *
2397 * @param string $parent The parent category if any
2398 * @param string $sort the sortorder
2399 * @param bool $shallow - set to false to get the children too
2400 * @return array of categories
2401 */
2402function get_categories($parent='none', $sort=NULL, $shallow=true) {
2403 global $DB;
2404
0198b4a5 2405 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
e1d54562
MG
2406 DEBUG_DEVELOPER);
2407
2408 if ($sort === NULL) {
2409 $sort = 'ORDER BY cc.sortorder ASC';
2410 } elseif ($sort ==='') {
2411 // leave it as empty
2412 } else {
2413 $sort = "ORDER BY $sort";
2414 }
2415
2416 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
2417
2418 if ($parent === 'none') {
2419 $sql = "SELECT cc.* $ccselect
2420 FROM {course_categories} cc
2421 $ccjoin
2422 $sort";
2423 $params = array();
2424
2425 } elseif ($shallow) {
2426 $sql = "SELECT cc.* $ccselect
2427 FROM {course_categories} cc
2428 $ccjoin
2429 WHERE cc.parent=?
2430 $sort";
2431 $params = array($parent);
2432
2433 } else {
2434 $sql = "SELECT cc.* $ccselect
2435 FROM {course_categories} cc
2436 $ccjoin
2437 JOIN {course_categories} ccp
2438 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
2439 WHERE ccp.id=?
2440 $sort";
2441 $params = array($parent);
2442 }
2443 $categories = array();
2444
2445 $rs = $DB->get_recordset_sql($sql, $params);
2446 foreach($rs as $cat) {
db314f34 2447 context_helper::preload_from_record($cat);
e1d54562
MG
2448 $catcontext = context_coursecat::instance($cat->id);
2449 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
2450 $categories[$cat->id] = $cat;
2451 }
2452 }
2453 $rs->close();
2454 return $categories;
2455}
a8d683ca
MG
2456
2457/**
2458* Displays a course search form
2459*
2460* This function is deprecated, please use course renderer:
2461* $renderer = $PAGE->get_renderer('core', 'course');
2462* echo $renderer->course_search_form($value, $format);
2463*
2464* @deprecated since 2.5
2465*
2466* @param string $value default value to populate the search field
2467* @param bool $return if true returns the value, if false - outputs
2468* @param string $format display format - 'plain' (default), 'short' or 'navbar'
2469* @return null|string
2470*/
2471function print_course_search($value="", $return=false, $format="plain") {
2472 global $PAGE;
2473 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2474 $renderer = $PAGE->get_renderer('core', 'course');
2475 if ($return) {
2476 return $renderer->course_search_form($value, $format);
2477 } else {
2478 echo $renderer->course_search_form($value, $format);
2479 }
2480}
09ae7ee0
MG
2481
2482/**
2483 * Prints custom user information on the home page
2484 *
2485 * This function is deprecated, please use:
2486 * $renderer = $PAGE->get_renderer('core', 'course');
2487 * echo $renderer->frontpage_my_courses()
2488 *
2489 * @deprecated since 2.5
2490 */
2491function print_my_moodle() {
2492 global $PAGE;
2493 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
2494
2495 $renderer = $PAGE->get_renderer('core', 'course');
2496 echo $renderer->frontpage_my_courses();
2497}
2498
2499/**
2500 * Prints information about one remote course
2501 *
2502 * This function is deprecated, it is replaced with protected function
2503 * {@link core_course_renderer::frontpage_remote_course()}
2504 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2505 *
2506 * @deprecated since 2.5
2507 */
2508function print_remote_course($course, $width="100%") {
2509 global $CFG, $USER;
2510 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2511
2512 $linkcss = '';
2513
2514 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}";
2515
2516 echo '<div class="coursebox remotecoursebox clearfix">';
2517 echo '<div class="info">';
2518 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
2519 $linkcss.' href="'.$url.'">'
2520 . format_string($course->fullname) .'</a><br />'
2521 . format_string($course->hostname) . ' : '
2522 . format_string($course->cat_name) . ' : '
2523 . format_string($course->shortname). '</div>';
2524 echo '</div><div class="summary">';
2525 $options = new stdClass();
2526 $options->noclean = true;
2527 $options->para = false;
2528 $options->overflowdiv = true;
2529 echo format_text($course->summary, $course->summaryformat, $options);
2530 echo '</div>';
2531 echo '</div>';
2532}
2533
2534/**
2535 * Prints information about one remote host
2536 *
2537 * This function is deprecated, it is replaced with protected function
2538 * {@link core_course_renderer::frontpage_remote_host()}
2539 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2540 *
2541 * @deprecated since 2.5
2542 */
2543function print_remote_host($host, $width="100%") {
2544 global $OUTPUT;
2545 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2546
2547 $linkcss = '';
2548
2549 echo '<div class="coursebox clearfix">';
2550 echo '<div class="info">';
2551 echo '<div class="name">';
2552 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
2553 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
2554 . s($host['name']).'</a> - ';
2555 echo $host['count'] . ' ' . get_string('courses');
2556 echo '</div>';
2557 echo '</div>';
2558 echo '</div>';
2559}
2560
2561/**
2562 * Recursive function to print out all the categories in a nice format
2563 * with or without courses included
2564 *
2565 * @deprecated since 2.5
2566 *
2567 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2568 */
2569function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
2570 global $PAGE;
2571 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2572
2573 $renderer = $PAGE->get_renderer('core', 'course');
2574 if ($showcourses && $category) {
2575 echo $renderer->course_category($category);
2576 } else if ($showcourses) {
2577 echo $renderer->frontpage_combo_list();
2578 } else {
2579 echo $renderer->frontpage_categories_list();
2580 }
2581}
2582
2583/**
2584 * Prints the category information.
2585 *
2586 * @deprecated since 2.5
2587 *
2588 * This function was only used by {@link print_whole_category_list()} but now
2589 * all course category rendering is moved to core_course_renderer.
2590 *
2591 * @param stdClass $category
2592 * @param int $depth The depth of the category.
2593 * @param bool $showcourses If set to true course information will also be printed.
2594 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
2595 */
2596function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
2597 global $PAGE;
2598 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2599
2600 $renderer = $PAGE->get_renderer('core', 'course');
2601 echo $renderer->course_category($category);
2602}
2603
2604/**
2605 * This function generates a structured array of courses and categories.
2606 *
2607 * @deprecated since 2.5
2608 *
2609 * This function is not used any more in moodle core and course renderer does not have render function for it.
2610 * Combo list on the front page is displayed as:
2611 * $renderer = $PAGE->get_renderer('core', 'course');
2612 * echo $renderer->frontpage_combo_list()
2613 *
2614 * The new class {@link coursecat} stores the information about course category tree
2615 * To get children categories use:
2616 * coursecat::get($id)->get_children()
2617 * To get list of courses use:
2618 * coursecat::get($id)->get_courses()
2619 *
2620 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2621 *
2622 * @param int $id
2623 * @param int $depth
2624 */
2625function get_course_category_tree($id = 0, $depth = 0) {
2626 global $DB, $CFG;
2627 if (!$depth) {
2628 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
2629 }
2630
2631 $categories = array();
2632 $categoryids = array();
2633 $sql = context_helper::get_preload_record_columns_sql('ctx');
2634 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2635 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2636 array(CONTEXT_COURSECAT, $id));
2637 foreach ($records as $category) {
2638 context_helper::preload_from_record($category);
2639 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2640 continue;
2641 }
2642 $categories[] = $category;
2643 $categoryids[$category->id] = $category;
2644 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
2645 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
2646 foreach ($subcategories as $subid=>$subcat) {
2647 $categoryids[$subid] = $subcat;
2648 }
2649 $category->courses = array();
2650 }
2651 }
2652
2653 if ($depth > 0) {
2654 // This is a recursive call so return the required array
2655 return array($categories, $categoryids);
2656 }
2657
2658 if (empty($categoryids)) {
2659 // No categories available (probably all hidden).
2660 return array();
2661 }
2662
2663 // The depth is 0 this function has just been called so we can finish it off
2664
2665 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
2666 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
2667 $sql = "SELECT
2668 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
2669 $ccselect
2670 FROM {course} c
2671 $ccjoin
2672 WHERE c.category $catsql ORDER BY c.sortorder ASC";
2673 if ($courses = $DB->get_records_sql($sql, $catparams)) {
2674 // loop throught them
2675 foreach ($courses as $course) {
2676 if ($course->id == SITEID) {
2677 continue;
2678 }
db314f34 2679 context_helper::preload_from_record($course);
09ae7ee0
MG
2680 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
2681 $categoryids[$course->category]->courses[$course->id] = $course;
2682 }
2683 }
2684 }
2685 return $categories;
2686}
2687
2688/**
2689 * Print courses in category. If category is 0 then all courses are printed.
2690 *
2691 * @deprecated since 2.5
2692 *
2693 * To print a generic list of courses use:
2694 * $renderer = $PAGE->get_renderer('core', 'course');
2695 * echo $renderer->courses_list($courses);
2696 *
2697 * To print list of all courses:
2698 * $renderer = $PAGE->get_renderer('core', 'course');
2699 * echo $renderer->frontpage_available_courses();
2700 *
2701 * To print list of courses inside category:
2702 * $renderer = $PAGE->get_renderer('core', 'course');
2703 * echo $renderer->course_category($category); // this will also print subcategories
2704 *
2705 * @param int|stdClass $category category object or id.
2706 * @return bool true if courses found and printed, else false.
2707 */
2708function print_courses($category) {
2709 global $CFG, $OUTPUT, $PAGE;
2710 require_once($CFG->libdir. '/coursecatlib.php');
2711 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2712
2713 if (!is_object($category) && $category==0) {
2714 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
2715 } else {
2716 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
2717 }
2718
2719 if ($courses) {
2720 $renderer = $PAGE->get_renderer('core', 'course');
2721 echo $renderer->courses_list($courses);
2722 } else {
2723 echo $OUTPUT->heading(get_string("nocoursesyet"));
2724 $context = context_system::instance();
2725 if (has_capability('moodle/course:create', $context)) {
2726 $options = array();
2727 if (!empty($category->id)) {
2728 $options['category'] = $category->id;
2729 } else {
2730 $options['category'] = $CFG->defaultrequestcategory;
2731 }
2732 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
2733 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
2734 echo html_writer::end_tag('div');
2735 return false;
2736 }
2737 }
2738 return true;
2739}
2740
2741/**
2742 * Print a description of a course, suitable for browsing in a list.
2743 *
2744 * @deprecated since 2.5
2745 *
2746 * Please use course renderer to display a course information box.
2747 * $renderer = $PAGE->get_renderer('core', 'course');
2748 * echo $renderer->courses_list($courses); // will print list of courses
2749 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
2750 *
2751 * @param object $course the course object.
2752 * @param string $highlightterms Ignored in this deprecated function!
2753 */
2754function print_course($course, $highlightterms = '') {
2755 global $PAGE;
2756
2757 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2758 $renderer = $PAGE->get_renderer('core', 'course');
2759 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
2760 // To print list of courses use $renderer->courses_list();
2761 echo $renderer->course_info_box($course);
2762}
2763
2764/**
2765 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
2766 *
2767 * @deprecated since 2.5
2768 *
2769 * This function is not used any more in moodle core and course renderer does not have render function for it.
2770 * Combo list on the front page is displayed as:
2771 * $renderer = $PAGE->get_renderer('core', 'course');
2772 * echo $renderer->frontpage_combo_list()
2773 *
2774 * The new class {@link coursecat} stores the information about course category tree
2775 * To get children categories use:
2776 * coursecat::get($id)->get_children()
2777 * To get list of courses use:
2778 * coursecat::get($id)->get_courses()
2779 *
2780 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2781 *
2782 * @param int $categoryid
2783 * @return array
2784 */
2785function get_category_courses_array($categoryid = 0) {
2786 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
2787 $tree = get_course_category_tree($categoryid);
2788 $flattened = array();
2789 foreach ($tree as $category) {
2790 get_category_courses_array_recursively($flattened, $category);
2791 }
2792 return $flattened;
2793}
2794
2795/**
2796 * Recursive function to help flatten the course category tree.
2797 *
2798 * @deprecated since 2.5
2799 *
2800 * Was intended to be called from {@link get_category_courses_array()}
2801 *
2802 * @param array &$flattened An array passed by reference in which to store courses for each category.
2803 * @param stdClass $category The category to get courses for.
2804 */
2805function get_category_courses_array_recursively(array &$flattened, $category) {
2806 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
2807 $flattened[$category->id] = $category->courses;
2808 foreach ($category->categories as $childcategory) {
2809 get_category_courses_array_recursively($flattened, $childcategory);
2810 }
2811}
2812
7ac18cf9
AA
2813/**
2814 * Returns a URL based on the context of the current page.
2815 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
2816 *
2817 * @param stdclass $context
2818 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
2819 * @todo Remove this in 2.7
2820 * @return string
2821 */
2822function blog_get_context_url($context=null) {
2823 global $CFG;
2824
2825 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
2826 $viewblogentriesurl = new moodle_url('/blog/index.php');
2827
2828 if (empty($context)) {
2829 global $PAGE;
2830 $context = $PAGE->context;
2831 }
2832
2833 // Change contextlevel to SYSTEM if viewing the site course
2834 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
2835 $context = context_system::instance();
2836 }
2837
2838 $filterparam = '';
2839 $strlevel = '';
2840
2841 switch ($context->contextlevel) {
2842 case CONTEXT_SYSTEM:
2843 case CONTEXT_BLOCK:
2844 case CONTEXT_COURSECAT:
2845 break;
2846 case CONTEXT_COURSE:
2847 $filterparam = 'courseid';
2848 $strlevel = get_string('course');
2849 break;
2850 case CONTEXT_MODULE:
2851 $filterparam = 'modid';
329846f1 2852 $strlevel = $context->get_context_name();
7ac18cf9
AA
2853 break;
2854 case CONTEXT_USER:
2855 $filterparam = 'userid';
2856 $strlevel = get_string('user');
2857 break;
2858 }
2859
2860 if (!empty($filterparam)) {
2861 $viewblogentriesurl->param($filterparam, $context->instanceid);
2862 }
2863
2864 return $viewblogentriesurl;
2865}
2866
09ae7ee0
MG
2867/**
2868 * Retrieve course records with the course managers and other related records
2869 * that we need for print_course(). This allows print_courses() to do its job
2870 * in a constant number of DB queries, regardless of the number of courses,
2871 * role assignments, etc.
2872 *
2873 * The returned array is indexed on c.id, and each course will have
2874 * - $course->managers - array containing RA objects that include a $user obj
2875 * with the minimal fields needed for fullname()
2876 *
2877 * @deprecated since 2.5
2878 *
2879 * To get list of all courses with course contacts ('managers') use
2880 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
2881 *
2882 * To get list of courses inside particular category use
2883 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
2884 *
2885 * Additionally you can specify sort order, offset and maximum number of courses,
2886 * see {@link coursecat::get_courses()}
2887 *
2888 * Please note that code of this function is not changed to use coursecat class because
2889 * coursecat::get_courses() returns result in slightly different format. Also note that
2890 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
2891 * coursecat::get_courses() does.
2892 *
2893 * @global object
2894 * @global object
2895 * @global object
2896 * @uses CONTEXT_COURSE
2897 * @uses CONTEXT_SYSTEM
2898 * @uses CONTEXT_COURSECAT
2899 * @uses SITEID
2900 * @param int|string $categoryid Either the categoryid for the courses or 'all'
2901 * @param string $sort A SQL sort field and direction
2902 * @param array $fields An array of additional fields to fetch
2903 * @return array
2904 */
2905function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
2906 /*
2907 * The plan is to
2908 *
2909 * - Grab the courses JOINed w/context
2910 *
2911 * - Grab the interesting course-manager RAs
2912 * JOINed with a base user obj and add them to each course
2913 *
2914 * So as to do all the work in 2 DB queries. The RA+user JOIN
2915 * ends up being pretty expensive if it happens over _all_
2916 * courses on a large site. (Are we surprised!?)
2917 *
2918 * So this should _never_ get called with 'all' on a large site.
2919 *
2920 */
2921 global $USER, $CFG, $DB;
2922 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
2923
2924 $params = array();
2925 $allcats = false; // bool flag
2926 if ($categoryid === 'all') {
2927 $categoryclause = '';
2928 $allcats = true;
2929 } elseif (is_numeric($categoryid)) {
2930 $categoryclause = "c.category = :catid";
2931 $params['catid'] = $categoryid;
2932 } else {
2933 debugging("Could not recognise categoryid = $categoryid");
2934 $categoryclause = '';
2935 }
2936
2937 $basefields = array('id', 'category', 'sortorder',
2938 'shortname', 'fullname', 'idnumber',
2939 'startdate', 'visible',
2940 'newsitems', 'groupmode', 'groupmodeforce');
2941
2942 if (!is_null($fields) && is_string($fields)) {
2943 if (empty($fields)) {
2944 $fields = $basefields;
2945 } else {
2946 // turn the fields from a string to an array that
2947 // get_user_courses_bycap() will like...
2948 $fields = explode(',',$fields);
2949 $fields = array_map('trim', $fields);
2950 $fields = array_unique(array_merge($basefields, $fields));
2951 }
2952 } elseif (is_array($fields)) {
2953 $fields = array_merge($basefields,$fields);
2954 }
2955 $coursefields = 'c.' .join(',c.', $fields);
2956
2957 if (empty($sort)) {
2958 $sortstatement = "";
2959 } else {
2960 $sortstatement = "ORDER BY $sort";
2961 }
2962
2963 $where = 'WHERE c.id != ' . SITEID;
2964 if ($categoryclause !== ''){
2965 $where = "$where AND $categoryclause";
2966 }
2967
2968 // pull out all courses matching the cat
2969 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
2970 $sql = "SELECT $coursefields $ccselect
2971 FROM {course} c
2972 $ccjoin
2973 $where
2974 $sortstatement";
2975
2976 $catpaths = array();
2977 $catpath = NULL;
2978 if ($courses = $DB->get_records_sql($sql, $params)) {
2979 // loop on courses materialising
2980 // the context, and prepping data to fetch the
2981 // managers efficiently later...
2982 foreach ($courses as $k => $course) {
db314f34 2983 context_helper::preload_from_record($course);
09ae7ee0
MG
2984 $coursecontext = context_course::instance($course->id);
2985 $courses[$k] = $course;
2986 $courses[$k]->managers = array();
2987 if ($allcats === false) {
2988 // single cat, so take just the first one...
2989 if ($catpath === NULL) {
2990 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
2991 }
2992 } else {
2993 // chop off the contextid of the course itself
2994 // like dirname() does...
2995 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
2996 }
2997 }
2998 } else {
2999 return array(); // no courses!
3000 }
3001
3002 $CFG->coursecontact = trim($CFG->coursecontact);
3003 if (empty($CFG->coursecontact)) {
3004 return $courses;
3005 }
3006
3007 $managerroles = explode(',', $CFG->coursecontact);
3008 $catctxids = '';
3009 if (count($managerroles)) {
3010 if ($allcats === true) {
3011 $catpaths = array_unique($catpaths);
3012 $ctxids = array();
3013 foreach ($catpaths as $cpath) {
3014 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3015 }
3016 $ctxids = array_unique($ctxids);
3017 $catctxids = implode( ',' , $ctxids);
3018 unset($catpaths);
3019 unset($cpath);
3020 } else {
3021 // take the ctx path from the first course
3022 // as all categories will be the same...
3023 $catpath = substr($catpath,1);
3024 $catpath = preg_replace(':/\d+$:','',$catpath);
3025 $catctxids = str_replace('/',',',$catpath);
3026 }
3027 if ($categoryclause !== '') {
3028 $categoryclause = "AND $categoryclause";
3029 }
3030 /*
3031 * Note: Here we use a LEFT OUTER JOIN that can
3032 * "optionally" match to avoid passing a ton of context
3033 * ids in an IN() clause. Perhaps a subselect is faster.
3034 *
3035 * In any case, this SQL is not-so-nice over large sets of
3036 * courses with no $categoryclause.
3037 *
3038 */
3039 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3040 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3041 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3042 FROM {role_assignments} ra
3043 JOIN {context} ctx ON ra.contextid = ctx.id
3044 JOIN {user} u ON ra.userid = u.id
3045 JOIN {role} r ON ra.roleid = r.id
3046 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3047 LEFT OUTER JOIN {course} c
3048 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3049 WHERE ( c.id IS NOT NULL";
3050 // under certain conditions, $catctxids is NULL
3051 if($catctxids == NULL){
3052 $sql .= ") ";
3053 }else{
3054 $sql .= " OR ra.contextid IN ($catctxids) )";
3055 }
3056
3057 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3058 $categoryclause
3059 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3060 $rs = $DB->get_recordset_sql($sql, $params);
3061
3062 // This loop is fairly stupid as it stands - might get better
3063 // results doing an initial pass clustering RAs by path.
3064 foreach($rs as $ra) {
3065 $user = new stdClass;
3066 $user->id = $ra->userid; unset($ra->userid);
3067 $user->firstname = $ra->firstname; unset($ra->firstname);
3068 $user->lastname = $ra->lastname; unset($ra->lastname);
3069 $ra->user = $user;
3070 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3071 foreach ($courses as $k => $course) {
3072 $courses[$k]->managers[] = $ra;
3073 }
3074 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3075 if ($allcats === false) {
3076 // It always applies
3077 foreach ($courses as $k => $course) {
3078 $courses[$k]->managers[] = $ra;
3079 }
3080 } else {
3081 foreach ($courses as $k => $course) {
3082 $coursecontext = context_course::instance($course->id);
3083 // Note that strpos() returns 0 as "matched at pos 0"
3084 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3085 // Only add it to subpaths
3086 $courses[$k]->managers[] = $ra;
3087 }
3088 }
3089 }
3090 } else { // course-level
3091 if (!array_key_exists($ra->instanceid, $courses)) {
3092 //this course is not in a list, probably a frontpage course
3093 continue;
3094 }
3095 $courses[$ra->instanceid]->managers[] = $ra;
3096 }
3097 }
3098 $rs->close();
3099 }
3100
3101 return $courses;
3102}
c269b9d1
MG
3103
3104/**
3105 * Converts a nested array tree into HTML ul:li [recursive]
3106 *
3107 * @deprecated since 2.5
3108 *
3109 * @param array $tree A tree array to convert
3110 * @param int $row Used in identifying the iteration level and in ul classes
3111 * @return string HTML structure
3112 */
3113function convert_tree_to_html($tree, $row=0) {
3114 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3115
3116 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3117
3118 $first = true;
3119 $count = count($tree);
3120
3121 foreach ($tree as $tab) {
3122 $count--; // countdown to zero
3123
3124 $liclass = '';
3125
3126 if ($first && ($count == 0)) { // Just one in the row
3127 $liclass = 'first last';
3128 $first = false;
3129 } else if ($first) {
3130 $liclass = 'first';
3131 $first = false;
3132 } else if ($count == 0) {
3133 $liclass = 'last';
3134 }
3135
3136 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3137 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3138 }
3139
3140 if ($tab->inactive || $tab->active || $tab->selected) {
3141 if ($tab->selected) {
3142 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3143 } else if ($tab->active) {
3144 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3145 }
3146 }
3147
3148 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3149
3150 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3151 // The a tag is used for styling
3152 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3153 } else {
3154 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3155 }
3156
3157 if (!empty($tab->subtree)) {
3158 $str .= convert_tree_to_html($tab->subtree, $row+1);
3159 } else if ($tab->selected) {
3160 $str .= '<div class="tabrow'.($row+1).' empty">&nbsp;</div>'."\n";
3161 }
3162
3163 $str .= ' </li>'."\n";
3164 }
3165 $str .= '</ul>'."\n";
3166
3167 return $str;
3168}
3169
3170/**
3171 * Convert nested tabrows to a nested array
3172 *
3173 * @deprecated since 2.5
3174 *
3175 * @param array $tabrows A [nested] array of tab row objects
3176 * @param string $selected The tabrow to select (by id)
3177 * @param array $inactive An array of tabrow id's to make inactive
3178 * @param array $activated An array of tabrow id's to make active
3179 * @return array The nested array
3180 */
3181function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3182
3183 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
c269b9d1 3184
3d7414b3 3185 // Work backwards through the rows (bottom to top) collecting the tree as we go.
c269b9d1
MG
3186 $tabrows = array_reverse($tabrows);
3187
3188 $subtree = array();
3189
3190 foreach ($tabrows as $row) {
3191 $tree = array();
3192
3193 foreach ($row as $tab) {
3194 $tab->inactive = in_array((string)$tab->id, $inactive);
3195 $tab->active = in_array((string)$tab->id, $activated);
3196 $tab->selected = (string)$tab->id == $selected;
3197
3198 if ($tab->active || $tab->selected) {
3199 if ($subtree) {
3200 $tab->subtree = $subtree;
3201 }
3202 }
3203 $tree[] = $tab;
3204 }
3205 $subtree = $tree;
3206 }
3207
3208 return $subtree;
3209}
9052fc44 3210
8ef3a222
DP
3211/**
3212 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3213 *
3214 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3215 * @return bool True for yes, false for no
3216 */
3217function can_use_rotated_text() {
3218 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
3219 return true;
3220}
61a0299a
AA
3221
3222/**
3223 * Get the context instance as an object. This function will create the
3224 * context instance if it does not exist yet.
3225 *
3226 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
3227 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
3228 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
3229 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
3230 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
3231 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3232 * MUST_EXIST means throw exception if no record or multiple records found
3233 * @return context The context object.
3234 */
3235function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
3236
1b80060f 3237 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
61a0299a
AA
3238
3239 $instances = (array)$instance;
3240 $contexts = array();
3241
3242 $classname = context_helper::get_class_for_level($contextlevel);
3243
3244 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
3245 foreach ($instances as $inst) {
3246 $contexts[$inst] = $classname::instance($inst, $strictness);
3247 }
3248
3249 if (is_array($instance)) {
3250 return $contexts;
3251 } else {
3252 return $contexts[$instance];
3253 }
3254}
7b2ca655 3255
ce2b2150
RT
3256/**
3257 * Get a context instance as an object, from a given context id.
3258 *
3259 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
ce2b2150 3260 * @see context::instance_by_id($id)
ce2b2150
RT
3261 */
3262function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
f9b7be4f 3263 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
ce2b2150 3264}
85b2e46f 3265
492ba9de
AA
3266/**
3267 * Returns system context or null if can not be created yet.
3268 *
3269 * @see context_system::instance()
01546175 3270 * @deprecated since 2.2
492ba9de
AA
3271 * @param bool $cache use caching
3272 * @return context system context (null if context table not created yet)
3273 */
3274function get_system_context($cache = true) {
3275 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
3276 return context_system::instance(0, IGNORE_MISSING, $cache);
3277}
8e8891b7
FM
3278
3279/**
3280 * Recursive function which, given a context, find all parent context ids,
3281 * and return the array in reverse order, i.e. parent first, then grand
3282 * parent, etc.
3283 *
3284 * @see context::get_parent_context_ids()
3285 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
3286 * @param context $context
3287 * @param bool $includeself optional, defaults to false
3288 * @return array
3289 */
3290function get_parent_contexts(context $context, $includeself = false) {
3291 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
3292 return $context->get_parent_context_ids($includeself);
3293}
766fd0d9
AD
3294
3295/**
7f5b51c4
RT
3296 * Return the id of the parent of this context, or false if there is no parent (only happens if this
3297 * is the site context.)
3298 *
3299 * @deprecated since Moodle 2.2
3300 * @see context::get_parent_context()
3301 * @param context $context
3302 * @return integer the id of the parent context.
766fd0d9 3303 */
7f5b51c4
RT
3304function get_parent_contextid(context $context) {
3305 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
3306
3307 if ($parent = $context->get_parent_context()) {
3308 return $parent->id;
3309 } else {
3310 return false;
3311 }
766fd0d9 3312}
f9aa8016
FM
3313
3314/**
3315 * Recursive function which, given a context, find all its children contexts.
3316 *
3317 * For course category contexts it will return immediate children only categories and courses.
3318 * It will NOT recurse into courses or child categories.
3319 * If you want to do that, call it on the returned courses/categories.
3320 *
3321 * When called for a course context, it will return the modules and blocks
3322 * displayed in the course page.
3323 *
3324 * If called on a user/course/module context it _will_ populate the cache with the appropriate
3325 * contexts ;-)
3326 *
3327 * @see context::get_child_contexts()
3328 * @deprecated since 2.2
3329 * @param context $context
3330 * @return array Array of child records
3331 */
3332function get_child_contexts(context $context) {
3333 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
3334 return $context->get_child_contexts();
3335}
9fdbf620
FM
3336
3337/**
3338 * Precreates all contexts including all parents.
3339 *
3340 * @see context_helper::create_instances()
3341 * @deprecated since 2.2
3342 * @param int $contextlevel empty means all
3343 * @param bool $buildpaths update paths and depths
3344 * @return void
3345 */
3346function create_contexts($contextlevel = null, $buildpaths = true) {
3347 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
3348 context_helper::create_instances($contextlevel, $buildpaths);
3349}
84378a57
FM
3350
3351/**
3352 * Remove stale context records.
3353 *
3354 * @see context_helper::cleanup_instances()
3355 * @deprecated since 2.2
3356 * @return bool
3357 */
3358function cleanup_contexts() {
3359 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
3360 context_helper::cleanup_instances();
3361 return true;
3362}
79f6b384
FM
3363
3364/**
3365 * Populate context.path and context.depth where missing.
3366 *
3367 * @see context_helper::build_all_paths()
3368 * @deprecated since 2.2
3369 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
3370 * @return void
3371 */
3372function build_context_path($force = false) {
3373 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
3374 context_helper::build_all_paths($force);
3375}
cc4de415
FM
3376
3377/**
3378 * Rebuild all related context depth and path caches.
3379 *
3380 * @see context::reset_paths()
3381 * @deprecated since 2.2
3382 * @param array $fixcontexts array of contexts, strongtyped
3383 * @return void
3384 */
3385function rebuild_contexts(array $fixcontexts) {
3386 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
3387 foreach ($fixcontexts as $fixcontext) {
3388 $fixcontext->reset_paths(false);
3389 }
3390 context_helper::build_all_paths(false);
3391}
8f7d3d12
RT
3392
3393/**
3394 * Preloads all contexts relating to a course: course, modules. Block contexts
3395 * are no longer loaded here. The contexts for all the blocks on the current
3396 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
3397 *
3398 * @deprecated since Moodle 2.2
3399 * @see context_helper::preload_course()
3400 * @param int $courseid Course ID
3401 * @return void
3402 */
3403function preload_course_contexts($courseid) {
3404 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
3405 context_helper::preload_course($courseid);
3406}
2c5b0eb7
RT
3407
3408/**
3409 * Update the path field of the context and all dep. subcontexts that follow
3410 *
3411 * Update the path field of the context and
3412 * all the dependent subcontexts that follow
3413 * the move.
3414 *
3415 * The most important thing here is to be as
3416 * DB efficient as possible. This op can have a
3417 * massive impact in the DB.
3418 *
3419 * @deprecated since Moodle 2.2
3420 * @see context::update_moved()
3421 * @param context $context context obj
3422 * @param context $newparent new parent obj
3423 * @return void
3424 */
3425function context_moved(context $context, context $newparent) {
3426 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
3427 $context->update_moved($newparent);
c5dcd25d
AA
3428}
3429
a439b2f9
FM
3430/**
3431 * Extracts the relevant capabilities given a contextid.
3432 * All case based, example an instance of forum context.
3433 * Will fetch all forum related capabilities, while course contexts
3434 * Will fetch all capabilities
3435 *
3436 * capabilities
3437 * `name` varchar(150) NOT NULL,
3438 * `captype` varchar(50) NOT NULL,
3439 * `contextlevel` int(10) NOT NULL,
3440 * `component` varchar(100) NOT NULL,
3441 *
3442 * @see context::get_capabilities()
3443 * @deprecated since 2.2
3444 * @param context $context
3445 * @return array
3446 */
3447function fetch_context_capabilities(context $context) {
3448 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
3449 return $context->get_capabilities();
3450}
3451
c5dcd25d
AA
3452/**
3453 * Preloads context information from db record and strips the cached info.
3454 * The db request has to contain both the $join and $select from context_instance_preload_sql()
3455 *
3456 * @deprecated since 2.2
3457 * @see context_helper::preload_from_record()
3458 * @param stdClass $rec
3459 * @return void (modifies $rec)
3460 */
3461function context_instance_preload(stdClass $rec) {
3462 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
3463 context_helper::preload_from_record($rec);
3464}
b4482dfe
AG
3465
3466/**
3467 * Returns context level name
3468 *
3469 * @deprecated since 2.2
3470 * @see context_helper::get_level_name()
3471 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
3472 * @return string the name for this type of context.
3473 */
3474function get_contextlevel_name($contextlevel) {
3475 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
3476 return context_helper::get_level_name($contextlevel);
3477}
329846f1
AG
3478
3479/**
3480 * Prints human readable context identifier.
3481 *
3482 * @deprecated since 2.2
3483 * @see context::get_context_name()
3484 * @param context $context the context.
3485 * @param boolean $withprefix whether to prefix the name of the context with the
3486 * type of context, e.g. User, Course, Forum, etc.
3487 * @param boolean $short whether to user the short name of the thing. Only applies
3488 * to course contexts
3489 * @return string the human readable context name.
3490 */
3491function print_context_name(context $context, $withprefix = true, $short = false) {
3492 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
3493 return $context->get_context_name($withprefix, $short);
3494}
1de02d62
AG
3495
3496/**
3497 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
3498 *
3499 * @deprecated since 2.2, use $context->mark_dirty() instead
3500 * @see context::mark_dirty()
3501 * @param string $path context path
3502 */
3503function mark_context_dirty($path) {
3504 global $CFG, $USER, $ACCESSLIB_PRIVATE;
3505 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
3506
3507 if (during_initial_install()) {
3508 return;
3509 }
3510
3511 // only if it is a non-empty string
3512 if (is_string($path) && $path !== '') {
3513 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
3514 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
3515 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
3516 } else {
3517 if (CLI_SCRIPT) {
3518 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3519 } else {
3520 if (isset($USER->access['time'])) {
3521 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
3522 } else {
3523 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3524 }
3525 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
3526 }
3527 }
3528 }
3529}
c592eea2
RT
3530
3531/**
3532 * Remove a context record and any dependent entries,
3533 * removes context from static context cache too
3534 *
3535 * @deprecated since Moodle 2.2
3536 * @see context_helper::delete_instance() or context::delete_content()
3537 * @param int $contextlevel
3538 * @param int $instanceid
3539 * @param bool $deleterecord false means keep record for now
3540 * @return bool returns true or throws an exception
3541 */
3542function delete_context($contextlevel, $instanceid, $deleterecord = true) {
3543 if ($deleterecord) {
3544 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
3545 context_helper::delete_instance($contextlevel, $instanceid);
3546 } else {
3547 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
3548 $classname = context_helper::get_class_for_level($contextlevel);
3549 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
3550 $context->delete_content();
3551 }
3552 }
3553
3554 return true;
3555}
6c89d4e1
MN
3556
3557/**
3558 * Get a URL for a context, if there is a natural one. For example, for
3559 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
3560 * user profile page.
3561 *
3562 * @deprecated since 2.2
3563 * @see context::get_url()
3564 * @param context $context the context
3565 * @return moodle_url
3566 */
3567function get_context_url(context $context) {
3568 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
3569 return $context->get_url();
3570}
3571
dd33f4af
MN
3572/**
3573 * Is this context part of any course? if yes return course context,
3574 * if not return null or throw exception.
3575 *
3576 * @deprecated since 2.2
3577 * @see context::get_course_context()
3578 * @param context $context
aa386d29 3579 * @return context_course context of the enclosing course, null if not found or exception
dd33f4af
MN
3580 */
3581function get_course_context(context $context) {
3582 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
3583 return $context->get_course_context(true);
3584}
6acc54b3
AA
3585
3586/**
3587 * Get an array of courses where cap requested is available
3588 * and user is enrolled, this can be relatively slow.
3589 *
3590 * @deprecated since 2.2
3591 * @see enrol_get_users_courses()
3592 * @param int $userid A user id. By default (null) checks the permissions of the current user.
3593 * @param string $cap - name of the capability
3594 * @param array $accessdata_ignored
3595 * @param bool $doanything_ignored
3596 * @param string $sort - sorting fields - prefix each fieldname with "c."
3597 * @param array $fields - additional fields you are interested in...
3598 * @param int $limit_ignored
3599 * @return array $courses - ordered array of course objects - see notes above
3600 */
3601function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
3602
3603 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
3604 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
3605 foreach ($courses as $id=>$course) {
3606 $context = context_course::instance($id);
3607 if (!has_capability($cap, $context, $userid)) {
3608 unset($courses[$id]);
3609 }
3610 }
3611
3612 return $courses;
3613}
ae38dcb1
RT
3614
3615/**
3616 * This is really slow!!! do not use above course context level
3617 *
3618 * @deprecated since Moodle 2.2
3619 * @param int $roleid
3620 * @param context $context
3621 * @return array
3622 */
3623function get_role_context_caps($roleid, context $context) {
3624 global $DB;
3625 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
3626
3627 // This is really slow!!!! - do not use above course context level.
3628 $result = array();
3629 $result[$context->id] = array();
3630
3631 // First emulate the parent context capabilities merging into context.
3632 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
3633 foreach ($searchcontexts as $cid) {
3634 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
3635 foreach ($capabilities as $cap) {
3636 if (!array_key_exists($cap->capability, $result[$context->id])) {
3637 $result[$context->id][$cap->capability] = 0;
3638 }
3639 $result[$context->id][$cap->capability] += $cap->permission;
3640 }
3641 }
3642 }
3643
3644 // Now go through the contexts below given context.
3645 $searchcontexts = array_keys($context->get_child_contexts());
3646 foreach ($searchcontexts as $cid) {
3647 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
3648 foreach ($capabilities as $cap) {
3649 if (!array_key_exists($cap->contextid, $result)) {
3650 $result[$cap->contextid] = array();
3651 }
3652 $result[$cap->contextid][$cap->capability] = $cap->permission;
3653 }
3654 }
3655 }
3656
3657 return $result;
3658}
b123a543
FM
3659
3660/**
3661 * Returns current course id or false if outside of course based on context parameter.
3662 *
3663 * @see context::get_course_context()
3664 * @deprecated since 2.2
3665 * @param context $context
3666 * @return int|bool related course id or false
3667 */
3668function get_courseid_from_context(context $context) {
3669 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
3670 if ($coursecontext = $context->get_course_context(false)) {
3671 return $coursecontext->instanceid;
3672 } else {
3673 return false;
3674 }
6a30b48d 3675}
2e4c0c91
FM
3676
3677/**
3678 * Preloads context information together with instances.
3679 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
3680 *
3681 * If you are using this methid, you should have something like this:
3682 *
3683 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3684 *
3685 * To prevent the use of this deprecated function, replace the line above with something similar to this:
3686 *
3687 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
3688 * ^
3689 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
3690 * ^ ^ ^ ^
3691 * $params = array('contextlevel' => CONTEXT_COURSE);
3692 * ^
3693 * @see context_helper:;get_preload_record_columns_sql()
3694 * @deprecated since 2.2
3695 * @param string $joinon for example 'u.id'
3696 * @param string $contextlevel context level of instance in $joinon
3697 * @param string $tablealias context table alias
3698 * @return array with two values - select and join part
3699 */
3700function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
3701 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
3702 $select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
3703 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
3704 return array($select, $join);
b123a543 3705}
b6452844
MN
3706
3707/**
3708 * Gets a string for sql calls, searching for stuff in this context or above.
3709 *
3710 * @deprecated since 2.2
3711 * @see context::get_parent_context_ids()
3712 * @param context $context
3713 * @return string
3714 */
3715function get_related_contexts_string(context $context) {
3716 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
3717 if ($parents = $context->get_parent_context_ids()) {
3718 return (' IN ('.$context->id.','.implode(',', $parents).')');
3719 } else {
3720 return (' ='.$context->id);
3721 }
3722}
0142523d 3723
d0cac8b5
FM
3724/**
3725 * Get a list of all the plugins of a given type that contain a particular file.
3726 *
3727 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
3728 * @param string $file the name of file that must be present in the plugin.
3729 * (e.g. 'view.php', 'db/install.xml').
3730 * @param bool $include if true (default false), the file will be include_once-ed if found.
3731 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
3732 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
3733 * @deprecated since 2.6
3734 * @see core_component::get_plugin_list_with_file()
3735 */
3736function get_plugin_list_with_file($plugintype, $file, $include = false) {
3737 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
3738 DEBUG_DEVELOPER);
3739 return core_component::get_plugin_list_with_file($plugintype, $file, $include);
3740}
c3d2fbf9
SH
3741
3742/**
3743 * Checks to see if is the browser operating system matches the specified brand.
3744 *
3745 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
3746 *
3747 * @deprecated since 2.6
3748 * @param string $brand The operating system identifier being tested
3749 * @return bool true if the given brand below to the detected operating system
3750 */
3751function check_browser_operating_system($brand) {
3752 debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3753 return core_useragent::check_browser_operating_system($brand);
3754}
3755
3756/**
3757 * Checks to see if is a browser matches the specified
3758 * brand and is equal or better version.
3759 *
3760 * @deprecated since 2.6
3761 * @param string $brand The browser identifier being tested
3762 * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons)
3763 * @return bool true if the given version is below that of the detected browser
3764 */
3765function check_browser_version($brand, $version = null) {
3766 debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3767 return core_useragent::check_browser_version($brand, $version);
3768}
3769
3770/**
3771 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
3772 * an optional admin specified regular expression. If enabledevicedetection is set to no or not set
3773 * it returns default
3774 *
3775 * @deprecated since 2.6
3776 * @return string device type
3777 */
3778function get_device_type() {
3779 debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3780 return core_useragent::get_device_type();
3781}
3782
3783/**
3784 * Returns a list of the device types supporting by Moodle
3785 *
3786 * @deprecated since 2.6
3787 * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting
3788 * @return array $types
3789 */
3790function get_device_type_list($incusertypes = true) {
3791 debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3792 return core_useragent::get_device_type_list($incusertypes);
3793}
3794
3795/**
3796 * Returns the theme selected for a particular device or false if none selected.
3797 *
3798 * @deprecated since 2.6
3799 * @param string $devicetype
3800 * @return string|false The name of the theme to use for the device or the false if not set
3801 */
3802function get_selected_theme_for_device_type($devicetype = null) {
3803 debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3804 return core_useragent::get_device_type_theme($devicetype);
3805}
3806
3807/**
3808 * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility.
3809 *
3810 * @deprecated since 2.6
3811 * @param string $devicetype
3812 * @return string The config variable to use to determine the theme
3813 */
3814function get_device_cfg_var_name($devicetype = null) {
3815 debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3816 return core_useragent::get_device_type_cfg_var_name($devicetype);
3817}
3818
3819/**
3820 * Allows the user to switch the device they are seeing the theme for.
3821 * This allows mobile users to switch back to the default theme, or theme for any other device.
3822 *
3823 * @deprecated since 2.6
3824 * @param string $newdevice The device the user is currently using.
3825 * @return string The device the user has switched to
3826 */
3827function set_user_device_type($newdevice) {
3828 debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3829 return core_useragent::set_user_device_type($newdevice);
3830}
3831
3832/**
3833 * Returns the device the user is currently using, or if the user has chosen to switch devices
3834 * for the current device type the type they have switched to.
3835 *
3836 * @deprecated since 2.6