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