Merge branch 'master' into storageareas

This commit is contained in:
Isaac Connor 2018-09-09 11:36:52 -04:00
commit e4c87ce256
25 changed files with 420 additions and 306 deletions

View File

@ -150,7 +150,7 @@ Orientation
WebSite
^^^^^^^
This Source Type allows one to configure an arbitrary website as a non-reocrdable, fully interactive, monitor in ZoneMinder. Note that sites with self-signed certificates will not display until the end user first manually navigates to the site and accpets the unsigned certificate. Also note that some sites will set an X-Frame option in the header, which discourages their site from being displayed within a frame. ZoneMinder will detect this condition and present a warning in the log. When this occurs, the end user can choose to install a browser plugin or extension to workaround this issue.
This Source Type allows one to configure an arbitrary website as a non-recordable, fully interactive, monitor in ZoneMinder. Note that sites with self-signed certificates will not display until the end user first manually navigates to the site and accpets the unsigned certificate. Also note that some sites will set an X-Frame option in the header, which discourages their site from being displayed within a frame. ZoneMinder will detect this condition and present a warning in the log. When this occurs, the end user can choose to install a browser plugin or extension to workaround this issue.
Website URL
Enter the full http or https url to the desired website.

View File

@ -1,27 +1,3 @@
# ==========================================================================
#
# ZoneMinder Base Module, $Date$, $Revision$
# Copyright (C) 2001-2008 Philip Coombes
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ==========================================================================
#
# This module contains the common definitions and functions used by the rest
# of the ZoneMinder scripts
#
package ZoneMinder::Base;
use 5.006;
@ -82,11 +58,18 @@ Philip Coombes, E<lt>philip.coombes@zoneminder.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2001-2008 Philip Coombes
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 library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.3 or,
at your option, any later version of Perl 5 you may have available.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
=cut

View File

@ -440,7 +440,7 @@ sub databaseLevel {
if ( defined($databaseLevel) ) {
$databaseLevel = $this->limit($databaseLevel);
if ( $this->{databaseLevel} != $databaseLevel ) {
if ( $databaseLevel > NOLOG and $this->{databaseLevel} <= NOLOG ) {
if ( ( $databaseLevel > NOLOG ) and ( $this->{databaseLevel} <= NOLOG ) ) {
if ( !$this->{dbh} ) {
$this->{dbh} = ZoneMinder::Database::zmDbConnect();
}
@ -560,11 +560,14 @@ sub logPrint {
if ( $level <= $this->{databaseLevel} ) {
if ( ! ( $this->{dbh} and $this->{dbh}->ping() ) ) {
$this->{sth} = undef;
# Turn this off because zDbConnect will do logging calls.
my $oldlevel = $this->{databaseLevel};
$this->{databaseLevel} = NOLOG;
if ( ! ( $this->{dbh} = ZoneMinder::Database::zmDbConnect() ) ) {
#print(STDERR "Can't log to database: ");
$this->{databaseLevel} = NOLOG;
return;
}
$this->{databaseLevel} = $oldlevel;
}
my $sql = 'INSERT INTO Logs ( TimeKey, Component, Pid, Level, Code, Message, File, Line ) VALUES ( ?, ?, ?, ?, ?, ?, ?, NULL )';

View File

@ -53,7 +53,6 @@ use constant START_DELAY => 30; # To give everything else time to start
@EXTRA_PERL_LIB@
use ZoneMinder;
use ZoneMinder::Storage;
use POSIX;
use DBI;
use autouse 'Data::Dumper'=>qw(Dumper);
@ -72,15 +71,13 @@ sleep( START_DELAY );
my $dbh = zmDbConnect();
my $sql = $Config{ZM_SERVER_ID} ? 'SELECT * FROM Monitors WHERE ServerId=?' : 'SELECT * FROM Monitors';
my $sth = $dbh->prepare_cached( $sql )
or Fatal( "Can't prepare '$sql': ".$dbh->errstr() );
while( 1 ) {
while ( ! ( $dbh and $dbh->ping() ) ) {
Info("Reconnecting to db");
$dbh = zmDbConnect();
if ( ! ( $dbh = zmDbConnect() ) ) {
#What we do here is not that important, so just skip this interval
sleep($Config{ZM_STATS_UPDATE_INTERVAL});
}
}
$dbh->do('DELETE FROM Events_Hour WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 hour)') or Error($dbh->errstr());
@ -88,7 +85,7 @@ while( 1 ) {
$dbh->do('DELETE FROM Events_Week WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 week)') or Error($dbh->errstr());
$dbh->do('DELETE FROM Events_Month WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 month)') or Error($dbh->errstr());
sleep( $Config{ZM_STATS_UPDATE_INTERVAL} );
sleep($Config{ZM_STATS_UPDATE_INTERVAL});
} # end while (1)
Info( "Stats Daemon exiting\n" );

View File

@ -78,6 +78,11 @@ my $sth = $dbh->prepare_cached($sql)
or Fatal("Can't prepare '$sql': ".$dbh->errstr());
while( 1 ) {
while ( ! ( $dbh and $dbh->ping() ) ) {
if ( ! ( $dbh = zmDbConnect() ) ) {
sleep($Config{ZM_WATCH_CHECK_INTERVAL});
}
}
my $res = $sth->execute( $Config{ZM_SERVER_ID} ? $Config{ZM_SERVER_ID} : () )
or Fatal('Can\'t execute: '.$sth->errstr());
@ -98,7 +103,7 @@ while( 1 ) {
Debug("Monitor $$monitor{Id} LastWriteTime is $capture_time.");
if ( !$capture_time ) {
my $startup_time = zmGetStartupTime($monitor);
if ( $now - $startup_time > $Config{ZM_WATCH_MAX_DELAY} ) {
if ( ( $now - $startup_time ) > $Config{ZM_WATCH_MAX_DELAY} ) {
Info(
"Restarting capture daemon for $$monitor{Name}, no image since startup. ".
"Startup time was $startup_time - now $now > $Config{ZM_WATCH_MAX_DELAY}"
@ -111,11 +116,12 @@ while( 1 ) {
}
}
if ( ! $restart ) {
my $max_image_delay = ( $monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0)
&&($monitor->{MaxFPS}<1)
) ? (3/$monitor->{MaxFPS})
: $Config{ZM_WATCH_MAX_DELAY}
my $max_image_delay = (
$monitor->{MaxFPS}
&&($monitor->{MaxFPS}>0)
&&($monitor->{MaxFPS}<1)
) ? (3/$monitor->{MaxFPS})
: $Config{ZM_WATCH_MAX_DELAY}
;
my $image_delay = $now-$capture_time;
Debug("Monitor $monitor->{Id} last captured $image_delay seconds ago, max is $max_image_delay");

View File

@ -336,14 +336,14 @@ bool VideoStore::open() {
} else if (av_dict_count(opts) != 0) {
Warning("some options not set\n");
}
if (opts) av_dict_free(&opts);
if (ret < 0) {
Error("Error occurred when writing out file header to %s: %s\n",
filename, av_make_error_string(ret).c_str());
return false;
}
if (opts) av_dict_free(&opts);
return true;
}
} // end VideoStore::open()
VideoStore::~VideoStore() {
@ -398,12 +398,14 @@ VideoStore::~VideoStore() {
pkt.stream_index = audio_out_stream->index;
av_interleaved_write_frame(oc, &pkt);
zm_av_packet_unref(&pkt);
} // while have buffered frames
} // end if audio_out_codec
} // while have buffered frames
} // end if audio_out_codec
// Flush Queues
Debug(1,"Flushing interleaved queues");
av_interleaved_write_frame(oc, NULL);
Debug(1,"Writing trailer");
/* Write the trailer before close */
if (int rc = av_write_trailer(oc)) {
Error("Error writing trailer %s", av_err2str(rc));
@ -411,7 +413,7 @@ VideoStore::~VideoStore() {
Debug(3, "Sucess Writing trailer");
}
// WHen will be not using a file ?
// When will we not be using a file ?
if ( !(out_format->flags & AVFMT_NOFILE) ) {
/* Close the out file. */
Debug(2, "Closing");
@ -507,6 +509,7 @@ bool VideoStore::setup_resampler() {
}
Debug(2, "Have audio out codec");
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// audio_out_ctx = audio_out_stream->codec;
audio_out_ctx = avcodec_alloc_context3(audio_out_codec);
@ -517,6 +520,12 @@ bool VideoStore::setup_resampler() {
}
Debug(2, "Have audio_out_ctx");
// Now copy them to the out stream
audio_out_stream = avformat_new_stream(oc, NULL);
#else
audio_out_stream = avformat_new_stream(oc, NULL);
audio_out_ctx = audio_out_stream->codec;
#endif
/* put sample parameters */
audio_out_ctx->bit_rate = audio_in_ctx->bit_rate;
@ -559,8 +568,6 @@ bool VideoStore::setup_resampler() {
audio_out_ctx->time_base =
(AVRational){1, audio_out_ctx->sample_rate};
// Now copy them to the out stream
audio_out_stream = avformat_new_stream(oc, audio_out_codec);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
ret = avcodec_parameters_from_context(audio_out_stream->codecpar,

View File

@ -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'];

View File

@ -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 ) {

@ -1 +1 @@
Subproject commit ca91b87fda8e006e4fca2ed870f24f9a29c2905d
Subproject commit ea90c0cd7f6e24333a90885e563b5d30b793db29

@ -1 +1 @@
Subproject commit c3976f1478c681b0bbc132ec3a3e82c3984eeed5
Subproject commit 0bd63fb464957080ead342db58ca9e01532cf1ef

View File

@ -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 ) {

View File

@ -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');

View File

@ -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
?>

View File

@ -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;
}

View File

@ -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
?>

View File

@ -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];

View File

@ -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;

View File

@ -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).'%';

View File

@ -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();',

View File

@ -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;

View File

@ -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>
@ -200,7 +200,10 @@ while ( $event_row = dbFetchNext($results) ) {
<td class="colAlarmFrames"><?php echo makePopupLink( '?view=frames&amp;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&amp;eid='.$event->Id().'&amp;fid=0', 'zmImage', array( 'image', reScale( $event->Width(), $scale ), reScale( $event->Height(), $scale ) ), $event->MaxScore() ) ?></td>
<td class="colMaxScore"><?php echo makePopupLink(
'?view=frame&amp;eid='.$event->Id().'&amp;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&amp;eid='. $event->Id().$filterQuery.$sortQuery.'&amp;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,7 +269,6 @@ if ( $pagination ) {
<h3 class="pagination"><?php echo $pagination ?></h3>
<?php
}
if ( true || canEdit( 'Events' ) ) {
?>
<div id="contentButtons">
<button type="button" name="viewBtn" value="View" onclick="viewEvents(this, 'eids[]');" disabled="disabled">
@ -288,9 +293,6 @@ if ( true || canEdit( 'Events' ) ) {
<?php echo translate('Delete') ?>
</button>
</div>
<?php
}
?>
</form>
</div>
</div>

View File

@ -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('&nbsp;&nbsp;', $Groups[$option['Id']]->depth() ) . $option['Name'];
foreach ( dbFetchAll($sql, null, $kids) as $option ) {
$options[$option['Id']] = str_repeat('&nbsp;&nbsp;', $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>

View File

@ -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">&nbsp;</td>', $Group->depth() );
$html .= str_repeat('<td class="colName">&nbsp;</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>

View File

@ -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>

View File

@ -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&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Id()), $canEdit ) ?></td>
<td class="colName"><?php echo makePopupLink( '?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?></td>
<td class="colPath"><?php echo makePopupLink( '?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?></td>
<td class="colType"><?php echo makePopupLink( '?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?></td>
<td class="colScheme"><?php echo makePopupLink( '?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?></td>
<td class="colName"><?php echo makePopupLink('?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?></td>
<td class="colPath"><?php echo makePopupLink('?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Path()), $canEdit ) ?></td>
<td class="colType"><?php echo makePopupLink('?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Type()), $canEdit ) ?></td>
<td class="colScheme"><?php echo makePopupLink('?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Scheme()), $canEdit ) ?></td>
<td class="colServer"><?php
echo makePopupLink( '?view=storage&amp;id='.$Storage->Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?></td>
echo makePopupLink('?view=storage&amp;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() ?>