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