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'; if($this->RequestHandler->isAjax()) { Configure::write('debug', 0); } } function isAuthorized() { return true; } /** * Check if the current logged in user is an admin * @return boolean */ function isAdmin() { $currentuser = $this->getCurrentUser(); if($currentuser['access_level'] == 'admin') { return true; } else { return false; } } function isManager() { $currentuser = $this->getCurrentUser(); if($currentuser['access_level'] == 'manager') { return true; } else { return false; } } /** * Read the current logged in user. * @return array - the currently logged in user. */ function getCurrentUser() { return $this->Session->read('Auth.User'); } /** * Return the id of the current user. False if not logged in. */ function getCurrentUserID() { $currentuser = $this->getCurrentUser(); if($currentuser) { return $currentuser['id']; } else { return false; } } function calculateTotals($document, $gst) { $totals = array('subtotal'=>0, 'gst'=>0, 'total'=>0); foreach($document['LineItem'] as $lineitem) { if($lineitem['option'] == 1) { $totals['subtotal'] = 'TBA'; $totals['total'] = 'TBA'; $totals['gst'] = 'TBA'; return $totals; } else { $totals['subtotal'] += $lineitem['net_price']; } } if($gst == 1) { $totals['gst'] = 0.1*$totals['subtotal']; } $totals['total'] = $totals['gst'] + $totals['subtotal']; return $totals; } } ?>