Start on service alerts api
Start on service alerts api

 Binary files /dev/null and b/css/images/warning.png differ
file:b/geo/route.kml.php (new)
--- /dev/null
+++ b/geo/route.kml.php
@@ -1,1 +1,30 @@
+<?php
+header('Content-Type: application/vnd.google-earth.kml+xml');
+include ('../include/common.inc.php');
+echo '<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"><Document>';
+echo '
+    <Style id="yellowLineGreenPoly">
+      <LineStyle>
+        <color>7f00ff00</color>
+        <width>4</width>
+      </LineStyle>
+      <PolyStyle>
+        <color>7f00ffff</color>
+      </PolyStyle>
+	</Style>';
+$route = getRoute($routeid);
+ echo "\n<Placemark>\n";
+ $link = curPageURL()."/../trip.php?routeid=".htmlspecialchars ($route["route_id"]);
+ echo "<name>".$route['route_short_name']."</name>";
+  echo '<atom:link href="'.$link.'"/>';
+ echo '<description><![CDATA[ <a href="'.$link.'">'.$route['route_short_name']." ".$route['route_long_name']."</a>]]> </description>";
+echo "<styleUrl>#yellowLineGreenPoly</styleUrl>";
 
+	$trips = getRouteTrips($routeid);
+	echo getTripShape($trips[0]['trip_id']);
+
+echo "</Placemark>\n</Document></kml>\n";
+?>
+
+

--- a/include/common-session.inc.php
+++ b/include/common-session.inc.php
@@ -41,9 +41,6 @@
 			}
 		}
 	}
-	if ($_SESSION['lat'] != "" && isAnalyticsOn()) {
-		trackEvent("Geolocation", "Updated Location", "Geocoded - " . ($geocoded ? "Yes" : "No"));
-	}
 	sessionUpdated();
 }
 function sessionUpdated()
@@ -63,3 +60,4 @@
 	return ($_SESSION['time'] ? $_SESSION['time'] : date("H:i:s"));
 }
 ?>
+

--- a/include/db/route-dao.inc.php
+++ b/include/db/route-dao.inc.php
@@ -13,6 +13,7 @@
 	}
 	return $query->fetch(PDO::FETCH_ASSOC);
 }
+
 function getRoutes()
 {
 	global $conn;

--- a/include/db/trip-dao.inc.php
+++ b/include/db/trip-dao.inc.php
@@ -16,40 +16,25 @@
 	}
 	return $query->fetch(PDO::FETCH_ASSOC);
 }
-function getTripShape()
-{
-	/* def handle_json_GET_tripstopTimes(self, params):
-	   schedule = self.server.schedule
-	   try:
-	     trip = schedule.GetTrip(params.get('trip'))
-	   except KeyError:
-	      # if a non-existent trip is searched for, the return nothing
-	     return
-	   time_stops = trip.GetTimeInterpolatedStops()
-	   stops = []
-	   times = []
-	   for arr,ts,is_timingpoint in time_stops:
-	     stops.append(StopToTuple(ts.stop))
-	     times.append(arr)
-	   return [stops, times]
-	
-	 def handle_json_GET_tripshape(self, params):
-	   schedule = self.server.schedule
-	   try:
-	     trip = schedule.GetTrip(params.get('trip'))
-	   except KeyError:
-	      # if a non-existent trip is searched for, the return nothing
-	     return
-	   points = []
-	   if trip.shape_id:
-	     shape = schedule.GetShape(trip.shape_id)
-	     for (lat, lon, dist) in shape.points:
-	       points.append((lat, lon))
-	   else:
-	     time_stops = trip.GetTimeStops()
-	     for arr,dep,stop in time_stops:
-	       points.append((stop.stop_lat, stop.stop_lon))
-	   return points*/
+function getTripShape($tripID)
+{
+	global $conn;
+	$query = "SELECT ST_AsKML(ST_MakeLine(geometry(a.position))) as the_route
+FROM (SELECT position,
+	stop_sequence, trips.trip_id
+FROM stop_times
+join trips on trips.trip_id = stop_times.trip_id
+join stops on stops.stop_id = stop_times.stop_id
+WHERE trips.trip_id = :tripID ORDER BY stop_sequence) as a group by a.trip_id";
+	debug($query, "database");
+	$query = $conn->prepare($query);
+	$query->bindParam(":tripID", $tripID);
+	$query->execute();
+	if (!$query) {
+		databaseError($conn->errorInfo());
+		return Array();
+	}
+	return $query->fetchColumn(0);
 }
 function getTimeInterpolatedTrip($tripID, $range = "")
 {

--- /dev/null
+++ b/servicealerts_api.php
@@ -1,1 +1,54 @@
+<?php
+include ('include/common.inc.php');
+/*
+  also need last modified epoch of client gtfs
+  
+         - add,remove,patch
+            - stop
+            - trip
+          - patterns (WHERE=)
+            - route (short_name or route_id)
+            - street
+            - stop
+            - trip */
+/* header {
+  gtrtfs_version: "1"
+  timestamp: 1307926866
+}
+entity {
+  id: "21393"
+  alert {
+    active_period {
+      start: 1307955600
+      end: 1307988000
+    }
+    informed_entity {
+      route_id: "100"
+      route_type: 1
+    }
+    url {
+      translation {
+        text: "http://trimet.org/alerts/"
+      }
+    }
+    description_text {
+      translation {
+        text: "Rose Festival fleet departures will cause bridge lifts until around 10 a.m. Expect delays."
+      }
+    }
+  }
+}*/
+$return = Array();
 
+header('Content-Type: text/javascript; charset=utf8');
+// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/');
+header('Access-Control-Max-Age: 3628800');
+header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
+if (isset($_GET['callback'])) {
+	$json = '(' . json_encode($return) . ');'; //must wrap in parens and end with semicolon
+	print_r($_GET['callback'] . $json); //callback is prepended for json-p
+	
+}
+else echo json_encode($return);
+            ?>
+

--- a/sitemap.xml.php
+++ b/sitemap.xml.php
@@ -22,6 +22,17 @@
 	echo "<priority>0.9</priority>";
 	echo "</url>\n";
  }
+ 
+ // geosite map
+ foreach (getRoutes() as $route) {
+      echo " <url><loc>".curPageURL()."geo/route.kml.php?routeid=".htmlspecialchars ($route["route_id"])."</loc>";
+	echo "<lastmod>" . $last_updated . "</lastmod>";
+	echo "<geo:geo>
+       <geo:format>kml</geo:format>
+   </geo:geo>";
+	echo "</url>\n";
+ }
+ 
   echo '</urlset>';
 
 ?>