| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- function commit_sandbox_to_live($comment)
- {
- global $sql;
- $safever=mysqli_escape_string($sql,date('Y-m-d H:i:s') . " " . $comment);
- mysqli_query($sql,"BEGIN");
-
- mysqli_query($sql,"INSERT INTO old_paddles SELECT '$safever' AS verstring, paddles.* FROM paddles");
- mysqli_query($sql,"DELETE FROM live_paddles");
- mysqli_query($sql,"INSERT INTO live_paddles SELECT paddles.* FROM paddles");
- mysqli_query($sql,"INSERT INTO old_stops SELECT '$safever' AS verstring, stops.* FROM stops");
- mysqli_query($sql,"DELETE FROM live_stops");
- mysqli_query($sql,"INSERT INTO live_stops SELECT stops.* FROM stops");
-
- mysqli_query($sql,"COMMIT");
- $tmp=fopen("/tmp/new_paddles_exist","wb");
- if($tmp) fclose($tmp);
- }
- function version_list()
- {
- global $sql;
- $accum=array();
-
- $res=mysqli_query($sql,"SELECT verstring FROM old_stops GROUP BY verstring ORDER BY verstring DESC");
- while($row=mysqli_fetch_assoc($res))
- {
- $accum[]=$row['verstring'];
- }
- return $accum;
- }
- function load_sandbox_from_old($version)
- {
- global $sql;
- $safever=mysqli_escape_string($sql,$version);
- mysqli_query($sql,"BEGIN");
-
- $res=mysqli_query($sql,"SELECT COUNT(id) AS num FROM old_stops WHERE verstring='$safever'");
- $row=mysqli_fetch_assoc($res);
- if($row['num'] < 1)
- {
- mysqli_query($sql,"ROLLBACK");
- return false;
- }
-
- $res=mysqli_query($sql,"SELECT COUNT(id) AS num FROM old_paddles WHERE verstring='$safever'");
- $row=mysqli_fetch_assoc($res);
- if($row['num'] < 1)
- {
- mysqli_query($sql,"ROLLBACK");
- return false;
- }
-
- mysqli_query($sql,"DELETE FROM paddles");
- mysqli_query($sql,"INSERT INTO paddles SELECT id, slot, arrival, route, trip, stage, stop, stopid FROM old_paddles WHERE verstring='$safever'");
- mysqli_query($sql,"DELETE FROM stops");
- mysqli_query($sql,"INSERT INTO stops SELECT id, latitude, longitude, name FROM old_stops WHERE verstring='$safever'");
-
- mysqli_query($sql,"COMMIT");
-
- return true;
- }
- $vers=version_list();
- if(isset($_REQUEST['commit_confirm']))
- {
- if( strlen(trim($_REQUEST['comment'])) < 1)
- {
- echo "You must supply a comment.<br>";
- }
- else
- {
- commit_sandbox_to_live($_REQUEST['comment']);
- echo "Changes Committed to live busses.<br>";
- echo '<a href="index.php?goto=mainmenu>Return to Main Menu</a>';
- exit();
- }
- }
- if(isset($_REQUEST['commit_to_live']))
- {
- echo "<h1>Are you sure you want to commit your current paddles? Doing so will place them in the live database and they will go into effect as the busses synchronize.</h1>";
- echo "<h2><a href=\"index.php\">Do Not Commit</a></h2>";
- echo '<form method="POST">Enter your comment for this revision: <input type="text" size="32" name="comment"> <input type="submit" name="commit_confirm" value="Commit Changes"></form><br>';
- }
- if(isset($_REQUEST['load_old_confirm']))
- {
- $found=false;
-
- foreach($vers as $ver)
- {
- if(!strcmp($ver,$_REQUEST['version']))
- {
- $found=true;
- break;
- }
- }
-
- if(!$found)
- {
- echo "Could not find saved data version \"${_REQUEST['version']}\"!<br>";
- }
- else
- {
- load_sandbox_from_old($_REQUEST['version']);
- echo "Previous configuration \"${_REQUEST['version']}\" loaded.<br>";
- echo '<a href="index.php?goto=mainmenu>Return to Main Menu</a>';
- exit();
- }
- }
- if(isset($_REQUEST['load_old']))
- {
- echo '<form method="POST">';
- echo '<p style="color: red;">Loading saved data will wipe out any stops and paddles currently in the editor.</p>';
- echo 'Please select an old configuration to load into the editor: <select name="version"><option value="">Select</option>';
- foreach($vers as $ver)
- {
- echo "<option value=\"$ver\">$ver</option>";
- }
- echo "</select> ";
- echo '<input type="submit" name="load_old_confirm" value="Load">';
- echo '</form>';
-
- echo '</form>';
- }
- echo '<hr>';
- echo '<a href="index.php?commit_to_live">Commit current Paddles and Stops to the <b>live server.</b></a>';
- echo '<br>';
- echo '<a href="index.php?load_old">Load Old Configuration into editor</a>';
- ?>
|