filter-mediaplugin MDL-16706 Replaced inline JS with new PAGE methods and created...
[moodle.git] / lib / deprecatedlib.php
CommitLineData
c861fe2f 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
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.
14//
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 *
c861fe2f 133 * @todo Is object(user) a correct return type? Or is array the proper return type with a
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) {
34a2777c 246 debugging('print_simple_box(_star/_end) is deprecated. Please use $OUTPUT->box(_star/_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
1570
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 *
1730 * This funciton has been deprecated by the file API changes in Moodle 2.0.
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
8954245a 1742/**
1743 * Prints some red text using echo
1744 *
1745 * @deprecated
1746 * @param string $error The text to be displayed in red
1747 */
1748function formerr($error) {
1749 global $OUTPUT;
1750 echo $OUTPUT->error_text($error);
1751}
1752
34a2777c 1753/**
1754 * Return the markup for the destination of the 'Skip to main content' links.
1755 * Accessibility improvement for keyboard-only users.
1756 *
1757 * Used in course formats, /index.php and /course/index.php
1758 *
1759 * @deprecated use $OUTPUT->skip_link_target() in instead.
1760 * @return string HTML element.
1761 */
1762function skip_main_destination() {
1763 global $OUTPUT;
1764 return $OUTPUT->skip_link_target();
1765}
1766
1767/**
1768 * Prints a string in a specified size (retained for backward compatibility)
1769 *
1770 * @deprecated
1771 * @param string $text The text to be displayed
1772 * @param int $size The size to set the font for text display.
1773 * @param bool $return If set to true output is returned rather than echoed Default false
1774 * @return string|void String if return is true
1775 */
1776function print_headline($text, $size=2, $return=false) {
1777 global $OUTPUT;
1778 $output = $OUTPUT->heading($text, $size);
1779 if ($return) {
1780 return $output;
1781 } else {
1782 echo $output;
1783 }
1784}
1785
1786/**
1787 * Prints text in a format for use in headings.
1788 *
1789 * @deprecated
1790 * @param string $text The text to be displayed
1791 * @param string $deprecated No longer used. (Use to do alignment.)
1792 * @param int $size The size to set the font for text display.
1793 * @param string $class
1794 * @param bool $return If set to true output is returned rather than echoed, default false
1795 * @param string $id The id to use in the element
1796 * @return string|void String if return=true nothing otherwise
1797 */
1798function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
1799 global $OUTPUT;
1800 if (!empty($deprecated)) {
1801 debugging('Use of deprecated align attribute of print_heading. ' .
1802 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
1803 }
1804 $output = $OUTPUT->heading($text, $size, $class, $id);
1805 if ($return) {
1806 return $output;
1807 } else {
1808 echo $output;
1809 }
1810}
1811
1812/**
1813 * Output a standard heading block
1814 *
1815 * @deprecated
1816 * @param string $heading The text to write into the heading
1817 * @param string $class An additional Class Attr to use for the heading
1818 * @param bool $return If set to true output is returned rather than echoed, default false
1819 * @return string|void HTML String if return=true nothing otherwise
1820 */
1821function print_heading_block($heading, $class='', $return=false) {
1822 global $OUTPUT;
1823 $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . moodle_renderer_base::prepare_classes($class));
1824 if ($return) {
1825 return $output;
1826 } else {
1827 echo $output;
1828 }
1829}
1830
1831/**
1832 * Print a message in a standard themed box.
1833 * Replaces print_simple_box (see deprecatedlib.php)
1834 *
1835 * @deprecated
1836 * @param string $message, the content of the box
1837 * @param string $classes, space-separated class names.
1838 * @param string $ids
1839 * @param boolean $return, return as string or just print it
1840 * @return string|void mixed string or void
1841 */
1842function print_box($message, $classes='generalbox', $ids='', $return=false) {
1843 global $OUTPUT;
1844 $output = $OUTPUT->box($message, $classes, $ids);
1845 if ($return) {
1846 return $output;
1847 } else {
1848 echo $output;
1849 }
1850}
1851
1852/**
1853 * Starts a box using divs
1854 * Replaces print_simple_box_start (see deprecatedlib.php)
1855 *
1856 * @deprecated
1857 * @param string $classes, space-separated class names.
1858 * @param string $ids
1859 * @param boolean $return, return as string or just print it
1860 * @return string|void string or void
1861 */
1862function print_box_start($classes='generalbox', $ids='', $return=false) {
1863 global $OUTPUT;
1864 $output = $OUTPUT->box_start($classes, $ids);
1865 if ($return) {
1866 return $output;
1867 } else {
1868 echo $output;
1869 }
1870}
1871
1872/**
1873 * Simple function to end a box (see above)
1874 * Replaces print_simple_box_end (see deprecatedlib.php)
1875 *
1876 * @deprecated
1877 * @param boolean $return, return as string or just print it
1878 * @return string|void Depending on value of return
1879 */
1880function print_box_end($return=false) {
1881 global $OUTPUT;
1882 $output = $OUTPUT->box_end();
1883 if ($return) {
1884 return $output;
1885 } else {
1886 echo $output;
1887 }
1888}
1889
1890/**
1891 * Print a message in a standard themed container.
1892 *
1893 * @deprecated
1894 * @param string $message, the content of the container
1895 * @param boolean $clearfix clear both sides
1896 * @param string $classes, space-separated class names.
1897 * @param string $idbase
1898 * @param boolean $return, return as string or just print it
1899 * @return string|void Depending on value of $return
1900 */
1901function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
1902 global $OUTPUT;
1903 if ($clearfix) {
1904 $classes .= ' clearfix';
1905 }
1906 $output = $OUTPUT->container($message, $classes, $idbase);
1907 if ($return) {
1908 return $output;
1909 } else {
1910 echo $output;
1911 }
1912}
1913
1914/**
1915 * Starts a container using divs
1916 *
1917 * @deprecated
1918 * @param boolean $clearfix clear both sides
1919 * @param string $classes, space-separated class names.
1920 * @param string $idbase
1921 * @param boolean $return, return as string or just print it
1922 * @return string|void Based on value of $return
1923 */
1924function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
1925 global $OUTPUT;
1926 if ($clearfix) {
1927 $classes .= ' clearfix';
1928 }
1929 $output = $OUTPUT->container_start($classes, $idbase);
1930 if ($return) {
1931 return $output;
1932 } else {
1933 echo $output;
1934 }
1935}
1936
1937/**
1938 * Simple function to end a container (see above)
1939 *
1940 * @deprecated
1941 * @param boolean $return, return as string or just print it
1942 * @return string|void Based on $return
1943 */
1944function print_container_end($return=false) {
1945 global $OUTPUT;
1946 $output = $OUTPUT->container_end();
1947 if ($return) {
1948 return $output;
1949 } else {
1950 echo $output;
1951 }
1952}
1953
1954/**
1955 * Print a bold message in an optional color.
1956 *
1957 * @deprecated use $OUTPUT->notification instead.
1958 * @param string $message The message to print out
1959 * @param string $style Optional style to display message text in
1960 * @param string $align Alignment option
1961 * @param bool $return whether to return an output string or echo now
1962 * @return string|bool Depending on $result
1963 */
1964function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
1965 global $OUTPUT;
1966
1967 if ($classes == 'green') {
1968 debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
1969 $classes = 'notifysuccess'; // Backward compatible with old color system
1970 }
1971
1972 $output = $OUTPUT->notification($message, $classes);
1973 if ($return) {
1974 return $output;
1975 } else {
1976 echo $output;
1977 }
1978}
1979
1980/**
1981 * Print a continue button that goes to a particular URL.
1982 *
1983 * @param string $link The url to create a link to.
1984 * @param bool $return If set to true output is returned rather than echoed, default false
1985 * @return string|void HTML String if return=true nothing otherwise
1986 */
1987function print_continue($link, $return = false) {
1988 global $CFG, $OUTPUT;
1989
1990 if ($link == '') {
1991 if (!empty($_SERVER['HTTP_REFERER'])) {
1992 $link = $_SERVER['HTTP_REFERER'];
1993 $link = str_replace('&', '&amp;', $link); // make it valid XHTML
1994 } else {
1995 $link = $CFG->wwwroot .'/';
1996 }
1997 }
1998
1999 $output = $OUTPUT->continue_button($link);
2000 if ($return) {
2001 return $output;
2002 } else {
2003 echo $output;
2004 }
2005}
2006
2007/**
2008 * Returns a string containing a link to the user documentation for the current
2009 * page. Also contains an icon by default. Shown to teachers and admin only.
2010 *
2011 * @global object
2012 * @global object
2013 * @param string $text The text to be displayed for the link
2014 * @param string $iconpath The path to the icon to be displayed
2015 * @return string The link to user documentation for this current page
2016 */
2017function page_doc_link($text='', $iconpath='') {
2018 global $CFG, $PAGE;
2019
2020 if (empty($CFG->docroot) || during_initial_install()) {
2021 return '';
2022 }
2023 if (!has_capability('moodle/site:doclinks', $PAGE->context)) {
2024 return '';
2025 }
2026
2027 $path = $PAGE->docspath;
2028 if (!$path) {
2029 return '';
2030 }
2031 return doc_link($path, $text, $iconpath);
2032}
2033
2034/**
2035 * Print a standard header
2036 *
2037 * @param string $title Appears at the top of the window
2038 * @param string $heading Appears at the top of the page
2039 * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
2040 * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
2041 * @param string $meta Meta tags to be added to the header
2042 * @param boolean $cache Should this page be cacheable?
2043 * @param string $button HTML code for a button (usually for module editing)
2044 * @param string $menu HTML code for a popup menu
2045 * @param boolean $usexml use XML for this page
2046 * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
2047 * @param bool $return If true, return the visible elements of the header instead of echoing them.
2048 * @return string|void If return=true then string else void
2049 */
2050function print_header($title='', $heading='', $navigation='', $focus='',
2051 $meta='', $cache=true, $button='&nbsp;', $menu='',
2052 $usexml=false, $bodytags='', $return=false) {
2053 global $PAGE, $OUTPUT;
2054
2055 $PAGE->set_title($title);
2056 $PAGE->set_heading($heading);
2057 $PAGE->set_cacheable($cache);
2058 $PAGE->set_focuscontrol($focus);
2059 if ($button == '') {
2060 $button = '&nbsp;';
2061 }
2062 $PAGE->set_button($button);
2063
2064 if ($navigation == 'home') {
2065 $navigation = '';
2066 }
2067 if (gettype($navigation) == 'string' && strlen($navigation) != 0 && $navigation != 'home') {
2068 debugging("print_header() was sent a string as 3rd ($navigation) parameter. "
2069 . "This is deprecated in favour of an array built by build_navigation(). Please upgrade your code.", DEBUG_DEVELOPER);
2070 }
2071
2072 // TODO $navigation
2073 // TODO $menu
2074
2075 if ($meta) {
2076 throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
e29380f3 2077 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
34a2777c 2078 }
2079 if ($usexml) {
2080 throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
2081 }
2082 if ($bodytags) {
2083 throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
2084 }
2085
2086 $output = $OUTPUT->header($navigation, $menu);
2087
2088 if ($return) {
2089 return $output;
2090 } else {
2091 echo $output;
2092 }
2093}
2094
2095function print_footer($course = NULL, $usercourse = NULL, $return = false) {
2096 global $PAGE, $OUTPUT;
2097 // TODO check arguments.
2098 if (is_string($course)) {
2099 debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
2100 'To achieve a similar effect, call $PAGE->set_generaltype before you call print_header.', DEBUG_DEVELOPER);
2101 } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
2102 throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
2103 }
2104 if (!is_null($usercourse)) {
2105 debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
2106 '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
2107 }
2108 $output = $OUTPUT->footer();
2109 if ($return) {
2110 return $output;
2111 } else {
2112 echo $output;
2113 }
2114}