'; } $string .= $label; if ( $condition ) { $string .= ''; } return( $string ); } function buildSelect( $name, $contents, $onchange="" ) { if ( preg_match( "/^(\w+)\s*\[\s*['\"]?(\w+)[\"']?\s*]$/", $name, $matches ) ) { $arr = $matches[1]; $idx = $matches[2]; global $$arr; $value = ${$arr}[$idx]; } else { global $$name; $value = $$name; } ob_start(); ?> $value ) { switch( $types[$key] ) { case 'set' : { if ( is_array( $new_values[$key] ) ) { if ( join(',',$new_values[$key]) != $values[$key] ) { $changes[] = "$key = '".join(',',$new_values[$key])."'"; } } elseif ( $values[$key] ) { $changes[] = "$key = ''"; } break; } default : { if ( $values[$key] != $value ) { $changes[] = "$key = '$value'"; } break; } } } return( $changes ); } 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( 'Safari/([0-9.]+)',$HTTP_SERVER_VARS[HTTP_USER_AGENT],$log_version)) { $version = $log_version[1]; $browser = 'safari'; } 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() { return( ZM_CAN_STREAM || isNetscape() || (ZM_OPT_CAMBOZOLA && file_exists( ZM_PATH_WEB.'/'.ZM_PATH_CAMBOZOLA )) ); } function fixDevices() { $string = ZM_PATH_BIN."/zmfix"; $string .= " 2>/dev/null >&- <&- >/dev/null"; exec( $string ); } function packageControl( $command ) { $string = ZM_PATH_BIN."/zmpkg.pl $command"; $string .= " 2>/dev/null >&- <&- >/dev/null"; exec( $string ); } function daemonControl( $command, $daemon=false, $args=false ) { $string = ZM_PATH_BIN."/zmdc.pl $command"; if ( $daemon ) { $string .= " $daemon"; if ( $args ) { $string .= " $args"; } } $string .= " 2>/dev/null >&- <&- >/dev/null"; exec( $string ); } function zmcControl( $monitor, $restart=false ) { if ( $monitor[Type] == "Local" ) { $sql = "select count(if(Function!='None',1,NULL)) as ActiveCount from Monitors where Device = '$monitor[Device]'"; $zmc_args = "-d $monitor[Device]"; } else { $sql = "select count(if(Function!='None',1,NULL)) as ActiveCount from Monitors where Host = '$monitor[Host]' and Port = '$monitor[Port]' and Path = '$monitor[Path]'"; $zmc_args = "-H $monitor[Host] -P $monitor[Port] -p '$monitor[Path]'"; } $result = mysql_query( $sql ); if ( !$result ) echo mysql_error(); $row = mysql_fetch_assoc( $result ); $active_count = $row[ActiveCount]; if ( !$active_count ) { daemonControl( "stop", "zmc", $zmc_args ); } else { if ( $restart ) { daemonControl( "stop", "zmc", $zmc_args ); } daemonControl( "start", "zmc", $zmc_args ); } } function zmaControl( $monitor, $restart=false ) { if ( !is_array( $monitor ) ) { $sql = "select Id,Function,RunMode from Monitors where Id = '$monitor'"; $result = mysql_query( $sql ); if ( !$result ) echo mysql_error(); $monitor = mysql_fetch_assoc( $result ); } if ( $monitor[RunMode] == 'Triggered' ) { // Don't touch anything that's triggered return; } switch ( $monitor['Function'] ) { case 'Modect' : case 'Record' : case 'Mocord' : { if ( $restart ) { daemonControl( "stop", "zmfilter.pl", "-m $monitor[Id] -e -1" ); daemonControl( "stop", "zma", "-m $monitor[Id]" ); if ( ZM_OPT_FRAME_SERVER ) { daemonControl( "stop", "zmf", "-m $monitor[Id]" ); } } if ( ZM_OPT_FRAME_SERVER ) { daemonControl( "start", "zmf", "-m $monitor[Id]" ); } daemonControl( "start", "zma", "-m $monitor[Id]" ); daemonControl( "start", "zmfilter.pl", "-m $monitor[Id] -e -1" ); break; } default : { daemonControl( "stop", "zmfilter.pl", "-m $monitor[Id] -e -1" ); daemonControl( "stop", "zma", "-m $monitor[Id]" ); if ( ZM_OPT_FRAME_SERVER ) { daemonControl( "stop", "zmf", "-m $monitor[Id]" ); } break; } } } function daemonCheck( $daemon=false, $args=false ) { $string = ZM_PATH_BIN."/zmdc.pl check"; if ( $daemon ) { $string .= " $daemon"; if ( $args ) $string .= " $args"; } $result = exec( $string ); return( preg_match( '/running/', $result ) ); } function zmcCheck( $monitor ) { if ( $monitor[Type] == 'Local' ) { $zmc_args = "-d $monitor[Device]"; } else { $zmc_args = "-H $monitor[Host] -P $monitor[Port] -p '$monitor[Path]'"; } return( daemonCheck( "zmc", $zmc_args ) ); } function zmaCheck( $monitor ) { if ( is_array( $monitor ) ) { $monitor = $monitor[Id]; } return( daemonCheck( "zma", "-m $monitor" ) ); } function createVideo( $event, $rate, $scale, $overwrite=0 ) { $command = ZM_PATH_BIN."/zmvideo.pl -e $event[Id] -r $rate -s $scale"; if ( $overwrite ) $command .= " -o"; $result = exec( $command, $output, $status ); return( $status?"":rtrim($result) ); } function reScale( $dimension, $scale=1 ) { if ( $scale == 1 ) return( $dimension ); if ( $scale > 0 ) { return( (int)($dimension*$scale) ); } else { return( (int)(1+(($dimension-1)/-$scale)) ); } } ?>