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

321 lines
10 KiB
PHP
Raw 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;
2014-11-12 07:53:53 +08:00
$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'
)
)
),
2015-01-04 21:01:01 +08:00
'AlarmScore'=>array(
2014-11-12 07:53:53 +08:00
'Type'=>'integer',
2015-01-04 21:01:01 +08:00
'Name'=>'AlarmScore',
2014-11-12 07:53:53 +08:00
'Min'=>'1',
'Max'=>'100',
'Value'=>'99',
'Require'=>array(
array(
'Name'=>'Enabled',
'Value'=>'Yes'
)
)
)
);
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']))
$optionValue['Require'] = array (
array(
'Name'=>'Enabled',
'Value'=>'Yes'
)
);
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(
'Name'=>'Enabled',
'Value'=>'Yes'
)
);
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-07 05:16:09 +08:00
foreach($pOptions as $name => $values)
2013-03-17 07:45:21 +08:00
{
if(!in_array($name, $optionNames))
{
2015-05-07 05:16:09 +08:00
$popt=$pOptions[$name];
2014-11-12 07:53:53 +08:00
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 ) );
}
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
2014-11-12 07:53:53 +08:00
xhtmlHeaders(__FILE__, $SLANG['Plugin'] );
2013-03-17 07:45:21 +08:00
?>
<body>
<div id="page">
<div id="header">
<h2><?php echo $SLANG['Monitor'] ?> <?php echo $monitor['Name'] ?> - <?php echo $SLANG['Zone'] ?> <?php echo $newZone['Name'] ?> - <?php echo $SLANG['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-07 05:16:09 +08:00
foreach($pOptions as $name => $popt)
2013-03-17 07:45:21 +08:00
{
?>
2015-03-08 20:13:49 +08:00
<tr><th scope="row"><?php echo pLang($name) ?></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>
<input type="checkbox" name="dsp_pluginOpt[<?php echo $popt['Name']; ?>]" id="dsp_pluginOpt[<?php echo $popt['Name']; ?>]" <?php if ($popt['Value'] == "Yes") echo 'checked="checked"'; if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?> onchange="applyChanges();">
<input type="hidden" name="pluginOpt[<?php echo $popt['Name'] ?>]" id="pluginOpt[<?php echo $popt['Name']; ?>]" value="<?php if ($popt['Value'] == "Yes") echo "Yes"; else echo "No"; ?>">
</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-03-08 20:13:49 +08:00
<select name="dsp_pluginOpt[<?php echo $popt['Name'] ?>]" id="dsp_pluginOpt[<?php echo $popt['Name']; ?>]" <?php if (!isEnabled($popt['Name'])) 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-03-08 20:13:49 +08:00
<input type="hidden" name="pluginOpt[<?php echo $popt['Name'] ?>]" id="pluginOpt[<?php echo $popt['Name']; ?>]" 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>
<input type="text" name="dsp_pluginOpt[<?php echo $popt['Name'] ?>]" id="dsp_pluginOpt[<?php echo $popt['Name']; ?>]" value="<?php echo $popt['Value']; ?>" <?php if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?> onchange="applyChanges();">
<input type="hidden" name="pluginOpt[<?php echo $popt['Name'] ?>]" id="pluginOpt[<?php echo $popt['Name']; ?>]" value="<?php echo $popt['Value']; ?>" />
</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>
<input type="text" name="dsp_pluginOpt[<?php echo $popt['Name'] ?>]" id="dsp_pluginOpt[<?php echo $popt['Name']; ?>]" onchange="limitRange( this, <?php echo $popt['Min'] ?>, <?php echo $popt['Max']; ?> ); applyChanges();" value="<?php echo $popt['Value']; ?>" size="4" <?php if (!isEnabled($popt['Name'])) echo 'disabled="disabled"'; ?>>
<input type="hidden" name="pluginOpt[<?php echo $popt['Name'] ?>]" id="pluginOpt[<?php echo $popt['Name']; ?>]" value="<?php echo $popt['Value']; ?>" />
</td>
2014-12-22 07:28:16 +08:00
<?php
2014-11-12 07:53:53 +08:00
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 $SLANG['Save'] ?>" onclick="return saveChanges( this )"<?php if (!canEdit( 'Monitors' ) || (false && $selfIntersecting)) { ?> disabled="disabled"<?php } ?>/><input type="button" value="<?php echo $SLANG['Cancel'] ?>" onclick="closeWindow()"/>
2013-03-17 07:45:21 +08:00
</div>
</form>
</div>
</div>
</body>
</html>