2017-12-05 04:52:16 +08:00
|
|
|
<?php
|
|
|
|
App::uses('AppController', 'Controller');
|
|
|
|
/**
|
|
|
|
* Groups Controller
|
|
|
|
*
|
|
|
|
* @property Group $Group
|
2018-03-05 10:20:48 +08:00
|
|
|
* @property PaginatorComponent $Paginator
|
2017-12-05 04:52:16 +08:00
|
|
|
*/
|
|
|
|
class GroupsController extends AppController {
|
|
|
|
/**
|
|
|
|
* Components
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2018-03-05 10:20:48 +08:00
|
|
|
public $components = array('Paginator', 'RequestHandler');
|
|
|
|
|
2018-03-07 01:29:59 +08:00
|
|
|
public function beforeFilter() {
|
|
|
|
parent::beforeFilter();
|
|
|
|
$canView = $this->Session->Read('groupsPermission');
|
|
|
|
if ( $canView == 'None' ) {
|
|
|
|
throw new UnauthorizedException(__('Insufficient Privileges'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-12-05 04:52:16 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* index method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
$this->Group->recursive = -1;
|
|
|
|
$groups = $this->Group->find('all');
|
|
|
|
$this->set(array(
|
|
|
|
'groups' => $groups,
|
|
|
|
'_serialize' => array('groups')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* view method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function view($id = null) {
|
|
|
|
$this->Group->recursive = -1;
|
|
|
|
if (!$this->Group->exists($id)) {
|
|
|
|
throw new NotFoundException(__('Invalid group'));
|
|
|
|
}
|
|
|
|
$options = array('conditions' => array('Group.' . $this->Group->primaryKey => $id));
|
|
|
|
$group = $this->Group->find('first', $options);
|
|
|
|
$this->set(array(
|
|
|
|
'group' => $group,
|
|
|
|
'_serialize' => array('group')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function add() {
|
|
|
|
if ($this->request->is('post')) {
|
2018-03-05 10:20:48 +08:00
|
|
|
|
2018-03-07 01:29:59 +08:00
|
|
|
if ($this->Session->Read('groupPermission') != 'Edit') {
|
|
|
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
|
|
|
return;
|
2018-03-05 10:20:48 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 04:52:16 +08:00
|
|
|
$this->Group->create();
|
|
|
|
if ($this->Group->save($this->request->data)) {
|
|
|
|
return $this->flash(__('The group has been saved.'), array('action' => 'index'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$monitors = $this->Group->Monitor->find('list');
|
|
|
|
$this->set(compact('monitors'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* edit method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function edit($id = null) {
|
|
|
|
if (!$this->Group->exists($id)) {
|
|
|
|
throw new NotFoundException(__('Invalid group'));
|
|
|
|
}
|
2018-03-07 01:29:59 +08:00
|
|
|
if ( $this->request->is(array('post', 'put'))) {
|
|
|
|
if ( $this->Session->Read('groupPermission') != 'Edit' ) {
|
|
|
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
|
|
|
return;
|
|
|
|
}
|
2017-12-05 04:52:16 +08:00
|
|
|
if ($this->Group->save($this->request->data)) {
|
|
|
|
return $this->flash(__('The group has been saved.'), array('action' => 'index'));
|
2018-03-07 01:29:59 +08:00
|
|
|
} else {
|
|
|
|
$message = 'Error';
|
2017-12-05 04:52:16 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$options = array('conditions' => array('Group.' . $this->Group->primaryKey => $id));
|
|
|
|
$this->request->data = $this->Group->find('first', $options);
|
|
|
|
}
|
|
|
|
$monitors = $this->Group->Monitor->find('list');
|
2018-03-05 10:20:48 +08:00
|
|
|
$this->set(array(
|
|
|
|
'message' => $message,
|
2018-03-07 01:29:59 +08:00
|
|
|
'monitors'=> $monitors,
|
|
|
|
'_serialize' => array('message',)
|
2018-03-05 10:20:48 +08:00
|
|
|
));
|
2017-12-05 04:52:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete method
|
|
|
|
*
|
|
|
|
* @throws NotFoundException
|
|
|
|
* @param string $id
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function delete($id = null) {
|
|
|
|
$this->Group->id = $id;
|
|
|
|
if (!$this->Group->exists()) {
|
|
|
|
throw new NotFoundException(__('Invalid group'));
|
|
|
|
}
|
|
|
|
$this->request->allowMethod('post', 'delete');
|
2018-03-07 01:29:59 +08:00
|
|
|
if ( $this->Session->Read('groupPermission') != 'Edit' ) {
|
2018-03-05 10:20:48 +08:00
|
|
|
throw new UnauthorizedException(__('Insufficient privileges'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-05 04:52:16 +08:00
|
|
|
if ($this->Group->delete()) {
|
|
|
|
return $this->flash(__('The group has been deleted.'), array('action' => 'index'));
|
|
|
|
} else {
|
|
|
|
return $this->flash(__('The group could not be deleted. Please, try again.'), array('action' => 'index'));
|
|
|
|
}
|
2018-03-07 01:29:59 +08:00
|
|
|
} // end function delete
|
|
|
|
} // end class GroupController
|