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.

385 lines
14 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 * FROM `sessions` WHERE `final`='N' ORDER BY (`ts`*1000)+`ts_ms` DESC LIMIT 32";
  17. $RR = $DATABASE->Query( $QS );
  18. if( count( $RR ) ){
  19. if( $Data['active_session_id']==0 ) $Data['active_session_id'] = intval( $RR[0]['id'] );
  20. $Data['actual'] = array();
  21. foreach( $RR as $R ){
  22. $CA = array();
  23. $CA['id']=intval($R['id'] );
  24. $CA['track']=intval( $R['track_id'] );
  25. $QS = "SELECT `st`.`id` AS `s_id`, `st`.`name` 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']}";
  26. $GG = $DATABASE->Query( $QS );
  27. $CA['station_name']=$GG[0]['s_name'];
  28. $CA['station']=intval( $GG[0]['s_id'] );
  29. $CA['platform_name']=date( "H:i:s", $R['ts']);//$GG[0]['p_name'];
  30. $CA['platform']=intval( $GG[0]['p_id'] );
  31. $CA['track_tag']=$GG[0]['short'];
  32. $CA['status']=0;
  33. $Data['actual'][] = $CA;
  34. $ALRM_STATIONS[$GG[0]['s_id']] = 4;
  35. };
  36. $Data['actual'] = array_reverse( $Data['actual'] );
  37. };
  38. $QS = "SELECT * FROM `sessions` WHERE `final`='Y' AND `status`=0 ORDER BY (`ts`*1000)+`ts_ms` DESC LIMIT 32";
  39. $RR = $DATABASE->Query( $QS );
  40. if( count( $RR ) ){
  41. $Data['expired'] = array();
  42. foreach( $RR as $R ){
  43. $CA = array();
  44. $CA['id']=intval($R['id'] );
  45. $CA['track']=intval( $R['track_id'] );
  46. $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']}";
  47. $GG = $DATABASE->Query( $QS );
  48. $CA['station_name']=$GG[0]['s_name'];
  49. $CA['platform_name']=date( "H:i:s", $R['ts']);//$GG[0]['p_name'];
  50. $CA['track_tag']=$GG[0]['short'];
  51. $CA['status']=1;
  52. $Data['expired'][] = $CA;
  53. if( !isset($ALRM_STATIONS[$GG[0]['s_id']] ) ) $ALRM_STATIONS[$GG[0]['s_id']] = 3;
  54. };
  55. $Data['expired'] = array_reverse( $Data['expired'] );
  56. };
  57. switch( $Data['VLVL'] ){
  58. case 0:{ // Map Level Monitoring
  59. // check the station/modules online statuses, check just side sessions
  60. $QS = "SELECT id FROM `metro_stations`";
  61. $RR = $DATABASE->Query( $QS );
  62. foreach( $RR as $CR ){
  63. //If station not Alarmed
  64. if( !isset($ALRM_STATIONS[$CR['id']] ) ){
  65. $ALRM_STATIONS[$CR['id']] = 1; // default Station is ok
  66. $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']}";
  67. $ZZ = $DATABASE->Query( $QS );
  68. if( count( $ZZ ) ){
  69. foreach( $ZZ as $CZ ){
  70. $QS = "SELECT `id` FROM `metro_modules` WHERE `track_id`={$CZ['id']}";
  71. $JJ = $DATABASE->Query( $QS );
  72. if( count( $JJ ) ){
  73. foreach( $JJ as $J ){
  74. //check online status of module
  75. //$QS = "SELECT
  76. };
  77. } else $ALRM_STATIONS[$CR['id']] = 2; // Has No Modules at all
  78. };
  79. } else {
  80. $ALRM_STATIONS[$CR['id']] = 0; // No Infrostructure
  81. };
  82. };
  83. };
  84. $SI = array();
  85. $SS = array();
  86. foreach( $ALRM_STATIONS as $K=>$V ){
  87. $SI[] = $K;
  88. $SS[] = $V;
  89. };
  90. $Data['station_ids'] = $SI;
  91. $Data['station_status'] = $SS;
  92. break;
  93. };
  94. case 1:{ // Station View
  95. $SSID = intval( $_POST['SSID'] );
  96. $Data['platforms'] = array();
  97. if( $SSID ){
  98. $QS = "SELECT * FROM `metro_platforms` WHERE `station_id`={$SSID}";
  99. $PL = $DATABASE->Query( $QS );
  100. foreach( $PL as $P ){
  101. $CP = array();
  102. $CP['id'] = intval( $P['id'] );
  103. $CP['status'] = 0;
  104. foreach( $Data['actual'] as $CC ) if( $CC['station'] == $SSID ) if( $CP['id'] == $CC['platform'] ) {
  105. $CP['status'] = 1;
  106. break;
  107. };
  108. $PID = $CP['id'];
  109. $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}";
  110. $RR = $DATABASE->Query( $QS );
  111. if( count( $RR ) ){
  112. $Modules = array();
  113. foreach( $RR as $CT ){
  114. $CM = intval( $CT['near_module_id'] );
  115. $LD = array();
  116. if( $CM ){
  117. $LD['id']=$CM;
  118. if( getOnlineStatus( $CM ) ){
  119. $LD['status'] = 2;
  120. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  121. $RZ = $DATABASE->Query( $QS );
  122. $MM = $RZ[0];
  123. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  124. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  125. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  126. $RZ = $DATABASE->Query( $QS );
  127. if( count( $RZ ) ){
  128. $LD['status'] = 3;
  129. $LD['session'] = intval( $RZ[0]['id'] );
  130. };
  131. } else {
  132. $LD['status'] = 1;
  133. $LD['img'] = '/style/assets/no-signal_h.png';
  134. };
  135. } else {
  136. $LD['status'] = 0;
  137. };
  138. $Modules[] = $LD;
  139. $CM = $CT['far_module_id'];
  140. $LD = array();
  141. if( $CM ){
  142. $LD['id']=$CM;
  143. if( getOnlineStatus( $CM ) ){
  144. $LD['status'] = 2;
  145. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  146. $RZ = $DATABASE->Query( $QS );
  147. $MM = $RZ[0];
  148. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  149. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  150. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  151. $RZ = $DATABASE->Query( $QS );
  152. if( count( $RZ ) ){
  153. $LD['status'] = 3;
  154. $LD['session'] = intval( $RZ[0]['id'] );
  155. };
  156. } else {
  157. $LD['status'] = 1;
  158. $LD['img'] = '/style/assets/no-signal_h.png';
  159. };
  160. } else {
  161. $LD['status'] = 0;
  162. };
  163. $Modules[] = $LD;
  164. };
  165. $CP['modules'] = $Modules;
  166. };
  167. $Data['platforms'][] = $CP;
  168. };
  169. };
  170. break;
  171. };
  172. case 2:{ //Platform View
  173. $PID = intval( $_POST['PID'] );
  174. if( $PID ){
  175. $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}";
  176. $RR = $DATABASE->Query( $QS );
  177. if( count( $RR ) ){
  178. $Modules = array();
  179. $TrainPos = 0;
  180. foreach( $RR as $CT ){
  181. $CM = intval( $CT['near_module_id'] );
  182. $LD = array();
  183. if( $CM ){
  184. $LD['id']=$CM;
  185. $MOS = getOnlineStatus( $CM );
  186. if( $MOS ){
  187. $LD['status'] = 2;
  188. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  189. $RZ = $DATABASE->Query( $QS );
  190. $MM = $RZ[0];
  191. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  192. if( $MOS == 3 ) {
  193. if( $CT['side'] == 'U' ){
  194. $TrainPos = $TrainPos | 1;
  195. } else {
  196. $TrainPos = $TrainPos | 8;
  197. };
  198. };
  199. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  200. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'";
  201. $RZ = $DATABASE->Query( $QS );
  202. if( count( $RZ ) ){
  203. $LD['status'] = 3;
  204. $LD['session'] = intval( $RZ[0]['id'] );
  205. };
  206. } else {
  207. $LD['status'] = 1;
  208. $LD['img'] = '/style/assets/no-signal_h.png';
  209. };
  210. } else {
  211. $LD['status'] = 0;
  212. };
  213. $Modules[] = $LD;
  214. $CM = $CT['far_module_id'];
  215. $LD = array();
  216. if( $CM ){
  217. $LD['id']=$CM;
  218. $MOS = getOnlineStatus( $CM );
  219. if( $MOS ){
  220. $LD['status'] = 2;
  221. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  222. $RZ = $DATABASE->Query( $QS );
  223. $MM = $RZ[0];
  224. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  225. if( $MOS == 3 ) {
  226. if( $CT['side'] == 'U' ){
  227. $TrainPos = $TrainPos | 2;
  228. } else {
  229. $TrainPos = $TrainPos | 4;
  230. };
  231. };
  232. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  233. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `final`='N'";
  234. $RZ = $DATABASE->Query( $QS );
  235. if( count( $RZ ) ){
  236. $LD['status'] = 3;
  237. $LD['session'] = intval( $RZ[0]['id'] );
  238. };
  239. } else {
  240. $LD['status'] = 1;
  241. $LD['img'] = '/style/assets/no-signal_h.png';
  242. };
  243. } else {
  244. $LD['status'] = 0;
  245. };
  246. $Modules[] = $LD;
  247. };
  248. $Data['modules'] = $Modules;
  249. $QS = "SELECT * FROM `modbus_modules` WHERE `platform_id`={$PID}";
  250. $RR = $DATABASE->Query( $QS );
  251. $Data['scada'] = array();
  252. if( count($RR) == 0 ) {
  253. $Data['scada']['status']=0;
  254. } else {
  255. $SM = $RR[0];
  256. if( $SM['wm'] == 'D' ){
  257. $Data['scada']['status']=1;
  258. } else {
  259. $SM['status'] = intval($SM['status']);
  260. $Data['scada']['status']=$SM['status']+2;
  261. if( $SM['status'] > 0 ){
  262. $CV = intval($SM['values']);
  263. $Data['scada']['A']= $CV & 0x01;
  264. $Data['scada']['B']= $CV & 0x02;
  265. $Data['scada']['C']= $CV & 0x04;
  266. $Data['scada']['D']= $CV & 0x08;
  267. };
  268. };
  269. };
  270. $Data['train']=array( 'status'=>$TrainPos );
  271. };
  272. };
  273. break;
  274. };
  275. case 3:{ // Track View
  276. $TID = intval( $_POST['TID'] );
  277. if( $TID ){
  278. $QS = "SELECT * FROM `metro_tracks` WHERE `id`={$TID}";
  279. $RR = $DATABASE->Query( $QS );
  280. if( count( $RR ) ){
  281. $CT = $RR[0];
  282. $Modules = array();
  283. $CM = intval( $CT['near_module_id'] );
  284. $LD = array();
  285. if( $CM ){
  286. $LD['id']=$CM;
  287. if( getOnlineStatus( $CM ) ){
  288. $LD['status'] = 2;
  289. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  290. $RZ = $DATABASE->Query( $QS );
  291. $MM = $RZ[0];
  292. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  293. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  294. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  295. $RZ = $DATABASE->Query( $QS );
  296. if( count( $RZ ) ){
  297. $LD['status'] = 3;
  298. $LD['session'] = intval( $RZ[0]['id'] );
  299. };
  300. } else {
  301. $LD['status'] = 1;
  302. $LD['img'] = '/style/assets/no-signal_h.png';
  303. };
  304. } else {
  305. $LD['status'] = 0;
  306. };
  307. $Modules[] = $LD;
  308. $CM = $CT['far_module_id'];
  309. $LD = array();
  310. if( $CM ){
  311. $LD['id']=$CM;
  312. if( getOnlineStatus( $CM ) ){
  313. $LD['status'] = 2;
  314. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  315. $RZ = $DATABASE->Query( $QS );
  316. $MM = $RZ[0];
  317. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  318. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  319. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  320. $RZ = $DATABASE->Query( $QS );
  321. if( count( $RZ ) ){
  322. $LD['status'] = 3;
  323. $LD['session'] = intval( $RZ[0]['id'] );
  324. };
  325. } else {
  326. $LD['status'] = 1;
  327. $LD['img'] = '/style/assets/no-signal_h.png';
  328. };
  329. } else {
  330. $LD['status'] = 0;
  331. };
  332. $Modules[] = $LD;
  333. $Data['modules'] = $Modules;
  334. };
  335. $QS="SELECT `id`, `ts` FROM `sessions` WHERE `track_id`={$TID} AND `final`='N' ORDER BY (`ts`*1000)+`ts_ms` LIMIT 1";
  336. $RR = $DATABASE->Query( $QS );
  337. if( count( $RR ) ){
  338. $Data['active_session_id']=intval( $RR[0]['id'] );
  339. //Fetch Targets
  340. $Basepath = '/lib/controller/data/reports/'.$TID.'/'.date("Y/m/d",intval( $RR[0]['ts'] ));
  341. if( file_exists( $SYSPath . $Basepath ) ){
  342. $RBASE = new SQLite_DB( $SYSPath . $Basepath .'/report.db' );
  343. $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";
  344. $RR = $RBASE->Query( $QS );
  345. $RR = array_reverse( $RR );
  346. foreach( $RR as $CR ){
  347. $CE = array();
  348. //$CE['id']=intval($CR['id']);
  349. //$CE['ts']=intval($CR['ts'])*1000+intval($CR['ts_ms']);
  350. //if( $Data['start_ts'] > $CE['ts'] ) $Data['start_ts'] = $CE['ts'];
  351. //$CE['module_id']=intval( $CR['module_id'] );
  352. $CE['az']=floatval( $CR['azimuth'] );
  353. $CE['r']=floatval( $CR['range'] );//cos( floatval( $CR['azimuth'] ) )
  354. if( $CT['side'] == 'U' ){
  355. if( $CT['near_module_id'] == intval( $CR['module_id'] ) ){
  356. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  357. } else {
  358. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  359. };
  360. } else {
  361. if( $CT['far_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. };
  367. $Data['events'][] = $CE;
  368. };
  369. };
  370. };
  371. };
  372. break;
  373. };
  374. };// Data By Level
  375. $Data['status'] = 'ok';
  376. $Data['messages'] = ob_get_clean();
  377. echo json_encode( $Data );
  378. } else {
  379. header('location: /');
  380. };
  381. ?>