<?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-mar-del'];
  $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['mar_id'])) puterror2($TEXT['error-marsh16']);
  if(strlen($_POST['mar_id'])>11) puterror2($TEXT['error-marsh13']);
  $_POST['mar_id'] = rep($_POST['mar_id']);

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

  //*************************************
  $query = "SELECT `mar_id`, `mar_name` FROM `tbl_marsh` WHERE `mar_id`='".$_POST['mar_id']."' ";
  $res_mar = mysql_query($query);
  if(!$res_mar) puterror2($TEXT['error-tbl42']);
   $mar2 = mysql_fetch_array($res_mar);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-marsh3'];
  $what = $mar2['mar_name'].$TEXT['log-id'].$_POST['mar_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "DELETE FROM `tbl_marsh` WHERE `mar_id`='".$_POST['mar_id']."' LIMIT 1";
  if(mysql_query($query))
  {
   $query2 = "DELETE FROM `tbl_step` WHERE `mar_id`='".$_POST['mar_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($query2))
         {
          echo "<html><head>
                <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
                </head></html>";
         } else puterror2($TEXT['error-log']);
    } else puterror2($TEXT['error-tbl43']);
  } else puterror2($TEXT['error-tbl42']);
  require_once "../util/bottom.php";
?>