<?php require_once('../Connections/oprmConn.php');

mysql_select_db($database_oprmConn, $oprmConn);
$query_getPassEx = "SELECT DATEDIFF(weby_profiles.passport_edate,current_date) AS days_left, weby_profiles.full_name, weby_profiles.passport_edate, weby_profiles.passport_number, weby_users.email_address, weby_users.user_id FROM weby_profiles, weby_users where weby_profiles.user_id = weby_users.user_id and weby_users.status = 'A' and weby_users.user_role <> 1 and weby_profiles.status = 'A' AND weby_profiles.passport_edate NOT IN ('', '0') having days_left <= 180";
$getPassEx = mysql_query($query_getPassEx, $oprmConn) or die(mysql_error());
$row_getPassEx = mysql_fetch_assoc($getPassEx);
$totalRows_getPassEx = mysql_num_rows($getPassEx);

mysql_select_db($database_oprmConn, $oprmConn);
$query_getProj22 = "select email_address FROM weby_users where user_role = 1";
$getProj22 = mysql_query($query_getProj22, $oprmConn) or die(mysql_error());
$row_getProj22 = mysql_fetch_assoc($getProj22);
$totalRows_getProj22 = mysql_num_rows($getProj22);

if($totalRows_getPassEx>0)  do { 
$user_email = $row_getPassEx['email_address'];
//$user_email = "info@SS WEB TECHNOLOGIES";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $SERVER_EMAIL" . "\r\n" ;
$subject = "SS WEB TECHNOLOGIES. - $row_getPassEx[full_name]: Passport Expiry Alert";
$body = "Hi $row_getPassEx[full_name],<br>This is to inform you that your below Passport Expiry Date alert. <br><br>
<table width='100%' border='1' cellpadding='5' cellspacing='0'>
<th height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>User Id</strong>
<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Name</strong></td>
<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Passport No</strong></td>
<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Expiry Date</strong></td>
<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Days Left</strong></td></th>
<tr align='left' valign='top'>	
<td height='30'>$row_getPassEx[user_id]</td>
<td height='30'>$row_getPassEx[full_name]</td>
<td height='30'>$row_getPassEx[passport_number]</td>
<td height='30'>$row_getPassEx[passport_edate]</td>
<td height='30'>$row_getPassEx[days_left]</td></tr></table><br>Auto generated e-mail...";
//echo $body.'<br><br><br>';
if($totalRows_getPassEx>0){	
mail($user_email, $subject, $body, $headers);
}
} while ($row_getPassEx = mysql_fetch_assoc($getPassEx));

?>