<?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['nd-title3'];
  $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['razd_id'])) puterror2($TEXT['error-nd16']);
  if(strlen($_GET['razd_id'])>11) puterror2($TEXT['error-nd13']);
  if(empty($_GET['doc_id'])) puterror2($TEXT['error-nd17']);
  if(strlen($_GET['doc_id'])>11) puterror2($TEXT['error-nd18']);
  $_GET['razd_id'] = rep($_GET['razd_id']);
  $_GET['doc_id'] = rep($_GET['doc_id']);

  $razd_id = $_GET['razd_id'];
  $doc_id = $_GET['doc_id'];

  $query = "SELECT `path`, `doc_id` FROM `tbl_documents` WHERE `doc_id` = '$doc_id'";
  $doc_del = mysql_query($query);
  if(!$doc_del) puterror2($TEXT['error-tbl14']);
  {
    if(mysql_num_rows($doc_del)>0)
    {
      $doc = mysql_fetch_array($doc_del);
      if(file_exists("../".$doc['path']) && $doc['path'] != "-")
         unlink("../".$doc['path']);
    }
  }
  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-nd3'];
  $what = $doc['path'];
  $who = $result2['fullname'];
  //*************************************
  $query2 = "DELETE FROM `tbl_documents` WHERE `doc_id`='$doc_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=docindex.php?razd_id=$razd_id' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-nd19']);
  require_once "../util/bottom.php";
?>
