<?php
$table_name = $_SESSION['db_prefix']."_alerts";
$alert_query = "SELECT user_name, send_alert, send_email FROM $table_name WHERE alert_name = 'Min direct materials' ";
$alert_result = $con->query($alert_query);
$alert_num = mysqli_num_rows($alert_result);
	
			
$i=0;
$email_address = '';
while($row = $alert_result->fetch_assoc()) {
		$user_name = $row["user_name"];
		$send_alert = $row["send_alert"];
		$send_email = $row["send_email"];
		
		if ($send_alert=='yes') {
			$nn = count($alert_array);
			$n=0;
			while ($n<$nn) {
			$table_name = $_SESSION['db_prefix']."_alerts_store";
			$message_query = "INSERT INTO $table_name (user_name, department, recording_date, alert, detail_1, detail_2, detail_3 ) VALUES ('".$user_name."', 'store', '".$entry_date."', '31', '".$alert_array[$n]."', '', '".$alert2_array[$n]."' ) ";
			$message_result = $con->query($message_query);
			$n++;
			}
			
		}
		
		
		if ($send_email=='yes') {
			$table_name = $_SESSION['db_prefix']."_users";
			$address_query = "SELECT email FROM $table_name WHERE username = '".$user_name."' ";
			$address_result = $con->query($address_query);
			$row = mysqli_fetch_assoc($address_result);
			$email_address = $row["email"];			
		}
		else {
			$email_address = '';
		}

	 
	  if ($email_address!='') {			
			$subject = "Radstone stock below minimum";
			$message = "<body><font face=Calibri size=3><font color=#FF0000 size=+3><b>Stock alert</b></font><br><br>".$stock_alert_text."<br><br>For more info, login at <a href=costing.tocotex.com/bypass.php?c=pec&a=min_stock&r=&e=>Radstone 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');
		}
	  
$i++;		
}
	
?>

