zoneminder/web/skins/classic/views/plugin.php

368 lines
13 KiB
PHP
Raw Permalink Normal View History

2013-03-17 07:45:21 +08:00
<?php
//
// ZoneMinder web zone view file, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
if ( !canView( 'Monitors' ) )
{
$view = "error";
return;
}
$mid = validInt($_REQUEST['mid']);
$zid = !empty($_REQUEST['zid'])?validInt($_REQUEST['zid']):0;
2013-12-18 01:53:15 +08:00
if ( $zid > 0 ) {
$newZone = dbFetchOne( 'SELECT * FROM Zones WHERE MonitorId = ? AND Id = ?', NULL, array( $mid, $zid) );
2013-03-17 07:45:21 +08:00
} else {
$view = "error";
return;
}
$monitor = dbFetchMonitor ( $mid );
2013-12-18 01:53:15 +08:00
$plugin = $_REQUEST['pl'];
2013-03-17 07:45:21 +08:00
2014-11-12 07:53:53 +08:00
$plugin_path = dirname($_SERVER['SCRIPT_FILENAME'])."/plugins/".$plugin;
2013-03-17 07:45:21 +08:00
$focusWindow = true;
2015-05-15 14:11:51 +08:00
$generalOptions = array(
'Enabled' => array(
'Type' => 'select',
'Choices' => 'Yes,No',
'Value' => 'No',
2014-11-12 07:53:53 +08:00
),
2015-05-15 14:11:51 +08:00
'RequireNatDet' => array(
'Type' => 'select',
'Choices' => 'Yes,No',
'Value' => 'No',
'Require' => array(
2014-11-12 07:53:53 +08:00
array(
2015-05-15 14:11:51 +08:00
'Name' => 'Enabled',
'Value' => 'Yes',
),
),
2014-11-12 07:53:53 +08:00
),
2015-05-15 14:11:51 +08:00
'IncludeNatDet' => array(
'Type' => 'select',
'Choices' => 'Yes,No',
'Value' => 'No',
'Require' => array(
2014-11-12 07:53:53 +08:00
array(
2015-05-15 14:11:51 +08:00
'Name' => 'Enabled',
'Value' => 'Yes',
2014-11-12 07:53:53 +08:00
),
array(
2015-05-15 14:11:51 +08:00
'Name' => 'RequireNatDet',
'Value' => 'Yes',
),
),
2014-11-12 07:53:53 +08:00
),
2015-05-15 14:11:51 +08:00
'ReInitNatDet' => array(
'Type' => 'select',
'Choices' => 'Yes,No',
'Value' => 'No',
'Require' => array(
2014-11-12 07:53:53 +08:00
array(
2015-05-15 14:11:51 +08:00
'Name' => 'Enabled',
'Value' => 'Yes',
2014-11-12 07:53:53 +08:00
),
array(
2015-05-15 14:11:51 +08:00
'Name' => 'RequireNatDet',
'Value' => 'Yes',
),
),
2014-11-12 07:53:53 +08:00
),
2015-01-04 21:01:01 +08:00
'AlarmScore'=>array(
2014-11-12 07:53:53 +08:00
'Type'=>'integer',
'Min'=>'1',
'Max'=>'100',
'Value'=>'99',
'Require'=>array(
array(
2015-05-15 14:11:51 +08:00
'Name' => 'Enabled',
'Value' => 'Yes',
),
),
),
2014-11-12 07:53:53 +08:00
);
2013-03-17 07:45:21 +08:00
2015-05-07 05:16:09 +08:00
$pOptions=$generalOptions;
2013-03-17 07:45:21 +08:00
$optionNames=array();
if(file_exists($plugin_path."/config.php"))
{
include_once($plugin_path."/config.php");
2014-11-12 07:53:53 +08:00
if(isset($pluginOptions))
foreach( $pluginOptions as $optionKey => $optionValue )
{
// Set default dependency information if not set in configuration file
if(!isset($optionValue['Require']))
2015-05-14 17:38:38 +08:00
{
2014-11-12 07:53:53 +08:00
$optionValue['Require'] = array (
array(
2015-05-15 14:11:51 +08:00
'Name' => 'Enabled',
'Value' => 'Yes',
),
2014-11-12 07:53:53 +08:00
);
2015-05-14 17:38:38 +08:00
}
elseif(is_array($optionValue['Require']))
{
$optionValue['Require'][] = array (
2015-05-15 14:11:51 +08:00
'Name' => 'Enabled',
'Value' => 'Yes',
2015-05-14 17:38:38 +08:00
);
}
else
{
// Wrong type
continue;
}
2015-05-07 05:16:09 +08:00
$pOptions[$optionKey]=$optionValue;
2014-11-12 07:53:53 +08:00
}
}
2013-03-17 07:45:21 +08:00
2013-12-18 01:53:15 +08:00
$sql='SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?';
foreach( dbFetchAll( $sql, NULL, array( $mid, $zid, $plugin ) ) as $popt )
2013-03-17 07:45:21 +08:00
{
2015-05-07 05:16:09 +08:00
if(array_key_exists($popt['Name'], $pOptions)
&& $popt['Type']==$pOptions[$popt['Name']]['Type'])
2013-03-17 07:45:21 +08:00
{
array_push($optionNames, $popt['Name']);
2014-11-12 07:53:53 +08:00
// Backup dependency information
$require = '';
2015-05-07 05:16:09 +08:00
if(isset($pOptions[$popt['Name']]['Require']))
$require = $pOptions[$popt['Name']]['Require'];
2014-11-12 07:53:53 +08:00
// Set value from database
2015-05-07 05:16:09 +08:00
$pOptions[$popt['Name']]=$popt;
2014-11-12 07:53:53 +08:00
// Restore dependancy information from backup
if(!empty($require))
2015-05-07 05:16:09 +08:00
$pOptions[$popt['Name']]['Require'] = $require;
2014-11-12 07:53:53 +08:00
// Set default dependancy information if not set in configuration
else if($popt['Name'] != 'Enabled')
2015-05-07 05:16:09 +08:00
$pOptions[$popt['Name']]['Require'] = array (
2014-11-12 07:53:53 +08:00
array(
2015-05-15 14:11:51 +08:00
'Name' => 'Enabled',
'Value' => 'Yes',
),
2014-11-12 07:53:53 +08:00
);
2013-03-17 07:45:21 +08:00
} else {
2013-12-18 01:53:15 +08:00
dbQuery('DELETE FROM PluginsConfig WHERE Id=?', array( $popt['Id'] ) );
2013-03-17 07:45:21 +08:00
}
}
2014-11-12 07:53:53 +08:00
2015-05-15 02:49:36 +08:00
// Add option in database if missing
foreach($pOptions as $key => $popt)
2013-03-17 07:45:21 +08:00
{
2015-05-15 02:49:36 +08:00
if(!in_array($key, $optionNames))
2013-03-17 07:45:21 +08:00
{
2014-11-12 07:53:53 +08:00
switch($popt['Type'])
{
case "select":
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,?,'','',?,?,?)";
2015-05-15 02:49:36 +08:00
dbQuery($sql, array( $key, $popt['Value'], $popt['Type'], $popt['Choices'], $mid, $zid, $plugin ) );
2015-05-14 17:38:38 +08:00
break;
2014-11-12 07:53:53 +08:00
case "integer":
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,'',?,?,?,?,?)";
2015-05-15 02:49:36 +08:00
dbQuery($sql, array( $key, $popt['Value'], $popt['Type'], $popt['Min'], $popt['Max'], $mid, $zid, $plugin ) );
2015-05-14 17:38:38 +08:00
break;
case "list":
$sql="INSERT INTO PluginsConfig VALUES ('',?,'',?,'','','',?,?,?)";
2015-05-15 02:49:36 +08:00
dbQuery($sql, array( $key, $popt['Type'], $mid, $zid, $plugin ) );
2015-05-14 17:38:38 +08:00
break;
2014-11-12 07:53:53 +08:00
case "checkbox":
case "text":
default:
$sql="INSERT INTO PluginsConfig VALUES ('',?,?,?,'','','',?,?,?)";
2015-05-15 02:49:36 +08:00
dbQuery($sql, array( $key, $popt['Value'], $popt['Type'], $mid, $zid, $plugin ) );
2014-11-12 07:53:53 +08:00
}
2013-03-17 07:45:21 +08:00
}
}
$PLANG=array();
2014-11-12 07:53:53 +08:00
$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);
}
}
2013-03-17 07:45:21 +08:00
}
function pLang($name)
{
2014-11-12 07:53:53 +08:00
global $SLANG;
2013-03-17 07:45:21 +08:00
global $PLANG;
2014-11-12 07:53:53 +08:00
if(array_key_exists($name, $SLANG))
return $SLANG[$name];
else if(array_key_exists($name, $PLANG))
2013-03-17 07:45:21 +08:00
return $PLANG[$name];
else
return $name;
}
2014-11-12 07:53:53 +08:00
function isEnabled($param)
{
2015-05-07 05:16:09 +08:00
global $pOptions;
$option = $pOptions[$param];
2014-11-12 07:53:53 +08:00
if (!isset($option['Require']))
return true;
foreach($option['Require'] as $req_couple)
{
$name = $req_couple['Name'];
2015-05-07 05:16:09 +08:00
if (!array_key_exists($name, $pOptions))
2014-11-12 07:53:53 +08:00
continue;
2015-05-07 05:16:09 +08:00
if ($req_couple['Value'] != $pOptions[$name]['Value'])
2014-11-12 07:53:53 +08:00
return false;
}
return true;
}
2013-03-17 07:45:21 +08:00
2015-06-07 00:35:43 +08:00
xhtmlHeaders(__FILE__, pLang('Plugin') );
2013-03-17 07:45:21 +08:00
?>
<body>
<div id="page">
<div id="header">
<h2><?php echo pLang('Monitor') ?> <?php echo $monitor['Name'] ?> - <?php echo pLang('Zone') ?> <?php echo $newZone['Name'] ?> - <?php echo pLang('Plugin') ?> <?php echo $plugin ?></h2>
2013-03-17 07:45:21 +08:00
</div>
<div id="content">
<form name="pluginForm" id="pluginForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="hidden" name="view" value="<?php echo $view ?>"/>
2013-03-17 07:45:21 +08:00
<input type="hidden" name="action" value="plugin"/>
<input type="hidden" name="mid" value="<?php echo $mid ?>"/>
<input type="hidden" name="zid" value="<?php echo $zid ?>"/>
<input type="hidden" name="pl" value="<?php echo $plugin ?>"/>
2013-03-17 07:45:21 +08:00
<div id="settingsPanel">
<table id="pluginSettings" cellspacing="0">
<tbody>
2014-12-22 07:28:16 +08:00
<?php
2015-05-15 02:49:36 +08:00
foreach($pOptions as $key => $popt)
2013-03-17 07:45:21 +08:00
{
?>
2015-05-15 02:49:36 +08:00
<tr><th scope="row"><?php echo pLang($key) ?></th>
2014-12-22 07:28:16 +08:00
<?php
2013-03-17 07:45:21 +08:00
switch($popt['Type'])
{
case "checkbox":
2014-11-12 07:53:53 +08:00
?>
2015-03-08 20:13:49 +08:00
<td>
2015-05-15 02:49:36 +08:00
<input type="checkbox" name="dsp_pluginOpt[<?php echo $key; ?>]" id="dsp_pluginOpt[<?php echo $key; ?>]" <?php if ($popt['Value'] == "Yes") echo 'checked="checked"'; if (!isEnabled($key)) echo 'disabled="disabled"'; ?> onchange="applyChanges();">
<input type="hidden" name="pluginOpt[<?php echo $key; ?>]" id="pluginOpt[<?php echo $key; ?>]" value="<?php if ($popt['Value'] == "Yes") echo "Yes"; else echo "No"; ?>">
2015-03-08 20:13:49 +08:00
</td>
2014-12-22 07:28:16 +08:00
<?php
2013-03-17 07:45:21 +08:00
break;
case "select":
$pchoices=explode(',',$popt['Choices']);
?>
<td colspan="2">
2015-05-15 02:49:36 +08:00
<select name="dsp_pluginOpt[<?php echo $key; ?>]" id="dsp_pluginOpt[<?php echo $key; ?>]" <?php if (!isEnabled($key)) echo 'disabled="disabled"'; ?> onchange="applyChanges();">
2014-12-22 07:28:16 +08:00
<?php
2015-03-08 20:13:49 +08:00
foreach($pchoices as $pchoice) {
2013-03-17 07:45:21 +08:00
$psel="";
if($popt['Value']==$pchoice)
2015-03-08 20:13:49 +08:00
$psel="selected=\"selected\"";
?>
<option value="<?php echo $pchoice ?>" <?php echo $psel ?>><?php echo pLang($pchoice); ?></option>
<?php
2013-03-17 07:45:21 +08:00
}
?>
</select>
2015-05-15 02:49:36 +08:00
<input type="hidden" name="pluginOpt[<?php echo $key; ?>]" id="pluginOpt[<?php echo $key; ?>]" value="<?php echo $popt['Value']; ?>" />
2014-11-12 07:53:53 +08:00
</td>
2014-12-22 07:28:16 +08:00
<?php
2013-03-17 07:45:21 +08:00
break;
case "text":
2014-11-12 07:53:53 +08:00
?>
2015-03-08 20:13:49 +08:00
<td>
2015-05-15 02:49:36 +08:00
<input type="text" name="dsp_pluginOpt[<?php echo $key; ?>]" id="dsp_pluginOpt[<?php echo $key; ?>]" value="<?php echo $popt['Value']; ?>" <?php if (!isEnabled($key)) echo 'disabled="disabled"'; ?> onchange="applyChanges();">
<input type="hidden" name="pluginOpt[<?php echo $key; ?>]" id="pluginOpt[<?php echo $key; ?>]" value="<?php echo $popt['Value']; ?>" />
2015-03-08 20:13:49 +08:00
</td>
2014-12-22 07:28:16 +08:00
<?php
2014-11-12 07:53:53 +08:00
break;
case "integer":
?>
2015-03-08 20:13:49 +08:00
<td>
2015-05-15 02:49:36 +08:00
<input type="text" name="dsp_pluginOpt[<?php echo $key; ?>]" id="dsp_pluginOpt[<?php echo $key; ?>]" onchange="limitRange( this, <?php echo $popt['Min'] ?>, <?php echo $popt['Max']; ?> ); applyChanges();" value="<?php echo $popt['Value']; ?>" size="4" <?php if (!isEnabled($key)) echo 'disabled="disabled"'; ?>>
<input type="hidden" name="pluginOpt[<?php echo $key; ?>]" id="pluginOpt[<?php echo $key; ?>]" value="<?php echo $popt['Value']; ?>" />
2015-03-08 20:13:49 +08:00
</td>
2014-12-22 07:28:16 +08:00
<?php
2014-11-12 07:53:53 +08:00
break;
2015-05-14 17:38:38 +08:00
case "list":
$nbopt = 0;
$pvalues=explode(',',$popt['Value']);
?>
<td style="padding:0px;"><table class="listSetting">
<tr>
<td>
2015-05-15 02:49:36 +08:00
<input type="text" name="dsp_input_pluginOpt[<?php echo $key; ?>]" id="dsp_input_pluginOpt[<?php echo $key; ?>]" <?php if (!isEnabled($key)) echo 'disabled="disabled"'; ?> onkeyup="updateAddBtn('<?php echo $key; ?>');" />
2015-05-14 17:38:38 +08:00
</td>
<td>
<input type="button" name="addBtn[<?php echo $key; ?>]" id="addBtn[<?php echo $key; ?>]" value="<?php echo pLang('Add') ?>" onclick="addOption('<?php echo $key; ?>');" disabled="disabled" />
2015-05-14 17:38:38 +08:00
</td>
</tr><tr>
<td>
2015-05-15 02:49:36 +08:00
<select multiple="multiple" name="dsp_pluginOpt[<?php echo $key; ?>]" id="dsp_pluginOpt[<?php echo $key; ?>]" <?php if (!isEnabled($key)) echo 'disabled="disabled"'; ?>>
2015-05-14 17:38:38 +08:00
<?php
foreach($pvalues as $pvalue) {
if(!empty($pvalue)) {
$nbopt++;
?>
<option value="<?php echo $pvalue; ?>"><?php echo $pvalue; ?></option>
<?php
}
}
?>
</select>
2015-05-15 02:49:36 +08:00
<input type="hidden" name="pluginOpt[<?php echo $key; ?>]" id="pluginOpt[<?php echo $key; ?>]" value="<?php echo $popt['Value']; ?>" />
2015-05-14 17:38:38 +08:00
</td>
<td>
<input type="button" name="removeBtn[<?php echo $key; ?>]" id="removeBtn[<?php echo $key; ?>]" value="<?php echo pLang('Remove') ?>" onclick="removeOptionSelected('<?php echo $key; ?>');" <?php if ($nbopt == 0) echo 'disabled="disabled"'; ?> />
2015-05-14 17:38:38 +08:00
</td>
</tr>
</table></td>
<?php
break;
2013-03-17 07:45:21 +08:00
default:
2014-11-12 07:53:53 +08:00
echo "Type '".$popt['Type']."' is not implemented<br>";
2013-03-17 07:45:21 +08:00
}
?>
</tr>
2014-12-22 07:28:16 +08:00
<?php
2013-03-17 07:45:21 +08:00
}
?>
</tbody>
</table>
<input type="submit" id="submitBtn" name="submitBtn" value="<?php echo pLang('Save') ?>" onclick="return saveChanges( this )"<?php if (!canEdit( 'Monitors' ) || (false && $selfIntersecting)) { ?> disabled="disabled"<?php } ?>/><input type="button" value="<?php echo pLang('Cancel') ?>" onclick="closeWindow()"/>
2013-03-17 07:45:21 +08:00
</div>
</form>
</div>
</div>
</body>
</html>