<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include('../include/session.php');


$set = $_GET['set'];
$message='';

if ($set==0) {

$table_name = $_SESSION['db_prefix']."_users";
$select_query = "SELECT access_id, username FROM $table_name ORDER BY username";
	$arrId = array ();
	$arrName = array ();
	$select_result = execsql($select_query);
	$select_num = mysql_num_rows($select_result);
	$a = 0;
	while ($a < $select_num) {
		$arrId[$a] = mysql_result($select_result, $a, "access_id");
		$arrName[$a] = mysql_result($select_result, $a, "username");
		$a++;
	}
$user_name = '';
$email = '';	
} 
else {
$access_id = $_GET['user_select'];
$table_name = $_SESSION['db_prefix']."_users";
$email_query = "SELECT username, email FROM $table_name WHERE access_id = '".$access_id."'  ";
$email_result = mySQL_query($email_query);
$email_num = mysql_num_rows($email_result);
$user_name = mysql_result($email_result, 0, "username");
$email = mysql_result($email_result, 0, "email");	
}
?>



<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="../jscript/gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>  
</head>


<body >
<?php
include ("../navigation/header.php");
$page_name = "AD-permissions";
include ("../navigation/access.php");
if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>

<div class="main_frame"  style="height:auto; min-height:570px;">
<div class="page_head_frame">
<label class="label_page_head">Set  alerts and email</label>
</div>


<div class="page_middle_frame" style="margin-top:20px;">
<?php if ($set=='') { ?>
<div class="page_inside_frame">
<form name="form1" id="form1" action="alerts.php" method="get"> <label class="label_std">Select a user to set and send alerts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <select name="user_select" class="select160" onchange="needToConfirm = false; window.location.href= this.form.user_select.options[this.form.user_select.selectedIndex].value" >
      <option value=""></option>
      <?php
        	for ($i = 0; $i < count($arrId); $i++) {
    		echo "<option value=alerts.php?user_select=".$arrId[$i]."&set=1>".$arrName[$i]."</option>";
	}
?>
    </select>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</form>
</div>
<?php } ?>

<?php if ($set==1) { ?>
<form action="alerts_save.php" method="get" name="form2" id="form2">
<div class="page_inside_frame">
Set alerts and e-mail notification for:&nbsp <label class="label_std" style="font-size:14px"><?php echo $user_name ?></label>
<input type="hidden" name="access_id" id="access_id"  value="<?php echo $access_id?>"/><input type="hidden" name="user_name" id="user_name"  value="<?php echo $user_name?>"/>
<br />
<br />

      email address for this user:
      &nbsp;&nbsp;&nbsp;
<input name="email_text" type="text"  class="text300"  id="email_text"  value="<?php echo $email?>"   onblur="if (!document.getElementById('email_text').value)
{
    document.getElementById('receive_order_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts or reports by email, an email address is required.<br><br>If email alerts or reports were checked below, they have been deselected.');
    document.getElementById('receive_order_email_checkbox').checked = false;
    
}" >
<br />
      <br />
  </div>
    <br />
<br />
<div class="page_inside_frame" >
      <label class="label_std" style="font-size:14px">Instant alerts:</label>
      <br />
      
      <div class="page_inside_frame" style="width:650px;">
      <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'late' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$condition_1 = mysql_result($check_result, 0, "condition_1");
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$condition_1 = '5';
			$send_alert = '';
			$send_email = '';
		}
	?>HR
      <table width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td width="319">Alert when employee more then 3 times late in</td>
    <td width="162"><select name="late_days_select" class="select50">
      <option value="5">5</option>
        <option value="7">7</option>
        <option value="10">10</option>
        <option value="14">14</option>
        <option value="21">21</option>
        <option value="31">31</option>
        <option value="<?php echo $condition_1?>" selected="selected"><?php echo $condition_1?></option>
    </select> 
      days</td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="late_alert_checkbox" id="late_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="late_email_checkbox" id="late_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('late_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
      <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'absent' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$condition_1 = mysql_result($check_result, 0, "condition_1");
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$condition_1 = '31';
			$send_alert = '';
			$send_email = '';
		}
	?>
<tr>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td width="319">Alert when employee more then 3 times absent in:&nbsp;</td>
    <td width="162"><select name="absent_days_select" class="select50">
      <option value="5">5</option>
      <option value="7">7</option>
      <option value="10">10</option>
      <option value="14">14</option>
      <option value="21">21</option>
      <option value="31">31</option>
      <option value="<?php echo $condition_1?>" selected="selected"><?php echo $condition_1?></option>
    </select> 
      &nbsp;days</td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="absent_alert_checkbox" id="absent_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="absent_email_checkbox" id="absent_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('absent_order_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
  
      <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'leave' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
	?>
<tr>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td width="319">Alert when employee exceeds maximum leave days:&nbsp;</td>
    <td width="162"></td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="leave_alert_checkbox" id="leave_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="leave_email_checkbox" id="leave_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('leave_order_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>   
      </table>
 </div>
      
      
      
      <div class="page_inside_frame" style="width:650px;">
      <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'quotation' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$condition_1 = mysql_result($check_result, 0, "condition_1");
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$condition_1 = '20000';
			$send_alert = '';
			$send_email = '';
		}
	?>Sales
      <table width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td width="361">Alert when a quotation made of more than:&nbsp;</td>
    <td width="120">P&nbsp;
      <select name="quotation_select" class="select100">
        <option value="20000">20000</option>
        <option value="30000">30000</option>
        <option value="40000">40000</option>
        <option value="50000">50000</option>
        <option value="60000">60000</option>
        <option value="70000">70000</option>
        <option value="80000">80000</option>
        <option value="90000">90000</option>
        <option value="100000">100000</option>
        <option value="110000">110000</option>
        <option value="120000">120000</option>
        <option value="150000">150000</option>
        <option value="200000">200000</option>
        <option value="250000">250000</option>
        <option value="300000">300000</option>
        <option value="400000">400000</option>
        <option value="500000">500000</option>
        <option value="<?php echo $condition_1?>" selected="selected"><?php echo $condition_1?></option>
      </select></td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="quotation_alert_checkbox" id="quotation_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="quotation_email_checkbox" id="quotation_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('quotation_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>



      <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'receive order' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$condition_1 = mysql_result($check_result, 0, "condition_1");
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$condition_1 = '20000';
			$send_alert = '';
			$send_email = '';
		}
	?>
<tr>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td width="361">Alert when an order is received of more than:&nbsp;</td>
    <td width="120">P&nbsp;
      <select name="receive_order_select" class="select100">
        <option value="20000">20000</option>
        <option value="30000">30000</option>
        <option value="40000">40000</option>
        <option value="50000">50000</option>
        <option value="60000">60000</option>
        <option value="70000">70000</option>
        <option value="80000">80000</option>
        <option value="90000">90000</option>
        <option value="100000">100000</option>
        <option value="110000">110000</option>
        <option value="120000">120000</option>
        <option value="150000">150000</option>
        <option value="200000">200000</option>
        <option value="250000">250000</option>
        <option value="300000">300000</option>
        <option value="400000">400000</option>
        <option value="500000">500000</option>
        <option value="<?php echo $condition_1?>" selected="selected"><?php echo $condition_1?></option>
      </select></td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="receive_order_alert_checkbox" id="receive_order_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="receive_order_email_checkbox" id="receive_order_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('receive_order_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
</table>
 </div>
      <div class="page_inside_frame" style="width:650px;">		
        Orders
        <table width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4">&nbsp;</td>
    </tr>
  <tr>
    <td width="361">Alert when compiled order value exceeds order value:</td>
    <td width="120">&nbsp;</td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="order_value_alert_checkbox" id="order_value_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="order_value_email_checkbox" id="order_value_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('order_value_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
 <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'order stock' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>

  <tr>
    <td width="361">Alert on insufficient stock on compiled order:</td>
    <td width="120">&nbsp;</td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="order_stock_alert_checkbox" id="order_stock_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="order_stock_email_checkbox" id="order_stock_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('order_stock_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
 <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'non-stock order' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>

  <tr>
    <td>Alert on non stock item on order:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="non_stock_order_alert_checkbox" id="non_stock_order_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox4"></label>
alert&nbsp;</td>
    <td><input type="checkbox" name="non_stock_order_email_checkbox" id="non_stock_order_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('non_stock_order_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email</td>
  </tr>
   <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'new mworks job' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
  <tr>
    <td width="361">Alert on new M-works job:</td>
    <td width="120">&nbsp;</td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="mworks_job_alert_checkbox" id="mworks_job_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="mworks_job_email_checkbox" id="mworks_job_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('mworks_job_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
  <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'job inspected' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
  <tr>
    <td>Alert on job inspection completed:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="job_inspection_alert_checkbox" id="job_inspection_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      alert&nbsp;</td>
    <td><input type="checkbox" name="job_inspection_email_checkbox" id="job_inspection_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('job_inspection_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
   <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'job invoiced' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
     <td>Alert on job invoiced:</td>
     <td>&nbsp;</td>
     <td>&nbsp;&nbsp;
       <input type="checkbox" name="job_invoiced_alert_checkbox" id="job_invoiced_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       <label for="checkbox5"></label>
alert&nbsp;</td>
     <td><input type="checkbox" name="job_invoiced_email_checkbox" id="job_invoiced_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('job_invoiced_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
   </tr>
   <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'job completed' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on job completed:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="job_completed_alert_checkbox" id="job_completed_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox2"></label>
      alert&nbsp;</td>
    <td><input type="checkbox" name="job_completed_email_checkbox" id="job_completed_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('job_completed_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
  <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'job comment' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on job comment:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="job_comment_alert_checkbox" id="job_comment_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox2"></label>
      alert&nbsp;</td>
    <td><input type="checkbox" name="job_comment_email_checkbox" id="job_comment_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('job_comment_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
        </table>
 </div>
 
 <br />
 <div class="page_inside_frame" style="width:650px;">
Production
   <table width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4">&nbsp;</td>
    </tr>

<?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'm-order value' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>    
  <tr>
    <td width="361">Alert when compiled M-works order value exceeds order value:</td>
    <td width="120">&nbsp;</td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="m_order_value_alert_checkbox" id="m_order_value_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="m_order_value_email_checkbox" id="m_order_value_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('m_order_value_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
 <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'm-order stock' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>

  <tr>
    <td width="361">Alert on insufficient stock on compiled M-works order:</td>
    <td width="120">&nbsp;</td>
    <td width="90">&nbsp;&nbsp;
      <input type="checkbox" name="m_order_stock_alert_checkbox" id="m_order_stock_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox3"></label>
alert&nbsp;</td>
    <td width="79"><input type="checkbox" name="m_order_stock_email_checkbox" id="m_order_stock_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('m_order_stock_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
  </tr>
 <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'm-non-stock order' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>

  <tr>
    <td>Alert on non stock item on M-works order:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="m_non_stock_order_alert_checkbox" id="m_non_stock_order_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox4"></label>
alert&nbsp;</td>
    <td><input type="checkbox" name="m_non_stock_order_email_checkbox" id="m_non_stock_order_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('m_non_stock_order_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email</td>
  </tr>
  <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'm-job production' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
     <td>Alert on M-works production done:</td>
     <td>&nbsp;</td>
     <td>&nbsp;&nbsp;
       <input type="checkbox" name="m_production_alert_checkbox" id="m_production_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       <label for="checkbox4"></label>
       alert&nbsp;</td>
     <td><input type="checkbox" name="m_production_email_checkbox" id="m_production_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('m_production_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
  &nbsp;&nbsp;email</td>
     </tr>
      <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'm-job invoiced' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
     <td>Alert on M-works job invoiced:</td>
     <td>&nbsp;</td>
     <td>&nbsp;&nbsp;
       <input type="checkbox" name="m_job_invoiced_alert_checkbox" id="m_job_invoiced_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       <label for="checkbox4"></label>
       alert&nbsp;</td>
     <td><input type="checkbox" name="m_job_invoiced_email_checkbox" id="m_job_invoiced_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('m_job_invoiced_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
  &nbsp;&nbsp;email</td>
     </tr>
       <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'm-job completed' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on M-works job completed:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="m_job_completed_alert_checkbox" id="m_job_completed_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
      <label for="checkbox2"></label>
      alert&nbsp;</td>
    <td><input type="checkbox" name="m_job_completed_email_checkbox" id="m_job_completed_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('m_job_completed_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
        </table>
 </div>
 
<!--start maintenance--> 
<div class="page_inside_frame" style="width:650px;">		
        Maintenance
          <table width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4">&nbsp;</td>
    </tr>
    
<?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'maintenance quoted' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
     <td width="361">Alert on maintenance quote accepted:</td>
     <td width="120">&nbsp;</td>
     <td width="90">&nbsp;&nbsp;
       <input type="checkbox" name="maintenance_quoted_alert_checkbox" id="maintenance_quoted_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       <label for="checkbox5"></label>
alert&nbsp;</td>
     <td width="79"><input type="checkbox" name="maintenance_quoted_email_checkbox" id="maintenance_quoted_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('job_quoted_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
   </tr    
    
><?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'maintenance invoiced' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
     <td width="361">Alert on maintenance quote invoiced:</td>
     <td width="120">&nbsp;</td>
     <td width="90">&nbsp;&nbsp;
       <input type="checkbox" name="maintenance_invoiced_alert_checkbox" id="maintenance_invoiced_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       <label for="checkbox5"></label>
alert&nbsp;</td>
     <td width="79"><input type="checkbox" name="maintenance_invoiced_email_checkbox" id="maintenance_invoiced_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('job_invoiced_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
&nbsp;&nbsp;email </td>
   </tr>

<?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'maintenance opened' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on maintenance card opened::</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="maintenance_opened_alert_checkbox" id="maintenance_opened_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       alert&nbsp;</td>
    <td><input type="checkbox" name="maintenance_opened_email_checkbox" id="maintenance_opened_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('maintenance_opened_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
 <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'maintenance closed' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on maintenance card closed:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="maintenance_closed_alert_checkbox" id="maintenance_closed_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       alert&nbsp;</td>
    <td><input type="checkbox" name="maintenance_closed_email_checkbox" id="maintenance_closed_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('maintenance_closed_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
   
<?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'maintenance completed' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on maintenance job completed:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="maintenance_completed_alert_checkbox" id="maintenance_completed_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       alert&nbsp;</td>
    <td><input type="checkbox" name="maintenance_completed_email_checkbox" id="maintenance_completed_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('maintenance_completed_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
<?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'maintenance request' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
  <tr>
    <td>Alert on maintenance request  from survey:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="maintenance_request_alert_checkbox" id="maintenance_request_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       alert&nbsp;</td>
    <td><input type="checkbox" name="maintenance_request_email_checkbox" id="maintenance_request_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('maintenance_request_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
        </table>
 </div>
<!--end maintenance-->

      <div class="page_inside_frame" style="width:650px;">
      <?php
      $table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, condition_2, condition_3, condition_4, condition_5, send_alert, send_email  FROM $table_name WHERE alert_name = 'min stock' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$condition_1 = mysql_result($check_result, 0, "condition_1");
		$condition_2 = mysql_result($check_result, 0, "condition_2");
		$condition_3 = mysql_result($check_result, 0, "condition_3");
		$condition_4 = mysql_result($check_result, 0, "condition_4");
		$condition_5 = mysql_result($check_result, 0, "condition_5");
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$condition_1 = '';
			$condition_2 = '';
			$condition_3 = '';
			$condition_4 = '';
			$condition_5 = '';
			$send_alert = '';
			$send_email = '';
		}
		?>
                
        <div style="width:650px;">
       <table width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="4">Alert when stock becomes lower than required minimum in:</td>
    </tr>
  <tr>
    <td width="363" height="42"><input type="checkbox" name="electric_fencing_checkbox" value="Electric fencing" id="electric_fencing_checkbox" <?php if ($condition_1=='Electric fencing') {?> checked="checked" <?php } ?>/>
            Electric fencing
           <input type="checkbox" name="fencing_checkbox" value="Fencing" id="fencing_checkbox" <?php if ($condition_2=='Fencing') {?> checked="checked" <?php } ?>/>
            Fencing
           <input type="checkbox" name="palisade_checkbox" value="Palisade" id="palisade_checkbox" <?php if ($condition_3=='Palisade') {?> checked="checked" <?php } ?>/>
            Palisade
            <span class="label_std">
            <br />
            <input type="checkbox" name="mworks_checkbox" value="Other" id="mworks_checkbox"<?php if ($condition_4=='M-works') {?> checked="checked" <?php } ?> /> 
            M-works
</span> 
            <label class="label_std">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="checkbox" name="other_checkbox" value="Other" id="other_checkbox"<?php if ($condition_5=='Other') {?> checked="checked" <?php } ?> />
            Other</label></td>
    <td width="118">&nbsp;</td>
    <td width="90">&nbsp;&nbsp;&nbsp;<input type="checkbox" name="min_stock_alert_checkbox" id="min_stock_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?>/>
&nbsp;alert    </td>
    <td width="79">
    <input type="checkbox" name="min_stock_email_checkbox" id="min_stock_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?> 
      onclick="if (!document.getElementById('email_text').value)
{
    alertMessage(2, '', 'There is no e-mail address for this user.<br>To send alerts by email, an email address is required.<br><br>Enter an email address in the box above and try again.');
    document.getElementById('min_stock_email_checkbox').checked = false;
}"/>
    email</td>
  </tr>
  <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'purchase to authorise' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on purchase order to be authorised:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="purchase_to_authorise_alert_checkbox" id="purchase_to_authorise_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       alert&nbsp;</td>
    <td><input type="checkbox" name="purchase_to_authorise_email_checkbox" id="purchase_to_authorise_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('purchase_to_authorise_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
  
  <?php
	  	$table_name = $_SESSION['db_prefix']."_alerts";
		$check_query = "SELECT condition_1, send_alert, send_email  FROM $table_name WHERE alert_name = 'purchase authorised' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_alert = mysql_result($check_result, 0, "send_alert");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_alert = '';
			$send_email = '';
		}
?>
   <tr>
    <td>Alert on purchase order authorised:</td>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;
      <input type="checkbox" name="purchase_authorised_alert_checkbox" id="purchase_authorised_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
       alert&nbsp;</td>
    <td><input type="checkbox" name="purchase_authorised_email_checkbox" id="purchase_authorised_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('purchase_authorised_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send alerts by email, an email address is required.&lt;br&gt;&lt;br&gt;Enter an email address in the box above and try again.');
}"
 />
      &nbsp;&nbsp;email </td>
  </tr>
       </table>
</div>
</div>
 
 
 </div>  
   
<div class="page_inside_frame" align="right" >
  <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save"  onclick="needToConfirm = false;"/>
    <input name="save_close_button" type="submit" class="imagebutton" id="save_close_button" value="Save &amp; Close" onclick="needToConfirm = false;"/>
  </div>
</form>
<?php
}
?>
</div>
</div>
</div>
</body>

<?php include ('../navigation/side_bar.php'); ?>

<?php } else {
    $_SESSION['denied_return'] = "admin_module/user_list.php";	
    include ("../navigation/admin_sidebar.php");?>
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>
</html>