<?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-title4'];
  $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['razd_id'])) puterror2($TEXT['error-nd16']);
  if(strlen($_POST['razd_id'])>11) puterror2($TEXT['error-nd13']);
  $_POST['razd_id'] = rep($_POST['razd_id']);

  $razd_id = $_POST['razd_id'];

  $query = "SELECT `photo`, `razd_id` FROM `tbl_razdel_instr` WHERE `razd_id` = '$razd_id'";
  $razd_del = mysql_query($query);
  if(!$razd_del) puterror2($TEXT['error-tbl19']);
  {
    if(mysql_num_rows($razd_del)>0)
    {
      $razd = mysql_fetch_array($razd_del);
      if(file_exists("../".$razd['photo']) && $razd['photo'] !="-")
         unlink("../".$razd['photo']);
    }
  }

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

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-inst3'];
  $what = $result2['razdel'].$TEXT['log-id'].$_POST['razd_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "DELETE FROM `tbl_razdel_instr` WHERE `razd_id`='".$_POST['razd_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-nd20']);
  require_once "../util/bottom.php";
?>
