<?php
    include('../loginsession.php');
    error_reporting(E_ALL);
    $filename = __FILE__;  //---Nama file saat ini
    if (strlen(__FILE__) > 48) {$filename = substr(__FILE__, 48);}
    $save = mysqli_query($conn, "INSERT INTO novia_abc_user_logs (userid,filename) VALUES ('$userini_id','$filename')");
//-------------
    if(isset($_GET['check'])){
        $check = $_GET['check'];
    }
    if ($check == "2" && $userini_id == "3"){
        $check = "1";
    }
    if ($check == "2" && $userini_id != "3"){
        $check = "0";
    }
//-------------

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//ID" "http://www.w3.org/TR/html4/frameset.dtd">
<html lang="id">
<head>
	<title>CATATAN PERSONAL</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="../css/style.css">
	<link href="../images/balance.ico" rel="icon" type="image/icon" />
	
<style>
    *{
        box-sizing:border-box;
        margin:0;
        padding:0;
    }

    body{
        font-family: "Segoe UI", Tahoma, sans-serif;
        background:
            linear-gradient(rgba(20,20,20,0.75), rgba(20,20,20,0.75)),
            url('../images/bg_brown_01.jpg');
        background-size:cover;
        background-position:center;
        background-attachment:fixed;
        color:#f1f1f1;
        padding:15px;
    }

    a{
        text-decoration:none;
        color:inherit;
        transition:0.3s;
    }

    a:hover{
        color:#ffd369;
    }

    .container{
        max-width:1200px;
        margin:auto;
    }

    /* ======================
       HEADER
    ====================== */

    .title-box{
        text-align:center;
        margin:25px 0 25px 0;
    }

    h1{
        font-size:48px;
        color:#ffffff;
        letter-spacing:3px;
        margin-bottom:5px;
        text-shadow:2px 2px 10px rgba(0,0,0,0.6);
    }

    h2{
        font-size:24px;
        color:#ffd369;
        font-weight:400;
        letter-spacing:5px;
    }

    /* ======================
       NAVIGATION BUTTON
    ====================== */

    .nav-table{
        width:100%;
        border-collapse:separate;
        border-spacing:10px;
        margin-bottom:10px;
        border:none;
    }
    .nav-table td{
        border:none;
    }

    .nav-btn{
        width:100%;
        padding:14px;
        border:none !important;
        outline:none !important;
        border-radius:12px;
        background:linear-gradient(135deg,#4b79a1,#283e51);
        color:white;
        font-size:15px;
        font-weight:bold;
        cursor:pointer;
        transition:0.3s;
    }

    .nav-btn:hover{
        transform:translateY(-2px);
        background:linear-gradient(135deg,#5d63d8,#9fa4ff);
        border:none;
    }

    /* ======================
       FORM
    ====================== */

    .form-box{
        background:rgba(255,255,255,0.08);
        backdrop-filter:blur(10px);
        border-radius:18px;
        padding:20px;
        margin-bottom:25px;
        box-shadow:0 6px 25px rgba(0,0,0,0.35);
        border:1px solid rgba(255,255,255,0.08);
    }

    textarea{
        width:100%;
        min-height:120px;
        resize:vertical;
        border:none;
        border-radius:14px;
        padding:15px;
        font-size:15px;
        background:rgba(255,255,255,0.12);
        color:#fff;
        outline:none;
        margin-bottom:15px;
    }

    textarea::placeholder{
        color:#ddd;
    }

    input[type="text"]{
        width:100%;
        padding:12px;
        border:none;
        border-radius:10px;
        background:rgba(255,255,255,0.12);
        color:#fff;
        outline:none;
        font-size:14px;
    }

    input[type="submit"]{
        width:100%;
        padding:12px;
        border:none;
        border-radius:10px;
        background:linear-gradient(135deg,#00b09b,#96c93d);
        color:#fff;
        font-size:15px;
        font-weight:bold;
        cursor:pointer;
        transition:0.3s;
    }

    input[type="submit"]:hover{
        transform:scale(1.02);
        opacity:0.95;
    }
    .form-flex{
        display:flex;
        gap:10px;
    }
    /*
    .form-grid{
        display:grid;
        grid-template-columns:1fr 180px;
        gap:10px;
    }
    /*

    /* ======================
       TABLE
    ====================== */

    .table-wrapper{
        overflow-x:auto;
        border-radius:18px;
        box-shadow:0 6px 25px rgba(0,0,0,0.35);
    }

    .diary-table{
        width:100%;
        border-collapse:collapse;
        overflow:hidden;
        background:rgba(255,255,255,0.08);
        backdrop-filter:blur(10px);
    }

    .diary-table th{
        background:linear-gradient(135deg,#232526,#414345);
        color:#fff;
        padding:14px;
        text-align:left;
        font-size:14px;
        letter-spacing:1px;
        border:none;
    }

    .diary-table td{
        padding:14px;
        border-bottom:1px solid rgba(255,255,255,0.08);
        color:#f5f5f5;
        vertical-align:top;
        font-size:14px;
    }

    .diary-table tr:nth-child(even){
        background:rgba(255,255,255,0.03);
    }

    .diary-table tr:hover{
        background:rgba(255,255,255,0.08);
        transition:0.3s;
    }

    .date-link{
        color:#ffd369;
        font-weight:bold;
    }

    .note-text{
        color:#ffffff;
        line-height:1.6;
    }

    .user-tag{
        color:#8be9fd;
        font-weight:bold;
    }

    /* ======================
       CHECKBOX
    ====================== */

    .checkbox-area{
        margin-bottom:15px;
        text-align:center;
    }

    input[type="checkbox"]{
        transform:scale(1.3);
        cursor:pointer;
    }

    /* ======================
       MOBILE
    ====================== */

    @media(max-width:768px){

        h1{
            font-size:34px;
        }

        h2{
            font-size:18px;
        }

        .form-grid{
            grid-template-columns:1fr;
        }

        .diary-table th,
        .diary-table td{
            font-size:13px;
            padding:10px;
        }

        .nav-btn{
            font-size:13px;
            padding:12px;
            border:none;
        }
    }
</style>
	
</head>

<body>

<div class="container">

    <table class="nav-table">
        <tr>
            <td>
                <a href="../administrasi.php">
                    <button class="nav-btn">PUSAT NAVIGASI</button>
                </a>
            </td>

            <td>
                <a href="../index.php">
                    <button class="nav-btn">HOME</button>
                </a>
            </td>
        </tr>
    </table>

    <div class="title-box">
        <h1>CATATAN</h1>
        <h2>HARIAN</h2>
    </div>
     <div class="checkbox-area">
            <?php
                if($userini_id == "3" && $check =="0"){
            ?>
                <input type="checkbox" id="checkIndex">
            <?php
                }
    
                if($userini_id == "3" && $check =="1"){
            ?>
                <input type="checkbox" id="checkIndex" checked>
            <?php
                }
            ?>
        </div>
    <form method="post" action="">

        <div class="form-box">

   

            <textarea name="note" placeholder="Tulis catatan di sini..."></textarea>

            <div class="form-flex">

                <input type="text"
                       name="TglJam"
                       autocomplete="off"
                       value="<?php echo date("Y-m-d H:i:s")?>"/>

                <input type="submit" name="submit" value="SIMPAN">

            </div>

        </div>

    </form>

    <div class="table-wrapper">

        <table class="diary-table">

            <tr>
                <th width="90">Tanggal</th>
                <th>Catatan</th>
                <th>By</th>
            </tr>
        
<?php
    $mark = "";
    
    if (isset($_POST['note'])) {
        $note=$_POST['note'];
    } else {
        $note='';
    }
    if (isset($_POST['TglJam'])) {
        $TglJam=$_POST['TglJam'];
    }
    if (isset($_POST['submit']) && !empty($_POST['note'])) {
        if ($userini_id == "3" && $check == "1"){
            $mark = "@";
        }
        $save = mysqli_query($conn, "INSERT INTO novia_abc_diary (tanggal, userid, note, mark) VALUES ('$TglJam', '$userini_id', '$note', '$mark')");
        if($save && $check == "0"){ 
            echo "<script>document.location='index.php?check=0'</script>";
            
        }
        if($save && $check == "1"){ 
            echo "<script>document.location='index.php?check=1'</script>";
            
        }   
    }
    
    $no = "0";
    $sql = "SELECT * FROM novia_abc_diary ORDER BY tanggal DESC";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $id = $row['id'];
            $Mark = $row['mark'];
            $User = $row['userid'];
            if (isset($USERNAME[$User])) {
                $user = $USERNAME[$User];
            } else {
                $user = "Unknown"; // fallback jika userid tidak ada
            }
            if ( ( $userini_id == "3" && $check == "0" ) || ( $userini_id == "3" && $check == "1" && $Mark == "@"  ) || ( $userini_id != "3" && $Mark == "" )){
                $no ++;
                
                $Tanggal = new Datetime($row['tanggal']);
                $tanggal = $Tanggal->format('Y-m-d');
                $Hari = $Tanggal -> format('l');
                $hari = $HARI[$Hari];
                ?>

<tr>

    <td align="center">
        <a class="date-link"
           href="note_edit.php?id=<?php echo $id; ?>&check=<?php echo $check; ?>">
           <?php echo $hari.'<br>'.$tanggal; ?>
        </a>
    </td>

    <td>
        <a class="note-text"
           href="note_edit.php?id=<?php echo $id; ?>&check=<?php echo $check; ?>">
           <?php echo $row['note']; ?>
        </a>
    </td>

    <td class="user-tag">
        <?php echo $user; ?>
    </td>
</tr>
                
                
                <?php
            }
            
        }
    }
?>


    </table>
</div>

</div>

<script>
document.getElementById("checkIndex").addEventListener("change", function () {

    if (this.checked) {
        window.location.href = "index.php?check=1";
    } else {
        window.location.href = "index.php?check=0";
    }

});
</script>

</body>
</html>
