View file users/account/cabinet/components/top/01_location.php

File size: 1.51Kb
<?php
  
/*
------------------------------
Автоопределение местоположения
------------------------------
*/
  
if (user('ID') > 0){
  
  if (str(settings('CITY')) == 0 && str(settings('COUNTRY')) == 0){

    $location = @unserialize(file_get_contents('http://ip-api.com/php/'.IP.'?lang=ru'));
    
    $city = db::get_string("SELECT `NAME`,`ID_COUNTRY` FROM `CITY` WHERE `NAME` = ? LIMIT 1", [(isset($location['city']) ? esc($location['city']) : null)]);
    $country = db::get_string("SELECT `NAME` FROM `COUNTRY` WHERE `ID` = ? LIMIT 1", [esc($city['ID_COUNTRY'])]);
    
    $ct = 'Москва';
    $cn = 'Россия';
    
    if (str($city['NAME']) > 0 && str($country['NAME']) > 0) {
      
      $ct = tabs($city['NAME']);
      $cn = tabs($country['NAME']);
      
    }
    
    if (get('location') == 'set'){
      
      get_check_valid();
      
      db::get_add("UPDATE `USERS_SETTINGS` SET `CITY` = ?, `COUNTRY` = ? WHERE `USER_ID` = ? LIMIT 1", [$ct, $cn, user('ID')]);
      
      success('Изменения успешно приняты');
      redirect('/id'.user('ID'));
      
    }
    
    ?>
    <div class='list'>
    <?=user('LOGIN')?>, <?=lg('Вы в городе')?> <b><?=$ct?></b> <?=lg('страны')?> <b><?=$cn?></b>?<br /><br />
    <a href='/account/cabinet/?location=set&<?=TOKEN_URL?>' class='btn'><?=lg('Да')?></a>
    <a href='/account/form/?id=<?=user('ID')?>&get=geo&<?=TOKEN_URL?>' class='btn-o'><?=lg('Выбрать место')?></a>
    </div>
    <?
    
  }
  
}