HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /var/www/html/nt/application/controllers/admin/Car.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Car extends MY_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->model(array('admin/mcar', 'mcommon'));
		$this->load->helper(array('sms', 'email'));
	}
	
	public function index() {
		$data['cars'] = $this->mcar->getCarData();
		$data['content'] = 'admin/car/list';
		$this->load->view('admin/layouts/index', $data);
	}
	
	public function add() {
 		$data['content'] = 'admin/car/add';
		$this->load->view('admin/layouts/index', $data);
    }

    public function saveCarData() {
        // Assuming you're using CodeIgniter's form validation library
        $this->load->library('form_validation');
        
        // Validation rules for plot header
        $this->form_validation->set_rules('taxi_number', 'Taxi Number', 'required');
        $this->form_validation->set_rules('terminal', 'Terminal', 'required');
        $this->form_validation->set_rules('owner_name', 'Owner Name', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('remarks', 'Remarks', 'required');
        // Validation rules for plot details
        // $this->form_validation->set_rules('area[]', 'Area (in acre)', 'numeric');
    
        if ($this->form_validation->run() == FALSE) {
            // Form validation failed, return validation errors or redirect to the form page with error messages
            $this->session->set_flashdata('error', 'There was an error in saving the car data. Please check your inputs.');
            redirect('addNewCar');
        } else {
            $carData = array(
                'taxi_number' => $this->input->post('taxi_number'),
                'terminal' => $this->input->post('terminal'),
                'owner_name' => $this->input->post('owner_name'),
                'password' => $this->input->post('password'),
                'remarks' => $this->input->post('remarks'),
                'status' => 1,
                // 'created_by' => $this->session->admin['user_id']
            );
            // echo "<pre>"; print_r($carData);
            $existingCar = $this->mcar->checkExistingCar($carData);
            if($existingCar){
                $this->session->set_flashdata('error', 'Car already exists!');
                redirect('addNewCar');
            }
            $car_id = $this->mcar->saveCarData($carData);
            if($car_id){
                $this->session->set_flashdata('success', 'Car data saved successfully!');
            } else {
                $this->session->set_flashdata('error', 'There was an error in saving the car data. Please try again.');
            }
            redirect('car');       
        }
    }
    
    public function edit($carID) {
        $carDetails = $this->mcar->getCardetailsByCarId($carID);
        if ($carDetails) {
            $data['carDetails'] = $carDetails;  
            $data['content'] = 'admin/car/edit'; // Adjust the view path as per your directory structure
            $this->load->view('admin/layouts/index', $data);
        } else {
            redirect('car');       
        }
    }

    public function updateCarData() {
        // echo "<pre>"; print_r($this->input->post()); die;
        // Assuming you're using CodeIgniter's form validation library
        $this->load->library('form_validation');
        
        // Validation rules for plot header
        $this->form_validation->set_rules('taxi_number', 'Taxi Number', 'required');
        $this->form_validation->set_rules('terminal', 'Terminal', 'required');
        $this->form_validation->set_rules('owner_name', 'Owner Name', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('remarks', 'Remarks', 'required');
        // Validation rules for plot details
        // $this->form_validation->set_rules('area[]', 'Area (in acre)', 'numeric');
    
        if ($this->form_validation->run() == FALSE) {
            // Form validation failed, return validation errors or redirect to the form page with error messages
            $this->session->set_flashdata('error', 'There was an error in saving the car data. Please check your inputs.');
            redirect('updateCarData');
        } else {
            $carData = array(
                'taxi_number' => $this->input->post('taxi_number'),
                'terminal' => $this->input->post('terminal'),
                'owner_name' => $this->input->post('owner_name'),
                'password' => $this->input->post('password'),
                'remarks' => $this->input->post('remarks'),
                'status' => 1,
                // 'created_by' => $this->session->admin['user_id']
            );
            // echo "<pre>"; print_r($carData); die;
            $car_id = $this->mcar->updateCarData($carData, $this->input->post('car_id'));
            if($car_id){
                $this->session->set_flashdata('success', 'Car data updated successfully!');
            } else {
                $this->session->set_flashdata('error', 'There was an error in updating the car data. Please try again.');
            }
            redirect('car');       
        }
    }
    
	public function updatePlotData() {
        // Assuming you're using CodeIgniter's form validation library
        $this->load->library('form_validation');
    
        // Validation rules for plot header
        $this->form_validation->set_rules('industrialPark', 'Industrial Park', 'required');
        $this->form_validation->set_rules('plotRefNo', 'Plot / Ref No.', 'required');
        $this->form_validation->set_rules('totalArea', 'Total Area', 'required|numeric');
    
        // Validation rules for plot details
        $this->form_validation->set_rules('area[]', 'Area (in acre)', 'numeric');
    
        if ($this->form_validation->run() == FALSE) {
            // Form validation failed, return validation errors or redirect to the form page with error messages
            $this->session->set_flashdata('error', 'There was an error in updating the plot data. Please check your inputs.');
            redirect('admin/plot/edit/' . $this->input->post('plot_header_id'));
        } else {
            // Form validation passed, proceed to update data in the database
    
            // Update plot header details
            $plotHeaderId = $this->input->post('plot_header_id');
            $plotHeaderData = array(
                'industrial_park_id' => $this->input->post('industrialPark'),
                'plot_ref_no' => $this->input->post('plotRefNo'),
                'total_area' => $this->input->post('totalArea'),
                'uom_id' => $this->input->post('uom'),
                'updated_by' => $this->session->userdata('user_id')

            );
            $this->mplot->updatePlotHeader($plotHeaderId, $plotHeaderData);
    
            // Delete existing plot details
            $this->mplot->deletePlotDetails($plotHeaderId);
    
            // Save updated plot details
            $mouzas = $this->input->post('mouza[]');
            $dagNos = $this->input->post('dag_no[]');
            $areas = $this->input->post('area[]');
            $partFulls = $this->input->post('type[]');
            foreach ($mouzas as $key => $mouza) {
                if ($mouza || $dagNos[$key] || $areas[$key]) {
                    $plotDetailData = array(
                        'plot_header_id' => $plotHeaderId,
                        'mouza_no' => $mouza,
                        'lr_dag_no' => $dagNos[$key],
                        'area_no' => $areas[$key],
                        'type_id' => $partFulls[$key],
                        'updated_by' => $this->session->userdata('user_id')
                    );
                    $this->mplot->savePlotDetail($plotDetailData);
                }
            }
    
            // Delete existing boundary details
            $this->mplot->deleteBoundaryDetails($plotHeaderId);
    
            // Save updated boundary details
            $sites = $this->input->post('site[]');
            $descriptions = $this->input->post('description[]');
            foreach ($sites as $key => $site) {
                if ($site || $descriptions[$key]) {
                    $boundaryDetailData = array(
                        'plot_header_id' => $plotHeaderId,
                        'site' => $site,
                        'description' => $descriptions[$key],
                        'updated_by' => $this->session->userdata('user_id')
                    );
                    $this->mplot->saveBoundaryDetail($boundaryDetailData);
                }
            }
    
            $this->session->set_flashdata('success', 'Plot data updated successfully!');
            redirect('admin/plot');
        }
    }
    

    public function getPlotDetails() {
          // Retrieve plot_header_id from the GET request
         $plotHeaderId = $this->input->get('plot_header_id');
        // Call the model method to fetch plot details
        $plotDetails = $this->mplot->getPlotDetails($plotHeaderId);

        // Send the plot details as JSON response
        $this->output->set_content_type('application/json')->set_output(json_encode($plotDetails));
    }
    

}