<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<?php
include ("../navigation/header.php");
$page_name = "AD-permissions";
include ("../navigation/access.php");


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

if ($set==0) {

$table_name = $_SESSION['db_prefix']."_users";
$select_query = "SELECT access_id, username FROM $table_name ";
	$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> 
</head>
<?php
if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>
<body >

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

<?php if ($set==0) { ?>
<div class="page_middle_frame" style="margin-top:20px;"><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="selectbox120">
    <option value=""></option>
    <?php
        	for ($i = 0; $i < count($arrId); $i++) {
    		echo "<option value=" . "\"" . $arrId[$i] . "\"" . ">" . $arrName[$i] . "</option>";
	}
?>
  </select>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input name="button" type="submit" class="imagebutton" id="button" value="go" />
    <input name="set" type="hidden" id="set" value="1" />
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("form1");
  frmvalidator.EnableMsgsTogether();
  frmvalidator.addValidation("user_select","req","Please select user.");
</script></div>
<?php }
else {
	?>
<form action="alerts_save.php" method="get">
<div class="page_middle_frame">
Set alerts and e-mail notification for:&nbsp;<?php echo $user_name ?>
<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;
    document.getElementById('min_stock_email_checkbox').checked = false;
    document.getElementById('emp_late_email_checkbox').checked = false;
    document.getElementById('sales_email_checkbox').checked = false;
}" >
<br />
      <br />
  </div>
    <br />
<br />
<div class="page_middle_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 = '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" height="35">Alert when a quotation made of more than:&nbsp;</td>
        <td width="120">P&nbsp;
          <input type="text" name="quotation_select" id="quotation_select" class="text60" onkeypress="return numbersonly(this, event)" onfocus = "this.select();" style="text-align:right" value="<?php echo $condition_1?>" /></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.&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 = '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_2 = 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_2 = '20000';
			$send_alert = '';
			$send_email = '';
		}
	?>
      <tr>
        <td width="361" height="30">Alert when an order is received of more than:&nbsp;</td>
        <td width="120">P&nbsp;
          <input type="text" name="receive_order_select" id="receive_order_select" class="text60" onkeypress="return numbersonly(this, event)" onfocus = "this.select();" style="text-align:right" value="<?php echo $condition_2 ?>" /></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.&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 send_alert, send_email  FROM $table_name WHERE alert_name = 'direct 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 height="30">Alert when an order for direct delivery by Radstone is placed:&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;&nbsp;
          <input type="checkbox" name="direct_order_alert_checkbox" id="direct_order_alert_checkbox" <?php if ($send_alert=='yes') {?> checked="checked" <?php } ?> />
          <label for="checkbox2"></label>
          alert&nbsp;</td>
        <td><input type="checkbox" name="direct_order_email_checkbox" id="direct_order_email_checkbox"  <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('direct_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>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
  </div>
  <br />
</div>  
<div class="page_middle_frame" align="right" >
  <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save"/>
    <input name="save_close_button" type="submit" class="imagebutton" id="save_close_button" value="Save &amp; Close"/>
  </div>
</form>
</div>
</div>

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

</body>



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