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.

261 lines
9.9 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. $LID = intval( $_POST['LID'] );
  12. if( $Data['LTS'] == 0 ) $Data['LTS'] = floor(microtime(true) * 1000);//time();
  13. $ALRM_STATIONS = array();
  14. //Data for Side Panel
  15. $QS = "SELECT * FROM `sessions` WHERE `final`='N' ORDER BY (`ts`*1000)+`ts_ms` DESC LIMIT 32";
  16. $RR = $DATABASE->Query( $QS );
  17. if( count( $RR ) ){
  18. $Data['actual'] = array();
  19. foreach( $RR as $R ){
  20. $CA = array();
  21. $CA['id']=intval($R['id'] );
  22. $CA['track']=intval( $R['track_id'] );
  23. $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']}";
  24. $GG = $DATABASE->Query( $QS );
  25. $CA['station_name']=$GG[0]['s_name'];
  26. $CA['platform_name']=$GG[0]['p_name'];
  27. $CA['track_tag']=$GG[0]['short'];
  28. $CA['status']=0;
  29. $Data['actual'][] = $CA;
  30. $ALRM_STATIONS[$GG[0]['s_id']] = 4;
  31. };
  32. };
  33. $QS = "SELECT * FROM `sessions` WHERE `final`='Y' AND `status`=0 ORDER BY (`ts`*1000)+`ts_ms` DESC LIMIT 32";
  34. $RR = $DATABASE->Query( $QS );
  35. if( count( $RR ) ){
  36. $Data['expired'] = array();
  37. foreach( $RR as $R ){
  38. $CA = array();
  39. $CA['id']=intval($R['id'] );
  40. $CA['track']=intval( $R['track_id'] );
  41. $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']}";
  42. $GG = $DATABASE->Query( $QS );
  43. $CA['station_name']=$GG[0]['s_name'];
  44. $CA['platform_name']=$GG[0]['p_name'];
  45. $CA['track_tag']=$GG[0]['short'];
  46. $CA['status']=1;
  47. $Data['expired'][] = $CA;
  48. if( !isset($ALRM_STATIONS[$GG[0]['s_id']] ) ) $ALRM_STATIONS[$GG[0]['s_id']] = 3;
  49. };
  50. };
  51. switch( $Data['VLVL'] ){
  52. case 0:{ // Map Level Monitoring
  53. // check the station/modules online statuses, check just side sessions
  54. $QS = "SELECT id FROM `metro_stations`";
  55. $RR = $DATABASE->Query( $QS );
  56. foreach( $RR as $CR ){
  57. //If station not Alarmed
  58. if( !isset($ALRM_STATIONS[$CR['id']] ) ){
  59. $ALRM_STATIONS[$CR['id']] = 1; // default Station is ok
  60. $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']}";
  61. $ZZ = $DATABASE->Query( $QS );
  62. if( count( $ZZ ) ){
  63. foreach( $ZZ as $CZ ){
  64. $QS = "SELECT `id` FROM `metro_modules` WHERE `track_id`={$CZ['id']}";
  65. $JJ = $DATABASE->Query( $QS );
  66. if( count( $JJ ) ){
  67. foreach( $JJ as $J ){
  68. //check online status of module
  69. //$QS = "SELECT
  70. };
  71. } else $ALRM_STATIONS[$CR['id']] = 2; // Has No Modules at all
  72. };
  73. } else {
  74. $ALRM_STATIONS[$CR['id']] = 0; // No Infrostructure
  75. };
  76. };
  77. };
  78. $SI = array();
  79. $SS = array();
  80. foreach( $ALRM_STATIONS as $K=>$V ){
  81. $SI[] = $K;
  82. $SS[] = $V;
  83. };
  84. $Data['station_ids'] = $SI;
  85. $Data['station_status'] = $SS;
  86. break;
  87. };
  88. case 2:{ //Platform View
  89. $PID = intval( $_POST['PID'] );
  90. if( $PID ){
  91. $QS = "SELECT * FROM `metro_tracks` WHERE `platform_id`={$PID}";
  92. $RR = $DATABASE->Query( $QS );
  93. if( count( $RR ) ){
  94. $Modules = array();
  95. foreach( $RR as $CT ){
  96. $CM = intval( $CT['near_module_id'] );
  97. $LD = array();
  98. if( $CM ){
  99. $LD['id']=$CM;
  100. if( getOnlineStatus( $CM ) ){
  101. $LD['status'] = 2;
  102. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  103. $RZ = $DATABASE->Query( $QS );
  104. $MM = $RZ[0];
  105. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  106. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  107. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  108. $RZ = $DATABASE->Query( $QS );
  109. if( count( $RZ ) ){
  110. $LD['status'] = 3;
  111. $LD['session'] = intval( $RZ[0]['id'] );
  112. };
  113. } else {
  114. $LD['status'] = 1;
  115. $LD['img'] = '/style/assets/no-signal_h.png';
  116. };
  117. } else {
  118. $LD['status'] = 0;
  119. };
  120. $Modules[] = $LD;
  121. $CM = $CT['far_module_id'];
  122. $LD = array();
  123. if( $CM ){
  124. $LD['id']=$CM;
  125. if( getOnlineStatus( $CM ) ){
  126. $LD['status'] = 2;
  127. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  128. $RZ = $DATABASE->Query( $QS );
  129. $MM = $RZ[0];
  130. //$LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  131. $LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  132. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  133. $RZ = $DATABASE->Query( $QS );
  134. if( count( $RZ ) ){
  135. $LD['status'] = 3;
  136. $LD['session'] = intval( $RZ[0]['id'] );
  137. };
  138. } else {
  139. $LD['status'] = 1;
  140. $LD['img'] = '/style/assets/no-signal_h.png';
  141. };
  142. } else {
  143. $LD['status'] = 0;
  144. };
  145. $Modules[] = $LD;
  146. };
  147. $Data['modules'] = $Modules;
  148. };
  149. };
  150. break;
  151. };
  152. case 3:{ // Track View
  153. $TID = intval( $_POST['TID'] );
  154. if( $TID ){
  155. $QS = "SELECT * FROM `metro_tracks` WHERE `id`={$TID}";
  156. $RR = $DATABASE->Query( $QS );
  157. if( count( $RR ) ){
  158. $CT = $RR[0];
  159. $Modules = array();
  160. $CM = intval( $CT['near_module_id'] );
  161. $LD = array();
  162. if( $CM ){
  163. $LD['id']=$CM;
  164. if( getOnlineStatus( $CM ) ){
  165. $LD['status'] = 2;
  166. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  167. $RZ = $DATABASE->Query( $QS );
  168. $MM = $RZ[0];
  169. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  170. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  171. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  172. $RZ = $DATABASE->Query( $QS );
  173. if( count( $RZ ) ){
  174. $LD['status'] = 3;
  175. $LD['session'] = intval( $RZ[0]['id'] );
  176. };
  177. } else {
  178. $LD['status'] = 1;
  179. $LD['img'] = '/style/assets/no-signal_h.png';
  180. };
  181. } else {
  182. $LD['status'] = 0;
  183. };
  184. $Modules[] = $LD;
  185. $CM = $CT['far_module_id'];
  186. $LD = array();
  187. if( $CM ){
  188. $LD['id']=$CM;
  189. if( getOnlineStatus( $CM ) ){
  190. $LD['status'] = 2;
  191. $QS = "SELECT * FROM `metro_modules` WHERE `id`={$CM}";
  192. $RZ = $DATABASE->Query( $QS );
  193. $MM = $RZ[0];
  194. $LD['img'] = "http://{$MM['IP4']}/video_feed/stream?id={$MM['cam_stream']}";
  195. //$LD['img'] = "http://{$MM['IP4']}/video_feed/preview?id={$MM['cam_stream']}";
  196. $QS = "SELECT `id` FROM `sessions` WHERE `track_id`={$CT['id']} AND `status`=0";
  197. $RZ = $DATABASE->Query( $QS );
  198. if( count( $RZ ) ){
  199. $LD['status'] = 3;
  200. $LD['session'] = intval( $RZ[0]['id'] );
  201. };
  202. } else {
  203. $LD['status'] = 1;
  204. $LD['img'] = '/style/assets/no-signal_h.png';
  205. };
  206. } else {
  207. $LD['status'] = 0;
  208. };
  209. $Modules[] = $LD;
  210. $Data['modules'] = $Modules;
  211. };
  212. $QS="SELECT `id`, `ts` FROM `sessions` WHERE `track_id`={$TID} AND `final`='N' ORDER BY (`ts`*1000)+`ts_ms` LIMIT 1";
  213. $RR = $DATABASE->Query( $QS );
  214. if( count( $RR ) ){
  215. $Data['active_session_id']=intval( $RR[0]['id'] );
  216. //Fetch Targets
  217. $Basepath = '/lib/controller/data/reports/'.$TID.'/'.date("Y/m/d",intval( $RR[0]['ts'] ));
  218. if( file_exists( $SYSPath . $Basepath ) ){
  219. $RBASE = new SQLite_DB( $SYSPath . $Basepath .'/report.db' );
  220. $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";
  221. $RR = $RBASE->Query( $QS );
  222. $RR = array_reverse( $RR );
  223. foreach( $RR as $CR ){
  224. $CE = array();
  225. //$CE['id']=intval($CR['id']);
  226. //$CE['ts']=intval($CR['ts'])*1000+intval($CR['ts_ms']);
  227. //if( $Data['start_ts'] > $CE['ts'] ) $Data['start_ts'] = $CE['ts'];
  228. //$CE['module_id']=intval( $CR['module_id'] );
  229. $CE['az']=floatval( $CR['azimuth'] );
  230. $CE['r']=floatval( $CR['range'] );//cos( floatval( $CR['azimuth'] ) )
  231. if( $CT['side'] == 'U' ){
  232. if( $CT['near_module_id'] == intval( $CR['module_id'] ) ){
  233. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  234. } else {
  235. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?1.0:-1.0) * floatval( $CR['range'] ) / 70.0;
  236. };
  237. } else {
  238. if( $CT['far_module_id'] == intval( $CR['module_id'] ) ){
  239. $CE['x'] = 75.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  240. } else {
  241. $CE['x'] = 25.0+25.0 *(($CR['azimuth']>90 && $CR['azimuth'] < 210)?-1.0:1.0) * floatval( $CR['range'] ) / 70.0;
  242. };
  243. };
  244. $Data['events'][] = $CE;
  245. };
  246. };
  247. };
  248. };
  249. break;
  250. };
  251. };// Data By Level
  252. $Data['status'] = 'ok';
  253. $Data['messages'] = ob_get_clean();
  254. echo json_encode( $Data );
  255. } else {
  256. header('location: /');
  257. };
  258. ?>