<?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['inst-title2'];
  $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['instr_id'])) puterror2($TEXT['error-inst6']);
  if(strlen($_GET['instr_id'])>11) puterror2($TEXT['error-inst7']);
  $_GET['razd_id'] = rep($_GET['razd_id']);
  $_GET['instr_id'] = rep($_GET['instr_id']);

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

  $query = "SELECT `photo`, `path`, `instr_id` FROM `tbl_instructions` WHERE `instr_id` = '$instr_id'";
  $instr_del = mysql_query($query);
  if(!$instr_del) puterror2($TEXT['error-tbl18']);
  {
    if(mysql_num_rows($instr_del)>0)
    {
      $inst = mysql_fetch_array($instr_del);
      if(file_exists("../".$inst['path']) && $inst['path'] != "-")
         unlink("../".$inst['path']);

      if(file_exists("../".$inst['photo']) && $inst['photo'] != "-")
         unlink("../".$inst['photo']);
    }
  }
  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-inst4'];
  $what = $inst['path'];
  $who = $result2['fullname'];
  //*************************************
  $query2 = "DELETE FROM `tbl_instructions` WHERE `instr_id`='$instr_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=instindex.php?razd_id=$razd_id' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-inst8']);
  require_once "../util/bottom.php";
?>
