/// CONSTANTS /////////////////////////////////////////////////////////////
-define('NOGROUPS', 0);
+define('NOGROUPS', 0);
define('SEPARATEGROUPS', 1);
define('VISIBLEGROUPS', 2);
global $USER;
- unset($USER->preference);
+ unset($USER->preference);
if ($preferences = get_records('user_preferences', 'userid', $USER->id)) {
foreach ($preferences as $preference) {
function get_user_preferences($name=NULL, $default=NULL) {
/// Without arguments, returns all the current user preferences
-/// as an array. If a name is specified, then this function
-/// attempts to return that particular preference value. If
+/// 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,
/// otherwise NULL.
function userdate($date, $format="", $timezone=99, $fixday = true) {
/// Returns a formatted string that represents a date in user time
/// WARNING: note that the format is for strftime(), not date().
-/// Because of a bug in most Windows time libraries, we can't use
+/// Because of a bug in most Windows time libraries, we can't use
/// the nicer %e, so we have to use %d which has leading zeroes.
-/// A lot of the fuss below is just getting rid of these leading
+/// A lot of the fuss below is just getting rid of these leading
/// zeroes as efficiently as possible.
///
-/// If parammeter fixday = true (default), then take off leading
+/// If parammeter fixday = true (default), then take off leading
/// zero from %d, else mantain it.
global $USER, $CFG;
}
function usergetdate($date, $timezone=99) {
-/// Given a $date timestamp in GMT, returns an array
+/// Given a $date timestamp in GMT, returns an array
/// that represents the date in user time
- global $USER;
+ global $USER, $CFG;
if ($timezone == 99) { // Work out the best timezone to use
if (isset($USER->timezone)) { // A user is logged in
}
function usertime($date, $timezone=99) {
-/// Given a GMT timestamp (seconds since epoch), offsets it by
+/// Given a GMT timestamp (seconds since epoch), offsets it by
/// the timezone. eg 3pm in India is 3pm GMT - 7 * 3600 seconds
- global $USER;
+ global $USER, $CFG;
if ($timezone == 99) { // Work out the best timezone to use
if (isset($USER->timezone)) { // A user is logged in
function usergetmidnight($date, $timezone=99) {
/// Given a time, return the GMT timestamp of the most recent midnight
/// for the current user.
- global $USER;
+ global $USER, $CFG;
if ($timezone == 99) { // Work out the best timezone to use
if (isset($USER->timezone)) { // A user is logged in
function usertimezone($timezone=99) {
/// Returns a string that prints the user's timezone
- global $USER;
+ global $USER, $CFG;
if ($timezone == 99) { // Work out the best timezone to use
if (isset($USER->timezone)) { // A user is logged in
/// If not, then it redirects them to the site login or course enrolment.
global $CFG, $SESSION, $USER, $FULLME, $MoodleSession;
-
+
// First check that the user is logged in to the site.
if (! (isset($USER->loggedin) and $USER->confirmed and ($USER->site == $CFG->wwwroot)) ) { // They're not
$SESSION->wantsurl = $FULLME;
redirect("$CFG->wwwroot/user/edit.php?id=$USER->id&course=$site->id");
die;
}
-
+
// Next, check if the user can be in a particular course
if ($courseid) {
if (!empty($USER->student[$courseid]) or !empty($USER->teacher[$courseid]) or !empty($USER->admin)) {
/// Is the user allowed to edit this course?
global $USER;
- if (isadmin($userid)) { // admins can do anything
+ if (isadmin($userid)) { // admins can do anything
return true;
}
function fullname($user, $override=false) {
/// Given an object containing firstname and lastname
-/// values, this function returns a string with the
+/// values, this function returns a string with the
/// full name of the person.
/// The result may depend on system settings
/// or language. 'override' will force both names
}
function create_user_record($username, $password) {
-/// Creates a bare-bones user record
+/// Creates a bare-bones user record
global $REMOTE_ADDR, $CFG;
//just in case check text case
$username = trim(moodle_strtolower($username));
}
function authenticate_user_login($username, $password) {
-/// Given a username and password, this function looks them
+/// Given a username and password, this function looks them
/// up using the currently selected authentication mechanism,
-/// and if the authentication is successful, it returns a
+/// 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
}
// If this is the admin, then just use internal methods
- // Doing this first (even though it's less efficient) because
- // the chosen authentication method might hang and lock the
+ // Doing this first (even though it's less efficient) because
+ // the chosen authentication method might hang and lock the
// admin out.
if (adminlogin($username, $md5password)) {
return get_user_info_from_db("username", $username);
}
}
}
-
+
return $user;
} else {
return false;
$strdeleted = get_string("deleted");
// First delete every instance of every module
-
+
if ($allmods = get_records("modules") ) {
foreach ($allmods as $mod) {
$modname = $mod->name;
/// GROUPS /////////////////////////////////////////////////////////
-
+
/**
* Returns a boolean: is the user a member of the given group?
-*
+*
* @param type description
*/
function ismember($groupid, $userid=0) {
/**
* Returns the group ID of the current user in the given course
-*
+*
* @param type description
*/
function mygroupid($courseid) {
}
/**
-* For a given course, and possibly course module, determine
+* For a given course, and possibly course module, determine
* what the current default groupmode is:
* NOGROUPS, SEPARATEGROUPS or VISIBLEGROUPS
-*
+*
* @param type description
*/
function groupmode($course, $cm=null) {
/**
* Sets the current group in the session variable
-*
+*
* @param type description
*/
function set_current_group($courseid, $groupid) {
/**
* Gets the current group for the current user as an id or an object
-*
+*
* @param type description
*/
function get_current_group($courseid, $full=false) {
function get_and_set_current_group($course, $groupmode, $groupid=-1) {
if (!$groupmode) { // Groups don't even apply
- return false;
+ return false;
}
$currentgroupid = get_current_group($course->id);
if (!empty($user->emailstop)) {
return false;
}
-
+
$mail = new phpmailer;
- $mail->Version = "Moodle $CFG->version"; // mailer version
+ $mail->Version = "Moodle $CFG->version"; // mailer version
$mail->PluginDir = "$CFG->libdir/phpmailer/"; // plugin directory (eg smtp plugin)
$mail->FromName = fullname($from);
$mail->Subject = stripslashes($subject);
- $mail->AddAddress("$user->email", fullname($user) );
+ $mail->AddAddress("$user->email", fullname($user) );
$mail->WordWrap = 70; // set word wrap
}
function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) {
-/// Related to the above function - this function returns an
-/// array of possible sizes in an array, translated to the
+/// Related to the above function - this function returns an
+/// array of possible sizes in an array, translated to the
/// local language.
if (!$maxsize = get_max_upload_file_size($sitebytes, $coursebytes, $modulebytes)) {
$filesize[$maxsize] = display_size($maxsize);
- $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152,
+ $sizelist = array(10240, 51200, 102400, 512000, 1048576, 2097152,
5242880, 10485760, 20971520, 52428800, 104857600);
foreach ($sizelist as $sizebytes) {
}
function get_directory_list($rootdir, $excludefile="", $descend=true) {
-/// Returns an array with all the filenames in
+/// Returns an array with all the filenames in
/// all subdirectories, relative to the given rootdir.
/// If excludefile is defined, then that file/directory is ignored
function get_real_size($size=0) {
/// Converts numbers like 10M into bytes
if (!$size) {
- return 0;
+ return 0;
}
$scan['MB'] = 1048576;
$scan['Mb'] = 1048576;
$size = round($size / 1048576 * 10) / 10 . $mb;
} else if ($size >= 1024) {
$size = round($size / 1024 * 10) / 10 . $kb;
- } else {
+ } else {
$size = $size ." $b";
}
return $size;
}
function get_string($identifier, $module="", $a=NULL) {
-/// Return the translated string specified by $identifier as
+/// Return the translated string specified by $identifier as
/// for $module. Uses the same format files as STphp.
/// $a is an object, string or number that can be used
/// within translation strings
// If the preferred language was English we can abort now
- if ($lang == "en") {
+ if ($lang == "en") {
return "[[$identifier]]";
}
// Is a parent language defined? If so, try it.
-
+
if ($result = get_string_from_file("parentlanguage", "$langpath/$lang/moodle.php", "\$parentlang")) {
eval($result);
if (!empty($parentlang)) {
}
}
- include("$CFG->dirroot/lang/$lang/countries.php");
+ include("$CFG->dirroot/lang/$lang/countries.php");
if (!empty($string)) {
asort($string);
}
}
- include_once("$CFG->dirroot/lang/$lang/pix.php");
+ include_once("$CFG->dirroot/lang/$lang/pix.php");
return $string;
}
global $CFG;
$event->timemodified = time();
-
+
if (!$event->id = insert_record("event", $event)) {
return false;
}
-
+
if (!empty($CFG->calendar)) { // call the add_event function of the selected calendar
if (file_exists("$CFG->dirroot/calendar/$CFG->calendar/lib.php")) {
include_once("$CFG->dirroot/calendar/$CFG->calendar/lib.php");
}
}
}
-
+
return $event->id;
}
global $CFG;
$event->timemodified = time();
-
+
if (!empty($CFG->calendar)) { // call the update_event function of the selected calendar
if (file_exists("$CFG->dirroot/calendar/$CFG->calendar/lib.php")) {
include_once("$CFG->dirroot/calendar/$CFG->calendar/lib.php");
global $CFG;
include_once("$CFG->dirroot/version.php"); # defines $version and upgrades
- if ($CFG->version) {
+ if ($CFG->version) {
if ($version > $CFG->version) {
return true;
}
return mb_strtolower($string); //use multibyte support with default encoding
} else {
return mb_strtolower($string,$encoding); //use given encoding
- }
+ }
} else {
return strtolower($string); // use common function what rely on current locale setting
- }
+ }
}
function count_words($string) {
function getweek ($startdate, $thedate) {
/// Given dates in seconds, how many weeks is the date from startdate
-/// The first week is 1, the second 2 etc ...
-
+/// The first week is 1, the second 2 etc ...
+
if ($thedate < $startdate) { // error
- return 0;
+ return 0;
}
return floor(($thedate - $startdate) / 604800.0) + 1;
function generate_password($maxlen=10) {
/// returns a randomly generated password of length $maxlen. inspired by
-/// http://www.phpbuilder.com/columns/jesus19990502.php3
+/// http://www.phpbuilder.com/columns/jesus19990502.php3
global $CFG;
$curr = $array[$i];
$array[$i] = $array[$from];
$array[$from] = $curr;
- }
+ }
return $array;
}
}
function draw_rand_array($array, $draws) {
-/// Given an arbitrary array, and a number of draws,
-/// this function returns an array with that amount
+/// Given an arbitrary array, and a number of draws,
+/// this function returns an array with that amount
/// of items. The indexes are retained.
srand ((double) microtime() * 10000000);
$return[$keys[$rand]] = $array[$keys[$rand]];
unset($array[$keys[$rand]]);
-
+
$draws--;
}
return $return;
-}
+}
function microtime_diff($a, $b) {
list($a_dec, $a_sec) = explode(" ", $a);
}
function make_menu_from_list($list, $separator=",") {
-/// Given a list (eg a,b,c,d,e) this function returns
+/// Given a list (eg a,b,c,d,e) this function returns
/// an array of 1->a, 2->b, 3->c etc
$array = array_reverse(explode($separator, $list), true);