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