<?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['supp-vazh-title4'];
  $helppage = "";

  require_once "../config.php";
  require_once "../util/top_layer1.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($_POST['vazh_id'])) puterror2($TEXT['error-vazh5']);
  if(strlen($_POST['vazh_id'])>11) puterror2($TEXT['error-vazh4']);
  $_POST['vazh_id'] = rep($_POST['vazh_id']);

  $vazh_id = $_POST['vazh_id'];

  $query = "SELECT `pic_sr`, `sroch_id` FROM `tbl_supp_srochnost` WHERE `sroch_id` = '$vazh_id'";
  $vazh_del = mysql_query($query);
  if(!$vazh_del) puterror2($TEXT['error-tbl24']);
  {
    if(mysql_num_rows($vazh_del)>0)
    {
      $vazh = mysql_fetch_array($vazh_del);
      if(file_exists("../".$vazh['pic_sr']) && $vazh['pic_sr'] !="-")
         unlink("../".$vazh['pic_sr']);
    }
  }

  //*************************************
  $query = "SELECT * FROM `tbl_supp_srochnost` WHERE `sroch_id`='".$_POST['vazh_id']."' ";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl24']);
   $result2 = mysql_fetch_array($result);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-supp5'];
  $what = $result2['srochnost'].$TEXT['log-id'].$_POST['vazh_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "DELETE FROM `tbl_supp_srochnost` WHERE `sroch_id`='".$_POST['vazh_id']."' LIMIT 1";
  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-vazh.php' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-vazh7']);
  require_once "../util/bottom.php";
?>
