<?php
  ///////////////////////////////////////////////////
  //выравнивание логики поведения
  //2011 (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['org-title3'];

  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($_GET['step_id'])) puterror2($TEXT['error-marsh6']);
  if(strlen($_GET['step_id'])>11) puterror2($TEXT['error-marsh7']);
  if(empty($_GET['mar_id'])) puterror2($TEXT['error-marsh16']);
  if(strlen($_GET['mar_id'])>11) puterror2($TEXT['error-marsh13']);
  if(empty($_GET['logika'])) puterror2($TEXT['error-marsh21']);
  if(strlen($_GET['logika'])>11) puterror2($TEXT['error-marsh24']);
  if(empty($_GET['position'])) puterror2($TEXT['error-marsh4']);
  if(strlen($_GET['position'])>5) puterror2($TEXT['error-marsh5']);

  $_GET['step_id'] = rep($_GET['step_id']);
  $_GET['logika'] = rep($_GET['logika']);
  $_GET['mar_id'] = rep($_GET['mar_id']);
  $_GET['position'] = rep($_GET['position']);

  $query_move = "SELECT `step_id` FROM `tbl_step` WHERE `mar_id`='".$_GET['mar_id']."' AND `step_id`!='".$_GET['step_id']."' AND `position`='".$_GET['position']."' ";
  $result_move = mysql_query($query_move);
  if(!$result_move) puterror2($TEXT['error-tbl43']);
   if(mysql_num_rows($result_move) > 0)
   {
    while($result2_move = mysql_fetch_array($result_move))
    {
    $query_upd = "UPDATE `tbl_step` SET `logika`='".$_GET['logika']."' WHERE `step_id`='".$result2_move['step_id']."' ";
     $result_upd = mysql_query($query_upd);
       if(!$result_upd) puterror2($TEXT['error-tbl43']);
    }
  }
  echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=marshindex.php?mar_id=".$_GET['mar_id']."' />
          </head></html>";
?>