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