<?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_Admin {
	protected $control_title = 'Export';
	protected $secure_actions = array(
		'add'=>TRUE,
		'edit'=>TRUE,
	);

	/**
	 * Add Export Maping items
	 */
	public function action_add() {
		$eo = ORM::factory('export');
		$output = '';

		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)));

			SystemMessage::add(array(
				'title'=>_('Record add'),
				'type'=>'info',
				'body'=>_('Export Map entry 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,
		));
	}

	/**
	 * Edit Export Maping items
	 */
	public function action_edit() {
	}
}
?>