<?php /* Smarty version 2.6.26, created on 2017-04-06 08:06:37
         compiled from /home3/bargaip4/public_html/gevimmo/plugins/locationFinder/admin/locationFinder.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'cat', '/home3/bargaip4/public_html/gevimmo/plugins/locationFinder/admin/locationFinder.tpl', 5, false),array('modifier', 'replace', '/home3/bargaip4/public_html/gevimmo/plugins/locationFinder/admin/locationFinder.tpl', 66, false),array('modifier', 'regex_replace', '/home3/bargaip4/public_html/gevimmo/plugins/locationFinder/admin/locationFinder.tpl', 458, false),)), $this); ?>
<!-- location finder admin contoller -->

<?php if ($this->_tpl_vars['db_update']): ?>
    <?php if ($this->_tpl_vars['update_error']): ?>
        <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => ((is_array($_tmp=((is_array($_tmp='blocks')) ? $this->_run_mod_handler('cat', true, $_tmp, @RL_DS) : smarty_modifier_cat($_tmp, @RL_DS)))) ? $this->_run_mod_handler('cat', true, $_tmp, 'm_block_start.tpl') : smarty_modifier_cat($_tmp, 'm_block_start.tpl')), 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

        <div class="lf-instruction">
            <p class="notice"><span class="red">IMPORTANT:</span> We recommend making a back-up of the database so you could easily restore it in case of an import failure.</p>
            <p>To enjoy new capabilities of the geo mapping you should populate your database with new locations using the <b>"Multifield/Location Filter"</b> plugin; to do so please follow the instruction:</p>

            <?php $this->assign('df_phrase_key', 'admin_controllers+name+data_formats'); ?>
            <ul class="list">
                <li>Go to <a target="_blank" href="<?php echo $this->_tpl_vars['rlBase']; ?>
index.php?controller=data_formats"><?php echo $this->_tpl_vars['lang'][$this->_tpl_vars['df_phrase_key']]; ?>
</a> and remove the <b>"Countries"</b> data entry if you have it (Trash Box should be disabled);</li>
                <li>Go to <a target="_blank" href="<?php echo $this->_tpl_vars['rlBase']; ?>
index.php?controller=multi_formats">Multi-field Plugin</a> manager and click the <b>"Add an Entry"</b> buttom at the right top corner;</li>
                <li>Enter the following details in the form:<br />
                - Create as: <b>New data entry</b><br />
                - Key: <b>countries</b><br />
                - Name: <b>Country</b><br />
                - Sorting order: <b>Alphabetic</b><br />
                - Geo Filtering: <b>enable or disable</b><br /> - it's up to you, enable it if you need to filter website listings by visitor location
                - Status: <b>Active</b><br /><br />
                Click the <b>"Add"</b> button;
                </li>
                <li>Find the <b>"Country"</b> data entry and click the <b>"Hammer"</b> icon to manage it;</li>
                <li>Then click the <b>"Import Data"</b> button at the right top corner;</li>
                <li>Find the <b>"World Locations Database5"</b> in a window and click the <b>"Import the entire database"</b> or <b>"Select items to be imported"</b> button;</li>
                <li><a href="<?php echo $this->_tpl_vars['rlBase']; ?>
index.php?controller=<?php echo $_GET['controller']; ?>
&action=update">Reload the page</a> once importing in the previous step is completed;</li>
            </ul>

            Click <a href="<?php echo $this->_tpl_vars['rlBase']; ?>
index.php?controller=<?php echo $_GET['controller']; ?>
&action=update&fix">here</a> if you are sure your current location database is OK and you are ready to import the "geo mapping database".</b>.
        </div>

        <script>
        <?php echo '

        $(document).ready(function(){
            printMessage(\'error\', \''; ?>
<?php echo $this->_tpl_vars['lang']['locationFinder_incompatible_database_error']; ?>
<?php echo '\');
        });

        '; ?>

        </script>

        <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => ((is_array($_tmp=((is_array($_tmp='blocks')) ? $this->_run_mod_handler('cat', true, $_tmp, @RL_DS) : smarty_modifier_cat($_tmp, @RL_DS)))) ? $this->_run_mod_handler('cat', true, $_tmp, 'm_block_end.tpl') : smarty_modifier_cat($_tmp, 'm_block_end.tpl')), 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
    <?php else: ?>
        <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => ((is_array($_tmp=((is_array($_tmp='blocks')) ? $this->_run_mod_handler('cat', true, $_tmp, @RL_DS) : smarty_modifier_cat($_tmp, @RL_DS)))) ? $this->_run_mod_handler('cat', true, $_tmp, 'm_block_start.tpl') : smarty_modifier_cat($_tmp, 'm_block_start.tpl')), 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

        <div class="lf-upload-interface">
            <p>
                <?php if (! $this->_tpl_vars['config']['locationFinder_db_version']): ?>
                    <?php echo $this->_tpl_vars['lang']['locationFinder_remote_install_text']; ?>

                <?php else: ?>
                    <?php echo $this->_tpl_vars['lang']['locationFinder_remote_update_text']; ?>

                <?php endif; ?>
            </p>

            <p style="padding: 10px 0 10px;">
                <span class="red"><b><?php echo $this->_tpl_vars['lang']['notice']; ?>
:</b></span> <?php echo $this->_tpl_vars['lang']['locationFinder_remote_update_notice']; ?>

            </p>

            <?php $this->assign('replace_var', ('{')."percent".('}')); ?>

            <div><input id="install_database" <?php if ($this->_tpl_vars['config']['locationFinder_db_version']): ?>accesskey="update"<?php endif; ?> type="button" value="<?php if (! $this->_tpl_vars['config']['locationFinder_db_version']): ?><?php echo $this->_tpl_vars['lang']['install']; ?>
<?php else: ?><?php echo $this->_tpl_vars['lang']['update']; ?>
<?php endif; ?>" /></div>
            <div class="loading-interface">
                <div class="progress"><?php echo $this->_tpl_vars['lang']['locationFinder_preparing']; ?>
</div>
                <div class="progress-bar"><div></div></div>
                <div class="progress-info"><?php echo ((is_array($_tmp=$this->_tpl_vars['lang']['locationFinder_remote_update_status'])) ? $this->_run_mod_handler('replace', true, $_tmp, $this->_tpl_vars['replace_var'], '<span>0</span>') : smarty_modifier_replace($_tmp, $this->_tpl_vars['replace_var'], '<span>0</span>')); ?>
</div>
                <ul class="progress-error-message red"></ul>
            </div>
        </div>

        <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => ((is_array($_tmp=((is_array($_tmp='blocks')) ? $this->_run_mod_handler('cat', true, $_tmp, @RL_DS) : smarty_modifier_cat($_tmp, @RL_DS)))) ? $this->_run_mod_handler('cat', true, $_tmp, 'm_block_end.tpl') : smarty_modifier_cat($_tmp, 'm_block_end.tpl')), 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

        <script>
        lang['update'] = '<?php echo $this->_tpl_vars['lang']['update']; ?>
';

        <?php echo '

        $(document).ready(function(){
            var loading_interface = $(\'.lf-upload-interface .loading-interface\');
            var progress_bar = loading_interface.find(\'.progress-bar > div\');
            var error_area = loading_interface.find(\'.progress-error-message\');
            var progress_dump = loading_interface.find(\'.progress\');
            var progress_info = loading_interface.find(\'.progress-info > span\');
            var current_file = 1;
            var total_files = 0;
            var in_progress = false;

            $.ajaxSetup({cache: false});

            var locationFinderUploadFile = function(){
                $.post(rlConfig[\'tpl_base\']+\'request.ajax.php\', {item: \'locationFinderUploadFile\', file: current_file}, function(response){
                    if (response.status == \'OK\') {
                        progress_dump.text(lang[\'locationFinder_file_upload_info\'].replace(\'{files}\', total_files).replace(\'{file}\', current_file));
                        locationFinderImport();
                    } else {
                        locationFinderError(response.data);
                    }
                }, \'json\');
            }

            var locationFinderImport = function(){
                $.post(rlConfig[\'tpl_base\']+\'request.ajax.php\', {item: \'locationFinderImport\'}, function(response){
                    if (response[\'error\']) {
                        locationFinderError(Array(response[\'error\']));
                    } else if (response[\'action\'] == \'next_stack\') {
                        locationFinderImport();

                        response[\'progress\'] = response[\'progress\'] > 100 ? 100 : response[\'progress\'];
                        progress_bar.width(response[\'progress\']+\'%\');
                        progress_info.text(response[\'progress\']);
                    } else if (response[\'action\'] == \'next_file\') {
                        current_file++;
                        progress_dump.text(lang[\'locationFinder_file_download_info\'].replace(\'{files}\', total_files).replace(\'{file}\', current_file));

                        locationFinderUploadFile();
                    } else if (response[\'action\'] == \'end\') {
                        progress_bar.width(\'100%\');
                        progress_info.text(100);

                        in_progress = false;
                        printMessage(\'notice\', lang[\'locationFinder_import_completed\']);
                        progress_dump.text(lang[\'locationFinder_import_completed\']);
                    }
                }, \'json\')
            }

            var locationFinderError = function(data){
                for (var i in data) {
                    if (typeof data[i] != \'string\')
                        continue;

                    error_area.append($(\'<li>\').text(data[i]));
                }
                error_area.fadeIn();
                progress_bar.css(\'width\', \'0\');
            }

            $(\'#install_database\').click(function(){
                // update mode
                if ($(this).attr(\'accesskey\') == \'update\') {
                    $(this).val(lang[\'loading\']);
                    var self = this;

                    $.post(rlConfig[\'tpl_base\']+\'request.ajax.php\', {item: \'ipgeoCheckUpdate\'}, function(response){
                        if (response.data == \'NO\') {
                            $(self).val(lang[\'update\']);
                            printMessage(\'notice\', lang[\'locationFinder_db_uptodate\']);
                        } else {
                            $(self).removeAttr(\'accesskey\');
                            $(self).trigger(\'click\');
                        }
                    }, \'json\');
                }
                // import mode
                else {
                    $(this).parent().fadeOut(function(){
                        loading_interface.fadeIn(function(){
                            $.post(rlConfig[\'tpl_base\']+\'request.ajax.php\', {item: \'locationFinderPrepare\'}, function(response){
                                if (response.status == \'OK\') {
                                    in_progress = true;

                                    total_files = response.data.calc;
                                    progress_dump.text(lang[\'locationFinder_file_download_info\'].replace(\'{files}\', total_files).replace(\'{file}\', current_file));
                                    locationFinderUploadFile();
                                } else {
                                    locationFinderError(response.data);
                                }
                            }, \'json\');
                        });
                    });
                }
            });

            $(window).bind(\'beforeunload\', function() {
                if (in_progress) {
                    return \'Uploading the data is in process; closing the page will stop the process.\';
                }
            });
        });

        '; ?>

        </script>
    <?php endif; ?>
<?php else: ?>
    <?php if ($this->_tpl_vars['is_mapping_available']): ?>
    <!-- navigation bar -->
    <div id="nav_bar">
        <a href="<?php echo $this->_tpl_vars['rlBase']; ?>
index.php?controller=<?php echo $_GET['controller']; ?>
&action=update" class="button_bar"><span class="left"></span><span class="center_import"><?php echo $this->_tpl_vars['lang']['locationFinder_update_database']; ?>
</span><span class="right"></span></a>
    </div>
    <!-- navigation bar end -->
    <?php endif; ?>

    <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => ((is_array($_tmp=((is_array($_tmp='blocks')) ? $this->_run_mod_handler('cat', true, $_tmp, @RL_DS) : smarty_modifier_cat($_tmp, @RL_DS)))) ? $this->_run_mod_handler('cat', true, $_tmp, 'm_block_start.tpl') : smarty_modifier_cat($_tmp, 'm_block_start.tpl')), 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

    <?php if ($this->_tpl_vars['is_mapping_available']): ?>
        <?php if ($this->_tpl_vars['fields']): ?>
            <script src="//maps.googleapis.com/maps/api/js?libraries=places<?php if (@RL_LANG_CODE != '' && @RL_LANG_CODE != 'en'): ?>&language=<?php echo @RL_LANG_CODE; ?>
<?php endif; ?><?php if ($this->_tpl_vars['config']['google_map_key']): ?>&key=<?php echo $this->_tpl_vars['config']['google_map_key']; ?>
<?php endif; ?>"></script>
            <script type="text/javascript" src="<?php echo @RL_LIBS_URL; ?>
jquery/jquery.flmap.js"></script>

            <div class="lc-interface clearfix">
                <div>
                    <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => ((is_array($_tmp=((is_array($_tmp='blocks')) ? $this->_run_mod_handler('cat', true, $_tmp, @RL_DS) : smarty_modifier_cat($_tmp, @RL_DS)))) ? $this->_run_mod_handler('cat', true, $_tmp, 'field.tpl') : smarty_modifier_cat($_tmp, 'field.tpl')), 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>

                    <table class="form">
                    <tr>
                        <td style="width: 185px;"></td>
                        <td><input id="edit_button" type="button" value="<?php echo $this->_tpl_vars['lang']['edit']; ?>
" /></td>
                    </tr>
                    </table>
                </div>
                <div>
                    <input id="pac-input" class="hide" type="text" placeholder="<?php echo $this->_tpl_vars['lang']['locationFinder_address_hint']; ?>
">
                    <div id="map"><span class="hint"><?php echo $this->_tpl_vars['lang']['locationFinder_default_map_hint']; ?>
</span></div>
                    <div class="hide" id="save_button"><input type="button" value="<?php echo $this->_tpl_vars['lang']['save']; ?>
" /></div>
                </div>
            </div>

            <script>
            var lfMap = false;
            var save_button = $('#save_button');
            var pac_input = $('#pac-input');
            var lfConfig = new Array();
            lfConfig['phrase_not_found'] = "<?php echo $this->_tpl_vars['lang']['location_not_found']; ?>
";
            lfConfig['zoom'] = <?php if ($this->_tpl_vars['config']['locationFinder_map_zoom']): ?><?php echo $this->_tpl_vars['config']['locationFinder_map_zoom']; ?>
<?php else: ?>12<?php endif; ?>;
            lang['edit'] = '<?php echo $this->_tpl_vars['lang']['edit']; ?>
';

            <?php echo '

            if (!rlConfig[\'ajax_url\']) {
                rlConfig[\'ajax_url\'] = \''; ?>
<?php echo @RL_URL_HOME; ?>
<?php echo @ADMIN; ?>
/request.ajax.php<?php echo '\';
            }

            if (!lang[\'system_error\']) {
                lang[\'system_error\'] = \''; ?>
<?php echo $this->_tpl_vars['lang']['system_error']; ?>
<?php echo '\';
            }

            var geocode_api = "//maps.googleapis.com/maps/api/geocode/json?language=en-US&latlng={latLng}";
            if (lfConfig[\'google_key\']) {
                geocode_api = \'https:\'+geocode_api;
                geocode_api += \'&key=\'+lfConfig[\'google_key\'];
            }

            $(document).ready(function(){
                var lfLoading = function(obj, enable){
                    if (enable) {
                        $(obj).val(lang[\'loading\']).attr(\'disabled\', true).addClass(\'disabled\');
                    } else {
                        $(obj).val(lang[\'edit\']).attr(\'disabled\', false).removeClass(\'disabled\');
                    }
                }

                var str2key = function(country, state, city){
                    var out = country;
                    if (state != \'\' && state != undefined) {
                        out += \'+\'+state;
                    }
                    if (city != \'\' && city != undefined) {
                        out += \'+\'+city;
                    }
                    out = out.replace(/ /gi, \'_\').replace(/[^a-zA-Z0-9\\+\\_]+/g, \'\').toLowerCase();

                    return out;
                }

                var lfBuildMap = function(address){
                    if (lfMap) {
                        if (address[2] == \'direct\') {
                            var pos = new google.maps.LatLng(address[0].split(\',\')[0], address[0].split(\',\')[1]);
                            lfMap.markers[0].setPosition(pos);
                            lfMap.map.setCenter(pos);
                        } else {
                            var geocoder = new google.maps.Geocoder()
                            geocoder.geocode({address: address[0]}, function(results, status){
                                if (status == google.maps.GeocoderStatus.OK) {
                                    lfMap.markers[0].setPosition(results[0].geometry.location);
                                    lfMap.map.setCenter(results[0].geometry.location);

                                    // show button for empty mapping
                                    save_button.slideDown();
                                }
                            })
                        }
                    } else {
                        $(\'#map\').flMap({
                            addresses: [
                                address
                            ],
                            phrases: {
                                notFound: lfConfig[\'phrase_not_found\']
                            },
                            scrollWheelZoom: false,
                            zoom: lfConfig[\'zoom\'],
                            ready: function(base){
                                lfMap = base;
                                base.markers[0].setDraggable(true);

                                // show button for empty mapping
                                if (address[2] == \'geocoder\') {
                                    save_button.slideDown();
                                }

                                google.maps.event.addListener(base.markers[0], \'dragend\', function(){
                                    save_button.slideDown();
                                });

                                // enable location search
                                pac_input.show();
                                var searchBox = new google.maps.places.SearchBox(pac_input.get(0));
                                base.map.controls[google.maps.ControlPosition.TOP_LEFT].push(pac_input.get(0));

                                searchBox.addListener(\'places_changed\', function() {
                                    var places = searchBox.getPlaces();

                                    if (places.length == 0) {
                                        return;
                                    }

                                    // set new location
                                    base.map.setCenter(places[0].geometry.location);
                                    base.markers[0].setPosition(places[0].geometry.location);

                                    // show save buttn
                                    save_button.slideDown();
                                });
                            }
                        });
                        //$(\'#pac-input\').show();
                    }
                }

                // edit button handler
                $(\'#edit_button\').click(function(){
                    var button = this;
                    var last_select = false;
                    var address = new Array();

                    $(\'.lc-interface select\').each(function(){
                        if ($(this).val() != \'0\') {
                            last_select = $(this);
                            address.push($(this).find(\'> option:selected\').text());
                        }
                    });

                    if (last_select.length) {
                        // enable loading
                        lfLoading(this, true);

                        // get current location data if so
                        $.post(rlConfig[\'ajax_url\'], {item: \'locationFinderGetMapping\', key: last_select.val()}, function(response){
                            // disable loading
                            lfLoading(button, false);

                            if (response.status == \'OK\' && response.results.Lat) {
                                address = [response.results.Lat + \',\' + response.results.Lng, address.join(\', \'), \'direct\'];
                            } else {
                                address = [address.join(\',\'), address.join(\', \'), \'geocoder\'];
                            }

                            lfBuildMap(address);
                        }, \'json\').fail(function(object, status) {
                            // disable loading
                            lfLoading(button, false);

                            if (status == \'abort\')
                                return;

                            printMessage(\'error\', lang[\'system_error\']);
                            console.log(\'locationFinder: AP | get mapping ajax request failed\');
                        });
                    } else {
                        printMessage(\'error\', lang[\'locationFinder_js_location_not_selected_error\']);
                    }
                });

                // save button handler
                save_button.click(function(){
                    var self = this;
                    var last_select = false;
                    var lat = lfMap.markers[0].getPosition().lat();
                    var lng = lfMap.markers[0].getPosition().lng();

                    $(\'.lc-interface select\').each(function(){
                        if ($(this).val() != \'0\') {
                            last_select = $(this);
                        }
                    });

                    lfLoading(this, true);

                    var api = geocode_api.replace(\'{latLng}\', lat+\',\'+lng);

                    $.getJSON(api, function(response){
                        if (response.status == \'OK\') {
                            var address = response.results;
                            var country = false;
                            var state = false;
                            var city = false;
                            var neighborhood = false;

                            for (var i=0; i<address.length; i++) {
                                switch(address[i].types[0]) {
                                    case \'country\':
                                        country = address[i].address_components[0];
                                        break;

                                    case \'administrative_area_level_1\':
                                        state = address[i].address_components[0];
                                        break;

                                    case \'locality\':
                                        city = address[i].address_components[0];
                                        break;

                                    case \'neighborhood\':
                                        neighborhood = address[i].address_components[0];
                                        break;
                                }
                            }

                            var locality = str2key(country.long_name, state.long_name, city.long_name);
                            var alternative = neighborhood.long_name && city.long_name && neighborhood.long_name != city.long_name
                            ? str2key(country.long_name, state.long_name, neighborhood.long_name)
                            : \'\';

                            // save location mapping
                            $.post(rlConfig[\'ajax_url\'], {item: \'locationFinderSaveMapping\', formatKey: last_select.val(), googleKey: locality, neighborhoodKey: alternative, lat: lat, lng: lng}, function(response){
                                if (response.status == \'OK\') {
                                    printMessage(\'notice\', lang[\'locationFinder_mapping_saved\']);
                                    $(save_button).slideUp();
                                }
                            }, \'json\').fail(function(object, status) {
                                if (status == \'abort\')
                                    return;

                                printMessage(\'error\', lang[\'system_error\']);
                                console.log(\'locationFinder: AP | save mapping ajax request failed\');
                            });

                            $(self).slideUp();
                            lfLoading(this, false);
                        } else {
                            printMessage(\'error\', lang[\'system_error\']);
                            console.log(\'locationFinder: AP | Geocoder request failed\');
                        }
                    });
                });

                // location dropdowns handler
                $(\'.lc-interface select\').change(function(){
                    $(save_button).slideUp();
                });
            });

            '; ?>

            </script>
        <?php else: ?>
            <?php $this->assign('link', ((is_array($_tmp=((is_array($_tmp='<a href="')) ? $this->_run_mod_handler('cat', true, $_tmp, $this->_tpl_vars['href']) : smarty_modifier_cat($_tmp, $this->_tpl_vars['href'])))) ? $this->_run_mod_handler('cat', true, $_tmp, '">$1</a>') : smarty_modifier_cat($_tmp, '">$1</a>'))); ?>
            <?php echo ((is_array($_tmp=$this->_tpl_vars['lang']['locationFinder_mapping_no_fields_mapping'])) ? $this->_run_mod_handler('regex_replace', true, $_tmp, '/\[(.+)\]/', $this->_tpl_vars['link']) : smarty_modifier_regex_replace($_tmp, '/\[(.+)\]/', $this->_tpl_vars['link'])); ?>

        <?php endif; ?>
    <?php else: ?>
        <?php echo $this->_tpl_vars['mapping_error']; ?>

    <?php endif; ?>

    <?php $_smarty_tpl_vars = $this->_tpl_vars;
$this->_smarty_include(array('smarty_include_tpl_file' => ((is_array($_tmp=((is_array($_tmp='blocks')) ? $this->_run_mod_handler('cat', true, $_tmp, @RL_DS) : smarty_modifier_cat($_tmp, @RL_DS)))) ? $this->_run_mod_handler('cat', true, $_tmp, 'm_block_end.tpl') : smarty_modifier_cat($_tmp, 'm_block_end.tpl')), 'smarty_include_vars' => array()));
$this->_tpl_vars = $_smarty_tpl_vars;
unset($_smarty_tpl_vars);
 ?>
<?php endif; ?>

<!-- location finder admin contoller end -->