<?php
session_start();
	
include_once("../class/class.MySQL.php");
require '../class/resizeImage.php';
$db=new MySQL();

$action	= $_GET['action'];
if($action == "cand_short_list")
{
	$id		= explode(',',$_GET['id']); 
	$data   = array();
	for($i=0;$i<count($id);$i++)
	{
		$res    = $db->fetchQuery("SELECT count(*) as cnt FROM interview WHERE interv_id=".$id[$i]." AND interv_status='Shortlisted'");
		if($res[0]['cnt']==0){
			$result = $db->fetchQuery("SELECT * FROM interview WHERE interv_id=".$id[$i]);
			$data['sht_name_cand'] = $result[0]['name_cand'];
			$data['sht_pos'] = $result[0]['interv_pos'];
			$data['sht_loc'] = $result[0]['interv_loc'];
			$data['sht_qual'] = $result[0]['interv_qual'];
			$data['sht_exp'] = $result[0]['interv_exp'];
			$data['sht_contdt'] = $result[0]['interv_contdt'];
			$data['sht_status'] = 'Shortlisted';
			$data['sht_remarks'] = $result[0]['interv_remark'];
			$data['sht_email'] = $result[0]['intv_email'];
			$data['sht_phone'] = $result[0]['intv_phone'];
			$data['sht_intv_dt'] = $result[0]['interv_schd'];
			$data['sht_resume'] = $result[0]['intv_resume'];
			$data['sht_exp_month'] = $result[0]['interv_exp_month'];
			$data['sht_dept'] = $result[0]['interv_dept'];
			$data['sht_desg'] = $result[0]['interv_desg'];
			$data['sht_gender'] = $result[0]['interv_gender'];
			
			$db->Insert($data,'shortlisted');
			
			$db->Update('interview',array('interv_status'=>'Shortlisted'),array('interv_id'=>$id[$i]));
			
			# send shortlist mail
	
			$to      = $result[0]['intv_email'];
			$subject = 'Call letter';
			$message = 'Dear '.$result[0]['name_cand']. ",\r\n".'
			 We are very happy to inform you that we have shortlisted you.'. "\r\n".
			'Thanks,' . "\r\n".
			'HRM';
			$headers = 'From: info@addhrm.com' . "\r\n" ;
			mail($to, $subject, $message, $headers);
		}
	}
}

if($action == "cand_sel_list")
{
	$id		= explode(',',$_GET['id']);
	$data   = array();
	for($i=0;$i<count($id);$i++)
	{
		$res    = $db->fetchQuery("SELECT count(*) as cnt FROM shortlisted WHERE shtlist_id=".$id[$i]." AND sht_status='Selected'");
		if($res[0]['cnt']==0){
			$result = $db->fetchQuery("SELECT * FROM shortlisted WHERE shtlist_id=".$id[$i]);
			$data['sel_name_cand'] = $result[0]['sht_name_cand'];
			$data['sel_desg'] = $result[0]['sht_desg'];
			$data['sel_loc'] = $result[0]['sht_loc'];
			$data['sel_email'] = $result[0]['sht_email'];
			$data['sel_phone'] = $result[0]['sht_phone'];
			$data['sel_dept'] = $result[0]['sht_dept'];
			$data['sel_gender'] = $result[0]['sht_gender'];
			
			
			$db->Insert($data,'selected_list');
			
			$db->Update('shortlisted',array('sht_status'=>'Selected'),array('shtlist_id'=>$id[$i]));
			
			# send shortlist mail
	
			$to      = $result[0]['sht_email'];
			$subject = 'Call letter';
			$message = 'Dear '.$result[0]['sht_name_cand']. ",\r\n".'
			  It’s a pleasure to inform you that you have been selected for the postion of '.$result[0]['sht_pos'].  ".\r\n".
			'Thanks,' . "\r\n".
			'HRM';
			$headers = 'From: info@addhrm.com' . "\r\n" ;
			mail($to, $subject, $message, $headers);
		}
	}
}
if($action == "update_sel_list")
{
	$sel_id	 =$_GET['sel_id'];
	$db->Update('selected_list',array('sel_status'=>'Employee joined'),array('sel_id'=>$sel_id));
			
}
if($action == "get_detail")
{
	$sel_id = $_GET['sel_id'];
	$resut    = $db->fetchQuery("SELECT * FROM selected_list WHERE sel_id=".$sel_id);
	echo '{"sel_list":'.json_encode($resut).'}';		
}

?>