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