3 ///////////////////////////////////////////////////////////////////////////
5 // NOTICE OF COPYRIGHT //
7 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // http://moodle.org //
10 // Copyright (C) 1999-2999 Martin Dougiamas, Moodle http://moodle.com //
12 // This program is free software; you can redistribute it and/or modify //
13 // it under the terms of the GNU General Public License as published by //
14 // the Free Software Foundation; either version 2 of the License, or //
15 // (at your option) any later version. //
17 // This program is distributed in the hope that it will be useful, //
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20 // GNU General Public License for more details: //
22 // http://www.gnu.org/copyleft/gpl.html //
24 ///////////////////////////////////////////////////////////////////////////
27 * deprecatedlib.php - Old functions retained only for backward compatibility
29 * Old functions retained only for backward compatibility. New code should not
30 * use any of these functions.
32 * @author Martin Dougiamas
34 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
42 * Ensure that a variable is set
44 * If $var is undefined throw an error, otherwise return $var.
46 * @param mixed $var the variable which may be unset
47 * @param mixed $default the value to return if $var is unset
49 function require_variable($var) {
51 if (!empty($CFG->disableglobalshack
)) {
52 error( 'The require_variable() function is deprecated.' );
55 error('A required parameter was missing');
60 * Ensure that a variable is set
62 * If $var is undefined set it (by reference), otherwise return $var.
64 * @param mixed $var the variable which may be unset
65 * @param mixed $default the value to return if $var is unset
67 function optional_variable(&$var, $default=0) {
69 if (!empty($CFG->disableglobalshack
)) {
70 error( "The optional_variable() function is deprecated ($var, $default)." );
78 * Ensure that a variable is set
80 * Return $var if it is defined, otherwise return $default,
81 * This function is very similar to {@link optional_variable()}
83 * @param mixed $var the variable which may be unset
84 * @param mixed $default the value to return if $var is unset
87 function nvl(&$var, $default='') {
90 if (!empty($CFG->disableglobalshack
)) {
91 error( "The nvl() function is deprecated ($var, $default)." );
93 return isset($var) ?
$var : $default;
97 * Determines if a user an admin
100 * @param int $userid The id of the user as is found in the 'user' table
101 * @staticvar array $admins List of users who have been found to be admins by user id
102 * @staticvar array $nonadmins List of users who have been found not to be admins by user id
105 function isadmin($userid=0) {
108 if (empty($CFG->rolesactive
)) { // Then the user is likely to be upgrading NOW
110 if (empty($USER->id
)) {
113 if (!empty($USER->admin
)) {
119 return record_exists('user_admins', 'userid', $userid);
122 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
124 return has_capability('moodle/legacy:admin', $context, $userid, false);
128 * Determines if a user is a teacher (or better)
131 * @param int $courseid The id of the course that is being viewed, if any
132 * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
133 * @param bool $obsolete_includeadmin Not used any more
137 function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) {
138 /// Is the user able to access this course as a teacher?
141 if (empty($CFG->rolesactive
)) { // Teachers are locked out during an upgrade to 1.7
146 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
148 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
151 return (has_capability('moodle/legacy:teacher', $context, $userid, false)
152 or has_capability('moodle/legacy:editingteacher', $context, $userid, false)
153 or has_capability('moodle/legacy:admin', $context, $userid, false));
157 * Determines if a user is a teacher in any course, or an admin
160 * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
161 * @param bool $includeadmin Include anyone wo is an admin as well
164 function isteacherinanycourse($userid=0, $includeadmin=true) {
167 if (empty($CFG->rolesactive
)) { // Teachers are locked out during an upgrade to 1.7
172 if (empty($USER->id
)) {
178 if (!record_exists('role_assignments', 'userid', $userid)) { // Has no roles anywhere
182 /// If this user is assigned as an editing teacher anywhere then return true
183 if ($roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW
)) {
184 foreach ($roles as $role) {
185 if (record_exists('role_assignments', 'roleid', $role->id
, 'userid', $userid)) {
191 /// If this user is assigned as a non-editing teacher anywhere then return true
192 if ($roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW
)) {
193 foreach ($roles as $role) {
194 if (record_exists('role_assignments', 'roleid', $role->id
, 'userid', $userid)) {
200 /// Include admins if required
202 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
203 if (has_capability('moodle/legacy:admin', $context, $userid, false)) {
212 * Determines if a user is allowed to edit a given course
214 * @param int $courseid The id of the course that is being edited
215 * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
218 function isteacheredit($courseid, $userid=0, $obsolete_ignorestudentview=false) {
221 if (empty($CFG->rolesactive
)) {
225 if (empty($courseid)) {
226 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
228 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
231 return (has_capability('moodle/legacy:editingteacher', $context, $userid, false)
232 or has_capability('moodle/legacy:admin', $context, $userid, false));
236 * Determines if a user can create new courses
238 * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
241 function iscreator ($userid=0) {
244 if (empty($CFG->rolesactive
)) {
248 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
250 return (has_capability('moodle/legacy:coursecreator', $context, $userid, false)
251 or has_capability('moodle/legacy:admin', $context, $userid, false));
255 * Determines if a user is a student in the specified course
257 * If the course id specifies the site then this determines
258 * if the user is a confirmed and valid user of this site.
262 * @param int $courseid The id of the course being tested
263 * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
266 function isstudent($courseid=0, $userid=0) {
269 if (empty($CFG->rolesactive
)) {
273 if ($courseid == 0) {
274 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
276 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
279 return has_capability('moodle/legacy:student', $context, $userid, false);
283 * Determines if the specified user is logged in as guest.
285 * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
288 function isguest($userid=0) {
291 if (empty($CFG->rolesactive
)) {
295 $context = get_context_instance(CONTEXT_SYSTEM
);
297 return has_capability('moodle/legacy:guest', $context, $userid, false);
301 * Enrols (or re-enrols) a student in a given course
303 * NOTE: Defaults to 'manual' enrolment - enrolment plugins
304 * must set it explicitly.
307 * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
308 * @param int $courseid The id of the course that is being viewed
309 * @param int $timestart ?
310 * @param int $timeend ?
311 * @param string $enrol ?
314 function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='manual') {
318 if (!$user = get_record('user', 'id', $userid)) { // Check user
322 if (!$roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW
)) {
326 $role = array_shift($roles); // We can only use one, let's use the first one
328 if (!$context = get_context_instance(CONTEXT_COURSE
, $courseid)) {
332 return role_assign($role->id
, $user->id
, 0, $context->id
, $timestart, $timeend, 0, $enrol);
336 * Unenrols a student from a given course
338 * @param int $courseid The id of the course that is being viewed, if any
339 * @param int $userid The id of the user that is being tested against.
342 function unenrol_student($userid, $courseid=0) {
348 /// First delete any crucial stuff that might still send mail
349 if ($forums = get_records('forum', 'course', $courseid)) {
350 foreach ($forums as $forum) {
351 delete_records('forum_subscriptions', 'forum', $forum->id
, 'userid', $userid);
354 /// remove from all legacy student roles
355 if ($courseid == SITEID
) {
356 $context = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
357 } else if (!$context = get_context_instance(CONTEXT_COURSE
, $courseid)) {
360 if (!$roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW
)) {
363 foreach($roles as $role) {
364 $status = role_unassign($role->id
, $userid, 0, $context->id
) and $status;
367 // recursivelly unenroll student from all courses
368 if ($courses = get_records('course')) {
369 foreach($courses as $course) {
370 $status = unenrol_student($userid, $course->id
) and $status;
379 * Add a teacher to a given course
381 * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
382 * @param int $courseid The id of the course that is being viewed, if any
383 * @param int $editall Can edit the course
384 * @param string $role Obsolete
385 * @param int $timestart The time they start
386 * @param int $timeend The time they end in this role
387 * @param string $enrol The type of enrolment this is
390 function add_teacher($userid, $courseid, $editall=1, $role='', $timestart=0, $timeend=0, $enrol='manual') {
393 if (!$user = get_record('user', 'id', $userid)) { // Check user
397 $capability = $editall ?
'moodle/legacy:editingteacher' : 'moodle/legacy:teacher';
399 if (!$roles = get_roles_with_capability($capability, CAP_ALLOW
)) {
403 $role = array_shift($roles); // We can only use one, let's use the first one
405 if (!$context = get_context_instance(CONTEXT_COURSE
, $courseid)) {
409 return role_assign($role->id
, $user->id
, 0, $context->id
, $timestart, $timeend, 0, $enrol);
413 * Removes a teacher from a given course (or ALL courses)
414 * Does not delete the user account
416 * @param int $courseid The id of the course that is being viewed, if any
417 * @param int $userid The id of the user that is being tested against.
420 function remove_teacher($userid, $courseid=0) {
423 $roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW
);
426 $roles +
= get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW
);
428 $roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW
);
439 if (!$context = get_context_instance(CONTEXT_COURSE
, $courseid)) {
443 /// First delete any crucial stuff that might still send mail
444 if ($forums = get_records('forum', 'course', $courseid)) {
445 foreach ($forums as $forum) {
446 delete_records('forum_subscriptions', 'forum', $forum->id
, 'userid', $userid);
450 /// No need to remove from groups now
452 foreach ($roles as $role) { // Unassign them from all the teacher roles
453 $newreturn = role_unassign($role->id
, $userid, 0, $context->id
);
454 if (empty($newreturn)) {
460 delete_records('forum_subscriptions', 'userid', $userid);
462 foreach ($roles as $role) { // Unassign them from all the teacher roles
463 $newreturn = role_unassign($role->id
, $userid, 0, 0);
464 if (empty($newreturn)) {
474 * Add an admin to a site
477 * @param int $userid The id of the user that is being tested against.
479 * @TODO: remove from cvs
481 function add_admin($userid) {
485 function get_user_info_from_db($field, $value) { // For backward compatibility
486 return get_complete_user_data($field, $value);
491 * Get the guest user information from the database
493 * @return object(user) An associative array with the details of the guest user account.
494 * @todo Is object(user) a correct return type? Or is array the proper return type with a note that the contents include all details for a user.
496 function get_guest() {
497 return get_complete_user_data('username', 'guest');
501 * Returns $user object of the main teacher for a course
504 * @param int $courseid The course in question.
505 * @return user|false A {@link $USER} record of the main teacher for the specified course or false if error.
506 * @todo Finish documenting this function
508 function get_teacher($courseid) {
512 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
514 if ($users = get_users_by_capability($context, 'moodle/course:update', 'u.*,ra.hidden', 'r.sortorder ASC',
515 '', '', '', '', false)) {
516 foreach ($users as $user) {
517 if (!$user->hidden ||
has_capability('moodle/role:viewhiddenassigns', $context)) {
527 * Searches logs to find all enrolments since a certain date
529 * used to print recent activity
532 * @param int $courseid The course in question.
533 * @return object|false {@link $USER} records or false if error.
534 * @todo Finish documenting this function
536 function get_recent_enrolments($courseid, $timestart) {
540 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
542 return get_records_sql("SELECT DISTINCT u.id, u.firstname, u.lastname, l.time
543 FROM {$CFG->prefix}user u,
544 {$CFG->prefix}role_assignments ra,
546 WHERE l.time > '$timestart'
547 AND l.course = '$courseid'
548 AND l.module = 'course'
549 AND l.action = 'enrol'
552 AND ra.contextid ".get_related_contexts_string($context)."
553 ORDER BY l.time ASC");
557 * Returns array of userinfo of all students in this course
558 * or on this site if courseid is id of site
562 * @param int $courseid The course in question.
563 * @param string $sort ?
564 * @param string $dir ?
566 * @param int $recordsperpage ?
567 * @param string $firstinitial ?
568 * @param string $lastinitial ?
570 * @param string $search ?
571 * @param string $fields A comma separated list of fields to be returned from the chosen table.
572 * @param string $exceptions ?
574 * @todo Finish documenting this function
576 function get_course_students($courseid, $sort='ul.timeaccess', $dir='', $page='', $recordsperpage='',
577 $firstinitial='', $lastinitial='', $group=NULL, $search='', $fields='', $exceptions='') {
581 if ($courseid == SITEID
and $CFG->allusersaresitestudents
) {
582 // return users with confirmed, undeleted accounts who are not site teachers
583 // the following is a mess because of different conventions in the different user functions
584 $sort = str_replace('s.timeaccess', 'lastaccess', $sort); // site users can't be sorted by timeaccess
585 $sort = str_replace('timeaccess', 'lastaccess', $sort); // site users can't be sorted by timeaccess
586 $sort = str_replace('u.', '', $sort); // the get_user function doesn't use the u. prefix to fields
587 $fields = str_replace('u.', '', $fields);
589 $sort = $sort .' '. $dir;
591 // Now we have to make sure site teachers are excluded
593 if ($teachers = get_course_teachers(SITEID
)) {
594 foreach ($teachers as $teacher) {
595 $exceptions .= ','. $teacher->userid
;
597 $exceptions = ltrim($exceptions, ',');
601 return get_users(true, $search, true, $exceptions, $sort, $firstinitial, $lastinitial,
602 $page, $recordsperpage, $fields ?
$fields : '*');
606 $fullname = sql_fullname('u.firstname','u.lastname');
610 // make sure it works on the site course
611 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
613 $select = "c.contextlevel=".CONTEXT_COURSE
." AND "; // Must be on a course
614 if ($courseid != SITEID
) {
615 // If not site, require specific course
616 $select.= "c.instanceid=$courseid AND ";
618 $select.="rc.capability='moodle/legacy:student' AND rc.permission=".CAP_ALLOW
." AND ";
620 $select .= ' u.deleted = \'0\' ';
623 $fields = 'u.id, u.confirmed, u.username, u.firstname, u.lastname, '.
624 'u.maildisplay, u.mailformat, u.maildigest, u.email, u.city, '.
625 'u.country, u.picture, u.idnumber, u.department, u.institution, '.
626 'u.emailstop, u.lang, u.timezone, ul.timeaccess as lastaccess';
630 $search = ' AND ('. $fullname .' '. $LIKE .'\'%'. $search .'%\' OR email '. $LIKE .'\'%'. $search .'%\') ';
634 $select .= ' AND u.firstname '. $LIKE .'\''. $firstinitial .'%\' ';
638 $select .= ' AND u.lastname '. $LIKE .'\''. $lastinitial .'%\' ';
641 if ($group === 0) { /// Need something here to get all students not in a group
644 } else if ($group !== NULL) {
645 $groupmembers = "INNER JOIN {$CFG->prefix}groups_members gm on u.id=gm.userid";
646 $select .= ' AND gm.groupid = \''. $group .'\'';
649 if (!empty($exceptions)) {
650 $select .= ' AND u.id NOT IN ('. $exceptions .')';
654 $sort = ' ORDER BY '. $sort .' ';
657 $students = get_records_sql("SELECT $fields
658 FROM {$CFG->prefix}user u INNER JOIN
659 {$CFG->prefix}role_assignments ra on u.id=ra.userid INNER JOIN
660 {$CFG->prefix}role_capabilities rc ON ra.roleid=rc.roleid INNER JOIN
661 {$CFG->prefix}context c ON c.id=ra.contextid LEFT OUTER JOIN
662 {$CFG->prefix}user_lastaccess ul on ul.userid=ra.userid
664 WHERE $select $search $sort $dir", $page, $recordsperpage);
670 * Counts the students in a given course (or site), or a subset of them
672 * @param object $course The course in question as a course object.
673 * @param string $search ?
674 * @param string $firstinitial ?
675 * @param string $lastinitial ?
677 * @param string $exceptions ?
679 * @todo Finish documenting this function
681 function count_course_students($course, $search='', $firstinitial='', $lastinitial='', $group=NULL, $exceptions='') {
683 if ($students = get_course_students($course->id
, '', '', 0, 999999, $firstinitial, $lastinitial, $group, $search, '', $exceptions)) {
684 return count($students);
690 * Returns list of all teachers in this course
692 * If $courseid matches the site id then this function
693 * returns a list of all teachers for the site.
696 * @param int $courseid The course in question.
697 * @param string $sort ?
698 * @param string $exceptions ?
700 * @todo Finish documenting this function
702 function get_course_teachers($courseid, $sort='t.authority ASC', $exceptions='') {
706 $sort = 'ul.timeaccess DESC';
708 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
709 return get_users_by_capability($context, 'moodle/course:update', 'u.*, ul.timeaccess as lastaccess, ra.hidden', $sort, '','','',$exceptions, false);
710 /// some fields will be missing, like authority, editall
712 return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest,
713 u.email, u.city, u.country, u.lastlogin, u.picture, u.lang, u.timezone,
714 u.emailstop, t.authority,t.role,t.editall,t.timeaccess as lastaccess
715 FROM {$CFG->prefix}user u,
716 {$CFG->prefix}user_teachers t
717 WHERE t.course = '$courseid' AND t.userid = u.id
718 AND u.deleted = '0' AND u.confirmed = '1' $exceptions $sort");
723 * Returns all the users of a course: students and teachers
725 * @param int $courseid The course in question.
726 * @param string $sort ?
727 * @param string $exceptions ?
728 * @param string $fields A comma separated list of fields to be returned from the chosen table.
730 * @todo Finish documenting this function
732 function get_course_users($courseid, $sort='ul.timeaccess DESC', $exceptions='', $fields='') {
734 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
735 return get_users_by_capability($context, 'moodle/course:view', 'u.*, ul.timeaccess as lastaccess', $sort, '','','',$exceptions, false);
740 * Returns an array of user objects
743 * @param int $groupid The group(s) in question.
744 * @param string $sort How to sort the results
745 * @return object (changed to groupids)
747 function get_group_students($groupids, $sort='ul.timeaccess DESC') {
749 if (is_array($groupids)){
751 // all groups must be from one course anyway...
752 $group = groups_get_group(array_shift($groups));
754 $group = groups_get_group($groupids);
760 $context = get_context_instance(CONTEXT_COURSE
, $group->courseid
);
761 return get_users_by_capability($context, 'moodle/legacy:student', 'u.*, ul.timeaccess as lastaccess', $sort, '','',$groupids, '', false);
765 * Returns list of all the teachers who can access a group
768 * @param int $courseid The course in question.
769 * @param int $groupid The group in question.
772 function get_group_teachers($courseid, $groupid) {
773 /// Returns a list of all the teachers who can access a group
774 if ($teachers = get_course_teachers($courseid)) {
775 foreach ($teachers as $key => $teacher) {
776 if ($teacher->editall
) { // These can access anything
779 if (($teacher->authority
> 0) and ismember($groupid, $teacher->id
)) { // Specific group teachers
782 unset($teachers[$key]);
790 ########### FROM weblib.php ##########################################################################
794 * Print a message in a standard themed box.
795 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
796 * parameters remain. If possible, $align, $width and $color should not be defined at all.
797 * Preferably just use print_box() in weblib.php
799 * @param string $align, alignment of the box, not the text (default center, left, right).
800 * @param string $width, width of the box, including units %, for example '100%'.
801 * @param string $color, background colour of the box, for example '#eee'.
802 * @param int $padding, padding in pixels, specified without units.
803 * @param string $class, space-separated class names.
804 * @param string $id, space-separated id names.
805 * @param boolean $return, return as string or just print it
807 function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
809 $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
810 $output .= stripslashes_safe($message);
811 $output .= print_simple_box_end(true);
823 * This old function used to implement boxes using tables. Now it uses a DIV, but the old
824 * parameters remain. If possible, $align, $width and $color should not be defined at all.
825 * Even better, please use print_box_start() in weblib.php
827 * @param string $align, alignment of the box, not the text (default center, left, right). DEPRECATED
828 * @param string $width, width of the box, including % units, for example '100%'. DEPRECATED
829 * @param string $color, background colour of the box, for example '#eee'. DEPRECATED
830 * @param int $padding, padding in pixels, specified without units. OBSOLETE
831 * @param string $class, space-separated class names.
832 * @param string $id, space-separated id names.
833 * @param boolean $return, return as string or just print it
835 function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
839 $divclasses = 'box '.$class.' '.$class.'content';
843 $divclasses .= ' boxalign'.$align; // Implement alignment using a class
845 if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
846 if (substr($width, -1, 1) == '%') { // Width is a % value
847 $width = (int) substr($width, 0, -1); // Extract just the number
849 $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
850 } else if ($width > 60) {
851 $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
853 $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
856 $divstyles .= ' width:'.$width.';'; // Last resort
859 if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
860 $divstyles .= ' background:'.$color.';';
863 $divstyles = ' style="'.$divstyles.'"';
867 $id = ' id="'.$id.'"';
870 $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
881 * Print the end portion of a standard themed box.
882 * Preferably just use print_box_end() in weblib.php
884 function print_simple_box_end($return=false) {
894 * deprecated - use clean_param($string, PARAM_FILE); instead
895 * Check for bad characters ?
897 * @param string $string ?
898 * @param int $allowdots ?
899 * @todo Finish documenting this function - more detail needed in description as well as details on arguments
901 function detect_munged_arguments($string, $allowdots=1) {
902 if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
905 if (ereg('[\|\`]', $string)) { // check for other bad characters
908 if (empty($string) or $string == '/') {
915 /** Deprecated function - returns the code of the current charset - originally depended on the selected language pack.
917 * @param $ignorecache not used anymore
918 * @return string always returns 'UTF-8'
920 function current_charset($ignorecache = false) {
925 /////////////////////////////////////////////////////////////
926 /// Old functions not used anymore - candidates for removal
927 /////////////////////////////////////////////////////////////
930 * Load a template from file - this function dates back to Moodle 1 :-) not used anymore
932 * Returns a (big) string containing the contents of a template file with all
933 * the variables interpolated. all the variables must be in the $var[] array or
934 * object (whatever you decide to use).
936 * <b>WARNING: do not use this on big files!!</b>
938 * @param string $filename Location on the server's filesystem where template can be found.
939 * @param mixed $var Passed in by reference. An array or object which will be loaded with data from the template file.
942 function read_template($filename, &$var) {
944 $temp = str_replace("\\", "\\\\", implode(file($filename), ''));
945 $temp = str_replace('"', '\"', $temp);
946 eval("\$template = \"$temp\";");
952 * deprecated - relies on register globals; use new formslib instead
954 * Set a variable's value depending on whether or not it already has a value.
956 * If variable is set, set it to the set_value otherwise set it to the
957 * unset_value. used to handle checkboxes when you are expecting them from
960 * @param mixed $var Passed in by reference. The variable to check.
961 * @param mixed $set_value The value to set $var to if $var already has a value.
962 * @param mixed $unset_value The value to set $var to if $var does not already have a value.
964 function checked(&$var, $set_value = 1, $unset_value = 0) {
974 * deprecated - use new formslib instead
976 * Prints the word "checked" if a variable is true, otherwise prints nothing,
977 * used for printing the word "checked" in a checkbox form element.
979 * @param boolean $var Variable to be checked for true value
980 * @param string $true_value Value to be printed if $var is true
981 * @param string $false_value Value to be printed if $var is false
983 function frmchecked(&$var, $true_value = 'checked', $false_value = '') {
993 * Legacy function, provided for backward compatability.
994 * This method now simply calls {@link use_html_editor()}
996 * @deprecated Use {@link use_html_editor()} instead.
997 * @param string $name Form element to replace with HTMl editor by name
998 * @todo Finish documenting this function
1000 function print_richedit_javascript($form, $name, $source='no') {
1001 use_html_editor($name);