<?php
  ///////////////////////////////////////////////////
  //2007 (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['inst-title2'];
  $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($_GET['mar_id'])) puterror2($TEXT['error-marsh16']);
  if(strlen($_GET['mar_id'])>11) puterror2($TEXT['error-marsh13']);
  if(empty($_GET['step_id'])) puterror2($TEXT['error-marsh17']);
  if(strlen($_GET['step_id'])>11) puterror2($TEXT['error-marsh18']);
  if(empty($_GET['position'])) puterror2($TEXT['error-marsh10']);
  if(strlen($_GET['position'])>11) puterror2($TEXT['error-marsh11']);
  $_GET['mar_id'] = rep($_GET['mar_id']);
  $_GET['step_id'] = rep($_GET['step_id']);
  $_GET['position'] = rep($_GET['position']);

  $query10 = "SELECT `step` FROM `tbl_supp_zayavka` WHERE `mar_id` = '".$_GET['mar_id']."' AND `step`='".$_GET['position']."' ";
  $result10 = mysql_query($query10);
  if(!$result10) puterror2(mysql_error());
   if(mysql_num_rows($result10) > 0) puterror2($TEXT['error-marsh14']);

  $query11 = "SELECT tbl_step.step_name, tbl_marsh.mar_name
    FROM tbl_step
    JOIN tbl_marsh ON tbl_step.mar_id=tbl_marsh.mar_id
    WHERE `step_id`='".$_GET['step_id']."' ";
  $result11 = mysql_query($query11);
  if(!$result11) puterror2($TEXT['error-tbl43']);
      $result_step = mysql_fetch_array($result11);
  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-marsh3'];
  $what = $TEXT['log-marsh13']." &laquo;".$result_step['mar_name']."&raquo; ".$TEXT['log-marsh14']." &laquo;".$result_step['step_name']."&raquo; ".$TEXT['log-id'].$_GET['step_id'];
  $who = $result2['fullname'];
  //*************************************
  $query2 = "DELETE FROM `tbl_step` WHERE `step_id`='".$_GET['step_id']."'";
  if(mysql_query($query2))
  {
    $query3 = "INSERT INTO `tbl_logs` ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysql_query($query3))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=marshindex.php?mar_id=".$_GET['mar_id']."' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-tbl43']);
  require_once "../util/bottom.php";
?>