| A | B | C | ... |
| Route# | Stop 1 Name | Stop 2 Name | ... |
| ... |
';
echo 'Paddle spreadsheet should have the following format:';
echo '| A | B | C | D | E | F | G | ... |
| Paddle# | Order# | Block# | Route # | Trip # | Stop 1 Time | Stop 2 Time | ... |
| ... |
';
echo 'It should be noted that Order# and Block# are ignored, it is assumed that the spreadsheet is sorted.
';
echo '
';
exit;
}
$routes=array();
$stops=array();
$res=mysqli_query($sql, "SELECT name,id FROM stops");
while($row=mysqli_fetch_assoc($res))
{
$stops[$row['name']]=$row['id'];
}
//print_r($_FILES);
$f=fopen($_FILES['routesfile']['tmp_name'],"rb");
while($row=fgetcsv($f,1024))
{
$num=intval($row[0]);
if($num > 0)
{
$idx=0;
$tmp=array();
while(strlen($row[$idx + 1]) > 0)
{
$tmp[$idx]=trim($row[$idx + 1]);
$idx++;
}
$routes[$num]=$tmp;
}
}
fclose($f);
// echo "";
// print_r($routes);
// echo "
";
$paddles=array();
$f=fopen($_FILES['paddlesfile']['tmp_name'],"rb");
while($row=fgetcsv($f,1024))
{
$pnum=intval($row[0]);
if($pnum > 0)
{
$rt=intval($row[3]);
$tp=intval($row[4]);
if(isset($routes[$rt]))
{
$n=count($routes[$rt]);
for($i=0;$i < $n; $i++)
{
$time=$row[$i + 5];
if(isset($stops[$routes[$rt][$i]]))
{
$stpid=$stops[$routes[$rt][$i]];
}
else
{
$stpid=0;
$err=$routes[$rt][$i];
$x=$i+1;
echo "Ignoring Unknown stop \"$err\" (Work Run $pnum Route $rt Trip $tp Stop $x)
";
continue;
}
if(strlen(trim($time)) > 0)
{
$paddles[$pnum][]=array( 'id' => $pnum, 'arrival' => $time, 'route' => $rt, 'trip' => $tp, 'stop' => ($i + 1), 'stage' => ($i + 1), 'stopid' => $stpid);
}
}
}
}
}
fclose($f);
//echo '';
//print_r($paddles);
//echo '
';
foreach($paddles as $pnum => $paddle)
{
mysqli_query($sql,"DELETE FROM paddles WHERE id='$pnum'");
foreach($paddle as $slot => $record)
{
$arr=$record['arrival'];
$rt=$record['route'];
$tp=$record['trip'];
$stp=$record['stop'];
$stg=$record['stage'];
$stpid=$record['stopid'];
mysqli_query($sql,"INSERT INTO paddles SET id='$pnum', slot='$slot', arrival='$arr', route='$rt', trip='$tp', stage='$stg', stop='$stp', stopid='$stpid'");
}
}
echo "Done!
";
echo 'Return to menu';
?>