comparison index.php @ 44:57af36f0864e

Rename some functions + reindentation cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 Aug 2012 18:35:20 +0300
parents 7621bfc47491
children d8a1e85b8dda
comparison
equal deleted inserted replaced
43:7621bfc47491 44:57af36f0864e
49 global $luokkaDefault; 49 global $luokkaDefault;
50 if (preg_match("#^([A-Z]{3}\d[A-Za-z0-9_]{1,6}|ccr|Ryh_[A-Z]{3}\d[A-Za-z0-9_]{1,6})$#", $id, $m)) { 50 if (preg_match("#^([A-Z]{3}\d[A-Za-z0-9_]{1,6}|ccr|Ryh_[A-Z]{3}\d[A-Za-z0-9_]{1,6})$#", $id, $m)) {
51 $id = $m[1]; 51 $id = $m[1];
52 return TRUE; 52 return TRUE;
53 } else { 53 } else {
54 lukErrorMsg("Virhe! Luokan täytyy olla muotoa <b>XXXnXXX</b>, käytetään vakioarvoa <b>".$luokkaDefault."</b>."); 54 errorMsg("Virhe! Luokan täytyy olla muotoa <b>XXXnXXX</b>, käytetään vakioarvoa <b>".$luokkaDefault."</b>.");
55 $id = $luokkaDefault; 55 $id = $luokkaDefault;
56 return FALSE; 56 return FALSE;
57 } 57 }
58 } 58 }
59 59
119 } else 119 } else
120 if (isset($_COOKIE["lukluokka"])) { 120 if (isset($_COOKIE["lukluokka"])) {
121 $luokka = $_COOKIE["lukluokka"]; 121 $luokka = $_COOKIE["lukluokka"];
122 lukCheckClassID($luokka); 122 lukCheckClassID($luokka);
123 } else { 123 } else {
124 lukErrorMsg("Luokkaa ei asetettu, käytetään vakioarvoa <b>".$luokkaDefault."</b>."); 124 errorMsg("Luokkaa ei asetettu, käytetään vakioarvoa <b>".$luokkaDefault."</b>.");
125 $luokka = $luokkaDefault; 125 $luokka = $luokkaDefault;
126 } 126 }
127 127
128 128
129 if (isset($_GET["tila"])) { 129 if (isset($_GET["tila"])) {
174 } 174 }
175 flock($fp, LOCK_UN); 175 flock($fp, LOCK_UN);
176 } 176 }
177 fclose($fp); 177 fclose($fp);
178 } else { 178 } else {
179 lukErrorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua."); 179 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua.");
180 } 180 }
181 181
182 182
183 if (!file_exists($dataFile)) { 183 if (!file_exists($dataFile)) {
184 lukErrorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! Jos luokkakoodi on uusi, ilmestyy se järjestelmään seuraavan päivityksen aikana. Luokkatiedot päivitetään 2 kertaa vuorokaudessa."); 184 errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ".
185 "Jos luokkakoodi on uusi, ilmestyy se järjestelmään seuraavan ".
186 "päivityksen aikana. Luokkatiedot päivitetään kerran viikossa.");
185 $haveData = FALSE; 187 $haveData = FALSE;
186 } else { 188 } else {
187 require($dataFile); 189 require($dataFile);
188 $haveData = isset($classDefs); 190 $haveData = isset($classDefs);
189 } 191 }
190 192
191 193
192 function printHourInfo($dayHours, $showDays) 194 function lukPrintHourInfo($dayHours, $showDays)
193 { 195 {
194 $out = " <tr>\n <td>Tunteja<br />(<b>ryhmä/vv</b>)</td>\n"; 196 $out = " <tr>\n <td>Tunteja<br />(<b>ryhmä/vv</b>)</td>\n";
195 for ($day = 0; $day < $showDays; $day++) { 197 for ($day = 0; $day < $showDays; $day++) {
196 $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n"; 198 $out .= " <td>".$dayHours[$day]["total"]."h (<b>".$dayHours[$day]["grouped"]."h</b>)</td>\n";
197 } 199 }
211 break; 213 break;
212 return $n; 214 return $n;
213 } 215 }
214 216
215 217
216 function findNextHour(&$j, &$i, $day, $hour, $chk) 218 function lukFindNextActiveHour(&$j, &$i, $day, $hour, $chk)
217 { 219 {
218 global $classInfo, $classHourTable; 220 global $classInfo, $classHourTable;
219 // for ($j = $day; $j < $classInfo["maxdays"]; $j++) 221 // for ($j = $day; $j < $classInfo["maxdays"]; $j++)
220 $j = $day; 222 $j = $day;
221 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) { 223 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) {
228 230
229 return -1; 231 return -1;
230 } 232 }
231 233
232 234
233 function getHourInfo($isSplit, $d) 235 function lukGetHourInfo($isSplit, $d)
234 { 236 {
235 if ($isSplit) { 237 if ($isSplit) {
236 $out = "<table>". 238 $out = "<table>".
237 "<tr><td>".lukMatchCourse($d[0])."</td><td>".lukMatchCourse($d[1])."</td></tr>"; 239 "<tr><td>".lukMatchCourse($d[0])."</td><td>".lukMatchCourse($d[1])."</td></tr>";
238 240
239 for ($j = 2; $j < count($d); $j += 2) 241 for ($i = 2; $i < count($d); $i += 2)
240 $out .= "<tr><td>".lukChEntities($d[$j])."</td><td>".(isset($d[$j+1]) ? lukChEntities($d[$j+1]) : "")."</td></tr>"; 242 $out .= "<tr><td>".lukChEntities($d[$i])."</td><td>".(isset($d[$i+1]) ? lukChEntities($d[$i+1]) : "")."</td></tr>";
241 243
242 return $out."</table>"; 244 return $out."</table>";
243 } else { 245 } else {
244 $out = lukMatchCourse($d[0])."<br />"; 246 $out = lukMatchCourse($d[0])."<br />";
245 247
246 for ($j = 1; $j < count($d); $j++) 248 for ($i = 1; $i < count($d); $i++)
247 $out .= lukChEntities($d[$j])."<br />"; 249 $out .= lukChEntities($d[$i])."<br />";
248 250
249 return $out; 251 return $out;
250 } 252 }
251 } 253 }
252 254
253 255
254 function getHourInfoData($id) 256 function lukGetHourInfoData($id)
255 { 257 {
256 global $classDefs; 258 global $classDefs;
257 259
258 if (isset($id)) { 260 if (isset($id)) {
259 if ($id >= 0 && isset($classDefs[$id])) { 261 if ($id >= 0 && isset($classDefs[$id])) {
260 $i = $classDefs[$id]; 262 $i = $classDefs[$id];
261 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]); 263 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]);
262 return getHourInfo($isSplit, $i["data"]); 264 return lukGetHourInfo($isSplit, $i["data"]);
263 } else 265 } else
264 return "<p>Ei tunteja.</p>"; 266 return "<p>Ei tunteja.</p>";
265 } else 267 } else
266 return "<p>Ei mitään.</p>"; 268 return "<p>Ei mitään.</p>";
267 269
268 return ""; 270 return "";
269 } 271 }
270 272
273
274 $out = "";
271 275
272 if ($miniMode && $haveData) { 276 if ($miniMode && $haveData) {
273 $stamp = time(); 277 $stamp = time();
274 $aika = getdate($stamp); 278 $aika = getdate($stamp);
275 $day = $aika["wday"] - 1; 279 $day = $aika["wday"] - 1;
281 if ($hour >= 0 && $day >= 0) 285 if ($hour >= 0 && $day >= 0)
282 { 286 {
283 $id = $classHourTable[$hour][$day]; 287 $id = $classHourTable[$hour][$day];
284 $out .= 288 $out .=
285 "<h2>".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". 289 "<h2>".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n".
286 getHourInfoData($id)."\n"; 290 lukGetHourInfoData($id)."\n";
287 } 291 }
288 292
289 293
290 if (isset($id) && $id >= 0 && isset($classDefs[$id])) { 294 if (isset($id) && $id >= 0 && isset($classDefs[$id])) {
291 $i = $classDefs[$id]; 295 $i = $classDefs[$id];
307 $hour = 0; 311 $hour = 0;
308 $id = -1; 312 $id = -1;
309 } 313 }
310 314
311 // echo "day=$day, hour=$hour, id=$id<br />\n"; 315 // echo "day=$day, hour=$hour, id=$id<br />\n";
312 $found = findNextHour($nday, $nhour, $day, $hour, $id); 316 $found = lukFindNextActiveHour($nday, $nhour, $day, $hour, $id);
313 317
314 // echo "nday=$nday, nhour=$nhour, id=$found<br />\n"; 318 // echo "nday=$nday, nhour=$nhour, id=$found<br />\n";
315 319
316 $out .= "<h2>Seuraavaksi"; 320 $out .= "<h2>Seuraavaksi";
317 if ($found > 0) { 321 if ($found > 0) {
318 $stamp = lukMakeHourStamp($nhour, 0, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]); 322 $stamp = lukMakeHourStamp($nhour, 0, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]);
319 $aika = getdate($stamp); 323 $aika = getdate($stamp);
320 $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n". 324 $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n".
321 getHourInfoData($found)."\n"; 325 lukGetHourInfoData($found)."\n";
322 } else { 326 } else {
323 $out .= "</h2>\n". 327 $out .= "</h2>\n".
324 "<p>Ei mitään</p>\n"; 328 "<p>Ei mitään</p>\n";
325 } 329 }
326 330
360 $out .= " <th style=\"width: ".(100 / $classInfo["maxdays"]). 364 $out .= " <th style=\"width: ".(100 / $classInfo["maxdays"]).
361 "%;\" class=\"days\">".$dayNames[$day]."</th>\n"; 365 "%;\" class=\"days\">".$dayNames[$day]."</th>\n";
362 } 366 }
363 $out .= " </tr>\n"; 367 $out .= " </tr>\n";
364 368
365 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) { 369 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) {
366 $out .= " <tr>\n". 370 $out .= " <tr>\n".
367 " <th class=\"hours\">".getHour($hour)."</th>\n"; 371 " <th class=\"hours\">".getHour($hour)."</th>\n";
368 for ($day = 0; $day < $classInfo["maxdays"]; $day++) { 372 for ($day = 0; $day < $classInfo["maxdays"]; $day++) {
369 if (isset($classHourTable[$hour][$day])) { 373 if (isset($classHourTable[$hour][$day])) {
370 $h = $classHourTable[$hour][$day]; 374 $h = $classHourTable[$hour][$day];
371 375
372 if ($h < 1) { 376 if ($h < 1) {
373 if ($h > -9999) { 377 if ($h > -9999) {
374 $n = lukResolveHours($hour, $day, $h, TRUE); 378 $n = lukResolveHours($hour, $day, $h, TRUE);
375 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n"; 379 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n";
376 } 380 }
381 } else
382 if (isset($classDefs[$h])) {
383 if (!isset($classDefs[$h]["done"])) {
384 $classDefs[$h]["done"] = true;
385 $i = $classDefs[$h];
386 $d = $classDefs[$h]["data"];
387
388 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]);
389
390 $hours = lukResolveHours($hour, $day, $h, FALSE);
391 if ($hours != $i["hours"]) {
392 errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!");
393 }
394
395 $out .= " <td rowspan=\"".$hours.
396 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">".
397 lukGetHourInfo($isSplit, $d).
398 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n";
399 }
400 } else
401 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!");
377 } else 402 } else
378 if (isset($classDefs[$h])) { 403 errorMsg("Internal error, cell $hour / $day does not exist.");
379 if (!isset($classDefs[$h]["done"])) { 404 }
380 $classDefs[$h]["done"] = true; 405 $out .= " </tr>\n";
381 $i = $classDefs[$h]; 406 }
382 $d = $classDefs[$h]["data"]; 407
383 408 $out .= lukPrintHourInfo($dayHours, $classInfo["maxdays"]).
384 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]);
385
386 $hours = lukResolveHours($hour, $day, $h, FALSE);
387 if ($hours != $i["hours"]) {
388 lukErrorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!");
389 }
390
391 $out .= " <td rowspan=\"".$hours.
392 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">".
393 getHourInfo($isSplit, $d).
394 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n";
395 }
396 } else
397 lukErrorMsg("Internal error cell $hour / $day : hour id $h does not exist!");
398 } else
399 lukErrorMsg("Internal error, cell $hour / $day does not exist.");
400 }
401 $out .= " </tr>\n";
402 }
403
404 $out .= printHourInfo($dayHours, $classInfo["maxdays"]).
405 "</table>\n"; 409 "</table>\n";
406 410
407 } // haveData 411 } // haveData
408 412
409 413
446 echo "<h1>".$pageTitle."</h1>\n"; 450 echo "<h1>".$pageTitle."</h1>\n";
447 451
448 // Show error messages 452 // Show error messages
449 if ($errorSet) { 453 if ($errorSet) {
450 echo "<ul>\n"; 454 echo "<ul>\n";
451 foreach ($lukErrorMsgs as $msg) 455 foreach ($errorMsgs as $msg)
452 echo "<li>$msg</li>\n"; 456 echo "<li>$msg</li>\n";
453 echo "</ul>\n"; 457 echo "</ul>\n";
454 } 458 }
455 459
456 echo $out; 460 echo $out;