"; echo ''; foreach($stops as $stop) { if($nums) { $label=$stop['id'] . ": " . $stop['name']; } else { $label=$stop['name']; } if($stop['id'] == $selid) { echo ""; } else { echo ""; } } echo ''; } function load_paddle($paddlenum) { global $sql; $safenum=mysqli_escape_string($sql,$paddlenum); $qry="SELECT id, DATE_FORMAT(arrival, '%H:%i') AS arrival, route, trip, stage, stop, stopid FROM paddles WHERE id='$paddlenum' ORDER BY slot ASC"; $res=mysqli_query($sql,$qry); $accum=array(); while($row=mysqli_fetch_assoc($res)) { $accum[]=array( 'id' => $row['id'], 'arrival' => $row['arrival'], 'route' => $row['route'], 'trip' => $row['trip'], 'stage' => $row['stage'], 'stop' => $row['stop'], 'stopid' => $row['stopid']); } return $accum; } function move_up($index) { if($index > 0) { $temp=$_SESSION['paddle'][$index]; $_SESSION['paddle'][$index]=$_SESSION['paddle'][$index-1]; $_SESSION['paddle'][$index-1]=$temp; return true; } return false; } function move_down($index) { if($index < (count($_SESSION['paddle']) - 1)) { $temp=$_SESSION['paddle'][$index]; $_SESSION['paddle'][$index]=$_SESSION['paddle'][$index+1]; $_SESSION['paddle'][$index+1]=$temp; return true; } return false; } function del_stop($index) { $accum=array(); foreach($_SESSION['paddle'] as $key => $record) { if($key != $index) { $accum[] = $record; } } $_SESSION['paddle']=$accum; } function compare_paddle($paddle1, $legend1, $paddle2, $legend2) { global $count; global $stops; // $ugly=' bgcolor="#0000FF" '; $ugly=''; echo "
"; echo ''; echo ''; echo ''; echo ''; echo ''; $idx=0; while( isset($paddle1[$idx]) || isset($paddle2[$idx]) ) { if(isset($paddle1[$idx])) { $p1a=$paddle1[$idx]['arrival']; $p1s=$paddle1[$idx]['stopid']; $p1n=$stops[$p1s]['name']; $p1rt=$paddle1[$idx]['route']; $p1tr=$paddle1[$idx]['trip']; $p1st=$paddle1[$idx]['stop']; $p1sg=$paddle1[$idx]['stage']; } else { $p1a=$p1s=$p1n=$p1rt=$p1tr=$p1st=$p1sg=" "; } if(isset($paddle2[$idx])) { $p2a=$paddle2[$idx]['arrival']; $p2s=$paddle2[$idx]['stopid']; $p2n=$stops[$p2s]['name']; $p2rt=$paddle2[$idx]['route']; $p2tr=$paddle2[$idx]['trip']; $p2st=$paddle2[$idx]['stop']; $p2sg=$paddle2[$idx]['stage']; } else { $p2a=$p2s=$p2n=$p2rt=$p2tr=$p2st=$p2sg=" "; } if( ($count % 2) == 1) { $bkgr="#E0FFE0"; } else { $bkgr="#FFE0E0"; } echo ""; if($p1s < 0) { echo ""; } else { echo ""; } echo ""; if($p2s < 0) { echo ""; } else { echo ""; } echo ""; $idx++; } echo "
$legend1with$legend2
ArrivalRouteTripStageStopStop
ID
Stop Name ArrivalRouteTripStageStopStop
ID
Stop Name
$p1a$p1rt$p1tr$p1sg$p1stDeleted Stop$p1a$p1rt$p1tr$p1sg$p1st$p1s$p1n $p2a$p2rt$p2tr$p2sg$p2stDeleted Stop$p2a$p2rt$p2tr$p2sg$p2st$p2s$p2n
"; } function commit_test() { $firstidx=0; $lastidx=count($_SESSION['paddle']) - 1; if($lastidx > 0) { if( strlen($_SESSION['paddle'][$firstidx]['arrival']) == 0 ) { echo "First stop in paddle must have an arrival time.
"; return false; } if( strlen($_SESSION['paddle'][$lastidx]['arrival']) == 0 ) { echo "Last stop in paddle must have an arrival time.
"; return false; } } return true; } function commit_paddle() { global $sql; if(!commit_test()) return false; $safeid=mysqli_escape_string($sql,$_SESSION['current_paddle']); mysqli_query($sql,'BEGIN'); mysqli_query($sql,"DELETE FROM paddles WHERE id='$safeid'"); $idx=1; foreach($_SESSION['paddle'] as $stop) { if(strlen($stop['arrival']) > 0) { $arrclause="'" . mysqli_escape_string($sql,$stop['arrival']) . "'"; } else { $arrclause = "NULL"; } $safe_stopid=mysqli_escape_string($sql,$stop['stopid']); $sroute=mysqli_escape_string($sql,$stop['route']); $strip=mysqli_escape_string($sql,$stop['trip']); $sstage=mysqli_escape_string($sql,$stop['stage']); $sstop=mysqli_escape_string($sql,$stop['stop']); $qry="INSERT INTO paddles SET id='$safeid', slot='$idx', route='$sroute', trip='$strip', stage='$sstage', stop='$sstop', arrival=$arrclause, stopid='$safe_stopid'"; mysqli_query($sql,$qry); $idx++; } mysqli_query($sql,'COMMIT'); return true; } $stops=load_stops_name(); $stopsid=load_stops_id(); if(!isset($_SESSION['current_paddle'])) { $_SESSION['current_paddle']=0; } if(!isset($_SESSION['paddle'])) { if($_SESSION['current_paddle'] > 0) { $_SESSION['paddle']=load_paddle($_SESSION['current_paddle']); $_SESSION['paddle_dirty']=false; } } if(isset($_REQUEST['up'])) { if(isset($_SESSION['paddle'][$_REQUEST['key']])) { if(move_up($_REQUEST['key'])) { $_SESSION['paddle_dirty']=true; } } redirect('index.php'); exit; } if(isset($_REQUEST['dn'])) { if(isset($_SESSION['paddle'][$_REQUEST['key']])) { if(move_down($_REQUEST['key'])) { $_SESSION['paddle_dirty']=true; } } redirect('index.php'); exit; } if(isset($_REQUEST['del'])) { if(isset($_SESSION['paddle'][$_REQUEST['key']])) { del_stop($_REQUEST['key']); } $_SESSION['paddle_dirty']=true; redirect('index.php'); exit; } if(isset($_REQUEST['commit_paddle'])) { if(commit_test()) { echo '

Replace this paddle?

'; compare_paddle(load_paddle($_SESSION['current_paddle']),"Old",$_SESSION['paddle'],"New"); echo "
(Cancel) (OK)
"; exit; } } else if(isset($_REQUEST['commit_paddleconf'])) { if(commit_paddle()) { unset($_SESSION['paddle']); unset($_SESSION['paddle_list']); redirect('index.php'); } } if(isset($_REQUEST['revert_paddle'])) { echo '

Replace this paddle?

'; compare_paddle($_SESSION['paddle'],"New",load_paddle($_SESSION['current_paddle']),"Old"); echo "
(Cancel) (OK)
"; exit; } else if(isset($_REQUEST['revert_paddleconf'])) { unset($_SESSION['paddle']); unset($_SESSION['paddle_list']); redirect('index.php'); } if(isset($_REQUEST['addstop'])) { $s1=$_REQUEST['stopid_1']; $s2=$_REQUEST['stopid_2']; $arr=$_REQUEST['arrival']; $rte=$_REQUEST['route']; $trp=$_REQUEST['trip']; $stg=$_REQUEST['stage']; $stp=$_REQUEST['stop']; $okay=true; if( ($s1 < 0) && ($s2 < 0) ) { $okay=false; $errstring .= "You must select a stop to add to this paddle.
"; } if( ($s1 >= 0) && ($s2 >= 0) ) { if($s1 != $s2) { $okay=false; $errstring .= "Selected stops conflict. Please select either by number OR by name.
"; } } if(!preg_match('/[\d]+/',$rte)) { $okay=false; $errstring .= "Route must be numeric.
"; } if(!preg_match('/[\d]+/',$trp)) { $okay=false; $errstring .= "Trip must be numeric.
"; } if(!preg_match('/[\d]+/',$stp)) { $okay=false; $errstring .= "Stop must be numeric.
"; } if(!preg_match('/[\d]+/',$stg)) { $stg=0; } if( strlen($arr) > 0) { $mats=array(); if(!preg_match('/([\d][\d]?):([\d][\d])/',$arr,$mats)) { $okay=false; $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.
"; } else { if( ($mats[1] > 23) || ($mats[2] > 59) ) { $okay=false; $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.
"; } } } if($okay) { if($s1 >= 0) { $stopid=$s1; } else { $stopid=$s2; } $_SESSION['paddle'][]=array( 'id' => $_SESSION['current_paddle'], 'arrival' => $_REQUEST['arrival'], 'route' => $rte, 'stop' => $stp, 'trip' => $trp, 'stage' => $stg, 'stopid' => $stopid); $_SESSION['paddle_dirty']=true; redirect('index.php'); } } if(isset($_REQUEST['edit_done'])) { $s1=$_REQUEST['stopid_1']; $s2=$_REQUEST['stopid_2']; $arr=$_REQUEST['arrival']; $rte=$_REQUEST['route']; $trp=$_REQUEST['trip']; $stg=$_REQUEST['stage']; $stp=$_REQUEST['stop']; $okay=true; if( ($s1 < 0) && ($s2 < 0) ) { $okay=false; $errstring .= "You must select a valid stop.
"; } if( ($s1 >= 0) && ($s2 >= 0) ) { if($s1 != $s2) { $okay=false; $errstring .= "Selected stops conflict. Please select either by number OR by name.
"; } } if(!preg_match('/[\d]+/',$rte)) { $okay=false; $errstring .= "Route must be numeric.
"; } if(!preg_match('/[\d]+/',$trp)) { $okay=false; $errstring .= "Trip must be numeric.
"; } if(!preg_match('/[\d]+/',$stp)) { $okay=false; $errstring .= "Stop must be numeric.
"; } if(!preg_match('/[\d]+/',$stg)) { $stg=0; } if( strlen($arr) > 0) { $mats=array(); if(!preg_match('/([\d][\d]?):([\d][\d])/',$arr,$mats)) { $okay=false; $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.
"; } else { if( ($mats[1] > 23) || ($mats[2] > 59) ) { $okay=false; $errstring .= "Arrival time must be blank, or in the form HH:MM using 24 hour time.
"; } } } if($okay) { if($s1 >= 0) { $stopid=$s1; } else { $stopid=$s2; } $_SESSION['paddle'][$_REQUEST['key']]=array( 'id' => $_SESSION['current_paddle'], 'arrival' => $_REQUEST['arrival'], 'route' => $rte, 'stop' => $stp, 'trip' => $trp, 'stage' => $stg, 'stopid' => $stopid); $_SESSION['paddle_dirty']=true; redirect('index.php'); } } function generate_edit_line($dflt) { global $stopsid; global $stops; global $errstring; if(strlen($errstring) > 0) { echo "
$errstring
"; } $myreq=$_REQUEST; if(!isset($myreq['stopid_1'])) { if (!array_key_exists('arrival',$dflt)) { $dflt['arrival'] = null; } if (!array_key_exists('route',$dflt)) { $dflt['route'] = null; } if (!array_key_exists('trip',$dflt)) { $dflt['trip'] = null; } if (!array_key_exists('stage',$dflt)) { $dflt['stage'] = null; } if (!array_key_exists('stop',$dflt)) { $dflt['stop'] = null; } if (!array_key_exists('stopid',$dflt)) { $dflt['stopid'] = null; } echo $dflt['arrival']; $myreq['arrival']=$dflt['arrival']; $myreq['route']=$dflt['route']; $myreq['trip']=$dflt['trip']; $myreq['stage']=$dflt['stage']; $myreq['stop']=$dflt['stop']; $myreq['stopid_1']=$dflt['stopid']; $myreq['stopid_2']=$dflt['stopid']; } echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; //--------------sub table that lives in the colspanned cell containing stop ID and stop name--- echo '
'; echo ''; echo ''; echo '
By number:
or
By name:
'; generate_stop_name_select($stopsid,'stopid_1',true,$myreq['stopid_1']); echo ''; generate_stop_name_select($stops,'stopid_2',false,$myreq['stopid_2']); echo '
'; //--------------------------------------------------------------------------------------------- if(isset($_REQUEST['edit'])) { echo " (Cancel)
"; } else { echo ''; } } //--------------------------------------------If the paddle is unmodified from its last saved state, allow the user to browse to a different one, //------------------------------------------create a new one, etc... if(isset($_REQUEST['submitadv'])) { $_SESSION['paddle']=array(); $lines=preg_split("/[\r\n]+/",$_REQUEST['advtxt']); foreach($lines as $line) { $mats=array(); if(preg_match("/([\d]+:[\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([\d]+)[\s]+([\d]+)/",$line,$mats)) { //echo "
";
      //print_r($mats);
      //echo "
"; $_SESSION['paddle'][]=array('arrival' => $mats[1], 'route' => $mats[2], 'trip' => $mats[3], 'stage' => $mats[4], 'stop' => $mats[5], 'stopid' => $mats[6]); } } $_SESSION['paddle_dirty']=true; //echo "
";
  //print_r($lines);
  //echo "
"; //exit; } if(!$_SESSION['paddle_dirty']) { if(!isset($_SESSION['paddle_list'])) { $_SESSION['paddle_list']=paddle_list(); } if( isset($_REQUEST['selectpaddle']) && ($_REQUEST['selectpaddle'] != $_SESSION['current_paddle']) ) { $_SESSION['current_paddle']=$_REQUEST['selectpaddle']; unset($_SESSION['paddle']); redirect('index.php'); exit; } else if( isset($_REQUEST['createnewpaddle']) ) { $newpaddle=$_REQUEST['newpaddle']; if(preg_match('/[\d]+/', $newpaddle) && (intval($newpaddle > 0)) && !in_array($newpaddle,$_SESSION['paddle_list']) ) {//the above test insures that the new paddle number is unique, numeric, and non-zero $_SESSION['paddle_list'][]=$newpaddle; $_SESSION['current_paddle']=$newpaddle; unset($_SESSION['paddle']); redirect('index.php'); exit; } else { echo '

New Paddle number must be unique and non-zero.

'; } } echo '
'; echo '
'; echo 'Select an existing paddle: '; echo ''; echo ' or create a new one: '; echo ' '; echo ''; echo '
'; echo '
'; } if(isset($_REQUEST['advanced_edit'])) { $accum="Time Route Trp Stg Stp StopID Stopname\n"; foreach($_SESSION['paddle'] as $key => $record) { $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']); } echo '
'; echo ''; echo ''; echo '
'; } else if($_SESSION['current_paddle'] > 0) { //only draw the current paddle edit UI if we actually have a valid paddle selected //--------------------------------------------------------------BELOW DEALS WITH DISPLAYING THE MAIN PADDLE MANAGEMENT SCREEN------------- echo '
'; echo ''; echo ""; echo ''; $count=0; foreach($_SESSION['paddle'] as $key => $record) { $stopname=$stops[$record['stopid']]['name']; $stopid=$record['stopid']; $arrival=$record['arrival']; $route=$record['route']; $trip=$record['trip']; $stage=$record['stage']; $stop=$record['stop']; $upurl="index.php?up&key=$key"; $dnurl="index.php?dn&key=$key"; $delurl="index.php?del&key=$key"; $editurl="index.php?edit&key=$key"; if( ($count % 2) == 1) { $bkgr="#E0FFE0"; } else { $bkgr="#FFE0E0"; } if(isset($_REQUEST['edit']) && ($_REQUEST['key'] == $key) ) { generate_edit_line($record); } else { if($stopid >= 0) { echo ""; } else { echo ""; } } $count++; } if(!isset($_REQUEST['edit'])) { generate_edit_line(array()); } if($_SESSION['paddle_dirty']) { echo ''; } echo '
Advanced Edit
Paddle Number ${_SESSION['current_paddle']}
Scheduled
Arrival
Route #Trip #Stage #Stop #Unique
Stop ID
Stop
Name
Actions
$arrival$route$trip$stage$stop$stopid$stopname(Move Up) (Move Down) (Delete) (Edit)
This stop has been deleted.
(Move Up) (Move Down) (Delete)
(Commit Changes to Paddle) (Revert to Saved Paddle)
'; } ?>