2011-10-11 08:52:31 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
2011-10-14 05:44:12 +00:00
|
|
|
* This class provides Admin Product management
|
2011-10-11 08:52:31 +00:00
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage Product
|
|
|
|
* @category Controllers/Admin
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
|
|
|
|
protected $secure_actions = array(
|
2012-03-30 04:13:01 +00:00
|
|
|
'ajaxtranslateform'=>TRUE,
|
2011-10-11 08:52:31 +00:00
|
|
|
'list'=>TRUE,
|
2012-03-30 04:13:01 +00:00
|
|
|
'update'=>TRUE,
|
|
|
|
'view'=>TRUE,
|
2011-10-11 08:52:31 +00:00
|
|
|
);
|
|
|
|
|
2012-03-30 04:13:01 +00:00
|
|
|
public function action_ajaxtranslateform() {
|
|
|
|
$this->auto_render = FALSE;
|
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$po = ORM::factory('Product',$this->request->param('id'));
|
2012-03-30 04:13:01 +00:00
|
|
|
|
|
|
|
if (! $this->request->is_ajax() OR ! $po->loaded() OR ! isset($_REQUEST['key']))
|
|
|
|
$this->response->body(_('Unable to find translate data'));
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
$pto = $po->product_translate->where('language_id','=',$_REQUEST['key'])->find();
|
|
|
|
|
|
|
|
$this->response->body(View::factory($this->viewpath())->set('pto',$pto));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-11 08:52:31 +00:00
|
|
|
/**
|
2011-10-14 05:44:12 +00:00
|
|
|
* Show a list of products
|
2011-10-11 08:52:31 +00:00
|
|
|
*/
|
|
|
|
public function action_list() {
|
2012-03-30 04:13:01 +00:00
|
|
|
if ($this->request->param('id'))
|
2012-11-09 23:13:57 +00:00
|
|
|
$prods = ORM::factory('Product')->list_category($this->request->param('id'),FALSE);
|
2012-03-30 04:13:01 +00:00
|
|
|
else
|
2012-11-09 23:13:57 +00:00
|
|
|
$prods = ORM::factory('Product')->order_by('status DESC,prod_plugin_file')->find_all();
|
2012-03-30 04:13:01 +00:00
|
|
|
|
2011-10-11 08:52:31 +00:00
|
|
|
Block::add(array(
|
|
|
|
'title'=>_('Customer Products'),
|
|
|
|
'body'=>Table::display(
|
2012-03-30 04:13:01 +00:00
|
|
|
$prods,
|
2011-10-11 08:52:31 +00:00
|
|
|
25,
|
|
|
|
array(
|
2011-10-14 05:44:12 +00:00
|
|
|
'id'=>array('label'=>'ID','url'=>'product/view/'),
|
2011-10-11 08:52:31 +00:00
|
|
|
'name()'=>array('label'=>'Details'),
|
2012-08-01 12:43:33 +00:00
|
|
|
'status'=>array('label'=>'Active'),
|
2011-10-11 08:52:31 +00:00
|
|
|
'prod_plugin_file'=>array('label'=>'Plugin Name'),
|
|
|
|
'prod_plugin_data'=>array('label'=>'Plugin Data'),
|
|
|
|
'price_type'=>array('label'=>'Price Type'),
|
|
|
|
'price_base'=>array('label'=>'Price Base'),
|
|
|
|
'taxable'=>array('label'=>'Taxable'),
|
2012-08-01 12:43:33 +00:00
|
|
|
'count_services()'=>array('label'=>'Services'),
|
|
|
|
'count_invoices()'=>array('label'=>'Invoices'),
|
2011-10-11 08:52:31 +00:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
2011-10-14 05:44:12 +00:00
|
|
|
'form'=>'product/view',
|
2011-10-11 08:52:31 +00:00
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
2012-03-30 04:13:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Edit a product configuration
|
|
|
|
*/
|
|
|
|
public function action_update() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$po = ORM::factory('Product',$this->request->param('id'));
|
2012-03-30 04:13:01 +00:00
|
|
|
|
|
|
|
if (! $po->loaded())
|
2012-11-09 23:13:57 +00:00
|
|
|
HTTP::redirect('welcome/index');
|
2012-03-30 04:13:01 +00:00
|
|
|
|
|
|
|
if ($_POST) {
|
2012-11-09 23:13:57 +00:00
|
|
|
if (isset($_POST['product_translate']['id']) AND ($pto=ORM::factory('Product_Translate',$_POST['product_translate']['id'])) AND $pto->loaded())
|
2012-07-01 00:18:21 +00:00
|
|
|
if (! $pto->values($_POST['product_translate'])->save())
|
2012-03-30 04:13:01 +00:00
|
|
|
throw new Kohana_Exception('Failed to save updates to product_translate data for record :record',array(':record'=>$po->id()));
|
|
|
|
|
2012-07-01 00:18:21 +00:00
|
|
|
if (! $po->values($_POST)->save())
|
2012-03-30 04:13:01 +00:00
|
|
|
throw new Kohana_Exception('Failed to save updates to product data for record :record',array(':record'=>$so->id()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s %s:%s',_('Update Product'),$po->id,$po->name()),
|
|
|
|
'body'=>View::factory($this->viewpath())
|
|
|
|
->set('po',$po)
|
|
|
|
->set('mediapath',Route::get('default/media'))
|
|
|
|
->set('plugin_form',$po->admin_update()),
|
|
|
|
));
|
|
|
|
|
|
|
|
Script::add(array('type'=>'stdin','data'=>'
|
|
|
|
$(document).ready(function() {
|
|
|
|
$("select[name=language_id]").change(function() {
|
|
|
|
// Send the request and update sub category dropdown
|
|
|
|
$.ajax({
|
|
|
|
type: "GET",
|
|
|
|
data: "key="+$(this).val(),
|
|
|
|
dataType: "html",
|
|
|
|
cache: false,
|
|
|
|
url: "'.URL::site('admin/product/ajaxtranslateform/'.$po->id).'",
|
|
|
|
timeout: 2000,
|
|
|
|
error: function(x) {
|
|
|
|
alert("Failed to submit");
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$("div[id=translate]").replaceWith(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_view() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$po = ORM::factory('Product',$this->request->param('id'));
|
2012-03-30 04:13:01 +00:00
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s: %s',_('Current Services Using this Product'),$po->name()),
|
|
|
|
'body'=>Table::display(
|
2012-11-09 23:13:57 +00:00
|
|
|
ORM::factory('Service')->where('product_id','=',$po->id)->find_all(),
|
2012-03-30 04:13:01 +00:00
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
|
|
|
'account->accnum()'=>array(),
|
|
|
|
'account->name()'=>array('label'=>'Account'),
|
|
|
|
'name()'=>array('label'=>'Details'),
|
2012-08-01 12:43:33 +00:00
|
|
|
'status'=>array('label'=>'Active'),
|
2012-03-30 04:13:01 +00:00
|
|
|
'price(TRUE,TRUE)'=>array('label'=>'Price','align'=>'right'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>'user/service/view',
|
|
|
|
)),
|
|
|
|
));
|
|
|
|
}
|
2011-10-11 08:52:31 +00:00
|
|
|
}
|
|
|
|
?>
|