Add service alert editor
Add service alert editor

--- a/include/common-template.inc.php
+++ b/include/common-template.inc.php
@@ -25,7 +25,7 @@
 }
 function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = false, $datepicker = false)
 {
-	global $labsPath;
+	global $labsPath,$serviceAlertsEnabled;
 	echo '
 <!DOCTYPE html> 
 <html lang="en">
@@ -156,11 +156,13 @@
 				echo '<div id="servicewarning">Buses are running on an altered timetable today due to industrial action/public holiday. See <a href="http://www.action.act.gov.au">http://www.action.act.gov.au</a> for details.</div>';
 			}
 		}
+		if ($serviceAlertsEnabled) {
 		$serviceAlerts = getServiceAlerts("network","network");
 		foreach ($serviceAlerts['entities'] as $entity) {
-			echo "<div id='servicewarning'> From ".date("F j, g:i a",strtotime($entity['alert']['active_period']['start']))." to ". date("F j, g:i a", strtotime($entity['alert']['active_period']['end']))."<br>Warning: {$entity['alert']['description']['translation']} 
+			echo "<div id='servicewarning'>".date("F j, g:i a",strtotime($entity['alert']['active_period']['start']))." to ". date("F j, g:i a", strtotime($entity['alert']['active_period']['end']))."<br>Warning: {$entity['alert']['description']['translation']} 
 			<br><a href='{$entity['alert']['url']['translation']}'>Source</a>  </div>";
 		}
+	}
 	}
 }
 function include_footer()

--- a/include/common-transit.inc.php
+++ b/include/common-transit.inc.php
@@ -54,11 +54,17 @@
             - stop
             - trip
             - network
-          - patterns (WHERE=)
+          - classes (WHERE=)
             - route (short_name or route_id)
             - street
             - stop
-            - trip */
+            - trip 
+            Currently support:
+            network inform
+            trip patch: stop remove
+            street inform: route inform, trip inform, stop inform
+            route patch: trip remove
+            */
 $return = Array();
 $return['header']['gtrtfs_version'] = "1";
 $return['header']['timestamp'] = time();
@@ -97,8 +103,8 @@
 					$id = $value;
 				}
 			}
-		$return[$class][$id]['entity'] = $entity;
-		$return[$class][$id]['action'] = $informed["x-action"];
+		$return[$class][$id][]['entity'] = $entity;
+		$return[$class][$id][]['action'] = $informed["x-action"];
 	}
 	}
 }

--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -10,6 +10,7 @@
 	"database",
 	"other"
 );
+$serviceAlertsEnabled = true;
 $cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6";
 $googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q";
 $otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/';

--- a/include/db/route-dao.inc.php
+++ b/include/db/route-dao.inc.php
@@ -1,211 +1,222 @@
 <?php
 function getRoute($routeID)
-{
-	global $conn;
-	$query = "Select * from routes where route_id = :routeID LIMIT 1";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":routeID", $routeID);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetch(PDO::FETCH_ASSOC);
-}
+
+{
+     global $conn;
+     $query = "Select * from routes where route_id = :routeID LIMIT 1";
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":routeID", $routeID);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetch(PDO :: FETCH_ASSOC);
+    } 
 
 function getRouteByFullName($routeFullName)
-{
-	global $conn;
-	$query = "Select * from routes where route_short_name||route_long_name = :routeFullName LIMIT 1";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":routeFullName", $routeFullName);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetch(PDO::FETCH_ASSOC);
-}
+
+{
+     global $conn;
+     $query = "Select * from routes where route_short_name||route_long_name = :routeFullName LIMIT 1";
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":routeFullName", $routeFullName);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetch(PDO :: FETCH_ASSOC);
+    } 
 
 function getRoutes()
-{
-	global $conn;
-	$query = "Select * from routes order by route_short_name;";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+
+{
+     global $conn;
+     $query = "Select * from routes order by route_short_name;";
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 function getRoutesByNumber($routeNumber = "")
-{
-	global $conn;
-	if ($routeNumber != "") {
-		$query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes  join trips on trips.route_id =
+
+{
+     global $conn;
+     if ($routeNumber != "") {
+        $query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes  join trips on trips.route_id =
 routes.route_id join stop_times on stop_times.trip_id = trips.trip_id
 where route_short_name = :routeNumber OR route_short_name LIKE :routeNumber2 order by route_short_name;";
-	}
-	else {
-		$query = "SELECT DISTINCT route_short_name from routes order by route_short_name";
-	}
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	if ($routeNumber != "") {
-		$query->bindParam(":routeNumber", $routeNumber);
-                $routeNumber2 = "% ".$routeNumber;
-		$query->bindParam(":routeNumber2", $routeNumber2);
-	}
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+         } 
+    else {
+        $query = "SELECT DISTINCT route_short_name from routes order by route_short_name";
+         } 
+    debug($query, "database");
+     $query = $conn -> prepare($query);
+     if ($routeNumber != "") {
+        $query -> bindParam(":routeNumber", $routeNumber);
+         $routeNumber2 = "% " . $routeNumber;
+         $query -> bindParam(":routeNumber2", $routeNumber2);
+         } 
+    $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 function getRoutesByNumberSeries($routeNumberSeries = "")
-{
-	global $conn;
-	if (strlen($routeNumberSeries) == 1) {
-		return getRoutesByNumber($routeNumberSeries);
-	}
-	$seriesMin = substr($routeNumberSeries, 0, -1) . "0";
-	$seriesMax = substr($routeNumberSeries, 0, -1) . "9";
-	$query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes  join trips on trips.route_id =
+
+{
+     global $conn;
+     if (strlen($routeNumberSeries) == 1) {
+        return getRoutesByNumber($routeNumberSeries);
+         } 
+    $seriesMin = substr($routeNumberSeries, 0, -1) . "0";
+     $seriesMax = substr($routeNumberSeries, 0, -1) . "9";
+     $query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes  join trips on trips.route_id =
 routes.route_id join stop_times on stop_times.trip_id = trips.trip_id where to_number(route_short_name, 'FM999') between :seriesMin and :seriesMax OR route_short_name LIKE :routeNumberSeries order by route_short_name;";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":seriesMin", $seriesMin);
-	$query->bindParam(":seriesMax", $seriesMax);
-        $routeNumberSeries = "% ".substr($routeNumberSeries, 0, -1)."%";
-        $query->bindParam(":routeNumberSeries", $routeNumberSeries);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":seriesMin", $seriesMin);
+     $query -> bindParam(":seriesMax", $seriesMax);
+     $routeNumberSeries = "% " . substr($routeNumberSeries, 0, -1) . "%";
+     $query -> bindParam(":routeNumberSeries", $routeNumberSeries);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 function getRouteNextTrip($routeID)
-{
-	global $conn;
-	$query = "select * from routes join trips on trips.route_id = routes.route_id
+
+{
+     global $conn;
+     $query = "select * from routes join trips on trips.route_id = routes.route_id
 join stop_times on stop_times.trip_id = trips.trip_id where
 arrival_time > :currentTime and routes.route_id = :routeID order by
 arrival_time limit 1";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":currentTime", current_time());
-	$query->bindParam(":routeID", $routeID);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	$r = $query->fetch(PDO::FETCH_ASSOC);
-
-	// past last trip of the day special case
-	if (sizeof($r) < 16) {
-		$query = "select * from routes join trips on trips.route_id = routes.route_id
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":currentTime", current_time());
+     $query -> bindParam(":routeID", $routeID);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    $r = $query -> fetch(PDO :: FETCH_ASSOC);
+    
+     // past last trip of the day special case
+    if (sizeof($r) < 16) {
+        $query = "select * from routes join trips on trips.route_id = routes.route_id
 join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID order by
 arrival_time DESC limit 1";
-		debug($query, "database");
-		$query = $conn->prepare($query);
-		$query->bindParam(":routeID", $routeID);
-		$query->execute();
-		if (!$query) {
-			databaseError($conn->errorInfo());
-			return Array();
-		}
-            
-		$r = $query->fetch(PDO::FETCH_ASSOC);
-	}
-	return $r;
-}
+         debug($query, "database");
+         $query = $conn -> prepare($query);
+         $query -> bindParam(":routeID", $routeID);
+         $query -> execute();
+         if (!$query) {
+            databaseError($conn -> errorInfo());
+             return Array();
+             } 
+        
+        $r = $query -> fetch(PDO :: FETCH_ASSOC);
+         } 
+    return $r;
+    } 
 function getTimeInterpolatedRouteAtStop($routeID, $stop_id)
-{
-	$nextTrip = getRouteNextTrip($routeID);
-	if ($nextTrip['trip_id']) {
-		foreach (getTimeInterpolatedTrip($nextTrip['trip_id']) as $tripStop) {
-			if ($tripStop['stop_id'] == $stop_id) return $tripStop;
-		}
-	}
-	return Array();
-}
+
+{
+     $nextTrip = getRouteNextTrip($routeID);
+     if ($nextTrip['trip_id']) {
+        foreach (getTimeInterpolatedTrip($nextTrip['trip_id']) as $tripStop) {
+            if ($tripStop['stop_id'] == $stop_id) return $tripStop;
+             } 
+        } 
+    return Array();
+    } 
 function getRouteTrips($routeID)
-{
-	global $conn;
-	$query = "select routes.route_id,trips.trip_id,service_id,arrival_time, stop_id, stop_sequence from routes join trips on trips.route_id = routes.route_id
+
+{
+     global $conn;
+     $query = "select routes.route_id,trips.trip_id,service_id,arrival_time, stop_id, stop_sequence from routes join trips on trips.route_id = routes.route_id
 join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID and stop_sequence = '1' order by
 arrival_time ";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":routeID", $routeID);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":routeID", $routeID);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 function getRoutesByDestination($destination = "", $service_period = "")
-{
-	global $conn;
-	if ($service_period == "") $service_period = service_period();
-	if ($destination != "") {
-		$query = "SELECT DISTINCT trips.route_id,route_short_name,route_long_name, service_id
+
+{
+     global $conn;
+     if ($service_period == "") $service_period = service_period();
+     if ($destination != "") {
+        $query = "SELECT DISTINCT trips.route_id,route_short_name,route_long_name, service_id
 FROM stop_times join trips on trips.trip_id =
 stop_times.trip_id join routes on trips.route_id = routes.route_id
 WHERE route_long_name = :destination AND  service_id=:service_period order by route_short_name";
-	}
-	else {
-		$query = "SELECT DISTINCT route_long_name
+         } 
+    else {
+        $query = "SELECT DISTINCT route_long_name
 FROM stop_times join trips on trips.trip_id =
 stop_times.trip_id join routes on trips.route_id = routes.route_id
 WHERE service_id= :service_period order by route_long_name";
-	}
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":service_period", $service_period);
-	if ($destination != "") $query->bindParam(":destination", $destination);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+         } 
+    debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":service_period", $service_period);
+     if ($destination != "") $query -> bindParam(":destination", $destination);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 function getRoutesBySuburb($suburb, $service_period = "")
-{
-	if ($service_period == "") $service_period = service_period();
-	global $conn;
-	$query = "SELECT DISTINCT service_id,trips.route_id,route_short_name,route_long_name
+
+{
+     if ($service_period == "") $service_period = service_period();
+     global $conn;
+     $query = "SELECT DISTINCT service_id,trips.route_id,route_short_name,route_long_name
 FROM stop_times join trips on trips.trip_id = stop_times.trip_id
 join routes on trips.route_id = routes.route_id
 join stops on stops.stop_id = stop_times.stop_id
 WHERE zone_id LIKE ':suburb AND service_id=:service_period ORDER BY route_short_name";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":service_period", $service_period);
-        $suburb = "%" . $suburb . ";%";
-	$query->bindParam(":suburb", $suburb);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":service_period", $service_period);
+     $suburb = "%" . $suburb . ";%";
+     $query -> bindParam(":suburb", $suburb);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 function getRoutesNearby($lat, $lng, $limit = "", $distance = 500)
-{
-	if ($service_period == "") $service_period = service_period();
-	if ($limit != "") $limitSQL = " LIMIT :limit ";
-	global $conn;
-	$query = "SELECT service_id,trips.route_id,route_short_name,route_long_name,min(stops.stop_id) as stop_id,
+
+{
+     if ($service_period == "") $service_period = service_period();
+     if ($limit != "") $limitSQL = " LIMIT :limit ";
+     global $conn;
+     $query = "SELECT service_id,trips.route_id,route_short_name,route_long_name,min(stops.stop_id) as stop_id,
         min(ST_Distance(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), FALSE)) as distance
 FROM stop_times
 join trips on trips.trip_id = stop_times.trip_id
@@ -215,16 +226,16 @@
 AND ST_DWithin(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), :distance, FALSE)
         group by service_id,trips.route_id,route_short_name,route_long_name
         order by distance $limitSQL";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":service_period", $service_period);
-	$query->bindParam(":distance", $distance);
-	if ($limit != "") $query->bindParam(":limit", $limit);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":service_period", $service_period);
+     $query -> bindParam(":distance", $distance);
+     if ($limit != "") $query -> bindParam(":limit", $limit);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 ?>

--- a/include/db/servicealert-dao.inc.php
+++ b/include/db/servicealert-dao.inc.php
@@ -1,59 +1,167 @@
 <?php
-function getServiceOverride($date="") {
-	global $conn;
-	$query = "Select * from calendar_dates where date = :date and exception_type = '1' LIMIT 1";
-	// debug($query,"database");
-	$query = $conn->prepare($query); // Create a prepared statement
-	$query->bindParam(":date", date("Ymd",($date != "" ? $date : time())));
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetch(PDO::FETCH_ASSOC);
-}
+function getServiceOverride($date = "")
+{
+     global $conn;
+     $query = "Select * from calendar_dates where date = :date and exception_type = '1' LIMIT 1";
+     // debug($query,"database");
+    $query = $conn -> prepare($query); // Create a prepared statement
+     $query -> bindParam(":date", date("Ymd", ($date != "" ? $date : time())));
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetch(PDO :: FETCH_ASSOC);
+    } 
 
-function getCurrentAlerts() {
-		global $conn;
-	$query = 'SELECT * from servicealerts_alerts where NOW() > start and NOW() < "end"';
-	//debug($query, "database");
-	$query = $conn->prepare($query);
-	//if ($stop_sequence != "") $query->bindParam(":stop_sequence", $stop_sequence);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
-function getInformedAlerts($id,$filter_class,$filter_id) {
-	
-		global $conn;
-	$query = "SELECT * from servicealerts_informed where servicealert_id = :servicealert_id";
-	
-	if ($filter_class != "" ) {
-		$query .= " AND informed_class = :informed_class  ";
-	
-	}
-		if ($filter_id != "") {
-		$query .= " AND informed_id = :informed_id ";
-	
-	}
-	//debug($query, "database");
-	$query = $conn->prepare($query);
-	if ($filter_class != "" ) {
-		$query->bindParam(":informed_class", $filter_class);
-	}
-		if ($filter_id != "") {
-		$query->bindParam(":informed_id", $filter_id);
-	}
-	$query->bindParam(":servicealert_id", $id);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+function getServiceAlert($alertID)
+{
+     global $conn;
+     $query = 'SELECT * from servicealerts_alerts where id = :servicealert_id';
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":servicealert_id", $alertID);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetch(PDO :: FETCH_ASSOC);
+    } 
 
+
+function updateServiceAlert($alertID, $start, $end, $description, $url)
+{
+     global $conn;
+     $query = 'update servicealerts_alerts set start=:start, "end"=:end, description=:description, url=:url where id = :servicealert_id';
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":servicealert_id", $alertID);
+     $query -> bindParam(":start", $start);
+     $query -> bindParam(":end", $end);
+     $query -> bindParam(":description", $description);
+     $query -> bindParam(":url", $url);
+     $query -> execute();
+
+     print_r($conn -> errorInfo());
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetch(PDO :: FETCH_ASSOC);
+    } 
+
+    function addServiceAlert($start, $end, $description, $url)
+{
+     global $conn;
+     $query = 'INSERT INTO servicealerts_alerts (start, "end", description, url) VALUES (:start, :end, :description, :url) ';
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":start", $start);
+     $query -> bindParam(":end", $end);
+     $query -> bindParam(":description", $description);
+     $query -> bindParam(":url", $url);
+     $query -> execute();
+
+     print_r($conn -> errorInfo());
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetch(PDO :: FETCH_ASSOC);
+    } 
+
+function getCurrentAlerts()
+{
+     global $conn;
+     $query = 'SELECT * from servicealerts_alerts where NOW() > start and NOW() < "end"';
+     // debug($query, "database");
+    $query = $conn -> prepare($query);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
+
+function getFutureAlerts()
+{
+     global $conn;
+     $query = 'SELECT * from servicealerts_alerts where NOW() > start or NOW() < "end"';
+     // debug($query, "database");
+    $query = $conn -> prepare($query);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
+function getInformedAlerts($id, $filter_class, $filter_id)
+{
+    
+     global $conn;
+     $query = "SELECT * from servicealerts_informed where servicealert_id = :servicealert_id";
+    
+     if ($filter_class != "") {
+        $query .= " AND informed_class = :informed_class  ";
+        
+         } 
+    if ($filter_id != "") {
+        $query .= " AND informed_id = :informed_id ";
+        
+         } 
+    // debug($query, "database");
+    $query = $conn -> prepare($query);
+     if ($filter_class != "") {
+        $query -> bindParam(":informed_class", $filter_class);
+         } 
+    if ($filter_id != "") {
+        $query -> bindParam(":informed_id", $filter_id);
+         } 
+    $query -> bindParam(":servicealert_id", $id);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
+function deleteInformedAlert($serviceAlertID, $class, $id)
+{
+     global $conn;
+     $query = 'DELETE from servicealerts_informed where servicealert_id = :servicealert_id and informed_class = :informed_class  AND informed_id = :informed_id';
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":servicealert_id", $serviceAlertID);
+     $query -> bindParam(":informed_class", $class);
+     $query -> bindParam(":informed_id", $id);
+     $query -> execute();
+     print_r($conn -> errorInfo());
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return null;
+    } 
+function addInformedAlert($serviceAlertID, $class, $id, $action)
+{
+     global $conn;
+     $query = 'INSERT INTO servicealerts_informed (servicealert_id , informed_class , informed_id) VALUES(:servicealert_id ,:informed_class, :informed_id)';
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":servicealert_id", $serviceAlertID);
+     $query -> bindParam(":informed_class", $class);
+     $query -> bindParam(":informed_id", $id);
+     $query -> execute();
+
+     print_r($conn -> errorInfo());
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return null;
+    
+    } 
 ?>

--- a/include/db/stop-dao.inc.php
+++ b/include/db/stop-dao.inc.php
@@ -1,131 +1,154 @@
 <?php
 function getStop($stopID)
-{
-	global $conn;
-	$query = "Select * from stops where stop_id = :stopID LIMIT 1";
-	debug($query, "database");
-	$query = $conn->prepare($query);
-	$query->bindParam(":stopID", $stopID);
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetch(PDO::FETCH_ASSOC);
-}
+
+{
+     global $conn;
+     $query = "Select * from stops where stop_id = :stopID LIMIT 1";
+     debug($query, "database");
+     $query = $conn -> prepare($query);
+     $query -> bindParam(":stopID", $stopID);
+     $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetch(PDO :: FETCH_ASSOC);
+    } 
 function getStops($timingPointsOnly = false, $firstLetter = "", $startsWith = "")
-{
-	global $conn;
-	$conditions = Array();
-	if ($timingPointsOnly) $conditions[] = "substr(stop_code,1,2) != 'Wj'";
-	if ($firstLetter != "") $conditions[] = "substr(stop_name,1,1) = :firstLetter";
-	if ($startsWith != "") $conditions[] = "stop_name like :startsWith";
-	$query = "Select * from stops";
-	if (sizeof($conditions) > 0) {
-		if (sizeof($conditions) > 1) {
-			$query.= " Where " . implode(" AND ", $conditions) . " ";
-		}
-		else {
-			$query.= " Where " . $conditions[0] . " ";
-		}
-	}
-	$query.= " order by stop_name;";
-	$query = $conn->prepare($query);
-        if ($firstLetter != "") $query->bindParam(":firstLetter", $firstLetter);
-        
-        if ($startsWith != "") {
-            $startsWith = $startsWith."%";
-            $query->bindParam(":startsWith", $startsWith);
-        }
-	$query->execute();
-	if (!$query) {
-		databaseError($conn->errorInfo());
-		return Array();
-	}
-	return $query->fetchAll();
-}
+
+{
+     global $conn;
+     $conditions = Array();
+     if ($timingPointsOnly) $conditions[] = "substr(stop_code,1,2) != 'Wj'";
+     if ($firstLetter != "") $conditions[] = "substr(stop_name,1,1) = :firstLetter";
+     if ($startsWith != "") $conditions[] = "stop_name like :startsWith";
+     $query = "Select * from stops";
+     if (sizeof($conditions) > 0) {
+        if (sizeof($conditions) > 1) {
+            $query .= " Where " . implode(" AND ", $conditions) . " ";
+             } 
+        else {
+            $query .= " Where " . $conditions[0] . " ";
+             } 
+        } 
+    $query .= " order by stop_name;";
+     $query = $conn -> prepare($query);
+     if ($firstLetter != "") $query -> bindParam(":firstLetter", $firstLetter);
+    
+     if ($startsWith != "") {
+        $startsWith = $startsWith . "%";
+         $query -> bindParam(":startsWith", $startsWith);
+         } 
+    $query -> execute();
+     if (!$query) {
+        databaseError($conn -> errorInfo());
+         return Array();
+         } 
+    return $query -> fetchAll();
+    } 
 function getNearbyStops($lat, $lng, $limit = "", $distance = 1000)
-{
-	if ($lat == null || $lng == null) return Array();
-	if ($limit != "") $limitSQL = " LIMIT :limit ";
-	global $conn;
-	$query = "Select *, ST_Distance(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), FALSE) as distance
+
+{
+     if ($lat == null || $lng == null) return Array();
+     if ($limit != "") $limitSQL = " LIMIT :limit ";
+     global $conn;
+     $query = "Select *, ST_Distance(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), FALSE) as distance
         from stops WHERE ST_DWithin(position, ST_GeographyFromText('SRID=4326;POINT($lng $lat)'), :distance, F