<?php
    session_start();
    if(!isset($_SESSION['username'])){
        $_SESSION['msg']="You must log in first";
        header('location: login.php');
    }
    if (isset($_GET['logout'])){
        session_destroy();
        unset($_SESSION['username']);
        header('location: login.php');
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page</title>
<style>
    body {
        font-family: Arial, sans-serif;
        background-color: #f2f2f2;
        margin: 0;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        flex-direction: column;
    }
    .homeheader {
        background-color: #007BFF;
        color: white;
        padding: 20px;
        border-radius: 5px 5px 0 0;
        text-align: center;
        width: 100%;
        max-width: 600px;
    }
    .homecontent {
        background-color: white;
        padding: 20px;
        border-radius: 0 0 5px 5px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        width: 100%;
        max-width: 600px;
        text-align: center;
    }
    .success {
        background-color: #d4edda;
        color: green;
        border: 1px solid #4CAF50;
        padding: 10px;
        margin-bottom: 20px;
        border-radius: 5px;
    }
    .homecontent p {
        margin: 10px 0;
    }
    .homecontent a {
        color: #007BFF;
        text-decoration: none;
        font-weight: bold;
        padding: 10px;
        border-radius: 5px;
        display: block;
        transition: background-color 0.3s;
    }
    .homecontent a:hover {
        background-color: #e7f3ff;
    }
    .homecontent a[style*="color: red;"] {
        color: red;
    }
    .homecontent a[style*="color: red;"]:hover {
        background-color: #f9d6d5;
    }
</style>
</head>

<body>

<div class="homeheader">
    <h2>Home Page</h2>
</div>

<div class="homecontent">

    <!--- nonfication message --->
    <?php if (isset($_SESSION['success'])) : ?>
    <div class="success">
    <h3>
    <?php
    echo $_SESSION['success'];
    unset($_SESSION['success']);
    ?>
    </h3>
    </div>
    <?php endif ?>

    <!--- logged in user information --->
    <?php if (isset($_SESSION['username'])): ?>
    <p>Welcome User : <strong><?php echo $_SESSION['username']; ?></strong></p>
    <p><a href="checkstd.php">เช็คชื่อนักเรียน</a></p>
    <p><a href="Activity.php">เช็คกิจกรรม(ไม่บังคับเข้า)</a></p>
    <p><a href="checkstd.php">เช็คกิจกรรม(บังคับเข้า)</a></p>
    <p><a href="index.php?logout='1'"style="color: red;">logout</a></p>
    <?php endif ?>

</div>

</body>
</html>
