Add and Remove operations for between stops
[bus.git] / betweenpoint.delete.php
blob:a/betweenpoint.delete.php -> blob:b/betweenpoint.delete.php
<?php <?php
$conn = pg_connect("dbname=bus user=postgres password=snmc"); $conn = pg_connect("dbname=bus user=postgres password=snmc");
if (!$conn) { if (!$conn) {
echo "An error occured.\n"; echo "An error occured.\n";
exit; exit;
} }
if ($_REQUEST['oldgeopo']) { if ($_REQUEST['oldgeopo']) {
$sql = " DELETE from stops WHERE geohash = '{$_REQUEST['oldgeopo']}'"; $sql = " DELETE from stops WHERE geohash = '{$_REQUEST['oldgeopo']}'";
$result = pg_query($conn, $sql); $result = pg_query($conn, $sql);
if (!$result) { if (!$result) {
echo("Error in SQL query: " . pg_last_error() . "<br>\n"); echo("Error in SQL query: " . pg_last_error() . "<br>\n");
} else { } else {
echo "Deleted {$_REQUEST['oldgeopo']}<br>"; 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(); flush();
?> ?>