Site setup fixes

This commit is contained in:
Deon George 2011-12-30 18:10:02 +11:00
parent 125407656d
commit acd1bf116c
16 changed files with 231 additions and 29 deletions

View File

@ -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='<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')));
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='<br/>') {
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() {

View File

@ -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;
}
}
?>

View File

@ -0,0 +1,47 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Siet Configuration Setup
*
* @package lnApp
* @subpackage Page/Setup
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Setup extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'edit'=>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,
));
}
}
?>

View File

@ -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());

View File

@ -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;
}
}
?>

View File

@ -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.

View File

@ -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;
}
}
?>

View File

@ -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);

View File

@ -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));
}
}
?>

View File

@ -0,0 +1,46 @@
<!-- @todo NEEDS TO BE TRANSLATED -->
<table class="box-full">
<tr>
<td class="head" style="width: 25%;">Site Name</td>
<td style="width: 75%;"><?php echo Form::input('site_details[name]',$o->site_details('name')); ?></td>
</tr>
<tr>
<td class="head">Site Address 1</td>
<td><?php echo Form::input('site_details[address1]',$o->site_details('address1')); ?></td>
</tr>
<tr>
<td class="head">Site Address 2</td>
<td><?php echo Form::input('site_details[address2]',$o->site_details('address2')); ?></td>
</tr>
<tr>
<td class="head">City</td>
<td><?php echo Form::input('site_details[city]',$o->site_details('city')); ?></td>
</tr>
<tr>
<td class="head">State</td>
<td><?php echo Form::input('site_details[state]',$o->site_details('state')); ?></td>
</tr>
<tr>
<td class="head">Postal Code</td>
<td><?php echo Form::input('site_details[pcode]',$o->site_details('pcode')); ?></td>
</tr>
<tr>
<td class="head">Country</td>
<td><?php echo StaticList_Module::form('country_id','country',61,'id','name',array(),null,array('class'=>'form_button'));?></td>
</tr>
<tr>
<td class="spacer" colspan="2">&nbsp;</td>
</tr>
<tr>
<td class="head">Phone</td>
<td><?php echo Form::input('site_details[phone]',$o->site_details('phone')); ?></td>
</tr>
<tr>
<td class="head">Fax</td>
<td><?php echo Form::input('site_details[fax]',$o->site_details('fax')); ?></td>
</tr>
<tr>
<td class="head">Email</td>
<td><?php echo Form::input('site_details[email]',$o->site_details('email')); ?></td>
</tr>
</table>

View File

@ -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');
}
}

View File

@ -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.

View File

@ -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);

View File

@ -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;

View File

@ -5,7 +5,7 @@
<table class="company_details" border="0">
<tr>
<td class="logo"><?php echo Config::logo(); ?></td>
<td class="address"><span class="company_name"><?php echo Config::sitename(); ?></span><br/><?php echo Company::address(); ?><br/><?php echo Company::contacts(); ?></td>
<td class="address"><span class="company_name"><?php echo Company::name(); ?></span><br/><?php echo Company::address(); ?><br/><?php echo Company::contacts(); ?></td>
</tr>
</table>
</td>

View File

@ -5,7 +5,7 @@
<table class="company_details" border="0">
<tr>
<td class="logo"><?php echo Config::logo(); ?></td>
<td class="address"><span class="company_name"><?php echo Config::sitename(); ?></span><br/><?php echo Company::address(); ?><br/><?php echo Company::contacts(); ?></td>
<td class="address"><span class="company_name"><?php echo Company::name(); ?></span><br/><?php echo Company::address(); ?><br/><?php echo Company::contacts(); ?></td>
</tr>
</table>
</td>