<?php 
session_start();
error_reporting(E_ALL);
include "config/koneksi.php";
include "config/library.php";
include "config/fungsi_indotgl.php";
include "config/fungsi_seo.php";

// Cek login
if (!isset($_SESSION['id'])) {
    header("Location: login.php");
    exit;
}

// Ambil data user
$level = $_SESSION['level'];
if ($level=='superuser' || $level=='kepala' || $level=='guru' || $level=='siswa') {
    if ($level=='superuser'){
        $iden = mysqli_fetch_array(mysqli_query(dblink(), "SELECT * FROM rb_users WHERE id_user='".$_SESSION['id']."'"));
        $nama = $iden['nama_lengkap'];
        $foto = 'dist/img/user2-160x160.jpg';
    } elseif ($level=='kepala'){
        $iden = mysqli_fetch_array(mysqli_query(dblink(), "SELECT * FROM rb_users WHERE id_user='".$_SESSION['id']."'"));
        $gu = mysqli_fetch_array(mysqli_query(dblink(), "SELECT * FROM rb_guru WHERE nip='".$iden['username']."'"));
        $nama = $iden['nama_lengkap'];
        $foto = (trim($gu['foto'])=='') ? 'foto_siswa/no-image.jpg' : 'foto_pegawai/'.$gu['foto'];
    } elseif ($level=='guru'){
        $iden = mysqli_fetch_array(mysqli_query(dblink(), "SELECT * FROM rb_guru WHERE nip='".$_SESSION['id']."'"));
        $nama = $iden['nama_guru'];
        $foto = (trim($iden['foto'])=='') ? 'foto_siswa/no-image.jpg' : 'foto_pegawai/'.$iden['foto'];
    } elseif ($level=='siswa'){
        $iden = mysqli_fetch_array(mysqli_query(dblink(), "SELECT * FROM rb_siswa WHERE nisn='".$_SESSION['id']."'"));
        $nama = $iden['nama'];
        $foto = (trim($iden['foto'])=='') ? 'foto_siswa/no-image.jpg' : 'foto_siswa/'.$iden['foto'];
    }
}

// Ambil kurikulum aktif
$kurikulum = mysqli_fetch_array(mysqli_query(dblink(), "SELECT * FROM rb_kurikulum WHERE status_kurikulum='Ya'"));

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Sistem Informasi Akademik Sekolah</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap & AdminLTE -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- Font Awesome & Ionicons -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- Plugins -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <!-- Header -->
    <header class="main-header">
        <?php include "main-header.php"; ?>
    </header>

    <!-- Sidebar -->
    <aside class="main-sidebar">
        <?php include "menu-admin.php"; ?>
    </aside>

    <!-- Content Wrapper -->
    <div class="content-wrapper">
        <section class="content-header">
            <h1>Dashboard <small>Control Panel</small></h1>
        </section>

        <section class="content">
            <?php
            $view = isset($_GET['view']) ? $_GET['view'] : 'home';

            // Home page
            if ($view=='home' || $view==''){
                if ($level=='siswa'){
                    include "application/home_siswa.php";
                } elseif ($level=='guru'){
                    include "application/home_guru.php";
                } else {
                    echo "<div class='row'>";
                    include "application/home_admin_row1.php";
                    echo "</div><div class='row'>";
                    include "application/home_admin_row2.php";
                    echo "</div>";
                }
            }

            // Data Master
            elseif ($view=='identitas') include "application/master_identitas.php";
            elseif ($view=='kurikulum') include "application/master_kurikulum.php";
            elseif ($view=='tahunakademik') include "application/master_tahun_akademik.php";
            elseif ($view=='gedung') include "application/master_gedung.php";
            elseif ($view=='ruangan') include "application/master_ruangan.php";
            elseif ($view=='golongan') include "application/master_golongan.php";
            elseif ($view=='ptk') include "application/master_ptk.php";
            elseif ($view=='jurusan') include "application/master_jurusan.php";
            elseif ($view=='kelas') include "application/master_kelas.php";
            elseif ($view=='statuspegawai') include "application/master_statuspegawai.php";

            // Data Pengguna
            elseif ($view=='siswa') include "application/master_siswa.php";
            elseif ($view=='guru') include "application/master_guru.php";
            elseif ($view=='wakilkepala') include "application/master_wakilkepala.php";
            elseif ($view=='admin') include "application/master_admin.php";

            // Data Akademik
            elseif ($view=='kelompokmapel') include "application/master_kelompokmapel.php";
            elseif ($view=='matapelajaran') include "application/master_matapelajaran.php";
            elseif ($view=='jadwalpelajaran') include "application/master_jadwalpelajaran.php";
            elseif ($view=='bahantugas') include "application/bahan_tugas.php";
            elseif ($view=='kompetensidasar') include "application/master_kompetensidasar.php";
            elseif ($view=='penilaiandiri') include "application/master_penilaiandiri.php";
            elseif ($view=='predikat') include "application/master_predikat.php";
            elseif ($view=='penilaianteman') include "application/master_penilaianteman.php";

            // Absensi
            elseif ($view=='absensiswa') include "application/absensi_siswa.php";
            elseif ($view=='rekapabsensiswa') include "application/absensi_siswa_rekap.php";
            elseif ($view=='absenguru') include "application/absensi_guru.php";

            // Quiz / Forum
            elseif ($view=='soal') include "application/quiz_ujian_soal.php";
            elseif ($view=='forum') include "application/forum_diskusi.php";

            // Raport
            elseif ($view=='raport') include "application/raport.php";
            elseif ($view=='raportuts') include "application/raport_uts.php";
            elseif ($view=='raportcetak') include "application/raport_cetak.php";
            elseif ($view=='raportcetakuts') include "application/raport_cetak_uts.php";
            elseif ($view=='capaianhasilbelajar') include "application/raport/raport_capaian_hasil_belajar.php";
            elseif ($view=='extrakulikuler') include "application/raport/raport_extrakulikuler.php";
            elseif ($view=='prestasi') include "application/raport/raport_prestasi.php";

            // Dokumentasi
            elseif ($view=='dokumentasi') include "application/dokumentasi.php";
            ?>
        </section>
    </div>

    <!-- Footer -->
    <footer class="main-footer">
        <?php include "footer.php"; ?>
    </footer>
</div>

<!-- Scripts -->
<script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="plugins/fastclick/fastclick.min.js"></script>
<script src="dist/js/app.min.js"></script>
<script>
  $(function () {
    $('.sidebar-menu').tree();
    $(".datatable").DataTable();
  });
</script>

</body>
</html>
