annotate index.php @ 49:16aea8e5cb71

Improved CSS, added a third stylesheet option.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 17 Oct 2012 15:35:16 +0300
parents d41b51cd4ae5
children aa201ddd33dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
1 <?php
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
2 //
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
3 // Yes, this is horrible. :|
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
4 //
38
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
5 $pageCharset = "utf-8";
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
6 $internalCharset = "utf-8";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 $luokkaDefault = "TTE9SNO";
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
8 $classFile = "luokat.txt";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 $cacheFile = "coursecache.txt";
16
ea9558465ad6 Add link to original data, fix left-over beta stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
10 $baseURI = "http://tnsp.org/luk/";
30
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
11 //$infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&opas=2010-2011&vuosi=10S11K&koodi1=";
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
12 $infoURI = "http://www.oamk.fi/opiskelijalle/rakenne/opinto-opas/koulutusohjelmat/?sivu=oj&kieli=FI&koodi1=";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 $dayNames = array("Maanantai", "Tiistai", "Keskiviikko", "Torstai", "Perjantai", "Lauantai", "Sunnuntai");
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
48
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
15 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk");
49
16aea8e5cb71 Improved CSS, added a third stylesheet option.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
16 $pageCSSAlts = array("blue" => "1", "old" => "2", "purple" => "3");
48
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
17
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
18 $hourStamps = array(
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
19 array( 8, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
20 array( 9, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
21 array(10, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
22 array(11, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
23 array(12, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
24 array(13, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
25 array(14, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
26 array(15, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
27 array(16, 15),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
28 array(17, 5),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
29 array(18, 5),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
30 array(19, 0),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
31 array(20, 45),
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
32 );
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
33
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
34 // Include framework
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 require "mcommon.inc.php";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 require "merrors.inc.php";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
2
2471bb891299 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
38
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
39 // Helper functions
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
40 function lukChEntities($str)
38
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
41 {
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
42 global $internalCharset;
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
43 // return $str;
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
44 return htmlentities($str, ENT_NOQUOTES, $internalCharset);
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
45 }
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
46
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
47 function lukCheckClassID(&$id)
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 global $luokkaDefault;
23
b4b86915ae2c Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
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)) {
b4b86915ae2c Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
51 $id = $m[1];
b4b86915ae2c Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
52 return TRUE;
b4b86915ae2c Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
53 } else {
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
54 errorMsg("Virhe! Luokan täytyy olla muotoa <b>XXXnXXX</b>, käytetään vakioarvoa <b>".$luokkaDefault."</b>.");
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 $id = $luokkaDefault;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 return FALSE;
23
b4b86915ae2c Better input validation for $_GET arguments, thanks to Hjalmarr for pointing out the error.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
57 }
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
60 function lukMakeHourStamp($hour, $sec = 0, $mon = 0, $day = 0, $year = 0)
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
61 {
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
62 global $hourStamps;
17
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
63 if (isset($hourStamps[$hour]))
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
64 return mktime($hourStamps[$hour][0], $hourStamps[$hour][1], $sec, $mon, $year);
17
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
65 else
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
66 return mktime($hour + 8, 0, $sec, $mon, $year);
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
67 }
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
68
17
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
69
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
70 function getHour($hour)
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
71 {
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
72 $stamp = lukMakeHourStamp($hour);
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
73 return "<br />".date("H:i", $stamp)." - ".date("H:i", $stamp + 45 * 60)."<br /><br />";
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
74 }
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
75
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
76
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
77 function lukMatchCourse($id)
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
38
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
79 global $cache, $infoURI, $cacheDirty, $internalCharset;
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 // Check if course exists in cache
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 if (!isset($cache[$id])) {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 $cacheDirty = TRUE;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 // Not cached, try to fetch data
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 $data = @file_get_contents($infoURI.$id);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 if ($data !== FALSE) {
38
2195ede068c8 Add chentities() helper function and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
87 $data = iconv("iso-8859-1", $internalCharset, $data);
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 if (preg_match("#<td class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*op\s*</strong></td>#", $data, $m)) {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 // Add data to cache
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 $cache[$id] = array("desc" => $m[1], "op" => intval($m[2]));
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 if (isset($cache[$id]))
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
96 return "<a target=\"_blank\" title=\"".lukChEntities($id." - ".$cache[$id]["op"]." op").
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
97 "\" href=\"".lukChEntities($infoURI.$id)."\">".lukChEntities($cache[$id]["desc"])."</a>";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 else
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
99 return lukChEntities($id);
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
39
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
103 // Check for mini-info mode
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
104 $miniMode = isset($_GET["nyt"]);
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
105
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
106 // Check given parameters
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
107 if (isset($_GET["luokka"])) {
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
108 $luokka = $_GET["luokka"];
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
109 if (lukCheckClassID($luokka) && !$miniMode) {
39
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
110 setcookie("lukluokka", $luokka, time() + 365*24*60*60); // expire in a year
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
111 }
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
112 } else
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
113 if (isset($_COOKIE["lukluokka"])) {
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
114 $luokka = $_COOKIE["lukluokka"];
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
115 lukCheckClassID($luokka);
39
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
116 } else {
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
117 errorMsg("Luokkaa ei asetettu, käytetään vakioarvoa <b>".$luokkaDefault."</b>.");
39
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
118 $luokka = $luokkaDefault;
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
119 }
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
120
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
121
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
122 if (isset($_GET["next"])) {
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
123 $nextPeriod = TRUE;
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
124 $dataFile = "cache-next/".$luokka.".data";
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
125 } else {
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
126 $nextPeriod = FALSE;
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
127 $dataFile = "cache/".$luokka.".data";
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
128 }
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
129
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
130
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 // Global cache for course data
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 $cache = array();
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 $cacheDirty = FALSE;
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 // Try to read cachefile, if we can get file lock on it
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 $fp = @fopen($cacheFile, "rb");
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 if ($fp) {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 if (flock($fp, LOCK_SH)) {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 require($cacheFile);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 flock($fp, LOCK_UN);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 fclose($fp);
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
145
28
ab06d838d916 Cosmetics & comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
146 // Read classfile
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
147 $fp = @fopen($classFile, "rb");
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
148 $classes = array();
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
149 if ($fp) {
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
150 if (flock($fp, LOCK_SH)) {
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
151 while (!feof($fp)) {
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
152 $str = trim(fgets($fp, 128));
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
153 if (strlen($str) > 2 && $str[0] != "#")
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
154 $classes[] = $str;
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
155 }
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
156 flock($fp, LOCK_UN);
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
157 }
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
158 fclose($fp);
17
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
159 } else {
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
160 errorMsg("Luokkien listaa ei löytynyt. Kokeile ladata sivu uudelleen hetken kuluttua.");
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
31
dbe7ff545293 Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
164 if (!file_exists($dataFile)) {
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
165 errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ".
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
166 "Jos luokkakoodi on uusi, ilmestyy se järjestelmään seuraavan ".
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
167 "päivityksen aikana. Luokkatiedot päivitetään kerran viikossa.");
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
168 $haveData = FALSE;
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
169 } else {
31
dbe7ff545293 Add support for fetching and showing data for next/upcoming period.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
170 require($dataFile);
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
171 $haveData = isset($classDefs);
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
174
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
175 function lukResolveHours($start, $day, $cmp, $mark = FALSE)
12
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
176 {
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
177 global $classHourTable, $classInfo;
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
178 $n = 0;
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
179 for ($i = $start; $i < $classInfo["maxhours"]; $i++)
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
180 if ($classHourTable[$i][$day] == $cmp) {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
181 if ($mark) $classHourTable[$i][$day] = -9999;
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
182 $n++;
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
183 } else
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
184 break;
12
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
185 return $n;
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
186 }
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
187
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
188
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
189 function lukFindNextActiveHour(&$j, &$i, $day, $hour, $chk)
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
190 {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
191 global $classInfo, $classHourTable;
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
192 // for ($j = $day; $j < $classInfo["maxdays"]; $j++)
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
193 $j = $day;
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
194 for ($i = $hour; $i < $classInfo["maxhours"]; $i++) {
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
195 if ($chk > 0 && $classHourTable[$i][$j] != $chk)
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
196 return $classHourTable[$i][$j];
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
197
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
198 if ($classHourTable[$i][$j] > 0 && $classHourTable[$i][$j] != $chk)
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
199 return $classHourTable[$i][$j];
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
200 }
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
201
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
202 return -1;
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
203 }
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
204
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
205
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
206 function lukGetHourInfo($isSplit, $d)
19
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
207 {
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
208 if ($isSplit) {
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
209 $out = "<table>".
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
210 "<tr><td>".lukMatchCourse($d[0])."</td><td>".lukMatchCourse($d[1])."</td></tr>";
19
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
211
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
212 for ($i = 2; $i < count($d); $i += 2)
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
213 $out .= "<tr><td>".lukChEntities($d[$i])."</td><td>".(isset($d[$i+1]) ? lukChEntities($d[$i+1]) : "")."</td></tr>";
19
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
214
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
215 return $out."</table>";
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
216 } else {
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
217 $out = lukMatchCourse($d[0])."<br />";
19
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
218
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
219 for ($i = 1; $i < count($d); $i++)
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
220 $out .= lukChEntities($d[$i])."<br />";
19
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
221
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
222 return $out;
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
223 }
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
224 }
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
225
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
226
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
227 function lukGetHourInfoData($id)
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
228 {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
229 global $classDefs;
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
230
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
231 if (isset($id)) {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
232 if ($id >= 0 && isset($classDefs[$id])) {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
233 $i = $classDefs[$id];
19
777791321149 Modularize, cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
234 $isSplit = preg_match("/^[A-Z]\d{6}$/", $i["data"][1]);
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
235 return lukGetHourInfo($isSplit, $i["data"]);
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
236 } else
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
237 return "<p>Ei tunteja.</p>";
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
238 } else
37
3ba4feff55cb Partially convert to UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
239 return "<p>Ei mitään.</p>";
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
240
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
241 return "";
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
242 }
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
243
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
244
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
245 $out = "";
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
246
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
247 if ($miniMode && $haveData) {
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
248 $stamp = time();
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
249 $aika = getdate($stamp);
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
250 $day = $aika["wday"] - 1;
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
251 if ($day < 0) $day = 7;
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
252 $hour = $aika["hours"] - 8;
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
253
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
254 $out = "<div class=\"content\">\n";
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
255
45
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
256 if ($hour >= 0 && $day >= 0 && $hour < sizeof($classHourTable))
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
257 {
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
258 $id = $classHourTable[$hour][$day];
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
259 $out .=
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
260 "<h2>".$dayNames[$day]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n".
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
261 lukGetHourInfoData($id)."\n";
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
262 }
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
263
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
264
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
265 if (isset($id) && $id >= 0 && isset($classDefs[$id])) {
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
266 $i = $classDefs[$id];
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
267 $start = lukMakeHourStamp($i["start"]);
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
268 }
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
269
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
270 // echo "day=$day, hour=$hour, id=$id<br />\n";
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
271
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
272 if ($day >= $classInfo["maxdays"]) {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
273 $day = $hour = 0;
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
274 $id = -1;
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
275 } else
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
276 if ($hour < 0) {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
277 $hour = 0;
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
278 $id = -1;
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
279 } else
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
280 if ($hour >= $classInfo["maxhours"]) {
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
281 $day++;
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
282 $hour = 0;
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
283 $id = -1;
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
284 }
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
285
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
286 // echo "day=$day, hour=$hour, id=$id<br />\n";
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
287 $found = lukFindNextActiveHour($nday, $nhour, $day, $hour, $id);
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
288
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
289 // echo "nday=$nday, nhour=$nhour, id=$found<br />\n";
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
290
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
291 $out .= "<h2>Seuraavaksi";
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
292 if ($found > 0) {
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
293 $stamp = lukMakeHourStamp($nhour, 0, 0, $aika["mon"], $aika["mday"] + $nday - $day, $aika["year"]);
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
294 $aika = getdate($stamp);
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
295 $out .= ": ".$dayNames[$nday]." ".date("d.n.Y", $stamp)." - klo ".date("H:i", $stamp)."</h2>\n".
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
296 lukGetHourInfoData($found)."\n";
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
297 } else {
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
298 $out .= "</h2>\n".
37
3ba4feff55cb Partially convert to UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
299 "<p>Ei mitään</p>\n";
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
300 }
20
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
301
d9df76217991 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
302 $out .= "</div>\n";
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
303 }
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
304 else
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
305 if ($haveData) {
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
306 $totalHours = 0;
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
307 $totalGrouped = 0;
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
308 $dayHours = array();
7
2bb40c5945bc Remove useless variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
309
11
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
310 for ($day = 0; $day < $classInfo["maxdays"]; $day++) {
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
311 $dayHours[$day]["total"] = $dayHours[$day]["grouped"] = 0;
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312
11
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
313 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) {
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
314 $id = $classHourTable[$hour][$day];
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315
11
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
316 if ($id > 0) {
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
317 $totalHours++;
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
318 $dayHours[$day]["total"]++;
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
319
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
320 if ($classDefs[$id]["grouped"]) {
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
321 $totalGrouped++;
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
322 $dayHours[$day]["grouped"]++;
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
323 }
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
324 }
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
325 }
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
326 }
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
327
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
328 // Create the timetable table
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
329 $out =
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
330 "<p>".join("; ", $classInfo["general"])."</p>\n".
37
3ba4feff55cb Partially convert to UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
331 "<div>Viikossa yhteensä <b>".$totalHours."</b> tuntia, joista <b>".$totalGrouped."</b> ryhmissä tai vuoroviikoin.</div>\n".
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
332 "<table class=\"timetable\">".
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
333 " <tr>\n <th></th>\n";
7
2bb40c5945bc Remove useless variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
334 for ($day = 0; $day < $classInfo["maxdays"]; $day++) {
18
e0f1a5861f28 Fixes, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
335 $out .= " <th style=\"width: ".(100 / $classInfo["maxdays"]).
e0f1a5861f28 Fixes, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
336 "%;\" class=\"days\">".$dayNames[$day]."</th>\n";
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
337 }
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
338 $out .= " </tr>\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
340 for ($hour = 0; $hour < $classInfo["maxhours"]; $hour++) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
341 $out .= " <tr>\n".
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
342 " <th class=\"hours\">".getHour($hour)."</th>\n";
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
343 for ($day = 0; $day < $classInfo["maxdays"]; $day++) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
344 if (isset($classHourTable[$hour][$day])) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
345 $h = $classHourTable[$hour][$day];
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
347 if ($h < 1) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
348 if ($h > -9999) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
349 $n = lukResolveHours($hour, $day, $h, TRUE);
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
350 $out .= " <td rowspan=\"".$n."\" class=\"clnothing\"></td>\n";
12
306028aa2253 Fix hour counts when table has been modified.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
351 }
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
352 } else
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
353 if (isset($classDefs[$h])) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
354 if (!isset($classDefs[$h]["done"])) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
355 $classDefs[$h]["done"] = true;
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
356 $i = $classDefs[$h];
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
357 $d = $classDefs[$h]["data"];
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
358
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
359 $isSplit = preg_match("/^[A-Z]\d{6}$/", $d[1]);
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
360
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
361 $hours = lukResolveHours($hour, $day, $h, FALSE);
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
362 if ($hours != $i["hours"]) {
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
363 errorMsg("Internal error, cell $hour / $day : hour id $h hours ($hours) do not match ".$i["hours"]."!");
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
364 }
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
365
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
366 $out .= " <td rowspan=\"".$hours.
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
367 "\" class=\"".($isSplit || $i["grouped"] ? "clgrouped" : "clnormal")."\">".
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
368 lukGetHourInfo($isSplit, $d).
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
369 "<div class=\"nhours\"><span>".$hours."h</span></div></td>\n";
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
370 }
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
371 } else
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
372 errorMsg("Internal error cell $hour / $day : hour id $h does not exist!");
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 } else
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
374 errorMsg("Internal error, cell $hour / $day does not exist.");
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
375 }
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
376 $out .= " </tr>\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
48
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
379 $out .= "</table>\n";
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
380
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
381 } // haveData
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
382
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
383
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
384 $pageTitle = $haveData ? $luokka." / ".join("; ", $classInfo["info"]) : $luokka;
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
385 printPageHeader($pageTitle);
18
e0f1a5861f28 Fixes, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
386
e0f1a5861f28 Fixes, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
387 echo
30
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
388 "<form id=\"controls\" action=\"".$baseURI."\" method=\"get\">
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
389 <table>
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
390 <tr>
45
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
391 <th>
30
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
392 <select name=\"luokka\">
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
393 ";
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
394
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
395 foreach ($classes as $class) {
43
7621bfc47491 Various bits and pieces -- a commit that defies logic. Oh well.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
396 echo " <option ".($luokka == $class ? "selected=\"selected\" " : "")."value=\"".$class."\">".lukChEntities($class)."</option>\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 }
30
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
398 echo
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
399 " </select>
45
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
400 </th>
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
401 <th><input class=\"submit\" type=\"submit\" value=\" Vaihda \" /></th>
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
402 <th><a href=\"".$baseURI."?luokka=".$luokka;
17
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
403
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
404 if ($miniMode)
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
405 echo "\">Normaali";
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
406 else
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
407 echo "&amp;nyt\">Mini-info";
611452d30bd4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
408
45
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
409 echo "</a></th>
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
410 <th><a href=\"http://www.oamk.fi/tyojarjestykset/otek/luokat/OR_".$luokka.".htm\">Alkuperäinen</a></th>
39
78d0c1cd7282 Add support for upcoming period data.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
411
45
d8a1e85b8dda Change the visual style a tiny bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
412 <th><a href=\"".$baseURI.($nextPeriod ? "" : "?next")."\">".($nextPeriod ? "Nykyinen" : "Seuraava")." periodi</a></th>
30
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
413 </tr>
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
414 </table>
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
415 </form>
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
416 ";
13
57dd1db922c2 Fix hours, add mini-info mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
417
18
e0f1a5861f28 Fixes, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
418 echo "<h1>".$pageTitle."</h1>\n";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 // Show error messages
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 if ($errorSet) {
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 echo "<ul>\n";
44
57af36f0864e Rename some functions + reindentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
423 foreach ($errorMsgs as $msg)
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 echo "<li>$msg</li>\n";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 echo "</ul>\n";
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427
5
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
428 echo $out;
3d6a83eaa2ba Improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
429
48
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
430 echo "<div id=\"footer\">
37
3ba4feff55cb Partially convert to UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
431 Yhteydenotot <b>ccr @ IRCNet</b> tai <b>ccr at tnsp dot org</b>. En vastaa mahdollisista virheistä tiedoissa!
30
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
432 </div>
48
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
433 <div id=\"csssel\">
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
434 Style: ";
49
16aea8e5cb71 Improved CSS, added a third stylesheet option.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
435 foreach ($pageCSSAlts as $name => $id)
48
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
436 echo "<a href=\"?css=".$id."\">".$name."</a>";
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
437 echo "
d41b51cd4ae5 Implement switchable CSS support and a new default style + very minor code
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
438 </div>
30
6148ce4a83ed Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
439 ";
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 printPageFooter();
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 // Dump the course data cache, but only if it has changed
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 if ($cacheDirty) {
27
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
445 // Create string containing the data
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
446 $str = "<?\n\$cache = array(\n";
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
447 foreach ($cache as $id => $data) {
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
448 $str .= " \"".addslashes($id)."\" => array(\"desc\" => \"".
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
449 addslashes($data["desc"])."\", \"op\" => ".$data["op"]."),\n";
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
450 }
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
451 $str .= ");\n?>";
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
452
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
453 // Use locking to prevent concurrent access and dump data
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
454 if (file_put_contents($cacheFile, $str, LOCK_EX) === FALSE) {
7655db03ea60 Use different strategy of saving course cache, by using file_put_contents() with locking instead of using separate writes.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
455 // Can't do much anything here ..
1
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 }
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458
21fde93375e9 Add beta code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 ?>