File: /home/cafsindia/allyindian_com/backend/application/controllers/Vehicle.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Secure_Controller.php");
class vehicle extends Secure_Controller
{
public function __construct()
{
parent::__construct('vehicle');
$this->load->model('Vehicle_model');
}
public function index(){
if(!$this->Appconfig->isAppvalid())
{
redirect('config');
}
$data['table_headers']=$this->xss_clean(get_vehicle_headers());
$this->load->view('vehicle/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');
$vehicle=$this->Vehicle_model->search($search,$limit,$offset,$sort,$order);
$TotalRows=$this->Vehicle_model->get_found_rows($search);
$DataRows=array();
foreach ($vehicle->result() as $person)
{
$DataRows[]=get_vehicle_datarows($person,$this);
}
//$DataRows=$this->xss_clean($DataRows);
echo json_encode(array('total'=>$TotalRows,'rows'=>$DataRows));
}
public function view($vehicle_id=-1){
$info=$this->Vehicle_model->get_info($vehicle_id);
foreach (get_object_vars($info) as $property => $value)
{
$info->$property = $this->xss_clean($value);
}
$data['vehicle']=$info;
$vehicle_type[""] = "--Select Vehicle Type--";
foreach($this->Vehicle_model->get_vehicle_type()->result_array() as $row){
$vehicle_type[$this->xss_clean($row['veh_type_id'])] = $this->xss_clean($row['veh_type']);
}
$data['vehicle_type'] = $vehicle_type;
$this->load->view("vehicle/form",$data);
}
public function view_seats($vehicle_id){
$data['vehicle_data'] = $this->Vehicle_model->get_vehicle_data($vehicle_id);
$this->load->view("vehicle/view_seats",$data);
}
/*
Inserts/updates a vehicle
*/
public function save($vehicle_id = -1){
$vehicle_data = array(
'vehicle_id' => $this->input->post('vehicle_id'),
'vehicle_no' => $this->input->post('vehicle_no'),
'model' => $this->input->post('model'),
'vehicle_type' => $this->input->post('vehicle_type'),
'fuel_type' => $this->input->post('fuel_type'),
'seat_capacity' => $this->input->post('seat_capacity'),
'seat_type' => $this->input->post('seat_type'),
'multi_type' => $this->input->post('multi_type'),
'no_of_seats_up' => $this->input->post('no_of_seats_up'),
'seats_per_row_up' => $this->input->post('seats_per_row_up'),
'seats_in_last_row_up' => $this->input->post('seats_in_last_row_up'),
'no_of_seats_low' => $this->input->post('no_of_seats_low'),
'seats_per_row_low' => $this->input->post('seats_per_row_low'),
'seats_in_last_row_low' => $this->input->post('seats_in_last_row_low'),
'created_by' => $this->session->userdata('emp_id'),
'created_date' => date("Y-m-d h:i:s"),
);
if($this->Vehicle_model->save_vehicle($vehicle_data, $vehicle_id)){
$vehicle_data = $this->xss_clean($vehicle_data);
//New vehicle
if($vehicle_id == -1)
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('vehicle_successful_adding').' '.
$vehicle_data['vehicle_name'], 'id' => $vehicle_data['vehicle_id']));
}else {
//Existing vehicles
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('vehicle_successful_updating').' '.
$vehicle_data['vehicle_name'], 'id' => $vehicle_id));
}
}else{
//failure
$vehicle_data = $this->xss_clean($vehicle_data);
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('vehicle_error_adding_updating').' '.
$vehicle_data['vehicle_name'], 'id' => -1));
}
}
public function add_seats(){
$vehicle_id = $this->input->post('vehicle_id');
$lower = implode(",",$this->input->post('lower'));
$upper = implode(",",$this->input->post('upper'));
$seat_data = $this->Vehicle_model->add_seats($vehicle_id,$lower,$upper);
echo json_encode(array('success' => true, 'message' => "Seat Added / Updated successfully",'seat_data'=>$seat_data));
}
public function get_seat_data(){
$vehicle_id = $this->input->post('vehicle_id');
$seat_data = $this->Vehicle_model->get_vehicle_data($vehicle_id);
echo json_encode(array('success' => true, 'seat_data'=>$seat_data));
}
public function get_row($vehicle_ids){
$vehicle_infos = $this->Vehicle_model->get_multiple_info($vehicle_ids);
$result = array();
foreach($vehicle_infos as $item_info)
{
$result[$item_info->vehicle_id] = $this->xss_clean(get_item_data_row($item_info, $this));
}
echo json_encode($result);
}
/*
This deletes vehicles from the vehicles table
*/
public function delete(){
$vehicle_to_delete = $this->xss_clean($this->input->post('ids'));
if($this->Vehicle_model->delete_list($vehicle_to_delete))
{
echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('vehicle_successful_deleted').' '.
count($vehicle_to_delete).' '.$this->lang->line('vehicle_one_or_multiple')));
}
else
{
echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('vehicle_cannot_be_deleted')));
}
}
}
?>