Support plugins in web user interface

This commit is contained in:
manupap1 2014-11-12 00:53:53 +01:00
parent 6d083fef10
commit eae1357a45
23 changed files with 647 additions and 70 deletions

View File

@ -372,11 +372,14 @@ if ( !empty($action) )
$changes=0; $changes=0;
foreach( $pconfs as $pconf ) foreach( $pconfs as $pconf )
{ {
$value=$_REQUEST['pluginOpt'][$pconf['Name']]; if(isset($_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'] ) ); $value=$_REQUEST['pluginOpt'][$pconf['Name']];
$changes++; 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) if($changes>0)
@ -409,6 +412,7 @@ if ( !empty($action) )
foreach( $_REQUEST['markZids'] as $markZid ) foreach( $_REQUEST['markZids'] as $markZid )
{ {
dbQuery( "delete from Zones WHERE MonitorId=? AND Id=?", array( $mid, $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; $deletedZid = 1;
} }
if ( $deletedZid ) if ( $deletedZid )
@ -593,6 +597,7 @@ if ( !empty($action) )
// This is the important stuff // This is the important stuff
dbQuery( "delete from Monitors where Id = ?", array($markMid) ); dbQuery( "delete from Monitors where Id = ?", array($markMid) );
dbQuery( "delete from Zones where MonitorId = ?", array($markMid) ); dbQuery( "delete from Zones where MonitorId = ?", array($markMid) );
dbQuery( "delete from PluginsConfig where MonitorId = ?", array($markMid) );
if ( ZM_OPT_X10 ) if ( ZM_OPT_X10 )
dbQuery( "delete from TriggersX10 where MonitorId=?", array($markMid) ); dbQuery( "delete from TriggersX10 where MonitorId=?", array($markMid) );

View File

@ -55,6 +55,7 @@ var popupSizes = {
'montage': { 'width': -1, 'height': -1 }, 'montage': { 'width': -1, 'height': -1 },
'optionhelp': { 'width': 400, 'height': 320 }, 'optionhelp': { 'width': 400, 'height': 320 },
'options': { 'width': 1000, 'height': 660 }, 'options': { 'width': 1000, 'height': 660 },
'plugin': { 'addWidth': 16, 'addHeight': 48 },
'preset': { 'width': 300, 'height': 120 }, 'preset': { 'width': 300, 'height': 120 },
'settings': { 'width': 220, 'height': 225 }, 'settings': { 'width': 220, 'height': 225 },
'state': { 'width': 370, 'height': 134 }, 'state': { 'width': 370, 'height': 134 },

View File

@ -41,6 +41,7 @@ dist_web_DATA = \
none.php \ none.php \
optionhelp.php \ optionhelp.php \
options.php \ options.php \
plugin.php \
postlogin.php \ postlogin.php \
settings.php \ settings.php \
state.php \ state.php \

View File

@ -23,6 +23,7 @@ dist_web_DATA = \
montage.css \ montage.css \
montage_freeform.css \ montage_freeform.css \
options.css \ options.css \
plugin.css \
stats.css \ stats.css \
timeline.css \ timeline.css \
timeline.css.php \ timeline.css.php \

View File

@ -3,6 +3,10 @@
margin: 0 2px; margin: 0 2px;
} }
#settingsPanel input[type=submit] {
margin: 8px 4px;
}
#pluginSettings { #pluginSettings {
border-collapse: collapse; border-collapse: collapse;
} }

View File

@ -93,3 +93,22 @@
#zonePoints table a { #zonePoints table a {
margin: 0 2px; 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;
}

View File

@ -33,6 +33,8 @@ dist_web_DATA = \
montage.js \ montage.js \
montage.js.php \ montage.js.php \
options.js.php \ options.js.php \
plugin.js \
plugin.js.php \
postlogin.js \ postlogin.js \
state.js \ state.js \
state.js.php \ state.js.php \

View File

@ -5,9 +5,49 @@ function validateForm( form )
function submitForm( 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(); 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 ) function limitRange( field, minValue, maxValue )
{ {

View File

@ -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
}
}
?>

View File

@ -106,6 +106,7 @@ if ( ! empty($_REQUEST['mid']) ) {
'Triggers' => "", 'Triggers' => "",
'V4LMultiBuffer' => '', 'V4LMultiBuffer' => '',
'V4LCapturesPerFrame' => 1, '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[Enabled]" value="<?= validHtmlStr($newMonitor['Enabled']) ?>"/>
<input type="hidden" name="newMonitor[RefBlendPerc]" value="<?= validHtmlStr($newMonitor['RefBlendPerc']) ?>"/> <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[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[MaxFPS]" value="<?= validHtmlStr($newMonitor['MaxFPS']) ?>"/>
<input type="hidden" name="newMonitor[AlarmMaxFPS]" value="<?= validHtmlStr($newMonitor['AlarmMaxFPS']) ?>"/> <input type="hidden" name="newMonitor[AlarmMaxFPS]" value="<?= validHtmlStr($newMonitor['AlarmMaxFPS']) ?>"/>
<?php <?php
@ -655,6 +657,7 @@ switch ( $tab )
<?php <?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> <tr><td><?= $SLANG['Triggers'] ?></td><td>
<?php <?php
$optTriggers = getSetValues( 'Monitors', 'Triggers' ); $optTriggers = getSetValues( 'Monitors', 'Triggers' );

View File

@ -38,67 +38,200 @@ if ( $zid > 0 ) {
$monitor = dbFetchMonitor ( $mid ); $monitor = dbFetchMonitor ( $mid );
$plugin = $_REQUEST['pl']; $plugin = $_REQUEST['pl'];
$plugin_path = dirname(ZM_PLUGINS_CONFIG_PATH)."/".$plugin; $plugin_path = dirname($_SERVER['SCRIPT_FILENAME'])."/plugins/".$plugin;
$focusWindow = true; $focusWindow = true;
xhtmlHeaders(__FILE__, $SLANG['Plugin'] ); $generalOptions=array(
'Enabled'=>array(
'Type'=>'select',
$pluginOptions=array( 'Name'=>'Enabled',
'Enabled'=>array( 'Choices'=>'Yes,No',
'Type'=>'select', 'Value'=>'No'
'Name'=>'Enabled', ),
'Choices'=>'yes,no', 'RequireNatDet'=>array(
'Value'=>'no' '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(); $optionNames=array();
if(file_exists($plugin_path."/config.php")) if(file_exists($plugin_path."/config.php"))
{ {
include_once($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=?'; $sql='SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?';
foreach( dbFetchAll( $sql, NULL, array( $mid, $zid, $plugin ) ) as $popt ) foreach( dbFetchAll( $sql, NULL, array( $mid, $zid, $plugin ) ) as $popt )
{ {
if(array_key_exists($popt['Name'], $pluginOptions) if(array_key_exists($popt['Name'], $options)
&& $popt['Type']==$pluginOptions[$popt['Name']]['Type'] && $popt['Type']==$options[$popt['Name']]['Type'])
&& $popt['Choices']==$pluginOptions[$popt['Name']]['Choices']
)
{ {
$pluginOptions[$popt['Name']]=$popt;
array_push($optionNames, $popt['Name']); 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 { } else {
dbQuery('DELETE FROM PluginsConfig WHERE Id=?', array( $popt['Id'] ) ); dbQuery('DELETE FROM PluginsConfig WHERE Id=?', array( $popt['Id'] ) );
} }
} }
foreach($pluginOptions as $name => $values)
foreach($options as $name => $values)
{ {
if(!in_array($name, $optionNames)) if(!in_array($name, $optionNames))
{ {
$popt=$pluginOptions[$name]; $popt=$options[$name];
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,?,?,?,?)"; switch($popt['Type'])
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Choices'], $mid, $zid, $plugin ) ); {
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(); $PLANG=array();
if(file_exists($plugin_path."/lang/".$user['Language'].".php")) { $lang_path = $plugin_path."/lang";
include_once($plugin_path."/lang/".$user['Language'].".php"); $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) function pLang($name)
{ {
global $SLANG;
global $PLANG; 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]; return $PLANG[$name];
else else
return $name; 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> <body>
<div id="page"> <div id="page">
@ -117,21 +250,23 @@ function pLang($name)
<table id="pluginSettings" cellspacing="0"> <table id="pluginSettings" cellspacing="0">
<tbody> <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']) switch($popt['Type'])
{ {
case "checkbox": 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; break;
case "select": case "select":
$pchoices=explode(',',$popt['Choices']); $pchoices=explode(',',$popt['Choices']);
?> ?>
<td colspan="2"> <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) foreach($pchoices as $pchoice)
{ {
@ -143,13 +278,22 @@ foreach($pluginOptions as $name => $popt)
<? <?
} }
?> ?>
</td>
</select> </select>
</td>
<? <?
break; break;
case "text": 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: default:
echo "DEFAULT"; echo "Type '".$popt['Type']."' is not implemented<br>";
} }
?> ?>
</tr> </tr>

View File

@ -212,6 +212,60 @@ xhtmlHeaders(__FILE__, $SLANG['Zone'] );
<th scope="row"><?= $SLANG['ZoneExtendAlarmFrames'] ?></th> <th scope="row"><?= $SLANG['ZoneExtendAlarmFrames'] ?></th>
<td colspan="2"><input type="text" name="newZone[ExtendAlarmFrames]" value="<?= $newZone['ExtendAlarmFrames'] ?>" size="4"/></td> <td colspan="2"><input type="text" name="newZone[ExtendAlarmFrames]" value="<?= $newZone['ExtendAlarmFrames'] ?>" size="4"/></td>
</tr> </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&amp;mid=".$monitor['Id']."&amp;zid=".
$zid."&amp;pl=".urlencode($plName)."' onclick=\"createPopup('?view=plugin&amp;mid=".
$monitor['Id']."&amp;zid=".$zid."&amp;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> </tbody>
</table> </table>
</div> </div>

View File

@ -55,6 +55,7 @@ var popupSizes = {
'montage': { 'width': -1, 'height': -1 }, 'montage': { 'width': -1, 'height': -1 },
'optionhelp': { 'width': 400, 'height': 320 }, 'optionhelp': { 'width': 400, 'height': 320 },
'options': { 'width': 1370, 'height': 620 }, 'options': { 'width': 1370, 'height': 620 },
'plugin': { 'addWidth': 16, 'addHeight': 48 },
'preset': { 'width': 300, 'height': 120 }, 'preset': { 'width': 300, 'height': 120 },
'settings': { 'width': 200, 'height': 225 }, 'settings': { 'width': 200, 'height': 225 },
'state': { 'width': 400, 'height': 154 }, 'state': { 'width': 400, 'height': 154 },

View File

@ -41,6 +41,7 @@ dist_web_DATA = \
none.php \ none.php \
optionhelp.php \ optionhelp.php \
options.php \ options.php \
plugin.php \
postlogin.php \ postlogin.php \
settings.php \ settings.php \
state.php \ state.php \

View File

@ -23,6 +23,7 @@ dist_web_DATA = \
montage.css \ montage.css \
montage_freeform.css \ montage_freeform.css \
options.css \ options.css \
plugin.css \
stats.css \ stats.css \
timeline.css \ timeline.css \
timeline.css.php \ timeline.css.php \

View File

@ -3,6 +3,10 @@
margin: 0 2px; margin: 0 2px;
} }
#settingsPanel input[type=submit] {
margin: 8px 4px;
}
#pluginSettings { #pluginSettings {
border-collapse: collapse; border-collapse: collapse;
} }

View File

@ -93,3 +93,22 @@
#zonePoints table a { #zonePoints table a {
margin: 0 2px; 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;
}

View File

@ -33,6 +33,8 @@ dist_web_DATA = \
montage.js \ montage.js \
montage.js.php \ montage.js.php \
options.js.php \ options.js.php \
plugin.js \
plugin.js.php \
postlogin.js \ postlogin.js \
state.js \ state.js \
state.js.php \ state.js.php \

View File

@ -5,9 +5,49 @@ function validateForm( form )
function submitForm( 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(); 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 ) function limitRange( field, minValue, maxValue )
{ {

View File

@ -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
}
}
?>

View File

@ -106,6 +106,7 @@ if ( ! empty($_REQUEST['mid']) ) {
'Triggers' => "", 'Triggers' => "",
'V4LMultiBuffer' => '', 'V4LMultiBuffer' => '',
'V4LCapturesPerFrame' => 1, '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[Enabled]" value="<?= validHtmlStr($newMonitor['Enabled']) ?>"/>
<input type="hidden" name="newMonitor[RefBlendPerc]" value="<?= validHtmlStr($newMonitor['RefBlendPerc']) ?>"/> <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[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[MaxFPS]" value="<?= validHtmlStr($newMonitor['MaxFPS']) ?>"/>
<input type="hidden" name="newMonitor[AlarmMaxFPS]" value="<?= validHtmlStr($newMonitor['AlarmMaxFPS']) ?>"/> <input type="hidden" name="newMonitor[AlarmMaxFPS]" value="<?= validHtmlStr($newMonitor['AlarmMaxFPS']) ?>"/>
<?php <?php
@ -656,6 +658,7 @@ switch ( $tab )
<?php <?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> <tr><td><?= $SLANG['Triggers'] ?></td><td>
<?php <?php
$optTriggers = getSetValues( 'Monitors', 'Triggers' ); $optTriggers = getSetValues( 'Monitors', 'Triggers' );

View File

@ -38,67 +38,200 @@ if ( $zid > 0 ) {
$monitor = dbFetchMonitor ( $mid ); $monitor = dbFetchMonitor ( $mid );
$plugin = $_REQUEST['pl']; $plugin = $_REQUEST['pl'];
$plugin_path = dirname(ZM_PLUGINS_CONFIG_PATH)."/".$plugin; $plugin_path = dirname($_SERVER['SCRIPT_FILENAME'])."/plugins/".$plugin;
$focusWindow = true; $focusWindow = true;
xhtmlHeaders(__FILE__, $SLANG['Plugin'] ); $generalOptions=array(
'Enabled'=>array(
'Type'=>'select',
$pluginOptions=array( 'Name'=>'Enabled',
'Enabled'=>array( 'Choices'=>'Yes,No',
'Type'=>'select', 'Value'=>'No'
'Name'=>'Enabled', ),
'Choices'=>'yes,no', 'RequireNatDet'=>array(
'Value'=>'no' '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(); $optionNames=array();
if(file_exists($plugin_path."/config.php")) if(file_exists($plugin_path."/config.php"))
{ {
include_once($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=?'; $sql='SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?';
foreach( dbFetchAll( $sql, NULL, array( $mid, $zid, $plugin ) ) as $popt ) foreach( dbFetchAll( $sql, NULL, array( $mid, $zid, $plugin ) ) as $popt )
{ {
if(array_key_exists($popt['Name'], $pluginOptions) if(array_key_exists($popt['Name'], $options)
&& $popt['Type']==$pluginOptions[$popt['Name']]['Type'] && $popt['Type']==$options[$popt['Name']]['Type'])
&& $popt['Choices']==$pluginOptions[$popt['Name']]['Choices']
)
{ {
$pluginOptions[$popt['Name']]=$popt;
array_push($optionNames, $popt['Name']); 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 { } else {
dbQuery('DELETE FROM PluginsConfig WHERE Id=?', array( $popt['Id'] ) ); dbQuery('DELETE FROM PluginsConfig WHERE Id=?', array( $popt['Id'] ) );
} }
} }
foreach($pluginOptions as $name => $values)
foreach($options as $name => $values)
{ {
if(!in_array($name, $optionNames)) if(!in_array($name, $optionNames))
{ {
$popt=$pluginOptions[$name]; $popt=$options[$name];
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,?,?,?,?)"; switch($popt['Type'])
dbQuery($sql, array( $popt['Name'], $popt['Value'], $popt['Type'], $popt['Choices'], $mid, $zid, $plugin ) ); {
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(); $PLANG=array();
if(file_exists($plugin_path."/lang/".$user['Language'].".php")) { $lang_path = $plugin_path."/lang";
include_once($plugin_path."/lang/".$user['Language'].".php"); $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) function pLang($name)
{ {
global $SLANG;
global $PLANG; 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]; return $PLANG[$name];
else else
return $name; 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> <body>
<div id="page"> <div id="page">
@ -117,21 +250,23 @@ function pLang($name)
<table id="pluginSettings" cellspacing="0"> <table id="pluginSettings" cellspacing="0">
<tbody> <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']) switch($popt['Type'])
{ {
case "checkbox": 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; break;
case "select": case "select":
$pchoices=explode(',',$popt['Choices']); $pchoices=explode(',',$popt['Choices']);
?> ?>
<td colspan="2"> <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) foreach($pchoices as $pchoice)
{ {
@ -143,13 +278,22 @@ foreach($pluginOptions as $name => $popt)
<? <?
} }
?> ?>
</td>
</select> </select>
</td>
<? <?
break; break;
case "text": 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: default:
echo "DEFAULT"; echo "Type '".$popt['Type']."' is not implemented<br>";
} }
?> ?>
</tr> </tr>

View File

@ -212,6 +212,60 @@ xhtmlHeaders(__FILE__, $SLANG['Zone'] );
<th scope="row"><?= $SLANG['ZoneExtendAlarmFrames'] ?></th> <th scope="row"><?= $SLANG['ZoneExtendAlarmFrames'] ?></th>
<td colspan="2"><input type="text" name="newZone[ExtendAlarmFrames]" value="<?= $newZone['ExtendAlarmFrames'] ?>" size="4"/></td> <td colspan="2"><input type="text" name="newZone[ExtendAlarmFrames]" value="<?= $newZone['ExtendAlarmFrames'] ?>" size="4"/></td>
</tr> </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&amp;mid=".$monitor['Id']."&amp;zid=".
$zid."&amp;pl=".urlencode($plName)."' onclick=\"createPopup('?view=plugin&amp;mid=".
$monitor['Id']."&amp;zid=".$zid."&amp;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> </tbody>
</table> </table>
</div> </div>