<?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['nd-title'];
  $helppage = "";

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

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

  if(empty($_POST['marsh'])) puterror2($TEXT['error-marsh2']);
  if(strlen($_POST['marsh'])>255) puterror2($TEXT['error-marsh3']);
  if(empty($_POST['position'])) puterror2($TEXT['error-marsh4']);
  if(strlen($_POST['position'])>11) puterror2($TEXT['error-marsh5']);

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

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

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

  $_POST['razdel'] = rep($_POST['razdel']);
  $_POST['position'] = rep($_POST['position']);

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

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-marsh1'];
  $what = $_POST['marsh'];
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO `tbl_marsh` ( `mar_id`, `mar_name`, `position`, `visible` ) VALUES ( NULL, '".$_POST['marsh']."', '".$_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($TEXT['error-tbl42']);
  require_once "../util/bottom.php";
?>