Optimised Company() Setup() Config() and changed method_directory into URL
This commit is contained in:
@@ -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();
|
||||
|
@@ -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='<br/>') {
|
||||
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='<br/>') {
|
||||
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='<br/>') {
|
||||
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='<br/>') {
|
||||
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 '';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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()));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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'),
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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(
|
||||
|
@@ -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).'");
|
||||
});'
|
||||
));
|
||||
}
|
||||
|
@@ -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'),
|
||||
),
|
||||
|
@@ -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'),
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
@@ -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(),
|
||||
));
|
||||
|
@@ -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.
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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');
|
||||
|
@@ -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.
|
||||
|
@@ -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());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
}
|
||||
|
@@ -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'),
|
||||
);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
31
application/classes/Request.php
Normal file
31
application/classes/Request.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Request. Uses the [Route] class to determine what
|
||||
* [Controller] to send the request to.
|
||||
*
|
||||
* @package lnApp/Modifications
|
||||
* @category Classes
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Request extends Kohana_Request {
|
||||
/**
|
||||
* Sets and gets the directory for the controller.
|
||||
*
|
||||
* We override the Kohana version, so that we can have short directory URLs.
|
||||
* eg: admin=>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);
|
||||
}
|
||||
}
|
||||
?>
|
54
application/classes/URL.php
Normal file
54
application/classes/URL.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class overrides Kohana's URL
|
||||
*
|
||||
* @package OSB/Modifications
|
||||
* @category Classes
|
||||
* @category Helpers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class URL extends Kohana_URL {
|
||||
// Our method paths for different functions
|
||||
public static $method_directory = array(
|
||||
'admin'=>'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;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user