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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="/public/css/site.css?time=<?= time() ?>">

    <script src="/public/js/jquery/jquery.min.js"></script>
    <script src="/public/js/bootstrap/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>
    <script src="/public/js/sweetalert/sweetalert.min.js"></script>

    <?php if ($isAdmin) : ?>
        <script src="/public/js/admin.js?time=<?= time() ?>"></script>
    <?php endif; ?>

    <?php if ($active == 'trialusage') : ?>
        <link rel="stylesheet" href="/public/css/bootstrap/bootstrap-datepicker.min.css">

        <script src="/public/js/bootstrap/bootstrap-datepicker.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
        <script src="/public/js/program_usage.js?time=<?= time() ?>"></script>
    <?php endif; ?>

    <?php if ($active == 'trialrequests') : ?>
        <link rel="stylesheet" href="/public/css/bootstrap/bootstrap-datepicker.min.css">

        <script src="/public/js/bootstrap/bootstrap-datepicker.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
        <script src="/public/js/trialrequests.js?time=<?= time() ?>"></script>
    <?php endif; ?>

    <?php if ($active == 'index') : ?>
        <script src="/public/js/weborder.js?time=<?= time() ?>"></script>
    <?php endif; ?>

    <title><?= $title ?></title>
</head>

<body class="<?= $active ?>">
    <nav class="navbar navbar-default navbar-fixed-top sticky">
        <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="/partners">Home</a>
            </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <li class="<?= $active == 'index' ? 'active' : '' ?>"><a href="/weborder/index">Retail Store</a></li>
                    <li class="<?= $active == 'orders' ? 'active' : '' ?>"><a href="/weborder/orders">My Orders</a></li>
                    <li><a href="/partners/bugtracker">Bug Tracker Database</a></li>
                    <li><a href="/partners/keys">Product Key Database</a></li>
                    <?php if ($access->rm_access == 1) : ?>
                        <li><a href="/resourcemanager/index">Resource Manager</a></li>
                    <?php endif; ?>

                    <li class="<?= $active == 'trialusage' ? 'active' : '' ?>"><a href="/trialusage">Diagrams</a></li>

                    <?php if ($isAdmin) : ?>
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Distributors <span class="caret"></span></a>
                            <ul id="distributor-menu" class="dropdown-menu">
                                <?php foreach ($partners as $partner) : ?>
                                    <li class="<?= $username == $partner->username ? 'active' : '' ?>">
                                        <a href="/weborder/changeDistributor/<?= $partner->id ?>/<?= $url ?>">
                                            <?= $partner->username ?>
                                        </a>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                        </li>
                    <?php endif; ?>

                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">User: <?= $username ?> <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <?php if ($isAdmin) : ?>
                                <li><a data-toggle="modal" data-target="#createUserModal">Create User</a></li>
                            <?php endif; ?>
                            <li><a href="/partners/logout">Sign Out</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <?php if ($isAdmin) : ?>
        <!-- Modal -->
        <div id="createUserModal" class="modal fade" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">Create User</h4>
                    </div>
                    <div class="modal-body user-modal-body">
                        <?php
                        $userData['distributors'] = $this->mweborder->getDistributors();
                        $this->load->view('weborder/includes/create_user.php', $userData);
                        ?>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    <?php endif; ?>