<?php
// include_once 'src/inc/db/function.php';
include_once 'src/inc/db/globarvar.php';
include_once 'encrypt.php';
// user_logs('ot_custRegist_confirm');
// $today = date("Y-m-d");

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$con = checkEmail($action, $key, $iv);

// $msg = (isset($_REQUEST['message']) ? $_REQUEST['message'] : '');
// $msg = urldecode($msg); // 解码字符串
// $msg = json_decode($msg, true); // 解析为关联数组
// print_r($msg);

function checkEmail($action, $key, $iv)
{
    global $conn;
    $params = array();
    $resultAction = decrypt($action, $key, $iv);
    $resultAction = str_replace('+', '%2B', $resultAction);
    $today = date("Y-m-d"); // 獲取今天的日期
    // 使用 parse_str() 函数解析字符串
    parse_str($resultAction, $params);
    if (isset($params['act']) && isset($params['email']) && isset($params['userRid']) && $params['email'] && $params['userRid'] && $params['act'] == 'confirm_customer_mail') {
        $sql = "UPDATE users set userStatus = 'Y', startDay = ? where user_id = ? AND email = ?";
        $stmt = $conn->prepare($sql);
        $rs =  $stmt->execute([$today, $params['userRid'], $params['email']]);
        return True;
    } else {
        return False;
    }
}

?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="description" content="">
    <meta name="author" content="Frontier,本網站由〔前沿科技〕設計與製作" />
    <meta name="keywords" content="hanyu,Chinese learn,payin ">

    <title>帳號確認 | 負碳平台, Frontier Technology</title>

    <script src="assets/js/jquery-3.7.1.js"></script>
    <link href="fonts/fonts.css" rel="stylesheet">
    <style type='text/css'>
        .container-fluid {
            display: flex;
            justify-content: center;
            /* 水平居中 */
            align-items: center;
            /* 垂直居中 */
            min-height: 100vh;
            /* 至少占满视窗的高度 */
        }

        .content {
            text-align: center;
            width: 50%;
            min-width: 320px;
            margin: 0 auto;
            padding: 40px 10px 20px 10px;
            background-color: #f8f8f8;
            min-height: 400px;
            border-radius: 10px;
            position: relative;
            margin: 6% auto;
        }

        a {
            text-decoration: none;
        }

        p {
            text-align: center;
            /* 将段落内的文字水平居中 */
        }

        .form-signin {
            width: 90%;
            max-width: 500px;
            margin: auto;
            /* 确保在 flexbox 布局下居中 */
            padding: 20px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }

        /*** ADD BY DARREN ***/
        @import url(https://fonts.googleapis.com/earlyaccess/notosanstc.css);

        body {
            font-family: Noto Sans TC, Microsoft JhengHei, Apple LiGothic, Arial, Helvetica, sans-serif;
        }

        .logo-area {
            width: 50%;
            overflow: hidden;
            text-align: right;
            margin: 6% auto 1%;
        }

        .logo-area hr {
            display: inline-block;
            width: 58%;
            margin: 2.5% 0 0 1.5%;
            border: #E3E3E3 1px dotted;
        }

        .logo-area img {
            width: 35%;
            margin-right: 3%;
        }

        .content {
            margin: 0 auto 6%;
            border: #D5D5D5 1px solid;
            box-shadow: 1px 1px 16px #E5E5E5;
        }

        .content h4 {
            color: #025EAD;
            letter-spacing: 0.05em;
        }

        .form-signin {
            text-align: center;
            /* 将表单内所有的文本内容都居中对齐 */
        }

        .expire-message {
            display: none;
            color: #727171;
            font-size: 1.125em;
            font-weight: 300;
            line-height: 150%;
            text-align: center;
        }

        .expire-message-deco-pic {
            width: 35%;
            overflow: hidden;
            margin: 0 auto 8%;
            padding: 0;
        }

        .expire-message-deco-pic img {
            width: 100%;
            overflow: hidden;
            margin: 0 auto 2%;
            padding: 0;
        }
    </style>
</head>

<body class="text-center" style="background-color: rgba(0,0,0,0);">
    <div class="container-fluid">
        <!-- <div class="logo-area" style="max-width:450px;"> -->
        <!-- <hr> -->
        <!-- <image src="./images/logo_hanyu_ot_01.png"/>  -->
        <!-- <p> Hanyu VR APP </p> -->
        <!-- </div>  -->
        <div class="content">
        <img src="./assets/img/NCHC_R.png" class="img img-fluid" />
            <div class="form-signin" style="background-color: #f8f8f8; margin: 8% auto; padding: 1% 5%;">
                <div id="signin">
                    <?php if ($con) { ?>
                        <!-- <p> Learning Chinese can be fun and effective ! </p> -->
                        <span class="material-symbols-outlined" style="color:	#005AB5; font-size: 1.2em;">
                            您的電子信箱已經被確認。
                        </span>
                        <p>
                            請回到<a href="login.php">負碳平台</a>並登入。
                        </p>
                    <?php } else { ?>
                        <!-- <p> Learning Chinese can be fun and effective ! </p> -->
                        <div class="expire-message-deco-pic">
                            <img src="./images/deco_registe_fail_01.png" />
                        </div>
                        <p>
                            驗證錯誤！
                        </p>
                    <?php } ?>
                </div>
                <!-- <div id="msg" class="expire-message">
                    <div class="expire-message-deco-pic">
                        <img src="./images/deco_registe_fail_01.png" />
                    </div> -->
                <!-- No registered account found or the link has expired !
                    <br>
                    Please try register again.
                    <br><br> -->
                <!-- Some error occur!!! -->
                <!--  <span style="color: #cd5353;">
                    No Registered Account Found !
                    </span> -->
                <!-- <br>
                </div>                 -->
                <!-- <p class="mt-5 mb-3 text-muted" style="font-size: 0.75em;"> -->
                <!-- <a class="btn" href="https://www.roomie-p.com/hanyu_www/">Go Website </a> -->
                <br><br>
                &copy; 2024 負碳平台
                </p>
            </div>
        </div>
    </div>
</body>

</html>