<?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['kat-title'];

  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['strukt_name'])) puterror2($TEXT['error-kat2']);
  if(strlen($_POST['strukt_name'])>255) puterror2($TEXT['error-kat3']);
  if(empty($_POST['position'])) puterror2($TEXT['error-kat4']);
  if(strlen($_POST['position'])>6) puterror2($TEXT['error-kat5']);
  if(empty($_POST['parent'])) $_POST['parent'] = 0;
  if(strlen($_POST['parent'])>20) puterror2($TEXT['error-kat18']);

  if($_POST['visible'] == "on") $visible = "show";
    else $visible = "hide";

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

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

  $_POST['strukt_name'] = rep($_POST['strukt_name']);
  $_POST['position'] = rep($_POST['position']);
  //$_POST['parent'] = rep($_POST['parent']);
  //$_POST['level'] = rep($_POST['level']);

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-kat1'];
  $what = $_POST['strukt_name'];
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO `tbl_zhnaniy_strukt` ( `zh_str_id` , `strukt_name`, `parent`, `position`, `visible` ) VALUES ( NULL , '".$_POST['strukt_name']."', ".$_POST['parent'].", '".$_POST['position']."', '$visible') ";
  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(mysql_error());
  require_once "../util/bottom.php";
?>