cmc-sales/app/controllers/app_controller.php

153 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/* App Controller */
class AppController extends Controller {
2010-01-10 15:34:31 -08:00
var $components = array('Auth', 'RequestHandler');
var $helpers = array('Javascript', 'Time', 'Html', 'Form');
2010-01-10 15:34:31 -08:00
function beforeFilter() {
$this->set('currentuser', $this->Auth->user());
2010-01-10 10:05:04 -08:00
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'enquiries', 'action' => 'index');
$this->Auth->allow('display');
$this->Auth->authorize = 'controller';
2010-01-10 10:05:04 -08:00
2012-09-07 18:40:45 -07:00
$this->Auth->autoRedirect = false;
if($this->RequestHandler->isAjax()) {
Configure::write('debug', 0);
}
2010-01-10 15:34:31 -08:00
}
2012-11-17 18:57:16 -08:00
//WTF. Why is this here??
2010-01-10 15:34:31 -08:00
function isAuthorized() {
return true;
2010-01-10 15:34:31 -08:00
}
/**
* Check if the current logged in user is an admin
* @return boolean
*/
function isAdmin() {
$currentuser = $this->getCurrentUser();
2011-03-09 23:18:26 -08:00
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;
}
2010-02-16 19:34:17 -08:00
function unset_keys($array, $keys) {
foreach($keys as $key ) {
$array[$key] = null;
}
return $array;
}
function unset_multiple_keys($array, $keys) {
foreach($array as $index => $item) {
$array[$index]['id'] = null;
$array[$index]['document_id'] = null;
$array[$index]['costing_id'] = null;
}
}
2011-09-26 20:47:36 -07:00
/**
*
* @param <type> $year
* @param <type> $prevYear
* @return <type>
*/
function getFirstDayFY($year,$prevYear = false) {
if($prevYear == false) {
return mktime(0,0,0,7,1,$year);
}
else {
return mktime(0,0,0,7,1,$year-1);
}
}
/**
*
* @param <type> $year
* @return <int>
*/
function getLastDayFY($year) {
return mktime(23,59,59,6,30,$year);
}
2010-02-16 19:34:17 -08:00
2010-01-10 10:05:04 -08:00
}
2012-09-07 18:40:45 -07:00
?>