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.

1379 lines
43 KiB

​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
12 months ago
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //<?php require_once('../../js_asm.php'); ?>
  2. var monitoringViewLevel = 0;
  3. var monitoringActiveSession = false;
  4. var mon_selectedEventId = 0;
  5. var mon_selectedPlatform = 0;
  6. var mon_selectedStation = 0;
  7. var mon_selectedTrack = 0;
  8. var mon_selectedModule = 0;
  9. var autoRiseEvent = true;
  10. var activeEvents = [];
  11. var expiredEvents = [];
  12. function imgLoadEvent(){
  13. alert('l c');
  14. };
  15. function createEventTagContent( a ){
  16. var gif='green_2.gif';
  17. var add=','+a.status;
  18. if( a.status == 0 ){
  19. gif='red_2.gif';
  20. };
  21. if( mon_selectedEventId == a.id ){
  22. return '<div id="event_tag_'+a.id+'"class="evt_side_tag_selected" onclick="selectEvent('+a.id+add+');"><table width="100%" border=0><tr><td colspan=2><div class="evt_side_stname">'+a.station_name+'</div></td><td width="18px"><img src="/style/assets/'+gif+'"></td></tr><tr><td><div class="evt_side_plname">'+a.platform_name+'</div></td><td colspan=2><div class="level_label_title">'+a.track_tag+'</div></td></tr></div>';
  23. };
  24. return '<div id="event_tag_'+a.id+'"class="evt_side_tag" onclick="selectEvent('+a.id+add+');"><table width="100%" border=0><tr><td colspan=2><div class="evt_side_stname">'+a.station_name+'</div></td><td width="18px"><img src="/style/assets/'+gif+'"></td></tr><tr><td><div class="evt_side_plname">'+a.platform_name+'</div></td><td colspan=2><div class="level_label_title">'+a.track_tag+'</div></td></tr></div>';
  25. };
  26. var GREEN_Icon = L.icon({
  27. iconUrl: '/style/assets/igr.png',
  28. iconSize: [44, 44],
  29. iconAnchor: [22, 22],
  30. popupAnchor: [0, -22]
  31. //shadowUrl: 'leaf-shadow.png',
  32. //shadowSize: [50, 64], // size of the shadow
  33. //shadowAnchor: [4, 62], // the same for the shadow
  34. });
  35. var BLUE_Icon = L.icon({
  36. iconUrl: '/style/assets/irs.png',
  37. iconSize: [44, 44],
  38. iconAnchor: [22, 22],
  39. popupAnchor: [0, -22]
  40. //shadowUrl: 'leaf-shadow.png',
  41. //shadowSize: [50, 64], // size of the shadow
  42. //shadowAnchor: [4, 62], // the same for the shadow
  43. });
  44. var RED_Icon = L.icon({
  45. iconUrl: '/style/assets/ira.png',
  46. iconSize: [44, 44],
  47. iconAnchor: [22, 22],
  48. popupAnchor: [0, -22]
  49. });
  50. var REDB_Icon = L.icon({
  51. iconUrl: '/style/assets/irabl.gif',
  52. iconSize: [44, 44],
  53. iconAnchor: [22, 22],
  54. popupAnchor: [0, -22]
  55. });
  56. var GREY_Icon = L.icon({
  57. iconUrl: '/style/assets/ign.png',
  58. iconSize: [44, 44],
  59. iconAnchor: [22, 22],
  60. popupAnchor: [0, -22]
  61. });
  62. var GREYN_Icon = L.icon({
  63. iconUrl: '/style/assets/ign.png',
  64. iconSize: [44, 44],
  65. iconAnchor: [22, 22],
  66. popupAnchor: [0, -22]
  67. });
  68. function makePtzMove( me ){
  69. var name = me.target.id;
  70. const myArray = name.split("_");
  71. Ext.Ajax.request({
  72. url: '/lib/controller/doModuleOperations.php',
  73. params: {
  74. UID: <?=$UserID;?>,
  75. SID: '<?=$Session;?>',
  76. OPID: 8,
  77. MID: myArray[3],
  78. MOV: myArray[2]
  79. },
  80. failure: failureAJAXFunction
  81. });
  82. };
  83. function makePtzStop( me ){
  84. var name = me.target.id;
  85. const myArray = name.split("_");
  86. Ext.Ajax.request({
  87. url: '/lib/controller/doModuleOperations.php',
  88. params: {
  89. SITE: <?=$SiteID;?>,
  90. UID: <?=$UserID;?>,
  91. SID: '<?=$Session;?>',
  92. OPID: 8,
  93. MID: myArray[3],
  94. MOV: 0
  95. },
  96. failure: failureAJAXFunction
  97. });
  98. };
  99. function makePtzHome( me ){
  100. var name = me.target.id;
  101. const myArray = name.split("_");
  102. Ext.Ajax.request({
  103. url: '/lib/controller/doModuleOperation.php',
  104. params: {
  105. SITE: <?=$SiteID;?>,
  106. UID: <?=$UserID;?>,
  107. SID: '<?=$Session;?>',
  108. OPID: 9,
  109. MID: myArray[3],
  110. MOV: 0
  111. },
  112. failure: failureAJAXFunction
  113. });
  114. };
  115. var fsDrawID = 0;
  116. function exitFullScreen( evt ){
  117. if( document.fullscreenElement ){
  118. } else {
  119. if( fsDrawID ){
  120. console.log("Leaving fullscreen mode.");
  121. };
  122. };
  123. };
  124. function fullScreen( id = '' ){
  125. if(
  126. id == '' ||
  127. document.fullscreenElement ||
  128. document.webkitFullscreenElement ||
  129. document.mozFullScreenElement ||
  130. document.msFullscreenElement
  131. ){
  132. if( document.exitFullscreen ){
  133. document.exitFullscreen();
  134. }else if( document.mozCancelFullScreen ){
  135. document.mozCancelFullScreen();
  136. }else if( document.webkitExitFullscreen ){
  137. document.webkitExitFullscreen();
  138. }else if( document.msExitFullscreen ){
  139. document.msExitFullscreen();
  140. };
  141. if( fsDrawID ){
  142. console.log('resized');
  143. };
  144. }else{
  145. var element = document.getElementById( id );
  146. if( element.requestFullscreen ){
  147. element.requestFullscreen();
  148. }else if( element.mozRequestFullScreen ){
  149. element.mozRequestFullScreen();
  150. }else if( element.webkitRequestFullscreen ){
  151. element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  152. }else if( element.msRequestFullscreen ){
  153. element.msRequestFullscreen();
  154. };
  155. };
  156. };
  157. function loadStationViewEvt( e ){
  158. loadStationView( e.target.options.mycustomid );
  159. };
  160. function loadStationView( STT, buba ){
  161. if( buba == undefined ){
  162. autoRiseEvent = false;
  163. } else {
  164. autoRiseEvent = buba;
  165. };
  166. if( mon_selectedEventId ) unselectEvent();
  167. mon_selectedStation = STT;
  168. changeContent( 1, 1, mon_selectedStation );
  169. updateUserContent();
  170. Ext.Ajax.request({
  171. url: '/lib/controller/getMonitoringStationView.php',
  172. params: {
  173. STT: mon_selectedStation,
  174. UID: <?=$UserID;?>,
  175. SID: '<?=$Session;?>'
  176. },
  177. success: function( response, opts ){
  178. var data = Ext.decode(response.responseText);
  179. if( data.status == 'ok' ){
  180. monitoringViewLevel = 1;
  181. Ext.getCmp('main_content').removeAll(true);
  182. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  183. Ext.getCmp('main_content').doLayout();
  184. if( data.pids != undefined ){
  185. if( data.pids.length > 0 ){
  186. //for( i=0; i<data.pids.length; i++ )correctPlatformView( data.pids[i] );
  187. };
  188. };
  189. fetchStatus();
  190. } else {
  191. if( data.status == 'steight' ){
  192. loadPlatformView( data.next_id );
  193. };
  194. };
  195. },
  196. failure: failureAJAXFunction
  197. });
  198. return;
  199. };
  200. function correctPlatformView( id ){
  201. var pp = Ext.getCmp('plat_panel_'+id);
  202. var pawi = pp.getWidth() / 70;
  203. var tt = document.getElementById('plat_table_'+id );
  204. if( tt != null ){
  205. tt.width = 36.5 * pawi +'px';
  206. };
  207. tt = Ext.getCmp('plat_schematics_'+id );
  208. if( tt != null ){
  209. //tt.setHeight( 18 * pawi + 2 * 56 );
  210. tt.setHeight( PanelH-130 );
  211. };
  212. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(0).custom);
  213. if( tt != null ){
  214. tt.style.width = 16 * pawi +'px';
  215. tt.style.height = 9 * pawi +'px';
  216. };
  217. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(2).custom);
  218. if( tt != null ){
  219. tt.style.width = 16 * pawi +'px';
  220. tt.style.height = 9 * pawi +'px';
  221. };
  222. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(3).custom);
  223. if( tt != null ){
  224. tt.style.width = 16 * pawi +'px';
  225. tt.style.height = 9 * pawi +'px';
  226. };
  227. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(4).custom);
  228. if( tt != null ){
  229. tt.style.width = 16 * pawi +'px';
  230. tt.style.height = 9 * pawi +'px';
  231. };
  232. var O = new Ext.Panel({
  233. renderTo: 'scada_postbox_'+id,
  234. id: 'scada_postbox_scr_'+id,
  235. height: 170,
  236. width: 36.5 * pawi,
  237. autoScroll: true,
  238. frame: false,
  239. border: false,
  240. bodyStyle: {
  241. 'background-color': '#808080'
  242. },
  243. items: [{
  244. xtype: 'panel',
  245. id: 'scada_postbox_ctx_'+id,
  246. height: 150,
  247. layout: 'hbox',
  248. layoutConfig: {
  249. align: 'stretch', // Options: 'top', 'middle', 'stretch', 'stretchmax'
  250. pack: 'start', // Options: 'start', 'center', 'end'
  251. padding: '5 5 5 5'
  252. },
  253. defaults: {
  254. flex: 1,
  255. bodyStyle: 'padding:10px',
  256. //margins: '0 5 0 5'
  257. },
  258. items: []
  259. }]
  260. });
  261. last_poster_md5 = '';
  262. /*
  263. var O = new Ext.Panel({
  264. renderTo: 'scada_postbox_'+id,
  265. width: 500,
  266. height: 150,
  267. autoScroll: true, // This enables the scrollbar on the wrapper
  268. items: [{
  269. xtype: 'panel',
  270. layout: 'hbox',
  271. // Important: Set a fixed or calculated wide width so the parent scrolls
  272. width: 1000,
  273. border: false,
  274. layoutConfig: {
  275. pack: 'start',
  276. align: 'stretch'
  277. },
  278. items: [
  279. { title: 'Panel 1', width: 300, html: 'Content 1' },
  280. { title: 'Panel 2', width: 300, html: 'Content 2' },
  281. { title: 'Panel 3', width: 400, html: 'Content 3' }
  282. ]
  283. }]
  284. });
  285. */
  286. O.doLayout();
  287. };
  288. function correctModuleView( id ){
  289. var juja = Ext.getCmp('module_panel_'+id );
  290. var pawi = juja.getWidth() / 70;
  291. var tt = Ext.getCmp('module_schematics_'+id);
  292. tt.setWidth( 20+35 * pawi );
  293. tt.setHeight( 38+19 * pawi );
  294. tt = document.getElementById('plat_video_div_'+id );
  295. tt.style.width = 32 * pawi +'px';
  296. tt.style.height = 18 * pawi +'px';
  297. pawi = Ext.getCmp('plat_video_panel_'+id);
  298. pawi.setWidth( 32+32 * pawi);
  299. pawi.setHeight( 32+ 18 * pawi);
  300. };
  301. function addSetSessionUI( session_id ){
  302. Ext.Ajax.request({
  303. url: '/lib/controller/doSessionOperations.php',
  304. params: {
  305. SESSION: session_id,
  306. OPID: 2,
  307. OPAR: 0,
  308. UID: <?=$UserID;?>,
  309. SID: '<?=$Session;?>'
  310. },
  311. success: function( response, opts ){
  312. var data = Ext.decode(response.responseText);
  313. if( data.status == 'ok' ){
  314. var tv = Ext.getCmp('trx_view');
  315. if( tv != undefined ){
  316. var tt = Ext.getCmp('sets_ui');
  317. if( tt != undefined ){
  318. tv.remove( tt );
  319. };
  320. tv.add( Ext.decode( data.content ) );
  321. tv.doLayout();
  322. };
  323. };
  324. }//,
  325. //failure: failureAJAXFunction
  326. });
  327. };
  328. function doSessionOperation( session_id, op, param, reload ){
  329. Ext.Ajax.request({
  330. url: '/lib/controller/doSessionOperations.php',
  331. params: {
  332. SESSION: session_id,
  333. OPID: op,
  334. OPAR: param,
  335. UID: <?=$UserID;?>,
  336. SID: '<?=$Session;?>'
  337. },
  338. success: function( response, opts ){
  339. var data = Ext.decode(response.responseText);
  340. if( data.status == 'ok' ){
  341. if( reload ){
  342. };
  343. };
  344. },
  345. failure: failureAJAXFunction
  346. });
  347. };
  348. function loadPlatformView( pid, buba ){
  349. if( buba == undefined ){
  350. autoRiseEvent = false;
  351. } else {
  352. autoRiseEvent = buba;
  353. };
  354. if( mon_selectedEventId ) unselectEvent( mon_selectedEventId );
  355. mon_selectedPlatform = pid;
  356. changeContent( 1, 2, pid );
  357. updateUserContent();
  358. Ext.Ajax.request({
  359. url: '/lib/controller/getMonitoringPlatformView.php',
  360. params: {
  361. PID: mon_selectedPlatform,
  362. UID: <?=$UserID;?>,
  363. SID: '<?=$Session;?>'
  364. },
  365. success: function( response, opts ){
  366. var data = Ext.decode(response.responseText);
  367. if( data.status == 'ok' ){
  368. monitoringViewLevel = 2;
  369. Ext.getCmp('main_content').removeAll(true);
  370. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  371. Ext.getCmp('main_content').doLayout();
  372. correctPlatformView( data.pid );
  373. fetchStatus();
  374. };
  375. },
  376. failure: failureAJAXFunction
  377. });
  378. return;
  379. };
  380. function loadTrackViewBySession( session_id ){
  381. autoRiseEvent = false;
  382. mSvgElements = [];
  383. Ext.Ajax.request({
  384. url: '/lib/controller/getMonitoringTrackView.php',
  385. params: {
  386. SESSION: session_id,
  387. UID: <?=$UserID;?>,
  388. SID: '<?=$Session;?>'
  389. },
  390. success: function( response, opts ){
  391. var data = Ext.decode(response.responseText);
  392. if( data.status == 'ok' ){
  393. monitoringViewLevel = 3;
  394. mon_selectedTrack = data.track_id;
  395. changeContent( 1, 3, mon_selectedTrack );
  396. updateUserContent();
  397. Ext.getCmp('main_content').removeAll(true);
  398. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  399. Ext.getCmp('main_content').doLayout();
  400. tt=document.getElementById('trx_status_txt');
  401. tt.classList.remove('static_status_text');
  402. tt.classList.add('blinking_status_text');
  403. tt.innerText = 'ACTIVE';
  404. tt=document.getElementById('trx_status_cell');
  405. tt.classList.remove('top_status_hidden');
  406. tt.classList.add('top_status_red_lbl');
  407. monitoringActiveSession = true;
  408. fetchStatus();
  409. };
  410. },
  411. failure: failureAJAXFunction
  412. });
  413. return;
  414. };
  415. function loadTrackView( tid ){
  416. autoRiseEvent = false;
  417. mon_selectedTrack = tid;
  418. changeContent( 1, 3, mon_selectedTrack );
  419. updateUserContent();
  420. mSvgElements = [];
  421. Ext.Ajax.request({
  422. url: '/lib/controller/getMonitoringTrackView.php',
  423. params: {
  424. TID: mon_selectedTrack,
  425. UID: <?=$UserID;?>,
  426. SID: '<?=$Session;?>'
  427. },
  428. success: function( response, opts ){
  429. var data = Ext.decode(response.responseText);
  430. if( data.status == 'ok' ){
  431. monitoringViewLevel = 3;
  432. mon_selectedPlatform = data.platform_id;
  433. mon_selectedStation = data.station_id;
  434. Ext.getCmp('main_content').removeAll(true);
  435. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  436. Ext.getCmp('main_content').doLayout();
  437. tt=document.getElementById('trx_status_txt');
  438. tt.innerText = 'LIVE VIEW';
  439. monitoringActiveSession = false;
  440. tt=document.getElementById('trx_status_cell');
  441. tt.classList.remove('top_status_hidden');
  442. tt.classList.add('top_status_green_lbl');
  443. fetchStatus();
  444. };
  445. },
  446. failure: failureAJAXFunction
  447. });
  448. return;
  449. };
  450. function loadModuleView( pid, mid ){
  451. autoRiseEvent = false;
  452. if( mon_selectedEventId ) unselectEvent( mon_selectedEventId );
  453. changeContent( 1, 4, pid+'-'+mid );
  454. updateUserContent();
  455. Ext.Ajax.request({
  456. url: '/lib/controller/getMonitoringModuleView.php',
  457. params: {
  458. PID: pid,
  459. MID: mid,
  460. UID: <?=$UserID;?>,
  461. SID: '<?=$Session;?>'
  462. },
  463. success: function( response, opts ){
  464. var data = Ext.decode(response.responseText);
  465. if( data.status == 'ok' ){
  466. monitoringViewLevel = 4;
  467. Ext.getCmp('main_content').removeAll(true);
  468. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  469. Ext.getCmp('main_content').doLayout();
  470. correctModuleView( mid );
  471. fetchStatus();
  472. };
  473. },
  474. failure: failureAJAXFunction
  475. });
  476. return;
  477. };
  478. function loadMapView(){
  479. autoRiseEvent = false;
  480. if( mon_selectedEventId ) unselectEvent( mon_selectedEventId );
  481. Ext.Ajax.request({
  482. url: '/lib/controller/getMonitoringMapView.php',
  483. params: {
  484. UID: <?=$UserID;?>,
  485. SID: '<?=$Session;?>'
  486. },
  487. success: function( response, opts ){
  488. var data = Ext.decode(response.responseText);
  489. if( data.status == 'ok' ){
  490. monitoringViewLevel = 0;
  491. Ext.getCmp('main_content').removeAll(true);
  492. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  493. Ext.getCmp('main_content').doLayout();
  494. };
  495. },
  496. failure: failureAJAXFunction
  497. });
  498. return;
  499. };
  500. var monitoring_map = null;
  501. var c_icon = null;
  502. var stationMarkers = [];
  503. function initMonitoringMap( map_id, x, y ){
  504. var mapLayers = [];
  505. if( monitoring_map != null ){
  506. monitoring_map.off();
  507. monitoring_map.remove();
  508. monitoring_map = null;
  509. };
  510. monitoring_map = L.map( map_id,{
  511. crs: L.CRS.Simple,
  512. attributionControl: false,
  513. preferCanvas: true,
  514. zoomControl: true,
  515. center: [x,y],
  516. zoom: 0,
  517. minZoom: -3,
  518. maxZoom: 0,
  519. keyboard: false
  520. });
  521. var bounds = [[SCHEMATIC_SET.bounds_lx,SCHEMATIC_SET.bounds_ly], [SCHEMATIC_SET.bounds_rx,SCHEMATIC_SET.bounds_ry]];
  522. var image = L.imageOverlay( SCHEMATIC_SET.layer_url, bounds ).addTo( monitoring_map );
  523. Ext.Ajax.request({
  524. url: '/lib/controller/listStations.php',
  525. params: {
  526. UID: <?=$UserID;?>,
  527. SID: '<?=$Session;?>'
  528. },
  529. success: function( response, opts ){
  530. var data = Ext.decode(response.responseText);
  531. if( data.status == 'ok' ){
  532. for( i=0; i < data.stations.length; i++ ){
  533. stationMarkers[ data.stations[i].id ] = L.marker([data.stations[i].y, data.stations[i].x], { draggable: false, icon: GREY_Icon, zIndexOffset: 1000, mycustomid: data.stations[i].id } ).addTo( monitoring_map ).on('click', loadStationViewEvt );;
  534. };
  535. };
  536. // Ready -> Start Getting data
  537. fetchStatus();
  538. },
  539. failure: failureAJAXFunction
  540. });
  541. };
  542. function getBackToMap(){
  543. autoRiseEvent = true;
  544. changeContent( 1, 0 );
  545. updateUserContent();
  546. loadMapView();
  547. };
  548. function initMonitoring( x, y ){
  549. if( tlInterval!= null ){
  550. window.clearInterval( tlInterval );
  551. tlInterval = null;
  552. timelineObj = null;
  553. };
  554. var tP = Ext.getCmp('left_side_menu');
  555. tP.removeAll( true );
  556. tP.add({
  557. layout:'vbox',
  558. frame: false,
  559. border: false,
  560. items:[{
  561. width: "100%",
  562. height: 42,
  563. html: '<div id="a_title" class="mon_side_tag">Active Alerts</div>'
  564. },{
  565. id: 'sme_inner',
  566. //layout:'vbox',
  567. width: "100%",
  568. height: PanelH/2-24,
  569. frame: false,
  570. border: false,
  571. autoScroll: true,
  572. cls: 'thin-scrollbar',//'hide-scrollbar', // Apply the CSS class
  573. items:[],
  574. listeners: {
  575. render: function(p) {
  576. p.body.on('scroll', function(e, t) {
  577. if (t.scrollTop + t.clientHeight >= t.scrollHeight) {
  578. console.log('A Scrolled to end!');
  579. // Handle reaching the bottom here
  580. };
  581. });
  582. }
  583. }
  584. },{
  585. width: "100%",
  586. height: 42,
  587. html: '<div id="e_title" class="mon_side_tag">Expired Alerts</div>'
  588. },{
  589. id: 'sme_outer',
  590. //layout:'vbox',
  591. width: "100%",
  592. height: PanelH/2-24,
  593. frame: false,
  594. border: true,
  595. autoScroll: true,
  596. cls: 'thin-scrollbar',//'hide-scrollbar', // Apply the CSS class
  597. items:[],
  598. listeners: {
  599. render: function(p) {
  600. p.body.on('scroll', function(e, t) {
  601. if (t.scrollTop + t.clientHeight >= t.scrollHeight) {
  602. console.log('E Scrolled to end!');
  603. // Handle reaching the bottom here
  604. };
  605. });
  606. }
  607. }
  608. }]
  609. });
  610. tP.doLayout();
  611. monitoringViewLevel = contentView.l[1].v;
  612. switch( monitoringViewLevel ){
  613. case 0:{
  614. loadMapView();
  615. break;
  616. };
  617. case 1:{
  618. loadStationView( parseInt( contentView.l[1].p ), autoRiseEvent );
  619. break;
  620. };
  621. case 2:{
  622. loadPlatformView( parseInt( contentView.l[1].p ), autoRiseEvent );
  623. break;
  624. };
  625. case 3:{
  626. loadTrackView( parseInt( contentView.l[1].p ), autoRiseEvent );
  627. break;
  628. };
  629. case 4:{
  630. var tA = contentView.l[1].p.split('-');
  631. a = parseInt( tA[0] );
  632. b = parseInt( tA[1] );
  633. loadModuleView( a, b );
  634. break;
  635. };
  636. case 5:{
  637. selectEvent( parseInt( contentView.l[1].p ), true );
  638. break;
  639. };
  640. };
  641. Ext.getCmp('main_content').doLayout();
  642. };
  643. var statusLTS = 0;
  644. var statusLID = 0;
  645. function manageSideTags( tag_area, buba ){
  646. var tP = Ext.getCmp( tag_area );
  647. if( tP != undefined ){
  648. if( buba != undefined ){
  649. if( buba.length ){
  650. var idx_a = 0;
  651. //alert( tag_area + ' has '+tP.items.getCount() );
  652. while( a = tP.getComponent( idx_a ) ){
  653. var f=false;
  654. for( var zz=0; zz < buba.length; zz++ ){
  655. if( a.getId() == 'tag_panel_'+buba[zz].id ){
  656. f = true;
  657. break;
  658. };
  659. };
  660. if( !f ) {
  661. tt--;
  662. tP.remove( a, true );
  663. } else idx_a++;
  664. };
  665. tP.doLayout();
  666. var aa = tP.items.getRange();
  667. var tt = aa.length;
  668. for( var zz=0; zz < buba.length; zz++ ){
  669. var f=false;
  670. for( var i=0; i < aa.length; i++ ){
  671. if( aa[i].getId() == 'tag_panel_'+buba[zz].id ){
  672. f = true;
  673. break;
  674. };
  675. };
  676. if( !f ){
  677. tP.insert( 0,{
  678. id: 'tag_panel_'+buba[zz].id,
  679. width: "100%",
  680. html: createEventTagContent( buba[zz] )
  681. });
  682. tt++;
  683. };
  684. if( tt > 32 ){
  685. tP.remove( aa[31], true );
  686. tt--;
  687. };
  688. };
  689. if( tag_area == 'sme_inner' ){
  690. // Active
  691. activeEvents = [];
  692. for( var zz=0; zz < buba.length; zz++ ) activeEvents[zz]={id: buba[zz].id};
  693. } else {
  694. // Expired
  695. expiredEvents = [];
  696. for( var zz=0; zz < buba.length; zz++ ) expiredEvents[zz]={id: buba[zz].id};
  697. };
  698. } else {
  699. tP.removeAll( true );
  700. if( tag_area == 'sme_inner' ){
  701. // Active
  702. activeEvents = [];
  703. } else {
  704. // Expired
  705. expiredEvents = [];
  706. };
  707. };
  708. } else {
  709. tP.removeAll( true );
  710. if( tag_area == 'sme_inner' ){
  711. // Active
  712. activeEvents = [];
  713. } else {
  714. // Expired
  715. expiredEvents = [];
  716. };
  717. };
  718. tP.doLayout();
  719. };
  720. };
  721. var mSvgElements = [];
  722. var last_poster_md5 = '';
  723. function fetchStatus(){
  724. if( tlInterval!= null ){
  725. window.clearTimeout( tlInterval );
  726. tlInterval = null;
  727. };
  728. switch(monitoringViewLevel){
  729. case 0:{
  730. var ll = monitoring_map.getCenter();
  731. CX = ll.lat;
  732. CY = ll.lng;
  733. ajax_params = {
  734. VLVL: monitoringViewLevel,
  735. UID: <?=$UserID;?>,
  736. SID: '<?=$Session;?>',
  737. LTS: statusLTS,
  738. LID: statusLID,
  739. MX: CX,
  740. MY: CY
  741. };
  742. break;
  743. };
  744. case 1:{
  745. ajax_params = {
  746. VLVL: monitoringViewLevel,
  747. UID: <?=$UserID;?>,
  748. SID: '<?=$Session;?>',
  749. LTS: statusLTS,
  750. LID: statusLID,
  751. SSID: mon_selectedStation
  752. };
  753. break;
  754. };
  755. case 2:{
  756. ajax_params = {
  757. VLVL: monitoringViewLevel,
  758. UID: <?=$UserID;?>,
  759. SID: '<?=$Session;?>',
  760. PID: mon_selectedPlatform,
  761. SCM: last_poster_md5,
  762. LTS: statusLTS,
  763. LID: statusLID
  764. };
  765. break;
  766. };
  767. case 3:{
  768. ajax_params = {
  769. VLVL: monitoringViewLevel,
  770. UID: <?=$UserID;?>,
  771. SID: '<?=$Session;?>',
  772. TID: mon_selectedTrack,
  773. LTS: statusLTS,
  774. LID: statusLID
  775. };
  776. break;
  777. };
  778. case 4:{
  779. ajax_params = {
  780. VLVL: monitoringViewLevel,
  781. UID: <?=$UserID;?>,
  782. SID: '<?=$Session;?>',
  783. MID: mon_selectedModule,
  784. LTS: statusLTS,
  785. LID: statusLID
  786. };
  787. break;
  788. };
  789. case 5:{
  790. ajax_params = {
  791. VLVL: monitoringViewLevel,
  792. UID: <?=$UserID;?>,
  793. SID: '<?=$Session;?>',
  794. SESSION: mon_selectedEventId,
  795. LTS: statusLTS,
  796. LID: statusLID
  797. };
  798. break;
  799. };
  800. };
  801. Ext.Ajax.request({
  802. url: '/lib/controller/getStatus.php',
  803. params: ajax_params,
  804. success: function( response, opts ){
  805. var data = Ext.decode(response.responseText);
  806. if( data.status == 'ok' ){
  807. if( monitoringViewLevel == data.VLVL ){
  808. statusLTS = data.LTS;
  809. if( autoRiseEvent ){
  810. if( data.active_session_id != undefined ){
  811. if( data.active_session_id > 0 ){
  812. if( ssIsActive ) ssHideSS();
  813. if( data.active_session_id != mon_selectedEventId ){
  814. playSound( 1 );
  815. selectEvent( data.active_session_id, false );
  816. return;
  817. };
  818. };
  819. };
  820. };
  821. //debugger;
  822. switch( monitoringViewLevel ){
  823. case 0:{ //Map
  824. for( i=0; i < data.station_ids.length; i++ ){
  825. switch( data.station_status[i] ){
  826. case 0: {
  827. if( stationMarkers[data.station_ids[i]].options.icon != GREY_Icon ) stationMarkers[data.station_ids[i]].setIcon( GREY_Icon );
  828. break;
  829. };
  830. case 1: {
  831. if( stationMarkers[data.station_ids[i]].options.icon != BLUE_Icon ) stationMarkers[data.station_ids[i]].setIcon( BLUE_Icon );
  832. break;
  833. };
  834. case 2: {
  835. if( stationMarkers[data.station_ids[i]].options.icon != GREEN_Icon ) stationMarkers[data.station_ids[i]].setIcon( GREEN_Icon );
  836. break;
  837. };
  838. case 3: {
  839. if( ( Math.floor(Date.now() / 1000) % 2 ) == 0 ) {
  840. if( stationMarkers[data.station_ids[i]].options.icon != GREEN_Icon ) stationMarkers[data.station_ids[i]].setIcon( GREEN_Icon );
  841. } else {
  842. if( stationMarkers[data.station_ids[i]].options.icon != RED_Icon ) stationMarkers[data.station_ids[i]].setIcon( RED_Icon );
  843. };
  844. break;
  845. };
  846. case 4: {
  847. if( stationMarkers[data.station_ids[i]].options.icon != REDB_Icon ) stationMarkers[data.station_ids[i]].setIcon( REDB_Icon );
  848. break;
  849. };
  850. };
  851. };
  852. break;
  853. };
  854. case 1:{ //Platforms
  855. if( data.platforms != undefined ){
  856. for( i=0; i< data.platforms.length; i++ ){
  857. var tt = document.getElementById( 'plat_table_'+data.platforms[i].id );
  858. if( data.platforms[i].status == 1 ){
  859. if( tt.classList.contains('active_green') ){
  860. tt.classList.remove('active_green');
  861. tt.classList.add('active_red');
  862. };
  863. } else {
  864. if( tt.classList.contains('active_red') ){
  865. tt.classList.remove('active_red');
  866. tt.classList.add('active_green');
  867. };
  868. };
  869. if( data.platforms[i].modules != undefined ){
  870. for( j=0; j<data.platforms[i].modules.length; j++ ){
  871. if( data.platforms[i].modules[j].status ){
  872. var zz = document.getElementById('mod_vp_'+data.platforms[i].modules[j].id );
  873. if( zz.style.backgroundImage != 'url("'+data.platforms[i].modules[j].img+'")' ){
  874. zz.style.backgroundImage = 'url("'+data.platforms[i].modules[j].img+'")';
  875. };
  876. };
  877. };
  878. };
  879. };
  880. };
  881. break;
  882. };
  883. case 2:{ // Platform
  884. if( data.modules != undefined ){
  885. for( var i=0; i< data.modules.length; i++){
  886. if( data.modules[i].status > 0 ){
  887. var tt = document.getElementById('plat_video_'+mon_selectedPlatform+'_'+data.modules[i].id );
  888. if( tt != undefined ){
  889. //if( tt.src != data.modules[i].img ) tt.src = data.modules[i].img;
  890. };
  891. tt = document.getElementById('plat_status_'+mon_selectedPlatform+'_'+data.modules[i].id );
  892. if( tt != undefined ){
  893. switch( data.modules[i].status ){
  894. case 1: tt.innerHTML='<img src="/style/assets/bul_gray.png">'; break;
  895. case 2: tt.innerHTML='<img src="/style/assets/bul_green.png">'; break;
  896. case 3: tt.innerHTML='<img src="/style/assets/bul_green_rst.png">'; break;
  897. };
  898. };
  899. };
  900. };
  901. };
  902. if( data.scada != undefined ){
  903. var tt = document.getElementById('scada_status');
  904. switch( data.scada.status ){
  905. case 0:{
  906. tt.innerHTML='<?=$Labels->GetLabel('_NOT_ASSIGNED_');?>';
  907. tt.setAttribute('class', 'mon_scada_status_tag_na');
  908. tt = document.getElementById('scada_a');
  909. tt.setAttribute('class', 'mon_scada_head');
  910. tt = document.getElementById('scada_b');
  911. tt.setAttribute('class', 'mon_scada_head');
  912. tt = document.getElementById('scada_c');
  913. tt.setAttribute('class', 'mon_scada_head');
  914. tt = document.getElementById('scada_d');
  915. tt.setAttribute('class', 'mon_scada_head');
  916. break;
  917. };
  918. case 1:{
  919. tt.innerHTML='<?=$Labels->GetLabel('__DISABLED__');?>';
  920. tt.setAttribute('class', 'mon_scada_status_tag_na');
  921. tt = document.getElementById('scada_a');
  922. tt.setAttribute('class', 'mon_scada_head');
  923. tt = document.getElementById('scada_b');
  924. tt.setAttribute('class', 'mon_scada_head');
  925. tt = document.getElementById('scada_c');
  926. tt.setAttribute('class', 'mon_scada_head');
  927. tt = document.getElementById('scada_d');
  928. tt.setAttribute('class', 'mon_scada_head');
  929. break;
  930. };
  931. case 2:{//offline
  932. tt.innerHTML='<?=$Labels->GetLabel('__OFFLINE__');?>';
  933. tt.setAttribute('class', 'mon_scada_status_tag_na');
  934. tt = document.getElementById('scada_a');
  935. tt.setAttribute('class', 'mon_scada_head');
  936. tt = document.getElementById('scada_b');
  937. tt.setAttribute('class', 'mon_scada_head');
  938. tt = document.getElementById('scada_c');
  939. tt.setAttribute('class', 'mon_scada_head');
  940. tt = document.getElementById('scada_d');
  941. tt.setAttribute('class', 'mon_scada_head');
  942. break;
  943. };
  944. case 3:{//online
  945. tt.innerHTML='<?=$Labels->GetLabel('__ONLINE__');?>';
  946. tt.setAttribute('class', 'mon_scada_status_tag_ok');
  947. tt = document.getElementById('scada_a');
  948. if( data.scada.A ){
  949. tt.setAttribute('class', 'mon_scada_head_active');
  950. } else {
  951. tt.setAttribute('class', 'mon_scada_head_ok');
  952. };
  953. tt = document.getElementById('scada_b');
  954. if( data.scada.B ){
  955. tt.setAttribute('class', 'mon_scada_head_active');
  956. } else {
  957. tt.setAttribute('class', 'mon_scada_head_ok');
  958. };
  959. tt = document.getElementById('scada_c');
  960. if( data.scada.C ){
  961. tt.setAttribute('class', 'mon_scada_head_active');
  962. } else {
  963. tt.setAttribute('class', 'mon_scada_head_ok');
  964. };
  965. tt = document.getElementById('scada_d');
  966. if( data.scada.D ){
  967. tt.setAttribute('class', 'mon_scada_head_active');
  968. } else {
  969. tt.setAttribute('class', 'mon_scada_head_ok');
  970. };
  971. break;
  972. };
  973. };
  974. };
  975. if( data.events != undefined ){
  976. var sid = data.events.length - 1;
  977. if( sid > -1 ){
  978. for( var i=0; i< max_grad_levels; i++ ){
  979. var cid = sid-i;
  980. var csize = getSize( i );
  981. //debugger;
  982. if( typeof mSvgElements[i] === 'undefined') {
  983. if( cid > -1 ){
  984. var svgns = "http://www.w3.org/2000/svg";
  985. mSvgElements[i] = document.createElementNS(svgns, 'rect');
  986. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  987. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  988. mSvgElements[i].setAttribute('height', ''+csize);
  989. mSvgElements[i].setAttribute('width', ''+csize);
  990. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i));
  991. var tt = document.getElementById('svgTrackMap');
  992. var zz = document.getElementById('scheme_anch');
  993. tt.insertBefore( mSvgElements[i], zz );
  994. //document.getElementById('svgTrackMap').appendChild(this.mSvgElements[i]);
  995. };
  996. } else {
  997. if( cid > -1 ){
  998. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  999. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  1000. mSvgElements[i].setAttribute('height', ''+csize);
  1001. mSvgElements[i].setAttribute('width', ''+csize);
  1002. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i) );
  1003. } else {
  1004. mSvgElements[i].setAttribute('fill', '#FF000000');
  1005. };
  1006. };
  1007. };
  1008. } else
  1009. for( var i=0; i< max_grad_levels; i++ )
  1010. if( typeof mSvgElements[i] !== 'undefined') mSvgElements[i].setAttribute('fill', '#FF000000');
  1011. };
  1012. if( data.poster != undefined ){
  1013. if( last_poster_md5 != data.poster_md5 ){
  1014. last_poster_md5 = data.poster_md5;
  1015. var jj = Ext.getCmp( 'scada_postbox_ctx_'+mon_selectedPlatform );
  1016. if( jj != undefined ){
  1017. jj.removeAll();
  1018. for( i = 0; i < data.poster.length; i++){
  1019. var nc = Ext.decode( data.poster[i].content );
  1020. jj.add( nc );
  1021. }
  1022. jj.setWidth( data.poster.length * 301 );
  1023. jj = Ext.getCmp( 'scada_postbox_scr_'+mon_selectedPlatform );
  1024. if( jj != undefined ) jj.doLayout();
  1025. };
  1026. };
  1027. };
  1028. break;
  1029. };
  1030. case 3:{ // Track
  1031. if( data.active_session_id != undefined ){
  1032. if( data.active_session_id > 0 ){
  1033. if( mon_selectedEventId != data.active_session_id ){
  1034. mon_selectedEventId = data.active_session_id;
  1035. monitoringActiveSession = true;
  1036. for( var zz=0; zz< activeEvents.length; zz++ ){
  1037. var tP = document.getElementById('event_tag_'+activeEvents[zz].id );
  1038. if( tP != undefined ){
  1039. tP.className ='';
  1040. if( activeEvents[zz].id == mon_selectedEventId ){
  1041. tP.classList.add("evt_side_tag_selected");
  1042. } else {
  1043. tP.classList.add("evt_side_tag");
  1044. };
  1045. };
  1046. };
  1047. addSetSessionUI( mon_selectedEventId );
  1048. tt=document.getElementById('trx_status_txt');
  1049. tt.classList.remove('static_status_text');
  1050. tt.classList.add('blinking_status_text');
  1051. tt.innerText = 'ACTIVE';
  1052. tt=document.getElementById('trx_status_cell');
  1053. tt.classList.remove('top_status_hidden');
  1054. tt.classList.remove('top_status_green_lbl');
  1055. tt.classList.add('top_status_red_lbl');
  1056. };
  1057. } else {
  1058. if( mon_selectedEventId ){
  1059. mon_selectedEventId = 0;
  1060. monitoringActiveSession = false;
  1061. tt=document.getElementById('trx_status_txt');
  1062. tt.classList.remove('blinking_status_text');
  1063. tt.classList.add('static_status_text');
  1064. tt.innerText = 'LIVE VEW';
  1065. tt=document.getElementById('trx_status_cell');
  1066. tt.classList.remove('top_status_hidden');
  1067. tt.classList.remove('top_status_red_lbl');
  1068. tt.classList.add('top_status_green_lbl');
  1069. };
  1070. };
  1071. };
  1072. if( data.modules != undefined ){
  1073. for( var i=0; i< data.modules.length; i++){
  1074. if( data.modules[i].status > 0 ){
  1075. var tt = document.getElementById('plat_video_img_'+data.modules[i].id );
  1076. if( tt != undefined ){
  1077. if( tt.src != data.modules[i].img ) tt.src = data.modules[i].img;
  1078. };
  1079. //tt = document.getElementById('plat_status_'+mon_selectedPlatform+'_'+data.modules[i].id );
  1080. tt = document.getElementById('cam_ctrl_'+data.modules[i].id );
  1081. if( tt != undefined ){
  1082. if( data.modules[i].status > 1 ) {
  1083. if( tt.style.display != 'block' )tt.style.display = 'block';
  1084. } else {
  1085. if( tt.style.display != 'none' )tt.style.display = 'none';
  1086. };
  1087. };
  1088. };
  1089. };
  1090. };
  1091. if( data.events != undefined ){
  1092. var sid = data.events.length - 1;
  1093. if( sid > -1 ){
  1094. for( var i=0; i< max_grad_levels; i++ ){
  1095. var cid = sid-i;
  1096. var csize = getSize( i );
  1097. //debugger;
  1098. if( typeof mSvgElements[i] === 'undefined') {
  1099. if( cid > -1 ){
  1100. var svgns = "http://www.w3.org/2000/svg";
  1101. mSvgElements[i] = document.createElementNS(svgns, 'rect');
  1102. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  1103. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  1104. mSvgElements[i].setAttribute('height', ''+csize);
  1105. mSvgElements[i].setAttribute('width', ''+csize);
  1106. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i));
  1107. var tt = document.getElementById('svgTrackMap');
  1108. var zz = document.getElementById('scheme_anch');
  1109. tt.insertBefore( mSvgElements[i], zz );
  1110. //document.getElementById('svgTrackMap').appendChild(this.mSvgElements[i]);
  1111. };
  1112. } else {
  1113. if( cid > -1 ){
  1114. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  1115. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  1116. mSvgElements[i].setAttribute('height', ''+csize);
  1117. mSvgElements[i].setAttribute('width', ''+csize);
  1118. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i) );
  1119. } else {
  1120. mSvgElements[i].setAttribute('fill', '#FF000000');
  1121. };
  1122. };
  1123. };
  1124. } else
  1125. for( var i=0; i< max_grad_levels; i++ )
  1126. if( typeof mSvgElements[i] !== 'undefined') mSvgElements[i].setAttribute('fill', '#FF000000');
  1127. };
  1128. if( data.scada != undefined ){
  1129. };
  1130. break;
  1131. };
  1132. };
  1133. var tt = document.getElementById('a_title');
  1134. if( tt != null ){
  1135. if( data.actual_count > 0 ){
  1136. tt.innerHTML = 'Active Alerts<br/>['+data.actual_count+']';
  1137. } else {
  1138. tt.innerHTML = 'Active Alerts';
  1139. };
  1140. manageSideTags('sme_inner', data.actual );
  1141. };
  1142. if( tt != null ){
  1143. tt = document.getElementById('e_title');
  1144. if( data.expired_count > 0 ){
  1145. tt.innerHTML = 'Expired Alerts<br/>['+data.expired_count+']';
  1146. } else {
  1147. tt.innerHTML = 'Expired Alerts';
  1148. };
  1149. manageSideTags('sme_outer', data.expired );
  1150. };
  1151. };
  1152. };
  1153. if( contentView.l[0].v == 0 ){
  1154. tlInterval = window.setTimeout( fetchStatus, 333, selectedSite );
  1155. };
  1156. },
  1157. failure: failureAJAXFunction
  1158. });
  1159. };
  1160. function selectEvent( ii, bb ){
  1161. mon_selectedEventId = ii;
  1162. if( tlInterval!= null ){
  1163. window.clearTimeout( tlInterval );
  1164. tlInterval = null;
  1165. };
  1166. for( var zz=0; zz< expiredEvents.length; zz++ ){
  1167. var tP = document.getElementById('event_tag_'+expiredEvents[zz].id );
  1168. if( tP != undefined ){
  1169. tP.className ='';
  1170. if( expiredEvents[zz].id == mon_selectedEventId ){
  1171. monitoringActiveSession = false;
  1172. tP.classList.add("evt_side_tag_selected");
  1173. } else {
  1174. tP.classList.add("evt_side_tag");
  1175. };
  1176. };
  1177. };
  1178. for( var zz=0; zz< activeEvents.length; zz++ ){
  1179. var tP = document.getElementById('event_tag_'+activeEvents[zz].id );
  1180. if( tP != undefined ){
  1181. tP.className ='';
  1182. if( activeEvents[zz].id == mon_selectedEventId ){
  1183. monitoringActiveSession = true;
  1184. tP.classList.add("evt_side_tag_selected");
  1185. } else {
  1186. tP.classList.add("evt_side_tag");
  1187. };
  1188. };
  1189. };
  1190. if( bb ){
  1191. loadMonitoringSessionView( ii );
  1192. } else {
  1193. loadTrackViewBySession( ii );
  1194. };
  1195. };
  1196. function setSessionStatus( a , b, autoremove ){
  1197. if( autoremove ) alert( 'Autoremove' );
  1198. Ext.Ajax.request({
  1199. url: '/lib/controller/doSessionOperations.php',
  1200. params: {
  1201. SESSION: a,
  1202. OPID: 2,
  1203. OPAR: b,
  1204. UID: <?=$UserID;?>,
  1205. SID: '<?=$Session;?>'
  1206. },
  1207. success: function( response, opts ){
  1208. var data = Ext.decode(response.responseText);
  1209. if( data.status == 'ok' ){
  1210. var tv = Ext.getCmp('trx_view');
  1211. if( tv != undefined ){
  1212. var tt = Ext.getCmp('sets_ui');
  1213. if( tt != undefined ){
  1214. tv.remove( tt );
  1215. };
  1216. tv.add( Ext.decode( data.content ) );
  1217. tv.doLayout();
  1218. };
  1219. };
  1220. },
  1221. failure: failureAJAXFunction
  1222. });
  1223. };
  1224. function unselectEvent( ii ){
  1225. mon_selectedEventId = 0;
  1226. for( var zz=0; zz< activeEvents.length; zz++ ){
  1227. var tP = document.getElementById('event_tag_'+activeEvents[zz].id );
  1228. if( tP != undefined ){
  1229. tP.className ='';
  1230. tP.classList.add("evt_side_tag");
  1231. };
  1232. };
  1233. for( var zz=0; zz< expiredEvents.length; zz++ ){
  1234. var tP = document.getElementById('event_tag_'+expiredEvents[zz].id );
  1235. if( tP != undefined ){
  1236. tP.className ='';
  1237. tP.classList.add("evt_side_tag");
  1238. };
  1239. };
  1240. };
  1241. function loadMonitoringSessionView( session_id ){
  1242. autoRiseEvent = false;
  1243. mon_selectedEventId = session_id;
  1244. changeContent( 1, 5, mon_selectedEventId );
  1245. updateUserContent();
  1246. Ext.Ajax.request({
  1247. url: '/lib/controller/getMonitoringSessionView.php',
  1248. params: {
  1249. SESSION: mon_selectedEventId,
  1250. UID: <?=$UserID;?>,
  1251. SID: '<?=$Session;?>'
  1252. },
  1253. success: function( response, opts ){
  1254. var data = Ext.decode(response.responseText);
  1255. if( data.status == 'ok' ){
  1256. monitoringViewLevel = 5;
  1257. if( mSesPlay!= null ) {
  1258. mSesPlay.dispose();
  1259. mSesPlay = null;
  1260. };
  1261. Ext.getCmp('main_content').removeAll(true);
  1262. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  1263. Ext.getCmp('main_content').doLayout();
  1264. tt=document.getElementById('trx_status_txt');
  1265. //tt.classList.remove('static_status_text');
  1266. //tt.classList.add('blinking_status_text');
  1267. tt.innerText = 'EXPIRED';
  1268. tt=document.getElementById('trx_status_cell');
  1269. tt.classList.remove('top_status_hidden');
  1270. tt.classList.remove('top_status_red_lbl');
  1271. tt.classList.remove('top_status_green_lbl');
  1272. tt.classList.add('top_status_orange_lbl');
  1273. mSesPlay = new argusSessionPlayer( mon_selectedEventId, true );
  1274. //mSesPlay.triggerPlay();
  1275. fetchStatus();
  1276. };
  1277. },
  1278. failure: failureAJAXFunction
  1279. });
  1280. };
  1281. var peerConnections = [];
  1282. async function startWhepClient( video_id, ip_address, stream_id ){
  1283. const STREAM_PATH = stream_id; // 'stream_3'; // Replace with your stream name
  1284. const MEDIAMTX_URL = 'http://'+ip_address+':8889/'+STREAM_PATH+'/whep';
  1285. // 1. Initialize the RTCPeerConnection
  1286. //if( peerConnection == null ){
  1287. const peerConnection = new RTCPeerConnection({
  1288. iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] // Standard STUN for local/NAT routing
  1289. });
  1290. peerConnections[video_id] = peerConnection;
  1291. //};
  1292. // 2. Set up media placeholders (MediaMTX requires transceivers before the offer)
  1293. peerConnection.addTransceiver('video', { direction: 'recvonly' });
  1294. //peerConnection.addTransceiver('audio', { direction: 'recvonly' });
  1295. // 3. Handle incoming stream track
  1296. peerConnection.ontrack = (event) => {
  1297. var videoElement = document.getElementById( video_id );
  1298. if (videoElement && event.streams[0]) {
  1299. videoElement.srcObject = event.streams[0];
  1300. }
  1301. };
  1302. // 4. Create and set Local Description (Offer)
  1303. const offer = await peerConnection.createOffer();
  1304. await peerConnection.setLocalDescription(offer);
  1305. // 5. Send Offer to MediaMTX via HTTP POST
  1306. const response = await fetch(MEDIAMTX_URL, {
  1307. method: 'POST',
  1308. headers: { 'Content-Type': 'application/sdp' },
  1309. body: peerConnection.localDescription.sdp
  1310. });
  1311. if (!response.ok) {
  1312. throw new Error(`MediaMTX WHEP signaling failed: ${response.statusText}`);
  1313. }
  1314. // 6. Set Remote Description (Answer) received from MediaMTX
  1315. const answerSdp = await response.text();
  1316. await peerConnection.setRemoteDescription(new RTCSessionDescription({
  1317. type: 'answer',
  1318. sdp: answerSdp
  1319. }));
  1320. };
  1321. function stopWhepClient( video_id, stream_id ){
  1322. if( peerConnections[video_id] != undefined ){
  1323. peerConnections[video_id].getReceivers().forEach( receiver => {
  1324. if( receiver.track ){
  1325. receiver.track.stop();
  1326. }
  1327. });
  1328. peerConnections[video_id].close();
  1329. delete( peerConnections[video_id] );
  1330. var videoElement = document.getElementById( video_id );
  1331. videoElement.srcObject = null;
  1332. videoElement.load();
  1333. };
  1334. }