<!-- START HEADER -->
<header id="header" class="page-topbar">
    <!-- start header nav-->
    <div class="navbar-fixed">
        <nav class="navbar-color">
            <div class="nav-wrapper">
                <ul class="left">
                    <li>
                        <h1 class="logo-wrapper">
                            <a href="<?= PROJECT_URL ?>admin/index.php" style="margin: 0px 50px;" class="logo"><img
                                    style="width: 92%;"
                                    src="<?= PROJECT_URL ?>images/header-logo.png"
                                    alt="<?= PROJECT_NAME ?>"></a>
                            <span class="logo-text"><?= PROJECT_NAME ?></span></h1></li>
                </ul>
                <ul class="right hide-on-med-and-down">
                    <li><a href="javascript:void(0);" class="waves-effect waves-block waves-light toggle-fullscreen"><i
                                class="mdi-action-settings-overscan"></i></a>
                    </li>
                    <?php if ($_SESSION['sess_type'] == 'administrator') { ?>
                    <li><a href="javascript:void(0);" class="waves-effect waves-block waves-light notification-button"
                           data-activates="notifications-dropdown"><i class="mdi-social-notifications">
                                <small class="notification-badge">5</small>
                            </i></a></li>
                    <?php } ?>
                    <li>
                        <a class="waves-effect waves-block waves-light notification-button" href="#"
                           data-activates="profile-dropdown">
                            <?= ucfirst($_SESSION['sess_username']); ?>
                            <i class="mdi-navigation-arrow-drop-down right"></i>
                        </a>
                    </li>
                </ul>
                <!-- notifications-dropdown -->
                <?php if ($_SESSION['sess_type'] == 'administrator') { ?>
                <ul id="notifications-dropdown" class="dropdown-content">
                    <li>
                        <h5>NOTIFICATIONS <span class="new badge">5</span></h5>
                    </li>
                    <li class="divider"></li>

                    <?php
                    $datefromnot = date('Y-m-d', strtotime("-30 days"));
                    $datetonot = date('Y-m-d');
                    $filterPayments = " WHERE DATE_FORMAT(inv.create_date,'%Y-%m-%d')>='$datefromnot' and DATE_FORMAT(inv.create_date,'%Y-%m-%d')<='$datetonot' AND inv.status <> 'Draft' ";
                    $filterPayments .= " UNION SELECT 'payment' AS nameTable, pay.create_date, pay.code, pay.customer_id, pay.invoice_reference_code, pay.payment_type, pay.amount,
pay.cheque_bank_name, pay.cheque_number, pay.cheque_payee_name, pay.cheque_date, pay.bank_name, pay.bank_account_number, pay.party_name, pay.from_bank_name,
'', '', '','', '', '' from " . TABLE_PAYMENT . " AS pay WHERE DATE_FORMAT(pay.create_date,'%Y-%m-%d')>='$datefromnot' and DATE_FORMAT(pay.create_date,'%Y-%m-%d')<='$datetonot' ";


                    $filterPayments .= " ORDER BY create_date DESC LIMIT 5";
                    $qry = Invoice::GetInvoicePaymentReportLists($filterPayments);
                    if ($qry) {
                        foreach ($qry as $qery) { ?>
                            <li>
                                <a href="#!"><i class="mdi-action-payment"></i>
                                    <?php
                                    echo "A new " . $qery->nameTable;
                                    if ($qery->status == 'Cancel') {
                                        echo ' canceled.';
                                    } else {
                                        echo " generated!";
                                    }
                                    ?>
                                </a>
                                <time class="media-meta" datetime="2015-06-12T20:50:48+08:00">
                                    <?= Helper::ago(strtotime($qery->create_date)); ?>
                                </time>
                                <?php
                                if ($qery->nameTable == 'invoice') {
                                    echo '<label class="right">Rs ' . $qery->total_amount . '</label>';
                                } else if ($qery->nameTable == 'payment') {
                                    echo '<label class="right">Rs ' . $qery->amount . '</label>';
                                }
                                ?>
                            </li>
                        <?php }
                    } ?>
                </ul>
                <?php } ?>
                <!-- notifications-dropdown -->
                <ul id="profile-dropdown" class="dropdown-content navig" style="right: 0px;">
                    <li><a class="black-text" href="<?= PROJECT_ADMIN_URL ?>change_pwd.php"><i
                                class="mdi-action-face-unlock"></i> Profile</a>
                    </li>
                    <?php
                    if ($_SESSION['sess_type'] == 'administrator') {
                        ?>
                        <li><a class="black-text" href="<?= PROJECT_ADMIN_URL ?>setting.php"><i
                                    class="mdi-action-settings"></i> Settings</a>
                        </li>
                        <?php
                    }
                    ?>

                    <li class="divider"></li>
                    <li><a href="<?= PROJECT_ADMIN_URL ?>controller/login_ctl.php?action=2"><i
                                class="mdi-hardware-keyboard-tab"></i> Logout</a>
                    </li>
                </ul>
            </div>
        </nav>
    </div>
    <!-- end header nav-->
</header>
<!-- END HEADER -->
<?php
$myvalue = $_SERVER['REQUEST_URI'];
$arr = explode('?', trim($myvalue));
$arr[0];
$TotalMenu = Menu::GetMenuList();
if ($TotalMenu) {
    foreach ($TotalMenu AS $Menu) {
        $MenuValue = $Menu->url;
        $Value = explode('?', trim($MenuValue));
        $FinalValue[] = $Value[0];
    }
}
if ($FinalValue) {
    if (in_array($arr[0], $FinalValue)) {
        $Page = Menu::GetSelectedMenu($_SESSION['sess_userid']);
        $Pages = $Page->menu_id;

        $GetMenuFilter = " WHERE FIND_IN_SET(menu_id, '" . $Pages . "') ";
        $ShowMenu = Menu::GetMenuList($GetMenuFilter);
        foreach ($ShowMenu AS $menu) {
            $menuvalue = $menu->url;
            $value = explode('?', trim($menuvalue));
            $finalvalue[] = $value[0];

        }
        if (in_array($arr[0], $finalvalue)) {
            //echo "Done";
        } else {
            header('Location: /admin/dboardorderslists.php');
        }
    }
}

//$pagename = basename($_SERVER['PHP_SELF']);
$pagename = $_SERVER['REQUEST_URI'];
$pagename = explode('/', $pagename);


?>

<!-- START MAIN -->
<div id="main">
    <!-- START WRAPPER -->
    <div class="wrapper">

        <!-- START LEFT SIDEBAR NAV-->
        <aside id="left-sidebar-nav">
            <div>
                <?php
                //Menu
                $ShowselectedMenu = Menu::GetSelectedMenu($_SESSION['sess_userid']);
                $ShowMenuSelecteds = $ShowselectedMenu->menu_id;
                $ShowMenuSelected = explode(",", $ShowMenuSelecteds);
                $count = count($ShowMenuSelected);
                for ($i = 0; $i < $count; $i++) {
                    $ShowMenuSelected[$i];
                }
                //echo $ShowMenuSelected['1'];
                $i = 0;
                echo '<ul id="slide-out" class="side-nav leftside-navigation">';
                // piece1
                $Showfilter = " WHERE FIND_IN_SET(menu_id, '" . $ShowMenuSelecteds . "') AND parent_id = '0' AND status <> '0' ORDER BY menu_order";
                $ShowParentmenu = Menu::GetMenuList($Showfilter);
                foreach ($ShowParentmenu as $Showrow_menu) {
                    //echo $row_menu->name;
                    if ($i == 0) {
                        $icon = '<i class="mdi-action-dashboard"></i>';
                    } else if ($i % 2 == 0) {
                        $icon = '<i class="mdi-image-grid-on"></i>';
                    } else {
                        $icon = '<i class="mdi-image-grid-off"></i>';
                    }

                    $pageArray[] = $Showrow_menu->url;
                    if ($Showrow_menu->url == "#") {
                        echo '<li class="no-padding"><ul class="collapsible collapsible-accordion"><li class="bold"><a class="collapsible-header  waves-effect waves-cyan" class="a_setup ">' . $icon . '<span>' . $Showrow_menu->name . '</span></a>';
                    } else {
                        echo '<li class="bold"><a class=" waves-effect waves-cyan" href="' . PROJECT_ADMIN_URL . $Showrow_menu->url . '" class="a_setup ">' . $icon . '<span>' . $Showrow_menu->name . '</span></a>';
                    }
                    $i++;
                    $Showfilter = " WHERE FIND_IN_SET(menu_id, '" . $ShowMenuSelecteds . "') AND parent_id = '" . $Showrow_menu->menu_id . "' AND status <> '0' ORDER BY menu_order";
                    $ShowSubmenu = Menu::GetMenuList($Showfilter);
                    if ($ShowSubmenu) {
                        echo '<div class="collapsible-body"><ul>';
                    }
                    if ($ShowSubmenu) {
                        foreach ($ShowSubmenu as $Showrow_menu) {
                            $pageArray[] = $Showrow_menu->url;
                            if ($Showrow_menu->url == "#") {
                                echo '<li><a class="collapsible-header  waves-effect waves-cyan" class="a_setup ">' . $Showrow_menu->name . '</a>';
                            } else {
                                echo '<li><a class="  waves-effect waves-cyan" href="' . PROJECT_ADMIN_URL . $Showrow_menu->url . '" class="a_setup ">' . $Showrow_menu->name . '</a>';
                            }

                            $Showfilter = " WHERE FIND_IN_SET(menu_id, '" . $ShowMenuSelecteds . "') AND parent_id = '" . $Showrow_menu->menu_id . "' AND status <> '0' ORDER BY menu_order";
                            $ShowSubInnermenu = Menu::GetMenuList($Showfilter);
                            if ($ShowSubInnermenu) {
                                echo '<div class="collapsible-body"><ul>';
                            }
                            if ($ShowSubInnermenu) {
                                foreach ($ShowSubInnermenu as $Showrow_menu) {
                                    $pageArray[] = $Showrow_menu->url;
                                    echo '<li class="bold"><a href="' . PROJECT_ADMIN_URL . $Showrow_menu->url . '" class="a_setup ">' . $Showrow_menu->name . '</a>';
                                }
                            }
                            if ($ShowSubInnermenu) {
                                echo '</li></ul></div>';
                            }
                        }
                    }
                    if ($ShowSubmenu) {
                        echo '</li></ul></div>';
                    }
                }
                if (!empty($ShowParentsmenu)) {
                    echo '</ul></li></li></ul>';
                }
                //Menu
                if ($FinalValue) {
                    if (in_array($pagename, $FinalValue)) {
                        if (!in_array($pagename, $pageArray)) {
                            echo '<script>window.location="' . PROJECT_ADMIN_URL . 'dboardorderslist.php";</script>';
                        }
                    }
                }
                ?>
            </div>
            <a href="#" data-activates="slide-out" style="display: block!important;"
               class="sidebar-collapse btn-floating btn-medium waves-effect waves-light hide-on-large-only cyan"><i
                    class="mdi-navigation-menu"></i></a>
        </aside>
        <!-- END LEFT SIDEBAR NAV-->