<?php
if (($sub_category!='Timber') AND ($sub_category!='Mitek') AND ($sub_category!='Sundries') ) { $sub_category = 'Other'; }
$email_address='';

$table_name = $_SESSION['db_prefix']."_alerts";
	$alert_query = "SELECT user_name, send_email FROM $table_name WHERE alert_name = 'min stock' AND condition_1='Timber' ";
	$alert_result = mySQL_query($alert_query);
	$alert_num = mysql_num_rows($alert_result);
	$k=0;
	while ($k<$alert_num) {
		$send_email = mysql_result($alert_result, $k, "send_email");
		$user_name = mysql_result($alert_result, $k, "user_name");
		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=$email_address.mysql_result($address_result, 0, "email").', ';
		}
		$k++;
		}
$message = '<body><font face=Calibri size=3><b>Timber stock level report:</b></font><br>'.$_SESSION['message_timber'].'<br><font face=Calibri size=3><br>This message was generated on '.date("d-m-Y, H:m", strtotime($entry_date )).'.<br>For more info, login at <a href=costing.tocotex.com/mainmenu.php>Tlhomeso 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>';
if ((($email_address!='') OR ($email_address!='')) AND ($_SESSION['message_timber']!='') ) {
//include ('alert_to_email.php');
}
$email_address='';

		

$table_name = $_SESSION['db_prefix']."_alerts";
	$alert_query = "SELECT user_name, send_alert, send_email FROM $table_name WHERE alert_name = 'min stock' AND condition_2='Mitek' ";
	$alert_result = mySQL_query($alert_query);
	$alert_num = mysql_num_rows($alert_result);
	$k=0;
	while ($k<$alert_num) {
		$send_email = mysql_result($alert_result, $k, "send_email");
		$user_name = mysql_result($alert_result, $k, "user_name");
		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=$email_address.mysql_result($address_result, 0, "email").', ';
		}
		$k++;
		}
$message = '<body><font face=Calibri size=3><b>Mitek stock level report:</b></font><br>'.$_SESSION['message_mitek'].'<br><font face=Calibri size=3><br>This message was generated on '.date("d-m-Y, H:m", strtotime($entry_date )).'.<br>For more info, login at <a href=costing.tocotex.com/mainmenu.php>Tlhomeso 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>';
if ((($email_address!='') OR ($email_address!='')) AND ($_SESSION['message_mitek']!='') ) {
//include ('alert_to_email.php');
}
$email_address='';


$table_name = $_SESSION['db_prefix']."_alerts";
	$alert_query = "SELECT user_name, send_alert, send_email FROM $table_name WHERE alert_name = 'min stock' AND condition_3='Sundries' ";
	$alert_result = mySQL_query($alert_query);
	$alert_num = mysql_num_rows($alert_result);
	$k=0;
	while ($k<$alert_num) {
		$send_email = mysql_result($alert_result, $k, "send_email");
		$user_name = mysql_result($alert_result, $k, "user_name");
		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=$email_address.mysql_result($address_result, 0, "email").', ';
		}
		$k++;
		}
$message = '<body><font face=Calibri size=3><b>Sundries stock level report:</b></font><br>'.$_SESSION['message_sundries'].'<br><font face=Calibri size=3><br>This message was generated on '.date("d-m-Y, H:m", strtotime($entry_date )).'.<br>For more info, login at <a href=costing.tocotex.com/mainmenu.php>Tlhomeso 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>';
if ((($email_address!='') OR ($email_address!='')) AND ($_SESSION['message_sundries']!='') ) {
include ('alert_to_email.php');
}
$email_address='';


$table_name = $_SESSION['db_prefix']."_alerts";
	$alert_query = "SELECT user_name, send_alert, send_email FROM $table_name WHERE alert_name = 'min stock' AND condition_4='Other' ";
	$alert_result = mySQL_query($alert_query);
	$alert_num = mysql_num_rows($alert_result);
	$k=0;
	while ($k<$alert_num) {
		$send_email = mysql_result($alert_result, $k, "send_email");
		$user_name = mysql_result($alert_result, $k, "user_name");
		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=$email_address.mysql_result($address_result, 0, "email").', ';
		}
		$k++;
		}
$message = '<body><font face=Calibri size=3><b>Other stock level report:</b></font><br>'.$_SESSION['message_other'].'<br><font face=Calibri size=3><br>This message was generated on '.date("d-m-Y, H:m", strtotime($entry_date )).'.<br>For more info, login at <a href=costing.tocotex.com/mainmenu.php>Tlhomeso 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>';
if ((($email_address!='') OR ($email_address!='')) AND ($_SESSION['message_other']!='') ) {
//include ('alert_to_email.php');
}
$email_address='';
	
?>