make find and find_one functions consistent across Objects
This commit is contained in:
parent
fa690826a3
commit
dfdac2ed70
|
@ -93,7 +93,7 @@ Info("Testing connection to " . $url_bits['host'].':'.$port);
|
|||
foreach ( $available_streams as &$stream ) {
|
||||
# check for existence in db.
|
||||
$stream['url'] = unparse_url( $stream, array('path'=>'/','query'=>'action=stream') );
|
||||
$monitors = Monitor::find_all( array('Path'=>$stream['url']) );
|
||||
$monitors = Monitor::find( array('Path'=>$stream['url']) );
|
||||
if ( count($monitors) ) {
|
||||
Info("Found monitors matching " . $stream['url'] );
|
||||
$stream['Monitor'] = $monitors[0];
|
||||
|
@ -135,7 +135,7 @@ if ( canEdit( 'Monitors' ) ) {
|
|||
|
||||
if ( 0 ) {
|
||||
// Shortcut test
|
||||
$monitors = Monitor::find_all( array( 'Path'=>$_REQUEST['url'] ) );
|
||||
$monitors = Monitor::find( array('Path'=>$_REQUEST['url']) );
|
||||
if ( count( $monitors ) ) {
|
||||
Info("Monitor found for " . $_REQUEST['url']);
|
||||
$url_bits['url'] = $_REQUEST['url'];
|
||||
|
|
|
@ -33,7 +33,7 @@ switch ( $_REQUEST['task'] ) {
|
|||
if ( !canView('System') )
|
||||
ajaxError('Insufficient permissions to view log entries');
|
||||
|
||||
$servers = Server::find_all();
|
||||
$servers = Server::find();
|
||||
$servers_by_Id = array();
|
||||
# There is probably a better way to do this.
|
||||
foreach ( $servers as $server ) {
|
||||
|
@ -153,7 +153,7 @@ switch ( $_REQUEST['task'] ) {
|
|||
}
|
||||
$sortOrder = (isset($_POST['sortOrder']) and $_POST['sortOrder']) == 'asc' ? 'asc':'desc';
|
||||
|
||||
$servers = Server::find_all();
|
||||
$servers = Server::find();
|
||||
$servers_by_Id = array();
|
||||
# There is probably a better way to do this.
|
||||
foreach ( $servers as $server ) {
|
||||
|
|
|
@ -166,8 +166,7 @@ private $defaults = array(
|
|||
}
|
||||
}
|
||||
}
|
||||
public static function find_all( $parameters = null, $options = null ) {
|
||||
$filters = array();
|
||||
public static function find( $parameters = null, $options = null ) {
|
||||
$sql = 'SELECT * FROM Controls ';
|
||||
$values = array();
|
||||
|
||||
|
@ -189,15 +188,37 @@ private $defaults = array(
|
|||
}
|
||||
$sql .= implode(' AND ', $fields );
|
||||
}
|
||||
if ( $options and isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
if ( $options ) {
|
||||
if ( isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
if ( isset($options['limit']) ) {
|
||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Control::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$controls = array();
|
||||
$result = dbQuery($sql, $values);
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Control');
|
||||
foreach ( $results as $row => $obj ) {
|
||||
$filters[] = $obj;
|
||||
$controls[] = $obj;
|
||||
}
|
||||
return $filters;
|
||||
return $controls;
|
||||
}
|
||||
|
||||
public static function find_one( $parameters = array() ) {
|
||||
$results = Control::find( $parameters, array('limit'=>1) );
|
||||
if ( ! sizeof($results) ) {
|
||||
return;
|
||||
}
|
||||
return $results[0];
|
||||
}
|
||||
|
||||
public function save( $new_values = null ) {
|
||||
|
|
|
@ -486,7 +486,7 @@ class Event {
|
|||
isset($event_cache[$parameters['Id']]) ) {
|
||||
return $event_cache[$parameters['Id']];
|
||||
}
|
||||
$results = Event::find_all( $parameters, $options );
|
||||
$results = Event::find( $parameters, $options );
|
||||
if ( count($results) > 1 ) {
|
||||
Error("Event Returned more than 1");
|
||||
return $results[0];
|
||||
|
@ -497,7 +497,7 @@ class Event {
|
|||
}
|
||||
}
|
||||
|
||||
public static function find_all( $parameters = null, $options = null ) {
|
||||
public static function find( $parameters = null, $options = null ) {
|
||||
$filters = array();
|
||||
$sql = 'SELECT * FROM Events ';
|
||||
$values = array();
|
||||
|
@ -520,8 +520,21 @@ class Event {
|
|||
}
|
||||
$sql .= implode(' AND ', $fields );
|
||||
}
|
||||
if ( $options and isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
if ( $options ) {
|
||||
if ( isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
if ( isset($options['limit']) ) {
|
||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Event::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = dbQuery($sql, $values);
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Event');
|
||||
|
|
|
@ -26,12 +26,12 @@ public $defaults = array(
|
|||
public function __construct( $IdOrRow=NULL ) {
|
||||
$row = NULL;
|
||||
if ( $IdOrRow ) {
|
||||
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
|
||||
$row = dbFetchOne( 'SELECT * FROM Filters WHERE Id=?', NULL, array( $IdOrRow ) );
|
||||
if ( is_integer($IdOrRow) or is_numeric($IdOrRow) ) {
|
||||
$row = dbFetchOne('SELECT * FROM Filters WHERE Id=?', NULL, array($IdOrRow));
|
||||
if ( ! $row ) {
|
||||
Error('Unable to load Filter record for Id=' . $IdOrRow );
|
||||
Error('Unable to load Filter record for Id=' . $IdOrRow);
|
||||
}
|
||||
} elseif ( is_array( $IdOrRow ) ) {
|
||||
} elseif ( is_array($IdOrRow) ) {
|
||||
$row = $IdOrRow;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
|
@ -47,8 +47,8 @@ public $defaults = array(
|
|||
foreach ($row as $k => $v) {
|
||||
$this->{$k} = $v;
|
||||
}
|
||||
if ( array_key_exists( 'Query', $this ) and $this->{'Query'} ) {
|
||||
$this->{'Query'} = jsonDecode( $this->{'Query'} );
|
||||
if ( array_key_exists('Query', $this) and $this->{'Query'} ) {
|
||||
$this->{'Query'} = jsonDecode($this->{'Query'});
|
||||
} else {
|
||||
$this->{'Query'} = array();
|
||||
}
|
||||
|
@ -111,18 +111,62 @@ public $defaults = array(
|
|||
return $this->defaults{'limit'};
|
||||
}
|
||||
|
||||
public static function find_all() {
|
||||
public static function find( $parameters = null, $options = null ) {
|
||||
$filters = array();
|
||||
$result = dbQuery( 'SELECT * FROM Filters ORDER BY Name');
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Filter' );
|
||||
$sql = 'SELECT * FROM Filters ';
|
||||
$values = array();
|
||||
|
||||
if ( $parameters ) {
|
||||
$fields = array();
|
||||
$sql .= 'WHERE ';
|
||||
foreach ( $parameters as $field => $value ) {
|
||||
if ( $value == null ) {
|
||||
$fields[] = $field.' IS NULL';
|
||||
} else if ( is_array( $value ) ) {
|
||||
$func = function(){return '?';};
|
||||
$fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')';
|
||||
$values += $value;
|
||||
} else {
|
||||
$fields[] = $field.'=?';
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
$sql .= implode(' AND ', $fields);
|
||||
}
|
||||
if ( $options ) {
|
||||
if ( isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
if ( isset($options['limit']) ) {
|
||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Filter::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$result = dbQuery($sql, $values);
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Filter');
|
||||
foreach ( $results as $row => $obj ) {
|
||||
$filters[] = $obj;
|
||||
}
|
||||
return $filters;
|
||||
}
|
||||
} # end find()
|
||||
|
||||
public static function find_one( $parameters = array() ) {
|
||||
$results = Filter::find($parameters, array('limit'=>1));
|
||||
if ( ! sizeof($results) ) {
|
||||
return;
|
||||
}
|
||||
return $results[0];
|
||||
} # end find_one()
|
||||
|
||||
public function delete() {
|
||||
dbQuery( 'DELETE FROM Filters WHERE Id = ?', array($this->{'Id'}) );
|
||||
dbQuery('DELETE FROM Filters WHERE Id = ?', array($this->{'Id'}));
|
||||
} # end function delete()
|
||||
|
||||
public function set( $data ) {
|
||||
|
@ -141,8 +185,6 @@ public $defaults = array(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} # end class
|
||||
|
||||
?>
|
||||
|
|
|
@ -58,27 +58,7 @@ class Group {
|
|||
}
|
||||
}
|
||||
|
||||
public static function find_one($parameters = null, $options = null) {
|
||||
global $group_cache;
|
||||
if (
|
||||
( count($parameters) == 1 ) and
|
||||
isset($parameters['Id']) and
|
||||
isset($group_cache[$parameters['Id']]) ) {
|
||||
return $group_cache[$parameters['Id']];
|
||||
}
|
||||
$results = Group::find_all($parameters, $options);
|
||||
if ( count($results) > 1 ) {
|
||||
Error("Group::find_one Returned more than 1");
|
||||
return $results[0];
|
||||
} else if ( count($results) ) {
|
||||
return $results[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function find_all( $parameters = null ) {
|
||||
$filters = array();
|
||||
public static function find( $parameters = null, $options = null ) {
|
||||
$sql = 'SELECT * FROM Groups ';
|
||||
$values = array();
|
||||
|
||||
|
@ -90,22 +70,57 @@ class Group {
|
|||
$fields[] = $field.' IS NULL';
|
||||
} else if ( is_array( $value ) ) {
|
||||
$func = function(){return '?';};
|
||||
$fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')';
|
||||
$fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')';
|
||||
$values += $value;
|
||||
} else {
|
||||
$fields[] = $field.'=?';
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
$sql .= implode(' AND ', $fields );
|
||||
}
|
||||
$sql .= ' ORDER BY Name';
|
||||
$sql .= implode(' AND ', $fields);
|
||||
} # end if parameters
|
||||
if ( $options ) {
|
||||
if ( isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
if ( isset($options['limit']) ) {
|
||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Group::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} # end if options
|
||||
$groups = array();
|
||||
$result = dbQuery($sql, $values);
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Group');
|
||||
foreach ( $results as $row => $obj ) {
|
||||
$filters[] = $obj;
|
||||
$groups[] = $obj;
|
||||
}
|
||||
return $groups;
|
||||
} # end find()
|
||||
|
||||
public static function find_one($parameters = null, $options = null) {
|
||||
global $group_cache;
|
||||
if (
|
||||
( count($parameters) == 1 ) and
|
||||
isset($parameters['Id']) and
|
||||
isset($group_cache[$parameters['Id']]) ) {
|
||||
return $group_cache[$parameters['Id']];
|
||||
}
|
||||
$results = Group::find($parameters, $options);
|
||||
if ( count($results) > 1 ) {
|
||||
Error("Group::find_one Returned more than 1");
|
||||
return $results[0];
|
||||
} else if ( count($results) ) {
|
||||
return $results[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return $filters;
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
|
@ -182,7 +197,7 @@ class Group {
|
|||
|
||||
public static function get_dropdown_options() {
|
||||
$Groups = array();
|
||||
foreach ( Group::find_all( ) as $Group ) {
|
||||
foreach ( Group::find( ) as $Group ) {
|
||||
$Groups[$Group->Id()] = $Group;
|
||||
}
|
||||
|
||||
|
|
|
@ -278,8 +278,7 @@ private $control_fields = array(
|
|||
} # end if method_exists
|
||||
} # end foreach $data as $k=>$v
|
||||
}
|
||||
public static function find_all( $parameters = null, $options = null ) {
|
||||
$filters = array();
|
||||
public static function find( $parameters = null, $options = null ) {
|
||||
$sql = 'SELECT * FROM Monitors ';
|
||||
$values = array();
|
||||
|
||||
|
@ -289,9 +288,9 @@ private $control_fields = array(
|
|||
foreach ( $parameters as $field => $value ) {
|
||||
if ( $value == null ) {
|
||||
$fields[] = $field.' IS NULL';
|
||||
} else if ( is_array( $value ) ) {
|
||||
} else if ( is_array($value) ) {
|
||||
$func = function(){return '?';};
|
||||
$fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')';
|
||||
$fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')';
|
||||
$values += $value;
|
||||
|
||||
} else {
|
||||
|
@ -299,18 +298,40 @@ private $control_fields = array(
|
|||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
$sql .= implode(' AND ', $fields );
|
||||
$sql .= implode(' AND ', $fields);
|
||||
}
|
||||
if ( $options and isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
if ( $options ) {
|
||||
if ( isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
if ( isset($options['limit']) ) {
|
||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Control::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$monitors = array();
|
||||
$result = dbQuery($sql, $values);
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Monitor');
|
||||
foreach ( $results as $row => $obj ) {
|
||||
$filters[] = $obj;
|
||||
$monitors[] = $obj;
|
||||
}
|
||||
return $filters;
|
||||
}
|
||||
return $monitors;
|
||||
} # end find
|
||||
|
||||
public static function find_one( $parameters = array() ) {
|
||||
$results = Monitor::find( $parameters, array('limit'=>1) );
|
||||
if ( ! sizeof($results) ) {
|
||||
return;
|
||||
}
|
||||
return $results[0];
|
||||
} # end find_one
|
||||
|
||||
public function save($new_values = null) {
|
||||
|
||||
|
@ -509,5 +530,7 @@ private $control_fields = array(
|
|||
}
|
||||
return $source;
|
||||
} // end function Source
|
||||
|
||||
|
||||
} // end class Monitor
|
||||
?>
|
||||
|
|
|
@ -13,12 +13,12 @@ class Server {
|
|||
public function __construct( $IdOrRow = NULL ) {
|
||||
$row = NULL;
|
||||
if ( $IdOrRow ) {
|
||||
if ( is_integer( $IdOrRow ) or ctype_digit( $IdOrRow ) ) {
|
||||
$row = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $IdOrRow ) );
|
||||
if ( ! $row ) {
|
||||
Error("Unable to load Server record for Id=" . $IdOrRow );
|
||||
if ( is_integer($IdOrRow) or ctype_digit($IdOrRow) ) {
|
||||
$row = dbFetchOne('SELECT * FROM Servers WHERE Id=?', NULL, array($IdOrRow));
|
||||
if ( !$row ) {
|
||||
Error("Unable to load Server record for Id=" . $IdOrRow);
|
||||
}
|
||||
} elseif ( is_array( $IdOrRow ) ) {
|
||||
} elseif ( is_array($IdOrRow) ) {
|
||||
$row = $IdOrRow;
|
||||
}
|
||||
} # end if isset($IdOrRow)
|
||||
|
@ -31,39 +31,6 @@ class Server {
|
|||
$this->{'Hostname'} = '';
|
||||
}
|
||||
}
|
||||
public static function find_all( $parameters = null, $options = null ) {
|
||||
$filters = array();
|
||||
$sql = 'SELECT * FROM Servers ';
|
||||
$values = array();
|
||||
|
||||
if ( $parameters ) {
|
||||
$fields = array();
|
||||
$sql .= 'WHERE ';
|
||||
foreach ( $parameters as $field => $value ) {
|
||||
if ( $value == null ) {
|
||||
$fields[] = $field.' IS NULL';
|
||||
} else if ( is_array( $value ) ) {
|
||||
$func = function(){return '?';};
|
||||
$fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')';
|
||||
$values += $value;
|
||||
|
||||
} else {
|
||||
$fields[] = $field.'=?';
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
$sql .= implode(' AND ', $fields );
|
||||
}
|
||||
if ( $options and isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
$result = dbQuery($sql, $values);
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server');
|
||||
foreach ( $results as $row => $obj ) {
|
||||
$filters[] = $obj;
|
||||
}
|
||||
return $filters;
|
||||
}
|
||||
|
||||
public function Url() {
|
||||
if ( $this->Id() ) {
|
||||
|
@ -96,26 +63,45 @@ class Server {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function find( $parameters = array(), $limit = NULL ) {
|
||||
$sql = 'SELECT * FROM Servers';
|
||||
public static function find( $parameters = null, $options = null ) {
|
||||
$filters = array();
|
||||
$sql = 'SELECT * FROM Servers ';
|
||||
$values = array();
|
||||
if ( sizeof($parameters) ) {
|
||||
$sql .= ' WHERE ' . implode( ' AND ', array_map(
|
||||
function($v){ return $v.'=?'; },
|
||||
array_keys( $parameters )
|
||||
) );
|
||||
$values = array_values( $parameters );
|
||||
|
||||
if ( $parameters ) {
|
||||
$fields = array();
|
||||
$sql .= 'WHERE ';
|
||||
foreach ( $parameters as $field => $value ) {
|
||||
if ( $value == null ) {
|
||||
$fields[] = $field.' IS NULL';
|
||||
} else if ( is_array( $value ) ) {
|
||||
$func = function(){return '?';};
|
||||
$fields[] = $field.' IN ('.implode(',', array_map( $func, $value ) ). ')';
|
||||
$values += $value;
|
||||
|
||||
} else {
|
||||
$fields[] = $field.'=?';
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
$sql .= implode(' AND ', $fields );
|
||||
}
|
||||
if ( $options ) {
|
||||
if ( isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
if ( isset($options['limit']) ) {
|
||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Server::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( is_integer( $limit ) or ctype_digit( $limit ) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Server::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
$results = dbFetchAll( $sql, NULL, $values );
|
||||
if ( $results ) {
|
||||
return array_map( function($id){ return new Server($id); }, $results );
|
||||
|
@ -123,8 +109,8 @@ class Server {
|
|||
}
|
||||
|
||||
public static function find_one( $parameters = array() ) {
|
||||
$results = Server::find( $parameters, 1 );
|
||||
if ( ! sizeof( $results ) ) {
|
||||
$results = Server::find( $parameters, array('limit'=>1) );
|
||||
if ( ! sizeof($results) ) {
|
||||
return;
|
||||
}
|
||||
return $results[0];
|
||||
|
|
|
@ -40,7 +40,6 @@ class Storage {
|
|||
$this->{'Path'} = ZM_DIR_EVENTS;
|
||||
}
|
||||
return $this->{'Path'};
|
||||
|
||||
}
|
||||
return $this->{'Name'};
|
||||
}
|
||||
|
@ -53,19 +52,19 @@ class Storage {
|
|||
return $this->{'Name'};
|
||||
}
|
||||
|
||||
public function __call( $fn, array $args= NULL){
|
||||
if ( count( $args ) ) {
|
||||
public function __call( $fn, array $args= NULL ) {
|
||||
if ( count($args) ) {
|
||||
$this->{$fn} = $args[0];
|
||||
}
|
||||
if ( array_key_exists( $fn, $this ) ) {
|
||||
if ( array_key_exists($fn, $this) )
|
||||
return $this->{$fn};
|
||||
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Warning( "Unknown function call Storage->$fn from $file:$line" );
|
||||
}
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Warning("Unknown function call Storage->$fn from $file:$line");
|
||||
}
|
||||
|
||||
public static function find_one( $parameters = null, $options = null ) {
|
||||
global $storage_cache;
|
||||
if (
|
||||
|
@ -74,7 +73,7 @@ class Storage {
|
|||
isset($storage_cache[$parameters['Id']]) ) {
|
||||
return $storage_cache[$parameters['Id']];
|
||||
}
|
||||
$results = Storage::find_all( $parameters, $options );
|
||||
$results = Storage::find($parameters, $options);
|
||||
if ( count($results) > 1 ) {
|
||||
Error("Storage Returned more than 1");
|
||||
return $results[0];
|
||||
|
@ -84,8 +83,7 @@ class Storage {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
public static function find_all( $parameters = null, $options = null ) {
|
||||
$filters = array();
|
||||
public static function find( $parameters = null, $options = null ) {
|
||||
$sql = 'SELECT * FROM Storage ';
|
||||
$values = array();
|
||||
|
||||
|
@ -95,7 +93,7 @@ class Storage {
|
|||
foreach ( $parameters as $field => $value ) {
|
||||
if ( $value == null ) {
|
||||
$fields[] = $field.' IS NULL';
|
||||
} else if ( is_array( $value ) ) {
|
||||
} else if ( is_array($value) ) {
|
||||
$func = function(){return '?';};
|
||||
$fields[] = $field.' IN ('.implode(',', array_map($func, $value)). ')';
|
||||
$values += $value;
|
||||
|
@ -106,32 +104,47 @@ class Storage {
|
|||
}
|
||||
}
|
||||
$sql .= implode(' AND ', $fields);
|
||||
}
|
||||
if ( $options and isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
}
|
||||
} # end if parameters
|
||||
if ( $options ) {
|
||||
if ( isset($options['order']) ) {
|
||||
$sql .= ' ORDER BY ' . $options['order'];
|
||||
} # end if options
|
||||
if ( isset($options['limit']) ) {
|
||||
if ( is_integer($options['limit']) or ctype_digit($options['limit']) ) {
|
||||
$sql .= ' LIMIT ' . $limit;
|
||||
} else {
|
||||
$backTrace = debug_backtrace();
|
||||
$file = $backTrace[1]['file'];
|
||||
$line = $backTrace[1]['line'];
|
||||
Error("Invalid value for limit($limit) passed to Control::find from $file:$line");
|
||||
return;
|
||||
}
|
||||
} # end if limit
|
||||
} # end if options
|
||||
$storage_areas = array();
|
||||
$result = dbQuery($sql, $values);
|
||||
if ( $result ) {
|
||||
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Storage');
|
||||
foreach ( $results as $row => $obj ) {
|
||||
$filters[] = $obj;
|
||||
$storage_areas[] = $obj;
|
||||
}
|
||||
}
|
||||
return $filters;
|
||||
}
|
||||
return $storage_areas;
|
||||
} # end find()
|
||||
|
||||
public function disk_usage_percent() {
|
||||
$path = $this->Path();
|
||||
if ( ! $path ) {
|
||||
Warning("Storage::disk_usage_percent: path is empty");
|
||||
Warning('Storage::disk_usage_percent: path is empty');
|
||||
return 0;
|
||||
} else if ( ! file_exists( $path ) ) {
|
||||
} else if ( ! file_exists($path) ) {
|
||||
Warning("Storage::disk_usage_percent: path $path does not exist");
|
||||
return 0;
|
||||
}
|
||||
|
||||
$total = $this->disk_total_space();
|
||||
if ( ! $total ) {
|
||||
Error("disk_total_space returned false for " . $path );
|
||||
Error('disk_total_space returned false for ' . $path );
|
||||
return 0;
|
||||
}
|
||||
$used = $this->disk_used_space();
|
||||
|
@ -139,6 +152,7 @@ class Storage {
|
|||
//Logger::Debug("Used $usage = round( ( $used / $total ) * 100 )");
|
||||
return $usage;
|
||||
}
|
||||
|
||||
public function disk_total_space() {
|
||||
if ( !array_key_exists('disk_total_space', $this) ) {
|
||||
$path = $this->Path();
|
||||
|
@ -175,8 +189,8 @@ class Storage {
|
|||
if ( (! array_key_exists('DiskSpace', $this)) or (!$this->{'DiskSpace'}) ) {
|
||||
$used = dbFetchOne('SELECT SUM(DiskSpace) AS DiskSpace FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL', 'DiskSpace', array($this->Id()) );
|
||||
|
||||
foreach ( Event::find_all( array('StorageId'=>$this->Id(), 'DiskSpace'=>null) ) as $Event ) {
|
||||
$Event->Storage( $this ); // Prevent further db hit
|
||||
foreach ( Event::find(array('StorageId'=>$this->Id(), 'DiskSpace'=>null)) as $Event ) {
|
||||
$Event->Storage($this); // Prevent further db hit
|
||||
$used += $Event->DiskSpace();
|
||||
}
|
||||
$this->{'DiskSpace'} = $used;
|
||||
|
|
|
@ -329,7 +329,7 @@ if ($reload == 'reload') ob_start();
|
|||
?>
|
||||
<li><?php echo translate('Storage') ?>:
|
||||
<?php
|
||||
$storage_areas = Storage::find_all();
|
||||
$storage_areas = Storage::find();
|
||||
$storage_paths = null;
|
||||
foreach ( $storage_areas as $area ) {
|
||||
$storage_paths[$area->Path()] = $area;
|
||||
|
@ -350,7 +350,7 @@ if ($reload == 'reload') ob_start();
|
|||
return '<span class="'.$class.'" title="'.$title.'">'.$S->Name() . ': ' . $S->disk_usage_percent().'%' . '</span>'; };
|
||||
#$func = function($S){ return '<span title="">'.$S->Name() . ': ' . $S->disk_usage_percent().'%' . '</span>'; };
|
||||
if ( count($storage_areas) >= 4 )
|
||||
$storage_areas = Storage::find_all( array('ServerId'=>null) );
|
||||
$storage_areas = Storage::find( array('ServerId'=>null) );
|
||||
if ( count($storage_areas) < 4 )
|
||||
echo implode( ', ', array_map ( $func, $storage_areas ) );
|
||||
echo ' ' . ZM_PATH_MAP .': '. getDiskPercent(ZM_PATH_MAP).'%';
|
||||
|
|
|
@ -18,26 +18,26 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
$servers = Server::find_all(null, array('order'=>'lower(Name)'));
|
||||
$servers = Server::find(null, array('order'=>'lower(Name)'));
|
||||
$ServersById = array();
|
||||
foreach ( $servers as $S ) {
|
||||
$ServersById[$S->Id()] = $S;
|
||||
}
|
||||
session_start();
|
||||
foreach ( array('Group','Function','ServerId','StorageId','Status','MonitorId','MonitorName','Source') as $var ) {
|
||||
if ( isset( $_REQUEST[$var] ) ) {
|
||||
if ( isset($_REQUEST[$var]) ) {
|
||||
if ( $_REQUEST[$var] != '' ) {
|
||||
$_SESSION[$var] = $_REQUEST[$var];
|
||||
} else {
|
||||
unset( $_SESSION[$var] );
|
||||
unset($_SESSION[$var]);
|
||||
}
|
||||
} else if ( isset( $_REQUEST['filtering'] ) ) {
|
||||
unset( $_SESSION[$var] );
|
||||
} else if ( isset($_REQUEST['filtering']) ) {
|
||||
unset($_SESSION[$var]);
|
||||
}
|
||||
}
|
||||
session_write_close();
|
||||
|
||||
$storage_areas = Storage::find_all();
|
||||
$storage_areas = Storage::find();
|
||||
$StorageById = array();
|
||||
foreach ( $storage_areas as $S ) {
|
||||
$StorageById[$S->Id()] = $S;
|
||||
|
@ -50,7 +50,7 @@ $html =
|
|||
';
|
||||
|
||||
$GroupsById = array();
|
||||
foreach ( Group::find_all() as $G ) {
|
||||
foreach ( Group::find() as $G ) {
|
||||
$GroupsById[$G->Id()] = $G;
|
||||
}
|
||||
|
||||
|
@ -78,17 +78,17 @@ if ( $groupSql )
|
|||
foreach ( array('ServerId','StorageId','Status','Function') as $filter ) {
|
||||
if ( isset($_SESSION[$filter]) ) {
|
||||
if ( is_array($_SESSION[$filter]) ) {
|
||||
$conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter] ) ). ')';
|
||||
$values = array_merge( $values, $_SESSION[$filter] );
|
||||
$conditions[] = $filter . ' IN ('.implode(',', array_map(function(){return '?';}, $_SESSION[$filter])). ')';
|
||||
$values = array_merge($values, $_SESSION[$filter]);
|
||||
} else {
|
||||
$conditions[] = $filter . '=?';
|
||||
$values[] = $_SESSION[$filter];
|
||||
}
|
||||
}
|
||||
} # end foreach filter
|
||||
if ( ! empty( $user['MonitorIds'] ) ) {
|
||||
$ids = explode(',', $user['MonitorIds'] );
|
||||
$conditions[] = 'M.Id IN ('.implode(',',array_map( function(){return '?';}, $ids) ).')';
|
||||
if ( ! empty($user['MonitorIds']) ) {
|
||||
$ids = explode(',', $user['MonitorIds']);
|
||||
$conditions[] = 'M.Id IN ('.implode(',',array_map(function(){return '?';}, $ids)).')';
|
||||
$values += $ids;
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ $html .= '</span>';
|
|||
|
||||
if ( count($ServersById) > 1 ) {
|
||||
$html .= '<span class="ServerFilter"><label>'. translate('Server').':</label>';
|
||||
$html .= htmlSelect( 'ServerId[]', $ServersById,
|
||||
$html .= htmlSelect('ServerId[]', $ServersById,
|
||||
(isset($_SESSION['ServerId'])?$_SESSION['ServerId']:''),
|
||||
array(
|
||||
'onchange'=>'this.form.submit();',
|
||||
|
@ -129,7 +129,7 @@ if ( count($ServersById) > 1 ) {
|
|||
|
||||
if ( count($StorageById) > 1 ) {
|
||||
$html .= '<span class="StorageFilter"><label>'.translate('Storage').':</label>';
|
||||
$html .= htmlSelect( 'StorageId[]',$StorageById,
|
||||
$html .= htmlSelect('StorageId[]', $StorageById,
|
||||
(isset($_SESSION['StorageId'])?$_SESSION['StorageId']:''),
|
||||
array(
|
||||
'onchange'=>'this.form.submit();',
|
||||
|
|
|
@ -44,11 +44,11 @@ xhtmlHeaders(__FILE__, translate('AddMonitors'));
|
|||
</div>
|
||||
<div style="width:50%;position: absolute; top:0; left: 0;height: 100%;">
|
||||
<fieldset><legend>Enter by IP or URL</legend>
|
||||
<p>
|
||||
Simply enter the ip address or full url to the stream.
|
||||
It will be probed for available streams, or checked to see if it has already been entered.
|
||||
If streams are found, they will be listed in the results column. Click Add to add them.
|
||||
</p>
|
||||
<p>
|
||||
Simply enter the ip address or full url to the stream.
|
||||
It will be probed for available streams, or checked to see if it has already been entered.
|
||||
If streams are found, they will be listed in the results column. Click Add to add them.
|
||||
</p>
|
||||
<!--<input type="text" name="newMonitor[Name]" />-->
|
||||
<input type="text" name="newMonitor[Url]" oninput="probe(this);"/>
|
||||
</fieldset>
|
||||
|
@ -80,7 +80,7 @@ If streams are found, they will be listed in the results column. Click Add to ad
|
|||
?>
|
||||
</td></tr>
|
||||
<?php
|
||||
$servers = Server::find_all();
|
||||
$servers = Server::find();
|
||||
$ServersById = array();
|
||||
foreach ( $servers as $S ) {
|
||||
$ServersById[$S->Id()] = $S;
|
||||
|
@ -92,7 +92,7 @@ If streams are found, they will be listed in the results column. Click Add to ad
|
|||
</td></tr>
|
||||
<?php
|
||||
}
|
||||
$storage_areas = Storage::find_all();
|
||||
$storage_areas = Storage::find();
|
||||
$StorageById = array();
|
||||
foreach ( $storage_areas as $S ) {
|
||||
$StorageById[$S->Id()] = $S;
|
||||
|
|
|
@ -83,7 +83,7 @@ if ( $_POST ) {
|
|||
exit();
|
||||
}
|
||||
|
||||
$storage_areas = Storage::find_all();
|
||||
$storage_areas = Storage::find();
|
||||
$StorageById = array();
|
||||
foreach ( $storage_areas as $S ) {
|
||||
$StorageById[$S->Id()] = $S;
|
||||
|
@ -94,7 +94,7 @@ xhtmlHeaders(__FILE__, translate('Events') );
|
|||
?>
|
||||
<body>
|
||||
<div id="page">
|
||||
<?php echo getNavBarHTML() ?>
|
||||
<?php echo getNavBarHTML() ?>
|
||||
<div id="header">
|
||||
<div id="info">
|
||||
<h2><?php echo sprintf($CLANG['EventCount'], $nEvents, zmVlang($VLANG['Event'], $nEvents)) ?></h2>
|
||||
|
@ -153,17 +153,17 @@ while ( $event_row = dbFetchNext($results) ) {
|
|||
if ( ($count++%ZM_WEB_EVENTS_PER_PAGE) == 0 ) {
|
||||
?>
|
||||
<tr>
|
||||
<th class="colId"><a href="<?php echo sortHeader( 'Id' ) ?>"><?php echo translate('Id') ?><?php echo sortTag( 'Id' ) ?></a></th>
|
||||
<th class="colName"><a href="<?php echo sortHeader( 'Name' ) ?>"><?php echo translate('Name') ?><?php echo sortTag( 'Name' ) ?></a></th>
|
||||
<th class="colMonitor"><a href="<?php echo sortHeader( 'MonitorName' ) ?>"><?php echo translate('Monitor') ?><?php echo sortTag( 'MonitorName' ) ?></a></th>
|
||||
<th class="colCause"><a href="<?php echo sortHeader( 'Cause' ) ?>"><?php echo translate('Cause') ?><?php echo sortTag( 'Cause' ) ?></a></th>
|
||||
<th class="colTime"><a href="<?php echo sortHeader( 'StartTime' ) ?>"><?php echo translate('Time') ?><?php echo sortTag( 'StartTime' ) ?></a></th>
|
||||
<th class="colDuration"><a href="<?php echo sortHeader( 'Length' ) ?>"><?php echo translate('Duration') ?><?php echo sortTag( 'Length' ) ?></a></th>
|
||||
<th class="colFrames"><a href="<?php echo sortHeader( 'Frames' ) ?>"><?php echo translate('Frames') ?><?php echo sortTag( 'Frames' ) ?></a></th>
|
||||
<th class="colAlarmFrames"><a href="<?php echo sortHeader( 'AlarmFrames' ) ?>"><?php echo translate('AlarmBrFrames') ?><?php echo sortTag( 'AlarmFrames' ) ?></a></th>
|
||||
<th class="colTotScore"><a href="<?php echo sortHeader( 'TotScore' ) ?>"><?php echo translate('TotalBrScore') ?><?php echo sortTag( 'TotScore' ) ?></a></th>
|
||||
<th class="colAvgScore"><a href="<?php echo sortHeader( 'AvgScore' ) ?>"><?php echo translate('AvgBrScore') ?><?php echo sortTag( 'AvgScore' ) ?></a></th>
|
||||
<th class="colMaxScore"><a href="<?php echo sortHeader( 'MaxScore' ) ?>"><?php echo translate('MaxBrScore') ?><?php echo sortTag( 'MaxScore' ) ?></a></th>
|
||||
<th class="colId"><a href="<?php echo sortHeader('Id') ?>"><?php echo translate('Id') ?><?php echo sortTag('Id') ?></a></th>
|
||||
<th class="colName"><a href="<?php echo sortHeader('Name') ?>"><?php echo translate('Name') ?><?php echo sortTag('Name') ?></a></th>
|
||||
<th class="colMonitor"><a href="<?php echo sortHeader('MonitorName') ?>"><?php echo translate('Monitor') ?><?php echo sortTag('MonitorName') ?></a></th>
|
||||
<th class="colCause"><a href="<?php echo sortHeader('Cause') ?>"><?php echo translate('Cause') ?><?php echo sortTag('Cause') ?></a></th>
|
||||
<th class="colTime"><a href="<?php echo sortHeader('StartTime') ?>"><?php echo translate('Time') ?><?php echo sortTag('StartTime') ?></a></th>
|
||||
<th class="colDuration"><a href="<?php echo sortHeader('Length') ?>"><?php echo translate('Duration') ?><?php echo sortTag('Length') ?></a></th>
|
||||
<th class="colFrames"><a href="<?php echo sortHeader('Frames') ?>"><?php echo translate('Frames') ?><?php echo sortTag('Frames') ?></a></th>
|
||||
<th class="colAlarmFrames"><a href="<?php echo sortHeader('AlarmFrames') ?>"><?php echo translate('AlarmBrFrames') ?><?php echo sortTag('AlarmFrames') ?></a></th>
|
||||
<th class="colTotScore"><a href="<?php echo sortHeader('TotScore') ?>"><?php echo translate('TotalBrScore') ?><?php echo sortTag('TotScore') ?></a></th>
|
||||
<th class="colAvgScore"><a href="<?php echo sortHeader('AvgScore') ?>"><?php echo translate('AvgBrScore') ?><?php echo sortTag('AvgScore') ?></a></th>
|
||||
<th class="colMaxScore"><a href="<?php echo sortHeader('MaxScore') ?>"><?php echo translate('MaxBrScore') ?><?php echo sortTag('MaxScore') ?></a></th>
|
||||
<?php
|
||||
if ( count($storage_areas) > 1 ) {
|
||||
?>
|
||||
|
@ -200,7 +200,10 @@ while ( $event_row = dbFetchNext($results) ) {
|
|||
<td class="colAlarmFrames"><?php echo makePopupLink( '?view=frames&eid='.$event->Id(), 'zmFrames', 'frames', $event->AlarmFrames() ) ?></td>
|
||||
<td class="colTotScore"><?php echo $event->TotScore() ?></td>
|
||||
<td class="colAvgScore"><?php echo $event->AvgScore() ?></td>
|
||||
<td class="colMaxScore"><?php echo makePopupLink( '?view=frame&eid='.$event->Id().'&fid=0', 'zmImage', array( 'image', reScale( $event->Width(), $scale ), reScale( $event->Height(), $scale ) ), $event->MaxScore() ) ?></td>
|
||||
<td class="colMaxScore"><?php echo makePopupLink(
|
||||
'?view=frame&eid='.$event->Id().'&fid=0', 'zmImage',
|
||||
array('image', reScale($event->Width(), $scale), reScale($event->Height(), $scale)), $event->MaxScore()
|
||||
); ?></td>
|
||||
<?php
|
||||
if ( count($storage_areas) > 1 ) {
|
||||
?>
|
||||
|
@ -218,7 +221,8 @@ while ( $event_row = dbFetchNext($results) ) {
|
|||
#Logger::Debug(print_r($thumbData,true));
|
||||
echo '<td class="colThumbnail">';
|
||||
$imgSrc = $event->getThumbnailSrc();
|
||||
$streamSrc = $event->getStreamSrc(array('mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single'));
|
||||
$streamSrc = $event->getStreamSrc(array(
|
||||
'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single'));
|
||||
|
||||
$imgHtml = '<img id="thumbnail'.$event->id().'" src="'.$imgSrc.'" alt="'. validHtmlStr('Event '.$event->Id()) .'" style="width:'. validInt($event->ThumbnailWidth()) .'px;height:'. validInt($event->ThumbnailHeight()).'px;" onmouseover="this.src=\''.$streamSrc.'\';" onmouseout="this.src=\''.$imgSrc.'\';"/>';
|
||||
echo '<a href="?view=event&eid='. $event->Id().$filterQuery.$sortQuery.'&page=1">'.$imgHtml.'</a>';
|
||||
|
@ -234,23 +238,25 @@ while ( $event_row = dbFetchNext($results) ) {
|
|||
<?php
|
||||
if ( ZM_WEB_EVENT_DISK_SPACE ) {
|
||||
?>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="11">Totals:</td>
|
||||
<?php
|
||||
if ( count($storage_areas)>1 ) {
|
||||
?>
|
||||
<td class="colStorage"></td>
|
||||
<td class="colStorage"></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<td class="colDiskSpace"><?php echo human_filesize($disk_space_total) ?></td>
|
||||
<?php
|
||||
if ( ZM_WEB_LIST_THUMBS ) {
|
||||
?><td></td>
|
||||
?>
|
||||
<td></td>
|
||||
<?php
|
||||
}
|
||||
?><td></td>
|
||||
?>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<?php
|
||||
|
@ -263,20 +269,30 @@ if ( $pagination ) {
|
|||
<h3 class="pagination"><?php echo $pagination ?></h3>
|
||||
<?php
|
||||
}
|
||||
if ( true || canEdit( 'Events' ) ) {
|
||||
?>
|
||||
<div id="contentButtons">
|
||||
<input type="button" name="viewBtn" value="<?php echo translate('View') ?>" onclick="viewEvents( this, 'markEids' );" disabled="disabled"/>
|
||||
<input type="button" name="archiveBtn" value="<?php echo translate('Archive') ?>" onclick="archiveEvents( this, 'markEids' )" disabled="disabled"/>
|
||||
<input type="button" name="unarchiveBtn" value="<?php echo translate('Unarchive') ?>" onclick="unarchiveEvents( this, 'markEids' );" disabled="disabled"/>
|
||||
<input type="button" name="editBtn" value="<?php echo translate('Edit') ?>" onclick="editEvents( this, 'markEids' )" disabled="disabled"/>
|
||||
<input type="button" name="exportBtn" value="<?php echo translate('Export') ?>" onclick="exportEvents( this, 'markEids' )" disabled="disabled"/>
|
||||
<input type="button" name="downloadBtn" value="<?php echo translate('DownloadVideo') ?>" onclick="downloadVideo( this, 'markEids' )" disabled="disabled"/>
|
||||
<input type="button" name="deleteBtn" value="<?php echo translate('Delete') ?>" onclick="deleteEvents( this, 'markEids' );" disabled="disabled"/>
|
||||
<button type="button" name="viewBtn" value="View" onclick="viewEvents(this, 'markEids');" disabled="disabled">
|
||||
<?php echo translate('View') ?>
|
||||
</button>
|
||||
<button type="button" name="archiveBtn" value="Archive" onclick="archiveEvents(this, 'markEids')" disabled="disabled">
|
||||
<?php echo translate('Archive') ?>
|
||||
</button>
|
||||
<button type="button" name="unarchiveBtn" value="Unarchive" onclick="unarchiveEvents(this, 'markEids');" disabled="disabled">
|
||||
<?php echo translate('Unarchive') ?>
|
||||
</button>
|
||||
<button type="button" name="editBtn" value="Edit" onclick="editEvents(this, 'markEids')" disabled="disabled">
|
||||
<?php echo translate('Edit') ?>
|
||||
</button>
|
||||
<button type="button" name="exportBtn" value="Export" onclick="exportEvents(this, 'markEids')" disabled="disabled">
|
||||
<?php echo translate('Export') ?>
|
||||
</button>
|
||||
<button type="button" name="downloadBtn" value="DownloadVideo" onclick="downloadVideo(this, 'markEids')" disabled="disabled">
|
||||
<?php echo translate('DownloadVideo') ?>
|
||||
</button>
|
||||
<button type="button" name="deleteBtn" value="Delete" onclick="deleteEvents(this, 'markEids');" disabled="disabled">
|
||||
<?php echo translate('Delete') ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -18,18 +18,18 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
if ( !canEdit( 'Groups' ) ) {
|
||||
if ( !canEdit('Groups') ) {
|
||||
$view = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !empty($_REQUEST['gid']) ) {
|
||||
$newGroup = new Group( $_REQUEST['gid'] );
|
||||
$newGroup = new Group($_REQUEST['gid']);
|
||||
} else {
|
||||
$newGroup = new Group();
|
||||
}
|
||||
|
||||
xhtmlHeaders( __FILE__, translate('Group').' - '.$newGroup->Name() );
|
||||
xhtmlHeaders(__FILE__, translate('Group').' - '.$newGroup->Name());
|
||||
?>
|
||||
<body>
|
||||
<div id="page">
|
||||
|
@ -52,7 +52,7 @@ xhtmlHeaders( __FILE__, translate('Group').' - '.$newGroup->Name() );
|
|||
<td>
|
||||
<?php
|
||||
$Groups = array();
|
||||
foreach ( Group::find_all( ) as $Group ) {
|
||||
foreach ( Group::find() as $Group ) {
|
||||
$Groups[$Group->Id()] = $Group;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ function get_children($Group) {
|
|||
|
||||
$kids = array();
|
||||
if ( isset( $children[$Group->Id()] ) ) {
|
||||
$kids += array_map( 'get_Id', $children[$Group->Id()] );
|
||||
$kids += array_map('get_Id', $children[$Group->Id()]);
|
||||
foreach ( $children[$Group->Id()] as $G ) {
|
||||
foreach ( get_children($G) as $id ) {
|
||||
$kids[] = $id;
|
||||
|
@ -89,13 +89,12 @@ function get_children($Group) {
|
|||
$kids = get_children($newGroup);
|
||||
if ( $newGroup->Id() )
|
||||
$kids[] = $newGroup->Id();
|
||||
$sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids )).')' : '').' ORDER BY Name';
|
||||
$sql = 'SELECT Id,Name from Groups'.(count($kids)?' WHERE Id NOT IN ('.implode(',',array_map(function(){return '?';}, $kids)).')' : '').' ORDER BY Name';
|
||||
$options = array(''=>'None');
|
||||
foreach ( dbFetchAll( $sql, null, $kids ) as $option ) {
|
||||
|
||||
$options[$option['Id']] = str_repeat(' ', $Groups[$option['Id']]->depth() ) . $option['Name'];
|
||||
foreach ( dbFetchAll($sql, null, $kids) as $option ) {
|
||||
$options[$option['Id']] = str_repeat(' ', $Groups[$option['Id']]->depth()) . $option['Name'];
|
||||
}
|
||||
echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);' ));
|
||||
echo htmlSelect('newGroup[ParentId]', $options, $newGroup->ParentId(), array('onchange'=>'configureButtons(this);'));
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -104,10 +103,10 @@ echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('o
|
|||
<td>
|
||||
<select name="newGroup[MonitorIds][]" class="chosen" multiple="multiple" onchange="configureButtons(this);">
|
||||
<?php
|
||||
$monitors = dbFetchAll( 'SELECT Id,Name FROM Monitors ORDER BY Sequence ASC' );
|
||||
$monitors = dbFetchAll('SELECT Id,Name FROM Monitors ORDER BY Sequence ASC');
|
||||
$monitorIds = $newGroup->MonitorIds();
|
||||
foreach ( $monitors as $monitor ) {
|
||||
if ( visibleMonitor( $monitor['Id'] ) ) {
|
||||
if ( visibleMonitor($monitor['Id']) ) {
|
||||
?>
|
||||
<option value="<?php echo $monitor['Id'] ?>"<?php if ( in_array( $monitor['Id'], $monitorIds ) ) { ?> selected="selected"<?php } ?>><?php echo validHtmlStr($monitor['Name']) ?></option>
|
||||
<?php
|
||||
|
@ -120,7 +119,9 @@ echo htmlSelect( 'newGroup[ParentId]', $options, $newGroup->ParentId(), array('o
|
|||
</tbody>
|
||||
</table>
|
||||
<div id="contentButtons">
|
||||
<input type="submit" name="saveBtn" value="<?php echo translate('Save') ?>"<?php $newGroup->Id() ? '' : ' disabled="disabled"'?>/>
|
||||
<button type="submit" name="saveBtn" value="Save"<?php $newGroup->Id() ? '' : ' disabled="disabled"'?>>
|
||||
<?php echo translate('Save') ?>
|
||||
</button>
|
||||
<input type="button" value="<?php echo translate('Cancel') ?>" onclick="closeWindow()"/>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -28,7 +28,7 @@ $group_id = 0;
|
|||
$max_depth = 0;
|
||||
|
||||
$Groups = array();
|
||||
foreach ( Group::find_all( ) as $Group ) {
|
||||
foreach ( Group::find( ) as $Group ) {
|
||||
$Groups[$Group->Id()] = $Group;
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ foreach ( $Groups as $id=>$Group ) {
|
|||
if ( $max_depth < $Group->depth() )
|
||||
$max_depth = $Group->depth();
|
||||
}
|
||||
xhtmlHeaders(__FILE__, translate('Groups') );
|
||||
xhtmlHeaders(__FILE__, translate('Groups'));
|
||||
?>
|
||||
<body>
|
||||
<div id="page">
|
||||
|
@ -64,33 +64,37 @@ function group_line( $Group ) {
|
|||
global $children;
|
||||
global $max_depth;
|
||||
$html = '<tr>';
|
||||
$html .= str_repeat( '<td class="colName"> </td>', $Group->depth() );
|
||||
$html .= str_repeat('<td class="colName"> </td>', $Group->depth());
|
||||
$html .= '<td class="colName" colspan="'.($max_depth-($Group->depth()-1)).'">';
|
||||
if ( canEdit('Groups') ) {
|
||||
$html .= '<a href="#" onclick="editGroup('.$Group->Id().');">'. validHtmlStr($Group->Id() . ' ' . $Group->Name()).'</a>';
|
||||
} else {
|
||||
$html .= validHtmlStr($Group->Name());
|
||||
}
|
||||
$html .= '</td><td class="colIds">'. monitorIdsToNames( $Group->MonitorIds(), 30 ).'</td>
|
||||
$html .= '</td><td class="colIds">'. monitorIdsToNames($Group->MonitorIds(), 30).'</td>
|
||||
<td class="colSelect"><input type="checkbox" name="gid[]" value="'. $Group->Id() .'" onclick="configureButtons(this);"/></td>
|
||||
</tr>
|
||||
';
|
||||
if ( isset( $children[$Group->Id()] ) ) {
|
||||
foreach ( $children[$Group->Id()] as $G ) {
|
||||
$html .= group_line( $G );
|
||||
$html .= group_line($G);
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
if ( isset( $children[null] ) )
|
||||
foreach ( $children[null] as $Group )
|
||||
echo group_line( $Group );
|
||||
echo group_line($Group);
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="contentButtons">
|
||||
<input type="button" value="<?php echo translate('New') ?>" onclick="newGroup();"<?php echo canEdit('Groups')?'':' disabled="disabled"' ?>/>
|
||||
<input type="button" name="deleteBtn" value="<?php echo translate('Delete') ?>" onclick="deleteGroup(this);" disabled="disabled"/>
|
||||
<button type="button" value="New" onclick="newGroup();"<?php echo canEdit('Groups')?'':' disabled="disabled"' ?>>
|
||||
<?php echo translate('New') ?>
|
||||
</button>
|
||||
<button type="button" name="deleteBtn" value="Delete" onclick="deleteGroup(this);" disabled="disabled">
|
||||
<?php echo translate('Delete') ?>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -18,25 +18,24 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
if ( !canEdit( 'Monitors' ) ) {
|
||||
if ( !canEdit('Monitors') ) {
|
||||
$view = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
$monitors = Monitor::find_all( array('Id' => $_REQUEST['mids'] ) );
|
||||
$monitors = Monitor::find(array('Id' => $_REQUEST['mids']));
|
||||
$monitor = $monitors[0];
|
||||
$servers = Server::find_all();
|
||||
$servers = Server::find();
|
||||
$ServersById = array();
|
||||
foreach ( $servers as $S ) {
|
||||
$ServersById[$S->Id()] = $S;
|
||||
}
|
||||
$storage_areas = Storage::find_all();
|
||||
$storage_areas = Storage::find();
|
||||
$StorageById = array();
|
||||
foreach ( $storage_areas as $S ) {
|
||||
$StorageById[$S->Id()] = $S;
|
||||
}
|
||||
|
||||
|
||||
$focusWindow = true;
|
||||
|
||||
xhtmlHeaders(__FILE__, translate('Function'));
|
||||
|
@ -48,7 +47,7 @@ xhtmlHeaders(__FILE__, translate('Function'));
|
|||
</div>
|
||||
<div id="content">
|
||||
The following monitors will have these settings update when you click Save:<br/><br/>
|
||||
<?php echo implode('<br/>', array_map( function($m){return $m->Id().' ' .$m->Name();}, $monitors ) ); ?>
|
||||
<?php echo implode('<br/>', array_map(function($m){return $m->Id().' ' .$m->Name();}, $monitors)); ?>
|
||||
<form name="contentForm" id="contentForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" onsubmit="$j('#contentButtons').hide();return true;">
|
||||
<input type="hidden" name="view" value="none"/>
|
||||
<input type="hidden" name="action" value="save"/>
|
||||
|
@ -56,31 +55,31 @@ The following monitors will have these settings update when you click Save:<br/>
|
|||
<?php
|
||||
echo implode(
|
||||
"\n",
|
||||
array_map( function($m){
|
||||
array_map(function($m){
|
||||
return '<input type="hidden" name="mids[]" value="'.$m->Id().'"/>';
|
||||
}, $monitors )
|
||||
}, $monitors)
|
||||
);
|
||||
if ( count($ServersById) > 0 ) { ?>
|
||||
<p class="Server"><label><?php echo translate('Server')?></label>
|
||||
<?php echo htmlSelect( 'newMonitor[ServerId]', array(''=>'None')+$ServersById, $monitor->ServerId() ); ?>
|
||||
</p>
|
||||
<p class="Server"><label><?php echo translate('Server')?></label>
|
||||
<?php echo htmlSelect('newMonitor[ServerId]', array(''=>'None')+$ServersById, $monitor->ServerId()); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
if ( count($StorageById) > 0 ) {
|
||||
}
|
||||
if ( count($StorageById) > 0 ) {
|
||||
?>
|
||||
<p class="Storage"><label><?php echo translate('Storage')?></label>
|
||||
<?php echo htmlSelect( 'newMonitor[StorageId]', array(''=>'All')+$StorageById, $monitor->StorageId() ); ?>
|
||||
</p>
|
||||
<p class="Storage"><label><?php echo translate('Storage')?></label>
|
||||
<?php echo htmlSelect('newMonitor[StorageId]', array(''=>'All')+$StorageById, $monitor->StorageId()); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
<p><label><?php echo translate('Function') ?></label>
|
||||
<?php
|
||||
$options = array();
|
||||
foreach ( getEnumValues('Monitors', 'Function') as $opt ) {
|
||||
$options[$opt] = translate('Fn'.$opt);
|
||||
}
|
||||
echo htmlSelect( 'newMonitor[Function]', $options, $monitor->Function() );
|
||||
$options = array();
|
||||
foreach ( getEnumValues('Monitors', 'Function') as $opt ) {
|
||||
$options[$opt] = translate('Fn'.$opt);
|
||||
}
|
||||
echo htmlSelect('newMonitor[Function]', $options, $monitor->Function());
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
|
@ -89,7 +88,7 @@ echo htmlSelect( 'newMonitor[Function]', $options, $monitor->Function() );
|
|||
</p>
|
||||
<div id="contentButtons">
|
||||
<button type="submit" value="Save"><?php echo translate('Save') ?></button>
|
||||
<button onclick="closeWindow()"><?php echo translate('Cancel') ?></button>
|
||||
<button type="button" onclick="closeWindow()"><?php echo translate('Cancel') ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
|
||||
if ( !canView( 'System' ) ) {
|
||||
if ( !canView('System') ) {
|
||||
$view = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
$canEdit = canEdit( 'System' );
|
||||
$canEdit = canEdit('System');
|
||||
|
||||
$tabs = array();
|
||||
$tabs['skins'] = translate('Display');
|
||||
|
@ -50,10 +50,10 @@ else
|
|||
|
||||
$focusWindow = true;
|
||||
|
||||
xhtmlHeaders( __FILE__, translate('Options') );
|
||||
xhtmlHeaders(__FILE__, translate('Options'));
|
||||
|
||||
# Have to do this stuff up here before including header.php because fof the cookie setting
|
||||
$skin_options = array_map( 'basename', glob('skins/*',GLOB_ONLYDIR) );
|
||||
$skin_options = array_map('basename', glob('skins/*',GLOB_ONLYDIR));
|
||||
if ( $tab == 'skins' ) {
|
||||
$current_skin = $_COOKIE['zmSkin'];
|
||||
$reload = false;
|
||||
|
@ -75,7 +75,7 @@ if ( $tab == 'skins' ) {
|
|||
|
||||
?>
|
||||
<body>
|
||||
<?php echo getNavBarHTML(); ?>
|
||||
<?php echo getNavBarHTML(); ?>
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-sm-2 sidebar">
|
||||
|
@ -90,7 +90,7 @@ foreach ( $tabs as $name=>$value ) {
|
|||
</ul>
|
||||
</div>
|
||||
<div class="col-sm-10 col-sm-offset-2">
|
||||
<br/>
|
||||
<br/>
|
||||
<div id="options">
|
||||
<?php
|
||||
if ( $tab == 'skins' ) {
|
||||
|
@ -103,7 +103,7 @@ if ( $tab == 'skins' ) {
|
|||
<div class="col-sm-6">
|
||||
<select name="skin-choice" class="form-control chosen">
|
||||
<?php
|
||||
foreach($skin_options as $dir) {
|
||||
foreach ( $skin_options as $dir ) {
|
||||
echo '<option value="'.$dir.'" '.($current_skin==$dir ? 'SELECTED="SELECTED"' : '').'>'.$dir.'</option>';
|
||||
}
|
||||
?>
|
||||
|
@ -116,7 +116,7 @@ foreach($skin_options as $dir) {
|
|||
<div class="col-sm-6">
|
||||
<select name="css-choice" class="form-control chosen">
|
||||
<?php
|
||||
foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDIR) ) as $dir) {
|
||||
foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDIR)) as $dir ) {
|
||||
echo '<option value="'.$dir.'" '.($current_css==$dir ? 'SELECTED="SELECTED"' : '').'>'.$dir.'</option>';
|
||||
}
|
||||
?>
|
||||
|
@ -136,7 +136,7 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
|
|||
<input type="hidden" name="view" value="<?php echo $view ?>"/>
|
||||
<input type="hidden" name="tab" value="<?php echo $tab ?>"/>
|
||||
<input type="hidden" name="action" value="delete"/>
|
||||
<table id="contentTable" class="table table-striped" cellspacing="0">
|
||||
<table id="contentTable" class="table table-striped">
|
||||
<thead class="thead-highlight">
|
||||
<tr>
|
||||
<th class="colUsername"><?php echo translate('Username') ?></th>
|
||||
|
@ -155,17 +155,17 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
|
|||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$sql = 'select * from Monitors order by Sequence asc';
|
||||
$sql = 'SELECT * FROM Monitors ORDER BY Sequence ASC';
|
||||
$monitors = array();
|
||||
foreach( dbFetchAll( $sql ) as $monitor ) {
|
||||
foreach( dbFetchAll($sql) as $monitor ) {
|
||||
$monitors[$monitor['Id']] = $monitor;
|
||||
}
|
||||
|
||||
$sql = 'select * from Users';
|
||||
foreach( dbFetchAll( $sql ) as $row ) {
|
||||
$sql = 'SELECT * FROM Users ORDER BY Username';
|
||||
foreach( dbFetchAll($sql) as $row ) {
|
||||
$userMonitors = array();
|
||||
if ( !empty($row['MonitorIds']) ) {
|
||||
foreach ( explode( ',', $row['MonitorIds'] ) as $monitorId ) {
|
||||
foreach ( explode(',', $row['MonitorIds']) as $monitorId ) {
|
||||
$userMonitors[] = $monitors[$monitorId]['Name'];
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
|
|||
<input type="hidden" name="tab" value="<?php echo $tab ?>"/>
|
||||
<input type="hidden" name="action" value="delete"/>
|
||||
<input type="hidden" name="object" value="storage"/>
|
||||
<table id="contentTable" class="table table-striped" cellspacing="0">
|
||||
<table id="contentTable" class="table table-striped">
|
||||
<thead class="thead-highlight">
|
||||
<tr>
|
||||
<th class="colId"><?php echo translate('Id') ?></th>
|
||||
|
@ -270,15 +270,15 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach( Storage::find_all( null, array('order'=>'lower(Name)') ) as $Storage ) { ?>
|
||||
<?php foreach( Storage::find( null, array('order'=>'lower(Name)') ) as $Storage ) { ?>
|
||||
<tr>
|
||||
<td class="colId"><?php echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Id()), $canEdit ) ?></td>
|
||||
<td class="colName"><?php echo makePopupLink( '?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?></td>
|
||||
<td class="colPath"><?php echo makePopupLink( '?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?></td>
|
||||
<td class="colType"><?php echo makePopupLink( '?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?></td>
|
||||
<td class="colScheme"><?php echo makePopupLink( '?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?></td>
|
||||
<td class="colName"><?php echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?></td>
|
||||
<td class="colPath"><?php echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?></td>
|
||||
<td class="colType"><?php echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?></td>
|
||||
<td class="colScheme"><?php echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?></td>
|
||||
<td class="colServer"><?php
|
||||
echo makePopupLink( '?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?></td>
|
||||
echo makePopupLink('?view=storage&id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?></td>
|
||||
<td class="colDiskSpace"><?php echo human_filesize($Storage->disk_used_space()) . ' of ' . human_filesize($Storage->disk_total_space()) ?></td>
|
||||
<td class="colMark"><input type="checkbox" name="markIds[]" value="<?php echo $Storage->Id() ?>" onclick="configureDeleteButton(this);"<?php if ( !$canEdit ) { ?> disabled="disabled"<?php } ?>/></td>
|
||||
</tr>
|
||||
|
@ -400,6 +400,4 @@ foreach( array_map( 'basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI
|
|||
</div>
|
||||
</div> <!-- end row -->
|
||||
</div>
|
||||
<?php include("skins/$skin/views/state.php") ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php xhtmlFooter() ?>
|
||||
|
|
Loading…
Reference in New Issue