]> git.mjollnir.org Git - moodle.git/commitdiff
Fixed a few notices and extended some functions a little
authormoodler <moodler>
Thu, 29 Jul 2004 14:54:25 +0000 (14:54 +0000)
committermoodler <moodler>
Thu, 29 Jul 2004 14:54:25 +0000 (14:54 +0000)
lib/moodlelib.php
lib/weblib.php

index 19c1c4bc0c4dc5cc00bc5221ddd2232729095b30..757c1375b368d4d05ccf77b400d3363c6b8493d2 100644 (file)
@@ -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)
index 317ffca1df0b0a909162655241ebce67795177ec..ce72da401acc9af5ca3eba9c2108b9b4cfd5378f 100644 (file)
@@ -1350,7 +1350,17 @@ function print_user($user, $course) {
         echo "$string->email: <a href=\"mailto:$user->email\">$user->email</a><br />";
     }
     if ($user->city or $user->country) {
-        echo "$string->location: $user->city, ".$countries["$user->country"]."<br />";
+        echo "$string->location: ";
+        if ($user->city) {
+            echo $user->city;
+        }
+        if (!empty($countries[$user->country])) {
+            if ($user->city) {
+                echo ', ';
+            }
+            echo $countries[$user->country];
+        }
+        echo "<br />";
     }
     if ($user->lastaccess) {
         echo "$string->lastaccess: ".userdate($user->lastaccess);