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/pmw24/pmw_live_testing/OLD_Root_BAK/application/controllers/admin/Client.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Client extends MY_Controller {
	public function __construct() {
		parent::__construct();
		$this->redirect_guest();
		$this->admin=$this->session->userdata('admin');
		$this->load->model('admin/mjob');
		$this->load->model('admin/mclient');
	}
		
	public function index() { 
		$this->_load_list_view();		
	}
	
	private function _load_list_view() {
		$data['content'] = 'admin/client/list';		
		$this->load->view('admin/layouts/index', $data);
	}
	
	public function all_content_list(){
		$list = $this->mclient->get_datatables();
        $data = array();
        $no = $_POST['start'];
		$i=1;
        foreach ($list as $person) {			
            $no++;
            $row = array();	
			$row[] = '<input type="checkbox" class="cstm_view" title="'.$person->client_id.'">';			
			//$row[]=$i;			
			$row[] = $person->client_name;
			$row[] = $person->name;
			$row[] = $person->client_address;
			$row[] = $person->client_phone_no;       
			//$row[] = '<a class="cstm_view" href="'.base_url('admin/client/details/'.$person->client_id).'" title="Edit">Edit</a>|<a class="cstm_view" id="delete" style="padding-left:5px" href="javascript:void(0)" title="'.$person->client_id.'">Delete</a>|<a class="cstm_view" id="view" style="padding-left:5px" href="javascript:void(0)" title="'.$person->client_id.'">View</a>';
            $data[] = $row;
			$i++;
        }
        $output = array(
                        "draw" => $_POST['draw'],
                        "recordsTotal" => $this->mclient->count_all(),
                        "recordsFiltered" => $this->mclient->count_filtered(),
                        "data" => $data,
                );
        echo json_encode($output);
	}
	
	public function add(){		
		$this->_load_add_view();
	}
	
	private function _load_add_view(){	
		$data['city_list'] = $this->mjob->get_city_list();
		$data['content']='admin/client/add';
		$this->load->view('admin/layouts/index',$data);
	}
	
	public function add_content(){	
		if($this->input->post()){			
			$this->form_validation->set_rules('client_name','Client Name','required');
			$this->form_validation->set_rules('city_id','City','required');
			if($this->form_validation->run()==FALSE){				
				$this->_load_add_view();
			}else{
				$client_addresss = $this->input->post('client_address');
				$building_number = $this->input->post('building_number');
				$street_name = $this->input->post('street_name');
				$suburb = $this->input->post('suburb');
				$post_code = $this->input->post('post_code');
				foreach($client_addresss as $key=>$client_address)
				{
					$udata['client_name'] = $this->input->post('client_name');
					$udata['city_id'] = $this->input->post('city_id');
					$udata['client_address'] = $client_address;					
					$udata['client_phone_no'] = $this->input->post('client_phone_no');
					$udata['land_line_no'] = $this->input->post('land_line_no');
					$udata['date_of_creation'] = date('Y-m-d');	
					$client_id=$this->mclient->add($udata);
				}		
				$this->session->set_flashdata('success_msg','Client added successfully');
				redirect('admin/client');			
			}
		}else{
			$this->_load_list_view();
		}
	}
	
	public function all_details(){
		$client_id = $this->input->post('client_id');		
		$result = $this->mclient->get_details($client_id);		
		echo json_encode($result);
	}
	
	public function edit($client_id){
		$data['cms']=$this->mclient->get_details($client_id);
		if(empty($data['cms'])){
			$this->_load_list_view();
		}else{			
			$this->_load_details_view($data);
		}
	}
	
	private function _load_details_view($parms){
		$data['city_list'] = $this->mjob->get_city_list();
		$data['cms']=$parms['cms'];	
		$data['content'] = 'admin/client/detail';
		$this->load->view('admin/layouts/index', $data);
	}
	
	public function update(){
		if($this->input->post()){			
			$this->form_validation->set_rules('client_name','client Name','required');
			$this->form_validation->set_rules('client_address','Client Address','required');
			if($this->form_validation->run()==FALSE){
				$city_id = $this->input->post('city_id');
				$data['cms']=$this->mcity->get_details($city_id);				
				$this->_load_details_view($data);
			}else{
				$client_id = $this->input->post('client_id');
				$udata['client_name'] = $this->input->post('client_name');
				$udata['client_address'] = $this->input->post('client_address');
				$udata['city_id'] = $this->input->post('city_id');
						
				$udata['client_phone_no'] = $this->input->post('client_phone_no');
				$udata['land_line_no'] = $this->input->post('land_line_no');
				$udata['date_of_update'] = date('Y-m-d');				
				$condition=array('client_id'=>$client_id);
				$this->mclient->update($condition,$udata);
				$this->session->set_flashdata('success_msg','Client updated successfully');
				redirect('admin/client');
			}
		}else{
				$this->_load_list_view();
		}
	}
	
	public function delete_content(){
		$condition['client_id']=$this->input->post('client_id');		
		$this->mclient->delete($condition);
		$response=array('status'=>1,'message'=>'Success');
		echo header('Content-Type: application/json');
		echo json_encode($response);
	}
	
	public function multiple_del()
	{
		$client_ids = explode(',',$this->input->post('client_id'));
		foreach($client_ids as $client_id)
		{
			$condition['client_id'] = $client_id;					
			$this->mclient->delete($condition);			
			$response=array('status'=>1,'message'=>'Success');
		}		
		echo header('Content-Type: application/json');
		echo json_encode($response);
	}
}