<!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-presets";
include ("../navigation/access.php");

$table_name = $_SESSION['db_prefix']."_presets";
$preset_query = "SELECT  preset_value  FROM $table_name WHERE preset_name = 'Exchange rate' ";
$preset_result = $con->query($preset_query);
$row = mysqli_fetch_assoc($preset_result);
$exchange_rate = $row["preset_value"];


$table_name = $_SESSION['db_prefix']."_presets";
$preset_query = "SELECT  preset_value  FROM $table_name WHERE preset_name = 'production_margin' ";
$preset_result = $con->query($preset_query);
$row = mysqli_fetch_assoc($preset_result);
$production_margin = $row["preset_value"];

$table_name = $_SESSION['db_prefix']."_presets";
$preset_query = "SELECT  preset_value  FROM $table_name WHERE preset_name = 'packing_margin' ";
$preset_result = $con->query($preset_query);
$row = mysqli_fetch_assoc($preset_result);
$packing_margin = $row["preset_value"];

$table_name = $_SESSION['db_prefix']."_presets";
$preset_query = "SELECT  preset_value  FROM $table_name WHERE preset_name = 'VAT' ";
$preset_result = $con->query($preset_query);
$row = mysqli_fetch_assoc($preset_result);
$vat_rate = $row["preset_value"];


$table_name = $_SESSION['db_prefix']."_presets";
$time_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'clockin1'  ";
$time_result = $con->query($time_query);
$time_num = mysqli_num_rows($time_result);
if ($time_num!=0) {
$row = mysqli_fetch_assoc($time_result);
$hours1 = $row["preset_value"];
}
else {
	$hours1 = 0;
}

$clockin_hours1 =  floor($hours1/60); 
$clockin_mins1 =   $hours1 % 60; 
if ($clockin_hours1<10) { $clockin_hours1 = 0 . $clockin_hours1; }
if ($clockin_mins1<10) { $clockin_mins1 = 0 . $clockin_mins1; }

$table_name = $_SESSION['db_prefix']."_presets";

$time_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'clockout1'  ";
$time_result = $con->query($time_query);
$row = mysqli_fetch_assoc($time_result);
$hours1 = $row["preset_value"];


$grace_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'grace1'  ";
$grace_result = $con->query($grace_query);
$row = mysqli_fetch_assoc($grace_result);
$grace1 = $row["preset_value"];


$clockout_hours1 =  floor($hours1/60); 
$clockout_mins1 =   $hours1 % 60; 
if ($clockout_hours1<10) { $clockout_hours1 = 0 . $clockout_hours1; }
if ($clockout_mins1<10) { $clockout_mins1 = 0 . $clockout_mins1; }


$time_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'clockin2'  ";
$time_result = $con->query($time_query);
$row = mysqli_fetch_assoc($time_result);
$hours2 = $row["preset_value"];


$grace_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'grace2'  ";
$grace_result = $con->query($grace_query);
$row = mysqli_fetch_assoc($grace_result);
$grace2 = $row["preset_value"];


$clockin_hours2 =  floor($hours2/60); 
$clockin_mins2 =   $hours2 % 60; 
if ($clockin_hours2<10) { $clockin_hours2 = 0 . $clockin_hours2; }
if ($clockin_mins2<10) { $clockin_mins2 = 0 . $clockin_mins2; }


$time_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'clockout2'  ";
$time_result = $con->query($time_query);
$row = mysqli_fetch_assoc($time_result);
$hours2 = $row["preset_value"];


$clockout_hours2 =  floor($hours2/60); 
$clockout_mins2 =   $hours2 % 60; 
if ($clockout_hours2<10) { $clockout_hours2 = 0 . $clockout_hours2; }
if ($clockout_mins2<10) { $clockout_mins2 = 0 . $clockout_mins2; }

$time_query = "SELECT preset_value FROM $table_name WHERE preset_name = 'lunch'  ";
$time_result = $con->query($time_query);
$row = mysqli_fetch_assoc($time_result);
$lunch = $row["preset_value"];

?>

<!--jscript-->
<script language="JavaScript" src="../jscript/cancel_confirmation.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/confirm_exit.js"  type="text/javascript"></script>
<script language="JavaScript" src="../jscript/numbers_only_decimal.js"  type="text/javascript"></script> 
<script language="JavaScript" src="../jscript/numbers_only.js"  type="text/javascript"></script>


</head>

<body>
<?php 
if ($permission_num==1) {
	include ("../navigation/admin_sidebar.php");
?>

<div class="main_frame">
<div class="page_head_frame">
    <table width="809" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="385"><label class="label_page_head">Presets</label></td>
        <td align="right">&nbsp;</td>
      </tr>
    </table>
  </div>
  <div class="page_middle_frame">
  <form action="presets_save.php" method="get">
  <div class="page_inside_frame">
  <label class="label_std">Edit values and click Save.</label>
  <br />
<br />

  <table width="402" align="left"  id="table_display">
     <tr>
      <td width="237" align="left">Exchange rate:</td>
      <td width="153"><input type="text" name="exchange_text" id="exchange_text"  value="<?php echo $exchange_rate ?>" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\.....).*/, '$1')" class="text50" onfocus = "this.select();" style="text-align:right"/></td>
    </tr>
    <tr>
      <td width="237" align="left">VAT rate:</td>
      <td width="153"><input name="vat_text" type="text" id="vat_text" value="<?php echo $vat_rate ?>" onkeypress="return numbersonly(this, event)" class="text50" onfocus = "this.select();" style="text-align:right"/></td>
    </tr>
    <tr>
      <td align="left">Production margin:</td>
      <td><input name="margin_text" type="text" id="margin_text" value="<?php echo $production_margin ?>" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\.....).*/, '$1')" class="text50" onfocus = "this.select();" style="text-align:right"/> %</td>
      </tr>
    <tr>
      <td align="left">Packing margin:</td>
      <td><input name="packing_margin_text" type="text" id="packing_margin_text" value="<?php echo $packing_margin ?>" onKeyPress="return isNumberKey(event)" onkeyup=" this.value = this.value.replace (/(\.....).*/, '$1')" class="text50" onfocus = "this.select();" style="text-align:right"/> %</td>
    </tr>
   </table>
 </div><br /><br /><br />

<div class="page_inside_frame">
  Working times: <br />
    Time zone 1 clock-in: 
  <input name="clockin_hour_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="1" max="9" style="text-align:right" value="<?php echo $clockin_hours1 ?>" onfocus = "this.select();"/>
    :
  <input name="clockin_min_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="2" style="text-align:right" max="59" value="<?php echo $clockin_mins1 ?>" onfocus = "this.select();"/>
  &nbsp; clock_out:
  <input name="clockout_hour_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="2" max="20" style="text-align:right" value="<?php echo $clockout_hours1 ?>"  onfocus = "this.select();"/>
    :
  <input name="clockout_min_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="2" max="59" style="text-align:right" value="<?php echo $clockout_mins1 ?>" onfocus = "this.select();"/>
&nbsp;&nbsp;&nbsp;&nbsp;grace time: 
<input type="text" name="grace_min_text" id="grace_min_text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="2" style="text-align:right" value="<?php echo $grace1 ?>"  onfocus = "this.select();"/> minutes
<br />
<br />
  
  Time zone 2 clock-in:
    <input name="clockin_hour_2_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="1" max="9" style="text-align:right" value="<?php echo $clockin_hours2 ?>" onfocus = "this.select();"/>
:
<input name="clockin_min_2_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="2" style="text-align:right" max="59" value="<?php echo $clockin_mins2 ?>" onfocus = "this.select();"/>
&nbsp; clock_out:
<input name="clockout_hour_2_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="2" max="20" style="text-align:right" value="<?php echo $clockout_hours2 ?>" onfocus = "this.select();"/>
:
<input name="clockout_min_2_text" type="text" class="text20" onkeypress="return numbersonly(this, event)" maxlength="2" max="59" style="text-align:right" value="<?php echo $clockout_mins2 ?>" onfocus = "this.select();"/>
&nbsp;&nbsp;&nbsp;&nbsp;grace time: 
<input type="text" name="grace_min2_text" id="grace_min2_text" class="text20"  onkeypress="return numbersonly(this, event)" maxlength="2" style="text-align:right" value="<?php echo $grace2 ?>"  onfocus = "this.select();"/> minutes  
<br />
<br />
Tea time / Lunch time combined:&nbsp;&nbsp; 
<input type="text" name="lunch_text" id="lunch_text" class="text20"  onkeypress="return numbersonly(this, event)" onfocus = "this.select();" maxlength="2" style="text-align:right" value="<?php echo $lunch ?>" />
minutes<br />
</div>

<div class="page_inside_frame">
      <table width="645" border="0">
        <tr>
          <td width="20"></td>
          <td width="615" align="right">
            <input name="button2" type="button" class="imagebutton" id="button2" onclick="cancel_confirmation(3, '../admin_module/user_list.php');" value="Close"/>
            <input name="save_button"  id="save_button" type="submit" class="imagebutton" value="Save" onclick="needToConfirm = false; " />
            <input name="save_close_button"  id="save_close_button" type="submit" class="imagebutton" value="Save &amp; Close" onclick="needToConfirm = false; " /></td>
        </tr>
      </table>
    </div>  
 </form>
</div> 
</div> 

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

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


</html>