diff --git a/application/classes/company.php b/application/classes/company.php index 69282d92..1188832a 100644 --- a/application/classes/company.php +++ b/application/classes/company.php @@ -65,8 +65,13 @@ class Company { } public static function taxid() { - // @todo Details should be obtained from DB - return Kohana::config('config.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() { diff --git a/application/classes/controller/admin/setup.php b/application/classes/controller/admin/setup.php index 7f10c6b4..1b2ed385 100644 --- a/application/classes/controller/admin/setup.php +++ b/application/classes/controller/admin/setup.php @@ -33,15 +33,42 @@ class Controller_Admin_Setup extends Controller_TemplateDefault_Admin { } $output .= Form::open(); + + // site_details $output .= View::factory($this->viewpath()) ->set('o',$o);; - $output .= Form::submit('submit','submit',array('class'=>'form_button')); + + $output .= '
'.Form::submit('submit','submit',array('class'=>'form_button')).'
'; $output .= Form::close(); Block::add(array( 'title'=>_('Update Site Configuration'), '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, + )); } } ?> diff --git a/application/classes/controller/templatedefault/admin.php b/application/classes/controller/templatedefault/admin.php index d74984e3..8480b03f 100644 --- a/application/classes/controller/templatedefault/admin.php +++ b/application/classes/controller/templatedefault/admin.php @@ -11,5 +11,37 @@ * @license http://dev.leenooks.net/license.html */ 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, + )); + } + } } ?> diff --git a/application/classes/controller/templatedefault/user.php b/application/classes/controller/templatedefault/user.php index 763fb514..bce5af1f 100644 --- a/application/classes/controller/templatedefault/user.php +++ b/application/classes/controller/templatedefault/user.php @@ -17,6 +17,10 @@ class Controller_TemplateDefault_User extends Controller_TemplateDefault { protected $ao; 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()]))) 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())); diff --git a/application/classes/model/setup.php b/application/classes/model/setup.php index e5ae8a7e..9f4830dd 100644 --- a/application/classes/model/setup.php +++ b/application/classes/model/setup.php @@ -46,14 +46,17 @@ class Model_Setup extends ORMOSB { if (! $mo->loaded()) 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 === 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 - $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 $sc[$key] = $value; - return $value; + return $this; } } ?> diff --git a/application/classes/ormosb.php b/application/classes/ormosb.php index a104be96..6c8149a2 100644 --- a/application/classes/ormosb.php +++ b/application/classes/ormosb.php @@ -106,9 +106,18 @@ abstract class ORMOSB extends ORM { public function __get($column) { // 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]); + } + catch(Exception $e) { + // @todo Log this exception + echo Kohana_Exception::text($e), "\n"; + echo debug_print_backtrace(); + } - $this->_object[$column] = $this->blob($this->_object[$column]); $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. if ($this->_changed) 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); + // 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); } @@ -135,5 +149,11 @@ abstract class ORMOSB extends ORM { private function blob($data,$set=FALSE) { 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]; + } } ?> diff --git a/application/views/setup/admin/edit/module/body.php b/application/views/setup/admin/edit/module/body.php new file mode 100644 index 00000000..aa69bb2d --- /dev/null +++ b/application/views/setup/admin/edit/module/body.php @@ -0,0 +1,3 @@ + +
+ diff --git a/application/views/setup/admin/edit/module/foot.php b/application/views/setup/admin/edit/module/foot.php new file mode 100644 index 00000000..000ca4b0 --- /dev/null +++ b/application/views/setup/admin/edit/module/foot.php @@ -0,0 +1 @@ + diff --git a/application/views/setup/admin/edit/module/head.php b/application/views/setup/admin/edit/module/head.php new file mode 100644 index 00000000..d74d8467 --- /dev/null +++ b/application/views/setup/admin/edit/module/head.php @@ -0,0 +1 @@ + diff --git a/application/views/setup/admin/module/body.php b/application/views/setup/admin/module/body.php new file mode 100644 index 00000000..ce19d2c5 --- /dev/null +++ b/application/views/setup/admin/module/body.php @@ -0,0 +1,5 @@ + + + + + diff --git a/application/views/setup/admin/module/foot.php b/application/views/setup/admin/module/foot.php new file mode 100644 index 00000000..000ca4b0 --- /dev/null +++ b/application/views/setup/admin/module/foot.php @@ -0,0 +1 @@ +
diff --git a/application/views/setup/admin/module/head.php b/application/views/setup/admin/module/head.php new file mode 100644 index 00000000..d74d8467 --- /dev/null +++ b/application/views/setup/admin/module/head.php @@ -0,0 +1 @@ + diff --git a/modules/host/classes/model/host/server.php b/modules/host/classes/model/host/server.php index 83dfd23f..146abe8c 100644 --- a/modules/host/classes/model/host/server.php +++ b/modules/host/classes/model/host/server.php @@ -24,7 +24,7 @@ class Model_Host_Server extends ORMOSB { return $po->manage_button($u,$p,$d); } - public function config() { + public function prov_plugin_data() { if (! $this->provision_plugin_data) throw new Kohana_Exception('No plugin configuration data'); diff --git a/modules/host/vendor/plesk.php b/modules/host/vendor/plesk.php index f6cc935d..982b494b 100644 --- a/modules/host/vendor/plesk.php +++ b/modules/host/vendor/plesk.php @@ -95,7 +95,7 @@ class Plesk { } 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)) ->method('POST'); diff --git a/modules/invoice/classes/controller/admin/invoice.php b/modules/invoice/classes/controller/admin/invoice.php index 2d94e4ca..62a12f77 100644 --- a/modules/invoice/classes/controller/admin/invoice.php +++ b/modules/invoice/classes/controller/admin/invoice.php @@ -17,8 +17,18 @@ class Controller_Admin_Invoice extends Controller_TemplateDefault_Admin { protected $secure_actions = array( '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 */ diff --git a/modules/invoice/classes/invoice/tcpdf/default.php b/modules/invoice/classes/invoice/tcpdf/default.php index 93890179..bcb95655 100644 --- a/modules/invoice/classes/invoice/tcpdf/default.php +++ b/modules/invoice/classes/invoice/tcpdf/default.php @@ -42,7 +42,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF { $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::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; $y += 2; @@ -92,7 +92,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF { $y = 216; $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::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; // Previous Due @@ -122,7 +122,7 @@ class Invoice_TCPDF_Default extends Invoice_TCPDF { else $name = $this->io->account->name(); - $this->SetXY($x,$y); $this->Cell(0,0,html_entity_decode($name,ENT_NOQUOTES)); $y += 5; + $this->SetXY($x,$y); $this->Cell(0,0,html_entity_decode($name,ENT_NOQUOTES)); $y += 5; $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s %s ',$this->io->account->address1,$this->io->account->address2)); $y += 5; $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$this->io->account->city,$this->io->account->state,$this->io->account->zip)); $y += 5; } diff --git a/modules/service/classes/controller/admin/service.php b/modules/service/classes/controller/admin/service.php index 038fef10..abe810d9 100644 --- a/modules/service/classes/controller/admin/service.php +++ b/modules/service/classes/controller/admin/service.php @@ -525,7 +525,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin { Block::add(array( 'title'=>_('Services to Invoice'), 'body'=>Table::display( - ORM::factory('service')->list_invoicesoon(), + ORM::factory('service')->list_invoicesoon(ORM::factory('invoice')->config('GEN_SOON_DAYS')), 25, array( 'id'=>array('label'=>'ID','url'=>'user/service/view/'), diff --git a/modules/service/classes/model/service.php b/modules/service/classes/model/service.php index f81a37de..c382eaef 100644 --- a/modules/service/classes/model/service.php +++ b/modules/service/classes/model/service.php @@ -147,14 +147,13 @@ class Model_Service extends ORMOSB { /** * 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() { - // @todo This needs to be configurable - $days = 35; - + public function list_invoicesoon($days=0) { return $this->_list_active() ->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(); } diff --git a/modules/task/classes/model/task.php b/modules/task/classes/model/task.php index cc384513..f542bbcd 100644 --- a/modules/task/classes/model/task.php +++ b/modules/task/classes/model/task.php @@ -60,19 +60,19 @@ class Model_Task extends ORMOSB { $this->date_run = time(); $this->running = 0; $this->running_host = NULL; - $this->save(); $tlo->result = 0; $tlo->message = $r->body(); } catch (Exception $e) { $tlo->result = $e->getCode(); - $tlo->message = $e->getMessage(); + $tlo->message = Kohana_Exception::text($e); - $this->running = 0; - $this->running_host = NULL; - $this->save(); + $this->running = 1; + $this->running_host = 'ERROR'; } + + $this->save(); } if ($this->log)