<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
    <link rel="stylesheet" href="/public/css/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" href="/public/css/toastify/toastify.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/public/css/resourcemanager/main.css?test=<?= time() ?>">

    <script src="/public/js/jquery/jquery.min.js"></script>
    <script src="/public/js/bootstrap/bootstrap.min.js"></script>
    <script src="/public/js/toastify/toastify.js"></script>
    <script src="/public/js/sweetalert/sweetalert.min.js"></script>
    <script src="/public/js/resourcemanager/common.js?test=<?= time() ?>"></script>
    <?php if ($this->mresourcemanager->isAdmin() && $this->mresourcemanager->isAdminPage()) : ?>
        <script src="/public/js/resourcemanager/admin.js?test=<?= time() ?>"></script>
    <?php else : ?>
        <script src="/public/js/resourcemanager/main.js?test=<?= time() ?>"></script>
    <?php endif; ?>

    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Resource Manager - <?= $title ?></title>
</head>

<body>
    <?php $user = $this->mresourcemanager->getSelectedPartner($_SESSION['partner_id']); ?>

    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand nav-logo" href="<?= $this->mresourcemanager->isAdmin() ? '/resourcemanager_live/reference' : '/resourcemanager' ?>"><img src="/public/img/resourcemanager/ARCHLineXP_ResourceManager_logo_01.png"></a>
                <h3>LIVE</h3>
            </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li class="icon-list <?= $active == 'help' ? 'active' : '' ?>"><a class="navbar-brand" href="/resourcemanager_live/help"><span class="fa fa-question-circle fa-2x custom-icon <?= $active == 'help' ? 'active-icon' : '' ?>"></span></a></li>

                    <?php if ($this->mresourcemanager->isAdmin()) : ?>
                        <li class="dropdown <?= $this->mresourcemanager->isAdminPage() && $active != 'reference' ? 'active' : '' ?>">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Admin <span class="caret"></span></a>

                            <ul class="dropdown-menu">
                                <?php foreach ($this->mresourcemanager->admin_pages_live as $key => $value) : ?>
                                    <li class="<?= site_url($_SERVER['REQUEST_URI']) == $key ? 'active' : '' ?>">
                                        <a href="<?= $key ?>"><?= $value ?></a>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                        </li>
                    <?php endif; ?>

                    <?php if ($this->mresourcemanager->isAdmin()) : ?>
                        <li class="dropdown <?= $active == 'index' || $active == 'reference' ? 'active' : '' ?>">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                <img class="flag-icon" src="<?= $active == 'reference' ? '/public/img/resourcemanager/Globe_icon.png' : $user->flag ?>" /> Resources <span class="caret"></span>
                            </a>
                            <ul class="dropdown-menu">
                                <li class="<?= $active == 'reference' ? 'active' : '' ?>">
                                    <a href="/resourcemanager_live/reference">
                                        <img class="flag-icon" src="/public/img/resourcemanager/Globe_icon.png" /> Master
                                    </a>
                                </li>

                                <?php foreach ($this->mresourcemanager->getPartners() as $partner) : ?>
                                    <?php if ($this->mresourcemanager->tableExist($partner->username)) : ?>
                                        <li class="<?= ($partner_id == $partner->username && $active == 'index') ? 'active' : '' ?>">
                                            <a href="/resourcemanager_live/index/<?= $partner->username ?>/1">
                                                <img class="flag-icon" src="<?= $partner->flag ?>" /> <?= $partner->name ?>
                                            </a>
                                        </li>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </ul>
                        </li>
                    <?php else : ?>
                        <li class="<?= $active == 'index' ? 'active' : '' ?>"><a href="/resourcemanager_live/index"><img class="flag-icon" src="<?= $user->flag ?>" /> Home</a></li>
                    <?php endif; ?>

                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">User<?= $this->mresourcemanager->isAdmin() ? ': Admin' : '' ?> <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a class="menu-without-link" data-toggle="modal" data-target="#userModal">User Profile</a></li>
                            <li><a id="logout-btn" href="/resourcemanager/logout">Logout</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div id="userModal" class="modal fade" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Edit user profile</h4>
                </div>
                <div class="modal-body">
                    <?php
                    $resData['partner'] = $this->mresourcemanager->getSelectedPartner($this->phpsession->get('access_id'));
                    $this->load->view('resourcemanager/includes/user_profile.php', $resData);
                    ?>
                </div>
                <div class="modal-footer">
                    <button type="button" id="btn-save-profile" class="btn btn-success">Save</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>