Support plugins in web user interface
This commit is contained in:
parent
6d083fef10
commit
eae1357a45
|
@ -372,11 +372,14 @@ if ( !empty($action) )
|
|||
$changes=0;
|
||||
foreach( $pconfs as $pconf )
|
||||
{
|
||||
$value=$_REQUEST['pluginOpt'][$pconf['Name']];
|
||||
if(array_key_exists($pconf['Name'], $_REQUEST['pluginOpt']) && ($pconf['Value']!=$value))
|
||||
if(isset($_REQUEST['pluginOpt'][$pconf['Name']]))
|
||||
{
|
||||
dbQuery("UPDATE PluginsConfig SET Value=? WHERE id=?", array( $value, $pconf['Id'] ) );
|
||||
$changes++;
|
||||
$value=$_REQUEST['pluginOpt'][$pconf['Name']];
|
||||
if(array_key_exists($pconf['Name'], $_REQUEST['pluginOpt']) && ($pconf['Value']!=$value))
|
||||
{
|
||||
dbQuery("UPDATE PluginsConfig SET Value=? WHERE id=?", array( $value, $pconf['Id'] ) );
|
||||
$changes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($changes>0)
|
||||
|
@ -409,6 +412,7 @@ if ( !empty($action) )
|
|||
foreach( $_REQUEST['markZids'] as $markZid )
|
||||
{
|
||||
dbQuery( "delete from Zones WHERE MonitorId=? AND Id=?", array( $mid, $markZid) );
|
||||
dbQuery( "delete from PluginsConfig WHERE MonitorId=? AND ZoneId=?", array( $mid, $markZid) );
|
||||
$deletedZid = 1;
|
||||
}
|
||||
if ( $deletedZid )
|
||||
|
@ -593,6 +597,7 @@ if ( !empty($action) )
|
|||
// This is the important stuff
|
||||
dbQuery( "delete from Monitors where Id = ?", array($markMid) );
|
||||
dbQuery( "delete from Zones where MonitorId = ?", array($markMid) );
|
||||
dbQuery( "delete from PluginsConfig where MonitorId = ?", array($markMid) );
|
||||
if ( ZM_OPT_X10 )
|
||||
dbQuery( "delete from TriggersX10 where MonitorId=?", array($markMid) );
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ var popupSizes = {
|
|||
'montage': { 'width': -1, 'height': -1 },
|
||||
'optionhelp': { 'width': 400, 'height': 320 },
|
||||
'options': { 'width': 1000, 'height': 660 },
|
||||
'plugin': { 'addWidth': 16, 'addHeight': 48 },
|
||||
'preset': { 'width': 300, 'height': 120 },
|
||||
'settings': { 'width': 220, 'height': 225 },
|
||||
'state': { 'width': 370, 'height': 134 },
|
||||
|
|
|
@ -41,6 +41,7 @@ dist_web_DATA = \
|
|||
none.php \
|
||||
optionhelp.php \
|
||||
options.php \
|
||||
plugin.php \
|
||||
postlogin.php \
|
||||
settings.php \
|
||||
state.php \
|
||||
|
|
|
@ -23,6 +23,7 @@ dist_web_DATA = \
|
|||
montage.css \
|
||||
montage_freeform.css \
|
||||
options.css \
|
||||
plugin.css \
|
||||
stats.css \
|
||||
timeline.css \
|
||||
timeline.css.php \
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
margin: 0 2px;
|
||||
}
|
||||
|
||||
#settingsPanel input[type=submit] {
|
||||
margin: 8px 4px;
|
||||
}
|
||||
|
||||
#pluginSettings {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
|
|
@ -93,3 +93,22 @@
|
|||
#zonePoints table a {
|
||||
margin: 0 2px;
|
||||
}
|
||||
|
||||
a.pluginNotEnabled {
|
||||
text-decoration: none;
|
||||
color: grey;
|
||||
}
|
||||
|
||||
a.pluginError {
|
||||
text-decoration: none;
|
||||
color: red;
|
||||
}
|
||||
|
||||
a.pluginNotActive {
|
||||
color: orange;
|
||||
}
|
||||
|
||||
a.pluginActive {
|
||||
color: green;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ dist_web_DATA = \
|
|||
montage.js \
|
||||
montage.js.php \
|
||||
options.js.php \
|
||||
plugin.js \
|
||||
plugin.js.php \
|
||||
postlogin.js \
|
||||
state.js \
|
||||
state.js.php \
|
||||
|
|
|
@ -5,9 +5,49 @@ function validateForm( form )
|
|||
|
||||
function submitForm( form )
|
||||
{
|
||||
var cb = form.getElementsByTagName('input');
|
||||
for ( var i = 0; i < cb.length; i++)
|
||||
{
|
||||
if ( cb[i].type == 'checkbox' && !cb[i].checked ) // if this is an unchecked checkbox
|
||||
{
|
||||
cb[i].value = 0; // set the value to "off"
|
||||
cb[i].checked = true; // make sure it submits
|
||||
}
|
||||
}
|
||||
form.submit();
|
||||
}
|
||||
|
||||
function saveChanges( element )
|
||||
{
|
||||
var form = element.form;
|
||||
if ( validateForm( form ) )
|
||||
{
|
||||
submitForm( form );
|
||||
return( true );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
function applyDependencies()
|
||||
{
|
||||
var form = document.pluginForm;
|
||||
for ( var option in dependencies )
|
||||
{
|
||||
var enabled = true;
|
||||
for ( var name in dependencies[option] )
|
||||
{
|
||||
if (form.elements['pluginOpt[' + name + ']'].value != dependencies[option][name])
|
||||
{
|
||||
form.elements['pluginOpt[' + option + ']'].disabled = true;
|
||||
enabled = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (enabled)
|
||||
form.elements['pluginOpt[' + option + ']'].disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function limitRange( field, minValue, maxValue )
|
||||
{
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
var dependencies = {};
|
||||
<?php
|
||||
foreach ( $options as $option )
|
||||
{
|
||||
if (!isset($option['Require']))
|
||||
continue;
|
||||
?>
|
||||
dependencies['<?= $option['Name'] ?>'] = {};
|
||||
<?php
|
||||
foreach($option['Require'] as $req_couple)
|
||||
{
|
||||
?>
|
||||
dependencies['<?= $option['Name'] ?>']['<?= $req_couple['Name'] ?>'] = '<?= $req_couple['Value'] ?>';
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -106,6 +106,7 @@ if ( ! empty($_REQUEST['mid']) ) {
|
|||
'Triggers' => "",
|
||||
'V4LMultiBuffer' => '',
|
||||
'V4LCapturesPerFrame' => 1,
|
||||
'DoNativeMotDet' => true
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -471,6 +472,7 @@ if ( $tab != 'general' )
|
|||
<input type="hidden" name="newMonitor[Enabled]" value="<?= validHtmlStr($newMonitor['Enabled']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[RefBlendPerc]" value="<?= validHtmlStr($newMonitor['RefBlendPerc']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[AlarmRefBlendPerc]" value="<?= validHtmlStr($newMonitor['AlarmRefBlendPerc']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[DoNativeMotDet]" value="<?= validHtmlStr($newMonitor['DoNativeMotDet']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[MaxFPS]" value="<?= validHtmlStr($newMonitor['MaxFPS']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[AlarmMaxFPS]" value="<?= validHtmlStr($newMonitor['AlarmMaxFPS']) ?>"/>
|
||||
<?php
|
||||
|
@ -655,6 +657,7 @@ switch ( $tab )
|
|||
<?php
|
||||
}
|
||||
?>
|
||||
<tr><td><?= $SLANG['DoNativeMotionDetection'] ?></td><td><input type="checkbox" name="newMonitor[DoNativeMotDet]" value="1"<?php if ( !empty($newMonitor['DoNativeMotDet']) ) { ?> checked="checked"<?php } ?>/></td></tr>
|
||||
<tr><td><?= $SLANG['Triggers'] ?></td><td>
|
||||
<?php
|
||||
$optTriggers = getSetValues( 'Monitors', 'Triggers' );
|
||||
|
|
|
@ -38,67 +38,200 @@ if ( $zid > 0 ) {
|
|||
$monitor = dbFetchMonitor ( $mid );
|
||||
$plugin = $_REQUEST['pl'];
|
||||
|
||||
$plugin_path = dirname(ZM_PLUGINS_CONFIG_PATH)."/".$plugin;
|
||||
$plugin_path = dirname($_SERVER['SCRIPT_FILENAME'])."/plugins/".$plugin;
|
||||
|
||||
$focusWindow = true;
|
||||
|
||||
xhtmlHeaders(__FILE__, $SLANG['Plugin'] );
|
||||
|
||||
|
||||
$pluginOptions=array(
|
||||
'Enabled'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'Enabled',
|
||||
'Choices'=>'yes,no',
|
||||
'Value'=>'no'
|
||||
)
|
||||
);
|
||||
$generalOptions=array(
|
||||
'Enabled'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'Enabled',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No'
|
||||
),
|
||||
'RequireNatDet'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'RequireNatDet',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
),
|
||||
'IncludeNatDet'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'IncludeNatDet',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
),
|
||||
array(
|
||||
'Name'=>'RequireNatDet',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
),
|
||||
'ReInitNatDet'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'ReInitNatDet',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
),
|
||||
array(
|
||||
'Name'=>'RequireNatDet',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
),
|
||||
'AlarmeScore'=>array(
|
||||
'Type'=>'integer',
|
||||
'Name'=>'AlarmeScore',
|
||||
'Min'=>'1',
|
||||
'Max'=>'100',
|
||||
'Value'=>'99',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$options=$generalOptions;
|
||||
$optionNames=array();
|
||||
if(file_exists($plugin_path."/config.php"))
|
||||
{
|
||||
include_once($plugin_path."/config.php");
|
||||
}
|
||||
if(isset($pluginOptions))
|
||||
foreach( $pluginOptions as $optionKey => $optionValue )
|
||||
{
|
||||
// Set default dependency information if not set in configuration file
|
||||
if(!isset($optionValue['Require']))
|
||||
$optionValue['Require'] = array (
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
);
|
||||
$options[$optionKey]=$optionValue;
|
||||
}
|
||||
}
|
||||
|
||||
$sql='SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?';
|
||||
foreach( dbFetchAll( $sql, NULL, array( $mid, $zid, $plugin ) ) as $popt )
|
||||
{
|
||||
if(array_key_exists($popt['Name'], $pluginOptions)
|
||||
&& $popt['Type']==$pluginOptions[$popt['Name']]['Type']
|
||||
&& $popt['Choices']==$pluginOptions[$popt['Name']]['Choices']
|
||||
)
|
||||
if(array_key_exists($popt['Name'], $options)
|
||||
&& $popt['Type']==$options[$popt['Name']]['Type'])
|
||||
{
|
||||
$pluginOptions[$popt['Name']]=$popt;
|
||||
array_push($optionNames, $popt['Name']);
|
||||
|
||||
// Backup dependency information
|
||||
$require = '';
|
||||
if(isset($options[$popt['Name']]['Require']))
|
||||
$require = $options[$popt['Name']]['Require'];
|
||||
|
||||
// Set value from database
|
||||
$options[$popt['Name']]=$popt;
|
||||
|
||||
// Restore dependancy information from backup
|
||||
if(!empty($require))
|
||||
$options[$popt['Name']]['Require'] = $require;
|
||||
|
||||
// Set default dependancy information if not set in configuration
|
||||
else if($popt['Name'] != 'Enabled')
|
||||
$options[$popt['Name']]['Require'] = array (
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
dbQuery('DELETE FROM PluginsConfig WHERE Id=?', array( $popt['Id'] ) );
|
||||
}
|
||||
}
|
||||
foreach($pluginOptions as $name => $values)
|
||||
|
||||
foreach($options as $name => $values)
|
||||
{
|
||||
if(!in_array($name, $optionNames))
|
||||
{
|
||||
$popt=$pluginOptions[$name];
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,?,?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Choices'], $mid, $zid, $plugin ) );
|
||||
$popt=$options[$name];
|
||||
switch($popt['Type'])
|
||||
{
|
||||
case "select":
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,?,'','',?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Choices'], $mid, $zid, $plugin ) );
|
||||
break;
|
||||
case "integer":
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,'',?,?,?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Min'], $popt['Max'], $mid, $zid, $plugin ) );
|
||||
break;
|
||||
case "checkbox":
|
||||
case "text":
|
||||
default:
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,'','','',?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $mid, $zid, $plugin ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$PLANG=array();
|
||||
if(file_exists($plugin_path."/lang/".$user['Language'].".php")) {
|
||||
include_once($plugin_path."/lang/".$user['Language'].".php");
|
||||
$lang_path = $plugin_path."/lang";
|
||||
$userLangFile = $lang_path."/".$user['Language'].".php";
|
||||
if (isset($user['Language']) && file_exists($userLangFile)) {
|
||||
include_once($userLangFile);
|
||||
} else {
|
||||
$systemLangFile = $lang_path."/".ZM_LANG_DEFAULT.".php";
|
||||
if (file_exists($systemLangFile)) {
|
||||
include_once($systemLangFile);
|
||||
} else {
|
||||
$fallbackLangFile = $lang_path."/en_gb.php";
|
||||
if (file_exists($fallbackLangFile)) {
|
||||
include_once($fallbackLangFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pLang($name)
|
||||
{
|
||||
global $SLANG;
|
||||
global $PLANG;
|
||||
if(array_key_exists($name, $PLANG))
|
||||
if(array_key_exists($name, $SLANG))
|
||||
return $SLANG[$name];
|
||||
else if(array_key_exists($name, $PLANG))
|
||||
return $PLANG[$name];
|
||||
else
|
||||
return $name;
|
||||
}
|
||||
|
||||
function isEnabled($param)
|
||||
{
|
||||
global $options;
|
||||
$option = $options[$param];
|
||||
if (!isset($option['Require']))
|
||||
return true;
|
||||
foreach($option['Require'] as $req_couple)
|
||||
{
|
||||
$name = $req_couple['Name'];
|
||||
if (!array_key_exists($name, $options))
|
||||
continue;
|
||||
if ($req_couple['Value'] != $options[$name]['Value'])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
xhtmlHeaders(__FILE__, $SLANG['Plugin'] );
|
||||
?>
|
||||
<body>
|
||||
<div id="page">
|
||||
|
@ -117,21 +250,23 @@ function pLang($name)
|
|||
<table id="pluginSettings" cellspacing="0">
|
||||
<tbody>
|
||||
<?
|
||||
foreach($pluginOptions as $name => $popt)
|
||||
foreach($options as $name => $popt)
|
||||
{
|
||||
?>
|
||||
<tr><th scope="row"><?= pLang($name) ?></th>
|
||||
<?
|
||||
?>
|
||||
<tr><th scope="row"><?= pLang($name) ?></th>
|
||||
<?
|
||||
switch($popt['Type'])
|
||||
{
|
||||
case "checkbox":
|
||||
echo "CHECKBOX";
|
||||
?>
|
||||
<td><input type="checkbox" name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" <? if ($popt['Value']) echo 'checked="checked"'; if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?>></td>
|
||||
<?
|
||||
break;
|
||||
case "select":
|
||||
$pchoices=explode(',',$popt['Choices']);
|
||||
?>
|
||||
<td colspan="2">
|
||||
<select name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]">
|
||||
<select name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" <? if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?> onchange="applyDependencies()" >
|
||||
<?
|
||||
foreach($pchoices as $pchoice)
|
||||
{
|
||||
|
@ -143,13 +278,22 @@ foreach($pluginOptions as $name => $popt)
|
|||
<?
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</select>
|
||||
</td>
|
||||
<?
|
||||
break;
|
||||
case "text":
|
||||
?>
|
||||
<td><input type="text" name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" value="<?= $popt['Value'] ?>" <? if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?>></td>
|
||||
<?
|
||||
break;
|
||||
case "integer":
|
||||
?>
|
||||
<td><input type="text" name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" onchange="limitRange( this, <?= $popt['Min'] ?>, <?= $popt['Max'] ?> )" value="<?= $popt['Value'] ?>" size="4" <? if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?>></td>
|
||||
<?
|
||||
break;
|
||||
default:
|
||||
echo "DEFAULT";
|
||||
echo "Type '".$popt['Type']."' is not implemented<br>";
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
|
|
|
@ -212,6 +212,60 @@ xhtmlHeaders(__FILE__, $SLANG['Zone'] );
|
|||
<th scope="row"><?= $SLANG['ZoneExtendAlarmFrames'] ?></th>
|
||||
<td colspan="2"><input type="text" name="newZone[ExtendAlarmFrames]" value="<?= $newZone['ExtendAlarmFrames'] ?>" size="4"/></td>
|
||||
</tr>
|
||||
<?php
|
||||
if ($zid > 0)
|
||||
{
|
||||
// Get plugin status from zmu command line
|
||||
exec(escapeshellcmd(getZmuCommand(" -p -m".$mid)), $cmdOutput, $retval);
|
||||
if($retval == 0)
|
||||
{
|
||||
echo "<tr><th scope=\"row\">".$SLANG['Plugins']."</th><td colspan=2>\n";
|
||||
$plName = "";
|
||||
$plReg = "0";
|
||||
$plConf = "0";
|
||||
foreach($cmdOutput as $key => $line)
|
||||
{
|
||||
// Skip header lines or "No plugin found"
|
||||
if($key < 2) continue;
|
||||
// Parse line
|
||||
$pl = preg_split ('/[\s]+/ ', trim($line));
|
||||
$offset = 0;
|
||||
if(sizeof($pl) == 9)
|
||||
{
|
||||
$plName = $pl[0];
|
||||
$plReg = $pl[1];
|
||||
$plConf = $pl[2];
|
||||
$offset = 3;
|
||||
}
|
||||
// Skip line if zone mismatch
|
||||
if($pl[$offset] != $zid) continue;
|
||||
// Select class and set display setting
|
||||
$class = '';
|
||||
$dspPlConf = true;
|
||||
if(!ZM_LOAD_PLUGINS) {
|
||||
$class = " class=\"pluginNotEnabled\"";
|
||||
$dspPlConf = false;
|
||||
} else if($plReg == "0" || (($plReg == "1") && ($plConf == "0"))) {
|
||||
$class = " class=\"pluginError\"";
|
||||
$dspPlConf = false;
|
||||
} else if(($pl[1 + $offset] == "1") && ($pl[2 + $offset] == "0")) {
|
||||
$class = " class=\"pluginNotActive\"";
|
||||
} else if($pl[2 + $offset] == "1") {
|
||||
$class = " class=\"pluginActive\"";
|
||||
}
|
||||
// Display plugin name and enable link
|
||||
if($dspPlConf)
|
||||
echo "<a".$class." href='?view=plugin&mid=".$monitor['Id']."&zid=".
|
||||
$zid."&pl=".urlencode($plName)."' onclick=\"createPopup('?view=plugin&mid=".
|
||||
$monitor['Id']."&zid=".$zid."&pl=".urlencode($plName)."','plugin','plugin',".
|
||||
"500,400); return(false)\">".$plName."</a><br>\n";
|
||||
else
|
||||
echo "<a".$class.">".$plName."</a><br>\n";
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -55,6 +55,7 @@ var popupSizes = {
|
|||
'montage': { 'width': -1, 'height': -1 },
|
||||
'optionhelp': { 'width': 400, 'height': 320 },
|
||||
'options': { 'width': 1370, 'height': 620 },
|
||||
'plugin': { 'addWidth': 16, 'addHeight': 48 },
|
||||
'preset': { 'width': 300, 'height': 120 },
|
||||
'settings': { 'width': 200, 'height': 225 },
|
||||
'state': { 'width': 400, 'height': 154 },
|
||||
|
|
|
@ -41,6 +41,7 @@ dist_web_DATA = \
|
|||
none.php \
|
||||
optionhelp.php \
|
||||
options.php \
|
||||
plugin.php \
|
||||
postlogin.php \
|
||||
settings.php \
|
||||
state.php \
|
||||
|
|
|
@ -23,6 +23,7 @@ dist_web_DATA = \
|
|||
montage.css \
|
||||
montage_freeform.css \
|
||||
options.css \
|
||||
plugin.css \
|
||||
stats.css \
|
||||
timeline.css \
|
||||
timeline.css.php \
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
margin: 0 2px;
|
||||
}
|
||||
|
||||
#settingsPanel input[type=submit] {
|
||||
margin: 8px 4px;
|
||||
}
|
||||
|
||||
#pluginSettings {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
|
|
@ -93,3 +93,22 @@
|
|||
#zonePoints table a {
|
||||
margin: 0 2px;
|
||||
}
|
||||
|
||||
a.pluginNotEnabled {
|
||||
text-decoration: none;
|
||||
color: grey;
|
||||
}
|
||||
|
||||
a.pluginError {
|
||||
text-decoration: none;
|
||||
color: red;
|
||||
}
|
||||
|
||||
a.pluginNotActive {
|
||||
color: orange;
|
||||
}
|
||||
|
||||
a.pluginActive {
|
||||
color: green;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,8 @@ dist_web_DATA = \
|
|||
montage.js \
|
||||
montage.js.php \
|
||||
options.js.php \
|
||||
plugin.js \
|
||||
plugin.js.php \
|
||||
postlogin.js \
|
||||
state.js \
|
||||
state.js.php \
|
||||
|
|
|
@ -5,9 +5,49 @@ function validateForm( form )
|
|||
|
||||
function submitForm( form )
|
||||
{
|
||||
var cb = form.getElementsByTagName('input');
|
||||
for ( var i = 0; i < cb.length; i++)
|
||||
{
|
||||
if ( cb[i].type == 'checkbox' && !cb[i].checked ) // if this is an unchecked checkbox
|
||||
{
|
||||
cb[i].value = 0; // set the value to "off"
|
||||
cb[i].checked = true; // make sure it submits
|
||||
}
|
||||
}
|
||||
form.submit();
|
||||
}
|
||||
|
||||
function saveChanges( element )
|
||||
{
|
||||
var form = element.form;
|
||||
if ( validateForm( form ) )
|
||||
{
|
||||
submitForm( form );
|
||||
return( true );
|
||||
}
|
||||
return( false );
|
||||
}
|
||||
|
||||
function applyDependencies()
|
||||
{
|
||||
var form = document.pluginForm;
|
||||
for ( var option in dependencies )
|
||||
{
|
||||
var enabled = true;
|
||||
for ( var name in dependencies[option] )
|
||||
{
|
||||
if (form.elements['pluginOpt[' + name + ']'].value != dependencies[option][name])
|
||||
{
|
||||
form.elements['pluginOpt[' + option + ']'].disabled = true;
|
||||
enabled = false;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (enabled)
|
||||
form.elements['pluginOpt[' + option + ']'].disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function limitRange( field, minValue, maxValue )
|
||||
{
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
var dependencies = {};
|
||||
<?php
|
||||
foreach ( $options as $option )
|
||||
{
|
||||
if (!isset($option['Require']))
|
||||
continue;
|
||||
?>
|
||||
dependencies['<?= $option['Name'] ?>'] = {};
|
||||
<?php
|
||||
foreach($option['Require'] as $req_couple)
|
||||
{
|
||||
?>
|
||||
dependencies['<?= $option['Name'] ?>']['<?= $req_couple['Name'] ?>'] = '<?= $req_couple['Value'] ?>';
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -106,6 +106,7 @@ if ( ! empty($_REQUEST['mid']) ) {
|
|||
'Triggers' => "",
|
||||
'V4LMultiBuffer' => '',
|
||||
'V4LCapturesPerFrame' => 1,
|
||||
'DoNativeMotDet' => true
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -471,6 +472,7 @@ if ( $tab != 'general' )
|
|||
<input type="hidden" name="newMonitor[Enabled]" value="<?= validHtmlStr($newMonitor['Enabled']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[RefBlendPerc]" value="<?= validHtmlStr($newMonitor['RefBlendPerc']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[AlarmRefBlendPerc]" value="<?= validHtmlStr($newMonitor['AlarmRefBlendPerc']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[DoNativeMotDet]" value="<?= validHtmlStr($newMonitor['DoNativeMotDet']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[MaxFPS]" value="<?= validHtmlStr($newMonitor['MaxFPS']) ?>"/>
|
||||
<input type="hidden" name="newMonitor[AlarmMaxFPS]" value="<?= validHtmlStr($newMonitor['AlarmMaxFPS']) ?>"/>
|
||||
<?php
|
||||
|
@ -656,6 +658,7 @@ switch ( $tab )
|
|||
<?php
|
||||
}
|
||||
?>
|
||||
<tr><td><?= $SLANG['DoNativeMotionDetection'] ?></td><td><input type="checkbox" name="newMonitor[DoNativeMotDet]" value="1"<?php if ( !empty($newMonitor['DoNativeMotDet']) ) { ?> checked="checked"<?php } ?>/></td></tr>
|
||||
<tr><td><?= $SLANG['Triggers'] ?></td><td>
|
||||
<?php
|
||||
$optTriggers = getSetValues( 'Monitors', 'Triggers' );
|
||||
|
|
|
@ -38,67 +38,200 @@ if ( $zid > 0 ) {
|
|||
$monitor = dbFetchMonitor ( $mid );
|
||||
$plugin = $_REQUEST['pl'];
|
||||
|
||||
$plugin_path = dirname(ZM_PLUGINS_CONFIG_PATH)."/".$plugin;
|
||||
$plugin_path = dirname($_SERVER['SCRIPT_FILENAME'])."/plugins/".$plugin;
|
||||
|
||||
$focusWindow = true;
|
||||
|
||||
xhtmlHeaders(__FILE__, $SLANG['Plugin'] );
|
||||
|
||||
|
||||
$pluginOptions=array(
|
||||
'Enabled'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'Enabled',
|
||||
'Choices'=>'yes,no',
|
||||
'Value'=>'no'
|
||||
)
|
||||
);
|
||||
$generalOptions=array(
|
||||
'Enabled'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'Enabled',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No'
|
||||
),
|
||||
'RequireNatDet'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'RequireNatDet',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
),
|
||||
'IncludeNatDet'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'IncludeNatDet',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
),
|
||||
array(
|
||||
'Name'=>'RequireNatDet',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
),
|
||||
'ReInitNatDet'=>array(
|
||||
'Type'=>'select',
|
||||
'Name'=>'ReInitNatDet',
|
||||
'Choices'=>'Yes,No',
|
||||
'Value'=>'No',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
),
|
||||
array(
|
||||
'Name'=>'RequireNatDet',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
),
|
||||
'AlarmeScore'=>array(
|
||||
'Type'=>'integer',
|
||||
'Name'=>'AlarmeScore',
|
||||
'Min'=>'1',
|
||||
'Max'=>'100',
|
||||
'Value'=>'99',
|
||||
'Require'=>array(
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$options=$generalOptions;
|
||||
$optionNames=array();
|
||||
if(file_exists($plugin_path."/config.php"))
|
||||
{
|
||||
include_once($plugin_path."/config.php");
|
||||
}
|
||||
if(isset($pluginOptions))
|
||||
foreach( $pluginOptions as $optionKey => $optionValue )
|
||||
{
|
||||
// Set default dependency information if not set in configuration file
|
||||
if(!isset($optionValue['Require']))
|
||||
$optionValue['Require'] = array (
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
);
|
||||
$options[$optionKey]=$optionValue;
|
||||
}
|
||||
}
|
||||
|
||||
$sql='SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?';
|
||||
foreach( dbFetchAll( $sql, NULL, array( $mid, $zid, $plugin ) ) as $popt )
|
||||
{
|
||||
if(array_key_exists($popt['Name'], $pluginOptions)
|
||||
&& $popt['Type']==$pluginOptions[$popt['Name']]['Type']
|
||||
&& $popt['Choices']==$pluginOptions[$popt['Name']]['Choices']
|
||||
)
|
||||
if(array_key_exists($popt['Name'], $options)
|
||||
&& $popt['Type']==$options[$popt['Name']]['Type'])
|
||||
{
|
||||
$pluginOptions[$popt['Name']]=$popt;
|
||||
array_push($optionNames, $popt['Name']);
|
||||
|
||||
// Backup dependency information
|
||||
$require = '';
|
||||
if(isset($options[$popt['Name']]['Require']))
|
||||
$require = $options[$popt['Name']]['Require'];
|
||||
|
||||
// Set value from database
|
||||
$options[$popt['Name']]=$popt;
|
||||
|
||||
// Restore dependancy information from backup
|
||||
if(!empty($require))
|
||||
$options[$popt['Name']]['Require'] = $require;
|
||||
|
||||
// Set default dependancy information if not set in configuration
|
||||
else if($popt['Name'] != 'Enabled')
|
||||
$options[$popt['Name']]['Require'] = array (
|
||||
array(
|
||||
'Name'=>'Enabled',
|
||||
'Value'=>'Yes'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
dbQuery('DELETE FROM PluginsConfig WHERE Id=?', array( $popt['Id'] ) );
|
||||
}
|
||||
}
|
||||
foreach($pluginOptions as $name => $values)
|
||||
|
||||
foreach($options as $name => $values)
|
||||
{
|
||||
if(!in_array($name, $optionNames))
|
||||
{
|
||||
$popt=$pluginOptions[$name];
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,?,?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Choices'], $mid, $zid, $plugin ) );
|
||||
$popt=$options[$name];
|
||||
switch($popt['Type'])
|
||||
{
|
||||
case "select":
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,?,'','',?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Choices'], $mid, $zid, $plugin ) );
|
||||
break;
|
||||
case "integer":
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,'',?,?,?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Min'], $popt['Max'], $mid, $zid, $plugin ) );
|
||||
break;
|
||||
case "checkbox":
|
||||
case "text":
|
||||
default:
|
||||
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,'','','',?,?,?)";
|
||||
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $mid, $zid, $plugin ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$PLANG=array();
|
||||
if(file_exists($plugin_path."/lang/".$user['Language'].".php")) {
|
||||
include_once($plugin_path."/lang/".$user['Language'].".php");
|
||||
$lang_path = $plugin_path."/lang";
|
||||
$userLangFile = $lang_path."/".$user['Language'].".php";
|
||||
if (isset($user['Language']) && file_exists($userLangFile)) {
|
||||
include_once($userLangFile);
|
||||
} else {
|
||||
$systemLangFile = $lang_path."/".ZM_LANG_DEFAULT.".php";
|
||||
if (file_exists($systemLangFile)) {
|
||||
include_once($systemLangFile);
|
||||
} else {
|
||||
$fallbackLangFile = $lang_path."/en_gb.php";
|
||||
if (file_exists($fallbackLangFile)) {
|
||||
include_once($fallbackLangFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function pLang($name)
|
||||
{
|
||||
global $SLANG;
|
||||
global $PLANG;
|
||||
if(array_key_exists($name, $PLANG))
|
||||
if(array_key_exists($name, $SLANG))
|
||||
return $SLANG[$name];
|
||||
else if(array_key_exists($name, $PLANG))
|
||||
return $PLANG[$name];
|
||||
else
|
||||
return $name;
|
||||
}
|
||||
|
||||
function isEnabled($param)
|
||||
{
|
||||
global $options;
|
||||
$option = $options[$param];
|
||||
if (!isset($option['Require']))
|
||||
return true;
|
||||
foreach($option['Require'] as $req_couple)
|
||||
{
|
||||
$name = $req_couple['Name'];
|
||||
if (!array_key_exists($name, $options))
|
||||
continue;
|
||||
if ($req_couple['Value'] != $options[$name]['Value'])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
xhtmlHeaders(__FILE__, $SLANG['Plugin'] );
|
||||
?>
|
||||
<body>
|
||||
<div id="page">
|
||||
|
@ -117,21 +250,23 @@ function pLang($name)
|
|||
<table id="pluginSettings" cellspacing="0">
|
||||
<tbody>
|
||||
<?
|
||||
foreach($pluginOptions as $name => $popt)
|
||||
foreach($options as $name => $popt)
|
||||
{
|
||||
?>
|
||||
<tr><th scope="row"><?= pLang($name) ?></th>
|
||||
<?
|
||||
?>
|
||||
<tr><th scope="row"><?= pLang($name) ?></th>
|
||||
<?
|
||||
switch($popt['Type'])
|
||||
{
|
||||
case "checkbox":
|
||||
echo "CHECKBOX";
|
||||
?>
|
||||
<td><input type="checkbox" name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" <? if ($popt['Value']) echo 'checked="checked"'; if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?>></td>
|
||||
<?
|
||||
break;
|
||||
case "select":
|
||||
$pchoices=explode(',',$popt['Choices']);
|
||||
?>
|
||||
<td colspan="2">
|
||||
<select name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]">
|
||||
<select name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" <? if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?> onchange="applyDependencies()" >
|
||||
<?
|
||||
foreach($pchoices as $pchoice)
|
||||
{
|
||||
|
@ -143,13 +278,22 @@ foreach($pluginOptions as $name => $popt)
|
|||
<?
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</select>
|
||||
</td>
|
||||
<?
|
||||
break;
|
||||
case "text":
|
||||
?>
|
||||
<td><input type="text" name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" value="<?= $popt['Value'] ?>" <? if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?>></td>
|
||||
<?
|
||||
break;
|
||||
case "integer":
|
||||
?>
|
||||
<td><input type="text" name="pluginOpt[<?= $popt['Name'] ?>]" id="pluginOpt[<?= $popt['Name'] ?>]" onchange="limitRange( this, <?= $popt['Min'] ?>, <?= $popt['Max'] ?> )" value="<?= $popt['Value'] ?>" size="4" <? if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?>></td>
|
||||
<?
|
||||
break;
|
||||
default:
|
||||
echo "DEFAULT";
|
||||
echo "Type '".$popt['Type']."' is not implemented<br>";
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
|
|
|
@ -212,6 +212,60 @@ xhtmlHeaders(__FILE__, $SLANG['Zone'] );
|
|||
<th scope="row"><?= $SLANG['ZoneExtendAlarmFrames'] ?></th>
|
||||
<td colspan="2"><input type="text" name="newZone[ExtendAlarmFrames]" value="<?= $newZone['ExtendAlarmFrames'] ?>" size="4"/></td>
|
||||
</tr>
|
||||
<?php
|
||||
if ($zid > 0)
|
||||
{
|
||||
// Get plugin status from zmu command line
|
||||
exec(escapeshellcmd(getZmuCommand(" -p -m".$mid)), $cmdOutput, $retval);
|
||||
if($retval == 0)
|
||||
{
|
||||
echo "<tr><th scope=\"row\">".$SLANG['Plugins']."</th><td colspan=2>\n";
|
||||
$plName = "";
|
||||
$plReg = "0";
|
||||
$plConf = "0";
|
||||
foreach($cmdOutput as $key => $line)
|
||||
{
|
||||
// Skip header lines or "No plugin found"
|
||||
if($key < 2) continue;
|
||||
// Parse line
|
||||
$pl = preg_split ('/[\s]+/ ', trim($line));
|
||||
$offset = 0;
|
||||
if(sizeof($pl) == 9)
|
||||
{
|
||||
$plName = $pl[0];
|
||||
$plReg = $pl[1];
|
||||
$plConf = $pl[2];
|
||||
$offset = 3;
|
||||
}
|
||||
// Skip line if zone mismatch
|
||||
if($pl[$offset] != $zid) continue;
|
||||
// Select class and set display setting
|
||||
$class = '';
|
||||
$dspPlConf = true;
|
||||
if(!ZM_LOAD_PLUGINS) {
|
||||
$class = " class=\"pluginNotEnabled\"";
|
||||
$dspPlConf = false;
|
||||
} else if($plReg == "0" || (($plReg == "1") && ($plConf == "0"))) {
|
||||
$class = " class=\"pluginError\"";
|
||||
$dspPlConf = false;
|
||||
} else if(($pl[1 + $offset] == "1") && ($pl[2 + $offset] == "0")) {
|
||||
$class = " class=\"pluginNotActive\"";
|
||||
} else if($pl[2 + $offset] == "1") {
|
||||
$class = " class=\"pluginActive\"";
|
||||
}
|
||||
// Display plugin name and enable link
|
||||
if($dspPlConf)
|
||||
echo "<a".$class." href='?view=plugin&mid=".$monitor['Id']."&zid=".
|
||||
$zid."&pl=".urlencode($plName)."' onclick=\"createPopup('?view=plugin&mid=".
|
||||
$monitor['Id']."&zid=".$zid."&pl=".urlencode($plName)."','plugin','plugin',".
|
||||
"500,400); return(false)\">".$plName."</a><br>\n";
|
||||
else
|
||||
echo "<a".$class.">".$plName."</a><br>\n";
|
||||
}
|
||||
echo "</td></tr>\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue