Licence and jqmobile beta 3 upgrade
[busui.git] / include / common-transit.inc.php
blob:a/include/common-transit.inc.php -> blob:b/include/common-transit.inc.php
--- a/include/common-transit.inc.php
+++ b/include/common-transit.inc.php
@@ -23,14 +23,18 @@
 
 function service_period($date = "") {
 
-    if (isset($_SESSION['service_period']))
-        return $_SESSION['service_period'];
+    if (isset($_REQUEST['service_period'])) {
+        return $_REQUEST['service_period'];
+    }
+
     $override = getServiceOverride($date);
-    if ($override['service_id']) {
-        return $override['service_id'];
-    }
-
-    switch (date('w', ($date != "" ? $date : time()))) {
+    if (isset($override['service_id'])) {
+        return strtolower($override['service_id']);
+    }
+    $date = ($date != "" ? $date : time());
+    $dow = date('w', $date);
+
+    switch ($dow) {
         case 0:
             return 'sunday';
         case 6:
@@ -38,6 +42,29 @@
         default:
             return 'weekday';
     }
+}
+
+function service_ids($service_period, $date = "") {
+    switch ($service_period) {
+        case 'sunday':
+            return Array("Sunday", "Sunday");
+        case 'saturday':
+            return Array("Saturday", "Saturday");
+        default:
+            $date = ($date != "" ? $date : time());
+// school holidays
+            $ymd = date('Ymd', $date);
+            $dow = date('w', $date);
+            if (intval($ymd) < "20120203" && $dow != 0 && $dow != 6) {
+                return Array("Weekday-SchoolVacation", "Weekday-SchoolVacation");
+            } else {
+                return Array("Weekday", "Weekday");
+            }
+    }
+}
+
+function valid_service_ids() {
+    return array_merge(service_ids(""), service_ids('saturday'), service_ids('sunday'));
 }
 
 function midnight_seconds($time = "") {
@@ -87,7 +114,7 @@
         "UNKNOWN_EFFECT" => "Unknown effect",
         "STOP_MOVED" => "Stop moved");
 
-    set_include_path(get_include_path() . PATH_SEPARATOR . $labsPath . "lib/Protobuf-PHP/library/DrSlump/");
+    set_include_path(get_include_path() . PATH_SEPARATOR . ($basePath . "lib/Protobuf-PHP/library/DrSlump/"));
 
     include_once("Protobuf.php");
     include_once("Protobuf/Message.php");
@@ -95,7 +122,7 @@
     include_once("Protobuf/Descriptor.php");
     include_once("Protobuf/Field.php");
 
-    include_once($labsPath . "lib/Protobuf-PHP/gtfs-realtime.php");
+    include_once($basePath . "lib/Protobuf-PHP/gtfs-realtime.php");
     include_once("Protobuf/CodecInterface.php");
     include_once("Protobuf/Codec/PhpArray.php");
     include_once("Protobuf/Codec/Binary.php");
@@ -274,5 +301,4 @@
     }
 
 }
-?>
-
+