<?php
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
ini_set('session.gc_maxlifetime', 28800);
session_set_cookie_params(28800);
if(!file_exists("../config/config.inc.php")) {
    header("Location: ../install/start.php");
}
include_once("../config/languages.inc.php");
include_once("../config/version.inc.php");
session_start();
require_once("functions.php");
$session_id = session_id();
$_SESSION['sml_si']=$session_id;
if(isset($_SESSION['id_user'])) {
    $id_user = $_SESSION['id_user'];
} else {
    $current_url = urlencode($_SERVER['REQUEST_URI']);
    header("Location: login.php?redirect=$current_url");
    exit;
}
$v = time();
$version = APP_VERSION;
$rev = APP_REVISION;
$settings = get_settings();
$need_update = false;
if(!empty($settings['version'])) {
    $version_c = $settings['version'];
    if($version!=$version_c) {
        $need_update = true;
    }
} else {
    $need_update = true;
}
$user_info = get_user_info($id_user);
if(empty($user_info) || !sml_is_backend_user_role($user_info['role'])) {
    unset($_SESSION['id_user']);
    unset($_SESSION['sml_si']);
    $current_url = urlencode($_SERVER['REQUEST_URI']);
    header("Location: login.php?redirect=$current_url");
    exit;
}
if(!empty($user_info['language'])) {
    set_language($user_info['language'],$settings['language_domain']);
    unset($settings);
    $settings = get_settings();
} else {
    if(empty($_SESSION['lang'])) {
        $_SESSION['lang']=$settings['language'];
    }
    set_language($settings['language'],$settings['language_domain']);
}
if(isset($_GET['p'])) {
    $page = $_GET['p'];
} else {
    $page = "dashboard";
}
if(file_exists("../config/demo.inc.php")) {
    require_once("../config/demo.inc.php");
    $_SESSION['demo_developer_ip']=DEMO_DEVELOPER_IP;
    $_SESSION['demo_server_ip']=DEMO_SERVER_IP;
    $_SESSION['demo_user_id']=DEMO_USER_ID;
    if(($_SERVER['SERVER_ADDR']==$_SESSION['demo_server_ip']) && ($_SERVER['REMOTE_ADDR']!=$_SESSION['demo_developer_ip']) && ($_SESSION['id_user']==$_SESSION['demo_user_id'])) {
        $demo = true;
        if(!isset($_SESSION['id_map_sel'])) {
            $_SESSION['id_map_sel'] = 1;
            $_SESSION['name_map_sel'] = 'Simple Map Locator';
        }
    } else {
        $demo = false;
    }
    if(($_SERVER['REMOTE_ADDR']==$_SESSION['demo_developer_ip'])) {
        $k = time();
    } else {
        $k = $version."_".$rev;
    }
} else {
    $demo = false;
    $k = $version."_".$rev;
    $_SESSION['demo_developer_ip']='';
    $_SESSION['demo_server_ip']='';
    $_SESSION['demo_user_id']='';
}
$_SESSION['demo'] = $demo;
$_SESSION['theme_color']=$settings['theme_color'];
$_SESSION['sidebar_color_1']=$settings['sidebar_color_1'];
$_SESSION['sidebar_color_2']=$settings['sidebar_color_2'];
$_SESSION['theme_color_dark']=$settings['theme_color_dark'];
$_SESSION['sidebar_color_1_dark']=$settings['sidebar_color_1_dark'];
$_SESSION['sidebar_color_2_dark']=$settings['sidebar_color_2_dark'];
$_SESSION['input_license']=0;
$deepl_api_key = $settings['deepl_api_key'];
$enable_deepl = $settings['enable_deepl'];
if($enable_deepl && !empty($deepl_api_key)) {
    $deepl = 1;
} else {
    $deepl = 0;
}
switch($_SESSION['lang']) {
    case 'pt_BR':
        $lang_code='pt-BR';
        break;
    case 'pt_PT':
        $lang_code='pt-PT';
        break;
    case 'zh_CN':
        $lang_code='zh-CN';
        break;
    case 'zh_TW':
        $lang_code='zh-TW';
        break;
    case 'zh_HK':
        $lang_code='zh-hk';
        break;
    default:
        $lang_code = substr($_SESSION['lang'], 0, 2);
        break;
}
switch($lang_code) {
    case 'ar':
    case 'he':
    case 'fa':
        $dir = "rtl";
        break;
    default:
        $dir = "ltr";
        break;
}
switch ($page) {
    case 'dashboard':
        $menu_title = _("Dashboard");
        break;
    case 'statistics':
        $menu_title = _("Statistics") . " - " . _("Map");
        break;
    case 'statistics_all':
        $menu_title = _("Statistics") . " - " . _("Overall");
        break;
    case 'maps':
        $menu_title = _("List Maps");
        break;
    case 'edit_map':
        $menu_title = _("Edit Map");
        break;
    case 'markers':
    case 'import':
        $menu_title = _("Markers");
        break;
    case 'add_marker':
        $menu_title = _("Add Marker");
        break;
    case 'edit_marker':
        $menu_title = _("Edit Marker");
        break;
    case 'markers_connections':
        $menu_title = _("Connections");
        break;
    case 'story':
        $menu_title = _("Story");
        break;
    case 'categories':
        $menu_title = _("Categories");
        break;
    case 'add_category':
        $menu_title = _("Add Category");
        break;
    case 'edit_category':
        $menu_title = _("Edit Category");
        break;
    case 'icons_library':
        $menu_title = _("Icons Library");
        break;
    case 'media_library':
        $menu_title = _("Media Library");
        break;
    case 'reviews':
        $menu_title = _("Reviews");
        break;
    case 'issue_reports':
        $menu_title = _("Issue Reports");
        break;
    case 'live_tracking':
        $menu_title = _("Live Tracking");
        break;
    case 'preview':
        $menu_title = _("Preview");
        break;
    case 'publish':
        $menu_title = _("Publish") . " - " . _("Map");
        break;
    case 'settings':
        $menu_title = _("Settings");
        break;
    case 'updater':
        $menu_title = _("Upgrade");
        break;
    case 'users':
        $menu_title = _("Users");
        break;
    case 'edit_user':
        $menu_title = _("Edit User");
        break;
    case 'edit_profile':
        $menu_title = _("Edit Profile");
        break;
    case 'draw':
        $menu_title = _("Geometries");
        break;
    case 'geoimages':
        $menu_title = _("Geo Images");
        break;
    case 'boundaries':
        $menu_title = _("Boundaries");
        break;
    case 'geodata':
        $menu_title = _("Geo Data");
        break;
    case 'showcases':
        $menu_title = _("Publish") . " - " . _("Showcases");
        break;
    case 'edit_showcase':
        $menu_title = _("Edit Showcase");
        break;
    case 'markers_to_validate':
        $menu_title = _("Markers to validate");
        break;
    case 'photos_to_validate':
        $menu_title = _("Photos to validate");
        break;
    case 'bulk_translate':
        $menu_title = _("Bulk Translate");
        break;
    default:
        $menu_title = "";
        break;
}
?>
<!DOCTYPE html>
<html dir="<?php echo $dir; ?>" lang="<?php echo $lang_code; ?>">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <meta charset="UTF-8">
    <meta name="description" content="">
    <meta name="author" content="">
    <title><?php echo (empty($menu_title)) ? $settings['name'] : $settings['name']." | ".$menu_title; ?></title>
    <?php echo print_favicons_backend($settings['logo'],$settings['theme_color']); ?>
    <link rel="stylesheet" type="text/css" href="../viewer/vendor/fontawesome-free/css/fontawesome.min.css?v=7.2.0">
    <link rel="stylesheet" type="text/css" href="../viewer/vendor/fontawesome-free/css/solid.min.css?v=7.2.0">
    <link rel="stylesheet" type="text/css" href="../viewer/vendor/fontawesome-free/css/regular.min.css?v=7.2.0">
    <link rel="stylesheet" type="text/css" href="../viewer/vendor/fontawesome-free/css/brands.min.css?v=7.2.0">
    <?php switch ($settings['font_provider']) {
    case 'google': ?>
        <?php if($settings['cookie_consent']) { ?>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <script type="text/plain" data-category="functionality" data-service="Google Fonts">
            (function(d, l, s) {
                const fontName = '<?php echo $settings['font_backend']; ?>';
                    const e = d.createElement(l);
                    e.rel = s;
                    e.type = 'text/css';
                    e.href = `https://fonts.googleapis.com/css2?family=${fontName}`;
                    e.id = 'font_backend_link';
                    d.head.appendChild(e);
                  })(document, 'link', 'stylesheet');
        </script>
    <?php } else { ?>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link rel='stylesheet' type="text/css" crossorigin="anonymous" id="font_backend_link" href="https://fonts.googleapis.com/css2?family=<?php echo $settings['font_backend']; ?>">
    <?php } ?>
    <?php break;
    case 'collabs': ?>
    <link rel="preconnect" href="https://api.fonts.coollabs.io" crossorigin>
    <link rel="stylesheet" type="text/css" id="font_backend_link" href="https://api.fonts.coollabs.io/css2?family=<?php echo $settings['font_backend']; ?>&display=swap">
    <?php break;
    default: ?>
    <link rel="stylesheet" type="text/css" crossorigin="anonymous" id="font_backend_link" href="">
        <?php break;
    } ?>
    <?php if($dir=='rtl') : ?>
    <link rel="stylesheet" type="text/css" href="css/sb-admin-2.rtl.min.css?v=3">
    <?php else: ?>
    <link rel="stylesheet" type="text/css" href="css/sb-admin-2.min.css?v=6">
    <?php endif; ?>
    <?php if(in_array($page,['categories','users','edit_user','geodata','markers','markers_to_validate','photos_to_validate','markers_connections','reviews','issue_reports','showcases','story','live_tracking'])) : ?>
        <link rel="stylesheet" type="text/css" href="vendor/datatables2/datatables.min.css?v=2.3.7b4c">
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','draw','geoimages','boundaries','live_tracking'])) : ?>
    <link rel="stylesheet" type="text/css" href="../viewer/css/ol.css?v=10.10.0">
    <link rel="stylesheet" type="text/css" href="../viewer/css/ol-ext.min.css?v=4.0.38b">
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','geodata','settings','bulk_translate'])) : ?>
    <link rel="stylesheet" type="text/css" href="vendor/quill/quill.core.css">
    <link rel="stylesheet" type="text/css" href="vendor/quill/quill.snow.css">
    <link rel="stylesheet" type="text/css" href="vendor/quill/quill.bubble.css">
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','edit_category','add_category','edit_map','settings'])) : ?>
    <link rel="stylesheet" type="text/css" href="vendor/iconpicker/iconpicker-1.5.0.css?v=3" />
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','edit_category','add_category','edit_map','edit_showcase','markers_connections','settings','geodata'])) : ?>
    <link rel="stylesheet" type="text/css" href="vendor/spectrum/spectrum.min.css?v=2.0.9">
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','icons_library','media_library'])) : ?>
    <link rel="stylesheet" type="text/css" href="vendor/dropzone/dropzone.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/dropzone/basic.min.css">
    <?php endif; ?>
    <link rel="stylesheet" type="text/css" href="vendor/bootstrap-select/css/bootstrap-select.min.css?v=3">
    <link rel="stylesheet" type="text/css" href="vendor/tooltipster/css/tooltipster.bundle.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/tooltipster/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-borderless.min.css">
    <?php if(in_array($page,['edit_map','settings'])) : ?>
    <link rel="stylesheet" type="text/css" href="vendor/jquery.fontpicker/jquery.fontpicker.min.css">
    <?php endif; ?>
    <link rel="stylesheet" type="text/css" href="vendor/bootstrap-select-country/css/bootstrap-select-country.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/bootstrap4-toggle/bootstrap4-toggle.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/alertifyjs/css/alertify.min.css">
    <link rel="stylesheet" type="text/css" href="vendor/alertifyjs/css/themes/bootstrap.min.css">
    <?php if(in_array($page,['edit_map'])) : ?>
    <link rel="stylesheet" type="text/css" href="vendor/summernote/summernote.min.css">
    <?php endif; ?>
    <?php if(in_array($page,['statistics','statistics_all'])) : ?>
        <link rel="stylesheet" type="text/css" href="vendor/jsvectormap/jsvectormap.min.css">
    <?php endif; ?>
    <?php if($settings['cookie_consent']) : ?>
        <link rel="stylesheet" type="text/css" href="vendor/cookieconsent/cookieconsent.min.css?v=3.1.0">
    <?php endif; ?>
    <link rel="stylesheet" type="text/css" id="css_theme" href="css/theme.php?v=<?php echo $k; ?>">
    <link rel="stylesheet" type="text/css" id="css_theme_dark" href="css/theme_dark.php?v=<?php echo $v; ?>">
    <link rel="stylesheet" type="text/css" href="css/dark_mode.css?v=<?php echo $k; ?>">
    <link rel="stylesheet" type="text/css" href="css/custom.css?v=<?php echo $v; ?>">
    <?php if($dir=='rtl') : ?>
    <link rel="stylesheet" type="text/css" href="css/custom.rtl.css?v=<?php echo $v; ?>">
    <?php endif; ?>
    <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'custom_b.css')) : ?>
    <link rel="stylesheet" type="text/css" href="css/custom_b.css?v=<?php echo $v; ?>">
    <?php endif; ?>
    <script type="text/javascript" src="vendor/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="vendor/jquery-ui/jquery-ui.min.js"></script>
    <script type="text/javascript" src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript" src="vendor/jquery-easing/jquery.easing.min.js"></script>
    <script type="text/javascript" src="vendor/clipboard.js/clipboard.min.js"></script>
    <script type="text/javascript" src="vendor/jquery.searchable-1.1.0.min.js"></script>
    <?php if(in_array($page,['dashboard'])) : ?>
        <script type="text/javascript" src="js/jquery.twbsPagination.min.js"></script>
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','draw','geoimages','boundaries','live_tracking'])) : ?>
    <script type="text/javascript" src="../viewer/js/ol.js?v=10.10.0"></script>
    <script type="text/javascript" src="../viewer/js/olms.js?v=12.5.0"></script>
    <script type="text/javascript" src="../viewer/js/ol-ext.min.js?v=4.0.38b"></script>
    <?php endif; ?>
    <script type="text/javascript" src="../viewer/js/gifler.min.js"></script>
    <script type="text/javascript" src="vendor/highlightjs/hljs.min.js"></script>
    <script type="text/javascript" src="vendor/highlightjs/xml.min.js"></script>
    <?php if(in_array($page,['edit_marker','add_marker','geodata','settings','bulk_translate'])) : ?>
    <script type="text/javascript" src="vendor/quill/quill.core.js"></script>
    <script type="text/javascript" src="vendor/quill/quill.js"></script>
    <script type="text/javascript" src="vendor/quill/quill.min.js"></script>
    <script type="text/javascript" src="vendor/quill/quill.html.js"></script>
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','edit_category','add_category','edit_map','settings'])) : ?>
    <script type="text/javascript" src="vendor/iconpicker/iconpicker-1.5.0.js?v=3"></script>
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','edit_category','add_category','edit_map','edit_showcase','markers_connections','settings','geodata'])) : ?>
    <script type="text/javascript" src="vendor/spectrum/spectrum.min.js?v=2.0.9"></script>
    <?php endif; ?>
    <?php if(in_array($page,['dashboard'])) : ?>
    <script type="text/javascript" src="vendor/chart.js/Chart.min.js"></script>
    <?php endif; ?>
    <?php if(in_array($page,['statistics','statistics_all'])) : ?>
    <script type="text/javascript" src="vendor/hchart/hs.min.js?v=1"></script>
    <script type="text/javascript" src="vendor/hchart/exporting.js"></script>
    <script type="text/javascript" src="vendor/hchart/accessibility.js"></script>
    <?php endif; ?>
    <?php if(in_array($page,['edit_marker','add_marker','icons_library','media_library'])) : ?>
    <script type="text/javascript" src="vendor/dropzone/dropzone.min.js"></script>
    <?php endif; ?>
    <script type="text/javascript" src="vendor/bootstrap-select/js/bootstrap-select.min.js"></script>
    <script type="text/javascript" src="vendor/tooltipster/js/tooltipster.bundle.min.js"></script>
    <?php if(in_array($page,['edit_map'])) : ?>
    <script type="text/javascript" src="vendor/summernote/summernote.min.js"></script>
        <?php if ($_SESSION['lang'] !== 'en_US' && $_SESSION['lang'] !== 'en_GB') : ?>
            <script type="text/javascript" src="vendor/summernote/lang/summernote-<?php echo str_replace('_', '-', $_SESSION['lang']) ?>.js"></script>
        <?php endif; ?>
    <?php endif; ?>
    <?php if(in_array($page,['statistics','statistics_all'])) : ?>
        <script type="text/javascript" src="vendor/jsvectormap/jsvectormap.min.js"></script>
        <script type="text/javascript" src="vendor/jsvectormap/world.js"></script>
    <?php endif; ?>
    <?php if(in_array($page,['edit_map','settings'])) : ?>
    <?php
    switch ($settings['font_provider']) {
        case 'collabs':
            echo '<script type="text/javascript" src="vendor/jquery.fontpicker/jquery.fontpicker.collabs.min.js?v=1.6"></script>';
            break;
        default:
            echo '<script type="text/javascript" src="vendor/jquery.fontpicker/jquery.fontpicker.min.js?v=1.6"></script>';
            break;
    }
    ?>
    <?php endif; ?>
    <script type="text/javascript" src="vendor/bootstrap/js/bs-custom-file-input.min.js"></script>
    <script type="text/javascript" src="vendor/bootstrap-select-country/js/bootstrap-select-country.min.js"></script>
    <?php if(in_array($page,['edit_marker','add_marker','edit_showcase','markers_connections','settings','story','edit_map'])) : ?>
        <script type="text/javascript" src="vendor/ace-editor/ace.js?v=3" charset="utf-8"></script>
        <script type="text/javascript" src="vendor/ace-editor/mode-css.js?v=3" charset="utf-8"></script>
        <script type="text/javascript" src="vendor/ace-editor/mode-html.js?v=3" charset="utf-8"></script>
        <script type="text/javascript" src="vendor/ace-editor/ext-language_tools.js?v=3" charset="utf-8"></script>
        <script type="text/javascript" src="vendor/ace-editor/theme-one_dark.min.js?v=7" charset="utf-8"></script>
        <?php if($dir=='rtl') : ?>
        <script type="text/javascript" src="vendor/ace-editor/ext-rtl.js" charset="utf-8"></script>
        <?php endif; ?>
    <?php endif; ?>
    <script type="text/javascript" src="vendor/bootstrap4-toggle/bootstrap4-toggle.min.js"></script>
    <script type="text/javascript" src="vendor/jquery.searchable-1.1.0.min.js"></script>
    <script type="text/javascript" src="vendor/Sortable.min.js?v=1.14"></script>
    <script type="text/javascript" src="vendor/alertifyjs/alertify.min.js"></script>
    <script type="text/javascript" src="js/Sortable.min.js?v=1.15.3"></script>
    <script type="text/javascript" src="js/pace.min.js"></script>
    <?php if($settings['cookie_consent']) : ?>
        <script type="text/javascript" src="vendor/cookieconsent/cookieconsent.min.js?v=3.1.0"></script>
    <?php endif; ?>
    <script src="js/function.js?v=<?php echo $k; ?>"></script>
    <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'custom_b.js')) : ?>
        <script type="text/javascript" src="js/custom_b.js?v=<?php echo $v; ?>"></script>
    <?php endif; ?>
    <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'header'.DIRECTORY_SEPARATOR.'custom_b.php')) {
        include(__DIR__.DIRECTORY_SEPARATOR.'header'.DIRECTORY_SEPARATOR.'custom_b.php');
    } ?>
</head>

<body id="page-top" class="<?php echo ($settings['dark_mode']==2) ? 'dark_mode' : ''; ?>">
<script>
    var dark_mode_setting = <?php echo $settings['dark_mode']; ?>;
    var dark_mode = '0';
    window.rtl = <?php echo ($dir=='rtl') ? 1 : 0; ?>;
    if(dark_mode_setting==1) {
        if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
            dark_mode = '1';
        }
        if (localStorage.getItem("dark_mode") === null) {
            localStorage.setItem("dark_mode",dark_mode);
        } else {
            dark_mode = localStorage.getItem('dark_mode');
        }
        if(dark_mode=='1') {
            document.body.classList.add("dark_mode");
            document.documentElement.classList.add('cc--darkmode');
        }
        window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
            dark_mode = e.matches ? '1' : '0';
            if(dark_mode=='1') {
                $('.btn_mode_switcher').attr('id','btn_dark_mode');
                $('.btn_mode_switcher').removeClass('fa-sun').addClass('fa-moon');
                document.body.classList.add("dark_mode");
                document.documentElement.classList.add('cc--darkmode');
                localStorage.setItem("dark_mode",'1');
            } else {
                $('.btn_mode_switcher').attr('id','btn_light_mode');
                $('.btn_mode_switcher').removeClass('fa-moon').addClass('fa-sun');
                document.body.classList.remove("dark_mode");
                document.documentElement.classList.remove('cc--darkmode');
                localStorage.setItem("dark_mode",'0');
            }
        });
    }
    window.deepl = <?php echo $deepl; ?>;
</script>
<style id="style_css">
    *{ font-family: '<?php echo $settings['font_backend']; ?>', sans-serif; }
</style>

<style>
    <?php if($page=='preview') : ?>
    #btn_preview {
        display: none;
    }
    <?php endif; ?>
</style>

<?php if($need_update) : ?>
    <div class="text-center mt-4">
        <h1 class="text-primary"><?php echo _("UPDATE IN PROGRESS"); ?>...</h1>
        <div class="spinner-border text-primary" role="status">
            <span class="sr-only"><?php echo _("Loading"); ?>...</span>
        </div>
        <p class="text-primary lead text-gray-800 mt-4"><?php echo _("Not close this window"); ?></p>
    </div>
    <script>
        $.ajax({
            url: "../services/pre_update.php",
            type: "POST",
            async: true,
            timeout: 120,
            success: function () {
                update_ajax();
            },
            error: function () {
                update_ajax();
            }
        });

        function update_ajax() {
            $.ajax({
                url: "ajax/update.php",
                type: "POST",
                data: {
                    version: '<?php echo $version; ?>'
                },
                async: true,
                timeout: 300000,
                success: function () {
                    location.reload();
                },
                error: function () {
                    alert('error');
                }
            });
        }
    </script>
    <?php
    exit;
endif;
?>

<div id="wrapper">
  <?php include_once("sidebar.php"); ?>
<div id="content-wrapper" class="d-flex flex-column position-relative">
      <div id="map_select"></div>
      <div id="content">
          <?php include_once("topbar.php"); ?>
        <div class="container-fluid">
            <?php
            if($user_info['role']=='administrator' && (empty($settings['license']) || empty($settings['purchase_code']))) {
                $_SESSION['input_license']=1;
                include_once("settings.php");
            } else {
                include_once("$page.php");
            }
            ?>
        </div>
      </div>
    <?php include_once("footer.php"); ?>
</div>
</div>
<div id="modal_preview_global" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" style="width: 95% !important; max-width: 95% !important;" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Preview"); ?></h5>
                <button onclick="close_preview_global_viewer();" type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div style="margin-bottom:-10px;" class="modal-body p-0"></div>
        </div>
    </div>
</div>
<a class="scroll-to-top rounded" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
<?php if(in_array($page,['categories','users','edit_user','geodata','markers','markers_to_validate','photos_to_validate','markers_connections','reviews','issue_reports','showcases','story','live_tracking'])) : ?>
<script src="vendor/datatables2/datatables.min.js?v=2.3.7b4c"></script>
<?php endif; ?>
<script src="js/sb-admin-2.js?v=4"></script>
<script>
    window.backend_labels = {
        "edit":`<?php echo _("EDIT"); ?>`,
        "publish":`<?php echo _("PUBLISH"); ?>`,
        "preview":`<?php echo _("PREVIEW"); ?>`,
        "markers":`<?php echo _("MARKERS"); ?>`,
        "delete":`<?php echo _("DELETE"); ?>`,
        "duplicate":`<?php echo _("DUPLICATE"); ?>`,
        "main_image":`<?php echo _("MAIN IMAGE"); ?>`,
        "set_as_main":`<?php echo _("SET AS MAIN"); ?>`,
        "searching":`<?php echo _("SEARCHING"); ?>`,
        "get_gps_position":`<?php echo _("GET GPS POSITION"); ?>`,
        "delete_sure_msg":`<?php echo _("Are you sure you want to delete?"); ?>`,
        "no_icon_msg":`<?php echo _("No icon images in this library!"); ?>`,
        "no_files_msg":`<?php echo _("No files in this library!"); ?>`,
        "delete_msg":`<?php echo _("Are you sure you want to delete?"); ?>`,
        "icons_assign_msg":`<?php echo _("Are you sure you want to assign this icon to all the markers?"); ?>`,
        "fields_assign_msg":`<?php echo _("Are you sure you want to assign this extra fields icons to all the markers?"); ?>`,
        "copied":`<?php echo _("copied"); ?>`,
        "search_map":`<?php echo _("Search Map ..."); ?>`,
        "save_ok":`<?php echo _("Changes saved successfully!"); ?>`,
        "save_error":`<?php echo _("An error occurred."); ?>`,
        "all_categories":`<?php echo _("All Categories"); ?>`,
        "position_set":`<?php echo _("POSITION SET"); ?>`,
        "check_msg":`<?php echo _("Are you sure you want to mark this report as checked?"); ?>`,
        "loading":`<?php echo _("Loading ..."); ?>`,
        "no_results":`<?php echo _("No results found!"); ?>`,
        "add":`<?php echo _("Add"); ?>`,
        "favorites":`<?php echo _("Favorites"); ?>`,
        "all_icons":`<?php echo _("All Icons"); ?>`,
        "fav_mode":`<?php echo _("Favorites Mode"); ?>`,
        "fav_mode_instructions":`<?php echo _("Click an icon in the all icons section to add it to your favorites, click an icon in the favorites section to remove it."); ?>`,
        "sure_validate_image":`<?php echo _("Are you sure you want to validate this photo and make it public and visible on the map?"); ?>`,
        "translating":`<?php echo _("translation in progress"); ?>`,
    };
</script>
<?php if(!empty($settings['ga_tracking_id'])) : ?>
    <?php if($settings['cookie_consent']) { ?>
        <script type="text/plain" data-category="analytics" data-service="Google Analytics" async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $settings['ga_tracking_id']; ?>"></script>
        <script type="text/plain" data-category="analytics" data-service="Google Analytics">
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', '<?php echo $settings['ga_tracking_id']; ?>', {
            'page_title': '<?php echo $page; ?>'
        });
        </script>
    <?php } else { ?>
        <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $settings['ga_tracking_id']; ?>"></script>
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', '<?php echo $settings['ga_tracking_id']; ?>', {
                'page_title': '<?php echo $page; ?>'
            });
        </script>
    <?php } ?>
<?php endif; ?>
<?php if($settings['cookie_consent']) : ?>
    <?php require_once('cookie_consent.php'); ?>
<?php endif; ?>
<script>
    window.addEventListener('load', () => {
        if ('serviceWorker' in navigator) {
            navigator.serviceWorker.register('service-worker.js?v=<?php echo $version; ?>', {
                scope: '.'
            });
        }
    });
</script>
<script>
    $(document).ready(function() {
        setTimeout(function() {
            $.ajax({
                url: "ajax/async_tasks.php",
                type: "POST",
                dataType: "json",
                success: function(data) {
                    if (data.update_available) {
                        $('.update_notification_icon').css('display', 'inline-block');
                        $('.update_notification_element').removeClass('d-none');
                    }
                }
            });
        }, 200);
    });
</script>
</body>
</html>
