MDL-44260 uplodate: move deprecated functions to deprecatedlib
[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,
2f1e464a 1390 * ex: core_text::convert()
3fed29a7 1391 *
2f1e464a 1392 * @deprecated since Moodle 2.2 use core_text::xxxx() instead
3fed29a7
PS
1393 * @see textlib
1394 * @return textlib instance
1395 */
1396function textlib_get_instance() {
1397
2f1e464a 1398 debugging('textlib_get_instance() is deprecated. Please use static calling core_text::functioname() instead.', DEBUG_DEVELOPER);
3fed29a7
PS
1399
1400 return new textlib();
1401}
1402
ee7084e9
MG
1403/**
1404 * Gets the generic section name for a courses section
1405 *
1406 * The global function is deprecated. Each course format can define their own generic section name
1407 *
1408 * @deprecated since 2.4
1409 * @see get_section_name()
1410 * @see format_base::get_section_name()
1411 *
1412 * @param string $format Course format ID e.g. 'weeks' $course->format
1413 * @param stdClass $section Section object from database
1414 * @return Display name that the course format prefers, e.g. "Week 2"
1415 */
1416function get_generic_section_name($format, stdClass $section) {
1417 debugging('get_generic_section_name() is deprecated. Please use appropriate functionality from class format_base', DEBUG_DEVELOPER);
1418 return get_string('sectionname', "format_$format") . ' ' . $section->section;
1419}
99e9f9a6
MG
1420
1421/**
1422 * Returns an array of sections for the requested course id
1423 *
1424 * It is usually not recommended to display the list of sections used
1425 * in course because the course format may have it's own way to do it.
1426 *
1427 * If you need to just display the name of the section please call:
1428 * get_section_name($course, $section)
1429 * {@link get_section_name()}
1430 * from 2.4 $section may also be just the field course_sections.section
1431 *
1432 * If you need the list of all sections it is more efficient to get this data by calling
b46be6ad 1433 * $modinfo = get_fast_modinfo($courseorid);
99e9f9a6
MG
1434 * $sections = $modinfo->get_section_info_all()
1435 * {@link get_fast_modinfo()}
1436 * {@link course_modinfo::get_section_info_all()}
1437 *
1438 * Information about one section (instance of section_info):
b46be6ad 1439 * get_fast_modinfo($courseorid)->get_sections_info($section)
99e9f9a6
MG
1440 * {@link course_modinfo::get_section_info()}
1441 *
1442 * @deprecated since 2.4
1443 *
1444 * @param int $courseid
1445 * @return array Array of section_info objects
1446 */
1447function get_all_sections($courseid) {
1448 global $DB;
1449 debugging('get_all_sections() is deprecated. See phpdocs for this function', DEBUG_DEVELOPER);
b46be6ad 1450 return get_fast_modinfo($courseid)->get_section_info_all();
99e9f9a6 1451}
722e6ba9
MG
1452
1453/**
1454 * Given a full mod object with section and course already defined, adds this module to that section.
1455 *
1456 * This function is deprecated, please use {@link course_add_cm_to_section()}
1457 * Note that course_add_cm_to_section() also updates field course_modules.section and
1458 * calls rebuild_course_cache()
1459 *
1460 * @deprecated since 2.4
1461 *
1462 * @param object $mod
1463 * @param int $beforemod An existing ID which we will insert the new module before
1464 * @return int The course_sections ID where the mod is inserted
1465 */
44aa854e 1466function add_mod_to_section($mod, $beforemod = null) {
722e6ba9
MG
1467 debugging('Function add_mod_to_section() is deprecated, please use course_add_cm_to_section()', DEBUG_DEVELOPER);
1468 global $DB;
b46be6ad 1469 return course_add_cm_to_section($mod->course, $mod->coursemodule, $mod->section, $beforemod);
722e6ba9 1470}
d57aa283
MG
1471
1472/**
1473 * Returns a number of useful structures for course displays
1474 *
1475 * Function get_all_mods() is deprecated in 2.4
1476 * Instead of:
1477 * <code>
b46be6ad 1478 * get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused);
d57aa283
MG
1479 * </code>
1480 * please use:
1481 * <code>
b46be6ad 1482 * $mods = get_fast_modinfo($courseorid)->get_cms();
d57aa283
MG
1483 * $modnames = get_module_types_names();
1484 * $modnamesplural = get_module_types_names(true);
b46be6ad 1485 * $modnamesused = get_fast_modinfo($courseorid)->get_used_module_names();
d57aa283
MG
1486 * </code>
1487 *
1488 * @deprecated since 2.4
1489 *
1490 * @param int $courseid id of the course to get info about
1491 * @param array $mods (return) list of course modules
1492 * @param array $modnames (return) list of names of all module types installed and available
1493 * @param array $modnamesplural (return) list of names of all module types installed and available in the plural form
1494 * @param array $modnamesused (return) list of names of all module types used in the course
1495 */
1496function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
1497 debugging('Function get_all_mods() is deprecated. Use get_fast_modinfo() and get_module_types_names() instead. See phpdocs for details', DEBUG_DEVELOPER);
1498
1499 global $COURSE;
1500 $modnames = get_module_types_names();
1501 $modnamesplural= get_module_types_names(true);
b46be6ad 1502 $modinfo = get_fast_modinfo($courseid);
d57aa283
MG
1503 $mods = $modinfo->get_cms();
1504 $modnamesused = $modinfo->get_used_module_names();
1505}
4ede27b2
MG
1506
1507/**
1508 * Returns course section - creates new if does not exist yet
1509 *
1510 * This function is deprecated. To create a course section call:
b46be6ad 1511 * course_create_sections_if_missing($courseorid, $sections);
4ede27b2 1512 * to get the section call:
b46be6ad 1513 * get_fast_modinfo($courseorid)->get_section_info($sectionnum);
4ede27b2
MG
1514 *
1515 * @see course_create_sections_if_missing()
1516 * @see get_fast_modinfo()
1517 * @deprecated since 2.4
1518 *
1519 * @param int $section relative section number (field course_sections.section)
1520 * @param int $courseid
1521 * @return stdClass record from table {course_sections}
1522 */
1523function get_course_section($section, $courseid) {
1524 global $DB;
1525 debugging('Function get_course_section() is deprecated. Please use course_create_sections_if_missing() and get_fast_modinfo() instead.', DEBUG_DEVELOPER);
1526
1527 if ($cw = $DB->get_record("course_sections", array("section"=>$section, "course"=>$courseid))) {
1528 return $cw;
1529 }
1530 $cw = new stdClass();
1531 $cw->course = $courseid;
1532 $cw->section = $section;
1533 $cw->summary = "";
1534 $cw->summaryformat = FORMAT_HTML;
1535 $cw->sequence = "";
1536 $id = $DB->insert_record("course_sections", $cw);
1537 rebuild_course_cache($courseid, true);
1538 return $DB->get_record("course_sections", array("id"=>$id));
1539}
1b2581f4
MG
1540
1541/**
1542 * Return the start and end date of the week in Weekly course format
1543 *
1544 * It is not recommended to use this function outside of format_weeks plugin
1545 *
1546 * @deprecated since 2.4
1547 * @see format_weeks::get_section_dates()
1548 *
1549 * @param stdClass $section The course_section entry from the DB
1550 * @param stdClass $course The course entry from DB
1551 * @return stdClass property start for startdate, property end for enddate
1552 */
1553function format_weeks_get_section_dates($section, $course) {
1554 debugging('Function format_weeks_get_section_dates() is deprecated. It is not recommended to'.
1555 ' use it outside of format_weeks plugin', DEBUG_DEVELOPER);
1556 if (isset($course->format) && $course->format === 'weeks') {
1557 return course_get_format($course)->get_section_dates($section);
1558 }
1559 return null;
1560}
9a36be73
MG
1561
1562/**
1563 * Obtains shared data that is used in print_section when displaying a
1564 * course-module entry.
1565 *
1566 * Deprecated. Instead of:
1567 * list($content, $name) = get_print_section_cm_text($cm, $course);
1568 * use:
1569 * $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
1570 * $name = $cm->get_formatted_name();
1571 *
1572 * @deprecated since 2.5
1573 * @see cm_info::get_formatted_content()
1574 * @see cm_info::get_formatted_name()
1575 *
1576 * This data is also used in other areas of the code.
1577 * @param cm_info $cm Course-module data (must come from get_fast_modinfo)
1578 * @param object $course (argument not used)
1579 * @return array An array with the following values in this order:
1580 * $content (optional extra content for after link),
1581 * $instancename (text of link)
1582 */
1583function get_print_section_cm_text(cm_info $cm, $course) {
1584 debugging('Function get_print_section_cm_text() is deprecated. Please use '.
1585 'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
1586 DEBUG_DEVELOPER);
1587 return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
1588 $cm->get_formatted_name());
1589}
1590
1591/**
1592 * Prints the menus to add activities and resources.
1593 *
1594 * Deprecated. Please use:
1595 * $courserenderer = $PAGE->get_renderer('core', 'course');
1596 * $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1597 * array('inblock' => $vertical));
1598 * echo $output; // if $return argument in print_section_add_menus() set to false
1599 *
1600 * @deprecated since 2.5
1601 * @see core_course_renderer::course_section_add_cm_control()
1602 *
1603 * @param stdClass $course course object, must be the same as set on the page
1604 * @param int $section relative section number (field course_sections.section)
1605 * @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
1606 * @param bool $vertical Vertical orientation
1607 * @param bool $return Return the menus or send them to output
1608 * @param int $sectionreturn The section to link back to
1609 * @return void|string depending on $return
1610 */
1611function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
1612 global $PAGE;
1613 debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
1614 'function course_section_add_cm_control()', DEBUG_DEVELOPER);
1615 $output = '';
1616 $courserenderer = $PAGE->get_renderer('core', 'course');
1617 $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
1618 array('inblock' => $vertical));
1619 if ($return) {
1620 return $output;
1621 } else {
1622 echo $output;
1623 return !empty($output);
1624 }
1625}
1626
1627/**
1628 * Produces the editing buttons for a module
1629 *
1630 * Deprecated. Please use:
1631 * $courserenderer = $PAGE->get_renderer('core', 'course');
1632 * $actions = course_get_cm_edit_actions($mod, $indent, $section);
1633 * return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1634 *
1635 * @deprecated since 2.5
1636 * @see course_get_cm_edit_actions()
1637 * @see core_course_renderer->course_section_cm_edit_actions()
1638 *
1639 * @param stdClass $mod The module to produce editing buttons for
1640 * @param bool $absolute_ignored (argument ignored) - all links are absolute
1641 * @param bool $moveselect (argument ignored)
1642 * @param int $indent The current indenting
1643 * @param int $section The section to link back to
1644 * @return string XHTML for the editing buttons
1645 */
1646function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
1647 global $PAGE;
1648 debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
1649 'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
1650 if (!($mod instanceof cm_info)) {
1651 $modinfo = get_fast_modinfo($mod->course);
1652 $mod = $modinfo->get_cm($mod->id);
1653 }
1654 $actions = course_get_cm_edit_actions($mod, $indent, $section);
1655
1656 $courserenderer = $PAGE->get_renderer('core', 'course');
1657 // The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
1658 // and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
1659 // the course page HTML will allow this to be removed.
1660 return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
1661}
1662
1663/**
1664 * Prints a section full of activity modules
1665 *
1666 * Deprecated. Please use:
1667 * $courserenderer = $PAGE->get_renderer('core', 'course');
1668 * echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
1669 * array('hidecompletion' => $hidecompletion));
1670 *
1671 * @deprecated since 2.5
1672 * @see core_course_renderer::course_section_cm_list()
1673 *
1674 * @param stdClass $course The course
1675 * @param stdClass|section_info $section The section object containing properties id and section
1676 * @param array $mods (argument not used)
1677 * @param array $modnamesused (argument not used)
1678 * @param bool $absolute (argument not used)
1679 * @param string $width (argument not used)
1680 * @param bool $hidecompletion Hide completion status
1681 * @param int $sectionreturn The section to return to
1682 * @return void
1683 */
1684function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
1685 global $PAGE;
1686 debugging('Function print_section() is deprecated. Please use course renderer function '.
1687 'course_section_cm_list() instead.', DEBUG_DEVELOPER);
1688 $displayoptions = array('hidecompletion' => $hidecompletion);
1689 $courserenderer = $PAGE->get_renderer('core', 'course');
1690 echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
1691}
00ba185d 1692
ff233851
MG
1693/**
1694 * Displays the list of courses with user notes
1695 *
1696 * This function is not used in core. It was replaced by block course_overview
1697 *
1698 * @deprecated since 2.5
1699 *
1700 * @param array $courses
1701 * @param array $remote_courses
1702 */
1703function print_overview($courses, array $remote_courses=array()) {
1704 global $CFG, $USER, $DB, $OUTPUT;
1705 debugging('Function print_overview() is deprecated. Use block course_overview to display this information', DEBUG_DEVELOPER);
1706
1707 $htmlarray = array();
1708 if ($modules = $DB->get_records('modules')) {
1709 foreach ($modules as $mod) {
1710 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
1711 include_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
1712 $fname = $mod->name.'_print_overview';
1713 if (function_exists($fname)) {
1714 $fname($courses,$htmlarray);
1715 }
1716 }
1717 }
1718 }
1719 foreach ($courses as $course) {
1720 $fullname = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
1721 echo $OUTPUT->box_start('coursebox');
1722 $attributes = array('title' => s($fullname));
1723 if (empty($course->visible)) {
1724 $attributes['class'] = 'dimmed';
1725 }
1726 echo $OUTPUT->heading(html_writer::link(
1727 new moodle_url('/course/view.php', array('id' => $course->id)), $fullname, $attributes), 3);
1728 if (array_key_exists($course->id,$htmlarray)) {
1729 foreach ($htmlarray[$course->id] as $modname => $html) {
1730 echo $html;
1731 }
1732 }
1733 echo $OUTPUT->box_end();
1734 }
1735
1736 if (!empty($remote_courses)) {
1737 echo $OUTPUT->heading(get_string('remotecourses', 'mnet'));
1738 }
1739 foreach ($remote_courses as $course) {
1740 echo $OUTPUT->box_start('coursebox');
1741 $attributes = array('title' => s($course->fullname));
1742 echo $OUTPUT->heading(html_writer::link(
1743 new moodle_url('/auth/mnet/jump.php', array('hostid' => $course->hostid, 'wantsurl' => '/course/view.php?id='.$course->remoteid)),
1744 format_string($course->shortname),
1745 $attributes) . ' (' . format_string($course->hostname) . ')', 3);
1746 echo $OUTPUT->box_end();
1747 }
1748}
a3f66bde
MG
1749
1750/**
1751 * This function trawls through the logs looking for
1752 * anything new since the user's last login
1753 *
1754 * This function was only used to print the content of block recent_activity
1755 * All functionality is moved into class {@link block_recent_activity}
1756 * and renderer {@link block_recent_activity_renderer}
1757 *
1758 * @deprecated since 2.5
1759 * @param stdClass $course
1760 */
1761function print_recent_activity($course) {
1762 // $course is an object
1763 global $CFG, $USER, $SESSION, $DB, $OUTPUT;
1764 debugging('Function print_recent_activity() is deprecated. It is not recommended to'.
1765 ' use it outside of block_recent_activity', DEBUG_DEVELOPER);
1766
1767 $context = context_course::instance($course->id);
1768
1769 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
1770
1771 $timestart = round(time() - COURSE_MAX_RECENT_PERIOD, -2); // better db caching for guests - 100 seconds
1772
1773 if (!isguestuser()) {
1774 if (!empty($USER->lastcourseaccess[$course->id])) {
1775 if ($USER->lastcourseaccess[$course->id] > $timestart) {
1776 $timestart = $USER->lastcourseaccess[$course->id];
1777 }
1778 }
1779 }
1780
1781 echo '<div class="activitydate">';
1782 echo get_string('activitysince', '', userdate($timestart));
1783 echo '</div>';
1784 echo '<div class="activityhead">';
1785
1786 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
1787
1788 echo "</div>\n";
1789
1790 $content = false;
1791
1792/// Firstly, have there been any new enrolments?
1793
1794 $users = get_recent_enrolments($course->id, $timestart);
1795
1796 //Accessibility: new users now appear in an <OL> list.
1797 if ($users) {
1798 echo '<div class="newusers">';
1799 echo $OUTPUT->heading(get_string("newusers").':', 3);
1800 $content = true;
1801 echo "<ol class=\"list\">\n";
1802 foreach ($users as $user) {
1803 $fullname = fullname($user, $viewfullnames);
1804 echo '<li class="name"><a href="'."$CFG->wwwroot/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
1805 }
1806 echo "</ol>\n</div>\n";
1807 }
1808
1809/// Next, have there been any modifications to the course structure?
1810
1811 $modinfo = get_fast_modinfo($course);
1812
1813 $changelist = array();
1814
1815 $logs = $DB->get_records_select('log', "time > ? AND course = ? AND
1816 module = 'course' AND
1817 (action = 'add mod' OR action = 'update mod' OR action = 'delete mod')",
1818 array($timestart, $course->id), "id ASC");
1819
1820 if ($logs) {
1821 $actions = array('add mod', 'update mod', 'delete mod');
1822 $newgones = array(); // added and later deleted items
1823 foreach ($logs as $key => $log) {
1824 if (!in_array($log->action, $actions)) {
1825 continue;
1826 }
1827 $info = explode(' ', $log->info);
1828
1829 // note: in most cases I replaced hardcoding of label with use of
1830 // $cm->has_view() but it was not possible to do this here because
1831 // we don't necessarily have the $cm for it
1832 if ($info[0] == 'label') { // Labels are ignored in recent activity
1833 continue;
1834 }
1835
1836 if (count($info) != 2) {
1837 debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER);
1838 continue;
1839 }
1840
1841 $modname = $info[0];
1842 $instanceid = $info[1];
1843
1844 if ($log->action == 'delete mod') {
1845 // unfortunately we do not know if the mod was visible
1846 if (!array_key_exists($log->info, $newgones)) {
1847 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $modname));
1848 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
1849 }
1850 } else {
1851 if (!isset($modinfo->instances[$modname][$instanceid])) {
1852 if ($log->action == 'add mod') {
1853 // do not display added and later deleted activities
1854 $newgones[$log->info] = true;
1855 }
1856 continue;
1857 }
1858 $cm = $modinfo->instances[$modname][$instanceid];
1859 if (!$cm->uservisible) {
1860 continue;
1861 }
1862
1863 if ($log->action == 'add mod') {
1864 $stradded = get_string('added', 'moodle', get_string('modulename', $modname));
1865 $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>");
1866
1867 } else if ($log->action == 'update mod' and empty($changelist[$log->info])) {
1868 $strupdated = get_string('updated', 'moodle', get_string('modulename', $modname));
1869 $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>");
1870 }
1871 }
1872 }
1873 }
1874
1875 if (!empty($changelist)) {
1876 echo $OUTPUT->heading(get_string("courseupdates").':', 3);
1877 $content = true;
1878 foreach ($changelist as $changeinfo => $change) {
1879 echo '<p class="activity">'.$change['text'].'</p>';
1880 }
1881 }
1882
1883/// Now display new things from each module
1884
1885 $usedmodules = array();
1886 foreach($modinfo->cms as $cm) {
1887 if (isset($usedmodules[$cm->modname])) {
1888 continue;
1889 }
1890 if (!$cm->uservisible) {
1891 continue;
1892 }
1893 $usedmodules[$cm->modname] = $cm->modname;
1894 }
1895
1896 foreach ($usedmodules as $modname) { // Each module gets it's own logs and prints them
1897 if (file_exists($CFG->dirroot.'/mod/'.$modname.'/lib.php')) {
1898 include_once($CFG->dirroot.'/mod/'.$modname.'/lib.php');
1899 $print_recent_activity = $modname.'_print_recent_activity';
1900 if (function_exists($print_recent_activity)) {
1901 // NOTE: original $isteacher (second parameter below) was replaced with $viewfullnames!
1902 $content = $print_recent_activity($course, $viewfullnames, $timestart) || $content;
1903 }
1904 } else {
1905 debugging("Missing lib.php in lib/{$modname} - please reinstall files or uninstall the module");
1906 }
1907 }
1908
1909 if (! $content) {
1910 echo '<p class="message">'.get_string('nothingnew').'</p>';
1911 }
1912}
a347aee3
MN
1913
1914/**
1915 * Delete a course module and any associated data at the course level (events)
1916 * Until 1.5 this function simply marked a deleted flag ... now it
1917 * deletes it completely.
1918 *
1919 * @deprecated since 2.5
1920 *
1921 * @param int $id the course module id
1922 * @return boolean true on success, false on failure
1923 */
1924function delete_course_module($id) {
1925 debugging('Function delete_course_module() is deprecated. Please use course_delete_module() instead.', DEBUG_DEVELOPER);
1926
1927 global $CFG, $DB;
1928
1929 require_once($CFG->libdir.'/gradelib.php');
1930 require_once($CFG->dirroot.'/blog/lib.php');
1931
1932 if (!$cm = $DB->get_record('course_modules', array('id'=>$id))) {
1933 return true;
1934 }
1935 $modulename = $DB->get_field('modules', 'name', array('id'=>$cm->module));
1936 //delete events from calendar
1937 if ($events = $DB->get_records('event', array('instance'=>$cm->instance, 'modulename'=>$modulename))) {
1938 foreach($events as $event) {
1939 delete_event($event->id);
1940 }
1941 }
1942 //delete grade items, outcome items and grades attached to modules
1943 if ($grade_items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
1944 'iteminstance'=>$cm->instance, 'courseid'=>$cm->course))) {
1945 foreach ($grade_items as $grade_item) {
1946 $grade_item->delete('moddelete');
1947 }
1948 }
1949 // Delete completion and availability data; it is better to do this even if the
1950 // features are not turned on, in case they were turned on previously (these will be
1951 // very quick on an empty table)
1952 $DB->delete_records('course_modules_completion', array('coursemoduleid' => $cm->id));
a347aee3
MN
1953 $DB->delete_records('course_completion_criteria', array('moduleinstance' => $cm->id,
1954 'criteriatype' => COMPLETION_CRITERIA_TYPE_ACTIVITY));
1955
1956 delete_context(CONTEXT_MODULE, $cm->id);
1957 return $DB->delete_records('course_modules', array('id'=>$cm->id));
1958}
2c49fb4c
MG
1959
1960/**
1961 * Prints the turn editing on/off button on course/index.php or course/category.php.
1962 *
1963 * @deprecated since 2.5
1964 *
1965 * @param integer $categoryid The id of the category we are showing, or 0 for system context.
1966 * @return string HTML of the editing button, or empty string, if this user is not allowed
1967 * to see it.
1968 */
1969function update_category_button($categoryid = 0) {
1970 global $CFG, $PAGE, $OUTPUT;
1971 debugging('Function update_category_button() is deprecated. Pages to view '.
1972 'and edit courses are now separate and no longer depend on editing mode.',
1973 DEBUG_DEVELOPER);
1974
1975 // Check permissions.
1976 if (!can_edit_in_category($categoryid)) {
1977 return '';
1978 }
1979
1980 // Work out the appropriate action.
1981 if ($PAGE->user_is_editing()) {
1982 $label = get_string('turneditingoff');
1983 $edit = 'off';
1984 } else {
1985 $label = get_string('turneditingon');
1986 $edit = 'on';
1987 }
1988
1989 // Generate the button HTML.
1990 $options = array('categoryedit' => $edit, 'sesskey' => sesskey());
1991 if ($categoryid) {
1992 $options['id'] = $categoryid;
1993 $page = 'category.php';
1994 } else {
1995 $page = 'index.php';
1996 }
1997 return $OUTPUT->single_button(new moodle_url('/course/' . $page, $options), $label, 'get');
1998}
4e0b6025
MG
1999
2000/**
2001 * This function recursively travels the categories, building up a nice list
2002 * for display. It also makes an array that list all the parents for each
2003 * category.
2004 *
2005 * For example, if you have a tree of categories like:
2006 * Miscellaneous (id = 1)
2007 * Subcategory (id = 2)
2008 * Sub-subcategory (id = 4)
2009 * Other category (id = 3)
2010 * Then after calling this function you will have
2011 * $list = array(1 => 'Miscellaneous', 2 => 'Miscellaneous / Subcategory',
2012 * 4 => 'Miscellaneous / Subcategory / Sub-subcategory',
2013 * 3 => 'Other category');
2014 * $parents = array(2 => array(1), 4 => array(1, 2));
2015 *
2016 * If you specify $requiredcapability, then only categories where the current
2017 * user has that capability will be added to $list, although all categories
2018 * will still be added to $parents, and if you only have $requiredcapability
2019 * in a child category, not the parent, then the child catgegory will still be
2020 * included.
2021 *
2022 * If you specify the option $excluded, then that category, and all its children,
2023 * are omitted from the tree. This is useful when you are doing something like
2024 * moving categories, where you do not want to allow people to move a category
2025 * to be the child of itself.
2026 *
2027 * This function is deprecated! For list of categories use
2028 * coursecat::make_all_categories($requiredcapability, $excludeid, $separator)
2029 * For parents of one particular category use
2030 * coursecat::get($id)->get_parents()
2031 *
2032 * @deprecated since 2.5
2033 *
2034 * @param array $list For output, accumulates an array categoryid => full category path name
2035 * @param array $parents For output, accumulates an array categoryid => list of parent category ids.
2036 * @param string/array $requiredcapability if given, only categories where the current
2037 * user has this capability will be added to $list. Can also be an array of capabilities,
2038 * in which case they are all required.
2039 * @param integer $excludeid Omit this category and its children from the lists built.
2040 * @param object $category Not used
2041 * @param string $path Not used
2042 */
2043function make_categories_list(&$list, &$parents, $requiredcapability = '',
2044 $excludeid = 0, $category = NULL, $path = "") {
2045 global $CFG, $DB;
2046 require_once($CFG->libdir.'/coursecatlib.php');
2047
2048 debugging('Global function make_categories_list() is deprecated. Please use '.
2049 'coursecat::make_categories_list() and coursecat::get_parents()',
2050 DEBUG_DEVELOPER);
2051
2052 // For categories list use just this one function:
2053 if (empty($list)) {
2054 $list = array();
2055 }
2056 $list += coursecat::make_categories_list($requiredcapability, $excludeid);
2057
2058 // Building the list of all parents of all categories in the system is highly undesirable and hardly ever needed.
2059 // Usually user needs only parents for one particular category, in which case should be used:
2060 // coursecat::get($categoryid)->get_parents()
2061 if (empty($parents)) {
2062 $parents = array();
2063 }
2064 $all = $DB->get_records_sql('SELECT id, parent FROM {course_categories} ORDER BY sortorder');
2065 foreach ($all as $record) {
2066 if ($record->parent) {
2067 $parents[$record->id] = array_merge($parents[$record->parent], array($record->parent));
2068 } else {
2069 $parents[$record->id] = array();
2070 }
2071 }
2072}
deb65ced
MG
2073
2074/**
2075 * Delete category, but move contents to another category.
2076 *
2077 * This function is deprecated. Please use
2078 * coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2079 *
2080 * @see coursecat::delete_move()
2081 * @deprecated since 2.5
2082 *
2083 * @param object $category
2084 * @param int $newparentid category id
2085 * @return bool status
2086 */
2087function category_delete_move($category, $newparentid, $showfeedback=true) {
2088 global $CFG;
2089 require_once($CFG->libdir.'/coursecatlib.php');
2090
2091 debugging('Function category_delete_move() is deprecated. Please use coursecat::delete_move() instead.');
2092
2093 return coursecat::get($category->id)->delete_move($newparentid, $showfeedback);
2094}
2095
2096/**
2097 * Recursively delete category including all subcategories and courses.
2098 *
2099 * This function is deprecated. Please use
2100 * coursecat::get($category->id)->delete_full($showfeedback);
2101 *
2102 * @see coursecat::delete_full()
2103 * @deprecated since 2.5
2104 *
2105 * @param stdClass $category
2106 * @param boolean $showfeedback display some notices
2107 * @return array return deleted courses
2108 */
2109function category_delete_full($category, $showfeedback=true) {
2110 global $CFG, $DB;
2111 require_once($CFG->libdir.'/coursecatlib.php');
2112
2113 debugging('Function category_delete_full() is deprecated. Please use coursecat::delete_full() instead.');
2114
2115 return coursecat::get($category->id)->delete_full($showfeedback);
2116}
6e1d1ee0
MG
2117
2118/**
2119 * Efficiently moves a category - NOTE that this can have
2120 * a huge impact access-control-wise...
2121 *
2122 * This function is deprecated. Please use
2123 * $coursecat = coursecat::get($category->id);
2124 * if ($coursecat->can_change_parent($newparentcat->id)) {
2125 * $coursecat->change_parent($newparentcat->id);
2126 * }
2127 *
2128 * Alternatively you can use
2129 * $coursecat->update(array('parent' => $newparentcat->id));
2130 *
2131 * Function update() also updates field course_categories.timemodified
2132 *
2133 * @see coursecat::change_parent()
2134 * @see coursecat::update()
2135 * @deprecated since 2.5
2136 *
2137 * @param stdClass|coursecat $category
2138 * @param stdClass|coursecat $newparentcat
2139 */
2140function move_category($category, $newparentcat) {
2141 global $CFG;
2142 require_once($CFG->libdir.'/coursecatlib.php');
2143
2144 debugging('Function move_category() is deprecated. Please use coursecat::change_parent() instead.');
2145
2146 return coursecat::get($category->id)->change_parent($newparentcat->id);
2147}
2148
2149/**
2150 * Hide course category and child course and subcategories
2151 *
2152 * This function is deprecated. Please use
2153 * coursecat::get($category->id)->hide();
2154 *
2155 * @see coursecat::hide()
2156 * @deprecated since 2.5
2157 *
2158 * @param stdClass $category
2159 * @return void
2160 */
2161function course_category_hide($category) {
2162 global $CFG;
2163 require_once($CFG->libdir.'/coursecatlib.php');
2164
2165 debugging('Function course_category_hide() is deprecated. Please use coursecat::hide() instead.');
2166
2167 coursecat::get($category->id)->hide();
2168}
2169
2170/**
2171 * Show course category and child course and subcategories
2172 *
2173 * This function is deprecated. Please use
2174 * coursecat::get($category->id)->show();
2175 *
2176 * @see coursecat::show()
2177 * @deprecated since 2.5
2178 *
2179 * @param stdClass $category
2180 * @return void
2181 */
2182function course_category_show($category) {
2183 global $CFG;
2184 require_once($CFG->libdir.'/coursecatlib.php');
2185
2186 debugging('Function course_category_show() is deprecated. Please use coursecat::show() instead.');
2187
2188 coursecat::get($category->id)->show();
2189}
2d8a275b
MG
2190
2191/**
2192 * Return specified category, default if given does not exist
2193 *
2194 * This function is deprecated.
2195 * To get the category with the specified it please use:
2196 * coursecat::get($catid, IGNORE_MISSING);
2197 * or
2198 * coursecat::get($catid, MUST_EXIST);
2199 *
2200 * To get the first available category please use
2201 * coursecat::get_default();
2202 *
2203 * class coursecat will also make sure that at least one category exists in DB
2204 *
2205 * @deprecated since 2.5
2206 * @see coursecat::get()
2207 * @see coursecat::get_default()
2208 *
2209 * @param int $catid course category id
2210 * @return object caregory
2211 */
2212function get_course_category($catid=0) {
2213 global $DB;
2214
2215 debugging('Function get_course_category() is deprecated. Please use coursecat::get(), see phpdocs for more details');
2216
2217 $category = false;
2218
2219 if (!empty($catid)) {
2220 $category = $DB->get_record('course_categories', array('id'=>$catid));
2221 }
2222
2223 if (!$category) {
2224 // the first category is considered default for now
2225 if ($category = $DB->get_records('course_categories', null, 'sortorder', '*', 0, 1)) {
2226 $category = reset($category);
2227
2228 } else {
2229 $cat = new stdClass();
2230 $cat->name = get_string('miscellaneous');
2231 $cat->depth = 1;
2232 $cat->sortorder = MAX_COURSES_IN_CATEGORY;
2233 $cat->timemodified = time();
2234 $catid = $DB->insert_record('course_categories', $cat);
2235 // make sure category context exists
2236 context_coursecat::instance($catid);
2237 mark_context_dirty('/'.SYSCONTEXTID);
2238 fix_course_sortorder(); // Required to build course_categories.depth and .path.
2239 $category = $DB->get_record('course_categories', array('id'=>$catid));
2240 }
2241 }
2242
2243 return $category;
2244}
9bad61db
MG
2245
2246/**
2247 * Create a new course category and marks the context as dirty
2248 *
2249 * This function does not set the sortorder for the new category and
2250 * {@link fix_course_sortorder()} should be called after creating a new course
2251 * category
2252 *
2253 * Please note that this function does not verify access control.
2254 *
2255 * This function is deprecated. It is replaced with the method create() in class coursecat.
2256 * {@link coursecat::create()} also verifies the data, fixes sortorder and logs the action
2257 *
2258 * @deprecated since 2.5
2259 *
2260 * @param object $category All of the data required for an entry in the course_categories table
2261 * @return object new course category
2262 */
2263function create_course_category($category) {
2264 global $DB;
2265
2266 debugging('Function create_course_category() is deprecated. Please use coursecat::create(), see phpdocs for more details', DEBUG_DEVELOPER);
2267
2268 $category->timemodified = time();
2269 $category->id = $DB->insert_record('course_categories', $category);
2270 $category = $DB->get_record('course_categories', array('id' => $category->id));
2271
2272 // We should mark the context as dirty
2273 $category->context = context_coursecat::instance($category->id);
2274 $category->context->mark_dirty();
2275
2276 return $category;
2277}
bc81b006
MG
2278
2279/**
2280 * Returns an array of category ids of all the subcategories for a given
2281 * category.
2282 *
2283 * This function is deprecated.
2284 *
2285 * To get visible children categories of the given category use:
2286 * coursecat::get($categoryid)->get_children();
2287 * This function will return the array or coursecat objects, on each of them
2288 * you can call get_children() again
2289 *
2290 * @see coursecat::get()
2291 * @see coursecat::get_children()
2292 *
2293 * @deprecated since 2.5
2294 *
2295 * @global object
2296 * @param int $catid - The id of the category whose subcategories we want to find.
2297 * @return array of category ids.
2298 */
2299function get_all_subcategories($catid) {
2300 global $DB;
2301
2302 debugging('Function get_all_subcategories() is deprecated. Please use appropriate methods() of coursecat class. See phpdocs for more details',
2303 DEBUG_DEVELOPER);
2304
2305 $subcats = array();
2306
2307 if ($categories = $DB->get_records('course_categories', array('parent' => $catid))) {
2308 foreach ($categories as $cat) {
2309 array_push($subcats, $cat->id);
2310 $subcats = array_merge($subcats, get_all_subcategories($cat->id));
2311 }
2312 }
2313 return $subcats;
2314}
8db5dcb7
MG
2315
2316/**
2317 * Gets the child categories of a given courses category
2318 *
2319 * This function is deprecated. Please use functions in class coursecat:
2320 * - coursecat::get($parentid)->has_children()
2321 * tells if the category has children (visible or not to the current user)
2322 *
2323 * - coursecat::get($parentid)->get_children()
2324 * returns an array of coursecat objects, each of them represents a children category visible
2325 * to the current user (i.e. visible=1 or user has capability to view hidden categories)
2326 *
2327 * - coursecat::get($parentid)->get_children_count()
2328 * returns number of children categories visible to the current user
2329 *
2330 * - coursecat::count_all()
2331 * returns total count of all categories in the system (both visible and not)
2332 *
2333 * - coursecat::get_default()
2334 * returns the first category (usually to be used if count_all() == 1)
2335 *
2336 * @deprecated since 2.5
2337 *
2338 * @param int $parentid the id of a course category.
2339 * @return array all the child course categories.
2340 */
2341function get_child_categories($parentid) {
2342 global $DB;
2343 debugging('Function get_child_categories() is deprecated. Use coursecat::get_children() or see phpdocs for more details.',
2344 DEBUG_DEVELOPER);
2345
2346 $rv = array();
2347 $sql = context_helper::get_preload_record_columns_sql('ctx');
2348 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2349 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2350 array(CONTEXT_COURSECAT, $parentid));
2351 foreach ($records as $category) {
2352 context_helper::preload_from_record($category);
2353 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2354 continue;
2355 }
2356 $rv[] = $category;
2357 }
2358 return $rv;
2359}
e1d54562
MG
2360
2361/**
2362 * Returns a sorted list of categories.
2363 *
2364 * When asking for $parent='none' it will return all the categories, regardless
2365 * of depth. Wheen asking for a specific parent, the default is to return
2366 * a "shallow" resultset. Pass false to $shallow and it will return all
2367 * the child categories as well.
2368 *
2369 * @deprecated since 2.5
2370 *
2371 * This function is deprecated. Use appropriate functions from class coursecat.
2372 * Examples:
2373 *
2374 * coursecat::get($categoryid)->get_children()
2375 * - returns all children of the specified category as instances of class
0198b4a5
MG
2376 * coursecat, which means on each of them method get_children() can be called again.
2377 * Only categories visible to the current user are returned.
e1d54562 2378 *
0198b4a5
MG
2379 * coursecat::get(0)->get_children()
2380 * - returns all top-level categories visible to the current user.
e1d54562
MG
2381 *
2382 * Sort fields can be specified, see phpdocs to {@link coursecat::get_children()}
2383 *
0198b4a5
MG
2384 * coursecat::make_categories_list()
2385 * - returns an array of all categories id/names in the system.
2386 * Also only returns categories visible to current user and can additionally be
2387 * filetered by capability, see phpdocs to {@link coursecat::make_categories_list()}
2388 *
2389 * make_categories_options()
2390 * - Returns full course categories tree to be used in html_writer::select()
2391 *
e1d54562
MG
2392 * Also see functions {@link coursecat::get_children_count()}, {@link coursecat::count_all()},
2393 * {@link coursecat::get_default()}
2394 *
2395 * The code of this deprecated function is left as it is because coursecat::get_children()
0198b4a5
MG
2396 * returns categories as instances of coursecat and not stdClass. Also there is no
2397 * substitute for retrieving the category with all it's subcategories. Plugin developers
2398 * may re-use the code/queries from this function in their plugins if really necessary.
e1d54562
MG
2399 *
2400 * @param string $parent The parent category if any
2401 * @param string $sort the sortorder
2402 * @param bool $shallow - set to false to get the children too
2403 * @return array of categories
2404 */
2405function get_categories($parent='none', $sort=NULL, $shallow=true) {
2406 global $DB;
2407
0198b4a5 2408 debugging('Function get_categories() is deprecated. Please use coursecat::get_children() or see phpdocs for other alternatives',
e1d54562
MG
2409 DEBUG_DEVELOPER);
2410
2411 if ($sort === NULL) {
2412 $sort = 'ORDER BY cc.sortorder ASC';
2413 } elseif ($sort ==='') {
2414 // leave it as empty
2415 } else {
2416 $sort = "ORDER BY $sort";
2417 }
2418
2419 list($ccselect, $ccjoin) = context_instance_preload_sql('cc.id', CONTEXT_COURSECAT, 'ctx');
2420
2421 if ($parent === 'none') {
2422 $sql = "SELECT cc.* $ccselect
2423 FROM {course_categories} cc
2424 $ccjoin
2425 $sort";
2426 $params = array();
2427
2428 } elseif ($shallow) {
2429 $sql = "SELECT cc.* $ccselect
2430 FROM {course_categories} cc
2431 $ccjoin
2432 WHERE cc.parent=?
2433 $sort";
2434 $params = array($parent);
2435
2436 } else {
2437 $sql = "SELECT cc.* $ccselect
2438 FROM {course_categories} cc
2439 $ccjoin
2440 JOIN {course_categories} ccp
2441 ON ((cc.parent = ccp.id) OR (cc.path LIKE ".$DB->sql_concat('ccp.path',"'/%'")."))
2442 WHERE ccp.id=?
2443 $sort";
2444 $params = array($parent);
2445 }
2446 $categories = array();
2447
2448 $rs = $DB->get_recordset_sql($sql, $params);
2449 foreach($rs as $cat) {
db314f34 2450 context_helper::preload_from_record($cat);
e1d54562
MG
2451 $catcontext = context_coursecat::instance($cat->id);
2452 if ($cat->visible || has_capability('moodle/category:viewhiddencategories', $catcontext)) {
2453 $categories[$cat->id] = $cat;
2454 }
2455 }
2456 $rs->close();
2457 return $categories;
2458}
a8d683ca
MG
2459
2460/**
2461* Displays a course search form
2462*
2463* This function is deprecated, please use course renderer:
2464* $renderer = $PAGE->get_renderer('core', 'course');
2465* echo $renderer->course_search_form($value, $format);
2466*
2467* @deprecated since 2.5
2468*
2469* @param string $value default value to populate the search field
2470* @param bool $return if true returns the value, if false - outputs
2471* @param string $format display format - 'plain' (default), 'short' or 'navbar'
2472* @return null|string
2473*/
2474function print_course_search($value="", $return=false, $format="plain") {
2475 global $PAGE;
2476 debugging('Function print_course_search() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2477 $renderer = $PAGE->get_renderer('core', 'course');
2478 if ($return) {
2479 return $renderer->course_search_form($value, $format);
2480 } else {
2481 echo $renderer->course_search_form($value, $format);
2482 }
2483}
09ae7ee0
MG
2484
2485/**
2486 * Prints custom user information on the home page
2487 *
2488 * This function is deprecated, please use:
2489 * $renderer = $PAGE->get_renderer('core', 'course');
2490 * echo $renderer->frontpage_my_courses()
2491 *
2492 * @deprecated since 2.5
2493 */
2494function print_my_moodle() {
2495 global $PAGE;
2496 debugging('Function print_my_moodle() is deprecated, please use course renderer function frontpage_my_courses()', DEBUG_DEVELOPER);
2497
2498 $renderer = $PAGE->get_renderer('core', 'course');
2499 echo $renderer->frontpage_my_courses();
2500}
2501
2502/**
2503 * Prints information about one remote course
2504 *
2505 * This function is deprecated, it is replaced with protected function
2506 * {@link core_course_renderer::frontpage_remote_course()}
2507 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2508 *
2509 * @deprecated since 2.5
2510 */
2511function print_remote_course($course, $width="100%") {
2512 global $CFG, $USER;
2513 debugging('Function print_remote_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2514
2515 $linkcss = '';
2516
2517 $url = "{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&amp;wantsurl=/course/view.php?id={$course->remoteid}";
2518
2519 echo '<div class="coursebox remotecoursebox clearfix">';
2520 echo '<div class="info">';
2521 echo '<div class="name"><a title="'.get_string('entercourse').'"'.
2522 $linkcss.' href="'.$url.'">'
2523 . format_string($course->fullname) .'</a><br />'
2524 . format_string($course->hostname) . ' : '
2525 . format_string($course->cat_name) . ' : '
2526 . format_string($course->shortname). '</div>';
2527 echo '</div><div class="summary">';
2528 $options = new stdClass();
2529 $options->noclean = true;
2530 $options->para = false;
2531 $options->overflowdiv = true;
2532 echo format_text($course->summary, $course->summaryformat, $options);
2533 echo '</div>';
2534 echo '</div>';
2535}
2536
2537/**
2538 * Prints information about one remote host
2539 *
2540 * This function is deprecated, it is replaced with protected function
2541 * {@link core_course_renderer::frontpage_remote_host()}
2542 * It is only used from function {@link core_course_renderer::frontpage_my_courses()}
2543 *
2544 * @deprecated since 2.5
2545 */
2546function print_remote_host($host, $width="100%") {
2547 global $OUTPUT;
2548 debugging('Function print_remote_host() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2549
2550 $linkcss = '';
2551
2552 echo '<div class="coursebox clearfix">';
2553 echo '<div class="info">';
2554 echo '<div class="name">';
2555 echo '<img src="'.$OUTPUT->pix_url('i/mnethost') . '" class="icon" alt="'.get_string('course').'" />';
2556 echo '<a title="'.s($host['name']).'" href="'.s($host['url']).'">'
2557 . s($host['name']).'</a> - ';
2558 echo $host['count'] . ' ' . get_string('courses');
2559 echo '</div>';
2560 echo '</div>';
2561 echo '</div>';
2562}
2563
2564/**
2565 * Recursive function to print out all the categories in a nice format
2566 * with or without courses included
2567 *
2568 * @deprecated since 2.5
2569 *
2570 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2571 */
2572function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $showcourses = true, $categorycourses=NULL) {
2573 global $PAGE;
2574 debugging('Function print_whole_category_list() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2575
2576 $renderer = $PAGE->get_renderer('core', 'course');
2577 if ($showcourses && $category) {
2578 echo $renderer->course_category($category);
2579 } else if ($showcourses) {
2580 echo $renderer->frontpage_combo_list();
2581 } else {
2582 echo $renderer->frontpage_categories_list();
2583 }
2584}
2585
2586/**
2587 * Prints the category information.
2588 *
2589 * @deprecated since 2.5
2590 *
2591 * This function was only used by {@link print_whole_category_list()} but now
2592 * all course category rendering is moved to core_course_renderer.
2593 *
2594 * @param stdClass $category
2595 * @param int $depth The depth of the category.
2596 * @param bool $showcourses If set to true course information will also be printed.
2597 * @param array|null $courses An array of courses belonging to the category, or null if you don't have it yet.
2598 */
2599function print_category_info($category, $depth = 0, $showcourses = false, array $courses = null) {
2600 global $PAGE;
2601 debugging('Function print_category_info() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2602
2603 $renderer = $PAGE->get_renderer('core', 'course');
2604 echo $renderer->course_category($category);
2605}
2606
2607/**
2608 * This function generates a structured array of courses and categories.
2609 *
2610 * @deprecated since 2.5
2611 *
2612 * This function is not used any more in moodle core and course renderer does not have render function for it.
2613 * Combo list on the front page is displayed as:
2614 * $renderer = $PAGE->get_renderer('core', 'course');
2615 * echo $renderer->frontpage_combo_list()
2616 *
2617 * The new class {@link coursecat} stores the information about course category tree
2618 * To get children categories use:
2619 * coursecat::get($id)->get_children()
2620 * To get list of courses use:
2621 * coursecat::get($id)->get_courses()
2622 *
2623 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2624 *
2625 * @param int $id
2626 * @param int $depth
2627 */
2628function get_course_category_tree($id = 0, $depth = 0) {
2629 global $DB, $CFG;
2630 if (!$depth) {
2631 debugging('Function get_course_category_tree() is deprecated, please use course renderer or coursecat class, see function phpdocs for more info', DEBUG_DEVELOPER);
2632 }
2633
2634 $categories = array();
2635 $categoryids = array();
2636 $sql = context_helper::get_preload_record_columns_sql('ctx');
2637 $records = $DB->get_records_sql("SELECT c.*, $sql FROM {course_categories} c ".
2638 "JOIN {context} ctx on ctx.instanceid = c.id AND ctx.contextlevel = ? WHERE c.parent = ? ORDER BY c.sortorder",
2639 array(CONTEXT_COURSECAT, $id));
2640 foreach ($records as $category) {
2641 context_helper::preload_from_record($category);
2642 if (!$category->visible && !has_capability('moodle/category:viewhiddencategories', context_coursecat::instance($category->id))) {
2643 continue;
2644 }
2645 $categories[] = $category;
2646 $categoryids[$category->id] = $category;
2647 if (empty($CFG->maxcategorydepth) || $depth <= $CFG->maxcategorydepth) {
2648 list($category->categories, $subcategories) = get_course_category_tree($category->id, $depth+1);
2649 foreach ($subcategories as $subid=>$subcat) {
2650 $categoryids[$subid] = $subcat;
2651 }
2652 $category->courses = array();
2653 }
2654 }
2655
2656 if ($depth > 0) {
2657 // This is a recursive call so return the required array
2658 return array($categories, $categoryids);
2659 }
2660
2661 if (empty($categoryids)) {
2662 // No categories available (probably all hidden).
2663 return array();
2664 }
2665
2666 // The depth is 0 this function has just been called so we can finish it off
2667
2668 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
2669 list($catsql, $catparams) = $DB->get_in_or_equal(array_keys($categoryids));
2670 $sql = "SELECT
2671 c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.summary,c.category
2672 $ccselect
2673 FROM {course} c
2674 $ccjoin
2675 WHERE c.category $catsql ORDER BY c.sortorder ASC";
2676 if ($courses = $DB->get_records_sql($sql, $catparams)) {
2677 // loop throught them
2678 foreach ($courses as $course) {
2679 if ($course->id == SITEID) {
2680 continue;
2681 }
db314f34 2682 context_helper::preload_from_record($course);
09ae7ee0
MG
2683 if (!empty($course->visible) || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
2684 $categoryids[$course->category]->courses[$course->id] = $course;
2685 }
2686 }
2687 }
2688 return $categories;
2689}
2690
2691/**
2692 * Print courses in category. If category is 0 then all courses are printed.
2693 *
2694 * @deprecated since 2.5
2695 *
2696 * To print a generic list of courses use:
2697 * $renderer = $PAGE->get_renderer('core', 'course');
2698 * echo $renderer->courses_list($courses);
2699 *
2700 * To print list of all courses:
2701 * $renderer = $PAGE->get_renderer('core', 'course');
2702 * echo $renderer->frontpage_available_courses();
2703 *
2704 * To print list of courses inside category:
2705 * $renderer = $PAGE->get_renderer('core', 'course');
2706 * echo $renderer->course_category($category); // this will also print subcategories
2707 *
2708 * @param int|stdClass $category category object or id.
2709 * @return bool true if courses found and printed, else false.
2710 */
2711function print_courses($category) {
2712 global $CFG, $OUTPUT, $PAGE;
2713 require_once($CFG->libdir. '/coursecatlib.php');
2714 debugging('Function print_courses() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2715
2716 if (!is_object($category) && $category==0) {
2717 $courses = coursecat::get(0)->get_courses(array('recursive' => true, 'summary' => true, 'coursecontacts' => true));
2718 } else {
2719 $courses = coursecat::get($category->id)->get_courses(array('summary' => true, 'coursecontacts' => true));
2720 }
2721
2722 if ($courses) {
2723 $renderer = $PAGE->get_renderer('core', 'course');
2724 echo $renderer->courses_list($courses);
2725 } else {
2726 echo $OUTPUT->heading(get_string("nocoursesyet"));
2727 $context = context_system::instance();
2728 if (has_capability('moodle/course:create', $context)) {
2729 $options = array();
2730 if (!empty($category->id)) {
2731 $options['category'] = $category->id;
2732 } else {
2733 $options['category'] = $CFG->defaultrequestcategory;
2734 }
2735 echo html_writer::start_tag('div', array('class'=>'addcoursebutton'));
2736 echo $OUTPUT->single_button(new moodle_url('/course/edit.php', $options), get_string("addnewcourse"));
2737 echo html_writer::end_tag('div');
2738 return false;
2739 }
2740 }
2741 return true;
2742}
2743
2744/**
2745 * Print a description of a course, suitable for browsing in a list.
2746 *
2747 * @deprecated since 2.5
2748 *
2749 * Please use course renderer to display a course information box.
2750 * $renderer = $PAGE->get_renderer('core', 'course');
2751 * echo $renderer->courses_list($courses); // will print list of courses
2752 * echo $renderer->course_info_box($course); // will print one course wrapped in div.generalbox
2753 *
2754 * @param object $course the course object.
2755 * @param string $highlightterms Ignored in this deprecated function!
2756 */
2757function print_course($course, $highlightterms = '') {
2758 global $PAGE;
2759
2760 debugging('Function print_course() is deprecated, please use course renderer', DEBUG_DEVELOPER);
2761 $renderer = $PAGE->get_renderer('core', 'course');
2762 // Please note, correct would be to use $renderer->coursecat_coursebox() but this function is protected.
2763 // To print list of courses use $renderer->courses_list();
2764 echo $renderer->course_info_box($course);
2765}
2766
2767/**
2768 * Gets an array whose keys are category ids and whose values are arrays of courses in the corresponding category.
2769 *
2770 * @deprecated since 2.5
2771 *
2772 * This function is not used any more in moodle core and course renderer does not have render function for it.
2773 * Combo list on the front page is displayed as:
2774 * $renderer = $PAGE->get_renderer('core', 'course');
2775 * echo $renderer->frontpage_combo_list()
2776 *
2777 * The new class {@link coursecat} stores the information about course category tree
2778 * To get children categories use:
2779 * coursecat::get($id)->get_children()
2780 * To get list of courses use:
2781 * coursecat::get($id)->get_courses()
2782 *
2783 * See http://docs.moodle.org/dev/Courses_lists_upgrade_to_2.5
2784 *
2785 * @param int $categoryid
2786 * @return array
2787 */
2788function get_category_courses_array($categoryid = 0) {
2789 debugging('Function get_category_courses_array() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
2790 $tree = get_course_category_tree($categoryid);
2791 $flattened = array();
2792 foreach ($tree as $category) {
2793 get_category_courses_array_recursively($flattened, $category);
2794 }
2795 return $flattened;
2796}
2797
2798/**
2799 * Recursive function to help flatten the course category tree.
2800 *
2801 * @deprecated since 2.5
2802 *
2803 * Was intended to be called from {@link get_category_courses_array()}
2804 *
2805 * @param array &$flattened An array passed by reference in which to store courses for each category.
2806 * @param stdClass $category The category to get courses for.
2807 */
2808function get_category_courses_array_recursively(array &$flattened, $category) {
2809 debugging('Function get_category_courses_array_recursively() is deprecated, please use methods of coursecat class', DEBUG_DEVELOPER);
2810 $flattened[$category->id] = $category->courses;
2811 foreach ($category->categories as $childcategory) {
2812 get_category_courses_array_recursively($flattened, $childcategory);
2813 }
2814}
2815
7ac18cf9
AA
2816/**
2817 * Returns a URL based on the context of the current page.
2818 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
2819 *
2820 * @param stdclass $context
2821 * @deprecated since Moodle 2.5 MDL-27814 - please do not use this function any more.
2822 * @todo Remove this in 2.7
2823 * @return string
2824 */
2825function blog_get_context_url($context=null) {
2826 global $CFG;
2827
2828 debugging('Function blog_get_context_url() is deprecated, getting params from context is not reliable for blogs.', DEBUG_DEVELOPER);
2829 $viewblogentriesurl = new moodle_url('/blog/index.php');
2830
2831 if (empty($context)) {
2832 global $PAGE;
2833 $context = $PAGE->context;
2834 }
2835
2836 // Change contextlevel to SYSTEM if viewing the site course
2837 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
2838 $context = context_system::instance();
2839 }
2840
2841 $filterparam = '';
2842 $strlevel = '';
2843
2844 switch ($context->contextlevel) {
2845 case CONTEXT_SYSTEM:
2846 case CONTEXT_BLOCK:
2847 case CONTEXT_COURSECAT:
2848 break;
2849 case CONTEXT_COURSE:
2850 $filterparam = 'courseid';
2851 $strlevel = get_string('course');
2852 break;
2853 case CONTEXT_MODULE:
2854 $filterparam = 'modid';
329846f1 2855 $strlevel = $context->get_context_name();
7ac18cf9
AA
2856 break;
2857 case CONTEXT_USER:
2858 $filterparam = 'userid';
2859 $strlevel = get_string('user');
2860 break;
2861 }
2862
2863 if (!empty($filterparam)) {
2864 $viewblogentriesurl->param($filterparam, $context->instanceid);
2865 }
2866
2867 return $viewblogentriesurl;
2868}
2869
09ae7ee0
MG
2870/**
2871 * Retrieve course records with the course managers and other related records
2872 * that we need for print_course(). This allows print_courses() to do its job
2873 * in a constant number of DB queries, regardless of the number of courses,
2874 * role assignments, etc.
2875 *
2876 * The returned array is indexed on c.id, and each course will have
2877 * - $course->managers - array containing RA objects that include a $user obj
2878 * with the minimal fields needed for fullname()
2879 *
2880 * @deprecated since 2.5
2881 *
2882 * To get list of all courses with course contacts ('managers') use
2883 * coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true));
2884 *
2885 * To get list of courses inside particular category use
2886 * coursecat::get($id)->get_courses(array('coursecontacts' => true));
2887 *
2888 * Additionally you can specify sort order, offset and maximum number of courses,
2889 * see {@link coursecat::get_courses()}
2890 *
2891 * Please note that code of this function is not changed to use coursecat class because
2892 * coursecat::get_courses() returns result in slightly different format. Also note that
2893 * get_courses_wmanagers() DOES NOT check that users are enrolled in the course and
2894 * coursecat::get_courses() does.
2895 *
2896 * @global object
2897 * @global object
2898 * @global object
2899 * @uses CONTEXT_COURSE
2900 * @uses CONTEXT_SYSTEM
2901 * @uses CONTEXT_COURSECAT
2902 * @uses SITEID
2903 * @param int|string $categoryid Either the categoryid for the courses or 'all'
2904 * @param string $sort A SQL sort field and direction
2905 * @param array $fields An array of additional fields to fetch
2906 * @return array
2907 */
2908function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=array()) {
2909 /*
2910 * The plan is to
2911 *
2912 * - Grab the courses JOINed w/context
2913 *
2914 * - Grab the interesting course-manager RAs
2915 * JOINed with a base user obj and add them to each course
2916 *
2917 * So as to do all the work in 2 DB queries. The RA+user JOIN
2918 * ends up being pretty expensive if it happens over _all_
2919 * courses on a large site. (Are we surprised!?)
2920 *
2921 * So this should _never_ get called with 'all' on a large site.
2922 *
2923 */
2924 global $USER, $CFG, $DB;
2925 debugging('Function get_courses_wmanagers() is deprecated, please use coursecat::get_courses()', DEBUG_DEVELOPER);
2926
2927 $params = array();
2928 $allcats = false; // bool flag
2929 if ($categoryid === 'all') {
2930 $categoryclause = '';
2931 $allcats = true;
2932 } elseif (is_numeric($categoryid)) {
2933 $categoryclause = "c.category = :catid";
2934 $params['catid'] = $categoryid;
2935 } else {
2936 debugging("Could not recognise categoryid = $categoryid");
2937 $categoryclause = '';
2938 }
2939
2940 $basefields = array('id', 'category', 'sortorder',
2941 'shortname', 'fullname', 'idnumber',
2942 'startdate', 'visible',
2943 'newsitems', 'groupmode', 'groupmodeforce');
2944
2945 if (!is_null($fields) && is_string($fields)) {
2946 if (empty($fields)) {
2947 $fields = $basefields;
2948 } else {
2949 // turn the fields from a string to an array that
2950 // get_user_courses_bycap() will like...
2951 $fields = explode(',',$fields);
2952 $fields = array_map('trim', $fields);
2953 $fields = array_unique(array_merge($basefields, $fields));
2954 }
2955 } elseif (is_array($fields)) {
2956 $fields = array_merge($basefields,$fields);
2957 }
2958 $coursefields = 'c.' .join(',c.', $fields);
2959
2960 if (empty($sort)) {
2961 $sortstatement = "";
2962 } else {
2963 $sortstatement = "ORDER BY $sort";
2964 }
2965
2966 $where = 'WHERE c.id != ' . SITEID;
2967 if ($categoryclause !== ''){
2968 $where = "$where AND $categoryclause";
2969 }
2970
2971 // pull out all courses matching the cat
2972 list($ccselect, $ccjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
2973 $sql = "SELECT $coursefields $ccselect
2974 FROM {course} c
2975 $ccjoin
2976 $where
2977 $sortstatement";
2978
2979 $catpaths = array();
2980 $catpath = NULL;
2981 if ($courses = $DB->get_records_sql($sql, $params)) {
2982 // loop on courses materialising
2983 // the context, and prepping data to fetch the
2984 // managers efficiently later...
2985 foreach ($courses as $k => $course) {
db314f34 2986 context_helper::preload_from_record($course);
09ae7ee0
MG
2987 $coursecontext = context_course::instance($course->id);
2988 $courses[$k] = $course;
2989 $courses[$k]->managers = array();
2990 if ($allcats === false) {
2991 // single cat, so take just the first one...
2992 if ($catpath === NULL) {
2993 $catpath = preg_replace(':/\d+$:', '', $coursecontext->path);
2994 }
2995 } else {
2996 // chop off the contextid of the course itself
2997 // like dirname() does...
2998 $catpaths[] = preg_replace(':/\d+$:', '', $coursecontext->path);
2999 }
3000 }
3001 } else {
3002 return array(); // no courses!
3003 }
3004
3005 $CFG->coursecontact = trim($CFG->coursecontact);
3006 if (empty($CFG->coursecontact)) {
3007 return $courses;
3008 }
3009
3010 $managerroles = explode(',', $CFG->coursecontact);
3011 $catctxids = '';
3012 if (count($managerroles)) {
3013 if ($allcats === true) {
3014 $catpaths = array_unique($catpaths);
3015 $ctxids = array();
3016 foreach ($catpaths as $cpath) {
3017 $ctxids = array_merge($ctxids, explode('/',substr($cpath,1)));
3018 }
3019 $ctxids = array_unique($ctxids);
3020 $catctxids = implode( ',' , $ctxids);
3021 unset($catpaths);
3022 unset($cpath);
3023 } else {
3024 // take the ctx path from the first course
3025 // as all categories will be the same...
3026 $catpath = substr($catpath,1);
3027 $catpath = preg_replace(':/\d+$:','',$catpath);
3028 $catctxids = str_replace('/',',',$catpath);
3029 }
3030 if ($categoryclause !== '') {
3031 $categoryclause = "AND $categoryclause";
3032 }
3033 /*
3034 * Note: Here we use a LEFT OUTER JOIN that can
3035 * "optionally" match to avoid passing a ton of context
3036 * ids in an IN() clause. Perhaps a subselect is faster.
3037 *
3038 * In any case, this SQL is not-so-nice over large sets of
3039 * courses with no $categoryclause.
3040 *
3041 */
3042 $sql = "SELECT ctx.path, ctx.instanceid, ctx.contextlevel,
3043 r.id AS roleid, r.name AS rolename, r.shortname AS roleshortname,
3044 rn.name AS rolecoursealias, u.id AS userid, u.firstname, u.lastname
3045 FROM {role_assignments} ra
3046 JOIN {context} ctx ON ra.contextid = ctx.id
3047 JOIN {user} u ON ra.userid = u.id
3048 JOIN {role} r ON ra.roleid = r.id
3049 LEFT JOIN {role_names} rn ON (rn.contextid = ctx.id AND rn.roleid = r.id)
3050 LEFT OUTER JOIN {course} c
3051 ON (ctx.instanceid=c.id AND ctx.contextlevel=".CONTEXT_COURSE.")
3052 WHERE ( c.id IS NOT NULL";
3053 // under certain conditions, $catctxids is NULL
3054 if($catctxids == NULL){
3055 $sql .= ") ";
3056 }else{
3057 $sql .= " OR ra.contextid IN ($catctxids) )";
3058 }
3059
3060 $sql .= "AND ra.roleid IN ({$CFG->coursecontact})
3061 $categoryclause
3062 ORDER BY r.sortorder ASC, ctx.contextlevel ASC, ra.sortorder ASC";
3063 $rs = $DB->get_recordset_sql($sql, $params);
3064
3065 // This loop is fairly stupid as it stands - might get better
3066 // results doing an initial pass clustering RAs by path.
3067 foreach($rs as $ra) {
3068 $user = new stdClass;
3069 $user->id = $ra->userid; unset($ra->userid);
3070 $user->firstname = $ra->firstname; unset($ra->firstname);
3071 $user->lastname = $ra->lastname; unset($ra->lastname);
3072 $ra->user = $user;
3073 if ($ra->contextlevel == CONTEXT_SYSTEM) {
3074 foreach ($courses as $k => $course) {
3075 $courses[$k]->managers[] = $ra;
3076 }
3077 } else if ($ra->contextlevel == CONTEXT_COURSECAT) {
3078 if ($allcats === false) {
3079 // It always applies
3080 foreach ($courses as $k => $course) {
3081 $courses[$k]->managers[] = $ra;
3082 }
3083 } else {
3084 foreach ($courses as $k => $course) {
3085 $coursecontext = context_course::instance($course->id);
3086 // Note that strpos() returns 0 as "matched at pos 0"
3087 if (strpos($coursecontext->path, $ra->path.'/') === 0) {
3088 // Only add it to subpaths
3089 $courses[$k]->managers[] = $ra;
3090 }
3091 }
3092 }
3093 } else { // course-level
3094 if (!array_key_exists($ra->instanceid, $courses)) {
3095 //this course is not in a list, probably a frontpage course
3096 continue;
3097 }
3098 $courses[$ra->instanceid]->managers[] = $ra;
3099 }
3100 }
3101 $rs->close();
3102 }
3103
3104 return $courses;
3105}
c269b9d1
MG
3106
3107/**
3108 * Converts a nested array tree into HTML ul:li [recursive]
3109 *
3110 * @deprecated since 2.5
3111 *
3112 * @param array $tree A tree array to convert
3113 * @param int $row Used in identifying the iteration level and in ul classes
3114 * @return string HTML structure
3115 */
3116function convert_tree_to_html($tree, $row=0) {
3117 debugging('Function convert_tree_to_html() is deprecated since Moodle 2.5. Consider using class tabtree and core_renderer::render_tabtree()', DEBUG_DEVELOPER);
3118
3119 $str = "\n".'<ul class="tabrow'.$row.'">'."\n";
3120
3121 $first = true;
3122 $count = count($tree);
3123
3124 foreach ($tree as $tab) {
3125 $count--; // countdown to zero
3126
3127 $liclass = '';
3128
3129 if ($first && ($count == 0)) { // Just one in the row
3130 $liclass = 'first last';
3131 $first = false;
3132 } else if ($first) {
3133 $liclass = 'first';
3134 $first = false;
3135 } else if ($count == 0) {
3136 $liclass = 'last';
3137 }
3138
3139 if ((empty($tab->subtree)) && (!empty($tab->selected))) {
3140 $liclass .= (empty($liclass)) ? 'onerow' : ' onerow';
3141 }
3142
3143 if ($tab->inactive || $tab->active || $tab->selected) {
3144 if ($tab->selected) {
3145 $liclass .= (empty($liclass)) ? 'here selected' : ' here selected';
3146 } else if ($tab->active) {
3147 $liclass .= (empty($liclass)) ? 'here active' : ' here active';
3148 }
3149 }
3150
3151 $str .= (!empty($liclass)) ? '<li class="'.$liclass.'">' : '<li>';
3152
3153 if ($tab->inactive || $tab->active || ($tab->selected && !$tab->linkedwhenselected)) {
3154 // The a tag is used for styling
3155 $str .= '<a class="nolink"><span>'.$tab->text.'</span></a>';
3156 } else {
3157 $str .= '<a href="'.$tab->link.'" title="'.$tab->title.'"><span>'.$tab->text.'</span></a>';
3158 }
3159
3160 if (!empty($tab->subtree)) {
3161 $str .= convert_tree_to_html($tab->subtree, $row+1);
3162 } else if ($tab->selected) {
3163 $str .= '<div class="tabrow'.($row+1).' empty">&nbsp;</div>'."\n";
3164 }
3165
3166 $str .= ' </li>'."\n";
3167 }
3168 $str .= '</ul>'."\n";
3169
3170 return $str;
3171}
3172
3173/**
3174 * Convert nested tabrows to a nested array
3175 *
3176 * @deprecated since 2.5
3177 *
3178 * @param array $tabrows A [nested] array of tab row objects
3179 * @param string $selected The tabrow to select (by id)
3180 * @param array $inactive An array of tabrow id's to make inactive
3181 * @param array $activated An array of tabrow id's to make active
3182 * @return array The nested array
3183 */
3184function convert_tabrows_to_tree($tabrows, $selected, $inactive, $activated) {
3185
3186 debugging('Function convert_tabrows_to_tree() is deprecated since Moodle 2.5. Consider using class tabtree', DEBUG_DEVELOPER);
c269b9d1 3187
3d7414b3 3188 // Work backwards through the rows (bottom to top) collecting the tree as we go.
c269b9d1
MG
3189 $tabrows = array_reverse($tabrows);
3190
3191 $subtree = array();
3192
3193 foreach ($tabrows as $row) {
3194 $tree = array();
3195
3196 foreach ($row as $tab) {
3197 $tab->inactive = in_array((string)$tab->id, $inactive);
3198 $tab->active = in_array((string)$tab->id, $activated);
3199 $tab->selected = (string)$tab->id == $selected;
3200
3201 if ($tab->active || $tab->selected) {
3202 if ($subtree) {
3203 $tab->subtree = $subtree;
3204 }
3205 }
3206 $tree[] = $tab;
3207 }
3208 $subtree = $tree;
3209 }
3210
3211 return $subtree;
3212}
9052fc44 3213
8ef3a222
DP
3214/**
3215 * Can handle rotated text. Whether it is safe to use the trickery in textrotate.js.
3216 *
3217 * @deprecated since 2.5 - do not use, the textrotate.js will work it out automatically
3218 * @return bool True for yes, false for no
3219 */
3220function can_use_rotated_text() {
3221 debugging('can_use_rotated_text() is deprecated since Moodle 2.5. JS feature detection is used automatically.', DEBUG_DEVELOPER);
3222 return true;
3223}
61a0299a
AA
3224
3225/**
3226 * Get the context instance as an object. This function will create the
3227 * context instance if it does not exist yet.
3228 *
3229 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
3230 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
3231 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
3232 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
3233 * for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
3234 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
3235 * MUST_EXIST means throw exception if no record or multiple records found
3236 * @return context The context object.
3237 */
3238function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {
3239
1b80060f 3240 debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);
61a0299a
AA
3241
3242 $instances = (array)$instance;
3243 $contexts = array();
3244
3245 $classname = context_helper::get_class_for_level($contextlevel);
3246
3247 // we do not load multiple contexts any more, PAGE should be responsible for any preloading
3248 foreach ($instances as $inst) {
3249 $contexts[$inst] = $classname::instance($inst, $strictness);
3250 }
3251
3252 if (is_array($instance)) {
3253 return $contexts;
3254 } else {
3255 return $contexts[$instance];
3256 }
3257}
7b2ca655 3258
ce2b2150
RT
3259/**
3260 * Get a context instance as an object, from a given context id.
3261 *
3262 * @deprecated since Moodle 2.2 MDL-35009 - please do not use this function any more.
ce2b2150 3263 * @see context::instance_by_id($id)
ce2b2150
RT
3264 */
3265function get_context_instance_by_id($id, $strictness = IGNORE_MISSING) {
f9b7be4f 3266 throw new coding_exception('get_context_instance_by_id() is now removed, please use context::instance_by_id($id) instead.');
ce2b2150 3267}
85b2e46f 3268
492ba9de
AA
3269/**
3270 * Returns system context or null if can not be created yet.
3271 *
3272 * @see context_system::instance()
01546175 3273 * @deprecated since 2.2
492ba9de
AA
3274 * @param bool $cache use caching
3275 * @return context system context (null if context table not created yet)
3276 */
3277function get_system_context($cache = true) {
3278 debugging('get_system_context() is deprecated, please use context_system::instance() instead.', DEBUG_DEVELOPER);
3279 return context_system::instance(0, IGNORE_MISSING, $cache);
3280}
8e8891b7
FM
3281
3282/**
3283 * Recursive function which, given a context, find all parent context ids,
3284 * and return the array in reverse order, i.e. parent first, then grand
3285 * parent, etc.
3286 *
3287 * @see context::get_parent_context_ids()
3288 * @deprecated since 2.2, use $context->get_parent_context_ids() instead
3289 * @param context $context
3290 * @param bool $includeself optional, defaults to false
3291 * @return array
3292 */
3293function get_parent_contexts(context $context, $includeself = false) {
3294 debugging('get_parent_contexts() is deprecated, please use $context->get_parent_context_ids() instead.', DEBUG_DEVELOPER);
3295 return $context->get_parent_context_ids($includeself);
3296}
766fd0d9
AD
3297
3298/**
7f5b51c4
RT
3299 * Return the id of the parent of this context, or false if there is no parent (only happens if this
3300 * is the site context.)
3301 *
3302 * @deprecated since Moodle 2.2
3303 * @see context::get_parent_context()
3304 * @param context $context
3305 * @return integer the id of the parent context.
766fd0d9 3306 */
7f5b51c4
RT
3307function get_parent_contextid(context $context) {
3308 debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
3309
3310 if ($parent = $context->get_parent_context()) {
3311 return $parent->id;
3312 } else {
3313 return false;
3314 }
766fd0d9 3315}
f9aa8016
FM
3316
3317/**
3318 * Recursive function which, given a context, find all its children contexts.
3319 *
3320 * For course category contexts it will return immediate children only categories and courses.
3321 * It will NOT recurse into courses or child categories.
3322 * If you want to do that, call it on the returned courses/categories.
3323 *
3324 * When called for a course context, it will return the modules and blocks
3325 * displayed in the course page.
3326 *
3327 * If called on a user/course/module context it _will_ populate the cache with the appropriate
3328 * contexts ;-)
3329 *
3330 * @see context::get_child_contexts()
3331 * @deprecated since 2.2
3332 * @param context $context
3333 * @return array Array of child records
3334 */
3335function get_child_contexts(context $context) {
3336 debugging('get_child_contexts() is deprecated, please use $context->get_child_contexts() instead.', DEBUG_DEVELOPER);
3337 return $context->get_child_contexts();
3338}
9fdbf620
FM
3339
3340/**
3341 * Precreates all contexts including all parents.
3342 *
3343 * @see context_helper::create_instances()
3344 * @deprecated since 2.2
3345 * @param int $contextlevel empty means all
3346 * @param bool $buildpaths update paths and depths
3347 * @return void
3348 */
3349function create_contexts($contextlevel = null, $buildpaths = true) {
3350 debugging('create_contexts() is deprecated, please use context_helper::create_instances() instead.', DEBUG_DEVELOPER);
3351 context_helper::create_instances($contextlevel, $buildpaths);
3352}
84378a57
FM
3353
3354/**
3355 * Remove stale context records.
3356 *
3357 * @see context_helper::cleanup_instances()
3358 * @deprecated since 2.2
3359 * @return bool
3360 */
3361function cleanup_contexts() {
3362 debugging('cleanup_contexts() is deprecated, please use context_helper::cleanup_instances() instead.', DEBUG_DEVELOPER);
3363 context_helper::cleanup_instances();
3364 return true;
3365}
79f6b384
FM
3366
3367/**
3368 * Populate context.path and context.depth where missing.
3369 *
3370 * @see context_helper::build_all_paths()
3371 * @deprecated since 2.2
3372 * @param bool $force force a complete rebuild of the path and depth fields, defaults to false
3373 * @return void
3374 */
3375function build_context_path($force = false) {
3376 debugging('build_context_path() is deprecated, please use context_helper::build_all_paths() instead.', DEBUG_DEVELOPER);
3377 context_helper::build_all_paths($force);
3378}
cc4de415
FM
3379
3380/**
3381 * Rebuild all related context depth and path caches.
3382 *
3383 * @see context::reset_paths()
3384 * @deprecated since 2.2
3385 * @param array $fixcontexts array of contexts, strongtyped
3386 * @return void
3387 */
3388function rebuild_contexts(array $fixcontexts) {
3389 debugging('rebuild_contexts() is deprecated, please use $context->reset_paths(true) instead.', DEBUG_DEVELOPER);
3390 foreach ($fixcontexts as $fixcontext) {
3391 $fixcontext->reset_paths(false);
3392 }
3393 context_helper::build_all_paths(false);
3394}
8f7d3d12
RT
3395
3396/**
3397 * Preloads all contexts relating to a course: course, modules. Block contexts
3398 * are no longer loaded here. The contexts for all the blocks on the current
3399 * page are now efficiently loaded by {@link block_manager::load_blocks()}.
3400 *
3401 * @deprecated since Moodle 2.2
3402 * @see context_helper::preload_course()
3403 * @param int $courseid Course ID
3404 * @return void
3405 */
3406function preload_course_contexts($courseid) {
3407 debugging('preload_course_contexts() is deprecated, please use context_helper::preload_course() instead.', DEBUG_DEVELOPER);
3408 context_helper::preload_course($courseid);
3409}
2c5b0eb7
RT
3410
3411/**
3412 * Update the path field of the context and all dep. subcontexts that follow
3413 *
3414 * Update the path field of the context and
3415 * all the dependent subcontexts that follow
3416 * the move.
3417 *
3418 * The most important thing here is to be as
3419 * DB efficient as possible. This op can have a
3420 * massive impact in the DB.
3421 *
3422 * @deprecated since Moodle 2.2
3423 * @see context::update_moved()
3424 * @param context $context context obj
3425 * @param context $newparent new parent obj
3426 * @return void
3427 */
3428function context_moved(context $context, context $newparent) {
3429 debugging('context_moved() is deprecated, please use context::update_moved() instead.', DEBUG_DEVELOPER);
3430 $context->update_moved($newparent);
c5dcd25d
AA
3431}
3432
a439b2f9
FM
3433/**
3434 * Extracts the relevant capabilities given a contextid.
3435 * All case based, example an instance of forum context.
3436 * Will fetch all forum related capabilities, while course contexts
3437 * Will fetch all capabilities
3438 *
3439 * capabilities
3440 * `name` varchar(150) NOT NULL,
3441 * `captype` varchar(50) NOT NULL,
3442 * `contextlevel` int(10) NOT NULL,
3443 * `component` varchar(100) NOT NULL,
3444 *
3445 * @see context::get_capabilities()
3446 * @deprecated since 2.2
3447 * @param context $context
3448 * @return array
3449 */
3450function fetch_context_capabilities(context $context) {
3451 debugging('fetch_context_capabilities() is deprecated, please use $context->get_capabilities() instead.', DEBUG_DEVELOPER);
3452 return $context->get_capabilities();
3453}
3454
c5dcd25d
AA
3455/**
3456 * Preloads context information from db record and strips the cached info.
3457 * The db request has to contain both the $join and $select from context_instance_preload_sql()
3458 *
3459 * @deprecated since 2.2
3460 * @see context_helper::preload_from_record()
3461 * @param stdClass $rec
3462 * @return void (modifies $rec)
3463 */
3464function context_instance_preload(stdClass $rec) {
3465 debugging('context_instance_preload() is deprecated, please use context_helper::preload_from_record() instead.', DEBUG_DEVELOPER);
3466 context_helper::preload_from_record($rec);
3467}
b4482dfe
AG
3468
3469/**
3470 * Returns context level name
3471 *
3472 * @deprecated since 2.2
3473 * @see context_helper::get_level_name()
3474 * @param integer $contextlevel $context->context level. One of the CONTEXT_... constants.
3475 * @return string the name for this type of context.
3476 */
3477function get_contextlevel_name($contextlevel) {
3478 debugging('get_contextlevel_name() is deprecated, please use context_helper::get_level_name() instead.', DEBUG_DEVELOPER);
3479 return context_helper::get_level_name($contextlevel);
3480}
329846f1
AG
3481
3482/**
3483 * Prints human readable context identifier.
3484 *
3485 * @deprecated since 2.2
3486 * @see context::get_context_name()
3487 * @param context $context the context.
3488 * @param boolean $withprefix whether to prefix the name of the context with the
3489 * type of context, e.g. User, Course, Forum, etc.
3490 * @param boolean $short whether to user the short name of the thing. Only applies
3491 * to course contexts
3492 * @return string the human readable context name.
3493 */
3494function print_context_name(context $context, $withprefix = true, $short = false) {
3495 debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER);
3496 return $context->get_context_name($withprefix, $short);
3497}
1de02d62
AG
3498
3499/**
3500 * Mark a context as dirty (with timestamp) so as to force reloading of the context.
3501 *
3502 * @deprecated since 2.2, use $context->mark_dirty() instead
3503 * @see context::mark_dirty()
3504 * @param string $path context path
3505 */
3506function mark_context_dirty($path) {
3507 global $CFG, $USER, $ACCESSLIB_PRIVATE;
3508 debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER);
3509
3510 if (during_initial_install()) {
3511 return;
3512 }
3513
3514 // only if it is a non-empty string
3515 if (is_string($path) && $path !== '') {
3516 set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout);
3517 if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) {
3518 $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1;
3519 } else {
3520 if (CLI_SCRIPT) {
3521 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3522 } else {
3523 if (isset($USER->access['time'])) {
3524 $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2);
3525 } else {
3526 $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1);
3527 }
3528 // flags not loaded yet, it will be done later in $context->reload_if_dirty()
3529 }
3530 }
3531 }
3532}
c592eea2
RT
3533
3534/**
3535 * Remove a context record and any dependent entries,
3536 * removes context from static context cache too
3537 *
3538 * @deprecated since Moodle 2.2
3539 * @see context_helper::delete_instance() or context::delete_content()
3540 * @param int $contextlevel
3541 * @param int $instanceid
3542 * @param bool $deleterecord false means keep record for now
3543 * @return bool returns true or throws an exception
3544 */
3545function delete_context($contextlevel, $instanceid, $deleterecord = true) {
3546 if ($deleterecord) {
3547 debugging('delete_context() is deprecated, please use context_helper::delete_instance() instead.', DEBUG_DEVELOPER);
3548 context_helper::delete_instance($contextlevel, $instanceid);
3549 } else {
3550 debugging('delete_context() is deprecated, please use $context->delete_content() instead.', DEBUG_DEVELOPER);
3551 $classname = context_helper::get_class_for_level($contextlevel);
3552 if ($context = $classname::instance($instanceid, IGNORE_MISSING)) {
3553 $context->delete_content();
3554 }
3555 }
3556
3557 return true;
3558}
6c89d4e1
MN
3559
3560/**
3561 * Get a URL for a context, if there is a natural one. For example, for
3562 * CONTEXT_COURSE, this is the course page. For CONTEXT_USER it is the
3563 * user profile page.
3564 *
3565 * @deprecated since 2.2
3566 * @see context::get_url()
3567 * @param context $context the context
3568 * @return moodle_url
3569 */
3570function get_context_url(context $context) {
3571 debugging('get_context_url() is deprecated, please use $context->get_url() instead.', DEBUG_DEVELOPER);
3572 return $context->get_url();
3573}
3574
dd33f4af
MN
3575/**
3576 * Is this context part of any course? if yes return course context,
3577 * if not return null or throw exception.
3578 *
3579 * @deprecated since 2.2
3580 * @see context::get_course_context()
3581 * @param context $context
aa386d29 3582 * @return context_course context of the enclosing course, null if not found or exception
dd33f4af
MN
3583 */
3584function get_course_context(context $context) {
3585 debugging('get_course_context() is deprecated, please use $context->get_course_context(true) instead.', DEBUG_DEVELOPER);
3586 return $context->get_course_context(true);
3587}
6acc54b3
AA
3588
3589/**
3590 * Get an array of courses where cap requested is available
3591 * and user is enrolled, this can be relatively slow.
3592 *
3593 * @deprecated since 2.2
3594 * @see enrol_get_users_courses()
3595 * @param int $userid A user id. By default (null) checks the permissions of the current user.
3596 * @param string $cap - name of the capability
3597 * @param array $accessdata_ignored
3598 * @param bool $doanything_ignored
3599 * @param string $sort - sorting fields - prefix each fieldname with "c."
3600 * @param array $fields - additional fields you are interested in...
3601 * @param int $limit_ignored
3602 * @return array $courses - ordered array of course objects - see notes above
3603 */
3604function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_ignored, $sort = 'c.sortorder ASC', $fields = null, $limit_ignored = 0) {
3605
3606 debugging('get_user_courses_bycap() is deprecated, please use enrol_get_users_courses() instead.', DEBUG_DEVELOPER);
3607 $courses = enrol_get_users_courses($userid, true, $fields, $sort);
3608 foreach ($courses as $id=>$course) {
3609 $context = context_course::instance($id);
3610 if (!has_capability($cap, $context, $userid)) {
3611 unset($courses[$id]);
3612 }
3613 }
3614
3615 return $courses;
3616}
ae38dcb1
RT
3617
3618/**
3619 * This is really slow!!! do not use above course context level
3620 *
3621 * @deprecated since Moodle 2.2
3622 * @param int $roleid
3623 * @param context $context
3624 * @return array
3625 */
3626function get_role_context_caps($roleid, context $context) {
3627 global $DB;
3628 debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
3629
3630 // This is really slow!!!! - do not use above course context level.
3631 $result = array();
3632 $result[$context->id] = array();
3633
3634 // First emulate the parent context capabilities merging into context.
3635 $searchcontexts = array_reverse($context->get_parent_context_ids(true));
3636 foreach ($searchcontexts as $cid) {
3637 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
3638 foreach ($capabilities as $cap) {
3639 if (!array_key_exists($cap->capability, $result[$context->id])) {
3640 $result[$context->id][$cap->capability] = 0;
3641 }
3642 $result[$context->id][$cap->capability] += $cap->permission;
3643 }
3644 }
3645 }
3646
3647 // Now go through the contexts below given context.
3648 $searchcontexts = array_keys($context->get_child_contexts());
3649 foreach ($searchcontexts as $cid) {
3650 if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
3651 foreach ($capabilities as $cap) {
3652 if (!array_key_exists($cap->contextid, $result)) {
3653 $result[$cap->contextid] = array();
3654 }
3655 $result[$cap->contextid][$cap->capability] = $cap->permission;
3656 }
3657 }
3658 }
3659
3660 return $result;
3661}
b123a543
FM
3662
3663/**
3664 * Returns current course id or false if outside of course based on context parameter.
3665 *
3666 * @see context::get_course_context()
3667 * @deprecated since 2.2
3668 * @param context $context
3669 * @return int|bool related course id or false
3670 */
3671function get_courseid_from_context(context $context) {
3672 debugging('get_courseid_from_context() is deprecated, please use $context->get_course_context(false) instead.', DEBUG_DEVELOPER);
3673 if ($coursecontext = $context->get_course_context(false)) {
3674 return $coursecontext->instanceid;
3675 } else {
3676 return false;
3677 }
6a30b48d 3678}
2e4c0c91
FM
3679
3680/**
3681 * Preloads context information together with instances.
3682 * Use context_instance_preload() to strip the context info from the record and cache the context instance.
3683 *
3684 * If you are using this methid, you should have something like this:
3685 *
3686 * list($ctxselect, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
3687 *
3688 * To prevent the use of this deprecated function, replace the line above with something similar to this:
3689 *
3690 * $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
3691 * ^
3692 * $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
3693 * ^ ^ ^ ^
3694 * $params = array('contextlevel' => CONTEXT_COURSE);
3695 * ^
3696 * @see context_helper:;get_preload_record_columns_sql()
3697 * @deprecated since 2.2
3698 * @param string $joinon for example 'u.id'
3699 * @param string $contextlevel context level of instance in $joinon
3700 * @param string $tablealias context table alias
3701 * @return array with two values - select and join part
3702 */
3703function context_instance_preload_sql($joinon, $contextlevel, $tablealias) {
3704 debugging('context_instance_preload_sql() is deprecated, please use context_helper::get_preload_record_columns_sql() instead.', DEBUG_DEVELOPER);
3705 $select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
3706 $join = "LEFT JOIN {context} $tablealias ON ($tablealias.instanceid = $joinon AND $tablealias.contextlevel = $contextlevel)";
3707 return array($select, $join);
b123a543 3708}
b6452844
MN
3709
3710/**
3711 * Gets a string for sql calls, searching for stuff in this context or above.
3712 *
3713 * @deprecated since 2.2
3714 * @see context::get_parent_context_ids()
3715 * @param context $context
3716 * @return string
3717 */
3718function get_related_contexts_string(context $context) {
3719 debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
3720 if ($parents = $context->get_parent_context_ids()) {
3721 return (' IN ('.$context->id.','.implode(',', $parents).')');
3722 } else {
3723 return (' ='.$context->id);
3724 }
3725}
0142523d 3726
d0cac8b5
FM
3727/**
3728 * Get a list of all the plugins of a given type that contain a particular file.
3729 *
3730 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
3731 * @param string $file the name of file that must be present in the plugin.
3732 * (e.g. 'view.php', 'db/install.xml').
3733 * @param bool $include if true (default false), the file will be include_once-ed if found.
3734 * @return array with plugin name as keys (e.g. 'forum', 'courselist') and the path
3735 * to the file relative to dirroot as value (e.g. "$CFG->dirroot/mod/forum/view.php").
3736 * @deprecated since 2.6
3737 * @see core_component::get_plugin_list_with_file()
3738 */
3739function get_plugin_list_with_file($plugintype, $file, $include = false) {
3740 debugging('get_plugin_list_with_file() is deprecated, please use core_component::get_plugin_list_with_file() instead.',
3741 DEBUG_DEVELOPER);
3742 return core_component::get_plugin_list_with_file($plugintype, $file, $include);
3743}
c3d2fbf9
SH
3744
3745/**
3746 * Checks to see if is the browser operating system matches the specified brand.
3747 *
3748 * Known brand: 'Windows','Linux','Macintosh','SGI','SunOS','HP-UX'
3749 *
3750 * @deprecated since 2.6
3751 * @param string $brand The operating system identifier being tested
3752 * @return bool true if the given brand below to the detected operating system
3753 */
3754function check_browser_operating_system($brand) {
3755 debugging('check_browser_operating_system has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3756 return core_useragent::check_browser_operating_system($brand);
3757}
3758
3759/**
3760 * Checks to see if is a browser matches the specified
3761 * brand and is equal or better version.
3762 *
3763 * @deprecated since 2.6
3764 * @param string $brand The browser identifier being tested
3765 * @param int $version The version of the browser, if not specified any version (except 5.5 for IE for BC reasons)
3766 * @return bool true if the given version is below that of the detected browser
3767 */
3768function check_browser_version($brand, $version = null) {
3769 debugging('check_browser_version has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3770 return core_useragent::check_browser_version($brand, $version);
3771}
3772
3773/**
3774 * Returns whether a device/browser combination is mobile, tablet, legacy, default or the result of
3775 * an optional admin specified regular expression. If enabledevicedetection is set to no or not set
3776 * it returns default
3777 *
3778 * @deprecated since 2.6
3779 * @return string device type
3780 */
3781function get_device_type() {
3782 debugging('get_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3783 return core_useragent::get_device_type();
3784}
3785
3786/**
3787 * Returns a list of the device types supporting by Moodle
3788 *
3789 * @deprecated since 2.6
3790 * @param boolean $incusertypes includes types specified using the devicedetectregex admin setting
3791 * @return array $types
3792 */
3793function get_device_type_list($incusertypes = true) {
3794 debugging('get_device_type_list has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3795 return core_useragent::get_device_type_list($incusertypes);
3796}
3797
3798/**
3799 * Returns the theme selected for a particular device or false if none selected.
3800 *
3801 * @deprecated since 2.6
3802 * @param string $devicetype
3803 * @return string|false The name of the theme to use for the device or the false if not set
3804 */
3805function get_selected_theme_for_device_type($devicetype = null) {
3806 debugging('get_selected_theme_for_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3807 return core_useragent::get_device_type_theme($devicetype);
3808}
3809
3810/**
3811 * Returns the name of the device type theme var in $CFG because there is not a convention to allow backwards compatibility.
3812 *
3813 * @deprecated since 2.6
3814 * @param string $devicetype
3815 * @return string The config variable to use to determine the theme
3816 */
3817function get_device_cfg_var_name($devicetype = null) {
3818 debugging('get_device_cfg_var_name has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3819 return core_useragent::get_device_type_cfg_var_name($devicetype);
3820}
3821
3822/**
3823 * Allows the user to switch the device they are seeing the theme for.
3824 * This allows mobile users to switch back to the default theme, or theme for any other device.
3825 *
3826 * @deprecated since 2.6
3827 * @param string $newdevice The device the user is currently using.
3828 * @return string The device the user has switched to
3829 */
3830function set_user_device_type($newdevice) {
3831 debugging('set_user_device_type has been deprecated, please update your code to use core_useragent instead.', DEBUG_DEVELOPER);
3832 return core_useragent::set_user_device_type($newdevice);
3833}
3834
3835/**
3836 * Returns the device the user is currently using, or if the user has chosen to switch devices
3837 * for the current device type the type th