Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More little robustness things

  • Loading branch information...
commit 1c0200e07483022a208ff2be79d0921cc3693284 1 parent db70b54
moodler authored

Showing 3 changed files with 30 additions and 15 deletions. Show diff stats Hide diff stats

  1. +1 1  admin/lang.php
  2. +16 2 course/lib.php
  3. +13 12 course/teacher.php
2  admin/lang.php
@@ -122,7 +122,7 @@
122 122 }
123 123 }
124 124
125   - if ($somethingfound) {
  125 + if (!empty($somethingfound)) {
126 126 print_continue("lang.php");
127 127 } else {
128 128 notice(get_string("languagegood"), "lang.php");
18 course/lib.php
@@ -4,6 +4,8 @@
4 4
5 5 $COURSE_MAX_LOG_DISPLAY = 150; // days
6 6
  7 +$COURSE_MAX_LOGS_PER_PAGE = 1000; // records
  8 +
7 9 $COURSE_TEACHER_COLOR = "#990000"; // To hilight certain items that are teacher-only
8 10
9 11 $COURSE_LIVELOG_REFRESH = 60; // Seconds
@@ -107,7 +109,7 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
107 109 // It is assumed that $date is the GMT time of midnight for that day,
108 110 // and so the next 86400 seconds worth of logs are printed.
109 111
110   - global $CFG;
  112 + global $CFG, $COURSE_MAX_LOGS_PER_PAGE;
111 113
112 114 if ($course->category) {
113 115 $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") {
139 141 $count=0;
140 142 $tt = getdate(time());
141 143 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
  144 + if (($totalcountlogs = count($logs)) > $COURSE_MAX_LOGS_PER_PAGE) {
  145 + $totalcountlogs = "$COURSE_MAX_LOGS_PER_PAGE/$totalcountlogs";
  146 + }
  147 +
142 148 echo "<P ALIGN=CENTER>";
143   - print_string("displayingrecords", "", count($logs));
  149 + print_string("displayingrecords", "", $totalcountlogs);
144 150 echo "</P>";
  151 +
  152 + $countlogs = 0;
145 153 echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
146 154 foreach ($logs as $log) {
147 155
  156 + $countlogs++;
  157 +
  158 + if ($countlogs > $COURSE_MAX_LOGS_PER_PAGE) {
  159 + break;
  160 + }
  161 +
148 162 if ($ld = get_record("log_display", "module", "$log->module", "action", "$log->action")) {
149 163 $log->info = get_field($ld->mtable, $ld->field, "id", $log->info);
150 164 }
25 course/teacher.php
@@ -66,12 +66,12 @@
66 66
67 67 /// Add a teacher if one is specified
68 68
69   - if ($add) {
  69 + if (!empty($add)) {
70 70 if (! $user = get_record("user", "id", $add)) {
71 71 error("That teacher (id = $add) doesn't exist", "teacher.php?id=$course->id");
72 72 }
73 73
74   - if ($teachers) {
  74 + if (!empty($teachers)) {
75 75 foreach ($teachers as $tt) {
76 76 if ($tt->id == $user->id) {
77 77 error("That user is already a teacher for this course.", "teacher.php?id=$course->id");
@@ -81,13 +81,13 @@
81 81
82 82 $teacher->userid = $user->id;
83 83 $teacher->course = $course->id;
84   - if ($teachers) {
  84 + if (!empty($teachers)) {
85 85 $teacher->authority = 2;
86 86 } else {
87 87 $teacher->authority = 1; // First teacher is the main teacher
88 88 }
89 89 $teacher->id = insert_record("user_teachers", $teacher);
90   - if (! $teacher->id) {
  90 + if (empty($teacher->id)) {
91 91 error("Could not add that teacher to this course!");
92 92 }
93 93 $teachers[] = $user;
@@ -95,11 +95,11 @@
95 95
96 96 /// Remove a teacher if one is specified.
97 97
98   - if ($remove) {
  98 + if (!empty($remove)) {
99 99 if (! $user = get_record("user", "id", $remove)) {
100 100 error("That teacher (id = $remove) doesn't exist", "teacher.php?id=$course->id");
101 101 }
102   - if ($teachers) {
  102 + if (!empty($teachers)) {
103 103 foreach ($teachers as $key => $tt) {
104 104 if ($tt->id == $user->id) {
105 105 remove_teacher($user->id, $course->id);
@@ -118,7 +118,7 @@
118 118
119 119 /// First, show existing teachers for this course
120 120
121   - if (! $teachers) {
  121 + if (empty($teachers)) {
122 122 echo "<P ALIGN=CENTER>$strnoexistingteachers</A>";
123 123
124 124 } else {
@@ -131,16 +131,17 @@
131 131
132 132 /// Print list of potential teachers
133 133
134   - if ($search) {
  134 + if (!empty($search)) {
135 135 $users = get_users_search($search);
  136 +
136 137 } else {
137 138 $users = get_users_confirmed();
138 139 }
139 140
140 141
141   - if ($users) {
  142 + if (!empty($users)) {
142 143 foreach ($users as $user) { // Remove users who are already teachers
143   - if ($teachers) {
  144 + if (!empty($teachers)) {
144 145 foreach ($teachers as $teacher) {
145 146 if ($teacher->id == $user->id) {
146 147 continue 2;
@@ -151,7 +152,7 @@
151 152 }
152 153 }
153 154
154   - if (! $potential) {
  155 + if (empty($potential)) {
155 156 echo "<P ALIGN=CENTER>$strnopotentialteachers</A>";
156 157 if ($search) {
157 158 echo "<FORM ACTION=teacher.php METHOD=GET>";
@@ -162,7 +163,7 @@
162 163 }
163 164
164 165 } else {
165   - if ($search) {
  166 + if (!empty($search)) {
166 167 echo "<P ALIGN=CENTER>($strsearchresults)</P>";
167 168 }
168 169 if (count($potential) <= 20) {

0 comments on commit 1c0200e

Please sign in to comment.
Something went wrong with that request. Please try again.