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$
|
2003-01-12 02:22:27 +08:00
|
|
|
// Copyright (C) 2003 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
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "update Events set Name = '$event_name' where Id = '$eid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
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
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "update Events set Archived = 1 where Id = '$eid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
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
|
|
|
{
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( "update Events set Archived = 0 where Id = '$eid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
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";
|
|
|
|
}
|
|
|
|
$filter_query_string = join( '&', $filter_parms );
|
2004-02-16 03:42:00 +08:00
|
|
|
$sql = "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'";
|
2002-10-03 19:39:36 +08:00
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
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
|
|
|
{
|
2004-02-16 03:42:00 +08:00
|
|
|
$sql = "delete from Filters where Name = '$fid'";
|
2003-06-27 20:10:10 +08:00
|
|
|
$result = mysql_query( $sql );
|
2002-10-03 19:39:36 +08:00
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
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 )
|
|
|
|
{
|
|
|
|
$sql = "update Monitors set Function = '$new_function' where Id = '$mid'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
echo mysql_error();
|
2002-10-03 19:39:36 +08:00
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
$monitor['Function'] = $new_function;
|
2003-12-08 01:13:19 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
$changes = array();
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $new_name != $zone['Name'] ) $changes[] = "Name = '$new_name'";
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( $new_type != $zone['Type'] ) $changes[] = "Type = '$new_type'";
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $new_units != $zone['Units'] ) $changes[] = "Units = '$new_units'";
|
|
|
|
if ( $new_lo_x != $zone['LoX'] ) $changes[] = "LoX = '$new_lo_x'";
|
|
|
|
if ( $new_lo_y != $zone['LoY'] ) $changes[] = "LoY = '$new_lo_y'";
|
|
|
|
if ( $new_hi_x != $zone['HiX'] ) $changes[] = "HiX = '$new_hi_x'";
|
|
|
|
if ( $new_hi_y != $zone['HiY'] ) $changes[] = "HiY = '$new_hi_y'";
|
|
|
|
if ( $new_alarm_rgb != $zone['AlarmRGB'] ) $changes[] = "AlarmRGB = '$new_alarm_rgb'";
|
2004-01-27 20:27:22 +08:00
|
|
|
if ( $new_min_pixel_threshold != $zone['MinPixelThreshold'] ) $changes[] = "MinPixelThreshold = '$new_min_pixel_threshold'";
|
|
|
|
if ( $new_max_pixel_threshold != $zone['MaxPixelThreshold'] ) $changes[] = "MaxPixelThreshold = '$new_max_pixel_threshold'";
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $new_min_alarm_pixels != $zone['MinAlarmPixels'] ) $changes[] = "MinAlarmPixels = '$new_min_alarm_pixels'";
|
|
|
|
if ( $new_max_alarm_pixels != $zone['MaxAlarmPixels'] ) $changes[] = "MaxAlarmPixels = '$new_max_alarm_pixels'";
|
|
|
|
if ( $new_filter_x != $zone['FilterX'] ) $changes[] = "FilterX = '$new_filter_x'";
|
|
|
|
if ( $new_filter_y != $zone['FilterY'] ) $changes[] = "FilterY = '$new_filter_y'";
|
|
|
|
if ( $new_min_filter_pixels != $zone['MinFilterPixels'] ) $changes[] = "MinFilterPixels = '$new_min_filter_pixels'";
|
|
|
|
if ( $new_max_filter_pixels != $zone['MaxFilterPixels'] ) $changes[] = "MaxFilterPixels = '$new_max_filter_pixels'";
|
|
|
|
if ( $new_min_blob_pixels != $zone['MinBlobPixels'] ) $changes[] = "MinBlobPixels = '$new_min_blob_pixels'";
|
|
|
|
if ( $new_max_blob_pixels != $zone['MaxBlobPixels'] ) $changes[] = "MaxBlobPixels = '$new_max_blob_pixels'";
|
|
|
|
if ( $new_min_blobs != $zone['MinBlobs'] ) $changes[] = "MinBlobs = '$new_min_blobs'";
|
|
|
|
if ( $new_max_blobs != $zone['MaxBlobs'] ) $changes[] = "MaxBlobs = '$new_max_blobs'";
|
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';
|
|
|
|
}
|
|
|
|
#echo "<html>$sql</html>";
|
2002-10-03 19:39:36 +08:00
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
2003-12-08 01:13:19 +08:00
|
|
|
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(
|
|
|
|
'Triggers' => 'set'
|
|
|
|
);
|
|
|
|
|
|
|
|
$changes = getFormChanges( $monitor, $new_monitor, $types );
|
|
|
|
|
2003-06-27 20:10:10 +08:00
|
|
|
if ( count( $changes ) )
|
|
|
|
{
|
|
|
|
if ( $mid > 0 )
|
|
|
|
{
|
2003-10-28 01:06:21 +08:00
|
|
|
$sql = "update Monitors set ".implode( ", ", $changes )." where Id = '$mid'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
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-01-27 20:27:22 +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, 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';
|
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();
|
2003-12-08 01:13:19 +08:00
|
|
|
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
|
|
|
{
|
2003-11-21 18:37:53 +08:00
|
|
|
$zmu_command = ZMU_COMMAND." -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 );
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2003-12-08 01:13:19 +08:00
|
|
|
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-01-08 18:09:35 +08:00
|
|
|
system( "rm -rf ".EVENT_PATH."/".$monitor['Name'] );
|
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
|
|
|
}
|
|
|
|
}
|
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" :
|
|
|
|
case "video" :
|
|
|
|
case "network" :
|
|
|
|
case "x10" :
|
|
|
|
case "mail" :
|
|
|
|
case "ftp" :
|
|
|
|
$restart = true;
|
|
|
|
break;
|
|
|
|
case "web" :
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
session_write_close();
|
|
|
|
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;
|
|
|
|
$sql = "replace into States set Name = '$run_state', Definition = '$definition'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
|
|
|
}
|
2003-06-30 04:53:55 +08:00
|
|
|
elseif ( $action == "delete" )
|
|
|
|
{
|
2003-12-08 01:13:19 +08:00
|
|
|
if ( $run_state )
|
|
|
|
{
|
|
|
|
$sql = "delete from States where Name = '$run_state'";
|
|
|
|
$result = mysql_query( $sql );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
2003-06-30 04:53:55 +08:00
|
|
|
if ( $mark_uids )
|
|
|
|
{
|
|
|
|
foreach( $mark_uids as $mark_uid )
|
|
|
|
{
|
|
|
|
$result = mysql_query( "delete from Users where Id = '$mark_uid'" );
|
|
|
|
if ( !$result )
|
|
|
|
die( mysql_error() );
|
|
|
|
}
|
2004-01-08 18:09:35 +08:00
|
|
|
if ( $row['Username'] == $user['Username'] )
|
2003-06-30 04:53:55 +08:00
|
|
|
{
|
|
|
|
userLogout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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" )
|
|
|
|
{
|
2004-01-08 18:09:35 +08:00
|
|
|
$HTTP_SESSION_VARS['event_reset_time'] = strftime( "%Y-%m-%d %H:%M:%S" );
|
|
|
|
setcookie( "event_reset_time", $HTTP_SESSION_VARS['event_reset_time'], time()+3600*24*30*12*10 );
|
2003-09-23 17:52:45 +08:00
|
|
|
session_write_close();
|
2002-10-05 05:40:55 +08:00
|
|
|
}
|
2002-10-03 19:39:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|