Файл: forum/delpost.php
Строк: 117
<?php
# Script by seg0ro http://mobilarts.ru
# Not for sale!!!
defined('_IN_JOHNCMS') or die('Error: restricted access');
$textl .= ' | Удаление';
require_once('../incfiles/head.php');
if (!$topic){
  echo functions::display_error('Отсутствует идентификатор темы!<br /><a href="index.php">Форум</a>');
  require_once('../incfiles/end.php');
  exit;
}
if (is_array($_POST['massdel']) || (isset($_POST['yes']) && is_array($_SESSION['dc']))){
  
  if ($rights != 3 && $rights < 6){
    echo functions::display_error('У вас недостаточно прав для просмотра этой страницы!<br /><a href="index.php">Форум</a>');
    require_once('../incfiles/end.php');
    exit;
  }
  
  $tree = array('<a href="index.php">Форум</a>', '<a href="index.php?topic='.$topic.'&page='.$page.'">'.functions::checkout($topicRes['topicname']).'</a>', 'Удаление сообщений');
  echo '<div class="phdr">'.functions::display_menu($tree).'</div>';
  if (isset($_POST['yes'])){
    
    foreach ($_SESSION['dc'] as $delId){
      $fileReq = mysql_query("SELECT * FROM `forum_files` WHERE `post` = '$delId' ");
      if (mysql_num_rows($fileReq)){
        while ($fileRes = mysql_fetch_array($fileReq)){
          unlink('../files/forum/'.$fileRes['filename']);
        }
        mysql_query("DELETE FROM `forum_files` WHERE `post` = '$delId' LIMIT 1 ");
      }
      $postRes = mysql_fetch_array(mysql_query("SELECT `user_id`, `rating` FROM `forum_posts` WHERE `post` = '$delId' LIMIT 1 "));
      mysql_query("UPDATE `users` SET `postforum` = postforum - 1 WHERE `id` = '".$postRes['user_id']."' LIMIT 1 ");
            
      if ($postRes['rating'])
        mysql_query("DELETE FROM `forum_posts_rating` WHERE `post` = '$delId' ");
      mysql_query("DELETE FROM `forum_posts` WHERE `post` = '$delId' LIMIT 1 ");
      ++$i;
    }
    $lastPost = mysql_fetch_array(mysql_query("SELECT `post`, `time`, `user` FROM `forum_posts` WHERE `topic` = '$topic' ORDER BY `time` DESC LIMIT 1 "));
    mysql_query("UPDATE `forum_topics` SET
    `time` = '".$lastPost['time']."',
    `lastpost` = '".$lastPost['user'].":|:".$lastPost['post']."',
    `count` = count - $i
    WHERE `topic` = '$topic' LIMIT 1 ");
    $lastTopic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `forum` = '".$topicRes['forum']."' ORDER BY `time` DESC LIMIT 1 "));
    mysql_query("UPDATE `forum_forums` SET
    `last_topic`='".$lastTopic['topic'].":|:".$lastTopic['topicname'].":|:".$lastTopic['time']."'
    WHERE `forum`='".$topicRes['forum']."' LIMIT 1 ");
    
    unset ($_SESSION['dc']);
    header ('Refresh:1; URL=index.php?topic='.$topic.'&page='.$page);
    forum_log('Массовое удаление сообщений в теме [url='.$set['homeurl'].'/forum/index.php?topic='.$topic.']'.$topicRes['topicname'].'[/url]');
    echo '<div class="gmenu">Отмеченные сообщения удалены<br /><a href="index.php?topic='.$topic.'&page='.$page.'">Далее</a></div>';
    
  }else{
    
    $total = count($_POST['massdel']);
    if (!$total){
      echo functions::display_error('Вы ничего не выбрали для удаления!<br /><a href="index.php?topic='.$topic.'&page='.$page.'">Назад</a>');
      require_once ('../incfiles/end.php');
      exit;
    }
    
    if ($topicRes['count'] == $total){
      echo '<form action="index.php?act=deltopic&topic='.$topic.'" method="post"><div class="rmenu">Вы собираетесь удалить все сообщения в теме, при удалении будет удалена и тема<br />';
      if ($rights > 6)
        echo '<input type="submit" name="yes" value="Удалить" /> ';
      echo '<a href="index.php?topic='.$topic.'&page='.$page.'">Отмена</a></div></form>';
      require_once('../incfiles/end.php');
      exit;
    }
    
    $firstPost = mysql_fetch_array(mysql_query("SELECT `post` FROM `forum_posts` WHERE `topic` = '$topic' ORDER BY `time` ASC LIMIT 1 "));
    
    foreach ($_POST['massdel'] as $v){
      $dc[] = intval($v);
    }
    $_SESSION['dc'] = $dc;
      
    echo '<form action="index.php?act=delpost&topic='.$topic.'&page='.$page.'" method="post"><div class="rmenu">'.(in_array($firstPost['post'], $_POST['massdel']) ? 'В числе выбранного есть первое сообщение темы, его удаление не рекомендуется!<br />' : '').'Вы уверены в удалении сообщений ('.$total.' шт.)?<br /><input type="submit" name="yes" value="Удалить" /> <a href="index.php?topic='.$topic.'&page='.$page.'">Отмена</a></div></form>';
  }
  
  require_once('../incfiles/end.php');
  exit;
}
if (!$post){
  echo functions::display_error('Отсутствует идентификатор сообщения!<br /><a href="index.php?topic='.$topic.'&page='.$page.'">Назад</a>');
  require_once('../incfiles/end.php');
  exit;
}
if ($rights != 3 && $rights < 6){
  if ($postRes['user_id'] != $user_id)
  $check = true;
  if ($postRes['time'] < time() - 300)
    $check = true;
  if ($topicRes['close'])
    $check = true;
  if ($check){
    echo functions::display_error('У вас недостаточно прав для просмотра этой страницы!<br /><a href="index.php?topic='.$topic.'&page='.$page.'#p'.$post.'">Назад</a>');
    require_once($path.'incfiles/end.php');
    exit;
  }
}
$tree = array('<a href="index.php">Форум</a>', '<a href="index.php?topic='.$topic.'&page='.$page.'#p'.$post.'">'.functions::checkout($topicRes['topicname']).'</a>', 'Удаление сообщения');
echo '<div class="phdr">'.functions::display_menu($tree).'</div>';
if (isset($_POST['yes'])){
  
  $lastPost = mysql_fetch_array(mysql_query("SELECT `post`, `user`, `time` FROM `forum_posts` WHERE `topic` = '".$postRes['topic']."' AND `post` != '$post' ORDER BY `time` DESC LIMIT 1 "));
  mysql_query("UPDATE `forum_topics` SET
  `time` = '".$lastPost['time']."',
  `count` = count - 1,
  `lastpost` = '".$lastPost['user'].":|:".$lastPost['post']."'
  WHERE `topic` = '".$postRes['topic']."' LIMIT 1 ");
  $lastTopic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `forum` = '".$topicRes['forum']."' ORDER BY `time` DESC LIMIT 1 "));
  mysql_query("UPDATE `forum_forums` SET `last_topic` = '".$lastTopic['topic'].":|:".$lastTopic['topicname'].":|:".$lastTopic['time']."' WHERE `forum` = '".$topicRes['forum']."' LIMIT 1 ");
  mysql_query("UPDATE `users` SET `postforum` = postforum - 1 WHERE `id` = '".$postRes['user_id']."' LIMIT 1 ");
  
  if ($postRes['files']){
    $fileReq = mysql_query("SELECT * FROM `forum_files` WHERE `post` = '$post' LIMIT 10 ");
    if (mysql_num_rows($fileReq)){
      while ($fileRes = mysql_fetch_array($fileReq)){
        unlink('../files/forum/'.$fileRes['filename']);
      }
      mysql_query("DELETE FROM `forum_files` WHERE `post` = '$post' ");
    }
  }
  
  if ($postRes['rating'])
    mysql_query("DELETE FROM `forum_posts_rating` WHERE `post` = '$post' ");
  
  mysql_query("DELETE FROM `forum_posts` WHERE `post` = '$post' LIMIT 1 ");
  
  header ('Refresh:1; URL=index.php?topic='.$topic.'&page='.$page);
  forum_log('Удаление сообщения в теме [url='.$set['homeurl'].'/forum/index.php?topic='.$topic.']'.$topicRes['topicname'].'[/url]');
  echo '<div class="gmenu">Сообщение удалено<br /><a href="index.php?topic='.$topic.'&page='.$page.'">Далее</a></div>';
}else{
  $check = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_posts` WHERE `topic` = '".$postRes['topic']."' LIMIT 2 "), 0);
  if ($check == 1){
    echo '<form action="index.php?act=deltopic&topic='.$topic.'" method="post"><div class="rmenu">Это последнее сообщени в теме, при его удалении будет удалена и тема<br />';
    if ($rights > 6)
      echo '<input type="submit" name="yes" value="Удалить" /> ';
    echo '<a href="index.php?topic='.$topic.'&page='.$page.'#p'.$post.'">Отмена</a></div></form>';
    require_once('../incfiles/end.php');
    exit;
  }
  $firstPost = mysql_fetch_assoc(mysql_query("SELECT `post` FROM `forum_posts` WHERE `topic` = '".$postRes['topic']."' ORDER BY `time` ASC LIMIT 1 "));
  echo '<form action="index.php?act=delpost&topic='.$topic.'&post='.$post.'&page='.$page.'" method="post"><div class="rmenu">'.($firstPost['post'] == $post ? 'Это первое сообщение темы, его удаление не рекомендуется!<br />' : '').'Вы действительно хотите удалить сообщение?<br /><input type="submit" name="yes" value="Удалить" /> <a href="index.php?topic='.$topic.'&page='.$page.'#p'.$post.'">Отмена</a></div></form>';
}