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.

391 lines
15 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. $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}";
  182. $RR = $DATABASE->Query( $QS );
  183. if( count( $RR ) ){
  184. $Modules = array();
  185. $TrainPos = 0;
  186. foreach( $RR as $CT ){
  187. $CM = intval( $CT['near_module_id'] );
  188. $LD = array();
  189. if( $CM ){
  190. $LD['id']=$CM;
  191. $MOS = getOnlineStatus( $CM );
  192. if( $MOS ){
  193. $LD['status'] = 2;
  194. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  195. $RZ = $DATABASE->Query( $QS );
  196. $MM = $RZ[0];
  197. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  198. if( $MOS == 3 ) {
  199. if( $CT['side'] == 'U' ){
  200. $TrainPos = $TrainPos | 1;
  201. } else {
  202. $TrainPos = $TrainPos | 8;
  203. };
  204. };
  205. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  206. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'";
  207. $RZ = $DATABASE->Query( $QS );
  208. if( count( $RZ ) ){
  209. $LD['status'] = 3;
  210. $LD['session'] = intval( $RZ[0]['id'] );
  211. };
  212. } else {
  213. $LD['status'] = 1;
  214. $LD['img'] = '/style/assets/no-signal_h.png';
  215. };
  216. } else {
  217. $LD['status'] = 0;
  218. };
  219. $Modules[] = $LD;
  220. $CM = $CT['far_module_id'];
  221. $LD = array();
  222. if( $CM ){
  223. $LD['id']=$CM;
  224. $MOS = getOnlineStatus( $CM );
  225. if( $MOS ){
  226. $LD['status'] = 2;
  227. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  228. $RZ = $DATABASE->Query( $QS );
  229. $MM = $RZ[0];
  230. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  231. if( $MOS == 3 ) {
  232. if( $CT['side'] == 'U' ){
  233. $TrainPos = $TrainPos | 2;
  234. } else {
  235. $TrainPos = $TrainPos | 4;
  236. };
  237. };
  238. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  239. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'";
  240. $RZ = $DATABASE->Query( $QS );
  241. if( count( $RZ ) ){
  242. $LD['status'] = 3;
  243. $LD['session'] = intval( $RZ[0]['id'] );
  244. };
  245. } else {
  246. $LD['status'] = 1;
  247. $LD['img'] = '/style/assets/no-signal_h.png';
  248. };
  249. } else {
  250. $LD['status'] = 0;
  251. };
  252. $Modules[] = $LD;
  253. };
  254. $Data['modules'] = $Modules;
  255. $QS = "SELECT * FROM `modbus_modules` WHERE `platform_id`={$PID}";
  256. $RR = $DATABASE->Query( $QS );
  257. $Data['scada'] = array();
  258. if( count($RR) == 0 ) {
  259. $Data['scada']['status']=0;
  260. } else {
  261. $SM = $RR[0];
  262. if( $SM['wm'] == 'D' ){
  263. $Data['scada']['status']=1;
  264. } else {
  265. $SM['status'] = intval($SM['status']);
  266. $Data['scada']['status']=$SM['status']+2;
  267. if( $SM['status'] > 0 ){
  268. $CV = intval($SM['values']);
  269. $Data['scada']['A']= $CV & 0x01;
  270. $Data['scada']['B']= $CV & 0x02;
  271. $Data['scada']['C']= $CV & 0x04;
  272. $Data['scada']['D']= $CV & 0x08;
  273. };
  274. };
  275. };
  276. $Data['train']=array( 'status'=>$TrainPos );
  277. };
  278. };
  279. break;
  280. };
  281. case 3:{ // Track View
  282. $TID = intval( $_POST['TID'] );
  283. if( $TID ){
  284. $QS = "SELECT * FROM `metro_tracks` WHERE `id`={$TID}";
  285. $RR = $DATABASE->Query( $QS );
  286. if( count( $RR ) ){
  287. $CT = $RR[0];
  288. $Modules = array();
  289. $CM = intval( $CT['near_module_id'] );
  290. $LD = array();
  291. if( $CM ){
  292. $LD['id']=$CM;
  293. if( getOnlineStatus( $CM ) ){
  294. $LD['status'] = 2;
  295. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  296. $RZ = $DATABASE->Query( $QS );
  297. $MM = $RZ[0];
  298. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  299. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  300. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  301. $RZ = $DATABASE->Query( $QS );
  302. if( count( $RZ ) ){
  303. $LD['status'] = 3;
  304. $LD['session'] = intval( $RZ[0]['id'] );
  305. };
  306. } else {
  307. $LD['status'] = 1;
  308. $LD['img'] = '/style/assets/no-signal_h.png';
  309. };
  310. } else {
  311. $LD['status'] = 0;
  312. };
  313. $Modules[] = $LD;
  314. $CM = $CT['far_module_id'];
  315. $LD = array();
  316. if( $CM ){
  317. $LD['id']=$CM;
  318. if( getOnlineStatus( $CM ) ){
  319. $LD['status'] = 2;
  320. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  321. $RZ = $DATABASE->Query( $QS );
  322. $MM = $RZ[0];
  323. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  324. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  325. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  326. $RZ = $DATABASE->Query( $QS );
  327. if( count( $RZ ) ){
  328. $LD['status'] = 3;
  329. $LD['session'] = intval( $RZ[0]['id'] );
  330. };
  331. } else {
  332. $LD['status'] = 1;
  333. $LD['img'] = '/style/assets/no-signal_h.png';
  334. };
  335. } else {
  336. $LD['status'] = 0;
  337. };
  338. $Modules[] = $LD;
  339. $Data['modules'] = $Modules;
  340. };
  341. $QS="SELECT `id`, `ts` FROM `sessions` WHERE `track_id`={$TID} AND `final`='N' ORDER BY (`ts`*1000)+`ts_ms` LIMIT 1";
  342. $RR = $DATABASE->Query( $QS );
  343. if( count( $RR ) ){
  344. $Data['active_session_id']=intval( $RR[0]['id'] );
  345. //Fetch Targets
  346. $Basepath = '/lib/controller/data/reports/'.$TID.'/'.date("Y/m/d",intval( $RR[0]['ts'] ));
  347. if( file_exists( $SYSPath . $Basepath ) ){
  348. $RBASE = new SQLite_DB( $SYSPath . $Basepath .'/report.db' );
  349. $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";
  350. $RR = $RBASE->Query( $QS );
  351. $RR = array_reverse( $RR );
  352. foreach( $RR as $CR ){
  353. $CE = array();
  354. //$CE['id']=intval($CR['id']);
  355. //$CE['ts']=intval($CR['ts'])*1000+intval($CR['ts_ms']);
  356. //if( $Data['start_ts'] > $CE['ts'] ) $Data['start_ts'] = $CE['ts'];
  357. //$CE['module_id']=intval( $CR['module_id'] );
  358. $CE['az']=floatval( $CR['azimuth'] );
  359. $CE['r']=floatval( $CR['range'] );//cos( floatval( $CR['azimuth'] ) )
  360. if( $CT['side'] == 'U' ){
  361. if( $CT['near_module_id'] == intval( $CR['module_id'] ) ){
  362. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  363. } else {
  364. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  365. };
  366. } else {
  367. if( $CT['far_module_id'] == intval( $CR['module_id'] ) ){
  368. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  369. } else {
  370. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  371. };
  372. };
  373. $Data['events'][] = $CE;
  374. };
  375. };
  376. };
  377. };
  378. break;
  379. };
  380. };// Data By Level
  381. $Data['status'] = 'ok';
  382. $Data['messages'] = ob_get_clean();
  383. echo json_encode( $Data );
  384. } else {
  385. header('location: /');
  386. };
  387. ?>