2013-03-17 07:45:21 +08:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// ZoneMinder web action file, $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
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2013-03-17 07:45:21 +08:00
|
|
|
//
|
2015-08-30 03:13:15 +08:00
|
|
|
|
|
|
|
|
2017-05-17 02:14:07 +08:00
|
|
|
function getAffectedIds( $name ) {
|
|
|
|
$names = $name.'s';
|
|
|
|
$ids = array();
|
2018-02-03 01:14:01 +08:00
|
|
|
if ( isset($_REQUEST[$names]) ) {
|
|
|
|
if ( is_array($_REQUEST[$names]) ) {
|
|
|
|
$ids = $_REQUEST[$names];
|
|
|
|
} else {
|
|
|
|
$ids = array($_REQUEST[$names]);
|
|
|
|
}
|
|
|
|
} else if ( isset($_REQUEST[$name]) ) {
|
|
|
|
if ( is_array($_REQUEST[$name]) ) {
|
|
|
|
$ids = $_REQUEST[$name];
|
|
|
|
} else {
|
|
|
|
$ids = array($_REQUEST[$name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ids;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( empty($action) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( $action == 'login' && isset($_REQUEST['username']) && ( ZM_AUTH_TYPE == 'remote' || isset($_REQUEST['password']) ) ) {
|
|
|
|
|
|
|
|
$refreshParent = true;
|
2018-10-09 22:05:50 +08:00
|
|
|
// User login is automatically performed in includes/auth.php So we don't need to perform a login here,
|
|
|
|
// just handle redirects. This is the action that comes from the login view, so the logical thing to
|
|
|
|
// do on successful auth is redirect to console, otherwise loop back to login.
|
|
|
|
if ( !$user ) {
|
|
|
|
$view = 'login';
|
|
|
|
} else {
|
|
|
|
$view = 'console';
|
|
|
|
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=console';
|
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} else if ( $action == 'logout' ) {
|
|
|
|
userLogout();
|
|
|
|
$refreshParent = true;
|
|
|
|
$view = 'none';
|
|
|
|
} else if ( $action == 'bandwidth' && isset($_REQUEST['newBandwidth']) ) {
|
|
|
|
$_COOKIE['zmBandwidth'] = validStr($_REQUEST['newBandwidth']);
|
2018-08-31 22:35:23 +08:00
|
|
|
setcookie('zmBandwidth', validStr($_REQUEST['newBandwidth']), time()+3600*24*30*12*10);
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
// Event scope actions, view permissions only required
|
2018-04-15 10:26:57 +08:00
|
|
|
if ( canView('Events') ) {
|
2017-05-17 02:14:07 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'addterm' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$_REQUEST['filter'] = addFilterTerm($_REQUEST['filter'], $_REQUEST['line']);
|
2017-10-31 04:29:27 +08:00
|
|
|
} elseif ( $action == 'delterm' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$_REQUEST['filter'] = delFilterTerm($_REQUEST['filter'], $_REQUEST['line']);
|
|
|
|
} else if ( canEdit('Events') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'delete' ) {
|
|
|
|
if ( ! empty($_REQUEST['Id']) ) {
|
2018-04-15 10:26:57 +08:00
|
|
|
dbQuery('DELETE FROM Filters WHERE Id=?', array($_REQUEST['Id']));
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2017-11-25 04:37:50 +08:00
|
|
|
} else if ( ( $action == 'Save' ) or ( $action == 'SaveAs' ) or ( $action == 'execute' ) ) {
|
|
|
|
# or ( $action == 'submit' ) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
$sql = '';
|
|
|
|
$_REQUEST['filter']['Query']['sort_field'] = validStr($_REQUEST['filter']['Query']['sort_field']);
|
|
|
|
$_REQUEST['filter']['Query']['sort_asc'] = validStr($_REQUEST['filter']['Query']['sort_asc']);
|
|
|
|
$_REQUEST['filter']['Query']['limit'] = validInt($_REQUEST['filter']['Query']['limit']);
|
2017-11-25 04:37:50 +08:00
|
|
|
if ( $action == 'execute' ) {
|
|
|
|
$tempFilterName = '_TempFilter'.time();
|
|
|
|
$sql .= ' Name = \''.$tempFilterName.'\'';
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
|
|
|
$sql .= ' Name = '.dbEscape($_REQUEST['filter']['Name']);
|
|
|
|
}
|
|
|
|
$sql .= ', Query = '.dbEscape(jsonEncode($_REQUEST['filter']['Query']));
|
|
|
|
$sql .= ', AutoArchive = '.(!empty($_REQUEST['filter']['AutoArchive']) ? 1 : 0);
|
|
|
|
$sql .= ', AutoVideo = '. ( !empty($_REQUEST['filter']['AutoVideo']) ? 1 : 0);
|
|
|
|
$sql .= ', AutoUpload = '. ( !empty($_REQUEST['filter']['AutoUpload']) ? 1 : 0);
|
|
|
|
$sql .= ', AutoEmail = '. ( !empty($_REQUEST['filter']['AutoEmail']) ? 1 : 0);
|
|
|
|
$sql .= ', AutoMessage = '. ( !empty($_REQUEST['filter']['AutoMessage']) ? 1 : 0);
|
|
|
|
$sql .= ', AutoExecute = '. ( !empty($_REQUEST['filter']['AutoExecute']) ? 1 : 0);
|
|
|
|
$sql .= ', AutoExecuteCmd = '.dbEscape($_REQUEST['filter']['AutoExecuteCmd']);
|
|
|
|
$sql .= ', AutoDelete = '. ( !empty($_REQUEST['filter']['AutoDelete']) ? 1 : 0);
|
2017-12-05 00:05:50 +08:00
|
|
|
if ( !empty($_REQUEST['filter']['AutoMove']) ? 1 : 0) {
|
|
|
|
$sql .= ', AutoMove = 1, AutoMoveTo='. validInt($_REQUEST['filter']['AutoMoveTo']);
|
|
|
|
} else {
|
|
|
|
$sql .= ', AutoMove = 0';
|
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$sql .= ', UpdateDiskSpace = '. ( !empty($_REQUEST['filter']['UpdateDiskSpace']) ? 1 : 0);
|
|
|
|
$sql .= ', Background = '. ( !empty($_REQUEST['filter']['Background']) ? 1 : 0);
|
|
|
|
$sql .= ', Concurrent = '. ( !empty($_REQUEST['filter']['Concurrent']) ? 1 : 0);
|
|
|
|
|
2017-11-24 00:26:55 +08:00
|
|
|
if ( $_REQUEST['Id'] and ( $action == 'Save' ) ) {
|
2018-04-15 10:26:57 +08:00
|
|
|
dbQuery('UPDATE Filters SET ' . $sql. ' WHERE Id=?', array($_REQUEST['Id']));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-04-15 10:26:57 +08:00
|
|
|
dbQuery('INSERT INTO Filters SET' . $sql);
|
2017-10-31 04:29:27 +08:00
|
|
|
$_REQUEST['Id'] = dbInsertId();
|
|
|
|
}
|
2017-11-25 04:37:50 +08:00
|
|
|
if ( $action == 'execute' ) {
|
|
|
|
executeFilter( $tempFilterName );
|
|
|
|
}
|
2017-06-19 22:18:44 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
} // end if save or execute
|
|
|
|
} // end if canEdit(Events)
|
|
|
|
return;
|
|
|
|
} // end if object == filter
|
|
|
|
else {
|
|
|
|
|
|
|
|
// Event scope actions, edit permissions required
|
2018-02-03 01:14:01 +08:00
|
|
|
if ( canEdit('Events') ) {
|
|
|
|
if ( ($action == 'rename') && isset($_REQUEST['eventName']) && !empty($_REQUEST['eid']) ) {
|
2018-04-15 10:26:57 +08:00
|
|
|
dbQuery('UPDATE Events SET Name=? WHERE Id=?', array($_REQUEST['eventName'], $_REQUEST['eid']));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else if ( $action == 'eventdetail' ) {
|
|
|
|
if ( !empty($_REQUEST['eid']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Events SET Cause=?, Notes=? WHERE Id=?',
|
|
|
|
array($_REQUEST['newEvent']['Cause'], $_REQUEST['newEvent']['Notes'], $_REQUEST['eid']) );
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-02-03 01:14:01 +08:00
|
|
|
$dbConn->beginTransaction();
|
|
|
|
foreach( getAffectedIds('markEid') as $markEid ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Events SET Cause=?, Notes=? WHERE Id=?',
|
|
|
|
array($_REQUEST['newEvent']['Cause'], $_REQUEST['newEvent']['Notes'], $markEid) );
|
2017-06-16 03:45:43 +08:00
|
|
|
}
|
2018-02-03 01:14:01 +08:00
|
|
|
$dbConn->commit();
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
$refreshParent = true;
|
|
|
|
$closePopup = true;
|
|
|
|
} elseif ( $action == 'archive' || $action == 'unarchive' ) {
|
|
|
|
$archiveVal = ($action == 'archive')?1:0;
|
|
|
|
if ( !empty($_REQUEST['eid']) ) {
|
2018-02-03 01:14:01 +08:00
|
|
|
dbQuery('UPDATE Events SET Archived=? WHERE Id=?', array($archiveVal, $_REQUEST['eid']));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-02-03 01:14:01 +08:00
|
|
|
$dbConn->beginTransaction();
|
2018-08-31 22:35:23 +08:00
|
|
|
foreach( getAffectedIds('markEid') as $markEid ) {
|
2018-02-03 01:14:01 +08:00
|
|
|
dbQuery('UPDATE Events SET Archived=? WHERE Id=?', array($archiveVal, $markEid));
|
2017-06-16 03:45:43 +08:00
|
|
|
}
|
2018-02-03 01:14:01 +08:00
|
|
|
$dbConn->commit();
|
2017-07-06 22:48:33 +08:00
|
|
|
$refreshParent = true;
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} elseif ( $action == 'delete' ) {
|
2018-02-03 01:14:01 +08:00
|
|
|
$dbConn->beginTransaction();
|
2018-09-04 21:57:32 +08:00
|
|
|
foreach( getAffectedIds('eids') as $markEid ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
deleteEvent($markEid);
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2018-02-03 01:14:01 +08:00
|
|
|
$dbConn->commit();
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
|
|
|
} // end if canEdit(Events)
|
|
|
|
} // end if filter or something else
|
|
|
|
} // end canView(Events)
|
|
|
|
|
|
|
|
// Monitor control actions, require a monitor id and control view permissions for that monitor
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( !empty($_REQUEST['mid']) && canView('Control', $_REQUEST['mid']) ) {
|
|
|
|
require_once('control_functions.php');
|
|
|
|
require_once('Monitor.php');
|
2017-10-31 04:29:27 +08:00
|
|
|
$mid = validInt($_REQUEST['mid']);
|
|
|
|
if ( $action == 'control' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$monitor = new Monitor($mid);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
$ctrlCommand = buildControlCommand($monitor);
|
|
|
|
sendControlCommand($monitor->Id(), $ctrlCommand);
|
|
|
|
} else if ( $action == 'settings' ) {
|
2017-12-07 23:31:25 +08:00
|
|
|
$args = ' -m ' . escapeshellarg($mid);
|
|
|
|
$args .= ' -B' . escapeshellarg($_REQUEST['newBrightness']);
|
|
|
|
$args .= ' -C' . escapeshellarg($_REQUEST['newContrast']);
|
|
|
|
$args .= ' -H' . escapeshellarg($_REQUEST['newHue']);
|
|
|
|
$args .= ' -O' . escapeshellarg($_REQUEST['newColour']);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
$zmuCommand = getZmuCommand($args);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
$zmuOutput = exec($zmuCommand);
|
|
|
|
list($brightness, $contrast, $hue, $colour) = explode(' ', $zmuOutput);
|
|
|
|
dbQuery(
|
|
|
|
'UPDATE Monitors SET Brightness = ?, Contrast = ?, Hue = ?, Colour = ? WHERE Id = ?',
|
|
|
|
array($brightness, $contrast, $hue, $colour, $mid));
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
// Control capability actions, require control edit permissions
|
2018-03-04 01:32:23 +08:00
|
|
|
if ( canEdit('Control') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'controlcap' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
require_once('Control.php');
|
2018-03-04 01:32:23 +08:00
|
|
|
$Control = new Control( !empty($_REQUEST['cid']) ? $_REQUEST['cid'] : null );
|
2014-06-06 03:14:12 +08:00
|
|
|
|
2018-03-04 01:32:23 +08:00
|
|
|
//$changes = getFormChanges( $control, $_REQUEST['newControl'], $types, $columns );
|
2018-08-31 22:35:23 +08:00
|
|
|
$Control->save($_REQUEST['newControl']);
|
2018-03-04 01:32:23 +08:00
|
|
|
$refreshParent = true;
|
2017-10-31 04:29:27 +08:00
|
|
|
$view = 'none';
|
|
|
|
} elseif ( $action == 'delete' ) {
|
|
|
|
if ( isset($_REQUEST['markCids']) ) {
|
|
|
|
foreach( $_REQUEST['markCids'] as $markCid ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('DELETE FROM Controls WHERE Id = ?', array($markCid));
|
|
|
|
dbQuery('UPDATE Monitors SET Controllable = 0, ControlId = 0 WHERE ControlId = ?', array($markCid));
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2018-03-04 01:32:23 +08:00
|
|
|
} // end if action
|
|
|
|
} // end if canEdit Controls
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( isset($_REQUEST['object']) and $_REQUEST['object'] == 'Monitor' ) {
|
|
|
|
if ( $action == 'save' ) {
|
|
|
|
foreach ( $_REQUEST['mids'] as $mid ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$mid = ValidInt($mid);
|
|
|
|
if ( ! canEdit('Monitors', $mid) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
Warning("Cannot edit monitor $mid");
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
$Monitor = new Monitor($mid);
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( $Monitor->Type() != 'WebSite' ) {
|
|
|
|
$Monitor->zmaControl('stop');
|
|
|
|
$Monitor->zmcControl('stop');
|
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
$Monitor->save($_REQUEST['newMonitor']);
|
|
|
|
if ( $Monitor->Function() != 'None' && $Monitor->Type() != 'WebSite' ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
$Monitor->zmcControl('start');
|
|
|
|
if ( $Monitor->Enabled() ) {
|
|
|
|
$Monitor->zmaControl('start');
|
2017-10-24 08:01:43 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
} // end foreach mid
|
|
|
|
$refreshParent = true;
|
|
|
|
} // end if action == save
|
|
|
|
} // end if object is Monitor
|
|
|
|
|
|
|
|
// Monitor edit actions, require a monitor id and edit permissions for that monitor
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( !empty($_REQUEST['mid']) && canEdit('Monitors', $_REQUEST['mid']) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
$mid = validInt($_REQUEST['mid']);
|
|
|
|
if ( $action == 'function' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id=?', NULL, array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
$newFunction = validStr($_REQUEST['newFunction']);
|
|
|
|
# Because we use a checkbox, it won't get passed in the request. So not being in _REQUEST means 0
|
2018-08-31 22:35:23 +08:00
|
|
|
$newEnabled = ( !isset($_REQUEST['newEnabled']) or $_REQUEST['newEnabled'] != '1' ) ? '0' : '1';
|
2017-10-31 04:29:27 +08:00
|
|
|
$oldFunction = $monitor['Function'];
|
|
|
|
$oldEnabled = $monitor['Enabled'];
|
|
|
|
if ( $newFunction != $oldFunction || $newEnabled != $oldEnabled ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Monitors SET Function=?, Enabled=? WHERE Id=?',
|
|
|
|
array($newFunction, $newEnabled, $mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
$monitor['Function'] = $newFunction;
|
|
|
|
$monitor['Enabled'] = $newEnabled;
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( daemonCheck() && ($monitor['Type'] != 'WebSite') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
$restart = ($oldFunction == 'None') || ($newFunction == 'None') || ($newEnabled != $oldEnabled);
|
2018-08-31 22:35:23 +08:00
|
|
|
zmaControl($monitor, 'stop');
|
|
|
|
zmcControl($monitor, $restart?'restart':'');
|
|
|
|
zmaControl($monitor, 'start');
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2017-10-24 08:01:43 +08:00
|
|
|
$refreshParent = true;
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
} else if ( $action == 'zone' && isset($_REQUEST['zid']) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
$zid = validInt($_REQUEST['zid']);
|
2018-08-31 22:35:23 +08:00
|
|
|
$monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id=?', NULL, array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
if ( !empty($zid) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$zone = dbFetchOne('SELECT * FROM Zones WHERE MonitorId=? AND Id=?', NULL, array($mid, $zid));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
|
|
|
$zone = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $_REQUEST['newZone']['Units'] == 'Percent' ) {
|
|
|
|
$_REQUEST['newZone']['MinAlarmPixels'] = intval(($_REQUEST['newZone']['MinAlarmPixels']*$_REQUEST['newZone']['Area'])/100);
|
|
|
|
$_REQUEST['newZone']['MaxAlarmPixels'] = intval(($_REQUEST['newZone']['MaxAlarmPixels']*$_REQUEST['newZone']['Area'])/100);
|
|
|
|
if ( isset($_REQUEST['newZone']['MinFilterPixels']) )
|
|
|
|
$_REQUEST['newZone']['MinFilterPixels'] = intval(($_REQUEST['newZone']['MinFilterPixels']*$_REQUEST['newZone']['Area'])/100);
|
|
|
|
if ( isset($_REQUEST['newZone']['MaxFilterPixels']) )
|
|
|
|
$_REQUEST['newZone']['MaxFilterPixels'] = intval(($_REQUEST['newZone']['MaxFilterPixels']*$_REQUEST['newZone']['Area'])/100);
|
|
|
|
if ( isset($_REQUEST['newZone']['MinBlobPixels']) )
|
|
|
|
$_REQUEST['newZone']['MinBlobPixels'] = intval(($_REQUEST['newZone']['MinBlobPixels']*$_REQUEST['newZone']['Area'])/100);
|
|
|
|
if ( isset($_REQUEST['newZone']['MaxBlobPixels']) )
|
|
|
|
$_REQUEST['newZone']['MaxBlobPixels'] = intval(($_REQUEST['newZone']['MaxBlobPixels']*$_REQUEST['newZone']['Area'])/100);
|
|
|
|
}
|
|
|
|
|
|
|
|
unset( $_REQUEST['newZone']['Points'] );
|
|
|
|
$types = array();
|
2018-08-31 22:35:23 +08:00
|
|
|
$changes = getFormChanges($zone, $_REQUEST['newZone'], $types);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( count($changes) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $zid > 0 ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Zones SET '.implode(', ', $changes).' WHERE MonitorId=? AND Id=?', array($mid, $zid));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('INSERT INTO Zones SET MonitorId=?, '.implode(', ', $changes), array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( daemonCheck() && ($monitor['Type'] != 'WebSite') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $_REQUEST['newZone']['Type'] == 'Privacy' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
zmaControl($monitor, 'stop');
|
|
|
|
zmcControl($monitor, 'restart');
|
|
|
|
zmaControl($monitor, 'start');
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
zmaControl($monitor, 'restart');
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( ($_REQUEST['newZone']['Type'] == 'Privacy') && $monitor['Controllable'] ) {
|
|
|
|
require_once('control_functions.php');
|
|
|
|
sendControlCommand($mid, 'quit');
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
|
|
|
$view = 'none';
|
2018-08-31 22:35:23 +08:00
|
|
|
} elseif ( $action == 'plugin' && isset($_REQUEST['pl']) ) {
|
|
|
|
$sql = 'SELECT * FROM PluginsConfig WHERE MonitorId=? AND ZoneId=? AND pluginName=?';
|
|
|
|
$pconfs=dbFetchAll($sql, NULL, array($mid, $_REQUEST['zid'], $_REQUEST['pl']));
|
|
|
|
$changes = 0;
|
|
|
|
foreach ( $pconfs as $pconf ) {
|
|
|
|
$value = $_REQUEST['pluginOpt'][$pconf['Name']];
|
|
|
|
if ( array_key_exists($pconf['Name'], $_REQUEST['pluginOpt']) && ($pconf['Value'] != $value) ) {
|
|
|
|
dbQuery('UPDATE PluginsConfig SET Value=? WHERE id=?', array($value, $pconf['Id']));
|
2017-10-31 04:29:27 +08:00
|
|
|
$changes++;
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( $changes > 0 ) {
|
|
|
|
if ( daemonCheck() && ($monitor['Type'] != 'WebSite') ) {
|
|
|
|
zmaControl($mid, 'restart');
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
|
|
|
$view = 'none';
|
2018-08-31 22:35:23 +08:00
|
|
|
} elseif ( ($action == 'sequence') && isset($_REQUEST['smid']) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
$smid = validInt($_REQUEST['smid']);
|
2018-08-31 22:35:23 +08:00
|
|
|
$monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id = ?', NULL, array($mid));
|
|
|
|
$smonitor = dbFetchOne('SELECT * FROM Monitors WHERE Id = ?', NULL, array($smid));
|
2017-05-17 02:14:07 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Monitors SET Sequence=? WHERE Id=?', array($smonitor['Sequence'], $monitor['Id']));
|
|
|
|
dbQuery('UPDATE Monitors SET Sequence=? WHERE Id=?', array($monitor['Sequence'], $smonitor['Id']));
|
2017-05-17 02:14:07 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
fixSequences();
|
|
|
|
} elseif ( $action == 'delete' ) {
|
|
|
|
if ( isset($_REQUEST['markZids']) ) {
|
|
|
|
$deletedZid = 0;
|
2018-08-31 22:35:23 +08:00
|
|
|
foreach ( $_REQUEST['markZids'] as $markZid ) {
|
|
|
|
$zone = dbFetchOne('SELECT * FROM Zones WHERE Id=?', NULL, array($markZid));
|
|
|
|
dbQuery('DELETE FROM Zones WHERE MonitorId=? AND Id=?', array($mid, $markZid));
|
2017-10-31 04:29:27 +08:00
|
|
|
$deletedZid = 1;
|
|
|
|
}
|
|
|
|
if ( $deletedZid ) {
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( daemonCheck() && $monitor['Type'] != 'WebSite' ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $zone['Type'] == 'Privacy' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
zmaControl($mid, 'stop');
|
|
|
|
zmcControl($mid, 'restart');
|
|
|
|
zmaControl($mid, 'start');
|
2017-05-17 02:14:07 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
zmaControl($mid, 'restart');
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} // end if daemonCheck()
|
2017-05-17 02:14:07 +08:00
|
|
|
$refreshParent = true;
|
2017-10-31 04:29:27 +08:00
|
|
|
} // end if deletedzid
|
|
|
|
} // end if isset($_REQUEST['markZids'])
|
|
|
|
} // end if action
|
|
|
|
} // end if $mid and canEdit($mid)
|
|
|
|
|
|
|
|
// Monitor edit actions, monitor id derived, require edit permissions for that monitor
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( canEdit('Monitors') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'monitor' ) {
|
|
|
|
$mid = 0;
|
|
|
|
if ( !empty($_REQUEST['mid']) ) {
|
|
|
|
$mid = validInt($_REQUEST['mid']);
|
2018-08-31 22:35:23 +08:00
|
|
|
$monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id=?', NULL, array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
if ( ZM_OPT_X10 ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$x10Monitor = dbFetchOne('SELECT * FROM TriggersX10 WHERE MonitorId=?', NULL, array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( !$x10Monitor )
|
|
|
|
$x10Monitor = array();
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
|
|
|
$monitor = array();
|
|
|
|
if ( ZM_OPT_X10 ) {
|
|
|
|
$x10Monitor = array();
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2018-04-25 21:32:15 +08:00
|
|
|
$Monitor = new Monitor($monitor);
|
2017-05-17 02:14:07 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
// Define a field type for anything that's not simple text equivalent
|
|
|
|
$types = array(
|
|
|
|
'Triggers' => 'set',
|
|
|
|
'Controllable' => 'toggle',
|
|
|
|
'TrackMotion' => 'toggle',
|
|
|
|
'Enabled' => 'toggle',
|
|
|
|
'DoNativeMotDet' => 'toggle',
|
|
|
|
'Exif' => 'toggle',
|
|
|
|
'RTSPDescribe' => 'toggle',
|
|
|
|
'RecordAudio' => 'toggle',
|
2018-03-15 23:04:41 +08:00
|
|
|
'Method' => 'raw',
|
2017-10-31 04:29:27 +08:00
|
|
|
);
|
|
|
|
|
2018-01-26 00:41:42 +08:00
|
|
|
if ( $_REQUEST['newMonitor']['ServerId'] == 'auto' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$_REQUEST['newMonitor']['ServerId'] = dbFetchOne(
|
|
|
|
'SELECT Id FROM Servers WHERE Status=\'Running\' ORDER BY FreeMem DESC, CpuLoad ASC LIMIT 1', 'Id');
|
|
|
|
Logger::Debug('Auto selecting server: Got ' . $_REQUEST['newMonitor']['ServerId'] );
|
2018-01-26 00:41:42 +08:00
|
|
|
if ( ( ! $_REQUEST['newMonitor'] ) and defined('ZM_SERVER_ID') ) {
|
|
|
|
$_REQUEST['newMonitor']['ServerId'] = ZM_SERVER_ID;
|
2018-08-31 22:35:23 +08:00
|
|
|
Logger::Debug('Auto selecting server to ' . ZM_SERVER_ID);
|
2018-01-26 00:41:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 21:32:15 +08:00
|
|
|
$columns = getTableColumns('Monitors');
|
|
|
|
$changes = getFormChanges($monitor, $_REQUEST['newMonitor'], $types, $columns);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( count($changes) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $mid ) {
|
|
|
|
|
|
|
|
# If we change anything that changes the shared mem size, zma can complain. So let's stop first.
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( $monitor['Type'] != 'WebSite' ) {
|
2018-06-12 04:34:40 +08:00
|
|
|
zmaControl($monitor, 'stop');
|
|
|
|
zmcControl($monitor, 'stop');
|
2018-04-27 05:18:36 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Monitors SET '.implode(', ', $changes).' WHERE Id=?', array($mid));
|
2018-02-28 03:19:44 +08:00
|
|
|
// Groups will be added below
|
2018-01-23 00:42:07 +08:00
|
|
|
if ( isset($changes['Name']) or isset($changes['StorageId']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$OldStorage = new Storage($monitor['StorageId']);
|
|
|
|
$saferOldName = basename($monitor['Name']);
|
|
|
|
if ( file_exists($OldStorage->Path().'/'.$saferOldName) )
|
|
|
|
unlink($OldStorage->Path().'/'.$saferOldName);
|
|
|
|
|
|
|
|
$NewStorage = new Storage($_REQUEST['newMonitor']['StorageId']);
|
|
|
|
if ( ! file_exists($NewStorage->Path().'/'.$mid) )
|
|
|
|
mkdir($NewStorage->Path().'/'.$mid, 0755);
|
|
|
|
$saferNewName = basename($_REQUEST['newMonitor']['Name']);
|
|
|
|
symlink($mid, $NewStorage->Path().'/'.$saferNewName);
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( isset($changes['Width']) || isset($changes['Height']) ) {
|
|
|
|
$newW = $_REQUEST['newMonitor']['Width'];
|
|
|
|
$newH = $_REQUEST['newMonitor']['Height'];
|
|
|
|
$newA = $newW * $newH;
|
|
|
|
$oldW = $monitor['Width'];
|
|
|
|
$oldH = $monitor['Height'];
|
|
|
|
$oldA = $oldW * $oldH;
|
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
$zones = dbFetchAll('SELECT * FROM Zones WHERE MonitorId=?', NULL, array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
foreach ( $zones as $zone ) {
|
|
|
|
$newZone = $zone;
|
2018-08-31 22:35:23 +08:00
|
|
|
$points = coordsToPoints($zone['Coords']);
|
2017-10-31 04:29:27 +08:00
|
|
|
for ( $i = 0; $i < count($points); $i++ ) {
|
|
|
|
$points[$i]['x'] = intval(($points[$i]['x']*($newW-1))/($oldW-1));
|
|
|
|
$points[$i]['y'] = intval(($points[$i]['y']*($newH-1))/($oldH-1));
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
$newZone['Coords'] = pointsToCoords($points);
|
2017-10-31 04:29:27 +08:00
|
|
|
$newZone['Area'] = intval(round(($zone['Area']*$newA)/$oldA));
|
|
|
|
$newZone['MinAlarmPixels'] = intval(round(($newZone['MinAlarmPixels']*$newA)/$oldA));
|
|
|
|
$newZone['MaxAlarmPixels'] = intval(round(($newZone['MaxAlarmPixels']*$newA)/$oldA));
|
|
|
|
$newZone['MinFilterPixels'] = intval(round(($newZone['MinFilterPixels']*$newA)/$oldA));
|
|
|
|
$newZone['MaxFilterPixels'] = intval(round(($newZone['MaxFilterPixels']*$newA)/$oldA));
|
|
|
|
$newZone['MinBlobPixels'] = intval(round(($newZone['MinBlobPixels']*$newA)/$oldA));
|
|
|
|
$newZone['MaxBlobPixels'] = intval(round(($newZone['MaxBlobPixels']*$newA)/$oldA));
|
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
$changes = getFormChanges($zone, $newZone, $types);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( count($changes) ) {
|
|
|
|
dbQuery('UPDATE Zones SET '.implode(', ', $changes).' WHERE MonitorId=? AND Id=?',
|
|
|
|
array($mid, $zone['Id']));
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
} // end foreach zone
|
|
|
|
} // end if width and height
|
2018-01-19 04:40:10 +08:00
|
|
|
$restart = true;
|
2018-08-31 22:35:23 +08:00
|
|
|
} else if ( ! $user['MonitorIds'] ) {
|
|
|
|
// Can only create new monitors if we are not restricted to specific monitors
|
2017-05-17 02:14:07 +08:00
|
|
|
# FIXME This is actually a race condition. Should lock the table.
|
2018-02-02 23:27:50 +08:00
|
|
|
$maxSeq = dbFetchOne('SELECT MAX(Sequence) AS MaxSequence FROM Monitors', 'MaxSequence');
|
2017-10-31 04:29:27 +08:00
|
|
|
$changes[] = 'Sequence = '.($maxSeq+1);
|
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( dbQuery('INSERT INTO Monitors SET '.implode(', ', $changes)) ) {
|
2018-01-30 02:41:09 +08:00
|
|
|
$mid = dbInsertId();
|
|
|
|
$zoneArea = $_REQUEST['newMonitor']['Width'] * $_REQUEST['newMonitor']['Height'];
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("INSERT INTO Zones SET MonitorId = ?, Name = 'All', Type = 'Active', Units = 'Percent', NumCoords = 4, Coords = ?, Area=?, AlarmRGB = 0xff0000, CheckMethod = 'Blobs', MinPixelThreshold = 25, MinAlarmPixels=?, MaxAlarmPixels=?, FilterX = 3, FilterY = 3, MinFilterPixels=?, MaxFilterPixels=?, MinBlobPixels=?, MinBlobs = 1", array( $mid, sprintf( "%d,%d %d,%d %d,%d %d,%d", 0, 0, $_REQUEST['newMonitor']['Width']-1, 0, $_REQUEST['newMonitor']['Width']-1, $_REQUEST['newMonitor']['Height']-1, 0, $_REQUEST['newMonitor']['Height']-1 ), $zoneArea, intval(($zoneArea*3)/100), intval(($zoneArea*75)/100), intval(($zoneArea*3)/100), intval(($zoneArea*75)/100), intval(($zoneArea*2)/100) ) );
|
2018-01-30 02:41:09 +08:00
|
|
|
//$view = 'none';
|
2018-08-31 22:35:23 +08:00
|
|
|
$Storage = new Storage($_REQUEST['newMonitor']['StorageId']);
|
|
|
|
mkdir($Storage->Path().'/'.$mid, 0755);
|
2018-01-30 02:41:09 +08:00
|
|
|
$saferName = basename($_REQUEST['newMonitor']['Name']);
|
2018-08-31 22:35:23 +08:00
|
|
|
symlink($mid, $Storage->Path().'/'.$saferName);
|
2018-02-28 03:19:44 +08:00
|
|
|
|
2018-01-30 02:41:09 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
Error('Error saving new Monitor.');
|
2018-01-30 02:41:09 +08:00
|
|
|
return;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
Error('Users with Monitors restrictions cannot create new monitors.');
|
2018-02-28 03:19:44 +08:00
|
|
|
return;
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2018-04-19 00:14:49 +08:00
|
|
|
|
2018-04-25 21:32:15 +08:00
|
|
|
$restart = true;
|
2018-06-12 04:34:40 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
Logger::Debug('No action due to no changes to Monitor');
|
2018-04-25 21:32:15 +08:00
|
|
|
} # end if count(changes)
|
2018-06-07 00:57:35 +08:00
|
|
|
|
|
|
|
if (
|
|
|
|
( !isset($_POST['newMonitor']['GroupIds']) )
|
|
|
|
or
|
|
|
|
( count($_POST['newMonitor']['GroupIds']) != count($Monitor->GroupIds()) )
|
|
|
|
or
|
|
|
|
array_diff($_POST['newMonitor']['GroupIds'], $Monitor->GroupIds())
|
|
|
|
) {
|
|
|
|
if ( $Monitor->Id() )
|
|
|
|
dbQuery('DELETE FROM Groups_Monitors WHERE MonitorId=?', array($mid));
|
|
|
|
|
|
|
|
if ( isset($_POST['newMonitor']['GroupIds']) ) {
|
|
|
|
foreach ( $_POST['newMonitor']['GroupIds'] as $group_id ) {
|
|
|
|
dbQuery('INSERT INTO Groups_Monitors (GroupId,MonitorId) VALUES (?,?)', array($group_id, $mid));
|
2018-02-28 03:19:44 +08:00
|
|
|
}
|
2018-06-07 00:57:35 +08:00
|
|
|
}
|
|
|
|
} // end if there has been a change of groups
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
if ( ZM_OPT_X10 ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$x10Changes = getFormChanges($x10Monitor, $_REQUEST['newX10Monitor']);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( count($x10Changes) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $x10Monitor && isset($_REQUEST['newX10Monitor']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE TriggersX10 SET '.implode(', ', $x10Changes).' WHERE MonitorId=?', array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
} elseif ( !$user['MonitorIds'] ) {
|
|
|
|
if ( !$x10Monitor ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('INSERT INTO TriggersX10 SET MonitorId = ?, '.implode(', ', $x10Changes), array($mid));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('DELETE FROM TriggersX10 WHERE MonitorId = ?', array($mid));
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$restart = true;
|
2018-08-31 22:35:23 +08:00
|
|
|
} # end if has x10Changes
|
|
|
|
} # end if ZM_OPT_X10
|
2017-05-17 02:14:07 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $restart ) {
|
2018-01-19 04:40:10 +08:00
|
|
|
|
|
|
|
$new_monitor = new Monitor($mid);
|
2017-10-31 04:29:27 +08:00
|
|
|
//fixDevices();
|
|
|
|
|
2018-04-27 05:18:36 +08:00
|
|
|
if ( $monitor['Type'] != 'WebSite' ) {
|
|
|
|
$new_monitor->zmcControl('start');
|
|
|
|
$new_monitor->zmaControl('start');
|
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-01-19 04:40:10 +08:00
|
|
|
if ( $new_monitor->Controllable() ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
require_once('control_functions.php');
|
|
|
|
sendControlCommand($mid, 'quit');
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
// really should thump zmwatch and maybe zmtrigger too.
|
|
|
|
//daemonControl( 'restart', 'zmwatch.pl' );
|
|
|
|
$refreshParent = true;
|
|
|
|
} // end if restart
|
|
|
|
$view = 'none';
|
|
|
|
} elseif ( $action == 'delete' ) {
|
|
|
|
if ( isset($_REQUEST['markMids']) && !$user['MonitorIds'] ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
require_once('Monitor.php');
|
|
|
|
foreach ( $_REQUEST['markMids'] as $markMid ) {
|
2018-03-21 03:18:07 +08:00
|
|
|
if ( canEdit('Monitors', $markMid) ) {
|
|
|
|
// This could be faster as a select all
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( $monitor = dbFetchOne('SELECT * FROM Monitors WHERE Id = ?', NULL, array($markMid)) ) {
|
2018-03-21 03:18:07 +08:00
|
|
|
$Monitor = new Monitor($monitor);
|
|
|
|
$Monitor->delete();
|
|
|
|
} // end if monitor found in db
|
2017-10-31 04:29:27 +08:00
|
|
|
} // end if canedit this monitor
|
|
|
|
} // end foreach monitor in MarkMid
|
|
|
|
} // markMids is set and we aren't limited to specific monitors
|
|
|
|
} // end if action == Delete
|
|
|
|
}
|
2017-05-17 02:14:07 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
// Device view actions
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( canEdit('Devices') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'device' ) {
|
|
|
|
if ( !empty($_REQUEST['command']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
setDeviceStatusX10($_REQUEST['key'], $_REQUEST['command']);
|
|
|
|
} else if ( isset($_REQUEST['newDevice']) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( isset($_REQUEST['did']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Devices SET Name=?, KeyString=? WHERE Id=?',
|
|
|
|
array($_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString'], $_REQUEST['did']) );
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('INSERT INTO Devices SET Name=?, KeyString=?',
|
|
|
|
array($_REQUEST['newDevice']['Name'], $_REQUEST['newDevice']['KeyString']) );
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
$refreshParent = true;
|
2017-05-17 02:14:07 +08:00
|
|
|
$view = 'none';
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
} elseif ( $action == 'delete' ) {
|
|
|
|
if ( isset($_REQUEST['markDids']) ) {
|
|
|
|
foreach( $_REQUEST['markDids'] as $markDid ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('DELETE FROM Devices WHERE Id=?', array($markDid));
|
2017-05-17 02:14:07 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
2015-08-16 02:22:13 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} // end if action
|
|
|
|
} // end if canedit devices
|
|
|
|
|
|
|
|
// Group view actions
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( canView('Groups') && ($action == 'setgroup') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( !empty($_REQUEST['gid']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
setcookie('zmGroup', validInt($_REQUEST['gid']), time()+3600*24*30*12*10);
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
setcookie('zmGroup', '', time()-3600*24*2);
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
// Group edit actions
|
2018-08-31 22:35:23 +08:00
|
|
|
# Should probably verify that each monitor id is a valid monitor, that we have access to.
|
|
|
|
# However at the moment, you have to have System permissions to do this
|
|
|
|
if ( canEdit('Groups') ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'group' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$monitors = empty($_POST['newGroup']['MonitorIds']) ? '' : implode(',', $_POST['newGroup']['MonitorIds']);
|
2017-12-05 11:02:56 +08:00
|
|
|
$group_id = null;
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( !empty($_POST['gid']) ) {
|
2017-12-05 11:02:56 +08:00
|
|
|
$group_id = $_POST['gid'];
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery(
|
|
|
|
'UPDATE Groups SET Name=?, ParentId=? WHERE Id=?',
|
|
|
|
array(
|
|
|
|
$_POST['newGroup']['Name'],
|
|
|
|
( $_POST['newGroup']['ParentId'] == '' ? null : $_POST['newGroup']['ParentId'] ),
|
|
|
|
$group_id,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
dbQuery('DELETE FROM Groups_Monitors WHERE GroupId=?', array($group_id));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery(
|
|
|
|
'INSERT INTO Groups (Name,ParentId) VALUES (?,?)',
|
|
|
|
array(
|
|
|
|
$_POST['newGroup']['Name'],
|
|
|
|
( $_POST['newGroup']['ParentId'] == '' ? null : $_POST['newGroup']['ParentId'] ),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$group_id = dbInsertId();
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2017-12-05 11:02:56 +08:00
|
|
|
if ( $group_id ) {
|
|
|
|
foreach ( $_POST['newGroup']['MonitorIds'] as $mid ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('INSERT INTO Groups_Monitors (GroupId,MonitorId) VALUES (?,?)', array($group_id, $mid));
|
2017-12-05 11:02:56 +08:00
|
|
|
}
|
2017-12-05 04:52:16 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$view = 'none';
|
|
|
|
$refreshParent = true;
|
|
|
|
} else if ( $action == 'delete' ) {
|
|
|
|
if ( !empty($_REQUEST['gid']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( is_array($_REQUEST['gid']) ) {
|
|
|
|
foreach ( $_REQUEST['gid'] as $gid ) {
|
|
|
|
$Group = new Group($gid);
|
2017-10-31 04:29:27 +08:00
|
|
|
$Group->delete();
|
|
|
|
}
|
2017-05-17 02:14:07 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
$Group = new Group($_REQUEST['gid'] );
|
2017-10-31 04:29:27 +08:00
|
|
|
$Group->delete();
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
$refreshParent = true;
|
|
|
|
} # end if action
|
|
|
|
} // end if can edit groups
|
|
|
|
|
|
|
|
// System edit actions
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( canEdit('System') ) {
|
|
|
|
if ( isset($_REQUEST['object']) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $_REQUEST['object'] == 'MontageLayout' ) {
|
|
|
|
require_once('MontageLayout.php');
|
|
|
|
if ( $action == 'Save' ) {
|
|
|
|
$Layout = null;
|
|
|
|
if ( $_REQUEST['Name'] != '' ) {
|
|
|
|
$Layout = new MontageLayout();
|
2018-08-31 22:35:23 +08:00
|
|
|
$Layout->Name($_REQUEST['Name']);
|
2017-10-10 22:38:13 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
$Layout = new MontageLayout($_REQUEST['zmMontageLayout']);
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
$Layout->Positions($_REQUEST['Positions']);
|
2017-10-31 04:29:27 +08:00
|
|
|
$Layout->save();
|
2017-11-02 00:19:27 +08:00
|
|
|
session_start();
|
|
|
|
$_SESSION['zmMontageLayout'] = $Layout->Id();
|
2018-08-31 22:35:23 +08:00
|
|
|
setcookie('zmMontageLayout', $Layout->Id(), 1);
|
2017-11-02 00:19:27 +08:00
|
|
|
session_write_close();
|
2018-08-01 04:46:36 +08:00
|
|
|
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=montage';
|
2017-10-31 04:29:27 +08:00
|
|
|
} // end if save
|
|
|
|
|
|
|
|
} else if ( $_REQUEST['object'] == 'server' ) {
|
|
|
|
|
|
|
|
if ( $action == 'Save' ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( !empty($_REQUEST['id']) ) {
|
|
|
|
$dbServer = dbFetchOne(
|
|
|
|
'SELECT * FROM Servers WHERE Id=?',
|
|
|
|
NULL,
|
|
|
|
array($_REQUEST['id']) );
|
|
|
|
} else {
|
2017-10-31 04:29:27 +08:00
|
|
|
$dbServer = array();
|
2018-08-31 22:35:23 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
$types = array();
|
2018-08-31 22:35:23 +08:00
|
|
|
$changes = getFormChanges($dbServer, $_REQUEST['newServer'], $types);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( count($changes) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( !empty($_REQUEST['id']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Servers SET '.implode(', ', $changes).' WHERE Id = ?',
|
|
|
|
array($_REQUEST['id']) );
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('INSERT INTO Servers SET '.implode(', ', $changes));
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
|
|
|
$refreshParent = true;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$view = 'none';
|
|
|
|
} else if ( $action == 'delete' ) {
|
|
|
|
if ( !empty($_REQUEST['markIds']) ) {
|
|
|
|
foreach( $_REQUEST['markIds'] as $Id )
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('DELETE FROM Servers WHERE Id=?', array($Id));
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
$refreshParent = true;
|
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
Error("Unknown action $action in saving Server");
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
} else if ( $_REQUEST['object'] == 'storage' ) {
|
|
|
|
if ( $action == 'Save' ) {
|
|
|
|
if ( !empty($_REQUEST['id']) )
|
2018-08-31 22:35:23 +08:00
|
|
|
$dbStorage = dbFetchOne('SELECT * FROM Storage WHERE Id=?', NULL, array($_REQUEST['id']));
|
2017-10-31 04:29:27 +08:00
|
|
|
else
|
|
|
|
$dbStorage = array();
|
|
|
|
|
|
|
|
$types = array();
|
2018-08-31 22:35:23 +08:00
|
|
|
$changes = getFormChanges($dbStorage, $_REQUEST['newStorage'], $types);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( count($changes) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( !empty($_REQUEST['id']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Storage SET '.implode(', ', $changes).' WHERE Id = ?', array($_REQUEST['id']));
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('INSERT INTO Storage set '.implode(', ', $changes));
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
|
|
|
$refreshParent = true;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$view = 'none';
|
|
|
|
} else if ( $action == 'delete' ) {
|
|
|
|
if ( !empty($_REQUEST['markIds']) ) {
|
|
|
|
foreach( $_REQUEST['markIds'] as $Id )
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('DELETE FROM Storage WHERE Id=?', array($Id));
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
$refreshParent = true;
|
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
Error("Unknown action $action in saving Storage");
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} # end if isset($_REQUEST['object'] )
|
|
|
|
|
|
|
|
} else if ( $action == 'version' && isset($_REQUEST['option']) ) {
|
|
|
|
$option = $_REQUEST['option'];
|
|
|
|
switch( $option ) {
|
|
|
|
case 'go' :
|
|
|
|
{
|
|
|
|
// Ignore this, the caller will open the page itself
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'ignore' :
|
|
|
|
{
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '".ZM_DYN_LAST_VERSION."' WHERE Name = 'ZM_DYN_CURR_VERSION'");
|
2017-10-31 04:29:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'hour' :
|
|
|
|
case 'day' :
|
|
|
|
case 'week' :
|
|
|
|
{
|
|
|
|
$nextReminder = time();
|
|
|
|
if ( $option == 'hour' ) {
|
|
|
|
$nextReminder += 60*60;
|
|
|
|
} elseif ( $option == 'day' ) {
|
|
|
|
$nextReminder += 24*60*60;
|
|
|
|
} elseif ( $option == 'week' ) {
|
|
|
|
$nextReminder += 7*24*60*60;
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '".$nextReminder."' WHERE Name = 'ZM_DYN_NEXT_REMINDER'");
|
2017-10-31 04:29:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'never' :
|
|
|
|
{
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_CHECK_FOR_UPDATES'");
|
2017-10-31 04:29:27 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
if ( $action == 'donate' && isset($_REQUEST['option']) ) {
|
|
|
|
$option = $_REQUEST['option'];
|
|
|
|
switch( $option ) {
|
|
|
|
case 'go' :
|
|
|
|
{
|
|
|
|
// Ignore this, the caller will open the page itself
|
|
|
|
break;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
case 'hour' :
|
|
|
|
case 'day' :
|
|
|
|
case 'week' :
|
|
|
|
case 'month' :
|
|
|
|
{
|
|
|
|
$nextReminder = time();
|
|
|
|
if ( $option == 'hour' ) {
|
|
|
|
$nextReminder += 60*60;
|
|
|
|
} elseif ( $option == 'day' ) {
|
|
|
|
$nextReminder += 24*60*60;
|
|
|
|
} elseif ( $option == 'week' ) {
|
|
|
|
$nextReminder += 7*24*60*60;
|
|
|
|
} elseif ( $option == 'month' ) {
|
|
|
|
$nextReminder += 30*24*60*60;
|
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '".$nextReminder."' WHERE Name = 'ZM_DYN_DONATE_REMINDER_TIME'");
|
2017-10-31 04:29:27 +08:00
|
|
|
break;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
case 'never' :
|
|
|
|
case 'already' :
|
|
|
|
{
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_DYN_SHOW_DONATE_REMINDER'");
|
2017-10-31 04:29:27 +08:00
|
|
|
break;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} // end switch option
|
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( ($action == 'privacy') && isset($_REQUEST['option']) ) {
|
|
|
|
switch( $_REQUEST['option'] ) {
|
2018-08-31 01:25:02 +08:00
|
|
|
case 'decline' :
|
|
|
|
{
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_SHOW_PRIVACY'");
|
|
|
|
dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_TELEMETRY_DATA'");
|
2018-08-31 01:25:02 +08:00
|
|
|
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=console';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'accept' :
|
|
|
|
{
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_SHOW_PRIVACY'");
|
|
|
|
dbQuery("UPDATE Config SET Value = '1' WHERE Name = 'ZM_TELEMETRY_DATA'");
|
2018-08-31 01:25:02 +08:00
|
|
|
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=console';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: # Enable the privacy statement if we somehow submit something other than accept or decline
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery("UPDATE Config SET Value = '1' WHERE Name = 'ZM_SHOW_PRIVACY'");
|
2018-08-31 01:25:02 +08:00
|
|
|
} // end switch option
|
2018-08-31 22:35:23 +08:00
|
|
|
return;
|
2018-08-31 01:25:02 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'options' && isset($_REQUEST['tab']) ) {
|
2018-10-25 21:13:07 +08:00
|
|
|
$config = array();
|
|
|
|
$configCat = array();
|
|
|
|
$configCats = array();
|
|
|
|
|
|
|
|
$result = $dbConn->query('SELECT * FROM Config ORDER BY Id ASC');
|
|
|
|
if ( !$result )
|
|
|
|
echo mysql_error();
|
|
|
|
while( $row = dbFetchNext($result) ) {
|
|
|
|
$config[$row['Name']] = $row;
|
|
|
|
if ( !($configCat = &$configCats[$row['Category']]) ) {
|
|
|
|
$configCats[$row['Category']] = array();
|
|
|
|
$configCat = &$configCats[$row['Category']];
|
|
|
|
}
|
|
|
|
$configCat[$row['Name']] = $row;
|
|
|
|
}
|
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
$configCat = $configCats[$_REQUEST['tab']];
|
|
|
|
$changed = false;
|
|
|
|
foreach ( $configCat as $name=>$value ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
unset($newValue);
|
2017-12-13 00:16:08 +08:00
|
|
|
if ( $value['Type'] == 'boolean' && empty($_REQUEST['newConfig'][$name]) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
$newValue = 0;
|
2017-12-13 00:16:08 +08:00
|
|
|
} else if ( isset($_REQUEST['newConfig'][$name]) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
$newValue = preg_replace("/\r\n/", "\n", stripslashes($_REQUEST['newConfig'][$name]));
|
2017-12-13 00:16:08 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
if ( isset($newValue) && ($newValue != $value['Value']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Config SET Value=? WHERE Name=?', array($newValue, $name));
|
2017-10-31 04:29:27 +08:00
|
|
|
$changed = true;
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
|
|
|
if ( $changed ) {
|
|
|
|
switch( $_REQUEST['tab'] ) {
|
|
|
|
case 'system' :
|
|
|
|
case 'config' :
|
|
|
|
$restartWarning = true;
|
|
|
|
break;
|
|
|
|
case 'web' :
|
|
|
|
case 'tools' :
|
|
|
|
break;
|
|
|
|
case 'logging' :
|
|
|
|
case 'network' :
|
|
|
|
case 'mail' :
|
|
|
|
case 'upload' :
|
|
|
|
$restartWarning = true;
|
|
|
|
break;
|
|
|
|
case 'highband' :
|
|
|
|
case 'medband' :
|
|
|
|
case 'lowband' :
|
|
|
|
break;
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2018-01-29 04:13:57 +08:00
|
|
|
$redirect = ZM_BASE_URL.$_SERVER['PHP_SELF'].'?view=options&tab='.$_REQUEST['tab'];
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
loadConfig(false);
|
|
|
|
return;
|
2017-10-31 04:29:27 +08:00
|
|
|
} elseif ( $action == 'user' ) {
|
|
|
|
if ( !empty($_REQUEST['uid']) )
|
2018-08-31 22:35:23 +08:00
|
|
|
$dbUser = dbFetchOne('SELECT * FROM Users WHERE Id=?', NULL, array($_REQUEST['uid']));
|
2017-10-31 04:29:27 +08:00
|
|
|
else
|
|
|
|
$dbUser = array();
|
|
|
|
|
|
|
|
$types = array();
|
2018-08-31 22:35:23 +08:00
|
|
|
$changes = getFormChanges($dbUser, $_REQUEST['newUser'], $types);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
if ( $_REQUEST['newUser']['Password'] )
|
2017-12-07 23:31:25 +08:00
|
|
|
$changes['Password'] = 'Password = password('.dbEscape($_REQUEST['newUser']['Password']).')';
|
2017-10-31 04:29:27 +08:00
|
|
|
else
|
2018-08-31 22:35:23 +08:00
|
|
|
unset($changes['Password']);
|
2017-10-31 04:29:27 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
if ( count($changes) ) {
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( !empty($_REQUEST['uid']) ) {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('UPDATE Users SET '.implode(', ', $changes).' WHERE Id = ?', array($_REQUEST['uid']));
|
2017-10-31 04:29:27 +08:00
|
|
|
# If we are updating the logged in user, then update our session user data.
|
|
|
|
if ( $user and ( $dbUser['Username'] == $user['Username'] ) )
|
2018-08-31 22:35:23 +08:00
|
|
|
userLogin($dbUser['Username'], $dbUser['Password']);
|
2017-10-31 04:29:27 +08:00
|
|
|
} else {
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('INSERT INTO Users SET '.implode(', ', $changes));
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
|
|
|
$view = 'none';
|
|
|
|
} elseif ( $action == 'state' ) {
|
|
|
|
if ( !empty($_REQUEST['runState']) ) {
|
|
|
|
//if ( $cookies ) session_write_close();
|
2018-08-31 22:35:23 +08:00
|
|
|
packageControl($_REQUEST['runState']);
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
|
|
|
}
|
|
|
|
} elseif ( $action == 'save' ) {
|
|
|
|
if ( !empty($_REQUEST['runState']) || !empty($_REQUEST['newState']) ) {
|
|
|
|
$sql = 'SELECT Id,Function,Enabled FROM Monitors ORDER BY Id';
|
|
|
|
$definitions = array();
|
2018-08-31 22:35:23 +08:00
|
|
|
foreach( dbFetchAll($sql) as $monitor ) {
|
2017-12-07 23:31:25 +08:00
|
|
|
$definitions[] = $monitor['Id'].':'.$monitor['Function'].':'.$monitor['Enabled'];
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2018-08-31 22:35:23 +08:00
|
|
|
$definition = join(',', $definitions);
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $_REQUEST['newState'] )
|
|
|
|
$_REQUEST['runState'] = $_REQUEST['newState'];
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('REPLACE INTO States SET Name=?, Definition=?', array($_REQUEST['runState'],$definition));
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
} elseif ( $action == 'delete' ) {
|
|
|
|
if ( isset($_REQUEST['runState']) )
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('DELETE FROM States WHERE Name=?', array($_REQUEST['runState']));
|
2017-10-31 04:29:27 +08:00
|
|
|
|
|
|
|
if ( isset($_REQUEST['markUids']) ) {
|
|
|
|
foreach( $_REQUEST['markUids'] as $markUid )
|
2018-08-31 22:35:23 +08:00
|
|
|
dbQuery('DELETE FROM Users WHERE Id = ?', array($markUid));
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $markUid == $user['Id'] )
|
|
|
|
userLogout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( ZM_USER_SELF_EDIT && $action == 'user' ) {
|
|
|
|
$uid = $user['Id'];
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2018-08-31 22:35:23 +08:00
|
|
|
$dbUser = dbFetchOne('SELECT Id, Password, Language FROM Users WHERE Id = ?', NULL, array($uid));
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
$types = array();
|
2018-08-31 22:35:23 +08:00
|
|
|
$changes = getFormChanges($dbUser, $_REQUEST['newUser'], $types);
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( !empty($_REQUEST['newUser']['Password']) )
|
2017-12-07 23:31:25 +08:00
|
|
|
$changes['Password'] = 'Password = password('.dbEscape($_REQUEST['newUser']['Password']).')';
|
2017-10-31 04:29:27 +08:00
|
|
|
else
|
2018-08-31 22:35:23 +08:00
|
|
|
unset($changes['Password']);
|
|
|
|
if ( count($changes) ) {
|
|
|
|
dbQuery('UPDATE Users SET '.implode(', ', $changes).' WHERE Id=?', array($uid));
|
2017-10-31 04:29:27 +08:00
|
|
|
$refreshParent = true;
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
$view = 'none';
|
2017-05-17 02:14:07 +08:00
|
|
|
}
|
2017-10-31 04:29:27 +08:00
|
|
|
}
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2017-10-31 04:29:27 +08:00
|
|
|
if ( $action == 'reset' ) {
|
2018-03-21 03:18:07 +08:00
|
|
|
session_start();
|
2018-08-31 22:35:23 +08:00
|
|
|
$_SESSION['zmEventResetTime'] = strftime(STRF_FMT_DATETIME_DB);
|
|
|
|
setcookie('zmEventResetTime', $_SESSION['zmEventResetTime'], time()+3600*24*30*12*10);
|
2018-03-21 03:18:07 +08:00
|
|
|
session_write_close();
|
2013-03-17 07:45:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|