File: /home/cafsindia/allyindian_com/backend/application/controllers/Veh_category.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Veh_category extends Secure_Controller
{
public function __construct()
{
parent::__construct('Veh_category');
$this->load->model('Veh_category_model');
}
public function index()
{
if(!$this->Appconfig->isAppvalid())
{
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_veh_category_headers());
$this->load->view('veh_category/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');
$cat=$this->Veh_category_model->search($search,$limit,$offset,$sort,$order);
$TotalRows=$this->Veh_category_model->get_found_rows($search);
$DataRows=array();
foreach ($cat->result() as $person)
{
$DataRows[]=get_veh_category_datarows($person,$this);
}
$DataRows=$this->xss_clean($DataRows);
echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
}
public function view($veh_cat_id=-1)
{
$info=$this->Veh_category_model->get_info($veh_cat_id);
foreach (get_object_vars($info) as $property => $value)
{
$info->$property = $this->xss_clean($value);
}
$data['category']=$info;
$this->load->view("veh_category/form",$data);
}
/*
Inserts/updates a Vehicle Category
*/
public function save($veh_cat_id = -1)
{
$category_data = array(
'veh_cat_id' => $this->input->post('veh_cat_id'),
'veh_category' => $this->input->post('veh_category'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d h:i:s"),
);
if($this->Veh_category_model->save_category($category_data, $veh_cat_id)){
$category_data = $this->xss_clean($category_data);
//New customer
if($veh_cat_id == -1)
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('category_successful_adding').' '.
$category_data['veh_category'], 'id' => $category_data['veh_cat_id']));
}else {
//Existing customer
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('category_successful_updating').' '.
$category_data['veh_category'], 'id' => $veh_cat_id));
}
}else{
//failure
$category_data = $this->xss_clean($category_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('category_error_adding_updating').' '.
$category_data['veh_category'], 'id' => -1));
}
}
public function get_row($cat_ids)
{
$category_infos = $this->Veh_category_model->get_multiple_info($cat_ids);
$result = array();
foreach($category_infos as $item_info)
{
$result[$item_info->veh_cat_id] = $this->xss_clean(get_item_data_row($item_info, $this));
}
echo json_encode($result);
}
/*
This deletes customers from the customers table
*/
public function delete(){
$category_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->Veh_category_model->delete_list($category_to_delete))
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('category_successful_deleted').' '.
count($category_to_delete).' '.$this->lang->line('category_one_or_multiple')));
}
else
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('category_cannot_be_deleted')));
}
}
}
?>