Web UI for ARGUS server
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.
 
 
 
 

762 lines
21 KiB

//<?php require_once('../../js_asm.php'); ?>
function Pie(cx, cy, radius, data) {
var decimals = 4;
var total = 0;
var offset = 0;
var offset2;
var arr = [];
var x;
var y;
var la;
var radians;
for (var i = 0; i < data.length; i++)
total += data[i].value;
for (var i = 0; i < data.length; i++) {
var item = data[i];
var tmp = {};
tmp.index = i;
tmp.value = item.value;
radians = ((((item.value / total) * 360) * Math.PI) / 180).floor(decimals);
offset2 = ((offset / total) * 360).floor(decimals);
tmp.data = item;
x = (cx + Math.sin(radians) * radius).floor(decimals);
y = (cy - Math.cos(radians) * radius).floor(decimals);
la = radians > Math.PI ? 1 : 0;
// Arc
tmp.d = 'M{0} {1},L{0} {2},A{3} {3},0 {4} 1,{5} {6}Z'.format(cx, cy, cy - radius, radius, la, x, y);
tmp.transform = 'rotate({0}, {1}, {2})'.format(offset2, cx, cy);
// Text
x = (cx + Math.sin(radians / 2) * radius / 2).floor(decimals);
y = (cy - Math.cos(radians / 2) * radius / 2).floor(decimals);
tmp.text = 'x="{0}" y="{1}" transform="rotate({2},{0},{1})"'.format(x, y, -offset2);
offset += item.value;
arr.push(tmp);
}
return arr;
}
function Donut(cx, cy, radius, data) {
function arcradius(cx, cy, radius, degrees) {
var radians = (degrees - 90) * Math.PI / 180.0;
return { x: cx + (radius * Math.cos(radians)), y: cy + (radius * Math.sin(radians)) };
}
var decimals = 4;
var total = 0;
var arr = [];
var beg = 0;
var end = 0;
var count = 0;
var half = radius / 2;
var midpoint = radius / 2.4;
for (var i = 0; i < data.length; i++)
total += data[i].value;
for (var i = 0; i < data.length; i++) {
var item = data[i];
var tmp = {};
//var p = (((item.value + 1) / total) * 100).floor( 2 );
var p = Math.floor(((item.value + 1) / total) * 100);
count += p;
if (i === length - 1 && count < 100)
p = p + (100 - count);
end = beg + ((360 / 100) * p);
tmp.index = i;
tmp.value = item.value;
tmp.data = item;
var b = arcradius(cx, cy, radius, end);
var e = arcradius(cx, cy, radius, beg);
var la = (end - beg) <= 180 ? 0 : 1;
tmp.d = ['M', Math.floor( b.x ), Math.floor( b.y ), 'A', radius, radius, 0, la, 0, Math.floor( e.x ), Math.floor( e.y ) ].join(' ');
arr.push(tmp);
beg = end;
}
return arr;
}
//Pie Chart Usage
/*
var svg = $('#yoursvgelement');
var data = [{ value: 33 }, { value: 20 }, { value: 80 }, { value: 48 }];
var centerX = 300;
var centerY = 300;
var radius = 250;
var color = ['#F6BB42', '#8CC152', '#3BAFDA', '#967ADC', '#DA4453'];
var arr = Pie(centerX, centerY, radius, data);
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
svg.asvg('<g transform="{0}"><path d="{1}" fill="{4}" /><text fill="white" font-size="25" {2}>{3}</text></g>'.format(item.transform, item.d, item.text, item.value, color[i]));
}
*/
// Donut Chart Usage
/*
var svg = $('#yoursvgelement');
var data = [{ value: 33 }, { value: 20 }, { value: 80 }, { value: 48 }];
var centerX = 300;
var centerY = 300;
var radius = 250;
var color = ['#F6BB42', '#8CC152', '#3BAFDA', '#967ADC', '#DA4453'];
var arr = Donut(centerX, centerY, radius, data);
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
svg.asvg('<g><path d="{0}" stroke="{1}" fill="none" stroke-width="50" /></g>'.format(item.d, color[i]));
}
*/
function makePtzMove( me ){
var name = me.target.id;
Ext.Ajax.request({
url: '/lib/controller/camMakeMove.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
CMD: name
},
//success: function( response, opts ){
//},
failure: failureAJAXFunction
});
};
function ptzCtrl( a ){
};
function makePtzStop( me ){
var name = me.target.id;
Ext.Ajax.request({
url: '/lib/controller/camStop.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
CMD: name
},
//success: function( response, opts ){
//},
failure: failureAJAXFunction
});
};
function fullScreen( id ){
// if already full screen; exit
// else go fullscreen
if(
document.fullscreenElement ||
document.webkitFullscreenElement ||
document.mozFullScreenElement ||
document.msFullscreenElement
){
if( document.exitFullscreen ){
document.exitFullscreen();
}else if( document.mozCancelFullScreen ){
document.mozCancelFullScreen();
}else if( document.webkitExitFullscreen ){
document.webkitExitFullscreen();
}else if( document.msExitFullscreen ){
document.msExitFullscreen();
};
}else{
//element = $('#container').get(0);
var element = document.getElementById( id ); //Ext.getCmp( id );
if( element.requestFullscreen ){
element.requestFullscreen();
}else if( element.mozRequestFullScreen ){
element.mozRequestFullScreen();
}else if( element.webkitRequestFullscreen ){
element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}else if( element.msRequestFullscreen ){
element.msRequestFullscreen();
};
};
};
function updateDashBoardItemLayout( id, x, y ){
Ext.Ajax.request({
url: '/lib/controller/updateDashBoardItems.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
PANEL: id,
X: x,
Y: y
},
success: function( response, opts ){
//var data = Ext.decode(response.responseText);
//var tPanel = Ext.getCmp('main_portal');
//tPanel.removeAll(true);
//for( i=0; i < data.length; i++) tPanel.add( data[i] );
//tPanel.doLayout();
},
failure: failureAJAXFunction
});
};
var drawZoomLevels = Array();
function cleanupDraw( a ){
var canvas = document.getElementById('targ_canvas_'+a );
var ctx = canvas.getContext('2d');
var img = document.getElementById('draw_img_'+a );
ctx.drawImage( img, 0, 0 );
canvas.style='display: block;';
img.style='display: none;';
};
function DrawTargets( k, b ){
var canvas = document.getElementById('targ_canvas_'+k );
var ctx = canvas.getContext('2d');
var img = document.getElementById('draw_img_'+k );
ctx.drawImage( img, 0, 0 );
canvas.style='display: block;';
img.style='display: none;';
for( var i=0; i< b.length; i++ ){
switch( drawZoomLevels[k] ){
case 12:{
if( b[i].digital < 256 ){
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital)/ 512;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 24, 24 );
};
break;
};
case 25:{
if( b[i].digital < 512 ){
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital)/ 1024;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 12, 12 );
};
break;
};
case 50:{
if( b[i].digital < 1024 ){
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital) / 2048;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 6, 6 );
};
break;
};
case 100:{
var cc = 255 - i ;//* ( 255 / 33 );
//ctx.fillStyle = "#" + cc.toString(16) + "0000";
ctx.fillStyle = "rgba(255, 0, 0,"+((b.length - i)/ b.length )+")";
//ctx.strokeStyle = "#FF0000";
var r = (196 * b[i].digital)/ 4096;
var a = -1.0 * b[i].az * ( Math.PI / 180 );
var x = 100 + Math.cos( a ) * r;
var y = 100 + Math.sin( a ) * r;
ctx.fillRect( x, y, 3, 3 );
break;
};
};
};
};
var lastNotificationID = 0;
function setDonatStatus( id , value ){
var val1D = document.getElementById('donut'+id+'-segment1');
var val2D = document.getElementById('donut'+id+'-segment2');
var val3D = document.getElementById('donut'+id+'-segment3');
var val1 = (value>-1)?value:0;
var val2 = (value>-1)?100 - val1:0;//data.nodes[i].cpu5 * 100;
var val3 = (value>-1)?0:100;//data.nodes[i].cpu15 * 100;
var totalValue = document.getElementById('totalValue'+id);
var total = val1+val2+val3;
var per1 = val1/total*100;
var per2 = val2/total*100;
var per3 = val3/total*100;
var offset = 25;
if( ( val1 != undefined ) && ( value > -1 ) ){
totalValue.textContent = val1+'%';
} else {
totalValue.textContent = 'No Data';
};
val1D.style.transition = "stroke-dasharray 0.5s ease-in-out, stroke-dashoffset 0.5s ease-in-out";
val1D.style.strokeDasharray = per1+" "+(100-per1);
val1D.style.strokeDashoffset = offset;
val2D.style.transition = "stroke-dasharray 0.5s ease-in-out, stroke-dashoffset 0.5s ease-in-out";
val2D.style.strokeDasharray = per2+" "+(100-per2);
val2D.style.strokeDashoffset = 100-per1+offset;
val3D.style.transition = "stroke-dasharray 0.5s ease-in-out, stroke-dashoffset 0.5s ease-in-out";
val3D.style.strokeDasharray = per3+" "+(100-per3);
val3D.style.strokeDashoffset = 100-(per1+per2)+offset;
};
function fetchSiteStatus(){
Ext.Ajax.request({
url: '/lib/controller/getStatus.php',
params: {
SITE: <?=$SiteID;?>,
LNID: lastNotificationID,
SPID: ServerPID,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>'
},
success: function( response, opts ){
var data = Ext.decode(response.responseText);
if( data.nodes.length > 0 ){
for( i=0; i < data.nodes.length; i++ ){
if( data.nodes[i].type == 0 ){
//Handle Server Status
if ( data.nodes[i].status ){
setDonatStatus( '' , data.nodes[i].cpu5 );
setDonatStatus( '1' , data.nodes[i].mem );
setDonatStatus( '2' , data.nodes[i].disk );
} else {
setDonatStatus( '' , -1 );
setDonatStatus( '1' , -1 );
setDonatStatus( '2' , -1 );
};
};
if( data.nodes[i].type > 9 && data.nodes[i].type < 14 ){
var iel = document.getElementById('img-'+data.nodes[i].id );
if( !data.nodes[i].valid ){
if( iel.src != "/style/assets/no-signal.png" ) iel.src = "/style/assets/no-signal.png";
} else {
if( data.nodes[i].src != iel.src ) iel.src = data.nodes[i].src;
};//else {
//https://man7.org/linux/man-pages/man2/getrusage.2.html
//https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode
//https://stackoverflow.com/questions/13465073/how-to-catch-an-exception-from-image-onload
//if( data.nodes[i].valid && ServerIsOnline ){
//iel.src = "/style/assets/no-signal.png";
/*
iel.onerror = function(){
//alert("IMG onerror!");
iel.troubled = true;
};
iel.decode()
.then(() => {
//document.body.appendChild(img);
})
.catch((encodingError) => {
//alert('Stream Ended!');
iel.troubled = true;
})
*/
//};
//};
};
var tt = Ext.getCmp('status_'+data.nodes[i].id );
if( tt != undefined ){
switch( data.nodes[i].status ){
case 0:{
cleanupDraw( data.nodes[i].id );
tt.update('<table style="background-color:#808080; color:#ffff00;" border="0" width="100%"><tr><td>Offline</td><td width="16"><img width="16px" src="/style/assets/offline.png"></td></tr></table>');
break;
};
case 1:{
cleanupDraw( data.nodes[i].id );
tt.update('<table style="background-color:#008000; color:#ffff00;" border="0" width="100%"><tr><td>Online</td><td width="16"><img width="16px" src="/style/assets/online.gif"></td></tr></table>');
break;
};
case 2:{
cleanupDraw( data.nodes[i].id );
tt.update('<table style="background-color:#008000; color:#ffff00;" border="0" width="100%"><tr><td>Initializing</td><td width="16"><img width="16px" src="/style/assets/online.gif"></td></tr></table>');
break;
};
case 3:{
cleanupDraw( data.nodes[i].id );
tt.update('<table style="background-color:#800000; color:#ffff00;" border="0" width="100%"><tr><td>Trouble</td><td width="16"><img width="16px" src="/style/assets/offline.png"></td></tr></table>');
break;
};
case 4:{
DrawTargets( data.nodes[i].id, data.nodes[i].targets );
tt.update('<table style="background-color:#ff0000; color:#ffff00;" border="0" width="100%"><tr><td>Alarm</td><td width="16"><img width="16px" src="/style/assets/online.gif"></td></tr></table>');
break;
};
};
};
};
};
if( data.notifications.length > 0 ){
sndExcl.play();
for( i=0; i < data.notifications.length; i++ ){
/*const not = PNotify.alert({
title: 'You Will Receive a Side',
text: 'You have no choice.',
icon: 'fas fa-info-circle',
hide: false,
closer: false,
sticker: false,
destroy: true,
modules: new Map([
...PNotify.defaultModules,
[PNotifyConfirm, {
confirm: true,
buttons: [{
text: 'Ok',
primary: true,
click: notice => notice.close()
}]
}]
])
});
*/
const l = PNotify.alert({
type: data.notifications[i].type,
text: data.notifications[i].msg,
textTrusted: true,
stack: NotificationStack,
title: data.notifications[i].action,
hide: data.notifications[i].hide,
closer: data.notifications[i].hide,
sticker: data.notifications[i].hide,
destroy: true,
modules: (data.notifications[i].react )? new Map([
...PNotify.defaultModules,
[PNotifyConfirm, {
confirm: true,
buttons: [{
text: 'Ok',
primary: true,
click: ( notice, value, evt ) => {
notice.close();
if( notice.title!='' ){
resolveDeviceMistmatch( notice.title );
};
}
}]
}]
]): null
});
/*
if( data.notifications[i].react ){
l.on('click', (notice, value) => {
notice.close();
resolveDeviceMistmatch( notice.title );
});
};
*/
lastNotificationID = data.notifications[i].id;
};
};
},
failure: failureAJAXFunction
});
};
function loadDashBoard(){
if( tlInterval!= null ){
window.clearInterval( tlInterval );
tlInterval = null;
timelineObj = null;
};
Ext.Ajax.request({
url: '/lib/controller/getDashBoardItems.php',
params: {
SITE: <?=$SiteID;?>,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>'
},
success: function( response, opts ){
var data = Ext.decode(response.responseText);
Ext.getCmp('main_content').setTitle( '<?=$Labels->GetLabel('_SYS_DASHBOARD_');?>' );
var tPanel = Ext.getCmp('main_portal');
tPanel.removeAll(true);
for( i=0; i < data.length; i++) tPanel.add( data[i] );
tPanel.doLayout();
$('img[data-enlargeable]').addClass('img-enlargeable').click(function() {
var src = $(this).attr('src');
var modal;
function removeModal() {
modal.remove();
$('body').off('keyup.modal-close');
}
modal = $('<div>').css({
background: 'RGBA(0,0,0,.5) url(' + src + ') no-repeat center',
backgroundSize: 'contain',
width: '100%',
height: '100%',
position: 'fixed',
zIndex: '10000',
top: '0',
left: '0',
cursor: 'zoom-out'
}).click(function() {
removeModal();
}).appendTo('body');
//handling ESC
$('body').on('keyup.modal-close', function(e) {
if (e.key === 'Escape') {
removeModal();
}
});
});
tlInterval = window.setInterval( fetchSiteStatus, 333, selectedSite );
},
failure: failureAJAXFunction
});
};
var serverToolBox = null;
function showServerToolBox( ServerNodeId ){
if( serverToolBox == null ){
serverToolBox = new Ext.Window({
title: '<?=$Labels->GetLabel('_SERV_CTLPANEL_SHRT_');?>',
modal: true,
width: 400,
height: 328,
closeAction: 'hide',
items:[{
xtype: 'button',
text: 'Restart',
width: '100%',
textAlign: 'left',
iconCls: 'server_btn_restart',
scale: 'large',
iconAlign: 'left'
},{
xtype: 'button',
text: 'Clear Site',
width: '100%',
textAlign: 'left',
iconCls: 'server_btn_restart',
scale: 'large',
iconAlign: 'left'
}]
});
};
serverToolBox.show();
};
var detectionProfileWindow = null;
var deviceCtrlNode = '';
function showDetectionProfile( NodeID ){
deviceCtrlNode = NodeID + ':0';
<?php if( $CUser->Data['access']>4 ) $ColSpan = 4; else $ColSpan = 3; ?>
if( detectionProfileWindow == null ){
detectionProfileWindow = new Ext.Window({
title: '<?=$Labels->GetLabel('_DEV_CTLPANEL_SHRT_');?>',
modal: true,
width: <?=$ColSpan*80+16;?>,
height: 328,
closeAction: 'hide',
items:[]
});
};
Ext.Ajax.request({
url: '/lib/controller/getDetectionProfile.php',
params: {
SITE: SelectedSite,
UID: <?=$UserID;?>,
SID: '<?=$Session;?>',
NID: NodeID
},
success: function( response, opts ){
var data = Ext.decode( response.responseText );
detectionProfileWindow.setTitle( '['+data.name + '] <?=$Labels->GetLabel('_DEV_CTLPANEL_SHRT_');?>');
detectionProfileWindow.removeAll( true );
if( data.data_status == 3 ){
detectionProfileWindow.add({
xtype: 'panel',
layout: 'table',
layoutConfig: {
columns: <?=$ColSpan;?>
},
items:[{
xtype: 'spacer',
height: 30,
style: {
marginTop: '13px'
},
html: '<center><?=$Labels->GetLabel('_DET_SENSITIVITY_');?></center>',
colspan: <?=$ColSpan;?>
},<?php
if( $CUser->Data['access']>4 ){
?>{
xtype: 'button',
text: 'Factory',
id: 'DDSPBTN0',
width: 80,
iconCls: 'detection_btn_factory',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
},<?php
};
?>{
xtype: 'button',
text: 'Low',
id: 'DDSPBTN1',
width: 80,
iconCls: 'detection_btn_low',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
},{
xtype: 'button',
text: 'Meduim',
id: 'DDSPBTN2',
width: 80,
iconCls: 'detection_btn_medium',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
},{
xtype: 'button',
text: 'High',
id: 'DDSPBTN3',
width: 80,
iconCls: 'detection_btn_high',
enableToggle: true,
toggleGroup: 'det_sens_btn_grp',
disabled: true,
scale: 'large',
iconAlign: 'top'
}]
});
for( i=0; i < data.profiles.length; i++ ){
Ext.getCmp('DDSPBTN'+data.profiles[i] ).enable();
if( i == data.profile_id ) Ext.getCmp('DDSPBTN'+data.profiles[i] ).toggle();
};
} else if( data.data_status == 4 ){
detectionProfileWindow.add({
xtype: 'panel',
//layout: 'fit',
//layoutConfig: {
// columns: 3
//},
items:[{
xtype: 'spacer',
height: 40,
//colspan: 3,
style: {
marginTop: '20px'
},
html: '<center><?=$Labels->GetLabel('_DET_SENSITIVITY_');?></center>',
}<?php
if( $CUser->Data['access']>4 ){
?>,{
xtype: 'button',
text: 'Resolve Trouble',
width: '100%',
//colspan: 3,
iconCls: 'ctrl_panel_cog',
scale: 'large',
iconAlign: 'left',
handler: function(){
detectionProfileWindow.hide();
resolveDeviceMistmatch( deviceCtrlNode );
}
}<?php
};
?>]
});
};
detectionProfileWindow.add({
xtype: 'spacer',
height: 30,
style: {
marginTop: '13px'
},
html: '<center><?=$Labels->GetLabel('_DET_GENWORKS_');?></center>',
});
detectionProfileWindow.add({
xtype: 'button',
width: '100%',
text: 'Clear Alarm',
scale: 'large',
iconCls: 'ctrl_panel_clean',
iconAlign: 'left'
});
detectionProfileWindow.add({
xtype: 'button',
width: '100%',
text: 'Draw Background',
scale: 'large',
iconCls: 'ctrl_panel_drawscan',
iconAlign: 'left',
handler: function(){
doDeviceOperation( deviceCtrlNode, 3 );
}
});
detectionProfileWindow.add({
xtype: 'button',
width: '100%',
text: 'Force Study Background',
scale: 'large',
iconCls: 'ctrl_panel_study',
iconAlign: 'left'
});
detectionProfileWindow.add({
xtype: 'button',
width: '100%',
buttonAlign: 'left',
//text: '<table width="100%" border=1><tr><td style="text-align:left">Button 1</td></tr></table>',
text: 'Force Reset Sensor',
scale: 'large',
iconCls: 'ctrl_panel_reset',
iconAlign: 'left',
handler: function(){
doDeviceOperation( deviceCtrlNode, 1 );
}
});
detectionProfileWindow.show();
},
failure: failureAJAXFunction
});
};