<?php
define('NTLCMS', 1);
$module = 'city';
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
$page_title = 'Страница выбора вашего местонахождения - клик клуба ' . strtoupper($_SERVER['HTTP_HOST']);
include ('../system/head.php');
if (!$active){
header('Location: '.URL);
$_SESSION['fail'] = 'Вы не авторизированы!';
exit;
}
switch($act){
case 'region':
echo '<div class="title"><b>'.razd.' Выберите регион</b></div>';
$count_pry = isset($_GET['country']) ? filter_var($_GET['country'], FILTER_SANITIZE_NUMBER_INT) : '0';
$sql = DB :: run() -> query("select * from `country` where `id_country` = '".$count_pry."' limit 1");
if (DB :: run() -> querySingle("select * from `country` where `id_country` = '".$count_pry."'") == 0){
header('Location: '.URL); exit;
}
$k_post = DB :: run() -> querySingle("select count(*) from `region` where `id_country` = '".$count_pry."'");
$k_page = k_page($k_post, $onpage); 
$page = page($k_page); 
$start = $onpage * $page - $onpage; 
$sql = DB :: run() -> query("select * from `region` where `id_country` = '".$count_pry."' order by `name_region` asc limit ".$start.", ".$onpage);
if ($k_post == 0){
echo '<div class="post"><center><i class="fa fa-close fa-fw"></i> База регионов отсутствует!</center></div>';
} else {	      
while ($row = $sql -> fetch(PDO::FETCH_OBJ)){
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/country'.$count_pry.'/region'.((int) $row -> id_region).'">'.($row -> name_region).'</a></div>';
}
if ($k_page > 1) navigation(URL.'/country'.$count_pry.'?', $k_page, $page);
}
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a></div>';
break;	 
case 'city':
echo '<div class="title"><b>'.razd.' Выберите город</b></div>';
$count_pry = isset($_GET['country']) ? filter_var($_GET['country'], FILTER_SANITIZE_NUMBER_INT) : '0';
$sql = DB :: run() -> query("select * from `country` where `id_country` = '".$count_pry."' limit 1");
if (DB :: run() -> querySingle("select * from `country` where `id_country` = '".$count_pry."'") == 0){
header('Location: '.URL); exit;
}
$region = isset($_GET['region']) ? filter_var($_GET['region'], FILTER_SANITIZE_NUMBER_INT) : '0';
$sql = DB :: run() -> query("select * from `region` where `id_region` = '".$region."' and `id_country` = '".$count_pry."' limit 1");
if (DB :: run() -> querySingle("select * from `region` where `id_region` = '".$region."' and `id_country` = '".$count_pry."'") == 0){
header('Location: '.URL); exit;
}
$k_post = DB :: run() -> querySingle("select count(*) from `city` where `id_country` = '".$count_pry."' and `id_region` = '".$region."'");
$k_page = k_page($k_post, $onpage); 
$page = page($k_page); 
$start = $onpage * $page - $onpage; 
$sql = DB :: run() -> query("select * from `city` where `id_country` = '".$count_pry."' and `id_region` = '".$region."' order by `name_city` asc limit ".$start.", ".$onpage);
if ($k_post == 0){
echo '<div class="post"><center><i class="fa fa-close fa-fw"></i> База городов отсутствует!</center></div>';
} else {
while ($row = $sql -> fetch(PDO::FETCH_OBJ)){
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/country'.$count_pry.'/region'.$region.'/city'.((int) $row -> id_city).'">'.($row -> name_city).'</a></div>';
}
if ($k_page > 1) navigation(URL.'/country'.$count_pry.'/region'.$region.'?', $k_page, $page);
}
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a></div>';
break;
case 'ok':
echo '<div class="title"><b>'.razd.' Местонахождение</b></div>';
$count_pry = isset($_GET['country']) ? filter_var($_GET['country'], FILTER_SANITIZE_NUMBER_INT) : '0';
$sql = DB :: run() -> query("select * from `country` where `id_country` = '".$count_pry."' limit 1");
if (DB :: run() -> querySingle("select * from `country` where `id_country` = '".$count_pry."'") == 0){
header('Location: '.URL); exit;
}
$row_country = $sql -> fetch(PDO::FETCH_OBJ);
$region = isset($_GET['region']) ? filter_var($_GET['region'], FILTER_SANITIZE_NUMBER_INT) : '0';
$sql = DB :: run() -> query("select * from `region` where `id_region` = '".$region."' and `id_country` = '".$count_pry."' limit 1");
if (DB :: run() -> querySingle("select * from `region` where `id_region` = '".$region."' and `id_country` = '".$count_pry."'") == 0){
header('Location: '.URL); exit;
}
$row_region = $sql -> fetch(PDO::FETCH_OBJ);
$city = isset($_GET['city']) ? filter_var($_GET['city'], FILTER_SANITIZE_NUMBER_INT) : '0';
$sql = DB :: run() -> query("select * from `city` where `id_city` = '".$city."' and `id_country` = '".$count_pry."' and `id_region` = '".$region."' limit 1");
if (DB :: run() -> querySingle("select * from `city` where `id_city` = '".$city."' and `id_country` = '".$count_pry."' and `id_region` = '".$region."'") == 0){
header('Location: '.URL); exit;
}
$row_city = $sql -> fetch(PDO::FETCH_OBJ);
if (!isset($_GET['i'])){
echo '<div class="post"><center>'.($row_country -> name_country).', '.($row_city -> name_city).' ('.($row_region -> name_region).')</div>';
echo '<div class="menu"><center><a href="'.URL.'/country'.$count_pry.'/region'.$region.'/city'.$city.'/success">Сохранить данные!</a></center></div>';
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a></div>';
} else {
DB :: run() -> query("update `users` set `country` = '".($row_country -> name_country)."', `region` = '".($row_region -> name_region)."', `city` = '".($row_city -> name_city)."' where `login` = '".$ilogin."'");
echo '<div class="post"><center><i class="fa fa-check-circle fa-fw"></i> Информация успешно сохранена!</center></div>';
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a></div>';
}
break;
default:
echo '<div class="title"><b>'.razd.' Выберите страну</b></div>';
$k_post = DB :: run() -> querySingle("select count(*) from `country`");
$k_page = k_page($k_post, $onpage); 
$page = page($k_page); 
$start = $onpage * $page - $onpage; 
$sql = DB :: run() -> query("select * from `country` order by `id_country` asc limit ".$start.", ".$onpage);
if ($k_post == 0){
echo '<div class="post"><center><i class="fa fa-close fa-fw"></i> База стран отсутствует!</center></div>';
} else {
while ($row = $sql -> fetch(PDO::FETCH_OBJ)){
echo '<div class="menu"><i class="fa fa-dot-circle-o fa-fw"></i> <a href="'.URL.'/country'.((int) $row -> id_country).'">'.($row -> name_country).'</a></div>';
}
if ($k_page > 1) navigation(URL.'/city?', $k_page, $page);
}
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a></div>';
break;
}
include ('../system/foot.php');
?>