$string['entercourse'] = "Click to enter this course";
$string['enteremailaddress'] = "Enter in your email address to reset your
password and have the new password sent to you via email.";
+$string['error'] = "Error";
+$string['errortoomanylogins'] = "Sorry, you have exceeded the allowed number of login attempts. Restart your browser.";
$string['existingadmins'] = "Existing admins";
$string['existingteachers'] = "Existing teachers";
-$string['error'] = "Error";
$string['feedback'] = "Feedback";
$string['filemissing'] = "\$a is missing";
$string['files'] = "Files";
$string['enteremailaddress'] = "Enter in your email address to reset your \r
password and have the new password sent to you via email.";
$string['error'] = "Error";
+$string['errortoomanylogins'] = "Sorry, you have exceeded the allowed number of login attempts. Restart your browser.";
$string['existingadmins'] = "Existing admins";
$string['existingteachers'] = "Existing teachers";
$string['feedback'] = "Feedback";
}
}
+function update_user_login_times() {
+ global $USER;
+
+ $USER->lastlogin = $user->lastlogin = $USER->currentlogin;
+ $USER->currentlogin = $user->currentlogin = time();
+ save_session("USER");
+
+ $user->id = $USER->id;
+
+ return update_record("user", $user);
+}
+
function update_login_count() {
/// Keeps track of login attempts
if ($SESSION->logincount > $max_logins) {
unset($SESSION->wantsurl);
save_session("SESSION");
- error("Sorry, you have exceeded the allowed number of login attempts. Restart your browser.");
+ error(get_string("errortoomanylogins"));
}
}
}
-
function isadmin($userid=0) {
/// Is the user an admin?
global $USER;
}
}
+function reset_password_and_mail($user) {
+
+ global $CFG;
+
+ $site = get_site();
+ $from = get_admin();
+
+ $newpassword = generate_password();
+
+ if (! set_field("user", "password", md5($newpassword), "id", $user->id) ) {
+ error("Could not set user password!");
+ }
+
+ $a->firstname = $user->firstname;
+ $a->sitename = $site->fullname;
+ $a->username = $user->username;
+ $a->newpassword = $newpassword;
+ $a->link = "$CFG->wwwroot/login/change_password.php";
+ $a->signoff = "$from->firstname $from->lastname ($from->email)";
+
+ $message = get_string("newpasswordtext", "", $a);
+
+ $subject = "$site->fullname: ".get_string("changedpassword");
+
+ return email_to_user($user, $from, $subject, $message);
+
+}
+
+function send_confirmation_email($user) {
+
+ global $CFG;
+
+ $site = get_site();
+ $from = get_admin();
+
+ $data->firstname = $user->firstname;
+ $data->sitename = $site->fullname;
+ $data->link = "$CFG->wwwroot/login/confirm.php?p=$user->secret&s=$user->username";
+ $data->admin = "$from->firstname $from->lastname ($from->email)";
+
+ $message = get_string("emailconfirmation", "", $data);
+ $subject = "$site->fullname account confirmation";
+
+ return email_to_user($user, $from, $subject, $message);
+
+}
+
+
/// FILE HANDLING /////////////////////////////////////////////
return $languages;
}
-function get_list_of_plugins($plugin="mod") {
-/// Lists plugin directories within some directory
-
- global $CFG;
-
- $basedir = opendir("$CFG->dirroot/$plugin");
- while ($dir = readdir($basedir)) {
- if ($dir == "." || $dir == ".." || $dir == "CVS") {
- continue;
- }
- if (filetype("$CFG->dirroot/$plugin/$dir") != "dir") {
- continue;
- }
- $plugins[] = $dir;
- }
- if ($plugins) {
- asort($plugins);
- }
- return $plugins;
-}
-
/// ENCRYPTION ////////////////////////////////////////////////
/// ENVIRONMENT CHECKING ////////////////////////////////////////////////////////////
+function get_list_of_plugins($plugin="mod") {
+/// Lists plugin directories within some directory
+
+ global $CFG;
+
+ $basedir = opendir("$CFG->dirroot/$plugin");
+ while ($dir = readdir($basedir)) {
+ if ($dir == "." || $dir == ".." || $dir == "CVS") {
+ continue;
+ }
+ if (filetype("$CFG->dirroot/$plugin/$dir") != "dir") {
+ continue;
+ }
+ $plugins[] = $dir;
+ }
+ if ($plugins) {
+ asort($plugins);
+ }
+ return $plugins;
+}
+
function check_php_version($version="4.1.0") {
/// Returns true is the current version of PHP is greater that the specified one
$minversion = intval(str_replace(".", "", $version));
return count(preg_split("/\w\b/", $string)) - 1;
}
+function random_string ($length=15) {
+ $pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ $pool .= "abcdefghijklmnopqrstuvwxyz";
+ $pool .= "0123456789";
+ $poollen = strlen($pool);
+ mt_srand ((double) microtime() * 1000000);
+ $string = "";
+ for ($i = 0; $i < $length; $i++) {
+ $string .= substr($pool, (mt_rand()%($poollen)), 1);
+ }
+ return $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 ...
$USER = $user;
- $timenow = time();
-
- $rs = $db->Execute("UPDATE user SET confirmed=1, lastIP='$REMOTE_ADDR',
- firstaccess='$timenow', lastaccess='$timenow'
- WHERE id = '$USER->id' ");
- if (!$rs) {
- error("Could not update this user while confirming");
+ if (!set_field("user", "confirmed", 1, "id", $USER->id)) {
+ error("Could not confirm this user!");
+ }
+ if (!set_field("user", "firstaccess", time(), "id", $USER->id)) {
+ error("Could not set this user's first access date!");
+ }
+ if (!update_user_in_db($USER->id)) {
+ error("Could not update this user's information");
}
set_moodle_cookie($USER->username);
+ // The user has confirmed successfully, let's log them in
+
$USER->loggedin = true;
$USER->confirmed = 1;
$USER->site = $CFG->wwwroot;
-
save_session("USER");
- if ( ! empty($SESSION->wantsurl) ) {
+ if ( ! empty($SESSION->wantsurl) ) { // Send them where they were going
$goto = $SESSION->wantsurl;
unset($SESSION->wantsurl);
save_session("SESSION");
}
-function reset_password_and_mail($user) {
-
- global $CFG;
-
- $site = get_site();
- $from = get_admin();
-
- $newpassword = generate_password();
-
- if (! set_field("user", "password", md5($newpassword), "id", $user->id) ) {
- error("Could not set user password!");
- }
-
- $a->firstname = $user->firstname;
- $a->sitename = $site->fullname;
- $a->username = $user->username;
- $a->newpassword = $newpassword;
- $a->link = "$CFG->wwwroot/login/change_password.php";
- $a->signoff = "$from->firstname $from->lastname ($from->email)";
-
- $message = get_string("newpasswordtext", "", $a);
-
- $subject = "$site->fullname: ".get_string("changedpassword");
-
- return email_to_user($user, $from, $subject, $message);
-
-}
-
?>
// No footer on this page
-function update_user_login_times() {
- global $db, $USER;
-
- $USER->lastlogin = $USER->currentlogin;
- $USER->currentlogin = time();
- save_session("USER");
-
- return $db->Execute("UPDATE user
- SET lastlogin='$USER->lastlogin', currentlogin='$USER->currentlogin'
- WHERE id = '$USER->id'");
-}
?>
}
-function random_string ($length=15) {
- $pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- $pool .= "abcdefghijklmnopqrstuvwxyz";
- $pool .= "0123456789";
- $poollen = strlen($pool);
- mt_srand ((double) microtime() * 1000000);
- $string = "";
- for ($i = 0; $i < $length; $i++) {
- $string .= substr($pool, (mt_rand()%($poollen)), 1);
- }
- return $string;
-}
-
-
-function send_confirmation_email($user) {
-
- global $CFG;
-
- $site = get_site();
- $from = get_admin();
-
- $data->firstname = $user->firstname;
- $data->sitename = $site->fullname;
- $data->link = "$CFG->wwwroot/login/confirm.php?p=$user->secret&s=$user->username";
- $data->admin = "$from->firstname $from->lastname ($from->email)";
-
- $message = get_string("emailconfirmation", "", $data);
- $subject = "$site->fullname account confirmation";
-
- return email_to_user($user, $from, $subject, $message);
-
-}
-
-
-
?>