Просмотр файла forum/includes/addpost.php

Размер файла: 5.75Kb
  1. <?php
  2. # Script by seg0ro http://mobilarts.ru
  3. # Not for sale!!!
  4.  
  5. # fixed
  6.  
  7. $set['title'] .= ' | Новое сообщение';
  8. include H . 'engine/includes/head.php';
  9. $cur_page = isset($_GET['page']) ? intval($_GET['page']) : 1;
  10. if (!$topic){
  11. echo Core::msg_show('Отсутствует идентификатор темы!<br /><a href="index.php">Форум</a>');
  12. include H . 'engine/includes/foot.php';
  13. }
  14. $quote = isset($_GET['quote']) ? '&amp;quote' : '';
  15. $text = isset($_POST['text']) ? trim($_POST['text']) : '';
  16. $quoteText = '';
  17. $max_size = include H.'engine/includes/max_file_size.php';
  18.  
  19. if (!$user_id || ($topicRes['close'] && (!$moder))){
  20. echo Core::msg_show('У вас недостаточно прав для просмотра этой страницы!<br /><a href="index.php">Форум</a>');
  21. include H . 'engine/includes/foot.php';
  22. }
  23.  
  24. if (empty($_SESSION['tempid']))
  25. $_SESSION['tempid'] = mt_rand(1111, 9999).$user_id;
  26.  
  27.  
  28. echo '<div class="fmenu"><a href="index.php">Форум</a> / <a href="index.php?topic='.$topicRes['id'].'&amp;page='.$cur_page.'">'.text::output($topicRes['name']).'</a> / Новое сообщение</div>';
  29.  
  30.  
  31. if ($post){
  32. $res = $postRes;
  33.  
  34. if (isset($_GET['quote'])){
  35. $quoteText = isset($_POST['quote']) ? trim($_POST['quote']) : trim(preg_replace('#\[quote=(.*?)\](.*?)\[/quote\]#si', '', $postRes['text']));
  36. }else{
  37. $text = isset($_POST['text']) ? trim($_POST['text']) : '[b]'.$postRes['user'].'[/b], ';
  38. }
  39. }
  40.  
  41. if (isset($_POST['addfile']) && $_FILES['file']['name']){
  42. $postId = 0;
  43. $topicId = $topic;
  44. $tempId = $_SESSION['tempid'];
  45. require_once ('includes/fileupload.php');
  46. }
  47.  
  48. if (isset($_POST['delfile'])){
  49. $array = $_POST['delfile'];
  50. if (is_array($array)){
  51. foreach ($array as $file => $val){
  52. require_once ('includes/delfile.php');
  53. }
  54. }else{
  55. $error = 'Возникла ошибка при удалении файла!';
  56. }
  57. }
  58.  
  59. $fileReq = mysqli_query($sql->db, "SELECT * FROM `forum_files` WHERE `tempid` = '".intval($_SESSION['tempid'])."' LIMIT 11 ");
  60. $total = $sql->num_rows($fileReq);
  61.  
  62. if (isset($_POST['send'])){
  63.  
  64. if (!$text || ($post && $text == '[b]'.$postRes['user'].'[/b],'))
  65. $error .= 'Не введен текст сообщения!<br />';
  66. if ($quote && !$quoteText)
  67. $error .= 'Не введен текст цитаты!<br />';
  68.  
  69. if (!isset($error)){
  70. $quoteText = $quote ? '[quote='.$postRes['user'].']'.$quoteText.'[/quote]' : '';
  71. $sql->query("SELECT * FROM `forum_posts` WHERE `user_id` = '$user_id' AND `refid` = '$topic' ORDER BY `time` DESC LIMIT 1 ");
  72. if ($sql->num_rows() > 0){
  73. $checkText = $sql->fetch();
  74. if ($checkText['text'] == $quoteText.$text) {
  75. echo Core::msg_show('Такое сообщение уже было!<br /><a href="index.php?topic='.$topic.'&amp;page='.$cur_page.'">Назад</a>');
  76. include H . 'engine/includes/foot.php';
  77. }
  78. }
  79.  
  80. $sql->query("INSERT INTO `forum_posts` SET
  81. `refid` = '$topic',
  82. `time` = '$time',
  83. `user_id` = '$user_id',
  84. `user` = '$user[nick]',
  85. `text` = '".my_esc($quoteText.$text)."',
  86. `files` = '$total'");
  87. $pid = mysqli_insert_id($sql->db);
  88. if ($post)
  89. journal_add($postRes['user_id'], 'Вам ответили в теме: <a href="index.php?post='.$pid.'">'.$topicRes['name'].'</a>');
  90. if ($total){
  91. $sql->query("UPDATE `forum_files` SET
  92. `refid` = '$pid',
  93. `tempid` = ''
  94. WHERE `tempid` = '".intval($_SESSION['tempid'])."' ");
  95. }
  96.  
  97. $sql->query("UPDATE `forum_topics` SET
  98. `time` = '$time',
  99. `lastpost` = '$user[nick]:|:$pid',
  100. `count` = count + 1 WHERE `id` = '$topic' LIMIT 1 ");
  101.  
  102. $sql->query("UPDATE `forum_forums` SET `last_topic` = '$topic:|:".$topicRes['name'].":|:$time' WHERE `id` = '".$topicRefid['id']."' LIMIT 1 ");
  103.  
  104. unset ($_SESSION['tempid'], $_SESSION['filename']);
  105. header ('Location: index.php?topic='.$topic.'&page=end#p'.$pid);
  106. }
  107. }
  108.  
  109. if (isset($error))
  110. echo Core::msg_show($error);
  111.  
  112. if ($text && isset($_POST['preview'])){
  113. $quotePreview = $quote ? '[quote='.$postRes['user'].']'.$quoteText.'[/quote]' : '';
  114. $textPreview = quote(text::output($quotePreview.$text));
  115.  
  116. echo '<div class="p_m"><strong>Предпросмотр:</strong><br />'.$textPreview.'</div>';
  117. }
  118.  
  119. echo '<form id="form" name="form" action="index.php?act=addpost&amp;topic='.$topic.($post ? '&amp;post='.$post : '').$quote.'&amp;page='.$cur_page.'" method="post" enctype="multipart/form-data">';
  120. echo '<div class="msg">'.($quote ? 'Цитата ('.$postRes['user'].'):<br /><textarea name="quote">'.htmlspecialchars($quoteText).'</textarea><br />' : '').'Текст:<br /><textarea name="text">'.htmlspecialchars($text).'</textarea><br /><input type="submit" name="send" value="Отправить" /> <input type="submit" name="preview" value="Предпросм." /></div>';
  121.  
  122. echo '<div class="fmenu">Файлы: '.$total.' из 10</div>';
  123. if ($total){
  124. while ($fileRes = mysqli_fetch_assoc($fileReq)){
  125. echo $i % 2 ? '<div class="p_t">' : '<div class="p_m">';
  126. echo show_file($fileRes);
  127. echo '<div class="sub"><input type="submit" name="delfile['.$fileRes['id'].']" onclick="return confirm(\'Вы действительно хотите удалить файл?\');" value="Удалить" /></div></div>';
  128. ++$i;
  129. }
  130. }
  131. if ($total < 10){
  132. echo '<div class="msg">Файл <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Максимально '.text::size_data($max_size).'" />:<br /><input type="file" name="file" />';
  133. echo '<br /><input type="submit" name="addfile" value="Прикрепить" /></div>';
  134. }
  135. echo '</form>';