Skip to content

Instantly share code, notes, and snippets.

@064023 064023/timing4.php
Last active Jan 10, 2019

Embed
What would you like to do?
臺中市公車結合去回程的動態到站時刻表
<?php
mb_parse_str($_SERVER["QUERY_STRING"], $qs);
$rid = array_key_exists('rid', $qs) ? $qs["rid"] : "";
$timeformat = array_key_exists('timeformat', $qs) ? $qs["timeformat"] : "0";
$refresh = array_key_exists('refresh', $qs) ? $qs["refresh"] : "0";
$reverse = array_key_exists('reverse', $qs) ? $qs["reverse"] : "0";
$hidecar = array_key_exists('hidecar', $qs) ? $qs["hidecar"] : "0";
$dark = array_key_exists('dark', $qs) ? $qs["dark"] : "0";
$ivrno = array_key_exists('ivrno', $qs) ? $qs["ivrno"] : "";
$stopID = array_key_exists('stopID', $qs) ? $qs["stopID"] : "";
$stopName = array_key_exists('stopName', $qs) ? $qs["stopName"] : "";
if(file_exists("bus_data/".date("Y")."/".date("m")."/".date("d")."/routes.json")){
$routes = json_decode(file_get_contents("bus_data/".date("Y")."/".date("m")."/".date("d")."/routes.json"));
}else{
$routes = json_decode(file_get_contents("bus_data/".date("Y", strtotime("yesterday"))."/".date("m", strtotime("yesterday"))."/".date("d", strtotime("yesterday"))."/routes.json"));
}
$ro="0";
for ($r = 0; $r<count($routes); $r++) {
if ($routes[$r][0]==$rid) $ro="99999";
}
if ($ro!="99999") $rid = "";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
//if ($rid == "") $refresh=0;
if (($rid != "")&&($refresh=="1" || $refresh=="2" || $refresh=="3")){
print ' <meta http-equiv="refresh" content="'. $refresh*20 . '">'."\n";
}
?>
<style type="text/css">
html {
font-family: "Microsoft JhengHei",MingLiU,Helvetica,Arial,sans-serif;
background-color: <?php echo $dark==1 ? "#000" : "#FFF"; ?>;
}
body {
padding: 0px 15px;
}
form, input, select, select option {
font-family: "Microsoft JhengHei",MingLiU,Helvetica,Arial,sans-serif;
font-size: 18px;
<?php echo $dark==1 ? "background-color: #000;" : ""; ?>
<?php echo $dark==1 ? "color: #0F8;" : ""; ?>
}
input:hover {
<?php echo $dark==1 ? "background-color: #1A1A1A;" : ""; ?>
}
a:link, a:visited, span.link {
text-decoration: underline;
font-weight: normal;
color: #FF4500;
cursor: pointer;
}
a:hover, a:active, span.link:hover {
text-decoration: none;
}
th, td {
padding: 5px 10px 5px 3px;
border-style: none;
border-radius: 10px;
color: <?php echo $dark==1 ? "#0F8" : "#000"; ?>;
}
th {
background-color: <?php echo $dark==1 ? "#000" : "#94FF70"; ?>;
}
td.ts a{
color: <?php echo $dark==1 ? "#0F8" : "#000"; ?>;
font-weight: normal;
}
th.tb, th.tt {
color: <?php echo $dark==1 ? "#0F8" : "#000"; ?>;
background: <?php echo $dark==1 ? "#000" : "#99CCFF"; ?>;
}
th.ts {
background: <?php echo $dark==1 ? "#000" : "#99FF99"; ?>;
}
td.hilight {
background: <?php echo $dark==1 ? "#000" : "#FFFF00"; ?>;
}
.tb, .tt {
padding: 5px 20px 5px 5px;
background: <?php echo $dark==1 ? "#000" : "#F3F9FF"; ?>;
}
.tb {
color: <?php echo $dark==1 ? "#000" : "#F3F9FF"; ?>;
}
.tb.hilight {
color: <?php echo $dark==1 ? "#0F8" : "#000"; ?>;
}
.tt {
background: <?php echo $dark==1 ? "#000" : "#B2FFF0"; ?>;
text-align: center;
font-weight: 900;
}
.tt.skip {
font-weight: normal;
background: <?php echo $dark==1 ? "#000" : "#F3F9FF"; ?>;
}
.ts, .tss {
padding: 5px 30px 5px 5px;
border-style: none;
border-radius: 10px;
background: <?php echo $dark==1 ? "#000" : "#D6FFC2"; ?>;
}
td.tha {
padding: 5px 40px 5px 5px;
border-style: none;
border-radius: 10px;
background: <?php echo $dark==1 ? "#000" : "#FFE5FF"; ?>;
}
td.tha > a {
font-weight: 900;
}
td.ti0 {
font-size: 180%;
font-weight: bold;
background: rgba(230, 230, 230, 0);
}
td.ti1 {
font-size: 120%;
font-weight: bold;
background: rgba(230, 230, 230, 0);
}
.tia {
font-size: 150%;
font-weight: bold;
padding: 2px 15px;
background: <?php echo $dark==1 ? "#000" : "#CCFF99"; ?>;
}
table.routes > tbody > tr:nth-child(even) > td {
background-color: <?php echo $dark==1 ? "#000" : "#ccffff"; ?>
}
table.routes > tbody > tr:nth-child(odd) > td {
background-color: <?php echo $dark==1 ? "#000" : "#D4FFA9"; ?>
}
table.routes > tbody > tr:hover > td {
background-color: <?php echo $dark==1 ? "#000" : "#ffff99"; ?>
}
table.routes, table.times {
padding: 5px;
border-style: solid;
border-color: <?php echo $dark==1 ? "#000" : "#800000"; ?>;
border-radius: 10px;
background-color: <?php echo $dark==1 ? "#000" : "#F9F9F9"; ?>;
}
div#topspace {
min-height: 120px;
height: auto;
}
div#titlefix {
position: fixed;
width: 800px;
background-color: <?php echo $dark==1 ? "rgba(64, 64, 64, 0.8)" : "rgba(230, 230, 230, 0.8)"; ?>;
border-radius: 10px;
padding: 0px 10px;
}
a.dark, a.reverse, a.hidecar, a.timeformat, a.refresh {
border-radius: 5px;
padding: 2px 2px 2px 2px;
color: <?php echo $dark==1 ? "#0F8" : "#000"; ?>;
}
a.dark {
<?php echo $dark==1 ? "border: 5px solid #D1D3D4;" : ""; ?>
}
a.reverse {
<?php echo $dark==1&&$reverse==1 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$reverse==1 ? "background: #FFCC00;" : ""; ?>
}
a.hidecar {
<?php echo $dark==1&&$hidecar==1 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$hidecar==1 ? "background: #FFCC00;" : ""; ?>
}
a.tf0 {
<?php echo $dark==1&&$timeformat==0 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$timeformat==0 ? "background: #FFCC00;" : ""; ?>
}
a.tf1 {
<?php echo $dark==1&&$timeformat==1 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$timeformat==1 ? "background: #FFCC00;" : ""; ?>
}
a.tf2 {
<?php echo $dark==1&&$timeformat==2 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$timeformat==2 ? "background: #FFCC00;" : ""; ?>
}
a.rf0 {
<?php echo $dark==1&&$refresh==0 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$refresh==0 ? "background: #FFCC00;" : ""; ?>
}
a.rf1 {
<?php echo $dark==1&&$refresh==1 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$refresh==1 ? "background: #FFCC00;" : ""; ?>
}
a.rf2 {
<?php echo $dark==1&&$refresh==2 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$refresh==2 ? "background: #FFCC00;" : ""; ?>
}
a.rf3 {
<?php echo $dark==1&&$refresh==3 ? "border: 5px solid #D1D3D4;" : ""; ?>
<?php echo $dark==0&&$refresh==3 ? "background: #FFCC00;" : ""; ?>
}
@media only screen and (max-device-width: 800px) {
input {
font-size: 100%;
}
body {
margin: 0px !important;
padding: 0px !important;
}
div.head_table, div#time_table, div.title_table {
margin: 0px !important;
}
table {
font-size: 300%;
width: 100%;
border: none !important;
padding: 0px !important;
margin: 5px 0px 5px 0px !important;
border-radius: 30px !important;
}
th, td {
padding: 15px !important;
border-radius: 30px !important;
}
div#topspace {
min-height: 320px !important;
}
div#titlefix {
width: 100% !important;
border-radius: 0px !important;
padding: 0px !important;
}
}
</style>
<?php
if ($rid == ""){
print "<title>臺中市公車結合去回程的動態到站時刻表</title>";
}elseif($ivrno == "" || $stopID == "" || $stopName == ""){
$table = file_get_contents("http://117.56.85.168/tcbus2/GetEstimateTime.php?routeIds=$rid");
$table2 = file_get_contents("http://117.56.85.168/tcbus2/GetStopEx.php?useXno=1&json=1&routeIds=$rid");
//$table = preg_replace("/\n/","",$table);
//$table = preg_replace("/<!--.*$/","",$table);
//$table2 = preg_replace("/\n/","",$table2);
//$table2 = preg_replace("/<!--.*$/","",$table2);
foreach ($routes as $r) {
if ($r[0]==$rid){ print "<title>$r[1] - ".date("H:i:s")." - 臺中市公車結合去回程的動態到站時刻表</title>"; }
}
}else{
$table = file_get_contents("http://117.56.85.168/tcbus2/routeEstEx.php?ivrno=$ivrno&stopID=$stopID");
//$table = preg_replace("/\n/","",$table);
//$table = preg_replace("/<!--.*$/","",$table);
print "<title>$stopName - ".date("H:i:s")." - 臺中市公車結合去回程的動態到站時刻表</title>";
}
?>
</head>
<body>
<div style="display: inline-block;">
<?php
if ($rid == ""){
echo '<div class="title_table">';
echo '<table>';
echo '<tr><td class="ti0">';
echo '臺中市公車結合去回程的動態到站時刻表';
echo '</table>';
echo '</div>';
}elseif($ivrno == "" || $stopID == "" || $stopName == ""){
$table = json_decode($table);
$table = $table->$rid;
//if (count($table)<5) exit("$rid : 查無此路線");
//var_dump($table);
$table2 = json_decode($table2,true);
//var_dump($table2);
$table22[1] = $table22[0] = array();
foreach($table2[0] as $t){
array_push($table22[0], $t);
}
foreach($table2[1] as $t){
array_push($table22[1], $t);
}
$table2 = $table22;
//var_dump($table2[1]);
function to_number($ts) {
return substr($ts,0,2)*60 + substr($ts,3,2)*1;
}
function to_string($tn) {
if ($tn/60 >= 24){
return sprintf("%02d:%02d", $tn/60 - 24, $tn%60);
}else{
return sprintf("%02d:%02d", $tn/60, $tn%60);
}
}
$now = date("H")*60+date("i");
$db[2] = $db[1] = array(
'stops' => array(),
'carId' => '',
);
# $db[1]: 去程
# $db[2]: 回程
for($stop = 0; $stop < count($table); $stop++) {
$dir = $table[$stop]->GoBack;
$arriving = '';
if ($table[$stop]->carId != $db[$dir]['carId']) {
$arriving = ' hilight';
$db[$dir]['carId'] = $table[$stop]->carId;
}
$time = "";
if($table[$stop]->Value === "null" && $table[$stop]->comeCarid == ""){
$time = '<font color="gray">離站</font>';
}elseif($table[$stop]->Value === "null"){
if ($timeformat == "1"){
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. (to_number($table[$stop]->comeTime) - date("H")*60 - date("i")) .' 分</font>';
}else{
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. $table[$stop]->comeTime.'</font>';
}
}elseif($table[$stop]->Value == 0){
$time = '<font color="'.($dark==1 ? "#FFCC00" : "red").'">進站中</font>';
}elseif($table[$stop]->Value == -3){
$time = '<font color="gray">末班駛離</font>';
}elseif($table[$stop]->Value < 3){
$time = '<font color="'.($dark==1 ? "#FFCC00" : "red").'">即將到站</font>';
}else{
if ($timeformat == "2"){
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. to_string(date("H")*60 + date("i") + $table[$stop]->Value) .'</font>';
}else{
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. $table[$stop]->Value.' 分</font>';
}
}
array_push($db[$dir]['stops'], array(
'name' => $table[$stop]->StopName,
'cometime' => $table[$stop]->comeTime,
'carId' => $table[$stop]->carId,
'comecar' => $table[$stop]->comeCarid,
'time' => $time,
'arriving' => $arriving,
'ivrno' => $dir==2?$table2[$dir-1][$stop-count($db[1]['stops'])][0]:$table2[$dir-1][$stop][0],
'stopID' => $dir==2?$table2[$dir-1][$stop-count($db[1]['stops'])][5]:$table2[$dir-1][$stop][5],
) );
}
$db[2]['stops'] = array_reverse($db[2]['stops']);
//var_dump($db);
//echo "<br>";
$stops[3] = $stops[2] = $stops[1] = array();
foreach ($db[1]['stops'] as $s){ array_push($stops[1], $s['name']); }
foreach ($db[2]['stops'] as $s){ array_push($stops[2], $s['name']); }
function combine_inator($a1, $a2) {
$bs = 0;
$a = array();
for ($g = 0; $g < count($a1); $g++) {
for ($b = $bs; $b < count($a2); $b++) {
if ($a1[$g] == $a2[$b]){
if ($b != $bs){
for ($n = $bs; $n < $b; $n++) {
array_push($a, $a2[$n]);
}
}
array_push($a, $a1[$g]);
$bs = $b+1;
$b = count($a2);
}
if(($b == count($a2)-1) && ($a1[$g] != $a2[$b])){
array_push($a, $a1[$g]);
}
}
if (($bs == count($a2)) && ($g != count($a1)-1)){
if ($a1[$g] == $a2[count($a2)-1]){
for ($n = $g+1; $n < count($a1); $n++) {
array_push($a, $a1[$n]);
}
}else{
for ($n = $g; $n < count($a1); $n++) {
array_push($a, $a1[$n]);
}
}
$g = count($a1);
}
if (($g == count($a1)-1) && ($bs != count($a2))){
for ($n = $bs; $n < count($a2); $n++) {
array_push($a, $a2[$n]);
}
}
}
return $a;
}
$stops[3] = combine_inator($stops[1], $stops[2]);
//var_dump($stops[3]);
foreach ($routes as $r) {
if ($r[0]==$rid){
echo '<div id="titlefix" class="title_table">';
echo '<table style="width: 100%;">';
echo '<tr><td class="ti0" colspan="3"><span style="color:'.($dark==1 ? "#8FDAFF" : "blue").';">'.$r[1].'</span></td></tr>';
echo '<tr><td class="ti1" style="width: 1%; white-space: nowrap;"><a style="font-weight: 900;" href="'.$_SERVER['PHP_SELF'].'?timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'">← 回首頁</a></td>';
//echo '<td class="ti1" style="width: 1%; white-space: nowrap;text-align: center;">'.date("H").":".date("i").":".date("s").'</td>';
echo '<td style="width: 1%; white-space: nowrap;text-align: center;"><span id="updatetime">0</span> 秒前</td>';
echo '<td class="ti1" style="width: 1%; white-space: nowrap;text-align: right;"><span class="link" style="font-weight: 900;" onclick="location.reload();">更新 ↻</span></td></tr>';
echo '</table>';
echo '</div>';
echo '<div id="topspace"></div>';
echo '<table class="title">';
echo '<tr><td class="tia">'.$r[2].'</td>';
echo '<tr><td>'.$r[3].'</td>';
echo '</table>';
}
}
}else{
$table = json_decode($table);
//if (count($table)<5) exit("$rid : 查無此路線");
//var_dump($table);
function to_number($ts) {
return substr($ts,0,2)*60 + substr($ts,3,2)*1;
}
function to_string($tn) {
if ($tn/60 >= 24){
return sprintf("%02d:%02d", $tn/60 - 24, $tn%60);
}else{
return sprintf("%02d:%02d", $tn/60, $tn%60);
}
}
$now = date("H")*60+date("i");
$db = array();
for($stop = 0; $stop < count($table); $stop++) {
$time = "";
if($table[$stop][6] === "null" && $table[$stop][7] == ""){
$time = '<font color="gray">離站</font>';
}elseif($table[$stop][6] === "null"){
if ($timeformat == "1"){
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. (to_number($table[$stop][7]) - date("H")*60 - date("i")) .' 分</font>';
}else{
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. $table[$stop][7].'</font>';
}
}elseif($table[$stop][6] == 0){
$time = '<font color="'.($dark==1 ? "#FFCC00" : "red").'">進站中</font>';
}elseif($table[$stop][6] == -3){
$time = '<font color="gray">末班駛離</font>';
}elseif($table[$stop][6] < 3){
$time = '<font color="'.($dark==1 ? "#FFCC00" : "red").'">即將到站</font>';
}else{
if ($timeformat == "2"){
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. to_string(date("H")*60 + date("i") + $table[$stop][6]) .'</font>';
}else{
$time = '<font color="'.($dark==1 ? "#8FDAFF" : "blue").'">'. $table[$stop][6].' 分</font>';
}
}
array_push($db, array(
'id' => $table[$stop][0],
'route' => $table[$stop][10],
'to' => $table[$stop][4],
'comecar' => $table[$stop][9],
'time' => $time,
'timesort' => $table[$stop][6]=="0"?(0):($table[$stop][6]=="-3"?(99998):($table[$stop][6]=="null"?($table[$stop][7]==""?(99999):(to_number($table[$stop][7]) - date("H")*60 - date("i"))):($table[$stop][6])))
) );
}
//var_dump($db);
//echo "<br><br>";
$dbsort = array();
for($stop = 0; $stop < count($db); ) {
$s = 0;
for($i = 0; $i < count($db); $i++) {
if($db[$i]['timesort']<$db[$s]['timesort']){$s=$i;}
}
array_push($dbsort, $db[$s]);
unset($db[$s]);
$db = array_values($db);
}
//var_dump($dbsort);
echo '<div id="titlefix" class="title_table">';
echo '<table style="width: 100%;">';
echo '<tr><td class="ti0" colspan="3"><span style="color:'.($dark==1 ? "#8FDAFF" : "blue").';">'.$stopName.'</span></td></tr>';
echo '<tr><td class="ti1" style="width: 1%; white-space: nowrap;">';
foreach ($routes as $r) {
if ($r[0]==$rid){
echo '<a style="font-weight: 900;" href="'.$_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'" title="返回路線 '.$r[1].'">← '.$r[1].'</a></td>';
}
}
//echo '<td class="ti1" style="width: 1%; white-space: nowrap;text-align: center;">'.date("H").":".date("i").":".date("s").'</td>';
echo '<td style="width: 1%; white-space: nowrap;text-align: center;"><span id="updatetime">0</span> 秒前</td>';
echo '<td class="ti1" style="width: 1%; white-space: nowrap;text-align: right;"><span class="link" style="font-weight: 900;" onclick="location.reload();">更新 ↻</span></td></tr>';
echo '</table>';
echo '</div>';
echo '<div id="topspace"></div>';
}
?>
<div class="head_table">
<form method ="GET" action ="<?php echo $_SERVER['PHP_SELF']; ?>">
<table class="head">
<tr><td class="tha">
輸入路線編號: <input type="text" name="rid" size="6" value="<?php echo $rid; ?>" />
<input type="submit" value="查詢路線" />
<tr><td class="tha">
時間顯示格式:
<a class="timeformat tf0" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat=0&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">預設</a>
<a class="timeformat tf1" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat=1&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">幾分鐘</a>
<a class="timeformat tf2" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat=2&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">幾點幾分</a>
<input type="radio" name="timeformat" value="0" <?php if($timeformat!="1" && $timeformat!="2") echo 'checked="checked"';?> readonly hidden />
<input type="radio" name="timeformat" value="1" <?php if ($timeformat=="1") echo 'checked="checked"';?> readonly hidden />
<input type="radio" name="timeformat" value="2" <?php if ($timeformat=="2") echo 'checked="checked"';?> readonly hidden />
<tr><td class="tha">
自動更新間隔:
<a class="refresh rf0" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh=0&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">關閉</a>
<a class="refresh rf1" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh=1&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">20秒</a>
<a class="refresh rf2" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh=2&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">40秒</a>
<a class="refresh rf3" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh=3&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">60秒</a>
<select name="refresh" readonly hidden >
<option value="0" >關閉</option>
<option value="1" <?php if ($refresh==1) echo 'selected="selected"'; ?> >20 秒</option>
<option value="2" <?php if ($refresh==2) echo 'selected="selected"'; ?> >40 秒</option>
<option value="3" <?php if ($refresh==3) echo 'selected="selected"'; ?> >60 秒</option>
</select>
<tr><td class="tha">
<a class="reverse" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.($reverse==0?1:0).'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">倒轉站名排列</a>
<input type="checkbox" name="reverse" value="1" <?php if ($reverse=="1") echo 'checked'; ?> readonly hidden />
<a class="hidecar" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.($hidecar==0?1:0).'&dark='.$dark.'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">隱藏車牌號碼</a>
<input type="checkbox" name="hidecar" value="1" <?php if ($hidecar=="1") echo 'checked'; ?> readonly hidden />
<tr><td class="tha">
<a class="dark" href="<?php echo $_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.($dark==0?1:0).'&ivrno='.$ivrno.'&stopID='.$stopID.'&stopName='.$stopName ?>">黑底亮字模式</a>
<input type="checkbox" name="dark" value="1" <?php if ($dark=="1") echo 'checked'; ?> readonly hidden />
</table>
</form>
</div>
<?php
if ($rid == ""){
echo '<div id="time_table">';
echo '<table class="routes">';
echo '<tr><th>路線編號</th><th>路線名稱</th><th>路線描述</th><th>路線業者</th></tr>';
foreach ($routes as $r) {
print '<tr><td><a href="'.$_SERVER['PHP_SELF'].'?rid='.$r[0].'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'">'.$r[0]."</a><td>".$r[1]."<td>".$r[2]."<td>".$r[3]."\n";
}
echo "</table>";
echo "</div>";
}elseif($ivrno == "" || $stopID == "" || $stopName == ""){
echo '<div id="time_table">';
echo '<table class="times">';
echo '<tr>'.($hidecar==0?('<th class="tb">↓ 車牌'):'').'<th class="tt">↓ 時間<th class="ts">站名<th class="tt">時間 ↑'.($hidecar==0?('<th class="tb">車牌 ↑'):'');
$gs = $bs = 0;
$t = array();
//$gnostop = 0;
$gbiv = "";
$gbst = "";
for ($n = 0; $n < count($stops[3]); $n++) {
if ($gs < count($stops[1])){
if ($stops[3][$n]==$stops[1][$gs]){
$t[$n][1] = $db[1]['stops'][$gs]['arriving'];
if ($db[1]['stops'][$gs]['carId']=="" && $db[1]['stops'][$gs]['time']!='<font color="gray">末班駛離</font>'){
$t[$n][2] = $db[1]['stops'][$gs]['comecar'];
}else{
$t[$n][2] = $db[1]['stops'][$gs]['carId'];
}
$t[$n][3] = $db[1]['stops'][$gs]['time'];
$gbiv = $db[1]['stops'][$gs]['ivrno'];
$gbst = $db[1]['stops'][$gs]['stopID'];
$gs++;
//$gnostop = 0;
}else{
//$gnostop = 1;
$t[$n][1] = "";
$t[$n][2] = (($reverse == 1) ? "↑" : "↓");
$t[$n][3] = (($reverse == 1) ? "↑" : "↓");
}
}else{
//$gnostop = 1;
$t[$n][1] = "";
$t[$n][2] = (($reverse == 1) ? "↑" : "↓");
$t[$n][3] = (($reverse == 1) ? "↑" : "↓");
}
if ($bs < count($stops[2])){
if ($stops[3][$n]==$stops[2][$bs]){
$t[$n][4] = $db[2]['stops'][$bs]['arriving'];
$t[$n][5] = $db[2]['stops'][$bs]['time'];
if ($db[2]['stops'][$bs]['carId']=="" && $db[2]['stops'][$bs]['time']!='<font color="gray">末班駛離</font>'){
$t[$n][6] = $db[2]['stops'][$bs]['comecar'];
}else{
$t[$n][6] = $db[2]['stops'][$bs]['carId'];
}
$gbiv = $db[2]['stops'][$bs]['ivrno'];
$gbst = $db[2]['stops'][$bs]['stopID'];
$bs++;
}else{
$t[$n][4] = "";
$t[$n][5] = (($reverse == 1) ? "↓" : "↑");
$t[$n][6] = (($reverse == 1) ? "↓" : "↑");
}
}else{
$t[$n][4] = "";
$t[$n][5] = (($reverse == 1) ? "↓" : "↑");
$t[$n][6] = (($reverse == 1) ? "↓" : "↑");
}
//$t[$n][0] = '<a href="'.$_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&dark='.$dark.'&ivrno='.(($gnostop==1)?$db[2]['stops'][$bs-1]['ivrno']:$db[1]['stops'][$gs-1]['ivrno']).'&stopID='.(($gnostop==1)?$db[2]['stops'][$bs-1]['stopID']:$db[1]['stops'][$gs-1]['stopID']).'&stopName='.$stops[3][$n].'">'.$stops[3][$n].'</a>';
$t[$n][0] = '<a href="'.$_SERVER['PHP_SELF'].'?rid='.$rid.'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'&ivrno='.$gbiv.'&stopID='.$gbst.'&stopName='.$stops[3][$n].'">'.$stops[3][$n].'</a>';
//(($stops[3][$n]==$stops[1][$gs])?$db[2]['stops'][$bs]['stopID']:$db[1]['stops'][$gs]['stopID'])
}
for($r = 0; $r < count($t); $r++) {
if($reverse == 1){
print '<tr>'.($hidecar==0?('<td class="tb'.$t[count($t)-$r-1][4].'">'.$t[count($t)-$r-1][6]):'');
print '<td class="tt'.(($t[count($t)-$r-1][5]=="↓") ? " skip" : "").$t[count($t)-$r-1][4].'">'.$t[count($t)-$r-1][5];
print '<td class="ts">'.$t[count($t)-$r-1][0];
print '<td class="tt'.(($t[count($t)-$r-1][3]=="↑") ? " skip" : "").$t[count($t)-$r-1][1].'">'.$t[count($t)-$r-1][3];
print ($hidecar==0?('<td class="tb'.$t[count($t)-$r-1][1].'">'.$t[count($t)-$r-1][2]):'')."\n";
}else{
print '<tr>'.($hidecar==0?('<td class="tb'.$t[$r][1].'">'.$t[$r][2]):'');
print '<td class="tt'.(($t[$r][3]=="↓") ? " skip" : "").$t[$r][1].'">'.$t[$r][3];
print '<td class="ts">'.$t[$r][0];
print '<td class="tt'.(($t[$r][5]=="↑") ? " skip" : "").$t[$r][4].'">'.$t[$r][5];
print ($hidecar==0?('<td class="tb'.$t[$r][4].'">'.$t[$r][6]):'')."\n";
}
}
echo "</table>";
echo "</div>";
}else{
echo '<div id="time_table">';
echo '<table class="times">';
echo '<tr><th class="tt">時間</th><th class="ts">路線</th><th class="ts">方向</th>'.($hidecar==0?('<th class="ts">車牌</th>'):'').'</tr>';
for($r = 0; $r < count($dbsort); $r++) {
print '<tr><td class="tt">'.$dbsort[$r]['time'].'<td class="tss">'.'<a href="'.$_SERVER['PHP_SELF'].'?rid='.$dbsort[$r]['id'].'&timeformat='.$timeformat.'&refresh='.$refresh.'&reverse='.$reverse.'&hidecar='.$hidecar.'&dark='.$dark.'">'.$dbsort[$r]['route'].'</a>'.'<td class="ts">往 '.$dbsort[$r]['to'].($hidecar==0?('<td class="ts">'.$dbsort[$r]['comecar']):'');
}
echo "</table>";
echo "</div>";
}
if($rid!=""){
echo '
<script>
var time0 = new Date();
setInterval(function(){
var time1 = new Date();
var time = Math.round((time1-time0)/1000);
document.getElementById("updatetime").innerHTML = time;
}, 500);
</script>';
}
?>
<div class="title_table">
<table>
<tr><td>
作者: 064023; 詳見 <a href=
"http://doofenshmirtzevilincorporated.blogspot.tw/2015/07/tcbus-timing4.html" target="_blank">
臺中市公車結合去回程的動態到站時刻表<br />
</table>
</div>
</div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.