/dev/null >&- <&- >/dev/null"; exec( $string ); } function zmcControl( $device, $restart=false ) { 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]; if ( !$passive_count && !$active_count && !$x10_count ) { daemonControl( "stop", "zmc", "-d $device" ); } else { if ( $restart ) { daemonControl( "stop", "zmc", "-d $device" ); } daemonControl( "start", "zmc", "-d $device" ); } } function zmaControl( $monitor, $restart=false ) { if ( !is_array( $monitor ) ) { $sql = "select Id,Function from Monitors where Id = '$monitor'"; $result = mysql_query( $sql ); if ( !$result ) echo mysql_error(); $monitor = mysql_fetch_assoc( $result ); } if ( $monitor['Function'] == 'Active' ) { if ( $restart ) { daemonControl( "stop", "zma", "-m $monitor[Id]" ); } daemonControl( "start", "zma", "-m $monitor[Id]" ); } else { daemonControl( "stop", "zma", "-m $monitor[Id]" ); } } function daemonCheck( $daemon=false, $args=false ) { $string = ZM_PATH."/zmdc.pl check"; if ( $daemon ) { $string .= " $daemon"; if ( $args ) $string .= " $args"; } $result = exec( $string ); return( preg_match( '/running/', $result ) ); } function zmcCheck( $device ) { if ( is_array( $device ) ) { $device = $device[Device]; } return( daemonCheck( "zmc", "-d $device" ) ); } function zmaCheck( $monitor ) { if ( is_array( $monitor ) ) { $monitor = $monitor[Id]; } return( daemonCheck( "zma", "-m $monitor" ) ); } ?>