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.

487 lines
20 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
12 months ago
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. require_once('../php/argus/server.php');
  4. ob_start();
  5. $UID = intval( $CUser->Data['id'] );
  6. $ACCESS = intval( $CUser->Data['access'] );
  7. if( $UID > 1 ){
  8. $Data = array();
  9. $Data['VLVL'] = intval( $_POST['VLVL'] );
  10. $Data['LTS'] = intval( $_POST['LTS'] );
  11. $Data['active_session_id'] = 0;
  12. $LID = intval( $_POST['LID'] );
  13. if( $Data['LTS'] == 0 ) $Data['LTS'] = floor(microtime(true) * 1000);//time();
  14. $ALRM_STATIONS = array();
  15. //Data for Side Panel
  16. $QS = "SELECT count( `id` ) AS `cnt` FROM `sessions` WHERE `final`='N'";
  17. $RR = $DATABASE->Query( $QS );
  18. $Data['actual_count'] =intval($RR[0]['cnt']);
  19. $QS = "SELECT * FROM `sessions` WHERE `final`='N' ORDER BY (`ts`*1000+`ts_ms`) DESC LIMIT 32";
  20. $RR = $DATABASE->Query( $QS );
  21. if( count( $RR ) ){
  22. if( $Data['active_session_id']==0 ) $Data['active_session_id'] = intval( $RR[0]['id'] );
  23. $Data['actual'] = array();
  24. foreach( $RR as $R ){
  25. $CA = array();
  26. $CA['id']=intval($R['id'] );
  27. $CA['track']=intval( $R['track_id'] );
  28. $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']}";
  29. $GG = $DATABASE->Query( $QS );
  30. $CA['station_name']=$GG[0]['s_name'];
  31. $CA['station']=intval( $GG[0]['s_id'] );
  32. $CA['platform_name']=date( "M d H:i:s", $R['ts']);//$GG[0]['p_name'];
  33. $CA['platform']=intval( $GG[0]['p_id'] );
  34. $CA['track_tag']=$GG[0]['short'];
  35. $CA['status']=0;
  36. $Data['actual'][] = $CA;
  37. $ALRM_STATIONS[$GG[0]['s_id']] = 4;
  38. };
  39. $Data['actual'] = array_reverse( $Data['actual'] );
  40. };
  41. $QS = "SELECT count( `id` ) AS `cnt` FROM `sessions` WHERE `final`='Y' AND `status`=0";
  42. $RR = $DATABASE->Query( $QS );
  43. $Data['expired_count']=intval($RR[0]['cnt']);
  44. $QS = "SELECT * FROM `sessions` WHERE `final`='Y' AND `status`=0 ORDER BY (`ts`*1000+`ts_ms`) DESC LIMIT 32";
  45. $RR = $DATABASE->Query( $QS );
  46. if( count( $RR ) ){
  47. $Data['expired'] = array();
  48. foreach( $RR as $R ){
  49. $CA = array();
  50. $CA['id']=intval($R['id'] );
  51. $CA['track']=intval( $R['track_id'] );
  52. $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']}";
  53. $GG = $DATABASE->Query( $QS );
  54. $CA['station_name']=$GG[0]['s_name'];
  55. $CA['platform_name']=date( "M d H:i:s", $R['ts']);//$GG[0]['p_name'];
  56. $CA['track_tag']=$GG[0]['short'];
  57. $CA['status']=1;
  58. $Data['expired'][] = $CA;
  59. if( !isset($ALRM_STATIONS[$GG[0]['s_id']] ) ) $ALRM_STATIONS[$GG[0]['s_id']] = 3;
  60. };
  61. $Data['expired'] = array_reverse( $Data['expired'] );
  62. };
  63. switch( $Data['VLVL'] ){
  64. case 0:{ // Map Level Monitoring
  65. // check the station/modules online statuses, check just side sessions
  66. $QS = "SELECT id FROM `metro_stations`";
  67. $RR = $DATABASE->Query( $QS );
  68. foreach( $RR as $CR ){
  69. //If station not Alarmed
  70. if( !isset($ALRM_STATIONS[$CR['id']] ) ){
  71. $ALRM_STATIONS[$CR['id']] = 1; // default Station is ok
  72. $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']}";
  73. $ZZ = $DATABASE->Query( $QS );
  74. if( count( $ZZ ) ){
  75. foreach( $ZZ as $CZ ){
  76. $QS = "SELECT `id` FROM `metro_modules` WHERE `track_id`={$CZ['id']}";
  77. $JJ = $DATABASE->Query( $QS );
  78. if( count( $JJ ) ){
  79. foreach( $JJ as $J ){
  80. //check online status of module
  81. //$QS = "SELECT
  82. };
  83. } else $ALRM_STATIONS[$CR['id']] = 2; // Has No Modules at all
  84. };
  85. } else {
  86. $ALRM_STATIONS[$CR['id']] = 0; // No Infrostructure
  87. };
  88. };
  89. };
  90. $SI = array();
  91. $SS = array();
  92. foreach( $ALRM_STATIONS as $K=>$V ){
  93. $SI[] = $K;
  94. $SS[] = $V;
  95. };
  96. $Data['station_ids'] = $SI;
  97. $Data['station_status'] = $SS;
  98. break;
  99. };
  100. case 1:{ // Station View
  101. $SSID = intval( $_POST['SSID'] );
  102. $Data['platforms'] = array();
  103. if( $SSID ){
  104. $QS = "SELECT * FROM `metro_platforms` WHERE `station_id`={$SSID}";
  105. $PL = $DATABASE->Query( $QS );
  106. foreach( $PL as $P ){
  107. $CP = array();
  108. $CP['id'] = intval( $P['id'] );
  109. $CP['status'] = 0;
  110. foreach( $Data['actual'] as $CC ) if( $CC['station'] == $SSID ) if( $CP['id'] == $CC['platform'] ) {
  111. $CP['status'] = 1;
  112. break;
  113. };
  114. $PID = $CP['id'];
  115. $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}";
  116. $RR = $DATABASE->Query( $QS );
  117. if( count( $RR ) ){
  118. $Modules = array();
  119. foreach( $RR as $CT ){
  120. $CM = intval( $CT['near_module_id'] );
  121. $LD = array();
  122. if( $CM ){
  123. $LD['id']=$CM;
  124. if( getOnlineStatus( $CM ) ){
  125. $LD['status'] = 2;
  126. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  127. $RZ = $DATABASE->Query( $QS );
  128. $MM = $RZ[0];
  129. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  130. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  131. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  132. $RZ = $DATABASE->Query( $QS );
  133. if( count( $RZ ) ){
  134. $LD['status'] = 3;
  135. $LD['session'] = intval( $RZ[0]['id'] );
  136. };
  137. } else {
  138. $LD['status'] = 1;
  139. $LD['img'] = '/style/assets/no-signal_h.png';
  140. };
  141. } else {
  142. $LD['status'] = 0;
  143. };
  144. $Modules[] = $LD;
  145. $CM = $CT['far_module_id'];
  146. $LD = array();
  147. if( $CM ){
  148. $LD['id']=$CM;
  149. if( getOnlineStatus( $CM ) ){
  150. $LD['status'] = 2;
  151. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  152. $RZ = $DATABASE->Query( $QS );
  153. $MM = $RZ[0];
  154. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  155. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  156. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  157. $RZ = $DATABASE->Query( $QS );
  158. if( count( $RZ ) ){
  159. $LD['status'] = 3;
  160. $LD['session'] = intval( $RZ[0]['id'] );
  161. };
  162. } else {
  163. $LD['status'] = 1;
  164. $LD['img'] = '/style/assets/no-signal_h.png';
  165. };
  166. } else {
  167. $LD['status'] = 0;
  168. };
  169. $Modules[] = $LD;
  170. };
  171. $CP['modules'] = $Modules;
  172. };
  173. $Data['platforms'][] = $CP;
  174. };
  175. };
  176. break;
  177. };
  178. case 2:{ //Platform View
  179. $PID = intval( $_POST['PID'] );
  180. if( $PID ){
  181. $MODULENAMES = array();
  182. $QS = "SELECT `left_side`, `right_side` FROM `metro_platforms` WHERE `id`={$PID}";
  183. $RR = $DATABASE->Query( $QS );
  184. $SIDES = $RR[0];
  185. $QS = "SELECT `modbus_health_level` FROM `system_props` LIMIT 1";
  186. $RR = $DATABASE->Query( $QS );
  187. $MBHL = intval( $RR[0]['modbus_health_level'] );
  188. $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}";
  189. $RR = $DATABASE->Query( $QS );
  190. if( count( $RR ) ){
  191. $Modules = array();
  192. $TrainPos = 0;
  193. foreach( $RR as $CT ){
  194. $CM = intval( $CT['near_module_id'] );
  195. $LD = array();
  196. if( $CM ){
  197. $LD['id']=$CM;
  198. $MOS = getOnlineStatus( $CM );
  199. if( $MOS ){
  200. $LD['status'] = 2;
  201. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  202. $RZ = $DATABASE->Query( $QS );
  203. $MM = $RZ[0];
  204. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  205. if( $MOS == 3 ) {
  206. if( $CT['side'] == 'U' ){
  207. $TrainPos = $TrainPos | 1;
  208. } else {
  209. $TrainPos = $TrainPos | 8;
  210. };
  211. };
  212. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  213. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'";
  214. $RZ = $DATABASE->Query( $QS );
  215. if( count( $RZ ) ){
  216. $LD['status'] = 3;
  217. $LD['session'] = intval( $RZ[0]['id'] );
  218. };
  219. } else {
  220. $LD['status'] = 1;
  221. $LD['img'] = '/style/assets/no-signal_h.png';
  222. };
  223. // Names
  224. if( $CT['side'] == 'U' ){
  225. $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['right_side'];
  226. } else {
  227. $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['left_side'];
  228. };
  229. } else {
  230. $LD['status'] = 0;
  231. };
  232. $Modules[] = $LD;
  233. $CM = $CT['far_module_id'];
  234. $LD = array();
  235. if( $CM ){
  236. $LD['id']=$CM;
  237. $MOS = getOnlineStatus( $CM );
  238. if( $MOS ){
  239. $LD['status'] = 2;
  240. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  241. $RZ = $DATABASE->Query( $QS );
  242. $MM = $RZ[0];
  243. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  244. if( $MOS == 3 ) {
  245. if( $CT['side'] == 'U' ){
  246. $TrainPos = $TrainPos | 2;
  247. } else {
  248. $TrainPos = $TrainPos | 4;
  249. };
  250. };
  251. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  252. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'";
  253. $RZ = $DATABASE->Query( $QS );
  254. if( count( $RZ ) ){
  255. $LD['status'] = 3;
  256. $LD['session'] = intval( $RZ[0]['id'] );
  257. };
  258. } else {
  259. $LD['status'] = 1;
  260. $LD['img'] = '/style/assets/no-signal_h.png';
  261. };
  262. // Names
  263. if( $CT['side'] == 'U' ){
  264. $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['left_side'];
  265. } else {
  266. $MODULENAMES[$CM]= $CT['short'] . ":" . $SIDES['right_side'];
  267. };
  268. } else {
  269. $LD['status'] = 0;
  270. };
  271. $Modules[] = $LD;
  272. };
  273. $Data['modules'] = $Modules;
  274. //Select only TCC module
  275. $QS = "SELECT * FROM `modbus_modules` WHERE `platform_id`={$PID} AND `func`=3";
  276. $RR = $DATABASE->Query( $QS );
  277. $Data['scada'] = array();
  278. if( count($RR) == 0 ) {
  279. $Data['scada']['status']=0;
  280. } else {
  281. $SM = $RR[0];
  282. if( $SM['wm'] == 'D' ){
  283. $Data['scada']['status']=0;
  284. } else {
  285. $SM['status'] = intval($SM['status']);
  286. $Data['scada']['status']=$SM['status']+2;
  287. if( $SM['status'] > 0 ){
  288. $CV = intval($SM['values']);
  289. $Data['scada']['A']= (($CV & 0x01) == 1);
  290. $Data['scada']['B']= (($CV & 0x02) == 2);
  291. $Data['scada']['C']= (($CV & 0x04) == 4);
  292. $Data['scada']['D']= (($CV & 0x08) == 8);
  293. };
  294. };
  295. };
  296. $Data['train']=array( 'status'=>$TrainPos );
  297. };
  298. $QS = "SELECT * FROM `metro_platforms_mboxes` WHERE `platform_id`={$PID} ORDER BY `ts`";
  299. $RR = $DATABASE->Query( $QS, false );
  300. $Data['poster'] = array();
  301. if( count( $RR ) ){
  302. foreach( $RR as $M ){
  303. $CR = array();
  304. $CR['id'] = intval( $M['id'] );
  305. $CR['status'] = intval( $M['status'] );
  306. $DD = Date( "M j, Y, g:i a", intval( $M['ts'] ) );
  307. switch( $M['type'] ){
  308. 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>";
  309. $BGC = '#00002f';
  310. break;
  311. 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>";
  312. $BGC = '#002f00';
  313. break;
  314. 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>";
  315. $BGC = '#002f2f';
  316. break;
  317. 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>";
  318. $BGC = '#2f2f00';
  319. break;
  320. 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>";
  321. $BGC = '#2f002f';
  322. break;
  323. case 6:
  324. $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>";
  325. $BGC = '#002f00';
  326. break;
  327. }
  328. if( $CR['status'] ){
  329. $DBE = 'true';
  330. $DBBT = $Labels->GetLabel('_SNOOZED_');
  331. } else {
  332. $DBE = 'false';
  333. $DBBT = $Labels->GetLabel('_SNOOZE_');
  334. };
  335. if( $MBHL ){
  336. if( $M['type'] >= $MBHL ){
  337. $SNOOZEBTN="{ text: '{$DBBT}', disabled: {$DBE}, handler: function(){ doPlatformOperation( {$PID}, 31, {$M['id']},false); } },";
  338. };
  339. } else {
  340. if( $M['type'] == 6 ){
  341. $SNOOZEBTN="{ text: '{$DBBT}', disabled: {$DBE}, handler: function(){ doPlatformOperation( {$PID}, 31, {$M['id']},false); } },";
  342. };
  343. };
  344. $CR['content'] =<<<DATA_BOUNDARY
  345. {
  346. xtype: 'panel',
  347. frame: true,
  348. width: 300,
  349. border: false,
  350. frame: false,
  351. id: 'mbox_post_panel_{$M['id']}',
  352. html: '{$CONTENT}',
  353. bodyStyle: 'background-color: {$BGC};',
  354. style: 'border: 2px solid {$BGC}; border-radius: 5px;',
  355. bbar:[{$SNOOZEBTN}{
  356. text: '{$Labels->GetLabel('_DISSMISS_')}',
  357. handler: function(){
  358. doPlatformOperation( {$PID}, 32, {$M['id']}, false);
  359. }
  360. }]
  361. }
  362. DATA_BOUNDARY;
  363. $Data['poster'][] = $CR;
  364. };
  365. $TT = '';
  366. foreach( $Data['poster'] as $P ) $TT .= $P['content'];
  367. $Data['poster_md5'] = md5( $TT );
  368. if( isset( $_POST['SCM'] ) ){
  369. if( $_POST['SCM'] == $Data['poster_md5'] ) $Data['poster'] = array();
  370. };
  371. } else {
  372. };
  373. };
  374. break;
  375. };
  376. case 3:{ // Track View
  377. $TID = intval( $_POST['TID'] );
  378. if( $TID ){
  379. $QS = "SELECT * FROM `metro_tracks` WHERE `id`={$TID}";
  380. $RR = $DATABASE->Query( $QS );
  381. if( count( $RR ) ){
  382. $CT = $RR[0];
  383. $Modules = array();
  384. $CM = intval( $CT['near_module_id'] );
  385. $LD = array();
  386. if( $CM ){
  387. $LD['id']=$CM;
  388. if( getOnlineStatus( $CM ) ){
  389. $LD['status'] = 2;
  390. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  391. $RZ = $DATABASE->Query( $QS );
  392. $MM = $RZ[0];
  393. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  394. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  395. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  396. $RZ = $DATABASE->Query( $QS );
  397. if( count( $RZ ) ){
  398. $LD['status'] = 3;
  399. $LD['session'] = intval( $RZ[0]['id'] );
  400. };
  401. } else {
  402. $LD['status'] = 1;
  403. $LD['img'] = '/style/assets/no-signal_h.png';
  404. };
  405. } else {
  406. $LD['status'] = 0;
  407. };
  408. $Modules[] = $LD;
  409. $CM = $CT['far_module_id'];
  410. $LD = array();
  411. if( $CM ){
  412. $LD['id']=$CM;
  413. if( getOnlineStatus( $CM ) ){
  414. $LD['status'] = 2;
  415. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  416. $RZ = $DATABASE->Query( $QS );
  417. $MM = $RZ[0];
  418. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  419. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  420. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  421. $RZ = $DATABASE->Query( $QS );
  422. if( count( $RZ ) ){
  423. $LD['status'] = 3;
  424. $LD['session'] = intval( $RZ[0]['id'] );
  425. };
  426. } else {
  427. $LD['status'] = 1;
  428. $LD['img'] = '/style/assets/no-signal_h.png';
  429. };
  430. } else {
  431. $LD['status'] = 0;
  432. };
  433. $Modules[] = $LD;
  434. $Data['modules'] = $Modules;
  435. };
  436. $QS="SELECT `id`, `ts` FROM `sessions` WHERE `track_id`={$TID} AND `final`='N' ORDER BY (`ts`*1000)+`ts_ms` LIMIT 1";
  437. $RR = $DATABASE->Query( $QS );
  438. if( count( $RR ) ){
  439. $Data['active_session_id']=intval( $RR[0]['id'] );
  440. //Fetch Targets
  441. $Basepath = '/lib/controller/data/reports/'.$TID.'/'.date("Y/m/d",intval( $RR[0]['ts'] ));
  442. if( file_exists( $SYSPath . $Basepath ) ){
  443. $RBASE = new SQLite_DB( $SYSPath . $Basepath .'/report.db' );
  444. $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";
  445. $RR = $RBASE->Query( $QS );
  446. $RR = array_reverse( $RR );
  447. foreach( $RR as $CR ){
  448. $CE = array();
  449. //$CE['id']=intval($CR['id']);
  450. //$CE['ts']=intval($CR['ts'])*1000+intval($CR['ts_ms']);
  451. //if( $Data['start_ts'] > $CE['ts'] ) $Data['start_ts'] = $CE['ts'];
  452. //$CE['module_id']=intval( $CR['module_id'] );
  453. $CE['az']=floatval( $CR['azimuth'] );
  454. $CE['r']=floatval( $CR['range'] );//cos( floatval( $CR['azimuth'] ) )
  455. if( $CT['side'] == 'U' ){
  456. if( $CT['near_module_id'] == intval( $CR['module_id'] ) ){
  457. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  458. } else {
  459. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  460. };
  461. } else {
  462. if( $CT['far_module_id'] == intval( $CR['module_id'] ) ){
  463. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  464. } else {
  465. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  466. };
  467. };
  468. $Data['events'][] = $CE;
  469. };
  470. };
  471. };
  472. };
  473. break;
  474. };
  475. };// Data By Level
  476. $Data['status'] = 'ok';
  477. $Data['messages'] = ob_get_clean();
  478. echo json_encode( $Data );
  479. } else {
  480. header('location: /');
  481. };
  482. ?>