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

Размер файла: 9.9Kb
  1. <?php
  2. # Script by seg0ro http://mobilarts.ru
  3. # Not for sale!!!
  4.  
  5.  
  6.  
  7. $set['title'] .= ' | Редактирование';
  8. include H . 'engine/includes/head.php';
  9.  
  10. if (!$topic){
  11. Core::msg_show('Отсутствует идентификатор темы!<br /><a href="index.php">Форум</a>');
  12. include H . 'engine/includes/foot.php';
  13. }
  14.  
  15. if (!$moder){
  16. Core::msg_show('У вас недостаточно прав для просмотра этой страницы!<br /><a href="index.php">Форум</a>');
  17. include H . 'engine/includes/foot.php';
  18. }
  19.  
  20. $name = isset($_POST['name']) ? trim($_POST['name']) : $topicRes['name'];
  21. $pollName = isset($_POST['poll_name']) ? trim($_POST['poll_name']) : $topicRes['poll_name'];
  22.  
  23. echo '<div class="fmenu"><a href="index.php">Форум</a> / <a href="index.php?topic='.$topicRes['id'].'&amp;page=1">'.text::output($topicRes['name']).'</a> / Изменить тему</div>';
  24.  
  25.  
  26. if (isset($_POST['send'])){
  27. if (empty($name))
  28. $error .= 'Не введено название!<br />';
  29.  
  30. if (!isset($error)){
  31.  
  32. $sql->query("UPDATE `forum_topics` SET
  33. `name` = '".my_esc($name)."',
  34. `close` = '".(isset($_POST['close']) ? 1 : 0)."',
  35. `sticky` = '".(isset($_POST['sticky']) ? 1 : 0)."',
  36. `clip` = '".(isset($_POST['clip']) ? 1 : 0)."'
  37. WHERE `id` = '$topic'
  38. ");
  39. if ($topicRes['name'] != $name){
  40. $sql->query("INSERT INTO `forum_posts` SET
  41. `refid` = '$topic',
  42. `time` = '".time()."',
  43. `user_id` = '2',
  44. `user` = 'Система',
  45. `text` = 'Тема переименована (cтарое название [b]".$topicRes['name']."[/b])',
  46. `files` = '0'");
  47. $pid = mysqli_insert_id($sql->db);
  48. if ($topicRes['user_id'] != $user_id)
  49. journal_add($topicRes['user_id'], 'Ваша <a href="index.php?post='.$pid.'">тема</a> переименована (cтарое название <strong>'.$topicRes['name'].'</strong>)');
  50. $sql->query("UPDATE `forum_topics` SET
  51. `time` = '".time()."',
  52. `lastpost` = '$user[nick]:|:$pid',
  53. `count` = count + 1 WHERE `id` = '$topic' LIMIT 1 ");
  54. $sql->query("UPDATE `forum_forums` SET `last_topic` = '$topic:|:$name:|:".time()."' WHERE `id` = '".$topicRes['refid']."' LIMIT 1 ");
  55.  
  56. }
  57. if ($moder){
  58. $user2 = $sql->query("SELECT `id`, `group_access` FROM `user` WHERE `id` = '".abs(intval($_POST['curator']))."' LIMIT 1 ")->fetch();
  59. if ($user2['group_access'] == 1 && intval($_POST['curator']) != $user_id)
  60. $sql->query("UPDATE `forum_topics` SET `curator` = '".abs(intval($_POST['curator']))."' WHERE `id` = '$topic' ");
  61. }
  62. header ('Refresh:1; URL=index.php?topic='.$topic.'&page=end');
  63. echo '<div class="post">Тема изменена<br /><a href="index.php?topic='.$topic.'&amp;page=end">Далее</a></div>';
  64. include H . 'engine/includes/foot.php';
  65. }
  66. }
  67.  
  68. if (isset($_GET['closepoll'])){
  69. $pollSet = array('poll_mod' => $pollSet['poll_mod'], 'total_polls' => $pollSet['total_polls'], 'total_polled' => $pollSet['total_polled'], 'poll_close' => 1);
  70. $sql->query("UPDATE `forum_topics` SET
  71. `poll_set` = '".serialize($pollSet)."'
  72. WHERE `id`='$topic'
  73. ");
  74. $pollSet['poll_close'] = 1;
  75. }
  76.  
  77. if (isset($_GET['openpoll'])){
  78. $pollSet = array('poll_mod' => $pollSet['poll_mod'], 'total_polls' => $pollSet['total_polls'], 'total_polled' => $pollSet['total_polled'], 'poll_close' => 0);
  79. $sql->query("UPDATE `forum_topics` SET
  80. `poll_set` = '".serialize($pollSet)."'
  81. WHERE `id` = '$topic'
  82. ");
  83. $pollSet['poll_close'] = 0;
  84. }
  85.  
  86. if (isset($_POST['poll'])){
  87. if (empty($_POST['poll_name']))
  88. $error .= 'Вы не ввели имя голосования!<br />';
  89. if (!$topicRes['poll_name'] && (empty($_POST[0]) || empty($_POST[1])))
  90. $error .= 'Не введены как минимум два варианта голосования!<br />';
  91. if (!$error){
  92. if ($topicRes['poll_name']){
  93. $pollSet = array('poll_mod' => $pollSet['poll_mod'], 'total_polls' => $pollSet['total_polls'], 'total_polled' => $pollSet['total_polled'], 'poll_close' => $pollSet['poll_close']);
  94. $sql->query("UPDATE `forum_topics` SET
  95. `poll_name` = '$pollName',
  96. `poll_set` = '".serialize($pollSet)."'
  97. WHERE `id` = '$topic'
  98. ");
  99. while ($pollRes = mysql_fetch_array($pollReq)){
  100. if (!empty ($_POST[$pollRes['id']])){
  101. $text = mb_substr(trim($_POST[$pollRes['id']]), 0, 100);
  102. $sql->query("UPDATE `forum_polls` SET
  103. `name` = '".my_esc($text)."'
  104. WHERE `id` = '".$pollRes['id']."'
  105. ");
  106. }
  107. }
  108. header ('Refresh:1; URL=index.php?topic='.$topic.'&page=end');
  109. echo '<div class="msg">Голосование изменено<br /><a href="index.php?topic='.$topic.'&amp;page=end">Далее</a></div>';
  110. include H . 'engine/includes/foot.php';
  111. }else{
  112. $polName = mb_substr($pollName, 0, 200);
  113. $pollSet = array('poll_mod' => intval($_POST['poll_mod']), 'total_polls' => 0, 'total_polled' => 0, 'poll_close' => 0);
  114. $sql->query("UPDATE `forum_topics` SET
  115. `poll_name` = '".my_esc($pollName)."',
  116. `poll_set` = '".serialize($pollSet)."'
  117. WHERE `id` = '$topic'
  118. ");
  119. if ($_POST['count_vars'] > 20)
  120. $_POST['count_vars'] = 20;
  121. elseif ($_POST['count_vars'] < 2)
  122. $_POST['count_vars'] = 2;
  123. for ($var = 0; $var < $_POST['count_vars']; $var++){
  124. $vars = mb_substr(trim($_POST[$var]), 0, 100);
  125. if (empty($vars)){
  126. continue;
  127. }
  128. $sql->query("INSERT INTO `forum_polls` SET
  129. `refid` = '$topic',
  130. `name` = '".my_esc($vars)."'
  131. ");
  132. }
  133. header ('Refresh:1; URL=index.php?topic='.$topic.'&page='.$page);
  134. echo '<div class="msg">Голосование создано<br /><a href="index.php?topic='.$topic.'&amp;page='.$page.'">Далее</a></div>';
  135. include H . 'engine/includes/foot.php';
  136. }
  137. }
  138. }
  139.  
  140. if (isset($error))
  141. echo Core::msg_show($error);
  142.  
  143. echo '<form id="form" action="index.php?act=edittopic&amp;topic='.$topic.'&amp;page=1" method="post">';
  144. echo '<div class="p_m">Название <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Максимально 100 символов" />:<br /><input type="text" name="name" value="'.text($name).'" /></div>';
  145. echo '<div class="rmenu">';
  146. echo '<label><input type="checkbox" '.($topicRes['clip'] ? 'checked="checked" ' : '').'name="clip" value="1" />&nbsp;Закрепить 1-й пост</label><br />';
  147. echo '<label><input type="checkbox" '.($topicRes['close'] ? 'checked="checked" ' : '').'name="close" value="1" />&nbsp;Закрыть</label><br />';
  148. echo '<label><input type="checkbox" '.($topicRes['sticky'] ? 'checked="checked" ' : '').'name="sticky" value="1" />&nbsp;Закрепить</label><br />';
  149. if ($moder)
  150. echo 'ID куратора: <input type="text" size="5" name="curator" value="'.$topicRes['curator'].'" /><br />';
  151. echo '<input type="submit" name="send" value="Сохранить" /></div>';
  152.  
  153. if ($topicRes['poll_name']){
  154. echo '<div class="fmenu">Голосование <a href="index.php?act=delpoll&amp;topic='.$topic.'">удалить</a> <a href="index.php?act=edittopic&amp;topic='.$topic.'&amp;page=1&amp;'.($pollSet['poll_close'] ? 'openpoll">открыть' : 'closepoll">закрыть').'</a></div>';
  155. echo '<div class="p_m">Название <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Максимально 200 символов" />:<br /><input type="text" name="poll_name" value="'.text($pollName).'" /><br />';
  156. while ($pollRes = $sql->fetch()){
  157. echo 'Вариант '.($i + 1).' <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Максимально 100 символов" />:<br /><input type="text" name="'.$pollRes['id'].'" value="'.text($pollRes['name']).'" /><br />';
  158. ++$i;
  159. }
  160. }else{
  161. echo '<div class="fmenu">Голосование</div>';
  162. echo '<div class="p_m">Название <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Максимально 200 символов" />:<br /><input type="text" name="poll_name" value="'.(isset($_POST['poll_name']) ? htmlspecialchars($_POST['poll_name']) : null).'" /><br />';
  163.  
  164. if (isset($_POST['add']))
  165. ++$_POST['count_vars'];
  166. elseif (isset($_POST['del']))
  167. --$_POST['count_vars'];
  168. if (empty($_POST['count_vars']) || $_POST['count_vars'] < 2)
  169. $_POST['count_vars'] = 2;
  170. elseif ($_POST['count_vars'] > 20)
  171. $_POST['count_vars'] = 20;
  172. for ($vars = 0; $vars < $_POST['count_vars']; $vars++){
  173. echo 'Вариант '.($vars + 1).' <img style="cursor: pointer;" onclick="alert(this.title);" src="images/question.png" alt="?" title="Максимально 100 символов" />:<br /><input type="text" name="'.$vars.'" value="'.(isset($_POST[$vars]) ? htmlspecialchars($_POST[$vars]) : null).'" /><br />';
  174. }
  175. echo '<input type="hidden" name="count_vars" value="'.intval($_POST['count_vars']).'" />';
  176. echo $_POST['count_vars'] < 20 ? '<br /><input type="submit" name="add" value=" + " />' : '';
  177. echo $_POST['count_vars'] > 2 ? '<input type="submit" name="del" value=" - " /><br />' : '<br />';
  178. echo '<label><input type="radio" value="0" name="poll_mod" '.(isset($_POST['poll_mod']) ? 'checked="checked" ' : '').'/> Можно выбирать только один вариант</label><br />
  179. <label><input type="radio" value="1" name="poll_mod" '.(isset($_POST['poll_mod']) ? 'checked="checked" ' : '').'/> Можно выбирать несколько вариантов</label><br />';
  180. }
  181.  
  182. echo '<input type="submit" name="poll" value="Сохранить" /></div></form>';