<?php
// ini_set('display_errors','1');
// error_reporting(E_ALL);
$page="equipment";
include("../function/func.php");
session_start();
checkSession();
$testType = "normal";
$equipments=getEquipments();

if($_REQUEST['deleteID']){
    //echo "delete";
    deleteEquipment($_REQUEST['deleteID']);
    header("refresh:0;url=equipmentList.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">
                <div class="head">
                    <div class="item title">設備列表</div>
                    
                    <div class="item button blue" style="padding:5px;margin-top:0px;" onclick="location.href = 'insertEquipment.php';">新增設備</div>
                    
                    <a href="main.php"><div class="item" style="padding-top:0.3em">回前頁</div></a>
                    <div class="clear"></div>
                </div>
                <div class="orderList">
                    <div class="orderItem mainOrderItem">
                        <div class="item projectId">編號</div>
                        <div class="item placeId">設備名稱</div>
                    </div>
                    <?php for($i=0;$i<count($equipments);$i++){?>
                    <div class="orderItem <?php if($i%2==0){echo "gray";}?>" >
                        <div class="item projectId"><?php echo $equipments[$i]['id'];?></div>
                        <div class="item placeId"><?php echo $equipments[$i]['name'];?></div>
                        <div class="item button blue" onclick="location.href = 'updateEquipment.php?id=<?php echo $equipments[$i]['id'];?>';">修改</div>
                        
                        <div class="item button deleteButton" onclick="deleteItem(<?php echo $equipments[$i]['id'];?>);">刪除</div>
                    </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script>
function deleteItem(id){
    var yes = confirm('確定要刪除此項目？?');
    if (yes) {
        location.href='equipmentList.php?deleteID='+id
    }
}
</script>