From b40bc478d965132c2fe883e53d4b3317df2f3302 Mon Sep 17 00:00:00 2001 From: moodler Date: Thu, 29 Jul 2004 14:54:25 +0000 Subject: [PATCH] Fixed a few notices and extended some functions a little --- lib/moodlelib.php | 36 ++++++++++++++++++++++++------------ lib/weblib.php | 12 +++++++++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 19c1c4bc0c..757c1375b3 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -804,15 +804,17 @@ function authenticate_user_login($username, $password) { } } -function enrol_student($userid, $courseid) { +function enrol_student($userid, $courseid, $timestart=0, $timeend=0) { /// Enrols a student in a given course + $course = get_record("course", "id", $courseid); + if (!record_exists("user_students", "userid", $userid, "course", $courseid)) { if (record_exists("user", "id", $userid)) { $student->userid = $userid; $student->course = $courseid; - $student->start = 0; - $student->end = 0; + $student->timestart = $timestart; + $student->timeend = $timeend; $student->time = time(); return insert_record("user_students", $student); } @@ -845,16 +847,23 @@ function unenrol_student($userid, $courseid=0) { } } -function add_teacher($userid, $courseid, $editall=1, $role="") { +function add_teacher($userid, $courseid, $editall=1, $role="", $timestart=0, $timeend=0) { /// Add a teacher to a given course if ($teacher = get_record('user_teachers', 'userid', $userid, 'course', $courseid)) { - if ($teacher->editall == $editall) { // Already exists - return true; - } else { // Just change field - set_field('user_teachers', 'editall', $editall, 'id', $teacher->id); - return true; + $newteacher = NULL; + $newteacher->id = $teacher->id; + $newteacher->editall = $editall; + if ($role) { + $newteacher->role = $role; + } + if ($timestart) { + $newteacher->timestart = $timestart; } + if ($timeend) { + $newteacher->timeend = $timeend; + } + return update_record('user_teachers', $newteacher); } if (!record_exists("user", "id", $userid)) { @@ -2366,7 +2375,7 @@ function moodle_needs_upgrading() { /// MISCELLANEOUS //////////////////////////////////////////////////////////////////// function notify_login_failures() { - global $CFG; + global $CFG, $db; // notify admin users or admin user of any failed logins (since last notification). switch ($CFG->notifyloginfailures) { @@ -2394,12 +2403,14 @@ function notify_login_failures() { AND module='login' AND action='error' GROUP BY info HAVING count(*) > $CFG->notifyloginthreshold"); if ($notifyipsrs) { + $ipstr = ''; while ($row = $notifyipsrs->FetchRow()) { $ipstr .= "'".$row['ip']."',"; } $ipstr = substr($ipstr,0,strlen($ipstr)-1); } if ($notifyusersrs) { + $userstr = ''; while ($row = $notifyusersrs->FetchRow()) { $userstr .= "'".$row['info']."',"; } @@ -2413,9 +2424,10 @@ function notify_login_failures() { : ((strlen($ipstr) != 0) ? " AND ip IN ($ipstr) " : " AND info IN ($userstr) ")),"l.time DESC","","",$count); // if we haven't run in the last hour and we have something useful to report and we are actually supposed to be reporting to somebody - if (is_array($recip) and count($recip) > 0 and (($timenow - (60 * 60)) > $CFG->lastnotifyfailure) + if (is_array($recip) and count($recip) > 0 and ((time() - (60 * 60)) > $CFG->lastnotifyfailure) and is_array($logs) and count($logs) > 0) { - + + $message = ''; $site = get_site(); $subject = get_string('notifyloginfailuressubject','',$site->fullname); $message .= get_string('notifyloginfailuresmessagestart','',$CFG->wwwroot) diff --git a/lib/weblib.php b/lib/weblib.php index 317ffca1df..ce72da401a 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1350,7 +1350,17 @@ function print_user($user, $course) { echo "$string->email: email\">$user->email
"; } if ($user->city or $user->country) { - echo "$string->location: $user->city, ".$countries["$user->country"]."
"; + echo "$string->location: "; + if ($user->city) { + echo $user->city; + } + if (!empty($countries[$user->country])) { + if ($user->city) { + echo ', '; + } + echo $countries[$user->country]; + } + echo "
"; } if ($user->lastaccess) { echo "$string->lastaccess: ".userdate($user->lastaccess); -- 2.39.5