cmc-sales/controllers/users_controller.php
2009-02-13 17:11:12 +11:00

131 lines
3.4 KiB
PHP
Executable file

<?php
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form');
var $components = array('Acl','Auth');
var $paginate = array(
'Users' => array('order' => array('User.name' => 'asc'),
'limit' => 20
),
'Enquiry' => array('order' => array('Enquiry.id' => 'desc'), 'limit' => 250)
);
function beforeFilter() {
$this->Auth->allow('add');
$this->set('currentuser', $this->Auth->user());
}
function login() { //Provided by the authComponent
$this->pageTitle = ': Login';
$this->Session->setFlash(__('Please enter your Username and Password to continue', true));
}
function logout() {
$this->redirect($this->Auth->logout());
}
function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid User.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('user', $this->User->read(null, $id));
$this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.user_id' => $id)));
$statuses = $this->User->Enquiry->Status->find('all');
$status_list = array();
foreach ($statuses as $status) {
$status_list[] = array($status['Status']['id'], $status['Status']['name']);
}
$this->set('status_list', $status_list);
}
function add() {
$this->set('groups', $this->User->Group->find('list'));
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('The User has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid User', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('The User has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The User could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->User->read(null, $id);
$this->set('groups', $this->User->Group->find('list'));
}
}
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for User', true));
$this->redirect(array('action'=>'index'));
}
if ($this->User->del($id)) {
$this->Session->setFlash(__('User deleted', true));
$this->redirect(array('action'=>'index'));
}
}
function initpermissions() {
$group = $this->User->Group;
//Allow admins to everything
$group->id = 6;
$this->Acl->allow($group, 'controllers');
//Manager Permission
$group->id = 5;
$this->Acl->allow($group, 'controllers');
//User Permission
$group->id = 4;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Enquires/add');
$this->Acl->allow($group, 'controllers/Enquires/edit');
$this->Acl->allow($group, 'controllers/Enquires/view');
$this->Acl->allow($group, 'controllers/Quotes/add');
$this->Acl->allow($group, 'controllers/Quotes/edit');
$this->Acl->allow($group, 'controllers/Quotes/view');
$this->Acl->allow($group, 'controllers/QuoteProducts/add');
$this->Acl->allow($group, 'controllers/QuoteProducts/edit');
$this->Acl->allow($group, 'controllers/QuoteProducts/view');
}
}
?>