<?php
include '../connect/cms-config.php' ;
include '../requires/function.php' ;
include '../extensions/mailer.php' ;

$mysqli_employment = $mysqli->query("SELECT employment_id, employment_branch, employment_position, employment_name, employment_email, employment_interview_date FROM staff_employment WHERE
							      	 employment_trash = '0' AND (
							      	 	( employment_status = 'Interview' AND employment_interview_date LIKE '%".TODAYDAY."%' ) OR
							      	 	( employment_status = 'Reschedule' AND employment_r_interview_date LIKE '%".TODAYDAY."%' )
							      	 )" ) ;
if ( $mysqli_employment->num_rows > 0 ){

	$mailer 		  		    = new Mailer() ;

	// get all branch
	$array_branch  		        = [] ;
	$mysqli_branch              = $mysqli->query( "SELECT branch_id, branch_name, branch_hr_email, branch_hr_cc, branch_hr_contact, branch_email_footer FROM branch 
				         	       			       WHERE deleted_at IS NULL" ) ;
	if ( $mysqli_branch->num_rows > 0 ){
		while ( $row_branch     = $mysqli_branch->fetch_assoc() ){
			$row_branch['branch_hr_cc']        = explodeToArray( $row_branch['branch_hr_cc'] ) ;
            $row_branch['branch_email_footer'] = entityDecode( dataFilter( $row_branch['branch_email_footer'] ) ) ;

			$array_branch[$row_branch['branch_id']] = $row_branch ;
		}
	}

	// get all position
	$array_position  		    = [] ;
	$mysqli_position            = $mysqli->query( "SELECT a.job_position_id, b.job_position_desc FROM setting_job_position a
				           	    				   LEFT JOIN setting_job_position_translation b ON ( a.job_position_id = b.job_position_id )
				           	    				   WHERE a.deleted_at IS NULL AND b.lang = 'en'" ) ;
	if ( $mysqli_position->num_rows > 0 ){
		while ( $row_position 	= $mysqli_position->fetch_assoc() ){
			$array_position[$row_position['job_position_id']] = $row_position['job_position_desc'] ;
		}
	}

	while ( $row_employment     = $mysqli_employment->fetch_assoc() ){

		$title 	                = "Friendly Reminder For Today Interview" ;
		$link 					= PATH.'hr-employment-schedule-interview-date.php?page='.$row_employment['employment_id'].'&branch='.$row_employment['employment_branch'].'&sign='.md5($row_employment['employment_id'].$row_employment['employment_branch'].APIKEY) ;
		$link_reschedule        = '<a href="'.$link.'">'.$link.'</a>' ;
		$link_attach_resume     = '<a href="'.PATH.'uploads/Employment_Resume/'.$attach.'">Candidate\'s Resume</a>' ;

		$get_branch 			= $array_branch[$row_employment['employment_branch']] ;
		
		$content 		        = "
		<table>
			<tr><td>Dear ".strtoupper($row_employment['employment_name']).",</td></tr>
			<tr><td style='height:20px;'> </td></tr>
			<tr><td>Thank you for your application regarding the position of <span style='border-bottom:1px solid black; font-weight:bold;'>".$array_position[$row_employment['No AAR for react-native-reanimated found. Attempting to build from source.']]."</span> at <span style='border-bottom:1px solid black; font-weight:bold;'>".$get_branch['branch_name']."</span>.</td></tr>
			<tr><td style='height:20px;'> </td></tr>
			<tr><td>We are impressed with your qualifications and would like to meet with you to have a round of discussion. You are advised to attend for the interview on <span style='border-bottom:1px solid black; font-weight:bold;'>".date('Y-m-d H:i', strtotime($row_employment['employment_interview_date']))."</span> at our office.</td></tr>
			<tr><td style='height:20px;'> </td></tr>
			<tr><td>If you have any queries, please feel free to contact the office. We look forward to meet you soon at our office.</td></tr>
			<tr><td style='height:20px;'> </td></tr>
			<tr><td>Please Note That:</td></tr>
			<tr><td style='height:20px;'>1) This is an interview call for the job applied and does not guarantee employment with us.</td></tr>
			<tr><td style='height:20px;'>2) No TA / DA will be provided to candidates appearing for the interview.</td></tr>
			<tr><td style='height:20px;'>3) Bring this letter with you on the above-mentioned date and time of the interview.</td></tr>
			<tr><td style='height:20px;'>4) Bring photocopies and originals of your academic & other credentials along with a recent snap.</td></tr>
			<tr><td style='height:20px;'> </td></tr>
			<tr><td>Reschedule Interview Date (If you are inconvenience with the date provided): </td></tr>
			<tr><td>".$link_reschedule."</td></tr>
			<tr><td style='height:20px;'> </td></tr>
			<tr><td>*Please revert back to this email to confirm for your interview attendance.</td></tr>
		</table>" . $get_branch['branch_email_footer'] ;

		$mailer->from     = $get_branch['branch_hr_email'] ;
		$mailer->fromname = COMPANY ;
		$mailer->to       = [ $row_employment['employment_email'] ] ;
        if ( count($get_branch['branch_hr_cc']) > 0 ){
            $mailer->cc   = $get_branch['branch_hr_cc'] ;
        }
		$mailer->subject  = $title ;
		$mailer->body     = $content ;
		$mailer->send() ;


	}
}

?>