This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/export/classes/controller/affiliate/export.php
2012-01-12 19:53:54 +11:00

92 lines
2.4 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides OSB exporting capabilities.
*
* @package OSB
* @subpackage Export
* @category Controllers/Affiliate
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Affiliate_Export extends Controller_TemplateDefault_Affiliate {
protected $control_title = 'Export';
protected $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('affiliate/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;
// @todo: Need to limit this to affiliate acounts
$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;
// @todo: Need to limit this to affiliate acounts
$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',array('class'=>'form_button'));
$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())),
));
}
}
}
?>