90 lines
2.2 KiB
PHP
90 lines
2.2 KiB
PHP
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
/**
|
|
* This class provides OSB exporting capabilities.
|
|
*
|
|
* @package OSB
|
|
* @subpackage Export
|
|
* @category Controllers/Admin
|
|
* @author Deon George
|
|
* @copyright (c) 2010 Open Source Billing
|
|
* @license http://dev.osbill.net/license.html
|
|
*/
|
|
class Controller_Admin_Export extends Controller_TemplateDefault {
|
|
protected $control_title = 'Export';
|
|
public $secure_actions = array(
|
|
'index'=>TRUE,
|
|
'export'=>TRUE,
|
|
);
|
|
|
|
/**
|
|
* Export plugins must define an export action.
|
|
*/
|
|
public function action_export() {
|
|
if (empty($_POST['plugin']))
|
|
$this->request->redirect('admin/export');
|
|
|
|
$sc = sprintf('Export_%s',$_POST['plugin']);
|
|
if (! class_exists($sc))
|
|
throw new Kohana_Exception('Export Class doesnt exist for :plugin',array(':plugin'=>$_POST['plugin']));
|
|
else
|
|
$export = new $sc;
|
|
|
|
$export->export();
|
|
}
|
|
|
|
/**
|
|
* This is the main call to export, providing a list of items to export and
|
|
* setting up the page to call the export plugin when submitted.
|
|
*/
|
|
public function action_index($daysago) {
|
|
// @todo this should come from a file list
|
|
$TBRexportplugins = array('quicken'=>'Export to Quicken');
|
|
|
|
if (! $daysago)
|
|
$daysago = 30;
|
|
|
|
$payments = ORM::factory('payment')
|
|
->export($daysago);
|
|
|
|
if (count($payments)) {
|
|
$output = Form::open(Request::current()->uri(array('action'=>'export')));
|
|
$output .= '<table class="box-left">';
|
|
|
|
$output .= View::factory('export/payment/header')
|
|
->set('plugins',$TBRexportplugins);
|
|
|
|
$i = 0;
|
|
foreach ($payments as $payment) {
|
|
$output .= View::factory('export/payment/body')
|
|
->set('payment',$payment)
|
|
->set('i',$i++%2);
|
|
}
|
|
|
|
$output .= '</table>';
|
|
$output .= Form::submit('submit','export');
|
|
$output .= Form::close();
|
|
|
|
Style::add(array(
|
|
'type'=>'file',
|
|
'data'=>'css/list.css',
|
|
));
|
|
|
|
Block::add(array(
|
|
'title'=>_('Payments to Export'),
|
|
'body'=>$output,
|
|
));
|
|
|
|
# Nothing to export
|
|
} else {
|
|
SystemMessage::add(array(
|
|
'title'=>_('No payments to export'),
|
|
'type'=>'info',
|
|
'body'=>sprintf(_('There are no payments within the last %s days (since %s) to show.'),
|
|
$daysago,date(Kohana::config('osb')->get('date_format'),$daysago*86400+time())),
|
|
));
|
|
}
|
|
}
|
|
}
|
|
?>
|