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