<?php
 
session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");


$querylog="SELECT U_RePostTransaction as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

$querymodule="SELECT ifnull(module_delivery,0) as module_delivery from module ";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowsmod=mysql_fetch_array($resultmodule)){
	extract($rowsmod);
}

if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");


$transtype  = $_POST["transtype"]; 	if ($transtype == ""){$transtype = $_GET["transtype"];}   
$adjustcost = $_POST["adjustcost"]; if ($adjustcost == ""){$adjustcost = $_GET["adjustcost"];}   
$fromdate 	= $_POST["fromdate"]; 	if ($fromdate == ""){$fromdate = $_GET["fromdate"];}   
$todate 	= $_POST["todate"]; 	if ($todate == ""){$todate = $_GET["todate"];}   
$fromref   	= $_POST["fromref"]; 	if ($fromref == ""){$fromref = $_GET["fromref"];}   
$toref  	= $_POST["toref"]; 		if ($toref == ""){$toref = $_GET["toref"];}   


// Setting Initial Values For Parameters
$querydate = " Select Date_Format(StartFinancialDate,'%d/%m/%Y') As StartFinancialDate, Date_Format(EndFinancialDate,'%d/%m/%Y') As EndFinancialDate ".
			 " From ".$_SESSION['dbLabel'].".Directories ". 
			 " Where Upper(Concat(CompanyName, '_', DirYear)) = Upper('".$_SESSION['dbName']."') ";
$resultdate=mysql_query($querydate,$connection) or die(mysql_error());
$rowdate=mysql_fetch_row($resultdate);

if (!isset($fromdate))  $fromdate = $rowdate[0];
if (!isset($todate))    $todate   = $rowdate[1];

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

<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>


<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20101112" media="screen"></link>
<script type="text/javascript" src="dhtmlgoodies_calendar.js?random=20100118"></script>


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" language="javascript">


function RepostTrans() {
	var x=document.form1;

	var vFromDate  = x.fromdate.value;
	var vToDate    = x.todate.value;
	var vFromRef   = x.fromref.value;
	var vToRef     = x.toref.value;
	var vTransType = x.transtype.value;
	
	var vAdjustCost = 0;
	if (x.adjustcost.checked) vAdjustCost = 1;
	
		
	if (confirm("Are you sure you want to Repost Transactions?")) {

		if (document.getElementById('btnRepost')) x.btnRepost.disabled = true;
		document.getElementById("imgDiv").style.display="block";
		
		x.action =  "Form_RepostTransactions_Actions.php?fromdate="+vFromDate+"&todate="+vToDate+"&fromref="+vFromRef+"&toref="+vToRef+"&adjustcost="+vAdjustCost+"&transtype="+vTransType;
		x.submit();		
		
	}

}

function clearTrans(){
	var x=document.form1;
	x.transtype.value 	= '';
	x.fromdate.value 	= '';
	x.todate.value 		= '';
	x.fromref.value 	= '';
	x.toref.value 		= '';
	x.adjustcost.value  = '0';
	x.message.value 	= '';
	x.action = 'Form_RepostTransactions.php';
	x.submit();
}
</script>
<title>Repost Transactions</title>
<style type="text/css">


.style5 {color: #5151FF; font-size: 10px;}


div#imgDiv {
	font-size: 12px; 
    font-weight:bold; 
	color: #FF0000 ;
	text-align: center; 
	margin-top:10px;
	display:none;
}
</style>

</head>
<body>
<form id='form1' name='form1' method='post' action=''>
<input type='hidden' name='actionmode' value='$actionmode'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='message' value='$message' size='200'>

HERE;


echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";


echo" <tr style='height:26px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>REPOST TRANSACTIONS</span></td>
				<td valign='middle' style='height:26px;'>&nbsp;</td>
			</tr></table>
		</td>
	  </tr>";

echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'><span class='message'>".htmlspecialchars($message, ENT_QUOTES)."</span></td>";
echo"		</tr></table>";
echo"</td></tr>";


echo"<tr><td id='content-body'>
	<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
	<tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>
		<table border='0' style='table-layout:fixed'>
		  <col width=60>
		  <col width=130>
		  <col width=60>
		  <col width=130>
		  <col width=250>";	

echo" <tr height='30'>";	  
echo"   <td colspan='3' align='left'><span class='style1'>Transaction
			<select name='transtype' id='transtype' style='width:150px;'>";
echo"			<option value='PI' "; if($transtype=='PI') echo" selected ";  echo" >Purchases</option>";
echo"			<option value='PR' "; if($transtype=='PR') echo" selected ";  echo" >Return Purchases</option>";
if($module_delivery == 0){
echo"			<option value='DI' "; if($transtype=='DI') echo" selected ";  echo" >Sales</option>";
echo"			<option value='DR'"; if($transtype=='DR' ) echo" selected ";  echo" >Return Sales</option>";
} else if($module_delivery == 1){
echo"			<option value='DI' "; if($transtype=='DI') echo" selected ";  echo" >Delivery</option>";
echo"			<option value='DR'"; if($transtype=='DR' ) echo" selected ";  echo" >Return Delivery</option>";

echo"			<option value='SI' "; if($transtype=='SI') echo" selected ";  echo" >Sales</option>";
echo"			<option value='SR'"; if($transtype=='SR' ) echo" selected ";  echo" >Return Sales</option>";
}  
echo"			<option value='SO' "; if($transtype=='SO') echo" selected ";  echo" >Sales Order</option>";
echo"			<option value='AI' "; if($transtype=='AI') echo" selected ";  echo" >Stock IN</option>";
echo"			<option value='AR' "; if($transtype=='AR') echo" selected ";  echo" >Stock OUT</option>";
echo"			<option value='AD' "; if($transtype=='AD') echo" selected ";  echo" >Adjustment</option>";
echo"			<option value='PD' "; if($transtype=='PD') echo" selected ";  echo" >Production</option>";
echo"			<option value='TR' "; if($transtype=='TR') echo" selected ";  echo" >Transfer Request</option>";
echo"	</select></span></td>";
echo"   <td colspan='2' align='left'>&nbsp;</td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td height='19' colspan='2' align='left'><span class='style1'>Date</span></td>";
echo"   <td height='19' colspan='2' align='left'><span class='style1'>Reference</span></td>";
echo"   <td height='19' align='left'>&nbsp;</td>";
echo" </tr>";

echo" <tr>";
echo"   <td valign='top'><span class='style1'>From</span></td>";
echo"   <td valign='top'><span class='style1'><input type='text' name='fromdate' id='fromdate' value='$fromdate' maxlength='10' style='width:80px;'>
			<a href='#' onClick=\"displayCalendar(document.form1.fromdate,'dd/mm/yyyy',this); return false; \" name='anchor1' id='anchor1'><image src='./img/cal.gif' border=0 align=center></image></a></span></td>
		</span></td>";
echo"   <td valign='top'><span class='style1'>From</span></td>";
echo"   <td valign='top'><span class='style1'><input type='text' name='fromref' id='fromref' value='$fromref' style='width:100px;'></span></td>";
echo"   <td valign='top' rowspan='2'><span class='style1'>";
echo"		<label><input type='checkbox' name='adjustcost' id='adjustcost' value='1'"; if($adjustcost==1) echo " checked "; echo">Adjust Cost</label><br>";
echo"	</span></td>";
echo" </tr>";

echo" <tr>";
echo"   <td valign='top'><span class='style1'>To</span></td>";
echo"   <td valign='top'><span class='style1'><input type='text' name='todate' id='todate' value='$todate' maxlength='10' style='width:80px;'>
			<a HREF=\"#\" onClick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor2\" ID=\"anchor2\"><image src='./img/cal.gif' border=0 align=center></image></a>
		</span></td>";
echo"   <td valign='top'><span class='style1'>To</span></td>";
echo"   <td valign='top'><span class='style1'><input type='text' name='toref' id='toref' value='$toref' style='width:100px;'></span></td>";
echo" </tr>";

echo" <tr height='30'>";
echo"   <td colspan='5' align='center' valign='middle' >";
echo "		<div id='imgDiv'><p><image src='img/ajax-loader.gif' id='loader-img' /></p></div>";
echo"	</td>";
echo" </tr>";
echo" <tr height='60'>";	  
echo"   <td colspan='5' align='center'>";
echo" 		<button type='button' id='btnRepost' name='btnRepost' onclick=\"RepostTrans();return false;\" title='Repost Transactions'><span><span>Repost</span></span></button>";
echo" 		<button type='button' id='btnClear' name='btnClear' onclick=\"clearTrans();return false;\" title='Clear Page'><span><span>Clear</span></span></button>";
echo"	</td>";
echo" </tr>";


echo"   </table></td></tr>"; 
echo"</table></td></tr>"; 



echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
echo" </table>  ";//end of last table menu



echo"  
</form>
</body>
</html>";

?>