File: /home/cafsindia/crm_cafsindia_com/application/controllers/Items.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once("Secure_Controller.php");
class Items extends Secure_Controller
{
public function __construct(){
parent::__construct('items');
}
public function index(){
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$data['table_headers'] = $this->xss_clean(get_items_manage_table_headers());
$this->load->view('items/manage', $data);
}
public function search() {
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$items = $this->Item->search($search, $filters, $limit, $offset, $sort, $order);
$total_rows = $this->Item->get_found_rows($search, $filters);
$data_rows = array();
foreach($items->result() as $item){
$data_rows[] = $this->xss_clean(get_item_data_row($item, $this));
}
echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
}
public function get_row($item_ids){
$item_infos = $this->Item->get_multiple_info(explode(":", $item_ids));
$result = array();
foreach($item_infos->result() as $item_info){
$result[$item_info->item_id] = $this->xss_clean(get_item_data_row($item_info, $this));
}
echo json_encode($result);
}
public function view($item_id = -1){
$info = $this->Item->get_info($item_id);
foreach(get_object_vars($info) as $property => $value){
$info->$property = $this->xss_clean($value);
}
$data['item_info'] = $info;
$category_info[""] = "---- Select Category ----";
foreach($this->Employee->get_category()->result_array() as $row){
$category_info[$this->xss_clean($row['cat_id'])] = $this->xss_clean($row['cat_name']);
}
$data['category_info'] = $category_info;
if($item_id != -1){
$company_info[""] = "---- Select Category ----";
foreach($this->Item->get_company($info->category_id) as $row){
$company_info[$this->xss_clean($row['vendor_id'])] = $this->xss_clean($row['vendorcompanyname']);
}
$data['company_info'] = $company_info;
}
$this->load->view('items/form', $data);
}
public function get_company($id){
$data['company_info'] = $this->Item->get_company($id);
$this->load->view('team/ajax_get_company', $data);
}
public function save($item_id = -1){
$item_data = array(
'category_id' => $this->input->post('category'),
'vendorcompanyname' => $this->input->post('vendorcompanyname'),
'gst' => $this->input->post('gst'),
'product_name' => $this->input->post('product_name'),
'start_date' => date('Y-m-d',strtotime($this->input->post('start_date'))),
'end_date' => date('Y-m-d',strtotime($this->input->post('end_date'))),
'terms' => $this->input->post('terms'),
'ppt' => $this->input->post('ppt'),
'weight_credit' => $this->input->post('weight_credit'),
);
if($this->Item->save($item_data, $item_id)){
$item_data = $this->xss_clean($item_data,$item_id);
if($item_id == -1){
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('items_successful_adding').' '.
$item_data['product_name'], 'id' => $item_data['product_id']));
}else {
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('items_successful_updating').' '.
$item_data['product_name'], 'id' => $item_id));
}
}else{
$item_data = $this->xss_clean($item_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_error_adding_updating').' '.
$item_data['product_name'], 'id' => -1));
}
}
public function delete(){
$items_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->Item->delete_list($items_to_delete)){
$message = $this->lang->line('items_successful_deleted') . ' ' . count($items_to_delete) . ' ' . $this->lang->line('items_one_or_multiple');
echo json_encode(array('success' => TRUE, 'message' => $message));
}else{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_cannot_be_deleted')));
}
}
}
?>