From 288d974cfa96c2a982dbdf7525fd53cf6cfb6a85 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 12 Feb 2013 22:14:59 +1100 Subject: [PATCH] Optimised Company() Setup() Config() and changed method_directory into URL --- application/bootstrap.php | 2 +- application/classes/Auth/OSB.php | 4 +- application/classes/Company.php | 177 +++++++++++------- application/classes/Config.php | 128 +++++-------- .../classes/Controller/Admin/Account.php | 4 +- .../classes/Controller/Admin/Module.php | 8 +- .../Controller/Admin/Module/Method.php | 2 +- .../classes/Controller/Admin/Setup.php | 4 +- .../classes/Controller/Admin/Welcome.php | 8 +- .../classes/Controller/Affiliate/Account.php | 4 +- application/classes/Controller/Debug.php | 2 +- application/classes/Controller/Login.php | 6 +- .../classes/Controller/TemplateDefault.php | 4 +- .../Controller/TemplateDefault/Admin.php | 4 +- application/classes/Controller/Tree.php | 6 +- application/classes/Currency.php | 4 +- application/classes/DB.php | 8 +- application/classes/Model/Account.php | 6 +- application/classes/Model/Record/Id.php | 2 +- application/classes/Model/Setup.php | 1 + application/classes/ORM.php | 13 +- application/classes/ORM/OSB.php | 4 +- application/classes/Request.php | 31 +++ application/classes/URL.php | 54 ++++++ application/config/config.php | 16 +- application/config/debug.php | 1 + .../views/module/admin/method_detail_body.php | 2 +- application/views/yaml/page.php | 6 +- .../classes/Controller/Admin/Charge.php | 8 +- .../email/classes/Controller/Admin/Email.php | 6 +- .../email/classes/Controller/User/Email.php | 4 +- modules/email/classes/Email/Template.php | 2 +- .../views/email/admin/templatelist/body.php | 2 +- modules/export/classes/Export/Quicken.php | 4 +- .../host/classes/Controller/Admin/Host.php | 4 +- modules/host/classes/Model/Host/Server.php | 2 +- .../classes/Controller/Admin/Invoice.php | 4 +- .../classes/Controller/Task/Invoice.php | 14 +- .../classes/Controller/User/Invoice.php | 6 +- modules/invoice/classes/Invoice/TCPDF.php | 7 +- .../invoice/classes/Invoice/TCPDF/Default.php | 22 +-- modules/invoice/views/invoice/user/email.php | 4 +- modules/invoice/views/invoice/user/view.php | 14 +- .../lnApp/classes/lnApp/Controller/Login.php | 4 +- .../lnApp/Controller/TemplateDefault.php | 4 +- .../lnApp/classes/lnApp/Controller/Tree.php | 2 +- .../classes/Controller/Admin/Payment.php | 10 +- .../payment/classes/Payment/Bulk/Ezypay.php | 4 +- .../payment/admin/addbulk/ezypay/body.php | 2 +- .../views/payment/admin/autoitemlist/body.php | 2 +- .../classes/Controller/Admin/Product.php | 10 +- .../classes/Model/Product/Category.php | 4 +- .../classes/Controller/Admin/Service.php | 56 +++--- .../classes/Controller/Affiliate/Service.php | 28 +-- .../classes/Controller/User/Service.php | 4 +- .../service/classes/Model/Service/Plugin.php | 2 +- modules/service/views/service/admin/view.php | 2 +- modules/service/views/service/user/view.php | 4 +- modules/ssl/classes/Controller/Admin/Ssl.php | 8 +- modules/ssl/classes/Controller/User/Ssl.php | 2 +- .../ssl/classes/Model/Service/Plugin/Ssl.php | 2 +- .../views/statement/user/show/body.php | 2 +- .../task/classes/Controller/Admin/Task.php | 2 +- 63 files changed, 422 insertions(+), 346 deletions(-) create mode 100644 application/classes/Request.php create mode 100644 application/classes/URL.php diff --git a/application/bootstrap.php b/application/bootstrap.php index b479650c..02f72632 100644 --- a/application/bootstrap.php +++ b/application/bootstrap.php @@ -136,7 +136,7 @@ Kohana::modules(array_merge(Kohana::modules(),Config::modules())); */ Route::set('sections', '/(/(/(/)))', array( - 'directory' => '('.implode('|',Kohana::$config->load('config')->method_directory).')' + 'directory' => '('.implode('|',array_values(URL::$method_directory)).')' )) ->defaults(array( 'action' => 'index', diff --git a/application/classes/Auth/OSB.php b/application/classes/Auth/OSB.php index 62caffb4..21596839 100644 --- a/application/classes/Auth/OSB.php +++ b/application/classes/Auth/OSB.php @@ -30,7 +30,7 @@ class Auth_OSB extends Auth_ORM { // If we are not a valid user object, then we are not logged in if (is_object($user) AND $user instanceof Model_Account AND $user->loaded()) { - if (Config::sitemode() == Kohana::DEVELOPMENT && Kohana::$config->load('config')->site_debug) + if (Config::sitemode() == Kohana::DEVELOPMENT && Kohana::$config->load('debug')->site) SystemMessage::add(array('title'=>'Debug','type'=>'debug','body'=>Kohana::debug(array('user'=>$user->username,'r'=>$role)))); if (! empty($role)) { @@ -257,7 +257,7 @@ class Auth_OSB extends Auth_ORM { $sct = Kohana::$config->load('config')->session_change_trigger; if (session_id() != $oldsess AND count($sct)) foreach ($sct as $t => $c) - if (Config::moduleexist($t)) + if (Config::module_exist($t)) foreach (ORM::factory(ucwords($t))->where($c,'=',$oldsess)->find_all() as $o) $o->set('session_id',session_id()) ->update(); diff --git a/application/classes/Company.php b/application/classes/Company.php index 6ed97633..09e29100 100644 --- a/application/classes/Company.php +++ b/application/classes/Company.php @@ -4,58 +4,127 @@ * This class is for access company information. * * @package OSB - * @subpackage System + * @subpackage Company * @category Helpers * @author Deon George * @copyright (c) 2010 Open Source Billing * @license http://dev.osbill.net/license.html */ class Company { + // Our Company Setup object + private $so; + + public function __construct(Model_Setup $so) { + $this->so = $so; + + if (! $this->so->loaded()) + throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http'))); + + Kohana::$environment = (int)$this->so->status; + } + public static function instance() { - return new Company; + return new Company(ORM::factory('Setup',array('url'=>URL::base('http')))); } - public static function name() { - return Config::instance()->so->site_details('name'); + public function admin() { + return $this->so->account->name(); } - public static function street($ln='
') { - if ($b = Config::instance()->so->site_details('address2')) - return implode($ln,array(Config::instance()->so->site_details('address1'),Config::instance()->so->site_details('address2'))); + public function address($ln='
') { + return implode($ln,array($this->street($ln),sprintf('%s, %s %s',$this->city(),$this->state(),$this->pcode()))); + } + + public function city() { + return $this->so->site_details('city'); + } + + public function contacts() { + return 'Tel: '.$this->phone(); + } + + public function country() { + return $this->so->country; + } + + public function date_format() { + return $this->so->date_format; + } + + public function decimals() { + return $this->so->decimal_place; + } + + public function email() { + return $this->so->site_details('email'); + } + + public function fax() { + return $this->so->site_details('fax'); + } + + public function language() { + return $this->so->language->iso; + } + + public function logo() { + return Config::logo(); + } + + public function logo_file() { + list ($path,$suffix) = explode('.',Config::$logo); + + return ($x=Kohana::find_file(sprintf('media/site/%s',$this->site()),$path,$suffix)) ? $x : Kohana::find_file('media',$path,$suffix); + } + + public function name() { + return $this->so->site_details('name'); + } + + public function module_config($item) { + return $this->so->module_config($item); + } + + public function pcode() { + return $this->so->site_details('pcode'); + } + + public function phone() { + return $this->so->site_details('phone'); + } + + public function site($format=FALSE) { + return $format ? sprintf('%02s',$this->so->id) : $this->so->id; + } + + public function so() { + return $this->so; + } + + public function state() { + return $this->so->site_details('state'); + } + + public function street($ln='
') { + return $this->so->site_details('address2') ? implode($ln,array($this->so->site_details('address1'),$this->so->site_details('address2'))) : $this->so->site_details('address1'); + } + + public function sitemode() { + return $this->so->status; + } + + public function taxid() { + // Tax ID details are stored in invoice config + $mc = $this->so->module_config('invoice'); + + if (empty($mc['TAX_ID_NAME'])) + return empty($mc['TAX_ID']) ? '' : $mc['TAX_ID']; else - return Config::instance()->so->site_details('address1'); + return sprintf('%s: %s',$mc['TAX_ID_NAME'],empty($mc['TAX_ID']) ? '' : $mc['TAX_ID']); } - public static function city() { - return Config::instance()->so->site_details('city'); - } - - public static function state() { - return Config::instance()->so->site_details('state'); - } - - public static function pcode() { - return Config::instance()->so->site_details('pcode'); - } - - public static function address($ln='
') { - return implode($ln,array(static::street($ln),sprintf('%s, %s %s',static::city(),static::state(),static::pcode()))); - } - - public static function phone() { - return Config::instance()->so->site_details('phone'); - } - - public static function fax() { - return Config::instance()->so->site_details('fax'); - } - - public static function email() { - return Config::instance()->so->site_details('email'); - } - - public static function contacts() { - return 'Tel: '.static::phone(); + public function time_format() { + return $this->so->time_format; } public static function bsb() { @@ -67,37 +136,5 @@ class Company { // @todo Details should be obtained from DB return Kohana::$config->load('config')->accnum; } - - public static function taxid() { - // Tax ID details are stored in invoice config - $mc = Config::instance()->so->module_config('invoice'); - - if (empty($mc['TAX_ID_NAME'])) - return empty($mc['TAX_ID']) ? '' : $mc['TAX_ID']; - else - return sprintf('%s: %s',$mc['TAX_ID_NAME'],empty($mc['TAX_ID']) ? '' : $mc['TAX_ID']); - } - - public static function render() { - echo static::name(); - echo static::address(); - echo static::contacts(); - } - - /** - * Return the HTML to render the company address - */ - public function __toString() { - try { - return static::render(); - } - - // Display the exception message - catch (Exception $e) { - Kohana::exception_handler($e); - - return ''; - } - } } ?> diff --git a/application/classes/Config.php b/application/classes/Config.php index 1238ec44..6f2b7d98 100644 --- a/application/classes/Config.php +++ b/application/classes/Config.php @@ -11,10 +11,8 @@ * @license http://dev.osbill.net/license.html */ class Config extends Kohana_Config { - // Our setup object - public $so; - public static $no_site_id_tables = array('setup','country','currency','language','tax'); - protected static $logo = 'img/logo-small.png'; + // Our default logo, if there is no site logo + public static $logo = 'img/logo-small.png'; /** * @compat Restore KH 3.1 functionality @@ -27,6 +25,7 @@ class Config extends Kohana_Config { * * At this point, KH hasnt been fully initialised either, so we cant rely on * too many KH functions yet. + * * NOTE: Kohana doesnt provide a parent construct for the Kohana_Config class. */ public function __construct() { @@ -59,10 +58,23 @@ class Config extends Kohana_Config { return Config::$_instance; } - /** Overloaded methods **/ + /** + * Return our caching mechanism + */ + public static function cachetype() { + return is_null(Kohana::$config->load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type; + } + + public static function copywrite() { + return '(c) Open Source Billing Development Team'; + } + + public static function country() { + return Company::instance()->country(); + } public static function date($date) { - return date(Config::instance()->loadsite()->so->date_format,($date ? $date : time())); + return date(Company::instance()->date_format(),($date ? $date : time())); } /** @@ -73,38 +85,26 @@ class Config extends Kohana_Config { return sprintf('%s %s',static::date($date),static::time($date)); } - public static function siteid($format=FALSE) { - return $format ? sprintf('%02s',Config::instance()->loadsite()->so->id) : Config::instance()->loadsite()->so->id; + public static function language() { + return Company::instance()->language(); } - public static function sitemode() { - return Config::instance()->loadsite()->so->status; - } - - public static function time($date) { - return date(Config::instance()->loadsite()->so->time_format,($date ? $date : time())); - } - - /** Local Methods **/ - /** - * Load our site configuration from the DB - * - * We cant do this in __construct(), since Kohana hasn't been fully initialised yet. + * The URI to show for the login prompt. + * Normally if the user is logged in, we can replace it with a user edit call, instead of login */ - public function loadsite() { - // Anti-loop, if we have loaded our record, just return; - if ($this->so AND $this->so->loaded()) - return $this; + public static function login_uri() { + return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor(URL::link('user','account/edit'),$ao->name()) : HTML::anchor('login',_('Login')); + } - $this->so = ORM::factory('Setup',array('url'=>URL::base('http'))); + public static function logo() { + return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo'))); + } - if (! $this->so->loaded()) - throw new Kohana_Exception(_('Site [:site] not defined in DB?'),array(':site'=>URL::base('http'))); + public static function logo_uri() { + list ($path,$suffix) = explode('.',static::$logo); - Kohana::$environment = (int)static::sitemode(); - - return $this; + return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),'http'); } /** @@ -123,66 +123,24 @@ class Config extends Kohana_Config { return $return; } - public static function moduleexist($module) { + public static function module_config($item) { + return Company::instance()->module_config($item); + } + + public static function module_exist($module) { return array_key_exists(strtolower($module),static::modules()) ? TRUE : FALSE; } - public static function copywrite() { - return '(c) Open Source Billing Development Team'; - } - - /** - * Return our site name - */ - public static function site() { - return $_SERVER['SERVER_NAME']; - } - - public static function sitemodeverbose() { - $modes = array( - Kohana::PRODUCTION=>'Production', - Kohana::STAGING=>'Staging', - Kohana::TESTING=>'Testing', - Kohana::DEVELOPMENT=>'Development', - ); - - return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()]; - } - - public static function submode() { - $submode = Kohana::$config->load('config.debug.submode'); - - return (isset($submode[Request::$client_ip])) ? $submode[Request::$client_ip] : FALSE; + public static function siteid($format=FALSE) { + return Company::instance()->site($format); } public static function sitename() { - return Kohana::$config->load('config')->site_name; + return Company::instance()->name(); } - // Called in Invoice/Emailing to embed the file. - public static function logo_file() { - list ($path,$suffix) = explode('.',static::$logo); - return ($a=Kohana::find_file(sprintf('media/site/%s',Config::siteid()),$path,$suffix)) ? $a : Kohana::find_file('media',$path,$suffix); - } - - public static function logo_uri() { - list ($path,$suffix) = explode('.',static::$logo); - return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),'http'); - } - - public static function logo() { - return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo'))); - } - - public static function login_uri() { - return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? HTML::anchor('user/account/edit',$ao->name()) : HTML::anchor('login',_('Login')); - } - - /** - * Return our caching mechanism - */ - public static function cachetype() { - return is_null(Kohana::$config->load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type; + public static function sitemode() { + return Company::instance()->sitemode(); } /** @@ -203,5 +161,9 @@ class Config extends Kohana_Config { public static function theme() { return Kohana::$config->load('config')->theme; } + + public static function time($date) { + return date(Company::instance()->time_format(),($date ? $date : time())); + } } ?> diff --git a/application/classes/Controller/Admin/Account.php b/application/classes/Controller/Admin/Account.php index 22b461c2..ede9798a 100644 --- a/application/classes/Controller/Admin/Account.php +++ b/application/classes/Controller/Admin/Account.php @@ -60,7 +60,7 @@ class Controller_Admin_Account extends Controller_TemplateDefault_Admin { ORM::factory('Account')->list_active(), 25, array( - 'id'=>array('label'=>'ID','url'=>'user/account/view/'), + 'id'=>array('label'=>'ID','url'=>URL::link('user','account/view/')), 'accnum()'=>array('label'=>'Num'), 'name(TRUE)'=>array('label'=>'Account'), 'email'=>array('label'=>'Email'), @@ -70,7 +70,7 @@ class Controller_Admin_Account extends Controller_TemplateDefault_Admin { array( 'page'=>TRUE, 'type'=>'select', - 'form'=>'user/account/view', + 'form'=>URL::link('user','account/view'), )), )); } diff --git a/application/classes/Controller/Admin/Module.php b/application/classes/Controller/Admin/Module.php index 803a8b54..de96aa89 100644 --- a/application/classes/Controller/Admin/Module.php +++ b/application/classes/Controller/Admin/Module.php @@ -26,7 +26,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin { $methods = array(); // List of classes where all our methods are, including this one. - $classes = Kohana::$config->load('config')->method_directory; + $classes = URL::$method_directory; array_unshift($classes,''); foreach ($classes as $c) { @@ -56,7 +56,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin { $mo->find_all(), 25, array( - 'id'=>array('label'=>'ID','url'=>'admin/module/edit/'), + 'id'=>array('label'=>'ID','url'=>URL::link('admin','module/edit/')), 'name'=>array('label'=>'Name'), 'status'=>array('label'=>'Active'), ), @@ -96,7 +96,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin { $mo->module_method->find_all(), 25, array( - 'id'=>array('label'=>'ID','url'=>'admin/module_method/edit/'), + 'id'=>array('label'=>'ID','url'=>URL::link('admin','module_method/edit/')), 'name'=>array('label'=>'Name'), 'notes'=>array('label'=>'Notes'), 'menu_display'=>array('label'=>'Menu'), @@ -119,7 +119,7 @@ class Controller_Admin_Module extends Controller_TemplateDefault_Admin { $methods, 25, array( - '__VALUE__'=>array('label'=>'Name','url'=>sprintf('admin/module_method/add/%s/',$mo->id)), + '__VALUE__'=>array('label'=>'Name','url'=>URL::link('admin','module_method/add/'.$mo->id)), ), array( 'page'=>TRUE, diff --git a/application/classes/Controller/Admin/Module/Method.php b/application/classes/Controller/Admin/Module/Method.php index def470d8..9bf61ddb 100644 --- a/application/classes/Controller/Admin/Module/Method.php +++ b/application/classes/Controller/Admin/Module/Method.php @@ -40,7 +40,7 @@ class Controller_Admin_Module_Method extends Controller_Admin_Module { 'body'=>sprintf(_('Method %s defined to database'),$mmo->name), )); - HTTP::redirect(sprintf('admin/module/edit/%s',$mo->id)); + HTTP::redirect(URL::link('admin','/module/edit/'.$mo->id)); } else { SystemMessage::add(array( diff --git a/application/classes/Controller/Admin/Setup.php b/application/classes/Controller/Admin/Setup.php index 5a94c528..07bdb6d4 100644 --- a/application/classes/Controller/Admin/Setup.php +++ b/application/classes/Controller/Admin/Setup.php @@ -19,7 +19,7 @@ class Controller_Admin_Setup extends Controller_TemplateDefault_Admin { * View/Update the site configuration */ public function action_edit() { - $o = Config::instance()->so; + $o = Company::instance()->so(); $output = ''; if ($_POST) { @@ -58,7 +58,7 @@ class Controller_Admin_Setup extends Controller_TemplateDefault_Admin { Script::add(array('type'=>'stdin','data'=>' $(document).ready(function() { - $("div[id='.$mo->name.']").load("'.URL::site('admin/'.$mo->name.'/setup').'"); + $("div[id='.$mo->name.']").load("'.URL::link('admin',$mo->name.'/setup',TRUE).'"); });' )); } diff --git a/application/classes/Controller/Admin/Welcome.php b/application/classes/Controller/Admin/Welcome.php index 094f279a..9acc0829 100644 --- a/application/classes/Controller/Admin/Welcome.php +++ b/application/classes/Controller/Admin/Welcome.php @@ -32,7 +32,7 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin { 'account->accnum()'=>array('label'=>'Num'), 'account->name()'=>array('label'=>'Account'), 'account->display("status")'=>array('label'=>'Active'), - 'id'=>array('label'=>'ID','url'=>'user/invoice/view/'), + 'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')), 'total(TRUE)'=>array('label'=>'Total','class'=>'right'), 'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'), ), @@ -51,7 +51,7 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin { 'account->accnum()'=>array('label'=>'Num'), 'account->name()'=>array('label'=>'Account'), 'account->display("status")'=>array('label'=>'Active'), - 'id'=>array('label'=>'ID','url'=>'user/invoice/view/'), + 'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')), 'total(TRUE)'=>array('label'=>'Total','class'=>'right'), 'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'), ), @@ -70,7 +70,7 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin { 'account->accnum()'=>array('label'=>'Num'), 'account->name()'=>array('label'), 'account->display("status")'=>array('label'=>'Active'), - 'id'=>array('label'=>'ID','url'=>'user/invoice/view/'), + 'id'=>array('label'=>'ID','url'=>URL::link('user','invoice/view/')), 'total(TRUE)'=>array('label'=>'Total','class'=>'right'), 'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'), ), @@ -90,7 +90,7 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault_Admin { 'account->accnum()'=>array('label'=>'Num'), 'account->name()'=>array('label'=>'Account'), 'account->display("status")'=>array('label'=>'Active'), - 'id'=>array('label'=>'ID','url'=>'admin/payment/view/'), + 'id'=>array('label'=>'ID','url'=>URL::link('admin','payment/view/')), 'total_amt'=>array('label'=>'Total','class'=>'right'), 'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'), ), diff --git a/application/classes/Controller/Affiliate/Account.php b/application/classes/Controller/Affiliate/Account.php index cb4df5ab..6df4d10e 100644 --- a/application/classes/Controller/Affiliate/Account.php +++ b/application/classes/Controller/Affiliate/Account.php @@ -25,7 +25,7 @@ class Controller_Affiliate_Account extends Controller_TemplateDefault_Affiliate $this->filter(ORM::factory('Account')->list_active(),$this->ao->affiliate->id,'sortkey(TRUE)'), 25, array( - 'id'=>array('label'=>'ID','url'=>'user/account/view/'), + 'id'=>array('label'=>'ID','url'=>URL::link('user','account/view/')), 'accnum()'=>array('label'=>'Num'), 'name(TRUE)'=>array('label'=>'Account'), 'email'=>array('label'=>'Email'), @@ -35,7 +35,7 @@ class Controller_Affiliate_Account extends Controller_TemplateDefault_Affiliate array( 'page'=>TRUE, 'type'=>'select', - 'form'=>'user/account/view', + 'form'=>URL::link('user','account/view'), )), )); } diff --git a/application/classes/Controller/Debug.php b/application/classes/Controller/Debug.php index e30690a5..fc976ed7 100644 --- a/application/classes/Controller/Debug.php +++ b/application/classes/Controller/Debug.php @@ -14,7 +14,7 @@ class Controller_Debug extends Controller_TemplateDefault { $output .= debug::vars(array( 'm'=>__METHOD__, 'site'=>Config::site(), - 'siteID'=>Config::siteid(), + 'siteID'=>Company::instance()->site(), 'siteMode'=>Config::sitemodeverbose(), 'modules'=>Config::appmodules(), )); diff --git a/application/classes/Controller/Login.php b/application/classes/Controller/Login.php index 819ec985..305f8c8f 100644 --- a/application/classes/Controller/Login.php +++ b/application/classes/Controller/Login.php @@ -58,8 +58,8 @@ class Controller_Login extends lnApp_Controller_Login { $et->to = array('account'=>array($mmto->account_id)); $et->variables = array( 'SITE'=>URL::base(TRUE,TRUE), - 'SITE_ADMIN'=>Config::sitename(), - 'SITE_NAME'=>Config::sitename(), + 'SITE_ADMIN'=>Company::instance()->admin(), + 'SITE_NAME'=>Company::instance()->name(), 'TOKEN'=>$mmto->token, 'TOKEN_EXPIRE_MIN'=>$token_expire, 'USER_NAME'=>sprintf('%s %s',$mmto->account->first_name,$mmto->account->last_name), @@ -72,7 +72,7 @@ class Controller_Login extends lnApp_Controller_Login { // Redirect to our password reset, the Auth will validate the token. } elseif (! empty($_REQUEST['token'])) { - HTTP::redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token'])); + HTTP::redirect(URL::link('user','account/resetpassword?token=%s'.$_REQUEST['token'])); } // Show our token screen even if the email was invalid. diff --git a/application/classes/Controller/TemplateDefault.php b/application/classes/Controller/TemplateDefault.php index f8ee500d..32e692d7 100644 --- a/application/classes/Controller/TemplateDefault.php +++ b/application/classes/Controller/TemplateDefault.php @@ -21,7 +21,7 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault { protected function _headimages() { // This is where we should be able to change our country // @todo To implement - $co = Config::instance()->so->country; + $co = Config::country(); HeadImages::add(array( 'img'=>sprintf('img/country/%s.png',strtolower($co->two_code)), 'attrs'=>array('onclick'=>"target='_blank';",'title'=>$co->display('name')) @@ -43,7 +43,7 @@ class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault { } private function _cart() { - return (! Config::moduleexist('cart') OR ! class_exists('Cart') OR ! count(Cart::instance()->contents()) OR strtolower(Request::current()->controller()) == 'cart') ? '' : Cart::instance()->cart_block(); + return (! Config::module_exist('cart') OR ! class_exists('Cart') OR ! count(Cart::instance()->contents()) OR strtolower(Request::current()->controller()) == 'cart') ? '' : Cart::instance()->cart_block(); } } ?> diff --git a/application/classes/Controller/TemplateDefault/Admin.php b/application/classes/Controller/TemplateDefault/Admin.php index f8731360..f68c44ae 100644 --- a/application/classes/Controller/TemplateDefault/Admin.php +++ b/application/classes/Controller/TemplateDefault/Admin.php @@ -15,11 +15,11 @@ class Controller_TemplateDefault_Admin extends Controller_TemplateDefault_User { $module = Request::current()->controller(); if ($_POST AND isset($_POST['module_config'][$module])) - Config::instance()->so->module_config($module,$_POST['module_config'][$module])->save(); + Config::instance()->module_config($module,$_POST['module_config'][$module])->save(); if ($config_items) { $output = ''; - $mc = Config::instance()->so->module_config($module); + $mc = Config::instance()->module_config($module); $output .= Form::open(); $output .= View::factory('setup/admin/module/head'); diff --git a/application/classes/Controller/Tree.php b/application/classes/Controller/Tree.php index a4cae5d8..1d9b86dd 100644 --- a/application/classes/Controller/Tree.php +++ b/application/classes/Controller/Tree.php @@ -62,9 +62,11 @@ class Controller_Tree extends lnApp_Controller_Tree { foreach ($methods as $id => $mmo) { if (preg_match('/_/',$mmo->name)) { list($mode,$action) = explode('_',$mmo->name); - $url = URL::site(sprintf('%s/%s/%s',$mode,$mmo->module->name,$action)); + + $url = URL::link($mode,$mmo->module->name.'/'.$action,TRUE); + } else { - $url = URL::site(sprintf('%s/%s',$mmo->module->name,$mmo->name)); + $url = URL::site($mmo->module->name.'/'.$mmo->name); } // We can split our menus into sub menus using the _ char. diff --git a/application/classes/Currency.php b/application/classes/Currency.php index 73db2391..87b8a194 100644 --- a/application/classes/Currency.php +++ b/application/classes/Currency.php @@ -11,11 +11,11 @@ */ class Currency { public static function display($amount) { - return Num::format($amount,Config::instance()->so->decimal_place,TRUE); + return Num::format($amount,Company::instance()->decimals(),TRUE); } public static function round($amount) { - return Num::round($amount,Config::instance()->so->decimal_place); + return Num::round($amount,Company::instance()->decimals()); } } ?> diff --git a/application/classes/DB.php b/application/classes/DB.php index 58e9796d..93db8698 100644 --- a/application/classes/DB.php +++ b/application/classes/DB.php @@ -16,8 +16,8 @@ class DB extends Kohana_DB { { $db = new Database_Query_Builder_Delete($table); - if (! in_array($table,Config::$no_site_id_tables)) - return $db->where($table.'.site_id','=',Config::siteid()); + if (! in_array($table,ORM::$no_site_id_tables)) + return $db->where($table.'.site_id','=',Company::instance()->site()); else return $db; } @@ -27,8 +27,8 @@ class DB extends Kohana_DB { { $db = new Database_Query_Builder_Update($table); - if (! in_array($table,Config::$no_site_id_tables)) - return $db->where($table.'.site_id','=',Config::siteid()); + if (! in_array($table,ORM::$no_site_id_tables)) + return $db->where($table.'.site_id','=',Company::instance()->site()); else return $db; } diff --git a/application/classes/Model/Account.php b/application/classes/Model/Account.php index e9caf175..bdfe4e43 100644 --- a/application/classes/Model/Account.php +++ b/application/classes/Model/Account.php @@ -46,7 +46,7 @@ class Model_Account extends Model_Auth_UserDefault { } public function accnum() { - return sprintf('%s-%04s',Config::siteid(TRUE),$this->id); + return sprintf('%s-%04s',Company::instance()->site(TRUE),$this->id); } public function sortkey($withcompany=FALSE) { @@ -115,10 +115,6 @@ class Model_Account extends Model_Auth_UserDefault { foreach ($this->invoices_due($date) as $io) $result += $io->due(); - // @todo This shouldnt really be required - if ($result < 0) - throw new Kohana_Exception($result); - return $format ? Currency::display($result) : $result; } diff --git a/application/classes/Model/Record/Id.php b/application/classes/Model/Record/Id.php index df7af859..b502b67e 100644 --- a/application/classes/Model/Record/Id.php +++ b/application/classes/Model/Record/Id.php @@ -25,7 +25,7 @@ class Model_Record_Id extends ORM_OSB { $max = DB::select(array('MAX(id)','id')) ->from($mo->name) - ->where('site_id','=',Config::siteid()); + ->where('site_id','=',Company::instance()->site()); $this->id = $max->execute()->get('id'); } diff --git a/application/classes/Model/Setup.php b/application/classes/Model/Setup.php index 99aa03ec..0d64273c 100644 --- a/application/classes/Model/Setup.php +++ b/application/classes/Model/Setup.php @@ -18,6 +18,7 @@ class Model_Setup extends ORM_OSB { protected $_updated_column = FALSE; protected $_has_one = array( + 'account'=>array('foreign_key'=>'id','far_key'=>'admin_id'), 'country'=>array('foreign_key'=>'id','far_key'=>'country_id'), 'language'=>array('foreign_key'=>'id','far_key'=>'language_id'), ); diff --git a/application/classes/ORM.php b/application/classes/ORM.php index 8a0c8862..38a7d7d5 100644 --- a/application/classes/ORM.php +++ b/application/classes/ORM.php @@ -64,7 +64,7 @@ abstract class ORM extends Kohana_ORM { return (int) DB::select(array(DB::expr('COUNT(*)'), 'records_found')) ->from($this->_has_many[$alias]['through']) ->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk()) - ->where('site_id', '=', Config::siteid()) + ->where('site_id', '=', Company::instance()->site()) ->execute($this->_db)->get('records_found'); } @@ -81,14 +81,17 @@ abstract class ORM extends Kohana_ORM { ->from($this->_has_many[$alias]['through']) ->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk()) ->where($this->_has_many[$alias]['far_key'], 'IN', $far_keys) - ->where('site_id', '=', Config::siteid()) + ->where('site_id', '=', Company::instance()->site()) ->execute($this->_db)->get('records_found'); // Rows found need to match the rows searched return (int) $count; } - /** OSB SPECIFIC ENHANCEMENTS ** + /** OSB SPECIFIC ENHANCEMENTS **/ + + // Tables that do not have a site_id column + public static $no_site_id_tables = array('setup','country','currency','language','tax'); /** * Add our OSB site_id to each SELECT query @@ -96,8 +99,8 @@ abstract class ORM extends Kohana_ORM { */ final protected function _build($type) { // Exclude tables without site ID's - if (! in_array($this->_table_name,Config::$no_site_id_tables)) - $this->where($this->_object_name.'.site_id','=',Config::siteid()); + if (! in_array($this->_table_name,ORM::$no_site_id_tables)) + $this->where($this->_object_name.'.site_id','=',Company::instance()->site()); return parent::_build($type); } diff --git a/application/classes/ORM/OSB.php b/application/classes/ORM/OSB.php index e4f2c93c..24e51983 100644 --- a/application/classes/ORM/OSB.php +++ b/application/classes/ORM/OSB.php @@ -135,7 +135,7 @@ abstract class ORM_OSB extends ORM { } public function config($key) { - $mc = Config::instance()->so->module_config($this->_object_name); + $mc = Config::instance()->module_config($this->_object_name); return empty($mc[$key]) ? '' : $mc[$key]; } @@ -172,7 +172,7 @@ abstract class ORM_OSB extends ORM { return TRUE; $model->_changed[$field] = $field; - $model->$field = Config::siteid(); + $model->$field = Company::instance()->site(); return TRUE; } diff --git a/application/classes/Request.php b/application/classes/Request.php new file mode 100644 index 00000000..2d0b0586 --- /dev/null +++ b/application/classes/Request.php @@ -0,0 +1,31 @@ +a,reseller=>r. + * + * @param string $directory Directory to execute the controller from + * @return mixed + */ + public function directory($directory = NULL) { + // If $directory is NULL, we are a getter and see if we need to expand the directory + if ($directory === NULL AND $this->_directory) + $this->_directory = URL::dir($this->_directory); + + return parent::directory($directory); + } +} +?> diff --git a/application/classes/URL.php b/application/classes/URL.php new file mode 100644 index 00000000..3174e142 --- /dev/null +++ b/application/classes/URL.php @@ -0,0 +1,54 @@ +'a', + 'affiliate'=>'affiliate', // @todo To retire + 'reseller'=>'r', + 'user'=>'u', + ); + + /** + * Wrapper to provide a URL::site() link based on function + */ + public static function link($dir,$src,$site=FALSE) { + if (! $dir) + return $src; + + if (! array_key_exists($dir,URL::$method_directory)) + throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src)); + + $x = URL::$method_directory[$dir].'/'.$src; + + return $site ? URL::site($x) : $x; + } + + /** + * Function to reveal the real directory for a URL + */ + public static function dir($dir) { + // Quick check if we can do something here + if (! in_array(strtolower($dir),URL::$method_directory)) + return $dir; + + // OK, we can, find it. + foreach (URL::$method_directory as $k=>$v) + if (strtolower($dir) == $v) + return ucfirst($k); + + // If we get here, we didnt have anything. + return $dir; + } +} +?> diff --git a/application/config/config.php b/application/config/config.php index 432ce3e6..266eaec3 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -12,32 +12,18 @@ */ return array( - 'appname' => '', + 'appname' => 'OS Billing', 'cache_type' => 'file', 'email_from' => array('noreply@graytech.net.au'=>'Graytech Hosting'), 'email_admin_only'=> array( // 'adsl_traffic_notice'=>array('deon@leenooks.vpn'=>'Deon George'), ), - 'method_directory'=> array( // Out method paths for the different functions - 'admin', - 'affiliate', - 'reseller', - 'task', - 'user', - ), 'method_security' => TRUE, // Enables Method Security. Setting to false means any method can be run without authentication 'session_change_trigger'=>array( // Updates to tables to make when our session ID is changed 'Cart'=>'session_id', ), - 'site' => array( - '172.31.9.4'=>1, - 'www.graytech.net.au'=>1, - ), - 'site_debug' => FALSE, 'bsb' => '633-000', // @todo This should come from the DB 'accnum' => '120 440 821', // @todo This should come from the DB - 'site_name' => 'Graytech Hosting Pty Ltd', // @todo This should come from the DB - 'taxid' => 'ABN: 49 106 229 476', // @todo This should come from the DB 'theme' => 'yaml', // @todo This should be in the DB 'tmpdir' => '/tmp', ); diff --git a/application/config/debug.php b/application/config/debug.php index 4865b5c2..77608137 100644 --- a/application/config/debug.php +++ b/application/config/debug.php @@ -17,6 +17,7 @@ return array 'etag'=>FALSE, // Force generating ETAGS 'checkout_notify'=>FALSE, // Test mode to test a particular checkout_notify item 'invoice'=>0, // Number of invoices to generate in a pass + 'site'=>FALSE, // Glogal site debug 'show_inactive'=>FALSE, // Show Inactive Items 'task_sim'=>FALSE, // Simulate running tasks ); diff --git a/application/views/module/admin/method_detail_body.php b/application/views/module/admin/method_detail_body.php index 6dd67ba1..bf364d03 100644 --- a/application/views/module/admin/method_detail_body.php +++ b/application/views/module/admin/method_detail_body.php @@ -1,6 +1,6 @@ - display('name'); ?> + display('name'); ?> display('notes'); ?> display('status'); ?> diff --git a/application/views/yaml/page.php b/application/views/yaml/page.php index 38de4f14..669a2913 100644 --- a/application/views/yaml/page.php +++ b/application/views/yaml/page.php @@ -26,8 +26,8 @@
- so->country_id); ?> - so->country->display('name'); ?> + + display('name'); ?>
| @@ -36,7 +36,7 @@ |
- + name(); ?>