2002-10-03 19:39:36 +08:00
|
|
|
<?php
|
2002-10-11 17:44:13 +08:00
|
|
|
//
|
2002-12-10 21:23:22 +08:00
|
|
|
// ZoneMinder web action file, $Date$, $Revision$
|
2005-02-24 22:40:14 +08:00
|
|
|
// Copyright (C) 2003, 2004, 2005 Philip Coombes
|
2002-10-11 17:44:13 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( isset($action) )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2002-11-28 00:21:49 +08:00
|
|
|
//phpinfo( INFO_VARIABLES );
|
2003-06-26 19:12:00 +08:00
|
|
|
if ( $action == "login" && $username && $password )
|
|
|
|
{
|
|
|
|
userLogin( $username, $password );
|
|
|
|
}
|
2003-06-30 04:53:55 +08:00
|
|
|
elseif ( $action == "logout" )
|
|
|
|
{
|
|
|
|
userLogout();
|
|
|
|
$refresh_parent = true;
|
|
|
|
$view = 'none';
|
|
|
|
}
|
|
|
|
elseif ( $action == "bandwidth" && $new_bandwidth )
|
|
|
|
{
|
|
|
|
$bandwidth = $new_bandwidth;
|
|
|
|
setcookie( "bandwidth", $new_bandwidth, time()+3600*24*30*12*10 );
|
|
|
|
$refresh_parent = true;
|
|
|
|
$view = 'none';
|
|
|
|
}
|
|
|
|
if ( canEdit( 'Events' ) )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( $action == "rename" && $event_name && $eid )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "update Events set Name = '$event_name' where Id = '$eid'" );
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
elseif ( $action == "archive" && $eid )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "update Events set Archived = 1 where Id = '$eid'" );
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
elseif ( $action == "unarchive" && $eid )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "update Events set Archived = 0 where Id = '$eid'" );
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
elseif ( $action == "filter" )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( $filter_name || $new_filter_name )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( $new_filter_name )
|
|
|
|
$filter_name = $new_filter_name;
|
|
|
|
$filter_query = array();
|
2004-01-08 18:09:35 +08:00
|
|
|
$filter_query['trms'] = $trms;
|
2003-06-27 20:10:10 +08:00
|
|
|
for ( $i = 1; $i <= $trms; $i++ )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$conjunction_name = "cnj$i";
|
|
|
|
$obracket_name = "obr$i";
|
|
|
|
$cbracket_name = "cbr$i";
|
|
|
|
$attr_name = "attr$i";
|
|
|
|
$op_name = "op$i";
|
|
|
|
$value_name = "val$i";
|
|
|
|
if ( $i > 1 )
|
|
|
|
{
|
|
|
|
$filter_query[$conjunction_name] = $$conjunction_name;
|
|
|
|
}
|
|
|
|
$filter_query[$obracket_name] = $$obracket_name;
|
|
|
|
$filter_query[$cbracket_name] = $$cbracket_name;
|
|
|
|
$filter_query[$attr_name] = $$attr_name;
|
|
|
|
$filter_query[$op_name] = $$op_name;
|
|
|
|
$filter_query[$value_name] = $$value_name;
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
$filter_parms = array();
|
|
|
|
while( list( $key, $value ) = each( $filter_query ) )
|
|
|
|
{
|
|
|
|
$filter_parms[] = "$key=$value";
|
|
|
|
}
|
2004-04-21 17:20:28 +08:00
|
|
|
$filter_parms[] = "sort_field=$sort_field";
|
|
|
|
$filter_parms[] = "sort_asc=$sort_asc";
|
|
|
|
$filter_parms[] = "limit=$limit";
|
2003-06-27 20:10:10 +08:00
|
|
|
$filter_query_string = join( '&', $filter_parms );
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "replace into Filters set Name = '$filter_name', Query = '$filter_query_string', AutoArchive = '$auto_archive', AutoDelete = '$auto_delete', AutoUpload = '$auto_upload', AutoEmail = '$auto_email', AutoMessage = '$auto_message', AutoExecute = '$auto_execute'" );
|
2003-06-27 20:10:10 +08:00
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ( $action == "delete" )
|
|
|
|
{
|
|
|
|
if ( !$mark_eids && $mark_eid )
|
|
|
|
{
|
|
|
|
$mark_eids[] = $mark_eid;
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
if ( $mark_eids )
|
|
|
|
{
|
2002-11-07 20:23:54 +08:00
|
|
|
foreach( $mark_eids as $mark_eid )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2002-11-22 20:12:16 +08:00
|
|
|
deleteEvent( $mark_eid );
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
2002-11-07 20:23:54 +08:00
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( $fid )
|
2002-11-07 20:23:54 +08:00
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "delete from Filters where Name = '$fid'" );
|
2003-06-27 20:10:10 +08:00
|
|
|
//$refresh_parent = true;
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-01-15 05:17:54 +08:00
|
|
|
if ( canEdit( 'Monitors', $mid ) )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2004-01-15 05:17:54 +08:00
|
|
|
if ( $action == "function" && isset( $mid ) )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$sql = "select * from Monitors where Id = '$mid'";
|
2002-10-03 19:39:36 +08:00
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
2003-06-27 20:10:10 +08:00
|
|
|
die( mysql_error() );
|
|
|
|
$monitor = mysql_fetch_assoc( $result );
|
2002-10-03 19:39:36 +08:00
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
$old_function = $monitor['Function'];
|
|
|
|
if ( $new_function != $old_function )
|
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "update Monitors set Function = '$new_function' where Id = '$mid'" );
|
2002-10-03 19:39:36 +08:00
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
$monitor['Function'] = $new_function;
|
2004-12-29 02:20:11 +08:00
|
|
|
if ( $cookies ) session_write_close();
|
2003-06-27 20:10:10 +08:00
|
|
|
zmcControl( $monitor, true );
|
2003-11-08 19:51:17 +08:00
|
|
|
zmaControl( $monitor, true );
|
2003-06-27 20:10:10 +08:00
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ( $action == "zone" && isset( $mid ) && isset( $zid ) )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
|
2002-10-03 19:39:36 +08:00
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-06-27 20:10:10 +08:00
|
|
|
$monitor = mysql_fetch_assoc( $result );
|
2002-10-03 19:39:36 +08:00
|
|
|
|
|
|
|
if ( $zid > 0 )
|
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "select * from Zones where MonitorId = '$mid' and Id = '$zid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$zone = mysql_fetch_assoc( $result );
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$zone = array();
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
|
|
|
|
2004-04-19 18:05:27 +08:00
|
|
|
$types = array();
|
|
|
|
$changes = getFormChanges( $zone, $new_zone, $types );
|
2002-10-03 19:39:36 +08:00
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( count( $changes ) )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( $zid > 0 )
|
|
|
|
{
|
|
|
|
$sql = "update Zones set ".implode( ", ", $changes )." where MonitorId = '$mid' and Id = '$zid'";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sql = "insert into Zones set MonitorId = '$mid', ".implode( ", ", $changes );
|
|
|
|
$view = 'none';
|
|
|
|
}
|
2004-04-19 18:05:27 +08:00
|
|
|
//echo "<html>$sql</html>";
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( $sql );
|
2004-12-29 02:20:11 +08:00
|
|
|
if ( $cookies ) session_write_close();
|
2003-06-27 20:10:10 +08:00
|
|
|
zmaControl( $mid, true );
|
|
|
|
$refresh_parent = true;
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
|
|
|
elseif ( $action == "monitor" && isset( $mid ) )
|
|
|
|
{
|
|
|
|
if ( $mid > 0 )
|
2002-10-03 19:39:36 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
|
2002-10-03 19:39:36 +08:00
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-06-27 20:10:10 +08:00
|
|
|
$monitor = mysql_fetch_assoc( $result );
|
2003-10-28 01:06:21 +08:00
|
|
|
|
|
|
|
if ( ZM_OPT_X10 )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "select * from TriggersX10 where MonitorId = '$mid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$x10_monitor = mysql_fetch_assoc( $result );
|
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$monitor = array();
|
2003-10-28 01:06:21 +08:00
|
|
|
if ( ZM_OPT_X10 )
|
2003-09-23 17:52:45 +08:00
|
|
|
{
|
2003-10-28 01:06:21 +08:00
|
|
|
$x10_monitor = array();
|
2003-09-23 17:52:45 +08:00
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
2003-10-28 01:06:21 +08:00
|
|
|
|
|
|
|
// Define a field type for anything that's not simple text equivalent
|
|
|
|
$types = array(
|
2005-03-14 04:41:31 +08:00
|
|
|
'Triggers' => 'set',
|
|
|
|
'Controllable' => 'toggle',
|
2003-10-28 01:06:21 +08:00
|
|
|
);
|
|
|
|
|
2005-03-14 04:41:31 +08:00
|
|
|
$columns = getTableColumns( 'Monitors' );
|
|
|
|
$changes = getFormChanges( $monitor, $new_monitor, $types, $columns );
|
2003-10-28 01:06:21 +08:00
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( count( $changes ) )
|
|
|
|
{
|
|
|
|
if ( $mid > 0 )
|
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "update Monitors set ".implode( ", ", $changes )." where Id = '$mid'" );
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $changes['Name'] )
|
2003-06-27 20:10:10 +08:00
|
|
|
{
|
2004-01-08 18:09:35 +08:00
|
|
|
exec( escapeshellcmd( "mv ".EVENTS_PATH."/".$monitor['Name']." ".EVENTS_PATH."/".$new_monitor['Name'] ) );
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
|
|
|
}
|
2004-01-08 18:09:35 +08:00
|
|
|
elseif ( !$user['MonitorIds'] )
|
2003-06-27 20:10:10 +08:00
|
|
|
{
|
|
|
|
$sql = "insert into Monitors set ".implode( ", ", $changes );
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$mid = mysql_insert_id();
|
2004-02-16 04:02:41 +08:00
|
|
|
$sql = "insert into Zones set MonitorId = $mid, Name = 'All', Type = 'Active', Units = 'Percent', LoX = 0, LoY = 0, HiX = 100, HiY = 100, AlarmRGB = 0xff0000, CheckMethod = 'Blobs', MinPixelThreshold = 25, MaxPixelThreshold = 0, MinAlarmPixels = 3, MaxAlarmPixels = 75, FilterX = 3, FilterY = 3, MinFilterPixels = 3, MaxFilterPixels = 75, MinBlobPixels = 2, MaxBlobPixels = 0, MinBlobs = 1, MaxBlobs = 0";
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-09-23 17:52:45 +08:00
|
|
|
//$view = 'none';
|
2005-01-31 20:08:49 +08:00
|
|
|
mkdir( ZM_DIR_EVENTS."/".$mid, 0755 );
|
2004-09-07 16:45:00 +08:00
|
|
|
chdir( ZM_DIR_EVENTS );
|
|
|
|
symlink( $mid, $new_monitor['Name'] );
|
|
|
|
chdir( ".." );
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
2003-10-28 01:06:21 +08:00
|
|
|
$restart = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ZM_OPT_X10 )
|
|
|
|
{
|
|
|
|
$x10_changes = getFormChanges( $x10_monitor, $new_x10_monitor );
|
|
|
|
|
|
|
|
if ( count( $x10_changes ) )
|
|
|
|
{
|
2003-12-11 23:33:22 +08:00
|
|
|
if ( $x10_monitor && $new_x10_monitor )
|
2003-10-28 01:06:21 +08:00
|
|
|
{
|
2003-12-11 23:18:27 +08:00
|
|
|
$sql = "update TriggersX10 set ".implode( ", ", $x10_changes )." where MonitorId = '$mid'";
|
2003-10-28 01:06:21 +08:00
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
2004-01-08 18:09:35 +08:00
|
|
|
elseif ( !$user['MonitorIds'] )
|
2003-10-28 01:06:21 +08:00
|
|
|
{
|
2003-12-11 23:33:22 +08:00
|
|
|
if ( !$x10_monitor )
|
|
|
|
{
|
|
|
|
$sql = "insert into TriggersX10 set MonitorId = '$mid', ".implode( ", ", $x10_changes );
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sql = "delete from TriggersX10 where MonitorId = '$mid'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
2003-10-28 01:06:21 +08:00
|
|
|
}
|
|
|
|
$restart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $restart )
|
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
|
2002-10-03 19:39:36 +08:00
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-06-27 20:10:10 +08:00
|
|
|
$monitor = mysql_fetch_assoc( $result );
|
|
|
|
fixDevices();
|
2004-12-29 02:20:11 +08:00
|
|
|
if ( $cookies ) session_write_close();
|
2003-06-27 20:10:10 +08:00
|
|
|
zmcControl( $monitor, true );
|
|
|
|
zmaControl( $monitor, true );
|
2003-11-08 19:51:17 +08:00
|
|
|
//daemonControl( 'restart', 'zmwatch.pl' );
|
2003-06-27 20:10:10 +08:00
|
|
|
$refresh_parent = true;
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
|
|
|
}
|
2004-01-15 05:17:54 +08:00
|
|
|
elseif ( $action == "settings" && isset( $mid ) )
|
2002-11-28 00:21:49 +08:00
|
|
|
{
|
2005-02-02 07:04:37 +08:00
|
|
|
$zmu_command = getZmuCommand( " -m $mid -B$new_brightness -C$new_contrast -H$new_hue -O$new_colour" );
|
2003-06-27 20:10:10 +08:00
|
|
|
$zmu_output = exec( escapeshellcmd( $zmu_command ) );
|
|
|
|
list( $brightness, $contrast, $hue, $colour ) = split( ' ', $zmu_output );
|
2005-01-31 20:08:49 +08:00
|
|
|
$sql = "update Monitors set Brightness = '$brightness', Contrast = '$contrast', Hue = '$hue', Colour = '$colour' where Id = '$mid'";
|
2004-09-26 00:37:41 +08:00
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
2005-02-24 18:43:29 +08:00
|
|
|
elseif ( $action == "control" && isset( $mid ) )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "select * from Monitors as M inner join Controls as C on (M.ControlId = C.Id ) where M.Id = '$mid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$monitor = mysql_fetch_assoc( $result );
|
|
|
|
|
|
|
|
$ctrl_command = $monitor['Command'];
|
|
|
|
if ( $monitor['ControlDevice'] )
|
|
|
|
$ctrl_command .= " --device=".$monitor['ControlDevice'];
|
|
|
|
if ( $monitor['ControlAddress'] )
|
|
|
|
$ctrl_command .= " --address=".$monitor['ControlAddress'];
|
|
|
|
|
|
|
|
//$ctrl_command .= " --command=".$control;
|
|
|
|
|
|
|
|
if ( isset($x) && isset($y) )
|
|
|
|
{
|
|
|
|
if ( $control == "move_map" )
|
|
|
|
{
|
|
|
|
$x = deScale( $x, $scale );
|
|
|
|
$y = deScale( $y, $scale );
|
|
|
|
switch ( $monitor['Orientation'] )
|
|
|
|
{
|
|
|
|
case '0' :
|
|
|
|
case '180' :
|
2005-05-06 00:46:26 +08:00
|
|
|
case 'hori' :
|
|
|
|
case 'vert' :
|
2005-02-24 18:43:29 +08:00
|
|
|
$width = $monitor['Width'];
|
|
|
|
$height = $monitor['Height'];
|
|
|
|
break;
|
|
|
|
case '90' :
|
|
|
|
case '270' :
|
|
|
|
$width = $monitor['Height'];
|
|
|
|
$height = $monitor['Width'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch ( $monitor['Orientation'] )
|
|
|
|
{
|
|
|
|
case '90' :
|
|
|
|
$temp_y = $y;
|
|
|
|
$y = $height - $x;
|
|
|
|
$x = $temp_y;
|
|
|
|
break;
|
|
|
|
case '180' :
|
|
|
|
$x = $width - $x;
|
|
|
|
$y = $height - $y;
|
|
|
|
break;
|
|
|
|
case '270' :
|
|
|
|
$temp_x = $x;
|
|
|
|
$x = $width - $y;
|
|
|
|
$y = $temp_x;
|
|
|
|
break;
|
2005-05-06 00:46:26 +08:00
|
|
|
case 'hori' :
|
|
|
|
$x = $width - $x;
|
|
|
|
break;
|
|
|
|
case 'vert' :
|
|
|
|
$y = $height - $y;
|
|
|
|
break;
|
2005-02-24 18:43:29 +08:00
|
|
|
}
|
|
|
|
$ctrl_command .= " -xcoord $x -ycoord $y -width $width -height $height";
|
|
|
|
}
|
|
|
|
elseif ( $control == "move_pseudo_map" )
|
|
|
|
{
|
|
|
|
$x = deScale( $x, $scale );
|
|
|
|
$y = deScale( $y, $scale );
|
|
|
|
|
|
|
|
$half_width = $monitor['Width'] / 2;
|
|
|
|
$half_height = $monitor['Height'] / 2;
|
|
|
|
$x_factor = ($x - $half_width)/$half_width;
|
|
|
|
$y_factor = ($y - $half_height)/$half_height;
|
|
|
|
|
|
|
|
switch ( $monitor['Orientation'] )
|
|
|
|
{
|
|
|
|
case '90' :
|
|
|
|
$temp_y_factor = $y;
|
|
|
|
$y_factor = -$x_factor;
|
|
|
|
$x_factor = $temp_y_factor;
|
|
|
|
break;
|
|
|
|
case '180' :
|
|
|
|
$x_factor = -$x_factor;
|
|
|
|
$y_factor = -$y_factor;
|
|
|
|
break;
|
|
|
|
case '270' :
|
|
|
|
$temp_x_factor = $x;
|
|
|
|
$x_factor = -$y_factor;
|
|
|
|
$y_factor = $tenp_x_factor;
|
|
|
|
break;
|
2005-05-06 00:46:26 +08:00
|
|
|
case 'hori' :
|
|
|
|
$x_factor = -$x_factor;
|
|
|
|
break;
|
|
|
|
case 'vert' :
|
|
|
|
$y_factor = -$y_factor;
|
|
|
|
break;
|
2005-02-24 18:43:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$turbo = 0.9; // Threshold for turbo speed
|
|
|
|
$blind = 0.1; // Threshold for blind spot
|
|
|
|
|
|
|
|
$pan_control = '';
|
|
|
|
$tilt_control = '';
|
|
|
|
if ( $x_factor > $blind )
|
|
|
|
{
|
|
|
|
$pan_control = 'right';
|
|
|
|
}
|
|
|
|
elseif ( $x_factor < -$blind )
|
|
|
|
{
|
|
|
|
$pan_control = 'left';
|
|
|
|
}
|
|
|
|
if ( $y_factor > $blind )
|
|
|
|
{
|
|
|
|
$tilt_control = 'down';
|
|
|
|
}
|
|
|
|
elseif ( $y_factor < -$blind )
|
|
|
|
{
|
|
|
|
$tilt_control = 'up';
|
|
|
|
}
|
|
|
|
|
|
|
|
$dirn = $tilt_control.$pan_control;
|
|
|
|
if ( !$dirn )
|
|
|
|
{
|
|
|
|
// No command, probably in blind spot in middle
|
|
|
|
$control = 'null';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$control = 'move_rel_'.$dirn;
|
|
|
|
$x_factor = abs($x_factor);
|
|
|
|
$y_factor = abs($y_factor);
|
|
|
|
|
|
|
|
if ( $monitor['HasPanSpeed'] && $x_factor )
|
|
|
|
{
|
|
|
|
if ( $monitor['HasTurboPan'] )
|
|
|
|
{
|
|
|
|
if ( $x_factor >= $turbo )
|
|
|
|
{
|
|
|
|
$pan_speed = $monitor['TurboPanSpeed'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$x_factor = $x_factor/$turbo;
|
|
|
|
$pan_speed = intval(round($monitor['MinPanSpeed']+(($monitor['MaxPanSpeed']-$monitor['MinPanSpeed'])*$x_factor)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$pan_speed = intval(round($monitor['MinPanSpeed']+(($monitor['MaxPanSpeed']-$monitor['MinPanSpeed'])*$x_factor)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $monitor['HasTiltSpeed'] && $y_factor )
|
|
|
|
{
|
|
|
|
if ( $monitor['HasTurboTilt'] )
|
|
|
|
{
|
|
|
|
if ( $y_factor >= $turbo )
|
|
|
|
{
|
|
|
|
$tilt_speed = $monitor['TurboTiltSpeed'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$y_factor = $y_factor/$turbo;
|
|
|
|
$tilt_speed = intval(round($monitor['MinTiltSpeed']+(($monitor['MaxTiltSpeed']-$monitor['MinTiltSpeed'])*$y_factor)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tilt_speed = intval(round($monitor['MinTiltSpeed']+(($monitor['MaxTiltSpeed']-$monitor['MinTiltSpeed'])*$y_factor)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( preg_match( '/(left|right)$/', $dirn ) )
|
|
|
|
{
|
|
|
|
$pan_step = intval(round($monitor['MinPanStep']+(($monitor['MaxPanStep']-$monitor['MinPanStep'])*$x_factor)));
|
|
|
|
$ctrl_command .= " --panstep=".$pan_step." --panspeed=".$pan_speed;
|
|
|
|
}
|
|
|
|
if ( preg_match( '/^(up|down)/', $dirn ) )
|
|
|
|
{
|
|
|
|
$tilt_step = intval(round($monitor['MinTiltStep']+(($monitor['MaxTiltStep']-$monitor['MinTiltStep'])*$y_factor)));
|
|
|
|
$ctrl_command .= " --tiltstep=".$tilt_step." --tiltspeed=".$tilt_speed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$turbo = 0.9; // Threshold for turbo speed
|
|
|
|
$long_y = 48;
|
|
|
|
$short_x = 32;
|
|
|
|
$short_y = 32;
|
|
|
|
|
|
|
|
if ( preg_match( '/^([^_]+)_([^_]+)_([^_]+)$/', $control, $matches ) )
|
|
|
|
{
|
|
|
|
$command = $matches[1];
|
|
|
|
$mode = $matches[2];
|
|
|
|
$dirn = $matches[3];
|
|
|
|
|
|
|
|
switch( $command )
|
|
|
|
{
|
|
|
|
case 'focus' :
|
|
|
|
{
|
|
|
|
switch( $dirn )
|
|
|
|
{
|
|
|
|
case 'near' :
|
|
|
|
{
|
|
|
|
$factor = ($long_y-($y+1))/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'far' :
|
|
|
|
{
|
|
|
|
$factor = ($y+1)/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $monitor['HasFocusSpeed'] )
|
|
|
|
{
|
|
|
|
$speed = intval(round($monitor['MinFocusSpeed']+(($monitor['MaxFocusSpeed']-$monitor['MinFocusSpeed'])*$factor)));
|
|
|
|
$ctrl_command .= " --speed=".$speed;
|
|
|
|
}
|
|
|
|
switch( $mode )
|
|
|
|
{
|
|
|
|
case 'abs' :
|
|
|
|
case 'rel' :
|
|
|
|
{
|
|
|
|
$step = intval(round($monitor['MinFocusStep']+(($monitor['MaxFocusStep']-$monitor['MinFocusStep'])*$x_factor)));
|
|
|
|
$ctrl_command .= " --step=".$step;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'zoom' :
|
|
|
|
{
|
|
|
|
switch( $dirn )
|
|
|
|
{
|
|
|
|
case 'tele' :
|
|
|
|
{
|
|
|
|
$factor = ($long_y-($y+1))/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'wide' :
|
|
|
|
{
|
|
|
|
$factor = ($y+1)/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $monitor['HasZoomSpeed'] )
|
|
|
|
{
|
|
|
|
$speed = intval(round($monitor['MinZoomSpeed']+(($monitor['MaxZoomSpeed']-$monitor['MinZoomSpeed'])*$factor)));
|
|
|
|
$ctrl_command .= " --speed=".$speed;
|
|
|
|
}
|
|
|
|
switch( $mode )
|
|
|
|
{
|
|
|
|
case 'abs' :
|
|
|
|
case 'rel' :
|
|
|
|
{
|
|
|
|
$step = intval(round($monitor['MinZoomStep']+(($monitor['MaxZoomStep']-$monitor['MinZoomStep'])*$x_factor)));
|
|
|
|
$ctrl_command .= " --step=".$step;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'iris' :
|
|
|
|
{
|
|
|
|
switch( $dirn )
|
|
|
|
{
|
|
|
|
case 'open' :
|
|
|
|
{
|
|
|
|
$factor = ($long_y-($y+1))/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'close' :
|
|
|
|
{
|
|
|
|
$factor = ($y+1)/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $monitor['HasIrisSpeed'] )
|
|
|
|
{
|
|
|
|
$speed = intval(round($monitor['MinIrisSpeed']+(($monitor['MaxIrisSpeed']-$monitor['MinIrisSpeed'])*$factor)));
|
|
|
|
$ctrl_command .= " --speed=".$speed;
|
|
|
|
}
|
|
|
|
switch( $mode )
|
|
|
|
{
|
|
|
|
case 'abs' :
|
|
|
|
case 'rel' :
|
|
|
|
{
|
|
|
|
$step = intval(round($monitor['MinIrisStep']+(($monitor['MaxIrisStep']-$monitor['MinIrisStep'])*$x_factor)));
|
|
|
|
$ctrl_command .= " --step=".$step;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'white' :
|
|
|
|
{
|
|
|
|
switch( $dirn )
|
|
|
|
{
|
|
|
|
case 'in' :
|
|
|
|
{
|
|
|
|
$factor = ($long_y-($y+1))/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'out' :
|
|
|
|
{
|
|
|
|
$factor = ($y+1)/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $monitor['HasWhiteSpeed'] )
|
|
|
|
{
|
|
|
|
$speed = intval(round($monitor['MinWhiteSpeed']+(($monitor['MaxWhiteSpeed']-$monitor['MinWhiteSpeed'])*$factor)));
|
|
|
|
$ctrl_command .= " --speed=".$speed;
|
|
|
|
}
|
|
|
|
switch( $mode )
|
|
|
|
{
|
|
|
|
case 'abs' :
|
|
|
|
case 'rel' :
|
|
|
|
{
|
|
|
|
$step = intval(round($monitor['MinWhiteStep']+(($monitor['MaxWhiteStep']-$monitor['MinWhiteStep'])*$x_factor)));
|
|
|
|
$ctrl_command .= " --step=".$step;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'gain' :
|
|
|
|
{
|
|
|
|
switch( $dirn )
|
|
|
|
{
|
|
|
|
case 'up' :
|
|
|
|
{
|
|
|
|
$factor = ($long_y-($y+1))/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'down' :
|
|
|
|
{
|
|
|
|
$factor = ($y+1)/$long_y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $monitor['HasGainSpeed'] )
|
|
|
|
{
|
|
|
|
$speed = intval(round($monitor['MinGainSpeed']+(($monitor['MaxGainSpeed']-$monitor['MinGainSpeed'])*$factor)));
|
|
|
|
$ctrl_command .= " --speed=".$speed;
|
|
|
|
}
|
|
|
|
switch( $mode )
|
|
|
|
{
|
|
|
|
case 'abs' :
|
|
|
|
case 'rel' :
|
|
|
|
{
|
|
|
|
$step = intval(round($monitor['MinGainStep']+(($monitor['MaxGainStep']-$monitor['MinGainStep'])*$x_factor)));
|
|
|
|
$ctrl_command .= " --step=".$step;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'move' :
|
|
|
|
{
|
|
|
|
$x_factor = 0;
|
|
|
|
$y_factor = 0;
|
|
|
|
|
|
|
|
if ( preg_match( '/^up/', $dirn ) )
|
|
|
|
{
|
|
|
|
$y_factor = ($short_y-($y+1))/$short_y;
|
|
|
|
}
|
|
|
|
elseif ( preg_match( '/^down/', $dirn ) )
|
|
|
|
{
|
|
|
|
$y_factor = ($y+1)/$short_y;
|
|
|
|
}
|
|
|
|
if ( preg_match( '/left$/', $dirn ) )
|
|
|
|
{
|
|
|
|
$x_factor = ($short_x-($x+1))/$short_x;
|
|
|
|
}
|
|
|
|
elseif ( preg_match( '/right$/', $dirn ) )
|
|
|
|
{
|
|
|
|
$x_factor = ($x+1)/$short_x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $monitor['Orientation'] != '0' )
|
|
|
|
{
|
|
|
|
$conversions = array(
|
|
|
|
'90' => array(
|
|
|
|
'up' => 'left',
|
|
|
|
'down' => 'right',
|
|
|
|
'left' => 'down',
|
|
|
|
'right' => 'up',
|
|
|
|
'upleft' => 'downleft',
|
|
|
|
'upright' => 'upleft',
|
|
|
|
'downleft' => 'downright',
|
|
|
|
'downright' => 'upright',
|
|
|
|
),
|
|
|
|
'180' => array(
|
|
|
|
'up' => 'down',
|
|
|
|
'down' => 'up',
|
|
|
|
'left' => 'right',
|
|
|
|
'right' => 'left',
|
|
|
|
'upleft' => 'downright',
|
|
|
|
'upright' => 'downleft',
|
|
|
|
'downleft' => 'upright',
|
|
|
|
'downright' => 'upleft',
|
|
|
|
),
|
|
|
|
'270' => array(
|
|
|
|
'up' => 'right',
|
|
|
|
'down' => 'left',
|
|
|
|
'left' => 'up',
|
|
|
|
'right' => 'down',
|
|
|
|
'upleft' => 'upright',
|
|
|
|
'upright' => 'downright',
|
|
|
|
'downleft' => 'upleft',
|
|
|
|
'downright' => 'downleft',
|
|
|
|
),
|
2005-05-06 00:46:26 +08:00
|
|
|
'hori' => array(
|
|
|
|
'up' => 'up',
|
|
|
|
'down' => 'down',
|
|
|
|
'left' => 'right',
|
|
|
|
'right' => 'left',
|
|
|
|
'upleft' => 'upright',
|
|
|
|
'upright' => 'upleft',
|
|
|
|
'downleft' => 'downright',
|
|
|
|
'downright' => 'downleft',
|
|
|
|
),
|
|
|
|
'vert' => array(
|
|
|
|
'up' => 'down',
|
|
|
|
'down' => 'up',
|
|
|
|
'left' => 'left',
|
|
|
|
'right' => 'right',
|
|
|
|
'upleft' => 'downleft',
|
|
|
|
'upright' => 'downright',
|
|
|
|
'downleft' => 'upleft',
|
|
|
|
'downright' => 'upright',
|
|
|
|
),
|
2005-02-24 18:43:29 +08:00
|
|
|
);
|
|
|
|
$new_dirn = $conversions[$monitor['Orientation']][$dirn];
|
|
|
|
$control = preg_replace( "/_$dirn\$/", "_$new_dirn", $control );
|
|
|
|
$dirn = $new_dirn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $monitor['HasPanSpeed'] && $x_factor )
|
|
|
|
{
|
|
|
|
if ( $monitor['HasTurboPan'] )
|
|
|
|
{
|
|
|
|
if ( $x_factor >= $turbo )
|
|
|
|
{
|
|
|
|
$pan_speed = $monitor['TurboPanSpeed'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$x_factor = $x_factor/$turbo;
|
|
|
|
$pan_speed = intval(round($monitor['MinPanSpeed']+(($monitor['MaxPanSpeed']-$monitor['MinPanSpeed'])*$x_factor)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$pan_speed = intval(round($monitor['MinPanSpeed']+(($monitor['MaxPanSpeed']-$monitor['MinPanSpeed'])*$x_factor)));
|
|
|
|
}
|
|
|
|
$ctrl_command .= " --panspeed=".$pan_speed;
|
|
|
|
}
|
|
|
|
if ( $monitor['HasTiltSpeed'] && $y_factor )
|
|
|
|
{
|
|
|
|
if ( $monitor['HasTurboTilt'] )
|
|
|
|
{
|
|
|
|
if ( $y_factor >= $turbo )
|
|
|
|
{
|
|
|
|
$tilt_speed = $monitor['TurboTiltSpeed'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$y_factor = $y_factor/$turbo;
|
|
|
|
$tilt_speed = intval(round($monitor['MinTiltSpeed']+(($monitor['MaxTiltSpeed']-$monitor['MinTiltSpeed'])*$y_factor)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tilt_speed = intval(round($monitor['MinTiltSpeed']+(($monitor['MaxTiltSpeed']-$monitor['MinTiltSpeed'])*$y_factor)));
|
|
|
|
}
|
|
|
|
$ctrl_command .= " --tiltspeed=".$tilt_speed;
|
|
|
|
}
|
|
|
|
switch( $mode )
|
|
|
|
{
|
|
|
|
case 'rel' :
|
|
|
|
case 'abs' :
|
|
|
|
{
|
|
|
|
if ( preg_match( '/(left|right)$/', $dirn ) )
|
|
|
|
{
|
|
|
|
$pan_step = intval(round($monitor['MinPanStep']+(($monitor['MaxPanStep']-$monitor['MinPanStep'])*$x_factor)));
|
|
|
|
$ctrl_command .= " --panstep=".$pan_step;
|
|
|
|
}
|
|
|
|
if ( preg_match( '/^(up|down)/', $dirn ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
$tilt_step = intval(round($monitor['MinTiltStep']+(($monitor['MaxTiltStep']-$monitor['MinTiltStep'])*$y_factor)));
|
|
|
|
$ctrl_command .= " --tiltstep=".$tilt_step;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( preg_match( '/^preset_goto_(\d+)$/', $control, $matches ) )
|
|
|
|
{
|
|
|
|
$control = 'preset_goto';
|
|
|
|
$ctrl_command .= " --preset ".$matches[1];
|
|
|
|
}
|
|
|
|
elseif ( $control == "move_map" )
|
|
|
|
{
|
|
|
|
$ctrl_command .= " -xcoord $x -ycoord $y";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $control != 'null' )
|
|
|
|
{
|
|
|
|
if ( $monitor['Function'] == 'Modect' || $monitor['Function'] == 'Mocord' )
|
|
|
|
{
|
|
|
|
$zmu_command = getZmuCommand( " -m $mid -r" );
|
|
|
|
$zmu_output = exec( escapeshellcmd( $zmu_command ) );
|
|
|
|
}
|
|
|
|
$ctrl_command .= " --command=".$control;
|
|
|
|
//echo $ctrl_command;
|
|
|
|
$ctrl_output = exec( escapeshellcmd( $ctrl_command ) );
|
|
|
|
//echo $ctrl_output;
|
|
|
|
}
|
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
elseif ( $action == "delete" )
|
|
|
|
{
|
|
|
|
if ( $mark_zids )
|
2002-11-28 00:21:49 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$deleted_zid = 0;
|
|
|
|
foreach( $mark_zids as $mark_zid )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "delete from Zones where Id = '$mark_zid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$deleted_zid = 1;
|
|
|
|
}
|
|
|
|
if ( $deleted_zid )
|
2002-11-28 00:21:49 +08:00
|
|
|
{
|
2004-12-29 02:20:11 +08:00
|
|
|
if ( $cookies ) session_write_close();
|
2003-06-27 20:10:10 +08:00
|
|
|
zmaControl( $mid, true );
|
|
|
|
$refresh_parent = true;
|
2002-11-28 00:21:49 +08:00
|
|
|
}
|
|
|
|
}
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $mark_mids && !$user['MonitorIds'] )
|
2002-11-29 19:21:37 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
foreach( $mark_mids as $mark_mid )
|
|
|
|
{
|
|
|
|
$sql = "select * from Monitors where Id = '$mark_mid'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
if ( !($monitor = mysql_fetch_assoc( $result )) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = "select Id from Events where MonitorId = '$mark_mid'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
|
|
|
|
$mark_eids = array();
|
|
|
|
while( $row = mysql_fetch_assoc( $result ) )
|
|
|
|
{
|
2004-01-08 18:09:35 +08:00
|
|
|
$mark_eids[] = $row['Id'];
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
|
|
|
foreach( $mark_eids as $mark_eid )
|
|
|
|
{
|
|
|
|
deleteEvent( $mark_eid );
|
|
|
|
}
|
2004-09-07 16:45:00 +08:00
|
|
|
unlink( ZM_DIR_EVENTS."/".$monitor['Name'] );
|
|
|
|
system( "rm -rf ".ZM_DIR_EVENTS."/".$monitor['Id'] );
|
2003-06-27 20:10:10 +08:00
|
|
|
|
|
|
|
$result = mysql_query( "delete from Zones where MonitorId = '$mark_mid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-10-28 01:06:21 +08:00
|
|
|
if ( ZM_OPT_X10 )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "delete from TriggersX10 where MonitorId = '$mark_mid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "delete from Monitors where Id = '$mark_mid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-10-28 01:06:21 +08:00
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
}
|
2002-11-29 19:21:37 +08:00
|
|
|
}
|
2002-11-28 00:21:49 +08:00
|
|
|
}
|
|
|
|
}
|
2004-10-13 17:49:11 +08:00
|
|
|
if ( canView( 'System' ) )
|
|
|
|
{
|
|
|
|
if ( $action == "group" )
|
|
|
|
{
|
|
|
|
if ( count($mark_gids) )
|
|
|
|
{
|
|
|
|
setcookie( "cgroup", $mark_gids[0], time()+3600*24*30*12*10 );
|
|
|
|
}
|
2004-12-28 23:48:45 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setcookie( "cgroup", "", time()-3600*24*2 );
|
|
|
|
}
|
|
|
|
$refresh_parent = true;
|
2004-10-13 17:49:11 +08:00
|
|
|
}
|
|
|
|
}
|
2003-06-30 04:53:55 +08:00
|
|
|
if ( canEdit( 'System' ) )
|
|
|
|
{
|
2004-01-27 18:17:23 +08:00
|
|
|
if ( $action == "version" && isset($option) )
|
|
|
|
{
|
|
|
|
switch( $option )
|
|
|
|
{
|
|
|
|
case 'go' :
|
|
|
|
{
|
|
|
|
// Ignore this, the caller will open the page itself
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'ignore' :
|
|
|
|
{
|
|
|
|
$sql = "update Config set Value = '".ZM_DYN_LAST_VERSION."' where Name = 'ZM_DYN_CURR_VERSION'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'hour' :
|
|
|
|
case 'day' :
|
|
|
|
case 'week' :
|
|
|
|
{
|
|
|
|
$next_reminder = time();
|
|
|
|
if ( $option == 'hour' )
|
|
|
|
{
|
|
|
|
$next_reminder += 60*60;
|
|
|
|
}
|
|
|
|
elseif ( $option == 'day' )
|
|
|
|
{
|
|
|
|
$next_reminder += 24*60*60;
|
|
|
|
}
|
|
|
|
elseif ( $option == 'week' )
|
|
|
|
{
|
|
|
|
$next_reminder += 7*24*60*60;
|
|
|
|
}
|
|
|
|
$sql = "update Config set Value = '".$next_reminder."' where Name = 'ZM_DYN_NEXT_REMINDER'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'never' :
|
|
|
|
{
|
|
|
|
$sql = "update Config set Value = '0' where Name = 'ZM_CHECK_FOR_UPDATES'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-04 04:39:02 +08:00
|
|
|
if ( $action == "options" && isset( $tab ) )
|
|
|
|
{
|
|
|
|
$config_cat = $config_cats[$tab];
|
|
|
|
$changed = false;
|
|
|
|
foreach ( $config_cat as $name=>$value )
|
|
|
|
{
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $value['Type'] == "boolean" && !$new_config[$name] )
|
2003-07-04 04:39:02 +08:00
|
|
|
{
|
|
|
|
$new_config[$name] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$new_config[$name] = preg_replace( "/\r\n/", "\n", stripslashes( $new_config[$name] ) );
|
|
|
|
}
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $value['Value'] != $new_config[$name] )
|
2003-07-04 04:39:02 +08:00
|
|
|
{
|
|
|
|
$sql = "update Config set Value = '".$new_config[$name]."' where Name = '".$name."'";
|
2003-07-04 21:00:03 +08:00
|
|
|
//echo $sql;
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-07-04 04:39:02 +08:00
|
|
|
$changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $changed )
|
|
|
|
{
|
|
|
|
switch( $tab )
|
|
|
|
{
|
|
|
|
case "system" :
|
|
|
|
case "paths" :
|
2004-03-15 07:27:36 +08:00
|
|
|
case "config" :
|
2003-07-04 04:39:02 +08:00
|
|
|
case "network" :
|
|
|
|
case "x10" :
|
|
|
|
case "mail" :
|
|
|
|
case "ftp" :
|
|
|
|
$restart = true;
|
|
|
|
break;
|
|
|
|
case "web" :
|
2004-03-15 07:27:36 +08:00
|
|
|
case "video" :
|
2003-07-04 04:39:02 +08:00
|
|
|
case "tools" :
|
|
|
|
case "highband" :
|
|
|
|
case "medband" :
|
|
|
|
case "lowband" :
|
|
|
|
case "phoneband" :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-07-07 21:26:50 +08:00
|
|
|
loadConfig();
|
2003-07-04 04:39:02 +08:00
|
|
|
}
|
|
|
|
elseif ( $action == "user" && isset( $uid ) )
|
2003-06-30 04:53:55 +08:00
|
|
|
{
|
|
|
|
if ( $uid > 0 )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "select * from Users where Id = '$uid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$row = mysql_fetch_assoc( $result );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$zone = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$changes = array();
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $new_username != $row['Username'] ) $changes[] = "Username = '$new_username'";
|
|
|
|
if ( $new_password != $row['Password'] ) $changes[] = "Password = password('$new_password')";
|
|
|
|
if ( $new_username != $row['Language'] ) $changes[] = "Language = '$new_language'";
|
|
|
|
if ( $new_enabled != $row['Enabled'] ) $changes[] = "Enabled = '$new_enabled'";
|
|
|
|
if ( $new_stream != $row['Stream'] ) $changes[] = "Stream = '$new_stream'";
|
|
|
|
if ( $new_events != $row['Events'] ) $changes[] = "Events = '$new_events'";
|
|
|
|
if ( $new_monitors != $row['Monitors'] ) $changes[] = "Monitors = '$new_monitors'";
|
|
|
|
if ( $new_system != $row['System'] ) $changes[] = "System = '$new_system'";
|
|
|
|
if ( $new_monitor_ids != $row['MonitorIds'] ) $changes[] = "MonitorIds = '$new_monitor_ids'";
|
2003-06-30 04:53:55 +08:00
|
|
|
|
|
|
|
if ( count( $changes ) )
|
|
|
|
{
|
|
|
|
if ( $uid > 0 )
|
|
|
|
{
|
|
|
|
$sql = "update Users set ".implode( ", ", $changes )." where Id = '$uid'";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sql = "insert into Users set ".implode( ", ", $changes );
|
|
|
|
}
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$view = 'none';
|
|
|
|
$refresh_parent = true;
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $row['Username'] == $user['Username'] )
|
2003-06-30 04:53:55 +08:00
|
|
|
{
|
2004-01-08 18:09:35 +08:00
|
|
|
userLogin( $row['Username'], $row['Password'] );
|
2003-06-30 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-12-08 01:13:19 +08:00
|
|
|
elseif ( $action == "state" )
|
|
|
|
{
|
|
|
|
if ( $run_state )
|
|
|
|
{
|
2004-12-29 02:20:11 +08:00
|
|
|
if ( $cookies ) session_write_close();
|
2003-12-08 01:13:19 +08:00
|
|
|
packageControl( $run_state );
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ( $action == "save" )
|
|
|
|
{
|
|
|
|
if ( $run_state || $new_state )
|
|
|
|
{
|
|
|
|
$sql = "select Id,Function from Monitors order by Id";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
|
|
|
|
$definitions = array();
|
|
|
|
while( $monitor = mysql_fetch_assoc( $result ) )
|
|
|
|
{
|
2004-01-08 18:09:35 +08:00
|
|
|
$definitions[] = $monitor['Id'].":".$monitor['Function'];
|
2003-12-08 01:13:19 +08:00
|
|
|
}
|
|
|
|
$definition = join( ',', $definitions );
|
|
|
|
if ( $new_state )
|
|
|
|
$run_state = $new_state;
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "replace into States set Name = '$run_state', Definition = '$definition'" );
|
2003-12-08 01:13:19 +08:00
|
|
|
}
|
|
|
|
}
|
2004-10-13 17:49:11 +08:00
|
|
|
elseif ( $action == "groups" )
|
|
|
|
{
|
|
|
|
if ( $names )
|
|
|
|
{
|
|
|
|
foreach ( array_keys( $names ) as $id )
|
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "update Groups set Name = '".$names[$id]."', MonitorIds = '".$monitor_ids[$id]."' where Id = '$id'" );
|
2004-10-13 17:49:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $new_monitor_ids )
|
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "insert into Groups set Name = '".$new_name."', MonitorIds = '".$new_monitor_ids."'" );
|
2004-10-13 17:49:11 +08:00
|
|
|
}
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
2005-02-24 18:43:29 +08:00
|
|
|
elseif ( $action == "controlcap" && isset( $cid ) )
|
|
|
|
{
|
|
|
|
if ( $cid > 0 )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "select * from Controls where Id = '$cid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$control = mysql_fetch_assoc( $result );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$control = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define a field type for anything that's not simple text equivalent
|
|
|
|
$types = array(
|
|
|
|
// Empty
|
|
|
|
);
|
|
|
|
|
2005-03-14 04:41:31 +08:00
|
|
|
$columns = getTableColumns( 'Controls' );
|
|
|
|
foreach ( $columns as $name=>$type )
|
|
|
|
{
|
|
|
|
if ( preg_match( '/^(Can|Has)/', $name ) )
|
|
|
|
{
|
|
|
|
$types[$name] = 'toggle';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$changes = getFormChanges( $control, $new_control, $types, $columns );
|
2005-02-24 18:43:29 +08:00
|
|
|
|
|
|
|
if ( count( $changes ) )
|
|
|
|
{
|
|
|
|
if ( $cid > 0 )
|
|
|
|
{
|
|
|
|
simpleQuery( "update Controls set ".implode( ", ", $changes )." where Id = '$cid'" );
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
$sql = "insert into Controls set ".implode( ", ", $changes );
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
$cid = mysql_insert_id();
|
|
|
|
}
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
}
|
2003-06-30 04:53:55 +08:00
|
|
|
elseif ( $action == "delete" )
|
|
|
|
{
|
2003-12-08 01:13:19 +08:00
|
|
|
if ( $run_state )
|
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "delete from States where Name = '$run_state'" );
|
2003-12-08 01:13:19 +08:00
|
|
|
}
|
2003-06-30 04:53:55 +08:00
|
|
|
if ( $mark_uids )
|
|
|
|
{
|
|
|
|
foreach( $mark_uids as $mark_uid )
|
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "delete from Users where Id = '$mark_uid'" );
|
2003-06-30 04:53:55 +08:00
|
|
|
}
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $row['Username'] == $user['Username'] )
|
2003-06-30 04:53:55 +08:00
|
|
|
{
|
|
|
|
userLogout();
|
|
|
|
}
|
|
|
|
}
|
2004-10-13 17:49:11 +08:00
|
|
|
if ( $mark_gids )
|
|
|
|
{
|
|
|
|
foreach( $mark_gids as $mark_gid )
|
|
|
|
{
|
2005-01-16 23:59:23 +08:00
|
|
|
simpleQuery( "delete from Groups where Id = '$mark_gid'" );
|
2004-10-13 17:49:11 +08:00
|
|
|
if ( $mark_gid == $cgroup )
|
|
|
|
{
|
|
|
|
unset( $cgroup );
|
|
|
|
setcookie( "cgroup", "", time()-3600*24*2 );
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-24 18:43:29 +08:00
|
|
|
if ( $mark_cids )
|
|
|
|
{
|
|
|
|
foreach( $mark_cids as $mark_cid )
|
|
|
|
{
|
|
|
|
simpleQuery( "delete from Controls where Id = '$mark_cid'" );
|
|
|
|
simpleQuery( "update Monitors set Controllable = 0, ControlId = 0 where ControlId = '$mark_cid'" );
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
}
|
2003-06-30 04:53:55 +08:00
|
|
|
}
|
|
|
|
}
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( $action == "learn" )
|
2003-06-25 17:47:09 +08:00
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( !$mark_eids && $mark_eid )
|
|
|
|
{
|
|
|
|
$mark_eids[] = $mark_eid;
|
|
|
|
$refresh_parent = true;
|
|
|
|
}
|
|
|
|
if ( $mark_eids )
|
|
|
|
{
|
|
|
|
foreach( $mark_eids as $mark_eid )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "update Events set LearnState = '$learn_state' where Id = '$mark_eid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
|
|
|
}
|
2003-06-25 17:47:09 +08:00
|
|
|
}
|
2002-10-05 05:40:55 +08:00
|
|
|
elseif ( $action == "reset" )
|
|
|
|
{
|
2005-01-17 00:08:35 +08:00
|
|
|
$_SESSION['event_reset_time'] = strftime( "%Y-%m-%d %H:%M:%S" );
|
|
|
|
setcookie( "event_reset_time", $_SESSION['event_reset_time'], time()+3600*24*30*12*10 );
|
2004-12-29 02:20:11 +08:00
|
|
|
if ( $cookies ) session_write_close();
|
2002-10-05 05:40:55 +08:00
|
|
|
}
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|