<?php
  ///////////////////////////////////////////////////
  //2007 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang."/".$lang.".php")) include "../lang/".$lang."/".$lang.".php";
     else include "../lang/ru/ru.php";

  $title=$titlepage= $TEXT['city-title2'];
  $helppage = "";

  require_once "../config.php";
  require_once "../util/top.php";

  if($result2['user'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(empty($_POST['city'])) puterror2($TEXT['error-city1']);
  if(strlen($_POST['city'])>120) puterror2($TEXT['error-city2']);

  if(isset($_POST['city'])) $city=trim($_POST['city']);
    else $city="";
     if (empty($city)) puterror2($TEXT['error-city3']);

  $_POST['city'] = rep($_POST['city']);

  $query_chk = "SELECT `city` FROM `tbl_city` WHERE `city`='".$_POST['city']."' ";
     $result_chk = mysql_query($query_chk);
     if (!$result_chk) puterror2($TEXT['error-tbl1']);
       if (mysql_num_rows($result_chk)>0) puterror2($TEXT['global-est']);

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-city1'];
  $what = $_POST['city'];
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO `tbl_city` ( `city_id` , `city` ) VALUES ( NULL , '".$_POST['city']."')";
  if(mysql_query($query))
  {
    $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysql_query($query2))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-city4']);
  require_once "../util/bottom.php";
?>
