2013-10-10 02:44:53 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides OSB exporting capabilities.
|
|
|
|
*
|
|
|
|
* @package Export
|
|
|
|
* @category Controllers/Admin
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-05-14 13:53:04 +00:00
|
|
|
class Controller_Admin_Export extends Controller_Export {
|
2013-10-10 02:44:53 +00:00
|
|
|
protected $secure_actions = array(
|
|
|
|
'add'=>TRUE,
|
2013-05-14 13:53:04 +00:00
|
|
|
'index'=>TRUE,
|
|
|
|
'module'=>TRUE,
|
2013-10-10 02:44:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add Export Maping items
|
|
|
|
*/
|
|
|
|
public function action_add() {
|
2013-05-14 13:53:04 +00:00
|
|
|
if (empty($_POST['export_module_id']) OR empty($_POST['module_id']))
|
|
|
|
HTTP::redirect(URL::link('admin','export/index'));
|
|
|
|
|
|
|
|
$edo = ORM::factory('Export_DataMap');
|
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
if ($_POST AND isset($_POST['item_id']) AND $edo->values($_POST)->changed()) {
|
2013-05-14 13:53:04 +00:00
|
|
|
$edo->status = 1;
|
2013-10-10 02:44:53 +00:00
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
$this->save($edo);
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 13:53:04 +00:00
|
|
|
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']))
|
2013-12-19 23:00:32 +00:00
|
|
|
->set('module',ORM::factory('Module',$_POST['module_id'])->instance()));
|
2013-05-14 13:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select our primary export target
|
|
|
|
*/
|
|
|
|
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'));
|
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
|
|
|
|
$output .= Form::close();
|
|
|
|
|
2013-05-14 13:53:04 +00:00
|
|
|
Block::factory()
|
|
|
|
->title('Select Export Target')
|
|
|
|
->title_icon('icon-share')
|
|
|
|
->body($output);
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-14 13:53:04 +00:00
|
|
|
* Update the export module settings
|
2013-10-10 02:44:53 +00:00
|
|
|
*/
|
2013-05-14 13:53:04 +00:00
|
|
|
public function action_module() {
|
|
|
|
if ($_POST AND isset($_POST['export_module_id'])) {
|
|
|
|
$emo = ORM::factory('Export_Module',$_POST['export_module_id']);
|
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
if ($emo->loaded() AND $emo->values($_POST)->changed() AND ! $this->save($emo))
|
|
|
|
$emo->reload();
|
2013-05-14 13:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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/')),
|
|
|
|
))
|
|
|
|
);
|
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|