diff --git a/application/classes/company.php b/application/classes/company.php index 308e5e3c..69282d92 100644 --- a/application/classes/company.php +++ b/application/classes/company.php @@ -16,35 +16,38 @@ class Company { } public static function name() { - return Config::sitename(); + return Config::instance()->so->site_details('name'); } - public static function street() { - return Config::instance()->so->display('site_address'); + 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'))); + else + return Config::instance()->so->site_details('address1'); } public static function city() { - return Config::instance()->so->display('site_city'); + return Config::instance()->so->site_details('city'); } public static function state() { - return Config::instance()->so->display('site_state'); + return Config::instance()->so->site_details('state'); } public static function pcode() { - return Config::instance()->so->display('site_zip'); + return Config::instance()->so->site_details('pcode'); } public static function address($ln='
') { - return implode($ln,array(static::street(),sprintf('%s, %s %s',static::city(),static::state(),static::pcode()))); + 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->display('site_phone'); + return Config::instance()->so->site_details('phone'); } public static function fax() { - return Config::instance()->so->display('site_fax'); + return Config::instance()->so->site_details('fax'); } public static function contacts() { diff --git a/application/classes/config.php b/application/classes/config.php index 8f380b88..bd787ca0 100644 --- a/application/classes/config.php +++ b/application/classes/config.php @@ -13,6 +13,7 @@ class Config extends lnApp_Config { // Our setup object public $so; + public static $no_site_id_tables = array('setup','country','currency','tax'); /** * Load our site configuration from the DB @@ -53,5 +54,17 @@ class Config extends lnApp_Config { public static function moduleexist($module) { return array_key_exists($module,static::modules()) ? TRUE : FALSE; } + + public static function sitename() { + return Company::name(); + } + + public static function siteid() { + return Config::instance()->loadsite()->so->id; + } + + public static function sitemode() { + return Config::instance()->loadsite()->so->status; + } } ?> diff --git a/application/classes/controller/admin/setup.php b/application/classes/controller/admin/setup.php new file mode 100644 index 00000000..7f10c6b4 --- /dev/null +++ b/application/classes/controller/admin/setup.php @@ -0,0 +1,47 @@ +TRUE, + ); + + /** + * View/Update the site configuration + */ + public function action_edit() { + $o = Config::instance()->so; + $output = ''; + + if ($_POST) { + // Entry updated + if ($o->values($_POST)->check() AND $o->save()) + SystemMessage::add(array( + 'title'=>'Site Configuration Recorded', + 'type'=>'info', + 'body'=>'Site Config successfully recorded.', + )); + } + + $output .= Form::open(); + $output .= View::factory($this->viewpath()) + ->set('o',$o);; + $output .= Form::submit('submit','submit',array('class'=>'form_button')); + $output .= Form::close(); + + Block::add(array( + 'title'=>_('Update Site Configuration'), + 'body'=>$output, + )); + } +} +?> diff --git a/application/classes/controller/lnapp/templatedefault.php b/application/classes/controller/lnapp/templatedefault.php index b6b58116..b5f1fc0a 100644 --- a/application/classes/controller/lnapp/templatedefault.php +++ b/application/classes/controller/lnapp/templatedefault.php @@ -163,7 +163,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template { $this->meta->language = Config::instance()->so->language_id; // Copyright - $this->meta->copywrite = Config::instance()->so->site_name; + $this->meta->copywrite = Config::sitename(); // Copyright $this->meta->description = sprintf('%s::%s',$this->request->controller(),$this->request->action()); diff --git a/application/classes/db.php b/application/classes/db.php index cd085078..58e9796d 100644 --- a/application/classes/db.php +++ b/application/classes/db.php @@ -16,7 +16,10 @@ class DB extends Kohana_DB { { $db = new Database_Query_Builder_Delete($table); - return $db->where($table.'.site_id','=',Config::siteid()); + if (! in_array($table,Config::$no_site_id_tables)) + return $db->where($table.'.site_id','=',Config::siteid()); + else + return $db; } // Add the site_id to the update query @@ -24,7 +27,10 @@ class DB extends Kohana_DB { { $db = new Database_Query_Builder_Update($table); - return $db->where($table.'.site_id','=',Config::siteid()); + if (! in_array($table,Config::$no_site_id_tables)) + return $db->where($table.'.site_id','=',Config::siteid()); + else + return $db; } } ?> diff --git a/application/classes/lnapp/config.php b/application/classes/lnapp/config.php index fe83e45a..28753061 100644 --- a/application/classes/lnapp/config.php +++ b/application/classes/lnapp/config.php @@ -41,14 +41,14 @@ abstract class lnApp_Config extends Kohana_Config { * Work out our site ID for multiehosting */ public static function siteid() { - return Config::instance()->loadsite()->so->id; + return Kohana::Config('config.site.id'); } /** * Work out our site mode (dev,test,prod) */ public static function sitemode() { - return Config::instance()->loadsite()->so->status; + return Kohana::Config('config.site.mode'); } public static function sitemodeverbose() { @@ -69,7 +69,7 @@ abstract class lnApp_Config extends Kohana_Config { } public static function sitename() { - return Config::instance()->loadsite()->so->site_name; + return Kohana::Config('config.site.name'); } // Called in Invoice/Emailing to embed the file. diff --git a/application/classes/model/setup.php b/application/classes/model/setup.php index 04d6acd8..7d5f1023 100644 --- a/application/classes/model/setup.php +++ b/application/classes/model/setup.php @@ -14,8 +14,78 @@ * @license http://dev.leenooks.net/license.html */ class Model_Setup extends ORMOSB { + // Setup doesnt use the update column + protected $_updated_column = FALSE; + protected $_has_one = array( 'country'=>array('foreign_key'=>'id','far_key'=>'country_id'), ); + + public function rules() { + $r = parent::rules(); + + // This module doesnt use site_id. + unset($r['site_id']); + + return $r; + } + + /** + * Get/Set Module Configuration + * + * @param $key Module name. + * @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value. + */ + public function module_config($key,array $value=NULL) { + // If we are not loaded, we dont have any config. + if (! $this->loaded() OR (is_null($value) AND ! $this->module_config)) + return array(); + + $mo = ORM::factory('module')->where('name','=',$key)->find(); + + if (! $mo->loaded()) + throw new Kohana_Exception('Unknown module :name',array(':name'=>$key)); + + static $mc = array(); + + if (! $mc) + $mc = $this->blob($this->module_config); + + // If $value is NULL, we are a getter + if ($value === NULL) + return empty($mc[$mo->id]) ? array() : $mc[$mo->id]; + + // Store new value + $mc[$mo->id] = $value; + $this->module_config = $this->blob($mc,TRUE); + $this->save(); + + return $this->saved(); + } + + /** + * Get/Set our Site Configuration from the DB + * + * @param $key Key + * @param $value Values to store. If NULL, retrieves the value stored, otherwise stores value. + */ + public function site_details($key,array $value=NULL) { + static $sc = array(); + + if (! $sc AND $this->site_details) + $sc = $this->blob($this->site_details); + + if (! in_array($key,array('name','address1','address2','city','state','pcode','phone','fax','email'))) + throw new Kohana_Exception('Unknown Site Configuration Key :key',array(':key'=>$key)); + + // If $value is NULL, we are a getter + if ($value === NULL) + return empty($sc[$key]) ? '' : $sc[$key]; + + // Store new value + $sc[$key] = $value; + + return $value; + } } ?> diff --git a/application/classes/orm.php b/application/classes/orm.php index b4742a43..5db74939 100644 --- a/application/classes/orm.php +++ b/application/classes/orm.php @@ -40,7 +40,7 @@ class ORM extends Kohana_ORM { // Add our OSB site_id to each SELECT query final protected function _build($type) { // Exclude tables without site ID's - if (! in_array($this->_table_name,array('setup','country','currency','tax'))) + if (! in_array($this->_table_name,Config::$no_site_id_tables)) $this->where($this->_table_name.'.site_id','=',Config::siteid()); return parent::_build($type); diff --git a/application/classes/ormosb.php b/application/classes/ormosb.php index 89a80542..075c5c36 100644 --- a/application/classes/ormosb.php +++ b/application/classes/ormosb.php @@ -104,8 +104,25 @@ abstract class ORMOSB extends ORM { $model->$field = serialize($value); } + public function save(Validation $validation = NULL) { + // Find any fields that have changed, and that are blobs, and encode them. + if ($this->_changed) + foreach ($this->_changed as $c) + if ($this->_table_columns[$c]['data_type'] == 'blob') + $this->$c = $this->blob($this->$c,TRUE); + + return parent::save($validation); + } + public function changed() { return $this->_changed; } + + /** + * Retrieve and Store DB BLOB data. + */ + protected function blob($data,$set=FALSE) { + return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data)); + } } ?> diff --git a/application/views/setup/admin/edit.php b/application/views/setup/admin/edit.php new file mode 100644 index 00000000..50fc90bc --- /dev/null +++ b/application/views/setup/admin/edit.php @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Site Namesite_details('name')); ?>
Site Address 1site_details('address1')); ?>
Site Address 2site_details('address2')); ?>
Citysite_details('city')); ?>
Statesite_details('state')); ?>
Postal Codesite_details('pcode')); ?>
Country'form_button'));?>
 
Phonesite_details('phone')); ?>
Faxsite_details('fax')); ?>
Emailsite_details('email')); ?>
diff --git a/modules/email/classes/email/template.php b/modules/email/classes/email/template.php index ed5e3aef..398ffd73 100644 --- a/modules/email/classes/email/template.php +++ b/modules/email/classes/email/template.php @@ -131,7 +131,7 @@ class Email_Template { throw new Kohana_Exception('Component :component has not been configured in :method',array(':component'=>$component,':method'=>__METHOD__)); } } else { - $sm->setSubject(_('Email from').' '.Config::sitename()); + $sm->setSubject(_('Email from').' '.Company::name()); $sm->setBody(print_r($this->email_data['variables'],TRUE),'text/plain'); } } diff --git a/modules/invoice/classes/controller/task/invoice.php b/modules/invoice/classes/controller/task/invoice.php index 34f2d8ca..6758c924 100644 --- a/modules/invoice/classes/controller/task/invoice.php +++ b/modules/invoice/classes/controller/task/invoice.php @@ -77,7 +77,7 @@ class Controller_Task_Invoice extends Controller_Task { 'FIRST_NAME'=>$io->account->first_name, 'INV_NUM'=>$io->refnum(), 'INV_URL'=>URL::site('user/invoice/view/'.$io->id,'http'), - 'SITE_NAME'=>Config::sitename(), + 'SITE_NAME'=>Company::name(), ); // @todo Record email log id if possible. @@ -136,13 +136,13 @@ class Controller_Task_Invoice extends Controller_Task { $et->variables = array( 'DUE'=>$io->due(TRUE), 'DUE_DATE'=>$io->display('due_date'), - 'EMAIL'=>'accounts@graytech.net.au', // @todo This should come from a config. + 'EMAIL'=>Company::email(), 'FIRST_NAME'=>$io->account->first_name, 'INV_NUM'=>$io->refnum(), 'INV_URL'=>URL::site('user/invoice/view/'.$io->id,'http'), 'LATE_FEE'=>'5.50', // @todo This should come from a config file. 'PAYMENTS_TABLE'=>$io->account->payment->list_recent_table(), - 'SITE_NAME'=>Config::sitename(), + 'SITE_NAME'=>Company::name(), ); // @todo Record email log id if possible. @@ -301,13 +301,13 @@ class Controller_Task_Invoice extends Controller_Task { $et->variables = array( 'DUE'=>$io->due(TRUE), 'DUE_DATE'=>$io->display('due_date'), - 'EMAIL'=>'accounts@graytech.net.au', // @todo This should come from a config. + 'EMAIL'=>Company::email(), 'FIRST_NAME'=>$io->account->first_name, 'HTML_INVOICE'=>$io->html(), 'INV_NUM'=>$io->refnum(), 'INV_URL'=>URL::site('user/invoice/view/'.$io->id,'http'), 'INV_URL_DOWNLOAD'=>URL::site(sprintf('user/invoice/download/%s?token=%s',$io->id,$token),'http'), - 'SITE_NAME'=>Config::sitename(), + 'SITE_NAME'=>Company::name(), ); // @todo Record email log id if possible. diff --git a/modules/invoice/classes/invoice/tcpdf.php b/modules/invoice/classes/invoice/tcpdf.php index 71de4f6e..06ad3b79 100644 --- a/modules/invoice/classes/invoice/tcpdf.php +++ b/modules/invoice/classes/invoice/tcpdf.php @@ -51,8 +51,8 @@ abstract class Invoice_TCPDF extends TCPDF { // Set up the invoice $this->SetCreator('Open Source Billing'); - $this->SetAuthor(Config::sitename()); - $this->SetTitle(sprintf('%s Invoice',Config::sitename())); + $this->SetAuthor(Company::name()); + $this->SetTitle(sprintf('%s Invoice',Company::name())); $this->SetSubject(sprintf('Invoice #%06s',$this->io->id())); $this->SetKeywords($this->io->id()); $this->SetAutoPageBreak(TRUE,25); diff --git a/modules/invoice/classes/invoice/tcpdf/default.php b/modules/invoice/classes/invoice/tcpdf/default.php index 30270f8c..93890179 100644 --- a/modules/invoice/classes/invoice/tcpdf/default.php +++ b/modules/invoice/classes/invoice/tcpdf/default.php @@ -37,7 +37,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF { $x = 40; $y = 7; $this->SetFont('helvetica','B',10); - $this->SetXY($x,$y); $this->Cell(0,0,Config::sitename()); $y += 4; + $this->SetXY($x,$y); $this->Cell(0,0,Company::name()); $y += 4; $this->SetFont('helvetica','',10); $this->SetXY($x,$y); $this->Cell(0,0,Company::taxid()); $y += 6; @@ -65,7 +65,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF { $this->SetFont('helvetica','',8); $this->SetXY($x,$y); $this->Cell(0,0,_('Please return this portion with your cheque or money order')); $y +=3; - $this->SetXY($x,$y); $this->Cell(0,0,_('made payable to').' '.Config::sitename()); + $this->SetXY($x,$y); $this->Cell(0,0,_('made payable to').' '.Company::name()); // Due Date $x = 110; $y = 200; @@ -91,7 +91,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF { // Company Address $y = 216; $this->SetFont('helvetica','',10); - $this->SetXY(18,$y); $this->Cell(0,0,Config::sitename()); $y += 4; + $this->SetXY(18,$y); $this->Cell(0,0,Company::name()); $y += 4; $this->SetXY(18,$y); $this->Cell(0,0,Company::street()); $y += 4; $this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4; diff --git a/modules/invoice/views/invoice/user/email.php b/modules/invoice/views/invoice/user/email.php index 81ff34e5..6f2166ea 100644 --- a/modules/invoice/views/invoice/user/email.php +++ b/modules/invoice/views/invoice/user/email.php @@ -5,7 +5,7 @@ - +




diff --git a/modules/invoice/views/invoice/user/view.php b/modules/invoice/views/invoice/user/view.php index 08eb0d48..cb828d9e 100644 --- a/modules/invoice/views/invoice/user/view.php +++ b/modules/invoice/views/invoice/user/view.php @@ -5,7 +5,7 @@ - +