View file apanel/moduls/add_region.php

File size: 2.04Kb
<?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']);
	      if (mysql_num_rows(mysql_query("SELECT * FROM `q_country` WHERE `id_country` = '".$id_country."' LIMIT 1;")) > 0)
	      {
	           $name_region = trim($_POST['name_region']);
		   $name_region = function_sql($name_region);
		   $explode_region = explode('\n', $name_region);
		   for ($i = 0; $i < count($explode_region); $i++)
		   {
	           if (!empty($explode_region[$i]))
		   {
		        $explode_region[$i] = iconv('utf-8', 'windows-1251', $explode_region[$i]);
			$explode_region[$i] = ucfirst(strtolower($explode_region[$i]));
			$explode_region[$i] = iconv('windows-1251', 'utf-8', $explode_region[$i]);
			
			if (mysql_num_rows(mysql_query("SELECT * FROM `q_region` WHERE `name_region` = '".function_sql(trim($explode_region[$i]))."' AND `id_country` = '".$id_country."' LIMIT 1;")) == 0)
		        {
			     mysql_query("INSERT INTO `q_region` (`id_country`, `name_region`) VALUES ('".$id_country."', '".function_sql($explode_region[$i])."');");
		             echo '<span class="green">Регион "'.htmlspecialchars($explode_region[$i], ENT_QUOTES).'" добавлен</span><br/>';
		        }
		        else
		        {
		             echo '<span class="red">Регион "'.htmlspecialchars($explode_region[$i], ENT_QUOTES).'" уже есть в БД</span><br/>';
		        }
		   }
		   }
	      }
	 }
?>