<?php


session_start();
if($HTTP_SESSION_VARS['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($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");


$querysetup ="select base1, base2, if(DefaultBase=1, base1, base2) as defaultcurr from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
$rowsetup=mysql_fetch_array($resultsetup);
extract($rowsetup);

if (empty($fromdate)) $fromdate = displayToday();
if (empty($todate))   $todate   = displayToday();
$rmaType = 2;

print <<< HERE

<html xmlns="http://www.w3.org/1999/xhtml">
<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="css-v2/style.css">
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<script type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>

<script language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->
<script type="text/javascript" language="javascript">

function ClearPage() {
	window.location ='Form_RMATracking.php';
}

function PrintPrev(){
    var fromDate = document.getElementById('fromdate').value;
    var toDate = document.getElementById('todate').value;
    var item = document.getElementById('item_code').value;
    var client = document.getElementById('client_code').value;
    var ref = document.getElementById('rma_ref').value;
    var type = document.getElementById('rmaType').value;

    var str = "Rep_RMATracking.php?item="+item+"&client="+client+"&fromdate="+fromDate+"&todate="+toDate+"&ref="+ref+"&type="+type;
    window.open(str);
}

function ExcelPrev(){
    var fromDate = document.getElementById('fromdate').value;
    var toDate = document.getElementById('todate').value;
    var item = document.getElementById('item_code').value;
    var client = document.getElementById('client_code').value;
    var ref = document.getElementById('rma_ref').value;
    var type = document.getElementById('rmaType').value;

    var str = "Exp_RMATracking.php?item="+item+"&client="+client+"&fromdate="+fromDate+"&todate="+toDate+"&ref="+ref+"&type="+type;
    window.open(str);
}

function openListItems(){
	var str = "List_SorItems.php?frm=12&ItemType=All";
	window.open(str, 'mywindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');
}

function openListCustomers(){
	var str = "List_SorClient.php?frm=10";
	window.open(str, 'mywindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=990,height=600,top=60,left=100');
}

function setRMAType(value){
    document.getElementById('rmaType').value = value;
}
    
</script>
</head>
<body>
HERE;

echo "<form id='form1' name='form1' method='post' action=''>";
		
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;'margin-top=20px><span class='title'>RMA Report</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</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'>";
		
echo "          <button type='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' title='Clear'><span><span>Clear</span></span></button>";
echo "          <button type='button' id='btnPreview' name='btnPreview'  onClick=\"PrintPrev()\"; title='Preview'><span><span>Preview</span></span></button>";
echo "          <button type='button' id='btnExp' name='btnExp'  onClick=\"ExcelPrev()\"; title='Export'><span><span>Excel</span></span></button>";
	  
  
echo "	</td></tr></table>";
echo "</td></tr>";				

$date = date("d/m/Y");	

echo "<tr><td id='content-body'>
        <table border='0'  align='center' valign='top' width=100% class='tablecontent' height='250px'>
            <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";		

echo "          <input type='hidden' id='rmaType' value='$rmaType'>";
echo "          <input type='hidden' id='RMADt_Remark' value='$RMADt_Remark'>";
echo "          <input type='hidden' id='RMADt_Quantity' value='$RMADt_Quantity'>";
echo "          <table border='0' style='table-layout:fixed' align='left' valign='top'>
                    <col width=120>
                    <col width=150>
                    <col width=250>
                    <col width=80>
                    <tr>
                        <td>
                            <span class='style1'>From Date: &nbsp;<span class='style26'></span></span>
                        </td>
                        <td>
                            <input type='text' name='fromdate' id='fromdate' value='$fromdate' size='8px' /> <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>
                        </td>
                    </tr>
                    <tr>
                        <td> 
                            <span class='style1'>To Date: &nbsp;<span class='style26'></span></span>
                        </td>
                        <td>
                            <input type='text' name='todate' id='todate' value='$todate' size='8px' /> <A HREF=\"#\" onClick=\"displayCalendar(document.form1.todate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class='style1'>Item: &nbsp;<span class='style26'></span></span>
                        </td>
                        <td>
                            <input style='width:100px' type ='text' name='item_code' id='item_code'>
                        </td>
                        <td>
                            <input style='width:200px' type='text' name='item_description' id='item_description'> 
                            <img src='img/btnopen.jpg' width=20 style='cursor: pointer; vertical-align: top' onclick=\"openListItems()\" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class='style1'>Client: &nbsp;<span class='style26'></span></span>
                        </td>
                        <td>
                            <input style='width:100px' type ='text' name='client_code' id='client_code'>
                        </td>
                        <td>
                            <input style='width:200px' type='text' name='client_name' id='client_name'> 
                            <img src='img/btnopen.jpg' width=20 style='cursor: pointer; vertical-align: top' onclick=\"openListCustomers()\" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <span class='style1'>RMA Ref. &nbsp;<span class='style26'></span></span>
                        </td>
                        <td>
                            <input style='width:100px' type ='text' name='rma_ref' id='rma_ref'>
                        </td>
                        <td>
                            <span class='style1'>Return &nbsp;<span class='style26'></span></span><input type='radio' id='rma_type' name='rma_type' value='return' onclick=\"setRMAType(1)\">
                            <span class='style1'>In Process &nbsp;<span class='style26'></span></span><input type='radio' id='rma_type' name='rma_type' value='inProcess' onclick=\"setRMAType(2)\" Checked>
                        </td>
                    </tr>
                </table>";

echo "</td></tr>"; 
echo "   </table></td></tr><tr><td align='center' id='content-bottom' ></td></tr>"; 
echo "</table>
 
        </form>
    </body>
</html>";

//Return Today's Date in DD/MM/YYYY format
function displayToday(){
	return strftime("%d")."/".strftime("%m")."/".strftime("%Y");
}
	  
?>