<?php

$table_name = $_SESSION['db_prefix']."_alerts";
	$alert_query = "SELECT user_name, send_email FROM $table_name WHERE alert_name = 'absent' ";
	$alert_result = mySQL_query($alert_query);
	$alert_num = mysql_num_rows($alert_result);


	$email_address = '';
	$i=0;
	while ($i<$alert_num) {
		$user_name = mysql_result($alert_result, $i, "user_name");
			
			$table_name = $_SESSION['db_prefix']."_users";
			$address_query = "SELECT email FROM $table_name WHERE username = '".$user_name."' ";
			$address_result = mySQL_query($address_query);
			$email_address_one = mysql_result($address_result, 0, "email");
			if ($email_address_one != '' ) {
				   if ($email_address=='') {
					     $email_address=$email_address_one;
				   }
				   else {
					     $email_address = $email_address.', '.$email_address_one;
				   }
			}
		
	$i++;	
	}

if ($email_address!='') {	
			$subject = 'Alert from Manase Management Program';
			$message = '<body><font face=Calibri size=3>The following employees have been absent 3 or more time in the past days:<br><br><table border=1 style=border-collapse:collapse;><tr><td width="200">Employee</td><td width="100">No absents</td><td width="100">Since</td></tr>'.$absent_email_message.'</table><br>Date: '.date("d-m-Y", strtotime($entry_date)).'<br><br>For more info, login at <a href=crmcustomized.manase.co.bw/login.php?e=>Manase Management Program</a>.<br><br><font face=Calibri size=3 color=red><b>This message comes from a non-responsive address, please do not reply</b></font><body>';
			include ('alert_to_email.php');
		}


	

?>