Display which routes are modified when a stop is moved or deleted
[bus.git] / betweenpoint.delete.php
blob:a/betweenpoint.delete.php -> blob:b/betweenpoint.delete.php
--- a/betweenpoint.delete.php
+++ b/betweenpoint.delete.php
@@ -13,6 +13,20 @@
           echo("Error in SQL query: " . pg_last_error() . "<br>\n");
       } else {
       echo "Deleted {$_REQUEST['oldgeopo']}<br>";
+      $updatedroutes = 0;
+      $result_outdatedroutes = pg_query($conn, "Select * FROM between_stops where points LIKE '%" . $_REQUEST['oldgeopo'] . ";%'");
+      while ($outdatedroute = pg_fetch_assoc($result_outdatedroutes)) {
+          $newpoints = str_replace($_REQUEST['oldgeopo'].';', '', $outdatedroute['points']);
+          $sql = "UPDATE between_stops set points='$newpoints' where fromlocation = '{$outdatedroute['fromlocation']}' AND tolocation = '{$outdatedroute['tolocation']}' ";
+          $result = pg_query($conn, $sql);
+          if (!$result) {
+              echo("Error in SQL query: " . pg_last_error() . "<br>\n");
+          }
+	    echo "updated ".$outdatedroute['fromlocation']."->".$outdatedroute['tolocation']."<br>";
+        
+          $updatedroutes++;
+      }
+      echo "updated $updatedroutes routes<br>";
       }
   }
   flush();