<?php
// ini_set('display_errors','1');
// error_reporting(E_ALL);
$page="main";
include("../function/func.php");
session_start();
checkSession();
$info=getOrderDetail($_REQUEST['id']);
$equipments = getEquipments();
//var_dump($info);
/*
id	
testTypeName	
ordersID	
number	
serialNum	
equipment	
type	
info	
forcePercentage	
formOfForce	
direction	
pressureValue	
designLoadKgf	
loadKgf	
destoryLocation
*/
if($_REQUEST['insertOneTest']==1){
    //取得設備參考值
    $equipmentId = getEquipmentIDFromName($_REQUEST['equipment']);
    $equipmentInfo = getEquipmentInfo($equipmentId);
    //
    $ordersID=$_REQUEST['id'];
    $serialNum=(int)$_REQUEST['serialNum'];
    $testTypeName=$_REQUEST['testTypeName'];
    $number=$_REQUEST['number'];
    $equipment=$_REQUEST['equipment'];
    $type=$_REQUEST['type'];
    $info=$_REQUEST['info'];
    $forcePercentage=$_REQUEST['forcePercentage'];
    $formOfForce=$_REQUEST['formOfForce'];
    $pressureValue=$_REQUEST['pressureValue'];
    $designLoadKgf=$_REQUEST['designLoadKgf'];
    $loadKgf=$_REQUEST['loadKgf'];
    if($pressureValue != 0 && $loadKgf==0 && count($equipmentInfo)>1){
        $loadKgf = linearInterpolation($pressureValue,$equipmentInfo);
    }
    $destoryLocation=$_REQUEST['destoryLocation'];
    // if($type=='0'){$type ="";}
    // if($info=='0'){$info ="";}
    // if($forcePercentage=='0'){$forcePercentage ="";}
    // if($formOfForce=='0'){$formOfForce ="";}
    // if($pressureValue=='0'){$pressureValue ="";}
    // if($designLoadKgf=='0'){$designLoadKgf ="";}
    // if($loadKgf=='0'){$loadKgf ="";}
    // if($destoryLocation=='0'){$destoryLocation ="";}
    createPullTest($testTypeName, $ordersID, $number, $serialNum, $equipment, $type, $info, $forcePercentage, $formOfForce, $direction, $pressureValue, $designLoadKgf, $loadKgf, $destoryLocation);
    header("refresh:0;url=testItemList.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">
    <link rel="stylesheet" href="//code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
    <script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
    <script>
        $( function() {
            $( "#productionDate" ).datepicker({
                showButtonPanel: true,
                dateFormat: 'yy-mm-dd'
            });
        } );
    </script>
  </head>
<body>
    <div class="bgBody">
        <?php include("./module/header.php");?>
        <div class="container">
            <?php include("./module/menu.php");?>
            <div class="mainContent">
                <div class="head">
                    <div class="item title">測試項目資訊</div>
                    <a href="testItemList.php?id=<?php echo $_REQUEST['id'];?>"><div class="item searchInput" style="padding-top:0.3em">回測試項目列表</div></a>
                    <div class="clear"></div>
                </div>
                <div class="testItemList">
                <div class="testItem gray">
                    <form action="insertPullTestItem.php?insertOneTest=1&id=<?php echo $_REQUEST['id'];?>" method="post">
                        <div class="item"><span style="color:#556B2F">新增一筆測試項目</span></div>
                        <div class="item">項目編號：<input type="text" name="serialNum" value=""></div>
                        <div class="item">測試項目：<select name="testTypeName" id="testTypeName">
                                <option value="現場植筋拉拔試驗報告">現場植筋拉拔試驗報告</option>
                                <option value="現場預埋鐵件拉拔試驗報告">現場預埋鐵件拉拔試驗報告</option>
                                <option value="現場化學螺栓拉拔試驗報告">現場化學螺栓拉拔試驗報告</option>
                                <option value="現場內迫螺栓拉拔試驗報告">現場內迫螺栓拉拔試驗報告</option>
                                <option value="現場拉脹螺栓拉拔試驗報告">現場拉脹螺栓拉拔試驗報告</option>
                            </select>
                        </div>
                        <div class="item">使用設備：<select name="equipment" id="equipment">
                        <?php foreach($equipments as $equipment) {?>
                                <option value="<?php echo $equipment['name'];?>" <?php echo ($testItems[0]['equipment'] == $equipment['name']) ? 'selected' : ''; ?>><?php echo $equipment['name']; ?></option>
                                
                            <?php } ?>
                            </select>
                        </div>
                        <div class="item">TYPE：<input type="text" name="type" value="" id="type"></div>
                        <div class="item">說明：<input type="text" name="info" id="info" value=""></div>
                        <div class="item">方向：<select name="forcePercentage" id="forcePercentage">
                                <option value="東">東</option>
                                <option value="南">南</option>
                                <option value="西">西</option>
                                <option value="北">北</option>
                                <option value="東南">東南</option>
                                <option value="西南">西南</option>
                                <option value="西北">西北</option>
                                <option value="東北">東北</option>
                            </select>
                        </div>
                        <div class="item">施力形式：<select name="formOfForce" id="formOfForce">
                                <option value="拉力">拉力</option>
                                <option value="剪力">剪力</option>
                                <option value="水平">水平</option>
                                <option value="垂直">垂直</option>
                            </select>
                        </div>
                        <div class="item">施力％：<select name="forcePercentage" id="forcePercentage">
                                <option value="50%">50%</option>
                                <option value="100%">100%</option>
                                <option value="150%">150%</option>
                                <option value="200%">200%</option>
                            </select>
                        </div>
                        <div class="item">壓力表值(psi)：<input type="text" name="pressureValue" value="" id="pressureValue"></div>
                        <div class="item">測試荷重(kgf)：<input type="text" name="loadKgf" id="loadKgf" value=""></div>
                        <div class="item">設計規範值(kgf)：<input type="text" name="designLoadKgf" value="" id="designLoadKgf"></div>
                        
                        <div class="item">破壞位置：<select name="destoryLocation" id="destoryLocation">
                                <option value="1.混凝土基材破壞">1.混凝土基材破壞</option>
                                <option value="2.樣品斷裂">2.樣品斷裂</option>
                                <option value="3.握裹喪失鬆脫">3.握裹喪失鬆脫</option>
                                <option value="4.達規範值未破壞">4.達規範值未破壞</option>
                            </select>
                        </div>
                        <div class="input"><input type="submit" value="新增測試"></div>
                    </form>
                </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="cal.js"></script>
