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/product/classes/Controller/Admin/Product.php

209 lines
5.3 KiB
PHP
Raw Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Admin Product management
*
* @package Product
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_Product extends Controller_Product {
protected $auth_required = TRUE;
2013-10-10 02:44:53 +00:00
protected $secure_actions = array(
'ajaxtranslatecategory'=>TRUE,
'ajaxtranslate'=>TRUE,
'category'=>TRUE,
'edit'=>TRUE,
2013-10-10 02:44:53 +00:00
'list'=>TRUE,
'view'=>TRUE,
);
public function action_ajaxtranslate() {
2013-10-10 02:44:53 +00:00
$po = ORM::factory('Product',$this->request->param('id'));
if (! $po->loaded() OR ! isset($_REQUEST['key'])) {
$output = _('Unable to find translate data');
2013-10-10 02:44:53 +00:00
} else {
$pto = $po->translate->where('language_id','=',$_REQUEST['key'])->find();
2013-10-10 02:44:53 +00:00
$output = View::factory('product/admin/ajaxtranslate')
->set('o',$pto);
2013-10-10 02:44:53 +00:00
}
$this->template->content = $output;
}
/**
* Retrieve the product category translate record
*/
public function action_ajaxtranslatecategory() {
$pco = ORM::factory('Product_Category',$this->request->param('id'));
if (! $pco->loaded() OR ! isset($_REQUEST['key'])) {
$output = _('Unable to find translate data');
} else {
2013-11-28 06:41:34 +00:00
$pcto = $pco->translate->where('language_id','=',$_REQUEST['key'])->find();
$output = View::factory('product/category/admin/ajaxtranslate')
->set('o',$pcto);
}
$this->template->content = $output;
}
/**
* Update the product category
*/
public function action_category() {
$pco = ORM::factory('Product_Category',$this->request->param('id'));
if (! $pco->loaded())
HTTP::redirect(URL::link('admin','product/list'));
if ($_POST AND $pco->values($_POST)->changed() AND (! $this->save($pco)))
$pco->reload();
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
$("select[name=language_id]").change(function() {
// If we select a blank, then dont continue
if (this.value == 0)
return false;
// Send the request and update sub category dropdown
$.ajax({
type: "GET",
data: "key="+$(this).val(),
dataType: "html",
cache: false,
url: "'.URL::link('admin','product/ajaxtranslatecategory/'.$pco->id,TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=translate]").empty().append(data);
}
});
});
});
');
Block::factory()
->type('form-horizontal')
->title('Update Category')
->title_icon('icon-wrench')
->body(View::factory('product/category/admin/edit')
->set('o',$pco));
}
/**
* Edit a product configuration
*/
public function action_edit() {
$po = ORM::factory('Product',$this->request->param('id'));
if (! $po->loaded())
HTTP::redirect('welcome/index');
if ($_POST AND $po->values($_POST)->changed() AND (! $this->save($po)))
$po->reload();
Script::factory()
->type('stdin')
->data('
$(document).ready(function() {
$("select[name=language_id]").change(function() {
// If we select a blank, then dont continue
if (this.value == 0)
return false;
// Send the request and update sub category dropdown
$.ajax({
type: "GET",
data: "key="+$(this).val(),
dataType: "html",
cache: false,
url: "'.URL::link('admin','product/ajaxtranslate/'.$po->id,TRUE).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=translate]").empty().append(data);
}
});
});
});
');
Block::factory()
->type('form-horizontal')
->title('Update Product')
->title_icon('icon-wrench')
->body(View::factory('product/admin/edit')
->set('plugin_form',$po->plugin_edit())
->set('o',$po));
2013-10-10 02:44:53 +00:00
}
/**
* Show a list of products
*/
public function action_list() {
$products = ($x=$this->request->param('id')) ? ORM::factory('Product_Category',$x)->products() : ORM::factory('Product')->order_by('status','DESC')->order_by('prod_plugin_file')->find_all();
Block::factory()
->title(_('Products'))
->title_icon('icon-th')
2013-11-28 06:41:34 +00:00
->body(Table::factory()
->data($products)
->page_items(25)
->columns(array(
'id'=>'ID',
'title()'=>'Details',
'status'=>'Active',
'prod_plugin_file'=>'Plugin Name',
'prod_plugin_data'=>'Plugin Data',
'price_type'=>'Price Type',
'taxable'=>'Taxable',
'service->list_count()'=>'Services',
'invoice->list_count()'=>'Invoices',
))
->prepend(array(
'id'=>array('url'=>URL::link('admin','product/edit/')),
)));
2013-10-10 02:44:53 +00:00
}
public function action_view() {
$po = ORM::factory('Product',$this->request->param('id'));
2013-06-13 13:35:19 +00:00
if (! $po->loaded())
throw HTTP_Exception::factory(403,'Product either doesnt exist, or you are not authorised to see it');
Block::factory()
->title(sprintf('%s: %s',_('Current Services Using this Product'),$po->title()))
->title_icon('icon-th-list')
2013-11-28 06:41:34 +00:00
->body(Table::factory()
->data($po->service->where_active()->find_all())
->page_items(25)
->columns(array(
'id'=>'ID',
'account->accnum()'=>'Acc Num',
'account->name()'=>'Account',
'name()'=>'Details',
'status'=>'Active',
'price(TRUE,TRUE)'=>'Price',
))
->prepend(array(
'id'=>array('url'=>URL::link('user','service/view/')),
)));
2013-10-10 02:44:53 +00:00
}
}
?>