<?php

$table_name = $_SESSION['db_prefix']."_alerts";
	$alert_query = "SELECT user_name, send_alert, send_email FROM $table_name WHERE alert_name = 'Min stock' ";
	$alert_result = mySQL_query($alert_query);
	$alert_num = mysql_num_rows($alert_result);
	
				
	$i=0;
	$email_address = '';
	while ($i<$alert_num) {
		$user_name = mysql_result($alert_result, $i, "user_name");
		$send_alert = mysql_result($alert_result, $i, "send_alert");
		$send_email = mysql_result($alert_result, $i, "send_email");
		
		
		
		if ($send_email=='yes') {
			$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 = mysql_result($address_result, 0, "email").', '.$email_address;
		}
	$i++;	
	}

		
	
		
if ($email_address!='') {			
			$subject = "Stock below minimum Radstone Phakalane";
			$message = "<body><font face=Calibri size=3>The following items are below mininum stock:<br><table border=1 cellpadding=2 style='border-collapse:collapse'><tr><td>Item</td><td>Category</td><td>Actual</td><td>Min required</td></tr>".$message_text."</table><br><br>For more info, login at <a href=costing.tocotex.com/bypass.php?c=rad&a=min_stock&r=&e=>Radstone Phakalane 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');
		}
			

	
	
?>

