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