Whitespace fixes

This commit is contained in:
Isaac Connor 2016-05-05 15:30:24 -04:00
parent 49dc917b2e
commit 4b782efd54
2 changed files with 130 additions and 129 deletions

View File

@ -3,114 +3,115 @@ require_once( 'database.php' );
require_once( 'Server.php' ); require_once( 'Server.php' );
class Monitor { class Monitor {
public function __construct( $IdOrRow ) { public function __construct( $IdOrRow ) {
$row = NULL; $row = NULL;
if ( $IdOrRow ) { if ( $IdOrRow ) {
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) { if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
$row = dbFetchOne( 'SELECT * FROM Monitors WHERE Id=?', NULL, array( $IdOrRow ) ); $row = dbFetchOne( 'SELECT * FROM Monitors WHERE Id=?', NULL, array( $IdOrRow ) );
if ( ! $row ) { if ( ! $row ) {
Error("Unable to load Server record for Id=" . $IdOrRow ); Error("Unable to load Server record for Id=" . $IdOrRow );
}
} elseif ( is_array( $IdOrRow ) ) {
$row = $IdOrRow;
} else {
Error("Unknown argument passed to Monitor Constructor ($IdOrRow)");
return;
}
} # end if isset($IdOrRow)
if ( $row ) {
foreach ($row as $k => $v) {
$this->{$k} = $v;
}
if ( $this->{'Controllable'} ) {
$s = dbFetchOne( 'SELECT * FROM Controls WHERE Id=?', NULL, array( $this->{'ControlId'} ) );
foreach ($s as $k => $v) {
if ( $k == 'Id' ) {
continue;
} else if ( $k == 'Protocol' ) {
$this->{'ControlProtocol'} = $v;
} else if ( $k == 'Name' ) {
$this->{'ControlName'} = $v;
} else if ( $k == 'Type' ) {
$this->{'ControlType'} = $v;
} else {
$this->{$k} = $v;
}
}
}
} else {
Error("No row for Monitor " . $IdOrRow );
}
} // end function __construct
public function Server() {
return new Server( $this->{'ServerId'} );
}
public function __call( $fn, array $args){
if(isset($this->{$fn})){
return $this->{$fn};
#array_unshift($args, $this);
#call_user_func_array( $this->{$fn}, $args);
} }
} elseif ( is_array( $IdOrRow ) ) {
$row = $IdOrRow;
} else {
Error("Unknown argument passed to Monitor Constructor ($IdOrRow)");
return;
}
} # end if isset($IdOrRow)
if ( $row ) {
foreach ($row as $k => $v) {
$this->{$k} = $v;
}
if ( $this->{'Controllable'} ) {
$s = dbFetchOne( 'SELECT * FROM Controls WHERE Id=?', NULL, array( $this->{'ControlId'} ) );
foreach ($s as $k => $v) {
if ( $k == 'Id' ) {
continue;
# The reason for these is that the name overlaps Monitor fields.
} else if ( $k == 'Protocol' ) {
$this->{'ControlProtocol'} = $v;
} else if ( $k == 'Name' ) {
$this->{'ControlName'} = $v;
} else if ( $k == 'Type' ) {
$this->{'ControlType'} = $v;
} else {
$this->{$k} = $v;
}
}
}
} else {
Error("No row for Monitor " . $IdOrRow );
}
} // end function __construct
public function Server() {
return new Server( $this->{'ServerId'} );
}
public function __call( $fn, array $args){
if ( isset( $this->{$fn} ) ) {
return $this->{$fn};
#array_unshift($args, $this);
#call_user_func_array( $this->{$fn}, $args);
}
}
public function getStreamSrc( $args, $querySep='&' ) {
if ( isset($this->{'ServerId'}) and $this->{'ServerId'} ) {
$Server = new Server( $this->{'ServerId'} );
$streamSrc = ZM_BASE_PROTOCOL.'://'.$Server->Hostname().ZM_PATH_ZMS;
} else {
$streamSrc = ZM_BASE_URL.ZM_PATH_ZMS;
} }
public function getStreamSrc( $args, $querySep='&' ) {
if ( isset($this->{'ServerId'}) and $this->{'ServerId'} ) {
$Server = new Server( $this->{'ServerId'} );
$streamSrc = ZM_BASE_PROTOCOL.'://'.$Server->Hostname().ZM_PATH_ZMS;
} else {
$streamSrc = ZM_BASE_URL.ZM_PATH_ZMS;
}
$args[] = "monitor=".$this->{'Id'}; $args[] = "monitor=".$this->{'Id'};
if ( ZM_OPT_USE_AUTH ) { if ( ZM_OPT_USE_AUTH ) {
if ( ZM_AUTH_RELAY == "hashed" ) { if ( ZM_AUTH_RELAY == "hashed" ) {
$args[] = "auth=".generateAuthHash( ZM_AUTH_HASH_IPS ); $args[] = "auth=".generateAuthHash( ZM_AUTH_HASH_IPS );
} elseif ( ZM_AUTH_RELAY == "plain" ) { } elseif ( ZM_AUTH_RELAY == "plain" ) {
$args[] = "user=".$_SESSION['username']; $args[] = "user=".$_SESSION['username'];
$args[] = "pass=".$_SESSION['password']; $args[] = "pass=".$_SESSION['password'];
} elseif ( ZM_AUTH_RELAY == "none" ) { } elseif ( ZM_AUTH_RELAY == "none" ) {
$args[] = "user=".$_SESSION['username']; $args[] = "user=".$_SESSION['username'];
} }
} }
if ( !in_array( "mode=single", $args ) && !empty($GLOBALS['connkey']) ) { if ( !in_array( "mode=single", $args ) && !empty($GLOBALS['connkey']) ) {
$args[] = "connkey=".$GLOBALS['connkey']; $args[] = "connkey=".$GLOBALS['connkey'];
} }
if ( ZM_RAND_STREAM ) { if ( ZM_RAND_STREAM ) {
$args[] = "rand=".time(); $args[] = "rand=".time();
} }
if ( count($args) ) { if ( count($args) ) {
$streamSrc .= "?".join( $querySep, $args ); $streamSrc .= "?".join( $querySep, $args );
} }
return( $streamSrc ); return( $streamSrc );
} // end function getStreamSrc } // end function getStreamSrc
public function Width() { public function Width() {
if ( $this->Orientation() == '90' or $this->Orientation() == '270' ) { if ( $this->Orientation() == '90' or $this->Orientation() == '270' ) {
return $this->{'Height'}; return $this->{'Height'};
} }
return $this->{'Width'}; return $this->{'Width'};
} }
public function Height() { public function Height() {
if ( $this->Orientation() == '90' or $this->Orientation() == '270' ) { if ( $this->Orientation() == '90' or $this->Orientation() == '270' ) {
return $this->{'Width'}; return $this->{'Width'};
} }
return $this->{'Height'}; return $this->{'Height'};
} }
public function set( $data ) { public function set( $data ) {
foreach ($data as $k => $v) { foreach ($data as $k => $v) {
if ( is_array( $v ) ) { if ( is_array( $v ) ) {
# perhaps should turn into a comma-separated string # perhaps should turn into a comma-separated string
$this->{$k} = implode(',',$v); $this->{$k} = implode(',',$v);
} else if ( is_string( $v ) ) { } else if ( is_string( $v ) ) {
$this->{$k} = trim( $v ); $this->{$k} = trim( $v );
} else { } else {
Error( "Unknown type of var " . gettype( $v ) ); Error( "Unknown type of var " . gettype( $v ) );
$this->{$k} = $v; $this->{$k} = $v;
} }
} }
} }
} }
?> ?>

View File

@ -1,28 +1,28 @@
<?php <?php
require_once( 'database.php' ); require_once( 'database.php' );
class Server {
public function __construct( $IdOrRow = NULL ) { class Server {
$row = NULL; public function __construct( $IdOrRow = NULL ) {
if ( $IdOrRow ) { $row = NULL;
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) { if ( $IdOrRow ) {
$row = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $IdOrRow ) ); if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
if ( ! $row ) { $row = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $IdOrRow ) );
Error("Unable to load Server record for Id=" . $IdOrRow ); if ( ! $row ) {
} Error("Unable to load Server record for Id=" . $IdOrRow );
} elseif ( is_array( $IdOrRow ) ) { }
$row = $IdOrRow; } elseif ( is_array( $IdOrRow ) ) {
} $row = $IdOrRow;
} # end if isset($IdOrRow) }
if ( $row ) { } # end if isset($IdOrRow)
foreach ($row as $k => $v) { if ( $row ) {
$this->{$k} = $v; foreach ($row as $k => $v) {
} $this->{$k} = $v;
} else { }
$this->{'Name'} = ''; } else {
$this->{'Hostname'} = ''; $this->{'Name'} = '';
} $this->{'Hostname'} = '';
} }
}
public static function find_all() { public static function find_all() {
$servers = array(); $servers = array();
$result = dbQuery( 'SELECT * FROM Servers ORDER BY Name'); $result = dbQuery( 'SELECT * FROM Servers ORDER BY Name');
@ -47,11 +47,11 @@ class Server {
return $this->{'Name'}; return $this->{'Name'};
} }
public function __call( $fn, array $args= NULL){ public function __call( $fn, array $args= NULL){
if(isset($this->{$fn})){ if(isset($this->{$fn})){
return $this->{$fn}; return $this->{$fn};
#array_unshift($args, $this); #array_unshift($args, $this);
#call_user_func_array( $this->{$fn}, $args); #call_user_func_array( $this->{$fn}, $args);
}
} }
}
} }
?> ?>