<?php
  ///////////////////////////////////////////////////
  //2011 (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['bllst-text4'];
  $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['tip_id'])) puterror2($TEXT['error-tip5']);
  if(strlen($_POST['tip_id'])>11) puterror2($TEXT['error-tip4']);
  $_POST['tip_id'] = rep($_POST['tip_id']);

  $tip_id = $_POST['tip_id'];

  $query = "SELECT `pic_tip`, `tip_id` FROM `tbl_tip_resurs` WHERE `tip_id` = '$tip_id'";
  $tip_del = mysql_query($query);
  if(!$tip_del) puterror2($TEXT['error-tbl38']);
  {
    if(mysql_num_rows($tip_del)>0)
    {
      $tip = mysql_fetch_array($tip_del);
      if(file_exists("../".$tip['pic_tip']) && $tip['pic_tip'] !="-")
         unlink("../".$tip['pic_tip']);
    }
  }

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

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-tip2'];
  $what = $result2['tip_name'].$TEXT['log-id'].$_POST['tip_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "DELETE FROM `tbl_tip_resurs` WHERE `tip_id`='".$_POST['tip_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-tip.php' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-tip7']);
  require_once "../util/bottom.php";
?>
