Просмотр файла apanel/moduls/add_city.php

Размер файла: 2.29Kb
<?php
/**********************************************/
/* Автор скрипта: Александр Есин              */
/* E-Mail: [email protected] ([email protected]) */
/* ICQ: 6464729                               */
/* Site: http://ticlove.ru                    */
/**********************************************/
?>
<?php define ('SECURED', true); ?>
<?php require (dirname(__FILE__).'/../../_inc/sql.php'); ?>
<?php require (dirname(__FILE__).'/../../_inc/config.php'); ?>
<?php require (dirname(__FILE__).'/../../_inc/function.php'); ?>
<?php
	 if (!empty($_SESSION['auth_admin']) && (intval($_POST['auth_admin']) == $_SESSION['auth_admin']))
	 {
	      $id_country = intval($_POST['id_country']);
	      $id_region = intval($_POST['id_region']);
	      
	      if (mysql_num_rows(mysql_query("SELECT * FROM `q_country` WHERE `id_country` = '".$id_country."' LIMIT 1;")) > 0)
	      {
	           if (mysql_num_rows(mysql_query("SELECT * FROM `q_region` WHERE `id_region` = '".$id_region."' AND `id_country` = '".$id_country."' LIMIT 1;")) > 0)
		   {
		   $name_city = trim($_POST['name_city']);
		   $name_city = function_sql($name_city);
		   $explode_city = explode('\n', $name_city);
		   for ($i = 0; $i < count($explode_city); $i++)
		   {
	           if (!empty($explode_city[$i]))
		   {
		        $explode_city[$i] = iconv('utf-8', 'windows-1251', $explode_city[$i]);
			$explode_city[$i] = ucfirst(strtolower($explode_city[$i]));
			$explode_city[$i] = iconv('windows-1251', 'utf-8', $explode_city[$i]);
			
			if (mysql_num_rows(mysql_query("SELECT * FROM `q_city` WHERE `name_city` = '".function_sql(trim($explode_city[$i]))."' AND `id_country` = '".$id_country."' AND `id_region` = '".$id_region."' LIMIT 1;")) == 0)
		        {
			     mysql_query("INSERT INTO `q_city` (`id_country`, `id_region`, `name_city`) VALUES ('".$id_country."', '".$id_region."', '".function_sql($explode_city[$i])."');");
		             echo '<span class="green">Город "'.htmlspecialchars($explode_city[$i], ENT_QUOTES).'" добавлен</span><br/>';
		        }
		        else
		        {
		             echo '<span class="red">Город "'.htmlspecialchars($explode_city[$i], ENT_QUOTES).'" уже есть в БД</span><br/>';
		        }
		   }
		   }
		   }
	      }
	 }
?>