<?php
session_start();
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");

$actionmode = $_GET['actionmode'];
$rma_id = $_GET['rma_id'];
$reference = $_GET['reference'];
$date = $_GET['date'];
$client_code = $_GET['client_code'];
$start = $_GET['start'];
$pagenumber = $_GET['pagenumber'];

if($actionmode == "showrmadt"){
	drawRMADtSearch($connection, $rma_id);
	echo "[BRK]";
}
else
	if($actionmode == "movenext"){
		$query_access  = "select FI_RMA, FI_RMAApp, FI_RMAMod, FI_RMADel from ".$_SESSION['dbLabel'].".login";
        $result_access = mysql_query($query_access, $connection);
        $row_access    = mysql_fetch_array($result_access);
        extract($row_access);
		drawListRMA($connection, $FI_RMA, $FI_RMAApp, $FI_RMAMod, $FI_RMADel, $reference, $date, $client_code, $start, $pagenumber);
		echo "[BRK]";
	}
	else
	if($actionmode == "moveprev"){
		$query_access  = "select FI_RMA, FI_RMAApp, FI_RMAMod, FI_RMADel from ".$_SESSION['dbLabel'].".login";
        $result_access = mysql_query($query_access, $connection);
        $row_access    = mysql_fetch_array($result_access);
        extract($row_access);
		drawListRMA($connection, $FI_RMA, $FI_RMAApp, $FI_RMAMod, $FI_RMADel, $reference, $date, $client_code, $start, $pagenumber);
		echo "[BRK]";
	}
	else
		if($actionmode == "searchrma"){
			$query_access  = "select FI_RMA, FI_RMAApp, FI_RMAMod, FI_RMADel from ".$_SESSION['dbLabel'].".login";
            $result_access = mysql_query($query_access, $connection);
            $row_access    = mysql_fetch_array($result_access);
            extract($row_access);
			drawListRMA($connection, $FI_RMA, $FI_RMAApp, $FI_RMAMod, $FI_RMADel, $reference, $date, $client_code, $start, $pagenumber);
		    echo "[BRK]";
		}
		else
			if($actionmode == "deleterma"){
				$query_adjustment   = "select adjustment_id from rma where rma_id = '$rma_id'";
				$result_adjustment  = mysql_query($query_adjustment, $connection);
				$row_adjustment     = mysql_fetch_array($result_adjustment);
				extract($row_adjustment);
				$query_deleteadjustment  = "delete from adjustment where adjustment_id = '$adjustment_id'";
				$result_deleteadjustment = mysql_query($query_deleteadjustment, $connection); 
				$query_deleterma    = "delete from rma where rma_id = '$rma_id'";
				$query_deletermadt  = "delete from rmadt where rma_id = '$rma_id'";
				$result_deleterma   = mysql_query($query_deleterma, $connection);
				$result_deletermadt = mysql_query($query_deletermadt, $connection);
				$query_access  = "select FI_RMA, FI_RMAApp, FI_RMAMod, FI_RMADel from ".$_SESSION['dbLabel'].".login";
            $result_access = mysql_query($query_access, $connection);
            $row_access    = mysql_fetch_array($result_access);
            extract($row_access);
				drawListRMA($connection, $FI_RMA, $FI_RMAApp, $FI_RMAMod, $FI_RMADel, $reference, $date, $client_code, $start, $pagenumber);
		        echo "[BRK]";
			}
?>