2014-04-24 03:59:52 +08:00
|
|
|
<?php
|
|
|
|
App::uses('AppController', 'Controller');
|
|
|
|
/**
|
|
|
|
* Configs Controller
|
|
|
|
*
|
|
|
|
* @property Config $Config
|
|
|
|
*/
|
|
|
|
class ConfigsController extends AppController {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Components
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $components = array('RequestHandler');
|
|
|
|
|
2015-07-22 01:28:37 +08:00
|
|
|
/**
|
2015-12-20 07:36:38 +08:00
|
|
|
* resolves the issue of not returning all config parameters
|
2015-07-22 01:28:37 +08:00
|
|
|
* refer https://github.com/ZoneMinder/ZoneMinder/issues/953
|
|
|
|
* index method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-05-11 01:44:46 +08:00
|
|
|
public function index() {
|
|
|
|
global $configvals;
|
|
|
|
$this->Config->recursive = 0;
|
|
|
|
$configs = $this->Config->find('all');
|
|
|
|
foreach ( $configvals as $k=>$v ) {
|
|
|
|
$configs[] = array( 'Config'=>array('Name'=>$k, 'Value'=>$v ) );
|
|
|
|
}
|
|
|
|
$this->set(array(
|
|
|
|
'configs' => $configs,
|
|
|
|
'_serialize' => array('configs')
|
|
|
|
));
|
|
|
|
}
|
2015-07-22 01:28:37 +08:00
|
|
|
|
2014-04-24 03:59:52 +08:00
|
|
|
/**
|
|
|
|
* view method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function view($id = null) {
|
|
|
|
if (!$this->Config->exists($id)) {
|
|
|
|
throw new NotFoundException(__('Invalid config'));
|
|
|
|
}
|
|
|
|
$options = array('conditions' => array('Config.' . $this->Config->primaryKey => $id));
|
|
|
|
$config = $this->Config->find('first', $options);
|
|
|
|
$this->set(array(
|
|
|
|
'config' => $config,
|
|
|
|
'_serialize' => array('config')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-06-11 10:58:58 +08:00
|
|
|
public function viewByName($name = null) {
|
|
|
|
$config = $this->Config->findByName($name, array('fields' => 'Value'));
|
|
|
|
|
|
|
|
if (!$config) {
|
|
|
|
throw new NotFoundException(__('Invalid config'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->set(array(
|
|
|
|
'config' => $config['Config'],
|
|
|
|
'_serialize' => array('config')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2014-04-24 03:59:52 +08:00
|
|
|
/**
|
|
|
|
* edit method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function edit($id = null) {
|
2014-04-26 03:18:59 +08:00
|
|
|
$this->Config->id = $id;
|
|
|
|
|
2014-04-24 03:59:52 +08:00
|
|
|
if (!$this->Config->exists($id)) {
|
|
|
|
throw new NotFoundException(__('Invalid config'));
|
|
|
|
}
|
|
|
|
if ($this->request->is(array('post', 'put'))) {
|
|
|
|
if ($this->Config->save($this->request->data)) {
|
|
|
|
return $this->flash(__('The config has been saved.'), array('action' => 'index'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$options = array('conditions' => array('Config.' . $this->Config->primaryKey => $id));
|
|
|
|
$this->request->data = $this->Config->find('first', $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function delete($id = null) {
|
|
|
|
$this->Config->id = $id;
|
|
|
|
if (!$this->Config->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid config'));
|
|
|
|
}
|
|
|
|
$this->request->allowMethod('post', 'delete');
|
|
|
|
if ($this->Config->delete()) {
|
|
|
|
return $this->flash(__('The config has been deleted.'), array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
return $this->flash(__('The config could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
|
|
}
|
2014-08-19 22:55:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* categories method
|
|
|
|
*
|
2015-06-11 10:58:58 +08:00
|
|
|
* return a list of distinct categories
|
2014-08-19 22:55:32 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
public function categories($category = null) {
|
2015-06-11 10:58:58 +08:00
|
|
|
$categories = $this->Config->find('all', array(
|
|
|
|
'fields' => array('DISTINCT Config.Category'),
|
|
|
|
'conditions' => array('Config.Category !=' => 'hidden'),
|
|
|
|
'recursive' => 0
|
2014-09-22 22:42:19 +08:00
|
|
|
));
|
|
|
|
$this->set(array(
|
2015-06-11 10:58:58 +08:00
|
|
|
'categories' => $categories,
|
|
|
|
'_serialize' => array('categories')
|
2014-09-22 22:42:19 +08:00
|
|
|
));
|
|
|
|
}
|
2014-08-19 22:55:32 +08:00
|
|
|
}
|
2015-06-11 10:58:58 +08:00
|
|
|
|