getAuthObj(); if (!$e) { return HTML_FlexyFramework::run('Login'); } // DB_DataObject::debugLevel(5); $this->switchToUserDatabase($e->email); //print_r($e); return true; // everyone is allowed here! } function get($str) { // if we get a url that is not handled throw a 404 error page. if (strlen($str)) { echo "404 - not allowed"; // HTML_FlexyFramework::run('Error/404'); exit; } return; $this->loadAccounts(); } function post($str) { // if we get a url that is not handled throw a 404 error page. if (strlen($str)) { echo "404 - not allowed"; // HTML_FlexyFramework::run('Error/404'); exit; } } var $accountsArray; function loadAccounts() { $ac = DB_DataObject::factory('account'); $this->accountsArray = $ac->loadAccountsTree(); $this->accountsFlatArray = array(); $this->buildFlatAccounts($this->accountsArray); } function buildFlatAccounts($ar,$indent = 0) { if (!$ar) { return 0; } $this->buildTotals($ar); foreach($ar as $i=>$ac) { $ar[$i]->indent = $indent; $dup = clone($ar[$i]); $dup->children = array(); $this->accountsFlatArray[] = $dup; $this->buildFlatAccounts($ar[$i]->children,$indent+1); } } function buildTotals(&$ar) { $ent = 0; $tot = 0; foreach($ar as $i=>$ac) { $ent += $ar[$i]->entries; $tot += $ar[$i]->total; $ar[$i]->allTotal = $ar[$i]->total; $ar[$i]->allEntries = $ar[$i]->entries; if (!$ar[$i]->children) { continue; } list($entries, $total) = $this->buildTotals($ar[$i]->children); $ar[$i]->allTotal += $total; $ar[$i]->allEntries += $entries; $ent += $entries; $tot += $tot; } return array($ent,$tot); } var $customerArray = array(); function loadCustomers($currency="") { $ac = DB_DataObject::factory('customer'); if ($currency) { $ac->currency = $currency; } $this->customerArray = $ac->getAll(); } function loadVendors($currency="") { $ac = DB_DataObject::factory('vendor'); if ($currency) { $ac->currency = $currency; } $this->vendorArray = $ac->getAll(); } public $balance = 0; function balance($no) { $this->balance += $no; return $this->balance; } function getAccountName($id) { // echo "get acc name? $id"; return FlexyCash_DataObjects_Account::toFullPath($id); } function indent($no) { return str_repeat('   ', $no); } function toCurrency($from,$to, $ammount) { //FIX ME - use prices table. switch($to) { case 'USD': return $ammount * 7.8; case 'HKD': return $ammount; case 'GBP': return $ammount * 14.1; } } var $menu = ""; function classCurrent($is) { if ('_' .$this->menu == $is) { return 'current'; } if ($this->menu) { return $this->menu; } if (!$is) { return (in_array(strtolower(get_class($this)), array(strtolower(__CLASS__), 'flexycash_account') )) ? 'current' : get_class($this); } return is_a($this , 'FlexyCash'. $is) ? 'current' : get_class($this); } function switchToUserDatabase($email) { $dbname = $this->databaseNameFromEmail($email); $lpos = strrpos( $GLOBALS['_DB_DATAOBJECT']['CONFIG']['database_cash'] , '/'); $GLOBALS['_DB_DATAOBJECT']['CONFIG']['database_cash'] = substr( $GLOBALS['_DB_DATAOBJECT']['CONFIG']['database_cash'] , 0, $lpos+1) . $dbname; $GLOBALS['_DB_DATAOBJECT']['CONFIG']['database'] = $GLOBALS['_DB_DATAOBJECT']['CONFIG']['database_cash']; $GLOBALS['_DB_DATAOBJECT']['CONFIG']['ini_'.$dbname] = $GLOBALS['_DB_DATAOBJECT']['CONFIG']['schema_location'] . '/gnucash.ini'; //print_r($GLOBALS['_DB_DATAOBJECT']['CONFIG']); } function databaseNameFromEmail($email) { $bits = explode('@', $email); $first = preg_replace("/(\.[a-z]+|\.com|\.net|\.org)$/i","", $bits[1]); $second = preg_replace("/(\.[a-z]{2})$/i","", $first); if (!strlen($second)) { $second = $first; } $third = preg_replace("/(\.com|\.net|\.org)$/i","", $second); return 'cash_'.preg_replace('/[^A-Z0-9]+/i', '_', $third); } function bcsub($a,$b) { return bcsub($a,$b,2); } function nicedate($str) { $d = strtotime($str); return date('dMY',$d); } function toArray($obj, $prefix = "") { $ret = array(); foreach($obj as $k=>$v) { if (($k[0] == '_') || ($k== 'N') || is_array($v) || is_object($v) ) { continue; } $ret[$prefix . $k] = $v; } return $ret; } }