From 1c0200e07483022a208ff2be79d0921cc3693284 Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 1 Jan 2003 08:21:19 +0000 Subject: [PATCH] More little robustness things --- admin/lang.php | 2 +- course/lib.php | 18 ++++++++++++++++-- course/teacher.php | 25 +++++++++++++------------ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/admin/lang.php b/admin/lang.php index 2289ca713c..6fe4da5f2b 100644 --- a/admin/lang.php +++ b/admin/lang.php @@ -122,7 +122,7 @@ } } - if ($somethingfound) { + if (!empty($somethingfound)) { print_continue("lang.php"); } else { notice(get_string("languagegood"), "lang.php"); diff --git a/course/lib.php b/course/lib.php index 1ff0e9a1a2..a28a54fc9c 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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 "

"; - print_string("displayingrecords", "", count($logs)); + print_string("displayingrecords", "", $totalcountlogs); echo "

"; + + $countlogs = 0; echo ""; 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); } diff --git a/course/teacher.php b/course/teacher.php index bfd220a551..e3172f4b36 100644 --- a/course/teacher.php +++ b/course/teacher.php @@ -66,12 +66,12 @@ /// 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"); @@ -81,13 +81,13 @@ $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; @@ -95,11 +95,11 @@ /// 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); @@ -118,7 +118,7 @@ /// First, show existing teachers for this course - if (! $teachers) { + if (empty($teachers)) { echo "

$strnoexistingteachers"; } else { @@ -131,16 +131,17 @@ /// 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; @@ -151,7 +152,7 @@ } } - if (! $potential) { + if (empty($potential)) { echo "

$strnopotentialteachers"; if ($search) { echo "
"; @@ -162,7 +163,7 @@ } } else { - if ($search) { + if (!empty($search)) { echo "

($strsearchresults)

"; } if (count($potential) <= 20) { -- 2.39.5