c4d0753b |
1 | <?php // $Id$ |
2 | |
3 | /////////////////////////////////////////////////////////////////////////// |
4 | // // |
5 | // NOTICE OF COPYRIGHT // |
6 | // // |
7 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // |
8 | // http://moodle.org // |
9 | // // |
73f7ad71 |
10 | // Copyright (C) 1999 onwards Martin Dougiamas, Moodle http://moodle.com// |
c4d0753b |
11 | // // |
12 | // This program is free software; you can redistribute it and/or modify // |
13 | // it under the terms of the GNU General Public License as published by // |
14 | // the Free Software Foundation; either version 2 of the License, or // |
15 | // (at your option) any later version. // |
16 | // // |
17 | // This program is distributed in the hope that it will be useful, // |
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
20 | // GNU General Public License for more details: // |
21 | // // |
22 | // http://www.gnu.org/copyleft/gpl.html // |
23 | // // |
24 | /////////////////////////////////////////////////////////////////////////// |
25 | |
26 | /** |
27 | * deprecatedlib.php - Old functions retained only for backward compatibility |
28 | * |
29 | * Old functions retained only for backward compatibility. New code should not |
30 | * use any of these functions. |
31 | * |
32 | * @author Martin Dougiamas |
33 | * @version $Id$ |
34 | * @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
35 | * @package moodlecore |
36 | */ |
37 | |
c4d0753b |
38 | /** |
39 | * Determines if a user is a teacher (or better) |
40 | * |
c4d0753b |
41 | * @uses $CFG |
42 | * @param int $courseid The id of the course that is being viewed, if any |
43 | * @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. |
44 | * @param bool $obsolete_includeadmin Not used any more |
45 | * @return bool |
46 | */ |
47 | |
48 | function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) { |
49 | /// Is the user able to access this course as a teacher? |
c2da0757 |
50 | global $CFG; |
c4d0753b |
51 | |
52 | if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7 |
53 | return false; |
54 | } |
55 | |
56 | if ($courseid) { |
57 | $context = get_context_instance(CONTEXT_COURSE, $courseid); |
58 | } else { |
12d06877 |
59 | $context = get_context_instance(CONTEXT_SYSTEM); |
c4d0753b |
60 | } |
61 | |
c2da0757 |
62 | return (has_capability('moodle/legacy:teacher', $context, $userid, false) |
63 | or has_capability('moodle/legacy:editingteacher', $context, $userid, false) |
64 | or has_capability('moodle/legacy:admin', $context, $userid, false)); |
c4d0753b |
65 | } |
66 | |
67 | /** |
68 | * Determines if a user is a teacher in any course, or an admin |
69 | * |
70 | * @uses $USER |
71 | * @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 |
72 | * @param bool $includeadmin Include anyone wo is an admin as well |
c4d0753b |
73 | * @return bool |
74 | */ |
c2da0757 |
75 | function isteacherinanycourse($userid=0, $includeadmin=true) { |
79eaec48 |
76 | global $USER, $CFG, $DB; |
c4d0753b |
77 | |
78 | if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7 |
79 | return false; |
80 | } |
81 | |
82 | if (!$userid) { |
83 | if (empty($USER->id)) { |
84 | return false; |
85 | } |
86 | $userid = $USER->id; |
87 | } |
88 | |
79eaec48 |
89 | if (!$DB->record_exists('role_assignments', array('userid'=>$userid))) { // Has no roles anywhere |
c4d0753b |
90 | return false; |
91 | } |
92 | |
93 | /// If this user is assigned as an editing teacher anywhere then return true |
94 | if ($roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW)) { |
95 | foreach ($roles as $role) { |
79eaec48 |
96 | if ($DB->record_exists('role_assignments', array('roleid'=>$role->id, 'userid'=>$userid))) { |
c4d0753b |
97 | return true; |
98 | } |
99 | } |
100 | } |
101 | |
102 | /// If this user is assigned as a non-editing teacher anywhere then return true |
103 | if ($roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) { |
104 | foreach ($roles as $role) { |
79eaec48 |
105 | if ($DB->record_exists('role_assignments', array('roleid'=>$role->id, 'userid'=>$userid))) { |
c4d0753b |
106 | return true; |
107 | } |
108 | } |
109 | } |
110 | |
c2da0757 |
111 | /// Include admins if required |
112 | if ($includeadmin) { |
12d06877 |
113 | $context = get_context_instance(CONTEXT_SYSTEM); |
c2da0757 |
114 | if (has_capability('moodle/legacy:admin', $context, $userid, false)) { |
115 | return true; |
116 | } |
117 | } |
c4d0753b |
118 | |
119 | return false; |
120 | } |
121 | |
c4d0753b |
122 | |
123 | /** |
124 | * Determines if the specified user is logged in as guest. |
125 | * |
c4d0753b |
126 | * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user. |
127 | * @return bool |
128 | */ |
129 | function isguest($userid=0) { |
c2da0757 |
130 | global $CFG; |
c4d0753b |
131 | |
132 | if (empty($CFG->rolesactive)) { |
133 | return false; |
134 | } |
135 | |
364fffda |
136 | $context = get_context_instance(CONTEXT_SYSTEM); |
c4d0753b |
137 | |
c2da0757 |
138 | return has_capability('moodle/legacy:guest', $context, $userid, false); |
c4d0753b |
139 | } |
140 | |
613bbd7c |
141 | |
142 | /** |
143 | * Get the guest user information from the database |
144 | * |
145 | * @return object(user) An associative array with the details of the guest user account. |
146 | * @todo Is object(user) a correct return type? Or is array the proper return type with a note that the contents include all details for a user. |
147 | */ |
148 | function get_guest() { |
149 | return get_complete_user_data('username', 'guest'); |
150 | } |
151 | |
613bbd7c |
152 | /** |
153 | * Returns $user object of the main teacher for a course |
154 | * |
155 | * @uses $CFG |
156 | * @param int $courseid The course in question. |
157 | * @return user|false A {@link $USER} record of the main teacher for the specified course or false if error. |
158 | * @todo Finish documenting this function |
159 | */ |
160 | function get_teacher($courseid) { |
161 | |
162 | global $CFG; |
163 | |
888fb649 |
164 | $context = get_context_instance(CONTEXT_COURSE, $courseid); |
165 | |
1113f800 |
166 | // Pass $view=true to filter hidden caps if the user cannot see them |
167 | if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', |
168 | '', '', '', '', false, true)) { |
b1469317 |
169 | $users = sort_by_roleassignment_authority($users, $context); |
1113f800 |
170 | return array_shift($users); |
613bbd7c |
171 | } |
888fb649 |
172 | |
173 | return false; |
613bbd7c |
174 | } |
175 | |
176 | /** |
177 | * Searches logs to find all enrolments since a certain date |
178 | * |
179 | * used to print recent activity |
180 | * |
181 | * @uses $CFG |
182 | * @param int $courseid The course in question. |
183 | * @return object|false {@link $USER} records or false if error. |
184 | * @todo Finish documenting this function |
185 | */ |
186 | function get_recent_enrolments($courseid, $timestart) { |
10df888a |
187 | global $DB; |
364fffda |
188 | |
71dea306 |
189 | $context = get_context_instance(CONTEXT_COURSE, $courseid); |
613bbd7c |
190 | |
10df888a |
191 | $sql = "SELECT DISTINCT u.id, u.firstname, u.lastname, l.time |
192 | FROM {user} u, {role_assignments} ra, {log} l |
193 | WHERE l.time > ? |
194 | AND l.course = ? |
195 | AND l.module = 'course' |
196 | AND l.action = 'enrol' |
9f43d70d |
197 | AND ".$DB->sql_cast_char2int('l.info')." = u.id |
10df888a |
198 | AND u.id = ra.userid |
199 | AND ra.contextid ".get_related_contexts_string($context)." |
200 | ORDER BY l.time ASC"; |
201 | $params = array($timestart, $courseid); |
202 | return $DB->get_records_sql($sql, $params); |
613bbd7c |
203 | } |
204 | |
2123b644 |
205 | ########### FROM weblib.php ########################################################################## |
206 | |
207 | |
208 | /** |
209 | * Print a message in a standard themed box. |
364fffda |
210 | * This old function used to implement boxes using tables. Now it uses a DIV, but the old |
2123b644 |
211 | * parameters remain. If possible, $align, $width and $color should not be defined at all. |
212 | * Preferably just use print_box() in weblib.php |
213 | * |
214 | * @param string $align, alignment of the box, not the text (default center, left, right). |
215 | * @param string $width, width of the box, including units %, for example '100%'. |
216 | * @param string $color, background colour of the box, for example '#eee'. |
217 | * @param int $padding, padding in pixels, specified without units. |
218 | * @param string $class, space-separated class names. |
219 | * @param string $id, space-separated id names. |
220 | * @param boolean $return, return as string or just print it |
221 | */ |
222 | function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) { |
223 | $output = ''; |
224 | $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true); |
294ce987 |
225 | $output .= $message; |
2123b644 |
226 | $output .= print_simple_box_end(true); |
227 | |
228 | if ($return) { |
229 | return $output; |
230 | } else { |
231 | echo $output; |
232 | } |
233 | } |
234 | |
235 | |
236 | |
237 | /** |
364fffda |
238 | * This old function used to implement boxes using tables. Now it uses a DIV, but the old |
2123b644 |
239 | * parameters remain. If possible, $align, $width and $color should not be defined at all. |
240 | * Even better, please use print_box_start() in weblib.php |
241 | * |
242 | * @param string $align, alignment of the box, not the text (default center, left, right). DEPRECATED |
243 | * @param string $width, width of the box, including % units, for example '100%'. DEPRECATED |
244 | * @param string $color, background colour of the box, for example '#eee'. DEPRECATED |
245 | * @param int $padding, padding in pixels, specified without units. OBSOLETE |
246 | * @param string $class, space-separated class names. |
247 | * @param string $id, space-separated id names. |
248 | * @param boolean $return, return as string or just print it |
249 | */ |
250 | function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) { |
251 | |
252 | $output = ''; |
253 | |
8f36e33e |
254 | $divclasses = 'box '.$class.' '.$class.'content'; |
2123b644 |
255 | $divstyles = ''; |
256 | |
257 | if ($align) { |
258 | $divclasses .= ' boxalign'.$align; // Implement alignment using a class |
259 | } |
260 | if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad) |
8f36e33e |
261 | if (substr($width, -1, 1) == '%') { // Width is a % value |
262 | $width = (int) substr($width, 0, -1); // Extract just the number |
263 | if ($width < 40) { |
264 | $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme |
265 | } else if ($width > 60) { |
266 | $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme |
267 | } else { |
268 | $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme |
269 | } |
270 | } else { |
271 | $divstyles .= ' width:'.$width.';'; // Last resort |
272 | } |
2123b644 |
273 | } |
274 | if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad) |
275 | $divstyles .= ' background:'.$color.';'; |
276 | } |
277 | if ($divstyles) { |
278 | $divstyles = ' style="'.$divstyles.'"'; |
279 | } |
280 | |
281 | if ($id) { |
282 | $id = ' id="'.$id.'"'; |
283 | } |
284 | |
285 | $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">'; |
286 | |
287 | if ($return) { |
288 | return $output; |
289 | } else { |
290 | echo $output; |
291 | } |
292 | } |
293 | |
294 | |
295 | /** |
296 | * Print the end portion of a standard themed box. |
297 | * Preferably just use print_box_end() in weblib.php |
298 | */ |
299 | function print_simple_box_end($return=false) { |
300 | $output = '</div>'; |
301 | if ($return) { |
302 | return $output; |
303 | } else { |
304 | echo $output; |
305 | } |
306 | } |
307 | |
ed5dd29f |
308 | /** |
309 | * deprecated - use clean_param($string, PARAM_FILE); instead |
310 | * Check for bad characters ? |
311 | * |
312 | * @param string $string ? |
313 | * @param int $allowdots ? |
314 | * @todo Finish documenting this function - more detail needed in description as well as details on arguments |
315 | */ |
316 | function detect_munged_arguments($string, $allowdots=1) { |
317 | if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references |
318 | return true; |
319 | } |
320 | if (ereg('[\|\`]', $string)) { // check for other bad characters |
321 | return true; |
322 | } |
323 | if (empty($string) or $string == '/') { |
324 | return true; |
325 | } |
326 | |
327 | return false; |
328 | } |
329 | |
9152fc99 |
330 | |
0c6d2dd4 |
331 | /** |
332 | * Unzip one zip file to a destination dir |
333 | * Both parameters must be FULL paths |
334 | * If destination isn't specified, it will be the |
335 | * SAME directory where the zip file resides. |
336 | */ |
337 | function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) { |
338 | global $CFG; |
339 | |
340 | //Extract everything from zipfile |
341 | $path_parts = pathinfo(cleardoubleslashes($zipfile)); |
342 | $zippath = $path_parts["dirname"]; //The path of the zip file |
343 | $zipfilename = $path_parts["basename"]; //The name of the zip file |
344 | $extension = $path_parts["extension"]; //The extension of the file |
345 | |
346 | //If no file, error |
347 | if (empty($zipfilename)) { |
348 | return false; |
349 | } |
350 | |
351 | //If no extension, error |
352 | if (empty($extension)) { |
353 | return false; |
354 | } |
355 | |
356 | //Clear $zipfile |
357 | $zipfile = cleardoubleslashes($zipfile); |
358 | |
359 | //Check zipfile exists |
360 | if (!file_exists($zipfile)) { |
361 | return false; |
362 | } |
363 | |
364 | //If no destination, passed let's go with the same directory |
365 | if (empty($destination)) { |
366 | $destination = $zippath; |
367 | } |
368 | |
369 | //Clear $destination |
370 | $destpath = rtrim(cleardoubleslashes($destination), "/"); |
371 | |
372 | //Check destination path exists |
373 | if (!is_dir($destpath)) { |
374 | return false; |
375 | } |
376 | |
377 | $result = get_file_packer()->unzip_files_to_pathname($zipfile, $destpath); |
378 | |
379 | if ($result === false) { |
380 | return false; |
381 | } |
382 | |
383 | foreach ($result as $status) { |
384 | if ($status !== true) { |
385 | return false; |
386 | } |
387 | } |
388 | |
389 | return true; |
390 | } |
391 | |
ed5dd29f |
392 | ///////////////////////////////////////////////////////////// |
393 | /// Old functions not used anymore - candidates for removal |
394 | ///////////////////////////////////////////////////////////// |
395 | |
ed5dd29f |
396 | |
1d684195 |
397 | /** various deprecated groups function **/ |
398 | |
399 | |
5bf243d1 |
400 | /** |
401 | * Get the IDs for the user's groups in the given course. |
402 | * |
403 | * @uses $USER |
404 | * @param int $courseid The course being examined - the 'course' table id field. |
405 | * @return array An _array_ of groupids. |
406 | * (Was return $groupids[0] - consequences!) |
407 | */ |
408 | function mygroupid($courseid) { |
409 | global $USER; |
410 | if ($groups = groups_get_all_groups($courseid, $USER->id)) { |
411 | return array_keys($groups); |
412 | } else { |
413 | return false; |
414 | } |
415 | } |
416 | |
5bf243d1 |
417 | |
5bf243d1 |
418 | /** |
419 | * Returns the current group mode for a given course or activity module |
364fffda |
420 | * |
5bf243d1 |
421 | * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin) |
422 | */ |
423 | function groupmode($course, $cm=null) { |
424 | |
425 | if (isset($cm->groupmode) && empty($course->groupmodeforce)) { |
426 | return $cm->groupmode; |
427 | } |
428 | return $course->groupmode; |
429 | } |
430 | |
c584346c |
431 | /** |
432 | * Sets the current group in the session variable |
433 | * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups. |
434 | * Sets currentgroup[$courseid] in the session variable appropriately. |
435 | * Does not do any permission checking. |
436 | * @uses $SESSION |
437 | * @param int $courseid The course being examined - relates to id field in |
438 | * 'course' table. |
439 | * @param int $groupid The group being examined. |
440 | * @return int Current group id which was set by this function |
441 | */ |
442 | function set_current_group($courseid, $groupid) { |
443 | global $SESSION; |
444 | return $SESSION->currentgroup[$courseid] = $groupid; |
445 | } |
446 | |
5bf243d1 |
447 | |
5bf243d1 |
448 | /** |
364fffda |
449 | * Gets the current group - either from the session variable or from the database. |
5bf243d1 |
450 | * |
451 | * @uses $USER |
452 | * @uses $SESSION |
364fffda |
453 | * @param int $courseid The course being examined - relates to id field in |
5bf243d1 |
454 | * 'course' table. |
364fffda |
455 | * @param bool $full If true, the return value is a full record object. |
5bf243d1 |
456 | * If false, just the id of the record. |
457 | */ |
458 | function get_current_group($courseid, $full = false) { |
459 | global $SESSION; |
460 | |
461 | if (isset($SESSION->currentgroup[$courseid])) { |
462 | if ($full) { |
463 | return groups_get_group($SESSION->currentgroup[$courseid]); |
464 | } else { |
465 | return $SESSION->currentgroup[$courseid]; |
466 | } |
467 | } |
468 | |
469 | $mygroupid = mygroupid($courseid); |
470 | if (is_array($mygroupid)) { |
471 | $mygroupid = array_shift($mygroupid); |
472 | set_current_group($courseid, $mygroupid); |
473 | if ($full) { |
474 | return groups_get_group($mygroupid); |
475 | } else { |
476 | return $mygroupid; |
477 | } |
478 | } |
479 | |
480 | if ($full) { |
481 | return false; |
482 | } else { |
483 | return 0; |
484 | } |
485 | } |
486 | |
487 | |
8ec50604 |
488 | /** |
489 | * Print an error page displaying an error message. |
490 | * Old method, don't call directly in new code - use print_error instead. |
491 | * |
8ec50604 |
492 | * @param string $message The message to display to the user about the error. |
493 | * @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. |
251387d0 |
494 | * @return terminates script, does not return! |
8ec50604 |
495 | */ |
245ac557 |
496 | function error($message, $link='') { |
251387d0 |
497 | global $UNITTEST; |
8ec50604 |
498 | |
251387d0 |
499 | // If unittest running, throw exception instead |
a230012c |
500 | if (!empty($UNITTEST->running)) { |
73f7ad71 |
501 | // Errors in unit test become exceptions, so you can unit test |
502 | // code that might call error(). |
251387d0 |
503 | throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message); |
8ec50604 |
504 | } |
505 | |
eee5d9bb |
506 | _print_normal_error('notlocalisederrormessage', 'error', $message, $link, debug_backtrace(), null, true); // show debug warning |
251387d0 |
507 | } |
8ec50604 |
508 | |
8ec50604 |
509 | |
b1f93b15 |
510 | /// Deprecated DDL functions, to be removed soon /// |
511 | |
512 | function table_exists($table) { |
513 | global $DB; |
514 | debugging('Deprecated ddllib function used!'); |
515 | return $DB->get_manager()->table_exists($table); |
516 | } |
517 | |
518 | function field_exists($table, $field) { |
519 | global $DB; |
520 | debugging('Deprecated ddllib function used!'); |
521 | return $DB->get_manager()->field_exists($table, $field); |
522 | } |
523 | |
524 | function find_index_name($table, $index) { |
525 | global $DB; |
526 | debugging('Deprecated ddllib function used!'); |
527 | return $DB->get_manager()->find_index_name($table, $index); |
528 | } |
529 | |
530 | function index_exists($table, $index) { |
531 | global $DB; |
532 | debugging('Deprecated ddllib function used!'); |
533 | return $DB->get_manager()->index_exists($table, $index); |
534 | } |
535 | |
536 | function find_check_constraint_name($table, $field) { |
537 | global $DB; |
538 | debugging('Deprecated ddllib function used!'); |
539 | return $DB->get_manager()->find_check_constraint_name($table, $field); |
540 | } |
541 | |
542 | function check_constraint_exists($table, $field) { |
543 | global $DB; |
544 | debugging('Deprecated ddllib function used!'); |
545 | return $DB->get_manager()->check_constraint_exists($table, $field); |
546 | } |
547 | |
548 | function find_key_name($table, $xmldb_key) { |
549 | global $DB; |
550 | debugging('Deprecated ddllib function used!'); |
551 | return $DB->get_manager()->find_key_name($table, $xmldb_key); |
552 | } |
553 | |
554 | function find_sequence_name($table) { |
555 | global $DB; |
556 | debugging('Deprecated ddllib function used!'); |
557 | return $DB->get_manager()->find_sequence_name($table); |
558 | } |
559 | |
eee5d9bb |
560 | function drop_table($table) { |
b1f93b15 |
561 | global $DB; |
562 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
563 | $DB->get_manager()->drop_table($table); |
564 | return true; |
b1f93b15 |
565 | } |
566 | |
567 | function install_from_xmldb_file($file) { |
568 | global $DB; |
569 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
570 | $DB->get_manager()->install_from_xmldb_file($file); |
571 | return true; |
b1f93b15 |
572 | } |
573 | |
eee5d9bb |
574 | function create_table($table) { |
b1f93b15 |
575 | global $DB; |
576 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
577 | $DB->get_manager()->create_table($table); |
578 | return true; |
b1f93b15 |
579 | } |
580 | |
eee5d9bb |
581 | function create_temp_table($table) { |
b1f93b15 |
582 | global $DB; |
583 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
584 | $DB->get_manager()->create_temp_table($table); |
585 | return true; |
b1f93b15 |
586 | } |
587 | |
eee5d9bb |
588 | function rename_table($table, $newname) { |
b1f93b15 |
589 | global $DB; |
590 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
591 | $DB->get_manager()->rename_table($table, $newname); |
592 | return true; |
b1f93b15 |
593 | } |
594 | |
eee5d9bb |
595 | function add_field($table, $field) { |
b1f93b15 |
596 | global $DB; |
597 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
598 | $DB->get_manager()->add_field($table, $field); |
599 | return true; |
b1f93b15 |
600 | } |
601 | |
eee5d9bb |
602 | function drop_field($table, $field) { |
b1f93b15 |
603 | global $DB; |
604 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
605 | $DB->get_manager()->drop_field($table, $field); |
606 | return true; |
b1f93b15 |
607 | } |
608 | |
eee5d9bb |
609 | function change_field_type($table, $field) { |
b1f93b15 |
610 | global $DB; |
611 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
612 | $DB->get_manager()->change_field_type($table, $field); |
613 | return true; |
b1f93b15 |
614 | } |
615 | |
eee5d9bb |
616 | function change_field_precision($table, $field) { |
b1f93b15 |
617 | global $DB; |
618 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
619 | $DB->get_manager()->change_field_precision($table, $field); |
620 | return true; |
b1f93b15 |
621 | } |
622 | |
eee5d9bb |
623 | function change_field_unsigned($table, $field) { |
b1f93b15 |
624 | global $DB; |
625 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
626 | $DB->get_manager()->change_field_unsigned($table, $field); |
627 | return true; |
b1f93b15 |
628 | } |
629 | |
eee5d9bb |
630 | function change_field_notnull($table, $field) { |
b1f93b15 |
631 | global $DB; |
632 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
633 | $DB->get_manager()->change_field_notnull($table, $field); |
634 | return true; |
b1f93b15 |
635 | } |
636 | |
eee5d9bb |
637 | function change_field_enum($table, $field) { |
b1f93b15 |
638 | global $DB; |
639 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
640 | $DB->get_manager()->change_field_enum($table, $field); |
641 | return true; |
b1f93b15 |
642 | } |
643 | |
eee5d9bb |
644 | function change_field_default($table, $field) { |
b1f93b15 |
645 | global $DB; |
646 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
647 | $DB->get_manager()->change_field_default($table, $field); |
648 | return true; |
b1f93b15 |
649 | } |
650 | |
eee5d9bb |
651 | function rename_field($table, $field, $newname) { |
b1f93b15 |
652 | global $DB; |
653 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
654 | $DB->get_manager()->rename_field($table, $field); |
655 | return true; |
b1f93b15 |
656 | } |
657 | |
eee5d9bb |
658 | function add_key($table, $key) { |
b1f93b15 |
659 | global $DB; |
660 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
661 | $DB->get_manager()->add_key($table, $key); |
662 | return true; |
b1f93b15 |
663 | } |
664 | |
eee5d9bb |
665 | function drop_key($table, $key) { |
b1f93b15 |
666 | global $DB; |
667 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
668 | $DB->get_manager()->drop_key($table, $key); |
669 | return true; |
b1f93b15 |
670 | } |
671 | |
eee5d9bb |
672 | function rename_key($table, $key, $newname) { |
b1f93b15 |
673 | global $DB; |
674 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
675 | $DB->get_manager()->rename_key($table, $key, $newname); |
676 | return true; |
b1f93b15 |
677 | } |
678 | |
eee5d9bb |
679 | function add_index($table, $index) { |
b1f93b15 |
680 | global $DB; |
681 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
682 | $DB->get_manager()->add_index($table, $index); |
683 | return true; |
b1f93b15 |
684 | } |
685 | |
eee5d9bb |
686 | function drop_index($table, $index) { |
b1f93b15 |
687 | global $DB; |
688 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
689 | $DB->get_manager()->drop_index($table, $index); |
690 | return true; |
b1f93b15 |
691 | } |
692 | |
eee5d9bb |
693 | function rename_index($table, $index, $newname) { |
b1f93b15 |
694 | global $DB; |
695 | debugging('Deprecated ddllib function used!'); |
eee5d9bb |
696 | $DB->get_manager()->rename_index($table, $index, $newname); |
697 | return true; |
b1f93b15 |
698 | } |
699 | |
8ec50604 |
700 | |
251387d0 |
701 | ////////////////////////// |
702 | /// removed functions //// |
703 | ////////////////////////// |
294ce987 |
704 | |
245ac557 |
705 | function addslashes_object($dataobject) { |
294ce987 |
706 | error('addslashes() not available anymore'); |
707 | } |
708 | |
709 | function addslashes_recursive($var) { |
710 | error('addslashes_recursive() not available anymore'); |
711 | } |
712 | |
245ac557 |
713 | function execute_sql($command, $feedback=true) { |
714 | error('execute_sql() not available anymore'); |
715 | } |
716 | |
717 | function record_exists_select($table, $select='') { |
718 | error('record_exists_select() not available anymore'); |
719 | } |
720 | |
721 | function record_exists_sql($sql) { |
722 | error('record_exists_sql() not available anymore'); |
723 | } |
724 | |
725 | function count_records_select($table, $select='', $countitem='COUNT(*)') { |
726 | error('count_records_select() not available anymore'); |
727 | } |
728 | |
729 | function count_records_sql($sql) { |
730 | error('count_records_sql() not available anymore'); |
731 | } |
732 | |
733 | function get_record_sql($sql, $expectmultiple=false, $nolimit=false) { |
734 | error('get_record_sql() not available anymore'); |
735 | } |
736 | |
737 | function get_record_select($table, $select='', $fields='*') { |
738 | error('get_record_select() not available anymore'); |
739 | } |
740 | |
741 | function get_recordset($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') { |
742 | error('get_recordset() not available anymore'); |
743 | } |
744 | |
745 | function get_recordset_sql($sql, $limitfrom=null, $limitnum=null) { |
746 | error('get_recordset_sql() not available anymore'); |
747 | } |
748 | |
749 | function rs_fetch_record(&$rs) { |
750 | error('rs_fetch_record() not available anymore'); |
751 | } |
752 | |
753 | function rs_next_record(&$rs) { |
754 | error('rs_next_record() not available anymore'); |
755 | } |
756 | |
757 | function rs_fetch_next_record(&$rs) { |
758 | error('rs_fetch_next_record() not available anymore'); |
759 | } |
760 | |
761 | function rs_EOF($rs) { |
762 | error('rs_EOF() not available anymore'); |
763 | } |
764 | |
765 | function rs_close(&$rs) { |
766 | error('rs_close() not available anymore'); |
767 | } |
768 | |
769 | function get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') { |
770 | error('get_records_select() not available anymore'); |
771 | } |
772 | |
773 | function get_field_select($table, $return, $select) { |
774 | error('get_field_select() not available anymore'); |
775 | } |
776 | |
777 | function get_field_sql($sql) { |
778 | error('get_field_sql() not available anymore'); |
779 | } |
294ce987 |
780 | |
245ac557 |
781 | function delete_records_select($table, $select='') { |
782 | delete_records_select('get_field_sql() not available anymore'); |
783 | } |
784 | |
785 | |
786 | function configure_dbconnection() { |
787 | error('configure_dbconnection() removed'); |
788 | } |
789 | |
790 | function sql_max($field) { |
791 | error('sql_max() removed - use normal sql MAX() instead'); |
792 | } |
793 | |
794 | function sql_as() { |
795 | error('sql_as() removed - do not use AS for tables at all'); |
796 | } |
797 | |
798 | function sql_paging_limit($page, $recordsperpage) { |
799 | error('Function sql_paging_limit() is deprecated. Replace it with the correct use of limitfrom, limitnum parameters'); |
800 | } |
801 | |
802 | function db_uppercase() { |
803 | error('upper() removed - use normal sql UPPER()'); |
804 | } |
805 | |
806 | function db_lowercase() { |
807 | error('upper() removed - use normal sql LOWER()'); |
808 | } |
809 | |
810 | function modify_database($sqlfile='', $sqlstring='') { |
811 | error('modify_database() removed - use new XMLDB functions'); |
812 | } |
813 | |
814 | function where_clause($field1='', $value1='', $field2='', $value2='', $field3='', $value3='') { |
815 | error('where_clause() removed - use new functions with $conditions parameter'); |
816 | } |
817 | |
818 | function execute_sql_arr($sqlarr, $continue=true, $feedback=true) { |
819 | error('execute_sql_arr() removed'); |
820 | } |
821 | |
822 | function get_records_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') { |
823 | error('get_records_list() removed'); |
824 | } |
825 | |
826 | function get_recordset_list($table, $field='', $values='', $sort='', $fields='*', $limitfrom='', $limitnum='') { |
827 | error('get_recordset_list() removed'); |
828 | } |
829 | |
830 | function get_records_menu($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') { |
831 | error('get_records_menu() removed'); |
832 | } |
833 | |
834 | function get_records_select_menu($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='') { |
835 | error('get_records_select_menu() removed'); |
836 | } |
837 | |
838 | function get_records_sql_menu($sql, $limitfrom='', $limitnum='') { |
839 | error('get_records_sql_menu() removed'); |
840 | } |
841 | |
842 | function column_type($table, $column) { |
843 | error('column_type() removed'); |
844 | } |
845 | |
846 | function recordset_to_menu($rs) { |
847 | error('recordset_to_menu() removed'); |
848 | } |
849 | |
850 | function records_to_menu($records, $field1, $field2) { |
851 | error('records_to_menu() removed'); |
852 | } |
853 | |
854 | function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) { |
855 | error('set_field_select() removed'); |
856 | } |
857 | |
858 | function get_fieldset_select($table, $return, $select) { |
859 | error('get_fieldset_select() removed'); |
860 | } |
861 | |
862 | function get_fieldset_sql($sql) { |
863 | error('get_fieldset_sql() removed'); |
864 | } |
865 | |
866 | function sql_ilike() { |
867 | error('sql_ilike() not available anymore'); |
868 | } |
869 | |
870 | function sql_fullname($first='firstname', $last='lastname') { |
871 | error('sql_fullname() not available anymore'); |
872 | } |
873 | |
874 | function sql_concat() { |
875 | error('sql_concat() not available anymore'); |
876 | } |
877 | |
878 | function sql_empty() { |
879 | error('sql_empty() not available anymore'); |
880 | } |
881 | |
882 | function sql_substr() { |
883 | error('sql_substr() not available anymore'); |
884 | } |
885 | |
886 | function sql_bitand($int1, $int2) { |
887 | error('sql_bitand() not available anymore'); |
888 | } |
889 | |
890 | function sql_bitnot($int1) { |
891 | error('sql_bitnot() not available anymore'); |
892 | } |
893 | |
894 | function sql_bitor($int1, $int2) { |
895 | error('sql_bitor() not available anymore'); |
896 | } |
897 | |
898 | function sql_bitxor($int1, $int2) { |
899 | error('sql_bitxor() not available anymore'); |
900 | } |
901 | |
902 | function sql_cast_char2int($fieldname, $text=false) { |
903 | error('sql_cast_char2int() not available anymore'); |
904 | } |
905 | |
906 | function sql_compare_text($fieldname, $numchars=32) { |
907 | error('sql_compare_text() not available anymore'); |
908 | } |
909 | |
910 | function sql_order_by_text($fieldname, $numchars=32) { |
911 | error('sql_order_by_text() not available anymore'); |
912 | } |
913 | |
914 | function sql_concat_join($separator="' '", $elements=array()) { |
915 | error('sql_concat_join() not available anymore'); |
916 | } |
917 | |
918 | function sql_isempty($tablename, $fieldname, $nullablefield, $textfield) { |
919 | error('sql_isempty() not available anymore'); |
920 | } |
921 | |
922 | function sql_isnotempty($tablename, $fieldname, $nullablefield, $textfield) { |
923 | error('sql_isnotempty() not available anymore'); |
924 | } |
925 | |
926 | function begin_sql() { |
927 | error('begin_sql() not available anymore'); |
928 | } |
929 | |
930 | function commit_sql() { |
931 | error('commit_sql() not available anymore'); |
932 | } |
933 | |
934 | function rollback_sql() { |
935 | error('rollback_sql() not available anymore'); |
936 | } |
937 | |
938 | function insert_record($table, $dataobject, $returnid=true, $primarykey='id') { |
939 | error('insert_record() not available anymore'); |
940 | } |
941 | |
942 | function update_record($table, $dataobject) { |
943 | error('update_record() not available anymore'); |
944 | } |
945 | |
946 | function get_records($table, $field='', $value='', $sort='', $fields='*', $limitfrom='', $limitnum='') { |
947 | error('get_records() not available anymore'); |
948 | } |
949 | |
950 | function get_record($table, $field1, $value1, $field2='', $value2='', $field3='', $value3='', $fields='*') { |
951 | error('get_record() not available anymore'); |
952 | } |
953 | |
954 | function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') { |
955 | error('set_field() not available anymore'); |
956 | } |
957 | |
958 | function count_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') { |
959 | error('count_records() not available anymore'); |
960 | } |
961 | |
962 | function record_exists($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') { |
963 | error('record_exists() not available anymore'); |
964 | } |
965 | |
966 | function delete_records($table, $field1='', $value1='', $field2='', $value2='', $field3='', $value3='') { |
967 | error('delete_records() not available anymore'); |
968 | } |
969 | |
970 | function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') { |
971 | error('get_field() not available anymore'); |
972 | } |
294ce987 |
973 | |
e6b4f00e |
974 | function table_column($table, $oldfield, $field, $type='integer', $size='10', |
975 | $signed='unsigned', $default='0', $null='not null', $after='') { |
976 | error('table_column() was removed, please use new ddl functions'); |
977 | } |
b1f93b15 |
978 | |