<?php
$where = "";
switch ($_SESSION['usrLevel']) {
    case 1:
        $where = " ((HEAD.dtSubmitDIR = '1000-01-01' AND HEAD.dtSubmitMGR <> '1000-01-01' AND HEAD.dtSubmitSPV <> '1000-01-01') OR 
                    (HEAD.strMailDIR=HEAD.strMailMGR AND HEAD.dtSubmitMGR = '1000-01-01' AND HEAD.dtSubmitSPV <> '1000-01-01') OR 
                    (HEAD.strMailDIR=HEAD.strMailSPV AND HEAD.dtSubmitSPV = '1000-01-01')) AND strMailDIR='" . $_SESSION['strEmail'] . "'
                    ";
        break;
    case 2:
        $where = " ((HEAD.dtSubmitMGR = '1000-01-01' AND HEAD.dtSubmitSPV <> '1000-01-01') OR 
                    (HEAD.strMailMGR=HEAD.strMailSPV AND HEAD.dtSubmitSPV = '1000-01-01')) AND strMailMGR='" . $_SESSION['strEmail'] . "' 
                    ";
        break;
    case 3:
        $where = " HEAD.dtSubmitSPV = '1000-01-01' AND strMailSPV='" . $_SESSION['strEmail'] . "'";
        break;
}

if ($where <> "") {
    $MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
    $query = "SELECT IFNULL(SUM(HEAD.stsAktif), '0') AS iJumlahItem 
            FROM tpc_h_lpbj AS HEAD 
            WHERE " . $where . " AND 
                HEAD.stsAktif = 1 
            "; //echo $query;
    $result = $MySQLi->query($query);
    $row = $result->fetch_array();
}
?>

<ul class="navbar-nav flex-column">
    <li class="nav-divider">
        Menu
    </li>
    <li class="nav-devider ">
        <a class="nav-link active" href="index.php">Dashboard <span class="badge badge-success"><?php echo $row['iJumlahItem']; ?></span></a>
    </li>
    <?php
    if (strtoupper($_SESSION['strJobPosition']) == "ACCOUNTING") {
    ?>
        <li class="nav-item ">
            <a class="nav-link active" href="#" data-toggle="collapse" aria-expanded="false" data-target="#submenu-master" aria-controls="submenu-master"><i class="fa fa-fw fa-user-circle"></i>Master<span class="badge badge-success">6</span></a>
            <div id="submenu-master" class="collapse submenu">
                <ul>
                    <li class="nav-item">
                        <a class="nav-link" href="?menu=master-barang">Master Barang</a>
                    </li>
                </ul>
            </div>
        </li>
    <?php
    }
    ?>
    <li class="nav-item ">
        <a class="nav-link active" href="#" data-toggle="collapse" aria-expanded="false" data-target="#submenu-pembelian" aria-controls="submenu-pembelian"><i class="fa fa-fw fa-user-circle"></i>Pembelian<span class="badge badge-success">1</span></a>
        <div id="submenu-pembelian" class="collapse submenu">
            <ul>
                <li class="nav-item">
                    <a class="nav-link" href="?menu=tambah-lpbj">Tambah LPBJ</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="?menu=laporan-lpbj">Laporan LPBJ</a>
                </li>
            </ul>
        </div>
    </li>
    <li class="nav-item ">
        <a class="nav-link active" href="#" data-toggle="collapse" aria-expanded="false" data-target="#submenu-pengaturan" aria-controls="submenu-pengaturan"><i class="fa fa-fw fa-user-circle"></i>Pengaturan<span class="badge badge-success">3</span></a>
        <div id="submenu-pengaturan" class="collapse submenu">
            <ul class="nav flex-column">
                <li class="nav-item">
                    <a class="nav-link" href="#" data-toggle="collapse" aria-expanded="false" data-target="#submenu-pengaturan-2" aria-controls="submenu-pengaturan-2">Profile</a>
                    <div id="submenu-pengaturan-2" class="collapse submenu" style="">
                        <ul class="nav flex-column">
                            <li class="nav-item">
                                <a class="nav-link" href="?menu=ubah-sandi">Ubah Sandi</a>
                            </li>
                        </ul>
                    </div>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="logout.php">Logout</a>
                </li>
            </ul>
        </div>
    </li>
</ul>