manageconfig.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. function commit_sandbox_to_live($comment)
  3. {
  4. global $sql;
  5. $safever=mysqli_escape_string($sql,date('Y-m-d H:i:s') . " " . $comment);
  6. mysqli_query($sql,"BEGIN");
  7. mysqli_query($sql,"INSERT INTO old_paddles SELECT '$safever' AS verstring, paddles.* FROM paddles");
  8. mysqli_query($sql,"DELETE FROM live_paddles");
  9. mysqli_query($sql,"INSERT INTO live_paddles SELECT paddles.* FROM paddles");
  10. mysqli_query($sql,"INSERT INTO old_stops SELECT '$safever' AS verstring, stops.* FROM stops");
  11. mysqli_query($sql,"DELETE FROM live_stops");
  12. mysqli_query($sql,"INSERT INTO live_stops SELECT stops.* FROM stops");
  13. mysqli_query($sql,"COMMIT");
  14. $tmp=fopen("/tmp/new_paddles_exist","wb");
  15. if($tmp) fclose($tmp);
  16. }
  17. function version_list()
  18. {
  19. global $sql;
  20. $accum=array();
  21. $res=mysqli_query($sql,"SELECT verstring FROM old_stops GROUP BY verstring ORDER BY verstring DESC");
  22. while($row=mysqli_fetch_assoc($res))
  23. {
  24. $accum[]=$row['verstring'];
  25. }
  26. return $accum;
  27. }
  28. function load_sandbox_from_old($version)
  29. {
  30. global $sql;
  31. $safever=mysqli_escape_string($sql,$version);
  32. mysqli_query($sql,"BEGIN");
  33. $res=mysqli_query($sql,"SELECT COUNT(id) AS num FROM old_stops WHERE verstring='$safever'");
  34. $row=mysqli_fetch_assoc($res);
  35. if($row['num'] < 1)
  36. {
  37. mysqli_query($sql,"ROLLBACK");
  38. return false;
  39. }
  40. $res=mysqli_query($sql,"SELECT COUNT(id) AS num FROM old_paddles WHERE verstring='$safever'");
  41. $row=mysqli_fetch_assoc($res);
  42. if($row['num'] < 1)
  43. {
  44. mysqli_query($sql,"ROLLBACK");
  45. return false;
  46. }
  47. mysqli_query($sql,"DELETE FROM paddles");
  48. mysqli_query($sql,"INSERT INTO paddles SELECT id, slot, arrival, route, trip, stage, stop, stopid FROM old_paddles WHERE verstring='$safever'");
  49. mysqli_query($sql,"DELETE FROM stops");
  50. mysqli_query($sql,"INSERT INTO stops SELECT id, latitude, longitude, name FROM old_stops WHERE verstring='$safever'");
  51. mysqli_query($sql,"COMMIT");
  52. return true;
  53. }
  54. $vers=version_list();
  55. if(isset($_REQUEST['commit_confirm']))
  56. {
  57. if( strlen(trim($_REQUEST['comment'])) < 1)
  58. {
  59. echo "You must supply a comment.<br>";
  60. }
  61. else
  62. {
  63. commit_sandbox_to_live($_REQUEST['comment']);
  64. echo "Changes Committed to live busses.<br>";
  65. echo '<a href="index.php?goto=mainmenu>Return to Main Menu</a>';
  66. exit();
  67. }
  68. }
  69. if(isset($_REQUEST['commit_to_live']))
  70. {
  71. 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>";
  72. echo "<h2><a href=\"index.php\">Do Not Commit</a></h2>";
  73. 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>';
  74. }
  75. if(isset($_REQUEST['load_old_confirm']))
  76. {
  77. $found=false;
  78. foreach($vers as $ver)
  79. {
  80. if(!strcmp($ver,$_REQUEST['version']))
  81. {
  82. $found=true;
  83. break;
  84. }
  85. }
  86. if(!$found)
  87. {
  88. echo "Could not find saved data version \"${_REQUEST['version']}\"!<br>";
  89. }
  90. else
  91. {
  92. load_sandbox_from_old($_REQUEST['version']);
  93. echo "Previous configuration \"${_REQUEST['version']}\" loaded.<br>";
  94. echo '<a href="index.php?goto=mainmenu>Return to Main Menu</a>';
  95. exit();
  96. }
  97. }
  98. if(isset($_REQUEST['load_old']))
  99. {
  100. echo '<form method="POST">';
  101. echo '<p style="color: red;">Loading saved data will wipe out any stops and paddles currently in the editor.</p>';
  102. echo 'Please select an old configuration to load into the editor: <select name="version"><option value="">Select</option>';
  103. foreach($vers as $ver)
  104. {
  105. echo "<option value=\"$ver\">$ver</option>";
  106. }
  107. echo "</select> ";
  108. echo '<input type="submit" name="load_old_confirm" value="Load">';
  109. echo '</form>';
  110. echo '</form>';
  111. }
  112. echo '<hr>';
  113. echo '<a href="index.php?commit_to_live">Commit current Paddles and Stops to the <b>live server.</b></a>';
  114. echo '<br>';
  115. echo '<a href="index.php?load_old">Load Old Configuration into editor</a>';
  116. ?>