|
|
<?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'] ); $Data['active_session_id'] = 0; $LID = intval( $_POST['LID'] ); if( $Data['LTS'] == 0 ) $Data['LTS'] = floor(microtime(true) * 1000);//time();
$ALRM_STATIONS = array(); //Data for Side Panel
$QS = "SELECT count( `id` ) AS `cnt` FROM `sessions` WHERE `final`='N'"; $RR = $DATABASE->Query( $QS ); $Data['actual_count'] =intval($RR[0]['cnt']); $QS = "SELECT * FROM `sessions` WHERE `final`='N' ORDER BY (`ts`*1000+`ts_ms`) DESC LIMIT 32"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ if( $Data['active_session_id']==0 ) $Data['active_session_id'] = intval( $RR[0]['id'] ); $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`.`short` AS `s_name`, `pt`.`id` AS `p_id`, `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['station']=intval( $GG[0]['s_id'] ); $CA['platform_name']=date( "M d H:i:s", $R['ts']);//$GG[0]['p_name'];
$CA['platform']=intval( $GG[0]['p_id'] ); $CA['track_tag']=$GG[0]['short']; $CA['status']=0; $Data['actual'][] = $CA; $ALRM_STATIONS[$GG[0]['s_id']] = 4; }; $Data['actual'] = array_reverse( $Data['actual'] ); }; $QS = "SELECT count( `id` ) AS `cnt` FROM `sessions` WHERE `final`='Y' AND `status`=0"; $RR = $DATABASE->Query( $QS ); $Data['expired_count']=intval($RR[0]['cnt']); $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`.`short` 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']=date( "M d H:i:s", $R['ts']);//$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; }; $Data['expired'] = array_reverse( $Data['expired'] ); }; 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 1:{ // Station View
$SSID = intval( $_POST['SSID'] ); $Data['platforms'] = array(); if( $SSID ){ $QS = "SELECT * FROM `metro_platforms` WHERE `station_id`={$SSID}"; $PL = $DATABASE->Query( $QS ); foreach( $PL as $P ){ $CP = array(); $CP['id'] = intval( $P['id'] ); $CP['status'] = 0; foreach( $Data['actual'] as $CC ) if( $CC['station'] == $SSID ) if( $CP['id'] == $CC['platform'] ) { $CP['status'] = 1; break; }; $PID = $CP['id']; $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; }; $CP['modules'] = $Modules; }; $Data['platforms'][] = $CP; }; }; break; }; case 2:{ //Platform View
$PID = intval( $_POST['PID'] ); if( $PID ){ $MODULENAMES = array(); $QS = "SELECT `left_side`, `right_side` FROM `metro_platforms` WHERE `id`={$PID}"; $RR = $DATABASE->Query( $QS ); $SIDES = $RR[0]; $QS = "SELECT `modbus_health_level` FROM `system_props` LIMIT 1"; $RR = $DATABASE->Query( $QS ); $MBHL = intval( $RR[0]['modbus_health_level'] ); $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}"; $RR = $DATABASE->Query( $QS ); if( count( $RR ) ){ $Modules = array(); $TrainPos = 0; foreach( $RR as $CT ){ $CM = intval( $CT['near_module_id'] ); $LD = array(); if( $CM ){ $LD['id']=$CM; $MOS = getOnlineStatus( $CM ); if( $MOS ){ $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']}";
if( $MOS == 3 ) { if( $CT['side'] == 'U' ){ $TrainPos = $TrainPos | 1; } else { $TrainPos = $TrainPos | 8; }; }; $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}"; $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'"; $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'; }; // Names
if( $CT['side'] == 'U' ){ $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['right_side']; } else { $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['left_side']; }; } else { $LD['status'] = 0; }; $Modules[] = $LD; $CM = $CT['far_module_id']; $LD = array(); if( $CM ){ $LD['id']=$CM; $MOS = getOnlineStatus( $CM ); if( $MOS ){ $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']}";
if( $MOS == 3 ) { if( $CT['side'] == 'U' ){ $TrainPos = $TrainPos | 2; } else { $TrainPos = $TrainPos | 4; }; }; $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}"; $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'"; $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'; }; // Names
if( $CT['side'] == 'U' ){ $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['left_side']; } else { $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['right_side']; }; } else { $LD['status'] = 0; }; $Modules[] = $LD; }; $Data['modules'] = $Modules; //Select only TCC module
$QS = "SELECT * FROM `modbus_modules` WHERE `platform_id`={$PID} AND `func`=3"; $RR = $DATABASE->Query( $QS ); $Data['scada'] = array(); if( count($RR) == 0 ) { $Data['scada']['status']=0; } else { $SM = $RR[0]; if( $SM['wm'] == 'D' ){ $Data['scada']['status'] = 0; } else { $SM['status'] = intval($SM['status']); $Data['scada']['status'] = $SM['status']+2; if( $SM['status'] > 0 ){ $CV = intval( $SM['values'] ); $CB = array(); $CB[0] = 0x0f & intval( $SM['crossbar_a'] ); $CB[1] = 0x0f & intval( $SM['crossbar_b'] ); $CB[2] = 0x0f & intval( $SM['crossbar_c'] ); $CB[3] = 0x0f & intval( $SM['crossbar_d'] ); $Data['scada']['crossbar'] = $CB; if( $CB[0] ){ $Data['scada']['A']= (($CV & ( 0x01 << ($CB[0]-1) )) == ( 0x01 << ($CB[0]-1) )); }else $Data['scada']['A']= false; if( $CB[1] ){ $Data['scada']['B']= (($CV & ( 0x01 << ($CB[1]-1) )) == ( 0x01 << ($CB[1]-1) )); } else $Data['scada']['B']= false; if( $CB[2] ){ $Data['scada']['C']= (($CV & ( 0x01 << ($CB[2]-1) )) == ( 0x01 << ($CB[2]-1) )); } else $Data['scada']['C']= false; if( $CB[3] ){ $Data['scada']['D']= (($CV & ( 0x01 << ($CB[3]-1) )) == ( 0x01 << ($CB[3]-1) )); } else $Data['scada']['D']= false; }; }; }; $Data['train']=array( 'status'=>$TrainPos ); }; $QS = "SELECT * FROM `metro_platforms_mboxes` WHERE `platform_id`={$PID} ORDER BY `ts`"; $RR = $DATABASE->Query( $QS, false ); $Data['poster'] = array(); if( count( $RR ) ){ foreach( $RR as $M ){ $CR = array(); $CR['id'] = intval( $M['id'] ); $CR['status'] = intval( $M['status'] ); $DD = Date( "M j, Y, g:i a", intval( $M['ts'] ) ); switch( $M['type'] ){ case 1: $CONTENT = "<table wodth=\"100%\"><tr><td valign=\"top\"><img width=\"64px\" src=\"/style/wicons/cam_icon.png\"></td><td valign=\"top\">" . $Labels->GetLabel('__ON__')." {$DD} ". $Labels->GetLabel('_W_REGISTERED_')." ".$Labels->GetLabel('_HEALTH_1_MSG_')." <b>".$MODULENAMES[$M['src']]."</b> ".$Labels->GetLabel('___MODULE__')."</td></tr></table>"; $BGC = '#00002f'; break; case 2: $CONTENT = "<table wodth=\"100%\"><tr><td valign=\"top\"><img width=\"64px\" src=\"/style/wicons/sensor_icon.png\"></td><td valign=\"top\">" . $Labels->GetLabel('__ON__')." {$DD} ". $Labels->GetLabel('_W_REGISTERED_')." ".$Labels->GetLabel('_HEALTH_2_MSG_')." <b>".$MODULENAMES[$M['src']]."</b> ".$Labels->GetLabel('___MODULE__')."</td></tr></table>"; $BGC = '#002f00'; break; case 3: $CONTENT = "<table wodth=\"100%\"><tr><td valign=\"top\"><img width=\"64px\" src=\"/style/wicons/sensor_icon.png\"></td><td valign=\"top\">" . $Labels->GetLabel('__ON__')." {$DD} ". $Labels->GetLabel('_W_REGISTERED_')." ".$Labels->GetLabel('_HEALTH_3_MSG_')." <b>".$MODULENAMES[$M['src']]."</b> ".$Labels->GetLabel('___MODULE__')."</td></tr></table>"; $BGC = '#002f2f'; break; case 4: $CONTENT = "<table wodth=\"100%\"><tr><td valign=\"top\"><img width=\"64px\" src=\"/style/wicons/soft_icon.png\"></td><td valign=\"top\">" . $Labels->GetLabel('__ON__')." {$DD} ". $Labels->GetLabel('_W_REGISTERED_')." ".$Labels->GetLabel('_HEALTH_4_MSG_')." <b>".$MODULENAMES[$M['src']]."</b> ".$Labels->GetLabel('___MODULE__')."</td></tr></table>"; $BGC = '#2f2f00'; break; case 5: $CONTENT = "<table wodth=\"100%\"><tr><td valign=\"top\"><img width=\"64px\" src=\"/style/wicons/net_icon.png\"></td><td valign=\"top\">" . $Labels->GetLabel('__ON__')." {$DD} ". $Labels->GetLabel('_W_REGISTERED_')." ".$Labels->GetLabel('_HEALTH_5_MSG_')." <b>".$MODULENAMES[$M['src']]."</b> ".$Labels->GetLabel('___MODULE__')."</td></tr></table>"; $BGC = '#2f002f'; break; case 6: $CONTENT = "<table wodth=\"100%\"><tr><td valign=\"top\"><img width=\"64px\" src=\"/style/wicons/strobe-1.png\"></td><td valign=\"top\">" . $Labels->GetLabel('__ON__')." {$DD} ". $Labels->GetLabel('_W_REGISTERED_')." ".$Labels->GetLabel('_HEALTH_6_MSG_')." <b>".$MODULENAMES[$M['src']]."</b> ".$Labels->GetLabel('___SIDE__')."</td></tr></table>"; $BGC = '#002f00'; break; } if( $CR['status'] ){ $DBE = 'true'; $DBBT = $Labels->GetLabel('_SNOOZED_'); } else { $DBE = 'false'; $DBBT = $Labels->GetLabel('_SNOOZE_'); }; if( $MBHL ){ if( $M['type'] >= $MBHL ){ $SNOOZEBTN="{ text: '{$DBBT}', disabled: {$DBE}, handler: function(){ doPlatformOperation( {$PID}, 31, {$M['id']},false); } },"; }; } else { if( $M['type'] == 6 ){ $SNOOZEBTN="{ text: '{$DBBT}', disabled: {$DBE}, handler: function(){ doPlatformOperation( {$PID}, 31, {$M['id']},false); } },"; }; }; $CR['content'] =<<<DATA_BOUNDARY{ xtype: 'panel', frame: true, width: 300, border: false, frame: false, id: 'mbox_post_panel_{$M['id']}', html: '{$CONTENT}', bodyStyle: 'background-color: {$BGC};', style: 'border: 2px solid {$BGC}; border-radius: 5px;', bbar:[{$SNOOZEBTN}{ text: '{$Labels->GetLabel('_DISSMISS_')}', handler: function(){ doPlatformOperation( {$PID}, 32, {$M['id']}, false); } }]}DATA_BOUNDARY; $Data['poster'][] = $CR; }; $TT = ''; foreach( $Data['poster'] as $P ) $TT .= $P['content']; $Data['poster_md5'] = md5( $TT ); if( isset( $_POST['SCM'] ) ){ if( $_POST['SCM'] == $Data['poster_md5'] ) $Data['poster'] = array(); }; } else { }; }; 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: /'); };
?>
|