/**
* Time constant - the number of seconds in a week
*/
-define('WEEKSECS', 604800);
+define('WEEKSECS', 604800);
/**
* Time constant - the number of seconds in a day
/// PARAMETER HANDLING ////////////////////////////////////////////////////
/**
- * Returns a particular value for the named variable, taken from
- * POST or GET. If the parameter doesn't exist then an error is
+ * Returns a particular value for the named variable, taken from
+ * POST or GET. If the parameter doesn't exist then an error is
* thrown because we require this variable.
*
- * This function should be used to initialise all required values
- * in a script that are based on parameters. Usually it will be
+ * This function should be used to initialise all required values
+ * in a script that are based on parameters. Usually it will be
* used like this:
* $id = required_param('id');
*
}
/**
- * Returns a particular value for the named variable, taken from
+ * Returns a particular value for the named variable, taken from
* POST or GET, otherwise returning a given default.
*
- * This function should be used to initialise all optional values
- * in a script that are based on parameters. Usually it will be
+ * This function should be used to initialise all optional values
+ * in a script that are based on parameters. Usually it will be
* used like this:
* $name = optional_param('name', 'Fred');
*
}
/**
- * Used by {@link optional_param()} and {@link required_param()} to
- * clean the variables and/or cast to specific types, based on
+ * Used by {@link optional_param()} and {@link required_param()} to
+ * clean the variables and/or cast to specific types, based on
* an options field.
*
* @param mixed $param the variable we are cleaning
}
if ($param === '.' or $param === ' ') {
$param = '';
- }
+ }
}
if ($options & PARAM_PATH) { // Strip all suspicious characters from file path
global $USER;
- if (empty($userid)){
+ if (empty($userid)){
$userid = $USER->id;
}
global $USER;
- if (empty($userid)){
+ if (empty($userid)){
$userid = $USER->id;
}
return false;
}
- if (empty($userid)){
+ if (empty($userid)){
$userid = $USER->id;
}
/**
* If no arguments are supplied this function will return
- * all of the current user preferences as an array.
+ * all of the current user preferences as an array.
* If a name is specified then this function
* attempts to return that particular preference value. If
* none is found, then the optional value $default is returned,
* the nicer %e, so we have to use %d which has leading zeroes.
* A lot of the fuss in the function is just getting rid of these leading
* zeroes as efficiently as possible.
- *
+ *
* If parameter fixday = true (default), then take off leading
* zero from %d, else mantain it.
*
}
/**
- * Given a $date timestamp in GMT (seconds since epoch),
+ * Given a $date timestamp in GMT (seconds since epoch),
* returns an array that represents the date in user time
*
* @uses HOURSECS
} elseif($CFG->changepassword) {
redirect($CFG->changepassword);
} else {
- error('You cannot proceed without changing your password.
+ error('You cannot proceed without changing your password.
However there is no available page for changing it.
Please contact your Moodle Administrator.');
}
}
// Make sure current IP matches the one for this session (if required)
- if (!empty($CFG->tracksessionip)) {
+ if (!empty($CFG->tracksessionip)) {
if ($USER->sessionIP != md5(getremoteaddr())) {
error(get_string('sessionipnomatch', 'error'));
}
// Next, check if the user can be in a particular course
if ($courseid) {
- if ($courseid == SITEID) {
+ if ($courseid == SITEID) {
return; // Anyone can be in the site course
}
if (!empty($USER->student[$courseid]) or !empty($USER->teacher[$courseid]) or !empty($USER->admin)) {
* Determines if a user can create new courses
*
* @uses $USER
- * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
+ * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
* @return boolean
*/
function iscreator ($userid=0) {
/**
* Determines if a user is a student in the specified course
- *
+ *
* If the course id specifies the site then the function determines
* if the user is a confirmed and valid user of this site.
*
* @uses $CFG
* @uses SITEID
* @param int $courseid The id of the course being tested
- * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
+ * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
* @return boolean
*/
function isstudent($courseid, $userid=0) {
* Determines if the specified user is logged in as guest.
*
* @uses $USER
- * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
+ * @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
* @return boolean
*/
function isguest($userid=0) {
* full name of the person.
* The result may depend on system settings
* or language. 'override' will force both names
- * to be used even if system settings specify one.
+ * to be used even if system settings specify one.
* @uses $CFG
* @uses $SESSION
* @param type description
'country' => 2,
'url' => 255,
);
-
+
// apply where needed
foreach (array_keys($info) as $key) {
if (!empty($limit[$key])) {
$info[$key] = substr($info[$key],0, $limit[$key]);
- }
+ }
}
-
+
return $info;
}
* up using the currently selected authentication mechanism,
* and if the authentication is successful, it returns a
* valid $user object from the 'user' table.
- *
+ *
* Uses auth_ functions from the currently active auth module
*
* @uses $CFG
- * @param string $username User's username
- * @param string $password User's password
+ * @param string $username User's username
+ * @param string $password User's password
* @return user|flase A {@link $USER} object or false if error
*/
function authenticate_user_login($username, $password) {
}
}
}
- }
+ }
}
$user->sessionIP = md5(getremoteaddr()); // Store the current IP in the session
return $user;
$student->time = time();
$student->enrol = $enrol;
return update_record('user_students', $student);
-
+
} else {
require_once("$CFG->dirroot/mod/forum/lib.php");
forum_add_user($userid, $courseid);
* Does not delete the user account
*
* @param int $courseid The id of the course that is being viewed, if any
- * @param int $userid The id of the user that is being tested against.
+ * @param int $userid The id of the user that is being tested against.
* @return boolean
*/
function remove_teacher($userid, $courseid=0) {
/**
* Add a creator to the site
*
- * @param int $userid The id of the user that is being tested against.
+ * @param int $userid The id of the user that is being tested against.
* @return boolean
*/
function add_creator($userid) {
if (!record_exists('user_admins', 'userid', $userid)) {
if (record_exists('user', 'id', $userid)) {
$admin->userid = $userid;
-
+
// any admin is also a teacher on the site course
if (!record_exists('user_teachers', 'course', SITEID, 'userid', $userid)) {
if (!add_teacher($userid, SITEID)) {
return false;
}
}
-
+
return insert_record('user_admins', $admin);
}
return false;
* @param string $messagehtml complete html version of the message (optional)
* @param string $attachment a file on the filesystem, relative to $CFG->dataroot
* @param string $attachname the name of the file (extension indicates MIME)
- * @param boolean $usetrueaddress determines whether $from email address should
+ * @param boolean $usetrueaddress determines whether $from email address should
* be sent out. Will be overruled by user profile setting for maildisplay
- * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
+ * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
* was blocked by user and "false" if there was another sort of error.
*/
function email_to_user($user, $from, $subject, $messagetext, $messagehtml='', $attachment='', $attachname='', $usetrueaddress=true) {
*
* @uses $CFG
* @param user $user A {@link $USER} object
- * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
+ * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
* was blocked by user and "false" if there was another sort of error.
*/
function reset_password_and_mail($user) {
*
* @uses $CFG
* @param user $user A {@link $USER} object
- * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
+ * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
* was blocked by user and "false" if there was another sort of error.
*/
function send_confirmation_email($user) {
*
* @uses $CFG
* @param user $user A {@link $USER} object
- * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
+ * @return boolean|string Returns "true" if mail was sent OK, "emailstop" if email
* was blocked by user and "false" if there was another sort of error.
* @todo Finish documenting this function
*/
*
* $filearray is a 1-dimensional sub-array of the $_FILES array
* eg $filearray = $_FILES['userfile1']
- * If left empty then the first element of the $_FILES array will be used
+ * If left empty then the first element of the $_FILES array will be used
*
* @uses $_FILES
* @param array $filearray A 1-dimensional sub-array of the $_FILES array
* @param string $module The module where the key identifier is stored. If none is specified then moodle.php is used.
* @param mixed $a An object, string or number that can be used
* within translation strings
- */
+ */
function print_string($identifier, $module='', $a=NULL) {
echo get_string($identifier, $module, $a);
}
* <code>
* $string['wordforstudent'] = 'Your word for Student';
* </code>
- * So if you want to display the string 'Your word for student'
- * in any language that supports it on your site
+ * So if you want to display the string 'Your word for student'
+ * in any language that supports it on your site
* you just need to use the identifier 'wordforstudent'
* <code>
* $mystring = '<strong>'. get_string('wordforstudent') .'</strong>';
or
* </code>
- * If the string you want is in another file you'd take a slightly
- * different approach. Looking in moodle/lang/en/calendar.php you find
+ * If the string you want is in another file you'd take a slightly
+ * different approach. Looking in moodle/lang/en/calendar.php you find
* around line 75:
* <code>
* $string['typecourse'] = 'Course event';
* </code>
- * If you want to display the string "Course event" in any language
- * supported you would use the identifier 'typecourse' and the module 'calendar'
+ * If you want to display the string "Course event" in any language
+ * supported you would use the identifier 'typecourse' and the module 'calendar'
* (because it is in the file calendar.php):
* <code>
* $mystring = '<h1>'. get_string('typecourse', 'calendar') .'</h1>';
* within translation strings
* @return string The localized string.
*/
-function get_string($identifier, $module='', $a=NULL) {
+function get_string($identifier, $module='', $a=NULL) {
global $CFG;
* @uses $CFG
* @uses $USER
* @return string?
- * @todo Finish documenting this function.
+ * @todo Finish documenting this function.
*/
function get_list_of_countries() {
global $CFG, $USER;
* @return string?
* @todo Finish documenting this function.
*/
-function get_list_of_pixnames() {
+function get_list_of_pixnames() {
global $CFG;
$lang = current_language();
* @return ?
* @todo Finish documenting this function
*/
-function document_file($file, $include=true) {
+function document_file($file, $include=true) {
global $CFG;
$file = clean_filename($file);
* to override it
*
* The memory limit should be expressed with a string (eg:'64M')
-*
+*
* Return boolean
*
* @param value string with the new memory limit
*/
function raise_memory_limit ($newlimit) {
- if (empty($newlimit)) {
+ if (empty($newlimit)) {
return false;
}
-
+
$cur = @ini_get('memory_limit');
if (empty($cur)) {
// if php is compiled without --enable-memory-limits
}
$cur = return_bytes($cur);
}
-
+
$new = return_bytes($newlimit);
if ($new > $cur) {
ini_set('memory_limit', $newlimit);
- return true;
+ return true;
}
return false;
}
* @return string
* @todo Finish documenting this function
*/
-function endecrypt ($pwd, $data, $case) {
+function endecrypt ($pwd, $data, $case) {
if ($case == 'de') {
$data = urldecode($data);
* @return boolean
* @todo Finish documenting this function
*/
- function check_browser_version($brand='MSIE', $version=5.5) {
+ function check_browser_version($brand='MSIE', $version=5.5) {
$agent = $_SERVER['HTTP_USER_AGENT'];
if (empty($agent)) {
case 'Gecko': /// Gecko based browsers
- if (substr_count($agent, 'Camino')) { // MacOS X Camino not supported.
- return false;
+ if (substr_count($agent, 'Camino')) {
+ // MacOS X Camino support
+ $version = 20041110;
}
// the proper string - Gecko/CCYYMMDD Vendor/Version
* @return boolean
* @todo Finish documenting this function
*/
-function ini_get_bool($ini_get_arg) {
+function ini_get_bool($ini_get_arg) {
$temp = ini_get($ini_get_arg);
if ($temp == '1' or strtolower($temp) == 'on') {
}
/**
- * Determines if the HTML editor is enabled.
+ * Determines if the HTML editor is enabled.
*
* This depends on site and user
* settings, as well as the current browser being used.
* returns 'MSIE' or 'Gecko'.
* @todo Finish documenting this function
*/
- function can_use_html_editor() {
+ function can_use_html_editor() {
global $USER, $CFG;
if (!empty($USER->htmleditor) and !empty($CFG->htmleditor)) {
* @return boolean
* @todo Finish documenting this function
*/
-function moodle_needs_upgrading() {
+function moodle_needs_upgrading() {
global $CFG;
include_once($CFG->dirroot .'/version.php'); # defines $version and upgrades
* @param string $string The text to be searched for words.
* @return int The count of words in the specified string
*/
-function count_words($string) {
+function count_words($string) {
$string = strip_tags($string);
return count(preg_split("/\w\b/", $string)) - 1;
}
* @return string
* @todo Finish documenting this function
*/
-function getweek ($startdate, $thedate) {
+function getweek ($startdate, $thedate) {
if ($thedate < $startdate) { // error
return 0;
}
* @param array $array The array to be rearranged
* @return array
*/
-function swapshuffle($array) {
+function swapshuffle($array) {
srand ((double) microtime() * 10000000);
$last = count($array) - 1;
* @return array
*/
function swapshuffle_assoc($array) {
-///
+///
$newkeys = swapshuffle(array_keys($array));
foreach ($newkeys as $newkey) {
* @param string $separator ?
* @todo Finish documenting this function
*/
-function make_menu_from_list($list, $separator=',') {
+function make_menu_from_list($list, $separator=',') {
$array = array_reverse(explode($separator, $list), true);
foreach ($array as $key => $item) {
}
//If no extension, add it
- if (empty($extension)) {
+ if (empty($extension)) {
$extension = 'zip';
$destfilename = $destfilename.'.'.$extension;
}
//SAME directory where the zip file resides.
global $CFG;
-
+
//Extract everything from zipfile
$path_parts = pathinfo(cleardoubleslashes($zipfile));
$zippath = $path_parts["dirname"]; //The path of the zip file
if ($showstatus) {
unzip_show_status($list,$destpath);
}
-
+
return true;
}
// BSD: none (tested)
// Linux: ??
// MacosX: ??
- }
+ }
$p_header['filename'] = cleardoubleslashes($p_header['filename']); //normalize the slashes/backslashes
return 1;
}
/**
* Returns most reliable client address
- *
+ *
* @return string The remote IP address
*/
function getremoteaddr() {
else if(getenv('REMOTE_ADDR')) $ip = getenv('REMOTE_ADDR');
else $ip = false; //just in case
return $ip;
-}
+}
/**
* html_entity_decode is only supported by php 4.3.0 and higher