changeset 82:c553ad61e9c2

Make original data links work for both current and next period mode.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 24 Oct 2012 12:24:48 +0300
parents 8501f1b9bba3
children 85068c8513b4
files index.php update.sh
diffstat 2 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Wed Oct 24 12:00:53 2012 +0300
+++ b/index.php	Wed Oct 24 12:24:48 2012 +0300
@@ -8,8 +8,8 @@
 $pageCharset = "utf-8";
 $internalCharset = "utf-8";
 $classDefault = "TTE9SNO";
-$classFile = "classes.txt";
-$cacheFile = "coursecache.txt";
+$classIDFile = "classes.txt";
+$courseCacheFile = "coursecache.txt";
 $baseURI = "http://tnsp.org/luk/";
 
 $pageCSSData = array("cookie" => "lukcss", "prefix" => $baseURI."luk");
@@ -237,6 +237,8 @@
 
 
 // Check given parameters
+$mobileMode = isset($_GET["mobile"]) || isset($_COOKIE["lukmobile"]);
+
 if (isset($_GET["luokka"]))
 {
   $luokka = $_GET["luokka"];
@@ -280,12 +282,17 @@
 if (isset($_GET["next"]))
 {
   $nextPeriod = TRUE;
-  $dataFile = "cache-next/".$luokka.".data";
+  $cachePath = "cache-next/";
 }
 else
 {
   $nextPeriod = FALSE;
-  $dataFile = "cache/".$luokka.".data";
+  $cachePath = "cache/";
+}
+
+if (file_exists($cachePath."baseuri.data"))
+{
+  require $cachePath."baseuri.data";
 }
 
 
@@ -294,12 +301,12 @@
 $cacheDirty = FALSE;
 
 // Try to read cachefile, if we can get file lock on it
-$fp = @fopen($cacheFile, "rb");
+$fp = @fopen($courseCacheFile, "rb");
 if ($fp)
 {
   if (flock($fp, LOCK_SH))
   {
-    require($cacheFile);
+    require($courseCacheFile);
     flock($fp, LOCK_UN);
   }
   fclose($fp);
@@ -308,7 +315,7 @@
 
 // Read classfile
 $classes = array();
-$fp = @fopen($classFile, "rb");
+$fp = @fopen($classIDFile, "rb");
 if ($fp)
 {
   if (flock($fp, LOCK_SH))
@@ -329,6 +336,7 @@
 }
 
 
+$dataFile = $cachePath.$luokka.".data";
 if (!file_exists($dataFile))
 {
   errorMsg("Luokan ".lukChEntities($luokka)." tietoja ei löytynyt! ".
@@ -432,7 +440,7 @@
 "    </select>
    </th>
    <th><input class=\"submit\" type=\"submit\" value=\"".lukMsg("Switch")."\" /></th>
-   <th><a href=\"http://www.oamk.fi/tyojarjestykset/otek/luokat/OR_".$luokka.".htm\">".lukMsg("Original")."</a></th>
+   <th><a href=\"".$origBaseURI.$luokka.$origBaseExt."\">".lukMsg("Original")."</a></th>
 
    <th><a href=\"".$baseURI.($nextPeriod ? "" : "?next")."\">".
      ($nextPeriod ? lukMsg("Current period") : lukMsg("Next period"))."</a></th>
@@ -486,7 +494,7 @@
 if ($cacheDirty)
 {
   $str = "<?\n\$cache = ".var_export($cache, TRUE)."\n?>";
-  if (file_put_contents($cacheFile, $str, LOCK_EX) === FALSE) {
+  if (file_put_contents($courseCacheFile, $str, LOCK_EX) === FALSE) {
     // Can't do much anything here ..
   }
 }
--- a/update.sh	Wed Oct 24 12:00:53 2012 +0300
+++ b/update.sh	Wed Oct 24 12:24:48 2012 +0300
@@ -15,12 +15,13 @@
 createdir "${OLDCACHEDIR}"
 createdir "${CACHEDIR}"
 
-
 URLPREFIX="$1"
 CLASSFILE="$2"
 LISTFILE="$2.tmp"
 PATPREFIX="$3"
 
+echo "<? \$origBaseURI = \"${URLPREFIX}${PATPREFIX}\"; \$origBaseExt = \".htm\"; ?>" > "${CACHEDIR}baseuri.data";
+
 if wget -q -O "$LISTFILE" "$URLPREFIX"; then
 	perl -ne "if (/<a href=\"${PATPREFIX}([A-Z]{3}\d\S+)${URLSUFFIX}\">/) { print \"\$1\n\"; }" < "$LISTFILE" > "$CLASSFILE"
 	echo -n "* Fetched classfile $CLASSFILE: "