You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php require_once('../ajax_asm.php'); require_once('../php/argus/server.php'); ob_start(); $UID = intval( $CUser->Data['id'] ); $ACCESS = intval( $CUser->Data['access'] ); if( $UID > 1 ){ $Data = array(); $Data['VLVL'] = intval( $_POST['VLVL'] ); $Data['LTS'] = intval( $_POST['LTS'] ); $LID = intval( $_POST['LID'] ); if( $Data['LTS'] == 0 ) $Data['LTS'] = floor(microtime(true) * 1000);//time();
$ALRM_STATIONS = array(); //Data for Side Panel
$QS = "SELECT * FROM `sessions` WHERE `final`='N' ORDER BY (`ts`*1000)+`ts_ms` DESC LIMIT 32"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $Data['actual'] = array(); foreach( $RR as $R ){ $CA = array(); $CA['id']=intval($R['id'] ); $CA['track']=intval( $R['track_id'] ); $QS = "SELECT `st`.`id` AS `s_id`, `st`.`name` AS `s_name`, `pt`.`name` AS `p_name`, `tr`.`short` FROM `metro_tracks` `tr` LEFT JOIN `metro_platforms` `pt` ON (`tr`.`platform_id`=`pt`.`id`) LEFT JOIN `metro_stations` `st` ON (`pt`.`station_id`=`st`.`id`) WHERE `tr`.`id`={$CA['track']}"; $GG = $DATABASE->Query( $QS ); $CA['station_name']=$GG[0]['s_name']; $CA['platform_name']=$GG[0]['p_name']; $CA['track_tag']=$GG[0]['short']; $CA['status']=0; $Data['actual'][] = $CA; $ALRM_STATIONS[$GG[0]['s_id']] = 4; }; }; $QS = "SELECT * FROM `sessions` WHERE `final`='Y' AND `status`=0 ORDER BY (`ts`*1000)+`ts_ms` DESC LIMIT 32"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $Data['expired'] = array(); foreach( $RR as $R ){ $CA = array(); $CA['id']=intval($R['id'] ); $CA['track']=intval( $R['track_id'] ); $QS = "SELECT `st`.`id` AS `s_id`, `st`.`name` AS `s_name`, `pt`.`name` AS `p_name`, `tr`.`short` FROM `metro_tracks` `tr` LEFT JOIN `metro_platforms` `pt` ON (`tr`.`platform_id`=`pt`.`id`) LEFT JOIN `metro_stations` `st` ON (`pt`.`station_id`=`st`.`id`) WHERE `tr`.`id`={$CA['track']}"; $GG = $DATABASE->Query( $QS ); $CA['station_name']=$GG[0]['s_name']; $CA['platform_name']=$GG[0]['p_name']; $CA['track_tag']=$GG[0]['short']; $CA['status']=1; $Data['expired'][] = $CA; if( !isset($ALRM_STATIONS[$GG[0]['s_id']] ) ) $ALRM_STATIONS[$GG[0]['s_id']] = 3; }; }; switch( $Data['VLVL'] ){ case 0:{ // Map Level Monitoring
// check the station/modules online statuses, check just side sessions
$QS = "SELECT id FROM `metro_stations`"; $RR = $DATABASE->Query( $QS ); foreach( $RR as $CR ){ //If station not Alarmed
if( !isset($ALRM_STATIONS[$CR['id']] ) ){ $ALRM_STATIONS[$CR['id']] = 1; // default Station is ok
$QS = "SELECT `mt`.`id` as `id` FROM `metro_tracks` `mt` LEFT JOIN `metro_platforms` `mp` ON ( `mt`.`platform_id` = `mp`.`id` ) WHERE `mp`.`station_id` = {$CR['id']}"; $ZZ = $DATABASE->Query( $QS ); if( count( $ZZ ) ){ foreach( $ZZ as $CZ ){ $QS = "SELECT `id` FROM `metro_modules` WHERE `track_id`={$CZ['id']}"; $JJ = $DATABASE->Query( $QS ); if( count( $JJ ) ){ foreach( $JJ as $J ){ //check online status of module
//$QS = "SELECT
}; } else $ALRM_STATIONS[$CR['id']] = 2; // Has No Modules at all
}; } else { $ALRM_STATIONS[$CR['id']] = 0; // No Infrostructure
}; }; }; $SI = array(); $SS = array(); foreach( $ALRM_STATIONS as $K=>$V ){ $SI[] = $K; $SS[] = $V; }; $Data['station_ids'] = $SI; $Data['station_status'] = $SS; break; }; case 2:{ //Platform View
$PID = intval( $_POST['PID'] ); if( $PID ){ $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $Modules = array(); foreach( $RR as $CT ){ $CM = intval( $CT['near_module_id'] ); $LD = array(); if( $CM ){ $LD['id']=$CM; if( getOnlineStatus( $CM ) ){ $LD['status'] = 2; $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}"; $RZ = $DATABASE->Query( $QS ); $MM = $RZ[0]; //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}"; $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0"; $RZ = $DATABASE->Query( $QS ); if( count( $RZ ) ){ $LD['status'] = 3; $LD['session'] = intval( $RZ[0]['id'] ); }; } else { $LD['status'] = 1; $LD['img'] = '/style/assets/no-signal_h.png'; }; } else { $LD['status'] = 0; }; $Modules[] = $LD; $CM = $CT['far_module_id']; $LD = array(); if( $CM ){ $LD['id']=$CM; if( getOnlineStatus( $CM ) ){ $LD['status'] = 2; $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}"; $RZ = $DATABASE->Query( $QS ); $MM = $RZ[0]; //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}"; $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0"; $RZ = $DATABASE->Query( $QS ); if( count( $RZ ) ){ $LD['status'] = 3; $LD['session'] = intval( $RZ[0]['id'] ); }; } else { $LD['status'] = 1; $LD['img'] = '/style/assets/no-signal_h.png'; }; } else { $LD['status'] = 0; }; $Modules[] = $LD; }; $Data['modules'] = $Modules; }; }; break; }; case 3:{ // Track View
$TID = intval( $_POST['TID'] ); if( $TID ){ $QS = "SELECT * FROM `metro_tracks` WHERE `id`={$TID}"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $CT = $RR[0]; $Modules = array(); $CM = intval( $CT['near_module_id'] ); $LD = array(); if( $CM ){ $LD['id']=$CM; if( getOnlineStatus( $CM ) ){ $LD['status'] = 2; $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}"; $RZ = $DATABASE->Query( $QS ); $MM = $RZ[0]; $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}"; //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
$QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0"; $RZ = $DATABASE->Query( $QS ); if( count( $RZ ) ){ $LD['status'] = 3; $LD['session'] = intval( $RZ[0]['id'] ); }; } else { $LD['status'] = 1; $LD['img'] = '/style/assets/no-signal_h.png'; }; } else { $LD['status'] = 0; }; $Modules[] = $LD; $CM = $CT['far_module_id']; $LD = array(); if( $CM ){ $LD['id']=$CM; if( getOnlineStatus( $CM ) ){ $LD['status'] = 2; $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}"; $RZ = $DATABASE->Query( $QS ); $MM = $RZ[0]; $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}"; //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
$QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0"; $RZ = $DATABASE->Query( $QS ); if( count( $RZ ) ){ $LD['status'] = 3; $LD['session'] = intval( $RZ[0]['id'] ); }; } else { $LD['status'] = 1; $LD['img'] = '/style/assets/no-signal_h.png'; }; } else { $LD['status'] = 0; }; $Modules[] = $LD; $Data['modules'] = $Modules; }; $QS="SELECT `id`, `ts` FROM `sessions` WHERE `track_id`={$TID} AND `final`='N' ORDER BY (`ts`*1000)+`ts_ms` LIMIT 1"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $Data['active_session_id']=intval( $RR[0]['id'] ); //Fetch Targets
$Basepath = '/lib/controller/data/reports/'.$TID.'/'.date("Y/m/d",intval( $RR[0]['ts'] )); if( file_exists( $SYSPath . $Basepath ) ){ $RBASE = new SQLite_DB( $SYSPath . $Basepath .'/report.db' ); $QS = "SELECT * FROM `events` WHERE `session_id`={$Data['active_session_id']} AND `evt_type` IN(13,14,36) ORDER BY `ts`*1000+`ts_ms` DESC LIMIT 32"; $RR = $RBASE->Query( $QS ); $RR = array_reverse( $RR ); foreach( $RR as $CR ){ $CE = array(); //$CE['id']=intval($CR['id']);
//$CE['ts']=intval($CR['ts'])*1000+intval($CR['ts_ms']);
//if( $Data['start_ts'] > $CE['ts'] ) $Data['start_ts'] = $CE['ts'];
//$CE['module_id']=intval( $CR['module_id'] );
$CE['az']=floatval( $CR['azimuth'] ); $CE['r']=floatval( $CR['range'] );//cos( floatval( $CR['azimuth'] ) )
if( $CT['side'] == 'U' ){ if( $CT['near_module_id'] == intval( $CR['module_id'] ) ){ $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0; } else { $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0; }; } else { if( $CT['far_module_id'] == intval( $CR['module_id'] ) ){ $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0; } else { $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0; }; }; $Data['events'][] = $CE; }; }; }; }; break; }; };// Data By Level
$Data['status'] = 'ok'; $Data['messages'] = ob_get_clean(); echo json_encode( $Data ); } else { header('location: /'); };
?>
|