<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php
include ("../navigation/header.php");
$page_name = "Stores-distributor report";
include ("../navigation/access.php");

?>

<link href="../css/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/alert_message.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/go_to_url.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/show_hide_layers.js"  type="text/javascript"></script>  

<?php
if ($permission_num==1) {
	include ("../navigation/store_sidebar.php");
	
$report_no = $_GET['report_select'];

$table_name = $_SESSION['db_prefix']."_customer";
$customer_query = "SELECT cust_id, comp_name FROM $table_name ORDER BY comp_name  ";
$customer_result = mySQL_query($customer_query);
$customer_num = mysql_num_rows($customer_result);

$table_name = $_SESSION['db_prefix']."_distributor_ordered_report";
$report_query = "SELECT report_year, report_type FROM $table_name WHERE report_no = '".$report_no."' ";
$report_result = mySQL_query($report_query);
$report_year = mysql_result($report_result, 0, "report_year");	
$report_type = mysql_result($report_result, 0, "report_type");	

	
?>
<script>
function check_all() {
	
	 var line_num = <?php echo $customer_num ?>;
	
	 if (document.getElementById('all_checkbox').checked) {
	         k=0;
			 while (k<line_num)
			   { 
			   document.getElementById('cust_checkbox'+k).checked = true;
			   k++;
			   }
	 }
	 else {
		k=0;
			 while (k<line_num)
			   { 
			   document.getElementById('cust_checkbox'+k).checked = false;
			   k++;
			   }
	 }
}
</script>
</head>

<body onLoad="<?php $z=0; while ($z<25) { $_SESSION['cust_id'.$z]=''; $z++; } ?>">

<div class="main_frame">


<div class="page_middle_frame">
<form action="distributor_ordered_report_set.php" method="POST">
Select report to display:<br>
<br>
   <label>
      <input type="radio" name="report_select" value="1" id="report_select_group_0" <?php if ($report_no==1) { ?> checked <?php } ?> onclick="window.location= 'distributor_ordered_report_set.php?report_select=1'">
      Report 1</label>
   &nbsp;&nbsp;&nbsp;&nbsp;
    <label>
      <input type="radio" name="report_select" value="2" id="report_select_group_1" <?php if ($report_no==2) { ?> checked <?php } ?> onclick="window.location= 'distributor_ordered_report_set.php?report_select=2'">
      Report 2</label>
   &nbsp;&nbsp;&nbsp;&nbsp; 
    <label>
      <input type="radio" name="report_select" value="Report 3" id="report_select_group_2" <?php if ($report_no==3) { ?> checked <?php } ?> onclick="window.location= 'distributor_ordered_report_set.php?report_select=3'">
      Report 3</label>
   &nbsp;&nbsp;&nbsp;&nbsp; 
    <label>
      <input type="radio" name="report_select" value="Report 4" id="report_select_group_3" <?php if ($report_no==4) { ?> checked <?php } ?> onclick="window.location= 'distributor_ordered_report_set.php?report_select=4'">
      Report 4</label>
</form>
</div>

<div class="page_middle_frame">

<form  method="POST" >
<div style="width:250px; float:left;">
 Report year:
&nbsp;&nbsp;
<select name="report_year_select" id="report_year_select" onChange="document.getElementById('save_message').hidden=false;">
  <option value="2015">2015</option>
  <option value="2016">2016</option>
  <option value="2017">2017</option>
  <option value="2018">2018</option>
  <option value="2019">2019</option>
  <option value="2020">2020</option>
  <option value="2021">2021</option>
  <option value="2022">2022</option>
  <option value="2023">2023</option>
  <option value="2024">2024</option>
  <option value="2025">2025</option>
  <option value="2026">2026</option>
  <option value="<?php echo $report_year ?>" selected="selected"><?php echo $report_year ?></option>
</select>
<br>
<br>
Report type:<br>

  <label>
    <input type="radio" name="report_type" value="1" id="report_type_0" <?php if ($report_type==1) { ?> checked <?php } ?>  onChange="document.getElementById('save_message').hidden=false;">
    Tiles & Acc</label>
  <br>
  <label>
    <input type="radio" name="report_type" value="2" id="report_type_1" <?php if ($report_type==2) { ?> checked <?php } ?>  onChange="document.getElementById('save_message').hidden=false;">
    Tiles</label>
  <br>
  <label>
    <input type="radio" name="report_type" value="3" id="report_type_2" <?php if ($report_type==3) { ?> checked <?php } ?>  onChange="document.getElementById('save_message').hidden=false;">
    Accessories</label>
  <br>
  <br>
<br>
<br>
<input name="report_no_text" type="hidden" value="<?php echo $report_no ?>">
<input name="save_button" type="submit" value="Save report <?php echo $report_no ?>" class="imagebutton" formaction="distributor_ordered_report_set_save.php"  onClick="document.getElementById('save_message').hidden=false; this.form.target='_self';return true;"><br>
<br>
<br>
<br>
<div style="width:250px; height:200px;">
<div id="save_message" hidden="true" style="width:250px;">
<img src="../images/exclamation_mark_red_small.png" width="15" height="24">The changed report settings will be displayed in the report but are not saved.<br>To remember the new settings, save the settings before opening the report.
</div>
</div>
<br>


<input name="save_button" type="submit" value="Open report <?php echo $report_no ?>" class="imagebutton" formaction="distributor_ordered_report.php"  onClick=" this.form.target='_self';return true;"><br>
<br>

<input name="save_button" type="submit" value="Open report <?php echo $report_no ?> in new window" class="imagebutton" onclick="this.form.target='_blank';return true;" formaction="distributor_ordered_report_full_screen.php">
</div>

<div style=" width:300px; float:left;">
Customers to display:<br>
<br>
<table width="290" id="table_display">
  <tr>
    <td width="43" align="center"><input type="checkbox" name="all_checkbox" id="all_checkbox" onClick="check_all()"></td>
    <td width="235">&nbsp;</td>
    
  </tr>
<?php 
$i=0;
while ($i<$customer_num)  {
	$cust_id = mysql_result($customer_result, $i, "cust_id");
	$comp_name = mysql_result($customer_result, $i, "comp_name");
	
	$table_name = $_SESSION['db_prefix']."_distributor_ordered_report_cust";
	$check_query = "SELECT cust_id FROM $table_name WHERE report_no = '".$report_no."' AND cust_id = '".$cust_id."' ";
	$check_result = mySQL_query($check_query);
	$check_num = mysql_num_rows($check_result);
	if ($check_num>0) {
		  $checked = 'yes';
	}
	else {
		$checked = 'no';
	}
	
	?>
  <tr>
    <td align="center"><input type="checkbox" name="cust_checkbox<?php echo $i ?>" id="cust_checkbox<?php echo $i ?>" <?php if ($checked=='yes') { ?> checked <?php } ?>  onChange="document.getElementById('save_message').hidden=false;"></td>
    <td><?php echo $comp_name ?>
      <input type="hidden" name="cust_id_text<?php echo $i ?>" id="cust_id_text<?php echo $i ?>" value="<?php echo $cust_id ?>">&nbsp;(<?php echo $cust_id ?>) </td>
    </tr>
  <?php
  $i++;
}
?>
</table>
<input name="line_num_text" type="hidden" value="<?php echo $i ?>">

</div>


</form>

</div>

</div> 


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

<?php } else { ?>
<script> needToConfirm = false; </script>
<?php
    $_SESSION['denied_return'] = "store/select_store_report.php";	
    include ("../navigation/store_sidebar.php");?>
    
	<body onLoad="accessdenied(); return false">	
	</body>
<?php }
?>
</html>
