View file forum/includes/massdelpost.php

File size: 4.01Kb
  1. <?php
  2.  
  3. # fixed
  4.  
  5. $set['title'] .= ' | Массовое удаление постов';
  6. include H . 'engine/includes/head.php';
  7.  
  8. if (!$topic){
  9. echo Core::msg_show('Отсутствует идентификатор темы!<br /><a href="index.php">Форум</a>');
  10. include H . 'engine/includes/foot.php';
  11. }
  12.  
  13. if (!$moder){
  14. echo Core::msg_show('У вас недостаточно прав для просмотра этой страницы!<br /><a href="index.php">Форум</a>');
  15. include H . 'engine/includes/foot.php';
  16. }
  17.  
  18. echo '<div class="fmenu"><a href="index.php">Форум</a> / <a href="index.php?topic='.$topic.'&amp;page=1">'.text::output($topicRes['name']).'</a> / Удаление постов</div>';
  19.  
  20. if (isset ($_POST['yes'])){
  21. $dc = $_SESSION['dc'];
  22. foreach ($dc as $delid){
  23.  
  24. $fileReq = $sql->query("SELECT * FROM `forum_files` WHERE `refid` = '$delid' ");
  25. if ($sql->num_rows()){
  26. while ($fileRes = $sql->fetch()){
  27. unlink('../forum/files/attach/'.$fileRes['name']);
  28. }
  29. $sql->query("DELETE FROM `forum_files` WHERE `refid` = '$delid' LIMIT 1 ", true);
  30. }
  31. $postRes = $sql->query("SELECT `user_id`, `rating` FROM `forum_posts` WHERE `id` = '$delid' LIMIT 1 ")->fetch();
  32. ++$i;
  33. if ($postRes['rating'])
  34. $sql->query("DELETE FROM `forum_posts_rating` WHERE `refid` = '$delid' ");
  35.  
  36. $sql->query("DELETE FROM `forum_posts` WHERE `id` = '$delid' LIMIT 1 ");
  37. }
  38.  
  39. $lastPost = $sql->query("SELECT `id`, `time`, `user` FROM `forum_posts` WHERE `refid` = '$topic' ORDER BY `time` DESC LIMIT 1 ")->fetch();
  40.  
  41. $sql->query("UPDATE `forum_topics` SET
  42. `time` = '".$lastPost['time']."',
  43. `lastpost` = '".$lastPost['user'].":|:".$lastPost['id']."',
  44. `count` = count - $i
  45. WHERE `id` = '$topic' LIMIT 1 ");
  46.  
  47. $lastTopic = $sql->query("SELECT * FROM `forum_topics` WHERE `refid` = '".$topicRes['refid']."' ORDER BY `time` DESC LIMIT 1 ")->result();
  48. $sql->query("UPDATE `forum_forums` SET
  49. `last_topic`='".$lastTopic['refid'].":|:".$lastTopic['name'].":|:".$lastTopic['time']."'
  50. WHERE `id`='".$topicRes['refid']."' LIMIT 1 ");
  51.  
  52. header ('Refresh:1; URL=index.php?topic='.$topic.'&page=1');
  53. echo '<div class="msg">Отмеченные посты удалены<br /><a href="index.php?topic='.$topic.'&amp;page=1">Далее</a></div>';
  54. }elseif(isset($_POST['no'])){
  55. header ('Location: index.php?topic='.$topic.'&page=end');
  56. }else{
  57. if (empty ($_POST['delch'])){
  58. echo Core::msg_show('Вы ничего не выбрали для удаления!<br /><a href="index.php?topic='.$topic.'&amp;page=1">Назад</a>');
  59. include H . 'engine/includes/foot.php';
  60. }
  61. foreach ($_POST['delch'] as $v){
  62. $dc[] = intval($v);
  63. ++$i;
  64. }
  65. $_SESSION['dc'] = $dc;
  66.  
  67. $check = $sql->query("SELECT COUNT(*) FROM `forum_posts` WHERE `refid` = '$topic' ")->result();
  68. if ($check == $i){
  69. echo '<form action="index.php?act=deltopic&amp;topic='.$topic.'" method="post"><div class="rm">Вы собираетесь удалить все посты в теме, при удалении будет удалена и тема<br />';
  70. if ($moder)
  71. echo '<input type="submit" name="yes" value="Удалить" /> ';
  72. echo '<input type="submit" name="no" value="Отмена" /></div></form>';
  73. include H . 'engine/includes/foot.php';
  74. }
  75.  
  76. $firstPost = $sql->query("SELECT `id` FROM `forum_posts` WHERE `refid` = '$topic' ORDER BY `time` ASC LIMIT 1 ")->fetch();
  77. echo '<form action="index.php?act=massdelpost&amp;topic='.$topic.'&amp;page=1" method="post"><div class="rmenu">'.(in_array($firstPost['id'], $_POST['delch']) ? 'В числе выбранного есть первый пост темы, его удаление не рекомендуется!<br />' : '').'Вы уверены в удалении сообщений ('.$i.' шт.)?<br />';
  78. echo '<input type="submit" name="yes" value="Удалить" /> <input type="submit" name="no" value="Отмена" /></div></form>';
  79. }