<?php
header('Access-Control-Allow-Origin: *');
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED);
session_start();
require_once(__DIR__."/../backend/functions.php");
require_once(__DIR__."/../db/connection.php");
include_once("../config/version.inc.php");
include_once("../config/languages.inc.php");
$version = APP_VERSION;
$rev = APP_REVISION;
if(file_exists("../config/demo.inc.php")) {
    require_once("../config/demo.inc.php");
    $_SESSION['demo_developer_ip']=DEMO_DEVELOPER_IP;
    if(((!empty($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0] : $_SERVER['REMOTE_ADDR']))==$_SESSION['demo_developer_ip'])) {
        $v = $version.time();
    } else {
        $v = $version."_".$rev;
    }
} else {
    $v = $version."_".$rev;
}
if(is_ssl()) {
    $geolocation_disabled = "";
} else {
    $geolocation_disabled = "disabled";
}
$current_map = array();
$auto_start = 1;
$loading_visible = 1;
$show_list = 0;
$limit_list = -1;
$default_zoom = 0;
$selected_zoom = 18;
$duration_zoom = 300;
$density_color = 0;
$password = false;
$map_language='';
$map_languages_enabled = array();
$map_language_force = "";
$browser_language = '';
$code = '';
$currentPath = $_SERVER['PHP_SELF'];
$pathInfo = pathinfo($currentPath);
$hostName = $_SERVER['HTTP_HOST'];
if (is_ssl()) { $protocol = 'https'; } else { $protocol = 'http'; }
$url = $protocol."://".$hostName.$pathInfo['dirname']."/";
$url_map = $url;
$url_logo = "";
$logo_height = 40;
$logo_height_mobile = 30;
$logo_link = "";
$font_provider = 'google';
$direction_map = 'google';
$streetview_map = 'google';
$loading_background_color = '#343434';
$loading_text_color = '#fffff';
$enable_intro = 0;
$info_icon = "";
$info_content = "";
$geocoding_provider = 'nominatim';
$default_prefix = "";
$count_languages_enabled = 0;
$pwa_enable = true;
if(isset($_GET['preview'])) {
    $preview = $_GET['preview'];
} else {
    $preview = 0;
}
if(isset($_GET['ignore_embedded'])) {
    $ignore_embedded = $_GET['ignore_embedded'];
} else {
    $ignore_embedded = 0;
}
if(isset($_GET['no_pwa'])) {
    $no_pwa = $_GET['no_pwa'];
} else {
    $no_pwa = 0;
}
if((isset($_GET['furl'])) || (isset($_GET['code']))) {
    if(isset($_GET['furl'])) {
        $furl = strip_tags($_GET['furl']);
        $furl = str_replace("'","\'",$_GET['furl']);
        if(strpos($furl, '--')!==false) {
            list($furl, $marker_f) = explode('--', $furl, 2);
            if(strpos($marker_f, '-')!==false) {
                $parts = explode('-', $marker_f, 2);
                if(isset($parts[0])) {
                    $_GET['m'] = $parts[0];
                }
            }
        }
        if(strpos($furl, "@")!==false) {
            $parts = explode("@", $furl);
            $last_part = end($parts);
            if(strpos($last_part, "_")!==false) {
                $map_language_force = $last_part;
                $furl = str_replace("@$last_part","",$furl);
            }
        }
        if(!empty($furl)) {
            $where = "(friendly_url = '$furl' OR code = '$furl')";
        } else {
            $where = "(code = '$furl')";
        }
    }
    if(isset($_GET['lang'])) {
        $map_language_force = strip_tags($_GET['lang']);
    }
    if(isset($_GET['code'])) {
        $code = strip_tags($_GET['code']);
        $where = "code = '$code'";
    }
    $query = "SELECT * FROM sml_maps WHERE $where LIMIT 1;";
    if($smt = $mysqli->prepare($query)) {
        $result = $smt->execute();
        if($result) {
            $result = get_result($smt);
            if(count($result)==1) {
                $current_map = array_shift($result);
                $id_map = $current_map['id'];
                $code = $current_map['code'];
                $url_map = $url."index.php?code=".$code;
                if(!empty($current_map['logo'])) {
                    $url_logo = $url."logos/".$current_map['logo'];
                }
                if(!$current_map['active']) {
                    if(file_exists("../error_pages/custom/offline_map.html")) {
                        include("../error_pages/custom/offline_map.html");
                    } else {
                        include("../error_pages/default/offline_map.html");
                    }
                    exit;
                }
                if(!$current_map['pwa_enable']) {
                    $pwa_enable = false;
                }
                $map_language = $current_map['language'];
                if(empty($map_language)) $map_language='';
                if(!empty($current_map['languages_enabled'])) {
                    $map_languages_enabled=json_decode($current_map['languages_enabled'],true);
                    foreach ($map_languages_enabled as $lang_enabled) {
                        if($lang_enabled==1) {
                            $count_languages_enabled++;
                        }
                    }
                }
                $query_s = "SELECT language FROM sml_settings LIMIT 1;";
                $result_s = $mysqli->query($query_s);
                if($result_s) {
                    if ($result_s->num_rows == 1) {
                        $row_s = $result_s->fetch_array(MYSQLI_ASSOC);
                        if(!empty($map_language)) {
                            $language = $map_language;
                        } else {
                            $language = $row_s['language'];
                        }
                        $default_language = $language;
                        if(array_key_exists($language,$map_languages_enabled)) {
                            $map_languages_enabled[$language]=1;
                        }
                        if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                            $accepted_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
                            foreach ($accepted_languages as $lang) {
                                if(empty($browser_language)) {
                                    $lang = explode(';', $lang)[0];
                                    $lang = str_replace('-','_',$lang);
                                    if(array_key_exists($lang,$map_languages_enabled)) {
                                        if($map_languages_enabled[$lang]==1) {
                                            $browser_language = $lang;
                                        }
                                    }
                                    if(empty($browser_language)) {
                                        $lang_prefix = substr($lang, 0, 2);
                                        foreach ($map_languages_enabled as $key => $value) {
                                            if($value==1) {
                                                if (strpos($key, $lang_prefix) === 0) {
                                                    $browser_language = $key;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if(empty($map_language_force)) {
                            if(!empty($browser_language)) $language = $browser_language;
                        } else {
                            if(array_key_exists($map_language_force,$map_languages_enabled)) {
                                $language = $map_language_force;
                            }
                        }
                        if($count_languages_enabled>=1) {
                            $query_lang = "SELECT * FROM sml_maps_lang WHERE language='$language' AND id_map=$id_map LIMIT 1;";
                            $result_lang = $mysqli->query($query_lang);
                            if($result_lang) {
                                if ($result_lang->num_rows == 1) {
                                    $row_lang = $result_lang->fetch_array(MYSQLI_ASSOC);
                                    unset($row_lang['id_map']);
                                    unset($row_lang['language']);
                                    $array_vt_lang=$row_lang;
                                }
                            }
                        }
                    }
                }
                if(!empty($current_map['name']) && !empty($array_vt_lang['name'])) {
                    $current_map['name']=$array_vt_lang['name'];
                }
                if(!empty($current_map['meta_title']) && !empty($array_vt_lang['meta_title'])) {
                    $current_map['meta_title']=$array_vt_lang['meta_title'];
                }
                if(!empty($current_map['meta_description']) && !empty($array_vt_lang['meta_description'])) {
                    $current_map['meta_description']=$array_vt_lang['meta_description'];
                }
                if(!empty($current_map['info_content']) && !empty($array_vt_lang['info_content'])) {
                    $current_map['info_content']=$array_vt_lang['info_content'];
                }
                if(!empty($current_map['intro_params']) && !empty($array_vt_lang['intro_params'])) {
                    $row_items = json_decode($current_map['intro_params'], true);
                    $lang_items = json_decode($array_vt_lang['intro_params'], true);
                    if (is_array($row_items) && is_array($lang_items)) {
                        if (!empty($lang_items['title'])) {
                            $row_items['title'] = $lang_items['title'];
                        }
                        if (!empty($lang_items['description'])) {
                            $row_items['description'] = $lang_items['description'];
                        }
                        if (!empty($lang_items['button'])) {
                            $row_items['button'] = $lang_items['button'];
                        }
                    }
                    $current_map['intro_params'] = json_encode($row_items);
                }
                if(!empty($current_map['default_am_placeholders']) && !empty($array_vt_lang['default_am_placeholders'])) {
                    $row_items = json_decode($current_map['default_am_placeholders'], true);
                    $lang_items = json_decode($array_vt_lang['default_am_placeholders'], true);
                    if (is_array($row_items) && is_array($lang_items)) {
                        for($i=1; $i<=20; $i++) {
                            if (!empty($lang_items[$i])) {
                                $row_items[$i] = $lang_items[$i];
                            }
                        }
                    }
                    $current_map['default_am_placeholders'] = json_encode($row_items);
                }
                if(!empty($current_map['song_link'])) {
                    $current_map['song']=$current_map['song_link'];
                }
                $darker_color_hex = adjustBrightness($current_map['main_color_hex'],-0.3);
                if(isset($current_map['password'])) {
                    if(!empty($current_map['password'])) $password=true;
                }
                if(isset($current_map['show_list'])) $show_list = $current_map['show_list'];
                if(isset($current_map['limit_list'])) $limit_list = $current_map['limit_list'];
                if(isset($current_map['default_zoom'])) $default_zoom = $current_map['default_zoom'];
                if(isset($current_map['selected_zoom'])) $selected_zoom = $current_map['selected_zoom'];
                if(isset($current_map['duration_zoom'])) $duration_zoom = $current_map['duration_zoom'];
                if(isset($current_map['density_color'])) $density_color = $current_map['density_color'];
                if(empty($current_map['street_basemap'])) $current_map['street_basemap']='';
                if(empty($current_map['street_basemap_overlay'])) $current_map['street_basemap_overlay']='';
                if(empty($current_map['street_overlay_opacity'])) $current_map['street_overlay_opacity']=0;
                if(empty($current_map['satellite_basemap'])) $current_map['satellite_basemap']='';
                if(empty($current_map['satellite_basemap_overlay'])) $current_map['satellite_basemap_overlay']='';
                if(empty($current_map['satellite_overlay_opacity'])) $current_map['satellite_overlay_opacity']=0;
                if(empty($current_map['street_maxzoom'])) $current_map['street_maxzoom']=20;
                if(empty($current_map['satellite_maxzoom'])) $current_map['satellite_maxzoom']=20;
                if(empty($current_map['meta_title'])) {
                    $meta_title = $current_map['name'];
                } else {
                    $meta_title = $current_map['meta_title'];
                }
                if(empty($current_map['meta_description'])) {
                    $meta_description = '';
                } else {
                    $meta_description = $current_map['meta_description'];
                }
                $show_scale_control = isset($current_map['show_scale_control']) ? $current_map['show_scale_control'] : 1;
                $enable_measure = isset($current_map['enable_measure']) ? $current_map['enable_measure'] : 1;
                $background_image = $current_map['background_image'];
                $background_image_mobile = $current_map['background_image_mobile'];
                if(empty($background_image_mobile)) {
                    $background_image_mobile = $background_image;
                }
                if(empty($current_map['meta_image'])) {
                    $meta_image = $background_image;
                } else {
                    $meta_image = $current_map['meta_image'];
                }
                $_SESSION['marker_images_compression'] = $current_map['marker_images_compression'];
                $_SESSION['marker_images_max_size'] = $current_map['marker_images_max_size'];
                $logo_height = $current_map['logo_height'];
                $logo_height_mobile = $current_map['logo_height_mobile'];
                $logo_link = $current_map['logo_link'];
                $direction_map = $current_map['direction_map'];
                $streetview_map = $current_map['streetview_map'];
                $loading_background_color = $current_map['loading_background_color'];
                $loading_text_color = $current_map['loading_text_color'];
                $auto_start = $current_map['auto_start'];
                $loading_visible = $current_map['loading_visible'];
                $array_share_providers = explode(",",$current_map['share_providers']);
                $enable_intro = ($current_map['enable_intro']) ? 1 : 0;
                $intro_only_direct = ($current_map['intro_only_direct']) ? 1 : 0;
                if($current_map['info_content']=="<p><br></p>") {
                    $current_map['info_enable'] = 0;
                    $current_map['info_auto_open'] = 0;
                }
                if($current_map['info_enable']) {
                    $info_icon = explode("|",$current_map['info_icon'])[0];
                    $info_content = $current_map['info_content'];
                } else {
                    $current_map['info_auto_open'] = 0;
                }
                if(strpos($current_map['cat_filter_type'],'_')!==false) {
                    $current_map['cat_filter_type'] = explode('_',$current_map['cat_filter_type'])[0];
                    $current_map['cat_filter_switch'] = 1;
                } else {
                    $current_map['cat_filter_switch'] = 0;
                }
                if($current_map['map_style']=='custom' && empty($current_map['street_basemap'])) {
                    $current_map['map_style'] = 'osm_free';
                }
                if($current_map['map_style_satellite']=='custom' && empty($current_map['satellite_basemap'])) {
                    $current_map['map_style_satellite'] = 'arcgis';
                }
                $default_prefix = $current_map['default_prefix'];
            }
        }
    }
}
if(count($current_map)==0) {
    if(file_exists("../error_pages/custom/invalid_map.html")) {
        include("../error_pages/custom/invalid_map.html");
    } else {
        include("../error_pages/default/invalid_map.html");
    }
    exit;
}
$num_markers = 0;
$centered_marker_coordinates = null;
$id_map = $current_map['id'];
$query = "SELECT COUNT(id) as num FROM sml_markers WHERE id_map=$id_map AND to_validate=0;";
$result = $mysqli->query($query);
if($result) {
    $row = $result->fetch_array(MYSQLI_ASSOC);
    $num_markers = $row['num'];
}
if(isset($current_map['lazy_loading']) && (int)$current_map['lazy_loading']===2) {
    $query = "SELECT lat,lon FROM sml_markers
              WHERE id_map=$id_map AND to_validate=0 AND centered=1
              ORDER BY id ASC LIMIT 1;";
    $result = $mysqli->query($query);
    if($result && $result->num_rows===1) {
        $row = $result->fetch_array(MYSQLI_ASSOC);
        $centered_marker_coordinates = ['lat'=>(float)$row['lat'],'lon'=>(float)$row['lon']];
    }
}
$use_shp = false;
$query = "SELECT id FROM sml_geodata WHERE id_map=$id_map AND file LIKE '%.zip';";
$result = $mysqli->query($query);
if($result) {
    if($result->num_rows > 0) {
        $use_shp = true;
    }
}
$use_kmz = false;
$query = "SELECT id FROM sml_geodata WHERE id_map=$id_map AND file LIKE '%.kmz';";
$result = $mysqli->query($query);
if($result) {
    if($result->num_rows > 0) {
        $use_kmz = true;
    }
}
$cookie_policy = "";
$enable_tripadvisor = true;
$query = "SELECT language,language_domain,font_provider,share_providers,cookie_policy,terms_and_conditions,privacy_policy,geocoding_provider,pwa_enable,tripadvisor_api_key FROM sml_settings LIMIT 1;";$result = $mysqli->query($query);
if($result) {
    if($result->num_rows==1) {
        $row=$result->fetch_array(MYSQLI_ASSOC);
        $font_provider = $row['font_provider'];
        $cookie_policy = $row['cookie_policy'] ?? '';
        $terms_and_conditions = $row['terms_and_conditions'] ?? '';
        $privacy_policy = $row['privacy_policy'] ?? '';
        $array_share_providers_settings = explode(",",$row['share_providers']);
        $geocoding_provider = $row['geocoding_provider'];
        if(!$row['pwa_enable']) {
            $pwa_enable = false;
        }
        if(empty($row['tripadvisor_api_key'])) {
            $enable_tripadvisor = false;
        }
        switch($language) {
            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($language, 0, 2);
                break;
        }
        $lang_code_2 = str_replace("_","-",$language);
        if (function_exists('gettext')) {
            if(defined('LC_MESSAGES')) {
                $result = setlocale(LC_MESSAGES, $language);
                if(!$result) {
                    setlocale(LC_MESSAGES, $language.'.UTF-8');
                }
                if (function_exists('putenv')) {
                    $result = putenv('LC_MESSAGES='.$language);
                    if(!$result) {
                        putenv('LC_MESSAGES='.$language.'.UTF-8');
                    }
                }
            } else {
                if (function_exists('putenv')) {
                    $result = putenv('LC_ALL='.$language);
                    if(!$result) {
                        putenv('LC_ALL='.$language.'.UTF-8');
                    }
                }
            }
            $domain = $row['language_domain'];
            $result = bindtextdomain($domain, "../locale");
            if(!$result) {
                $domain = "default";
                bindtextdomain($domain, "../locale");
            }
            bind_textdomain_codeset($domain, 'UTF-8');
            textdomain($domain);
        } else {
            if (!function_exists('_')) {
                function _($a) {
                    return $a;
                }
            }
        }
    }
}
$ga_tracking_id = $current_map['ga_tracking_id'];
if(isset($_GET['cat'])) {
    $cat_sel = $_GET['cat'];
} else {
    $cat_sel = 0;
}
if(isset($_GET['m'])) {
    $marker_sel = (int)$_GET['m'];
} else {
    $marker_sel = 0;
}
if(isset($_GET['coord'])) {
    $coordinates = $_GET['coord'];
} else {
    $coordinates = '';
}
if(isset($_GET['zoom'])) {
    $default_zoom = $_GET['zoom'];
}
if(($marker_sel!=0 || !empty($coordinates)) && $intro_only_direct==1) {
    $enable_intro = 0;
}
$add_marker_open = 0;
if(isset($_GET['addm'])) {
    $add_marker_open = $_GET['addm'];
    if($current_map['enable_add_marker']==0) {
        $add_marker_open=0;
    }
}
if(isset($_GET['myloc'])) {
    $myloc = $_GET['myloc'];
} else {
    $myloc = '';
}
$meta_image_url = '';
if($meta_image!='') {
    $meta_image_url = $url."content/".$meta_image;
}
$url_map_s = $url_map;
$selected_marker_coordinates = null;
if($marker_sel!=0) {
    $url_map_s = $url_map."&m=".$marker_sel;
    $query = "SELECT m.id, m.name, m.description, m.lat, m.lon, i.image 
          FROM sml_markers AS m
          LEFT JOIN sml_images AS i ON m.id = i.id_marker AND i.main = 1
          WHERE m.id = $marker_sel AND m.id_map = $id_map AND m.to_validate = 0
          LIMIT 1;";
    $result = $mysqli->query($query);
    if ($result && $result->num_rows === 1) {
        $row = $result->fetch_assoc();
    } else {
        $query = "SELECT m.id, m.name, m.description, m.lat, m.lon, i.image 
              FROM sml_markers AS m
              LEFT JOIN sml_images AS i ON m.id = i.id_marker
              WHERE m.id = $marker_sel AND m.id_map = $id_map AND m.to_validate = 0
              LIMIT 1;";
        $result = $mysqli->query($query);
        $row = ($result && $result->num_rows === 1) ? $result->fetch_assoc() : null;
    }
    if (!empty($row)) {
        $selected_marker_coordinates = ['lat'=>(float)$row['lat'],'lon'=>(float)$row['lon']];
        $marker_name = $row['name'];
        $marker_description = strip_tags($row['description']);
        $marker_image = $row['image'];
        if (!empty($marker_image) && preg_match('/^image_\w+/i', $marker_image)) {
            $meta_image_url = $url . "marker_images/" . $marker_image;
        }
        if (!empty($marker_description)) {
            $meta_description = $marker_description;
        }
        $meta_title .= " - " . $marker_name;
    }
}
$query = "SELECT COUNT(c.id) as count_categories FROM sml_categories as c WHERE c.id_map=?;";
if($smt = $mysqli->prepare($query)) {
    $smt->bind_param('i', $current_map['id']);
    $result = $smt->execute();
    if ($result) {
        $result = get_result($smt);
        if (count($result) == 1) {
            $row = array_shift($result);
            if($row['count_categories']==0) $current_map['enable_categories']=0;
        }
    }
}
if(!empty($current_map['default_extra_fields'])) {
    $default_extra_fields = json_decode($current_map['default_extra_fields'],true);
} else {
    $default_extra_fields = array();
}
if(!empty($current_map['default_am_fields'])) {
    $default_am_fields = json_decode($current_map['default_am_fields'],true);
} else {
    $default_am_fields = array();
}
if(!empty($current_map['default_am_placeholders'])) {
    $default_am_placeholders = json_decode($current_map['default_am_placeholders'],true);
} else {
    $default_am_placeholders = array();
}
if(!empty($current_map['intro_params'])) {
    $intro_params = json_decode($current_map['intro_params'],true);
} else {
    $intro_params = array();
}
$cookie_consent = $current_map['cookie_consent'];
$show_legal = $current_map['show_legal'];
if ((!(array_key_exists('en_US', $map_languages_enabled) && $map_languages_enabled['en_US'] == 1) && (array_key_exists('en_GB', $map_languages_enabled) && $map_languages_enabled['en_GB'] == 1)) || ((array_key_exists('en_US', $map_languages_enabled) && $map_languages_enabled['en_US'] == 1) && !(array_key_exists('en_GB', $map_languages_enabled) && $map_languages_enabled['en_GB'] == 1))) {
    $languages_list['en_GB']['name'] = "English";
    $languages_list['en_US']['name'] = "English";
}
switch($lang_code) {
    case 'ar':
    case 'he':
    case 'fa':
        $dir = "rtl";
        break;
    default:
        $dir = "ltr";
        break;
}
$now = date('Y-m-d H:i:s');
$mysqli->query("DELETE FROM sml_live_tracking WHERE updated_at < '$now' - INTERVAL 1 DAY;");
$id_live_tracking = hash('sha256',uniqid(time(), true));
$live_tracking_hash = "";
if($current_map['live_tracking_only_admin']) {
    $isAdmin = isset($_GET['isAdmin']) ? $_GET['isAdmin'] : '0';
    $live_tracking_hash = isset($_GET['hash']) ? $_GET['hash'] : '';
    if (md5($isAdmin . 'smladmin') === $live_tracking_hash) {
        $_SESSION['live_tracking_view_positions'] = 1;
    } else {
        $_SESSION['live_tracking_view_positions'] = 0;
    }
} else {
    $_SESSION['live_tracking_view_positions'] = 1;
}
if($myloc==0) $current_map['default_my_location']=0;
$viewer_user = false;
$viewer_user_public = null;
$global_settings = get_settings();
$viewer_forgot = false;
$viewer_forgot_email = "";
$viewer_forgot_code = "";
if((int)($current_map['viewer_auth_mode'] ?? 0)>0 && isset($_GET['forgot'])) {
    $viewer_forgot = true;
    if(isset($_GET['email'])) {
        $viewer_forgot_email = strip_tags($_GET['email']);
    }
    if(isset($_GET['verification_code'])) {
        $viewer_forgot_code = strip_tags($_GET['verification_code']);
    }
}
if((int)($current_map['viewer_auth_mode'] ?? 0)>0) {
    $viewer_user = sml_get_viewer_user();
    if($viewer_user!==false) {
        $viewer_user_public = array(
            "id"=>(int)$viewer_user['id'],
            "username"=>$viewer_user['username'],
            "role"=>$viewer_user['role']
        );
        if(isset($viewer_user['email'])) {
            $viewer_user_public['email'] = $viewer_user['email'];
        }
        $viewer_user_public['markers_total'] = 0;
        $viewer_user_public['markers_pending'] = 0;
        $query_user_markers = "SELECT COUNT(*) as total, SUM(CASE WHEN to_validate=1 THEN 1 ELSE 0 END) as pending FROM sml_markers WHERE id_map=? AND id_user=?;";
        if($smt_user_markers = $mysqli->prepare($query_user_markers)) {
            $smt_user_markers->bind_param('ii',$current_map['id'],$viewer_user['id']);
            if($smt_user_markers->execute()) {
                $result_user_markers = get_result($smt_user_markers);
                if(count($result_user_markers)==1) {
                    $row_user_markers = array_shift($result_user_markers);
                    $viewer_user_public['markers_total'] = (int)$row_user_markers['total'];
                    $viewer_user_public['markers_pending'] = (int)$row_user_markers['pending'];
                }
            }
        }
    }
}
$viewer_initials = "";
if($viewer_user!==false) {
    $parts = preg_split('/\s+/', trim($viewer_user['username']));
    foreach($parts as $part) {
        if($part !== '') {
            $viewer_initials = strtoupper(substr($part,0,1));
            break;
        }
    }
    if(empty($viewer_initials)) $viewer_initials = strtoupper(substr($viewer_user['username'],0,1));
}
?>
    <!DOCTYPE HTML>
    <html dir="<?php echo $dir; ?>" lang="<?php echo $lang_code; ?>" style="background-color:<?php echo $loading_background_color; ?>">
    <head>
        <title><?php echo $meta_title; ?></title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1, minimum-scale=1">
        <meta property="og:type" content="website">
        <meta property="twitter:card" content="summary_large_image">
        <meta property="og:url" content="<?php echo $url_map_s; ?>">
        <meta property="twitter:url" content="<?php echo $url_map_s; ?>">
        <meta itemprop="name" content="<?php echo $meta_title; ?>">
        <meta property="og:title" content="<?php echo $meta_title; ?>">
        <meta property="twitter:title" content="<?php echo $meta_title; ?>">
        <?php if($meta_image_url!='') : ?>
            <meta itemprop="image" content="<?php echo $meta_image_url; ?>">
            <meta property="og:image" content="<?php echo $meta_image_url; ?>" />
            <meta property="twitter:image" content="<?php echo $meta_image_url; ?>">
        <?php endif; ?>
        <?php if($meta_description!='') : ?>
            <meta itemprop="description" content="<?php echo $meta_description; ?>">
            <meta name="description" content="<?php echo $meta_description; ?>"/>
            <meta property="og:description" content="<?php echo $meta_description; ?>" />
            <meta property="twitter:description" content="<?php echo $meta_description; ?>">
        <?php endif; ?>
        <meta property="og:locale" content="<?php echo $language; ?>">
        <?php echo print_favicons_map($code,$current_map['logo'],$loading_background_color); ?>
        <?php switch ($font_provider) {
        case 'google': ?>
            <?php if($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 $current_map['font_viewer']; ?>';
                        const e = d.createElement(l);
                        e.rel = s;
                        e.type = 'text/css';
                        e.href = `https://fonts.googleapis.com/css2?family=${fontName}`;
                        e.id = 'font_viewer_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_viewer_link" href="https://fonts.googleapis.com/css2?family=<?php echo $current_map['font_viewer']; ?>">
        <?php } ?>
        <?php break;
        case 'collabs': ?>
        <link rel="preconnect" href="https://api.fonts.coollabs.io" crossorigin>
        <link rel="stylesheet" type="text/css" id="font_viewer_link" href="https://api.fonts.coollabs.io/css2?family=<?php echo $current_map['font_viewer']; ?>&display=swap">
            <?php break;
        } ?>
        <link type="text/css" rel="stylesheet" href="css/ol.css?v=10.10.0">
        <link type="text/css" rel="stylesheet" href="css/ol-ext.min.css?v=4.0.38b">
        <link type="text/css" rel="stylesheet" href="css/ol-contextmenu.min.css?v=5.5.0">
        <link type="text/css" rel="stylesheet" href="vendor/clusterize/clusterize.css">
        <link rel="stylesheet" type="text/css" href="vendor/fontawesome-free/css/fontawesome.min.css?v=7.2.0">
        <link rel="stylesheet" type="text/css" href="vendor/fontawesome-free/css/solid.min.css?v=7.2.0">
        <link rel="stylesheet" type="text/css" href="vendor/fontawesome-free/css/regular.min.css?v=7.2.0">
        <link rel="stylesheet" type="text/css" href="vendor/fontawesome-free/css/brands.min.css?v=7.2.0">
        <link type="text/css" rel="stylesheet" href="vendor/Gallery/css/blueimp-gallery.min.css">
        <link type="text/css" rel="stylesheet" href="vendor/jquery_modal/jquery.modal.min.css">
        <link type="text/css" rel="stylesheet" href="vendor/tooltipster/css/tooltipster.bundle.min.css">
        <link type="text/css" rel="stylesheet" href="vendor/tooltipster/css/plugins/tooltipster/sideTip/themes/tooltipster-sideTip-borderless.min.css">
        <link type="text/css" rel="stylesheet" href="vendor/fancybox/jquery.fancybox.min.css">
        <link type="text/css" rel="stylesheet" href="vendor/owl/assets/owl.carousel.min.css">
        <link type="text/css" rel="stylesheet" href="vendor/owl/assets/owl.theme.default.min.css">
        <link type="text/css" rel="stylesheet" href="css/jquery.dialog.min.css">
        <link type="text/css" rel="stylesheet" href="css/jquery-ui.min.css?v=1.13.2">
        <link type="text/css" rel="stylesheet" href="css/progress.css">
        <link type="text/css" rel="stylesheet" href="vendor/ion.rangeSlider/ion.rangeSlider.min.css">
        <?php if($current_map['enable_globe']!=0) : ?>
            <link href="https://cesium.com/downloads/cesiumjs/releases/1.116/Build/Cesium/Widgets/widgets.css?v=116" rel="stylesheet">
        <?php endif; ?>
        <link rel="stylesheet" type="text/css" href="vendor/jquery-confirm/jquery-confirm.min.css">
        <link rel="stylesheet" type="text/css" href="vendor/switch-style-radio/css/jquery.toggleinput.css">
        <link rel="stylesheet" type='text/css' href="vendor/nanogallery2/css/nanogallery2.min.css" />
        <?php if($dir=='ltr') : ?>
            <link rel="stylesheet" href="vendor/alertifyjs/css/alertify.min.css"/>
            <link rel="stylesheet" href="vendor/alertifyjs/css/themes/default.min.css"/>
            <link rel="stylesheet" href="vendor/alertifyjs/css/themes/semantic.min.css"/>
            <link rel="stylesheet" href="vendor/alertifyjs/css/themes/bootstrap.min.css"/>
        <?php else : ?>
            <link rel="stylesheet" href="vendor/alertifyjs/css/alertify.rtl.min.css"/>
            <link rel="stylesheet" href="vendor/alertifyjs/css/themes/default.rtl.min.css"/>
            <link rel="stylesheet" href="vendor/alertifyjs/css/themes/semantic.rtl.min.css"/>
            <link rel="stylesheet" href="vendor/alertifyjs/css/themes/bootstrap.rtl.min.css"/>
        <?php endif; ?>
        <?php if($cookie_consent) : ?>
            <link rel="stylesheet" type="text/css" href="../backend/vendor/cookieconsent/cookieconsent.min.css?v=3.1.0">
        <?php endif; ?>
        <link type="text/css" rel="stylesheet" href="css/index.css?v=<?php echo $v; ?>">
        <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'custom.css')) : ?>
            <link type="text/css" rel="stylesheet" href="css/custom.css?v=<?php echo $v; ?>">
        <?php endif; ?>
        <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'custom_'.$code.'.css')) : ?>
            <link type="text/css" rel="stylesheet" href="css/custom_<?php echo $code; ?>.css?v=<?php echo $v; ?>">
        <?php endif; ?>
        <script type="text/javascript" src="js/ol.js?v=10.10.0"></script>
        <script type="text/javascript" src="js/olms.js?v=12.5.0"></script>
        <script type="text/javascript" src="js/KMLParser.js"></script>
        <script type="text/javascript" src="js/ol-ext.min.js?v=4.0.38b"></script>
        <script type="text/javascript" src="js/ol-contextmenu.min.js?v=5.5.0"></script>
        <script type="text/javascript" src="js/jquery.min.js?v=3.7.1"></script>
        <script type="text/javascript" src="js/jquery-ui.min.js?v=1.13.2"></script>
        <script type="text/javascript" src="vendor/dragscroll.js"></script>
        <script type="text/javascript" src="js/jquery.searchable.min.js"></script>
        <script type="text/javascript" src="vendor/jquery_modal/jquery.modal.min.js"></script>
        <script type="text/javascript" src="js/gifler.min.js"></script>
        <script type="text/javascript" src="js/jquery-captcha.min.js"></script>
        <script type="text/javascript" src="vendor/tooltipster/js/tooltipster.bundle.min.js"></script>
        <script type="text/javascript" src="https://api.mapbox.com/mapbox.js/plugins/arc.js/v0.1.0/arc.js"></script>
        <script type="text/javascript" src="vendor/fancybox/jquery.fancybox.min.js"></script>
        <script type="text/javascript" src="vendor/clusterize/clusterize.min.js"></script>
        <script type="text/javascript" src="vendor/owl/owl.carousel.min.js"></script>
        <script type="text/javascript" src="js/jquery.dialog.min.js"></script>
        <script type="text/javascript" src="js/progress.min.js"></script>
        <script type="text/javascript" src="vendor/ion.rangeSlider/ion.rangeSlider.min.js"></script>
        <script type="text/javascript" src="js/rangetouch.js?v=3"></script>
        <?php if($current_map['enable_globe']!=0) : ?>
            <script src="https://cesium.com/downloads/cesiumjs/releases/1.116/Build/Cesium/Cesium.js?v=116"></script>
            <script type="text/javascript" src="js/olcesium.js?v=2.17"></script>
        <?php endif; ?>
        <script type="text/javascript" src="vendor/jquery-confirm/jquery-confirm.min.js"></script>
        <script type="text/javascript" src="vendor/switch-style-radio/js/jquery.toggleinput.js"></script>
        <script type="text/javascript" src="vendor/nanogallery2/jquery.nanogallery2.core.min.js"></script>
        <?php if($use_shp || $use_kmz) : ?>
            <script src="vendor/shp2geojson/lib/jszip.js"></script>
            <script src="vendor/shp2geojson/lib/jszip-utils.js"></script>
            <script src="vendor/shp2geojson/proj4.js"></script>
            <script src="vendor/shp2geojson/preprocess.js"></script>
            <script src="vendor/shp2geojson/preview.js"></script>
        <?php endif; ?>
        <script src="vendor/alertifyjs/alertify.min.js"></script>
        <script type="text/javascript" src="vendor/clipboard.js/clipboard.min.js"></script>
        <script src="js/nosleep.min.js"></script>
        <?php if($cookie_consent) : ?>
            <script type="text/javascript" src="../backend/vendor/cookieconsent/cookieconsent.min.js?v=3.1.0"></script>
        <?php endif; ?>
        <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'header'.DIRECTORY_SEPARATOR.'custom.php')) {
            include(__DIR__.DIRECTORY_SEPARATOR.'header'.DIRECTORY_SEPARATOR.'custom.php');
        } ?>
        <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'header'.DIRECTORY_SEPARATOR.'custom_'.$code.'.php')) {
            include(__DIR__.DIRECTORY_SEPARATOR.'header'.DIRECTORY_SEPARATOR.'custom_'.$code.'.php');
        } ?>
    </head>
    <body id="fullscreen" style="background-color:<?php echo $loading_background_color; ?>">
    <div class="map_container">
        <style>
            *{ font-family: '<?php echo $current_map['font_viewer']; ?>', sans-serif; }
            .progress:after,.progress-2:after,.progress-3:after,.progress-4:after,.progress-5:after{
                background: <?php echo $current_map['main_color_hex']; ?>;
            }
            .ol-control button {
                color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .ol-scale-line-inner {
                color: <?php echo $current_map['main_color_hex']; ?>;
                border-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            #button_actions div {
                color: <?php echo $current_map['main_color_hex']; ?>;
                border-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .home_icon, .info_icon {
                color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .nav_marker_next, .nav_marker_prev {
                color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .btn_story, .btn_share_map, .btn_song_map, .globe_icon, .my_position_icon, .featured_icon, .connections_icon {
                color: <?php echo $current_map['main_color_hex']; ?>;
            }
            #measure-btn {
                color: <?php echo $current_map['main_color_hex']; ?>;
            }
            #measure-btn:hover {
                background-color: <?php echo $current_map['main_color_hex']; ?>;
                color: #ffffff;
            }
            #measure-btn.measuring {
                background-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .active_c {
                background-color: <?php echo $current_map['main_color_hex']; ?> !important;
                color: #ffffff !important;
            }
            #featured_categories .category-chip.active_f {
                border: 1px solid <?php echo $current_map['main_color_hex']; ?>;
                box-shadow: inset 0px 0px 1px 1px <?php echo $current_map['main_color_hex']; ?>;
            }
            .tooltipster-sidetip.tooltipster-borderless .tooltipster-box {
                background: <?php echo $current_map['main_color_hex']; ?>;
            }
            .tooltipster-sidetip.tooltipster-borderless.tooltipster-bottom .tooltipster-arrow-border {
                border-bottom-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .tooltipster-sidetip.tooltipster-borderless.tooltipster-left .tooltipster-arrow-border {
                border-left-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .tooltipster-sidetip.tooltipster-borderless.tooltipster-right .tooltipster-arrow-border {
                border-right-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .tooltipster-sidetip.tooltipster-borderless.tooltipster-top .tooltipster-arrow-border {
                border-top-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .direction_profile {
                color: <?php echo $current_map['main_color_hex']; ?>;
                border: 1px solid <?php echo $current_map['main_color_hex']; ?>;
            }
            .direction_profile_active {
                background-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .progress_bar_map .ol-bar {
                background-color: <?php echo hexToRgba($current_map['main_color_hex'],0.8); ?> !important;
            }
            .has-toggle-input label.active {
                background: <?php echo $current_map['main_color_hex']; ?>;
                border-color: <?php echo $current_map['main_color_hex']; ?>;
            }
            .btn_tts, .btn_review_small, .btn_add_photo_small {
                background: <?php echo $current_map['main_color_hex']; ?>;
            }
            <?php if(!$current_map['sheet_detail']) : ?> .list_block { cursor: default; pointer-events: none; } <?php endif; ?>
            @media (hover: hover) {
                .btn_story:focus, .btn_share_map:focus, .btn_song_map:focus, .globe_icon:focus, .my_position_icon:focus, .featured_icon:focus, .connections_icon:focus, .btn_story:hover, .btn_share_map:hover, .btn_song_map:hover, .globe_icon:hover, .my_position_icon:hover, .featured_icon:hover, .connections_icon:hover {
                    background-color: <?php echo $current_map['main_color_hex']; ?>;
                    color: #ffffff;
                }
                .ol-control button:focus, .ol-control button:hover {
                    background-color: <?php echo $current_map['main_color_hex']; ?>;
                    color: #ffffff;
                }
                #button_actions div:hover {
                    background-color: <?php echo $current_map['main_color_hex']; ?>;
                    color: #ffffff;
                }
                .home_icon:hover, .info_icon:hover {
                    background-color: <?php echo $current_map['main_color_hex']; ?>;
                    color: #ffffff;
                }
                .nav_marker_next:hover, .nav_marker_prev:hover {
                    background-color: <?php echo $current_map['main_color_hex']; ?>;
                    color: #ffffff !important;
                }
                .ol-ctx-menu-container li:not(.ol-ctx-menu-separator):hover {
                    background-color: <?php echo $current_map['main_color_hex']; ?>;
                }
            }
        </style>
        <div class="loading hidden" style="color:<?php echo $loading_text_color; ?>">
            <i onclick="start_map();" id="icon_play" class="fas fa-play"></i>
            <div class="protect">
                <?php if($password) { ?>
                    <span class="protect_title noselect"><?php echo _("This Map is password protected"); ?></span><br>
                    <span class="protect_description noselect"></span>
                    <div class="password-wrapper cf">
                        <input autocomplete="new-password" placeholder="<?php echo _("type your password"); ?>" id="map_password" type="text" style="box-shadow:none;color:<?php echo $loading_text_color; ?>" />
                        <button style="background-color:<?php echo $loading_text_color; ?>;color:<?php echo $loading_background_color; ?>" id="btn_check_password" onclick="check_password_map();"><i class="fas fa-sign-in-alt"></i></button>
                    </div>
                <?php } ?>
            </div>
            <div class="progress-circle noselect"></div>
            <div class="progress_map">
                <?php if($current_map['logo']!='') : ?>
                    <img src="logos/<?php echo $current_map['logo']; ?>" />
                <?php endif; ?>
                <h3 class="noselect" id="name_map"><?php echo $current_map['name']; ?></h3>
            </div>
        </div>
        <div id="background_loading" class="background_opacity"></div>
        <?php if($enable_intro) : ?>
            <div style="background-color:<?php echo $intro_params['background']; ?>;" class="intro noselect">
                <div class="intro_content noselect">
                    <?php if(!empty($intro_params['title'])) : ?>
                        <div class="intro_title noselect"><?php echo $intro_params['title']; ?></div>
                        <style>
                            .intro_title {
                                font-size:<?php echo $intro_params['title_size']; ?>px;
                                color:<?php echo $intro_params['title_color']; ?>;
                            }
                            @media screen and (max-width: 600px) {
                                .intro_title {
                                    font-size:<?php echo $intro_params['title_size']/1.3; ?>px;
                                }
                            }
                        </style>
                    <?php endif; ?>
                    <?php if(!empty($intro_params['description'])) : ?>
                        <div class="intro_description noselect"><?php echo nl2br($intro_params['description']); ?></div>
                        <style>
                            .intro_description {
                                font-size:<?php echo $intro_params['description_size']; ?>px;
                                color:<?php echo $intro_params['description_color']; ?>;
                            }
                            @media screen and (max-width: 600px) {
                                .intro_description {
                                    font-size:<?php echo $intro_params['description_size']/1.3; ?>px;
                                }
                            }
                        </style>
                    <?php endif; ?>
                    <?php if(!empty($current_map['intro_image'])) : ?>
                        <div class="intro_image noselect"><img src="content/<?php echo $current_map['intro_image']; ?>" /></div>
                        <style>
                            .intro_image img {
                                max-height:<?php echo $intro_params['image_height']; ?>px;
                            }
                            @media screen and (max-width: 600px) {
                                .intro_image img {
                                    max-height:<?php echo $intro_params['image_height']/1.3; ?>px;
                                }
                            }
                        </style>
                    <?php endif; ?>
                    <?php if(!empty($intro_params['button'])) { ?>
                        <div style="" onclick="close_intro();" class="intro_button noselect"><?php echo $intro_params['button']; ?></div>
                        <style>
                            .intro_button {
                                font-size:<?php echo $intro_params['button_size']; ?>px;
                                background:<?php echo $intro_params['button_background']; ?>;
                                color:<?php echo $intro_params['button_color']; ?>;
                                border: 2px solid <?php echo $intro_params['button_color']; ?>;
                            }
                            .intro_button:hover {
                                background: <?php echo $intro_params['button_color']; ?> !important;
                                color: <?php echo $intro_params['button_background']; ?> !important;
                                border: 2px solid <?php echo $intro_params['button_background']; ?> !important;
                            }
                            @media screen and (max-width: 600px) {
                                .intro_button {
                                    font-size:<?php echo $intro_params['button_size']/1.3; ?>px;
                                }
                            }
                        </style>
                    <?php } else { ?>
                        <script>
                            document.getElementsByClassName('intro')[0].addEventListener('click', function(event) {
                                close_intro();
                            });
                        </script>
                    <?php } ?>
                </div>
            </div>
        <?php endif; ?>
        <div class="map_render">
            <div style="pointer-events: <?php echo ($current_map['logo']!='' && !empty($logo_link)) ? 'initial' : 'none'; ?>" class="logo">
                <?php if($current_map['logo']!='') : ?>
                    <?php if(!empty($logo_link)) { echo "<a target='_blank' href='$logo_link'>"; } ?>
                    <img style="height:<?php echo $logo_height; ?>px" src="logos/<?php echo $current_map['logo']; ?>">
                    <?php if(!empty($logo_link)) { echo "</a>"; } ?>
                <?php endif; ?>
            </div>
            <div style="pointer-events: <?php echo ($current_map['logo_mobile']!='' && !empty($logo_link)) ? 'initial' : 'none'; ?>" class="logo_mobile">
                <?php if($current_map['logo_mobile']!='') : ?>
                    <?php if(!empty($logo_link)) { echo "<a target='_blank' href='$logo_link'>"; } ?>
                    <img style="height:<?php echo $logo_height_mobile; ?>px" src="logos/<?php echo $current_map['logo_mobile']; ?>">
                    <?php if(!empty($logo_link)) { echo "</a>"; } ?>
                <?php endif; ?>
            </div>
            <div style="display:<?php echo ($count_languages_enabled>=1) ? 'block' : 'none'; ?>" class="language_menu noselect">
                <div class="title" onclick="click_language_menu();"><img class="small-element" src="css/flags_lang/<?php echo $language; ?>.png?v=3" /></i>
                    <div class="arrow"></div>
                </div>
                <div class="dropdown">
                    <?php
                    foreach($languages_list as $lang_code => $lang_data) {
                        if(array_key_exists($lang_code, $map_languages_enabled) && $map_languages_enabled[$lang_code] == 1) : ?>
                            <p id="lang_item_<?php echo $lang_code; ?>" class="<?php echo ($language==$lang_code) ? 'active' : ''; ?>" onclick="change_language_map('<?php echo $lang_code; ?>')">
                                <img src="css/flags_lang/<?php echo $lang_code; ?>.png?v=3" />&nbsp;&nbsp;<?php echo $lang_data['name']; ?>
                            </p>
                        <?php endif; } ?>
                </div>
            </div>
            <div data-fancybox data-parent-el=".map_render" data-src="#info_content" href="javascript:;" style="display:<?php echo (empty($info_icon)) ? 'none' : 'block'; ?>" class="info_icon">
                <i class="<?php echo $info_icon; ?>"></i>
            </div>
            <?php if((int)($current_map['viewer_auth_mode'] ?? 0)>0) : ?>
                <div onclick="toggle_viewer_account();" class="viewer_account_btn noselect <?php echo ($viewer_user!==false) ? 'logged' : 'guest'; ?>">
                    <?php if($viewer_user!==false) : ?>
                        <span class="viewer_account_initials"><?php echo htmlspecialchars($viewer_initials); ?></span>
                        <span class="viewer_account_badge"><i class="fas fa-user"></i></span>
                    <?php else : ?>
                        <i class="fas fa-user"></i>
                    <?php endif; ?>
                </div>
                <div class="viewer_account_panel noselect">
                    <?php if($viewer_user!==false) : ?>
                        <div class="viewer_account_name"><?php echo htmlspecialchars($viewer_user['username']); ?></div>
                        <?php if((int)$current_map['enable_add_marker']!=0): ?>
                            <div class="viewer_account_markers">
                                <div><i class="fas fa-map-marker-alt"></i><span><?php echo _("My markers"); ?>: <?php echo (int)$viewer_user_public['markers_total']; ?></span></div>
                                <?php if((int)$viewer_user_public['markers_pending']>0): ?>
                                    <div><i class="fas fa-clock"></i><span><?php echo _("In validation"); ?>: <?php echo (int)$viewer_user_public['markers_pending']; ?></span></div>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                        <button class="viewer_account_action" onclick="viewer_logout();"><i class="fas fa-sign-out-alt"></i><span><?php echo _("Logout"); ?></span></button>
                    <?php else : ?>
                        <button class="viewer_account_action" onclick="open_viewer_login();"><i class="fas fa-sign-in-alt"></i><span><?php echo _("Login"); ?></span></button>
                        <?php if((int)($current_map['viewer_auth_mode'] ?? 0)==2) : ?>
                            <button class="viewer_account_action" onclick="open_viewer_register();"><i class="fas fa-user-plus"></i><span><?php echo _("Register"); ?></span></button>
                        <?php endif; ?>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
            <div style="display:none" id="info_content">
                <?php echo $info_content; ?>
            </div>
            <div class="weather">
                <div id="w_icon"></div>
                <span>--.- &#8451;</span>
            </div>
            <div id="context-menu"></div>
            <div onclick="geolocate()" class="my_position_icon noselect <?php echo $geolocation_disabled; ?>">
                <i class="geolocate_icon fas fa-crosshairs"></i>
                <i style="display:none;" class="geolocate_loading_icon fas fa-spin fa-circle-notch"></i>
            </div>
            <div onclick="go_to_home();" class="home_icon noselect">
                <i class="fas fa-home"></i>
            </div>
            <div class="categories_div noselect"></div>
            <div class="center_right_controls">
                <div onclick="prev_marker()" class="nav_marker_prev noselect disabled <?php echo ($current_map['nav_markers']==0) ? 'hidden' : ''; ?>">
                    <i class="fas fa-chevron-up"></i>
                </div>
                <div onclick="next_marker()" class="nav_marker_next noselect disabled <?php echo ($current_map['nav_markers']==0) ? 'hidden' : ''; ?>">
                    <i class="fas fa-chevron-down"></i>
                </div>
                <?php if($current_map['enable_story']) : ?>
                    <div onclick="show_story();" class="btn_story noselect disabled hidden">
                        <i class="fas fa-list-ol"></i>
                    </div>
                <?php endif; ?>
            </div>
            <div class="center_left_controls">
                <?php if($current_map['enable_share_map']) : ?>
                    <div onclick="toggle_share_map();" class="btn_share_map noselect">
                        <i class="fas fa-share-nodes"></i>
                    </div>
                <?php endif; ?>
                <div onclick="toggle_song();" class="btn_song_map noselect">
                    <i class="fas fa-volume-mute"></i>
                </div>
            </div>
            <?php if($current_map['enable_share_map']) : ?>
                <div class="share_map_section noselect">
                    <div class="a2a_kit a2a_kit_size_32 a2a_default_style share-buttons">
                        <?php if(in_array('copy_link',$array_share_providers_settings)) : ?><a class="a2a_button_copy_link <?php echo (in_array('copy_link',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('email',$array_share_providers_settings)) : ?><a class="a2a_button_email <?php echo (in_array('email',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('whatsapp',$array_share_providers_settings)) : ?><a class="a2a_button_whatsapp <?php echo (in_array('whatsapp',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('facebook',$array_share_providers_settings)) : ?><a class="a2a_button_facebook <?php echo (in_array('facebook',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('threads',$array_share_providers_settings)) : ?><a class="a2a_button_threads <?php echo (in_array('threads',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('twitter',$array_share_providers_settings)) : ?><a class="a2a_button_x <?php echo (in_array('twitter',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('linkedin',$array_share_providers_settings)) : ?><a class="a2a_button_linkedin <?php echo (in_array('linkedin',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('telegram',$array_share_providers_settings)) : ?><a class="a2a_button_telegram <?php echo (in_array('telegram',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('facebook_messenger',$array_share_providers_settings)) : ?><a class="a2a_button_facebook_messenger <?php echo (in_array('facebook_messenger',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('pinterest',$array_share_providers_settings)) : ?><a class="a2a_button_pinterest <?php echo (in_array('pinterest',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('reddit',$array_share_providers_settings)) : ?><a class="a2a_button_reddit <?php echo (in_array('reddit',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('line',$array_share_providers_settings)) : ?><a class="a2a_button_line <?php echo (in_array('line',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('viber',$array_share_providers_settings)) : ?><a class="a2a_button_viber <?php echo (in_array('viber',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('vk',$array_share_providers_settings)) : ?><a class="a2a_button_vk <?php echo (in_array('vk',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('qzone',$array_share_providers_settings)) : ?><a class="a2a_button_qzone <?php echo (in_array('qzone',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        <?php if(in_array('wechat',$array_share_providers_settings)) : ?><a class="a2a_button_wechat <?php echo (in_array('wechat',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                    </div>
                </div>
                <div class="share_popup">
                    <header>
                        <span><?php echo _("Share"); ?></span>
                        <div onclick="close_share_map()" class="share_close"><i class="fas fa-times"></i></div>
                    </header>
                    <div class="share_content">
                        <div style="" class="a2a_kit a2a_kit_size_40 a2a_default_style">
                            <?php if(in_array('email',$array_share_providers_settings)) : ?><a class="a2a_button_email <?php echo (in_array('email',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('whatsapp',$array_share_providers_settings)) : ?><a class="a2a_button_whatsapp <?php echo (in_array('whatsapp',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('facebook',$array_share_providers_settings)) : ?><a class="a2a_button_facebook <?php echo (in_array('facebook',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('twitter',$array_share_providers_settings)) : ?><a class="a2a_button_x <?php echo (in_array('twitter',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('linkedin',$array_share_providers_settings)) : ?><a class="a2a_button_linkedin <?php echo (in_array('linkedin',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('telegram',$array_share_providers_settings)) : ?><a class="a2a_button_telegram <?php echo (in_array('telegram',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('facebook_messenger',$array_share_providers_settings)) : ?><a class="a2a_button_facebook_messenger <?php echo (in_array('facebook_messenger',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('pinterest',$array_share_providers_settings)) : ?><a class="a2a_button_pinterest <?php echo (in_array('pinterest',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('reddit',$array_share_providers_settings)) : ?><a class="a2a_button_reddit <?php echo (in_array('reddit',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('line',$array_share_providers_settings)) : ?><a class="a2a_button_line <?php echo (in_array('line',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('viber',$array_share_providers_settings)) : ?><a class="a2a_button_viber <?php echo (in_array('viber',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('vk',$array_share_providers_settings)) : ?><a class="a2a_button_vk <?php echo (in_array('vk',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('qzone',$array_share_providers_settings)) : ?><a class="a2a_button_qzone <?php echo (in_array('qzone',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('wechat',$array_share_providers_settings)) : ?><a class="a2a_button_wechat <?php echo (in_array('wechat',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        </div>
                        <?php if($cookie_consent) { ?>
                            <script type="text/plain" data-category="functionality" data-service="Social Share (AddToAny)" async src="https://static.addtoany.com/menu/page.js"></script>
                        <?php } else { ?>
                            <script async src="https://static.addtoany.com/menu/page.js"></script>
                        <?php } ?>
                        <?php if(in_array('copy_link',$array_share_providers_settings)) : ?>
                            <div class="share_field">
                                <i class="share_url-icon fas fa-link"></i>
                                <input id="share_link" type="text" readonly value="">
                                <button id="share_button" data-clipboard-target="#share_link"><i class="fas fa-copy"></i></button>
                            </div>
                            <script>
                                var clipboard = new ClipboardJS("#share_button", {
                                    text: function(trigger) {
                                        set_share_link();
                                        return $('#share_link').text();
                                    }
                                });
                                clipboard.on('success', function(e) {
                                    setTooltip(e.trigger, window.viewer_labels.copied+"!");
                                });
                                var timeout_tooltip;
                                function setTooltip(btn, message) {
                                    clearTimeout(timeout_tooltip);
                                    try {
                                        $(btn).tooltip('destroy');
                                    } catch (e) {}
                                    $(btn).attr('title', message);
                                    $(btn).tooltip({
                                        items: '[title]',
                                        content: message,
                                        position: {
                                            my: "right center",
                                            at: "left-6 center",
                                            collision: "flipfit"
                                        },
                                    });
                                    $(btn).tooltip('open');
                                    timeout_tooltip = setTimeout(function() {
                                        $(btn).tooltip('close');
                                        $(btn).tooltip('destroy');
                                    }, 1000);
                                }
                            </script>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endif; ?>
            <script>
                function removeURLParameters(url, paramsToRemove) {
                    const urlObject = new URL(url);
                    paramsToRemove.forEach(param => {
                        if (urlObject.searchParams.has(param)) {
                            urlObject.searchParams.delete(param);
                        }
                    });
                    return urlObject.toString();
                }
                function share_config(share_data) {
                    var url = set_share_link();
                    return {
                        url: url,
                    };
                }
                var a2a_config = a2a_config || {};
                a2a_config.callbacks = a2a_config.callbacks || [];
                a2a_config.callbacks.push({
                    share: share_config,
                });
            </script>
            <div class="bottom_left_controls">
                <div class="switch_style">
                    <img onclick="change_map_style('default_style');" id="default_style" style="display: none" src="images/street.jpg" />
                    <img onclick="change_map_style('satellite_style');" id="satellite_style" src="images/satellite.jpg" />
                </div>
                <div class="overlay_slider noselect">
                    <div class="wrapper">
                        <input oninput="change_opacity_overlay();" type="range" min="0" max="1" value="1" step="0.01" />
                    </div>
                </div>
                <div onclick="toggle_globe()" class="globe_icon noselect hidden">
                    <i class="fas fa-globe"></i>
                </div>
                <div onclick="toggle_connections()" class="connections_icon noselect active_c hidden">
                    <i class="fas fa-exchange-alt"></i>
                </div>
                <div onclick="toggle_featured()" class="featured_icon noselect active_c hidden">
                    <i class="fas fa-bookmark"></i>
                </div>
            </div>
            <div class="btn_bar">
                <?php if($current_map['enable_categories']==1 || $current_map['enable_categories']==3) : ?>
                <div id="slider_categories_featured" class="slider-category-wrapper">
                    <div class="slider-mask-left"></div>
                    <div class="slider-mask-right"></div>
                    <button class="arrow left">
                        <svg viewBox="0 0 24 24"><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/></svg>
                    </button>
                    <div id="featured_categories"></div>
                    <button class="arrow right">
                        <svg viewBox="0 0 24 24"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>
                    </button>
                </div>
                <?php endif; ?>
                <?php if($current_map['enable_add_marker']!=0) : ?>
                    <div style="opacity:0;pointer-events:none" onclick="open_add_new_marker();" class="new_marker_btn noselect disabled">
                        <i style="vertical-align:middle"  class="fas fa-plus-circle"></i>&nbsp;&nbsp;<?php echo _("add new marker"); ?>
                    </div>
                    <br>
                <?php endif; ?>
                <?php if($current_map['live_tracking']!=0) : ?>
                    <div style="opacity:0;pointer-events:none" onclick="open_live_tracking();" class="live_tracking_btn noselect">
                        <i style="vertical-align:middle"  class="fas fa-location-arrow"></i>&nbsp;&nbsp;<?php echo _("live tracking"); ?>
                    </div>
                    <div style="opacity:0;pointer-events:none" onclick="stop_live_tracking();" class="live_tracking_stop_btn hidden noselect">
                        <i style="vertical-align:middle"  class="fas fa-stop"></i>&nbsp;&nbsp;<?php echo _("stop tracking"); ?>
                    </div>
                    <span class="<?php echo ($_SESSION['live_tracking_view_positions']==0) ? 'hidden' : ''; ?>" id="live_tracking_count"><b>0</b> <?php echo _("online"); ?></span>
                <?php endif; ?>
            </div>
            <div class="new_marker_msg noselect">
                <i style="vertical-align:middle"  class="fas fa-mouse"></i>&nbsp;&nbsp;<?php echo _("click on the map and place your marker"); ?>&nbsp;&nbsp;<i onclick="close_new_marker(false)" class="new_marker_cancel fas fa-times-circle"></i>
            </div>
            <div class="drag_marker_msg noselect">
                <i style="vertical-align:middle"  class="far fa-hand-rock"></i>&nbsp;&nbsp;<?php echo _("drag the marker to adjust the position"); ?>&nbsp;&nbsp;<span onclick="confirm_drag_new_marker()" class="new_marker_confirm"><i class="fas fa-check"></i>&nbsp;&nbsp;<?php echo _("confirm"); ?></span>&nbsp;&nbsp;<i onclick="close_new_marker(false)" class="new_marker_cancel fas fa-times-circle"></i>
            </div>
            <div id="featured_container"></div>
            <div class="sheet_detail dragscroll">
                <div class="sheet_detail_container">
                    <div onclick="close_sheet_detail()" id="close_btn_sd" class="<?php echo ($current_map['enable_search']) ? 'hidden' : ''; ?>">
                        <i class="fas fa-times"></i>
                    </div>
                    <div class="sheet_detail_image noselect" style="background-image:url('images/placeholder.jpg');"></div>
                    <video playsinline muted loop class="sheet_detail_video animated-background noselect"></video>
                    <div id="slider_categories_marker" class="slider-category-wrapper">
                        <div class="slider-mask-left"></div>
                        <div class="slider-mask-right"></div>
                        <button class="arrow left">
                            <svg viewBox="0 0 24 24"><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/></svg>
                        </button>
                        <div id="sheet_categories"></div>
                        <button class="arrow right">
                            <svg viewBox="0 0 24 24"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>
                        </button>
                    </div>
                    <div id="store_name" class="sheet_detail_name noselect"></div>
                    <div id="button_actions">
                        <div title="<?php echo _("DIRECTIONS"); ?>" class="btn_direction <?php echo (!$current_map['enable_directions']) ? 'hidden' : ''; ?>"><i class="fas fa-directions"></i></div>
                        <div title="<?php echo _("STREET VIEW"); ?>" class="btn_streetview <?php echo (!$current_map['enable_streetview']) ? 'hidden' : ''; ?>"><i class="fas fa-street-view"></i></div>
                        <div title="<?php echo _("ADD PHOTO"); ?>" onclick="open_modal_add_photo();" class="btn_add_photo <?php echo (!$current_map['enable_add_photo']) ? 'hidden' : ''; ?>"><i class="fas fa-camera"></i></div>
                        <div title="<?php echo _("WRITE A REVIEW"); ?>" onclick="open_modal_new_review();" class="btn_review disabled <?php echo (!$current_map['enable_reviews']) ? 'hidden' : ''; ?>"><i class="fas fa-feather-alt"></i></div>
                        <div style="display: none;" title="<?php echo _("EDIT"); ?>" onclick="open_edit_own_marker();" class="btn_edit_own_marker"><i class="fas fa-pen"></i></div>
                        <div style="display: none;" title="<?php echo _("DELETE"); ?>" onclick="delete_own_marker();" class="btn_delete_own_marker"><i class="fas fa-trash"></i></div>
                        <div style="display: none;" title="" onclick="" class="btn_custom_1"><i class=""></i></div>
                    </div>
                    <div id="box_warning_container" class="sheet_detail_features noselect">
                        <div class="features_icon"><i class="fas fa-exclamation"></i></div>
                        <div id="box_warning" class="features_value"></div>
                    </div>
                    <div id="last_update_container">
                        <i class="far fa-clock"></i> <?php echo _("Last update"); ?>:&nbsp;<span id="last_update_date">--</span>
                    </div>
                    <hr>
                    <div class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("Address"); ?>" class="fas fa-map-marker-alt"></i></div>
                        <div id="store_address" class="features_value"></div>
                    </div>
                    <div style="display:none;" class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("Distance"); ?>" class="fas fa-walking"></i></div>
                        <div id="store_distance" class="features_value"></div>
                    </div>
                    <div class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("Website"); ?>" class="fas fa-link"></i></div>
                        <div id="store_website" class="features_value"></div>
                    </div>
                    <div class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("E-Mail"); ?>" class="far fa-envelope"></i></div>
                        <div id="store_email" class="features_value"></div>
                    </div>
                    <div class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("Phone"); ?>" class="fas fa-phone"></i></div>
                        <div id="store_phone" class="features_value"></div>
                    </div>
                    <div class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("Website"); ?>" class="fab fa-whatsapp"></i></div>
                        <div id="store_whatsapp" class="features_value"></div>
                    </div>
                    <div class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("Hours"); ?>" class="far fa-clock"></i></div>
                        <div id="store_hours" class="features_value"></div>
                    </div>
                    <div class="sheet_detail_features noselect">
                        <div class="features_icon"><i title="<?php echo _("Description"); ?>" class="far fa-comment-alt"></i></div>
                        <div id="store_description" class="features_value"></div>
                    </div>
                    <?php for($k=1;$k<=20;$k++) { ?>
                        <div class="sheet_detail_features noselect" style="display: none">
                            <div id="icon_e<?php echo $k; ?>" class="features_icon features_icon_e"><i title="" class=""></i></div>
                            <div id="field_e<?php echo $k; ?>" class="features_value"></div>
                        </div>
                    <?php } ?>
                    <div class="sheet_detail_features sheet_detail_feature_images noselect">
                        <div class="features_icon" style="margin-top:5px;"><i title="<?php echo _("Media"); ?>" class="far fa-images"></i></div>
                        <div class="features_value">
                            <div id="sheet_images" style="margin-left:0px;"></div>
                            <div onclick="open_modal_add_photo();" class="btn_add_photo_small hide <?php echo (!$current_map['enable_add_photo']) ? 'hidden' : ''; ?>"><i class="fas fa-camera"></i>&nbsp;&nbsp;<?php echo _("Add a photo"); ?></div>
                        </div>
                    </div>
                    <div id="report_issue_div" class="sheet_detail_features noselect <?php echo (!$current_map['enable_issue_reports']) ? 'hidden' : ''; ?>">
                        <div class="features_icon"><i class="fas fa-triangle-exclamation"></i></div>
                        <div class="features_value"><?php echo _("See a problem?"); ?>&nbsp;&nbsp;<span onclick="open_modal_report_issue();"><?php echo _("Let us know"); ?></span></div>
                    </div>
                    <hr>
                    <div class="share_section noselect <?php echo (!$current_map['enable_share']) ? 'hidden' : ''; ?>">
                        <div onclick="alert_share_cookie_denied();" class="btn_share_cookie_denied noselect">
                            <i class="fas fa-share-nodes"></i>
                        </div>
                        <div class="a2a_kit a2a_kit_size_32 a2a_default_style share-buttons">
                            <?php if(in_array('copy_link',$array_share_providers_settings)) : ?><a class="a2a_button_copy_link <?php echo (in_array('copy_link',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('email',$array_share_providers_settings)) : ?><a class="a2a_button_email <?php echo (in_array('email',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('whatsapp',$array_share_providers_settings)) : ?><a class="a2a_button_whatsapp <?php echo (in_array('whatsapp',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('facebook',$array_share_providers_settings)) : ?><a class="a2a_button_facebook <?php echo (in_array('facebook',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('threads',$array_share_providers_settings)) : ?><a class="a2a_button_threads <?php echo (in_array('threads',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('twitter',$array_share_providers_settings)) : ?><a class="a2a_button_x <?php echo (in_array('twitter',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('linkedin',$array_share_providers_settings)) : ?><a class="a2a_button_linkedin <?php echo (in_array('linkedin',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('telegram',$array_share_providers_settings)) : ?><a class="a2a_button_telegram <?php echo (in_array('telegram',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('facebook_messenger',$array_share_providers_settings)) : ?><a class="a2a_button_facebook_messenger <?php echo (in_array('facebook_messenger',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('pinterest',$array_share_providers_settings)) : ?><a class="a2a_button_pinterest <?php echo (in_array('pinterest',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('reddit',$array_share_providers_settings)) : ?><a class="a2a_button_reddit <?php echo (in_array('reddit',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('line',$array_share_providers_settings)) : ?><a class="a2a_button_line <?php echo (in_array('line',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('viber',$array_share_providers_settings)) : ?><a class="a2a_button_viber <?php echo (in_array('viber',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('vk',$array_share_providers_settings)) : ?><a class="a2a_button_vk <?php echo (in_array('vk',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('qzone',$array_share_providers_settings)) : ?><a class="a2a_button_qzone <?php echo (in_array('qzone',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                            <?php if(in_array('wechat',$array_share_providers_settings)) : ?><a class="a2a_button_wechat <?php echo (in_array('wechat',$array_share_providers) ? '' : 'hidden'); ?>"></a><?php endif; ?>
                        </div>
                        <hr>
                    </div>
                    <div class="tripadvisor-section noselect <?php echo (!$enable_tripadvisor) ? 'hidden' : ''; ?>">
                        <div id="tripadvisor_container"></div>
                        <hr>
                    </div>
                    <div class="review-section noselect <?php echo (!$current_map['enable_reviews']) ? 'hidden' : ''; ?>">
                        <div class="rating-part">
                            <div class="average-rating">
                                <h2>-</h2>
                                <span class="rating"></span>
                                <p style="display: none"><?php echo _("Average Rating"); ?></p>
                                <p class="total_reviews"><b>-</b> <?php echo _("reviews"); ?></p>
                            </div>
                            <div class="loder-ratimg">
                                <style id="rating_bars_style"></style>
                                <div class="progress"></div>
                                <div class="progress-2"></div>
                                <div class="progress-3"></div>
                                <div class="progress-4"></div>
                                <div class="progress-5"></div>
                            </div>
                            <div class="start-part">
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <br>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <br>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <br>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <br>
                                <i aria-hidden="true" class="fas fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                                <i aria-hidden="true" class="far fa-star"></i>
                            </div>
                            <div style="clear: both;"></div>
                            <div onclick="open_modal_new_review();" class="btn_review btn_review_small disabled <?php echo (!$current_map['enable_reviews']) ? 'hidden' : ''; ?>"><i class="fas fa-feather-alt"></i>&nbsp;&nbsp;<?php echo _("Write a review"); ?></div>
                            <hr>
                            <div id="div_comments"></div>
                        </div>
                    </div>
                </div>
                <div onclick="resize_sheet_detail('up');" class="resize_sheet_icon"><i class="fas fa-caret-up"></i></div>
            </div>
            <div class="direction_detail">
                <div class="direction_detail_container">
                    <div id="direction_loading">
                        <div class="direction_features noselect">
                            <div class="features_icon"><i class="fas fa-spin fa-circle-notch"></i></div>
                            <div class="features_value">
                                <?php echo _("loading route in progress"); ?>...
                            </div>
                        </div>
                    </div>
                    <div style="display:none;" id="direction_detail_div">
                        <div class="direction_features noselect">
                            <div data-profile="driving-car" onclick="change_ors_direction('driving-car');" class="direction_profile direction_profile_active"><i class="fas fa-car"></i></div>
                            <div data-profile="foot-walking" onclick="change_ors_direction('foot-walking');" class="direction_profile"><i class="fas fa-walking"></i></div>
                            <div data-profile="cycling-regular" onclick="change_ors_direction('cycling-regular');" class="direction_profile"><i class="fas fa-bicycle"></i></div>
                            <div data-profile="wheelchair" onclick="change_ors_direction('wheelchair');" class="direction_profile"><i class="fas fa-wheelchair"></i></div>
                            <div data-profile="driving-hgv" onclick="change_ors_direction('driving-hgv');" class="direction_profile"><i class="fas fa-bus"></i></div>
                        </div>
                        <div class="direction_features noselect">
                            <div class="features_icon"><div style="background-color:green;">A</div></div>
                            <div class="features_value" style="display:flex; gap:5px;">
                                <input style="flex:1; margin-bottom:0;" autofill="off" autocomplete="off" id="direction_start_point" type="text" readonly value="<?php echo _("My Location"); ?>" />
                                <div id="btn_select_start_map" onclick="enable_select_start_point();" style="cursor:pointer; background:#2f2f2f; color:white; padding:0 8px; border-radius:4px; line-height:26px;" title="<?php echo _("Select on map"); ?>"><i class="fas fa-crosshairs"></i></div>
                                <div id="btn_reset_start_map" onclick="reset_start_point();" style="display:none; cursor:pointer; background:#dc2626; color:white; padding:0 8px; border-radius:4px; line-height:26px;" title="<?php echo _("Reset to My Location"); ?>"><i class="fas fa-undo"></i></div>
                            </div>
                        </div>
                        <div id="direction_waypoints_container"></div>
                        <div class="direction_features noselect" style="margin-top: 5px; margin-bottom: 5px; padding-left: 36px;">
                            <span onclick="add_empty_waypoint();" style="cursor:pointer; font-size:12px; font-weight:bold; color: #555;"><i class="fas fa-plus-circle"></i> <?php echo _("Add Stop"); ?></span>
                        </div>
                        <div class="direction_features noselect">
                            <div class="features_icon"><div style="background-color:red;">B</div></div>
                            <div class="features_value" style="display:flex; gap:5px;">
                                <input style="flex:1; margin-bottom:0;" autofill="off" autocomplete="off" id="direction_end_point" type="text" readonly value="" />
                                <div id="btn_select_end_map" onclick="enable_select_end_point();" style="cursor:pointer; background:#2f2f2f; color:white; padding:0 8px; border-radius:4px; line-height:26px;" title="<?php echo _("Select on map"); ?>"><i class="fas fa-crosshairs"></i></div>
                                <div id="btn_reset_end_map" onclick="reset_end_point();" style="display:none; cursor:pointer; background:#dc2626; color:white; padding:0 8px; border-radius:4px; line-height:26px;" title="<?php echo _("Reset Destination"); ?>"><i class="fas fa-undo"></i></div>
                            </div>
                        </div>
                        <div class="direction_features noselect" style="margin-top: 10px">
                            <div class="features_icon"><i class="fas fa-clock"></i></div>
                            <div class="features_value">
                                <b id="direction_duration">--</b>
                            </div>
                        </div>
                        <div class="direction_features noselect">
                            <div class="features_icon"><i class="fas fa-arrows-alt-h"></i></div>
                            <div class="features_value">
                                <b id="direction_length">--</b>
                            </div>
                        </div>
                        <hr style="margin: 15px 10px 5px 10px; border: 0; border-top: 1px solid #ccc;">
                        <div id="direction_steps" class="direction_steps_container"></div>
                    </div>
                </div>
                <div onclick="resize_direction_detail('up');" class="resize_direction_icon resize_sheet_icon"><i class="fas fa-caret-up"></i></div>
            </div>
            <div class="new_sheet_detail">
                <div class="new_sheet_detail_container">
                    <form autofill="off" autocomplete="off">
                        <div class="new_sheet_detail_image noselect <?php echo (array_key_exists('images',$default_am_fields)) ? (($default_am_fields['images']==1) ? '' : 'hidden') : ''; ?>" style="background-image:url('images/placeholder.jpg');"></div>
                        <div id="new_store_name" class="sheet_detail_name noselect">
                            <input autofill="off" autocomplete="off" tabindex="1" id="new_name" type="text" placeholder="<?php echo _("Name"); ?> *" />
                        </div>
                        <hr>
                        <div id="new_store_coordinates_container" class="sheet_detail_features noselect">
                            <div class="features_icon"><i class="fas fa-globe"></i></div>
                            <div id="new_store_coordinates" class="features_value">
                                <input autofill="off" autocomplete="off" style="margin-right: 5px;" id="new_latitude" type="text" placeholder="<?php echo _("Latitude"); ?> *" />
                                <input autofill="off" autocomplete="off" id="new_longitude" type="text" placeholder="<?php echo _("Longitude"); ?> *" />
                            </div>
                        </div>
                        <?php $add_marker_fields_mandatory = explode(",",$current_map['add_marker_fields_mandatory']); ?>
                        <div id="new_category_container" class="sheet_detail_features noselect <?php echo (array_key_exists('categories',$default_am_fields)) ? (($default_am_fields['categories']==1) ? '' : 'hidden') : ''; ?> <?php echo ($current_map['enable_categories']==0) ? 'hidden' : ''; ?>">
                            <div class="features_icon"><i class="fas fa-list"></i></div>
                            <div id="new_category_div" class="features_value">
                                <select <?php echo ($current_map['add_marker_multiple_category']) ? 'multiple' : ''; ?>  id="new_category" data-mandatory="<?php echo (in_array('categories',$add_marker_fields_mandatory) ? 1 : 0) ?>">
                                    <?php echo get_categories_viewer($current_map['id'],0,$language); ?>
                                </select>
                            </div>
                        </div>
                        <div id="new_store_street_container" class="sheet_detail_features noselect <?php echo (array_key_exists('street',$default_am_fields)) ? (($default_am_fields['street']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="fas fa-map-marker-alt"></i></div>
                            <div id="new_store_street" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="2" id="new_street" type="text" data-mandatory="<?php echo (in_array('street',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("Address").(in_array('street',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <div id="new_store_city_container" class="sheet_detail_features noselect <?php echo (array_key_exists('city',$default_am_fields)) ? (($default_am_fields['city']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="fas fa-map-marker-alt"></i></div>
                            <div id="new_store_city" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="3" id="new_city" type="text" data-mandatory="<?php echo (in_array('city',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("City").(in_array('city',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <div id="new_store_postal_code_container" class="sheet_detail_features noselect <?php echo (array_key_exists('postal_code',$default_am_fields)) ? (($default_am_fields['postal_code']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="fas fa-map-marker-alt"></i></div>
                            <div id="new_store_postal_code" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="5" id="new_postal_code" type="text" data-mandatory="<?php echo (in_array('postal_code',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("Postal Code").(in_array('postal_code',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <div id="new_store_county_container" class="sheet_detail_features noselect <?php echo (array_key_exists('county',$default_am_fields)) ? (($default_am_fields['county']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="fas fa-map-marker-alt"></i></div>
                            <div id="new_store_county" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="6" id="new_county" type="text" data-mandatory="<?php echo (in_array('county',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("County").(in_array('county',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <div id="new_store_state_container" class="sheet_detail_features noselect <?php echo (array_key_exists('state',$default_am_fields)) ? (($default_am_fields['state']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="fas fa-map-marker-alt"></i></div>
                            <div id="new_store_state" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="4" id="new_state" type="text" data-mandatory="<?php echo (in_array('state',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("State / Province").(in_array('state',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <div id="new_store_country_container" class="sheet_detail_features noselect <?php echo (array_key_exists('country',$default_am_fields)) ? (($default_am_fields['country']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="fas fa-map-marker-alt"></i></div>
                            <div id="new_store_country" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="7" id="new_country" type="text" data-mandatory="<?php echo (in_array('country',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("Country").(in_array('country',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <div id="new_store_website_container" class="sheet_detail_features noselect <?php echo (array_key_exists('website',$default_am_fields)) ? (($default_am_fields['website']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="fas fa-link"></i></div>
                            <div id="new_store_website" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="8" id="new_website" type="text" data-mandatory="<?php echo (in_array('website',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("Website").(in_array('website',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <div id="new_store_email_container" class="sheet_detail_features noselect <?php echo (array_key_exists('email',$default_am_fields)) ? (($default_am_fields['email']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="far fa-envelope"></i></div>
                            <div id="new_store_email" class="features_value">
                                <input autofill="off" autocomplete="off" tabindex="9" id="new_email" type="text" data-mandatory="<?php echo (in_array('email',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("E-mail").(in_array('email',$add_marker_fields_mandatory) ? ' *' : ''); ?>" />
                            </div>
                        </div>
                        <?php
                        generateSheetPhoneInput(
                            'phone',
                            'fas fa-phone',
                            '10',
                            '',
                            $default_am_fields,
                            $add_marker_fields_mandatory,
                            $default_prefix
                        );
                        ?>
                        <?php
                        generateSheetPhoneInput(
                            'whatsapp',
                            'fab fa-whatsapp',
                            '11',
                            '',
                            $default_am_fields,
                            $add_marker_fields_mandatory,
                            $default_prefix
                        );
                        ?>
                        <div id="new_store_hours_container" class="sheet_detail_features noselect <?php echo (array_key_exists('hours',$default_am_fields)) ? (($default_am_fields['hours']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="far fa-clock"></i></div>
                            <div id="new_store_hours" class="features_value">
                                <textarea autofill="off" autocomplete="off" tabindex="12" id="new_hours" rows="2" data-mandatory="<?php echo (in_array('hours',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("Hours").(in_array('hours',$add_marker_fields_mandatory) ? ' *' : ''); ?>"></textarea>
                            </div>
                        </div>
                        <div id="new_store_description_container" class="sheet_detail_features noselect <?php echo (array_key_exists('description',$default_am_fields)) ? (($default_am_fields['description']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="far fa-comment-alt"></i></div>
                            <div id="new_store_description" class="features_value">
                                <textarea autofill="off" autocomplete="off" tabindex="13" id="new_description" rows="2" data-mandatory="<?php echo (in_array('description',$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo _("Description").(in_array('description',$add_marker_fields_mandatory) ? ' *' : ''); ?>"></textarea>
                            </div>
                        </div>
                        <?php for($i=1;$i<=20;$i++) { ?>
                            <div id="new_store_field_<?php echo $i; ?>_container" class="sheet_detail_features noselect <?php echo (array_key_exists('field_'.$i,$default_am_fields)) ? (($default_am_fields['field_'.$i]==1) ? '' : 'hidden') : 'hidden'; ?>">
                                <div class="features_icon"><i class="<?php echo (array_key_exists($i,$default_extra_fields)) ? $default_extra_fields[$i] : 'far fa-circle'; ?>"></i></div>
                                <div id="new_store_field_<?php echo $i; ?>" class="features_value new_store_field">
                                    <textarea autofill="off" autocomplete="off" tabindex="<?php echo (13+$i); ?>" id="new_field_<?php echo $i; ?>" rows="2" data-mandatory="<?php echo (in_array('field'.$i,$add_marker_fields_mandatory) ? 1 : 0) ?>" placeholder="<?php echo ((array_key_exists($i,$default_am_placeholders)) ? (!empty($default_am_placeholders[$i]) ? $default_am_placeholders[$i] : '') : '').(in_array('field'.$i,$add_marker_fields_mandatory) ? ' *' : ''); ?>"></textarea>
                                </div>
                            </div>
                        <?php } ?>
                    </form>
                    <?php if($current_map['marker_images_num']!=0) : ?>
                        <div class="sheet_detail_features sheet_detail_feature_images noselect <?php echo (array_key_exists('images',$default_am_fields)) ? (($default_am_fields['images']==1) ? '' : 'hidden') : ''; ?>">
                            <div class="features_icon"><i class="far fa-images"></i></div>
                            <div class="features_value">
                                <div id="sheet_images" style="margin-left:-5px;margin-top: -5px;">
                                    <div id="uploaded_images" data-mandatory="<?php echo (in_array('images',$add_marker_fields_mandatory) ? 1 : 0) ?>"></div>
                                    <form autocomplete="off" id="frm" action="ajax/upload_new_marker_image.php" method="POST" enctype="multipart/form-data">
                                        <label for="txtFile">
                                            <div id="new_image_btn"><i class="fas fa-upload"></i></div>
                                        </label>
                                        <input accept="image/*,text/plain" type="file" style="display:none" id="txtFile" name="txtFile" />
                                        <input style="display: none;" type="submit" class="btn btn-block btn-success" id="btnUpload" />
                                    </form>
                                    <button onclick="delete_images();" id="btn_delete_images" style="clear:both;display:block;pointer-events:none;opacity:0.5"><?php echo _("delete images"); ?></button>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                    <hr>
                    <div id="new_button_actions">
                        <div onclick="close_new_marker(false)" class="btn_cancel_marker">
                            <i class="fas fa-times"></i> <?php echo _('CANCEL'); ?>
                        </div>
                        <div onclick="add_new_marker();" class="btn_add_marker">
                            <i class="fas fa-plus"></i> <?php echo _('SUBMIT'); ?>
                        </div>
                    </div>
                </div>
            </div>
            <div id="modal_new_review" class="modal" data-backdrop="static" data-keyboard="false">
                <form autofill="off" autocomplete="off" id="form_new_review" action="" method="post" onsubmit="add_review();return false;">
                    <fieldset class="noselect title_modal">
                        <span><?php echo _("Write Review"); ?></span>
                    </fieldset>
                    <fieldset class="noselect" id="new_rating">
                        <span><?php echo _("Your Rating"); ?></span>&nbsp;&nbsp;
                        <i onclick="set_rating(1);" aria-hidden="true" class="far fa-star"></i>
                        <i onclick="set_rating(2);" aria-hidden="true" class="far fa-star"></i>
                        <i onclick="set_rating(3);" aria-hidden="true" class="far fa-star"></i>
                        <i onclick="set_rating(4);" aria-hidden="true" class="far fa-star"></i>
                        <i onclick="set_rating(5);" aria-hidden="true" class="far fa-star"></i>
                    </fieldset>
                    <fieldset>
                        <input autofill="off" autocomplete="off" id="review_name" placeholder="<?php echo _("Your Name"); ?> *" type="text" tabindex="1" required>
                    </fieldset>
                    <fieldset>
                        <input autofill="off" autocomplete="off" id="review_email" placeholder="<?php echo _("Your Email Address (optional)"); ?>" type="email" tabindex="2">
                    </fieldset>
                    <fieldset>
                        <textarea autofill="off" autocomplete="off" id="review_comment" placeholder="<?php echo _("Type your Review here"); ?> *" tabindex="3" required></textarea>
                    </fieldset>
                    <fieldset class="viewer_captcha_field" data-feature="review">
                        <canvas id="captcha_canvas"></canvas>
                        <input autofill="off" autocomplete="off" id="captcha_code" type="text" placeholder="<?php echo _("Type the code above"); ?> *" tabindex="4" required />
                    </fieldset>
                    <fieldset>
                        <button id="review_submit" name="submit" type="submit" class="disabled"><?php echo _("Submit"); ?></button>
                    </fieldset>
                </form>
                <div id="review_feedback"><?php echo _("Thanks for your review!"); ?></div>
            </div>
            <div id="modal_add_photo" class="modal" data-backdrop="static" data-keyboard="false">
                <form autofill="off" autocomplete="off" id="form_add_photo" action="" method="post" enctype="multipart/form-data" onsubmit="add_photo(event);return false;">
                    <fieldset class="noselect title_modal">
                        <span><?php echo _("Add Photo"); ?></span>
                    </fieldset>
                    <fieldset>
                        <input autofill="off" autocomplete="off" id="photo_name" placeholder="<?php echo _("Your Name"); ?> *" type="text" tabindex="1" required>
                    </fieldset>
                    <fieldset>
                        <input autofill="off" autocomplete="off" id="photo_email" placeholder="<?php echo _("Your Email Address (optional)"); ?>" type="email" tabindex="2">
                    </fieldset>
                    <fieldset>
                        <div id="photo_dropzone" class="drag-drop-zone noselect">
                            <div class="dz-message">
                                <i class="fas fa-cloud-upload-alt"></i><br>
                                <span id="dz-text"><?php echo _("Drag & Drop your photo here or click to browse"); ?></span>
                            </div>
                            <div id="photo_preview_container" style="display: none;">
                                <img id="photo_preview_image" src="" alt="Preview">
                                <div class="dz-hover-overlay">
                                    <i class="fas fa-sync-alt"></i><br>
                                    <span><?php echo _("Click or drag to change"); ?></span>
                                </div>
                            </div>
                            <input accept="image/*" id="photo_file" type="file" tabindex="3" style="display: none;">
                        </div>
                    </fieldset>
                    <fieldset style="margin-bottom: 10px; font-size: 12px; display: flex; align-items: flex-start; gap: 8px;">
                        <input type="checkbox" id="photo_copyright" required tabindex="4" style="margin-top: 1px; width: auto; cursor: pointer;">
                        <label for="photo_copyright" style="margin: 0; cursor: pointer; line-height: 1.4;"><?php echo _("I do not violate any copyright or personal rights with uploaded photos."); ?></label>
                    </fieldset>
                    <fieldset class="viewer_captcha_field" data-feature="add_photo">
                        <canvas id="photo_captcha_canvas"></canvas>
                        <input autofill="off" autocomplete="off" id="photo_captcha_code" type="text" placeholder="<?php echo _("Type the code above"); ?> *" tabindex="5" required />
                    </fieldset>
                    <fieldset>
                        <button id="photo_submit" name="submit" type="submit"><?php echo _("Submit"); ?></button>
                    </fieldset>
                </form>
                <div id="photo_feedback"><?php echo _("Thanks for your photo! It will be visible on the map as soon as it is approved."); ?></div>
            </div>
            <div id="modal_report_issue" class="modal">
                <form autofill="off" autocomplete="off" id="form_report_issue" action="" method="post" onsubmit="add_report_issue();return false;">
                    <fieldset class="noselect title_modal">
                        <span><?php echo _("Issue Report"); ?></span>
                    </fieldset>
                    <fieldset>
                        <input autofill="off" autocomplete="off" id="issue_name" placeholder="<?php echo _("Your Name"); ?> *" type="text" tabindex="1" required>
                    </fieldset>
                    <fieldset>
                        <input autofill="off" autocomplete="off" id="issue_email" placeholder="<?php echo _("Your Email Address (optional)"); ?>" type="email" tabindex="2">
                    </fieldset>
                    <fieldset>
                        <textarea autofill="off" autocomplete="off" id="issue_comment" placeholder="<?php echo _("Type your report here"); ?> *" tabindex="3" required></textarea>
                    </fieldset>
                    <fieldset class="viewer_captcha_field" data-feature="issue_report">
                        <canvas id="issue_captcha_canvas"></canvas>
                        <input autofill="off" autocomplete="off" id="issue_captcha_code" type="text" placeholder="<?php echo _("Type the code above"); ?> *" tabindex="4" required />
                    </fieldset>
                    <fieldset>
                        <button id="issue_submit" name="submit" type="submit"><?php echo _("Submit"); ?></button>
                    </fieldset>
                </form>
                <div id="issue_feedback"><?php echo _("Thanks for your report!"); ?></div>
            </div>
            <?php if((int)($current_map['viewer_auth_mode'] ?? 0)>0) : ?>
                <div id="modal_viewer_login" class="modal">
                    <form autofill="off" autocomplete="off" id="form_viewer_login" class="viewer_auth_form" action="" method="post" onsubmit="viewer_login();return false;">
                        <fieldset class="noselect title_modal viewer_auth_title">
                            <i class="fas fa-sign-in-alt"></i>
                            <span><?php echo _("Login"); ?></span>
                        </fieldset>
                        <fieldset class="viewer_auth_field">
                            <i class="fas fa-user"></i>
                            <input autofill="off" autocomplete="off" id="viewer_login_username" placeholder="<?php echo _("Username or E-mail"); ?> *" type="text" required>
                        </fieldset>
                        <fieldset class="viewer_auth_field">
                            <i class="fas fa-lock"></i>
                            <input autofill="off" autocomplete="off" id="viewer_login_password" placeholder="<?php echo _("Password"); ?> *" type="password" required>
                        </fieldset>
                        <div id="viewer_login_feedback" class="viewer_auth_feedback"></div>
                        <fieldset class="viewer_remember_field">
                            <input id="viewer_login_remember" type="checkbox">
                            <label for="viewer_login_remember"><?php echo _("Remember me"); ?></label>
                        </fieldset>
                        <fieldset>
                            <button id="viewer_login_submit" name="submit" type="submit"><i class="fas fa-sign-in-alt"></i><span><?php echo _("Login"); ?></span></button>
                        </fieldset>
                        <?php if($global_settings['smtp_valid']) : ?>
                            <fieldset class="viewer_auth_switch">
                                <button type="button" onclick="open_viewer_forgot();"><i class="fas fa-key"></i><?php echo _("Forgot Password?"); ?></button>
                            </fieldset>
                        <?php endif; ?>
                        <?php if((int)($current_map['viewer_auth_mode'] ?? 0)==2) : ?>
                            <fieldset class="viewer_auth_switch">
                                <span><?php echo _("Don't have an account?"); ?></span>
                                <button type="button" onclick="open_viewer_register();"><i class="fas fa-user-plus"></i><?php echo _("Register"); ?></button>
                            </fieldset>
                        <?php endif; ?>
                    </form>
                </div>
                <?php if($global_settings['smtp_valid']) : ?>
                    <div id="modal_viewer_forgot" class="modal">
                        <form autofill="off" autocomplete="off" id="form_viewer_forgot" class="viewer_auth_form" action="" method="post" onsubmit="viewer_change_password_forgot();return false;">
                            <fieldset class="noselect title_modal viewer_auth_title">
                                <i class="fas fa-key"></i>
                                <span><?php echo _("Forgot Password"); ?></span>
                            </fieldset>
                            <div id="viewer_forgot_request" class="<?php echo (!empty($viewer_forgot_code)) ? 'disabled' : ''; ?>">
                                <fieldset class="viewer_auth_field">
                                    <i class="fas fa-envelope"></i>
                                    <input autofill="off" autocomplete="off" id="viewer_forgot_email" placeholder="<?php echo _("E-mail"); ?> *" type="email" value="<?php echo $viewer_forgot_email; ?>">
                                </fieldset>
                                <fieldset>
                                    <button id="viewer_forgot_code_submit" class="viewer_auth_submit" name="submit" type="button" onclick="viewer_send_verification_code();return false;"><i class="fas fa-envelope"></i><span><?php echo _("Send Verification Code"); ?></span></button>
                                </fieldset>
                            </div>
                            <fieldset class="viewer_auth_field">
                                <i class="fas fa-shield-alt"></i>
                                <input autofill="off" autocomplete="off" id="viewer_forgot_code" placeholder="<?php echo _("Verification code"); ?> *" type="text" value="<?php echo $viewer_forgot_code; ?>">
                            </fieldset>
                            <fieldset class="viewer_auth_field">
                                <i class="fas fa-lock"></i>
                                <input autofill="off" autocomplete="off" id="viewer_forgot_password" placeholder="<?php echo _("New password"); ?> *" type="password">
                            </fieldset>
                            <fieldset class="viewer_auth_field">
                                <i class="fas fa-shield-alt"></i>
                                <input autofill="off" autocomplete="off" id="viewer_forgot_repeat_password" placeholder="<?php echo _("Repeat Password"); ?> *" type="password">
                            </fieldset>
                            <div id="viewer_forgot_feedback" class="viewer_auth_feedback"></div>
                            <fieldset>
                                <button id="viewer_forgot_submit" name="submit" type="submit"><i class="fas fa-save"></i><span><?php echo _("Change password"); ?></span></button>
                            </fieldset>
                            <fieldset class="viewer_auth_switch">
                                <button type="button" onclick="open_viewer_login();"><i class="fas fa-sign-in-alt"></i><?php echo _("Login"); ?></button>
                            </fieldset>
                        </form>
                    </div>
                <?php endif; ?>
                <?php if((int)($current_map['viewer_auth_mode'] ?? 0)==2) : ?>
                    <div id="modal_viewer_register" class="modal">
                        <form autofill="off" autocomplete="off" id="form_viewer_register" class="viewer_auth_form" action="" method="post" onsubmit="viewer_register();return false;">
                            <fieldset class="noselect title_modal viewer_auth_title">
                                <i class="fas fa-user-plus"></i>
                                <span><?php echo _("Register"); ?></span>
                            </fieldset>
                            <fieldset class="viewer_auth_field">
                                <i class="fas fa-user"></i>
                                <input autofill="off" autocomplete="off" id="viewer_register_username" placeholder="<?php echo _("Username"); ?> *" type="text" required>
                            </fieldset>
                            <fieldset class="viewer_auth_field">
                                <i class="fas fa-envelope"></i>
                                <input autofill="off" autocomplete="off" id="viewer_register_email" placeholder="<?php echo _("E-mail"); ?> *" type="email" required>
                            </fieldset>
                            <fieldset class="viewer_auth_field">
                                <i class="fas fa-lock"></i>
                                <input autofill="off" autocomplete="off" id="viewer_register_password" placeholder="<?php echo _("Password"); ?> *" type="password" required>
                            </fieldset>
                            <fieldset class="viewer_auth_field">
                                <i class="fas fa-shield-alt"></i>
                                <input autofill="off" autocomplete="off" id="viewer_register_repeat_password" placeholder="<?php echo _("Repeat Password"); ?> *" type="password" required>
                            </fieldset>
                            <div id="viewer_register_feedback" class="viewer_auth_feedback"></div>
                            <fieldset>
                                <button id="viewer_register_submit" name="submit" type="submit"><i class="fas fa-user-plus"></i><span><?php echo _("Register"); ?></span></button>
                            </fieldset>
                            <fieldset class="viewer_auth_switch">
                                <span><?php echo _("Already have an account?"); ?></span>
                                <button type="button" onclick="open_viewer_login();"><i class="fas fa-sign-in-alt"></i><?php echo _("Login"); ?></button>
                            </fieldset>
                        </form>
                    </div>
                <?php endif; ?>
            <?php endif; ?>
            <div class="search_div noselect <?php echo (!$current_map['enable_search'] && !$current_map['enable_list'] && ($current_map['enable_categories']==0 || $current_map['enable_categories']==3)) ? 'hidden' : ''; ?>">
                <input id="searchbox" type="search" class="<?php echo (!$current_map['enable_search']) ? 'hidden' : ''; ?>" placeholder="<?php echo _("Search"); ?>..." />
                <div onclick="open_list_detail();" class="list_icon disabled noselect <?php echo (!$current_map['enable_list']) ? 'hidden' : ''; ?>">
                    <i class="fas fa-bars"></i>
                </div>
                <div onclick="toggle_categories();" class="filter_icon noselect <?php echo ($current_map['enable_categories']==0 || $current_map['enable_categories']==3) ? 'hidden' : ''; ?>">
                    <span style="opacity:0;" id="count_categories">0</span>
                    <i class="fas fa-filter"></i>
                </div>
                <div class="search_icon noselect <?php echo (!$current_map['enable_search']) ? 'hidden' : ''; ?>">
                    <span onclick="open_radius_m();" id="search_radius_m">--</span><i class="fas fa-search"></i>
                </div>
                <div id="search_radius_container">
                    <div style="float:left;width:calc(100% - 64px);margin-left:6px;">
                        <input id="search_radius_slider" type="text" class="js-range-slider"
                               data-type="single"
                               data-min="1000"
                               data-max="100000"
                               data-step="1000"
                               data-from="<?php echo ($current_map['search_radius_m']==-1) ? '100000' : $current_map['search_radius_m']; ?>"
                               data-grid="false"
                               data-hide-min-max="true"
                               data-hide-from-to="true"
                               data-skin="round"
                               data-disable="<?php echo ($current_map['search_radius_m']==-1) ? 'true' : 'false'; ?>"
                        />
                    </div>
                    <div style="float:right;width:49px;text-align:right;margin-right:6px;">
                        <label>
                            <input onchange="change_radius_infinity();" id="search_radius_infinity" type="checkbox" <?php echo ($current_map['search_radius_m']==-1) ? 'checked' : ''; ?>>&nbsp;<i style="display:inline-block" class="fa-solid fa-infinity"></i>
                        </label>
                    </div>
                </div>
            </div>
            <div id="list_area" class="list_detail dragscroll clusterize-scroll noselect">
                <div id="list" class="clusterize-content "></div>
            </div>
            <div id="blueimp-gallery" class="blueimp-gallery" aria-label="image gallery" aria-modal="true" role="dialog">
                <div class="slides" aria-live="polite"></div>
                <a class="prev" aria-controls="blueimp-gallery" aria-label="previous slide" aria-keyshortcuts="ArrowLeft">‹</a>
                <a class="next" aria-controls="blueimp-gallery" aria-label="next slide" aria-keyshortcuts="ArrowRight">›</a>
                <a class="close" aria-controls="blueimp-gallery" aria-label="close" aria-keyshortcuts="Escape">×</a>
                <ol class="indicator"></ol>
            </div>
            <div class="loading_geodata">
                <i class="fa fa-spin fa-circle-notch"></i>&nbsp;&nbsp;<?php echo _("Loading Geodata..."); ?>
            </div>
            <div id="markers_loading_status" class="markers-loading-status noselect" role="status" aria-live="polite">
                <i class="fas fa-spin fa-circle-notch" aria-hidden="true"></i>
                <span><?php echo _("Preparing the map..."); ?></span>
            </div>
            <div id="map" class="map"></div>
            <div class="measure-controls <?php echo ($enable_measure == 0) ? 'hidden' : ''; ?>">
                <div class="measure-buttons">
                    <button id="measure-btn">
                        <i class="fa-solid fa-ruler-horizontal"></i>
                    </button>
                    <button id="clear-btn" class="hidden">
                        <i class="fa-solid fa-trash-can"></i>
                    </button>
                </div>
            </div>
            <div id="tooltip-distance" class="tooltip-m tooltip-measure" style="position: absolute; display: none;"></div>
            <div id="help-tooltip-measure" class="tooltip-m" style="position: absolute; display: none;"></div>
            <div class="popup noselect">
                <img class="popup_image" src="" />
                <video playsinline muted loop class="popup_video animated-background" src=""></video>
                <div class="popup_title_div">
                    <div style="width:100%;">
                        <p class="popup_title"></p>
                        <p class="popup_rating <?php echo (!$current_map['enable_reviews']) ? 'hidden' : ''; ?>"></p>
                    </div>
                    <span class="popup_icon <?php echo (!$current_map['enable_popup_directions'] || !$current_map['enable_directions']) ? 'hidden' : ''; ?>">
                        <div class="btn_direction_p"><i class="fas fa-directions"></i></div>
                    </span>
                </div>
                <p class="popup_address"></p>
                <p class="popup_description"></p>
            </div>
            <div class="popup_c noselect">
                <p class="popup_c_title noselect"></p>
                <p class="popup_c_description noselect"></p>
            </div>
            <div class="div_change_lang">
                <div><?php echo sprintf(_("Switching language to %s"),'<span id="switching_lang"></span>'); ?></div>
            </div>
            <div class="map-legal-footer noselect">
                <div id="map-attributions"></div>
                    <?php
                    $footer_links = [];
                    if($show_legal) {
                        if(strpos($terms_and_conditions, 'http') === 0) {
                            $footer_links[] = "<a target='_blank' href='".$terms_and_conditions."'>"._("Terms")."</a>";
                        } else if(!empty($terms_and_conditions) && $terms_and_conditions!='<p></p>') {
                            $footer_links[] = "<a data-fancybox data-src='#modal_terms_and_conditions_b' href='javascript:;'>"._("Terms")."</a>";
                        }
                        if(strpos($privacy_policy, 'http') === 0) {
                            $footer_links[] = "<a target='_blank' href='".$privacy_policy."'>"._("Privacy")."</a>";
                        } else if(!empty($privacy_policy) && $privacy_policy!='<p></p>') {
                            $footer_links[] = "<a data-fancybox data-src='#modal_privacy_policy_b' href='javascript:;'>"._("Privacy")."</a>";
                        }
                    }
                    if ($cookie_consent) {
                        if(strpos($cookie_policy, 'http') === 0) {
                            $footer_links[] = "<a target='_blank' href='".$cookie_policy."'>"._("Cookies")."</a>";
                        } else if(!empty($cookie_policy) && $cookie_policy!='<p></p>') {
                            $footer_links[] = "<a data-fancybox data-src='#modal_cookie_policy_b' href='javascript:;'>"._("Cookies")."</a>";
                        }
                        $footer_links[] = "<a data-cc='show-consentModal' href='javascript:;'>"._("Cookie Preferences")."</a>";
                    }
                    if(count($footer_links) > 0) {
                        echo '<div class="footer-links">'.implode(' &nbsp;|&nbsp; ', $footer_links).'</div>';
                    }
                    ?>
                <div id="scale-line-target" class="<?php echo ($show_scale_control == 0) ? 'hidden' : ''; ?>"></div>
            </div>
            <div id="custom_html"><?php echo $current_map['custom_html']; ?></div>
        </div>
    </div>
    <div id="story_container" class="dragscroll noselect">
        <div id="story_content"></div>
    </div>
    <script type="text/javascript" src="js/index.js?v=<?php echo $v; ?>"></script>
    <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'custom.js')) : ?>
        <script type="text/javascript" src="js/custom.js?v=<?php echo time(); ?>"></script>
    <?php endif; ?>
    <?php if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR.'custom_'.$code.'.js')) : ?>
        <script type="text/javascript" src="js/custom_<?php echo $code; ?>.js?v=<?php echo time(); ?>"></script>
    <?php endif; ?>
    <script src="vendor/Gallery/js/blueimp-gallery.min.js"></script>
    <?php if($current_map['enable_share'] || $current_map['enable_share_map']) : ?>
        <?php if($cookie_consent) { ?>
            <script type="text/plain" data-category="functionality" data-service="Social Share (AddToAny)" async src="https://static.addtoany.com/menu/page.js"></script>
        <?php } else { ?>
            <script async src="https://static.addtoany.com/menu/page.js"></script>
        <?php } ?>
    <?php endif; ?>
    <script>
        (function ($) {
            'use strict';
            window.noSleep = new NoSleep();
            window.rtl = <?php echo ($dir=='rtl') ? 1 : 0; ?>;
            window.language = '<?php echo $language; ?>';
            window.default_language = '<?php echo $default_language; ?>';
            window.browser_language = '<?php echo $browser_language; ?>';
            window.url_map = '<?php echo $url_map; ?>';
            window.friendly_url = '<?php echo $furl; ?>';
            window.code = '<?php echo $code; ?>';
            window.map_name = `<?php echo $current_map['name']; ?>`;
            window.map_language = `<?php echo $map_language; ?>`;
            window.id_map = '<?php echo $current_map['id']; ?>';
            window.viewer_auth_mode = <?php echo (int)($current_map['viewer_auth_mode'] ?? 0); ?>;
            window.viewer_user = <?php echo json_encode($viewer_user_public); ?>;
            window.viewer_forgot = <?php echo ($viewer_forgot) ? 1 : 0; ?>;
            window.add_marker_require_login = <?php echo (int)($current_map['add_marker_require_login'] ?? 0); ?>;
            window.review_require_login = <?php echo (int)($current_map['review_require_login'] ?? 0); ?>;
            window.add_photo_require_login = <?php echo (int)($current_map['add_photo_require_login'] ?? 0); ?>;
            window.issue_report_require_login = <?php echo (int)($current_map['issue_report_require_login'] ?? 0); ?>;
            window.live_tracking_require_login = <?php echo (int)($current_map['live_tracking_require_login'] ?? 0); ?>;
            window.map_mode = '<?php echo $current_map['map_type']; ?>';
            window.num_markers = parseInt(<?php echo $num_markers; ?>);
            window.centered_marker_coordinates = <?php echo json_encode($centered_marker_coordinates); ?>;
            window.selected_marker_coordinates = <?php echo json_encode($selected_marker_coordinates); ?>;
            window.auto_start = <?php echo $auto_start; ?>;
            window.loading_visible = <?php echo $loading_visible; ?>;
            window.lazy_loading = <?php echo isset($current_map['lazy_loading']) ? (int)$current_map['lazy_loading'] : 0; ?>;
            window.markers_loaded = false;
            window.markers_load_failed = false;
            window.ignore_embedded = <?php echo $ignore_embedded; ?>;
            switch(window.auto_start) {
                case 0:
                    window.auto_start=false;
                    break;
                case 1:
                    window.auto_start=true;
                    break;
                case 2:
                    if ((window.self !== window.top) && (window.ignore_embedded==0)) {
                        window.auto_start=false;
                    } else {
                        window.auto_start=true;
                    }
                    break;
            }
            window.preview = <?php echo $preview; ?>;
            window.order_by = '<?php echo $current_map['order_by']; ?>';
            window.order_by_distance = <?php echo ($current_map['order_by_distance']) ? 1 : 0; ?>;
            window.main_color_hex = '<?php echo $current_map['main_color_hex']; ?>';
            window.darker_color_hex = '<?php echo $darker_color_hex; ?>';
            window.markers_color_hex = '<?php echo $current_map['markers_color_hex']; ?>';
            window.map_style = '<?php echo $current_map['map_style']; ?>';
            window.map_style_satellite = '<?php echo $current_map['map_style_satellite']; ?>';
            window.enable_map_street = <?php echo ($current_map['enable_map_street']) ? 1 : 0; ?>;
            window.enable_map_satellite = <?php echo ($current_map['enable_map_satellite']) ? 1 : 0; ?>;
            window.street_basemap = '<?php echo $current_map['street_basemap']; ?>';
            window.street_basemap_overlay = '<?php echo $current_map['street_basemap_overlay']; ?>';
            window.street_overlay_opacity = <?php echo $current_map['street_overlay_opacity']; ?>;
            window.street_attributions = `<?php echo $current_map['street_attributions']; ?>`;
            window.use_street_attributions =  <?php echo ($current_map['use_street_attributions']) ? 1 : 0; ?>;
            window.satellite_basemap = '<?php echo $current_map['satellite_basemap']; ?>';
            window.satellite_basemap_overlay = '<?php echo $current_map['satellite_basemap_overlay']; ?>';
            window.satellite_overlay_opacity = <?php echo $current_map['satellite_overlay_opacity']; ?>;
            window.satellite_attributions = `<?php echo $current_map['satellite_attributions']; ?>`;
            window.use_satellite_attributions =  <?php echo ($current_map['use_satellite_attributions']) ? 1 : 0; ?>;
            window.street_maxzoom = <?php echo $current_map['street_maxzoom']; ?>;
            window.street_minzoom = <?php echo $current_map['street_minzoom']; ?>;
            window.satellite_maxzoom = <?php echo $current_map['satellite_maxzoom']; ?>;
            window.satellite_minzoom = <?php echo $current_map['satellite_minzoom']; ?>;
            window.maptiler_api = '<?php echo $current_map['maptiler_api']; ?>';
            window.maptiler_api_satellite = '<?php echo $current_map['maptiler_api_satellite']; ?>';
            window.here_api = '<?php echo $current_map['here_api']; ?>';
            window.here_api_satellite = '<?php echo $current_map['here_api_satellite']; ?>';
            window.here_lang = '<?php echo (empty($current_map['here_lang'])) ? '' : $current_map['here_lang']; ?>';
            window.here_lang_satellite = '<?php echo (empty($current_map['here_lang_satellite'])) ? '' : $current_map['here_lang_satellite']; ?>';
            window.google_api = '<?php echo $current_map['google_api']; ?>';
            window.google_api_satellite = '<?php echo $current_map['google_api_satellite']; ?>';
            window.google_lang = '<?php echo (empty($current_map['google_lang'])) ? '' : $current_map['google_lang']; ?>';
            window.google_lang_satellite = '<?php echo (empty($current_map['google_lang_satellite'])) ? '' : $current_map['google_lang_satellite']; ?>';
            window.map_street_provider = '<?php echo $current_map['map_street_provider']; ?>';
            window.map_satellite_provider = '<?php echo $current_map['map_satellite_provider']; ?>';
            window.show_list = <?php echo $show_list; ?>;
            window.limit_list = <?php echo $limit_list; ?>;
            window.default_zoom = <?php echo $default_zoom; ?>;
            window.selected_zoom = <?php echo $selected_zoom; ?>;
            window.duration_zoom = <?php echo $duration_zoom; ?>;
            window.density_color = <?php echo $density_color; ?>;
            window.cat_sel = <?php echo $cat_sel; ?>;
            window.marker_sel = <?php echo $marker_sel; ?>;
            if(window.marker_sel!=0) {
                window.marker_sel_exists = true;
            } else {
                window.marker_sel_exists = false;
            }
            window.marker_current_id = 0;
            window.initial_coordinates = '<?php echo $coordinates; ?>';
            window.markers_size = <?php echo $current_map['markers_size']; ?>;
            window.enable_reviews = <?php echo $current_map['enable_reviews']; ?>;
            window.cluster_distance = <?php echo $current_map['cluster_distance']; ?>;
            window.cluster_animation = <?php echo isset($current_map['cluster_animation']) ? $current_map['cluster_animation'] : 300; ?>;
            window.cat_filter = <?php echo $current_map['cat_filter']; ?>;
            window.category_featured_mode = '<?php echo $current_map['category_featured_mode']; ?>';
            window.sheet_detail = <?php echo $current_map['sheet_detail']; ?>;
            window.default_view = '<?php echo $current_map['default_view']; ?>';
            window.qualityResolution = '<?php echo (isset($current_map['quality_resolution']) ? $current_map['quality_resolution'] : 'high'); ?>';
            window.updateWhileAnimating = <?php echo (isset($current_map['update_while_animating']) ? $current_map['update_while_animating'] : 1); ?> === 1;
            window.updateWhileInteracting = <?php echo (isset($current_map['update_while_interacting']) ? $current_map['update_while_interacting'] : 1); ?> === 1;
            window.loadTilesWhileAnimating = <?php echo (isset($current_map['load_tiles_while_animating']) ? $current_map['load_tiles_while_animating'] : 0); ?> === 1;
            window.loadTilesWhileInteracting = <?php echo (isset($current_map['load_tiles_while_interacting']) ? $current_map['load_tiles_while_interacting'] : 0); ?> === 1;
            window.preload_tiles = <?php echo (isset($current_map['preload_tiles']) ? $current_map['preload_tiles'] : 5); ?>;
            window.renderBuffer = <?php echo (isset($current_map['render_buffer']) ? $current_map['render_buffer'] : 100); ?>;
            window.unit_map = '<?php echo $current_map['unit_map']; ?>';
            window.my_location_zoom = <?php echo $current_map['my_location_zoom']; ?>;
            window.my_location_mode = '<?php echo $current_map['my_location_mode']; ?>';
            window.default_my_location = <?php echo $current_map['default_my_location']; ?>;
            window.enable_list = <?php echo $current_map['enable_list']; ?>;
            window.enable_search = <?php echo $current_map['enable_search']; ?>;
            window.enable_search_location = <?php echo $current_map['enable_search_location']; ?>;
            window.enable_categories = <?php echo $current_map['enable_categories']; ?>;
            if(window.enable_categories==0) {
                window.cat_filter=0;
            }
            window.show_categories_marker = <?php echo $current_map['show_categories_marker']; ?>;
            window.fit_categories = <?php echo $current_map['fit_categories']; ?>;
            window.custer_color_tolerance = <?php echo $current_map['density_color_tolerance']; ?>;
            window.search_highlight = <?php echo $current_map['search_highlight']; ?>;
            window.captcha = null;
            window.issue_captcha = null;
            window.first_image_upload = false;
            window.weather = '<?php echo $current_map['weather']; ?>';
            window.cat_filter_type = '<?php echo $current_map['cat_filter_type']; ?>';
            window.cat_filter_switch = <?php echo $current_map['cat_filter_switch']; ?>;
            window.globe = <?php echo $current_map['enable_globe']; ?>;
            window.saved_geometries = '<?php echo $current_map['draw_geometries']; ?>';
            window.enable_add_marker = <?php echo (int)$current_map['enable_add_marker']; ?>;
            window.ebable_popup = <?php echo (int)$current_map['enable_popup']; ?>;
            window.sheet_mobile = '<?php echo $current_map['sheet_mobile']; ?>';
            window.logo_mobile = '<?php echo $current_map['logo_mobile']; ?>';
            window.direction_map = '<?php echo $direction_map; ?>';
            window.streetview_map = '<?php echo $streetview_map; ?>';
            window.background_image = '<?php echo $background_image; ?>';
            window.background_image_mobile = '<?php echo $background_image_mobile; ?>';
            window.loading_text_color = '<?php echo $loading_text_color; ?>';
            window.password_protected = <?php echo ($password) ? 1 : 0; ?>;
            window.add_marker_open = <?php echo ($add_marker_open) ? 1 : 0; ?>;
            if(window.enable_search==1) {
                window.search_radius_enabled = <?php echo ($current_map['search_radius_enabled']) ? 1 : 0; ?>;
            } else {
                window.search_radius_enabled = 0;
            }
            window.search_radius_m = <?php echo $current_map['search_radius_m']; ?>;
            window.enable_intro = <?php echo $enable_intro; ?>;
            window.marker_images_num = <?php echo (empty($current_map['marker_images_num']) ? 0 : $current_map['marker_images_num']) ?>;
            window.marker_images_uploaded = 0;
            window.no_category_sel_mode = <?php echo $current_map['no_category_sel_mode']; ?>;
            window.info_auto_open = <?php echo $current_map['info_auto_open']; ?>;
            window.song_bg = '<?php echo $current_map['song']; ?>';
            window.song_autoplay = <?php echo isset($current_map['song_autoplay']) ? $current_map['song_autoplay'] : 1; ?>;
            window.song_loop = <?php echo isset($current_map['song_loop']) ? $current_map['song_loop'] : 1; ?>;
            window.main_song_bg_volume = '<?php echo $current_map['song_bg_volume']; ?>';
            window.tts_enable = <?php echo ($current_map['tts_enable']) ? 1 : 0; ?>;
            window.lang_code_2 = '<?php echo $lang_code_2; ?>';
            window.geocoding_provider = '<?php echo $geocoding_provider; ?>';
            window.extent = '<?php echo $current_map['extent']; ?>';
            window.id_live_tracking = '<?php echo $id_live_tracking; ?>';
            window.live_tracking = <?php echo isset($current_map['live_tracking']) ? $current_map['live_tracking'] : 0; ?>;
            window.live_tracking_interval = <?php echo isset($current_map['live_tracking_interval']) ? $current_map['live_tracking_interval'] : 5000; ?>;
            window.live_tracking_timeout = <?php echo isset($current_map['live_tracking_timeout']) ? $current_map['live_tracking_timeout'] : 10000; ?>;
            window.live_tracking_hash = '<?php echo $live_tracking_hash; ?>';
            window.live_tracking_only_admin = <?php echo ($current_map['live_tracking_only_admin']) ? 1 : 0; ?>;
            window.marker_sel_zoom = <?php echo isset($current_map['marker_sel_zoom']) ? $current_map['marker_sel_zoom'] : 1.5; ?>;
            window.field_placeholders = '<?php echo json_encode($default_am_placeholders); ?>';
            window.enable_share_map = <?php echo ($current_map['enable_share_map']) ? 1 : 0; ?>;
            window.enable_share_markers = <?php echo ($current_map['enable_share']) ? 1 : 0; ?>;
            window.enable_popup_directions = <?php echo ($current_map['enable_popup_directions']) ? 1 : 0; ?>;
            window.enable_directions = <?php echo ($current_map['enable_directions']) ? 1 : 0; ?>;
            window.share_location_context = false;
            window.openfreemap_street_url = '<?php echo $current_map['openfreemap_street_url']; ?>';
            window.is_webgl = hasWebGL();
            window.show_scale_control = <?php echo $show_scale_control; ?>;
            window.enable_measure = <?php echo $enable_measure; ?>;
            window.wake_lock = <?php echo $current_map['wake_lock']; ?>;
            window.viewer_labels = {
                "cancel_new_marker":`<?php echo _("Are you sure you want to CANCEL the request to insert this marker?"); ?>`,
                "cancel_edit_marker":`<?php echo _("Are you sure you want to cancel the changes to this marker?"); ?>`,
                "confirm_new_marker":`<?php echo _("Are you sure you want to SEND the request to insert this marker?"); ?>`,
                "confirm_edit_marker":`<?php echo _("Are you sure you want to save the changes to this marker?"); ?>`,
                "ok_new_marker":`<?php echo _("Thanks for inserting the marker! As soon as it is approved it will be visible on the map."); ?>`,
                "error_new_marker":`<?php echo _("An error has occurred, please try again later."); ?>`,
                "reset":`<?php echo _("reset"); ?>`,
                "select_all":`<?php echo _("select all"); ?>`,
                "filters":`<?php echo _("Filters"); ?>`,
                "start_story":`<?php echo _("Start, Scroll down"); ?>`,
                "end_story":`<?php echo _("End"); ?>`,
                "searching":`<?php echo _("Searching"); ?>`,
                "no_result":`<?php echo _("No results found."); ?>`,
                "preparing_map":`<?php echo _("Preparing the map..."); ?>`,
                "map_ready":`<?php echo _("Map ready"); ?>`,
                "zoom_in_for_content":`<?php echo _("Zoom in to discover more."); ?>`,
                "map_load_error":`<?php echo _("The map could not be fully loaded."); ?>`,
                "add_marker_title":`<?php echo _("Add New Marker"); ?>`,
                "add_marker_location":`<?php echo _("Do you want to use my position to add the marker?"); ?>`,
                "no":`<?php echo _("No"); ?>`,
                "yes":`<?php echo _("Yes"); ?>`,
                "addtoany_social_share":`<?php echo _("Social Share")." (AddToAny)"; ?>`,
                "cookie_denied_msg":`<?php echo _("To use this function you must enable the cookies relating to it."); ?>`,
                "open_cookie_pref":`<?php echo _("Open Cookie Preferences"); ?>`,
                "or":`<?php echo _("OR"); ?>`,
                "and":`<?php echo _("AND"); ?>`,
                "walk":`<?php echo _("walk"); ?>`,
                "minute":`<?php echo _("minute"); ?>`,
                "hour":`<?php echo _("hour"); ?>`,
                "day":`<?php echo _("day"); ?>`,
                "listen":`<?php echo _("listen"); ?>`,
                "live_tracking_title":`<?php echo _("Live Tracking"); ?>`,
                "live_tracking_msg":`<?php echo _("Want to share your real-time location with other map users?"); ?>`,
                "live_tracking_admin_msg":`<?php echo _("Want to share your real-time location with map administrators?"); ?>`,
                "live_tracking_policy":`<?php echo _("This app can track your location to let administrators view the routes taken by users. Your data is securely stored, not shared with third parties, and used only for internal purposes."); ?>`,
                "name_placeholder":`<?php echo _("Insert your name"); ?>`,
                "start":`<?php echo _("Start"); ?>`,
                "error_location":`<?php echo _("Unable to retrieve location"); ?>`,
                "enable_audio":`<?php echo _("ENABLE AUDIO?"); ?>`,
                "center_map_here":`<?php echo _("Center map here"); ?>`,
                "zoom_in":`<?php echo _("Zoom In"); ?>`,
                "zoom_out":`<?php echo _("Zoom Out"); ?>`,
                "copied_clipboard":`<?php echo _("Copied to Clipboard!"); ?>`,
                "share_location":`<?php echo _("Share this location"); ?>`,
                "copied":`<?php echo _("copied"); ?>`,
                "owner":`<?php echo _("Owner"); ?>`,
                "reviews":`<?php echo _("reviews"); ?>`,
                "click_drawing":`<?php echo _("Click to start drawing"); ?>`,
                "directions":`<?php echo _("Directions"); ?>`,
                "my_location":`<?php echo _("My Location"); ?>`,
                "click_start_point":`<?php echo _("Click on the map to set the starting point"); ?>`,
                "click_end_point":`<?php echo _("Click on the map to set the destination point"); ?>`,
                "directions_from_here":`<?php echo _("Directions from here"); ?>`,
                "directions_to_here":`<?php echo _("Directions to here"); ?>`,
                "add_stop":`<?php echo _("Add Stop"); ?>`,
                "add_stop_here":`<?php echo _("Add stop here"); ?>`,
                "select_on_map":`<?php echo _("Select on map"); ?>`,
                "remove":`<?php echo _("Remove"); ?>`,
                "drag_drop":`<?php echo _("Drag & Drop your photo here or click to browse"); ?>`,
                "out_of_bounds":`<?php echo _("You can only add markers inside the allowed boundaries!"); ?>`,
                "out_of_bounds_current_loc":`<?php echo _("Your current location is outside the allowed boundaries. Please click on the map to place the marker."); ?>`,
                "auth_required":`<?php echo _("Login required"); ?>`,
                "auth_required_msg":`<?php echo _("You must log in to continue."); ?>`,
                "login_error":`<?php echo _("Incorrect username or password."); ?>`,
                "account_inactive":`<?php echo _("Please activate your account from the e-mail we sent you."); ?>`,
                "check_msg":`<?php echo _("Check your inbox for the verification code."); ?>`,
                "password_success":`<?php echo _("Password successfully changed!"); ?>`,
                "invalid_email":`<?php echo _("Invalid e-mail"); ?>`,
                "invalid_code":`<?php echo _("Invalid verification code"); ?>`,
                "register_error":`<?php echo _("Unable to create account."); ?>`,
                "register_success":`<?php echo _("Registration completed successfully."); ?>`,
                "register_activation":`<?php echo _("Check your inbox to activate your account."); ?>`,
                "password_mismatch":`<?php echo _("Passwords do not match."); ?>`,
                "login":`<?php echo _("Login"); ?>`,
                "register":`<?php echo _("Register"); ?>`,
                "logout":`<?php echo _("Logout"); ?>`,
                "my_markers":`<?php echo _("My markers"); ?>`,
                "reload_map":`<?php echo _("Reload map"); ?>`,
                "markers_not_loaded":`<?php echo _("Some of your markers are not visible yet."); ?>`,
                "confirm_delete_marker":`<?php echo _("Are you sure you want to delete this marker?"); ?>`,
                "ok_update_marker":`<?php echo _("Marker updated successfully."); ?>`,
                "ok_delete_marker":`<?php echo _("Marker deleted successfully."); ?>`,
                "submit_marker":`<?php echo _("SUBMIT"); ?>`,
                "save_marker":`<?php echo _("SAVE"); ?>`,
                "cancel_marker":`<?php echo _("CANCEL"); ?>`,
                "cancel_edit":`<?php echo _("CANCEL EDIT"); ?>`,
                "pending_validation":`<?php echo _("In validation"); ?>`,
            };
            if(enable_add_marker==2) {
                window.viewer_labels.confirm_new_marker = `<?php echo _("Are you sure you want to insert this marker?"); ?>`;
                window.viewer_labels.ok_new_marker = `<?php echo _("Thanks for inserting the marker! Please reload the map to view it."); ?>`;
            }
            $(document).ready(function () {
                check_map();
                const footerObserver = new ResizeObserver(entries => {
                    for (let entry of entries) {
                        let footerHeight = entry.target.offsetHeight;
                        if (footerHeight === 0 && entry.target.style.padding !== '0px') {
                            footerHeight = 18;
                        }
                        document.documentElement.style.setProperty('--footer_height', footerHeight + 'px');
                        var button_size = window.innerWidth <= 600 ? 32 : 28;
                        $('#featured_container').css('bottom', (footerHeight + button_size + 16) + 'px');
                    }
                });
                var footerEl = document.querySelector('.map-legal-footer');
                if (footerEl) footerObserver.observe(footerEl);
            });
        })(jQuery);
        $('#txtFile').change(function() {
            $('#frm').submit();
        });
        $('body').on('submit','#frm',function(e){
            $('#new_image_btn i').removeClass();
            $('#new_image_btn i').addClass('fas').addClass('fa-spin').addClass('fa-circle-notch');
            $('#new_image_btn').addClass('disabled');
            e.preventDefault();
            var url = $(this).attr('action');
            var frm = $(this);
            var data = new FormData();
            if(frm.find('#txtFile[type="file"]').length === 1 ){
                data.append('file', frm.find( '#txtFile' )[0].files[0]);
            }
            var ajax  = new XMLHttpRequest();
            ajax.upload.addEventListener('progress',function(evt){

            },false);
            ajax.addEventListener('load',function(evt){
                $('#new_image_btn i').removeClass();
                $('#new_image_btn i').addClass('fas').addClass('fa-upload');
                $('#new_image_btn').removeClass('disabled');
                frm[0].reset();
                if(evt.target.responseText.toLowerCase().indexOf('error')>=0){
                    alert(evt.target.responseText);
                } else {
                    if(evt.target.responseText!='') {
                        $('#uploaded_images').append('<img data-image="'+evt.target.responseText+'" class="sheet_image" src="marker_images_tmp/thumb/'+evt.target.responseText+'" />');
                        if(!window.first_image_upload) {
                            $('.new_sheet_detail_image').css('background-image','url("marker_images_tmp/'+evt.target.responseText+'")');
                            $('#btn_delete_images').css('pointer-events','initial');
                            $('#btn_delete_images').css('opacity',1);
                            window.first_image_upload=true;
                        }
                        if(marker_images_num!=-1) {
                            marker_images_uploaded++;
                            if(marker_images_uploaded>=marker_images_num) {
                                $('#new_image_btn').addClass('disabled');
                            }
                        }
                    }
                }
            },false);
            ajax.addEventListener('error',function(evt){
                $('#new_image_btn i').removeClass();
                $('#new_image_btn i').addClass('fas').addClass('fa-upload');
                $('#new_image_btn').removeClass('disabled');
            },false);
            ajax.addEventListener('abort',function(evt){
                $('#new_image_btn i').removeClass();
                $('#new_image_btn i').addClass('fas').addClass('fa-upload');
                $('#new_image_btn').removeClass('disabled');
            },false);
            ajax.open('POST',url);
            ajax.send(data);
            return false;
        });
    </script>
    <?php if($ga_tracking_id!='') : ?>
        <?php if($cookie_consent) { ?>
            <script type="text/plain" data-category="analytics" data-service="Google Analytics" async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $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 $ga_tracking_id; ?>');
            </script>
        <?php } else { ?>
            <script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $ga_tracking_id; ?>"></script>
            <script>
                window.dataLayer = window.dataLayer || [];
                function gtag(){dataLayer.push(arguments);}
                gtag('js', new Date());
                gtag('config', '<?php echo $ga_tracking_id; ?>');
            </script>
        <?php } ?>
    <?php endif; ?>
    <?php if(!empty($terms_and_conditions) && $terms_and_conditions!='<p></p>') : ?>
        <div id="modal_terms_and_conditions_b" style="display:none; padding:30px; max-width:800px; width:100%; border-radius:8px;">
            <h3 style="margin-top:0; font-family:'<?php echo $current_map['font_viewer']; ?>', sans-serif;"><?php echo _("Terms and Conditions"); ?></h3>
            <hr>
            <div><?php echo $terms_and_conditions; ?></div>
        </div>
    <?php endif; ?>
    <?php if(!empty($privacy_policy) && $privacy_policy!='<p></p>') : ?>
        <div id="modal_privacy_policy_b" style="display:none; padding:30px; max-width:800px; width:100%; border-radius:8px;">
            <h3 style="margin-top:0; font-family:'<?php echo $current_map['font_viewer']; ?>', sans-serif;"><?php echo _("Privacy Policy"); ?></h3>
            <hr>
            <div><?php echo $privacy_policy; ?></div>
        </div>
    <?php endif; ?>
    <?php if(!empty($cookie_policy) && $cookie_policy!='<p></p>') : ?>
        <div id="modal_cookie_policy_b" style="display:none; padding:30px; max-width:800px; width:100%; border-radius:8px;">
            <h3 style="margin-top:0; font-family:'<?php echo $current_map['font_viewer']; ?>', sans-serif;"><?php echo _("Cookie Policy"); ?></h3>
            <hr>
            <div><?php echo $cookie_policy; ?></div>
        </div>
    <?php endif; ?>
    <?php if($cookie_consent) : ?>
        <?php require_once('cookie_consent.php'); ?>
    <?php endif; ?>
    <script>
        if ('serviceWorker' in navigator) {
            navigator.serviceWorker.register('service-worker.js', {
                scope: '.'
            });
        }
    </script>
    <?php if($pwa_enable) : ?>
    <script>
        if (window.self === window.top) {
            document.addEventListener('DOMContentLoaded', function() {
                const script = document.createElement('script');
                script.src = "js/pwa-install.js?v=0.5.7";
                document.head.appendChild(script);
                <?php
                $manifest = get_manifest($code);
                if (!empty($manifest) && $ignore_embedded == 0 && $no_pwa == 0) { ?>
                document.body.insertAdjacentHTML(
                    'beforeend',
                    `<pwa-install id="pwa-install" use-local-storage="false" manifest-url="<?php echo $manifest; ?>"></pwa-install>`
                );
                <?php } ?>
            });
        }
    </script>
    <?php endif; ?>
    </body>
    </html>

<?php
function adjustBrightness($hexCode, $adjustPercent) {
    $hexCode = ltrim($hexCode, '#');
    if (strlen($hexCode) == 3) {
        $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
    }
    $hexCode = array_map('hexdec', str_split($hexCode, 2));
    foreach ($hexCode as & $color) {
        $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
        $adjustAmount = ceil($adjustableLimit * $adjustPercent);

        $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
    }
    return '#'.implode($hexCode);
}
function hexToRgba($hex, $alpha = 1.0) {
    $hex = ltrim($hex, '#');
    if (strlen($hex) == 3) {
        $hex = str_repeat(substr($hex, 0, 1), 2) .
            str_repeat(substr($hex, 1, 1), 2) .
            str_repeat(substr($hex, 2, 1), 2);
    }
    $rgb = [
        'red'   => hexdec(substr($hex, 0, 2)),
        'green' => hexdec(substr($hex, 2, 2)),
        'blue'  => hexdec(substr($hex, 4, 2))
    ];
    $alpha = max(0, min(1, $alpha));
    return "rgba({$rgb['red']}, {$rgb['green']}, {$rgb['blue']}, {$alpha})";
}
function print_favicons_map($code, $logo, $theme_color) {
    global $pwa_enable;
    $path = '';
    $version = time();
    $path_m = 'm_'.$code.'/';
    $fs_path = $path_m;
    if (file_exists(dirname(__FILE__).'/../favicons/'.$path_m.'favicon.ico')) {
        $path = $path_m;
        $fs_path = $path_m;
        $version = preg_replace('/[^0-9]/', '', $logo);
    } else if (file_exists(dirname(__FILE__).'/../favicons/custom/favicon.ico')) {
        $path = 'custom/';
        $fs_path = 'custom/';
    }
    $path = "../favicons/".$path;
    $manifest = "";
    if($pwa_enable) {
        if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'site.webmanifest')) {
            $manifest = '<link rel="manifest" href="'.$path.'site.webmanifest?v='.$version.'">';
        }
    }
    $favicon16 = "";
    if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'favicon-16x16.png')) {
        $favicon16 = '<link rel="icon" type="image/png" sizes="16x16" href="'.$path.'favicon-16x16.png?v='.$version.'">';
    }
    $favicon32 = "";
    if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'favicon-32x32.png')) {
        $favicon32 = '<link rel="icon" type="image/png" sizes="32x32" href="'.$path.'favicon-32x32.png?v='.$version.'">';
    }
    $favicon96 = "";
    if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'favicon-96x96.png')) {
        $favicon96 = '<link rel="icon" type="image/png" sizes="96x96" href="'.$path.'favicon-96x96.png?v='.$version.'">';
    }
    $apple_touch = "";
    if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'apple-touch-icon.png')) {
        $apple_touch = '<link rel="apple-touch-icon" sizes="180x180" href="'.$path.'apple-touch-icon.png?v='.$version.'">';
    }
    $safari_pinned = "";
    if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'safari-pinned-tab.svg')) {
        $safari_pinned = '<link rel="mask-icon" href="'.$path.'safari-pinned-tab.svg?v='.$version.'" color="'.$theme_color.'">';
    }
    $favicon_ico = "";
    if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'favicon.ico')) {
        $favicon_ico = '<link rel="shortcut icon" href="'.$path.'favicon.ico?v='.$version.'">';
    }
    $browserconfig = "";
    if (file_exists(dirname(__FILE__).'/../favicons/'.$fs_path.'browserconfig.xml')) {
        $browserconfig = '<meta name="msapplication-config" content="'.$path.'browserconfig.xml?v='.$version.'">';
    }
    return $apple_touch.'
    '.$favicon16.$favicon32.$favicon96.'
    '.$manifest.'
    '.$safari_pinned.'
    '.$favicon_ico.'
    <meta name="msapplication-TileColor" content="'.$theme_color.'">
    '.$browserconfig.'
    <meta name="theme-color" content="'.$theme_color.'">';
}
function get_manifest($code) {
    $version = time();
    $path_m = 'm_'.$code.'/';
    if (file_exists(dirname(__FILE__).'/../favicons/m_'.$code.'/site.webmanifest')) {
        $manifest = '../favicons/'.$path_m.'site.webmanifest?v='.$version;
    } else {
        $manifest = "";
    }
    return $manifest;
}

$prefixes = [
    ['code' => '+93', 'country' => 'Afghanistan'], ['code' => '+355', 'country' => 'Albania'],
    ['code' => '+213', 'country' => 'Algeria'], ['code' => '+1684', 'country' => 'American Samoa'],
    ['code' => '+376', 'country' => 'Andorra'], ['code' => '+244', 'country' => 'Angola'],
    ['code' => '+1264', 'country' => 'Anguilla'], ['code' => '+672', 'country' => 'Antarctica'],
    ['code' => '+1268', 'country' => 'Antigua & Barbuda'], ['code' => '+54', 'country' => 'Argentina'],
    ['code' => '+374', 'country' => 'Armenia'], ['code' => '+297', 'country' => 'Aruba'],
    ['code' => '+61', 'country' => 'Australia'], ['code' => '+43', 'country' => 'Austria'],
    ['code' => '+994', 'country' => 'Azerbaijan'], ['code' => '+1242', 'country' => 'Bahamas'],
    ['code' => '+973', 'country' => 'Bahrain'], ['code' => '+880', 'country' => 'Bangladesh'],
    ['code' => '+1246', 'country' => 'Barbados'], ['code' => '+375', 'country' => 'Belarus'],
    ['code' => '+32', 'country' => 'Belgium'], ['code' => '+501', 'country' => 'Belize'],
    ['code' => '+229', 'country' => 'Benin'], ['code' => '+1441', 'country' => 'Bermuda'],
    ['code' => '+975', 'country' => 'Bhutan'], ['code' => '+591', 'country' => 'Bolivia'],
    ['code' => '+387', 'country' => 'Bosnia & Herzegovina'], ['code' => '+267', 'country' => 'Botswana'],
    ['code' => '+55', 'country' => 'Brazil'], ['code' => '+246', 'country' => 'British Indian Ocean Territory'],
    ['code' => '+1284', 'country' => 'British Virgin Islands'], ['code' => '+673', 'country' => 'Brunei'],
    ['code' => '+359', 'country' => 'Bulgaria'], ['code' => '+226', 'country' => 'Burkina Faso'],
    ['code' => '+257', 'country' => 'Burundi'], ['code' => '+855', 'country' => 'Cambodia'],
    ['code' => '+237', 'country' => 'Cameroon'], ['code' => '+1', 'country' => 'Canada'],
    ['code' => '+238', 'country' => 'Cape Verde'], ['code' => '+1345', 'country' => 'Cayman Islands'],
    ['code' => '+236', 'country' => 'Central African Republic'], ['code' => '+235', 'country' => 'Chad'],
    ['code' => '+56', 'country' => 'Chile'], ['code' => '+86', 'country' => 'China'],
    ['code' => '+61', 'country' => 'Christmas Island'], ['code' => '+61', 'country' => 'Cocos (Keeling) Islands'],
    ['code' => '+57', 'country' => 'Colombia'], ['code' => '+269', 'country' => 'Comoros'],
    ['code' => '+243', 'country' => 'Congo (DRC)'], ['code' => '+242', 'country' => 'Congo (Republic)'],
    ['code' => '+682', 'country' => 'Cook Islands'], ['code' => '+506', 'country' => 'Costa Rica'],
    ['code' => '+385', 'country' => 'Croatia'], ['code' => '+53', 'country' => 'Cuba'],
    ['code' => '+599', 'country' => 'Curaçao'], ['code' => '+357', 'country' => 'Cyprus'],
    ['code' => '+420', 'country' => 'Czech Republic'], ['code' => '+225', 'country' => 'Côte d\'Ivoire'],
    ['code' => '+45', 'country' => 'Denmark'], ['code' => '+253', 'country' => 'Djibouti'],
    ['code' => '+1767', 'country' => 'Dominica'], ['code' => '+1', 'country' => 'Dominican Republic'],
    ['code' => '+593', 'country' => 'Ecuador'], ['code' => '+20', 'country' => 'Egypt'],
    ['code' => '+503', 'country' => 'El Salvador'], ['code' => '+240', 'country' => 'Equatorial Guinea'],
    ['code' => '+291', 'country' => 'Eritrea'], ['code' => '+372', 'country' => 'Estonia'],
    ['code' => '+268', 'country' => 'Eswatini (Swaziland)'], ['code' => '+251', 'country' => 'Ethiopia'],
    ['code' => '+500', 'country' => 'Falkland Islands'], ['code' => '+298', 'country' => 'Faroe Islands'],
    ['code' => '+679', 'country' => 'Fiji'], ['code' => '+358', 'country' => 'Finland'],
    ['code' => '+33', 'country' => 'France'], ['code' => '+594', 'country' => 'French Guiana'],
    ['code' => '+689', 'country' => 'French Polynesia'], ['code' => '+241', 'country' => 'Gabon'],
    ['code' => '+220', 'country' => 'Gambia'], ['code' => '+995', 'country' => 'Georgia'],
    ['code' => '+49', 'country' => 'Germany'], ['code' => '+233', 'country' => 'Ghana'],
    ['code' => '+350', 'country' => 'Gibraltar'], ['code' => '+30', 'country' => 'Greece'],
    ['code' => '+299', 'country' => 'Greenland'], ['code' => '+1473', 'country' => 'Grenada'],
    ['code' => '+590', 'country' => 'Guadeloupe'], ['code' => '+1671', 'country' => 'Guam'],
    ['code' => '+502', 'country' => 'Guatemala'], ['code' => '+44-1481', 'country' => 'Guernsey'],
    ['code' => '+224', 'country' => 'Guinea'], ['code' => '+245', 'country' => 'Guinea-Bissau'],
    ['code' => '+592', 'country' => 'Guyana'], ['code' => '+509', 'country' => 'Haiti'],
    ['code' => '+504', 'country' => 'Honduras'], ['code' => '+852', 'country' => 'Hong Kong'],
    ['code' => '+36', 'country' => 'Hungary'], ['code' => '+354', 'country' => 'Iceland'],
    ['code' => '+91', 'country' => 'India'], ['code' => '+62', 'country' => 'Indonesia'],
    ['code' => '+98', 'country' => 'Iran'], ['code' => '+964', 'country' => 'Iraq'],
    ['code' => '+353', 'country' => 'Ireland'], ['code' => '+44-1624', 'country' => 'Isle of Man'],
    ['code' => '+972', 'country' => 'Israel'], ['code' => '+39', 'country' => 'Italy'],
    ['code' => '+1876', 'country' => 'Jamaica'], ['code' => '+81', 'country' => 'Japan'],
    ['code' => '+44-1534', 'country' => 'Jersey'], ['code' => '+962', 'country' => 'Jordan'],
    ['code' => '+7', 'country' => 'Kazakhstan'], ['code' => '+254', 'country' => 'Kenya'],
    ['code' => '+686', 'country' => 'Kiribati'], ['code' => '+383', 'country' => 'Kosovo'],
    ['code' => '+965', 'country' => 'Kuwait'], ['code' => '+996', 'country' => 'Kyrgyzstan'],
    ['code' => '+856', 'country' => 'Laos'], ['code' => '+371', 'country' => 'Latvia'],
    ['code' => '+961', 'country' => 'Lebanon'], ['code' => '+266', 'country' => 'Lesotho'],
    ['code' => '+231', 'country' => 'Liberia'], ['code' => '+218', 'country' => 'Libya'],
    ['code' => '+423', 'country' => 'Liechtenstein'], ['code' => '+370', 'country' => 'Lithuania'],
    ['code' => '+352', 'country' => 'Luxembourg'], ['code' => '+853', 'country' => 'Macau'],
    ['code' => '+261', 'country' => 'Madagascar'], ['code' => '+265', 'country' => 'Malawi'],
    ['code' => '+60', 'country' => 'Malaysia'], ['code' => '+960', 'country' => 'Maldives'],
    ['code' => '+223', 'country' => 'Mali'], ['code' => '+356', 'country' => 'Malta'],
    ['code' => '+692', 'country' => 'Marshall Islands'], ['code' => '+596', 'country' => 'Martinique'],
    ['code' => '+222', 'country' => 'Mauritania'], ['code' => '+230', 'country' => 'Mauritius'],
    ['code' => '+262', 'country' => 'Mayotte'], ['code' => '+52', 'country' => 'Mexico'],
    ['code' => '+691', 'country' => 'Micronesia'], ['code' => '+373', 'country' => 'Moldova'],
    ['code' => '+377', 'country' => 'Monaco'], ['code' => '+976', 'country' => 'Mongolia'],
    ['code' => '+382', 'country' => 'Montenegro'], ['code' => '+1664', 'country' => 'Montserrat'],
    ['code' => '+212', 'country' => 'Morocco'], ['code' => '+258', 'country' => 'Mozambique'],
    ['code' => '+95', 'country' => 'Myanmar (Burma)'], ['code' => '+264', 'country' => 'Namibia'],
    ['code' => '+674', 'country' => 'Nauru'], ['code' => '+977', 'country' => 'Nepal'],
    ['code' => '+31', 'country' => 'Netherlands'], ['code' => '+599', 'country' => 'Netherlands Antilles'],
    ['code' => '+687', 'country' => 'New Caledonia'], ['code' => '+64', 'country' => 'New Zealand'],
    ['code' => '+505', 'country' => 'Nicaragua'], ['code' => '+227', 'country' => 'Niger'],
    ['code' => '+234', 'country' => 'Nigeria'], ['code' => '+683', 'country' => 'Niue'],
    ['code' => '+672', 'country' => 'Norfolk Island'], ['code' => '+850', 'country' => 'North Korea'],
    ['code' => '+389', 'country' => 'North Macedonia'], ['code' => '+1670', 'country' => 'Northern Mariana Islands'],
    ['code' => '+47', 'country' => 'Norway'], ['code' => '+968', 'country' => 'Oman'],
    ['code' => '+92', 'country' => 'Pakistan'], ['code' => '+680', 'country' => 'Palau'],
    ['code' => '+970', 'country' => 'Palestine'], ['code' => '+507', 'country' => 'Panama'],
    ['code' => '+675', 'country' => 'Papua New Guinea'], ['code' => '+595', 'country' => 'Paraguay'],
    ['code' => '+51', 'country' => 'Peru'], ['code' => '+63', 'country' => 'Philippines'],
    ['code' => '+870', 'country' => 'Pitcairn Islands'], ['code' => '+48', 'country' => 'Poland'],
    ['code' => '+351', 'country' => 'Portugal'], ['code' => '+1', 'country' => 'Puerto Rico'],
    ['code' => '+974', 'country' => 'Qatar'], ['code' => '+40', 'country' => 'Romania'],
    ['code' => '+7', 'country' => 'Russia'], ['code' => '+250', 'country' => 'Rwanda'],
    ['code' => '+262', 'country' => 'Réunion'], ['code' => '+590', 'country' => 'Saint Barthélemy'],
    ['code' => '+290', 'country' => 'Saint Helena'], ['code' => '+1869', 'country' => 'Saint Kitts & Nevis'],
    ['code' => '+1758', 'country' => 'Saint Lucia'], ['code' => '+590', 'country' => 'Saint Martin'],
    ['code' => '+508', 'country' => 'Saint Pierre & Miquelon'], ['code' => '+1784', 'country' => 'Saint Vincent & Grenadines'],
    ['code' => '+685', 'country' => 'Samoa'], ['code' => '+378', 'country' => 'San Marino'],
    ['code' => '+239', 'country' => 'São Tomé & Príncipe'], ['code' => '+966', 'country' => 'Saudi Arabia'],
    ['code' => '+221', 'country' => 'Senegal'], ['code' => '+381', 'country' => 'Serbia'],
    ['code' => '+248', 'country' => 'Seychelles'], ['code' => '+232', 'country' => 'Sierra Leone'],
    ['code' => '+65', 'country' => 'Singapore'], ['code' => '+1721', 'country' => 'Sint Maarten'],
    ['code' => '+421', 'country' => 'Slovakia'], ['code' => '+386', 'country' => 'Slovenia'],
    ['code' => '+677', 'country' => 'Solomon Islands'], ['code' => '+252', 'country' => 'Somalia'],
    ['code' => '+27', 'country' => 'South Africa'], ['code' => '+82', 'country' => 'South Korea'],
    ['code' => '+211', 'country' => 'South Sudan'], ['code' => '+34', 'country' => 'Spain'],
    ['code' => '+94', 'country' => 'Sri Lanka'], ['code' => '+249', 'country' => 'Sudan'],
    ['code' => '+597', 'country' => 'Suriname'], ['code' => '+47', 'country' => 'Svalbard & Jan Mayen'],
    ['code' => '+46', 'country' => 'Sweden'], ['code' => '+41', 'country' => 'Switzerland'],
    ['code' => '+963', 'country' => 'Syria'], ['code' => '+886', 'country' => 'Taiwan'],
    ['code' => '+992', 'country' => 'Tajikistan'], ['code' => '+255', 'country' => 'Tanzania'],
    ['code' => '+66', 'country' => 'Thailand'], ['code' => '+670', 'country' => 'Timor-Leste'],
    ['code' => '+228', 'country' => 'Togo'], ['code' => '+690', 'country' => 'Tokelau'],
    ['code' => '+676', 'country' => 'Tonga'], ['code' => '+1868', 'country' => 'Trinidad & Tobago'],
    ['code' => '+216', 'country' => 'Tunisia'], ['code' => '+90', 'country' => 'Turkey'],
    ['code' => '+993', 'country' => 'Turkmenistan'], ['code' => '+1649', 'country' => 'Turks & Caicos Islands'],
    ['code' => '+688', 'country' => 'Tuvalu'], ['code' => '+256', 'country' => 'Uganda'],
    ['code' => '+380', 'country' => 'Ukraine'], ['code' => '+971', 'country' => 'United Arab Emirates'],
    ['code' => '+44', 'country' => 'United Kingdom'], ['code' => '+1', 'country' => 'United States'],
    ['code' => '+598', 'country' => 'Uruguay'], ['code' => '+1', 'country' => 'US Virgin Islands'],
    ['code' => '+998', 'country' => 'Uzbekistan'], ['code' => '+678', 'country' => 'Vanuatu'],
    ['code' => '+379', 'country' => 'Vatican City'], ['code' => '+58', 'country' => 'Venezuela'],
    ['code' => '+84', 'country' => 'Vietnam'], ['code' => '+681', 'country' => 'Wallis & Futuna'],
    ['code' => '+967', 'country' => 'Yemen'], ['code' => '+260', 'country' => 'Zambia'],
    ['code' => '+263', 'country' => 'Zimbabwe'],
];
function generateSheetPhoneInput($baseName, $iconClass, $tabIndex, $fullNumber, $defaultFields, $mandatoryFields, $default_prefix) {
    global $prefixes;
    $normalizedPhone = preg_replace('/[\s\(\)\-]+/', '', (string)$fullNumber);
    if (substr($normalizedPhone, 0, 2) === '00') {
        $normalizedPhone = '+' . substr($normalizedPhone, 2);
    }
    $selectedPrefix = '';
    $strippedPhone = $normalizedPhone;
    usort($prefixes, fn($a, $b) => strlen($b['code']) - strlen($a['code']));
    foreach ($prefixes as $p) {
        if (strpos($normalizedPhone, $p['code']) === 0) {
            $selectedPrefix = $p['code'];
            $strippedPhone = substr($normalizedPhone, strlen($p['code']));
            break;
        }
    }
    if(empty($fullNumber) && !empty($default_prefix) && $default_prefix != 'no') {
        $selectedPrefix = $default_prefix;
    }
    usort($prefixes, fn($a, $b) => strcmp($a['country'], $b['country']));
    $visibilityClass = (array_key_exists($baseName, $defaultFields)) ? (($defaultFields[$baseName] == 1) ? '' : 'hidden') : '';
    $isMandatory = in_array($baseName, $mandatoryFields);
    $placeholderText = _(ucfirst($baseName)) . ($isMandatory ? ' *' : '');
    ?>
    <div id="new_<?php echo htmlspecialchars($baseName); ?>_prefix_container" class="sheet_detail_features noselect <?php echo $visibilityClass; ?>">
        <div class="features_icon"><i class="<?php echo htmlspecialchars($iconClass); ?>"></i></div>
        <div id="new_store_<?php echo htmlspecialchars($baseName); ?>" class="features_value" style="display: flex; gap: 5px;">
            <select
                    name="<?php echo htmlspecialchars($baseName); ?>_prefix"
                    id="new_<?php echo htmlspecialchars($baseName); ?>_prefix"
                    class="form-control"
                    style="<?php echo (($default_prefix == 'no') ? 'display: none' : 'flex: 1 1 50%') ?>;"
                    autofill="off"
                    autocomplete="off"
                    tabindex="<?php echo htmlspecialchars($tabIndex); ?>">
                <option value="" <?php if(empty($selectedPrefix)) echo 'selected'; ?>><?php echo _("Select prefix"); ?></option>
                <?php
                foreach ($prefixes as $p) {
                    $selected = ($p['code'] === $selectedPrefix) ? 'selected' : '';
                    echo "<option value=\"{$p['code']}\" {$selected}>({$p['code']}) {$p['country']}</option>";
                }
                ?>
            </select>
            <input
                    type="tel"
                    name="<?php echo htmlspecialchars($baseName); ?>"
                    id="new_<?php echo htmlspecialchars($baseName); ?>"
                    class="form-control"
                    style="flex: 1 1 50%;margin-right: 10px;"
                    value="<?php echo ($default_prefix=='no') ? htmlspecialchars($fullNumber) : htmlspecialchars($strippedPhone); ?>"
                    placeholder="<?php echo htmlspecialchars($placeholderText); ?>"
                    data-mandatory="<?php echo $isMandatory ? '1' : '0'; ?>"
                    autofill="off"
                    autocomplete="off"
            />
        </div>
    </div>
    <?php
}
?>
