<?php
session_start();
require_once("functions.php");
$id_marker = $_GET['id'];
$marker = get_marker($id_marker,$_SESSION['id_user']);
$url_song = "";
if($marker!==false) {
    $id_map = $marker['id_map'];
    $map = get_map($id_map,$_SESSION['id_user']);
    $_SESSION['marker_images_compression']=$map['marker_images_compression'];
    $_SESSION['marker_images_max_size']=$map['marker_images_max_size'];
    $array_coordinates = get_array_coordinates($id_map);
    $center_lat_lon = array(0,0);
    if(count($array_coordinates)>0) {
        $center_lat_lon = getCenterLatLng($array_coordinates);
    }
    if(empty($map['friendly_url'])) $map['friendly_url']=$map['code'];
    $settings = get_settings();
    $tmp_languages = get_languages_map();
    $array_languages = $tmp_languages[0];
    $default_language = $tmp_languages[1];
    if($marker['marker_size']==0) $marker['marker_size']=$map['markers_size'];
    if (is_ssl()) { $protocol = 'https'; } else { $protocol = 'http'; }
    $link_marker = $protocol ."://". $_SERVER['SERVER_NAME'] . str_replace("backend/index.php","viewer/index.php?code=",$_SERVER['SCRIPT_NAME']);
    $link_marker_f = $protocol ."://". $_SERVER['SERVER_NAME'] . str_replace("backend/index.php","viewer/",$_SERVER['SCRIPT_NAME']);
    $link_marker_f = $link_marker_f.$map['friendly_url']."--".$marker['id']."-".slugify(str_replace(" ","-",strtolower($marker['name'])));
    if($user_info['role']=='editor') {
        $editor_permissions = get_editor_permissions($_SESSION['id_user'],$id_map);
        if($editor_permissions['edit_markers']==0) {
            $marker=false;
        }
    }
    if(!empty($marker['song'])) {
        $url_song = "../viewer/content/".$marker['song'];
    }
    if(!empty($map['default_am_placeholders'])) {
        $default_am_placeholders = json_decode($map['default_am_placeholders'],true);
    } else {
        $default_am_placeholders = array();
    }
}
$array_input_lang = array();
$query_lang = "SELECT * FROM sml_markers_lang WHERE id_marker=$id_marker;";
$result_lang = $mysqli->query($query_lang);
if($result_lang) {
    if ($result_lang->num_rows > 0) {
        while($row_lang = $result_lang->fetch_array(MYSQLI_ASSOC)) {
            $language = $row_lang['language'];
            unset($row_lang['id_marker']);
            unset($row_lang['language']);
            $array_input_lang[$language]=$row_lang;
        }
    }
}
if(isset($_GET['tab'])) {
    $_SESSION['tab_marker']=$_GET['tab'];
}
if(!isset($_SESSION['tab_marker'])) {
    $_SESSION['tab_marker']='settings';
} else {
    if ($marker['to_validate'] && $_SESSION['tab_marker']=='link') {
        $_SESSION['tab_marker']='settings';
    }
}

$photos_to_validate = get_photos_to_validate($_SESSION['id_user'],$id_marker);
?>

<?php if(!$marker): ?>
    <div class="text-center">
        <div class="error mx-auto" data-text="401">401</div>
        <p class="lead text-gray-800 mb-5"><?php echo _("Permission denied"); ?></p>
        <p class="text-gray-500 mb-0"><?php echo _("It looks like you found a glitch in the matrix..."); ?></p>
        <a href="index.php?p=dashboard">← <?php echo _("Back to Dashboard"); ?></a>
    </div>
    <script>
        $('.map_select_header').remove();
    </script>
<?php die(); endif; ?>

<?php if($marker['to_validate']) { ?>
    <div class="alert alert-warning shadow-sm mt-3 mb-3 d-flex flex-column flex-md-row justify-content-between align-items-center" role="alert">
        <div class="mb-3 mb-md-0 pr-md-3">
            <i class="fas fa-exclamation-triangle mr-2"></i>
            <?php echo _("This marker was added by a person outside the system. Check the data entered before approving it."); ?>
        </div>
        <div class="custom-control custom-switch" style="font-size: 1.1rem;">
            <input <?php echo ($marker['to_validate']) ? '' : 'checked' ; ?> type="checkbox" class="custom-control-input" id="to_validate" />
            <label class="custom-control-label font-weight-bold" for="to_validate" style="padding-top: 2px;">
                <?php echo _("Validated"); ?>
                <i title="<?php echo _("It must be validated to be visible on the map"); ?>" class="help_t fas fa-question-circle text-muted ml-1" style="cursor: help;"></i>
            </label>
        </div>
    </div>
<?php } ?>

<?php if($photos_to_validate>0) : ?>
    <div class="alert alert-warning shadow-sm mt-3 mb-3 d-flex flex-column flex-md-row justify-content-between align-items-center" role="alert">
        <div class="mb-3 mb-md-0 pr-md-3">
            <i class="fas fa-exclamation-triangle mr-2"></i>
            <?php echo sprintf(_("There are <strong>%d</strong> photos added by someone outside the system. Check the media tab to review them before approving."), $photos_to_validate); ?>
        </div>
        <div>
            <button type="button" class="btn btn-warning btn-sm font-weight-bold shadow-sm" onclick="$('.nav-link[href=\'#images_tab\']').click();">
                <i class="fas fa-images"></i> <?php echo _("Review Media"); ?>
            </button>
        </div>
    </div>
<?php endif; ?>

<ul class="nav bg-white nav-pills nav-fill mb-2">
    <li class="nav-item">
        <a class="nav-link <?php echo ($_SESSION['tab_marker']=='link') ? 'active' : ''; ?>" onclick="set_session_tab('marker','link')" data-toggle="pill" href="#link_tab"><i class="fas fa-link"></i> <?php echo strtoupper(_("DIRECT LINK")); ?></a>
    </li>
    <li class="nav-item">
        <a class="nav-link <?php echo ($_SESSION['tab_marker']=='settings') ? 'active' : ''; ?>" onclick="set_session_tab('marker','settings')" data-toggle="pill" href="#settings_tab"><i class="fas fa-cog"></i> <?php echo strtoupper(_("GENERAL")); ?></a>
    </li>
    <li class="nav-item">
        <a class="nav-link <?php echo ($_SESSION['tab_marker']=='style') ? 'active' : ''; ?>" onclick="set_session_tab('marker','style')" data-toggle="pill" href="#style_tab"><i class="fas fa-palette"></i> <?php echo strtoupper(_("STYLE")); ?></a>
    </li>
    <li class="nav-item">
        <a class="nav-link <?php echo ($_SESSION['tab_marker']=='extra') ? 'active' : ''; ?>" onclick="set_session_tab('marker','extra')" data-toggle="pill" href="#extra_tab"><i class="fab fa-wpforms"></i> <?php echo strtoupper(_("DETAILS")); ?></a>
    </li>
    <li class="nav-item">
        <a class="nav-link <?php echo ($_SESSION['tab_marker']=='images') ? 'active' : ''; ?>" onclick="set_session_tab('marker','images')" data-toggle="pill" href="#images_tab"><i class="fas fa-images"></i> <?php echo strtoupper(_("MEDIA")); ?></a>
    </li>
    <li class="nav-item">
        <a class="nav-link <?php echo ($_SESSION['tab_marker']=='schedule') ? 'active' : ''; ?>" onclick="set_session_tab('marker','schedule')" data-toggle="pill" href="#schedule_tab"><i class="fas fa-clock"></i> <?php echo strtoupper(_("SCHEDULE / BOX WARNING")); ?></a>
    </li>
</ul>
<div class="tab-content">
    <div class="tab-pane <?php echo ($_SESSION['tab_marker']=='link') ? 'active' : ''; ?>" id="link_tab">
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-body">
                        <div class="row">
                            <?php $link = $link_marker.$map['code']."&m=".$id_marker; ?>
                            <div class="col-md-12">
                                <div class="form-group">
                                    <label for="link"><i class="fas fa-link"></i> <?php echo _("Link"); ?></label>
                                    <div class="input-group">
                                        <input readonly type="text" class="form-control bg-white" id="link" value="<?php echo $link; ?>" />
                                        <div class="input-group-append">
                                            <a title="<?php echo _("OPEN LINK"); ?>" class="btn btn-success help_t" href="<?php echo $link; ?>" target="_blank">
                                                <i class="fas fa-external-link-alt"></i>
                                            </a>
                                            <button title="<?php echo _("COPY TO CLIPBOARD"); ?>" class="btn btn-primary cpy_btn" data-clipboard-target="#link">
                                                <i class="far fa-clipboard"></i>
                                            </button>
                                            <button title="<?php echo _("QR CODE"); ?>" onclick="open_qr_code_modal('<?php echo $link; ?>');" class="btn btn-secondary help_t">
                                                <i class="fas fa-qrcode"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <?php $array_share_providers = explode(",",$settings['share_providers']); ?>
                                <div style="margin-top: 5px" class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="<?php echo $link; ?>">
                                    <a class="a2a_button_email <?php echo (in_array('email',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_whatsapp <?php echo (in_array('whatsapp',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_facebook <?php echo (in_array('facebook',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_threads <?php echo (in_array('threads',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_x <?php echo (in_array('twitter',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_linkedin <?php echo (in_array('linkedin',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_telegram <?php echo (in_array('telegram',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_facebook_messenger <?php echo (in_array('facebook_messenger',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_pinterest <?php echo (in_array('pinterest',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_reddit <?php echo (in_array('reddit',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_line <?php echo (in_array('line',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_viber <?php echo (in_array('viber',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_vk <?php echo (in_array('vk',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_qzone <?php echo (in_array('qzone',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                    <a class="a2a_button_wechat <?php echo (in_array('wechat',$array_share_providers) ? '' : 'hidden'); ?>"></a>
                                </div>
                                <?php if($settings['cookie_consent']) { ?>
                                    <script type="text/plain" data-category="functionality" data-service="Social Share (AddToAny)" async src="https://static.addtoany.com/menu/page.js"></script>
                                    <div style="display:none" id="cookie_denied_msg"><?php echo _("To use sharing via social networks, enable \"Social Share\" cookies in the <a data-cc='show-consentModal' href='#'>cookie preferences</a>."); ?></div>
                                <?php } else { ?>
                                    <script async src="https://static.addtoany.com/menu/page.js"></script>
                                <?php } ?>
                            </div>
                            <div class="col-md-12 mt-3">
                                <div class="form-group">
                                    <label for="link_f"><i class="fas fa-link"></i> <?php echo _("Friendly Link"); ?></label>
                                    <div class="input-group">
                                        <input readonly type="text" class="form-control bg-white" id="link_f" value="<?php echo $link_marker_f; ?>" />
                                        <div class="input-group-append <?php echo (empty($map['friendly_url'])) ? 'disabled' : '' ; ?>">
                                            <a id="open_link_f" title="<?php echo _("OPEN LINK"); ?>" class="btn btn-success" href="<?php echo $link_marker_f; ?>" target="_blank">
                                                <i class="fas fa-external-link-alt"></i>
                                            </a>
                                            <button id="copy_link_f" title="<?php echo _("COPY TO CLIPBOARD"); ?>" class="btn btn-primary cpy_btn" data-clipboard-text="<?php echo $link_marker_f; ?>">
                                                <i class="far fa-clipboard"></i>
                                            </button>
                                            <button id="qrcode_link_f" title="<?php echo _("QR CODE"); ?>" onclick="open_qr_code_modal('<?php echo $link_marker_f; ?>');" class="btn btn-secondary">
                                                <i class="fas fa-qrcode"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-12">
                                <div class="form-group mb-0">
                                    <label for="code" class="mb-0"><i class="fas fa-code"></i> <?php echo _("Embed Code"); ?></label>
                                    <div class="row mt-2 mb-0">
                                        <div class="col-md-4 col-sm-12">
                                            <div class="input-group input-group-sm">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><i class="fas fa-expand"></i>&nbsp;&nbsp;<?php echo _("Mode"); ?></span>
                                                </div>
                                                <select class="form-control" id="embed_type">
                                                    <option value="responsive"><?php echo _("Aspect Ratio"); ?></option>
                                                    <option selected value="fixed"><?php echo _("Custom Dimensions"); ?></option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-4 col-sm-6 embed_responsive_settings d-none">
                                            <div class="input-group input-group-sm">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><?php echo _("Aspect Ratio"); ?></span>
                                                </div>
                                                <select class="form-control" id="embed_ratio">
                                                    <option value="16/9" selected>16:9</option>
                                                    <option value="9/16">9:16</option>
                                                    <option value="4/3">4:3</option>
                                                    <option value="3/4">3:4</option>
                                                    <option value="1/1">1:1</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-4 col-sm-6 embed_responsive_settings d-none">
                                            <div class="input-group input-group-sm">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><?php echo _("Max Width"); ?></span>
                                                </div>
                                                <input type="text" class="form-control" id="embed_max_width" value="100%">
                                            </div>
                                        </div>
                                        <div class="col-md-4 col-sm-6 embed_fixed_settings">
                                            <div class="input-group input-group-sm">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><?php echo _("Width"); ?></span>
                                                </div>
                                                <input type="text" class="form-control" id="embed_width" value="100%">
                                            </div>
                                        </div>
                                        <div class="col-md-4 col-sm-6 embed_fixed_settings">
                                            <div class="input-group input-group-sm">
                                                <div class="input-group-prepend">
                                                    <span class="input-group-text"><?php echo _("Height"); ?></span>
                                                </div>
                                                <input type="text" class="form-control" id="embed_height" value="600px">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="input-group">
                                        <?php
                                        $wrapper_style = "width:100%;height:600px;max-width:100%;overflow:hidden;position:relative;border-radius:8px;";
                                        $iframe_style = "width:100%;height:100%;border:0;display:block;";
                                        $iframe_allow = "accelerometer; camera; display-capture; fullscreen; geolocation; gyroscope; magnetometer; microphone; midi; xr-spatial-tracking;";
                                        $code_main = '<div class="ml_marker_wrapper_container" style="'.$wrapper_style.'">'."\n".'  <iframe id="ml_iframe_marker_'.$id_marker.'" allow="'.$iframe_allow.'" src="'.$link.'" loading="lazy" style="'.$iframe_style.'"></iframe>'."\n".'</div>';
                                        ?>
                                        <textarea id="code" class="form-control" rows="5" data-default-value='<?php echo htmlspecialchars($code_main, ENT_QUOTES); ?>'><?php echo $code_main; ?></textarea>
                                        <div class="input-group-append">
                                            <button id="copy_code" title="<?php echo _("COPY TO CLIPBOARD"); ?>" class="btn btn-primary cpy_btn help_t" data-clipboard-target="#code">
                                                <i class="far fa-clipboard"></i>
                                            </button>
                                            <?php foreach ($array_languages as $lang) {
                                                if($lang!=$default_language) : ?>
                                                    <button id="copy_code_<?php echo $lang; ?>" style="display:none;" title="<?php echo _("COPY TO CLIPBOARD"); ?>" class="btn btn-primary cpy_btn input_lang help_t" data-target-id="copy_code" data-lang="<?php echo $lang; ?>" data-clipboard-target="#code_<?php echo $lang; ?>">
                                                        <i class="far fa-clipboard"></i>
                                                    </button>
                                                <?php endif;
                                            } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-pane <?php echo ($_SESSION['tab_marker']=='settings') ? 'active' : ''; ?>" id="settings_tab">
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-8">
                                <div class="form-group">
                                    <label for="name"><?php echo _("Name"); ?> *</label><?php echo print_language_input_selector($array_languages,$default_language,'name'); ?>
                                    <input type="text" class="form-control" id="name" value="<?php echo $marker['name']; ?>" />
                                    <?php foreach ($array_languages as $lang) {
                                        if($lang!=$default_language) : ?>
                                            <input style="display:none;" type="text" class="form-control input_lang" data-target-id="name" data-lang="<?php echo $lang; ?>" value="<?php echo $array_input_lang[$lang]['name']; ?>" />
                                        <?php endif;
                                    } ?>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="category"><?php echo _("Category"); ?></label>
                                    <select multiple id="category" data-live-search="true" data-actions-box="true" data-selected-text-format="count > 3" class="form-control selectpicker">
                                        <?php echo get_categories($id_map,$marker['id_categories']); ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md">
                                <div class="form-group">
                                    <label for="active"><?php echo _("Active"); ?></label><br>
                                    <input <?php echo ($marker['active']) ? 'checked' : '' ; ?> type="checkbox" id="active" />
                                </div>
                            </div>
                            <div class="col-md">
                                <div class="form-group">
                                    <label for="visible_map"><?php echo _("Visible - Map"); ?></label><br>
                                    <input <?php echo ($marker['visible_map']) ? 'checked' : '' ; ?> type="checkbox" id="visible_map" />
                                </div>
                            </div>
                            <div class="col-md">
                                <div class="form-group">
                                    <label for="visible_search"><?php echo _("Visible - Search"); ?></label><br>
                                    <input <?php echo ($marker['visible_search']) ? 'checked' : '' ; ?> type="checkbox" id="visible_search" />
                                </div>
                            </div>
                            <div class="col-md">
                                <div class="form-group">
                                    <label for="centered"><?php echo _("Centered"); ?> <i title="<?php echo _("center the map on this marker"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                    <input <?php echo ($marker['centered']) ? 'checked' : '' ; ?> type="checkbox" id="centered" />
                                </div>
                            </div>
                            <div class="col-md">
                                <div class="form-group">
                                    <label for="featured"><?php echo _("Featured"); ?> <i title="<?php echo _("show this marker on featured list"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                    <input <?php echo ($marker['featured']) ? 'checked' : '' ; ?> type="checkbox" id="featured" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-map-location"></i> <?php echo _("Position"); ?></h6>
                    </div>
                    <div class="card-body">
                        <?php
                        $address_format_saved_array = json_decode($map['address_format'], true);
                        $form_field_definitions = [
                                'street'      => ['label' => _("Street Address"), 'col' => 'col-md-4'],
                                'postal_code' => ['label' => _("Postal Code"),    'col' => 'col-md-4'],
                                'city'        => ['label' => _("City"),           'col' => 'col-md-4'],
                                'county'      => ['label' => _("County"),         'col' => 'col-md-4'],
                                'state'       => ['label' => _("State / Province"),'col' => 'col-md-4'],
                                'country'     => ['label' => _("Country"),        'col' => 'col-md-4']
                        ];
                        ?>
                        <div class="row">
                            <?php
                            foreach ($address_format_saved_array as $item) {
                                $key = $item['field'];
                                if (!isset($form_field_definitions[$key])) continue;
                                $def = $form_field_definitions[$key];
                                $isEnabled = isset($item['enabled']) ? (bool)$item['enabled'] : true;
                                if ($isEnabled) {
                                    $statusIcon = '<i class="fas small fa-check-circle text-success ml-1"></i>';
                                } else {
                                    $statusIcon = '<i class="fas small fa-ban text-danger ml-1"></i>';
                                }
                                ?>
                                <div class="<?php echo $def['col']; ?>">
                                    <div class="form-group">
                                        <label for="<?php echo $key; ?>">
                                            <?php echo $def['label']; ?>
                                            <?php echo $statusIcon; ?>
                                        </label>
                                        <input
                                                onchange="check_set_address_position();"
                                                oninput="check_set_address_position();"
                                                type="text"
                                                class="form-control"
                                                id="<?php echo $key; ?>"
                                                value="<?php echo isset($marker[$key]) ? $marker[$key] : ''; ?>"
                                        />
                                    </div>
                                </div>
                                <?php
                            }
                            ?>
                        </div>
                        <hr>
                        <div class="row">
                            <div class="col-lg-4 col-md-4 col-sm-4">
                                <div class="form-group">
                                    <label for="latitude_edit"><?php echo _("Latitude"); ?></label>
                                    <input onchange="check_set_position();" oninput="this.value = this.value.replace(/[^0-9.\-]/g, '').replace(/(?!^)-/g, '');check_set_position();" type="text" pattern="-?[0-9]*(\.[0-9]+)?" class="form-control" id="latitude_edit" value="<?php echo $marker['lat']; ?>">
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4">
                                <div class="form-group">
                                    <label for="longitude_edit"><?php echo _("Longitude"); ?></label>
                                    <input onchange="check_set_position();" oninput="this.value = this.value.replace(/[^0-9.\-]/g, '').replace(/(?!^)-/g, '');check_set_position();" type="text" pattern="-?[0-9]*(\.[0-9]+)?" class="form-control" id="longitude_edit" value="<?php echo $marker['lon']; ?>">
                                </div>
                            </div>
                            <div class="col-lg-4 col-md-4 col-sm-4">
                                <div class="form-group">
                                    <label for="min_zoom_level"><?php echo _("Visible from Zoom Level"); ?></label>
                                    <select class="form-control" id="min_zoom_level">
                                        <?php
                                        for($i=0;$i<=20;$i++) {
                                            if($i==$marker['min_zoom_level']) {
                                                echo "<option selected id='$i'>$i</option>";
                                            } else {
                                                echo "<option id='$i'>$i</option>";
                                            }
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="selected_zoom"><?php echo _("Zoom Override"); ?> <i title="<?php echo _("zoom level when the marker is clicked (1 far - 20 near)"); ?>" class="help_t fas fa-question-circle"></i></label>
                                    <select id="selected_zoom" class="form-control">
                                        <option <?php echo ($marker['selected_zoom']==-1) ? 'selected' : ''; ?> id="-1"><?php echo _("No override"); ?> (<?php echo $map['selected_zoom']; ?>)</option>
                                        <option <?php echo ($marker['selected_zoom']==0) ? 'selected' : ''; ?> id="0"><?php echo _("Keep Zoom level"); ?></option>
                                        <?php
                                        for($i=1;$i<=20;$i++) {
                                            if($marker['selected_zoom']==$i) {
                                                echo "<option selected id='$i'>$i</option>";
                                            } else {
                                                echo "<option id='$i'>$i</option>";
                                            }
                                        }
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="duration_zoom"><?php echo _("Animation Zoom Override"); ?> <i title="<?php echo _("zoom animation duration in ms for this marker (-1 use default)"); ?>" class="help_t fas fa-question-circle"></i></label>
                                    <div class="input-group">
                                        <input type="number" class="form-control" id="duration_zoom" value="<?php echo $marker['duration_zoom']; ?>">
                                        <div class="input-group-append">
                                            <span class="input-group-text" id="basic-addon2">ms</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="geofence_radius"><?php echo _("Geofence Radius"); ?></label>
                                    <input onchange="draw_geofence();" oninput="draw_geofence();" min="0" type="number" class="form-control" id="geofence_radius" value="<?php echo $marker['geofence_radius']; ?>">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="geofence_color"><?php echo _("Geofence Color"); ?></label>
                                    <input type="text" class="form-control" id="geofence_color" value="<?php echo $marker['geofence_color']; ?>">
                                </div>
                            </div>
                        </div>
                        <hr>
                        <div class="row mb-2">
                            <div class="col-lg-3 col-md-3 col-sm-6">
                                <button id="btn_address_position" onclick="address_to_position();" class="btn btn-block btn-primary mb-1"><i class="fa-solid fa-map-pin"></i>&nbsp;&nbsp;<?php echo _("ADDRESS"); ?> → <?php echo _("POSITION"); ?></button>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-6">
                                <button id="btn_position_address" onclick="position_to_address();" class="btn btn-block btn-primary mb-1"><i class="fa-solid fa-map-pin"></i>&nbsp;&nbsp;<?php echo _("POSITION"); ?> → <?php echo _("ADDRESS"); ?></button>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-6">
                                <button id="btn_set_position" onclick="set_marker_position();" class="btn btn-block btn-primary mb-1"><i class="fa-solid fa-crosshairs"></i>&nbsp;&nbsp;<?php echo _("SET POSITION"); ?></button>
                            </div>
                            <div class="col-lg-3 col-md-3 col-sm-6">
                                <button id="btn_get_position" onclick="get_current_position();" class="btn btn-block btn-warning mb-1"><i class="fa-solid fa-location-arrow"></i>&nbsp;&nbsp;<?php echo _("GET GPS POSITION"); ?></button>
                            </div>
                            <div class="mt-2 text-center " style="width: 100%;">
                                <?php echo _("Latitude"); ?>: <b><span id="lat"><?php echo $marker['lat']; ?></span></b> -
                                <?php echo _("Longitude"); ?>: <b><span id="lon"><?php echo $marker['lon']; ?></span></b> -
                                <?php echo _("Zoom Level"); ?>: <b><span id="zoom_level">0</span></b><br>
                                <i><?php echo _("click/drag on map to change marker's position"); ?></i>
                            </div>
                            <script>
                                check_set_address_position();
                                check_set_position();
                            </script>
                        </div>
                        <div id="map_marker" class="map_marker">
                            <div class="switch_style">
                                <img onclick="change_map_style('default_style');" id="default_style" style="display: none" src="../viewer/images/street.jpg" />
                                <img onclick="change_map_style('satellite_style');" id="satellite_style" src="../viewer/images/satellite.jpg" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-pane <?php echo ($_SESSION['tab_marker']=='schedule') ? 'active' : ''; ?>" id="schedule_tab">
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-header pl-3 pt-3 pr-3 pb-1 noselect">
                        <input onchange="check_schedule();" type="checkbox" id="enable_schedule" />
                        <label for="enable_schedule"><?php echo _("Marker Visibility - Enable Schedule"); ?></label>
                    </div>
                    <div id="schedule_content" class="card-body disabled">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="date_from"><?php echo _("Date - From"); ?></label>
                                    <input type="date" class="form-control" id="date_from" />
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="date_to"><?php echo _("Date - To"); ?></label>
                                    <input type="date" class="form-control" id="date_to" />
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="ignore_year"><?php echo _("Repeat annually (ignore year)"); ?></label><br>
                                    <input type="checkbox" class="form-control" id="ignore_year" />
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <label><?php echo _("Days of the week"); ?></label><br>
                                <label><input type="checkbox" id="days_1"> <?php echo _("Monday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_2"> <?php echo _("Tuesday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_3"> <?php echo _("Wednesday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_4"> <?php echo _("Thursday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_5"> <?php echo _("Friday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_6"> <?php echo _("Saturday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_7"> <?php echo _("Sunday"); ?></label>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="hour_from"><?php echo _("Hour - From"); ?></label>
                                    <input type="time" class="form-control" id="hour_from" />
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="hour_to"><?php echo _("Hour - To"); ?></label>
                                    <input type="time" class="form-control" id="hour_to" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-header pl-3 pt-3 pr-3 pb-1 noselect">
                        <input onchange="check_schedule_box();" type="checkbox" id="enable_schedule_box" />
                        <label for="enable_schedule_box"><?php echo _("Box Warning - Enable Schedule"); ?></label>
                    </div>
                    <div class="card-body mb-0 pb-0">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-group mb-0">
                                    <label for="box_warning"><?php echo _("Message"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'box_warning'); ?>
                                    <textarea rows="3" class="form-control" id="box_warning"><?php echo $marker['box_warning']; ?></textarea>
                                    <?php foreach ($array_languages as $lang) {
                                        if($lang!=$default_language) : ?>
                                            <textarea style="display:none;" rows="3" class="form-control input_lang" data-target-id="box_warning" data-lang="<?php echo $lang; ?>"><?php echo $array_input_lang[$lang]['box_warning']; ?></textarea>
                                        <?php endif;
                                    } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="schedule_content_box" class="card-body disabled">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="date_from_box"><?php echo _("Date - From"); ?></label>
                                    <input type="date" class="form-control" id="date_from_box" />
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="date_to_box"><?php echo _("Date - To"); ?></label>
                                    <input type="date" class="form-control" id="date_to_box" />
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="ignore_year_box"><?php echo _("Repeat annually (ignore year)"); ?></label><br>
                                    <input type="checkbox" class="form-control" id="ignore_year_box" />
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <label><?php echo _("Days of the week"); ?></label><br>
                                <label><input type="checkbox" id="days_1_box"> <?php echo _("Monday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_2_box"> <?php echo _("Tuesday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_3_box"> <?php echo _("Wednesday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_4_box"> <?php echo _("Thursday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_5_box"> <?php echo _("Friday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_6_box"> <?php echo _("Saturday"); ?></label>&nbsp;&nbsp;
                                <label><input type="checkbox" id="days_7_box"> <?php echo _("Sunday"); ?></label>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="hour_from_box"><?php echo _("Hour - From"); ?></label>
                                    <input type="time" class="form-control" id="hour_from_box" />
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="hour_to_box"><?php echo _("Hour - To"); ?></label>
                                    <input type="time" class="form-control" id="hour_to_box" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-pane <?php echo ($_SESSION['tab_marker']=='style') ? 'active' : ''; ?>" id="style_tab">
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-map-marker"></i> <?php echo _("Icon Style"); ?></h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-9">
                                <div class="row">
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label><?php echo _("Type"); ?></label>
                                            <select id="icon_type" onchange="change_icon_type();" class="form-control">
                                                <option <?php echo ($marker['icon']=='' && $marker['icon_image']=='') ? 'selected' : '' ; ?> id="0"><?php echo _("Circle"); ?></option>
                                                <option <?php echo ($marker['icon']!='' && $marker['icon_image']=='') ? 'selected' : '' ; ?> id="1"><?php echo _("Icon"); ?></option>
                                                <option <?php echo ($marker['icon_image']!='') ? 'selected' : '' ; ?> id="2"><?php echo _("Icon Library"); ?></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label for="marker_size"><?php echo _("Size"); ?> (<span id="marker_size_value"><?php echo $marker['marker_size']; ?><?php echo ($marker['marker_size']==$map['markers_size']) ? ' default' : ''; ?></span>)</label><br>
                                            <input oninput="change_marker_size();" onchange="change_marker_size();" type="range" step="0.1" min="0.1" max="2.0" class="form-control-range" id="marker_size" value="<?php echo $marker['marker_size']; ?>" />
                                        </div>
                                    </div>
                                    <div id="icon_type_1" class="col-md-6 <?php echo ($marker['icon']!='' && $marker['icon_image']=='') ? '' : 'd-none' ; ?>">
                                        <div class="form-group">
                                            <label><?php echo _("Icon"); ?></label><br>
                                            <button class="btn btn-sm btn-primary" type="button" id="GetIconPicker" data-iconpicker-input="input#marker_icon_input" data-iconpicker-preview="i#marker_icon"><?php echo _("Select Icon"); ?></button>
                                            <input readonly type="text" id="marker_icon_input" name="Icon" value="<?php echo $marker['icon']; ?>" required="" placeholder="" autocomplete="off" spellcheck="false">
                                            <div class="icon-preview d-inline-block ml-1" data-toggle="tooltip" title="">
                                                <i id="marker_icon" class="<?php echo $marker['icon']; ?>"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="icon_type_2" class="col-md-6 <?php echo ($marker['icon_image']!='') ? '' : 'd-none' ; ?>">
                                        <div class="form-group">
                                            <label for="marker_library_icon"><?php echo _("Icon"); ?></label><br>
                                            <button data-toggle="modal" data-target="#modal_library_icons" class="btn btn-sm btn-primary" type="button" id="btn_library_icon"><?php echo _("Select Library Icon"); ?></button>
                                            <input type="hidden" id="marker_library_icon" value="<?php echo $marker['id_icon_library']; ?>">
                                            <img id="marker_library_icon_preview" style="height: 30px;display: <?php echo ($marker['icon_image']=='') ? 'none':'inline-block'; ?>" src="../viewer/icons/<?php echo $marker['icon_image']; ?>">
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-3">
                                        <div class="form-group <?php echo ($marker['icon_image']!='') ? 'disabled':''; ?>">
                                            <label><?php echo _("Background"); ?></label>
                                            <input type="text" class="form-control" id="color_hex" value="<?php echo $marker['color_hex']; ?>" />
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group <?php echo ($marker['icon_image']!='' || ($marker['icon']=='' && $marker['icon_image']=='')) ? 'disabled':''; ?>">
                                            <label><?php echo _("Color"); ?></label>
                                            <input type="text" class="form-control" id="icon_color_hex" value="<?php echo $marker['icon_color_hex']; ?>" />
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group <?php echo ($marker['icon_image']!='') ? 'disabled':''; ?>">
                                            <label><?php echo _("Background - Hover"); ?></label>
                                            <input type="text" class="form-control" id="color_hex_hover" value="<?php echo $marker['color_hex_hover']; ?>" />
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group <?php echo ($marker['icon_image']!='' || ($marker['icon']=='' && $marker['icon_image']=='')) ? 'disabled':''; ?>">
                                            <label><?php echo _("Color - Hover"); ?></label>
                                            <input type="text" class="form-control" id="icon_color_hex_hover" value="<?php echo $marker['icon_color_hex_hover']; ?>" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label><?php echo _("Label"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'icon_label'); ?> <i title="<?php echo _("label shown under the icon (use \\n to carriage return the text)"); ?>" class="help_t fas fa-question-circle"></i>
                                            <input oninput="change_style_marker();" type="text" class="form-control" id="icon_label" value="<?php echo $marker['icon_label']; ?>" />
                                            <?php foreach ($array_languages as $lang) {
                                                if($lang!=$default_language) : ?>
                                                    <input style="display:none;" type="text" class="form-control input_lang" data-target-id="icon_label" data-lang="<?php echo $lang; ?>" value="<?php echo $array_input_lang[$lang]['icon_label']; ?>" />
                                                <?php endif;
                                            } ?>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label><?php echo _("Label - Color"); ?></label>
                                            <input type="text" class="form-control" id="icon_label_color" value="<?php echo $marker['icon_label_color']; ?>" />
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label><?php echo _("Label - Size"); ?></label>
                                            <div class="input-group mb-3">
                                                <input oninput="change_style_marker();" type="number" class="form-control" id="icon_label_size" value="<?php echo $marker['icon_label_size']; ?>" />
                                                <div class="input-group-append">
                                                    <span class="input-group-text" id="basic-addon2">px</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div id="map_marker_style"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-8 col-md-6">
                        <div class="card shadow mb-4 <?php echo (!$map['sheet_detail']) ? 'disabled' : '' ; ?>">
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary d-inline-block"><i class="fas fa-window-maximize"></i> <?php echo _("Detail Window"); ?> <i title="<?php echo _("opens the details window by clicking on this marker"); ?>" class="help_t fas fa-question-circle"></i></h6>&nbsp;&nbsp;
                                <input <?php echo ($marker['open_sheet']) ? 'checked' : '' ; ?> onchange="change_open_sheet_marker();" type="checkbox" id="open_sheet" />
                            </div>
                            <div id="sheet_details_settings" class="card-body <?php echo (!$marker['open_sheet']) ? 'disabled' : '' ; ?>">
                                <div class="row">
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label for="type"><?php echo _("Type"); ?></label><br>
                                            <select onchange="change_marker_type();" id="type" class="form-control">
                                                <option <?php echo ($marker['type']=='default') ? 'selected' : '' ; ?> id="default"><?php echo _("Default"); ?></option>
                                                <option <?php echo ($marker['type']=='link') ? 'selected' : '' ; ?> id="link"><?php echo _("Open Link (New window)"); ?></option>
                                                <option <?php echo ($marker['type']=='link_same') ? 'selected' : '' ; ?> id="link_same"><?php echo _("Open Link (Same window)"); ?></option>
                                                <option <?php echo ($marker['type']=='iframe') ? 'selected' : '' ; ?> id="iframe"><?php echo _("Open Modal"); ?></option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-9">
                                        <div class="form-group">
                                            <label for="link_t"><?php echo _("Link"); ?></label><br>
                                            <input <?php echo ($marker['type']=='default') ? 'disabled' : '' ; ?> id="link_t" class="form-control" type="text" value="<?php echo $marker['link']; ?>" />
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-4">
                                        <div class="form-group <?php echo (!$map['enable_last_update']) ? 'disabled' : ''; ?>">
                                            <label for="view_last_update"><?php echo _("Last Update Date"); ?> <i title="<?php echo _("shows the last update date for this marker"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                            <input <?php echo ($marker['view_last_update']) ? 'checked' : ''; ?> type="checkbox" id="view_last_update" /> <?php echo (!$map['enable_last_update']) ? _("disabled on map") : ''; ?>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group <?php echo (!$map['enable_directions']) ? 'disabled' : ''; ?>">
                                            <label for="view_directions"><?php echo _("Directions"); ?> <i title="<?php echo _("enable the button 'directions' for this marker"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                            <input <?php echo ($marker['view_directions']) ? 'checked' : '' ; ?> type="checkbox" id="view_directions" /> <?php echo (!$map['enable_directions']) ? _("disabled on map") : ''; ?>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group <?php echo (!$map['enable_streetview']) ? 'disabled' : ''; ?>">
                                            <label for="view_street_view"><?php echo _("Street View"); ?> <i title="<?php echo _("enable the button 'street view' for this marker"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                            <input <?php echo ($marker['view_street_view']) ? 'checked' : '' ; ?> type="checkbox" id="view_street_view" /> <?php echo (!$map['enable_streetview']) ? _("disabled on map") : ''; ?>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group <?php echo (!$map['enable_reviews']) ? 'disabled' : ''; ?>">
                                            <label for="view_review"><?php echo _("Review"); ?> <i title="<?php echo _("enable the reviews for this marker"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                            <input <?php echo ($marker['view_review']) ? 'checked' : '' ; ?> type="checkbox" id="view_review" /> <?php echo (!$map['enable_reviews']) ? _("disabled on map") : ''; ?>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group <?php echo (!$map['enable_add_photo']) ? 'disabled' : ''; ?>">
                                            <label for="view_add_photo"><?php echo _("Add Photo"); ?> <i title="<?php echo _("enable the ability to add photo from the map for this marker"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                            <input <?php echo ($marker['view_add_photo']) ? 'checked' : '' ; ?> type="checkbox" id="view_add_photo" /> <?php echo (!$map['enable_add_photo']) ? _("disabled on map") : ''; ?>
                                        </div>
                                    </div>
                                    <div class="col-md-4">
                                        <div class="form-group <?php echo (!$map['enable_share']) ? 'disabled' : ''; ?>">
                                            <label for="view_share"><?php echo _("Share"); ?> <i title="<?php echo _("enable share buttons for this marker"); ?>" class="help_t fas fa-question-circle"></i></label><br>
                                            <input <?php echo ($marker['view_share']) ? 'checked' : '' ; ?> type="checkbox" id="view_share" /> <?php echo (!$map['enable_share']) ? _("disabled on map") : ''; ?>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 <?php echo (empty($settings['tripadvisor_api_key'])) ? 'disabled' : ''; ?>">
                                        <div class="form-group">
                                            <label for="tripadvisor_location_id">Tripadvisor - <?php echo _("Location Id"); ?></label><br>
                                            <div class="input-group">
                                                <input id="tripadvisor_location_id" class="form-control" type="text" value="<?php echo $marker['tripadvisor_location_id']; ?>" />
                                                <div class="input-group-append">
                                                    <button class="btn btn-outline-secondary" type="button" data-toggle="modal" data-target="#tripadvisor_modal">
                                                        <?php echo _("Search"); ?>
                                                    </button>
                                                    <button <?php echo ($demo) ? 'disabled' : ''; ?> class="btn btn-outline-info" type="button" id="tripadvisor_check_info_btn" onclick="tripadvisor_info();">
                                                        <?php echo _("Info"); ?>
                                                    </button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-6">
                        <div class="card shadow mb-4">
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-music"></i> <?php echo _("Audio"); ?> <i title="<?php echo _("audio played when the details window is opened"); ?>" class="help_t fas fa-question-circle"></i></h6>
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    <div style="display: none" id="div_player_song" class="col-md-12">
                                        <audio style="width: 100%" controls>
                                            <source src="<?php echo $url_song; ?>" type="audio/mpeg">
                                            Your browser does not support the audio element.
                                        </audio>
                                    </div>
                                    <div style="display: none" id="div_delete_song" class="col-md-12">
                                        <button onclick="delete_marker_song();return false;" id="btn_delete_song" class="btn btn-block btn-danger mb-3"><?php echo _("DELETE AUDIO"); ?></button>
                                    </div>
                                    <div style="display: none" id="div_upload_song" class="col-md-12">
                                        <form id="frm_s" action="ajax/upload_song.php" method="POST" enctype="multipart/form-data">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="input-group">
                                                        <div class="custom-file">
                                                            <input type="file" class="custom-file-input" id="txtFile_s" name="txtFile_s" />
                                                            <label class="custom-file-label" for="txtFile_s"><?php echo _("Choose file"); ?></label>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                        <input <?php echo ($demo) ? 'disabled':''; ?> type="submit" class="btn btn-block btn-success" id="btnUpload_s" value="<?php echo _("Upload Audio (MP3)"); ?>" />
                                                    </div>
                                                </div>
                                                <div class="col-md-12">
                                                    <div class="preview text-center">
                                                        <div class="progress mb-3" style="height: 2.35rem;display: none">
                                                            <div class="progress-bar" id="progressBar_s" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width:0%;">
                                                                0%
                                                            </div>
                                                        </div>
                                                        <div style="display: none;padding: .38rem;" class="alert alert-danger" id="error_s"></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="song_link"><?php echo _("External link"); ?></label>
                                            <input id="song_link" type="text" class="form-control" value="<?php echo $marker['song_link']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="song_volume"><?php echo _("Audio Volume"); ?> (<span id="song_volume_value"><?php echo $marker['song_volume']*100; ?>%</span>)</label>
                                            <input oninput="change_song_volume();" min="0" max="1" step="0.1" id="song_volume" type="range" class="form-control-range" value="<?php echo $marker['song_volume']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="song_bg_volume"><?php echo _("Background Volume"); ?> <i title="<?php echo _("sets the volume of the main map audio when listening to this audio"); ?>" class="help_t fas fa-question-circle"></i> (<span id="song_bg_volume_value"><?php echo $marker['song_bg_volume']*100; ?>%</span>)</label>
                                            <input oninput="change_song_bg_volume();" min="0" max="1" step="0.1" id="song_bg_volume" type="range" class="form-control-range" value="<?php echo $marker['song_bg_volume']; ?>">
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="song_play_bg"><?php echo _("Continuous playback"); ?></label> <i title="<?php echo _("continues playing even when the marker closes"); ?>" class="help_t fas fa-question-circle"></i>&nbsp;&nbsp;
                                            <input id="song_play_bg" type="checkbox" <?php echo ($marker['song_play_bg']) ? 'checked' : ''; ?> />
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card shadow mb-4 <?php echo (!$map['enable_popup']) ? 'disabled' : '' ; ?>">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary d-inline-block"><i class="fas fa-window-maximize"></i> <?php echo _("Popup"); ?> <i title="<?php echo _("display popup on hover over this marker"); ?>" class="help_t fas fa-question-circle"></i></h6>&nbsp;&nbsp;
                        <input <?php echo ($marker['view_popup']) ? 'checked' : '' ; ?> onchange="change_popup_marker();" type="checkbox" id="view_popup" />
                    </div>
                    <div id="popup_settings" class="card-body <?php echo (!$marker['view_popup']) ? 'disabled' : '' ; ?>">
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label><?php echo _("Image Height"); ?></label>
                                    <div class="input-group mb-3">
                                        <input min="0" type="number" class="form-control" id="popup_image_height" value="<?php echo $marker['popup_image_height']; ?>" />
                                        <div class="input-group-append">
                                            <span class="input-group-text" id="basic-addon2">px</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label><?php echo _("Background Color"); ?></label>
                                    <input type="text" class="form-control" id="popup_background" value="<?php echo $marker['popup_background']; ?>" />
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label><?php echo _("Text Color"); ?></label>
                                    <input type="text" class="form-control" id="popup_color" value="<?php echo $marker['popup_color']; ?>" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-pane <?php echo ($_SESSION['tab_marker']=='images') ? 'active' : ''; ?>" id="images_tab">
        <div class="row">
            <div class="col-md-8">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="d-inline-block m-0 font-weight-bold text-primary"><i class="fas fa-images"></i> <?php echo _("Images / Video"); ?></h6>
                        <div class="float-right <?php echo ($map['marker_images_num']==-1) ? 'd-none' : 'd-inline-block'; ?>"><?php echo _("maximum number of images: ").$map['marker_images_num']; ?> </div>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <form action="ajax/upload_marker_image.php" class="dropzone mb-3 noselect <?php echo ($demo) ? 'disabled' : ''; ?>" id="gallery-dropzone"></form>
                            </div>
                            <div id="image_others_btn" class="col-md-12 mb-3 text-center">
                                <button onclick="open_modal_media_library('all');" class="btn btn-sm btn-primary"><i class="fas fa-photo-video"></i> <?php echo _("Select from Media library"); ?></button>&nbsp;&nbsp;
                                <button data-toggle="modal" data-target="#modal_add_video_link" class="btn btn-sm btn-primary"><i class="fas fa-link"></i> <?php echo _("Add Video Link (YouTube / Vimeo)"); ?></button>
                            </div>
                            <div id="image_list" class="col-md-12">
                                <div id="image_gallery"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-toolbox"></i> <?php echo _("Media Action"); ?></h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div id="msg_sel_image" class="col-md-12">
                                <?php echo _("Select media first!"); ?>
                            </div>
                            <div id="btn_preview_media" class="col-md-12 mb-4 d-none">
                                <button onclick="preview_media();" class="btn btn-block btn-info"><i class="fas fa-search-plus"></i> <?php echo _("OPEN"); ?></button>
                            </div>
                            <div id="btn_validate_image" class="col-md-12 mb-4 d-none">
                                <button onclick="validate_image();" class="btn btn-block btn-warning"><i class="fas fa-check"></i> <?php echo _("VALIDATE"); ?></button>
                            </div>
                            <div id="div_edit_video_link" class="col-md-12 mb-4 d-none">
                                <label><?php echo _("Video Link"); ?></label>
                                <div class="input-group">
                                    <input type="text" class="form-control" id="video_link_edit" value="" />
                                    <div class="input-group-append">
                                        <button onclick="update_video_link();" class="btn btn-success" type="button"><i class="fas fa-save"></i></button>
                                    </div>
                                </div>
                            </div>
                            <div id="btn_setmain_image" class="col-md-12 mb-4 d-none">
                                <button <?php echo ($demo) ? 'disabled':''; ?> onclick="set_as_main();" class="btn btn-block btn-primary"><?php echo _("SET AS MAIN"); ?></button>
                            </div>
                            <div id="btn_hide_image" class="col-md-12 mb-4 d-none">
                                <button <?php echo ($demo) ? 'disabled':''; ?> onclick="hide_image();" class="btn btn-block btn-primary"><i class="fa-solid fa-eye-slash"></i>&nbsp;&nbsp;<?php echo _("HIDE"); ?></button>
                            </div>
                            <div id="btn_rotate_image_l" class="col-md-6 mb-4 d-none">
                                <button <?php echo ($demo) ? 'disabled':''; ?> onclick="" class="btn btn-block btn-primary"><i class="fa-solid fa-rotate-left"></i>&nbsp;&nbsp;<?php echo _("ROTATE LEFT"); ?></button>
                            </div>
                            <div id="btn_rotate_image_r" class="col-md-6 mb-4 d-none">
                                <button <?php echo ($demo) ? 'disabled':''; ?> onclick="" class="btn btn-block btn-primary"><i class="fa-solid fa-rotate-right"></i>&nbsp;&nbsp;<?php echo _("ROTATE RIGHT"); ?></button>
                            </div>
                            <div id="btn_show_image" class="col-md-12 mb-4 d-none">
                                <button <?php echo ($demo) ? 'disabled':''; ?> onclick="show_image();" class="btn btn-block btn-primary"><i class="fa-solid fa-eye"></i>&nbsp;&nbsp;<?php echo _("SHOW"); ?></button>
                            </div>
                            <div id="btn_delete_image" class="col-md-12 d-none">
                                <button <?php echo ($demo) ? 'disabled':''; ?> onclick="delete_image();" class="btn btn-block btn-danger"><i class="fa-solid fa-trash"></i>&nbsp;&nbsp;<?php echo _("DELETE"); ?></button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-location"></i> <?php echo _("GPS Location"); ?></h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div id="msg_sel_image_2" class="col-md-12">
                                <?php echo _("Select media first!"); ?>
                            </div>
                            <div id="msg_no_image_gps" style="display:none" class="col-md-12">
                                <?php echo _("No GPS location stored into the image."); ?>
                            </div>
                            <div id="image_gps_pos_div" style="display:none" class="col-md-12">
                                <div id="image_gps_pos"></div>
                                <button id="image_gps_pos_btn" onclick="set_marker_position_image();" <?php echo ($demo) ? 'disabled':''; ?> class="btn btn-block btn-primary mt-2"><i class="fa-solid fa-location-arrow"></i>&nbsp;&nbsp;<?php echo _("USE THIS LOCATION FOR MARKER"); ?></button>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="sender_info_card" class="card shadow mb-4" style="display: none;">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-user"></i> <?php echo _("Sender Information"); ?></h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <p class="mb-2"><strong><?php echo _("Name"); ?>:</strong> <span id="sender_name_val"></span></p>
                                <p class="mb-0" id="sender_email_div"><strong><?php echo _("Email"); ?>:</strong> <a id="sender_email_val" href=""></a></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-pane <?php echo ($_SESSION['tab_marker']=='extra') ? 'active' : ''; ?>" id="extra_tab">
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-list-alt"></i> <?php echo _("Details"); ?></h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="website"><?php echo _("Website Link"); ?></label>
                                    <input type="text" class="form-control" id="website" value="<?php echo $marker['website']; ?>" />
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="website_caption"><?php echo _("Website Name"); ?></label>
                                    <input type="text" class="form-control" id="website_caption" value="<?php echo $marker['website_caption']; ?>" />
                                </div>
                            </div>
                            <div class="col-md-4">
                                <?php generateAdvancedPhoneInput('phone', _("Phone"), $marker['phone'] ?? '', $map['default_prefix']); ?>
                            </div>
                            <div class="col-md-4">
                                <?php generateAdvancedPhoneInput('whatsapp', _("Whatsapp"), $marker['whatsapp'] ?? '',$map['default_prefix']); ?>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="email"><?php echo _("E-mail"); ?></label>
                                    <input type="text" class="form-control" id="email" value="<?php echo $marker['email']; ?>" />
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="hours"><?php echo _("Hours"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'hours_div'); ?>
                                    <div><div id="hours_div"><?php echo $marker['hours']; ?></div></div>
                                    <?php foreach ($array_languages as $lang) {
                                        if($lang!=$default_language) : ?>
                                            <div style="display:none;"><div id="hours_div_<?php echo $lang; ?>" class="input_lang" data-target-id="hours_div" data-lang="<?php echo $lang; ?>"><?php echo $array_input_lang[$lang]['hours']; ?></div></div>
                                        <?php endif;
                                    } ?>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="description"><?php echo _("Description"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'description_div'); ?>
                                    <div><div id="description_div"><?php echo $marker['description']; ?></div></div>
                                    <?php foreach ($array_languages as $lang) {
                                        if($lang!=$default_language) : ?>
                                            <div style="display:none;"><div id="description_div_<?php echo $lang; ?>" class="input_lang" data-target-id="description_div" data-lang="<?php echo $lang; ?>"><?php echo $array_input_lang[$lang]['description']; ?></div></div>
                                        <?php endif;
                                    } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-circle"></i> <?php echo _("Extra Button / Content"); ?></h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label><?php echo _("Open directly"); ?></label> <i title="<?php echo _("open this content when clicking on the marker instead of the detail window"); ?>" class="help_t fas fa-question-circle"></i><br>
                                            <input <?php echo ($marker['open_extra_content']) ? 'checked' : '' ; ?> type="checkbox" id="open_extra_content" />
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label><?php echo _("Button Icon"); ?></label><br>
                                            <button class="btn btn-sm btn-primary" type="button" id="GetIconPicker_b1" data-iconpicker-input="input#marker_icon_input_b1" data-iconpicker-preview="i#marker_icon_b1"><?php echo _("Select Icon"); ?></button>
                                            <input readonly type="text" id="marker_icon_input_b1" name="Icon" value="<?php echo $marker['extra_button_icon_1']; ?>" required="" placeholder="" autocomplete="off" spellcheck="false">
                                            <div class="icon-preview d-inline-block ml-1" data-toggle="tooltip" title="">
                                                <i id="marker_icon_b1" class="<?php echo $marker['extra_button_icon_1']; ?>"></i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <label for="extra_button_title_1"><?php echo _("Button Title"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'extra_button_title_1'); ?>
                                            <input type="text" class="form-control" id="extra_button_title_1" value="<?php echo $marker['extra_button_title_1']; ?>" />
                                            <?php foreach ($array_languages as $lang) {
                                                if($lang!=$default_language) : ?>
                                                    <input style="display:none;" type="text" class="form-control input_lang" data-target-id="extra_button_title_1" data-lang="<?php echo $lang; ?>" value="<?php echo $array_input_lang[$lang]['extra_button_title_1']; ?>" />
                                                <?php endif;
                                            } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="extra_button_value_1"><?php echo _("Custom Content"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'extra_button_value_1'); ?>&nbsp;&nbsp;&nbsp;<br><span onclick="open_modal_content('extra_button_value_1','link2');" style="cursor:pointer;" class="badge badge-primary"><i class="fas fa-plus"></i> <?php echo _("link"); ?></span> <span onclick="open_modal_content('extra_button_value_1','embed_link');" style="cursor:pointer;" class="badge badge-primary"><i class="fas fa-plus"></i> <?php echo _("embed link"); ?></span> <span onclick="open_modal_content('extra_button_value_1','text');" style="cursor:pointer;" class="badge badge-primary"><i class="fas fa-plus"></i> <?php echo _("text"); ?></span>
                                    <div><div id="extra_button_value_1"><?php echo htmlspecialchars(str_replace('\"','"',str_replace("<br>","\n",$marker["extra_button_value_1"]))); ?></div></div>
                                    <?php foreach ($array_languages as $lang) {
                                        if($lang!=$default_language) : ?>
                                            <div style="display:none;"><div id="extra_button_value_1_<?php echo $lang; ?>" type="text" class="input_lang" data-target-id="extra_button_value_1" data-lang="<?php echo $lang; ?>"><?php echo htmlspecialchars(str_replace('\"','"',str_replace("<br>","\n",$array_input_lang[$lang]['extra_button_value_1']))); ?></div></div>
                                        <?php endif;
                                    } ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="card shadow mb-4">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary"><i class="fab fa-wpforms"></i> <?php echo _("Extra Fields"); ?></h6>
                    </div>
                    <div class="card-body">
                        <?php
                        for($i=1;$i<=20;$i++) { ?>
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label><?php echo _("Field"); ?> <?php echo $i; ?> - <?php echo _("Visible"); ?></label><br>
                                                <input type="checkbox" id="extra_field_visible_<?php echo $i; ?>" <?php echo ($marker['extra_field_visible_'.$i]) ? 'checked' : ''; ?>>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label><?php echo _("Field"); ?> <?php echo $i; ?> - <?php echo _("Icon"); ?></label><br>
                                                <button class="btn btn-sm btn-primary field_icon_picker" type="button" id="GetIconPicker_e<?php echo $i; ?>" data-iconpicker-input="input#marker_icon_input_e<?php echo $i; ?>" data-iconpicker-preview="i#marker_icon_e<?php echo $i; ?>"><?php echo _("Select Icon"); ?></button>
                                                <input readonly type="text" id="marker_icon_input_e<?php echo $i; ?>" name="Icon" value="<?php echo $marker['extra_field_icon_'.$i]; ?>" required="" placeholder="" autocomplete="off" spellcheck="false">
                                                <div class="icon-preview d-inline-block ml-1" data-toggle="tooltip" title="">
                                                    <i id="marker_icon_e<?php echo $i; ?>" class="<?php echo $marker['extra_field_icon_'.$i]; ?>"></i>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-12">
                                            <div class="form-group">
                                                <label><?php echo _("Field"); ?> <?php echo $i; ?> - <?php echo _("Name"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'extra_field_name_'.$i); ?><br>
                                                <input type="text" class="form-control" id="extra_field_name_<?php echo $i; ?>" value="<?php echo $marker['extra_field_name_'.$i]; ?>"" placeholder="<?php echo (array_key_exists($i,$default_am_placeholders)) ? $default_am_placeholders[$i] : ''; ?>">
                                                <?php foreach ($array_languages as $lang) {
                                                    if($lang!=$default_language) : ?>
                                                        <input style="display:none;" type="text" class="form-control input_lang" data-target-id="extra_field_name_<?php echo $i; ?>" data-lang="<?php echo $lang; ?>" value="<?php echo $array_input_lang[$lang]['extra_field_name_'.$i]; ?>" />
                                                    <?php endif;
                                                } ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="extra_field_value_<?php echo $i; ?>"><?php echo _("Field"); ?> <?php echo $i; ?> - <?php echo _("Value"); ?></label><?php echo print_language_input_selector($array_languages,$default_language,'extra_field_value_'.$i); ?>&nbsp;&nbsp;&nbsp;<br><span onclick="open_modal_content('<?php echo $i; ?>','link');" style="cursor:pointer;" class="badge badge-primary"><i class="fas fa-plus"></i> <?php echo _("link"); ?></span> <span onclick="open_modal_content('<?php echo $i; ?>','download');" style="cursor:pointer;" class="badge badge-primary"><i class="fas fa-plus"></i> <?php echo _("download"); ?></span> <span onclick="open_modal_content('<?php echo $i; ?>','text');" style="cursor:pointer;" class="badge badge-primary"><i class="fas fa-plus"></i> <?php echo _("text"); ?></span>
                                        <div><div class="extra_field_value" id="extra_field_value_<?php echo $i; ?>"><?php echo htmlspecialchars(str_replace('\"','"',str_replace("<br>","\n",$marker["extra_field_value_$i"]))); ?></div></div>
                                        <?php foreach ($array_languages as $lang) {
                                            if($lang!=$default_language) : ?>
                                                <div style="display:none;"><div id="extra_field_value_<?php echo $i; ?>_<?php echo $lang; ?>" class="extra_field_value_lang input_lang" data-target-id="extra_field_value_<?php echo $i; ?>" data-lang="<?php echo $lang; ?>"><?php echo htmlspecialchars(str_replace('\"','"',str_replace("<br>","\n",$array_input_lang[$lang]['extra_field_value_'.$i]))); ?></div></div>
                                            <?php endif;
                                        } ?>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="modal_library_icons" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Library Icons"); ?></h5>
            </div>
            <div class="modal-body">
                <?php echo get_library_icons($id_map); ?>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_content_link" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_link_name"><?php echo _("Link Text"); ?></label>
                            <input type="text" class="form-control" id="content_link_name" />
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_link"><?php echo _("URL"); ?></label>
                            <input type="text" class="form-control" id="content_link" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success"><?php echo _("Insert"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_content_link2" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_link2"><?php echo _("URL"); ?></label>
                            <input type="text" class="form-control" id="content_link2" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success"><?php echo _("Insert"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_content_embed_link" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_embed_link"><?php echo _("URL"); ?></label>
                            <input type="text" class="form-control" id="content_embed_link" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success"><?php echo _("Insert"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_content_text" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_text"><?php echo _("Text"); ?></label>
                            <div id="content_text"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success"><?php echo _("Insert"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_content_download" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_download_name"><?php echo _("Link Text"); ?></label>
                            <input type="text" class="form-control" id="content_download_name" />
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_download"><?php echo _("File"); ?></label>
                            <form id="frm_d" action="ajax/upload_file.php" method="POST" enctype="multipart/form-data">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <input type="file" class="form-control" id="txtFile_d" name="txtFile_d" />
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <input <?php echo ($demo) ? 'disabled':''; ?> type="submit" class="btn btn-block btn-success" id="btnUpload_d" value="<?php echo _("Upload File"); ?>" />
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="preview text-center">
                                            <div class="progress mb-3 mb-sm-3 mb-lg-0 mb-xl-0" style="height: 2.35rem;display: none">
                                                <div class="progress-bar" id="progressBar_d" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width:0%;">
                                                    0%
                                                </div>
                                            </div>
                                            <div style="display: none;padding: .38rem;" class="alert alert-danger" id="error_d"></div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="content_download_link"><?php echo _("URL"); ?></label>
                            <input type="text" class="form-control" id="content_download_link" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success"><?php echo _("Insert"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_qrcode" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("QR Code"); ?></h5>
            </div>
            <div class="modal-body text-center">
                <i class="fas fa-spin fa-spinner"></i>
                <img style="width: 100%;" src="" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fas fa-times"></i> <?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="tripadvisor_modal" tabindex="-1" role="dialog" aria-labelledby="tripadvisor_modal_label" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="tripadvisor_modal_label">Tripadvisor - <?php echo _("Search Location"); ?></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <input type="text" id="tripadvisor_query" class="form-control" placeholder="<?php echo _("Name"); ?>" />
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-6">
                        <input type="text" id="tripadvisor_lat" class="form-control" placeholder="<?php echo _("Latitude"); ?>" />
                    </div>
                    <div class="col-md-6">
                        <input type="text" id="tripadvisor_lng" class="form-control" placeholder="<?php echo _("Longitude"); ?>" />
                    </div>
                </div>
                <button <?php echo ($demo) ? 'disabled':''; ?> class="btn btn-primary mt-2" onclick="tripadvisor_search()"><i class="fas fa-search"></i> <?php echo _("Search"); ?></button>
                <ul id="tripadvisor_results" class="list-group mt-2"></ul>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="tripadvisor_info_modal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">Tripadvisor - <?php echo _("Location Info"); ?></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body" id="tripadvisor_info_modal_body">
                <div id="tripadvisor_info_error" class="alert alert-danger d-none"></div>
                <div id="tripadvisor_info_wrapper">
                    <p><strong><?php echo _("Name"); ?>:</strong> <span id="tripadvisor_info_name"></span></p>
                    <p><strong><?php echo _("Address"); ?>:</strong> <span id="tripadvisor_info_address"></span></p>
                    <p><strong><?php echo _("Rating"); ?>:</strong> <span id="tripadvisor_info_rating"></span></p>
                    <p><strong><?php echo _("Reviews"); ?>:</strong> <span id="tripadvisor_info_reviews"></span></p>
                    <p><strong><?php echo _("Link"); ?>:</strong> <span id="tripadvisor_info_link"></span></p>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="modal_delete_marker" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Delete Marker"); ?></h5>
            </div>
            <div class="modal-body">
                <p><?php echo _("Are you sure you want to delete the marker?"); ?></p>
            </div>
            <div class="modal-footer">
                <button <?php echo ($demo) ? 'disabled':''; ?> id="btn_delete_marker" onclick="delete_marker(<?php echo $id_marker; ?>);" type="button" class="btn btn-danger"><?php echo _("Yes, Delete"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_add_video_link" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Add Video Link"); ?></h5>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="video_link_input"><?php echo _("YouTube / Vimeo URL"); ?></label>
                    <input type="text" class="form-control" id="video_link_input" placeholder="https://..." />
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" onclick="add_video_link();"><?php echo _("Add"); ?></button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_media_library" class="modal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog" style="width: 90% !important; max-width: 90% !important; margin: 0 auto !important;" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Media Library"); ?></h5>
            </div>
            <div class="modal-body"></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fas fa-times"></i> <?php echo _("Close"); ?></button>
            </div>
        </div>
    </div>
</div>

<div id="modal_preview_media" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-xl modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo _("Media Preview"); ?></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body text-center p-0" style="background: #000;">
            </div>
        </div>
    </div>
</div>

<script>
    (function($) {
        "use strict";
        Dropzone.autoDiscover = false;
        window.id_map = <?php echo $map['id']; ?>;
        window.id_marker = <?php echo $id_marker; ?>;
        window.marker_need_save = false;
        window.new_marker = <?php echo (empty($marker['lat']) || empty($marker['lon']) ? 1 : 0); ?>;
        window.lon_marker = '<?php echo (empty($marker['lon']) ? $center_lat_lon[1] : $marker['lon']); ?>';
        window.lat_marker = '<?php echo (empty($marker['lat']) ? $center_lat_lon[0] : $marker['lat']); ?>';
        window.color_hex_spectrum = null;
        window.icon_color_hex_spectrum = null;
        window.color_hex_hover_spectrum = null;
        window.icon_color_hex_hover_spectrum = null;
        window.geofence_color_spectrum = null;
        window.description_editor = null;
        window.hours_editor = null;
        window.description_editor_lang = [];
        window.hours_editor_lang = [];
        window.default_marker_size = <?php echo $map['markers_size']; ?>;
        window.editor_html_extra_fields = [];
        window.editor_html_extra_fields_langs = [];
        window.editor_html_extra_button_1 = null;
        window.editor_html_extra_button_1_langs = [];
        window.content_text_editor = null;
        window.popup_background_spectrum = null;
        window.popup_color_spectrum = null;
        window.enable_map_street = <?php echo ($map['enable_map_street']) ? 1 : 0; ?>;
        window.enable_map_satellite = <?php echo ($map['enable_map_satellite']) ? 1 : 0; ?>;
        window.default_view = '<?php echo $map['default_view']; ?>';
        window.map_style = '<?php echo $map['map_style']; ?>';
        window.window.openfreemap_street_url = '<?php echo $map['window.openfreemap_street_url']; ?>';
        window.map_style_satellite = '<?php echo $map['map_style_satellite']; ?>';
        window.street_maxzoom = <?php echo $map['street_maxzoom']; ?>;
        window.satellite_maxzoom = <?php echo $map['satellite_maxzoom']; ?>;
        window.street_basemap = '<?php echo $map['street_basemap']; ?>';
        window.satellite_basemap = '<?php echo $map['satellite_basemap']; ?>';
        window.maptiler_api = '<?php echo $map['maptiler_api']; ?>';
        window.maptiler_api_satellite = '<?php echo $map['maptiler_api_satellite']; ?>';
        window.here_api = '<?php echo $map['here_api']; ?>';
        window.here_api_satellite = '<?php echo $map['here_api_satellite']; ?>';
        window.here_lang = '<?php echo $map['here_lang']; ?>';
        window.here_lang_satellite = '<?php echo $map['here_lang_satellite']; ?>';
        window.google_api = '<?php echo $map['google_api']; ?>';
        window.google_api_satellite = '<?php echo $map['google_api_satellite']; ?>';
        window.google_lang = '<?php echo $map['google_lang']; ?>';
        window.google_lang_satellite = '<?php echo $map['google_lang_satellite']; ?>';
        window.map_street_provider = '<?php echo $map['map_street_provider']; ?>';
        window.map_satellite_provider = '<?php echo $map['map_satellite_provider']; ?>';
        window.schedule = `<?php echo $marker['schedule']; ?>`;
        window.schedule_box_warning = `<?php echo $marker['schedule_box_warning']; ?>`;
        window.saved_geometries = `<?php echo $map['draw_geometries']; ?>`;
        window.geoJSON = '<?php echo $map['geoJSON']; ?>';
        window.song = '<?php echo $marker['song']; ?>';
        window.geocoding_provider = '<?php echo $settings['geocoding_provider']; ?>';
        var DirectionAttribute = Quill.import('attributors/attribute/direction');
        Quill.register(DirectionAttribute,true);
        var AlignClass = Quill.import('attributors/class/align');
        Quill.register(AlignClass,true);
        var BackgroundClass = Quill.import('attributors/class/background');
        Quill.register(BackgroundClass,true);
        var ColorClass = Quill.import('attributors/class/color');
        Quill.register(ColorClass,true);
        var DirectionClass = Quill.import('attributors/class/direction');
        Quill.register(DirectionClass,true);
        var FontClass = Quill.import('attributors/class/font');
        Quill.register(FontClass,true);
        var SizeClass = Quill.import('attributors/class/size');
        Quill.register(SizeClass,true);
        var AlignStyle = Quill.import('attributors/style/align');
        Quill.register(AlignStyle,true);
        var BackgroundStyle = Quill.import('attributors/style/background');
        Quill.register(BackgroundStyle,true);
        var ColorStyle = Quill.import('attributors/style/color');
        Quill.register(ColorStyle,true);
        var DirectionStyle = Quill.import('attributors/style/direction');
        Quill.register(DirectionStyle,true);
        var FontStyle = Quill.import('attributors/style/font');
        Quill.register(FontStyle,true);
        var SizeStyle = Quill.import('attributors/style/size');
        SizeStyle.whitelist = ['12px','14px','16px','18px','20px','22px'];
        Quill.register(SizeStyle,true);
        var LinkFormats = Quill.import("formats/link");
        Quill.register(LinkFormats,true);
        window.marker_images_uploaded = 0;
        window.marker_image_max = <?php echo $map['marker_images_num']; ?>;
        var marker_name = `<?php echo $marker['name']; ?>`;
        $('#subtitle_header').html(marker_name);
        $(document).ready(function () {
            bsCustomFileInput.init();
            $('.help_t').tooltip();
            $('.cpy_btn').tooltip({
                trigger: 'click',
                placement: 'bottom'
            });
            new ClipboardJS('.btn_link');
            var clipboard = new ClipboardJS('.cpy_btn');
            clipboard.on('success', function(e) {
                setTooltip(e.trigger, window.backend_labels.copied+"!");
                hideTooltip(e.trigger);
            });
            $('.tooltip_arrows').tooltipster({
                delay: 10,
                hideOnClick: true
            });
            for(var i=1; i<=20; i++) {
                window.editor_html_extra_fields[i] = ace.edit('extra_field_value_'+i);
                window.editor_html_extra_fields[i].session.setMode("ace/mode/html");
                window.editor_html_extra_fields[i].session.setUseWrapMode(true);
                window.editor_html_extra_fields[i].session.setOption('indentedSoftWrap', false);
                window.editor_html_extra_fields[i].setOption('enableLiveAutocompletion',true);
                window.editor_html_extra_fields[i].setShowPrintMargin(false);
                if($('body').hasClass('dark_mode')) {
                    window.editor_html_extra_fields[i].setTheme("ace/theme/one_dark");
                }
                if(window.rtl==1) {
                    window.editor_html_extra_fields[i].setOption("rtl", true);
                }
            }
            window.editor_html_extra_button_1 = ace.edit('extra_button_value_1');
            window.editor_html_extra_button_1.session.setMode("ace/mode/html");
            window.editor_html_extra_button_1.session.setUseWrapMode(true);
            window.editor_html_extra_button_1.session.setOption('indentedSoftWrap', false);
            window.editor_html_extra_button_1.setOption('enableLiveAutocompletion',true);
            window.editor_html_extra_button_1.setShowPrintMargin(false);
            if($('body').hasClass('dark_mode')) {
                window.editor_html_extra_button_1.setTheme("ace/theme/one_dark");
            }
            if(window.rtl==1) {
                window.editor_html_extra_button_1.setOption("rtl", true);
            }
            var toolbarOptions = [
                ['bold', 'italic', 'underline', 'strike'],
                [{ 'size': ['12px','14px','16px','18px','20px','22px'] }],
                [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                [{ 'color': [] }, { 'background': [] }],
                [{ 'align': [] }],['link'],['image'],
                ['clean']
            ];
            hours_editor = new Quill('#hours_div', {
                modules: {
                    toolbar: toolbarOptions
                },
                theme: 'snow'
            });
            description_editor = new Quill('#description_div', {
                modules: {
                    toolbar: toolbarOptions
                },
                theme: 'snow'
            });
            content_text_editor = new Quill('#content_text', {
                modules: {
                    toolbar: toolbarOptions
                },
                theme: 'snow'
            });
            IconPicker.Init({
                jsonUrl: 'vendor/iconpicker/iconpicker-7.2.0.json',
                searchPlaceholder: '<?php echo _("Search Icon"); ?>',
                showAllButton: '<?php echo _("Show All"); ?>',
                cancelButton: '<?php echo _("Cancel"); ?>',
                noResultsFound: '<?php echo _("No results found."); ?>',
                borderRadius: '20px',
            });
            IconPicker.Run('#GetIconPicker', function(){
                $('#btn_delete_icon').prop('disabled',false);
                setTimeout(function () {
                    change_style_marker();
                },250);
                window.marker_need_save = true;
            });
            IconPicker.Run('.field_icon_picker', function(){
                window.marker_need_save = true;
            });
            IconPicker.Run('#GetIconPicker_b1', function(){
                window.marker_need_save = true;
            });
            window.color_hex_spectrum = $('#color_hex').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.icon_color_hex_spectrum = $('#icon_color_hex').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.color_hex_hover_spectrum = $('#color_hex_hover').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.icon_color_hex_hover_spectrum = $('#icon_color_hex_hover').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.geofence_color_spectrum = $('#geofence_color').spectrum({
                type: "text",
                preferredFormat: "rgb",
                showAlpha: true,
                showButtons: false,
                allowEmpty: false
            });
            window.popup_background_spectrum = $('#popup_background').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            window.popup_color_spectrum = $('#popup_color').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            $("#color_hex").on('move.spectrum', function(e, color) {
                change_style_marker();
            });
            $("#icon_color_hex").on('move.spectrum', function(e, color) {
                change_style_marker();
            });
            $("#geofence_color").on('move.spectrum', function(e, color) {
                draw_geofence();
            });
            $('#icon_label_color').spectrum({
                type: "text",
                preferredFormat: "hex",
                showAlpha: false,
                showButtons: false,
                allowEmpty: true
            });
            $("#icon_label_color").on('move.spectrum', function(e, color) {
                change_style_marker();
            });
            var gallery_dropzone = new Dropzone("#gallery-dropzone", {
                url: "ajax/upload_marker_image.php",
                parallelUploads: 1,
                <?php if($map['marker_images_num']>=0) : ?>
                maxFiles: <?php echo $map['marker_images_num']; ?>,
                <?php endif; ?>
                maxFilesize: 20,
                timeout: 120000,
                dictDefaultMessage: `<?php echo _("Drop files or click here to upload"); ?>`,
                dictFallbackMessage: `<?php echo _("Your browser does not support drag'n'drop file uploads."); ?>`,
                dictFallbackText: `<?php echo _("Please use the fallback form below to upload your files like in the olden days."); ?>`,
                dictFileTooBig: `<?php echo sprintf(_("File is too big (%sMiB). Max filesize: %sMiB."),'{{filesize}}','{{maxFilesize}}'); ?>`,
                dictInvalidFileType: `<?php echo _("You can't upload files of this type."); ?>`,
                dictResponseError: `<?php echo sprintf(_("Server responded with %s code."),'{{statusCode}}'); ?>`,
                dictCancelUpload: `<?php echo _("Cancel upload"); ?>`,
                dictCancelUploadConfirmation: `<?php echo _("Are you sure you want to cancel this upload?"); ?>`,
                dictRemoveFile: `<?php echo _("Remove file"); ?>`,
                dictMaxFilesExceeded: `<?php echo _("You can not upload any more files."); ?>`,
                acceptedFiles: '.jpeg,.jpg,.png,.webp,.gif,.mp4,.mov,.webm',
            });
            gallery_dropzone.on("addedfile", function(file) {
                $('#image_list').addClass('disabled');
                $('#image_others_btn').addClass('disabled');
            });
            gallery_dropzone.on("success", function(file,json) {
                var rsp = JSON.parse(json);
                if(rsp.success) {
                    marker_images_uploaded++;
                    var count_images = $('#image_gallery a[data-main="1"]').length;
                    if(count_images==0) {
                        var main = '1';
                        var icon_main = '<i style="display:block;" class="fas fa-star"></i>';
                        $("#image_gallery a i.fa-star").hide();
                    } else {
                        var main = '0';
                        var icon_main = '<i style="display:none;" class="fas fa-star"></i>';
                    }
                    var gps = rsp.gps;
                    if(gps!==null) {
                        var lat = gps.lat;
                        var lon = gps.lon;
                        var icon_gps = '<i style="display:block;" class="fas fa-location"></i>';
                    } else {
                        var lat = '';
                        var lon = '';
                        var icon_gps = '<i style="display:none;" class="fas fa-location"></i>';
                    }
                    var type = getMediaType(rsp.filename);
                    switch(type) {
                        case 'image':
                            $('#image_gallery').append("<a data-id='0' data-lat='"+lat+"' data-lon='"+lon+"' data-exclude='0' data-action='insert' data-image='"+rsp.filename+"' data-main='"+main+"' href='#'><i class=\"fa-solid fa-image\"></i>"+icon_main+icon_gps+"<img src='../viewer/marker_images/thumb/"+rsp.filename+"'/></a>");
                            break;
                        case 'video':
                            $('#image_gallery').append("<a data-id='0' data-lat='"+lat+"' data-lon='"+lon+"' data-exclude='0' data-action='insert' data-image='"+rsp.filename+"' data-main='"+main+"' href='#'><i class=\"fa-solid fa-video\"></i>"+icon_main+icon_gps+"<video muted src='../viewer/marker_images/"+rsp.filename+"#t=2'/></a>");
                            break;
                    }
                    var el = document.getElementById('image_gallery');
                    Sortable.create(el);
                    $('#image_gallery a').on('click',function () {
                        event.preventDefault();
                        select_image($(this));
                    });
                    window.marker_need_save = true;
                }
            });
            gallery_dropzone.on("queuecomplete", function() {
                if(marker_image_max!=-1) {
                    if(marker_images_uploaded>=marker_image_max) {
                        $('#gallery-dropzone').addClass('disabled');
                    }
                    $('#gallery-dropzone')[0].dropzone.options.maxFiles = marker_image_max-marker_images_uploaded;
                }
                $('#image_list').removeClass('disabled');
                $('#image_others_btn').removeClass('disabled');
                gallery_dropzone.removeAllFiles();
            });
            var schedule = window.schedule;
            var schedule_box = window.schedule_box_warning;
            if(schedule!='' && schedule!=null) {
                schedule = JSON.parse(schedule);
                $('#enable_schedule').prop('checked',true);
                $('#date_from').val(schedule.from_date);
                $('#date_to').val(schedule.to_date);
                $("#ignore_year").prop('checked',(schedule.ignore_year || 0) == 1);
                $('#hour_from').val(schedule.from_hour);
                $('#hour_to').val(schedule.to_hour);
                var days = schedule.days;
                var days_array = days.split(",");
                if(days_array[0]==1) $("#days_1").prop('checked',true); else $("#days_1").prop('checked',false);
                if(days_array[1]==1) $("#days_2").prop('checked',true); else $("#days_2").prop('checked',false);
                if(days_array[2]==1) $("#days_3").prop('checked',true); else $("#days_3").prop('checked',false);
                if(days_array[3]==1) $("#days_4").prop('checked',true); else $("#days_4").prop('checked',false);
                if(days_array[4]==1) $("#days_5").prop('checked',true); else $("#days_5").prop('checked',false);
                if(days_array[5]==1) $("#days_6").prop('checked',true); else $("#days_6").prop('checked',false);
                if(days_array[6]==1) $("#days_7").prop('checked',true); else $("#days_7").prop('checked',false);
                $('#schedule_content').removeClass('disabled');
            } else {
                $('#enable_schedule').prop('checked',false);
                $('#date_from').val('');
                $('#date_to').val('');
                $("#ignore_year").prop('checked',false);
                $('#hour_from').val('');
                $('#hour_to').val('');
                $("#days_1").prop('checked',false);
                $("#days_2").prop('checked',false);
                $("#days_3").prop('checked',false);
                $("#days_4").prop('checked',false);
                $("#days_5").prop('checked',false);
                $("#days_6").prop('checked',false);
                $("#days_7").prop('checked',false);
            }
            if(schedule_box!='' && schedule_box!=null) {
                schedule_box = JSON.parse(schedule_box);
                $('#enable_schedule_box').prop('checked',true);
                $('#date_from_box').val(schedule_box.from_date);
                $('#date_to_box').val(schedule_box.to_date);
                $("#ignore_year_box").prop('checked',(schedule_box.ignore_year || 0) == 1);
                $('#hour_from_box').val(schedule_box.from_hour);
                $('#hour_to_box').val(schedule_box.to_hour);
                var days = schedule_box.days;
                var days_array = days.split(",");
                if(days_array[0]==1) $("#days_1_box").prop('checked',true); else $("#days_1_box").prop('checked',false);
                if(days_array[1]==1) $("#days_2_box").prop('checked',true); else $("#days_2_box").prop('checked',false);
                if(days_array[2]==1) $("#days_3_box").prop('checked',true); else $("#days_3_box").prop('checked',false);
                if(days_array[3]==1) $("#days_4_box").prop('checked',true); else $("#days_4_box").prop('checked',false);
                if(days_array[4]==1) $("#days_5_box").prop('checked',true); else $("#days_5_box").prop('checked',false);
                if(days_array[5]==1) $("#days_6_box").prop('checked',true); else $("#days_6_box").prop('checked',false);
                if(days_array[6]==1) $("#days_7_box").prop('checked',true); else $("#days_7_box").prop('checked',false);
                $('#schedule_content_box').removeClass('disabled');
            } else {
                $('#enable_schedule_box').prop('checked',false);
                $('#date_from_box').val('');
                $('#date_to_box').val('');
                $("#ignore_year_box").prop('checked',false);
                $('#hour_from_box').val('');
                $('#hour_to_box').val('');
                $("#days_1_box").prop('checked',false);
                $("#days_2_box").prop('checked',false);
                $("#days_3_box").prop('checked',false);
                $("#days_4_box").prop('checked',false);
                $("#days_5_box").prop('checked',false);
                $("#days_6_box").prop('checked',false);
                $("#days_7_box").prop('checked',false);
            }
            if(window.song=='') {
                $('#div_delete_song').hide();
                $('#div_player_song').hide();
                $('#div_upload_song').show();
            } else {
                $('#div_delete_song').show();
                $('#div_player_song').show();
                $('#div_upload_song').hide();
            }
            get_marker_images(window.id_marker);
            if(window.new_marker==1) {
                initialize_map_marker(window.lon_marker,window.lat_marker,'add');
            } else {
                initialize_map_marker(window.lon_marker,window.lat_marker,'edit');
            }
            var update_embed_code = function() {
                var is_responsive = $('#embed_type').val() === 'responsive';
                var w, h, r;

                if (is_responsive) {
                    w = $('#embed_max_width').val() || '100%';
                    h = 'auto';
                    r = $('#embed_ratio').val() || '16/9';
                } else {
                    w = $('#embed_width').val() || '100%';
                    h = $('#embed_height').val() || '600px';
                    r = 'none';
                }

                var update_iframe_string = function(iframe_str) {
                    if (!iframe_str) return '';
                    var $container = $('<div>').html(iframe_str);
                    var $wrapper = $container.children('div').first();

                    if ($wrapper.length === 0) {
                        $wrapper = $container.find('iframe');
                    }

                    $wrapper.css('width', w);

                    if (r === 'none') {
                        $wrapper.css('height', h);
                        $wrapper.css('aspect-ratio', '');
                    } else {
                        $wrapper.css('height', h);
                        $wrapper.css('aspect-ratio', r);
                    }

                    return $container.html().replace(/;\s+/g, ';').replace(/:\s+/g, ':').replace(/\s*\/\s*/g, '/');
                };

                var $code = $('#code');
                if ($code.length) {
                    var val = update_iframe_string($code.attr('data-default-value'));
                    $code.attr('data-default-value', val);
                    $code.val(val);
                }

                $('.input_lang[data-target-id="code"]').each(function() {
                    var val_lang = update_iframe_string($(this).attr('data-default-value'));
                    $(this).attr('data-default-value', val_lang);
                    $(this).val(val_lang);
                });
            };

            $('#embed_type').on('change', function() {
                var is_responsive = $(this).val() === 'responsive';
                if (is_responsive) {
                    $('.embed_responsive_settings').removeClass('d-none');
                    $('.embed_fixed_settings').addClass('d-none');
                } else {
                    $('.embed_responsive_settings').addClass('d-none');
                    $('.embed_fixed_settings').removeClass('d-none');
                }
                update_embed_code();
            });

            $('#embed_width, #embed_height, #embed_ratio, #embed_max_width').on('input change', function() {
                update_embed_code();
            });
        });

        $(document).on('click', '.input_lang', function() {
            var elem = $(this).attr('data-target-id');
            var lang = $(this).attr('data-lang');
            var id = $(this).attr('id');
            if (!elem) return;
            var is_ace = elem.startsWith('extra_field_value_') || elem === 'extra_button_value_1';
            var is_quill = elem === 'hours_div' || elem === 'description_div';
            if ((is_ace || is_quill) && typeof window.init_lazy_editor === 'function') {
                window.init_lazy_editor(elem, lang, id);
            }
        });

        $('#tripadvisor_modal').on('show.bs.modal', function () {
            var lat = $('#latitude_edit').val();
            var lon = $('#longitude_edit').val();
            var name = $('#name').val();
            $('#tripadvisor_query').val(name);
            $('#tripadvisor_lat').val(lat);
            $('#tripadvisor_lng').val(lon);
            $('#tripadvisor_results').empty();
        });

        $('body').on('submit','#frm_d',function(e){
            e.preventDefault();
            $('#error_d').hide();
            var url = $(this).attr('action');
            var frm = $(this);
            var data = new FormData();
            if(frm.find('#txtFile_d[type="file"]').length === 1 ){
                data.append('file', frm.find( '#txtFile_d' )[0].files[0]);
            }
            var ajax  = new XMLHttpRequest();
            ajax.upload.addEventListener('progress',function(evt){
                var percentage = (evt.loaded/evt.total)*100;
                upadte_progressbar_d(Math.round(percentage));
            },false);
            ajax.addEventListener('load',function(evt){
                if(evt.target.responseText.toLowerCase().indexOf('error')>=0){
                    show_error_d(evt.target.responseText);
                } else {
                    if(evt.target.responseText!='') {
                        $('#content_download_link').val('content/'+evt.target.responseText);
                    }
                }
                upadte_progressbar_d(0);
                frm[0].reset();
            },false);
            ajax.addEventListener('error',function(evt){
                show_error_d('upload failed');
                upadte_progressbar_d(0);
            },false);
            ajax.addEventListener('abort',function(evt){
                show_error_d('upload aborted');
                upadte_progressbar_d(0);
            },false);
            ajax.open('POST',url);
            ajax.send(data);
            return false;
        });

        function upadte_progressbar_d(value){
            $('#progressBar_d').css('width',value+'%').html(value+'%');
            if(value==0){
                $('.progress').hide();
            }else{
                $('.progress').show();
            }
        }

        function show_error_d(error){
            $('.progress').hide();
            $('#error_d').show();
            $('#error_d').html(error);
        }

        $('body').on('submit','#frm_s',function(e){
            e.preventDefault();
            $('#error_s').hide();
            var url = $(this).attr('action');
            var frm = $(this);
            var data = new FormData();
            if(frm.find('#txtFile_s[type="file"]').length === 1 ){
                data.append('file', frm.find( '#txtFile_s' )[0].files[0]);
            }
            var ajax  = new XMLHttpRequest();
            ajax.upload.addEventListener('progress',function(evt){
                var percentage = (evt.loaded/evt.total)*100;
                upadte_progressbar_s(Math.round(percentage));
            },false);
            ajax.addEventListener('load',function(evt){
                if(evt.target.responseText.toLowerCase().indexOf('error')>=0){
                    show_error_s(evt.target.responseText);
                } else {
                    if(evt.target.responseText!='') {
                        window.marker_need_save = true;
                        window.song = evt.target.responseText;
                        $('#div_delete_song').show();
                        $('#div_player_song').show();
                        $('#div_upload_song').hide();
                        $('#div_player_song audio').attr('src','../viewer/content/'+window.song);
                    }
                }
                upadte_progressbar_s(0);
                frm[0].reset();
            },false);
            ajax.addEventListener('error',function(evt){
                show_error_s('upload failed');
                upadte_progressbar_s(0);
            },false);
            ajax.addEventListener('abort',function(evt){
                show_error_s('upload aborted');
                upadte_progressbar_s(0);
            },false);
            ajax.open('POST',url);
            ajax.send(data);
            return false;
        });

        function upadte_progressbar_s(value){
            $('#progressBar_s').css('width',value+'%').html(value+'%');
            if(value==0){
                $('.progress').hide();
            }else{
                $('.progress').show();
            }
        }

        function show_error_s(error){
            $('.progress').hide();
            $('#error_s').show();
            $('#error_s').html(error);
        }

        $("input").change(function(){
            window.marker_need_save = true;
        });

        $(window).on('beforeunload', function(){
            if(window.marker_need_save) {
                var c=confirm();
                if(c) return true; else return false;
            }
        });
    })(jQuery);
</script>
