<?php
    include ("../config/head.php");
    include ("../auth.php");
?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DNA Module - Edit Orders</title>
<link rel="stylesheet" type="text/css" href="../format.css">
<link rel="stylesheet" type="text/css" href="../input/XSLT/Styles.css">
<SCRIPT LANGUAGE="JavaScript1.1" src="../Functions.js"></SCRIPT>
<NOSCRIPT>Please enable Javascript!</NOSCRIPT>

</head>
<body>
<form name="formular" method="POST" action="edit_requests.php"> 
<table border="0">
<?php if (isset($_SESSION['guest']) || $_SESSION['guest'] || isset($_SESSION['project']) || $_SESSION['project']) {

echo "<tr><td><span class='error'>Sorry, you don't have permission for this site! If you want to search for existing DNA data please use the Search function!</span></td></tr>"; }

else { ?>
<tr><td>

<?php
//    include("date.php");
    $tr = "=";
    $no = "!=";
    $lk = "like";
    $bt = ">=";
    $st = "<=";
    $parr = $_GET;

    array($parr);
    foreach ($parr as $var)
    {
        $i ++;
        if(!empty($var) and $var!="dd.mm.yyyy" and $var!="Check Data" and $var!="Action")
        {
            switch (key($parr))
            {
                case 'Customer':
                    $str = "request.ID_People ".$tr."'".$var."' AND "; 
                    break;
                case 'formDnaBankNumber':
                    $str = "dnabanknumbers.Dna_Bank_Number ".$tr."'".$var."' AND ";
                    break;
                case 'formOrderDateFrom':
                    if ($OrderDateFrom!="") {
                    $str = "request.Request_Date ".$bt."'".$OrderDateFrom."' AND "; 
                    }
                    break;
                case 'formOrderDateTo':
                    if ($OrderDateTo!="") {
                    $str = "request.Request_Date ".$st."'".$OrderDateTo."' AND "; 
                    }
                    break;
                case 'formShippingDateFrom':
                    if ($ShippingDateFrom!="") {
                    $str = "request.Shipping_Date ".$bt."'".$ShippingDateFrom."' AND "; 
                    }
                    break;
                case 'formShippingDateTo':
                    if ($ShippingDateTo!="") {
                    $str = "request.Shipping_Date ".$st."'".$ShippingDateTo."' AND "; 
                    }
                    break;                    
                case 'Status':
                    if($Status=="order") {
                    $str = "(aliquots.Shipping_Partial ".$no."'YES' AND ";
                    $str .=  "aliquots.Shipping_All ".$no."'YES') AND ";}
                    if($Status=="shipping") {
                    $str = "(aliquots.Shipping_Partial ".$tr."'YES' OR "; 
                    $str .= "aliquots.Shipping_All ".$tr."'YES') AND "; }
                    if($Status=="all") {
                    $str = "(aliquots.Shipping_Partial ".$tr."'YES' OR "; 
                    $str .= "aliquots.Shipping_All ".$tr."'YES' OR "; 
                    $str .= "aliquots.Order_Partial ".$tr."'YES' OR ";
                    $str .= "aliquots.Order_All ".$tr."'YES') AND ";}
                    break;
            }           
            $where[$i] = $str;
        }
        next($parr);
    }
    
    if(empty($str))
    {  echo "<table  border='0' id='tablesearch'><tr><td><b>No search key entered.</b></td></tr>";
    echo "<tr><td><a class='red' href='edit_requests.php'>New Search.</a></td></tr></table>"; }
    else {


    foreach($where AS $a) $string .= $a;

        $l=strlen ($string);
        $max = $l-4;
        $where_str = substr($string, 0, $max);
        $wherestr = " WHERE " . $where_str . " AND request.Agreement = 'Yes'";
        
     
            //abfrage
            
            $result = "SELECT request.ID_Request, " .
                   "request.ID_Aliquots, " .
                   "dnabanknumbers.Dna_Bank_Number, " .
                   "request.Request_Number_Aliquots, " .
                   "request.Shipping_All, " .
                   "request.Shipping_Partial, " .
                   "request.Shipping_Rest, " .
                   "request.Order_All, " .
                   "request.Order_Partial, " .
                   "request.Order_Rest, " .
                   "request.Agreement, " .
                   "aliquots.Aliquot_Barcode, " .
                   "aliquots.Aliquot_Position, " .
                   "aliquots_box.Aliquots_Box, " .
                   "aliquots_rack.Aliquots_Rack, " .
                   "aliquots_fridge.Aliquots_Fridge, " .
                   "request.Request_Date, " .
                   "request.Request_Volume, " .
                   "request.Request_Notes, " .
                   "request.Shipping_Date, " .
                   "request.Price, " .
                   "request.Created_When, " .
                   "request.Created_Who, " .
                   "people.Name_All " .
                   "FROM request
                   LEFT JOIN aliquots ON request.ID_Aliquots = aliquots.ID_Aliquots 
                   LEFT JOIN dnabanknumbers ON request.ID_DNA = dnabanknumbers.ID_DNA
                   LEFT JOIN aliquots_box ON aliquots.ID_Aliquots_Box = aliquots_box.ID_Aliquots_Box
                   LEFT JOIN aliquots_rack ON aliquots.ID_Aliquots_Rack = aliquots_rack.ID_Aliquots_Rack
                   LEFT JOIN aliquots_fridge ON aliquots.ID_Aliquots_Fridge = aliquots_fridge.ID_Aliquots_Fridge
                   LEFT JOIN people ON request.ID_People = people.ID_People " .
                   $wherestr.$sqllimit;      

   $sql = mysqli_query($GLOBALS["___mysqli_ston"], $result) or die($result.'<br>'.((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));

$gesamt = mysqli_num_rows($sql);
if(!mysqli_num_rows($sql))
{ echo "<b>No hits found.</b>"; }
else {

echo "<i>Liste zeigt nur Aliquots, zu denen ein Material Transfer Agreement existiert!</i>";
//NORMAL
echo "<table width='100%' border='0'><th>Customer</th><th>DNA Extraction No</th><th>Aliquot No</th><th>Shipping volume</th><th>Fridge</th><th>Rack</th><th>Box</th><th>Order Date</th><th>Notes</th>";

//ZSM MÜNCHEN
//echo "<table width='100%' border='0'><th>Customer</th><th>DNA Extraction No</th><th>Position</th><th>Aliquot No</th><th>Barcode</th><th>Shipping volume</th><th>Fridge</th><th>Drawer</th><th>Rack</th><th>Order Date</th><th>Notes</th>";
 
for ($i=1; $i<=$gesamt; $i++) {
$row=mysqli_fetch_array($sql);
      
  $Name_All = $row['Name_All'];
  $DnaBankNumber = $row['Dna_Bank_Number'];
  $Aliquot_Number = $row['Request_Number_Aliquots'];
  $Request_Volume = $row['Request_Volume'];
  $Box = $row['Aliquots_Box'];
  $Rack = $row['Aliquots_Rack'];
  $Fridge = $row['Aliquots_Fridge'];
  $Barcode = $row['Aliquot_Barcode'];
  $Position = $row['Aliquot_Position'];
  $OrderAll = $row['Order_All'];
  $OrderPartial = $row['Order_Partial'];
  $OrderRest = $row['Order_Rest'];
  $ShippingAll = $row['Shipping_All'];
  $ShippingPartial = $row['Shipping_Partial'];
  $ShippingRest = $row['Shipping_Rest'];
  $Request_Date = $row['Request_Date'];
  $Request_Notes = $row['Request_Notes'];
  $Shipping_Date = $row['Shipping_Date'];
  $ID_Request = $row['ID_Request'];
  $ID_Aliquots = $row['ID_Aliquots'];
  
//NORMAL START  
echo "<tr><td align='center'>".$Name_All."</td><td align='center'>".$DnaBankNumber."<input type='hidden' name='IDRequest[".$i."]' value='".$ID_Request."'><input type='hidden' name='IDAliquots[".$i."]' value='".$ID_Aliquots."'></td><td align='center'>".$Aliquot_Number."<input type='hidden' name='Number[".$i."]' value='".$Aliquot_Number."'></td>";
echo "<td align='center'>".$Request_Volume." µl<input type='hidden' id='InputDay' name ='Rest[".$i."]' value='".$Request_Volume."'></td><td align='center'>".$Fridge."</td><td align='center'>".$Rack."</td><td align='center'>".$Box."</td>";
echo "<td align='center'>".DatumsWandler($Request_Date)."<input type='hidden' name='Request[".$i."]' value='".$Request_Date."'></td><td align='center'>";
echo "</td><td align='center'>".$Request_Notes."</td>";

echo "</tr>"; }
//NORMAL ENDE

/*ZSM MÜNCHEN START
echo "<tr><td align='center'>".$Name_All."</td><td align='center'>".$DnaBankNumber."<input type='hidden' name='IDRequest[".$i."]' value='".$ID_Request."'><input type='hidden' name='IDAliquots[".$i."]' value='".$ID_Aliquots."'></td><td align='center'>".$Position."</td><td align='center'>".$Aliquot_Number."<input type='hidden' name='Number[".$i."]' value='".$Aliquot_Number."'></td>";
echo "<td align='center'>".$Barcode."</td>";
echo "<td align='center'>".$Request_Volume." µl<input type='hidden' id='InputDay' name ='Rest[".$i."]' value='".$Request_Volume."'></td><td align='center'>".$Fridge."</td><td align='center'>".$Rack."</td><td align='center'>".$Box."</td>";
echo "<td align='center'>".DatumsWandler($Request_Date)."<input type='hidden' name='Request[".$i."]' value='".$Request_Date."'></td><td align='center'>";
echo "</td><td align='center'>".$Request_Notes."</td>";

echo "</tr>"; }
ZSM MÜNCHEN Ende*/
echo "</table></td></tr>";
echo "<tr><td colspan='3'><hr /></td></tr>"; }

}

}

?>


</table>
</td></tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>