<?php
$entryDate = date("Y-m-d H:i:s"); 

$table_name = $_SESSION['db_prefix']."_alerts";
	$alert_query = "SELECT user_name, condition_1, condition_2, condition_3, condition_4, condition_5, send_alert FROM $table_name WHERE alert_name = 'min stock' ";
	$alert_result = mySQL_query($alert_query);
	$alert_num = mysql_num_rows($alert_result);
		
	$j=0;
	while ($j<$alert_num) {
		$user_name = mysql_result($alert_result, $j, "user_name");
		$send_alert = mysql_result($alert_result, $j, "send_alert");
		$condition_1 = mysql_result($alert_result, $j, "condition_1");
		$condition_2 = mysql_result($alert_result, $j, "condition_2");
		$condition_3 = mysql_result($alert_result, $j, "condition_3");
		$condition_4 = mysql_result($alert_result, $j, "condition_4");
		$condition_5 = mysql_result($alert_result, $j, "condition_5");
						
		if ($condition_1==$sub_category) {
		if ($send_alert=='yes') {
			$table_name = $_SESSION['db_prefix']."_alert_message";
			$message_query = "INSERT INTO $table_name (user_name, department, generated, alert, detail_1, detail_2, detail_3 ) VALUES ('".$user_name."', 'stores', '".$entryDate."', '35', '".$store_item_id."', '".$total_quantity."', '".$sub_category."' ) ";
			execsql($message_query);
		}
		}
		
		if ($condition_2==$sub_category) {
		if ($send_alert=='yes') {
			$table_name = $_SESSION['db_prefix']."_alert_message";
			$message_query = "INSERT INTO $table_name (user_name, department, generated, alert, detail_1, detail_2, detail_3 ) VALUES ('".$user_name."', 'stores', '".$entryDate."', '35', '".$store_item_id."', '".$total_quantity."', '".$sub_category."' ) ";
			execsql($message_query);
		}
		}
		
		if ($condition_3==$sub_category) {
		if ($send_alert=='yes') {
			$table_name = $_SESSION['db_prefix']."_alert_message";
			$message_query = "INSERT INTO $table_name (user_name, department, generated, alert, detail_1, detail_2, detail_3 ) VALUES ('".$user_name."', 'stores', '".$entryDate."', '35', '".$store_item_id."', '".$total_quantity."', '".$sub_category."' ) ";
			execsql($message_query);
		}
		}
		
		if ($condition_4==$sub_category) {
		
		if ($send_alert=='yes') {
			$table_name = $_SESSION['db_prefix']."_alert_message";
			$message_query = "INSERT INTO $table_name (user_name, department, generated, alert, detail_1, detail_2, detail_3 ) VALUES ('".$user_name."', 'stores', '".$entryDate."', '35', '".$store_item_id."', '".$total_quantity."', '".$sub_category."' ) ";
			execsql($message_query);
		}
		}
		
		if ($condition_5==$sub_category) {
		if ($send_alert=='yes') {
			$table_name = $_SESSION['db_prefix']."_alert_message";
			$message_query = "INSERT INTO $table_name (user_name, department, generated, alert, detail_1, detail_2, detail_3 ) VALUES ('".$user_name."', 'stores', '".$entryDate."', '35', '".$store_item_id."', '".$total_quantity."', '".$sub_category."' ) ";
			execsql($message_query);
		}
		}
		
		
	$j++;	
	}
	
