editpaddles.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. <?php
  2. $errstring="";
  3. //$_SESSION['paddle_dirty']=false;
  4. function paddle_list()
  5. {
  6. global $sql;
  7. $qry="SELECT id FROM paddles GROUP BY id";
  8. $res=mysqli_query($sql, $qry);
  9. $accum=array();
  10. while($row=mysqli_fetch_assoc($res))
  11. {
  12. $accum[]=$row['id'];
  13. }
  14. return $accum;
  15. }
  16. function load_stops_name()
  17. {
  18. global $sql;
  19. $qry="SELECT id,latitude,longitude,name FROM stops ORDER BY name";
  20. $res=mysqli_query($sql,$qry);
  21. $accum=array();
  22. while($row=mysqli_fetch_assoc($res))
  23. {
  24. $accum[$row['id']]=$row;
  25. }
  26. return $accum;
  27. }
  28. function load_stops_id()
  29. {
  30. global $sql;
  31. $qry="SELECT id,latitude,longitude,name FROM stops ORDER BY id";
  32. $res=mysqli_query($sql, $qry);
  33. $accum=array();
  34. while($row=mysqli_fetch_assoc($res))
  35. {
  36. $accum[$row['id']]=$row;
  37. }
  38. return $accum;
  39. }
  40. function generate_stop_name_select($stops,$formname,$nums=false,$selid=-1)
  41. {
  42. echo "<select name=\"$formname\">";
  43. echo '<option value="-1">Select a Stop</option>';
  44. foreach($stops as $stop)
  45. {
  46. if($nums)
  47. {
  48. $label=$stop['id'] . ": " . $stop['name'];
  49. }
  50. else
  51. {
  52. $label=$stop['name'];
  53. }
  54. if($stop['id'] == $selid)
  55. {
  56. echo "<option value=\"${stop['id']}\" selected>$label</option>";
  57. }
  58. else
  59. {
  60. echo "<option value=\"${stop['id']}\">$label</option>";
  61. }
  62. }
  63. echo '</select>';
  64. }
  65. function load_paddle($paddlenum)
  66. {
  67. global $sql;
  68. $safenum=mysqli_escape_string($sql,$paddlenum);
  69. $qry="SELECT id, DATE_FORMAT(arrival, '%H:%i') AS arrival, route, trip, stage, stop, stopid FROM paddles WHERE id='$paddlenum' ORDER BY slot ASC";
  70. $res=mysqli_query($sql,$qry);
  71. $accum=array();
  72. while($row=mysqli_fetch_assoc($res))
  73. {
  74. $accum[]=array( 'id' => $row['id'], 'arrival' => $row['arrival'], 'route' => $row['route'], 'trip' => $row['trip'], 'stage' => $row['stage'], 'stop' => $row['stop'], 'stopid' => $row['stopid']);
  75. }
  76. return $accum;
  77. }
  78. function move_up($index)
  79. {
  80. if($index > 0)
  81. {
  82. $temp=$_SESSION['paddle'][$index];
  83. $_SESSION['paddle'][$index]=$_SESSION['paddle'][$index-1];
  84. $_SESSION['paddle'][$index-1]=$temp;
  85. return true;
  86. }
  87. return false;
  88. }
  89. function move_down($index)
  90. {
  91. if($index < (count($_SESSION['paddle']) - 1))
  92. {
  93. $temp=$_SESSION['paddle'][$index];
  94. $_SESSION['paddle'][$index]=$_SESSION['paddle'][$index+1];
  95. $_SESSION['paddle'][$index+1]=$temp;
  96. return true;
  97. }
  98. return false;
  99. }
  100. function del_stop($index)
  101. {
  102. $accum=array();
  103. foreach($_SESSION['paddle'] as $key => $record)
  104. {
  105. if($key != $index)
  106. {
  107. $accum[] = $record;
  108. }
  109. }
  110. $_SESSION['paddle']=$accum;
  111. }
  112. function compare_paddle($paddle1, $legend1, $paddle2, $legend2)
  113. {
  114. global $count;
  115. global $stops;
  116. // $ugly=' bgcolor="#0000FF" ';
  117. $ugly='';
  118. echo "<center><table width =\"80%\" border=\"1\"><tr><th colspan=\"7\">$legend1</th><th $ugly>with</th><th colspan=\"7\">$legend2</th></tr>";
  119. echo '<tr>';
  120. echo '<th>Arrival</th><th>Route</th><th>Trip</th><th>Stage</th><th>Stop</th><th>Stop<br>ID</th><th>Stop Name</th>';
  121. echo '<th> </th>';
  122. echo '<th>Arrival</th><th>Route</th><th>Trip</th><th>Stage</th><th>Stop</th><th>Stop<br>ID</th><th>Stop Name</th>';
  123. echo '</tr>';
  124. $idx=0;
  125. while( isset($paddle1[$idx]) || isset($paddle2[$idx]) )
  126. {
  127. if(isset($paddle1[$idx]))
  128. {
  129. $p1a=$paddle1[$idx]['arrival'];
  130. $p1s=$paddle1[$idx]['stopid'];
  131. $p1n=$stops[$p1s]['name'];
  132. $p1rt=$paddle1[$idx]['route'];
  133. $p1tr=$paddle1[$idx]['trip'];
  134. $p1st=$paddle1[$idx]['stop'];
  135. $p1sg=$paddle1[$idx]['stage'];
  136. }
  137. else
  138. {
  139. $p1a=$p1s=$p1n=$p1rt=$p1tr=$p1st=$p1sg=" ";
  140. }
  141. if(isset($paddle2[$idx]))
  142. {
  143. $p2a=$paddle2[$idx]['arrival'];
  144. $p2s=$paddle2[$idx]['stopid'];
  145. $p2n=$stops[$p2s]['name'];
  146. $p2rt=$paddle2[$idx]['route'];
  147. $p2tr=$paddle2[$idx]['trip'];
  148. $p2st=$paddle2[$idx]['stop'];
  149. $p2sg=$paddle2[$idx]['stage'];
  150. }
  151. else
  152. {
  153. $p2a=$p2s=$p2n=$p2rt=$p2tr=$p2st=$p2sg=" ";
  154. }
  155. if( ($count % 2) == 1)
  156. {
  157. $bkgr="#E0FFE0";
  158. }
  159. else
  160. {
  161. $bkgr="#FFE0E0";
  162. }
  163. echo "<tr bgcolor=\"$bkgr\">";
  164. if($p1s < 0)
  165. {
  166. echo "<td>$p1a</td><td>$p1rt</td><td>$p1tr</td><td>$p1sg</td><td>$p1st</td><td colspan=\"2\"><i>Deleted Stop</i></td>";
  167. }
  168. else
  169. {
  170. echo "<td>$p1a</td><td>$p1rt</td><td>$p1tr</td><td>$p1sg</td><td>$p1st</td><td>$p1s</td><td>$p1n</td>";
  171. }
  172. echo "<td $ugly> </td>";
  173. if($p2s < 0)
  174. {
  175. echo "<td>$p2a</td><td>$p2rt</td><td>$p2tr</td><td>$p2sg</td><td>$p2st</td><td colspan=\"2\"><i>Deleted Stop</i></td>";
  176. }
  177. else
  178. {
  179. echo "<td>$p2a</td><td>$p2rt</td><td>$p2tr</td><td>$p2sg</td><td>$p2st</td><td>$p2s</td><td>$p2n</td>";
  180. }
  181. echo "</tr>";
  182. $idx++;
  183. }
  184. echo "</table></center>";
  185. }
  186. function commit_test()
  187. {
  188. $firstidx=0;
  189. $lastidx=count($_SESSION['paddle']) - 1;
  190. if($lastidx > 0)
  191. {
  192. if( strlen($_SESSION['paddle'][$firstidx]['arrival']) == 0 )
  193. {
  194. echo "First stop in paddle must have an arrival time.<br>";
  195. return false;
  196. }
  197. if( strlen($_SESSION['paddle'][$lastidx]['arrival']) == 0 )
  198. {
  199. echo "Last stop in paddle must have an arrival time.<br>";
  200. return false;
  201. }
  202. }
  203. return true;
  204. }
  205. function commit_paddle()
  206. {
  207. global $sql;
  208. if(!commit_test())
  209. return false;
  210. $safeid=mysqli_escape_string($sql,$_SESSION['current_paddle']);
  211. mysqli_query($sql,'BEGIN');
  212. mysqli_query($sql,"DELETE FROM paddles WHERE id='$safeid'");
  213. $idx=1;
  214. foreach($_SESSION['paddle'] as $stop)
  215. {
  216. if(strlen($stop['arrival']) > 0)
  217. {
  218. $arrclause="'" . mysqli_escape_string($sql,$stop['arrival']) . "'";
  219. }
  220. else
  221. {
  222. $arrclause = "NULL";
  223. }
  224. $safe_stopid=mysqli_escape_string($sql,$stop['stopid']);
  225. $sroute=mysqli_escape_string($sql,$stop['route']);
  226. $strip=mysqli_escape_string($sql,$stop['trip']);
  227. $sstage=mysqli_escape_string($sql,$stop['stage']);
  228. $sstop=mysqli_escape_string($sql,$stop['stop']);
  229. $qry="INSERT INTO paddles SET id='$safeid', slot='$idx', route='$sroute', trip='$strip', stage='$sstage', stop='$sstop', arrival=$arrclause, stopid='$safe_stopid'";
  230. mysqli_query($sql,$qry);
  231. $idx++;
  232. }
  233. mysqli_query($sql,'COMMIT');
  234. return true;
  235. }
  236. $stops=load_stops_name();
  237. $stopsid=load_stops_id();
  238. if(!isset($_SESSION['current_paddle']))
  239. {
  240. $_SESSION['current_paddle']=0;
  241. }
  242. if(!isset($_SESSION['paddle']))
  243. {
  244. if($_SESSION['current_paddle'] > 0)
  245. {
  246. $_SESSION['paddle']=load_paddle($_SESSION['current_paddle']);
  247. $_SESSION['paddle_dirty']=false;
  248. }
  249. }
  250. if(isset($_REQUEST['up']))
  251. {
  252. if(isset($_SESSION['paddle'][$_REQUEST['key']]))
  253. {
  254. if(move_up($_REQUEST['key']))
  255. {
  256. $_SESSION['paddle_dirty']=true;
  257. }
  258. }
  259. redirect('index.php');
  260. exit;
  261. }
  262. if(isset($_REQUEST['dn']))
  263. {
  264. if(isset($_SESSION['paddle'][$_REQUEST['key']]))
  265. {
  266. if(move_down($_REQUEST['key']))
  267. {
  268. $_SESSION['paddle_dirty']=true;
  269. }
  270. }
  271. redirect('index.php');
  272. exit;
  273. }
  274. if(isset($_REQUEST['del']))
  275. {
  276. if(isset($_SESSION['paddle'][$_REQUEST['key']]))
  277. {
  278. del_stop($_REQUEST['key']);
  279. }
  280. $_SESSION['paddle_dirty']=true;
  281. redirect('index.php');
  282. exit;
  283. }
  284. if(isset($_REQUEST['commit_paddle']))
  285. {
  286. if(commit_test())
  287. {
  288. echo '<h1><center>Replace this paddle?</center></h1>';
  289. compare_paddle(load_paddle($_SESSION['current_paddle']),"Old",$_SESSION['paddle'],"New");
  290. echo "<tr><td colspan=\"7\"><center><big><a href=\"index.php\">(Cancel)</a> <a href=\"index.php?commit_paddleconf\">(OK)</a></big></center></td></tr>";
  291. exit;
  292. }
  293. }
  294. else if(isset($_REQUEST['commit_paddleconf']))
  295. {
  296. if(commit_paddle())
  297. {
  298. unset($_SESSION['paddle']);
  299. unset($_SESSION['paddle_list']);
  300. redirect('index.php');
  301. }
  302. }
  303. if(isset($_REQUEST['revert_paddle']))
  304. {
  305. echo '<h1><center>Replace this paddle?</center></h1>';
  306. compare_paddle($_SESSION['paddle'],"New",load_paddle($_SESSION['current_paddle']),"Old");
  307. echo "<tr><td colspan=\"7\"><center><big><a href=\"index.php\">(Cancel)</a> <a href=\"index.php?revert_paddleconf\">(OK)</a></big></center></td></tr>";
  308. exit;
  309. }
  310. else if(isset($_REQUEST['revert_paddleconf']))
  311. {
  312. unset($_SESSION['paddle']);
  313. unset($_SESSION['paddle_list']);
  314. redirect('index.php');
  315. }
  316. if(isset($_REQUEST['addstop']))
  317. {
  318. $s1=$_REQUEST['stopid_1'];
  319. $s2=$_REQUEST['stopid_2'];
  320. $arr=$_REQUEST['arrival'];
  321. $rte=$_REQUEST['route'];
  322. $trp=$_REQUEST['trip'];
  323. $stg=$_REQUEST['stage'];
  324. $stp=$_REQUEST['stop'];
  325. $okay=true;
  326. if( ($s1 < 0) && ($s2 < 0) )
  327. {
  328. $okay=false;
  329. $errstring .= "You must select a stop to add to this paddle.<br>";
  330. }
  331. if( ($s1 >= 0) && ($s2 >= 0) )
  332. {
  333. if($s1 != $s2)
  334. {
  335. $okay=false;
  336. $errstring .= "Selected stops conflict. Please select either by number OR by name.<br>";
  337. }
  338. }
  339. if(!preg_match('/[\d]+/',$rte))
  340. {
  341. $okay=false;
  342. $errstring .= "Route must be numeric.<br>";
  343. }
  344. if(!preg_match('/[\d]+/',$trp))
  345. {
  346. $okay=false;
  347. $errstring .= "Trip must be numeric.<br>";
  348. }
  349. if(!preg_match('/[\d]+/',$stp))
  350. {
  351. $okay=false;
  352. $errstring .= "Stop must be numeric.<br>";
  353. }
  354. if(!preg_match('/[\d]+/',$stg))
  355. {
  356. $stg=0;
  357. }
  358. if( strlen($arr) > 0)
  359. {
  360. $mats=array();
  361. if(!preg_match('/([\d][\d]?):([\d][\d])/',$arr,$mats))
  362. {
  363. $okay=false;
  364. $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.<br>";
  365. }
  366. else
  367. {
  368. if( ($mats[1] > 23) || ($mats[2] > 59) )
  369. {
  370. $okay=false;
  371. $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.<br>";
  372. }
  373. }
  374. }
  375. if($okay)
  376. {
  377. if($s1 >= 0)
  378. {
  379. $stopid=$s1;
  380. }
  381. else
  382. {
  383. $stopid=$s2;
  384. }
  385. $_SESSION['paddle'][]=array( 'id' => $_SESSION['current_paddle'], 'arrival' => $_REQUEST['arrival'], 'route' => $rte, 'stop' => $stp, 'trip' => $trp, 'stage' => $stg, 'stopid' => $stopid);
  386. $_SESSION['paddle_dirty']=true;
  387. redirect('index.php');
  388. }
  389. }
  390. if(isset($_REQUEST['edit_done']))
  391. {
  392. $s1=$_REQUEST['stopid_1'];
  393. $s2=$_REQUEST['stopid_2'];
  394. $arr=$_REQUEST['arrival'];
  395. $rte=$_REQUEST['route'];
  396. $trp=$_REQUEST['trip'];
  397. $stg=$_REQUEST['stage'];
  398. $stp=$_REQUEST['stop'];
  399. $okay=true;
  400. if( ($s1 < 0) && ($s2 < 0) )
  401. {
  402. $okay=false;
  403. $errstring .= "You must select a valid stop.<br>";
  404. }
  405. if( ($s1 >= 0) && ($s2 >= 0) )
  406. {
  407. if($s1 != $s2)
  408. {
  409. $okay=false;
  410. $errstring .= "Selected stops conflict. Please select either by number OR by name.<br>";
  411. }
  412. }
  413. if(!preg_match('/[\d]+/',$rte))
  414. {
  415. $okay=false;
  416. $errstring .= "Route must be numeric.<br>";
  417. }
  418. if(!preg_match('/[\d]+/',$trp))
  419. {
  420. $okay=false;
  421. $errstring .= "Trip must be numeric.<br>";
  422. }
  423. if(!preg_match('/[\d]+/',$stp))
  424. {
  425. $okay=false;
  426. $errstring .= "Stop must be numeric.<br>";
  427. }
  428. if(!preg_match('/[\d]+/',$stg))
  429. {
  430. $stg=0;
  431. }
  432. if( strlen($arr) > 0)
  433. {
  434. $mats=array();
  435. if(!preg_match('/([\d][\d]?):([\d][\d])/',$arr,$mats))
  436. {
  437. $okay=false;
  438. $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.<br>";
  439. }
  440. else
  441. {
  442. if( ($mats[1] > 23) || ($mats[2] > 59) )
  443. {
  444. $okay=false;
  445. $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.<br>";
  446. }
  447. }
  448. }
  449. if($okay)
  450. {
  451. if($s1 >= 0)
  452. {
  453. $stopid=$s1;
  454. }
  455. else
  456. {
  457. $stopid=$s2;
  458. }
  459. $_SESSION['paddle'][$_REQUEST['key']]=array( 'id' => $_SESSION['current_paddle'], 'arrival' => $_REQUEST['arrival'], 'route' => $rte, 'stop' => $stp, 'trip' => $trp, 'stage' => $stg, 'stopid' => $stopid);
  460. $_SESSION['paddle_dirty']=true;
  461. redirect('index.php');
  462. }
  463. }
  464. function generate_edit_line($dflt)
  465. {
  466. global $stopsid;
  467. global $stops;
  468. global $errstring;
  469. if(strlen($errstring) > 0)
  470. {
  471. echo "<tr><td colspan=\"8\" style=\"color: red;\"><center><big>$errstring</big></center></td></tr>";
  472. }
  473. $myreq=$_REQUEST;
  474. if(!isset($myreq['stopid_1']))
  475. {
  476. if (!array_key_exists('arrival',$dflt)) { $dflt['arrival'] = null; }
  477. if (!array_key_exists('route',$dflt)) { $dflt['route'] = null; }
  478. if (!array_key_exists('trip',$dflt)) { $dflt['trip'] = null; }
  479. if (!array_key_exists('stage',$dflt)) { $dflt['stage'] = null; }
  480. if (!array_key_exists('stop',$dflt)) { $dflt['stop'] = null; }
  481. if (!array_key_exists('stopid',$dflt)) { $dflt['stopid'] = null; }
  482. echo $dflt['arrival'];
  483. $myreq['arrival']=$dflt['arrival'];
  484. $myreq['route']=$dflt['route'];
  485. $myreq['trip']=$dflt['trip'];
  486. $myreq['stage']=$dflt['stage'];
  487. $myreq['stop']=$dflt['stop'];
  488. $myreq['stopid_1']=$dflt['stopid'];
  489. $myreq['stopid_2']=$dflt['stopid'];
  490. }
  491. echo "<tr><form name=\"frm\"><td><input type=\"text\" size=\"8\" name=\"arrival\" value=\"${myreq['arrival']}\"></td>";
  492. echo "<td><input type=\"text\" size=\"4\" name=\"route\" value=\"${myreq['route']}\"></td>";
  493. echo "<td><input type=\"text\" size=\"4\" name=\"trip\" value=\"${myreq['trip']}\"></td>";
  494. echo "<td><input type=\"text\" size=\"4\" name=\"stage\" value=\"${myreq['stage']}\"></td>";
  495. echo "<td><input type=\"text\" size=\"4\" name=\"stop\" value=\"${myreq['stop']}\"></td>";
  496. echo "<td colspan=\"2\">";
  497. //--------------sub table that lives in the colspanned cell containing stop ID and stop name---
  498. echo '<center><table>';
  499. echo '<tr><td><center>By number:</center></td><td><b>or</b></td><td><center>By name:</center></td></tr>';
  500. echo '<tr><td>';
  501. generate_stop_name_select($stopsid,'stopid_1',true,$myreq['stopid_1']);
  502. echo '</td><td></td><td>';
  503. generate_stop_name_select($stops,'stopid_2',false,$myreq['stopid_2']);
  504. echo '</td></tr>';
  505. echo '</table></center>';
  506. //---------------------------------------------------------------------------------------------
  507. if(isset($_REQUEST['edit']))
  508. {
  509. echo "</td><td><input type=\"hidden\" name=\"edit\" value=\"1\"><input type=\"hidden\" name=\"key\" value=\"${_REQUEST['key']}\"><input type=\"submit\" name=\"edit_done\" value=\"Done\"> <a href=\"index.php\">(Cancel)</a></td></form></tr>";
  510. }
  511. else
  512. {
  513. echo '</td><td><input type="submit" name="addstop" value="Add Stop to Paddle"></td></form></tr>';
  514. }
  515. }
  516. //--------------------------------------------If the paddle is unmodified from its last saved state, allow the user to browse to a different one,
  517. //------------------------------------------create a new one, etc...
  518. if(isset($_REQUEST['submitadv']))
  519. {
  520. $_SESSION['paddle']=array();
  521. $lines=preg_split("/[\r\n]+/",$_REQUEST['advtxt']);
  522. foreach($lines as $line)
  523. {
  524. $mats=array();
  525. if(preg_match("/([\d]+:[\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([\d]+)/",$line,$mats))
  526. {
  527. //echo "<pre>";
  528. //print_r($mats);
  529. //echo "</pre>";
  530. $_SESSION['paddle'][]=array('arrival' => $mats[1], 'route' => $mats[2], 'trip' => $mats[3], 'stage' => $mats[4], 'stop' => $mats[5], 'stopid' => $mats[6]);
  531. }
  532. }
  533. $_SESSION['paddle_dirty']=true;
  534. //echo "<pre>";
  535. //print_r($lines);
  536. //echo "</pre>";
  537. //exit;
  538. }
  539. if(!$_SESSION['paddle_dirty'])
  540. {
  541. if(!isset($_SESSION['paddle_list']))
  542. {
  543. $_SESSION['paddle_list']=paddle_list();
  544. }
  545. if( isset($_REQUEST['selectpaddle']) && ($_REQUEST['selectpaddle'] != $_SESSION['current_paddle']) )
  546. {
  547. $_SESSION['current_paddle']=$_REQUEST['selectpaddle'];
  548. unset($_SESSION['paddle']);
  549. redirect('index.php');
  550. exit;
  551. }
  552. else if( isset($_REQUEST['createnewpaddle']) )
  553. {
  554. $newpaddle=$_REQUEST['newpaddle'];
  555. if(preg_match('/[\d]+/', $newpaddle) && (intval($newpaddle > 0)) && !in_array($newpaddle,$_SESSION['paddle_list']) )
  556. {//the above test insures that the new paddle number is unique, numeric, and non-zero
  557. $_SESSION['paddle_list'][]=$newpaddle;
  558. $_SESSION['current_paddle']=$newpaddle;
  559. unset($_SESSION['paddle']);
  560. redirect('index.php');
  561. exit;
  562. }
  563. else
  564. {
  565. echo '<h3 style="color: red;"><center>New Paddle number must be unique and non-zero.</center></h3>';
  566. }
  567. }
  568. echo '<form name="jump1">';
  569. echo '<center><big>';
  570. echo 'Select an existing paddle: ';
  571. echo '<select name="myjumpbox" OnChange="location.href=jump1.myjumpbox.options[selectedIndex].value">';
  572. echo '<option value="index.php?selectpaddle=-1">Select a Paddle</option>';
  573. foreach($_SESSION['paddle_list'] as $paddle)
  574. {
  575. if($paddle == $_SESSION['current_paddle'])
  576. {
  577. echo "<option value=\"index.php?selectpaddle=$paddle\" selected>$paddle</option>";
  578. }
  579. else
  580. {
  581. echo "<option value=\"index.php?selectpaddle=$paddle\">$paddle</option>";
  582. }
  583. }
  584. echo '</select>';
  585. echo ' or create a new one: ';
  586. echo '<input type="text" name="newpaddle" size="6"> <input type="submit" name="createnewpaddle" value="Create New Paddle">';
  587. echo '</form>';
  588. echo '</big></center>';
  589. echo '<hr>';
  590. }
  591. if(isset($_REQUEST['advanced_edit']))
  592. {
  593. $accum="Time Route Trp Stg Stp StopID Stopname\n";
  594. foreach($_SESSION['paddle'] as $key => $record)
  595. {
  596. $accum .= sprintf("%6s %5d %3d %3d %3d %5d %s\n",$record['arrival'],$record['route'],$record['trip'],$record['stage'],$record['stop'],$record['stopid'],$stops[$record['stopid']]['name']);
  597. }
  598. echo '<form method="POST" action="index.php">';
  599. echo '<textarea rows="40" cols="90" name="advtxt">';
  600. echo htmlspecialchars($accum);
  601. echo '</textarea>';
  602. echo '<input type="submit" name="submitadv" value="Apply Change">';
  603. echo '</form>';
  604. }
  605. else if($_SESSION['current_paddle'] > 0)
  606. { //only draw the current paddle edit UI if we actually have a valid paddle selected
  607. //--------------------------------------------------------------BELOW DEALS WITH DISPLAYING THE MAIN PADDLE MANAGEMENT SCREEN-------------
  608. echo '<center><table width="90%" border="1">';
  609. echo '<tr><td colspan="8"><center><a href="index.php?advanced_edit">Advanced Edit</a></center></td></tr>';
  610. echo "<tr><th colspan=\"8\"><center>Paddle Number ${_SESSION['current_paddle']}</center></th></tr>";
  611. echo '<tr><th>Scheduled<br>Arrival</th><th>Route #</th><th>Trip #</th><th>Stage #</th><th>Stop #</th><th>Unique<br>Stop ID</th><th>Stop<br>Name</th><th>Actions</th></tr>';
  612. $count=0;
  613. foreach($_SESSION['paddle'] as $key => $record)
  614. {
  615. $stopname=$stops[$record['stopid']]['name'];
  616. $stopid=$record['stopid'];
  617. $arrival=$record['arrival'];
  618. $route=$record['route'];
  619. $trip=$record['trip'];
  620. $stage=$record['stage'];
  621. $stop=$record['stop'];
  622. $upurl="index.php?up&key=$key";
  623. $dnurl="index.php?dn&key=$key";
  624. $delurl="index.php?del&key=$key";
  625. $editurl="index.php?edit&key=$key";
  626. if( ($count % 2) == 1)
  627. {
  628. $bkgr="#E0FFE0";
  629. }
  630. else
  631. {
  632. $bkgr="#FFE0E0";
  633. }
  634. if(isset($_REQUEST['edit']) && ($_REQUEST['key'] == $key) )
  635. {
  636. generate_edit_line($record);
  637. }
  638. else
  639. {
  640. if($stopid >= 0)
  641. {
  642. echo "<tr bgcolor=\"$bkgr\"><td>$arrival</td><td>$route</td><td>$trip</td><td>$stage</td><td>$stop</td><td>$stopid</td><td>$stopname</td><td><a href=\"$upurl\">(Move Up)</a> <a href=\"$dnurl\">(Move Down)</a> <a href=\"$delurl\">(Delete)</a> <a href=\"$editurl\">(Edit)</a></td></tr>";
  643. }
  644. else
  645. {
  646. echo "<tr bgcolor=\"$bkgr\"><td colspan=7><center><i>This stop has been deleted.</i></center></td><td><a href=\"$upurl\">(Move Up)</a> <a href=\"$dnurl\">(Move Down)</a> <a href=\"$delurl\">(Delete)</a> </td></tr>";
  647. }
  648. }
  649. $count++;
  650. }
  651. if(!isset($_REQUEST['edit']))
  652. {
  653. generate_edit_line(array());
  654. }
  655. if($_SESSION['paddle_dirty'])
  656. {
  657. echo '<tr bgcolor="#FFA0A0"><td colspan="8"><center><big><a href="index.php?commit_paddle">(Commit Changes to Paddle)</a> <a href="index.php?revert_paddle">(Revert to Saved Paddle)</a></big></center></td></tr>';
  658. }
  659. echo '</table></center>';
  660. }
  661. ?>