Site/Module setup work and auto_format fixes

This commit is contained in:
Deon George 2012-01-02 12:35:47 +11:00
parent 407eed04c9
commit a464d73f9a
19 changed files with 138 additions and 26 deletions

View File

@ -65,8 +65,13 @@ class Company {
} }
public static function taxid() { public static function taxid() {
// @todo Details should be obtained from DB // Tax ID details are stored in invoice config
return Kohana::config('config.taxid'); $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() { public static function render() {

View File

@ -33,15 +33,42 @@ class Controller_Admin_Setup extends Controller_TemplateDefault_Admin {
} }
$output .= Form::open(); $output .= Form::open();
// site_details
$output .= View::factory($this->viewpath()) $output .= View::factory($this->viewpath())
->set('o',$o);; ->set('o',$o);;
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
$output .= '<div>'.Form::submit('submit','submit',array('class'=>'form_button')).'</div>';
$output .= Form::close(); $output .= Form::close();
Block::add(array( Block::add(array(
'title'=>_('Update Site Configuration'), 'title'=>_('Update Site Configuration'),
'body'=>$output, 'body'=>$output,
)); ));
// module_config
$output = '';
$output .= View::factory($this->viewpath().'/module/head');
foreach ($o->module_config as $mid => $detail) {
$mo = ORM::factory('module',$mid);
$output .= View::factory($this->viewpath().'/module/body')
->set('mo',$mo);
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("div[id='.$mo->name.']").load("'.URL::site('admin/'.$mo->name.'/setup').'");
});'
));
}
$output .= View::factory($this->viewpath().'/module/foot');
Block::add(array(
'title'=>_('Update Module Specific Configuration'),
'body'=>$output,
));
} }
} }
?> ?>

View File

@ -11,5 +11,37 @@
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Controller_TemplateDefault_Admin extends Controller_TemplateDefault_User { class Controller_TemplateDefault_Admin extends Controller_TemplateDefault_User {
protected function setup(array $config_items=array()) {
$module = Request::current()->controller();
if ($_POST AND isset($_POST['module_config'][$module]))
Config::instance()->so->module_config($module,$_POST['module_config'][$module])->save();
if ($config_items) {
$output = '';
$mc = Config::instance()->so->module_config($module);
$output .= Form::open();
$output .= View::factory('setup/admin/module/head');
foreach ($config_items as $k=>$v)
$output .= View::factory('setup/admin/module/body')
->set('module',$module)
->set('mc',$mc)
->set('key',$k)
->set('info',$v)
->set('val',empty($mc[$k]) ? '' : $mc[$k]);
$output .= View::factory('setup/admin/module/foot');
$output .= Form::submit('submit',_('Submit'),array('class'=>'form_button'));
$output .= Form::close();
Block::add(array(
'title'=>sprintf('%s: %s',strtoupper($module),_('Configuration')),
'body'=>$output,
));
}
}
} }
?> ?>

View File

@ -17,6 +17,10 @@ class Controller_TemplateDefault_User extends Controller_TemplateDefault {
protected $ao; protected $ao;
public function before() { public function before() {
// If our action doesnt exist, no point processing any further.
if (! method_exists($this,'action_'.Request::current()->action()))
return;
if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()]))) if (! count($this->secure_actions) OR (! isset($this->secure_actions[Request::current()->action()])))
throw new Kohana_Exception('Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action())); throw new Kohana_Exception('Class has no security defined :class, or no security configured for :method',array(':class'=>get_class($this),':method'=>Request::current()->action()));

View File

@ -46,14 +46,17 @@ class Model_Setup extends ORMOSB {
if (! $mo->loaded()) if (! $mo->loaded())
throw new Kohana_Exception('Unknown module :name',array(':name'=>$key)); throw new Kohana_Exception('Unknown module :name',array(':name'=>$key));
$mc = $this->module_config ? $this->module_config : array();
// If $value is NULL, we are a getter // If $value is NULL, we are a getter
if ($value === NULL) if ($value === NULL)
return empty($this->module_config[$mo->id]) ? array() : $this->module_config[$mo->id]; return empty($mc[$mo->id]) ? array() : $mc[$mo->id];
// Store new value // Store new value
$this->module_config[$mo->id] = $value; $mc[$mo->id] = $value;
$this->module_config = $mc;
return $value; return $this;
} }
/** /**
@ -73,7 +76,7 @@ class Model_Setup extends ORMOSB {
// Store new value // Store new value
$sc[$key] = $value; $sc[$key] = $value;
return $value; return $this;
} }
} }
?> ?>

View File

@ -106,9 +106,18 @@ abstract class ORMOSB extends ORM {
public function __get($column) { public function __get($column) {
// If the column is a blob, we'll decode it automatically // If the column is a blob, we'll decode it automatically
if (array_key_exists($column,$this->_object) AND $this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) { if (array_key_exists($column,$this->_table_columns) AND $this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
// In case our blob hasnt been saved as one.
try {
$this->_object[$column] = $this->blob($this->_object[$column]); $this->_object[$column] = $this->blob($this->_object[$column]);
}
catch(Exception $e) {
// @todo Log this exception
echo Kohana_Exception::text($e), "\n";
echo debug_print_backtrace();
}
$this->_table_columns[$column]['auto_convert'] = TRUE; $this->_table_columns[$column]['auto_convert'] = TRUE;
} }
@ -119,9 +128,14 @@ abstract class ORMOSB extends ORM {
// Find any fields that have changed, and that are blobs, and encode them. // Find any fields that have changed, and that are blobs, and encode them.
if ($this->_changed) if ($this->_changed)
foreach ($this->_changed as $c) foreach ($this->_changed as $c)
if ($this->_table_columns[$c]['data_type'] == 'blob') if ($this->_table_columns[$c]['data_type'] == 'blob') {
$this->$c = $this->blob($this->$c,TRUE); $this->$c = $this->blob($this->$c,TRUE);
// We need to reset our auto_convert flag
if (isset($this->_table_columns[$c]['auto_convert']))
$this->_table_columns[$c]['auto_convert'] = FALSE;
}
return parent::save($validation); return parent::save($validation);
} }
@ -135,5 +149,11 @@ abstract class ORMOSB extends ORM {
private function blob($data,$set=FALSE) { private function blob($data,$set=FALSE) {
return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data)); return $set ? gzcompress(serialize($data)) : unserialize(gzuncompress($data));
} }
public function config($key) {
$mc = Config::instance()->so->module_config($this->_object_name);
return empty($mc[$key]) ? '' : $mc[$key];
}
} }
?> ?>

View File

@ -0,0 +1,3 @@
<tr>
<td colspan="2"><div id="<?php echo $mo->name; ?>"></div></td>
</tr>

View File

@ -0,0 +1 @@
</table>

View File

@ -0,0 +1 @@
<table class="box-full">

View File

@ -0,0 +1,5 @@
<tr>
<td class="head" style="font-size: 75%;"><?php echo $key; ?></td>
<td><?php echo Form::input('module_config['.$module.']['.$key.']',$val); ?></td>
<td><?php echo $info; ?></td>
</tr>

View File

@ -0,0 +1 @@
</table>

View File

@ -0,0 +1 @@
<table class="box-full">

View File

@ -24,7 +24,7 @@ class Model_Host_Server extends ORMOSB {
return $po->manage_button($u,$p,$d); return $po->manage_button($u,$p,$d);
} }
public function config() { public function prov_plugin_data() {
if (! $this->provision_plugin_data) if (! $this->provision_plugin_data)
throw new Kohana_Exception('No plugin configuration data'); throw new Kohana_Exception('No plugin configuration data');

View File

@ -95,7 +95,7 @@ class Plesk {
} }
private function server_command(XML $xml) { private function server_command(XML $xml) {
$hs = $this->hso->config(); $hs = $this->hso->prov_plugin_data();
$request = Request::factory(sprintf('%s/%s',$this->hso->manage_url,$this->path)) $request = Request::factory(sprintf('%s/%s',$this->hso->manage_url,$this->path))
->method('POST'); ->method('POST');

View File

@ -17,8 +17,18 @@
class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin { class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin {
protected $secure_actions = array( protected $secure_actions = array(
'list'=>TRUE, 'list'=>TRUE,
'setup'=>TRUE,
); );
public function action_setup() {
$this->setup(array(
'GEN_DAYS'=>_('Generate Invoices this many days in advance of the due date'),
'GEN_SOON_DAYS'=>_('Days before GEN_DAYS to list invoices that will be generated'),
'TAX_ID'=>_('TAX ID shown on invoices'),
'TAX_ID_NAME'=>_('TAX ID name shown on invoices'),
));
}
/** /**
* Show a list of invoices * Show a list of invoices
*/ */

View File

@ -42,7 +42,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$this->SetFont('helvetica','',10); $this->SetFont('helvetica','',10);
$this->SetXY($x,$y); $this->Cell(0,0,Company::taxid()); $y += 6; $this->SetXY($x,$y); $this->Cell(0,0,Company::taxid()); $y += 6;
$this->SetXY($x,$y); $this->Cell(0,0,Company::street()); $y += 4; $this->SetXY($x,$y); $this->Cell(0,0,Company::street(', ')); $y += 4;
$this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4; $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4;
$y += 2; $y += 2;
@ -92,7 +92,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF {
$y = 216; $y = 216;
$this->SetFont('helvetica','',10); $this->SetFont('helvetica','',10);
$this->SetXY(18,$y); $this->Cell(0,0,Company::name()); $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,Company::street(', ')); $y += 4;
$this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4; $this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',Company::city(),Company::state(),Company::pcode())); $y += 4;
// Previous Due // Previous Due

View File

@ -525,7 +525,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
Block::add(array( Block::add(array(
'title'=>_('Services to Invoice'), 'title'=>_('Services to Invoice'),
'body'=>Table::display( 'body'=>Table::display(
ORM::factory('service')->list_invoicesoon(), ORM::factory('service')->list_invoicesoon(ORM::factory('invoice')->config('GEN_SOON_DAYS')),
25, 25,
array( array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'), 'id'=>array('label'=>'ID','url'=>'user/service/view/'),

View File

@ -147,14 +147,13 @@ class Model_Service extends ORMOSB {
/** /**
* List services that need to be billed. * List services that need to be billed.
*
* @param $days int Additional number of days to add to the query, above the module config.
*/ */
public function list_invoicesoon() { public function list_invoicesoon($days=0) {
// @todo This needs to be configurable
$days = 35;
return $this->_list_active() return $this->_list_active()
->where_open()->where('suspend_billing','IS',NULL)->or_where('suspend_billing','=','0')->where_close() ->where_open()->where('suspend_billing','IS',NULL)->or_where('suspend_billing','=','0')->where_close()
->where('date_next_invoice','<',time()+$days*86400) ->where('date_next_invoice','<',time()+(ORM::factory('invoice')->config('GEN_DAYS')+$days)*86400)
->find_all(); ->find_all();
} }

View File

@ -60,19 +60,19 @@ class Model_Task extends ORMOSB {
$this->date_run = time(); $this->date_run = time();
$this->running = 0; $this->running = 0;
$this->running_host = NULL; $this->running_host = NULL;
$this->save();
$tlo->result = 0; $tlo->result = 0;
$tlo->message = $r->body(); $tlo->message = $r->body();
} }
catch (Exception $e) { catch (Exception $e) {
$tlo->result = $e->getCode(); $tlo->result = $e->getCode();
$tlo->message = $e->getMessage(); $tlo->message = Kohana_Exception::text($e);
$this->running = 0; $this->running = 1;
$this->running_host = NULL; $this->running_host = 'ERROR';
$this->save();
} }
$this->save();
} }
if ($this->log) if ($this->log)