<?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['pho-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($_GET['mer_id'])) puterror2($TEXT['error-pho15']);
  if(strlen($_GET['mer_id'])>11) puterror2($TEXT['error-pho13']);
  if(empty($_GET['photo_id'])) puterror2($TEXT['error-pho17']);
  if(strlen($_GET['photo_id'])>11) puterror2($TEXT['error-pho18']);
  $_GET['mer_id'] = rep($_GET['mer_id']);
  $_GET['photo_id'] = rep($_GET['photo_id']);

  $mer_id = $_GET['mer_id'];
  $photo_id = $_GET['photo_id'];

  $query = "SELECT `big`, `small`, `photo_id` FROM `tbl_photo` WHERE `photo_id` = '$photo_id'";
  $photo_del = mysql_query($query);
  if(!$photo_del) puterror2($TEXT['error-tbl13']);
  {
    if(mysql_num_rows($photo_del)>0)
    {
      $photo = mysql_fetch_array($photo_del);
      if(file_exists("../".$photo['big']) && $photo['big'] != "-")
         unlink("../".$photo['big']);
      if(file_exists("../".$photo['small']) && $photo['small'] != "-")
         unlink("../".$photo['small']);
    }
  }

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-pho5'];
  $what = $photo['big'].$TEXT['log-pho3'].$photo['small'];
  $who = $result2['fullname'];
  //*************************************
  $query2 = "DELETE FROM `tbl_photo` WHERE `photo_id`='$photo_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=photoindex.php?mer_id=$mer_id' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
   } else puterror2($TEXT['error-pho19']);
  require_once "../util/bottom.php";
?>
