<?php
// admin_kurikulum.php — Admin Dashboard Kurikulum (CRUD penuh + Fullscreen + Bootstrap Dark/Light)
require_once __DIR__.'/config.php';
session_start();
if(!isset($_SESSION['is_admin'])) $_SESSION['is_admin']=true;

function safe($v){ return htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8'); }
$msg='';

/* ===================== PROSES BORANG ===================== */
if($_SERVER['REQUEST_METHOD']==='POST'){
  // ================== JADUAL WAKTU ==================
  if(isset($_POST['tambah_jadual'])){
    $stmt=$mysqli->prepare("INSERT INTO jadual_waktu (hari,masa,kelas,subjek,guru) VALUES (?,?,?,?,?)");
    $stmt->bind_param('sssss',$_POST['hari'],$_POST['masa'],$_POST['kelas'],$_POST['subjek'],$_POST['guru']);
    $msg=$stmt->execute()?"✅ Jadual ditambah":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['kemaskini_jadual'])){
    $stmt=$mysqli->prepare("UPDATE jadual_waktu SET hari=?,masa=?,kelas=?,subjek=?,guru=? WHERE id=?");
    $stmt->bind_param('sssssi',$_POST['hari'],$_POST['masa'],$_POST['kelas'],$_POST['subjek'],$_POST['guru'],$_POST['id']);
    $msg=$stmt->execute()?"✅ Jadual dikemaskini":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['padam_jadual'])){
    $stmt=$mysqli->prepare("DELETE FROM jadual_waktu WHERE id=?");
    $stmt->bind_param('i',$_POST['id']);
    $msg=$stmt->execute()?"🗑️ Jadual dipadam":"❌ ".$stmt->error;
    $stmt->close();
  }

  // ================== PEPERIKSAAN ==================
  if(isset($_POST['tambah_exam'])){
    $stmt=$mysqli->prepare("INSERT INTO peperiksaan (tahun,penggal,gpmp,peratus_lulus) VALUES (?,?,?,?)");
    $stmt->bind_param('isdd',$_POST['tahun'],$_POST['penggal'],$_POST['gpmp'],$_POST['peratus_lulus']);
    $msg=$stmt->execute()?"✅ Peperiksaan ditambah":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['kemaskini_exam'])){
    $stmt=$mysqli->prepare("UPDATE peperiksaan SET tahun=?,penggal=?,gpmp=?,peratus_lulus=? WHERE id=?");
    $stmt->bind_param('isddi',$_POST['tahun'],$_POST['penggal'],$_POST['gpmp'],$_POST['peratus_lulus'],$_POST['id']);
    $msg=$stmt->execute()?"✅ Peperiksaan dikemaskini":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['padam_exam'])){
    $stmt=$mysqli->prepare("DELETE FROM peperiksaan WHERE id=?");
    $stmt->bind_param('i',$_POST['id']);
    $msg=$stmt->execute()?"🗑️ Peperiksaan dipadam":"❌ ".$stmt->error;
    $stmt->close();
  }

  // ================== OPSYEN GURU ==================
  if(isset($_POST['tambah_opsyen'])){
    $stmt=$mysqli->prepare("INSERT INTO guru_opsyen (opsyen,bilangan) VALUES (?,?)");
    $stmt->bind_param('si',$_POST['opsyen'],$_POST['bilangan']);
    $msg=$stmt->execute()?"✅ Opsyen ditambah":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['kemaskini_opsyen'])){
    $stmt=$mysqli->prepare("UPDATE guru_opsyen SET opsyen=?,bilangan=? WHERE id=?");
    $stmt->bind_param('sii',$_POST['opsyen'],$_POST['bilangan'],$_POST['id']);
    $msg=$stmt->execute()?"✅ Opsyen dikemaskini":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['padam_opsyen'])){
    $stmt=$mysqli->prepare("DELETE FROM guru_opsyen WHERE id=?");
    $stmt->bind_param('i',$_POST['id']);
    $msg=$stmt->execute()?"🗑️ Opsyen dipadam":"❌ ".$stmt->error;
    $stmt->close();
  }

  // ================== PENCAPAIAN ==================
  if(isset($_POST['tambah_pencapaian'])){
    $stmt=$mysqli->prepare("INSERT INTO pencapaian (tahun,peperiksaan,pencapaian,kedudukan) VALUES (?,?,?,?)");
    $stmt->bind_param('isss',$_POST['tahun'],$_POST['peperiksaan'],$_POST['pencapaian'],$_POST['kedudukan']);
    $msg=$stmt->execute()?"✅ Pencapaian ditambah":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['kemaskini_pencapaian'])){
    $stmt=$mysqli->prepare("UPDATE pencapaian SET tahun=?,peperiksaan=?,pencapaian=?,kedudukan=? WHERE id=?");
    $stmt->bind_param('isssi',$_POST['tahun'],$_POST['peperiksaan'],$_POST['pencapaian'],$_POST['kedudukan'],$_POST['id']);
    $msg=$stmt->execute()?"✅ Pencapaian dikemaskini":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['padam_pencapaian'])){
    $stmt=$mysqli->prepare("DELETE FROM pencapaian WHERE id=?");
    $stmt->bind_param('i',$_POST['id']);
    $msg=$stmt->execute()?"🗑️ Pencapaian dipadam":"❌ ".$stmt->error;
    $stmt->close();
  }

  // ================== PROGRAM KHAS ==================
  if(isset($_POST['tambah_program'])){
    $stmt=$mysqli->prepare("INSERT INTO program_khas (nama_program,tarikh,keterangan) VALUES (?,?,?)");
    $stmt->bind_param('sss',$_POST['nama_program'],$_POST['tarikh'],$_POST['keterangan']);
    $msg=$stmt->execute()?"✅ Program ditambah":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['kemaskini_program'])){
    $stmt=$mysqli->prepare("UPDATE program_khas SET nama_program=?,tarikh=?,keterangan=? WHERE id=?");
    $stmt->bind_param('sssi',$_POST['nama_program'],$_POST['tarikh'],$_POST['keterangan'],$_POST['id']);
    $msg=$stmt->execute()?"✅ Program dikemaskini":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['padam_program'])){
    $stmt=$mysqli->prepare("DELETE FROM program_khas WHERE id=?");
    $stmt->bind_param('i',$_POST['id']);
    $msg=$stmt->execute()?"🗑️ Program dipadam":"❌ ".$stmt->error;
    $stmt->close();
  }

  // ================== KPI ==================
  if(isset($_POST['tambah_kpi'])){
    $stmt=$mysqli->prepare("INSERT INTO kpi_kurikulum (tahun,sasaran,pencapaian) VALUES (?,?,?)");
    $stmt->bind_param('idd',$_POST['tahun'],$_POST['sasaran'],$_POST['pencapaian']);
    $msg=$stmt->execute()?"✅ KPI ditambah":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['kemaskini_kpi'])){
    $stmt=$mysqli->prepare("UPDATE kpi_kurikulum SET tahun=?,sasaran=?,pencapaian=? WHERE id=?");
    $stmt->bind_param('iddi',$_POST['tahun'],$_POST['sasaran'],$_POST['pencapaian'],$_POST['id']);
    $msg=$stmt->execute()?"✅ KPI dikemaskini":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['padam_kpi'])){
    $stmt=$mysqli->prepare("DELETE FROM kpi_kurikulum WHERE id=?");
    $stmt->bind_param('i',$_POST['id']);
    $msg=$stmt->execute()?"🗑️ KPI dipadam":"❌ ".$stmt->error;
    $stmt->close();
  }

  // ================== PENGUMUMAN ==================
  if(isset($_POST['tambah_ann'])){
    $stmt=$mysqli->prepare("INSERT INTO kurikulum_announcements (tajuk,tarikh) VALUES (?,?)");
    $stmt->bind_param('ss',$_POST['tajuk'],$_POST['tarikh']);
    $msg=$stmt->execute()?"✅ Pengumuman ditambah":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['kemaskini_ann'])){
    $stmt=$mysqli->prepare("UPDATE kurikulum_announcements SET tajuk=?,tarikh=? WHERE id=?");
    $stmt->bind_param('ssi',$_POST['tajuk'],$_POST['tarikh'],$_POST['id']);
    $msg=$stmt->execute()?"✅ Pengumuman dikemaskini":"❌ ".$stmt->error;
    $stmt->close();
  }
  if(isset($_POST['padam_ann'])){
    $stmt=$mysqli->prepare("DELETE FROM kurikulum_announcements WHERE id=?");
    $stmt->bind_param('i',$_POST['id']);
    $msg=$stmt->execute()?"🗑️ Pengumuman dipadam":"❌ ".$stmt->error;
    $stmt->close();
  }
}

/* ===================== AMBIL DATA ===================== */
$jadual=$mysqli->query("SELECT * FROM jadual_waktu ORDER BY hari,masa ASC");
$exam=$mysqli->query("SELECT * FROM peperiksaan ORDER BY tahun DESC,penggal DESC");
$opsyen=$mysqli->query("SELECT * FROM guru_opsyen ORDER BY opsyen ASC");
$pencapaian=$mysqli->query("SELECT * FROM pencapaian ORDER BY tahun DESC");
$program=$mysqli->query("SELECT * FROM program_khas ORDER BY tarikh DESC");
$kpi=$mysqli->query("SELECT * FROM kpi_kurikulum ORDER BY tahun DESC");
$ann=$mysqli->query("SELECT * FROM kurikulum_announcements ORDER BY tarikh DESC");
?>
<!DOCTYPE html>
<html lang="ms">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Admin Kurikulum</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
  body{transition:0.3s;}
  .msg{margin:10px;font-weight:bold;}
  body.dark{background:#121212;color:#eee;}
  body.dark .card{background:#1e1e1e;color:#eee;}
  body.dark .table{color:#eee;}
  body.dark .nav-tabs .nav-link.active{background:#444;color:#fff;}
  th,td{vertical-align:middle;}
  
/* Remove default bootstrap tab styling */
.nav-tabs {
    border-bottom: none !important;
}

.nav-tabs .nav-link {
    background: linear-gradient(45deg, #FFE259, #FFA751) !important;
    color: #000 !important;
    border: none !important;
    border-radius: 8px !important;
    margin-right: 6px;
    padding: 10px 18px;
    font-weight: 600;
}

/* Active tab */
.nav-tabs .nav-link.active {
    background: linear-gradient(45deg, #FFD200, #FFB300) !important;
    color: #000 !important;
    box-shadow: 0 4px 10px rgba(255,193,7,0.4);
}

/* Hover */
.nav-tabs .nav-link:hover {
    filter: brightness(1.12);
}

</style>
</head>
<body>
<div class="container-fluid p-3 bg-primary text-white d-flex justify-content-between align-items-center">
  <h3 class="m-0">📚 Admin Kurikulum</h3>
  <button onclick="toggleTheme()" class="btn btn-light btn-sm">🌙/☀️</button>
</div>

<div class="container-fluid mt-3">
<?php if($msg): ?><div class="alert alert-info"><?=safe($msg)?></div><?php endif; ?>

<!-- Tab Navigation -->
<ul class="nav nav-tabs" role="tablist">
  <li class="nav-item"><button class="nav-link active" data-bs-toggle="tab" data-bs-target="#jadual" type="button">Jadual Waktu</button></li>
  <li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#exam" type="button">Peperiksaan</button></li>
  <li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#opsyen" type="button">Guru Opsyen</button></li>
  <li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#pencapaian" type="button">Pencapaian</button></li>
  <li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#program" type="button">Program Khas</button></li>
  <li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#kpi" type="button">KPI</button></li>
  <li class="nav-item"><button class="nav-link" data-bs-toggle="tab" data-bs-target="#ann" type="button">Pengumuman</button></li>
</ul>

<div class="tab-content mt-3">

  <!-- Jadual -->
  <div class="tab-pane fade show active" id="jadual">
    <div class="card p-3">
      <h5>📘 Jadual Waktu</h5>
      <form method="post" class="row g-2 mb-3">
        <div class="col"><input name="hari" class="form-control" placeholder="Hari"></div>
        <div class="col"><input name="masa" class="form-control" placeholder="Masa"></div>
        <div class="col"><input name="kelas" class="form-control" placeholder="Kelas"></div>
        <div class="col"><input name="subjek" class="form-control" placeholder="Subjek"></div>
        <div class="col"><input name="guru" class="form-control" placeholder="Guru"></div>
        <div class="col"><button class="btn btn-primary w-100" name="tambah_jadual">Tambah</button></div>
      </form>
      <table class="table table-bordered table-striped table-sm">
        <thead class="table-light"><tr><th>Hari</th><th>Masa</th><th>Kelas</th><th>Subjek</th><th>Guru</th><th>Tindakan</th></tr></thead>
        <tbody>
        <?php while($r=$jadual->fetch_assoc()): ?>
          <tr>
            <form method="post" class="d-flex flex-wrap">
              <td><input class="form-control form-control-sm" name="hari" value="<?=safe($r['hari'])?>"></td>
              <td><input class="form-control form-control-sm" name="masa" value="<?=safe($r['masa'])?>"></td>
              <td><input class="form-control form-control-sm" name="kelas" value="<?=safe($r['kelas'])?>"></td>
              <td><input class="form-control form-control-sm" name="subjek" value="<?=safe($r['subjek'])?>"></td>
              <td><input class="form-control form-control-sm" name="guru" value="<?=safe($r['guru'])?>"></td>
              <td>
                <input type="hidden" name="id" value="<?=$r['id']?>">
                <button class="btn btn-primary btn-sm" name="kemaskini_jadual">Simpan</button>
                <button class="btn btn-danger btn-sm" name="padam_jadual" onclick="return confirm('Padam jadual ini?')">Padam</button>
              </td>
            </form>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>

  <!-- Peperiksaan -->
  <div class="tab-pane fade" id="exam">
    <div class="card p-3">
      <h5>📝 Prestasi Peperiksaan</h5>
      <form method="post" class="row g-2 mb-3">
        <div class="col"><input type="number" name="tahun" class="form-control" placeholder="Tahun"></div>
        <div class="col"><input name="penggal" class="form-control" placeholder="Penggal"></div>
        <div class="col"><input type="number" step="0.01" name="gpmp" class="form-control" placeholder="GPMP"></div>
        <div class="col"><input type="number" step="0.01" name="peratus_lulus" class="form-control" placeholder="% Lulus"></div>
        <div class="col"><button class="btn btn-primary w-100" name="tambah_exam">Tambah</button></div>
      </form>
      <table class="table table-bordered table-striped table-sm">
        <thead class="table-light"><tr><th>Tahun</th><th>Penggal</th><th>GPMP</th><th>% Lulus</th><th>Tindakan</th></tr></thead>
        <tbody>
        <?php while($r=$exam->fetch_assoc()): ?>
          <tr>
            <form method="post">
              <td><input class="form-control form-control-sm" type="number" name="tahun" value="<?=$r['tahun']?>"></td>
              <td><input class="form-control form-control-sm" name="penggal" value="<?=safe($r['penggal'])?>"></td>
              <td><input class="form-control form-control-sm" type="number" step="0.01" name="gpmp" value="<?=$r['gpmp']?>"></td>
              <td><input class="form-control form-control-sm" type="number" step="0.01" name="peratus_lulus" value="<?=$r['peratus_lulus']?>"></td>
              <td>
                <input type="hidden" name="id" value="<?=$r['id']?>">
                <button class="btn btn-primary btn-sm" name="kemaskini_exam">Simpan</button>
                <button class="btn btn-danger btn-sm" name="padam_exam" onclick="return confirm('Padam rekod ini?')">Padam</button>
              </td>
            </form>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>

  <!-- Opsyen -->
  <div class="tab-pane fade" id="opsyen">
    <div class="card p-3">
      <h5>👩‍🏫 Guru Opsyen</h5>
      <form method="post" class="row g-2 mb-3">
        <div class="col"><input name="opsyen" class="form-control" placeholder="Opsyen"></div>
        <div class="col"><input type="number" name="bilangan" class="form-control" placeholder="Bilangan"></div>
        <div class="col"><button class="btn btn-primary w-100" name="tambah_opsyen">Tambah</button></div>
      </form>
      <table class="table table-bordered table-striped table-sm">
        <thead class="table-light"><tr><th>Opsyen</th><th>Bilangan</th><th>Tindakan</th></tr></thead>
        <tbody>
        <?php while($r=$opsyen->fetch_assoc()): ?>
          <tr>
            <form method="post">
              <td><input class="form-control form-control-sm" name="opsyen" value="<?=safe($r['opsyen'])?>"></td>
              <td><input class="form-control form-control-sm" type="number" name="bilangan" value="<?=$r['bilangan']?>"></td>
              <td>
                <input type="hidden" name="id" value="<?=$r['id']?>">
                <button class="btn btn-primary btn-sm" name="kemaskini_opsyen">Simpan</button>
                <button class="btn btn-danger btn-sm" name="padam_opsyen" onclick="return confirm('Padam rekod ini?')">Padam</button>
              </td>
            </form>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>

  <!-- Pencapaian -->
  <div class="tab-pane fade" id="pencapaian">
    <div class="card p-3">
      <h5>📈 Pencapaian Akademik</h5>
      <form method="post" class="row g-2 mb-3">
        <div class="col"><input type="number" name="tahun" class="form-control" placeholder="Tahun"></div>
        <div class="col"><input name="peperiksaan" class="form-control" placeholder="Peperiksaan"></div>
        <div class="col"><input name="pencapaian" class="form-control" placeholder="Pencapaian"></div>
        <div class="col"><input name="kedudukan" class="form-control" placeholder="Kedudukan"></div>
        <div class="col"><button class="btn btn-primary w-100" name="tambah_pencapaian">Tambah</button></div>
      </form>
      <table class="table table-bordered table-striped table-sm">
        <thead class="table-light"><tr><th>Tahun</th><th>Peperiksaan</th><th>Pencapaian</th><th>Kedudukan</th><th>Tindakan</th></tr></thead>
        <tbody>
        <?php while($r=$pencapaian->fetch_assoc()): ?>
          <tr>
            <form method="post">
              <td><input class="form-control form-control-sm" type="number" name="tahun" value="<?=$r['tahun']?>"></td>
              <td><input class="form-control form-control-sm" name="peperiksaan" value="<?=safe($r['peperiksaan'])?>"></td>
              <td><input class="form-control form-control-sm" name="pencapaian" value="<?=safe($r['pencapaian'])?>"></td>
              <td><input class="form-control form-control-sm" name="kedudukan" value="<?=safe($r['kedudukan'])?>"></td>
              <td>
                <input type="hidden" name="id" value="<?=$r['id']?>">
                <button class="btn btn-primary btn-sm" name="kemaskini_pencapaian">Simpan</button>
                <button class="btn btn-danger btn-sm" name="padam_pencapaian" onclick="return confirm('Padam rekod ini?')">Padam</button>
              </td>
            </form>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>

  <!-- Program Khas -->
  <div class="tab-pane fade" id="program">
    <div class="card p-3">
      <h5>🌟 Program Khas</h5>
      <form method="post" class="row g-2 mb-3">
        <div class="col"><input name="nama_program" class="form-control" placeholder="Nama Program"></div>
        <div class="col"><input type="date" name="tarikh" class="form-control"></div>
        <div class="col"><input name="keterangan" class="form-control" placeholder="Keterangan"></div>
        <div class="col"><button class="btn btn-primary w-100" name="tambah_program">Tambah</button></div>
      </form>
      <table class="table table-bordered table-striped table-sm">
        <thead class="table-light"><tr><th>Nama</th><th>Tarikh</th><th>Keterangan</th><th>Tindakan</th></tr></thead>
        <tbody>
        <?php while($r=$program->fetch_assoc()): ?>
          <tr>
            <form method="post">
              <td><input class="form-control form-control-sm" name="nama_program" value="<?=safe($r['nama_program'])?>"></td>
              <td><input class="form-control form-control-sm" type="date" name="tarikh" value="<?=$r['tarikh']?>"></td>
              <td><input class="form-control form-control-sm" name="keterangan" value="<?=safe($r['keterangan'])?>"></td>
              <td>
                <input type="hidden" name="id" value="<?=$r['id']?>">
                <button class="btn btn-primary btn-sm" name="kemaskini_program">Simpan</button>
                <button class="btn btn-danger btn-sm" name="padam_program" onclick="return confirm('Padam rekod ini?')">Padam</button>
              </td>
            </form>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>

  <!-- KPI -->
  <div class="tab-pane fade" id="kpi">
    <div class="card p-3">
      <h5>✅ KPI Kurikulum</h5>
      <form method="post" class="row g-2 mb-3">
        <div class="col"><input type="number" name="tahun" class="form-control" placeholder="Tahun"></div>
        <div class="col"><input type="number" step="0.01" name="sasaran" class="form-control" placeholder="Sasaran %"></div>
        <div class="col"><input type="number" step="0.01" name="pencapaian" class="form-control" placeholder="Pencapaian %"></div>
        <div class="col"><button class="btn btn-primary w-100" name="tambah_kpi">Tambah</button></div>
      </form>
      <table class="table table-bordered table-striped table-sm">
        <thead class="table-light"><tr><th>Tahun</th><th>Sasaran</th><th>Pencapaian</th><th>Tindakan</th></tr></thead>
        <tbody>
        <?php while($r=$kpi->fetch_assoc()): ?>
          <tr>
            <form method="post">
              <td><input class="form-control form-control-sm" type="number" name="tahun" value="<?=$r['tahun']?>"></td>
              <td><input class="form-control form-control-sm" type="number" step="0.01" name="sasaran" value="<?=$r['sasaran']?>"></td>
              <td><input class="form-control form-control-sm" type="number" step="0.01" name="pencapaian" value="<?=$r['pencapaian']?>"></td>
              <td>
                <input type="hidden" name="id" value="<?=$r['id']?>">
                <button class="btn btn-primary btn-sm" name="kemaskini_kpi">Simpan</button>
                <button class="btn btn-danger btn-sm" name="padam_kpi" onclick="return confirm('Padam rekod ini?')">Padam</button>
              </td>
            </form>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>

  <!-- Pengumuman -->
  <div class="tab-pane fade" id="ann">
    <div class="card p-3">
      <h5>📢 Pengumuman</h5>
      <form method="post" class="row g-2 mb-3">
        <div class="col"><input name="tajuk" class="form-control" placeholder="Tajuk"></div>
        <div class="col"><input type="date" name="tarikh" class="form-control"></div>
        <div class="col"><button class="btn btn-primary w-100" name="tambah_ann">Tambah</button></div>
      </form>
      <table class="table table-bordered table-striped table-sm">
        <thead class="table-light"><tr><th>Tajuk</th><th>Tarikh</th><th>Tindakan</th></tr></thead>
        <tbody>
        <?php while($r=$ann->fetch_assoc()): ?>
          <tr>
            <form method="post">
              <td><input class="form-control form-control-sm" name="tajuk" value="<?=safe($r['tajuk'])?>"></td>
              <td><input class="form-control form-control-sm" type="date" name="tarikh" value="<?=$r['tarikh']?>"></td>
              <td>
                <input type="hidden" name="id" value="<?=$r['id']?>">
                <button class="btn btn-primary btn-sm" name="kemaskini_ann">Simpan</button>
                <button class="btn btn-danger btn-sm" name="padam_ann" onclick="return confirm('Padam rekod ini?')">Padam</button>
              </td>
            </form>
          </tr>
        <?php endwhile; ?>
        </tbody>
      </table>
    </div>
  </div>

</div> <!-- /tab-content -->
</div> <!-- /container-fluid -->

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
function toggleTheme(){
  document.body.classList.toggle("dark");
  localStorage.setItem("theme",document.body.classList.contains("dark")?"dark":"light");
}
window.onload=function(){
  if(localStorage.getItem("theme")==="dark"){document.body.classList.add("dark");}
};
</script>
</body>
</html>
