2002-10-11 17:45:06 +08:00
< ? php
//
2002-12-10 21:23:22 +08:00
// ZoneMinder function library file, $Date$, $Revision$
2003-01-12 02:22:27 +08:00
// Copyright (C) 2003 Philip Coombes
2002-10-11 17:45:06 +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.
//
2002-11-22 20:12:16 +08:00
function deleteEvent ( $eid )
{
2002-12-24 19:56:01 +08:00
if ( $eid )
2002-12-10 20:51:27 +08:00
{
2002-12-24 19:56:01 +08:00
$result = mysql_query ( " delete from Events where Id = ' $eid ' " );
2002-12-10 20:51:27 +08:00
if ( ! $result )
die ( mysql_error () );
2003-01-11 01:12:23 +08:00
if ( ! ZM_OPT_FAST_DELETE )
2002-12-24 19:56:01 +08:00
{
$result = mysql_query ( " delete from Stats where EventId = ' $eid ' " );
if ( ! $result )
die ( mysql_error () );
$result = mysql_query ( " delete from Frames where EventId = ' $eid ' " );
if ( ! $result )
die ( mysql_error () );
2003-01-11 01:12:23 +08:00
system ( escapeshellcmd ( " rm -rf " . ZM_PATH_EVENTS . " /*/ " . sprintf ( " %04d " , $eid ) ) );
2002-12-24 19:56:01 +08:00
}
2002-12-10 20:51:27 +08:00
}
2002-11-22 20:12:16 +08:00
}
2002-10-11 17:45:06 +08:00
function getBrowser ( & $browser , & $version )
{
global $HTTP_SERVER_VARS ;
if ( ereg ( 'MSIE ([0-9].[0-9]{1,2})' , $HTTP_SERVER_VARS [ HTTP_USER_AGENT ], $log_version ))
{
$version = $log_version [ 1 ];
$browser = 'ie' ;
}
elseif ( ereg ( 'Opera ([0-9].[0-9]{1,2})' , $HTTP_SERVER_VARS [ HTTP_USER_AGENT ], $log_version ))
{
$version = $log_version [ 1 ];
$browser = 'opera' ;
}
elseif ( ereg ( 'Mozilla/([0-9].[0-9]{1,2})' , $HTTP_SERVER_VARS [ HTTP_USER_AGENT ], $log_version ))
{
$version = $log_version [ 1 ];
$browser = 'mozilla' ;
}
else
{
$version = 0 ;
$browser = 'unknown' ;
}
}
function isNetscape ()
{
getBrowser ( $browser , $version );
return ( $browser == " mozilla " );
}
function canStream ()
{
2003-01-11 18:15:12 +08:00
return ( isNetscape () || ( ZM_OPT_CAMBOZOLA && file_exists ( ZM_PATH_CAMBOZOLA )) );
2002-10-11 17:45:06 +08:00
}
2003-01-07 18:44:25 +08:00
function fixDevices ()
{
2003-01-15 23:06:15 +08:00
$string = ZM_PATH_BIN . " /zmfix " ;
2003-01-07 18:44:25 +08:00
$string .= " 2>/dev/null >&- <&- >/dev/null " ;
exec ( $string );
}
2003-01-14 21:07:57 +08:00
function packageControl ( $command )
{
2003-01-15 23:06:15 +08:00
$string = ZM_PATH_BIN . " /zmpkg.pl $command " ;
2003-01-14 21:07:57 +08:00
$string .= " 2>/dev/null >&- <&- >/dev/null " ;
exec ( $string );
}
2002-12-24 19:56:01 +08:00
function daemonControl ( $command , $daemon = false , $args = false )
2002-12-12 06:43:00 +08:00
{
2003-01-15 23:06:15 +08:00
$string = ZM_PATH_BIN . " /zmdc.pl $command " ;
2002-12-12 06:43:00 +08:00
if ( $daemon )
2002-12-24 20:43:13 +08:00
{
$string .= " $daemon " ;
if ( $args )
{
$string .= " $args " ;
}
}
2002-12-12 06:43:00 +08:00
$string .= " 2>/dev/null >&- <&- >/dev/null " ;
exec ( $string );
}
2002-12-24 19:56:01 +08:00
function zmcControl ( $device , $restart = false )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
if ( is_array ( $device ) )
{
$device = $device [ Device ];
}
$sql = " select count(if(Function='Passive',1,NULL)) as PassiveCount, count(if(Function='Active',1,NULL)) as ActiveCount, count(if(Function='X10',1,NULL)) as X10Count 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 ];
$x10_count = $row [ X10Count ];
2002-12-11 08:22:51 +08:00
2002-12-24 19:56:01 +08:00
if ( ! $passive_count && ! $active_count && ! $x10_count )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
daemonControl ( " stop " , " zmc " , " -d $device " );
2002-10-11 17:45:06 +08:00
}
2002-12-24 19:56:01 +08:00
else
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
if ( $restart )
{
daemonControl ( " stop " , " zmc " , " -d $device " );
}
daemonControl ( " start " , " zmc " , " -d $device " );
2002-10-11 17:45:06 +08:00
}
}
2002-12-24 19:56:01 +08:00
function zmaControl ( $monitor , $restart = false )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
if ( ! is_array ( $monitor ) )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
$sql = " select Id,Function from Monitors where Id = ' $monitor ' " ;
$result = mysql_query ( $sql );
if ( ! $result )
echo mysql_error ();
$monitor = mysql_fetch_assoc ( $result );
2002-10-11 17:45:06 +08:00
}
2002-12-24 19:56:01 +08:00
if ( $monitor [ 'Function' ] == 'Active' )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
if ( $restart )
{
daemonControl ( " stop " , " zma " , " -m $monitor[Id] " );
}
daemonControl ( " start " , " zma " , " -m $monitor[Id] " );
2002-10-11 17:45:06 +08:00
}
2002-12-24 19:56:01 +08:00
else
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
daemonControl ( " stop " , " zma " , " -m $monitor[Id] " );
2002-10-11 17:45:06 +08:00
}
}
2002-12-24 19:56:01 +08:00
function daemonCheck ( $daemon = false , $args = false )
2002-10-11 17:45:06 +08:00
{
2003-01-15 23:06:15 +08:00
$string = ZM_PATH_BIN . " /zmdc.pl check " ;
2002-12-24 19:56:01 +08:00
if ( $daemon )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
$string .= " $daemon " ;
if ( $args )
$string .= " $args " ;
2002-10-11 17:45:06 +08:00
}
2002-12-24 19:56:01 +08:00
$result = exec ( $string );
return ( preg_match ( '/running/' , $result ) );
}
function zmcCheck ( $device )
{
if ( is_array ( $device ) )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
$device = $device [ Device ];
2002-10-11 17:45:06 +08:00
}
2002-12-24 19:56:01 +08:00
return ( daemonCheck ( " zmc " , " -d $device " ) );
}
function zmaCheck ( $monitor )
{
if ( is_array ( $monitor ) )
2002-10-11 17:45:06 +08:00
{
2002-12-24 19:56:01 +08:00
$monitor = $monitor [ Id ];
2002-10-11 17:45:06 +08:00
}
2002-12-24 19:56:01 +08:00
return ( daemonCheck ( " zma " , " -m $monitor " ) );
2002-10-11 17:45:06 +08:00
}
?>