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