=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]; } echo $jikoku2.","; //0101という形式の日付データ $today = date("md"); //各ルートの番号 $route_id = array(5,6,9,18); foreach ($route_id as $r_id){ $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 = 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($r_id==9){ //現在のバス停通過番号 $bus_flag = rtrim(file_get_contents("./maintenance/data/location/bus_flag".$r_id2.$r_id.".txt", FILE_IGNORE_NEW_LINES)); } if($status==2 && $now_bin==4 && $r_id==9){ $now_pass=28; }else if($status==2 && $now_pass!=0){ $now_pass=0; } if($now_pass==0){ $check_bus=1; }else{ $check_bus=0; } if($_GET['debug']==1){ /*---------送信されたデータを出力-------*/ print('
'.' 路線番号:'.$r_id.'
'); print('
'.' 現在の運行状況:'.$status.'
'); print('
'.' 現在の便番号:'.$now_bin.'
'); if($r_id==9){ print('
'.' 現在の方向:'.$bus_flag.'
'); } print('
'.' 現在のバス停通過番号:'.$now_pass.'

'); /*------------------------------------------*/ } /*------------走行ルートの抽出------------*/ $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 where r_id=".$r_id." and busstop_id = ".$now_pass." union select busstop_id,bus_name from nbus_master inner join nbus_view using(r_id,busstop_id) where r_id=".$r_id." and view_bin=".$now_bin." and busstop_id > ".$now_pass." and view_fg=1 group by bus_name order by busstop_id asc"; if($_GET['debug']==1){ echo $sql."
"; } $res = mysql_query($sql); for($i = $check_bus;$row = mysql_fetch_array($res);$i++){ $stop_id[$r_id][$i]=intval($row['busstop_id']); $stop_name[$r_id][$i]=str_replace($cr,"",$row['bus_name']); if($_GET['debug']==2){ echo $i."
"; echo $stop_id[$r_id][$i]."
"; echo $stop_name[$r_id][$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 log_time from nbus_log where r_id=".$r_id." and busstop_id != 0 and busstop_id = ".$now_pass." and log_day=".$today." limit 1"; $res = mysql_query($sql); $log_data[$r_id][0] = @mysql_fetch_array($res);//ログデータ $delay_fg=1; if($log_data[$r_id][0]['log_time']!=null){ if($log_data[$r_id][0]['log_time'][0]!=0){ $log_time[$r_id]=$log_data[$r_id][0]['log_time'][0].$log_data[$r_id][0]['log_time'][1].":".$log_data[$r_id][0]['log_time'][2].$log_data[$r_id][0]['log_time'][3]; }else{ $log_time[$r_id]=$log_data[$r_id][0]['log_time'][1].":".$log_data[$r_id][0]['log_time'][2].$log_data[$r_id][0]['log_time'][3]; } if($_GET['debug']==1){ echo "通過時刻:".$log_time[$r_id]."
"; } }else{ $delay_fg=0; } 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"); if($now_pass>0){ $sql="select time from ntime_tbl where r_id=".$r_id." and busstop_id in (".$stop_id[$r_id][0].",".$stop_id[$r_id][1].") and busservice_id=".$now_bin." order by busstop_id asc"; }else{ $sql="select time from ntime_tbl where r_id=".$r_id." and busstop_id in (".$stop_id[$r_id][1].") and busservice_id=".$now_bin." order by busstop_id asc"; } if($_GET['debug']==1){ echo $sql."
"; } $res = mysql_query($sql); for($i = 0;$row = mysql_fetch_array($res);$i++){ $stop_time[$r_id][$i]=$row['time'];//0:現在の通過バス停,1:次のバス停 if($r_id==9 && $now_bin==4){ $data_array=explode(",", $stop_time[$r_id][$i]); $stop_time[$r_id][$i]=$data_array[$bus_flag]; } if($_GET['debug']==1){ echo "時刻表の時刻:".$stop_time[$r_id][$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); /*------------------------------------------*/ if($log_time[$r_id]==null){ $log_time[$r_id]=$stop_time[$r_id][0]; } if($delay_fg==1 && $status==1){ if(intval(str_replace(":","",$log_time[$r_id]))>intval(str_replace(":","",$stop_time[$r_id][0]))){ if($_GET['debug']==1){ echo "遅延
"; } $delay_time[$r_id]=intval(MinusVtime($log_time[$r_id],$stop_time[$r_id][0]));//遅延時間 }else{ if($_GET['debug']==1){ echo "早発
"; } $delay_time[$r_id]=(intval(MinusVtime($stop_time[$r_id][0],$log_time[$r_id]))*-1);//早発時間 } $delay_time[$r_id]=$delay_time[$r_id]-(40*(($delay_time[$r_id]-($delay_time[$r_id]%100))/100)); }else{ $delay_time[$r_id]=0; } //出力-> バス停名,通過時刻,到着時刻,遅延時間 //echo "路線番号:".$r_id.",運行状態:".$status.",通過バス停:".$stop_name[$r_id][0].",次のバス停:".$stop_name[$r_id][1].",通過時刻:".$log_time[$r_id].",到着予定時刻:".Timeadd($stop_time[$r_id][1],$delay_time[$r_id]).",遅延時間:".$delay_time[$r_id]; //echo $r_id.",".$status.",".$stop_name[$r_id][0].",".$stop_name[$r_id][1].",".$log_time[$r_id].",".Timeadd($stop_time[$r_id][1],$delay_time[$r_id]).",".$delay_time[$r_id]; if($stop_time[$r_id][1]!=null){ echo $now_pass.",".$status.",".$stop_name[$r_id][0].",".$stop_name[$r_id][1].",".Timeadd($stop_time[$r_id][1],$delay_time[$r_id]).",".$delay_time[$r_id]; }else{ echo $now_pass.",".$status.",".$stop_name[$r_id][0].",".$stop_name[$r_id][1].",".Timeadd($stop_time[$r_id][0],$delay_time[$r_id]).",".$delay_time[$r_id]; } if($r_id!=18){ echo ","; //echo "
"; } } unset($stop_time,$r_id,$now_pass,$now_bin,$stop_id,$stop_name,$today,$status,$log_data,$check_bus,$route_data,$route_id); ?>