<!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  reports 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="reports.php" method="get"> <label class="label_std">Select a user to set and send reports&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=reports.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="reports_save.php" method="get" name="form2" id="form2">
<div class="page_inside_frame">
Set reports 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">Reports:</label>
      <br />
     <div class="page_inside_frame" style="width:650px;"> HR:
       <table width="650" border="0" cellspacing="0" cellpadding="0">
   <?php
	  	$table_name = $_SESSION['db_prefix']."_reports";
		$check_query = "SELECT send_report, send_email  FROM $table_name WHERE report_name = 'daily attendance' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_report = mysql_result($check_result, 0, "send_report");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_report = '';
			$send_email = '';
		}
?>
          <tr>
            <td colspan="4">&nbsp;</td>
          </tr>
          <tr>
            <td width="361">Daily attendance report</td>
            <td width="120">every workday<sup></sup></td>
            <td width="90">&nbsp;&nbsp;
              <input type="checkbox" name="hr_attendance_report_checkbox" id="hr_attendance_report_checkbox" <?php if ($send_report=='yes') {?> checked="checked" <?php } ?> />
             report&nbsp;</td>
            <td width="79"><input type="checkbox" name="hr_attendance_email_checkbox" id="hr_attendance_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('hr_attendance_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send reports 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>
      <div class="page_inside_frame" style="width:650px;">
      Sales:
        <table width="650" border="0" cellspacing="0" cellpadding="0">
          <?php
	  	$table_name = $_SESSION['db_prefix']."_reports";
		$check_query = "SELECT send_report, send_email  FROM $table_name WHERE report_name = 'daily sales' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_report = mysql_result($check_result, 0, "send_report");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_report = '';
			$send_email = '';
		}
?>
          <tr>
            <td colspan="4">&nbsp;</td>
          </tr>
          <tr>
            <td width="361">Daily sales report</td>
            <td width="120">every workday<sup></sup></td>
            <td width="90">&nbsp;&nbsp;
              <input type="checkbox" name="daily_sales_report_checkbox" id="daily_sales_report_checkbox" <?php if ($send_report=='yes') {?> checked="checked" <?php } ?> />
              report&nbsp;</td>
            <td width="79"><input type="checkbox" name="daily_sales_email_checkbox" id="daily_sales_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('daily_sales_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send reports 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']."_reports";
		$check_query = "SELECT send_report, send_email  FROM $table_name WHERE report_name = 'daily follow up' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_report = mysql_result($check_result, 0, "send_report");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_report = '';
			$send_email = '';
		}
?>
          <tr>
            <td>Daily follow up report</td>
            <td>every workday<sup></sup></td>
            <td>&nbsp;&nbsp;
              <input type="checkbox" name="quote_follow_up_report_checkbox" id="quote_follow_up_report_checkbox" <?php if ($send_report=='yes') {?> checked="checked" <?php } ?> />
              report&nbsp;</td>
            <td><input type="checkbox" name="quote_follow_up_email_checkbox" id="quote_follow_up_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('quote_notes_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send reports 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']."_reports";
		$check_query = "SELECT send_report, send_email  FROM $table_name WHERE report_name = 'daily quote notes' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_report = mysql_result($check_result, 0, "send_report");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_report = '';
			$send_email = '';
		}
?>
         <tr>
            <td>Daily quote notes report</td>
            <td>every workday<sup></sup></td>
            <td>&nbsp;&nbsp;
              <input type="checkbox" name="quote_notes_report_checkbox" id="quote_notes_report_checkbox" <?php if ($send_report=='yes') {?> checked="checked" <?php } ?> />
              report&nbsp;</td>
            <td><input type="checkbox" name="quote_notes_email_checkbox" id="quote_notes_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('quote_notes_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send reports 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>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</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">&nbsp;</td>
    <td width="120">&nbsp;</td>
    <td width="90">&nbsp;</td>
    <td width="79">&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>

  <tr>
    <td width="361">&nbsp;</td>
    <td width="120">&nbsp;</td>
    <td width="90">&nbsp;</td>
    <td width="79">&nbsp;</td>
  </tr>
        </table>
 </div>
 <div class="page_inside_frame" style="width:650px;">
      Stores:
        <table width="650" border="0" cellspacing="0" cellpadding="0">
          <?php
	  	$table_name = $_SESSION['db_prefix']."_reports";
		$check_query = "SELECT send_report, send_email  FROM $table_name WHERE report_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) {
		$send_report = mysql_result($check_result, 0, "send_report");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_report = '';
			$send_email = '';
		}
?>
          <tr>
            <td colspan="4">&nbsp;</td>
          </tr>
          <tr>
            <td width="361">Minimum stock </td>
            <td width="120">every workday<sup></sup></td>
            <td width="90">&nbsp;&nbsp;
              <input type="checkbox" name="min_stock_report_checkbox" id="min_stock_report_checkbox" <?php if ($send_report=='yes') {?> checked="checked" <?php } ?> />
              report&nbsp;</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)
{
    document.getElementById('quote_notes_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send reports 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>
 <div class="page_inside_frame" style="width:650px;"> Transport:
   <table width="650" border="0" cellspacing="0" cellpadding="0">
   <?php
	  	$table_name = $_SESSION['db_prefix']."_reports";
		$check_query = "SELECT send_report, send_email  FROM $table_name WHERE report_name = 'license expiry' AND user_name = '".$user_name."' ";
		$check_result = mySQL_query($check_query);
		$check_num = mysql_num_rows($check_result);
		if ($check_num!=0) {
		$send_report = mysql_result($check_result, 0, "send_report");
		$send_email = mysql_result($check_result, 0, "send_email");
		}
		else {
			$send_report = '';
			$send_email = '';
		}
?>
          <tr>
            <td colspan="4">&nbsp;</td>
          </tr>
          <tr>
            <td width="361">Report on expiry dates vehicle licenses and insurance</td>
            <td width="120">monthly on 25<sup>th</sup></td>
            <td width="90">&nbsp;&nbsp;
              <input type="checkbox" name="transport_license_report_checkbox" id="transport_license_report_checkbox" <?php if ($send_report=='yes') {?> checked="checked" <?php } ?> />
             report&nbsp;</td>
            <td width="79"><input type="checkbox" name="transport_license_email_checkbox" id="transport_license_email_checkbox" <?php if ($send_email=='yes') {?> checked="checked" <?php } ?>  
      	onclick="if (!document.getElementById('email_text').value)
{
    document.getElementById('transport_license_email_checkbox').checked = false;
    alertMessage(2, '', 'There is no e-mail address for this user.&lt;br&gt;To send reports 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>
 
 
 </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>