<?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['supp-step-add1'];
  $helppage = $TEXT['supp-step-add1-tit'];

  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['name'])) puterror2($TEXT['error-marsh8']);
  if(strlen($_POST['name'])>255) puterror2($TEXT['error-marsh9']);
  if(empty($_POST['position'])) puterror2($TEXT['error-marsh10']);
  if(strlen($_POST['position'])>11) puterror2($TEXT['error-marsh11']);
  if(empty($_POST['mar_id'])) puterror2($TEXT['error-marsh16']);
  if(strlen($_POST['mar_id'])>11) puterror2($TEXT['error-marsh13']);
  if(empty($_POST['login_id'])) puterror2($TEXT['error-login15']);
  if(strlen($_POST['login_id'])>11) puterror2($TEXT['error-login14']);
  if(empty($_POST['logika'])) puterror2($TEXT['error-marsh21']);
  if(strlen($_POST['logika'])>11) puterror2($TEXT['error-marsh24']);
  if(empty($_POST['tema_id'])) puterror2($TEXT['error-tema5']);
  if(strlen($_POST['tema_id'])>11) puterror2($TEXT['error-tema4']);
  $_POST['name'] = rep($_POST['name']);
  $_POST['position'] = rep($_POST['position']);
  $_POST['login_id'] = rep($_POST['login_id']);
  $_POST['mar_id'] = rep($_POST['mar_id']);
  $_POST['logika'] = rep($_POST['logika']);
  $_POST['tema_id'] = rep($_POST['tema_id']);

  $mar_id = $_POST['mar_id'];
  $name = $_POST['name'];
  if($_POST['logika'] == "1") $logika = $TEXT['logic-marsh1'];
   elseif($_POST['logika'] == "2") $logika = $TEXT['logic-marsh2'];
    else $logika = $TEXT['logic-marsh3'];

  $query10 = "SELECT `mar_name` FROM `tbl_marsh` WHERE `mar_id`='".$_POST['mar_id']."' ";
  $result10 = mysql_query($query10);
  if(!$result10) puterror2($TEXT['error-tbl42']);
   $result_lib = mysql_fetch_array($result10);
  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-marsh9'];
  $what = $TEXT['supp-mar2']." &laquo;".$result_lib['mar_name']."&raquo;, ".$TEXT['supp-step-name']." &laquo;".$_POST['name']."&raquo;, ".$TEXT['logic-marsh-tit']." &laquo;".$logika."&raquo;";
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO `tbl_step` ( `step_id` , `mar_id` , `step_name` , `position` , `login_id`, `logika`, `tema_id`) VALUES ( NULL, '".$_POST['mar_id']."', '".$_POST['name']."', '".$_POST['position']."', '".$_POST['login_id']."', '".$_POST['logika']."', ".$_POST['tema_id'].") ";
  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=marshindex.php?mar_id=$mar_id' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-tbl43']);
  require_once "../util/bottom.php";
?>