]> git.mjollnir.org Git - moodle.git/commitdiff
More little robustness things
authormoodler <moodler>
Wed, 1 Jan 2003 08:21:19 +0000 (08:21 +0000)
committermoodler <moodler>
Wed, 1 Jan 2003 08:21:19 +0000 (08:21 +0000)
admin/lang.php
course/lib.php
course/teacher.php

index 2289ca713ce1c5cf8c5ae5c2f2beeab346621c29..6fe4da5f2b32ee84fd6c96ef4ef68412b358333f 100644 (file)
             }
         }
     
-        if ($somethingfound) {
+        if (!empty($somethingfound)) {
             print_continue("lang.php");
         } else {
             notice(get_string("languagegood"), "lang.php");
index 1ff0e9a1a230901c2a3db85f7291fc7a2308c521..a28a54fc9c1c08d59919e177bb12e811d59f7b0f 100644 (file)
@@ -4,6 +4,8 @@
 
 $COURSE_MAX_LOG_DISPLAY = 150;       // days
 
+$COURSE_MAX_LOGS_PER_PAGE = 1000;    // records
+
 $COURSE_TEACHER_COLOR = "#990000";   // To hilight certain items that are teacher-only
 
 $COURSE_LIVELOG_REFRESH = 60;        // Seconds
@@ -107,7 +109,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
 // It is assumed that $date is the GMT time of midnight for that day, 
 // and so the next 86400 seconds worth of logs are printed.
 
-    global $CFG;
+    global $CFG, $COURSE_MAX_LOGS_PER_PAGE;
 
     if ($course->category) {
         $selector = "WHERE l.course='$course->id' AND l.userid = u.id";
@@ -139,12 +141,24 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
     $count=0;
     $tt = getdate(time());
     $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
+    if (($totalcountlogs = count($logs)) > $COURSE_MAX_LOGS_PER_PAGE) {
+        $totalcountlogs = "$COURSE_MAX_LOGS_PER_PAGE/$totalcountlogs";
+    }
+
     echo "<P ALIGN=CENTER>";
-    print_string("displayingrecords", "", count($logs));
+    print_string("displayingrecords", "", $totalcountlogs);
     echo "</P>";
+
+    $countlogs = 0;
     echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
     foreach ($logs as $log) {
 
+        $countlogs++;
+
+        if ($countlogs > $COURSE_MAX_LOGS_PER_PAGE) {
+            break;
+        }
+
         if ($ld = get_record("log_display", "module", "$log->module", "action", "$log->action")) {
             $log->info = get_field($ld->mtable, $ld->field, "id", $log->info);
         }
index bfd220a551b04861f59b9c1e30802e1e7dfd20fb..e3172f4b36eafc868c2faa9f4fa2eb8aefa6ad5b 100644 (file)
 
 /// Add a teacher if one is specified
 
-    if ($add) {
+    if (!empty($add)) {
         if (! $user = get_record("user", "id", $add)) {
             error("That teacher (id = $add) doesn't exist", "teacher.php?id=$course->id");
         }
 
-        if ($teachers) {
+        if (!empty($teachers)) {
             foreach ($teachers as $tt) {
                 if ($tt->id == $user->id) {
                     error("That user is already a teacher for this course.", "teacher.php?id=$course->id");
 
         $teacher->userid   = $user->id;
         $teacher->course = $course->id;
-        if ($teachers) {
+        if (!empty($teachers)) {
             $teacher->authority = 2;
         } else {
             $teacher->authority = 1;   // First teacher is the main teacher
         }
         $teacher->id = insert_record("user_teachers", $teacher);
-        if (! $teacher->id) {
+        if (empty($teacher->id)) {
             error("Could not add that teacher to this course!");
         }
         $teachers[] = $user;
 
 /// Remove a teacher if one is specified.
 
-    if ($remove) {
+    if (!empty($remove)) {
         if (! $user = get_record("user", "id", $remove)) {
             error("That teacher (id = $remove) doesn't exist", "teacher.php?id=$course->id");
         }
-        if ($teachers) {
+        if (!empty($teachers)) {
             foreach ($teachers as $key => $tt) {
                 if ($tt->id == $user->id) {
                     remove_teacher($user->id, $course->id);
 
 /// First, show existing teachers for this course
 
-    if (! $teachers) { 
+    if (empty($teachers)) { 
         echo "<P ALIGN=CENTER>$strnoexistingteachers</A>";
 
     } else {
 
 /// Print list of potential teachers
 
-    if ($search) {
+    if (!empty($search)) {
         $users = get_users_search($search);
+
     } else {
         $users = get_users_confirmed();
     }
 
     
-    if ($users) {
+    if (!empty($users)) {
         foreach ($users as $user) {  // Remove users who are already teachers
-            if ($teachers) {
+            if (!empty($teachers)) {
                 foreach ($teachers as $teacher) {
                     if ($teacher->id == $user->id) {
                         continue 2;
         }
     }
 
-    if (! $potential) { 
+    if (empty($potential)) { 
         echo "<P ALIGN=CENTER>$strnopotentialteachers</A>";
         if ($search) {
             echo "<FORM ACTION=teacher.php METHOD=GET>";
         }
 
     } else {
-        if ($search) {
+        if (!empty($search)) {
             echo "<P ALIGN=CENTER>($strsearchresults)</P>";
         }
         if (count($potential) <= 20) {