<?php 
session_start();
include '../koneksi.php';
$allowed_status = array('administrator_logedin', 'input_pengeluaran_logedin');
if(!isset($_SESSION['status']) || !in_array($_SESSION['status'], $allowed_status)){
  header("location:../index.php?alert=belum_login");
  exit();
}
$is_input_pengeluaran = ($_SESSION['status'] === 'input_pengeluaran_logedin');
// Role input_pengeluaran tidak boleh akses halaman setting/rekening/kategori/user
if ($is_input_pengeluaran) {
  $forbidden = array('bank.php','bank_act.php','bank_update.php','bank_hapus.php','kategori.php','kategori_act.php','kategori_update.php','kategori_hapus.php','user.php','user_tambah.php','user_edit.php','user_update.php','user_act.php','user_hapus.php','setting_profil.php','setting_profil_update.php');
  $current = basename($_SERVER['PHP_SELF']);
  if (in_array($current, $forbidden)) {
    header('Location: index.php');
    exit;
  }
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Administrator - Sistem Informasi Keuangan</title>
  
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="../assets/bower_components/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="../assets/bower_components/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="../assets/bower_components/Ionicons/css/ionicons.min.css">
  <link rel="stylesheet" href="../assets/dist/css/AdminLTE.min.css">

  <link rel="stylesheet" href="../assets/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">

  <link rel="stylesheet" href="../assets/dist/css/skins/_all-skins.min.css">
  <link rel="stylesheet" href="../assets/bower_components/morris.js/morris.css">
  <link rel="stylesheet" href="../assets/bower_components/jvectormap/jquery-jvectormap.css">
  <link rel="stylesheet" href="../assets/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
  <link rel="stylesheet" href="../assets/bower_components/bootstrap-daterangepicker/daterangepicker.css">
  <link rel="stylesheet" href="../assets/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css">
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
  <!-- SweetAlert2 -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
  <style>
    /* Custom CSS untuk memperbesar SweetAlert */
    .swal2-popup {
      font-size: 1.6rem !important;
      padding: 2.5rem !important;
    }
    .swal2-title {
      font-size: 2.2rem !important;
      margin-bottom: 1.5rem !important;
    }
    .swal2-content {
      font-size: 1.6rem !important;
      line-height: 1.6 !important;
    }
    .swal2-confirm, .swal2-cancel {
      font-size: 1.4rem !important;
      padding: 0.8rem 2rem !important;
      border-radius: 0.5rem !important;
    }
    .swal2-icon {
      width: 6rem !important;
      height: 6rem !important;
      margin: 1.5rem auto 2rem !important;
    }
    .swal2-icon .swal2-icon-content {
      font-size: 4rem !important;
    }
    .swal2-close {
      font-size: 2rem !important;
      width: 2.5rem !important;
      height: 2.5rem !important;
    }
  </style>

</head>
<body class="sidebar-mini sidebar-collapse skin-green-light">

  <style>
    #table-datatable {
      width: 100% !important;
    }
    #table-datatable .sorting_disabled{
      border: 1px solid #f4f4f4;
    }
  </style>
  <div class="wrapper">

    <header class="main-header">
      <a href="index.php" class="logo">
        <span class="logo-mini"><b><i class="fa fa-money"></i></b> </span>
        <span class="logo-lg"><b>Keuangan</b>App</span>
      </a>
      <nav class="navbar navbar-static-top">
        <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
          <span class="sr-only">Toggle navigation</span>
        </a>

        <div class="navbar-custom-menu">
          <ul class="nav navbar-nav">

            <li class="dropdown user user-menu">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <?php 
                $id_user = $_SESSION['id'];
                $profil = mysqli_query($koneksi,"select * from user where user_id='$id_user'");
                $profil = mysqli_fetch_assoc($profil);
                if($profil['user_foto'] == ""){ 
                  ?>
                  <img src="../gambar/sistem/user.png" class="user-image">
                <?php }else{ ?>
                  <img src="../gambar/user/<?php echo $profil['user_foto'] ?>" class="user-image">
                <?php } ?>
                <span class="hidden-xs"><?php echo $_SESSION['nama']; ?> - <?php echo $_SESSION['level']; ?></span>
              </a>
            </li>
            <li>
              <a href="logout.php"><i class="fa fa-sign-out"></i> LOGOUT</a>
            </li>
          </ul>
        </div>
      </nav>
    </header>

    <aside class="main-sidebar">
      <section class="sidebar">
        <div class="user-panel">
          <div class="pull-left image">
            <?php 
            $id_user = $_SESSION['id'];
            $profil = mysqli_query($koneksi,"select * from user where user_id='$id_user'");
            $profil = mysqli_fetch_assoc($profil);
            if($profil['user_foto'] == ""){ 
              ?>
              <img src="../gambar/sistem/user.png" class="img-circle">
            <?php }else{ ?>
              <img src="../gambar/user/<?php echo $profil['user_foto'] ?>" class="img-circle" style="max-height:45px">
            <?php } ?>
          </div>
          <div class="pull-left info">
            <p><?php echo $_SESSION['nama']; ?></p>
            <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
          </div>
        </div>

        <ul class="sidebar-menu" data-widget="tree">
          <li class="header">MAIN NAVIGATION</li>

          <li>
            <a href="index.php">
              <i class="fa fa-dashboard"></i> <span>DASHBOARD</span>
            </a>
          </li>

          <?php if (!$is_input_pengeluaran): ?>
          <li>
            <a href="bank.php">
              <i class="fa fa-gears"></i> <span>SETTING REKENING</span>
            </a>
          </li>

          <li>
            <a href="kategori.php">
              <i class="fa fa-navicon"></i> <span>DATA KATEGORI</span>
            </a>
          </li>
          <?php endif; ?>

          <li>
            <a href="transaksi.php">
              <i class="fa fa-file-word-o"></i> <span>DATA TRANSAKSI</span>
            </a>
          </li>

          <li>
            <a href="pembayaran_tunai.php">
              <i class="fa fa-money"></i> <span>PEMBAYARAN TUNAI (KASIR)</span>
            </a>
          </li>

          <li>
            <a href="laporan.php">
              <i class="fa fa-file"></i> <span>LAPORAN ARUS KAS</span>
            </a>
          </li>

          <li>
            <a href="laporan_labarugi.php">
              <i class="fa fa-line-chart"></i> <span>LAPORAN LABA RUGI</span>
            </a>
          </li>

          <?php if (!$is_input_pengeluaran): ?>
          <li class="treeview">
            <a href="#">
              <i class="fa fa-user-plus"></i>
              <span>DATA PENGGUNA</span>
              <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
            </a>
            <ul class="treeview-menu" style="display: none;">
              <li><a href="user.php"><i class="fa fa-circle-o"></i> Data Pengguna</a></li>
              <li><a href="user_tambah.php"><i class="fa fa-circle-o"></i> Tambah Pengguna</a></li>
            </ul>
          </li>

          <li>
            <a href="setting_profil.php">
              <i class="fa fa-building"></i> <span>SETTING PROFIL</span>
            </a>
          </li>
          <?php endif; ?>

          <li>
            <a href="gantipassword.php">
              <i class="fa fa-lock"></i> <span>GANTI PASSWORD</span>
            </a>
          </li>

          <li>
            <a href="logout.php">
              <i class="fa fa-sign-out"></i> <span>LOGOUT</span>
            </a>
          </li>
          
        </ul>
      </section>
      <!-- /.sidebar -->
    </aside>
