<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Trans.php");
//include("Forms_DataGrid.php");
include("Forms_RMA_DataGrid.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");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

$query_user  = "select user_account as userAccount ".$_SESSION['dbLabel'].".login  where user_account = '".$_SESSION['useraccount']."'";
$result_user = mysql_query($query_user, $connection); 
$row_user = mysql_fetch_array($result_user);
extract($row_user);

$query_QC = "SELECT User_Name as userNames, User_account as userAccounts from ".$_SESSION['dbLabel'].".users where user_engineer='3'";
$result_QC = mysql_query($query_QC, $connection);

$rmadt_id = $_GET['rmadt_id'];
$search_rmadt_approved = $_GET['search_rmadt_approved'];
$rmadt_engrecieved = $_GET['rmadt_engrecieved'];

$query_rmadt_id = "SELECT rma_id 
                from rmadt 
                where rmadt_id = $rmadt_id";
$result_rmadt_id = mysql_query($query_rmadt_id,$connection);
$row_rmadt_id = mysql_fetch_array($result_rmadt_id);
extract($row_rmadt_id);
//echo $query_rmadt_id;

$query_isengineer  = "select ifNull(user_engineer, 0) as user_engineer from ".$_SESSION['dbLabel'].".users where User_account='".$_SESSION['useraccount']."'";
$result_isengineer = mysql_query($query_isengineer, $connection);
$row_isengineer    = mysql_fetch_array($result_isengineer);
extract($row_isengineer);

$query = "SELECT rma.client_code as ClientCode, 
                clients.ledger_name as ClientName, 
                rma.Currency_code as CurrencyCode, 
                rma.Client_Email as ClientEmail, 
                date_format(rma.rma_date, '%d/%m/%Y %H:%i:%s') as RMADate, 
                rma.Client_Tel as ClientPhone, 
                rma.Client_Cell as ClientMobile, 
                clients.Client_Address as ClientAddress,
                rma.RMA_Reference as RmaRef
        from rma left join clients on clients.ledger_number = rma.client_code
        where rma.rma_id = ".$rma_id;
//echo $query;exit;
$result_query = mysql_query($query,$connection);
$row_query = mysql_fetch_array($result_query);
extract($row_query);

$query2 = "     SELECT rmadt.item_code AS ItemCode,
                        items.Item_Description AS ItemName,
                        rmadt.RMADt_Remark AS RmaDtRemark,
                        rmadt_price AS RMADtCharge,
                        rmadt_price2 AS RMADtCharge2,
                        RMADt_Remark2 AS RMADtPickedUpBy,
                        rmadt_notes AS RmaDtNotes,
                        rmadt_received AS RmaDtReceived,
                        rmadt_problem AS RmaDtProblem,
                        rmadt_solution AS RmaDtSolution,
                        rmadt_physicalDamage AS RmaDtPhysicalDamage,
                        rmadt_DOA AS RmaDtDOA,
                        date_format(rmadt_informedon, '%d/%m/%Y') AS RmaDtInformedOn,
                        date_format(rmadt_repliedon, '%d/%m/%Y') AS RmaDtRepliedOn,
                        date_format(rmadt_backfromsrvon, '%d/%m/%Y') AS RmaDtBackFromSRVOn,
                        rmadt_servicecenter AS RmaDtServiceCenter,
                        RMADT_PROBLEMCATEGORY AS RmaDtProblemCategory,
                        Outside_Item AS OutsideItem,
                        RMADt_Quantity AS RMADtQuantity,
                        Serial_Number,
                        date_format(Invoice_Date, '%d/%m/%Y') AS Invoice_Date,
                        Invoice_Number,
                        Rmadt_Warranty,
                        rmadt_informedby AS rmadtinformedby
                FROM rmadt AS rmadt
                INNER JOIN rma AS rma ON rmadt.RMA_Id = rma.RMA_Id
                LEFT JOIN items ON items.item_code = rmadt.item_code
                WHERE rmadt.rmadt_id = '$rmadt_id'
                ";
//echo $query2;
$result_query2 = mysql_query($query2,$connection);
$row_query2 = mysql_fetch_array($result_query2);
extract($row_query2);

if(!empty($_POST['listUser_id'])){
	$listUser_id = $_POST['listUser_id'];
	//echo $listUser_id;
	$query="Update rmadt set user_onhand = '$listUser_id' where rmadt_id = '$rmadt_id'";
	//echo $query;
        $result = mysql_query($query, $connection);
        echo "<script type='text/javascript'>alert('User On Hand Changed!');</script>";
}

$query_check  = "SELECT rmadt_techquotation, 
                date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, 
                date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, 
                date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, 
                date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, 
                date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, 
                rmadt_techquotation2, 
                date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2  
                from rmadt 
                where rmadt_id = '$rmadt_id'";
$result_check = mysql_query($query_check, $connection);
$row_check    = mysql_fetch_array($result_check);
extract($row_check);
//echo $query_check;
//echo $query."\n".$query2;

$query_bypass = "SELECT bypass as bypassOpVal, bypassUser, bypassDate from rmadt where rmadt_id='$rmadt_id'";
$result_bypass = mysql_query($query_bypass, $connection);
$row_bypass    = mysql_fetch_array($result_bypass);
extract($row_bypass);

print <<<HERE
<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"> 


<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<link type="text/css" rel="stylesheet" href="js/calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>

<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>

<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />

<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

<script type="text/javascript" language="javascript">

function chkQcQpproved(v){
	document.getElementById('rmadt_qcapproved').value = v;
}

function updateQuotation(){
        var Rmadt_techquotation   = document.getElementById('Rmadt_techquotation').value;
        var operator = document.getElementById('operator').value;
        var rmadt_id = document.getElementById('rmadt_id').value;
        var start_date            = opener.document.getElementById('start_date').value;
	var end_date              = opener.document.getElementById('end_date').value;
	var start_time            = opener.document.getElementById('start_time').value;
	var end_time              = opener.document.getElementById('end_time').value;
	var start                 = opener.document.getElementById('start_par').value;
	var pagenumber            = opener.document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = opener.document.getElementById('search_rmadt_approved').value;
	var from_date             = opener.document.getElementById('from_date').value;
	var to_date               = opener.document.getElementById('to_date').value;
	var search_type           = opener.document.getElementById('search_type').value;
        var search_location       = opener.document.getElementById('search_location').value;
        var engineerchecked       = opener.document.getElementById('engineerchecked').value;
        var str = "Form_ListRMALocation_Actions.php?actionmode=updatequotation&rmadt_id="+rmadt_id+"&Rmadt_techquotation="+Rmadt_techquotation+"&user_onhand="+operator+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&engineerchecked="+engineerchecked;
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
                var data = xhttp.responseText.split('[BRK]');
                alert("Quotation added successfully!");
		document.getElementById('updates').innerHTML = data[1];
		opener.document.getElementById('list_location').innerHTML = data[2];
		}
        };
        xhttp.open("GET", str, true);
        xhttp.send();		
}

function saveStartDuration(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=savestartduration&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        if(data[1] == 0){
                                alert("You already started the process!");
                        }
                        else{
                                {/*document.getElementById('endp').style.display = 'inline-block';    
                                document.getElementById('qcselect').style.display = 'inline-block';*/}    
                                document.getElementById('list_location').innerHTML = data[0];
                                alert("Start process done successfully!");
                                document.getElementById('updates').innerHTML = data[2];
                        }
                                }
                                };
        xhttp.open("GET", str, true);
        xhttp.send();   
}

function saveStartEndDuration(){
        var rmadt_id              = document.getElementById('rmadt_id').value;
        var qcselect              = document.getElementById('qcselect').value;
        var start_date            = opener.document.getElementById('start_date').value;
	var end_date              = opener.document.getElementById('end_date').value;
	var start_time            = opener.document.getElementById('start_time').value;
	var end_time              = opener.document.getElementById('end_time').value;
	var start                 = opener.document.getElementById('start_par').value;
	var pagenumber            = opener.document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = opener.document.getElementById('search_rmadt_approved').value;
	var from_date             = opener.document.getElementById('from_date').value;
	var to_date               = opener.document.getElementById('to_date').value;
	var search_type           = opener.document.getElementById('search_type').value;
        var search_location       = opener.document.getElementById('search_location').value;
        if(document.getElementById('bypassOpVal').value == 0)
                var engineerchecked = 1;
        else
                var engineerchecked = opener.document.getElementById('engineerchecked').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=savestartendduration&rmadt_id="+rmadt_id+"&user_onhand="+qcselect+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&engineerchecked="+engineerchecked;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        if(data[1] == 0){
                                alert("Sorry, you cannot do this process!");
								
                        }
                        else{
                                
                                alert("End process done successfully!");
                                document.getElementById('updates').innerHTML = data[2];
                                opener.document.getElementById('list_location').innerHTML = data[0];
			
                        }
		}
	};
        xhttp.open("GET", str, true);
        xhttp.send();
}

function addQuotation2(){
        var rmadt_techquotation2   = document.getElementById('rmadt_techquotation2').value;
        var rmadt_id = document.getElementById('rmadt_id').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=addquotation2&rmadt_id="+rmadt_id+"&rmadt_techquotation2="+rmadt_techquotation2;
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
		     var data = xhttp.responseText.split('[BRK]');
                        if(data[0] == 0){
                                alert("First process is not done and/or the current transaction is not refused!");
                        }
                        else{
                                document.getElementById('list_location').innerHTML = data[1];
                                document.getElementById('updates').innerHTML = data[2];
								
                        }
				}
        };
        xhttp.open("GET", str, true);
        xhttp.send();
}

function startEngProcess2(){
        var rmadt_id = document.getElementById('rmadt_id').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=startengprocess2&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Quotation not added or you already started the process!");
		}
		else{
			document.getElementById('list_location').innerHTML = data[0];
			alert("Process Started successfully!");
			document.getElementById('updates').innerHTML = data[2];
			
		}
		
	}
        };
        xhttp.open("GET", str, true);
        xhttp.send();
	
}
function endEngProcess2(){
        var rmadt_id              = document.getElementById('rmadt_id').value;
        var qcselect              = document.getElementById('qcselect').value;
        var start_date            = opener.document.getElementById('start_date').value;
	var end_date              = opener.document.getElementById('end_date').value;
	var start_time            = opener.document.getElementById('start_time').value;
	var end_time              = opener.document.getElementById('end_time').value;
	var start                 = opener.document.getElementById('start_par').value;
	var pagenumber            = opener.document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = opener.document.getElementById('search_rmadt_approved').value;
	var from_date             = opener.document.getElementById('from_date').value;
	var to_date               = opener.document.getElementById('to_date').value;
	var search_type           = opener.document.getElementById('search_type').value;
        var search_location       = opener.document.getElementById('search_location').value;
        var engineerchecked       = opener.document.getElementById('engineerchecked').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=endengprocess2&rmadt_id="+rmadt_id+"&user_onhand="+qcselect+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&engineerchecked="+engineerchecked;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        if(data[1] == 0){
                                alert("Please start the process!");
                        }
                        else{
                                
                                alert("Process ended successfully!");
                                document.getElementById('updates').innerHTML = data[2];
                                opener.document.getElementById('list_location').innerHTML = data[0];
                        }
                        
                }
        };
        xhttp.open("GET", str, true);
        xhttp.send();
}

function startQcProcessOfQc(){
        
        var rmadt_id = document.getElementById('rmadt_id').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=startqcprocess&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("You already started the process!");
		}
		else{
                {/*document.getElementById('list_location').innerHTML = data[0];*/}
			alert("Started successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		}
		
	}
        };
        xhttp.open("GET", str, true);
        xhttp.send();
}

function endQcProcessOfQc(){
        var rmadt_id = document.getElementById('rmadt_id').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=endqcprocess&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Sorry, you cannot perform this process right now!");
		}
		else{
                {/*document.getElementById('list_location').innerHTML = data[0];*/}
			alert("Process Ended successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		}
		 
	}
        };
        xhttp.open("GET", str, true);
        xhttp.send();
}

function startQcProcess2(){
        var rmadt_id = document.getElementById('rmadt_id').value;
        var str = "Form_ListRMALocation_Actions.php?actionmode=startqcprocess2&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        if(data[1] == 0){
                                alert("Sorry, you cannot do this process!");
                        }
                        else{
                                document.getElementById('list_location').innerHTML = data[0];
                                alert("Started successfully!");
                                document.getElementById('labeltodisplay').innerHTML = data[2];
                        }
                }
        };
        xhttp.open("GET", str, true);
        xhttp.send();
	
}

function endQcProcess2(){
        var rmadt_id              = document.getElementById('rmadt_id').value;
        var str = "Form_ListRMALocation_Actions.php?actionmode=endqcprocess2&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        if(data[1] == 0){
                                alert("Sorry, you cannot do this process!");
                        }
                        else{
                                document.getElementById('list_location').innerHTML = data[0];
                                alert("Ended successfully!");
                                document.getElementById('labeltodisplay').innerHTML = data[2];
                        }
                }
        };
        xhttp.open("GET", str, true);
        xhttp.send();
                
}

function submitQC(){
	var rmadt_qcremark        = document.getElementById('rmadt_qcremark').value;
	var rmadt_id              = document.getElementById('rmadt_id').value;
        var rmadt_qcapproved      = document.getElementById('rmadt_qcapproved').value;
        
        var start_date            = opener.document.getElementById('start_date').value;
	var end_date              = opener.document.getElementById('end_date').value;
	var start_time            = opener.document.getElementById('start_time').value;
	var end_time              = opener.document.getElementById('end_time').value;
	var start                 = opener.document.getElementById('start_par').value;
	var pagenumber            = opener.document.getElementById('pagenumber_par').value;
	var from_date             = opener.document.getElementById('from_date').value;
	var to_date               = opener.document.getElementById('to_date').value;
	var search_type           = opener.document.getElementById('search_type').value;
        var search_location       = opener.document.getElementById('search_location').value;
        var qcchecked             = opener.document.getElementById('qcchecked').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=submitqc&rmadt_id="+rmadt_id+"&rmadt_qcremark="+rmadt_qcremark+"&rmadt_qcapproved="+rmadt_qcapproved+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&qcchecked="+qcchecked;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Sorry, QC process is not finished yet!");
		}
		else{
		
		alert("Replied Successfully!");
		opener.document.getElementById('list_location').innerHTML = data[0];
		}
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	
}

function chkRmadtApproved(reply){
        document.getElementById('rmadt_approved').value = reply;
}

function submitApproval(){
        var rmadt_id              = document.getElementById('rmadt_id').value;

        if(document.getElementById('bypassOpVal').value == 0)
                var rmadt_approved = document.getElementById('rmadt_approved').value;
        else
                var rmadt_approved = 1;

        var rmadt_operatorSpareParts = document.getElementById('rmadt_operatorSpareParts').value;
        var rmadt_operatoraditionalcomments = document.getElementById('rmadt_operatoraditionalcomments').value;

        if(document.getElementById('bypassOpVal').value == 0)
                var engineers = document.getElementById('engineers').value;
        else
                var engineers = document.getElementById('userAccount').value;

        var start_date            = opener.document.getElementById('start_date').value;
	var end_date              = opener.document.getElementById('end_date').value;
	var start_time            = opener.document.getElementById('start_time').value;
	var end_time              = opener.document.getElementById('end_time').value;
	var start                 = opener.document.getElementById('start_par').value;
	var pagenumber            = opener.document.getElementById('pagenumber_par').value;
	var from_date             = opener.document.getElementById('from_date').value;
	var to_date               = opener.document.getElementById('to_date').value;
	var search_type           = opener.document.getElementById('search_type').value;
        var search_location       = opener.document.getElementById('search_location').value;
        if(document.getElementById('bypassOpVal').value == 0)
                var operatorchecked = opener.document.getElementById('operatorchecked').value;
        else
                var operatorchecked = 1;
        
        var str = "Form_ListRMALocation_Actions.php?actionmode=submitapproval&rmadt_id="+rmadt_id+"&rmadt_approved="+rmadt_approved+"&rmadt_operatorSpareParts="+rmadt_operatorSpareParts+"&rmadt_operatoraditionalcomments="+rmadt_operatoraditionalcomments+"&user_onhand="+engineers+"&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&operatorchecked="+operatorchecked;
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        if(data[1] == 1)
                                alert("You MUST add a quotation first!");
                        else{
                                alert("Reply submitted successfully!");
                                opener.document.getElementById('list_location').innerHTML = data[0];
                        }
                }
        };
        xhttp.open("GET", str, true);
        xhttp.send();

}

function receiveRmaDt(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var rmadt_DateReceived    = document.getElementById('rmadt_DateReceived').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=receivermadt&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&search_rmadt_approved="+search_rmadt_approved+"&rmadt_DateReceived="+rmadt_DateReceived;
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        if(data[0] == 0){
                                alert("RMA should be refused by the operator or Accepted by the Quality Control!");
                        }
                        else{
                                
                                alert("Received Successfully!");
                                opener.document.getElementById('list_location').innerHTML = data[1];
                        }
                }                
        };
        xhttp.open("GET", str, true);
        xhttp.send();
	
}

function allocate(userType){
        var str = "Form_ListRMALocation_Actions.php?actionmode=showAllocators&userType="+userType;
        var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        document.getElementById('allocatortodisplay').innerHTML = data[1];
                }
        };
        xhttp.open("GET", str, true);
        xhttp.send();
}

function clear(){
        document.getElementById('updates').innerHTML = "";
}

function checkTechnicians(type){
        var rmadt_id = document.getElementById('rmadt_id').value;
        var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
        if(type=='op')
                var str = "Form_ListRMALocation_Actions.php?actionmode=checkOperator&rmadt_id="+rmadt_id+"&search_rmadt_approved="+search_rmadt_approved;
        else
                if(type=='qc')
                        var str = "Form_ListRMALocation_Actions.php?actionmode=checkQC&rmadt_id="+rmadt_id+"&search_rmadt_approved="+search_rmadt_approved;
        var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                        var data = xhttp.responseText.split('[BRK]');
                        document.getElementById('updates').innerHTML = data[1];
                }
        };
        xhttp.open("GET", str, true);
        xhttp.send();
}

function bypassOp(user){
        var rmadt_id = document.getElementById('rmadt_id').value;
        if(confirm("Are You Sure You Want To Override The Operator?")){
                document.getElementById('bypassOpVal').value = 1;
                var str="Form_ListRMALocation_Actions.php?actionmode=bypass&rmadt_id="+rmadt_id+"&recentUserAccount="+user;
                var xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                                var data = xhttp.responseText.split('[BRK]');
                                if(data[0]==0)
                                        alert("You MUST add a quotation first!");
                                else
                                        document.getElementById('updates').innerHTML = data[1];
                        }
                };
                xhttp.open("GET", str, true);
                xhttp.send();
                location.reload();
        }
}

</script>
HERE;

echo"<input type='hidden' id='userAccount' value='$userAccount'/>";
echo"<table width=100%>
        <tr style='height: 15px'>
                <td colspan=7></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>RMA Ref</td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='RmaRef' id='RmaRef' value='$RmaRef' style='width: 100px' readonly/></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Client: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='ClientCode' id='ClientCode' value='$ClientCode' style='width: 100px' readonly/></td>
                <td style='font-weight: bold; font-size: 12px; width: 100px' colspan='2'><input type='text' name='ClientName' id='ClientName' value='$ClientName' style='width: 250px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Address: </td>
                <td style='font-weight: bold; font-size: 12px;'colspan='1'><input type='text' name='ClientAddress' id='ClientAddress' value='$ClientAddress' style='width: 150px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Date: </td>
                <td style='font-weight: bold; font-size: 12px;'colspan='1'><input type='text' name='RMADate' id='RMADate' value='$RMADate' style='width: 150px' readonly/></td>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Telephone: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$ClientPhone' name='ClientPhone' id='ClientPhone' style='width: 100px' readonly/>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Mobile: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$ClientMobile' name='ClientMobile' id='ClientMobile' style='width: 116px' readonly/>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Email: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$ClientEmail' name='ClientEmail' id='ClientEmail' style='width: 100px' readonly/>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Item: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='ItemCode' id='ClieItemCodentCode' value='$ItemCode' style='width: 100px' readonly/></td>
                <td style='font-weight: bold; font-size: 12px; width: 100px' colspan='2'><input type='text' name='ItemName' id='ItemName' value='$ItemName' style='width: 250px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Quantity: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$RMADtQuantity' name='RMADtQuantity' id='RMADtQuantity' style='width: 100px' readonly/>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Serial Nb.: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$Serial_Number' name='Serial_Number' id='Serial_Number' style='width: 100px' readonly/>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Remark: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px' colspan='3'><input type='text' name='RmaDtRemark' id='RmaDtRemark' value='$RmaDtRemark' style='width: 354px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Charge: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$RMADtCharge' name='RMADtCharge' id='RMADtCharge' style='width: 100px' readonly/>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Cost: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$RMADtCharge2' name='RMADtCharge2' id='RMADtCharge2' style='width: 100px' readonly/>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Invoice Number: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$Invoice_Number' name='Invoice_Number' id='Invoice_Number' style='width: 100px' readonly/>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Invoice Date: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$Invoice_Date' name='Invoice_Date' id='Invoice_Date' style='width: 116px' readonly/>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 140px'>Outside Item: <input type='checkbox' value='$OutsideItem' name='OutsideItem' id='OutsideItem'";if($OutsideItem==1) echo"Checked"; echo"/>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Warranty: <input type='checkbox' value='$Rmadt_Warranty' name='Rmadt_Warranty' id='Rmadt_Warranty'";if($Rmadt_Warranty==1) echo"Checked"; echo"/>
                <td style='font-weight: bold; font-size: 12px; width: 140px'>Physical Damage: <input type='checkbox' value='$RmaDtPhysicalDamage' name='RmaDtPhysicalDamage' id='RmaDtPhysicalDamage'";if($RmaDtPhysicalDamage==1) echo"Checked"; echo"/>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>DOA: <input type='checkbox' value='$RmaDtDOA' name='RmaDtDOA' id='RmaDtDOA'";if($RmaDtDOA==1) echo"Checked"; echo"/>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Notes: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px' colspan='3'><input type='text' name='RmaDtNotes' id='RmaDtNotes' value='$RmaDtNotes' style='width: 354px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Picked By: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$RMADtPickedUpBy' name='RMADtPickedUpBy' id='RMADtPickedUpBy' style='width: 100px' readonly/>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Recieved: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' value='$RmaDtReceived' name='RmaDtReceived' id='RmaDtReceived' style='width: 100px' readonly/>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Problem: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px' colspan='3'><input type='text' name='RmaDtProblem' id='RmaDtProblem' value='$RmaDtProblem' style='width: 354px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Solution: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px' colspan='3'><input type='text' name='RmaDtSolution' id='RmaDtSolution' value='$RmaDtSolution' style='width: 354px' readonly/></td>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Informed By: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='rmadtinformedby' id='rmadtinformedby' value='$rmadtinformedby' style='width: 100px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Informed on: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='rmadtinformedOn' id='rmadtinformedOn' value='$rmadtinformedOn' style='width: 116px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Replied on: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='RmaDtRepliedOn' id='RmaDtRepliedOn' value='$RmaDtRepliedOn' style='width: 100px' readonly/></td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Back from srv on: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='RmaDtBackFromSRVOn' id='RmaDtBackFromSRVOn' value='$RmaDtBackFromSRVOn' style='width: 100px' readonly/></td>
        </tr>
        <tr>
                <td></td>
        </tr>
        <tr>
                <td style='font-weight: bold; font-size: 12px; width: 100px'>Service Center: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='RmaDtServiceCenter' id='RmaDtServiceCenter' value='$RmaDtServiceCenter' style='width: 100px' readonly/></td>
                <td align='center' style='font-weight: bold; font-size: 12px; width: 100px'>Problem Category: </td>
                <td style='font-weight: bold; font-size: 12px; width: 100px'><input type='text' name='RmaDtProblemCategory' id='RmaDtProblemCategory' value='$RmaDtProblemCategory' style='width: 116px' readonly/></td>
        </tr>
        <tr>
                <td></td>
        </tr>
</table>";
/*
if($rmadt_engrecieved==1){
        if($search_rmadt_approved==0)
                echo "Quotation<input type='text' name='Rmadt_techquotation' id='Rmadt_techquotation' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"updateQuotation($rmadt_id)\"><span><span>Add Quotation</span></span></button><br>
                        <div id='ops'></div>";
                                
        else
                if($search_rmadt_approved==1)
                        echo "<button onclick=\"startQcProcess($rmadt_id)\"><span><span>Start Process</span></span></button> <button onclick=\"endQcProcess($rmadt_id)\"><span><span>End Process</span></span></button>";
                else
                        if($search_rmadt_approved==2)
                        echo "Quotation <input type='text' name='rmadt_techquotation2' id='rmadt_techquotation2' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"addQuotation2($rmadt_id)\"><span><span>Add Quotation</span></span></button><br>
                                <div style='height: 15px'></div>
                                <button onclick=\"startEngProcess2($rmadt_id)\"><span><span>Start Process 2</span></span></button> <button onclick=\"endEngProcess2($rmadt_id)\"><span><span>End Process 2</span></span></button>";
}
echo "Operator<input type='radio' name='allocate' value='operator' onclick=\"checkTechnicians('op')\"> QC<input type='radio' name='allocate' value='qualityControl' onclick=\"checkTechnicians('qc')\">";
echo "<div id='allocatortodisplay'></div>";
echo "<div id='labeltodisplay'></div>";
echo "<div id='list_location'></div>";
*/

echo "<table width=50%>
        <tr style='height: 15px'>
                <td colspan=7></td>
        </tr>
        <tr>";
echo "<input type='hidden' id='rmadt_id' value='$rmadt_id'/>";
echo "<input type='hidden' id='search_rmadt_approved' value='$search_rmadt_approved'/>";
echo "<input type='hidden' id='bypassOpVal' value='$bypassOpVal'/>";
//echo $rmadt_qcrecieved;
if($user_engineer==1){
        if($rmadt_engrecieved==1){
                if($search_rmadt_approved==0){
                        $query_operator = "SELECT User_Name as userName, User_account as userAccount from ".$_SESSION['dbLabel'].".users where user_engineer='2'";
                        $result_operator = mysql_query($query_operator, $connection);
                        //echo $query_operator;
                        echo "<fieldset>
                                                <legend>Quotation Process 1</legend>
                                                <select name='operator' id='operator' style='width: 200px; height: 25px;'>";
                        while($row_operator = mysql_fetch_array($result_operator)){
                                extract($row_operator);
                                echo "<option value='$userAccount'>$userName</option>";
                        }
                        echo "</select>
                                Quotation <input type='text' name='Rmadt_techquotation' id='Rmadt_techquotation' value='$rmadt_techquotation' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"updateQuotation()\"><span><span>Add Quotation</span></span></button><br><br>";
                        echo "<div id='bypdiv'>";
                        if($bypassOpVal==0)
                                echo "<button onclick=\"bypassOp('$userAccount')\"><span><span>Bypass Operator</span></span></button>";
                        else {
                                $query_engineers  = "select User_Name as opUserName, User_account as opUserAccount from ".$_SESSION['dbLabel'].".users where user_engineer = 1";
                                //echo $query_engineers;
                                $result_engineers = mysql_query($query_engineers, $connection);
                                echo "&nbsp;Engineer: &nbsp;<select name='engineers' id='engineers'>";
                                while($row_engineers = mysql_fetch_array($result_engineers)){
                                        extract($row_engineers);
                                        echo "<option value='$opUserAccount'>$opUserName</option>";
                                }
                                echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                                echo "Spare Parts <input type='text' name='rmadt_operatorSpareParts' id='rmadt_operatorSpareParts' style='width: 380px' maxlength=200 /> <br>";
                                echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        Additional Comments <input type='text' name='rmadt_operatoraditionalcomments' id='rmadt_operatoraditionalcomments' style='width: 380px;'/>";
                                echo "<button onclick=\"submitApproval()\"><span><span>Submit</span></span></button>";
                                echo "<br><button onclick=\"saveStartDuration()\"><span><span>Start Process</span></span></button> <button id='endp' onclick=\"saveStartEndDuration()\"><span><span>End Process</span></span></button></span>
                                <select id='qcselect'>";
                                while($row_QC = mysql_fetch_array($result_QC)){
                                        extract($row_QC);
                                        echo "<option value='$userAccounts'>$userNames</option>";
                                }
                                echo "</select>";
                        }
                        echo "</div>";
                        echo "</fieldset>";


                        /*echo "<td align='center' style='font-weight: bold; font-size: 12px; width: 30px'>Operator<input type='radio' name='allocate' value='operator' onclick=\"checkTechnicians('op')\"></td>
                                <td align='center' style='font-weight: bold; font-size: 12px; width: 30px'><button id='clear' onclick=\"clear()\"><span><span>Clear</span></span></button></td>
                                <!--<td style='font-weight: bold; font-size: 12px; width: 30px'>QC<input type='radio' name='allocate' value='qualityControl' onclick=\"checkTechnicians('qc')\"></td>-->";
                        */
                }
                if($search_rmadt_approved==1){
                        /*echo "<td align='center' style='font-weight: bold; font-size: 12px; width: 30px'>Operator<input type='radio' name='allocate' value='operator' onclick=\"checkTechnicians('op')\"></td>
                                <td align='center' style='font-weight: bold; font-size: 12px; width: 30px'><button id='clear' onclick=\"clear()\"><span><span>Clear</span></span></button></td>        ";*/

                        $query_operator = "SELECT User_Name as userName, User_account as userAccount from ".$_SESSION['dbLabel'].".users where user_engineer='2'";
                        $result_operator = mysql_query($query_operator, $connection);
                        //echo $query_operator;
                        echo "<fieldset>
                                <legend>Quotation Process 1</legend>
                                <select name='operator' id='operator' style='width: 200px; height: 25px;'>";
                        while($row_operator = mysql_fetch_array($result_operator)){
                                extract($row_operator);
                                echo "<option value='$userAccount'>$userName</option>";
                        }
                        echo "</select>
                                Quotation <input type='text' name='Rmadt_techquotation' id='Rmadt_techquotation' value='$rmadt_techquotation' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"updateQuotation()\"><span><span>Add Quotation</span></span></button><br>";                                
                        echo "<br><button onclick=\"saveStartDuration()\"><span><span>Start Process</span></span></button> <button id='endp' onclick=\"saveStartEndDuration()\"><span><span>End Process</span></span></button></span>
                                <select id='qcselect'>";
                        while($row_QC = mysql_fetch_array($result_QC)){
                                extract($row_QC);
                                echo "<option value='$userAccounts'>$userNames</option>";
                        }
                        echo "</select>
                                </fieldset>";
                }
                if($search_rmadt_approved==2){
                        echo "<fieldset>
                                <legend>2nd Process</legend>
                                Quotation <input type='text' name='rmadt_techquotation2' id='rmadt_techquotation2' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"addQuotation2()\"><span><span>Add Quotation</span></span></button><br>
                                <br><button onclick=\"startEngProcess2()\"><span><span>Start Process 2</span></span></button> <button onclick=\"endEngProcess2()\"><span><span>End Process 2</span></span></button>";
                                echo "<select id='qcselect'>";
                                while($row_QC = mysql_fetch_array($result_QC)){
                                        extract($row_QC);
                                        echo "<option value='$userAccounts'>$userNames</option>";
                                }
                                echo "</select>
                                        </fieldset>";
                }
                
                echo "<div id='list_location'></div>"; 
                echo "<div id='updates'><table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
                                </tr>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
                                </tr>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
                                </tr>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
                                </tr>
                        </table></div>";       
        }
        /*else {
                if($search_rmadt_approved==2){
                        echo "<td align='center' style='font-weight: bold; font-size: 12px; width: 30px'>Clear<input type=button' id='clear' onclick=\"clear()\"></td>
                                        Quotation <input type='text' name='rmadt_techquotation2' id='rmadt_techquotation2' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"addQuotation2()\"><span><span>Add Quotation</span></span></button><br>
                                        <button onclick=\"startEngProcess2()\"><span><span>Start Process 2</span></span></button> <button onclick=\"endEngProcess2()\"><span><span>End Process 2</span></span></button>";
                        echo "<select>";
                        while($row_QC = mysql_fetch_array($result_QC)){
                                extract($row_QC);
                                echo "<option value='$userAccounts'>$userNames</option>";
                        }
                        echo "</select></td>";
                        echo "</table>";
                        echo "<div id='list_location'></div>"; 
                        echo "<div id='updates'></div>";      
                }
        }*/
}else if($user_engineer==3){
        if($rmadt_qcrecieved==1){
                echo "<fieldset style='width: 88%; margin: auto; font-size: 12px; font-weight: bold'>
                        <legend style='font-size: 14px; font-weight: bold'>Duration and Remarks</legend>
                        <button onclick=\"startQcProcessOfQc()\"><span><span>Start Process</span></span></button> <button onclick=\"endQcProcessOfQc()\"><span><span>End Process</span></span></button>
                        &nbsp;
                        <button onclick=\"startQcProcess2()\"><span><span>Start Process 2</span></span></button> <button onclick=\"endQcProcess2()\"><span><span>End Process 2</span></span></button>
                        <input type='hidden' name='rmadt_qcduration' id='rmadt_qcduration' style='width: 75px' /> <br><br>
                        <input type='hidden' name='rmadt_qcapproved' id='rmadt_qcapproved' value='' />
                        <input type='radio' name='chk_rmadt_qcapproved' id='chk_rmadt_qcapproved' onclick=\"chkQcQpproved(1)\"> Approve 
                        <input type='radio' name='chk_rmadt_qcapproved' id='chk_rmadt_qcrefuse' onclick=\"chkQcQpproved(0)\"> Refuse 
                        <input type='radio' name='chk_rmadt_qcapproved' id='chk_rmadt_qcnone' onclick=\"chkQcQpproved('')\"> None
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <input type='text' name='rmadt_qcremark' id='rmadt_qcremark' style='width: 656px' /> 
                        <button onclick=\"submitQC()\"><span><span>Submit</span></span></button>
                        </fieldset>";
                echo "<div id='list_location'></div>";
                echo "<div id='labeltodisplay'></div>";  
        }
}else if($user_engineer == 2){
	$query_engineers  = "select User_Name as userName, User_account as userAccount from ".$_SESSION['dbLabel'].".users where user_engineer = 1";
	//echo $query_engineers;
        $result_engineers = mysql_query($query_engineers, $connection);

        $query_approved = "SELECT rmadt_approved as ApprovalStatus from rmadt where rmadt_id='$rmadt_id'";
        $result_approved = mysql_query($query_approved, $connection);
        $row_approved = mysql_fetch_array($result_approved);
        extract($row_approved);
        
        $query_sparencomments = "SELECT rmadt_operatorSpareParts as spareParts, rmadt_operatoraditionalcomments as opComments from rmadt where rmadt_id = '$rmadt_id'";
        $result_sparencomments = mysql_query($query_sparencomments, $connection);
        $row_sparencomments = mysql_fetch_array($result_sparencomments);
        extract($row_sparencomments);
        echo "<fieldset style='width: 88%; margin: auto; font-size: 12px; font-weight: bold'>
                <legend style='font-size: 14px; font-weight: bold'>Spare Parts & Status Reply</legend>";
        if($ApprovalStatus == ''){
                echo "<input type='hidden' id='rmadt_approved' name='rmadt_approved' value='0' />
                <input type='radio' name='chk_rmadt_approved' id='chk_rmadt_approved' onclick=\"chkRmadtApproved('1')\" /> Approve&nbsp;&nbsp;<input type='radio' name='chk_rmadt_approved' id='chk_rmadt_refused' onclick=\"chkRmadtApproved('0')\" /> Refuse&nbsp;&nbsp;<input type='radio' name='chk_rmadt_approved' id='chk_rmadt_pending' onclick=\"chkRmadtApproved('')\" /> Waiting for reply&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        }
        echo "Spare Parts <input type='text' name='rmadt_operatorSpareParts' id='rmadt_operatorSpareParts' value='$spareParts' style='width: 380px' maxlength=200 ";if($ApprovalStatus != '') echo "readonly"; echo "/> <br>";
        if($ApprovalStatus == ''){
                echo "&nbsp;Engineer: &nbsp;<select name='engineers' id='engineers'>";
                while($row_engineers = mysql_fetch_array($result_engineers)){
                        extract($row_engineers);
                        echo "<option value='$userAccount'>$userName</option>";
                }
                echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        }
        echo "Additional Comments <input type='text' name='rmadt_operatoraditionalcomments' id='rmadt_operatoraditionalcomments' value='$opComments' style='width: 380px;' ";if($ApprovalStatus != '') echo "readonly"; echo "/>";
        if($ApprovalStatus == ''){        
                echo "<button onclick=\"submitApproval()\"><span><span>Submit</span></span></button>
                <div style='height: 10px;'></div>
                Received Date <input type='text' name='rmadt_DateReceived' id='rmadt_DateReceived' value='$date' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('rmadt_DateReceived'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A> <button onclick=\"receiveRmaDt()\"><span><span>Receive</span></span></button>
                ";
        }
        echo "</fieldset>";       
        echo "<div style='height: 15px'></div>";
        echo "<div id='list_location'></div>";
        echo "<div id='labeltodisplay'><table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
                                </tr>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
                                </tr>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
                                </tr>
                                <tr>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
                                <td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
                                <td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
                                </tr>
                        </table>
                </div>";        
}
?>