<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Career extends CI_Controller {
    
    public function index() {
        /************************************/
        // loading common model
        $this->load->model('Common_model');
        
        /************************************/
        /************************************/
       	    $column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
		$i = 1;
        $result23456789 = $this->Common_model->Results('tbl_language');
        foreach ($result23456789 as $row)
        {
            define('LANG_VALUE_' . $i, $row['lang_value']);
            $i++;
        }
        
	    $columntop_cities['status'] = '1';
		$tabletop_cities = 'tbl_top_cities';
        // we are getting results from common modal
		$resulttop_cities = $this->Common_model->ResultsWhere2($columntop_cities,$tabletop_cities);
		
		
	    $column3['status'] = '1';
	    $column3['status_home'] = '1';
		$table3 = 'tbl_top_category';
        // we are getting results from common modal
		$top_category = $this->Common_model->ResultsWhere2($column3,$table3);
		
	    $column3['status'] = '1';
	    $column3['status_home'] = '1';
		$table3 = 'tbl_mid_category';
        // we are getting results from common modal
		$mid_category = $this->Common_model->ResultsWhere2($column3,$table3);
		
	    $column3['status'] = '1';
	    $column3['status_home'] = '1';
		$table3 = 'tbl_end_category';
        // we are getting results from common modal
		$end_category = $this->Common_model->ResultsWhere2($column3,$table3);
		
		
	    $column3['status'] = '1';
	    $column3['status_home'] = '1';
		$table3 = 'tbl_top_category';
        // we are getting results from common modal
		$top_category = $this->Common_model->ResultsWhere2($column3,$table3);
		
	    $column32['status'] = '1';
		$table32 = 'tbl_mid_category';
        // we are getting results from common modal
		$data['mid_category2'] = $this->Common_model->ResultsWhere2($column32,$table32);
		
	    $column33['status'] = '1';
		$table33 = 'tbl_end_category';
        // we are getting results from common modal
		$data['end_category2'] = $this->Common_model->ResultsWhere2($column33,$table33);
		
	    $column31['status'] = 1;
		$table31 = 'tbl_top_cities';
        // we are getting results from common modal
		$top_cities = $this->Common_model->ResultsWhere2($column31,$table31);
		
		
	    $column31['status'] = 1;
		$table31 = 'tbl_social';
        // we are getting results from common modal
		$social = $this->Common_model->ResultsWhere2($column31,$table31);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['top_cities'] = $top_cities;
		$data['top_category'] = $top_category;
		$data['mid_category'] = $mid_category;
		$data['end_category'] = $end_category;
		$data['social'] = $social;
        
        /************************************/
        
        $table = 'tbl_state';
        /************************************/
        // we are getting results from common modal
        $data['state'] = $this->Common_model->Results($table);
        
        /************************************/
        $data['page'] = 'Career';
        
        /************************************/
        // we are loading admin dashboard
        $this->load->view('website/career',$data);	
    }
    
    public function enquiry(){
        /************************************/
        // loading common model
        $this->load->model('Common_model');
        
        /************************************/
        
        foreach ($_POST as $key => $value) {
            if (empty($value)) {
                $this->session->set_flashdata('error',''.strtoupper("$key").' Can not be Empty.');
			    redirect(base_url('career'));
			    exit();
            }
                $data[$key] = $value;
        }
        
            
        if (!empty($_FILES['cv']['name'])) {
            
            $path = $_FILES['cv']['name'];
            $ext = pathinfo( $path, PATHINFO_EXTENSION );
        
            $cv_name2 = 'CV-'.date('d M Y h:i:s A').'.'.$ext;
            
            $config['upload_path'] = 'uploads/website/cv/';
            $config['allowed_types'] = 'pdf|doc|docx';
            $config['file_name'] = $cv_name2;
            
            $this->load->library('upload',$config);
            
            if($this->upload->do_upload('cv')){
                $cv = $this->upload->data();
                $data['cv'] = $cv_name2;
    
            } else{
                $this->session->set_flashdata('error','Something went Wrong File is Not Uploaded.');
			    redirect(base_url('career'));
			    exit();
            }
           
        }
        
        $table = 'tbl_career';
        $data['addon'] = date('Y-m-d H:i:s');
        $data['status'] = 1;
        $data['ip_address'] = $_SERVER['REMOTE_ADDR'];
        $data['browser'] = $_SERVER['HTTP_USER_AGENT'];
        
        // we are updating data from tbl_settings
        $result  = $this->Common_model->Create($data,$table);
        if($result == true){
            $this->session->set_flashdata('success','SUCCESS!! CV is Submited Successfully.<br> We will contact you soon.');
		    redirect(base_url('career'));
		    exit();
        } else{
            $this->session->set_flashdata('error','Something went Wrong.');
		    redirect(base_url('career'));
		    exit();
        }
        
	}
	
	public function get_district(){
        /************************************/
        // loading common model
        $this->load->model('Common_model');
        
        /************************************/
        
	    if(!empty($_POST['state'])){
	        
            $state = $_POST['state'];
            $column['state'] = $state;
            $table = 'tbl_state';
            
            /************************************/
            // we are getting results from common modal
            $result = $this->Common_model->Result($column,$table);
            $state_id = $result['id'];
            
            /************************************/
            $column2['state'] = $state_id;
            $table2 = 'tbl_district';
            
            /************************************/
            // we are getting results from common modal
            $result4 = $this->Common_model->ResultsWhere2($column2, $table2);
            
            /************************************/
    		echo '<option value="" selected>Select District </option>';
    		for ($x = 0; $x < count($result4); $x++) {
    			echo '<option value="' . $result4[$x]['district'] . '">' . $result4[$x]['district'] . '</option>';
    		}
	    }
	}
}
