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