scales: Fix initialisation order problem.
[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 *
c861fe2f 116 * @global object
117 * @uses CONTEXT_SYSTEM
c4d0753b 118 * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
119 * @return bool
120 */
121function isguest($userid=0) {
c2da0757 122 global $CFG;
c4d0753b 123
364fffda 124 $context = get_context_instance(CONTEXT_SYSTEM);
c4d0753b 125
c2da0757 126 return has_capability('moodle/legacy:guest', $context, $userid, false);
c4d0753b 127}
128
613bbd7c 129
130/**
131 * Get the guest user information from the database
132 *
a5cb8d69 133 * @todo Is object(user) a correct return type? Or is array the proper return type with a
c861fe2f 134 * note that the contents include all details for a user.
135 *
613bbd7c 136 * @return object(user) An associative array with the details of the guest user account.
613bbd7c 137 */
138function get_guest() {
139 return get_complete_user_data('username', 'guest');
140}
141
613bbd7c 142/**
143 * Returns $user object of the main teacher for a course
144 *
c861fe2f 145 * @global object
146 * @uses CONTEXT_COURSE
613bbd7c 147 * @param int $courseid The course in question.
148 * @return user|false A {@link $USER} record of the main teacher for the specified course or false if error.
613bbd7c 149 */
150function get_teacher($courseid) {
151
152 global $CFG;
153
888fb649 154 $context = get_context_instance(CONTEXT_COURSE, $courseid);
155
1113f800 156 // Pass $view=true to filter hidden caps if the user cannot see them
157 if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC',
158 '', '', '', '', false, true)) {
b1469317 159 $users = sort_by_roleassignment_authority($users, $context);
1113f800 160 return array_shift($users);
613bbd7c 161 }
888fb649 162
163 return false;
613bbd7c 164}
165
166/**
167 * Searches logs to find all enrolments since a certain date
168 *
169 * used to print recent activity
170 *
c861fe2f 171 * @global object
172 * @uses CONTEXT_COURSE
613bbd7c 173 * @param int $courseid The course in question.
c861fe2f 174 * @param int $timestart The date to check forward of
613bbd7c 175 * @return object|false {@link $USER} records or false if error.
613bbd7c 176 */
177function get_recent_enrolments($courseid, $timestart) {
10df888a 178 global $DB;
364fffda 179
71dea306 180 $context = get_context_instance(CONTEXT_COURSE, $courseid);
613bbd7c 181
10df888a 182 $sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, l.time
183 FROM {user} u, {role_assignments} ra, {log} l
184 WHERE l.time > ?
185 AND l.course = ?
186 AND l.module = 'course'
187 AND l.action = 'enrol'
9f43d70d 188 AND ".$DB->sql_cast_char2int('l.info')." = u.id
10df888a 189 AND u.id = ra.userid
190 AND ra.contextid ".get_related_contexts_string($context)."
191 ORDER BY l.time ASC";
192 $params = array($timestart, $courseid);
193 return $DB->get_records_sql($sql, $params);
613bbd7c 194}
195
2123b644 196########### FROM weblib.php ##########################################################################
197
198
199/**
200 * Print a message in a standard themed box.
364fffda 201 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
2123b644 202 * parameters remain. If possible, $align, $width and $color should not be defined at all.
203 * Preferably just use print_box() in weblib.php
204 *
34a2777c 205 * @deprecated
c861fe2f 206 * @param string $message The message to display
207 * @param string $align alignment of the box, not the text (default center, left, right).
208 * @param string $width width of the box, including units %, for example '100%'.
209 * @param string $color background colour of the box, for example '#eee'.
210 * @param int $padding padding in pixels, specified without units.
211 * @param string $class space-separated class names.
212 * @param string $id space-separated id names.
213 * @param boolean $return return as string or just print it
214 * @return string|void Depending on $return
2123b644 215 */
216function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
217 $output = '';
218 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
294ce987 219 $output .= $message;
2123b644 220 $output .= print_simple_box_end(true);
221
222 if ($return) {
223 return $output;
224 } else {
225 echo $output;
226 }
227}
228
229
230
231/**
364fffda 232 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
2123b644 233 * parameters remain. If possible, $align, $width and $color should not be defined at all.
234 * Even better, please use print_box_start() in weblib.php
235 *
c861fe2f 236 * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
237 * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
238 * @param string $color background colour of the box, for example '#eee'. DEPRECATED
239 * @param int $padding padding in pixels, specified without units. OBSOLETE
240 * @param string $class space-separated class names.
241 * @param string $id space-separated id names.
242 * @param boolean $return return as string or just print it
243 * @return string|void Depending on $return
2123b644 244 */
245function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
600313b9 246 debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
2123b644 247
248 $output = '';
249
8f36e33e 250 $divclasses = 'box '.$class.' '.$class.'content';
2123b644 251 $divstyles = '';
252
253 if ($align) {
254 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
255 }
256 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
8f36e33e 257 if (substr($width, -1, 1) == '%') { // Width is a % value
258 $width = (int) substr($width, 0, -1); // Extract just the number
259 if ($width < 40) {
260 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
261 } else if ($width > 60) {
262 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
263 } else {
264 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
265 }
266 } else {
267 $divstyles .= ' width:'.$width.';'; // Last resort
268 }
2123b644 269 }
270 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
271 $divstyles .= ' background:'.$color.';';
272 }
273 if ($divstyles) {
274 $divstyles = ' style="'.$divstyles.'"';
275 }
276
277 if ($id) {
278 $id = ' id="'.$id.'"';
279 }
280
281 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
282
283 if ($return) {
284 return $output;
285 } else {
286 echo $output;
287 }
288}
289
290
291/**
292 * Print the end portion of a standard themed box.
293 * Preferably just use print_box_end() in weblib.php
c861fe2f 294 *
295 * @param boolean $return return as string or just print it
296 * @return string|void Depending on $return
2123b644 297 */
298function print_simple_box_end($return=false) {
299 $output = '</div>';
300 if ($return) {
301 return $output;
302 } else {
303 echo $output;
304 }
305}
306
ed5dd29f 307/**
308 * deprecated - use clean_param($string, PARAM_FILE); instead
309 * Check for bad characters ?
310 *
c861fe2f 311 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
312 *
ed5dd29f 313 * @param string $string ?
314 * @param int $allowdots ?
c861fe2f 315 * @return bool
ed5dd29f 316 */
317function detect_munged_arguments($string, $allowdots=1) {
318 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
319 return true;
320 }
321 if (ereg('[\|\`]', $string)) { // check for other bad characters
322 return true;
323 }
324 if (empty($string) or $string == '/') {
325 return true;
326 }
327
328 return false;
329}
330
9152fc99 331
0c6d2dd4 332/**
333 * Unzip one zip file to a destination dir
334 * Both parameters must be FULL paths
335 * If destination isn't specified, it will be the
336 * SAME directory where the zip file resides.
c861fe2f 337 *
338 * @global object
339 * @param string $zipfile The zip file to unzip
340 * @param string $destination The location to unzip to
341 * @param bool $showstatus_ignored Unused
0c6d2dd4 342 */
343function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
344 global $CFG;
345
346 //Extract everything from zipfile
347 $path_parts = pathinfo(cleardoubleslashes($zipfile));
348 $zippath = $path_parts["dirname"]; //The path of the zip file
349 $zipfilename = $path_parts["basename"]; //The name of the zip file
350 $extension = $path_parts["extension"]; //The extension of the file
351
352 //If no file, error
353 if (empty($zipfilename)) {
354 return false;
355 }
356
357 //If no extension, error
358 if (empty($extension)) {
359 return false;
360 }
361
362 //Clear $zipfile
363 $zipfile = cleardoubleslashes($zipfile);
364
365 //Check zipfile exists
366 if (!file_exists($zipfile)) {
367 return false;
368 }
369
370 //If no destination, passed let's go with the same directory
371 if (empty($destination)) {
372 $destination = $zippath;
373 }
374
375 //Clear $destination
376 $destpath = rtrim(cleardoubleslashes($destination), "/");
377
378 //Check destination path exists
379 if (!is_dir($destpath)) {
380 return false;
381 }
382
0b0bfa93 383 $packer = get_file_packer('application/zip');
384
385 $result = $packer->extract_to_pathname($zipfile, $destpath);
0c6d2dd4 386
387 if ($result === false) {
388 return false;
389 }
390
391 foreach ($result as $status) {
392 if ($status !== true) {
393 return false;
394 }
395 }
396
397 return true;
398}
399
ed94cb66 400/**
401 * Zip an array of files/dirs to a destination zip file
402 * Both parameters must be FULL paths to the files/dirs
c861fe2f 403 *
404 * @global object
405 * @param array $originalfiles Files to zip
406 * @param string $destination The destination path
407 * @return bool Outcome
ed94cb66 408 */
409function zip_files ($originalfiles, $destination) {
410 global $CFG;
411
412 //Extract everything from destination
413 $path_parts = pathinfo(cleardoubleslashes($destination));
414 $destpath = $path_parts["dirname"]; //The path of the zip file
415 $destfilename = $path_parts["basename"]; //The name of the zip file
416 $extension = $path_parts["extension"]; //The extension of the file
417
418 //If no file, error
419 if (empty($destfilename)) {
420 return false;
421 }
422
423 //If no extension, add it
424 if (empty($extension)) {
425 $extension = 'zip';
426 $destfilename = $destfilename.'.'.$extension;
427 }
428
429 //Check destination path exists
430 if (!is_dir($destpath)) {
431 return false;
432 }
433
434 //Check destination path is writable. TODO!!
435
436 //Clean destination filename
437 $destfilename = clean_filename($destfilename);
438
439 //Now check and prepare every file
440 $files = array();
441 $origpath = NULL;
442
443 foreach ($originalfiles as $file) { //Iterate over each file
444 //Check for every file
445 $tempfile = cleardoubleslashes($file); // no doubleslashes!
446 //Calculate the base path for all files if it isn't set
447 if ($origpath === NULL) {
448 $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
449 }
450 //See if the file is readable
451 if (!is_readable($tempfile)) { //Is readable
452 continue;
453 }
454 //See if the file/dir is in the same directory than the rest
455 if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
456 continue;
457 }
458 //Add the file to the array
459 $files[] = $tempfile;
460 }
461
462 $zipfiles = array();
463 $start = strlen($origpath)+1;
464 foreach($files as $file) {
465 $zipfiles[substr($file, $start)] = $file;
466 }
467
0b0bfa93 468 $packer = get_file_packer('application/zip');
ed94cb66 469
3ed22f1a 470 return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
ed94cb66 471}
472
ed5dd29f 473/////////////////////////////////////////////////////////////
474/// Old functions not used anymore - candidates for removal
475/////////////////////////////////////////////////////////////
476
ed5dd29f 477
1d684195 478/** various deprecated groups function **/
479
480
5bf243d1 481/**
482 * Get the IDs for the user's groups in the given course.
483 *
c861fe2f 484 * @global object
5bf243d1 485 * @param int $courseid The course being examined - the 'course' table id field.
c861fe2f 486 * @return array|bool An _array_ of groupids, or false
5bf243d1 487 * (Was return $groupids[0] - consequences!)
488 */
489function mygroupid($courseid) {
490 global $USER;
491 if ($groups = groups_get_all_groups($courseid, $USER->id)) {
492 return array_keys($groups);
493 } else {
494 return false;
495 }
496}
497
5bf243d1 498
5bf243d1 499/**
500 * Returns the current group mode for a given course or activity module
364fffda 501 *
5bf243d1 502 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
c861fe2f 503 *
504 * @param object $course Course Object
505 * @param object $cm Course Manager Object
506 * @return mixed $course->groupmode
5bf243d1 507 */
508function groupmode($course, $cm=null) {
509
510 if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
511 return $cm->groupmode;
512 }
513 return $course->groupmode;
514}
515
c584346c 516/**
517 * Sets the current group in the session variable
518 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
519 * Sets currentgroup[$courseid] in the session variable appropriately.
520 * Does not do any permission checking.
c861fe2f 521 *
522 * @global object
c584346c 523 * @param int $courseid The course being examined - relates to id field in
524 * 'course' table.
525 * @param int $groupid The group being examined.
526 * @return int Current group id which was set by this function
527 */
528function set_current_group($courseid, $groupid) {
529 global $SESSION;
530 return $SESSION->currentgroup[$courseid] = $groupid;
531}
532
5bf243d1 533
5bf243d1 534/**
364fffda 535 * Gets the current group - either from the session variable or from the database.
5bf243d1 536 *
c861fe2f 537 * @global object
364fffda 538 * @param int $courseid The course being examined - relates to id field in
5bf243d1 539 * 'course' table.
364fffda 540 * @param bool $full If true, the return value is a full record object.
5bf243d1 541 * If false, just the id of the record.
c861fe2f 542 * @return int|bool
5bf243d1 543 */
544function get_current_group($courseid, $full = false) {
545 global $SESSION;
546
547 if (isset($SESSION->currentgroup[$courseid])) {
548 if ($full) {
549 return groups_get_group($SESSION->currentgroup[$courseid]);
550 } else {
551 return $SESSION->currentgroup[$courseid];
552 }
553 }
554
555 $mygroupid = mygroupid($courseid);
556 if (is_array($mygroupid)) {
557 $mygroupid = array_shift($mygroupid);
558 set_current_group($courseid, $mygroupid);
559 if ($full) {
560 return groups_get_group($mygroupid);
561 } else {
562 return $mygroupid;
563 }
564 }
565
566 if ($full) {
567 return false;
568 } else {
569 return 0;
570 }
571}
572
573
8ec50604 574/**
575 * Print an error page displaying an error message.
576 * Old method, don't call directly in new code - use print_error instead.
577 *
c861fe2f 578 * @global object
8ec50604 579 * @param string $message The message to display to the user about the error.
580 * @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.
c861fe2f 581 * @return void Terminates script, does not return!
8ec50604 582 */
245ac557 583function error($message, $link='') {
fd1a792e 584 global $UNITTEST, $OUTPUT;
8ec50604 585
251387d0 586 // If unittest running, throw exception instead
a230012c 587 if (!empty($UNITTEST->running)) {
73f7ad71 588 // Errors in unit test become exceptions, so you can unit test
589 // code that might call error().
251387d0 590 throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message);
8ec50604 591 }
592
fd1a792e 593 list($message, $moreinfourl, $link) = prepare_error_message('notlocalisederrormessage', 'error', $link, $message);
594 $OUTPUT->fatal_error($message, $moreinfourl, $link, debug_backtrace(), null, true); // show debug warning
595 die;
251387d0 596}
8ec50604 597
8ec50604 598
b1f93b15 599/// Deprecated DDL functions, to be removed soon ///
c861fe2f 600/**
601 * @deprecated
602 * @global object
603 * @param string $table
604 * @return bool
605 */
b1f93b15 606function table_exists($table) {
607 global $DB;
608 debugging('Deprecated ddllib function used!');
609 return $DB->get_manager()->table_exists($table);
610}
611
c861fe2f 612/**
613 * @deprecated
614 * @global object
615 * @param string $table
616 * @param string $field
617 * @return bool
618 */
b1f93b15 619function field_exists($table, $field) {
620 global $DB;
621 debugging('Deprecated ddllib function used!');
622 return $DB->get_manager()->field_exists($table, $field);
623}
624
c861fe2f 625/**
626 * @deprecated
627 * @global object
628 * @param string $table
629 * @param string $index
630 * @return bool
631 */
b1f93b15 632function find_index_name($table, $index) {
633 global $DB;
634 debugging('Deprecated ddllib function used!');
635 return $DB->get_manager()->find_index_name($table, $index);
636}
637
c861fe2f 638/**
639 * @deprecated
640 * @global object
641 * @param string $table
642 * @param string $index
643 * @return bool
644 */
b1f93b15 645function index_exists($table, $index) {
646 global $DB;
647 debugging('Deprecated ddllib function used!');
648 return $DB->get_manager()->index_exists($table, $index);
649}
650
c861fe2f 651/**
652 * @deprecated
653 * @global object
654 * @param string $table
655 * @param string $field
656 * @return bool
657 */
b1f93b15 658function find_check_constraint_name($table, $field) {
659 global $DB;
660 debugging('Deprecated ddllib function used!');
661 return $DB->get_manager()->find_check_constraint_name($table, $field);
662}
663
c861fe2f 664/**
665 * @deprecated
666 * @global object
667 */
b1f93b15 668function check_constraint_exists($table, $field) {
669 global $DB;
670 debugging('Deprecated ddllib function used!');
671 return $DB->get_manager()->check_constraint_exists($table, $field);
672}
673
c861fe2f 674/**
675 * @deprecated
676 * @global object
677 * @param string $table
678 * @param string $xmldb_key
679 * @return bool
680 */
b1f93b15 681function find_key_name($table, $xmldb_key) {
682 global $DB;
683 debugging('Deprecated ddllib function used!');
684 return $DB->get_manager()->find_key_name($table, $xmldb_key);
685}
686
c861fe2f 687/**
688 * @deprecated
689 * @global object
690 * @param string $table
691 * @return bool
692 */
b1f93b15 693function find_sequence_name($table) {
694 global $DB;
695 debugging('Deprecated ddllib function used!');
696 return $DB->get_manager()->find_sequence_name($table);
697}
698
c861fe2f 699/**
700 * @deprecated
701 * @global object
702 * @param string $table
703 * @return bool
704 */
eee5d9bb 705function drop_table($table) {
b1f93b15 706 global $DB;
707 debugging('Deprecated ddllib function used!');
eee5d9bb 708 $DB->get_manager()->drop_table($table);
709 return true;
b1f93b15 710}
711
c861fe2f 712/**
713 * @deprecated
714 * @global object
715 * @param string $file
716 * @return bool
717 */
b1f93b15 718function install_from_xmldb_file($file) {
719 global $DB;
720 debugging('Deprecated ddllib function used!');
eee5d9bb 721 $DB->get_manager()->install_from_xmldb_file($file);
722 return true;
b1f93b15 723}
724
c861fe2f 725/**
726 * @deprecated
727 * @global object
728 * @param string $table
729 * @return bool
730 */
eee5d9bb 731function create_table($table) {
b1f93b15 732 global $DB;
733 debugging('Deprecated ddllib function used!');
eee5d9bb 734 $DB->get_manager()->create_table($table);
735 return true;
b1f93b15 736}
737
c861fe2f 738/**
739 * @deprecated
740 * @global object
741 * @param string $table
742 * @return bool
743 */
eee5d9bb 744function create_temp_table($table) {
b1f93b15 745 global $DB;
746 debugging('Deprecated ddllib function used!');
eee5d9bb 747 $DB->get_manager()->create_temp_table($table);
748 return true;
b1f93b15 749}
750
c861fe2f 751/**
752 * @deprecated
753 * @global object
754 * @param string $table
755 * @param string $newname
756 * @return bool
757 */
eee5d9bb 758function rename_table($table, $newname) {
b1f93b15 759 global $DB;
760 debugging('Deprecated ddllib function used!');
eee5d9bb 761 $DB->get_manager()->rename_table($table, $newname);
762 return true;
b1f93b15 763}
764
c861fe2f 765/**
766 * @deprecated
767 * @global object
768 * @param string $table
769 * @param string $field
770 * @return bool
771 */
eee5d9bb 772function add_field($table, $field) {
b1f93b15 773 global $DB;
774 debugging('Deprecated ddllib function used!');
eee5d9bb 775 $DB->get_manager()->add_field($table, $field);
776 return true;
b1f93b15 777}
778
c861fe2f 779/**
780 * @deprecated
781 * @global object
782 * @param string $table
783 * @param string $field
784 * @return bool
785 */
eee5d9bb 786function drop_field($table, $field) {
b1f93b15 787 global $DB;
788 debugging('Deprecated ddllib function used!');
eee5d9bb 789 $DB->get_manager()->drop_field($table, $field);
790 return true;
b1f93b15 791}
792
c861fe2f 793/**
794 * @deprecated
795 * @global object
796 * @param string $table
797 * @param string $field
798 * @return bool
799 */
eee5d9bb 800function change_field_type($table, $field) {
b1f93b15 801 global $DB;
802 debugging('Deprecated ddllib function used!');
eee5d9bb 803 $DB->get_manager()->change_field_type($table, $field);
804 return true;
b1f93b15 805}
806
c861fe2f 807/**
808 * @deprecated
809 * @global object
810 * @param string $table
811 * @param string $field
812 * @return bool
813 */
eee5d9bb 814function change_field_precision($table, $field) {
b1f93b15 815 global $DB;
816 debugging('Deprecated ddllib function used!');
eee5d9bb 817 $DB->get_manager()->change_field_precision($table, $field);
818 return true;
b1f93b15 819}
820
c861fe2f 821/**
822 * @deprecated
823 * @global object
824 * @param string $table
825 * @param string $field
826 * @return bool
827 */
eee5d9bb 828function change_field_unsigned($table, $field) {
b1f93b15 829 global $DB;
830 debugging('Deprecated ddllib function used!');
eee5d9bb 831 $DB->get_manager()->change_field_unsigned($table, $field);
832 return true;
b1f93b15 833}
834
c861fe2f 835/**
836 * @deprecated
837 * @global object
838 * @param string $table
839 * @param string $field
840 * @return bool
841 */
eee5d9bb 842function change_field_notnull($table, $field) {
b1f93b15 843 global $DB;
844 debugging('Deprecated ddllib function used!');
eee5d9bb 845 $DB->get_manager()->change_field_notnull($table, $field);
846 return true;
b1f93b15 847}
848
c861fe2f 849/**
850 * @deprecated
851 * @global object
852 * @param string $table
853 * @param string $field
854 * @return bool
855 */
eee5d9bb 856function change_field_enum($table, $field) {
b1f93b15 857 global $DB;
526fe7d8 858 debugging('Deprecated ddllib function used! Only dropping of enums is allowed.');
859 $DB->get_manager()->drop_enum_from_field($table, $field);
eee5d9bb 860 return true;
b1f93b15 861}
862
c861fe2f 863/**
864 * @deprecated
865 * @global object
866 * @param string $table
867 * @param string $field
868 * @return bool
869 */
eee5d9bb 870function change_field_default($table, $field) {
b1f93b15 871 global $DB;
872 debugging('Deprecated ddllib function used!');
eee5d9bb 873 $DB->get_manager()->change_field_default($table, $field);
874 return true;
b1f93b15 875}
876
c861fe2f 877/**
878 * @deprecated
879 * @global object
880 * @param string $table
881 * @param string $field
882 * @param string $newname
883 * @return bool
884 */
eee5d9bb 885function rename_field($table, $field, $newname) {
b1f93b15 886 global $DB;
887 debugging('Deprecated ddllib function used!');
fe772c2a 888 $DB->get_manager()->rename_field($table, $field, $newname);
eee5d9bb 889 return true;
b1f93b15 890}
891
c861fe2f 892/**
893 * @deprecated
894 * @global object
895 * @param string $table
896 * @param string $key
897 * @return bool
898 */
eee5d9bb 899function add_key($table, $key) {
b1f93b15 900 global $DB;
901 debugging('Deprecated ddllib function used!');
eee5d9bb 902 $DB->get_manager()->add_key($table, $key);
903 return true;
b1f93b15 904}
905
c861fe2f 906/**
907 * @deprecated
908 * @global object
909 * @param string $table
910 * @param string $key
911 * @return bool
912 */
eee5d9bb 913function drop_key($table, $key) {
b1f93b15 914 global $DB;
915 debugging('Deprecated ddllib function used!');
eee5d9bb 916 $DB->get_manager()->drop_key($table, $key);
917 return true;
b1f93b15 918}
919
c861fe2f 920/**
921 * @deprecated
922 * @global object
923 * @param string $table
924 * @param string $key
925 * @param string $newname
926 * @return bool
927 */
eee5d9bb 928function rename_key($table, $key, $newname) {
b1f93b15 929 global $DB;
930 debugging('Deprecated ddllib function used!');
eee5d9bb 931 $DB->get_manager()->rename_key($table, $key, $newname);
932 return true;
b1f93b15 933}
934
c861fe2f 935/**
936 * @deprecated
937 * @global object
938 * @param string $table
939 * @param string $index
940 * @return bool
941 */
eee5d9bb 942function add_index($table, $index) {
b1f93b15 943 global $DB;
944 debugging('Deprecated ddllib function used!');
eee5d9bb 945 $DB->get_manager()->add_index($table, $index);
946 return true;
b1f93b15 947}
948
c861fe2f 949/**
950 * @deprecated
951 * @global object
952 * @param string $table
953 * @param string $index
954 * @return bool
955 */
eee5d9bb 956function drop_index($table, $index) {
b1f93b15 957 global $DB;
958 debugging('Deprecated ddllib function used!');
eee5d9bb 959 $DB->get_manager()->drop_index($table, $index);
960 return true;
b1f93b15 961}
962
c861fe2f 963/**
964 * @deprecated
965 * @global object
966 * @param string $table
967 * @param string $index
968 * @param string $newname
969 * @return bool
970 */
eee5d9bb 971function rename_index($table, $index, $newname) {
b1f93b15 972 global $DB;
973 debugging('Deprecated ddllib function used!');
eee5d9bb 974 $DB->get_manager()->rename_index($table, $index, $newname);
975 return true;
b1f93b15 976}
977
8ec50604 978
251387d0 979//////////////////////////
980/// removed functions ////
981//////////////////////////
294ce987 982
c861fe2f 983/**
984 * @deprecated
985 * @param mixed $mixed
986 * @return void Throws an error and does nothing
987 */
2fd0e9fe 988function stripslashes_safe($mixed) {
989 error('stripslashes_safe() not available anymore');
990}
c861fe2f 991/**
992 * @deprecated
993 * @param mixed $var
994 * @return void Throws an error and does nothing
995 */
2fd0e9fe 996function stripslashes_recursive($var) {
997 error('stripslashes_recursive() not available anymore');
998}
c861fe2f 999/**
1000 * @deprecated
1001 * @param mixed $dataobject
1002 * @return void Throws an error and does nothing
1003 */
245ac557 1004function addslashes_object($dataobject) {
6795800d 1005 error('addslashes_object() not available anymore');
294ce987 1006}
c861fe2f 1007/**
1008 * @deprecated
1009 * @param mixed $var
1010 * @return void Throws an error and does nothing
1011 */
294ce987 1012function addslashes_recursive($var) {
1013 error('addslashes_recursive() not available anymore');
1014}
c861fe2f 1015/**
1016 * @deprecated
1017 * @param mixed $command
1018 * @param bool $feedback
1019 * @return void Throws an error and does nothing
1020 */
245ac557 1021function execute_sql($command, $feedback=true) {
1022 error('execute_sql() not available anymore');
1023}
c861fe2f 1024/**
1025 * @deprecated
1026 * @param mixed $table
1027 * @param mixed $select
1028 * @return void Throws an error and does nothing
1029 */
245ac557 1030function record_exists_select($table, $select='') {
1031 error('record_exists_select() not available anymore');
1032}
c861fe2f 1033/**
1034 * @deprecated
1035 * @param mixed $sql
1036 * @return void Throws an error and does nothing
1037 */
245ac557 1038function record_exists_sql($sql) {
1039 error('record_exists_sql() not available anymore');
1040}
c861fe2f 1041/**
1042 * @deprecated
1043 * @param mixed $table
1044 * @param mixed $select
1045 * @param mixed $countitem
1046 * @return void Throws an error and does nothing
1047 */
245ac557 1048function count_records_select($table, $select='', $countitem='COUNT(*)') {
1049 error('count_records_select() not available anymore');
1050}
c861fe2f 1051/**
1052 * @deprecated
1053 * @param mixed $sql
1054 * @return void Throws an error and does nothing
1055 */
245ac557 1056function count_records_sql($sql) {
1057 error('count_records_sql() not available anymore');
1058}
c861fe2f 1059/**
1060 * @deprecated
1061 * @param mixed $sql
1062 * @param bool $expectmultiple
1063 * @param bool $nolimit
1064 * @return void Throws an error and does nothing
1065 */
245ac557 1066function get_record_sql($sql, $expectmultiple=false, $nolimit=false) {
1067 error('get_record_sql() not available anymore');
1068}
c861fe2f 1069/**
1070 * @deprecated
1071 * @param mixed $table
1072 * @param mixed $select
1073 * @param mixed $fields
1074 * @return void Throws an error and does nothing
1075 */
245ac557 1076function get_record_select($table, $select='', $fields='*') {
1077 error('get_record_select() not available anymore');
1078}
c861fe2f 1079/**
1080 * @deprecated
1081 * @param mixed $table
1082 * @param mixed $field
1083 * @param mixed $value
1084 * @param mixed $sort
1085 * @param mixed $fields
1086 * @param mixed $limitfrom
1087 * @param mixed $limitnum
1088 * @return void Throws an error and does nothing
1089 */
245ac557 1090function get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1091 error('get_recordset() not available anymore');
1092}
c861fe2f 1093/**
1094 * @deprecated
1095 * @param mixed $sql
1096 * @param mixed $limitfrom
1097 * @param mixed $limitnum
1098 * @return void Throws an error and does nothing
1099 */
245ac557 1100function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) {
1101 error('get_recordset_sql() not available anymore');
1102}
c861fe2f 1103/**
1104 * @deprecated
1105 * @param mixed $rs
1106 * @return void Throws an error and does nothing
1107 */
245ac557 1108function rs_fetch_record(&$rs) {
1109 error('rs_fetch_record() not available anymore');
1110}
c861fe2f 1111/**
1112 * @deprecated
1113 * @param mixed $rs
1114 * @return void Throws an error and does nothing
1115 */
245ac557 1116function rs_next_record(&$rs) {
1117 error('rs_next_record() not available anymore');
1118}
c861fe2f 1119/**
1120 * @deprecated
1121 * @param mixed $rs
1122 * @return void Throws an error and does nothing
1123 */
245ac557 1124function rs_fetch_next_record(&$rs) {
1125 error('rs_fetch_next_record() not available anymore');
1126}
c861fe2f 1127/**
1128 * @deprecated
1129 * @param mixed $rs
1130 * @return void Throws an error and does nothing
1131 */
245ac557 1132function rs_EOF($rs) {
1133 error('rs_EOF() not available anymore');
1134}
c861fe2f 1135/**
1136 * @deprecated
1137 * @param mixed $rs
1138 * @return void Throws an error and does nothing
1139 */
245ac557 1140function rs_close(&$rs) {
1141 error('rs_close() not available anymore');
1142}
c861fe2f 1143/**
1144 * @deprecated
1145 * @param mixed $table
1146 * @param mixed $select
1147 * @param mixed $sort
1148 * @param mixed $fields
1149 * @param mixed $limitfrom
1150 * @param mixed $limitnum
1151 * @return void Throws an error and does nothing
1152 */
245ac557 1153function get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1154 error('get_records_select() not available anymore');
1155}
c861fe2f 1156/**
1157 * @deprecated
1158 * @param mixed $table
1159 * @param mixed $return
1160 * @param mixed $select
1161 * @return void Throws an error and does nothing
1162 */
245ac557 1163function get_field_select($table, $return, $select) {
1164 error('get_field_select() not available anymore');
1165}
c861fe2f 1166/**
1167 * @deprecated
1168 * @param mixed $sql
1169 * @return void Throws an error and does nothing
1170 */
245ac557 1171function get_field_sql($sql) {
1172 error('get_field_sql() not available anymore');
1173}
c861fe2f 1174/**
1175 * @deprecated
1176 * @param mixed $sql
1177 * @param mixed $select
1178 * @return void Throws an error and does nothing
1179 */
245ac557 1180function delete_records_select($table, $select='') {
165a2c9e 1181 error('get_field_sql() not available anymore');
245ac557 1182}
c861fe2f 1183/**
1184 * @deprecated
1185 * @return void Throws an error and does nothing
1186 */
245ac557 1187function configure_dbconnection() {
1188 error('configure_dbconnection() removed');
1189}
c861fe2f 1190/**
1191 * @deprecated
1192 * @param mixed $field
1193 * @return void Throws an error and does nothing
1194 */
245ac557 1195function sql_max($field) {
1196 error('sql_max() removed - use normal sql MAX() instead');
1197}
c861fe2f 1198/**
1199 * @deprecated
1200 * @return void Throws an error and does nothing
1201 */
245ac557 1202function sql_as() {
1203 error('sql_as() removed - do not use AS for tables at all');
1204}
c861fe2f 1205/**
1206 * @deprecated
1207 * @param mixed $page
1208 * @param mixed $recordsperpage
1209 * @return void Throws an error and does nothing
1210 */
245ac557 1211function sql_paging_limit($page, $recordsperpage) {
1212 error('Function sql_paging_limit() is deprecated. Replace it with the correct use of limitfrom, limitnum parameters');
1213}
c861fe2f 1214/**
1215 * @deprecated
1216 * @return void Throws an error and does nothing
1217 */
245ac557 1218function db_uppercase() {
1219 error('upper() removed - use normal sql UPPER()');
1220}
c861fe2f 1221/**
1222 * @deprecated
1223 * @return void Throws an error and does nothing
1224 */
245ac557 1225function db_lowercase() {
1226 error('upper() removed - use normal sql LOWER()');
1227}
c861fe2f 1228/**
1229 * @deprecated
1230 * @param mixed $sqlfile
1231 * @param mixed $sqlstring
1232 * @return void Throws an error and does nothing
1233 */
245ac557 1234function modify_database($sqlfile='', $sqlstring='') {
1235 error('modify_database() removed - use new XMLDB functions');
1236}
c861fe2f 1237/**
1238 * @deprecated
1239 * @param mixed $field1
1240 * @param mixed $value1
1241 * @param mixed $field2
1242 * @param mixed $value2
1243 * @param mixed $field3
1244 * @param mixed $value3
1245 * @return void Throws an error and does nothing
1246 */
245ac557 1247function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1248 error('where_clause() removed - use new functions with $conditions parameter');
1249}
c861fe2f 1250/**
1251 * @deprecated
1252 * @param mixed $sqlarr
1253 * @param mixed $continue
1254 * @param mixed $feedback
1255 * @return void Throws an error and does nothing
1256 */
245ac557 1257function execute_sql_arr($sqlarr, $continue=true, $feedback=true) {
1258 error('execute_sql_arr() removed');
1259}
c861fe2f 1260/**
1261 * @deprecated
1262 * @param mixed $table
1263 * @param mixed $field
1264 * @param mixed $values
1265 * @param mixed $sort
1266 * @param mixed $fields
1267 * @param mixed $limitfrom
1268 * @param mixed $limitnum
1269 * @return void Throws an error and does nothing
1270 */
245ac557 1271function get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1272 error('get_records_list() removed');
1273}
c861fe2f 1274/**
1275 * @deprecated
1276 * @param mixed $table
1277 * @param mixed $field
1278 * @param mixed $values
1279 * @param mixed $sort
1280 * @param mixed $fields
1281 * @param mixed $limitfrom
1282 * @param mixed $limitnum
1283 * @return void Throws an error and does nothing
1284 */
245ac557 1285function get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1286 error('get_recordset_list() removed');
1287}
c861fe2f 1288/**
1289 * @deprecated
1290 * @param mixed $table
1291 * @param mixed $field
1292 * @param mixed $value
1293 * @param mixed $sort
1294 * @param mixed $fields
1295 * @param mixed $limitfrom
1296 * @param mixed $limitnum
1297 * @return void Throws an error and does nothing
1298 */
245ac557 1299function get_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1300 error('get_records_menu() removed');
1301}
c861fe2f 1302/**
1303 * @deprecated
1304 * @param mixed $table
1305 * @param mixed $select
1306 * @param mixed $sort
1307 * @param mixed $fields
1308 * @param mixed $limitfrom
1309 * @param mixed $limitnum
1310 * @return void Throws an error and does nothing
1311 */
245ac557 1312function get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1313 error('get_records_select_menu() removed');
1314}
c861fe2f 1315/**
1316 * @deprecated
1317 * @param mixed $sql
1318 * @param mixed $limitfrom
1319 * @param mixed $limitnum
1320 * @return void Throws an error and does nothing
1321 */
245ac557 1322function get_records_sql_menu($sql, $limitfrom='', $limitnum='') {
1323 error('get_records_sql_menu() removed');
1324}
c861fe2f 1325/**
1326 * @deprecated
1327 * @param mixed $table
1328 * @param mixed $column
1329 * @return void Throws an error and does nothing
1330 */
245ac557 1331function column_type($table, $column) {
1332 error('column_type() removed');
1333}
c861fe2f 1334/**
1335 * @deprecated
1336 * @param mixed $rs
1337 * @return void Throws an error and does nothing
1338 */
245ac557 1339function recordset_to_menu($rs) {
1340 error('recordset_to_menu() removed');
1341}
c861fe2f 1342/**
1343 * @deprecated
1344 * @param mixed $records
1345 * @param mixed $field1
1346 * @param mixed $field2
1347 * @return void Throws an error and does nothing
1348 */
245ac557 1349function records_to_menu($records, $field1, $field2) {
1350 error('records_to_menu() removed');
1351}
c861fe2f 1352/**
1353 * @deprecated
1354 * @param mixed $table
1355 * @param mixed $newfield
1356 * @param mixed $newvalue
1357 * @param mixed $select
1358 * @param mixed $localcall
1359 * @return void Throws an error and does nothing
1360 */
245ac557 1361function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) {
1362 error('set_field_select() removed');
1363}
c861fe2f 1364/**
1365 * @deprecated
1366 * @param mixed $table
1367 * @param mixed $return
1368 * @param mixed $select
1369 * @return void Throws an error and does nothing
1370 */
245ac557 1371function get_fieldset_select($table, $return, $select) {
1372 error('get_fieldset_select() removed');
1373}
c861fe2f 1374/**
1375 * @deprecated
1376 * @param mixed $sql
1377 * @return void Throws an error and does nothing
1378 */
245ac557 1379function get_fieldset_sql($sql) {
1380 error('get_fieldset_sql() removed');
1381}
c861fe2f 1382/**
1383 * @deprecated
1384 * @return void Throws an error and does nothing
1385 */
245ac557 1386function sql_ilike() {
1387 error('sql_ilike() not available anymore');
1388}
c861fe2f 1389/**
1390 * @deprecated
1391 * @param mixed $first
1392 * @param mixed $last
1393 * @return void Throws an error and does nothing
1394 */
245ac557 1395function sql_fullname($first='firstname', $last='lastname') {
1396 error('sql_fullname() not available anymore');
1397}
c861fe2f 1398/**
1399 * @deprecated
1400 * @return void Throws an error and does nothing
1401 */
245ac557 1402function sql_concat() {
1403 error('sql_concat() not available anymore');
1404}
c861fe2f 1405/**
1406 * @deprecated
1407 * @return void Throws an error and does nothing
1408 */
245ac557 1409function sql_empty() {
1410 error('sql_empty() not available anymore');
1411}
c861fe2f 1412/**
1413 * @deprecated
1414 * @return void Throws an error and does nothing
1415 */
245ac557 1416function sql_substr() {
1417 error('sql_substr() not available anymore');
1418}
c861fe2f 1419/**
1420 * @deprecated
1421 * @param mixed $int1
1422 * @param mixed $int2
1423 * @return void Throws an error and does nothing
1424 */
245ac557 1425function sql_bitand($int1, $int2) {
1426 error('sql_bitand() not available anymore');
1427}
c861fe2f 1428/**
1429 * @deprecated
1430 * @param mixed $int1
1431 * @return void Throws an error and does nothing
1432 */
245ac557 1433function sql_bitnot($int1) {
1434 error('sql_bitnot() not available anymore');
1435}
c861fe2f 1436/**
1437 * @deprecated
1438 * @param mixed $int1
1439 * @param mixed $int2
1440 * @return void Throws an error and does nothing
1441 */
245ac557 1442function sql_bitor($int1, $int2) {
1443 error('sql_bitor() not available anymore');
1444}
c861fe2f 1445/**
1446 * @deprecated
1447 * @param mixed $int1
1448 * @param mixed $int2
1449 * @return void Throws an error and does nothing
1450 */
245ac557 1451function sql_bitxor($int1, $int2) {
1452 error('sql_bitxor() not available anymore');
1453}
c861fe2f 1454/**
1455 * @deprecated
1456 * @param mixed $fieldname
1457 * @param mixed $text
1458 * @return void Throws an error and does nothing
1459 */
245ac557 1460function sql_cast_char2int($fieldname, $text=false) {
1461 error('sql_cast_char2int() not available anymore');
1462}
c861fe2f 1463/**
1464 * @deprecated
1465 * @param mixed $fieldname
1466 * @param mixed $numchars
1467 * @return void Throws an error and does nothing
1468 */
245ac557 1469function sql_compare_text($fieldname, $numchars=32) {
1470 error('sql_compare_text() not available anymore');
1471}
c861fe2f 1472/**
1473 * @deprecated
1474 * @param mixed $fieldname
1475 * @param mixed $numchars
1476 * @return void Throws an error and does nothing
1477 */
245ac557 1478function sql_order_by_text($fieldname, $numchars=32) {
1479 error('sql_order_by_text() not available anymore');
1480}
c861fe2f 1481/**
1482 * @deprecated
1483 * @param mixed $fieldname
1484 * @return void Throws an error and does nothing
1485 */
7b837bc3 1486function sql_length($fieldname) {
1487 error('sql_length() not available anymore');
1488}
c861fe2f 1489/**
1490 * @deprecated
1491 * @param mixed $separator
1492 * @param mixed $elements
1493 * @return void Throws an error and does nothing
1494 */
245ac557 1495function sql_concat_join($separator="' '", $elements=array()) {
1496 error('sql_concat_join() not available anymore');
1497}
c861fe2f 1498/**
1499 * @deprecated
1500 * @param mixed $tablename
1501 * @param mixed $fieldname
1502 * @param mixed $nullablefield
1503 * @param mixed $textfield
1504 * @return void Throws an error and does nothing
1505 */
245ac557 1506function sql_isempty($tablename, $fieldname, $nullablefield, $textfield) {
1507 error('sql_isempty() not available anymore');
1508}
c861fe2f 1509/**
1510 * @deprecated
1511 * @param mixed $tablename
1512 * @param mixed $fieldname
1513 * @param mixed $nullablefield
1514 * @param mixed $textfield
1515 * @return void Throws an error and does nothing
1516 */
245ac557 1517function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) {
1518 error('sql_isnotempty() not available anymore');
1519}
c861fe2f 1520/**
1521 * @deprecated
1522 * @return void Throws an error and does nothing
1523 */
245ac557 1524function begin_sql() {
1525 error('begin_sql() not available anymore');
1526}
c861fe2f 1527/**
1528 * @deprecated
1529 * @return void Throws an error and does nothing
1530 */
245ac557 1531function commit_sql() {
1532 error('commit_sql() not available anymore');
1533}
c861fe2f 1534/**
1535 * @deprecated
1536 * @return void Throws an error and does nothing
1537 */
245ac557 1538function rollback_sql() {
1539 error('rollback_sql() not available anymore');
1540}
c861fe2f 1541/**
1542 * @deprecated
1543 * @param mixed $table
1544 * @param mixed $dataobject
1545 * @param mixed $returnid
1546 * @param mixed $primarykey
1547 * @return void Throws an error and does nothing
1548 */
245ac557 1549function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
1550 error('insert_record() not available anymore');
1551}
c861fe2f 1552/**
1553 * @deprecated
1554 * @param mixed $table
1555 * @param mixed $dataobject
1556 * @return void Throws an error and does nothing
1557 */
245ac557 1558function update_record($table, $dataobject) {
1559 error('update_record() not available anymore');
1560}
c861fe2f 1561/**
1562 * @deprecated
1563 * @param mixed $table
1564 * @param mixed $field
1565 * @param mixed $value
1566 * @param mixed $sort
1567 * @param mixed $fields
1568 * @param mixed $limitfrom
1569 * @param mixed $limitnum
a5cb8d69 1570 *
c861fe2f 1571 * @return void Throws an error and does nothing
1572 */
245ac557 1573function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') {
1574 error('get_records() not available anymore');
1575}
c861fe2f 1576/**
1577 * @deprecated
1578 * @param mixed $table
1579 * @param mixed $field1
1580 * @param mixed $value1
1581 * @param mixed $field2
1582 * @param mixed $value2
1583 * @param mixed $field3
1584 * @param mixed $value3
1585 * @param mixed $fields
1586 * @return void Throws an error and does nothing
1587 */
245ac557 1588function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') {
1589 error('get_record() not available anymore');
1590}
c861fe2f 1591/**
1592 * @deprecated
1593 * @param mixed $table
1594 * @param mixed $newfield
1595 * @param mixed $newvalue
1596 * @param mixed $field1
1597 * @param mixed $value1
1598 * @param mixed $field2
1599 * @param mixed $value2
1600 * @param mixed $field3
1601 * @param mixed $value3
1602 * @return void Throws an error and does nothing
1603 */
245ac557 1604function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1605 error('set_field() not available anymore');
1606}
c861fe2f 1607/**
1608 * @deprecated
1609 * @param mixed $table
1610 * @param mixed $field1
1611 * @param mixed $value1
1612 * @param mixed $field2
1613 * @param mixed $value2
1614 * @param mixed $field3
1615 * @param mixed $value3
1616 * @return void Throws an error and does nothing
1617 */
245ac557 1618function count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1619 error('count_records() not available anymore');
1620}
c861fe2f 1621/**
1622 * @deprecated
1623 * @param mixed $table
1624 * @param mixed $field1
1625 * @param mixed $value1
1626 * @param mixed $field2
1627 * @param mixed $value2
1628 * @param mixed $field3
1629 * @param mixed $value3
1630 * @return void Throws an error and does nothing
1631 */
245ac557 1632function record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1633 error('record_exists() not available anymore');
1634}
c861fe2f 1635/**
1636 * @deprecated
1637 * @param mixed $table
1638 * @param mixed $field1
1639 * @param mixed $value1
1640 * @param mixed $field2
1641 * @param mixed $value2
1642 * @param mixed $field3
1643 * @param mixed $value3
1644 * @return void Throws an error and does nothing
1645 */
245ac557 1646function delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') {
1647 error('delete_records() not available anymore');
1648}
c861fe2f 1649/**
1650 * @deprecated
1651 * @param mixed $table
1652 * @param mixed $return
1653 * @param mixed $field1
1654 * @param mixed $value1
1655 * @param mixed $field2
1656 * @param mixed $value2
1657 * @param mixed $field3
1658 * @param mixed $value3
1659 * @return void Throws an error and does nothing
1660 */
245ac557 1661function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
1662 error('get_field() not available anymore');
1663}
c861fe2f 1664/**
1665 * @deprecated
1666 * @param mixed $table
1667 * @param mixed $oldfield
1668 * @param mixed $field
1669 * @param mixed $type
1670 * @param mixed $size
1671 * @param mixed $signed
1672 * @param mixed $default
1673 * @param mixed $null
1674 * @param mixed $after
1675 * @return void Throws an error and does nothing
1676 */
e6b4f00e 1677function table_column($table, $oldfield, $field, $type='integer', $size='10',
1678 $signed='unsigned', $default='0', $null='not null', $after='') {
1679 error('table_column() was removed, please use new ddl functions');
1680}
c861fe2f 1681/**
1682 * @deprecated
1683 * @param mixed $name
1684 * @param mixed $editorhidebuttons
1685 * @param mixed $id
1686 * @return void Throws an error and does nothing
1687 */
88c8d161 1688function use_html_editor($name='', $editorhidebuttons='', $id='') {
1689 error('use_html_editor() not available anymore');
1690}
cf615522 1691
1692/**
1693 * The old method that was used to include JavaScript libraries.
1694 * Please use $PAGE->requires->js() or $PAGE->requires->yui_lib() instead.
1695 *
1696 * @param mixed $lib The library or libraries to load (a string or array of strings)
1697 * There are three way to specify the library:
1698 * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui_lib('yahoo')->asap();
1699 * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
1700 * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
1701 * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
1702 */
1703function require_js($lib) {
1704 global $CFG, $PAGE;
1705 // Add the lib to the list of libs to be loaded, if it isn't already
1706 // in the list.
1707 if (is_array($lib)) {
1708 foreach($lib as $singlelib) {
1709 require_js($singlelib);
1710 }
1711 return;
1712 }
1713
1714 // TODO uncomment this once we have eliminated the remaining calls to require_js from core.
1715 //debugging('Call to deprecated function require_js. Please use $PAGE->requires->js() ' .
1716 // 'or $PAGE->requires->yui_lib() instead.', DEBUG_DEVELOPER);
1717
1718 if (strpos($lib, 'yui_') === 0) {
1719 echo $PAGE->requires->yui_lib(substr($lib, 4))->asap();
1720 } else if (preg_match('/^https?:/', $lib)) {
1721 echo $PAGE->requires->js(str_replace($CFG->wwwroot, '', $lib))->asap();
1722 } else {
1723 echo $PAGE->requires->js($lib)->asap();
1724 }
1725}
5af6ec1b 1726
1727/**
1728 * Makes an upload directory for a particular module.
1729 *
a5cb8d69 1730 * This function has been deprecated by the file API changes in Moodle 2.0.
5af6ec1b 1731 *
1732 * @deprecated
1733 * @param int $courseid The id of the course in question - maps to id field of 'course' table.
1734 * @return string|false Returns full path to directory if successful, false if not
1735 */
1736function make_mod_upload_directory($courseid) {
1737 global $CFG;
1738 debugging('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.', DEBUG_DEVELOPER);
1739 return make_upload_directory($courseid .'/'. $CFG->moddata);
1740}
1741
a5cb8d69 1742
1743/**
1744 * This is a slight variatoin on the standard_renderer_factory that uses
1745 * custom_corners_core_renderer instead of moodle_core_renderer.
1746 *
1747 * This generates the slightly different HTML that the custom_corners theme expects.
1748 *
1749 * @copyright 2009 Tim Hunt
1750 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1751 * @deprecated Required to make the old $THEME->customcorners setting work.
1752 */
1753class custom_corners_renderer_factory extends standard_renderer_factory {
db8d89d8 1754 public function __construct($theme) {
1755 parent::__construct($theme);
a5cb8d69 1756 global $CFG;
fcae2e3b 1757 require_once($CFG->themedir . '/custom_corners/renderers.php');
db8d89d8 1758 }
1759 /* Implement the subclass method. */
897b5c82 1760 public function get_renderer($module, $page, $subtype=null) {
db8d89d8 1761 if ($module == 'core') {
1762 return new custom_corners_core_renderer($page);
1763 }
897b5c82 1764 return parent::get_renderer($module, $page, $subtype);
a5cb8d69 1765 }
1766}
1767
1768
b7009474 1769/**
1770 * Used to be used for setting up the theme. No longer used by core code, and
1771 * should not have been used elsewhere.
1772 *
1773 * The theme is now automatically initialised before it is first used. If you really need
1774 * to force this to happen, just reference $PAGE->theme.
1775 *
1776 * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
1777 * However, I can't think of any valid reason to do that outside the theme selector UI.
1778 *
1779 * @deprecated
1780 * @param string $theme The theme to use defaults to current theme
1781 * @param array $params An array of parameters to use
1782 */
1783function theme_setup($theme = '', $params=NULL) {
1784 throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
1785 'The current theme gets initialised automatically before it is first used.');
1786}
1787
1788/**
1789 * @deprecated use $PAGE->theme->name instead.
1790 * @return string the name of the current theme.
1791 */
1792function current_theme() {
1793 global $PAGE;
1794 // TODO, uncomment this once we have eliminated all references to current_theme in core code.
1795 // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
1796 return $PAGE->theme->name;
1797}
1798
1799/**
1800 * This used to be the thing that theme styles.php files used to do all the work.
1801 * This is now handled differently. You should copy theme/standard/styes.php
1802 * into your theme.
1803 *
1804 * @deprecated
1805 * @param int $lastmodified Always gets set to now
1806 * @param int $lifetime The max-age header setting (seconds) defaults to 300
1807 * @param string $themename The name of the theme to use (optional) defaults to current theme
1808 * @param string $forceconfig Force a particular theme config (optional)
1809 * @param string $lang Load styles for the specified language (optional)
1810 */
1811function style_sheet_setup($lastmodified=0, $lifetime=300, $themename='', $forceconfig='', $lang='') {
1812 global $CFG, $PAGE, $THEME, $showdeprecatedstylesheetsetupwarning;
1813 $showdeprecatedstylesheetsetupwarning = true;
1814 include($CFG->dirroot . '/theme/styles.php');
1815 exit;
1816}
1817
a64e25f6 1818/**
1819 * @todo Remove this deprecated function when no longer used
1820 * @deprecated since Moodle 2.0 - use $PAGE->pagetype instead of the .
1821 *
1822 * @param string $getid used to return $PAGE->pagetype.
1823 * @param string $getclass used to return $PAGE->legacyclass.
1824 */
1825function page_id_and_class(&$getid, &$getclass) {
1826 global $PAGE;
1827 debugging('Call to deprecated function page_id_and_class. Please use $PAGE->pagetype instead.', DEBUG_DEVELOPER);
1828 $getid = $PAGE->pagetype;
1829 $getclass = $PAGE->legacyclass;
1830}
1831
8954245a 1832/**
1833 * Prints some red text using echo
1834 *
1835 * @deprecated
1836 * @param string $error The text to be displayed in red
1837 */
1838function formerr($error) {
1839 global $OUTPUT;
1840 echo $OUTPUT->error_text($error);
1841}
1842
34a2777c 1843/**
1844 * Return the markup for the destination of the 'Skip to main content' links.
1845 * Accessibility improvement for keyboard-only users.
1846 *
1847 * Used in course formats, /index.php and /course/index.php
1848 *
1849 * @deprecated use $OUTPUT->skip_link_target() in instead.
1850 * @return string HTML element.
1851 */
1852function skip_main_destination() {
1853 global $OUTPUT;
1854 return $OUTPUT->skip_link_target();
1855}
1856
1857/**
1858 * Prints a string in a specified size (retained for backward compatibility)
1859 *
1860 * @deprecated
1861 * @param string $text The text to be displayed
1862 * @param int $size The size to set the font for text display.
1863 * @param bool $return If set to true output is returned rather than echoed Default false
1864 * @return string|void String if return is true
1865 */
1866function print_headline($text, $size=2, $return=false) {
1867 global $OUTPUT;
1868 $output = $OUTPUT->heading($text, $size);
1869 if ($return) {
1870 return $output;
1871 } else {
1872 echo $output;
1873 }
1874}
1875
1876/**
1877 * Prints text in a format for use in headings.
1878 *
1879 * @deprecated
1880 * @param string $text The text to be displayed
1881 * @param string $deprecated No longer used. (Use to do alignment.)
1882 * @param int $size The size to set the font for text display.
1883 * @param string $class
1884 * @param bool $return If set to true output is returned rather than echoed, default false
1885 * @param string $id The id to use in the element
1886 * @return string|void String if return=true nothing otherwise
1887 */
1888function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
1889 global $OUTPUT;
1890 if (!empty($deprecated)) {
1891 debugging('Use of deprecated align attribute of print_heading. ' .
1892 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
1893 }
1894 $output = $OUTPUT->heading($text, $size, $class, $id);
1895 if ($return) {
1896 return $output;
1897 } else {
1898 echo $output;
1899 }
1900}
1901
1902/**
1903 * Output a standard heading block
1904 *
1905 * @deprecated
1906 * @param string $heading The text to write into the heading
1907 * @param string $class An additional Class Attr to use for the heading
1908 * @param bool $return If set to true output is returned rather than echoed, default false
1909 * @return string|void HTML String if return=true nothing otherwise
1910 */
1911function print_heading_block($heading, $class='', $return=false) {
1912 global $OUTPUT;
1913 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . moodle_renderer_base::prepare_classes($class));
1914 if ($return) {
1915 return $output;
1916 } else {
1917 echo $output;
1918 }
1919}
1920
1921/**
1922 * Print a message in a standard themed box.
1923 * Replaces print_simple_box (see deprecatedlib.php)
1924 *
1925 * @deprecated
1926 * @param string $message, the content of the box
1927 * @param string $classes, space-separated class names.
1928 * @param string $ids
1929 * @param boolean $return, return as string or just print it
1930 * @return string|void mixed string or void
1931 */
1932function print_box($message, $classes='generalbox', $ids='', $return=false) {
1933 global $OUTPUT;
1934 $output = $OUTPUT->box($message, $classes, $ids);
1935 if ($return) {
1936 return $output;
1937 } else {
1938 echo $output;
1939 }
1940}
1941
1942/**
1943 * Starts a box using divs
1944 * Replaces print_simple_box_start (see deprecatedlib.php)
1945 *
1946 * @deprecated
1947 * @param string $classes, space-separated class names.
1948 * @param string $ids
1949 * @param boolean $return, return as string or just print it
1950 * @return string|void string or void
1951 */
1952function print_box_start($classes='generalbox', $ids='', $return=false) {
1953 global $OUTPUT;
1954 $output = $OUTPUT->box_start($classes, $ids);
1955 if ($return) {
1956 return $output;
1957 } else {
1958 echo $output;
1959 }
1960}
1961
1962/**
1963 * Simple function to end a box (see above)
1964 * Replaces print_simple_box_end (see deprecatedlib.php)
1965 *
1966 * @deprecated
1967 * @param boolean $return, return as string or just print it
1968 * @return string|void Depending on value of return
1969 */
1970function print_box_end($return=false) {
1971 global $OUTPUT;
1972 $output = $OUTPUT->box_end();
1973 if ($return) {
1974 return $output;
1975 } else {
1976 echo $output;
1977 }
1978}
1979
1980/**
1981 * Print a message in a standard themed container.
1982 *
1983 * @deprecated
1984 * @param string $message, the content of the container
1985 * @param boolean $clearfix clear both sides
1986 * @param string $classes, space-separated class names.
1987 * @param string $idbase
1988 * @param boolean $return, return as string or just print it
1989 * @return string|void Depending on value of $return
1990 */
1991function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1992 global $OUTPUT;
1993 if ($clearfix) {
1994 $classes .= ' clearfix';
1995 }
1996 $output = $OUTPUT->container($message, $classes, $idbase);
1997 if ($return) {
1998 return $output;
1999 } else {
2000 echo $output;
2001 }
2002}
2003
2004/**
2005 * Starts a container using divs
2006 *
2007 * @deprecated
2008 * @param boolean $clearfix clear both sides
2009 * @param string $classes, space-separated class names.
2010 * @param string $idbase
2011 * @param boolean $return, return as string or just print it
2012 * @return string|void Based on value of $return
2013 */
2014function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
2015 global $OUTPUT;
2016 if ($clearfix) {
2017 $classes .= ' clearfix';
2018 }
2019 $output = $OUTPUT->container_start($classes, $idbase);
2020 if ($return) {
2021 return $output;
2022 } else {
2023 echo $output;
2024 }
2025}
2026
2027/**
2028 * Simple function to end a container (see above)
2029 *
2030 * @deprecated
2031 * @param boolean $return, return as string or just print it
2032 * @return string|void Based on $return
2033 */
2034function print_container_end($return=false) {
2035 global $OUTPUT;
2036 $output = $OUTPUT->container_end();
2037 if ($return) {
2038 return $output;
2039 } else {
2040 echo $output;
2041 }
2042}
2043
2044/**
2045 * Print a bold message in an optional color.
2046 *
2047 * @deprecated use $OUTPUT->notification instead.
2048 * @param string $message The message to print out
2049 * @param string $style Optional style to display message text in
2050 * @param string $align Alignment option
2051 * @param bool $return whether to return an output string or echo now
a5cb8d69 2052 * @return string|bool Depending on $result
34a2777c 2053 */
2054function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
2055 global $OUTPUT;
2056
2057 if ($classes == 'green') {
2058 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
2059 $classes = 'notifysuccess'; // Backward compatible with old color system
2060 }
2061
2062 $output = $OUTPUT->notification($message, $classes);
2063 if ($return) {
2064 return $output;
2065 } else {
2066 echo $output;
2067 }
2068}
2069
2070/**
2071 * Print a continue button that goes to a particular URL.
2072 *
2073 * @param string $link The url to create a link to.
2074 * @param bool $return If set to true output is returned rather than echoed, default false
2075 * @return string|void HTML String if return=true nothing otherwise
2076 */
2077function print_continue($link, $return = false) {
2078 global $CFG, $OUTPUT;
2079
2080 if ($link == '') {
2081 if (!empty($_SERVER['HTTP_REFERER'])) {
2082 $link = $_SERVER['HTTP_REFERER'];
2083 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
2084 } else {
2085 $link = $CFG->wwwroot .'/';
2086 }
2087 }
2088
2089 $output = $OUTPUT->continue_button($link);
2090 if ($return) {
2091 return $output;
2092 } else {
2093 echo $output;
2094 }
2095}
2096
2097/**
2098 * Returns a string containing a link to the user documentation for the current
2099 * page. Also contains an icon by default. Shown to teachers and admin only.
2100 *
2101 * @global object
2102 * @global object
2103 * @param string $text The text to be displayed for the link
2104 * @param string $iconpath The path to the icon to be displayed
2105 * @return string The link to user documentation for this current page
2106 */
2107function page_doc_link($text='', $iconpath='') {
2108 global $CFG, $PAGE;
2109
2110 if (empty($CFG->docroot) || during_initial_install()) {
2111 return '';
2112 }
2113 if (!has_capability('moodle/site:doclinks', $PAGE->context)) {
2114 return '';
2115 }
2116
2117 $path = $PAGE->docspath;
2118 if (!$path) {
2119 return '';
2120 }
2121 return doc_link($path, $text, $iconpath);
2122}
2123
2124/**
2125 * Print a standard header
2126 *
2127 * @param string $title Appears at the top of the window
2128 * @param string $heading Appears at the top of the page
2129 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
2130 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2131 * @param string $meta Meta tags to be added to the header
2132 * @param boolean $cache Should this page be cacheable?
2133 * @param string $button HTML code for a button (usually for module editing)
2134 * @param string $menu HTML code for a popup menu
2135 * @param boolean $usexml use XML for this page
2136 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2137 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2138 * @return string|void If return=true then string else void
2139 */
2140function print_header($title='', $heading='', $navigation='', $focus='',
2141 $meta='', $cache=true, $button='&nbsp;', $menu='',
2142 $usexml=false, $bodytags='', $return=false) {
2143 global $PAGE, $OUTPUT;
2144
2145 $PAGE->set_title($title);
2146 $PAGE->set_heading($heading);
2147 $PAGE->set_cacheable($cache);
2148 $PAGE->set_focuscontrol($focus);
2149 if ($button == '') {
2150 $button = '&nbsp;';
2151 }
2152 $PAGE->set_button($button);
2153
2154 if ($navigation == 'home') {
2155 $navigation = '';
2156 }
2157 if (gettype($navigation) == 'string' && strlen($navigation) != 0 && $navigation != 'home') {
2158 debugging("print_header() was sent a string as 3rd ($navigation) parameter. "
2159 . "This is deprecated in favour of an array built by build_navigation(). Please upgrade your code.", DEBUG_DEVELOPER);
2160 }
2161
2162 // TODO $navigation
2163 // TODO $menu
2164
2165 if ($meta) {
2166 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
e29380f3 2167 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
34a2777c 2168 }
2169 if ($usexml) {
2170 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2171 }
2172 if ($bodytags) {
2173 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2174 }
2175
2176 $output = $OUTPUT->header($navigation, $menu);
2177
2178 if ($return) {
2179 return $output;
2180 } else {
2181 echo $output;
2182 }
2183}
2184
2185function print_footer($course = NULL, $usercourse = NULL, $return = false) {
2186 global $PAGE, $OUTPUT;
2187 // TODO check arguments.
2188 if (is_string($course)) {
2189 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
2190 'To achieve a similar effect, call $PAGE->set_generaltype before you call print_header.', DEBUG_DEVELOPER);
2191 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
2192 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
2193 }
2194 if (!is_null($usercourse)) {
2195 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
2196 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
2197 }
2198 $output = $OUTPUT->footer();
2199 if ($return) {
2200 return $output;
2201 } else {
2202 echo $output;
2203 }
a5cb8d69 2204}
2205
2206/**
2207 * Prints a nice side block with an optional header. The content can either
2208 * be a block of HTML or a list of text with optional icons.
2209 *
2210 * @todo Finish documenting this function. Show example of various attributes, etc.
2211 *
2212 * @static int $block_id Increments for each call to the function
2213 * @param string $heading HTML for the heading. Can include full HTML or just
2214 * plain text - plain text will automatically be enclosed in the appropriate
2215 * heading tags.
2216 * @param string $content HTML for the content
2217 * @param array $list an alternative to $content, it you want a list of things with optional icons.
2218 * @param array $icons optional icons for the things in $list.
2219 * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
2220 * @param array $attributes an array of attribute => value pairs that are put on the
2221 * outer div of this block. If there is a class attribute ' sideblock' gets appended to it. If there isn't
2222 * already a class, class='sideblock' is used.
2223 * @param string $title Plain text title, as embedded in the $heading.
2224 * @deprecated
2225 */
2226function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
2227 global $OUTPUT;
d4a03c00 2228
2229 // We don't use $heading, becuse it often contains HTML that we don't want.
2230 // However, sometimes $title is not set, but $heading is.
2231 if (empty($title)) {
2232 $title = strip_tags($heading);
2233 }
2234
2235 // Render list contents to HTML if required.
2236 if (empty($content) && $list) {
2237 $content = $OUTPUT->list_block_contents($icons, $list);
2238 }
2239
a5cb8d69 2240 $bc = new block_contents();
a5cb8d69 2241 $bc->content = $content;
a5cb8d69 2242 $bc->footer = $footer;
2243 $bc->title = $title;
2244
2245 if (isset($attributes['id'])) {
2246 $bc->id = $attributes['id'];
2247 unset($attributes['id']);
2248 }
2249 if (isset($attributes['class'])) {
2250 $bc->set_classes($attributes['class']);
2251 unset($attributes['class']);
2252 }
2253 $bc->attributes = $attributes;
2254
3ceb6910 2255 echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
a5cb8d69 2256}
2257
2258/**
2259 * Starts a nice side block with an optional header.
2260 *
2261 * @todo Finish documenting this function
2262 *
2263 * @global object
2264 * @global object
2265 * @param string $heading HTML for the heading. Can include full HTML or just
2266 * plain text - plain text will automatically be enclosed in the appropriate
2267 * heading tags.
2268 * @param array $attributes HTML attributes to apply if possible
2269 * @deprecated
2270 */
2271function print_side_block_start($heading='', $attributes = array()) {
3ceb6910 2272 throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
a5cb8d69 2273}
2274
2275/**
2276 * Print table ending tags for a side block box.
2277 *
2278 * @global object
2279 * @global object
2280 * @param array $attributes HTML attributes to apply if possible [id]
2281 * @param string $title
2282 * @deprecated
2283 */
2284function print_side_block_end($attributes = array(), $title='') {
3ceb6910 2285 throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
a5cb8d69 2286}
d4a03c00 2287
2288/**
2289 * This was used by old code to see whether a block region had anything in it,
2290 * and hence wether that region should be printed.
2291 *
2292 * We don't ever want old code to print blocks, so we now always return false.
2293 * The function only exists to avoid fatal errors in old code.
2294 *
2295 * @deprecated since Moodle 2.0. always returns false.
2296 *
2297 * @param object $blockmanager
2298 * @param string $region
2299 * @return bool
2300 */
2301function blocks_have_content(&$blockmanager, $region) {
2302 debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
2303 return false;
2304}
2305
2306/**
2307 * This was used by old code to print the blocks in a region.
2308 *
2309 * We don't ever want old code to print blocks, so this is now a no-op.
2310 * The function only exists to avoid fatal errors in old code.
2311 *
2312 * @deprecated since Moodle 2.0. does nothing.
2313 *
2314 * @param object $page
2315 * @param object $blockmanager
2316 * @param string $region
2317 */
2318function blocks_print_group($page, $blockmanager, $region) {
2319 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2320}
2321
2322/**
2323 * This used to be the old entry point for anyone that wants to use blocks.
2324 * Since we don't want people people dealing with blocks this way any more,
2325 * just return a suitable empty array.
2326 *
2327 * @deprecated since Moodle 2.0.
2328 *
2329 * @param object $page
2330 * @return array
2331 */
2332function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
2333 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2334 return array(BLOCK_POS_LEFT => array(), BLOCK_POS_RIGHT => array());
2335}
2336
2337/**
2338 * This iterates over an array of blocks and calculates the preferred width
2339 * Parameter passed by reference for speed; it's not modified.
2340 *
2341 * @deprecated since Moodle 2.0. Layout is now controlled by the theme.
2342 *
2343 * @param mixed $instances
2344 */
2345function blocks_preferred_width($instances) {
2346 debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
2347 $width = 210;
2348}
2349
480b0720 2350/**
2351 * Print a nicely formatted table.
2352 *
2353 * @deprecated since Moodle 2.0
2354 *
2355 * @param array $table is an object with several properties.
2356 */
2357function print_table($table, $return=false) {
2358 global $OUTPUT;
2359 // TODO MDL-19755 turn debugging on once we migrate the current core code to use the new API
2360 // debugging('print_table() has been deprecated. Please change your code to use $OUTPUT->table().');
2361 $newtable = new html_table();
2362 foreach ($table as $property => $value) {
2363 if (property_exists($newtable, $property)) {
2364 $newtable->{$property} = $value;
2365 }
2366 }
2367 if (isset($table->class)) {
2368 $newtable->set_classes($table->class);
2369 }
2370 if (isset($table->rowclass) && is_array($table->rowclass)) {
2371 debugging('rowclass[] has been deprecated for html_table and should be replaced by rowclasses[]. please fix the code.');
2372 $newtable->rowclasses = $table->rowclass;
2373 }
2374 $output = $OUTPUT->table($newtable);
2375 if ($return) {
2376 return $output;
2377 } else {
2378 echo $output;
2379 return true;
2380 }
2381}