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