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