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