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