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.

501 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. $CB = array();
  290. $CB[0] = 0x0f & intval( $SM['crossbar_a'] );
  291. $CB[1] = 0x0f & intval( $SM['crossbar_b'] );
  292. $CB[2] = 0x0f & intval( $SM['crossbar_c'] );
  293. $CB[3] = 0x0f & intval( $SM['crossbar_d'] );
  294. $Data['scada']['crossbar'] = $CB;
  295. if( $CB[0] ){
  296. $Data['scada']['A']= (($CV & ( 0x01 << ($CB[0]-1) )) == ( 0x01 << ($CB[0]-1) ));
  297. }else $Data['scada']['A']= false;
  298. if( $CB[1] ){
  299. $Data['scada']['B']= (($CV & ( 0x01 << ($CB[1]-1) )) == ( 0x01 << ($CB[1]-1) ));
  300. } else $Data['scada']['B']= false;
  301. if( $CB[2] ){
  302. $Data['scada']['C']= (($CV & ( 0x01 << ($CB[2]-1) )) == ( 0x01 << ($CB[2]-1) ));
  303. } else $Data['scada']['C']= false;
  304. if( $CB[3] ){
  305. $Data['scada']['D']= (($CV & ( 0x01 << ($CB[3]-1) )) == ( 0x01 << ($CB[3]-1) ));
  306. } else $Data['scada']['D']= false;
  307. };
  308. };
  309. };
  310. $Data['train']=array( 'status'=>$TrainPos );
  311. };
  312. $QS = "SELECT * FROM `metro_platforms_mboxes` WHERE `platform_id`={$PID} ORDER BY `ts`";
  313. $RR = $DATABASE->Query( $QS, false );
  314. $Data['poster'] = array();
  315. if( count( $RR ) ){
  316. foreach( $RR as $M ){
  317. $CR = array();
  318. $CR['id'] = intval( $M['id'] );
  319. $CR['status'] = intval( $M['status'] );
  320. $DD = Date( "M j, Y, g:i a", intval( $M['ts'] ) );
  321. switch( $M['type'] ){
  322. 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>";
  323. $BGC = '#00002f';
  324. break;
  325. 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>";
  326. $BGC = '#002f00';
  327. break;
  328. 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>";
  329. $BGC = '#002f2f';
  330. break;
  331. 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>";
  332. $BGC = '#2f2f00';
  333. break;
  334. 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>";
  335. $BGC = '#2f002f';
  336. break;
  337. case 6:
  338. $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>";
  339. $BGC = '#002f00';
  340. break;
  341. }
  342. if( $CR['status'] ){
  343. $DBE = 'true';
  344. $DBBT = $Labels->GetLabel('_SNOOZED_');
  345. } else {
  346. $DBE = 'false';
  347. $DBBT = $Labels->GetLabel('_SNOOZE_');
  348. };
  349. if( $MBHL ){
  350. if( $M['type'] >= $MBHL ){
  351. $SNOOZEBTN="{ text: '{$DBBT}', disabled: {$DBE}, handler: function(){ doPlatformOperation( {$PID}, 31, {$M['id']},false); } },";
  352. };
  353. } else {
  354. if( $M['type'] == 6 ){
  355. $SNOOZEBTN="{ text: '{$DBBT}', disabled: {$DBE}, handler: function(){ doPlatformOperation( {$PID}, 31, {$M['id']},false); } },";
  356. };
  357. };
  358. $CR['content'] =<<<DATA_BOUNDARY
  359. {
  360. xtype: 'panel',
  361. frame: true,
  362. width: 300,
  363. border: false,
  364. frame: false,
  365. id: 'mbox_post_panel_{$M['id']}',
  366. html: '{$CONTENT}',
  367. bodyStyle: 'background-color: {$BGC};',
  368. style: 'border: 2px solid {$BGC}; border-radius: 5px;',
  369. bbar:[{$SNOOZEBTN}{
  370. text: '{$Labels->GetLabel('_DISSMISS_')}',
  371. handler: function(){
  372. doPlatformOperation( {$PID}, 32, {$M['id']}, false);
  373. }
  374. }]
  375. }
  376. DATA_BOUNDARY;
  377. $Data['poster'][] = $CR;
  378. };
  379. $TT = '';
  380. foreach( $Data['poster'] as $P ) $TT .= $P['content'];
  381. $Data['poster_md5'] = md5( $TT );
  382. if( isset( $_POST['SCM'] ) ){
  383. if( $_POST['SCM'] == $Data['poster_md5'] ) $Data['poster'] = array();
  384. };
  385. } else {
  386. };
  387. };
  388. break;
  389. };
  390. case 3:{ // Track View
  391. $TID = intval( $_POST['TID'] );
  392. if( $TID ){
  393. $QS = "SELECT * FROM `metro_tracks` WHERE `id`={$TID}";
  394. $RR = $DATABASE->Query( $QS );
  395. if( count( $RR ) ){
  396. $CT = $RR[0];
  397. $Modules = array();
  398. $CM = intval( $CT['near_module_id'] );
  399. $LD = array();
  400. if( $CM ){
  401. $LD['id']=$CM;
  402. if( getOnlineStatus( $CM ) ){
  403. $LD['status'] = 2;
  404. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  405. $RZ = $DATABASE->Query( $QS );
  406. $MM = $RZ[0];
  407. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  408. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  409. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  410. $RZ = $DATABASE->Query( $QS );
  411. if( count( $RZ ) ){
  412. $LD['status'] = 3;
  413. $LD['session'] = intval( $RZ[0]['id'] );
  414. };
  415. } else {
  416. $LD['status'] = 1;
  417. $LD['img'] = '/style/assets/no-signal_h.png';
  418. };
  419. } else {
  420. $LD['status'] = 0;
  421. };
  422. $Modules[] = $LD;
  423. $CM = $CT['far_module_id'];
  424. $LD = array();
  425. if( $CM ){
  426. $LD['id']=$CM;
  427. if( getOnlineStatus( $CM ) ){
  428. $LD['status'] = 2;
  429. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  430. $RZ = $DATABASE->Query( $QS );
  431. $MM = $RZ[0];
  432. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  433. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  434. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  435. $RZ = $DATABASE->Query( $QS );
  436. if( count( $RZ ) ){
  437. $LD['status'] = 3;
  438. $LD['session'] = intval( $RZ[0]['id'] );
  439. };
  440. } else {
  441. $LD['status'] = 1;
  442. $LD['img'] = '/style/assets/no-signal_h.png';
  443. };
  444. } else {
  445. $LD['status'] = 0;
  446. };
  447. $Modules[] = $LD;
  448. $Data['modules'] = $Modules;
  449. };
  450. $QS="SELECT `id`, `ts` FROM `sessions` WHERE `track_id`={$TID} AND `final`='N' ORDER BY (`ts`*1000)+`ts_ms` LIMIT 1";
  451. $RR = $DATABASE->Query( $QS );
  452. if( count( $RR ) ){
  453. $Data['active_session_id']=intval( $RR[0]['id'] );
  454. //Fetch Targets
  455. $Basepath = '/lib/controller/data/reports/'.$TID.'/'.date("Y/m/d",intval( $RR[0]['ts'] ));
  456. if( file_exists( $SYSPath . $Basepath ) ){
  457. $RBASE = new SQLite_DB( $SYSPath . $Basepath .'/report.db' );
  458. $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";
  459. $RR = $RBASE->Query( $QS );
  460. $RR = array_reverse( $RR );
  461. foreach( $RR as $CR ){
  462. $CE = array();
  463. //$CE['id']=intval($CR['id']);
  464. //$CE['ts']=intval($CR['ts'])*1000+intval($CR['ts_ms']);
  465. //if( $Data['start_ts'] > $CE['ts'] ) $Data['start_ts'] = $CE['ts'];
  466. //$CE['module_id']=intval( $CR['module_id'] );
  467. $CE['az']=floatval( $CR['azimuth'] );
  468. $CE['r']=floatval( $CR['range'] );//cos( floatval( $CR['azimuth'] ) )
  469. if( $CT['side'] == 'U' ){
  470. if( $CT['near_module_id'] == intval( $CR['module_id'] ) ){
  471. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  472. } else {
  473. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  474. };
  475. } else {
  476. if( $CT['far_module_id'] == intval( $CR['module_id'] ) ){
  477. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  478. } else {
  479. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  480. };
  481. };
  482. $Data['events'][] = $CE;
  483. };
  484. };
  485. };
  486. };
  487. break;
  488. };
  489. };// Data By Level
  490. $Data['status'] = 'ok';
  491. $Data['messages'] = ob_get_clean();
  492. echo json_encode( $Data );
  493. } else {
  494. header('location: /');
  495. };
  496. ?>