<?php
//ini_set('display_errors','1');
//error_reporting(E_ALL);
$page="main";
include("../function/func.php");
session_start();
checkSession();
if($_REQUEST['id']&&$_REQUEST['isUpload']=='1'){
    if($_FILES['my_file']['size']>0){
        //echo $_REQUEST['orderID']=getOrderIDFromID($_REQUEST['id']);
        $file = $_FILES['my_file']['tmp_name'];
        $filenameArray=explode(".",$_FILES['my_file']['name']);
        $filename=$filenameArray[0]."_".Date("YmdHis").".".$filenameArray[1];
        $dest = '../signPics/'.$filename;
        # 將檔案移至指定位置
        move_uploaded_file($file, $dest);
        insertContactName($_REQUEST['id'],$_REQUEST['contactName'],$_REQUEST['type']);
        //$ordersID=getOrderIDFromID($_REQUEST['id']);
        insertSigns($_REQUEST['id'],$_REQUEST['type'],$filename);
        $message="上傳簽名檔成功";
        header("refresh:2;url=orderDetail.php?id=".$_REQUEST['id']);
    }else{
        $message="上傳簽名檔失敗";
    }
}
switch($_REQUEST['type']){
    case "0":
        $typeName="取樣人員";
        break;
    case "1":
        $typeName="會驗人員";
        break;
    case "2":
        $typeName="聯絡人";
        break;
    case "3":
        $typeName="測試人員";
        break;
}
?>
<!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">
                <div class="head">
                    <div class="item title">上傳<?php echo $typeName;?>簽名檔</div><div class="clear"></div>
                </div>
                <?php if($message!=""){?>
                <div class="message"><?php echo $message;?></div>
                <?php }else{?>
                <div style="margin:0.5em;">
                <form action="uploadSigns.php?id=<?php echo $_REQUEST['id'];?>&type=<?php echo $_REQUEST['type'];?>" method="post" enctype="multipart/form-data">
                    <div class="input"><?php echo $typeName;?>姓名：<input type="text" name="contactName"></div>
                    <div class="input"><input type="file" name="my_file"></div>
                    <input type="hidden" name="isUpload" value="1">
                    <div class="input"><input type="submit" value="送出"></div>
                </form>
                </div>
                <?php }?>
                
            </div>
        </div>
    </div>
</body>
</html>