fix spacing/quotes/google code style
This commit is contained in:
parent
f07b1105d3
commit
dc57a3c91c
|
@ -66,23 +66,24 @@ class AppController extends Controller {
|
|||
$config = $this->Config->find('first', $options);
|
||||
$zmOptApi = $config['Config']['Value'];
|
||||
|
||||
if ($zmOptApi !='1') {
|
||||
if ( $zmOptApi != '1' ) {
|
||||
throw new UnauthorizedException(__('API Disabled'));
|
||||
return;
|
||||
}
|
||||
// We need to reject methods that are not authenticated
|
||||
// besides login and logout
|
||||
if ( strcasecmp($this->params->action, "login") &&
|
||||
strcasecmp($this->params->action,"logout")) {
|
||||
if (!$this->Session->read('user.Username')) {
|
||||
throw new UnauthorizedException(__('Not Authenticated'));
|
||||
return;
|
||||
} else if (!$this->Session->read('user.Enabled')) {
|
||||
throw new UnauthorizedException(__('User is not enabled'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
strcasecmp($this->params->action, 'login')
|
||||
&&
|
||||
strcasecmp($this->params->action,"logout")
|
||||
) {
|
||||
if ( !$this->Session->read('user.Username') ) {
|
||||
throw new UnauthorizedException(__('Not Authenticated'));
|
||||
return;
|
||||
} else if ( !$this->Session->read('user.Enabled') ) {
|
||||
throw new UnauthorizedException(__('User is not enabled'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} # end function beforeFilter()
|
||||
}
|
||||
|
|
|
@ -7,61 +7,61 @@ App::uses('AppController', 'Controller');
|
|||
*/
|
||||
class EventsController extends AppController {
|
||||
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('RequestHandler', 'Scaler', 'Image', 'Paginator');
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('RequestHandler', 'Scaler', 'Image', 'Paginator');
|
||||
|
||||
public function beforeFilter() {
|
||||
parent::beforeFilter();
|
||||
$canView = $this->Session->Read('eventPermission');
|
||||
if ($canView =='None') {
|
||||
if ( $canView == 'None' ) {
|
||||
throw new UnauthorizedException(__('Insufficient Privileges'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* index method
|
||||
*
|
||||
* @return void
|
||||
* This also creates a thumbnail for each event.
|
||||
*/
|
||||
public function index() {
|
||||
$this->Event->recursive = -1;
|
||||
|
||||
$allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY);
|
||||
/**
|
||||
* index method
|
||||
*
|
||||
* @return void
|
||||
* This also creates a thumbnail for each event.
|
||||
*/
|
||||
public function index() {
|
||||
$this->Event->recursive = -1;
|
||||
|
||||
if (!empty($allowedMonitors)) {
|
||||
$allowedMonitors = preg_split('@,@', $this->Session->Read('allowedMonitors'), NULL, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
if ( !empty($allowedMonitors) ) {
|
||||
$mon_options = array('Event.MonitorId' => $allowedMonitors);
|
||||
} else {
|
||||
$mon_options='';
|
||||
$mon_options = '';
|
||||
}
|
||||
|
||||
if ($this->request->params['named']) {
|
||||
//$this->FilterComponent = $this->Components->load('Filter');
|
||||
//$conditions = $this->FilterComponent->buildFilter($this->request->params['named']);
|
||||
if ( $this->request->params['named'] ) {
|
||||
//$this->FilterComponent = $this->Components->load('Filter');
|
||||
//$conditions = $this->FilterComponent->buildFilter($this->request->params['named']);
|
||||
$conditions = $this->request->params['named'];
|
||||
} else {
|
||||
$conditions = array();
|
||||
}
|
||||
} else {
|
||||
$conditions = array();
|
||||
}
|
||||
$settings = array(
|
||||
// https://github.com/ZoneMinder/ZoneMinder/issues/995
|
||||
// 'limit' => $limit['ZM_WEB_EVENTS_PER_PAGE'],
|
||||
// 25 events per page which is what the above
|
||||
// default is, is way too low for an API
|
||||
// changing this to 100 so we don't kill ZM
|
||||
// with many event APIs. In future, we can
|
||||
// make a nice ZM_API_ITEMS_PER_PAGE for all pagination
|
||||
// API
|
||||
|
||||
'limit' => '100',
|
||||
'order' => array('StartTime'),
|
||||
'paramType' => 'querystring',
|
||||
// https://github.com/ZoneMinder/ZoneMinder/issues/995
|
||||
// 'limit' => $limit['ZM_WEB_EVENTS_PER_PAGE'],
|
||||
// 25 events per page which is what the above
|
||||
// default is, is way too low for an API
|
||||
// changing this to 100 so we don't kill ZM
|
||||
// with many event APIs. In future, we can
|
||||
// make a nice ZM_API_ITEMS_PER_PAGE for all pagination
|
||||
// API
|
||||
|
||||
'limit' => '100',
|
||||
'order' => array('StartTime'),
|
||||
'paramType' => 'querystring',
|
||||
);
|
||||
if ( isset( $conditions['GroupId'] ) ) {
|
||||
if ( isset($conditions['GroupId']) ) {
|
||||
$settings['joins'] = array(
|
||||
array(
|
||||
'table' => 'Groups_Monitors',
|
||||
|
@ -75,45 +75,45 @@ class EventsController extends AppController {
|
|||
}
|
||||
$settings['conditions'] = array($conditions, $mon_options);
|
||||
|
||||
// How many events to return
|
||||
$this->loadModel('Config');
|
||||
$limit = $this->Config->find('list', array(
|
||||
'conditions' => array('Name' => 'ZM_WEB_EVENTS_PER_PAGE'),
|
||||
'fields' => array('Name', 'Value')
|
||||
));
|
||||
$this->Paginator->settings = $settings;
|
||||
$events = $this->Paginator->paginate('Event');
|
||||
// How many events to return
|
||||
$this->loadModel('Config');
|
||||
$limit = $this->Config->find('list', array(
|
||||
'conditions' => array('Name' => 'ZM_WEB_EVENTS_PER_PAGE'),
|
||||
'fields' => array('Name', 'Value')
|
||||
));
|
||||
$this->Paginator->settings = $settings;
|
||||
$events = $this->Paginator->paginate('Event');
|
||||
|
||||
// For each event, get the frameID which has the largest score
|
||||
foreach ($events as $key => $value) {
|
||||
$maxScoreFrameId = $this->getMaxScoreAlarmFrameId($value['Event']['Id']);
|
||||
$events[$key]['Event']['MaxScoreFrameId'] = $maxScoreFrameId;
|
||||
}
|
||||
// For each event, get the frameID which has the largest score
|
||||
foreach ($events as $key => $value) {
|
||||
$maxScoreFrameId = $this->getMaxScoreAlarmFrameId($value['Event']['Id']);
|
||||
$events[$key]['Event']['MaxScoreFrameId'] = $maxScoreFrameId;
|
||||
}
|
||||
|
||||
$this->set(compact('events'));
|
||||
}
|
||||
$this->set(compact('events'));
|
||||
}
|
||||
|
||||
/**
|
||||
* view method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function view($id = null) {
|
||||
/**
|
||||
* view method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function view($id = null) {
|
||||
$this->loadModel('Config');
|
||||
|
||||
$this->Event->recursive = 1;
|
||||
if (!$this->Event->exists($id)) {
|
||||
if ( !$this->Event->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid event'));
|
||||
}
|
||||
|
||||
$allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY);
|
||||
$allowedMonitors = preg_split('@,@', $this->Session->Read('allowedMonitors'), NULL, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
if (!empty($allowedMonitors)) {
|
||||
if ( !empty($allowedMonitors) ) {
|
||||
$mon_options = array('Event.MonitorId' => $allowedMonitors);
|
||||
} else {
|
||||
$mon_options='';
|
||||
$mon_options = '';
|
||||
}
|
||||
|
||||
$options = array('conditions' => array(array('Event.' . $this->Event->primaryKey => $id), $mon_options));
|
||||
|
@ -149,14 +149,14 @@ class EventsController extends AppController {
|
|||
*/
|
||||
public function add() {
|
||||
|
||||
if ($this->Session->Read('eventPermission') != 'Edit') {
|
||||
if ( $this->Session->Read('eventPermission') != 'Edit' ) {
|
||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->request->is('post')) {
|
||||
if ( $this->request->is('post') ) {
|
||||
$this->Event->create();
|
||||
if ($this->Event->save($this->request->data)) {
|
||||
if ( $this->Event->save($this->request->data) ) {
|
||||
return $this->flash(__('The event has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
|
@ -173,18 +173,18 @@ class EventsController extends AppController {
|
|||
*/
|
||||
public function edit($id = null) {
|
||||
|
||||
if ($this->Session->Read('eventPermission') != 'Edit') {
|
||||
if ( $this->Session->Read('eventPermission') != 'Edit' ) {
|
||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->Event->id = $id;
|
||||
|
||||
if (!$this->Event->exists($id)) {
|
||||
if ( !$this->Event->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid event'));
|
||||
}
|
||||
|
||||
if ($this->Event->save($this->request->data)) {
|
||||
if ( $this->Event->save($this->request->data) ) {
|
||||
$message = 'Saved';
|
||||
} else {
|
||||
$message = 'Error';
|
||||
|
@ -204,16 +204,16 @@ class EventsController extends AppController {
|
|||
* @return void
|
||||
*/
|
||||
public function delete($id = null) {
|
||||
if ($this->Session->Read('eventPermission') != 'Edit') {
|
||||
if ( $this->Session->Read('eventPermission') != 'Edit' ) {
|
||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||
return;
|
||||
}
|
||||
$this->Event->id = $id;
|
||||
if (!$this->Event->exists()) {
|
||||
if ( !$this->Event->exists() ) {
|
||||
throw new NotFoundException(__('Invalid event'));
|
||||
}
|
||||
$this->request->allowMethod('post', 'delete');
|
||||
if ($this->Event->delete()) {
|
||||
if ( $this->Event->delete() ) {
|
||||
//$this->loadModel('Frame');
|
||||
//$this->Event->Frame->delete();
|
||||
return $this->flash(__('The event has been deleted.'), array('action' => 'index'));
|
||||
|
@ -228,7 +228,7 @@ class EventsController extends AppController {
|
|||
|
||||
foreach ($this->params['named'] as $param_name => $value) {
|
||||
// Transform params into mysql
|
||||
if (preg_match("/interval/i", $value, $matches)) {
|
||||
if ( preg_match('/interval/i', $value, $matches) ) {
|
||||
$condition = array("$param_name >= (date_sub(now(), $value))");
|
||||
} else {
|
||||
$condition = array($param_name => $value);
|
||||
|
@ -254,9 +254,9 @@ class EventsController extends AppController {
|
|||
$this->Event->recursive = -1;
|
||||
$results = array();
|
||||
|
||||
$moreconditions ="";
|
||||
$moreconditions = '';
|
||||
foreach ($this->request->params['named'] as $name => $param) {
|
||||
$moreconditions = $moreconditions . " AND ".$name.$param;
|
||||
$moreconditions = $moreconditions . ' AND '.$name.$param;
|
||||
}
|
||||
|
||||
$query = $this->Event->query("select MonitorId, COUNT(*) AS Count from Events WHERE (StartTime >= (DATE_SUB(NOW(), interval $interval)) $moreconditions) GROUP BY MonitorId;");
|
||||
|
@ -275,7 +275,7 @@ class EventsController extends AppController {
|
|||
public function createThumbnail($id = null) {
|
||||
$this->Event->recursive = -1;
|
||||
|
||||
if (!$this->Event->exists($id)) {
|
||||
if ( !$this->Event->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid event'));
|
||||
}
|
||||
|
||||
|
@ -285,13 +285,13 @@ class EventsController extends AppController {
|
|||
|
||||
// Find the max Frame for this Event. Error out otherwise.
|
||||
$this->loadModel('Frame');
|
||||
if (! $frame = $this->Frame->find('first', array(
|
||||
if ( !( $frame = $this->Frame->find('first', array(
|
||||
'conditions' => array(
|
||||
'EventId' => $event['Event']['Id'],
|
||||
'Score' => $event['Event']['MaxScore']
|
||||
)
|
||||
))) {
|
||||
throw new NotFoundException(__("Can not find Frame for Event " . $event['Event']['Id']));
|
||||
))) ) {
|
||||
throw new NotFoundException(__('Can not find Frame for Event ' . $event['Event']['Id']));
|
||||
}
|
||||
|
||||
$this->loadModel('Config');
|
||||
|
@ -304,14 +304,15 @@ class EventsController extends AppController {
|
|||
|
||||
$config = $this->Config->find('list', array(
|
||||
'conditions' => array('OR' => array(
|
||||
'Name' => array('ZM_WEB_LIST_THUMB_WIDTH',
|
||||
'ZM_WEB_LIST_THUMB_HEIGHT',
|
||||
'ZM_EVENT_IMAGE_DIGITS',
|
||||
'ZM_DIR_IMAGES',
|
||||
$thumbs,
|
||||
'ZM_DIR_EVENTS'
|
||||
)
|
||||
)),
|
||||
'Name' => array(
|
||||
'ZM_WEB_LIST_THUMB_WIDTH',
|
||||
'ZM_WEB_LIST_THUMB_HEIGHT',
|
||||
'ZM_EVENT_IMAGE_DIGITS',
|
||||
'ZM_DIR_IMAGES',
|
||||
$thumbs,
|
||||
'ZM_DIR_EVENTS'
|
||||
)
|
||||
)),
|
||||
'fields' => array('Name', 'Value')
|
||||
));
|
||||
$config['ZM_WEB_SCALE_THUMBS'] = $config[$thumbs];
|
||||
|
@ -340,7 +341,7 @@ class EventsController extends AppController {
|
|||
|
||||
public function archive($id = null) {
|
||||
$this->Event->recursive = -1;
|
||||
if (!$this->Event->exists($id)) {
|
||||
if ( !$this->Event->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid event'));
|
||||
}
|
||||
|
||||
|
@ -365,7 +366,7 @@ class EventsController extends AppController {
|
|||
public function getMaxScoreAlarmFrameId($id = null) {
|
||||
$this->Event->recursive = -1;
|
||||
|
||||
if (!$this->Event->exists($id)) {
|
||||
if ( !$this->Event->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid event'));
|
||||
}
|
||||
|
||||
|
@ -382,7 +383,7 @@ class EventsController extends AppController {
|
|||
'Score' => $event['Event']['MaxScore']
|
||||
)
|
||||
))) {
|
||||
throw new NotFoundException(__("Can not find Frame for Event " . $event['Event']['Id']));
|
||||
throw new NotFoundException(__('Can not find Frame for Event ' . $event['Event']['Id']));
|
||||
}
|
||||
return $frame['Frame']['Id'];
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ class MonitorsController extends AppController {
|
|||
public function beforeRender() {
|
||||
$this->set($this->Monitor->enumValues());
|
||||
}
|
||||
|
||||
public function beforeFilter() {
|
||||
parent::beforeFilter();
|
||||
$canView = $this->Session->Read('monitorPermission');
|
||||
|
@ -35,7 +36,7 @@ class MonitorsController extends AppController {
|
|||
public function index() {
|
||||
$this->Monitor->recursive = 0;
|
||||
|
||||
if ($this->request->params['named']) {
|
||||
if ( $this->request->params['named'] ) {
|
||||
$this->FilterComponent = $this->Components->load('Filter');
|
||||
//$conditions = $this->FilterComponent->buildFilter($this->request->params['named']);
|
||||
$conditions = $this->request->params['named'];
|
||||
|
@ -49,7 +50,7 @@ class MonitorsController extends AppController {
|
|||
}
|
||||
$find_array = array('conditions'=>$conditions,'contain'=>array('Group'));
|
||||
|
||||
if ( isset( $conditions['GroupId'] ) ) {
|
||||
if ( isset($conditions['GroupId']) ) {
|
||||
$find_array['joins'] = array(
|
||||
array(
|
||||
'table' => 'Groups_Monitors',
|
||||
|
@ -84,11 +85,11 @@ class MonitorsController extends AppController {
|
|||
*/
|
||||
public function view($id = null) {
|
||||
$this->Monitor->recursive = 0;
|
||||
if (!$this->Monitor->exists($id)) {
|
||||
if ( !$this->Monitor->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid monitor'));
|
||||
}
|
||||
$allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY);
|
||||
if (!empty($allowedMonitors)) {
|
||||
$allowedMonitors=preg_split('@,@', $this->Session->Read('allowedMonitors'), NULL, PREG_SPLIT_NO_EMPTY);
|
||||
if ( !empty($allowedMonitors) ) {
|
||||
$restricted = array('Monitor.' . $this->Monitor->primaryKey => $allowedMonitors);
|
||||
} else {
|
||||
$restricted = '';
|
||||
|
@ -115,12 +116,12 @@ class MonitorsController extends AppController {
|
|||
if ( $this->request->is('post') ) {
|
||||
|
||||
if ( $this->Session->Read('systemPermission') != 'Edit' ) {
|
||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->Monitor->create();
|
||||
if ($this->Monitor->save($this->request->data)) {
|
||||
if ( $this->Monitor->save($this->request->data) ) {
|
||||
$this->daemonControl($this->Monitor->id, 'start');
|
||||
//return $this->flash(__('The monitor has been saved.'), array('action' => 'index'));
|
||||
$message = 'Saved';
|
||||
|
@ -144,10 +145,10 @@ class MonitorsController extends AppController {
|
|||
public function edit($id = null) {
|
||||
$this->Monitor->id = $id;
|
||||
|
||||
if (!$this->Monitor->exists($id)) {
|
||||
if ( !$this->Monitor->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid monitor'));
|
||||
}
|
||||
if ($this->Session->Read('monitorPermission') != 'Edit') {
|
||||
if ( $this->Session->Read('monitorPermission') != 'Edit' ) {
|
||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||
return;
|
||||
}
|
||||
|
@ -163,9 +164,17 @@ class MonitorsController extends AppController {
|
|||
// - restart or stop this monitor after change
|
||||
$func = $Monitor['Function'];
|
||||
// We don't pass the request data as the monitor object because it may be a subset of the full monitor array
|
||||
$this->daemonControl( $this->Monitor->id, 'stop' );
|
||||
if ( ( $func != 'None' ) and ( (!defined('ZM_SERVER_ID')) or ($Monitor['ServerId']==ZM_SERVER_ID) ) ) {
|
||||
$this->daemonControl( $this->Monitor->id, 'start' );
|
||||
$this->daemonControl($this->Monitor->id, 'stop');
|
||||
if (
|
||||
( $func != 'None' )
|
||||
and
|
||||
(
|
||||
(!defined('ZM_SERVER_ID'))
|
||||
or
|
||||
($Monitor['ServerId']==ZM_SERVER_ID)
|
||||
)
|
||||
) {
|
||||
$this->daemonControl($this->Monitor->id, 'start');
|
||||
}
|
||||
} else {
|
||||
$message = 'Error ' . print_r($this->Monitor->invalidFields(), true);
|
||||
|
@ -187,10 +196,10 @@ class MonitorsController extends AppController {
|
|||
*/
|
||||
public function delete($id = null) {
|
||||
$this->Monitor->id = $id;
|
||||
if (!$this->Monitor->exists()) {
|
||||
if ( !$this->Monitor->exists() ) {
|
||||
throw new NotFoundException(__('Invalid monitor'));
|
||||
}
|
||||
if ($this->Session->Read('systemPermission') != 'Edit') {
|
||||
if ( $this->Session->Read('systemPermission') != 'Edit' ) {
|
||||
throw new UnauthorizedException(__('Insufficient privileges'));
|
||||
return;
|
||||
}
|
||||
|
@ -198,7 +207,7 @@ class MonitorsController extends AppController {
|
|||
|
||||
$this->daemonControl($this->Monitor->id, 'stop');
|
||||
|
||||
if ($this->Monitor->delete()) {
|
||||
if ( $this->Monitor->delete() ) {
|
||||
return $this->flash(__('The monitor has been deleted.'), array('action' => 'index'));
|
||||
} else {
|
||||
return $this->flash(__('The monitor could not be deleted. Please, try again.'), array('action' => 'index'));
|
||||
|
@ -226,7 +235,7 @@ class MonitorsController extends AppController {
|
|||
public function alarm() {
|
||||
$id = $this->request->params['named']['id'];
|
||||
$cmd = strtolower($this->request->params['named']['command']);
|
||||
if (!$this->Monitor->exists($id)) {
|
||||
if ( !$this->Monitor->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid monitor'));
|
||||
}
|
||||
if ( $cmd != 'on' && $cmd != 'off' && $cmd != 'status' ) {
|
||||
|
@ -252,19 +261,19 @@ class MonitorsController extends AppController {
|
|||
// form auth key based on auth credentials
|
||||
$this->loadModel('Config');
|
||||
$options = array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_OPT_USE_AUTH'));
|
||||
$config = $this->Config->find('first', $options);
|
||||
$config = $this->Config->find('first', $options);
|
||||
$zmOptAuth = $config['Config']['Value'];
|
||||
|
||||
|
||||
$options = array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_RELAY'));
|
||||
$config = $this->Config->find('first', $options);
|
||||
$config = $this->Config->find('first', $options);
|
||||
$zmAuthRelay = $config['Config']['Value'];
|
||||
|
||||
$auth='';
|
||||
$auth = '';
|
||||
if ( $zmOptAuth ) {
|
||||
if ( $zmAuthRelay == 'hashed' ) {
|
||||
$options = array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_HASH_SECRET'));
|
||||
$config = $this->Config->find('first', $options);
|
||||
$config = $this->Config->find('first', $options);
|
||||
$zmAuthHashSecret = $config['Config']['Value'];
|
||||
|
||||
$time = localtime();
|
||||
|
@ -293,7 +302,7 @@ class MonitorsController extends AppController {
|
|||
$id = $this->request->params['named']['id'];
|
||||
$daemon = $this->request->params['named']['daemon'];
|
||||
|
||||
if (!$this->Monitor->exists($id)) {
|
||||
if ( !$this->Monitor->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid monitor'));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,92 +8,93 @@ App::uses('AppController', 'Controller');
|
|||
*/
|
||||
class ZonePresetsController extends AppController {
|
||||
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('RequestHandler');
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('RequestHandler');
|
||||
|
||||
/**
|
||||
* index method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index() {
|
||||
$zonePresets = $this->ZonePreset->find('all');
|
||||
$this->set(array(
|
||||
'zonePresets' => $zonePresets,
|
||||
'_serialize' => array('zonePresets')
|
||||
));
|
||||
}
|
||||
/**
|
||||
* index method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index() {
|
||||
$zonePresets = $this->ZonePreset->find('all');
|
||||
$this->set(array(
|
||||
'zonePresets' => $zonePresets,
|
||||
'_serialize' => array('zonePresets')
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* view method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function view($id = null) {
|
||||
if (!$this->ZonePreset->exists($id)) {
|
||||
throw new NotFoundException(__('Invalid zone preset'));
|
||||
}
|
||||
$options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id));
|
||||
$this->set('zonePreset', $this->ZonePreset->find('first', $options));
|
||||
}
|
||||
/**
|
||||
* view method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function view($id = null) {
|
||||
if ( !$this->ZonePreset->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid zone preset'));
|
||||
}
|
||||
$options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id));
|
||||
$this->set('zonePreset', $this->ZonePreset->find('first', $options));
|
||||
}
|
||||
|
||||
/**
|
||||
* add method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add() {
|
||||
if ($this->request->is('post')) {
|
||||
$this->ZonePreset->create();
|
||||
if ($this->ZonePreset->save($this->request->data)) {
|
||||
return $this->flash(__('The zone preset has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* add method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add() {
|
||||
if ( $this->request->is('post') ) {
|
||||
$this->ZonePreset->create();
|
||||
if ( $this->ZonePreset->save($this->request->data) ) {
|
||||
return $this->flash(__('The zone preset has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* edit method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function edit($id = null) {
|
||||
if (!$this->ZonePreset->exists($id)) {
|
||||
throw new NotFoundException(__('Invalid zone preset'));
|
||||
}
|
||||
if ($this->request->is(array('post', 'put'))) {
|
||||
if ($this->ZonePreset->save($this->request->data)) {
|
||||
return $this->flash(__('The zone preset has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
} else {
|
||||
$options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id));
|
||||
$this->request->data = $this->ZonePreset->find('first', $options);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* edit method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function edit($id = null) {
|
||||
if ( !$this->ZonePreset->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid zone preset'));
|
||||
}
|
||||
if ( $this->request->is(array('post', 'put')) ) {
|
||||
if ( $this->ZonePreset->save($this->request->data) ) {
|
||||
return $this->flash(__('The zone preset has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
} else {
|
||||
$options = array('conditions' => array('ZonePreset.' . $this->ZonePreset->primaryKey => $id));
|
||||
$this->request->data = $this->ZonePreset->find('first', $options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* delete method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id = null) {
|
||||
$this->ZonePreset->id = $id;
|
||||
if (!$this->ZonePreset->exists()) {
|
||||
throw new NotFoundException(__('Invalid zone preset'));
|
||||
}
|
||||
$this->request->allowMethod('post', 'delete');
|
||||
if ($this->ZonePreset->delete()) {
|
||||
return $this->flash(__('The zone preset has been deleted.'), array('action' => 'index'));
|
||||
} else {
|
||||
return $this->flash(__('The zone preset could not be deleted. Please, try again.'), array('action' => 'index'));
|
||||
}
|
||||
}}
|
||||
/**
|
||||
* delete method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id = null) {
|
||||
$this->ZonePreset->id = $id;
|
||||
if ( !$this->ZonePreset->exists() ) {
|
||||
throw new NotFoundException(__('Invalid zone preset'));
|
||||
}
|
||||
$this->request->allowMethod('post', 'delete');
|
||||
if ( $this->ZonePreset->delete() ) {
|
||||
return $this->flash(__('The zone preset has been deleted.'), array('action' => 'index'));
|
||||
} else {
|
||||
return $this->flash(__('The zone preset could not be deleted. Please, try again.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
} // end class ZonePresetsController
|
||||
|
|
|
@ -7,148 +7,141 @@ App::uses('AppController', 'Controller');
|
|||
*/
|
||||
class ZonesController extends AppController {
|
||||
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('RequestHandler');
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $components = array('RequestHandler');
|
||||
|
||||
public function beforeFilter() {
|
||||
parent::beforeFilter();
|
||||
$canView = $this->Session->Read('monitorPermission');
|
||||
if ($canView =='None')
|
||||
{
|
||||
throw new UnauthorizedException(__('Insufficient Privileges'));
|
||||
return;
|
||||
}
|
||||
public function beforeFilter() {
|
||||
parent::beforeFilter();
|
||||
$canView = $this->Session->Read('monitorPermission');
|
||||
if ( $canView =='None' ) {
|
||||
throw new UnauthorizedException(__('Insufficient Privileges'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Find all zones which belong to a MonitorId
|
||||
public function forMonitor($id = null) {
|
||||
// Find all zones which belong to a MonitorId
|
||||
public function forMonitor($id = null) {
|
||||
$this->loadModel('Monitor');
|
||||
if (!$this->Monitor->exists($id)) {
|
||||
throw new NotFoundException(__('Invalid monitor'));
|
||||
if ( !$this->Monitor->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid monitor'));
|
||||
}
|
||||
$this->Zone->recursive = -1;
|
||||
$zones = $this->Zone->find('all', array(
|
||||
'conditions' => array('MonitorId' => $id)
|
||||
'conditions' => array('MonitorId' => $id)
|
||||
));
|
||||
$this->set(array(
|
||||
'zones' => $zones,
|
||||
'_serialize' => array('zones')
|
||||
'zones' => $zones,
|
||||
'_serialize' => array('zones')
|
||||
));
|
||||
}
|
||||
public function index() {
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$this->Zone->recursive = -1;
|
||||
|
||||
$allowedMonitors=preg_split ('@,@', $this->Session->Read('allowedMonitors'),NULL, PREG_SPLIT_NO_EMPTY);
|
||||
if (!empty($allowedMonitors))
|
||||
{
|
||||
$mon_options = array('Zones.MonitorId' => $allowedMonitors);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mon_options='';
|
||||
|
||||
$allowedMonitors = preg_split('@,@', $this->Session->Read('allowedMonitors'), NULL, PREG_SPLIT_NO_EMPTY);
|
||||
if ( !empty($allowedMonitors) ) {
|
||||
$mon_options = array('Zones.MonitorId' => $allowedMonitors);
|
||||
} else {
|
||||
$mon_options = '';
|
||||
}
|
||||
$zones = $this->Zone->find('all',$mon_options);
|
||||
$this->set(array(
|
||||
'zones' => $zones,
|
||||
'_serialize' => array('zones')
|
||||
'zones' => $zones,
|
||||
'_serialize' => array('zones')
|
||||
));
|
||||
}
|
||||
/**
|
||||
* add method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add() {
|
||||
if ($this->request->is('post')) {
|
||||
$this->Zone->create();
|
||||
if ($this->Zone->save($this->request->data)) {
|
||||
return $this->flash(__('The zone has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
$monitors = $this->Zone->Monitor->find('list');
|
||||
$this->set(compact('monitors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* edit method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function edit($id = null) {
|
||||
$this->Zone->id = $id;
|
||||
|
||||
if (!$this->Zone->exists($id)) {
|
||||
throw new NotFoundException(__('Invalid zone'));
|
||||
}
|
||||
if ($this->request->is(array('post', 'put'))) {
|
||||
if ($this->Zone->save($this->request->data)) {
|
||||
return $this->flash(__('The zone has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
} else {
|
||||
$options = array('conditions' => array('Zone.' . $this->Zone->primaryKey => $id));
|
||||
$this->request->data = $this->Zone->find('first', $options);
|
||||
}
|
||||
$monitors = $this->Zone->Monitor->find('list');
|
||||
$this->set(compact('monitors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* delete method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id = null) {
|
||||
$this->Zone->id = $id;
|
||||
if (!$this->Zone->exists()) {
|
||||
throw new NotFoundException(__('Invalid zone'));
|
||||
}
|
||||
$this->request->allowMethod('post', 'delete');
|
||||
if ($this->Zone->delete()) {
|
||||
return $this->flash(__('The zone has been deleted.'), array('action' => 'index'));
|
||||
} else {
|
||||
return $this->flash(__('The zone could not be deleted. Please, try again.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function createZoneImage( $id = null ) {
|
||||
$this->loadModel('Monitor');
|
||||
$this->Monitor->id = $id;
|
||||
if (!$this->Monitor->exists()) {
|
||||
throw new NotFoundException(__('Invalid zone'));
|
||||
}
|
||||
|
||||
|
||||
$this->loadModel('Config');
|
||||
$zm_dir_images = $this->Config->find('list', array(
|
||||
'conditions' => array('Name' => 'ZM_DIR_IMAGES'),
|
||||
'fields' => array('Name', 'Value')
|
||||
));
|
||||
|
||||
$zm_dir_images = $zm_dir_images['ZM_DIR_IMAGES'];
|
||||
$zm_path_web = Configure::read('ZM_PATH_WEB');
|
||||
$zm_path_bin = Configure::read('ZM_PATH_BIN');
|
||||
$images_path = "$zm_path_web/$zm_dir_images";
|
||||
|
||||
chdir($images_path);
|
||||
|
||||
$command = escapeshellcmd("$zm_path_bin/zmu -z -m $id");
|
||||
system( $command, $status );
|
||||
|
||||
$this->set(array(
|
||||
'status' => $status,
|
||||
'_serialize' => array('status')
|
||||
));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add() {
|
||||
if ( $this->request->is('post') ) {
|
||||
$this->Zone->create();
|
||||
if ( $this->Zone->save($this->request->data) ) {
|
||||
return $this->flash(__('The zone has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
$monitors = $this->Zone->Monitor->find('list');
|
||||
$this->set(compact('monitors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* edit method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function edit($id = null) {
|
||||
$this->Zone->id = $id;
|
||||
|
||||
if ( !$this->Zone->exists($id) ) {
|
||||
throw new NotFoundException(__('Invalid zone'));
|
||||
}
|
||||
if ( $this->request->is(array('post', 'put')) ) {
|
||||
if ( $this->Zone->save($this->request->data) ) {
|
||||
return $this->flash(__('The zone has been saved.'), array('action' => 'index'));
|
||||
}
|
||||
} else {
|
||||
$options = array('conditions' => array('Zone.' . $this->Zone->primaryKey => $id));
|
||||
$this->request->data = $this->Zone->find('first', $options);
|
||||
}
|
||||
$monitors = $this->Zone->Monitor->find('list');
|
||||
$this->set(compact('monitors'));
|
||||
}
|
||||
|
||||
/**
|
||||
* delete method
|
||||
*
|
||||
* @throws NotFoundException
|
||||
* @param string $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete($id = null) {
|
||||
$this->Zone->id = $id;
|
||||
if ( !$this->Zone->exists() ) {
|
||||
throw new NotFoundException(__('Invalid zone'));
|
||||
}
|
||||
$this->request->allowMethod('post', 'delete');
|
||||
if ( $this->Zone->delete() ) {
|
||||
return $this->flash(__('The zone has been deleted.'), array('action' => 'index'));
|
||||
} else {
|
||||
return $this->flash(__('The zone could not be deleted. Please, try again.'), array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
|
||||
public function createZoneImage($id = null) {
|
||||
$this->loadModel('Monitor');
|
||||
$this->Monitor->id = $id;
|
||||
if ( !$this->Monitor->exists() ) {
|
||||
throw new NotFoundException(__('Invalid zone'));
|
||||
}
|
||||
|
||||
$this->loadModel('Config');
|
||||
$zm_dir_images = $this->Config->find('list', array(
|
||||
'conditions' => array('Name' => 'ZM_DIR_IMAGES'),
|
||||
'fields' => array('Name', 'Value')
|
||||
));
|
||||
|
||||
$zm_dir_images = $zm_dir_images['ZM_DIR_IMAGES'];
|
||||
$zm_path_web = Configure::read('ZM_PATH_WEB');
|
||||
$zm_path_bin = Configure::read('ZM_PATH_BIN');
|
||||
$images_path = "$zm_path_web/$zm_dir_images";
|
||||
|
||||
chdir($images_path);
|
||||
|
||||
$command = escapeshellcmd("$zm_path_bin/zmu -z -m $id");
|
||||
system($command, $status);
|
||||
|
||||
$this->set(array(
|
||||
'status' => $status,
|
||||
'_serialize' => array('status')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ var popupSizes = {
|
|||
'monitorselect':{ 'width': 160, 'height': 200 },
|
||||
'montage': { 'width': -1, 'height': -1 },
|
||||
'onvifprobe': { 'width': 700, 'height': 550 },
|
||||
'optionhelp': { 'width': 400, 'height': 320 },
|
||||
'optionhelp': { 'width': 400, 'height': 400 },
|
||||
'options': { 'width': 1000, 'height': 660 },
|
||||
'preset': { 'width': 300, 'height': 220 },
|
||||
'server': { 'width': 600, 'height': 405 },
|
||||
|
|
Loading…
Reference in New Issue