<?php
require '../template/header.php';
require '../library/database.php';
require '../library/thaidate.php';
require '../library/jobclass.php';

if (!isset($_SESSION["session_user"]) || $_SESSION["session_user"] !== TRUE) {
    header("location: " . $app_url . "/login.php");
}
function status($status_check)
{
    switch ($status_check) {
        case '0':
            return '<span class="badge bg-danger">ออฟไลน์</span>';
            break;

        case '1':
            return '<span class="badge bg-success">ออนไลน์</span>';
            break;
        default:
            return 'NULL';
            break;
    }
}
?>
<section class="fxt-template-animation fxt-template-layout22" data-bg-image="<?= $app_url ?>/assets/img/figure/bg.jpg">
    <!-- Star Animation Start Here -->
    <div class="star-animation">
        <div id="stars4"></div>
        <div id="stars5"></div>
    </div>
    <!-- Star Animation End Here -->
    <div class="container">
        <div class="row align-items-center justify-content-md-center shadow-lg">
            <div class="col-lg-12 fxt-bg-color">
                <div class="fxt-content">
                    <div class="fxt-form">
                        <h2>ยินดีต้อนรับสมาชิก</h2>
                        <p>ไอดีเกมส์ : <span style="color:red;text-transform: uppercase;"><?= htmlspecialchars($_SESSION['userid']) ?></span></p>
                        <?php require_once '../template/menu.php' ?>
                        <?php

                        $account_id = $con->real_escape_string($_SESSION['account_id']);
                        $res_dashboard = $con->query("SELECT userid,state,lastlogin FROM login WHERE account_id={$account_id}")->fetch_object();

                        $eddgastudio_cp = $con->query("SELECT `value` FROM `acc_reg_num` WHERE  `key`= '{$set_cashpoint}' AND `account_id` = {$account_id}");
                        if ($eddgastudio_cp->num_rows > 0) {
                            $rs_cp = $eddgastudio_cp->fetch_object();
                            $cashpoints = number_format($rs_cp->value, 0);
                        } else {
                            $cashpoints = '0';
                        }

                        $eddgastudio_bp = $con->query("SELECT `value` FROM `acc_reg_num` WHERE  `key`= '{$set_bonuspoint}' AND `account_id` = {$account_id}");
                        if ($eddgastudio_bp->num_rows > 0) {
                            $rs_bp = $eddgastudio_bp->fetch_object();
                            $bonuspoints = number_format($rs_bp->value, 0);
                        } else {
                            $bonuspoints = '0';
                        }

                        $eddgastudio_share = $con->query("SELECT `value` FROM `acc_reg_num` WHERE  `key`= '{$set_sharepoint}' AND `account_id` = {$account_id}");
                        if ($eddgastudio_share->num_rows > 0) {
                            $rs_share = $eddgastudio_share->fetch_object();
                            $sharepoints = number_format($rs_share->value, 0);
                        } else {
                            $sharepoints = '0';
                        }


                        $eddgastudio_vote = $con->query("SELECT total_point FROM duckdig WHERE account_id = {$account_id}");
                        if ($eddgastudio_vote->num_rows > 0) {
                            $rs_vote = $eddgastudio_vote->fetch_object();
                            $votepoints = number_format($rs_vote->total_point, 0);
                        } else {
                            $votepoints = '0';
                        }
                        ?>
                        <div class="shadow p-2 mb-3 bg-body rounded">
                            <ul class="list-group list-group-flush">
                                <li class="list-group-item">
                                    <h5 class="card-title mb-3">ข้อมูลบัญชีผู้ใช้งาน <span style="color:blue;font-size:14px">Dashboard</span></h5>
                                    <div class="row">
                                        <div class="col-lg-4">
                                            <div class="border shadow-sm p-3 mb-3 bg-body rounded-start">
                                                <p class="text-start mt-2 fw-bold"><i class="fas fa-user-tie"></i> Account ID : <span class="badge bg-primary"><?= htmlspecialchars($account_id) ?></span></p>
                                                <div class="progress mb-2" style="height: 1px;">
                                                    <div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
                                                </div>
                                                <p class="text-start mb-2 fw-bold">
                                                    <i class="fas fa-unlock-alt"></i> Status ID :
                                                    <?php if ($res_dashboard->state == 0) : ?>
                                                        <span class="badge bg-success">ใช้งานได้ปกติ</span>
                                                    <?php else : ?>
                                                        <span class="badge bg-danger">ถูกระงับใช้งาน</span>
                                                    <?php endif; ?>
                                                </p>
                                                <div class="progress mb-2" style="height: 1px;">
                                                    <div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
                                                </div>
                                                <p class="text-start mb-2 fw-bold"><i class="fas fa-history"></i> Last Login : <span class="badge bg-secondary"><time class="timeago" datetime="<?= htmlspecialchars($res_dashboard->lastlogin) ?>" title="<?= thaidate($res_dashboard->lastlogin) ?>"></time></span></p>
                                                <div class="progress mb-2" style="height: 1px;">
                                                    <div class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
                                                </div>
                                                <p class="text-start fw-bold"><i class="fas fa-map-marked"></i> IP Address : <span class="badge bg-secondary"><?= getIP() ?></span></p>
                                            </div>
                                        </div>
                                        <div class="col-lg-4">
                                            <img src="<?= $app_url ?>/assets/images/img-dashboard.png" class="rounded mx-auto d-block" alt="...">
                                        </div>
                                        <div class="col-lg-4">
                                            <div class="border shadow-sm p-1 mb-2 bg-body rounded">
                                                <p class="text-center mt-1 fw-bold"><i class="fas fa-shopping-basket"></i> Cash Point : <span class="badge rounded-pill bg-primary"><?= $cashpoints ?></span></p>
                                            </div>
                                            <div class="border shadow-sm p-1 mb-2 bg-body rounded">
                                                <p class="text-center mt-1 fw-bold"><i class="fas fa-gift"></i> Bonus Point : <span class="badge rounded-pill bg-danger"><?= $bonuspoints ?></span></p>
                                            </div>
                                            <div class="border shadow-sm p-1 mb-2 bg-body rounded">
                                                <p class="text-center mt-1 fw-bold"><i class="fas fa-chess-queen"></i> Vote Point : <span class="badge rounded-pill bg-secondary"><?= $votepoints ?></span></p>
                                            </div>
                                            <div class="border shadow-sm p-1 mb-2 bg-body rounded">
                                                <p class="text-center mt-1 fw-bold"><i class="fab fa-facebook"></i> Share Point : <span class="badge rounded-pill bg-secondary"><?= $sharepoints ?></span></p>
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li class="list-group-item">
                                    <h5 class="card-title mb-3">ข้อมูลตัวละคร <span style="color:blue;font-size:14px">Char Info</span></h5>
                                    <div class="table-responsive">
                                        <table class="table" id="player_show">
                                            <thead>
                                                <tr>
                                                    <th class="text-center">ชื่อตัวละคร</th>
                                                    <th class="text-center">อาชีพ</th>
                                                    <th class="text-center">เลเวล/จ๊อบ</th>
                                                    <th class="text-center">เงินเซนี</th>
                                                    <th class="text-center">แผนที่ล่าสุด</th>
                                                    <th class="text-center">สถานะ</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $chars = $con->query("SELECT `name`,class,base_level,job_level,zeny,last_map,last_x,last_y,`online` FROM `char` WHERE account_id = {$account_id}");
                                                while ($char = $chars->fetch_object()) : ?>
                                                    <tr>
                                                        <td class="text-center"><?= htmlspecialchars($char->name) ?></td>
                                                        <td class="text-center"><?= getjob($char->class) ?></td>
                                                        <td class="text-center"><?= htmlspecialchars($char->base_level) ?> / <?= htmlspecialchars($char->job_level) ?></td>
                                                        <td class="text-center"><?= number_format($char->zeny, 0) ?></td>
                                                        <td class="text-center"><?= htmlspecialchars($char->last_map) ?> <?= htmlspecialchars($char->last_x) ?>,<?= htmlspecialchars($char->last_y) ?></td>
                                                        <td class="text-center"><?= status($char->online) ?></td>
                                                    </tr>
                                                <?php endwhile; ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                    <div class="fxt-footer">
                        <p>คุณต้องการออกจากระบบใช่หรือไม่ ?<a href="<?= $app_url ?>/logout.php" class="switcher-text2 inline-text">คลิกที่นี้</a></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<?php
require '../template/footer.php';
?>