changeset 171:66c871dacbc2

Improve course ID handling.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 24 Aug 2015 11:19:52 +0300
parents 34ce8339b956
children 14117fd8a083
files index.php
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Mon Aug 24 11:00:13 2015 +0300
+++ b/index.php	Mon Aug 24 11:19:52 2015 +0300
@@ -188,13 +188,14 @@
 }
 
 
-function lukFetchCourseData($uri, &$cache)
+function lukFetchCourseData($id, $uri, &$cache)
 {
   global $pageCharset;
 
   if (($data = @file_get_contents($uri)) !== FALSE)
   {
     $data = @iconv("iso8859-15", $pageCharset, $data);
+
     // <td id="oj_nimi" class="smallheadercell"><strong>Korjausrakentamisen rakennussuunnittelu 3 op</strong></td>
     if (preg_match("#<td id=\"oj_nimi\" class=\"smallheadercell\"><strong>(.+?)\s+(\d+)\s*(op|ECTS\s+cr)\s*</strong></td>#", $data, $m))
     {
@@ -203,7 +204,7 @@
     }
     else
     // <td><strong>... (N op)</strong></td>
-    if (preg_match("#<td><strong>(.+?)\s+\((\d+)\s*(op|ECTS\s+cr)\)\s*</strong></td>#", $data, $m))
+    if (preg_match("#<td><strong>(.+?)\s+\((\d+)\s*(op|ECTS\s+cr|cr)\)\s*</strong></td>#i", $data, $m))
     {
       $cache = array("desc" => $m[1], "op" => intval($m[2]), "uri" => $uri);
       return TRUE;
@@ -226,8 +227,10 @@
   {
     // Not cached, try to fetch data
     $uri = "http://www.oamk.fi/opinto-opas/opintojaksohaku/?sivu=oj_kuvaus&koodi1=".$id."&kieli=".strtoupper($pageLang);
-    if (lukFetchCourseData($uri."&opas=2015-2016", $cache[$id][$pageLang]) ||
-        lukFetchCourseData($uri."&opas=2014-2015", $cache[$id][$pageLang]))
+    if (
+        lukFetchCourseData($id, $uri."&opas=2014-2015", $cache[$id][$pageLang]) ||
+        lukFetchCourseData($id, $uri."&opas=2015-2016", $cache[$id][$pageLang])
+      )
       $cacheDirty = TRUE;
   }