<?php
  ///////////////////////////////////////////////////
  //2010 (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['etazh-title'];

  require_once "../config_a.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_adm.php";

  if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}

  if(empty($_POST['etazh'])) {puterror($result2['skin'],$TEXT['error-etazh1']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['etazh'])>20) {puterror($result2['skin'],$TEXT['error-etazh2']); require_once "../utils/bottom_adm.php"; exit();}

  if(isset($_POST['etazh'])) $etazh=trim($_POST['etazh']);
    else $etazh="";
     if (empty($etazh)) {puterror($result2['skin'],$TEXT['error-etazh3']); require_once "../utils/bottom_adm.php"; exit();}

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

  $query9 = "SELECT `etazh` FROM `tbl_etazh` WHERE `etazh`='".$_POST['etazh']."' ";
     $result9 = mysql_query($query9);
     if (!$result9) {puterror($result2['skin'],$TEXT['error-tbl11']); require_once "../utils/bottom_adm.php"; exit();}
       if (mysql_num_rows($result9)>0) {puterror($result2['skin'],$TEXT['error-double']); require_once "../utils/bottom_adm.php"; exit();}

  //*************************************
  //Информация для лога
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-etazh1'];
  $what = $_POST['etazh'];
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************

  $query = "INSERT INTO `tbl_etazh` ( `etazh_id` , `etazh` ) VALUES ( NULL , '".$_POST['etazh']."')";
  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 {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
  } else {puterror($result2['skin'],$TEXT['error-etazh4']); require_once "../utils/bottom_adm.php"; exit();}
require_once "../utils/bottom_adm.php";
?>