<?php
// ini_set('display_errors','1');
// error_reporting(E_ALL);
$page="main";
include("../function/func.php");
session_start();
checkSession();
/*
if($_REQUEST['id']&&$_REQUEST['name']&&$_REQUEST['phone']){
  updateOrderInfo($_REQUEST['id'],$_REQUEST['name'],$_REQUEST['phone']);
}elseif($_REQUEST['name']&&$_REQUEST['phone']){
  $insertResult=insertOrderInfo($_REQUEST['name'],$_REQUEST['phone']);
}*/
if($_REQUEST['id']){
  $orderInfo=getOrderDetail($_REQUEST['id']);
  //$ordersID=getOrderIDFromID($_REQUEST['id']);
  $signs0=getSigns($_REQUEST['id'],0);
  $signs1=getSigns($_REQUEST['id'],1);
  $signs2=getSigns($_REQUEST['id'],2);
  $signs3=getSigns($_REQUEST['id'],3);
}
if($_REQUEST['isUpload']=='1'){
    $orderID=$_REQUEST['orderID'];
    $testDate=$_REQUEST['testDate'];
    $projectName=$_REQUEST['projectName'];
    $applicantName=$_REQUEST['applicantName'];
    $businessOwner=$_REQUEST['businessOwner'];
    $supervisor=$_REQUEST['supervisor'];
    $contractor=$_REQUEST['contractor'];
    $sampler=$_REQUEST['sampler'];
    $examinator=$_REQUEST['examinator'];
    $structuralPart=$_REQUEST['structuralPart'];
    $remark=$_REQUEST['remark'];
    $productionDate=$_REQUEST['productionDate'];
    $testedMaterial=$_REQUEST['testedMaterial'];
    $weather=$_REQUEST['weather'];
    $materialsUsed=$_REQUEST['materialsUsed'];
    $surfaceTemp=$_REQUEST['surfaceTemp'];
    $equipUsed=$_REQUEST['equipUsed'];
    $materialsName=$_REQUEST['materialsName'];
    $paymentCompany=$_REQUEST['paymentCompany'];
    $paymentTax=$_REQUEST['paymentTax'];
    $paymentAddr=$_REQUEST['paymentAddr'];
    $paymentContactor=$_REQUEST['paymentContactor'];
    $paymentPhone=$_REQUEST['paymentPhone'];
    $paymentFee=$_REQUEST['paymentFee'];
    $tester=$_REQUEST['tester'];
    $id=$_REQUEST['id'];
    updateOrder($id,$orderID,$testDate,$projectName,$applicantName,$businessOwner,$supervisor,$contractor,$sampler,$examinator,$structuralPart,$remark,$productionDate,$testedMaterial,$weather,$materialsUsed,$surfaceTemp,$equipUsed,$materialsName,$paymentCompany,$paymentTax,$paymentAddr,$paymentContactor,$paymentPhone,$paymentFee,$tester);
    header("refresh:1;url=orderDetail.php?id=".$_REQUEST['id']);
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>桂田技術顧問訂單管理系統</title>
    <link href="./css/common.css?id=<?php echo rand(0,10000);?>" rel="stylesheet">
  </head>
<body>
    <div class="bgBody">
        <?php include("./module/header.php");?>
        <div class="container">
            <?php include("./module/menu.php");?>
            <div class="mainContent">
            <form action="orderDetail.php?id=<?php echo $orderInfo[0]['id'];?>" method="post">
                <div class="head">
                    <div class="item title">訂單資訊</div>
                    <div class="item searchInput"><input type="submit" value="儲存"></div>
                    <a href="main.php"><div class="item" style="padding-top:0.3em">回前頁</div></a>
                    <div class="clear"></div>
                </div>
                    
                    <div class="inputForm" >
                    <div class="row" >
                        <div class="input">訂單編號： <input type="text" name="orderID" value="<?php echo $orderInfo[0]['orderID'];?>"></div>
                        <div class="input">試驗日期： <input type="text" name="testDate" value="<?php echo $orderInfo[0]['testDate'];?>"></div>
                        <div class="input">工程名稱： <input type="text" name="projectName" value="<?php echo $orderInfo[0]['projectName'];?>"></div>
                    </div>
                    <div class="row" >
                        <div class="input">委託單位： <input type="text" name="applicantName" value="<?php echo $orderInfo[0]['applicantName'];?>"></div>
                        <div class="input">業主： <input type="text" name="businessOwner" value="<?php echo $orderInfo[0]['businessOwner'];?>"></div>
                        <div class="input">監造單位： <input type="text" name="supervisor" value="<?php echo $orderInfo[0]['supervisor'];?>"></div>
                    </div>
                    <div class="row" >
                        <div class="input">承包商： <input type="text" name="contractor" value="<?php echo $orderInfo[0]['contractor'];?>"></div>
                        <div class="input">結構部位： <input type="text" name="structuralPart" value="<?php echo $orderInfo[0]['structuralPart'];?>"></div>
                        <div class="input">製作日期： <input type="text" name="productionDate" value="<?php echo $orderInfo[0]['productionDate'];?>"></div>
                    </div>
                    
                    <div class="row" >
                        <div class="input">受測材料： <input type="text" name="testedMaterial" value="<?php echo $orderInfo[0]['testedMaterial'];?>"></div>
                        <div class="input">天氣： <input type="text" name="weather" value="<?php echo $orderInfo[0]['weather'];?>"></div>
                        <div class="input">使用材料： <input type="text" name="materialsUsed" value="<?php echo $orderInfo[0]['materialsUsed'];?>"></div>
                        </div>
                    <div class="row" >
                        <div class="input">表面溫度： <input type="text" name="surfaceTemp" value="<?php echo $orderInfo[0]['surfaceTemp'];?>"></div>
                        <div class="input">
                            使用設備： <!--<input type="text" name="equipUsed" value="<?php echo $orderInfo[0]['equipUsed'];?>">-->
                            <select name="equipUsed">
                                <option value="Proceq(電動)" <?php if($orderInfo[0]['equipUsed']!="SANKO TECHNO"){echo "selected";};?>>Proceq(電動)</option>
                                <option value="SANKO TECHNO" <?php if($orderInfo[0]['equipUsed']=="SANKO TECHNO"){echo "selected";};?>>SANKO TECHNO</option>
                            </select>
                        </div>
                        <div class="input">材料名稱： <input type="text" name="materialsName" value="<?php echo $orderInfo[0]['materialsName'];?>"></div>
                        </div>
                    <div class="row" >
                    
                    <div class="input">備註： <input type="text" name="remark" value="<?php echo $orderInfo[0]['remark'];?>"></div>
                        
                    </div>
                    <div class="row gray" >
                        <div class="input">請款資料:公司名稱： <input type="text" name="paymentCompany" value="<?php echo $orderInfo[0]['paymentCompany'];?>"></div>
                        <div class="input">請款資料:公司統編：<input type="text" name="paymentTax" value="<?php echo $orderInfo[0]['paymentTax'];?>"></div>
                        <div class="input">請款資料:公司地址：<input type="text" name="paymentAddr" value="<?php echo $orderInfo[0]['paymentAddr'];?>"></div>
                        </div>
                    <div class="row gray" >
                        <!--<div class="input">請款資料:聯絡人：<input type="text" name="name" value="<?php echo $orderInfo[0]['paymentContactor'];?>"></div>-->
                        <div class="input">請款資料:連絡電話：<input type="text" name="paymentPhone" value="<?php echo $orderInfo[0]['paymentPhone'];?>"></div>
                        <div class="input">請款資料:測試費用：<input type="text" name="paymentFee" value="<?php echo $orderInfo[0]['paymentFee'];?>"></div>
                        
                    </div>
                    
                    <div>
                        <div class="flex">
                            <div class="input">取樣人員：<input type="text" name="sampler" value="<?php echo $orderInfo[0]['sampler'];?>"></div>
                            <a href="uploadSigns.php?type=0&id=<?php echo $_REQUEST['id'];?>"><div class="uploadbutton darkblue">上傳新簽名檔</div></a>
                        </div>
                        <div class="sign">
                            <?php 
                                for($i=0;$i<count($signs0);$i++){
                                    if(filesize("../signPics/".$signs0[$i]['picName'])>200){
                            ?>
                                <img src="../signPics/<?php echo $signs0[$i]['picName'];?>">
                            <?php 
                            }
                        }?>
                        </div>
                        <div class="flex">
                            <div class="input">會驗人員： <input type="text" name="examinator" value="<?php echo $orderInfo[0]['examinator'];?>"></div>
                            <a href="uploadSigns.php?type=1&id=<?php echo $_REQUEST['id'];?>"><div class="uploadbutton darkblue">上傳新簽名檔</div></a>
                        </div>
                        <div class="sign">
                            <?php 
                                for($i=0;$i<count($signs1);$i++){
                                    if(filesize("../signPics/".$signs1[$i]['picName'])>200){
                            ?>
                                <img src="../signPics/<?php echo $signs1[$i]['picName'];?>">
                            <?php 
                            }
                        }?>
                        </div>
                        <div class="flex">
                            <div class="input">聯絡人： <input type="text" name="paymentContactor" value="<?php echo $orderInfo[0]['paymentContactor'];?>"></div>
                            <a href="uploadSigns.php?type=2&id=<?php echo $_REQUEST['id'];?>"><div class="uploadbutton darkblue">上傳新簽名檔</div></a>
                        
                        </div>
                        <div class="sign">
                            <?php 
                                for($i=0;$i<count($signs2);$i++){
                                    if(filesize("../signPics/".$signs2[$i]['picName'])>200){
                            ?>
                                <img src="../signPics/<?php echo $signs2[$i]['picName'];?>">
                            <?php 
                            }
                        }?>
                        </div>
                        <div class="flex">
                            <div class="input">測試人員： <input type="text" name="paymetnContactor" value="<?php echo $orderInfo[0]['paymetnContactor'];?>"></div>
                            <a href="uploadSigns.php?type=3&id=<?php echo $_REQUEST['id'];?>"><div class="uploadbutton darkblue">上傳新簽名檔</div></a>
                        </div>
                        <div class="sign">
                            <?php 
                                for($i=0;$i<count($signs3);$i++){
                                    if(filesize("../signPics/".$signs3[$i]['picName'])>200){
                            ?>
                                <img src="../signPics/<?php echo $signs3[$i]['picName'];?>">
                            <?php 
                            }
                        }?>
                        </div>
                        
                    </div>
                    
                    <div class="row" >
                        <input type="hidden" name="isUpload" value="1">
                        <input type="hidden" name="id" value="<?php echo $orderInfo[0]['id'];?>">
                        <div class="input"><input type="submit" value="儲存"></div>
                    </div>
                    </div>
                    </form>
                
            </div>
        </div>
    </div>
</body>
</html>