=60){ $a+=40; } if($a==2400){ $a=0; } } if(floor($a/1000)!=0){ $a = (floor($a/1000).floor(floor($a-floor($a/1000)*1000)/100).':'.floor(($a-floor($a/100)*100)/10).floor(($a-floor($a/100)*100)%10)); }else{ $a = (floor(floor($a-floor($a/1000)*1000)/100).':'.floor(($a-floor($a/100)*100)/10).floor(($a-floor($a/100)*100)%10)); } return $a; } //0000~2359という形式の時刻データ $jikoku = date("Hi"); //0:00~23:59という形式の時刻データを作る $jikoku2 = date("H:i"); if($jikoku2[0]==0){ $jikoku2=$jikoku2[1].':'.$jikoku2[3].$jikoku2[4]; } //0101という形式の日付データ $today = date("md"); $r_id=5; $r_id2=""; if($r_id<10){ $r_id2=0; } //各ルートの運行状態(0:運行終了,1:運行中,2:運行準備,3:点検など,4:運休) $status = rtrim(file_get_contents("../maintenance/data/location/status".$r_id2.$r_id.".txt", FILE_IGNORE_NEW_LINES)); //現在の便番号 $now_bin = rtrim(file_get_contents("../maintenance/data/location/bin".$r_id2.$r_id.".txt", FILE_IGNORE_NEW_LINES)); //現在のバス停通過番号 $now_pass = rtrim(file_get_contents("../maintenance/data/location/pass_bus".$r_id2.$r_id.".txt", FILE_IGNORE_NEW_LINES)); if($status==2 && $now_pass!=0){ $now_pass=0; } $bus_time = array(0,724,800,1050,1230,1425,1810); if($_GET['debug']==1){ /*---------送信されたデータを出力-------*/ print('
'.' 現在の運行状況:'.$status.'
'); print('
'.' 現在の便番号:'.$now_bin.'
'); print('
'.' 現在のバス停通過番号:'.$now_pass.'

'); /*------------------------------------------*/ } /*------------路線データの抽出------------*/ $con=@mysql_connect("localhost","event","L523GpA"); if(!$con){ unset($con,$data,$r_id,$lat,$lng,$time,$day); die("DB接続エラー"); } $select_db=@mysql_select_db("eventdb"); if(!$select_db){ unset($con,$select_db,$r_id,$lat,$lng,$time,$day); die ("DB選択エラー"); } @mysql_query("set names utf8"); $sql="select r_name,r_color,suspension_day from nroute_name_tbl where r_id=".$r_id; $res = mysql_query($sql); $route_data[0] = @mysql_fetch_array($res);//路線のデータ mysql_free_result($res); $close=@mysql_close($con); if(!$close){ unset($con,$select_db,$res,$sql,$row,$close,$r_id,$route_data); die("DB切断エラー"); } unset($con,$select_db,$res,$sql,$row,$close); if($_GET['debug']==1){ echo "路線データ
"; echo "路線名:".$route_data[0]['r_name']."
"; echo "ルート色:".$route_data[0]['r_color']."
"; echo "運休日等:".$route_data[0]['suspension_day']."
"; } /*------------------------------------------*/ /*------------通過した走行ルートの抽出------------*/ $cr = array(" 着"," 発"); $con=@mysql_connect("localhost","event","L523GpA"); if(!$con){ unset($con,$data,$r_id,$lat,$lng,$time,$day); die("DB接続エラー"); } $select_db=@mysql_select_db("eventdb"); if(!$select_db){ unset($con,$select_db,$r_id,$lat,$lng,$time,$day); die ("DB選択エラー"); } @mysql_query("set names utf8"); $sql="select busstop_id,bus_name from nbus_master inner join nbus_view using(r_id,busstop_id) where r_id=".$r_id." and busstop_id <=".$now_pass." and view_bin=".$now_bin." and view_fg=1 order by busstop_id desc limit 3"; $res = mysql_query($sql); $p_cnt=0; for($i = 0;$row = mysql_fetch_array($res);$i++){ $p_stop_id[$i]=intval($row['busstop_id']); $p_stop_name[$i]=str_replace($cr,"",$row['bus_name']); if($_GET['debug']==2){ echo $p_stop_id[$i]."
"; echo $p_stop_name[$i]."
"; } } if($i>0){ $p_cnt=($i-1); } mysql_free_result($res); $close=@mysql_close($con); if(!$close){ unset($con,$select_db,$res,$sql,$row,$close,$r_id,$lat,$lng,$time,$day); die("DB切断エラー"); } unset($con,$select_db,$res,$sql,$row,$close); /*------------------------------------------*/ /*------------次の走行ルートの抽出------------*/ $con=@mysql_connect("localhost","event","L523GpA"); if(!$con){ unset($con,$data,$r_id,$lat,$lng,$time,$day); die("DB接続エラー"); } $select_db=@mysql_select_db("eventdb"); if(!$select_db){ unset($con,$select_db,$r_id,$lat,$lng,$time,$day); die ("DB選択エラー"); } @mysql_query("set names utf8"); $sql="select busstop_id,bus_name from nbus_master inner join nbus_view using(r_id,busstop_id) where r_id=".$r_id." and busstop_id >".$now_pass." and view_bin=".$now_bin." and view_fg=1 order by busstop_id asc limit 4"; $res = mysql_query($sql); for($i = 0;$row = mysql_fetch_array($res);$i++){ $n_stop_id[$i]=intval($row['busstop_id']); $n_stop_name[$i]=str_replace($cr,"",$row['bus_name']); if($_GET['debug']==2){ echo $n_stop_id[$i]."
"; echo $n_stop_name[$i]."
"; } } mysql_free_result($res); $close=@mysql_close($con); if(!$close){ unset($con,$select_db,$res,$sql,$row,$close,$r_id,$lat,$lng,$time,$day); die("DB切断エラー"); } unset($con,$select_db,$res,$sql,$row,$close); /*------------------------------------------*/ /*------------通過ログのチェック------------*/ $con=@mysql_connect("localhost","event","L523GpA"); if(!$con){ unset($con,$data,$r_id,$lat,$lng,$time,$day); die("DB接続エラー"); } $select_db=@mysql_select_db("eventdb"); if(!$select_db){ unset($con,$select_db,$r_id,$lat,$lng,$time,$day); die ("DB選択エラー"); } @mysql_query("set names utf8"); $sql="select busstop_id,log_time from nbus_log inner join nbus_view using(r_id,busstop_id) where r_id=".$r_id." and busstop_id !=0 and busstop_id <=".$now_pass." and view_bin=1 and log_day=".$today." order by busstop_id desc limit 3"; $res = mysql_query($sql); for($i=0;$log_data=mysql_fetch_array($res);$i++){ if($log_data['log_time']!=null){ if($log_data['log_time'][0]!=0){ $log_time[$i]=$log_data['log_time'][0].$log_data['log_time'][1].":".$log_data['log_time'][2].$log_data['log_time'][3]; }else{ $log_time[$i]=$log_data['log_time'][1].":".$log_data['log_time'][2].$log_data['log_time'][3]; } if($_GET['debug']==2){ echo $log_data['busstop_id'].":".$log_time[$i]."
"; } $log_id[$i]=$log_data['busstop_id']; } } mysql_free_result($res); $close=@mysql_close($con); if(!$close){ unset($con,$select_db,$res,$sql,$row,$close,$r_id,$lat,$lng,$time,$day); die("DB切断エラー"); } unset($con,$select_db,$res,$sql,$row,$close); /*------------------------------------------*/ /*------------時刻データの取出し------------*/ $con=@mysql_connect("localhost","event","L523GpA"); if(!$con){ unset($con,$data,$r_id,$lat,$lng,$time,$day); die("DB接続エラー"); } $select_db=@mysql_select_db("eventdb"); if(!$select_db){ unset($con,$select_db,$r_id,$lat,$lng,$time,$day); die ("DB選択エラー"); } @mysql_query("set names utf8"); for($i = 0;$p_stop_id[$i]!=null;$i++){ $sql="select time from ntime_tbl where r_id=".$r_id." and busservice_id=".$now_bin." and busstop_id=".$p_stop_id[$i]." order by busstop_id asc"; $res = mysql_query($sql); $time_data[0] = @mysql_fetch_array($res);//ログデータ $stop_time[$i]=$time_data[0]['time'];//0:現在の通過バス停,1:次のバス停 if($_GET['debug']==2){ echo "p:".$p_stop_id[$i].":".$stop_time[$i]."
"; } } for($j = 0;$n_stop_id[$j]!=null;$j++){ $sql="select time from ntime_tbl where r_id=".$r_id." and busservice_id=".$now_bin." and busstop_id=".$n_stop_id[$j]." order by busstop_id asc"; $res = mysql_query($sql); $time_data[0] = @mysql_fetch_array($res);//ログデータ $stop_time[($j+$i)]=$time_data[0]['time'];//0:現在の通過バス停,1:次のバス停 if($_GET['debug']==2){ echo "n:".$n_stop_id[$j].":".$stop_time[($j+$i)]."
"; } } mysql_free_result($res); $close=@mysql_close($con); if(!$close){ unset($con,$select_db,$res,$sql,$row,$close,$r_id,$lat,$lng,$time,$day); die("DB切断エラー"); } unset($con,$select_db,$res,$sql,$row,$close); /*------------------------------------------*/ for($i=0;$stop_time[$i]!=null;$i++){ if($i<3){ if($log_time[$i]==null){ $log_time[$i]=$stop_time[$i]; }else if($log_id[$i]!=$p_stop_id[$i]){ $log_time[$i]=$stop_time[$i]; }else if((intval(str_replace(":","",$log_time[$i]))<$bus_time[$now_bin]) || (intval(str_replace(":","",$log_time[$i]))>$bus_time[($now_bin+1)])){ $log_time[$i]=$stop_time[$i]; } } if($i==0){ if(intval(str_replace(":","",$log_time[$i]))>intval(str_replace(":","",$stop_time[$i]))){ if($_GET['debug']==1){ echo "遅延
"; } $delay_time=intval(MinusVtime($log_time[$i],$stop_time[$i]));//遅延時間 }else{ if($_GET['debug']==1){ echo "早発
"; } $delay_time=(intval(MinusVtime($stop_time[$i],$log_time[$i]))*-1);//早発時間 } $delay_time=$delay_time-(40*(($delay_time-($delay_time%100))/100)); } } ?>
".$route_data[0]['r_name'].""); print("

"); if($status==1){ print("●バスの運行情報 (".$jikoku2."現在)

"); if($delay_time>0){ print("《約".$delay_time."分の遅延が発生》"); }else{ print("《定刻運行中》"); } print("
"); print("
"); for($i = 0;$p_stop_id[$i]!=null;$i++){ print(""); if(($p_cnt-$i)==0){ print($p_stop_name[($p_cnt-$i)]." (".$log_time[($p_cnt-$i)]."到着)
"); }else{ print($p_stop_name[($p_cnt-$i)]."
"); } } for($j = 0;$n_stop_id[$j]!=null;$j++){ if($j==0){ print(""); }else{ print(""); } print($n_stop_name[$j]." (".Timeadd($stop_time[($j+$i)],$delay_time)."到着予定)
"); } print("
"); }else if($status==2){ print("《運行準備中》"); print("
"); for($j = 0;$n_stop_id[$j]!=null;$j++){ if($j==0){ print(""); }else{ print(""); } print($n_stop_name[$j]." (".$stop_time[$j]."到着予定)
"); } }else{ print("
本日の運行は終了しました。
"); } ?>
※★マークが現在向かっているバス停です。
遅延情報は車載器との通信状態により、 実際の運行状況と異なる場合があります。
あくまで目安としてご利用ください。

トップページへ[0]
なんバス
ロケーションシステム