<?php
$settings = get_settings();
if(empty($_SESSION['lang'])) {
    $lang = $settings['language'];
} else {
    $lang = $_SESSION['lang'];
}
$delete_permission = false;
$sub_header = '';
switch ($page) {
    case 'dashboard':
        $menu_title = '<i class="fas fa-fw fa-tachometer-alt text-gray-700"></i> <span class="mb-0 text-gray-800">' . _("Dashboard") . '</span>';
        break;
    case 'statistics':
        $sub_header = print_map_selector('no');
        $menu_title = '<i class="fas fa-fw fa-map text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Statistics")." - "._("Map").'</span>';
        break;
    case 'statistics_all':
        $menu_title = '<i class="fas fa-fw fa-chart-area text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Statistics").' - '._("Overall").'</span>';
        break;
    case 'maps':
        $menu_title = '<i class="fas fa-fw fa-list text-gray-700"></i> <span class="mb-0 text-gray-800">' . _("List Maps") . '</span>';
        break;
    case 'edit_map':
        $sub_header = '<div class="map_select_header"><a id="save_btn" href="#" onclick="save_map();return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a></div>';
        $menu_title = '<i class="fas fa-fw fa-map text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Edit Map").'</span> <i id="subtitle_header" class="text-gray-700">.........</i>';
        break;
    case 'markers':
        $sub_header = print_map_selector('markers');
        $menu_title = '<i class="fas fa-fw fa-map-marker-alt text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Markers").'</span>';
        break;
    case 'import':
        $sub_header = print_map_selector('no');
        $menu_title = '<i class="fas fa-fw fa-map-marker-alt text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Markers").'</span>';
        break;
    case 'add_marker':
        $sub_header = '<div class="map_select_header"><a id="save_btn" href="#" onclick="save_marker();return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a></div>';
        $menu_title = '<i class="fas fa-fw fa-map-marker-alt text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Add Marker").'</span>';
        break;
    case 'edit_marker':
        $id_marker = $_GET['id'];
        $marker = get_marker($id_marker,$_SESSION['id_user']);
        if($marker!==false) {
            $id_map = $marker['id_map'];
            $next_prev_marker = get_next_prev_marker_id($id_marker,$id_map);
            $id_next_marker = $next_prev_marker[0];
            $id_prev_marker = $next_prev_marker[1];
            $btn_nav_rooms = '<a title="'._("EDIT PREVIOUS MARKER").'" href="index.php?p=edit_marker&id='.$id_prev_marker.'" class="btn btn-sm tooltip_arrows btn-primary btn-icon-split">
        <span class="icon text-white-50">
          <i class="fas fa-angle-left"></i>
        </span>
        </a>
        <a title="'._("EDIT NEXT MARKER").'" href="index.php?p=edit_marker&id='.$id_next_marker.'" class="btn btn-sm tooltip_arrows btn-primary btn-icon-split">
        <span class="icon text-white-50">
          <i class="fas fa-angle-right"></i>
        </span>
        </a>';
            if($user_info['role']=="editor") {
                $editor_permissions = get_editor_permissions($_SESSION['id_user'],$id_map);
                if($editor_permissions['delete_markers']==1) {
                    $delete_permission = true;
                } else {
                    $delete_permission = false;
                }
            } else {
                $delete_permission = true;
            }
            $sub_header = '<div class="map_select_header"><div class="justify-content-end">'.$btn_nav_rooms.'<a style="margin-left: 5px" id="save_btn" href="#" onclick="save_marker();return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a>&nbsp;&nbsp;&nbsp;<button data-toggle="modal" data-target="#modal_delete_marker" type="button" class="btn btn-sm btn-danger '.(($delete_permission) ? '' : 'd-none').'">'._("DELETE").'</button></div></div>';
        }
        $menu_title = '<i class="fas fa-fw fa-map-marker-alt text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Edit Marker").'</span>  <i id="subtitle_header" class="text-gray-700">.........</i>';
        break;
    case 'markers_connections':
        $sub_header = print_map_selector('markers_connections');
        $menu_title = '<i class="fas fa-fw fa-exchange-alt text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Connections").'</span>';
        break;
    case 'story':
        $sub_header = print_map_selector('story');
        $menu_title = '<i class="fas fa-fw fa-list-ul text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Story").'</span>';
        break;
    case 'categories':
        $sub_header = print_map_selector('categories');
        $menu_title = '<i class="fas fa-fw fa-stream text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Categories").'</span>';
        break;
    case 'add_category':
        $sub_header = '<div class="map_select_header"><div><a id="save_btn" href="#" onclick="save_category();return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a></div></div>';
        $menu_title = '<i class="fas fa-fw fa-stream text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Add Category").'</span>';
        break;
    case 'edit_category':
        $id_category = $_GET['id'];
        $category = get_category($id_category);
        if($category!==false) {
            $id_map = $category['id_map'];
            $next_prev_cat = get_next_prev_category_id($id_category, $id_map);
            $id_next_cat = $next_prev_cat[0];
            $id_prev_cat = $next_prev_cat[1];
            $btn_nav_rooms = '<a title="' . _("EDIT PREVIOUS CATEGORY") . '" href="index.php?p=edit_category&id=' . $id_prev_cat . '" class="btn btn-sm tooltip_arrows btn-primary btn-icon-split">
                <span class="icon text-white-50">
                  <i class="fas fa-angle-left"></i>
                </span>
                </a>
                <a title="' . _("EDIT NEXT CATEGORY") . '" href="index.php?p=edit_category&id=' . $id_next_cat . '" class="btn btn-sm tooltip_arrows btn-primary btn-icon-split">
                <span class="icon text-white-50">
                  <i class="fas fa-angle-right"></i>
                </span>
                </a>';
            $sub_header = '<div class="map_select_header"><div class="justify-content-end">'.$btn_nav_rooms.'<a style="margin-left: 5px;" id="save_btn" href="#" onclick="save_category();return false;" class="btn btn-sm btn-success btn-icon-split ' . (($demo) ? 'disabled' : '') . '"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">' . _("SAVE") . '</span></a><button ' . (($demo) ? 'disabled' : '') . ' onclick="modal_delete_category(' . $id_category . ');" class="btn btn-sm btn-danger ml-2">' . _("DELETE") . '</button></div></div>';
        }
        $menu_title = '<i class="fas fa-fw fa-stream text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Edit Category").'</span>';
        break;
    case 'icons_library':
        $sub_header = print_map_selector('icons_library');
        $menu_title = '<i class="fas fa-fw fa-icons text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Icons Library").'</span>';
        break;
    case 'media_library':
        $sub_header = print_map_selector('media_library');
        $menu_title = '<i class="fas fa-fw fa-photo-video text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Media Library").'</span>';
        break;
    case 'reviews':
        $sub_header = print_map_selector('reviews');
        $menu_title = '<i class="fas fa-fw fa-feather-alt text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Reviews").'</span>';
        break;
    case 'issue_reports':
        $sub_header = print_map_selector('issue_reports');
        $menu_title = '<i class="fas fa-fw fa-triangle-exclamation text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Issue Reports").'</span>';
        break;
    case 'markers_to_validate':
        $sub_header = print_map_selector('markers_to_validate');
        $menu_title = '<i class="fas fa-fw fa-check-to-slot text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Markers to validate").'</span>';
        break;
    case 'photos_to_validate':
        $sub_header = print_map_selector('photos_to_validate');
        $menu_title = '<i class="fas fa-fw fa-image text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Photos to validate").'</span>';
        break;
    case 'live_tracking':
        $sub_header = print_map_selector('live_tracking');
        $menu_title = '<i class="fas fa-fw fa-location-arrow text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Live Tracking").'</span>';
        break;
    case 'preview':
        $sub_header = print_map_selector('preview');
        $menu_title = '<i class="fas fa-fw fa-eye text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Preview").'</span>';
        break;
    case 'publish':
        $sub_header = print_map_selector('no');
        $menu_title = '<i class="fas fa-fw fa-map text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Publish")." - "._("Map").'</span>';
        break;
    case 'settings':
        $sub_header = '<div class="map_select_header"><a id="save_btn" href="#" onclick="save_settings(false);return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a></div>';
        $menu_title = '<i class="fas fa-fw fa-cogs text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Settings").'</span>';
        break;
    case 'updater':
        $menu_title = '<i class="fas fa-fw fa-download text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Upgrade").'</span>';
        break;
    case 'users':
        $menu_title = '<i class="fas fa-fw fa-users text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Users").'</span>';
        break;
    case "edit_user":
        $id_user_edit = $_GET['id'];
        $btn_del_user = '';
        if($_SESSION['id_user']!=$id_user_edit) {
            $btn_del_user = '<button '.(($demo) ? 'disabled':'').' onclick="modal_delete_user(\''.$id_user_edit.'\');" class="btn btn-sm btn-danger ml-2">'._("DELETE").'</button>';
        }
        $sub_header = '<div class="map_select_header"><a id="save_btn" href="#" onclick="save_user('.$id_user_edit.');return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a>'.$btn_del_user.'</div>';
        $menu_title = '<i class="fas fa-fw fa-users text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Edit User").'</span>';
        break;
    case 'edit_profile':
        $id_user_edit = $_SESSION['id_user'];
        $sub_header = '<div class="map_select_header"><a id="save_btn" href="#" onclick="save_profile(false);return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a></div>';
        $menu_title = '<i class="fas fa-fw fa-user text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Edit Profile").'</span>';
        break;
    case 'draw':
        $sub_header = print_map_selector();
        $menu_title = '<i class="fas fa-fw fa-draw-polygon text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Geometries").'</span>';
        break;
    case 'geoimages':
        $sub_header = print_map_selector('geoimages');
        $menu_title = '<i class="fas fa-fw fa-images text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Geo Images").'</span>';
        break;
    case 'boundaries':
        $sub_header = print_map_selector('boundaries');
        $menu_title = '<i class="far fa-fw fa-square text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Boundaries").'</span>';
        break;
    case 'geodata':
        $sub_header = print_map_selector('geodata');
        $menu_title = '<i class="fas fa-fw fa-route text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Geo Data").'</span>';
        break;
    case 'showcases':
        $menu_title = '<i class="fas fa-fw fa-object-group text-gray-700"></i> <span class="mb-0 text-gray-800">'._("Publish")." - "._("Showcases").'</span>';
        break;
    case 'edit_showcase':
        $id_showcase = $_GET['id'];
        $sub_header = '<div class="map_select_header"><div><a id="save_btn" href="#" onclick="save_showcase('.$id_showcase.');return false;" class="btn btn-sm btn-success btn-icon-split '.(($demo) ? 'disabled':'').'"><span class="icon text-white-50"><i class="far fa-circle"></i></span><span class="text">'._("SAVE").'</span></a><button '.(($demo) ? 'disabled':'').' onclick="modal_delete_showcase('.$id_showcase.');" class="btn btn-sm btn-danger ml-2">'._("DELETE").'</button></div></div>';
        $menu_title = '<i class="fas fa-fw fa-object-group text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Edit Showcase").'</span>';
        break;
    case 'bulk_translate':
        $sub_header = print_map_selector('bulk_translate');
        $menu_title = '<i class="fas fa-fw fa-language text-gray-700"></i> <span class="mb-0 text-gray-800">'. _("Bulk Translate").'</span>';
        break;
}
?>
<nav class="navbar navbar-expand navbar-light bg-white topbar static-top <?php echo (empty($sub_header) ? 'shadow' : '') ?>">
    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
        <i class="fa fa-bars"></i>
    </button>
    <div class="header_menu_title noselect ml-1"><?php echo $menu_title; ?></div>
    <ul class="navbar-nav ml-auto">
        <li class="nav-item dropdown no-arrow lang_switcher">
            <a class="nav-link dropdown-toggle" href="#" id="langDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" <?php echo ($settings['languages_count']==1) ? 'style="cursor:default;pointer-events:none;"' : ''; ?> >
                <img style="height: 14px;" src="img/flags_lang/<?php echo $lang; ?>.png" />
            </a>
            <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="langDropdown">
                <?php if((!check_language_enabled('en_US',$settings['languages_enabled']) && check_language_enabled('en_GB',$settings['languages_enabled'])) || (check_language_enabled('en_US',$settings['languages_enabled']) && !check_language_enabled('en_GB',$settings['languages_enabled']))) {
                    $languages_list['en_GB']['name'] = "English";
                    $languages_list['en_US']['name'] = "English";
                }
                foreach ($languages_list as $lang_code => $lang_data): ?>
                    <?php if (check_language_enabled($lang_code, $settings['languages_enabled'])): ?>
                        <span style="cursor: pointer;" onclick="switch_language('<?php echo $lang_code; ?>');" class="<?php echo ($lang == $lang_code) ? 'lang_active' : ''; ?> noselect dropdown-item align-middle">
                            <img class="mb-1" src="img/flags_lang/<?php echo $lang_code; ?>.png?v=3" />
                            <span class="ml-2"><?php echo $lang_data['name']; ?></span>
                        </span>
                    <?php endif; ?>
                <?php endforeach; ?>
            </div>
        </li>
        <?php if($settings['dark_mode']==1) : ?>
            <li class="nav-item dropdown no-arrow dark_mode_switcher ml-2">
                <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <i onclick="switch_dark_mode();" id='btn_light_mode' style="opacity:0;" class='btn_mode_switcher fas fa-sun'></i>
                    <script>
                        if (localStorage.getItem("dark_mode") === null) {
                            if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
                                $('.btn_mode_switcher').attr('id','btn_dark_mode');
                                $('.btn_mode_switcher').removeClass('fa-sun').addClass('fa-moon');
                            }
                        } else {
                            if(localStorage.getItem('dark_mode')==1) {
                                $('.btn_mode_switcher').attr('id','btn_dark_mode');
                                $('.btn_mode_switcher').removeClass('fa-sun').addClass('fa-moon');
                            }
                        }
                        $('.btn_mode_switcher').css('opacity',1);
                    </script>
                </a>
            </li>
        <?php endif; ?>
        <div class="topbar-divider d-none d-sm-block"></div>
        <li class="nav-item dropdown no-arrow">
            <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span style="padding-top:3px;" class="mr-2 d-none d-lg-inline text-gray-600 small"><?php echo $user_info['username']; ?></span>&nbsp;
                <img class="img-profile rounded-circle" src="img/avatar1.png">
            </a>
            <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">
                <a class="dropdown-item" href="index.php?p=edit_profile">
                    <i class="fas fa-lock fa-sm fa-fw mr-2 text-gray-400"></i>
                    <?php echo _("Edit profile"); ?>
                </a>
                <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">
                    <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
                    <?php echo _("Logout"); ?>
                </a>
            </div>
        </li>
    </ul>
</nav>
<?php echo $sub_header; ?>
<div class="mb-3"></div>
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel"><?php echo _("Ready to Leave?"); ?></h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body"><?php echo _("Select Logout below if you are ready to end your current session."); ?></div>
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal"><?php echo _("Cancel"); ?></button>
                <button class="btn btn-primary" onclick="logout();"><?php echo _("Logout"); ?></button>
            </div>
        </div>
    </div>
</div>

<script>
    $('.quick_action').tooltip();
    $("#sidebarToggleTop").click(function(){
        if($('#accordionSidebar').hasClass('toggled')) {
            sessionStorage.setItem("sidebar_accord", 1);
            $(".nav-item.active .collapse").addClass('show');
            if($('#sidebar_logo_small').length) {
                $('#sidebar_logo').show();
                $('#sidebar_logo_small').hide();
            }
        } else {
            sessionStorage.setItem("sidebar_accord", 0);
            $(".collapse").removeClass('show');
            if($('#sidebar_logo_small').length) {
                $('#sidebar_logo').hide();
                $('#sidebar_logo_small').show();
            }
        }
    });
    $('#map_selector').on('rendered.bs.select', function (e, clickedIndex, isSelected, previousValue) {
        $('#loading_header').hide();
        setTimeout(function() {
            $('#map_selector').css('opacity',1);
        },50);
        setTimeout(function() {
            $('.map_select_header .quick_action').css('opacity',1);
        },100);
    });
</script>