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