0 )
{
$result = mysql_query( "select * from Zones where MonitorId = '$mid' and Id = '$zid'" );
if ( !$result )
die( mysql_error() );
$zone = mysql_fetch_assoc( $result );
}
else
{
$zone = array();
}
$changes = array();
if ( $new_name != $zone[Name] ) $changes[] = "Name = '$new_name'";
if ( $new_type != $zone['Type'] ) $changes[] = "Type = '$new_type'";
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'";
if ( $new_alarm_threshold != $zone[AlarmThreshold] ) $changes[] = "AlarmThreshold = '$new_alarm_threshold'";
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'";
if ( count( $changes ) )
{
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 "$sql";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
startDaemon( "zma", $monitor[Device] );
$refresh_parent = true;
}
}
elseif ( $action == "monitor" && isset( $mid ) )
{
if ( $mid > 0 )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
}
else
{
$monitor = array();
}
$changes = array();
if ( $new_name != $monitor[Name] ) $changes[] = "Name = '$new_name'";
if ( $new_function != $monitor['Function'] ) $changes[] = "Function = '$new_function'";
if ( $new_device != $monitor['Device'] ) $changes[] = "Device = '$new_device'";
if ( $new_channel != $monitor['Channel'] ) $changes[] = "Channel = '$new_channel'";
if ( $new_format != $monitor['Format'] ) $changes[] = "Format = '$new_format'";
if ( $new_width != $monitor['Width'] ) $changes[] = "Width = '$new_width'";
if ( $new_height != $monitor['Height'] ) $changes[] = "Height = '$new_height'";
if ( $new_colours != $monitor['Colours'] ) $changes[] = "Colours = '$new_colours'";
if ( count( $changes ) )
{
if ( $mid > 0 )
{
$sql = "update Monitors set ".implode( ", ", $changes )." where MonitorId = '$mid'";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
if ( $new_name != $monitor[Name] )
{
exec( escape_shell_command( "mv ".EVENTS_PATH."/$monitor[Name] ".EVENTS_PATH."/$new_name" ) );
}
}
else
{
$sql = "insert into Monitors set ".implode( ", ", $changes );
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$mid = mysql_insert_id();
$sql = "insert into Zones set MonitorId = $mid, Name = 'All', Type = 'Active' Units = 'Percent' LoX = 0 LoY = 0 HiX = 100 HiY = 100 AlarmRGB = 0xff0000 AlarmThreshold = 25 MinAlarmPixels = 3 MaxAlarmPixels = 75 FilterX = 3 FilterY = 3 MinFilterPixels = 3 MaxFilterPixels = 75 MinBlobPixels = 2 MaxBlobPixels = 0 MinBlobs = 1 MaxBlobs = 0";
$result = mysql_query( $sql );
if ( !$result )
die( mysql_error() );
$view = 'none';
}
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
controlDaemons( $monitor[Device] );
$refresh_parent = true;
}
}
}
if ( !$view )
{
$view = "console";
}
if ( $view == "console" )
{
header("Refresh: ".REFRESH_MAIN."; URL='$PHP_SELF'" );
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
//$result = mysql_query( "select M.*, count(E.Id) as EventCount, count(if(E.Archived,1,NULL)) as ArchEventCount, count(if(E.StartTime>NOW() - INTERVAL 1 HOUR && E.Archived = 0,1,NULL)) as HourEventCount, count(if(E.StartTime>NOW() - INTERVAL 1 DAY && E.Archived = 0,1,NULL)) as DayEventCount, count(if(E.StartTime>NOW() - INTERVAL 7 DAY && E.Archived = 0,1,NULL)) as WeekEventCount, count(if(E.StartTime>NOW() - INTERVAL 1 MONTH && E.Archived = 0,1,NULL)) as MonthEventCount, count(Z.MonitorId) as ZoneCount from Monitors as M inner join Zones as Z on Z.MonitorId = M.Id left join Events as E on E.MonitorId = M.Id group by E.MonitorId,Z.MonitorId order by Id" );
$sql = "select M.*, count(E.Id) as EventCount, count(if(E.Archived,1,NULL)) as ArchEventCount, count(if(E.StartTime>NOW() - INTERVAL 1 HOUR && E.Archived = 0,1,NULL)) as HourEventCount, count(if(E.StartTime>NOW() - INTERVAL 1 DAY && E.Archived = 0,1,NULL)) as DayEventCount, count(if(E.StartTime>NOW() - INTERVAL 7 DAY && E.Archived = 0,1,NULL)) as WeekEventCount, count(if(E.StartTime>NOW() - INTERVAL 1 MONTH && E.Archived = 0,1,NULL)) as MonthEventCount from Monitors as M left join Events as E on E.MonitorId = M.Id group by E.MonitorId order by Id";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$monitors = array();
$max_width = 0;
$max_height = 0;
$cycle_count = 0;
while( $row = mysql_fetch_assoc( $result ) )
{
if ( $max_width < $row[Width] ) $max_width = $row[Width];
if ( $max_height < $row[Height] ) $max_height = $row[Height];
$sql = "select count(Id) as ZoneCount, count(if(Type='Active',1,NULL)) as ActZoneCount, count(if(Type='Inclusive',1,NULL)) as IncZoneCount, count(if(Type='Exclusive',1,NULL)) as ExcZoneCount, count(if(Type='Inactive',1,NULL)) as InactZoneCount from Zones where MonitorId = '$row[Id]'";
$result2 = mysql_query( $sql );
if ( !$result2 )
echo mysql_error();
$row2 = mysql_fetch_assoc( $result2 );
$monitors[] = array_merge( $row, $row2 );
if ( $row['Function'] != 'None' ) $cycle_count++;
}
$sql = "select distinct Device from Monitors order by Device";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$devices = array();
while( $row = mysql_fetch_assoc( $result ) )
{
$ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zmc $row[Device]' | grep -v grep" ) );
if ( $ps_array[3] )
{
$row['zmc'] = 1;
}
$ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zma $row[Device]' | grep -v grep" ) );
if ( $ps_array[3] )
{
$row['zma'] = 1;
}
$devices[] = $row;
}
?>
ZM - Console
Zone Monitor Console
ZM - Cycle Watch
ZM - - Watch
ZM - - Events Archive
ZM - Image
ZM - Event -
|
Refresh |
Delete |
Archive |
Stills |
Stream |
|
Video |
|
Close |
|
|
$thumb_image";
else
$command = "jpegtopnm -dct fast $capt_image | pnmscalefixed $fraction | ppmtojpeg --dct=fast > $thumb_image";
#exec( escapeshellcmd( $command ) );
exec( $command );
}
}
?>
|
|
ZM - - Zones
0 )
{
$result = mysql_query( "select * from Monitors where Id = '$mid'" );
if ( !$result )
die( mysql_error() );
$monitor = mysql_fetch_assoc( $result );
}
else
{
$monitor = array();
$monitor[Name] = "New";
}
?>
ZM - Monitor
0 )
{
$result = mysql_query( "select * from Zones where MonitorId = '$mid' and Id = '$zid'" );
if ( !$result )
die( mysql_error() );
$zone = mysql_fetch_assoc( $result );
}
else
{
$zone = array();
$zone[Name] = "New";
$zone[LoX] = 0;
$zone[LoY] = 0;
$zone[HiX] = $monitor[Width]-1;
$zone[HiY] = $monitor[Height]-1;
}
?>
ZM - - Zone
$event_dir/mpeg.log" ) );
}
//chdir( $event_dir );
//header("Content-type: video/mpeg");
//header("Content-Disposition: inline; filename=$video_name");
header("Location: $video_file" );
}
elseif ( $view == "device" )
{
$ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zmc $did' | grep -v grep" ) );
if ( $ps_array[3] )
{
$zmc = 1;
}
$ps_array = preg_split( "/\s+/", exec( "ps -edalf | grep 'zma $did' | grep -v grep" ) );
if ( $ps_array[3] )
{
$zma = 1;
}
?>
ZM - Device - /dev/video
ZM - Function -
/dev/null >&- <&- >/dev/null &';
exec( $command );
$ps_array = preg_split( "/\s+/", exec( $ps_command ) );
while ( !$pid )
{
sleep( 1 );
$ps_array = preg_split( "/\s+/", exec( $ps_command ) );
$pid = $ps_array[3];
}
}
function stopDaemon( $daemon, $did )
{
$ps_command = "ps -edalf | grep '$daemon $did' | grep -v grep";
$ps_array = preg_split( "/\s+/", exec( $ps_command ) );
if ( $ps_array[3] )
{
$pid = $ps_array[3];
exec( "kill -TERM $pid" );
}
else
{
return;
}
while( $pid )
{
sleep( 1 );
$ps_array = preg_split( "/\s+/", exec( $ps_command ) );
$pid = $ps_array[3];
}
}
function controlDaemons( $device )
{
$sql = "select count(if(Function='Passive',1,NULL)) as PassiveCount, count(if(Function='Active',1,NULL)) as ActiveCount from Monitors where Device = '$device'";
$result = mysql_query( $sql );
if ( !$result )
echo mysql_error();
$row = mysql_fetch_assoc( $result );
$passive_count = $row[PassiveCount];
$active_count = $row[ActiveCount];
if ( !$passive_count && !$active_count )
{
stopDaemon( "zmc", $device );
}
else
{
startDaemon( "zmc", $device );
}
if ( !$active_count )
{
stopDaemon( "zma", $device );
}
else
{
startDaemon( "zma", $device );
}
}
function getEnumValues( $table, $column )
{
$enum_values = array();
$result = mysql_query( "DESCRIBE $table $column" );
if ( $result )
{
$row = mysql_fetch_assoc($result);
preg_match_all( "/'([^']+)'/", $row[Type], $enum_matches );
$enum_values = $enum_matches[1];
}
else
{
echo mysql_error();
}
return $enum_values;
}
?>