<?php
  ///////////////////////////////////////////////////
  //Карпухин Павел
  //2010 (С)
  ///////////////////////////////////////////////////

  $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['krit-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['krit_id'])) puterror2($TEXT['error-krit5']);
  if(strlen($_POST['krit_id'])>11) puterror2($TEXT['error-krit4']);
  $_POST['krit_id'] = rep($_POST['krit_id']);

  //$krit_id = $_POST['krit_id'];

  $query = "SELECT `pic_krit`, `krit_id` FROM `tbl_kritichnost` WHERE `krit_id` = '".$_POST['krit_id']."'";
  $krit_del = mysql_query($query);
  if(!$krit_del) puterror2($TEXT['error-tbl39']);
  {
    if(mysql_num_rows($krit_del)>0)
    {
      $krit = mysql_fetch_array($krit_del);
      if(file_exists("../".$krit['pic_krit']) && $krit['pic_krit'] !="-")
         unlink("../".$krit['pic_krit']);
    }
  }

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

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-krit2'];
  $what = $result2['kritichnost'].$TEXT['log-id'].$_POST['krit_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "DELETE FROM `tbl_kritichnost` WHERE `krit_id`='".$_POST['krit_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.php' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-krit7']);
  require_once "../util/bottom.php";
?>