Site/Module setup work and auto_format fixes
This commit is contained in:
parent
407eed04c9
commit
a464d73f9a
@ -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() {
|
||||
|
@ -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 .= '<div>'.Form::submit('submit','submit',array('class'=>'form_button')).'</div>';
|
||||
$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,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -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,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -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()));
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -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->_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];
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
3
application/views/setup/admin/edit/module/body.php
Normal file
3
application/views/setup/admin/edit/module/body.php
Normal file
@ -0,0 +1,3 @@
|
||||
<tr>
|
||||
<td colspan="2"><div id="<?php echo $mo->name; ?>"></div></td>
|
||||
</tr>
|
1
application/views/setup/admin/edit/module/foot.php
Normal file
1
application/views/setup/admin/edit/module/foot.php
Normal file
@ -0,0 +1 @@
|
||||
</table>
|
1
application/views/setup/admin/edit/module/head.php
Normal file
1
application/views/setup/admin/edit/module/head.php
Normal file
@ -0,0 +1 @@
|
||||
<table class="box-full">
|
5
application/views/setup/admin/module/body.php
Normal file
5
application/views/setup/admin/module/body.php
Normal 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>
|
1
application/views/setup/admin/module/foot.php
Normal file
1
application/views/setup/admin/module/foot.php
Normal file
@ -0,0 +1 @@
|
||||
</table>
|
1
application/views/setup/admin/module/head.php
Normal file
1
application/views/setup/admin/module/head.php
Normal file
@ -0,0 +1 @@
|
||||
<table class="box-full">
|
@ -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');
|
||||
|
||||
|
2
modules/host/vendor/plesk.php
vendored
2
modules/host/vendor/plesk.php
vendored
@ -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');
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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/'),
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user