comparison index.php @ 193:16ce445c499a v3 tip

Import v3 branch.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 22 Jan 2017 02:31:10 +0200
parents f2adb44ea251
children
comparison
equal deleted inserted replaced
192:9f7eb4db99b4 193:16ce445c499a
1 <?php 1 <?php
2 // 2 //
3 // OAMK Lukkari v2.7 3 // OAMK Lukkari v3.0
4 // (C) Copyright 2010 - 2016 Matti 'ccr' Hämäläinen <ccr@tnsp.org> 4 // (C) Copyright 2010 - 2015 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
5 // Yes, this code is rather horrible. :| 5 // Yes, this code is rather horrible. :|
6 // 6 //
7 // Include framework 7 // Include framework
8 require "mgeneric.inc.php"; 8 require "mgeneric.inc.php";
9 9
10 // Default settings 10 // Default settings
11 $pageName = "OAMK Lukkari"; 11 $pageName = "OAMK Lukkari";
12 $pageVersion = "2.7"; 12 $pageVersion = "3.0alpha";
13 $mobileMode = FALSE; 13 $mobileMode = FALSE;
14 $baseURI = "http://example.com/"; 14 $baseURI = "http://example.com/";
15 15
16 $pageLanguages = array("fi", "en"); 16 $pageLanguages = array("fi", "en");
17 $pageCSSData = array("cookie" => "lukcss", "prefix" => "luk"); 17 $pageCSSData = array("cookie" => "lukcss", "prefix" => "luk");
192 { 192 {
193 global $classHourTimes; 193 global $classHourTimes;
194 if (isset($classHourTimes[$hour])) 194 if (isset($classHourTimes[$hour]))
195 { 195 {
196 return 196 return
197 "<br />".
198 lukGetHourStamp($classHourTimes[$hour]["start"]). 197 lukGetHourStamp($classHourTimes[$hour]["start"]).
199 " - ". 198 " - ".
200 lukGetHourStamp($classHourTimes[$hour]["end"]). 199 lukGetHourStamp($classHourTimes[$hour]["end"]);
201 "<br /><br />";
202 } 200 }
203 else 201 else
204 return "ERROR"; 202 return "ERROR";
205 } 203 }
206 204
277 else 275 else
278 return chentities($id); 276 return chentities($id);
279 } 277 }
280 278
281 279
282 function lukGetClassInfo($class) 280 function lukGetClassInfo($class, $indent = "")
283 { 281 {
284 $data = $class["data"]; 282 $data = $class["data"];
285
286 if ($class["grouped"]) 283 if ($class["grouped"])
287 { 284 {
288 // Grouped format 285 $out = "";
289 $out = "<table><tr>";
290
291 // Calculate max columns and add course titles
292 $maxColumns = 0;
293 foreach ($data as $col) 286 foreach ($data as $col)
294 { 287 {
295 $out .= "<td>".lukMatchCourse($col[0])."</td>"; 288 $out .=
296 if (count($col) > $maxColumns) 289 $indent."<div class=\"group\">\n".
297 $maxColumns = count($col); 290 $indent." <div class=\"groupCell\">".lukMatchCourse($col[0])."</div>\n";
298 } 291
299 $out .= "</tr>"; 292 for ($i = 1; $i < count($col); $i++)
300
301 // Print rest of the data
302 $ncol = 1;
303 for ($i = 1; $i < $maxColumns; $i++)
304 {
305 $out .= "<tr>";
306 foreach ($data as $col)
307 { 293 {
308 $out .= "<td>"; 294 $out .=
309 if (isset($col[$i])) 295 $indent." <div class=\"groupCell\">".
310 $out .= chentities($col[$i]); 296 (isset($col[$i]) ? chentities($col[$i]) : "").
311 $out .= "</td>"; 297 "</div>\n";
312 } 298 }
313 $out .= "</tr>"; 299
314 $ncol++; 300 $out .= $indent."</div>\n";
315 } 301 }
316 302
317 $out .= "</table>"; 303 if ($class["turns"])
304 $out .= "<div class=\"groupCell eoWeekly\">".cmQM("vuoroviikoin")."</div>\n";
305
306 return $out;
318 } 307 }
319 else 308 else
320 { 309 {
321 $out = lukMatchCourse($data[0][0])."<br />"; 310 $out = $indent."<div class=\"groupCell\">".lukMatchCourse($data[0][0])."</div>\n";
322 311
323 for ($i = 1; $i < count($data[0]); $i++) 312 for ($i = 1; $i < count($data[0]); $i++)
324 { 313 {
325 $out .= chentities($data[0][$i])."<br />"; 314 $out .= $indent."<div class=\"groupCell\">".chentities($data[0][$i])."</div>\n";
326 } 315 }
327 } 316
328 317 if ($class["turns"])
329 if ($class["turns"]) 318 $out .= "<div class=\"groupCell eoWeekly\">".cmQM("vuoroviikoin")."</div>\n";
330 $out .= cmQM("vuoroviikoin"); 319
331 320 return $out;
332 return $out; 321 }
333 } 322 }
334 323
335 324
336 function lukFindClass($day, $hour) 325 function lukFindClass($day, $hour)
337 { 326 {
389 $currTime = $currStamp - mktime(0, 0, 0); 378 $currTime = $currStamp - mktime(0, 0, 0);
390 $currDay = lukGetWeekdayFromTimestamp($currStamp); 379 $currDay = lukGetWeekdayFromTimestamp($currStamp);
391 380
392 $nextStamp = $currStamp + 30 * 60; 381 $nextStamp = $currStamp + 30 * 60;
393 $nextTime = $nextStamp - mktime(0, 0, 0); 382 $nextTime = $nextStamp - mktime(0, 0, 0);
383
384 $out =
385 "<div id=\"timeTable\">\n";
394 386
395 // Create the timetable table 387 // Create the timetable table
396 if ($mini) 388 if ($mini)
397 { 389 {
398 $out =
399 "<table id=\"timeTable\">\n".
400 " <tr>\n".
401 " <th></th>".
402 " <th class=\"days\">".lukGetDayName($currDay)."</th>\n".
403 " </tr>\n";
404
405 $startDay = $currDay; 390 $startDay = $currDay;
406 $lastDay = $currDay + 1; 391 $lastDay = $currDay + 1;
407 } 392 }
408 else 393 else
409 { 394 {
410 $out =
411 "<p>".join("; ", $classInfo["general"]).
412 //" [".cmQM("viikossa", $classInfo["totalHours"])."]".
413 "</p>\n".
414 "<table id=\"timeTable\">\n".
415 " <tr>\n".
416 " <th></th>\n";
417
418 $cellWidth = $classInfo["maxDays"] > 0 ? 100 / $classInfo["maxDays"] : 15;
419 if ($cellWidth > 25) $cellWidth = 25;
420
421 for ($day = 0; $day < $classInfo["maxDays"]; $day++)
422 {
423 $out .= " <th style=\"width: ".$cellWidth."%;\" class=\"days\">".lukGetDayName($day)."</th>\n";
424 }
425 $out .= " </tr>\n";
426 $startDay = 0; 395 $startDay = 0;
427 $lastDay = $classInfo["maxDays"]; 396 $lastDay = $classInfo["maxDays"];
428 } 397 }
429 398
430 399 $out .=
400 " <div class=\"timeTableHourList\" style=\"width: ".($mini ? "20%" : "10%").";\">\n".
401 " <div class=\"timeTableWeekday\">&nbsp;</div>\n";
431 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++) 402 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++)
432 { 403 {
433 $out .= " <tr>\n". 404 $out .= " <div class=\"timeTableHourBox\"><div class=\"timeTableHour\">".lukGetHourStr($hour)."</div></div>\n";
434 " <th class=\"hours\">".lukGetHourStr($hour)."</th>\n"; 405 }
435 for ($day = $startDay; $day < $lastDay; $day++) 406 $out .= " </div>\n";
407
408 if ($mini)
409 $tmpS = "style=\"width: 75%;\"";
410 else
411 $tmpS = sprintf("style=\"width: %1.3f%%;\"", 100 / ($lastDay - $startDay + 1));
412
413 for ($day = $startDay; $day < $lastDay; $day++)
414 {
415 $out .=
416 " <div class=\"timeTableDay".($day == $currDay ? " active" : "")."\" ".$tmpS.">\n".
417 " <div class=\"timeTableWeekday\">".lukGetDayName($day)."</div>\n";
418
419 for ($hour = $classInfo["firstHour"]; $hour < $classInfo["lastHour"]; $hour++)
436 { 420 {
437 $id = lukFindClass($day, $hour); 421 $id = lukFindClass($day, $hour);
438 if ($id > 0) 422 if ($id > 0)
439 { 423 {
440 $class = &$classHourDefs[$id]; 424 $class = &$classHourDefs[$id];
448 432
449 $isActive = $day == $currDay && 433 $isActive = $day == $currDay &&
450 $currTime >= $classHourTimes[$class["start"]]["start"] && 434 $currTime >= $classHourTimes[$class["start"]]["start"] &&
451 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"]; 435 $currTime < $classHourTimes[$class["start"] + $class["hours"] - 1]["end"];
452 436
453 $out .= " <td rowspan=\"".$class["hours"]."\" ". 437 $out .=
454 "title=\"".lukClassGetHourStr($hour, $hour + $class["hours"] - 1)."\" class=\"". 438 " <div class=\"classInfoBox\" style=\"height: ".($class["hours"] * 6)."em;\">\n".
455 ($isActive ? "clactive " : ""). 439 " <div class=\"classInfo".
456 (!$isActive && $nextActive ? "clnext " : ""). 440 ($isActive ? " clactive" : "").
457 (($class["grouped"] || $class["turns"]) ? "clgrouped" : "clnormal")."\">". 441 (!$isActive && $nextActive ? " clnext " : "").
458 lukGetClassInfo($class). 442 (($class["grouped"] || $class["turns"]) ? " clgrouped" : " clnormal")."\">\n".
459 "<div class=\"nhours\"><span>".$class["hours"]."h</span></div></td>\n"; 443 lukGetClassInfo($class, " ").
444 " <div class=\"nhours\"><span>".lukClassGetHourStr($hour, $hour + $class["hours"] - 1)." (".$class["hours"]."h)</span></div>\n".
445 " </div>\n".
446 " </div>\n";
460 } 447 }
461 } 448 }
462 else 449 else
463 { 450 {
464 $out .= " <td class=\"clnothing\"></td>\n"; 451 $out .= " <div class=\"classInfoBox\"><div class=\"classInfo clnothing\"></div></div>\n";
465 } 452 }
466 } 453 }
467 $out .= " </tr>\n"; 454 $out .= " </div>\n";
468 } 455 }
469 456
470 return $out."</table>\n"; 457 return $out."</div>\n";
471 } 458 }
472 459
473 460
474 461
475 // 462 //
496 if (in_array($tmp, $pageLanguages)) 483 if (in_array($tmp, $pageLanguages))
497 $pageLang = $tmp; 484 $pageLang = $tmp;
498 } 485 }
499 486
500 487
488 // Cookie info window
489 $showCookieInfo = isset($_COOKIE["lukcookieinfo"]) ? !$_COOKIE["lukcookieinfo"] : TRUE;
490
491
492 // Development info window
493 $showDevInfo = isset($_COOKIE["lukdevinfo"]) ? $_COOKIE["lukdevinfo"] : TRUE;
494 setcookie("lukdevinfo", 0, time() + 2*7*24*60*60);
495
496
501 // Check class setting (check "luokka" for backwards compatibility also) 497 // Check class setting (check "luokka" for backwards compatibility also)
502 if ((($classID = stGetRequestItem("class", FALSE, TRUE)) !== FALSE || 498 if ((($classID = stGetRequestItem("class", FALSE, TRUE)) !== FALSE ||
503 ($classID = stGetRequestItem("luokka", FALSE, TRUE)) !== FALSE) && lukCheckClassID($classID)) 499 ($classID = stGetRequestItem("luokka", FALSE, TRUE)) !== FALSE) && lukCheckClassID($classID))
504 { 500 {
505 setcookie("lukclass", $classID, time() + 365*24*60*60); // expire in a year 501 setcookie("lukclass", $classID, time() + 365*24*60*60); // expire in a year
579 $extra .= " <link rel=\"apple-touch-icon\" ". 575 $extra .= " <link rel=\"apple-touch-icon\" ".
580 ($addSize ? "sizes=\"".$iconSize."x".$iconSize."\" " : ""). 576 ($addSize ? "sizes=\"".$iconSize."x".$iconSize."\" " : "").
581 "href=\"img/icon-".$iconSize."-precomposed.png\" />\n"; 577 "href=\"img/icon-".$iconSize."-precomposed.png\" />\n";
582 } 578 }
583 579
580 // XXX: Temporarily no-index (remember also robots.txt!)
581 $extra .= " <meta name=\"robots\" content=\"noindex\">\n";
582
583 // For mobile shit
584 $extra .= " <meta name=\"viewport\" content=\"width=device-width\" />\n";
584 585
585 // Start printing the page 586 // Start printing the page
586 $pageTitle = $haveData ? $classID." / ".join("; ", $classInfo["info"]) : $classID; 587 $pageTitle = $haveData ? $classID." / ".join("; ", $classInfo["info"]) : $classID;
587 cmPrintPageHeader($pageTitle." - ".$pageName, $extra); 588 cmPrintPageHeader($pageTitle." - ".$pageName, $extra);
588 589
589 590 echo "
590 // Info box 591 <script type=\"text/javascript\">
592 function lukSetCookie(cname, cvalue, cctime)
593 {
594 var de = new Date();
595 de.setTime(de.getTime() + cctime*1000);
596 document.cookie = cname +\"=\"+ cvalue +\"; expires=\"+ de.toUTCString();
597 }
598
599 function lukSetViewDo(elem, state)
600 {
601 elem.style.display = state ? 'block' : 'none';
602 }
603
604 function lukSetView(id, state)
605 {
606 var elem = document.getElementById(id);
607 if (elem) lukSetViewDo(elem, state);
608 }
609
610 function lukToggleView(id)
611 {
612 var elem = document.getElementById(id);
613 if (elem) lukSetViewDo(elem, (elem.style.display == 'none'));
614 }
615
616 function lukAcknowledgeCookies()
617 {
618 lukSetCookie('lukcookieinfo', 1, 31*24*60*60);
619 var elem = document.getElementById('cookieInfo');
620 if (elem) lukSetViewDo(elem, false);
621 }
622 </script>
623
624 <div id=\"devInfo\" ".($showDevInfo ? "" : " style=\"display: none;\"").">
625 <h1>Notice!</h1>
626 <p>
627 <b>This is the development version of 'Lukkari', tentatively called \"3.0alpha\".</b>
628 It is constantly changing, any features may be broken and fixed at
629 rapid pace. The style/layout is also in flux, and not finished -
630 there may be rendering bugs. Currently I am testing a non-table-based layout,
631 although it is not certain if it will be used in 'production'.
632 </p>
633 <p>
634 If you wish to suggest features, send e-mail to <b>ccr (at) tnsp (dot) org</b>
635 </p>
636 <div class=\"popupControls\">
637 <button type=\"button\" onClick=\"lukSetView('devInfo', false);\">Okay</button>
638 </div>
639 </div>
640 ";
641
642 if ($showCookieInfo)
643 {
644 echo
645 "<div id=\"cookieInfo\">\n".
646 " <p>Lukkari web-site uses <a href=\"http://en.wikipedia.org/wiki/HTTP_cookie\">HTTP cookies</a> ".
647 " to store current settings (language, default class ID, etc.) ".
648 " Also, Google Analytics used on this site may store information via cookies.".
649 " </p>".
650 " By continued use of this site, you acknowledge that you have been informed of the situation.".
651 " <div class=\"popupControls\">\n".
652 " <button type=\"button\" onclick=\"lukAcknowledgeCookies()\">Okay</button>\n".
653 " </div>\n".
654 "</div>\n";
655 }
656
657
658 // Additional controls
591 echo 659 echo
592 "<div id=\"infobox\">\n". 660 " <div id=\"controls\">\n".
593 " <div id=\"ctitle\">".$pageName." v".$pageVersion."</div>\n"; 661 " <div id=\"infobox\">\n".
662 " <div id=\"ctitle\">".$pageName." v".$pageVersion."</div>\n";
594 663
595 if (!$mobileMode) 664 if (!$mobileMode)
596 { 665 {
597 echo 666 echo
598 " <div id=\"csssel\">".cmQM("Style").": "; 667 " <div id=\"csssel\">".cmQM("Style").": ";
599 668
600 if (isset($pageCSSAlts)) 669 if (isset($pageCSSAlts))
601 { 670 {
602 foreach ($pageCSSAlts as $name => $id) 671 foreach ($pageCSSAlts as $name => $id)
603 { 672 {
609 678
610 echo 679 echo
611 "</div>\n"; 680 "</div>\n";
612 } 681 }
613 682
614 echo 683 echo " <div id=\"clang\">";
615 " <div id=\"clang\">";
616 684
617 foreach ($pageLanguages as $id) 685 foreach ($pageLanguages as $id)
618 { 686 {
619 echo 687 echo
620 "<a ".(($pageLang == $id) ? "class=\"selected\" " : ""). 688 "<a ".(($pageLang == $id) ? "class=\"selected\" " : "").
621 "href=\"".$baseURI."?lang=".$id."\">".$id."</a>"; 689 "href=\"".$baseURI."?lang=".$id."\">".$id."</a>";
622 } 690 }
623 691
624 echo 692 echo
625 "</div>\n". 693 " </div>\n".
626 "</div>\n"; 694 " </div>\n".
627 695 " <form action=\"".$baseURI."\" method=\"get\">\n".
628 696 " <div>\n".
629 // Additional controls
630 echo
631 "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\">\n".
632 " <table>\n".
633 " <tr>\n".
634 " <th>\n".
635 " <select id=\"classSelect\" name=\"class\" onChange=\"this.form.submit();\">\n"; 697 " <select id=\"classSelect\" name=\"class\" onChange=\"this.form.submit();\">\n";
636 698
637 if ($classIDs !== FALSE) 699 if ($classIDs !== FALSE)
638 { 700 {
639 foreach ($classIDs as $id) 701 foreach ($classIDs as $id)
644 } 706 }
645 } 707 }
646 708
647 echo 709 echo
648 " </select>\n". 710 " </select>\n".
649 " </th>\n". 711 " </div>\n".
650 " <noscript><th><input id=\"classSwitch\" class=\"submit\" type=\"submit\" value=\"".cmQM("change")."\" /></th></noscript>\n"; 712 " <noscript><div><input id=\"classSwitch\" class=\"submit\" type=\"submit\" value=\"".cmQM("change")."\" /></div></noscript>\n";
651 713
652 if (!$mobileMode) 714 if (!$mobileMode)
653 { 715 {
654 echo 716 echo
655 " <th><a id=\"next\" class=\"textctrl\" href=\"". 717 " <div><a id=\"nextPeriod\" class=\"textctrl\" href=\"".
656 $baseURI.($nextPeriod ? "" : "?next")."\" title=\"".cmQM("expl_toggle_period")."\">". 718 $baseURI.($nextPeriod ? "" : "?next")."\" title=\"".cmQM("expl_toggle_period")."\">".
657 cmQM("period_shown").": ".($nextPeriod ? cmQM("next_period") : cmQM("current_period")). 719 cmQM("period_shown").": ".($nextPeriod ? cmQM("next_period") : cmQM("current_period")).
658 "</a></th>\n"; 720 "</a></div>\n";
659 721
660 if ($haveData) 722 if ($haveData)
661 { 723 {
662 echo 724 echo
663 " <th><a id=\"orig\" class=\"textctrl\" href=\"".$origBaseURI.$classID.$origBaseExt."\" title=\"".cmQM("expl_link_original_data")."\">".cmQM("link_original_data")."</a></th>\n"; 725 " <div><a id=\"origLink\" class=\"textctrl\" href=\"".$origBaseURI.$classID.$origBaseExt."\" title=\"".cmQM("expl_link_original_data")."\">".cmQM("link_original_data")."</a></div>\n";
664 //" <th><a id=\"xml\" class=\"textctrl\" href=\"".$baseURI.$cachePath."/".$class.".xml\">XML</a></th>\n"; 726 //" <div><a id=\"xml\" class=\"textctrl\" href=\"".$baseURI.$cachePath."/".$class.".xml\">XML</a></div>\n";
665 } 727 }
666 728
667 echo 729 // echo " <div><a id=\"mobileLink\" class=\"textctrl mobile\" href=\"http://tnsp.org/mluk/\" title=\"".cmQM("expl_link_mobile_version")."\">".cmQM("link_mobile_version")."</a></div>\n";
668 " <th><a class=\"textctrl mobile\" href=\"http://tnsp.org/mluk/\" title=\"".cmQM("expl_link_mobile_version")."\">".cmQM("link_mobile_version")."</a></th>\n";
669 } 730 }
670 731
671 $currURL = $baseURI."?class=".$classID."&amp;lang=".$pageLang. 732 $currURL = $baseURI."?class=".$classID."&amp;lang=".$pageLang.
672 (isset($pageCSSIndex) ? "&amp;css=".$pageCSSIndex : ""). 733 (isset($pageCSSIndex) ? "&amp;css=".$pageCSSIndex : "").
673 ($nextPeriod ? "&amp;next" : ""); 734 ($nextPeriod ? "&amp;next" : "");
674 735
675 echo 736 echo
676 " <th><a href=\"".$currURL."\" class=\"textctrl\" title=\"".cmQM("expl_link_current_settings")."\">".cmQM("link_current_settings")."</a></th>\n". 737 " <div><a href=\"".$currURL."\" class=\"textctrl\" title=\"".cmQM("expl_link_current_settings")."\">".cmQM("link_current_settings")."</a></div>\n".
677 // " <th class=\"advert\"><a href=\"http://tnsp.org/u/G1X\"><img src=\"img/hdd_fi.gif\" alt=\"HDD.fi\" /></a></th>\n". 738 " <div><button id=\"toggleDevInfo\" type=\"button\" onclick=\"lukToggleView('devInfo')\">INFO</button></div>\n".
678 " <th class=\"advert\"><a href=\"http://tnsp.org/u/H9w\"><img src=\"img/batmud.png\" alt=\"BatMUD\" /></a></th>\n". 739 " </form>\n".
679 // " <th><a href=\"http://tnsp.org/testluk/\"><img src=\"img/test.png\" alt=\"Lukkari v3\" /></a></th>\n". 740 "</div>\n".
680 " </tr>\n". 741 "<div id=\"header\">\n".
681 " </table>\n".
682 "</form>\n".
683 "<h1>".$pageTitle."</h1>\n"; 742 "<h1>".$pageTitle."</h1>\n";
743
744 if (!$mobileMode)
745 {
746 echo
747 "<p>".join("; ", $classInfo["general"]).
748 //" [".cmQM("viikossa", $classInfo["totalHours"])."]".
749 "</p>\n";
750 }
684 751
685 // Show error messages 752 // Show error messages
686 if ($errorSet) 753 if ($errorSet)
687 { 754 {
688 echo "<ul>\n"; 755 echo "<ul>\n";
689 foreach ($errorMsgs as $msg) 756 foreach ($errorMsgs as $msg)
690 echo "<li>".$msg."</li>\n"; 757 echo "<li>".$msg."</li>\n";
691 echo "</ul>\n"; 758 echo "</ul>\n";
692 } 759 }
760
761 echo "</div>\n";
693 762
694 if ($haveData) 763 if ($haveData)
695 { 764 {
696 echo lukPrintTimeTable($mobileMode); 765 echo lukPrintTimeTable($mobileMode);
697 } 766 }