File: //home/cafsindia/allyindian_com/backend/application/controllers/Veh_type.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class Veh_type extends Secure_Controller
{
public function __construct()
{
parent::__construct('Veh_type');
$this->load->model('Veh_type_model');
}
public function index()
{
if(!$this->Appconfig->isAppvalid())
{
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_veh_type_headers());
$this->load->view('veh_type/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_type_model->search($search,$limit,$offset,$sort,$order);
$TotalRows=$this->Veh_type_model->get_found_rows($search);
$DataRows=array();
foreach ($cat->result() as $person)
{
$DataRows[]=get_veh_type_datarows($person,$this);
}
$DataRows=$this->xss_clean($DataRows);
echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
}
public function view($veh_type_id=-1)
{
$info=$this->Veh_type_model->get_info($veh_type_id);
foreach (get_object_vars($info) as $property => $value)
{
$info->$property = $this->xss_clean($value);
}
$data['type']=$info;
$cat_info[""] = "---- Select Category ----";
foreach($this->Veh_type_model->get_category()->result_array() as $row){
$cat_info[$this->xss_clean($row['veh_cat_id'])] = $this->xss_clean($row['veh_category']);
}
$data['cat_info'] = $cat_info;
$this->load->view("veh_type/form",$data);
}
/*
Inserts/updates a Vehicle type
*/
public function save($veh_type_id = -1)
{
$type_data = array(
'veh_type_id' => $this->input->post('veh_type_id'),
'veh_category' => $this->input->post('veh_category'),
'veh_type' => $this->input->post('veh_type'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d h:i:s"),
);
if($this->Veh_type_model->save_type($type_data, $veh_type_id)){
$type_data = $this->xss_clean($type_data);
//New customer
if($veh_type_id == -1)
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('type_successful_adding').' '.
$type_data['veh_type'], 'id' => $type_data['veh_type_id']));
}else {
//Existing customer
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('type_successful_updating').' '.
$type_data['veh_type'], 'id' => $veh_type_id));
}
}else{
//failure
$type_data = $this->xss_clean($type_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('type_error_adding_updating').' '.
$type_data['veh_type'], 'id' => -1));
}
}
public function get_row($type_ids)
{
$type_infos = $this->Veh_type_model->get_multiple_info($type_ids);
$result = array();
foreach($type_infos as $item_info)
{
$result[$item_info->veh_type_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(){
$type_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->Veh_type_model->delete_list($type_to_delete))
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('type_successful_deleted').' '.
count($type_to_delete).' '.$this->lang->line('type_one_or_multiple')));
}
else
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('type_cannot_be_deleted')));
}
}
}
?>