diff --git a/controllers/app_controller.php b/controllers/app_controller.php index 8f75e92a..fe5ab4be 100755 --- a/controllers/app_controller.php +++ b/controllers/app_controller.php @@ -4,27 +4,39 @@ class AppController extends Controller { -var $components = array('Auth', 'RequestHandler'); + var $components = array('Auth', 'RequestHandler'); - var $helpers = array('Javascript', 'Time', 'Html', 'Form', 'Ajax'); - function beforeFilter() { - $this->set('currentuser', $this->Auth->user()); - - /** - * Define the scheme for issue Types. - */ - $this->set('issueTypes', array(1=>"Bug Report", 2=>"Feature Request", 3=>"Other IT Help")); - - $priorities = array(1 => 'Low',2=>"Medium",3=>"High", 4=>"Critical"); - $this->set('issuePriorities', $priorities); + var $helpers = array('Javascript', 'Time', 'Html', 'Form', 'Ajax'); + function beforeFilter() { + $this->set('currentuser', $this->Auth->user()); + + + $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); + $this->Auth->loginRedirect = array('controller' => 'enquiries', 'action' => 'index'); + $this->Auth->allow('display'); + $this->Auth->authorize = 'controller'; + + + /** + * Define the scheme for issue Types. + */ + $this->set('issueTypes', array(1=>"Bug Report", 2=>"Feature Request", 3=>"Other IT Help")); + + $priorities = array(1 => 'Low',2=>"Medium",3=>"High", 4=>"Critical"); + $this->set('issuePriorities', $priorities); - if($this->RequestHandler->isAjax()) { - Configure::write('debug', 0); - } + if($this->RequestHandler->isAjax()) { + Configure::write('debug', 0); + } - } + } + + + function isAuthorized() { + return true; + } } diff --git a/controllers/users_controller.php b/controllers/users_controller.php index 1dd8fc61..209d3959 100755 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -1,129 +1,161 @@ array('order' => array('User.name' => 'asc'), - 'limit' => 20 - ), - 'Enquiry' => array('order' => array('Enquiry.id' => 'desc'), 'limit' => 250) - ); + var $name = 'Users'; + var $helpers = array('Html', 'Form'); + var $components = array('Acl','Auth', 'Cookie'); + 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 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 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); - - } + /* Auth Cookie code from http://www.webdevelopment2.com/cakephp-auth-component-tutorial-3/ */ + //– code inside this function will execute only when autoRedirect was set to false (i.e. in a beforeFilter). + if ($this->Auth->user()) { + if (!empty($this->data) && $this->data['User']['remember_me']) { + $cookie = array(); + $cookie['username'] = $this->data['User']['username']; + $cookie['password'] = $this->data['User']['password']; + $this->Cookie->write('Auth.User', $cookie, true, '+2 weeks'); + unset($this->data['User']['remember_me']); + } + $this->redirect($this->Auth->redirect()); + } + if (empty($this->data)) { + $cookie = $this->Cookie->read('Auth.User'); + if (!is_null($cookie)) { + if ($this->Auth->login($cookie)) { + // Clear auth message, just in case we use it. + + $this->Session->setFlash(__('Welcome back '.$cookie['username']), true); + $this->Session->del('Message.auth'); + $this->redirect($this->Auth->redirect()); + } else { // Delete invalid Cookie + $this->Cookie->del('Auth.User'); + } - 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'); + function logout() { + $this->redirect($this->Auth->logout()); + } -//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'); + 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'); + + } -$this->Acl->allow($group, 'controllers/QuoteProducts/edit'); -$this->Acl->allow($group, 'controllers/QuoteProducts/view'); -} - - } diff --git a/vendors/xtcpdf.php b/vendors/xtcpdf.php index 4f6b69dc..db2d6577 100755 --- a/vendors/xtcpdf.php +++ b/vendors/xtcpdf.php @@ -90,7 +90,7 @@ class XTCPDF extends TCPDF { $fourthColWidth = -10; $pageNo = $this->PageNoFormatted(); - //$pageOf = $this->getAliasNbPages(); + @@ -98,13 +98,11 @@ class XTCPDF extends TCPDF { $this->SetXY($boxXstart, 55); $heightNeeded = $this->getNumLines($companyName, $secondColWidth); - //echo "Height needed: $heightNeeded"; + $lineHeight = 6.40997; //Size of a single line of text. If the company name is more, multiply this by the number of lines it needs. - // $lineHeight = 0; - - // $this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml); + $this->MultiCell($firstColWidth, $lineHeight*$heightNeeded, "QUOTATION TO:", 'LTR', 'L', 0, 0); @@ -112,7 +110,7 @@ class XTCPDF extends TCPDF { $this->MultiCell($thirdColWidth, $lineHeight*$heightNeeded, "FROM:", 'LT', 'L', 0, 0); $this->MultiCell($fourthColWidth, $lineHeight*$heightNeeded, "$fromName", 'TR', 'L', 0, 1, null,null, true,0,true); //Start a new line after this. - // echo "Last height: ".$this->getLastH(); + $this->MultiCell($firstColWidth, 0, "EMAIL TO:", 'LR', 'L', 0, 0); $this->MultiCell($secondColWidth, 0, "$emailTo", 'LR','L', 0, 0, null, null, true, 0, true); @@ -249,8 +247,7 @@ class XTCPDF extends TCPDF { $pageNo = $this->PageNoFormatted(); $this->MultiCell(0, 0, "PAGE $pageNo OF {nb}", 0, "R", 0, 1); $this->MultiCell(0, 0, "PRICING & SPECIFICATIONS", 0, "C", 0, 1); - $this->Ln(); - + $this->MultiCell($itemColwidth, 0, "ITEM\nNO.", 1, "C", 1, 0); $heightNeeded = $this->getLastH(); diff --git a/views/quotes/view.ctp b/views/quotes/view.ctp index aee2fadf..054ca213 100755 --- a/views/quotes/view.ctp +++ b/views/quotes/view.ctp @@ -56,7 +56,7 @@ foreach ($quote['QuotePage'] as $quotePage): -