Web Interface For Lite Argus Control modules
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.

992 lines
31 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //<?php require_once('../../js_asm.php'); ?>
  2. function getWidth() {
  3. return Math.max(
  4. document.body.scrollWidth,
  5. document.documentElement.scrollWidth,
  6. document.body.offsetWidth,
  7. document.documentElement.offsetWidth,
  8. document.documentElement.clientWidth
  9. );
  10. }
  11. function getHeight() {
  12. return Math.max(
  13. document.body.scrollHeight,
  14. document.documentElement.scrollHeight,
  15. document.body.offsetHeight,
  16. document.documentElement.offsetHeight,
  17. document.documentElement.clientHeight
  18. );
  19. }
  20. function trace( message ){
  21. //if( console ){
  22. console.log( message );
  23. //};
  24. }
  25. //https://www.pornhub.com/view_video.php?viewkey=ph5a8a095f04fc7
  26. function makeFullScreen() {
  27. var divObj = document.getElementById("theImage");
  28. //Use the specification method before using prefixed versions
  29. if (divObj.requestFullscreen) {
  30. divObj.requestFullscreen();
  31. } else if (divObj.msRequestFullscreen) {
  32. divObj.msRequestFullscreen();
  33. } else if (divObj.mozRequestFullScreen) {
  34. divObj.mozRequestFullScreen();
  35. } else if (divObj.webkitRequestFullscreen) {
  36. divObj.webkitRequestFullscreen();
  37. } else {
  38. console.log("Fullscreen API is not supported");
  39. };
  40. }
  41. var ScreanWidth = getWidth();
  42. trace('Width: ' + getWidth() );
  43. trace('Height: ' + getHeight() );
  44. var panelWidth = ScreanWidth*0.9;
  45. var iW = <?=getPictureWidth();?>;
  46. var iH = <?=getPictureHeight();?>;
  47. var imgWidth = panelWidth - 16;
  48. var imgHeight = ( imgWidth / iW ) * iH;
  49. var GEWindow = null;
  50. var VCWindow = null;
  51. var DCWindow = null;
  52. var DBWindow = null;
  53. var BG_Array = null;
  54. var VideoWindow = null;
  55. var VideoPlayer = null;
  56. var VideoIsPlaying = false;
  57. var VideoIsLooped = false;
  58. var VideoFlash = null;
  59. //https://www.w3schools.com/graphics/canvas_drawing.asp
  60. var updateInterval;
  61. var lastId = -1;
  62. var DetectorEnabled = false;
  63. var SelectedEvent = null;
  64. var VideoPosInterval = null;
  65. var Settings_SST = 1212;
  66. var Settings_OFFSET = 1212;
  67. var Settings_MAXRANGE = 1212;
  68. var Settings_L2L = 1212;
  69. var Settings_MINSPEED = 1212;
  70. var EvtGroupRecord = Ext.data.Record.create([
  71. 'id',
  72. 'ts',
  73. 'type',
  74. 'cnt',
  75. 'has_image',
  76. 'video'
  77. ]);
  78. var EvtListRecord = Ext.data.Record.create([
  79. 'id',
  80. 'ts',
  81. 'type',
  82. 'range',
  83. 'speed',
  84. 'f_lrf',
  85. 's_lrf'
  86. ]);
  87. var EvtListDataStore = new Ext.data.Store({
  88. reader: new Ext.data.JsonReader({
  89. // The metadata property, with configuration options:
  90. //totalProperty: "results", // the property which contains the total dataset size (optional)
  91. root: "rows", // the property which contains an Array of row objects
  92. idProperty: "id" // the property within each row object that provides an ID for the record (optional)
  93. },
  94. EvtListRecord // Ext.data.Record constructor that provides mapping for JSON object
  95. )
  96. });
  97. var EvtGroupDataStore = new Ext.data.Store({
  98. reader: new Ext.data.JsonReader({
  99. // The metadata property, with configuration options:
  100. //totalProperty: "results", // the property which contains the total dataset size (optional)
  101. root: "rows", // the property which contains an Array of row objects
  102. idProperty: "id" // the property within each row object that provides an ID for the record (optional)
  103. },
  104. EvtGroupRecord // Ext.data.Record constructor that provides mapping for JSON object
  105. )
  106. });
  107. function smooth(ctx, points){
  108. if(points == undefined || points.length == 0)
  109. {
  110. return true;
  111. }
  112. if(points.length == 1)
  113. {
  114. ctx.moveTo(points[0].x, points[0].y);
  115. ctx.lineTo(points[0].x, points[0].y);
  116. return true;
  117. }
  118. if(points.length == 2)
  119. {
  120. ctx.moveTo(points[0].x, points[0].y);
  121. ctx.lineTo(points[1].x, points[1].y);
  122. return true;
  123. }
  124. ctx.moveTo(points[0].x, points[0].y);
  125. for (var i = 1; i < points.length - 2; i ++)
  126. {
  127. var xc = (points[i].x + points[i + 1].x) / 2;
  128. var yc = (points[i].y + points[i + 1].y) / 2;
  129. ctx.quadraticCurveTo(points[i].x, points[i].y, xc, yc);
  130. }
  131. ctx.quadraticCurveTo(points[i].x, points[i].y, points[i+1].x, points[i+1].y);
  132. }
  133. function drawCurve(points, tension) {
  134. ctx.beginPath();
  135. ctx.moveTo(points[0].x, points[0].y);
  136. var t = (tension != null) ? tension : 1;
  137. for (var i = 0; i < points.length - 1; i++) {
  138. var p0 = (i > 0) ? points[i - 1] : points[0];
  139. var p1 = points[i];
  140. var p2 = points[i + 1];
  141. var p3 = (i != points.length - 2) ? points[i + 2] : p2;
  142. var cp1x = p1.x + (p2.x - p0.x) / 6 * t;
  143. var cp1y = p1.y + (p2.y - p0.y) / 6 * t;
  144. var cp2x = p2.x - (p3.x - p1.x) / 6 * t;
  145. var cp2y = p2.y - (p3.y - p1.y) / 6 * t;
  146. ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, p2.x, p2.y);
  147. }
  148. ctx.stroke();
  149. }
  150. function clearLiveBip(){
  151. var canvas = document.getElementById("StatusCanvas");
  152. var ctx = canvas.getContext("2d");
  153. ctx.fillStyle = "#FF0000";
  154. ctx.fillRect(5, 5, 10, 10);
  155. }
  156. function drawStatus(){
  157. var canvas = document.getElementById("StatusCanvas");
  158. var ctx = canvas.getContext("2d");
  159. ctx.fillStyle = "#00FF00";
  160. ctx.fillRect(5, 5, 10, 10);
  161. }
  162. function drawBackgrounds(){
  163. if( !DBWindow ) return;
  164. var canvas = document.getElementById("RangeBGCanvas");
  165. if( canvas ){
  166. var ctx = canvas.getContext("2d");
  167. var x = canvas.width;
  168. var y = canvas.height;
  169. if( ctx ){
  170. if( !BG_Array ){
  171. // No Data!
  172. ctx.font = "30px Arial";
  173. ctx.fillStyle = "#F0F0F0";
  174. ctx.fillRect(0, 0, x, y);
  175. ctx.strokeStyle = "#E0E0E0";
  176. ctx.lineWidth = 2;
  177. ctx.strokeRect(2, 2, x-4, y-4);
  178. ctx.beginPath();
  179. ctx.moveTo(2, 2);
  180. ctx.lineTo(x-2, y-2);
  181. ctx.moveTo(2, y-2);
  182. ctx.lineTo(x-2, 2);
  183. ctx.stroke();
  184. ctx.fillStyle = "#000000";
  185. ctx.fillText("No DATA!", ( x - ctx.measureText("No DATA!").width )>>> 1, y >>> 1 );
  186. } else {
  187. ctx.fillStyle = "#F0F0F0";
  188. ctx.fillRect(0, 0, x, y);
  189. var grd = ctx.createLinearGradient(0, 0, 0, y-20);
  190. grd.addColorStop(0, "#00FF00");
  191. grd.addColorStop(1, "#0000FF");
  192. ctx.fillStyle = grd;
  193. var bw = ( x - 27 ) / 9;
  194. var mx = y - 20;
  195. ctx.font = "10px Arial";
  196. ctx.strokeStyle = "#000000";
  197. for( i = 0; i < 9; i++ ){
  198. var cy = ( BG_Array[i] * mx ) / 1024;
  199. ctx.fillRect( 13 + i*bw, 10, bw-3, cy );
  200. ctx.strokeText((i+1)+":"+BG_Array[i], 13 + bw / 5 + i*bw, cy >>> 1 );
  201. };
  202. };
  203. };
  204. };
  205. }
  206. function ChangeHandler( me, nv, ov ){
  207. if( nv != ov ){
  208. //alert( 'Changes:' + me.name + ' ' + nv + ' '+ ov );
  209. Ext.Ajax.request({
  210. url: '/lib/controller/setVideoSourceParam.php',
  211. params: {
  212. param: me.name,
  213. oval: ov,
  214. nval: nv
  215. },
  216. success: function( response, opts ){
  217. // If the response is JSON, you have to decode it
  218. //var obj = Ext.decode(response.responseText);
  219. //Ext.fly('some_div').update('Success!');
  220. },
  221. failure: function( response, opts ) {
  222. //Ext.fly('some_div').update('Fail!');
  223. }/*,
  224. callback: function(options,success,response){
  225. // use this if you need to perform your own success/failure checking
  226. }*/
  227. });
  228. };
  229. };
  230. function showDetectionConfigWindow(){
  231. if( DCWindow == null ){
  232. DCWindow = new Ext.Window({
  233. title: 'Detection Parameters',
  234. width: 600,
  235. height: 220,
  236. closeAction: 'hide',
  237. y: 120,
  238. modal: true,
  239. items:[{
  240. xtype: 'form',
  241. labelAlign: 'right',
  242. labelWidth: 250,
  243. items: [{
  244. xtype: 'numberfield',
  245. id: 'sst_data',
  246. fieldLabel: 'Detection SST',
  247. emptyText: 'No Data'
  248. },{
  249. xtype: 'numberfield',
  250. id: 'offset_data',
  251. fieldLabel: 'Detection Offset',
  252. emptyText: 'No Data'
  253. },{
  254. xtype: 'numberfield',
  255. id: 'max_data',
  256. fieldLabel: 'Maximal Range',
  257. emptyText: 'No Data'
  258. },{
  259. xtype: 'numberfield',
  260. id: 'l2l_data',
  261. fieldLabel: 'Distance beetween Layers',
  262. emptyText: 'No Data',
  263. disabled: true
  264. },{
  265. xtype: 'numberfield',
  266. id: 'minspeed_data',
  267. fieldLabel: 'Minimal Speed',
  268. emptyText: 'No Data',
  269. disabled: true
  270. }],
  271. buttons:[{
  272. text: 'Submit',
  273. tooltip:'Set Detection Settings to Device',
  274. iconCls:'silk-tick',
  275. handler: function(){
  276. Settings_SST = Ext.getCmp('sst_data').getValue();
  277. Settings_OFFSET = Ext.getCmp('offset_data').getValue();
  278. Settings_MAXRANGE = Ext.getCmp('max_data').getValue();
  279. Settings_L2L = Ext.getCmp('l2l_data').getValue();
  280. Settings_MINSPEED = Ext.getCmp('minspeed_data').getValue();
  281. Ext.Ajax.request({
  282. url: '/lib/controller/setDetectorParam.php',
  283. params: {
  284. data_sst: Settings_SST,
  285. data_offset: Settings_OFFSET,
  286. data_maxrange: Settings_MAXRANGE,
  287. data_l2l: Settings_L2L,
  288. data_minspeed: Settings_MINSPEED,
  289. },
  290. success: function( response, opts ){
  291. // If the response is JSON, you have to decode it
  292. //var obj = Ext.decode(response.responseText);
  293. //Ext.fly('some_div').update('Success!');
  294. DCWindow.hide();
  295. },
  296. failure: function( response, opts ) {
  297. DCWindow.hide();
  298. Ext.Msg.alert('Status', 'Error Creating AJAX Connection.<br>Code: CENDL00221');
  299. }
  300. });
  301. }
  302. },{
  303. text: 'Cancel',
  304. tooltip:'Do Not Change Anything!',
  305. iconCls:'silk-cancel',
  306. handler: function(){
  307. DCWindow.hide();
  308. }
  309. }]
  310. }]
  311. });
  312. };
  313. DCWindow.show();
  314. Ext.getCmp('sst_data').setValue( Settings_SST );
  315. Ext.getCmp('offset_data').setValue( Settings_OFFSET );
  316. Ext.getCmp('max_data').setValue( Settings_MAXRANGE );
  317. Ext.getCmp('l2l_data').setValue( Settings_L2L );
  318. Ext.getCmp('minspeed_data').setValue( Settings_MINSPEED );
  319. };
  320. function showDetectionBackgroundWindow(){
  321. if( DBWindow == null ){
  322. DBWindow = new Ext.Window({
  323. title: 'Detection Background Ranges',
  324. width: 614,
  325. height: 514,
  326. y: 120,
  327. modal: true,
  328. closeAction: 'hide',
  329. html: '<canvas id="RangeBGCanvas" width="600px" height="480px"></canvas>'
  330. });
  331. };
  332. DBWindow.show();
  333. drawBackgrounds();
  334. };
  335. function videoPositionUpdater(){
  336. if(!VideoPlayer) return;
  337. var cPos = VideoPlayer.currentTime;
  338. };
  339. function setVideoToPlay( src ){
  340. if( VideoPlayer != null ){
  341. delete VideoPlayer;
  342. };
  343. if( VideoFlash != null ){
  344. swfobject.removeSWF( "vidflash" );
  345. Ext.getCmp('video-panel').removeAll( true );
  346. Ext.getCmp('video-panel').add({ html:'<div id="divvidflash" style="background: black;"></div>'});
  347. Ext.getCmp('video-panel').update();
  348. };
  349. var att = { data: "/lib/flash/player_flv_html5.swf?4", width: iW, height: iH, id: "vidflash", name: "vidflash"};
  350. var params = { flashvars: "listener=VideoPlayer&src="+src, swliveconnect: "true"};
  351. VideoFlash = swfobject.createSWF( att, params, "divvidflash" );
  352. VideoPlayer = new FlashFLVPlayer( VideoFlash );
  353. // Events
  354. VideoPlayer.addEventListener("loadstart", function(event) {
  355. trace("[event] loadstart");
  356. });
  357. VideoPlayer.addEventListener("load", function(event) {
  358. trace("[event] load");
  359. });
  360. VideoPlayer.addEventListener("play", function(event) {
  361. trace("[event] play");
  362. });
  363. VideoPlayer.addEventListener("ended", function(event) {
  364. if( VideoIsLooped ) VideoPlayer.currentTime = 0;
  365. });
  366. VideoPlayer.addEventListener("pause", function(event) {
  367. trace("[event] pause");
  368. });
  369. VideoPlayer.addEventListener("playing", function(event) {
  370. trace("[event] playing");
  371. });
  372. VideoPlayer.addEventListener("seeked", function(event) {
  373. trace("[event] seeked");
  374. });
  375. VideoPlayer.addEventListener("loadedmetadata", function(event) {
  376. trace("[event] loadedmetadata");
  377. //$('#videoWidth').text(VideoPlayer.videoWidth);
  378. //$('#videoHeight').text(VideoPlayer.videoHeight);
  379. });
  380. VideoPlayer.addEventListener("durationchange", function(event) {
  381. trace("[event] durationchange : " + VideoPlayer.duration);
  382. //$('#duration').text(VideoPlayer.duration);
  383. });
  384. VideoPlayer.addEventListener("timeupdate", function(event) {
  385. trace("[event] timeupdate : " + video.currentTime);
  386. });
  387. VideoPlayer.addEventListener("error", function(event) {
  388. trace("[event] error : " + VideoPlayer.networkState);
  389. });
  390. VideoPlayer.addEventListener("canplay", function(event) {
  391. trace("[event] canplay");
  392. });
  393. VideoPlayer.addEventListener("canplaythrough", function(event) {
  394. trace("[event] canplaythrough");
  395. });
  396. VideoPlayer.addEventListener("volumechange", function(event) {
  397. trace("[event] volumechange : " + VideoPlayer.volume);
  398. });
  399. // VideoPosition
  400. VideoPosInterval = window.setInterval( videoPositionUpdater, 100 );
  401. }
  402. function showVideoConfigWindow(){
  403. if( VCWindow == null ){
  404. VCWindow = new Ext.Window({
  405. title: 'Video Configuration',
  406. width: 500,
  407. height: 600,
  408. y: 120,
  409. modal: true,
  410. closeAction: 'hide',
  411. items: new Ext.TabPanel({
  412. activeTab: 0,
  413. enableTabScroll: true,
  414. autoScroll: true,
  415. items: [
  416. <?php
  417. $CC = getVideoSourcesCount();
  418. if( $CC ){
  419. $DD = array();
  420. //$CC++;
  421. for( $index = 0; $index < $CC; $index++ ){
  422. $ID = getVideoSourceID( $index );
  423. $DD[] = buildExtJSForm( getDeviceCtrl( $ID ), $ID );
  424. };
  425. $KU = implode( ',', $DD );
  426. echo $KU;
  427. };
  428. ?>
  429. ]
  430. })
  431. });
  432. };
  433. VCWindow.show();
  434. }
  435. function GetEventsLog( gid ){
  436. //clearLiveBip();
  437. Ext.Ajax.request({
  438. url: '/lib/controller/listEvents.php',
  439. success: function( response, opts ){
  440. var obj = Ext.decode( response.responseText );
  441. EvtListDataStore.removeAll();
  442. if( obj.empty != true ){
  443. EvtListDataStore.loadData( obj );
  444. };
  445. },
  446. failure: function( response, opts ){
  447. Ext.Msg.alert('Status', 'Error Creating AJAX Connection.<br>Code: CENDL00225');
  448. },
  449. headers: {
  450. 'author': 'gagua'
  451. },
  452. params: { id: gid }
  453. });
  454. };
  455. function GetGroupedEvents( gid ){
  456. Ext.Ajax.request({
  457. url: '/lib/controller/listEventGroups.php',
  458. success: function( response, opts ){
  459. var obj = Ext.decode( response.responseText );
  460. if( obj.SW_OK ){
  461. Ext.getCmp('rec-test').enable();
  462. Ext.getCmp('lrf-rst').enable();
  463. Ext.getCmp('ena-dis').enable();
  464. if( obj.MODE ) {
  465. DetectorEnabled = true;
  466. Ext.getCmp('ena-dis').setText('Disable Detection');
  467. Ext.getCmp('ena-dis').setIconClass('silk-cancel');
  468. } else {
  469. DetectorEnabled = false;
  470. Ext.getCmp('ena-dis').setText('Enable Detection');
  471. Ext.getCmp('ena-dis').setIconClass('silk-accept');
  472. };
  473. } else {
  474. Ext.getCmp('rec-test').disable();
  475. };
  476. Settings_SST = obj.LRF_SST;
  477. Settings_OFFSET = obj.LRF_OFFSET;
  478. Settings_MAXRANGE = obj.LRF_MAX;
  479. Settings_L2L = obj.LRF_DISTANCE;
  480. Settings_MINSPEED = obj.LRF_SPEED;
  481. BG_Array = obj.LRF_BG;
  482. drawBackgrounds();
  483. drawStatus();
  484. if( obj.empty == true ){
  485. if( lastId != 0 ){
  486. lastId = 0;
  487. EvtGroupDataStore.removeAll();
  488. //EvtListDataStore.sync();
  489. };
  490. } else {
  491. if( lastId != obj.rows[0].id ){
  492. lastId = obj.rows[0].id;
  493. //todo: Optimise to add just new arived items
  494. EvtGroupDataStore.loadData( obj );
  495. //EvtListDataStore.sync();
  496. };
  497. };
  498. },
  499. failure: function( response, opts ){
  500. Ext.Msg.alert('Status', 'Error Creating AJAX Connection.<br>Code: CENDL00225');
  501. },
  502. headers: {
  503. 'author': 'gagua'
  504. },
  505. params: { last_id: lastId }
  506. });
  507. };
  508. function makeAlarm(){
  509. Ext.Ajax.request({
  510. url: '/lib/controller/postAlarm.php',
  511. success: function( response, opts ){
  512. },
  513. failure: function( response, opts ){
  514. Ext.Msg.alert('Status', 'Error Creating AJAX Connection.<br>Code: CENDL00213');
  515. },
  516. headers: {
  517. 'my-header': 'foo'
  518. },
  519. params: { last_id: lastId }
  520. });
  521. }
  522. function resetDetector(){
  523. Ext.Ajax.request({
  524. url: '/lib/controller/resetDetector.php',
  525. success: function( response, opts ){
  526. },
  527. failure: function( response, opts ){
  528. Ext.Msg.alert('Status', 'Error Creating AJAX Connection.<br>Code: CENDL00213');
  529. },
  530. headers: {
  531. 'my-header': 'foo'
  532. },
  533. params: { last_id: lastId }
  534. });
  535. }
  536. function detectionEnable(){
  537. if( DetectorEnabled ){
  538. chucha = '/lib/controller/disableDetector.php';
  539. } else {
  540. chucha = '/lib/controller/enableDetector.php';
  541. };
  542. Ext.Ajax.request({
  543. url: chucha,
  544. success: function( response, opts ){
  545. },
  546. failure: function( response, opts ){
  547. Ext.Msg.alert('Status', 'Error Creating AJAX Connection.<br>Code: CENDL00213');
  548. },
  549. headers: {
  550. 'my-header': 'foo'
  551. },
  552. params: { last_id: lastId }
  553. });
  554. }
  555. function IconRenderer( type ){
  556. switch( type ){
  557. case 255:
  558. return '<img width="16px" src="/style/icons/icons/information.png"/>';
  559. case 251:
  560. return '<img width="16px" src="/style/icons/icons/arrow_refresh.png"/>';
  561. case 250:
  562. return '<img width="16px" src="/style/icons/icons/information.png"/>';
  563. case 0:
  564. return '<img width="16px" src="/style/icons/icons/tick.png"/>';
  565. case 1:
  566. return '<img width="16px" src="/style/icons/icons/house.png"/>';
  567. case 2:
  568. return '<img width="16px" src="/style/icons/icons/house_link.png"/>';
  569. case 3:
  570. return '<img width="16px" src="/style/icons/icons/shield_delete.png"/>';
  571. case 4:
  572. return '<img width="16px" src="/style/icons/icons/shield_add.png"/>';
  573. case 5:
  574. return '<img width="16px" src="/style/icons/icons/asterisk_yellow.png"/>';
  575. case 6:
  576. return '<img width="16px" src="/style/icons/icons/asterisk_orange.png"/>';
  577. case 7:
  578. return '<img width="16px" src="/style/icons/icons/information.png"/>';
  579. case 8:
  580. return '<img width="16px" src="/style/icons/icons/information.png"/>';
  581. default:
  582. return '<img width="16px" src="/style/icons/icons/help.png"/>';
  583. };
  584. };
  585. function TypeRenderer( type ){
  586. switch( type ){
  587. case 255: return 'System Shutted Down';
  588. case 251: return 'Sensor Reset issued by Operator';
  589. case 250: return 'Log Cleared by Operator';
  590. case 0: return 'System Started';
  591. case 1: return 'System Started Disarmed';
  592. case 2: return 'System Started Armed';
  593. case 3: return 'Disarmed by Operator';
  594. case 4: return 'Armed by Operator';
  595. case 5: return 'Alarm';
  596. case 6: return 'Alarm Test by Operator';
  597. case 7: return 'Parameters Changed by Operator';
  598. case 8: return 'Log Cleared by Operator';
  599. default: return 'Unusual Event';
  600. };
  601. };
  602. function LrfRenderer( value, metadata, record, rowIndex, colIndex, store ){
  603. var R = value / 1;
  604. if( R > 0 ){
  605. var RV = '<svg width="120" height="16">';
  606. if( R == 1024 ){
  607. for( i=0; i < 9; i++ ){
  608. RV = RV + '<circle cx="'+( 120 - ( ( i + 1 ) * 12 + 5 ) )+'" cy="8" r="5" stroke="black" stroke-width="2" fill="darkgrey" />';
  609. };
  610. } else {
  611. R--;
  612. for( i=0; i < 9; i++ ){
  613. if( ( R & ( 1 << i ) ) == 0 ){
  614. RV = RV + '<circle cx="'+( 120 - ( ( i + 1 ) * 12 + 5 ) )+'" cy="8" r="5" stroke="green" stroke-width="2" fill="grey" />';
  615. } else {
  616. RV = RV + '<circle cx="'+( 120 - ( ( i + 1 ) * 12 + 5 ) )+'" cy="8" r="5" stroke="red" stroke-width="2" fill="yellow" />';
  617. };
  618. };
  619. };
  620. return RV + '</svg>';
  621. };
  622. return '';
  623. };
  624. function VideoRenderer( value, metadata, record, rowIndex, colIndex, store ){
  625. if( value ){
  626. //return '<a href="#" onclick="ViewVideoPreview(\'' + record.data.video + '\');"><img width="16px" src="/style/icons/icons/film.png" alt="' + record.data.video + '" /></a>';
  627. return '<a href="#" onclick="showEventGroupWindow(\'' + record.data.video + '\','+record.data.id+');"><img width="16px" src="/style/icons/icons/film.png" alt="' + record.data.video + '" /></a>';
  628. };
  629. return '';
  630. };
  631. var EvtGroupColModel = new Ext.grid.ColumnModel([
  632. /*{header: "", width: 38, sortable: false, locked: true, menuDisabled: true, fixed: true, align: 'left', renderer: IconRenderer, dataIndex: 'icon'},
  633. {header: "Device ID", width: 120, sortable: true, align: 'center', css: 'vertical-align: middle;', dataIndex: 'device_id'},
  634. {header: "Vehicle ID", width: 120, sortable: true, align: 'left', css: 'vertical-align: middle;', dataIndex: 'name'},
  635. {header: "Status", width: 95, sortable: true, align: 'center', css: 'vertical-align: middle;', renderer: DevStatusRenderer, dataIndex: 'status'},
  636. {header: "SMS", width: 36, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: SMSRenderer, dataIndex: 'sms'},
  637. {header: "Active Since", width: 85, sortable: true, css: 'vertical-align: middle;', renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'created'},
  638. {header: "Last Activity", width: 85, sortable: true, css: 'vertical-align: middle;', renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'last_access'}*/
  639. {header: "", width: 24, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: IconRenderer, dataIndex: 'type' },
  640. {header: "Time Stamp", width: 160, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: Ext.util.Format.dateRenderer('d-m-Y H:i:s'), dataIndex: 'ts' },
  641. {header: "Event Description", width: 200, sortable: false, menuDisabled: true, align: 'left', css: 'vertical-align: middle;', renderer: TypeRenderer, dataIndex: 'type' },
  642. {header: "Grouped Events", width: 60, sortable: false, menuDisabled: true, align: 'center', css: 'vertical-align: middle;', dataIndex: 'cnt' },
  643. /*{header: "Range", width: 60, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', dataIndex: 'range' },
  644. {header: "LVL 0", width: 130, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: LrfRenderer, dataIndex: 'f_lrf' },
  645. {header: "LVL 1", width: 130, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: LrfRenderer, dataIndex: 's_lrf' },
  646. {header: "Speed", width: 60, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', dataIndex: 'lrf_id' },
  647. */
  648. {header: "Video", width: 50, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: VideoRenderer, dataIndex: 'has_image' }
  649. ]);
  650. var EvtGroupSelModel = new Ext.grid.RowSelectionModel({
  651. singleSelect: true,
  652. listeners: {
  653. rowselect: function(sm, row, rec) {
  654. if (!SelectedEvent){
  655. SelectedEvent = rec;
  656. SelectedEvent.sm = sm;
  657. SelectedEvent.rowId = row;
  658. } else {
  659. SelectedEvent = rec;
  660. SelectedEvent.sm = sm;
  661. SelectedEvent.rowId = row;
  662. };
  663. }
  664. }
  665. });
  666. var EvtListColModel = new Ext.grid.ColumnModel([
  667. {header: "", width: 24, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: IconRenderer, dataIndex: 'type' },
  668. {header: "Time Stamp", width: 160, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: Ext.util.Format.dateRenderer('d-m-Y H:i:s'), dataIndex: 'ts' },
  669. {header: "Event Description", sortable: false, menuDisabled: true, align: 'left', css: 'vertical-align: middle;', renderer: TypeRenderer, dataIndex: 'type' },
  670. {header: "Range", width: 60, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', dataIndex: 'range' },
  671. {header: "LVL 0", width: 130, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: LrfRenderer, dataIndex: 'f_lrf' },
  672. {header: "LVL 1", width: 130, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', renderer: LrfRenderer, dataIndex: 's_lrf' },
  673. {header: "Speed", width: 60, sortable: false, menuDisabled: true, align: 'center', fixed: true, css: 'vertical-align: middle;', dataIndex: 'speed' }
  674. ]);
  675. var EvtListSelModel = new Ext.grid.RowSelectionModel({
  676. singleSelect: true,
  677. listeners: {
  678. rowselect: function(sm, row, rec) {
  679. if (!SelectedEvent){
  680. SelectedEvent = rec;
  681. SelectedEvent.sm = sm;
  682. SelectedEvent.rowId = row;
  683. } else {
  684. SelectedEvent = rec;
  685. SelectedEvent.sm = sm;
  686. SelectedEvent.rowId = row;
  687. };
  688. }
  689. }
  690. });
  691. function showEventGroupWindow( vsrc, gid ){
  692. if( GEWindow == null ){
  693. GEWindow = new Ext.Window({
  694. title: 'Event Viewer',
  695. width: iW+20,
  696. height: iH+300,
  697. modal: true,
  698. y: 120,
  699. resizable: false,
  700. closeAction: 'hide',
  701. items: [{
  702. xtype: 'panel',
  703. id: 'video-panel',
  704. html: '<div id="divvidflash" style="background: black; width: '+iW+'px; height: '+iH+'px;"></div>',
  705. bbar: [{
  706. iconCls: 'silk-start',
  707. handler: function(){
  708. if( VideoPlayer ){
  709. VideoPlayer.currentTime = 0;
  710. };
  711. }
  712. },{
  713. text: 'Play',
  714. iconCls: 'silk-play',
  715. handler: function(){
  716. if( VideoPlayer ){
  717. if( VideoIsPlaying ){
  718. VideoPlayer.pause();
  719. VideoIsPlaying = false;
  720. } else {
  721. VideoPlayer.play();
  722. VideoIsPlaying = true;
  723. };
  724. };
  725. }
  726. },{
  727. iconCls: 'silk-replay',
  728. enableToggle: true,
  729. handler: function(){
  730. if( VideoPlayer ){
  731. VideoIsLooped = !VideoIsLooped;
  732. };
  733. }
  734. }]
  735. },{
  736. xtype: 'grid',
  737. title: 'Events Log',
  738. frame: false,
  739. id: 'grp_grid',
  740. forceFit: true,
  741. ds: EvtListDataStore,
  742. cm: EvtListColModel,
  743. sm: EvtListSelModel,
  744. //autoExpandColumn: 'login',
  745. height: 235,
  746. width: '100%',
  747. border: false,
  748. listeners: {
  749. render: function(g) {
  750. //g.getSelectionModel().selectRow(0);
  751. },
  752. delay: 10 // Allow rows to be rendered.
  753. },
  754. viewConfig: {
  755. forceFit:true
  756. },
  757. }],
  758. listeners: {
  759. beforehide : function(component) {
  760. if( VideoFlash != null ){
  761. if(VideoPosInterval) clearInterval( VideoPosInterval );
  762. VideoPosInterval = null;
  763. swfobject.removeSWF( "vidflash" );
  764. Ext.getCmp('video-panel').removeAll( true );
  765. Ext.getCmp('video-panel').add({ html:'<div id="divvidflash"></div>'});
  766. VideoFlash = null;
  767. VideoIsPlaying = false;
  768. };
  769. }
  770. }
  771. });
  772. };
  773. GEWindow.show();
  774. setVideoToPlay( vsrc );
  775. GetEventsLog( gid );
  776. }
  777. Ext.onReady(function() {
  778. var panel = new Ext.Panel({
  779. renderTo: 'content',
  780. width: panelWidth,
  781. items:[ {
  782. xtype: 'panel',
  783. id: '121',
  784. title:'Video',
  785. frame: true,
  786. html:'<img id="theImage" border=0 src="/cgi-bin/nph-video" width="'+panelWidth+'px" rel="shadowbox" onClick="makeFullScreen();">',
  787. width: imgWidth+12,
  788. height: imgHeight+75,
  789. anchor:'right 50%',
  790. fbar: [{
  791. text: 'Force Alarm',
  792. id: 'rec-test',
  793. disabled: true,
  794. iconCls: 'silk-belladd',
  795. handler: function(){
  796. Ext.Msg.show({
  797. title:'Test Record Frames?',
  798. msg: 'You are about to record 240 frames. Would you like to do so?',
  799. buttons: Ext.Msg.YESNOCANCEL,
  800. fn: function(btn, text){
  801. if( btn == 'yes' ) makeAlarm();
  802. },
  803. animEl: '121',
  804. icon: Ext.MessageBox.QUESTION
  805. });
  806. }
  807. },{
  808. iconCls: 'silk-cog',
  809. text: 'Video Config',
  810. handler: showVideoConfigWindow
  811. }]
  812. },{
  813. title: 'Detector Settings',
  814. xtype: 'form',
  815. layout: 'form',
  816. layoutConfig: {
  817. type: 'hbox',
  818. padding: '5',
  819. align: 'center'
  820. },
  821. //html: '<table width="100%" border=0><tr><td>Offset:</td><td><?=20;?></td><td>Max Distance:</td><td>3.00</td><td>Layer Distance:</td><td>0.5</td></tr></table>',
  822. width: panelWidth,
  823. buttons:[{
  824. xtype: 'panel',
  825. html: '<canvas id="StatusCanvas" width="120px" height="20px"></canvas>'
  826. },{
  827. text: 'Show Detection Backgrounds',
  828. iconCls: 'silk-chart',
  829. handler: showDetectionBackgroundWindow
  830. },{
  831. text: 'Change Detection Settings',
  832. iconCls: 'silk-cog',
  833. handler: showDetectionConfigWindow
  834. },{
  835. text: 'Reset Sensor',
  836. id: 'lrf-rst',
  837. disabled: true,
  838. iconCls: 'silk-arrow-refresh',
  839. handler: function(){
  840. Ext.Msg.show({
  841. title:'Reset Detector?',
  842. msg: 'You are about to reset detector. The system will be blind for 1 second. Would you like to do so?',
  843. buttons: Ext.Msg.YESNOCANCEL,
  844. fn: function(btn, text){
  845. if( btn == 'yes' ) resetDetector();
  846. },
  847. animEl: '121',
  848. icon: Ext.MessageBox.WARNING
  849. });
  850. }
  851. },{
  852. text: 'Enable Detection',
  853. disabled: true,
  854. id: 'ena-dis',
  855. iconCls: 'silk-accept',
  856. handler: detectionEnable
  857. }]
  858. },{
  859. xtype: 'grid',
  860. title: 'Events Log',
  861. frame: true,
  862. id: 'mygrid',
  863. forceFit: true,
  864. ds: EvtGroupDataStore,
  865. cm: EvtGroupColModel,
  866. sm: EvtGroupSelModel,
  867. //autoExpandColumn: 'login',
  868. height: 350,
  869. width: '100%',
  870. border: false,
  871. listeners: {
  872. render: function(g) {
  873. g.getSelectionModel().selectRow(0);
  874. },
  875. delay: 10 // Allow rows to be rendered.
  876. },
  877. viewConfig: {
  878. forceFit:true
  879. },
  880. bbar: [{
  881. tooltip:'Clear Log Messages',
  882. id: 'clrList',
  883. text: 'Clear',
  884. iconCls:'silk-cross',
  885. handler: function(){
  886. Ext.Msg.show({
  887. title:'Clear Log Messages?',
  888. msg: 'You are about to clear log. All data and pictures will be deleted. Would you like to do so?',
  889. buttons: Ext.Msg.YESNOCANCEL,
  890. fn: function(btn, text){
  891. if( btn == 'yes' ){
  892. Ext.Ajax.request({
  893. url: '/lib/controller/clearLOG.php',
  894. success: function( response, opts ){
  895. var obj = Ext.decode( response.responseText );
  896. },
  897. failure: function( response, opts ){
  898. Ext.Msg.alert('Status', 'Error Creating AJAX Connection.<br>Code: CENDL00215');
  899. },
  900. headers: {
  901. 'my-header': 'foo'
  902. },
  903. params: { last_id: lastId }
  904. });
  905. };
  906. },
  907. animEl: 'mygrid',
  908. icon: Ext.MessageBox.WARNING
  909. });
  910. },
  911. disabled: false
  912. }]
  913. }]
  914. });
  915. Ext.ux.SliderTip = Ext.extend(Ext.Tip, {
  916. minWidth: 10,
  917. offsets : [0, -10],
  918. init : function(slider){
  919. slider.on('dragstart', this.onSlide, this);
  920. slider.on('drag', this.onSlide, this);
  921. slider.on('dragend', this.hide, this);
  922. slider.on('destroy', this.destroy, this);
  923. },
  924. onSlide : function(slider){
  925. this.show();
  926. this.body.update(this.getText(slider));
  927. this.doAutoWidth();
  928. this.el.alignTo(slider.thumb, 'b-t?', this.offsets);
  929. },
  930. getText : function(slider){
  931. return String(slider.getValue());
  932. }
  933. });
  934. STip = new Ext.ux.SliderTip({
  935. getText: function(slider){
  936. return String.format('<b>More Than {0} '+SPEED_TYPE+'</b>', slider.getValue());
  937. }
  938. });
  939. Ext.QuickTips.init();
  940. // turn on validation errors beside the field globally
  941. Ext.form.Field.prototype.msgTarget = 'under';
  942. updateInterval = setInterval( GetGroupedEvents, 1000 );
  943. });