<?php
include("CheckSession.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="馬戲團" />
    <title>馬戲團</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<?php

require_once("class/DBConfig.php");
require_once("class/DBOperation.php");

$db = new DBOperation();

$AName = "";
$AAccount = "";
$APass = "";
$AFlag = "";
$AGroupId = -1;
$AErrTimes = 0;
$AMacAddress = "";
$ALogTime = "";
$id = "";
$ARightLevel = "";
$ARights = "";
$AUpdateFields = "";
$AHourExTimes = 0;
$ADayExTimes = 0;
$ALogTime = "";
$AMacAddressArr = null;
$ALogTimeArr = null;

$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
$db->query("SELECT * FROM AdminUser where AAccount = 'admin'");
$row = $db->fetch_row();
$AName = $row[1];
$AAccount = $row[2];
$AFlag = $row[4];
$AGroupId = $row[5];
$AMacAddress = $row[12];
$ARightLevel = $row[13];
$ARights = $row[14];
$AUpdateFields = $row[15];
$AMacAddressArr = explode(",", $AMacAddress);
$AHourExTimes = $row[17];
$ADayExTimes = $row[18];
$ALogTime = $row[19];
$ALogTimeArr = explode(";", $ALogTime);
$db->close_db();

?>
<SCRIPT language="JavaScript">
    function validateForm(objThisUi) {
        if (objThisUi.ALogTime0_1_1.value.length == 0 || objThisUi.ALogTime0_1_2.value.length == 0 ||
            objThisUi.ALogTime0_2_1.value.length == 0 || objThisUi.ALogTime0_2_2.value.length == 0) {
            alert("請至少輸入一個登入的時段!!");
            objThisUi.ALogTime0_1_1.focus();
            return false;
        }

        if (isNaN(Number(objThisUi.ALogTime0_1_1.value, 10)) ||
            isNaN(Number(objThisUi.ALogTime0_1_2.value, 10)) ||
            isNaN(Number(objThisUi.ALogTime0_2_1.value, 10)) ||
            isNaN(Number(objThisUi.ALogTime0_2_2.value, 10))) {
            alert("請確認可登入的時段1的時段資料須為数字!!");
            objThisUi.ALogTime0_1_1.focus();
            return false;
        }

        if (objThisUi.ALogTime1_1_1.value.length > 0 ||
            objThisUi.ALogTime1_1_2.value.length > 0 ||
            objThisUi.ALogTime1_2_1.value.length > 0 ||
            objThisUi.ALogTime1_2_2.value.length > 0 ) {

            if ((objThisUi.ALogTime1_1_1.value.length > 0 && isNaN(Number(objThisUi.ALogTime1_1_1.value, 10))) ||
                (objThisUi.ALogTime1_1_2.value.length > 0 && isNaN(Number(objThisUi.ALogTime1_1_2.value, 10))) ||
                (objThisUi.ALogTime1_2_1.value.length > 0 && isNaN(Number(objThisUi.ALogTime1_2_1.value, 10))) ||
                (objThisUi.ALogTime1_2_2.value.length > 0 && isNaN(Number(objThisUi.ALogTime1_2_2.value, 10)))) {
                alert("可登入的時段2 請輸入完全且正確的時段資料!!");
                objThisUi.ALogTime1_1_1.focus();
                return false;
            }
        }

        if (objThisUi.ALogTime2_1_1.value.length > 0 ||
            objThisUi.ALogTime2_1_2.value.length > 0 ||
            objThisUi.ALogTime2_2_1.value.length > 0 ||
            objThisUi.ALogTime2_2_2.value.length > 0 ) {

            if ((objThisUi.ALogTime2_1_1.value.length > 0 && isNaN(Number(objThisUi.ALogTime2_1_1.value, 10))) ||
                (objThisUi.ALogTime2_1_2.value.length > 0 && isNaN(Number(objThisUi.ALogTime2_1_2.value, 10))) ||
                (objThisUi.ALogTime2_2_1.value.length > 0 && isNaN(Number(objThisUi.ALogTime2_2_1.value, 10))) ||
                (objThisUi.ALogTime2_2_2.value.length > 0 && isNaN(Number(objThisUi.ALogTime2_2_2.value, 10)))) {
                alert("可登入的時段3 請輸入完全且正確的時段資料!!");
                objThisUi.ALogTime2_1_1.focus();
                return false;
            }
        }
        return true;
    }
</SCRIPT>
<body>
    <form method="post" action="LoginTimeSetUpDeal.php" onSubmit="return validateForm(this);">
        <table border="0" cellspacing="0" cellspadding="0" width="90%">
            <tr>
                <td align="left" colspan="2">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td align="left" colspan="2">
                    <span class="t14b"><b>登入時段限制設定</b></span>
                </td>
            </tr>
            <tr>
                <td align="left" colspan="2">
                    <table border="3" cellspacing="2" cellspadding="2" width="100%">
                        <tr>
                            <td align="left" width="15%">
                                <span class="t12">可登入的時段1</span>
                            </td>
                            <td align="left" width="85%">
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[0] == null) ? "" : explode(":", explode("-", $ALogTimeArr[0])[0])[0]; ?>" name="ALogTime0_1_1" id="ALogTime0_1_1" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                時
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[0] == null) ? "" : explode(":", explode("-", $ALogTimeArr[0])[0])[1]; ?>" name="ALogTime0_1_2" id="ALogTime0_1_2" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                分 至
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[0] == null) ? "" : explode(":", explode("-", $ALogTimeArr[0])[1])[0]; ?>" name="ALogTime0_2_1" id="ALogTime0_2_1" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                時
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[0] == null) ? "" : explode(":", explode("-", $ALogTimeArr[0])[1])[1]; ?>" name="ALogTime0_2_2" id="ALogTime0_2_2" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                分
                                <br />
                                <font color="red">輸入格式 如 下午1點30分 請輸入 : 13時30分
                                    <br />若登入時段為24小時 請輸入00時00分 至 00時00分
                                </font>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" width="15%">
                                <span class="t12">可登入的時段2</span>
                            </td>
                            <td align="left" width="85%">
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[1] == null) ? "" : explode(":", explode("-", $ALogTimeArr[1])[0])[0]; ?>" name="ALogTime1_1_1" id="ALogTime1_1_1" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                時
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[1] == null) ? "" : explode(":", explode("-", $ALogTimeArr[1])[0])[1]; ?>" name="ALogTime1_1_2" id="ALogTime1_1_2" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                分 至
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[1] == null) ? "" : explode(":", explode("-", $ALogTimeArr[1])[1])[0]; ?>" name="ALogTime1_2_1" id="ALogTime1_2_1" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                時
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[1] == null) ? "" : explode(":", explode("-", $ALogTimeArr[1])[1])[1]; ?>" name="ALogTime1_2_2" id="ALogTime1_2_2" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                分
                                <br />
                                <font color="red">輸入格式 如 下午1點30分 請輸入 : 13時30分
                            </td>
                        </tr>
                        <tr>
                            <td align="left" width="15%">
                                <span class="t12">可登入的時段3</span>
                            </td>
                            <td align="left" width="85%">
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[2] == null) ? "" : explode(":", explode("-", $ALogTimeArr[2])[0])[0]; ?>" name="ALogTime2_1_1" id="ALogTime2_1_1" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                時
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[2] == null) ? "" : explode(":", explode("-", $ALogTimeArr[2])[0])[1]; ?>" name="ALogTime2_1_2" id="ALogTime2_1_2" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                分 至
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[2] == null) ? "" : explode(":", explode("-", $ALogTimeArr[2])[1])[0]; ?>" name="ALogTime2_2_1" id="ALogTime2_2_1" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                時
                                <input type="text" value="<?php echo ($ALogTimeArr == null || $ALogTimeArr[2] == null) ? "" : explode(":", explode("-", $ALogTimeArr[2])[1])[1]; ?>" name="ALogTime2_2_2" id="ALogTime2_2_2" size="2" maxlength="2" style="font-size: 12.0pt;font-family: 微軟正黑體;" />
                                分
                                <br />
                                <font color="red">輸入格式 如 下午1點30分 請輸入 : 13時30分
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2">
                                <input type="submit" name="btnSub" id="btnSub" value="變更設定" class="t12" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</body>

</html>