<?php

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



class SubAdmin extends CI_Controller {



	function __construct() 

	{

        parent::__construct();

        $met= $this->router->method;

    	if(check_login())

    	{

    		$data1=$this->session->userdata('secret_admin');

    		if($data1['role']!=2)

    		{

    			return redirect(base_url('admin'),'refresh');

    		}

    	}

    	else

    	{

    		return redirect(base_url('admin'),'refresh');

    	}

    }

	public function index()

	{

		if(check_login())

    	{

    			$data1=$this->session->userdata('secret_admin');

				if($data1['role']==1)

				{

					$this->load->view('admin/dashboard');

				}

				elseif($data1['role']==2)

				{

					$this->load->view('subadmin/dashboard');

				}

				elseif($data1['role']==3)

				{

					$this->load->view('consultant/dashboard');

				}

				elseif($data1['role']==4)

				{

					$this->load->view('company/dashboard');

				}

    	}

    	else

    	{

    		$this->load->view('admin/login');

    	}

	}



	public function profile()

	{

		if(!check_login())

    	{

    		return redirect(base_url(),'refresh');

    	}

		$data1=$this->session->userdata('secret_admin');

		$data['profile']=$this->db->where('id',$data1['id'])->get('user')->row_array();

		if($data1['role']==1)

		{

			$this->load->view('admin/profile',$data);

		}

		elseif($data1['role']==2)

		{

			$this->load->view('subadmin/profile',$data);

		}

		elseif($data1['role']==3)

		{

			$this->load->view('consultant/profile',$data);

		}

		elseif($data1['role']==4)

		{

			$this->load->view('company/profile',$data);

		}

	}

	public function update_profile()

	{

		$data['profile']=$this->db->where('id',$_POST['id'])->get('user')->row_array();

		$this->db->where('id',$_POST['id'])->update('user',$_POST);

		$this->session->set_flashdata('msg', 'Profile SUccessfully updated');

		if($data['profile']['role']==1)

		{	

			$this->load->view('admin/profile',$data);

		}

		elseif($data['profile']['role']==2)

		{

			$this->load->view('subadmin/profile',$data);

		}

		elseif($data['profile']['role']==3)

		{

			$this->load->view('consultant/profile',$data);

		}

		elseif($data['profile']['role']==4)

		{

			$this->load->view('company/profile',$data);

		}	

	}



	public function add_position()

	{

		if($this->input->server('REQUEST_METHOD') == 'POST')

		{

						$this->form_validation->set_rules('position', 'position', 'required');

			$this->form_validation->set_rules('position_no', 'Position No', 'required|numeric');

			$this->form_validation->set_rules('location', 'Location', 'required');

			$this->form_validation->set_rules('exp', 'Exp', 'required');

			$this->form_validation->set_rules('ctc', 'CTC', 'required');

			$this->form_validation->set_rules('tat', 'TAT', 'required');

			if ($this->form_validation->run() == FALSE)

			{

				$this->load->view('subadmin/add_position');

			}

			else

			{

				$journalName = str_replace(' ', '_', $_FILES['jd']['name']);

				$config['upload_path']   = './uploads/position/'; 

				 $config['allowed_types'] = '*'; 

				$config['file_name']  			= time().$journalName;

				 $this->load->library('upload', $config);

					

				 if ( ! $this->upload->do_upload('jd')) 

				 {

				    $error = array('error' => $this->upload->display_errors()); 



				    $this->load->view('subadmin/add_position', $error); 

				    exit;

				 }

					

				 else 

				 { 

				    $_POST['jd']=$config['file_name'];

				 }

				 $maxid=$this->db->select_max('id')->get('position')->row_array()['id']+1;

				 $max='JOB'.substr(time(),-4).$maxid;

				 $_POST['job_id']=$max;

				 $user=$this->session->userdata('secret_admin');

				 $_POST['added_by']=$user['id'];

				 $_POST['notification']='0,';

				 $_POST['status']='Open';

				 $_POST['admin_status']='Inactive';

				 if($this->db->insert('position',$_POST))

				 {

				 	$this->session->set_flashdata('msg', 'Position Successfully Added');

				 	return redirect(base_url('subAdmin/add_position'),'refresh');

				 }

				 else

				 {

				 	$this->session->set_flashdata('err', 'Please try Again After SomeTime');

				 	return redirect(base_url('subAdmin/add_position'),'refresh');

				 }

			}

		}

		else

		{

			$user=$this->session->userdata('secret_admin');

			$data['position']=$this->db->where('added_by',$user['id'])->order_by('id','desc')->limit(5)->get('position')->result_array();

			$this->load->view('subadmin/add_position',$data);

		}

	}

	function get_job()
	{
		$x=$this->db->where('job_id',$_POST['job_id'])->get('position')->row_array();
		echo json_encode($x);
	}


	public function position()

	{

		$where=[];

		$user=$this->session->userdata('secret_admin');

		$page =(isset($_GET['page'])) ? $_GET['page'] : 0;

		if(isset($_GET['search']))

		{

			 $query='select * from position where (job_id like "%'.$_GET['search'].'%" or position like "%'.$_GET['search'].'%" or position_no like "%'.$_GET['search'].'%" or location like "%'.$_GET['search'].'%" or exp like "%'.$_GET['search'].'%" or ctc like "%'.$_GET['search'].'%" or tat like "%'.$_GET['search'].'%") order by id DESC limit '.($page).' , 20';

			 $num_rows=count($this->db->query('select * from position where (job_id like "%'.$_GET['search'].'%" or position like "%'.$_GET['search'].'%" or position_no like "%'.$_GET['search'].'%" or location like "%'.$_GET['search'].'%" or exp like "%'.$_GET['search'].'%" or ctc like "%'.$_GET['search'].'%" or tat like "%'.$_GET['search'].'%")')->result_array());

			 $data['links']=$this->pagi->pagination1('subAdmin/position',$num_rows,20);

			 $data['position']=$this->db->query($query)->result_array();

			 $this->load->view('subadmin/position',$data);

		}

		else

		{
			 
			 $user=$this->session->userdata('secret_admin');
			 $data=$this->db->select('permission')->where('id',$user['id'])->from('user')->get()->row_array();
			 
			 $array=explode(',',$data['permission']);
			 
			  if(!(in_array($user['id'],$array)))
			 {
				 array_push($array,$user['id']);
			 }
			  
			  


		$query=$this->db->select('position.*')->from('position')->where_in('added_by',$array)->order_by('id','desc')->limit(20,($page))->get();

		$num_rows=$this->db->order_by('id', 'desc')->get('position')->num_rows();

		$data['position']=$query->result_array();

		$data['links']=$this->pagi->pagination1('subAdmin/position',$num_rows,20);

		$this->load->view('subadmin/position',$data);

		}

	}

	

	

	

		public function positions($id)

	{

		

		$user=$this->session->userdata('secret_admin');

		$active_id=$user['id'];

		/* print_r($data);

		die(); */

		if(isset($_GET['msg'])){

			    $user=$this->session->userdata('secret_admin');

				$data=$this->db->select('notification')->from('position')->where('id',$id)->get()->row_array();

				

				$this->db->like('notification',$active_id.',');

				$isid=$this->db->get_where('position',array('id'=>$id))->num_rows();

		

				if($isid<1)

				{

				$notification=$data['notification'].$active_id.',';

				

				$data1=array('notification'=>$notification);

				$this->db->where('id',$id)->update('position',$data1);

				}

				

			}

			$data['position']=$this->db->where('id',$id)->get('position')->row_array();

			$this->load->view('subadmin/positions',$data);

	}

	

	 public function candidates($id)

	 {

		$user=$this->session->userdata('secret_admin');

		$active_id=$user['id'];

		/* print_r($data);

		die(); */

		if(isset($_GET['msg'])){

			    $user=$this->session->userdata('secret_admin');

				$data=$this->db->select('notification')->from('candidate')->where('id',$id)->get()->row_array();

				

				$this->db->like('notification',$active_id.',');

				$isid=$this->db->get_where('candidate',array('id'=>$id))->num_rows();

		

				if($isid<1)

				{

				$notification=$data['notification'].$active_id.',';

				

				$data1=array('notification'=>$notification);

				$this->db->where('id',$id)->update('candidate',$data1);

				}

				

			}

			$data['candidate']=$this->db->where('id',$id)->get('candidate')->row_array();

			$this->load->view('subadmin/candidates',$data);

		 

	 }

	



	public function change_position_status()

	{

		$this->db->where('id',$_POST['id'])->update('position',$_POST);

		$this->session->set_flashdata('msg', 'Successfully Updated Status');

		return redirect(base_url('subAdmin/position'),'refresh');

	}
	
	public function admin_status_candidate()
	{
		$this->db->where('id',$_POST['id'])->update('candidate',$_POST);
		return redirect(base_url('subAdmin/candidate'),'refresh');
		
	}
	
	public function admin_status_position()
	{
		$this->db->where('id',$_POST['id'])->update('position',$_POST);
		return redirect(base_url('subAdmin/position'),'refresh');
	}



	public function add_candidate()

	{

		if($this->input->server('REQUEST_METHOD') == 'POST')

		{

			$this->form_validation->set_rules('position', 'position', 'required');

			$this->form_validation->set_rules('job_location', 'Job Location', 'required');

			$this->form_validation->set_rules('current_location', 'Location', 'required');

			$this->form_validation->set_rules('email', 'Email', 'required');

			$this->form_validation->set_rules('ctc', 'CTC', 'required');

			$this->form_validation->set_rules('expected_ctc', 'Expected CTC', 'required');

			$this->form_validation->set_rules('current_company', 'Current Company', 'required');

			$this->form_validation->set_rules('notice_period', 'Notice Period', 'required');

			

			if ($this->form_validation->run() == FALSE)

			{

			$user=$this->session->userdata('secret_admin');

			$data['candidate']=$this->db->where('added_by',$user['id'])->order_by('id','desc')->limit(5)->get('candidate')->result_array();



			$this->load->view('subadmin/add_candidate',$data);

			}

			else

			{

				

				$journalName = str_replace(' ', '_', $_FILES['cv']['name']);

				$config['upload_path']   = './uploads/position/'; 

				 $config['allowed_types'] = '*'; 

				$config['file_name']  			= time().$journalName;

				 $this->load->library('upload', $config);

					

				 if ( ! $this->upload->do_upload('cv')) 

				 {

				    $error = array('error' => $this->upload->display_errors()); 

				    $this->session->set_flashdata('err', $error);

				   $user=$this->session->userdata('secret_admin');

			$data['candidate']=$this->db->where('added_by',$user['id'])->order_by('id','desc')->limit(5)->get('candidate')->result_array();



			$this->load->view('subadmin/add_candidate',$data); 

				    exit;

				 }

					

				 else 

				 { 

				    $_POST['cv']=$config['file_name'];

				 }

				 $maxid=$this->db->select_max('id')->get('position')->row_array()['id']+1;

				 $max='CDT'.substr(time(),-4).$maxid;

				 $_POST['candidate_id']=$max;

				 $user=$this->session->userdata('secret_admin');

				 $_POST['added_by']=$user['id'];

				 $_POST['notification']='0,';

				 $_POST['status']='Profile feedback pending';

				 $_POST['admin_status']='Inactive';

				 if($this->db->insert('candidate',$_POST))

				 {

				 	$this->session->set_flashdata('msg', 'Candidate Successfully Added');

				 	return redirect(base_url('subAdmin/add_candidate'),'refresh');

				 }

				 else

				 {

				 	$this->session->set_flashdata('err', 'Please try Again After SomeTime');

				 	return redirect(base_url('subAdmin/add_candidate'),'refresh');

				 }

			}

		}

		else

		{

			$user=$this->session->userdata('secret_admin');

			$data['candidate']=$this->db->where('added_by',$user['id'])->order_by('id','desc')->limit(5)->get('candidate')->result_array();

			$this->load->view('subadmin/add_candidate',$data);

		}

	}



	public function candidate()

	{

		$where=[];

		$user=$this->session->userdata('secret_admin');

		$page =(isset($_GET['page'])) ? $_GET['page'] : 0;

		if(isset($_GET['search']))

		{

			

			 $query='select * from candidate where (candidate.job_id like "%'.$_GET['search'].'%" or candidate.candidate_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%") order by id DESC limit '.($page*20).' , 20';

			 $num_rows=count($this->db->query('select * from candidate where  (candidate.job_id like "%'.$_GET['search'].'%" or candidate.candidate_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%")')->result_array());

			 $data['links']=$this->pagi->pagination1('subAdmin/candidate',$num_rows,20);

			 $data['candidate']=$this->db->query($query)->result_array();

			 $this->load->view('subadmin/candidate',$data);

		}

		else

		{

		     $user=$this->session->userdata('secret_admin');
			 $data=$this->db->select('permission')->where('id',$user['id'])->from('user')->get()->row_array();
			 
			 $array=explode(',',$data['permission']);
			 
			 if(!(in_array($user['id'],$array)))
			 {
				 array_push($array,$user['id']);
			 }

		$query=$this->db->select('candidate.*')->from('candidate')->where_in('added_by',$array)->order_by('id','desc')->limit(20,($page))->get();

		$num_rows=$this->db->order_by('id', 'desc')->get('candidate')->num_rows();

		$data['candidate']=$query->result_array();

		$data['links']=$this->pagi->pagination1('subAdmin/candidate',$num_rows,20);

		$this->load->view('subadmin/candidate',$data);

		}

	}



	public function opening()

	{

		$where=[];

		$user=$this->session->userdata('secret_admin');

		$page =(isset($_GET['page'])) ? $_GET['page'] : 0;

		if(isset($_GET['search']))

		{

			 $query='select * from position where status="Open" and (job_id like "%'.$_GET['search'].'%" or position like "%'.$_GET['search'].'%" or position_no like "%'.$_GET['search'].'%" or location like "%'.$_GET['search'].'%" or exp like "%'.$_GET['search'].'%" or ctc like "%'.$_GET['search'].'%" or tat like "%'.$_GET['search'].'%") order by id DESC limit '.($page*20).' , 20';

			 $num_rows=count($this->db->query('select * from position where status="Open" and (job_id like "%'.$_GET['search'].'%" or position like "%'.$_GET['search'].'%" or position_no like "%'.$_GET['search'].'%" or location like "%'.$_GET['search'].'%" or exp like "%'.$_GET['search'].'%" or ctc like "%'.$_GET['search'].'%" or tat like "%'.$_GET['search'].'%")')->result_array());

			 $data['links']=$this->pagi->pagination1('subAdmin/opening',$num_rows,20);

			 $data['position']=$this->db->query($query)->result_array();

			 $this->load->view('subadmin/opening',$data);

		}

		else

		{
			 $user=$this->session->userdata('secret_admin');
			 $data=$this->db->select('permission')->where('id',$user['id'])->from('user')->get()->row_array();
			 
			 $array=explode(',',$data['permission']);
			 
			 if(!(in_array($user['id'],$array)))
			 {
				 array_push($array,$user['id']);
			 }

		$query=$this->db->select('position.*')->from('position')->where('status','Open')->where_in('added_by',$array)->order_by('id','desc')->limit(20,($page))->get();

		$num_rows=$this->db->where('status','Open')->where_in('added_by',$array)->order_by('id', 'desc')->get('position')->num_rows();

		$data['position']=$query->result_array();

		$data['links']=$this->pagi->pagination1('subAdmin/opening',$num_rows,20);

		$this->load->view('subadmin/opening',$data);

		}

	}





	public function cv_feedback_pending()

	{

		$page =(isset($_GET['page'])) ? $_GET['page'] : 0;

		$user=$this->session->userdata('secret_admin');

		if(isset($_GET['search']))

		{

			 $query='select candidate.* from candidate where candidate.status="Profile feedback pending" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%") order by id DESC limit '.($page*20).' , 20';

			 $num_rows=count($this->db->query('select candidate.* from candidate where candidate.status="Profile feedback pending" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%")')->result_array());

			 $data['links']=$this->pagi->pagination1('subAdmin/cv_feedback_pending',$num_rows,20);

			 $data['candidate']=$this->db->query($query)->result_array();

			 $this->load->view('subadmin/cv_feedback_pending',$data);

		}

		else

		{

			$user=$this->session->userdata('secret_admin');
			 $data=$this->db->select('permission')->where('id',$user['id'])->from('user')->get()->row_array();
			 
			 $array=explode(',',$data['permission']);
			 
			 if(!(in_array($user['id'],$array)))
			 {
				 array_push($array,$user['id']);
			 }

			$data['candidate']=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Profile feedback pending')->where_in('added_by',$array)->order_by('id','desc')->limit(20,($page))->get()->result_array();

			$num_rows=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Profile feedback pending')->where_in('added_by',$array)->order_by('id','desc')->get()->num_rows();

			$data['links']=$this->pagi->pagination1('subAdmin/cv_feedback_pending',$num_rows,20);

			$this->load->view('subadmin/cv_feedback_pending',$data);

		}		

	}



	public function shortlisted_for_interview()

	{

		$page =(isset($_GET['page'])) ? $_GET['page'] : 0;

		$user=$this->session->userdata('secret_admin');

		if(isset($_GET['search']))

		{

			 $query='select candidate.* from candidate where candidate.status="Profile Shortlist For Interview" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%") order by id DESC limit '.($page*20).' , 20';

			 $num_rows=count($this->db->query('select candidate.* from candidate where candidate.status="Profile Shortlist For Interview" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%")')->result_array());

			 $data['links']=$this->pagi->pagination1('subAdmin/shortlisted_for_interview',$num_rows,20);

			 $data['candidate']=$this->db->query($query)->result_array();

			 $this->load->view('subadmin/shortlisted_for_interview',$data);

		}

		else

		{
			$user=$this->session->userdata('secret_admin');
			 $data=$this->db->select('permission')->where('id',$user['id'])->from('user')->get()->row_array();
			 
			 $array=explode(',',$data['permission']);
			 
             if(!(in_array($user['id'],$array)))
			 {
				 array_push($array,$user['id']);
			 } 

			$data['candidate']=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Profile Shortlist For Interview')->where_in('added_by',$array)->order_by('id','desc')->limit(20,($page*20))->get()->result_array();

			$num_rows=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Profile Shortlist For Interview')->where_in('added_by',$array)->order_by('id','desc')->get()->num_rows();

			$data['links']=$this->pagi->pagination1('subAdmin/shortlisted_for_interview',$num_rows,20);

			$this->load->view('subadmin/shortlisted_for_interview',$data);

		}

	}



	public function schedule_interview()

	{

		$_POST['status']='Schedule Interview';

		$this->db->where(['candidate_id'=> $_POST['candidate_id'],'job_id'=> $_POST['job_id']])->update('candidate',$_POST);

		$this->session->set_flashdata('msg', 'Interview Scheduled Succeessfully');

		return redirect(base_url('subAdmin/shortlisted_for_interview'),'refresh');

	}



	public function interview_scheduled()

	{

		$page =(isset($_GET['page'])) ? $_GET['page'] : 0;

		$user=$this->session->userdata('secret_admin');

		if(isset($_GET['search']))

		{

			 $query='select candidate.* from candidate where candidate.status="Schedule Interview" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%") order by id DESC limit '.($page*20).' , 20';

			 $num_rows=count($this->db->query('select candidate.* from candidate where candidate.status="Schedule Interview" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%")')->result_array());

			 $data['links']=$this->pagi->pagination1('subAdmin/interview_scheduled',$num_rows,20);

			 $data['candidate']=$this->db->query($query)->result_array();

			 $this->load->view('subadmin/interview_scheduled',$data);

		}

		else

		{
			$user=$this->session->userdata('secret_admin');
			 $data=$this->db->select('permission')->where('id',$user['id'])->from('user')->get()->row_array();
			 
			 $array=explode(',',$data['permission']);
			 
			 if(!(in_array($user['id'],$array)))
			 {
				 array_push($array,$user['id']);
			 }

			$data['candidate']=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Schedule Interview')->where_in('added_by',$array)->order_by('id','desc')->limit(20,($page))->get()->result_array();

			$num_rows=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Schedule Interview')->where_in('added_by',$array)->order_by('id','desc')->get()->num_rows();

			$data['links']=$this->pagi->pagination1('subAdmin/interview_scheduled',$num_rows,20);

			$this->load->view('subadmin/interview_scheduled',$data);

		}

	

	}



	public function update_remark()

	{

		if($this->db->where(['job_id'=>$_POST['job_id'],'candidate_id'=>$_POST['candidate_id']])->update('candidate',$_POST))

		{

			echo json_encode("Updated SuccessFully");

		}

		else

		{

			echo json_encode("Try Again");

		}

	}



	public function final_selected()

	{

		$page =(isset($_GET['page'])) ? $_GET['page'] : 0;

		$user=$this->session->userdata('secret_admin');

		if(isset($_GET['search']))

		{

			 $query='select candidate.* from candidate where candidate.status="Final Select" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%") order by id DESC limit '.($page).' , 20';

			 $num_rows=count($this->db->query('select candidate.* from candidate where candidate.status="Final Select" and (candidate.job_id like "%'.$_GET['search'].'%" or candidate.position like "%'.$_GET['search'].'%" or candidate.job_location like "%'.$_GET['search'].'%" or candidate.email like "%'.$_GET['search'].'%" or candidate.name like "%'.$_GET['search'].'%" or candidate.phone like "%'.$_GET['search'].'%" or candidate.ctc like "%'.$_GET['search'].'%" or candidate.expected_ctc like "%'.$_GET['search'].'%")')->result_array());

			 $data['links']=$this->pagi->pagination1('subAdmin/final_selected',$num_rows,20);

			 $data['candidate']=$this->db->query($query)->result_array();

			 $this->load->view('subadmin/final_selected',$data);

		}

		else

		{
			$user=$this->session->userdata('secret_admin');
			 $data=$this->db->select('permission')->where('id',$user['id'])->from('user')->get()->row_array();
			 
			 $array=explode(',',$data['permission']);
			 
			 if(!(in_array($user['id'],$array)))
			 {
				 array_push($array,$user['id']);
			 }

			$data['candidate']=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Final Select')->where_in('added_by',$array)->order_by('id','desc')->limit(20,($page))->get()->result_array();

			$num_rows=$this->db->select('candidate.*')->from('candidate')->where('candidate.status','Final Select')->where_in('added_by',$array)->order_by('id','desc')->get()->num_rows();

			$data['links']=$this->pagi->pagination1('subAdmin/final_selected',$num_rows,20);

			$this->load->view('subadmin/final_selected',$data);

		}

	

	}



	public function joining_info()

	{

		$this->db->where(['candidate_id'=> $_POST['candidate_id'],'job_id'=> $_POST['job_id']])->update('candidate',$_POST);

		$this->session->set_flashdata('msg', 'Joining Info Succeessfully');

		return redirect(base_url('company/interview_scheduled'),'refresh');	

	}





	public function logout()

	{

		$this->session->sess_destroy();

		return redirect(base_url('subAdmin'),'refresh');

	}

}

