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