Overhauled export, and other minor updates

This commit is contained in:
Deon George
2013-05-14 23:53:04 +10:00
parent e81eb7a446
commit 684b46f585
33 changed files with 690 additions and 652 deletions

View File

@@ -9,51 +9,123 @@
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Export extends Controller_TemplateDefault_Admin {
protected $control_title = 'Export';
class Controller_Admin_Export extends Controller_Export {
protected $secure_actions = array(
'add'=>TRUE,
'edit'=>TRUE,
'index'=>TRUE,
'module'=>TRUE,
);
/**
* Add Export Maping items
*/
public function action_add() {
$eo = ORM::factory('Export');
$output = '';
if (empty($_POST['export_module_id']) OR empty($_POST['module_id']))
HTTP::redirect(URL::link('admin','export/index'));
if ($_POST AND $eo->values($_POST)->check()) {
$eo->module_id = ORM::factory('Module',array('name'=>'product'))->id; // @todo This probably should be in the form.
$eo->plugin_name = 'quicken'; // @todo This should be in the form.
// Entry updated
if (! $eo->save())
throw new Kohana_Exception('Unable to save data :post',array(':post'=>serialize($_POST)));
$edo = ORM::factory('Export_DataMap');
SystemMessage::add(array(
'title'=>_('Record add'),
'type'=>'info',
'body'=>_('Export Map entry added.')
));
if ($_POST AND isset($_POST['item_id']) AND $edo->values($_POST)->check()) {
$edo->status = 1;
if (! $edo->save())
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($_POST)));
SystemMessage::factory()
->title('Record added')
->type('success')
->body(_('Export DataMap record has been added.'));
}
$output .= Form::open();
$output .= View::factory($this->viewpath())
->set('eo',$eo);
$output .= '<div>'.Form::submit('submit',_('Add'),array('class'=>'form_button')).'</div>';
$output .= Form::close();
Block::add(array(
'title'=>_('Add Export Map'),
'body'=>$output,
));
Block::factory()
->title('Add Export Item Map')
->title_icon('icon-plus-sign')
->type('form-horizontal')
->body(View::factory('export/admin/add')
->set('o',$edo)
->set('emo',ORM::factory('Export_Module',$_POST['export_module_id']))
->set('module',ORM::factory('Module',$_POST['module_id'])->module()));
}
/**
* Edit Export Maping items
* Select our primary export target
*/
public function action_edit() {
public function action_index() {
$output = '';
if ($_POST and isset($_POST['eid'])) {
$select = array();
foreach (ORM::factory('Export_Module')->where('export_id','=',$_POST['eid'])->find_all() as $emo)
$select[$emo->id] = $emo->module->name;
$output .= Form::open(URL::link('admin','export/add'));
$output .= Form::select('export_module_id',$select);
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
// @todo This shouldnt be hard coded.
$output .= Form::hidden('module_id',ORM::factory('Product')->mid());
} else {
$output .= Form::open();
$output .= Form::select('eid',ORM::factory('Export')->list_select());
$output .= Form::button('submit','Submit',array('class'=>'btn btn-primary'));
}
$output .= Form::close();
Block::factory()
->title('Select Export Target')
->title_icon('icon-share')
->body($output);
}
/**
* Update the export module settings
*/
public function action_module() {
if ($_POST AND isset($_POST['export_module_id'])) {
$emo = ORM::factory('Export_Module',$_POST['export_module_id']);
if ($emo->loaded()) {
$emo->values($_POST);
$emo->save();
if ($emo->saved())
SystemMessage::factory()
->title('Record updated')
->type('success')
->body(_('Export Module record has been updated.'));
}
}
if ($x = $this->request->param('id')) {
$emo = ORM::factory('Export_Module',$x);
if ($emo->loaded())
Block::factory()
->title(sprintf('Export Module: %s for %s',$emo->module->display('name'),$emo->export->display('name')))
->title_icon('icon-wrench')
->type('form-horizontal')
->body(View::factory('export/module/admin/edit')->set('o',$emo));
} else {
Block::factory()
->title('Export Module Update')
->title_icon('icon-th-list')
->body(Table::factory()
->data(ORM::factory('Export_Module')->find_all())
->jssort(TRUE)
->columns(array(
'id'=>'ID',
'export->name'=>'Name',
'module->name'=>'Module'
))
->prepend(array(
'id'=>array('url'=>URL::link('admin','export/module/')),
))
);
}
}
}
?>