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.

367 lines
14 KiB

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