PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/moderate.php

https://bitbucket.org/ametaireau/reseaugrappe-forums
PHP | 716 lines | 482 code | 159 blank | 75 comment | 107 complexity | 958352557a269adaa9cf6c261e113823 MD5 | raw file
  1. <?php
  2. /***********************************************************************
  3. Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org)
  4. This file is part of PunBB.
  5. PunBB is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published
  7. by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. PunBB is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  16. MA 02111-1307 USA
  17. ************************************************************************/
  18. define('PUN_ROOT', './');
  19. require PUN_ROOT.'include/common.php';
  20. // This particular function doesn't require forum-based moderator access. It can be used
  21. // by all moderators and admins.
  22. if (isset($_GET['get_host']))
  23. {
  24. if ($pun_user['g_id'] > PUN_MOD)
  25. message($lang_common['No permission']);
  26. // Is get_host an IP address or a post ID?
  27. if (@preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $_GET['get_host']))
  28. $ip = $_GET['get_host'];
  29. else
  30. {
  31. $get_host = intval($_GET['get_host']);
  32. if ($get_host < 1)
  33. message($lang_common['Bad request']);
  34. $result = $db->query('SELECT poster_ip FROM '.$db->prefix.'posts WHERE id='.$get_host) or error('Unable to fetch post IP address', __FILE__, __LINE__, $db->error());
  35. if (!$db->num_rows($result))
  36. message($lang_common['Bad request']);
  37. $ip = $db->result($result);
  38. }
  39. message('L\'adresse IP est : '.$ip.'<br />Le nom de l\'hôte est : '.@gethostbyaddr($ip).'<br /><br /><a href="admin_users.php?show_users='.$ip.'">Voir plus d\'utilisateurs pour cette IP</a>');
  40. }
  41. // All other functions require moderator/admin access
  42. $fid = isset($_GET['fid']) ? intval($_GET['fid']) : 0;
  43. if ($fid < 1)
  44. message($lang_common['Bad request']);
  45. $result = $db->query('SELECT moderators FROM '.$db->prefix.'forums WHERE id='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  46. $moderators = $db->result($result);
  47. $mods_array = ($moderators != '') ? unserialize($moderators) : array();
  48. if ($pun_user['g_id'] != PUN_ADMIN && ($pun_user['g_id'] != PUN_MOD || !array_key_exists($pun_user['username'], $mods_array)))
  49. message($lang_common['No permission']);
  50. // Load the misc.php language file
  51. require PUN_ROOT.'lang/'.$pun_user['language'].'/misc.php';
  52. // All other topic moderation features require a topic id in GET
  53. if (isset($_GET['tid']))
  54. {
  55. $tid = intval($_GET['tid']);
  56. if ($tid < 1)
  57. message($lang_common['Bad request']);
  58. // Fetch some info about the topic
  59. $result = $db->query('SELECT t.subject, t.num_replies, f.id AS forum_id, forum_name FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$fid.' AND t.id='.$tid.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
  60. if (!$db->num_rows($result))
  61. message($lang_common['Bad request']);
  62. $cur_topic = $db->fetch_assoc($result);
  63. // Delete one or more posts
  64. if (isset($_POST['delete_posts']) || isset($_POST['delete_posts_comply']))
  65. {
  66. $posts = $_POST['posts'];
  67. if (empty($posts))
  68. message($lang_misc['No posts selected']);
  69. if (isset($_POST['delete_posts_comply']))
  70. {
  71. confirm_referrer('moderate.php');
  72. if (@preg_match('/[^0-9,]/', $posts))
  73. message($lang_common['Bad request']);
  74. // Verify that the post IDs are valid
  75. $result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id IN('.$posts.') AND topic_id='.$tid) or error('Unable to check posts', __FILE__, __LINE__, $db->error());
  76. if ($db->num_rows($result) != substr_count($posts, ',') + 1)
  77. message($lang_common['Bad request']);
  78. // Delete the posts
  79. $db->query('DELETE FROM '.$db->prefix.'posts WHERE id IN('.$posts.')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
  80. require PUN_ROOT.'include/search_idx.php';
  81. strip_search_index($posts);
  82. // Get last_post, last_post_id, and last_poster for the topic after deletion
  83. $result = $db->query('SELECT id, poster, posted FROM '.$db->prefix.'posts WHERE topic_id='.$tid.' ORDER BY id DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  84. $last_post = $db->fetch_assoc($result);
  85. // How many posts did we just delete?
  86. $num_posts_deleted = substr_count($posts, ',') + 1;
  87. // Update the topic
  88. $db->query('UPDATE '.$db->prefix.'topics SET last_post='.$last_post['posted'].', last_post_id='.$last_post['id'].', last_poster=\''.$db->escape($last_post['poster']).'\', num_replies=num_replies-'.$num_posts_deleted.' WHERE id='.$tid) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
  89. update_forum($fid);
  90. redirect('viewtopic.php?id='.$tid, $lang_misc['Delete posts redirect']);
  91. }
  92. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_misc['Moderate'];
  93. require PUN_ROOT.'header.php';
  94. ?>
  95. <div class="blockform">
  96. <h2><span><?php echo $lang_misc['Delete posts'] ?></span></h2>
  97. <div class="box">
  98. <form method="post" action="moderate.php?fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
  99. <div class="inform">
  100. <fieldset>
  101. <legend><?php echo $lang_misc['Confirm delete legend'] ?></legend>
  102. <div class="infldset">
  103. <input type="hidden" name="posts" value="<?php echo implode(',', array_keys($posts)) ?>" />
  104. <p><?php echo $lang_misc['Delete posts comply'] ?></p>
  105. </div>
  106. </fieldset>
  107. </div>
  108. <p><input type="submit" name="delete_posts_comply" value="<?php echo $lang_misc['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  109. </form>
  110. </div>
  111. </div>
  112. <?php
  113. require PUN_ROOT.'footer.php';
  114. }
  115. // Show the delete multiple posts view
  116. // Load the viewtopic.php language file
  117. require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
  118. // Used to disable the Move and Delete buttons if there are no replies to this topic
  119. $button_status = ($cur_topic['num_replies'] == 0) ? ' disabled' : '';
  120. // Determine the post offset (based on $_GET['p'])
  121. $num_pages = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
  122. $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
  123. $start_from = $pun_user['disp_posts'] * ($p - 1);
  124. // Generate paging links
  125. $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'moderate.php?fid='.$fid.'&amp;tid='.$tid);
  126. if ($pun_config['o_censoring'] == '1')
  127. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  128. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$cur_topic['subject'];
  129. require PUN_ROOT.'header.php';
  130. ?>
  131. <div class="linkst">
  132. <div class="inbox">
  133. <p class="pagelink conl"><?php echo $paging_links ?></p>
  134. <ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li><li>&nbsp;&raquo;&nbsp;<a href="viewforum.php?id=<?php echo $fid ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li><li>&nbsp;&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_topic['subject']) ?></li></ul>
  135. <div class="clearer"></div>
  136. </div>
  137. </div>
  138. <form method="post" action="moderate.php?fid=<?php echo $fid ?>&amp;tid=<?php echo $tid ?>">
  139. <?php
  140. require PUN_ROOT.'include/parser.php';
  141. $bg_switch = true; // Used for switching background color in posts
  142. $post_count = 0; // Keep track of post numbers
  143. // Retrieve the posts (and their respective poster)
  144. $result = $db->query('SELECT u.title, u.num_posts, g.g_id, g.g_user_title, p.id, p.poster, p.poster_id, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE p.topic_id='.$tid.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  145. while ($cur_post = $db->fetch_assoc($result))
  146. {
  147. $post_count++;
  148. // If the poster is a registered user.
  149. if ($cur_post['poster_id'] > 1)
  150. {
  151. $poster = '<a href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['poster']).'</a>';
  152. // get_title() requires that an element 'username' be present in the array
  153. $cur_post['username'] = $cur_post['poster'];
  154. $user_title = get_title($cur_post);
  155. if ($pun_config['o_censoring'] == '1')
  156. $user_title = censor_words($user_title);
  157. }
  158. // If the poster is a guest (or a user that has been deleted)
  159. else
  160. {
  161. $poster = pun_htmlspecialchars($cur_post['poster']);
  162. $user_title = $lang_topic['Guest'];
  163. }
  164. // Switch the background color for every message.
  165. $bg_switch = ($bg_switch) ? $bg_switch = false : $bg_switch = true;
  166. $vtbg = ($bg_switch) ? ' roweven' : ' rowodd';
  167. // Perform the main parsing of the message (BBCode, smilies, censor words etc)
  168. $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
  169. ?>
  170. <div class="blockpost<?php echo $vtbg ?>">
  171. <a name="<?php echo $cur_post['id'] ?>"></a>
  172. <h2><span><span class="conr">#<?php echo ($start_from + $post_count) ?>&nbsp;</span><a href="viewtopic.php?pid=<?php echo $cur_post['id'].'#p'.$cur_post['id'] ?>"><?php echo format_time($cur_post['posted']) ?></a></span></h2>
  173. <div class="box">
  174. <div class="inbox">
  175. <div class="postleft">
  176. <dl>
  177. <dt><strong><?php echo $poster ?></strong></dt>
  178. <dd><strong><?php echo $user_title ?></strong></dd>
  179. </dl>
  180. </div>
  181. <div class="postright">
  182. <h3 class="nosize"><?php echo $lang_common['Message'] ?></h3>
  183. <div class="postmsg">
  184. <?php echo $cur_post['message']."\n" ?>
  185. <?php if ($cur_post['edited'] != '') echo "\t\t\t\t\t".'<p class="postedit"><em>'.$lang_topic['Last edit'].' '.pun_htmlspecialchars($cur_post['edited_by']).' ('.format_time($cur_post['edited']).')</em></p>'."\n"; ?>
  186. </div>
  187. <?php if ($start_from + $post_count > 1) echo '<p class="multidelete"><label><strong>'.$lang_misc['Select'].'</strong>&nbsp;&nbsp;<input type="checkbox" name="posts['.$cur_post['id'].']" value="1" /></label></p>'."\n" ?>
  188. </div>
  189. <div class="clearer"></div>
  190. </div>
  191. </div>
  192. </div>
  193. <?php
  194. }
  195. ?>
  196. <div class="postlinksb">
  197. <div class="inbox">
  198. <p class="pagelink conl"><?php echo $paging_links ?></p>
  199. <p class="conr"><input type="submit" name="delete_posts" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> /></p>
  200. <div class="clearer"></div>
  201. </div>
  202. </div>
  203. </form>
  204. <?php
  205. require PUN_ROOT.'footer.php';
  206. }
  207. // Move one or more topics
  208. if (isset($_REQUEST['move_topics']) || isset($_POST['move_topics_to']))
  209. {
  210. if (isset($_POST['move_topics_to']))
  211. {
  212. confirm_referrer('moderate.php');
  213. if (@preg_match('/[^0-9,]/', $_POST['topics']))
  214. message($lang_common['Bad request']);
  215. $topics = explode(',', $_POST['topics']);
  216. $move_to_forum = isset($_POST['move_to_forum']) ? intval($_POST['move_to_forum']) : 0;
  217. if (empty($topics) || $move_to_forum < 1)
  218. message($lang_common['Bad request']);
  219. // Verify that the topic IDs are valid
  220. $result = $db->query('SELECT 1 FROM '.$db->prefix.'topics WHERE id IN('.implode(',',$topics).') AND forum_id='.$fid) or error('Unable to check topics', __FILE__, __LINE__, $db->error());
  221. if ($db->num_rows($result) != count($topics))
  222. message($lang_common['Bad request']);
  223. // Delete any redirect topics if there are any (only if we moved/copied the topic back to where it where it was once moved from)
  224. $db->query('DELETE FROM '.$db->prefix.'topics WHERE forum_id='.$move_to_forum.' AND moved_to IN('.implode(',',$topics).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
  225. // Move the topic(s)
  226. $db->query('UPDATE '.$db->prefix.'topics SET forum_id='.$move_to_forum.' WHERE id IN('.implode(',',$topics).')') or error('Unable to move topics', __FILE__, __LINE__, $db->error());
  227. // Should we create redirect topics?
  228. if (isset($_POST['with_redirect']))
  229. {
  230. while (list(, $cur_topic) = @each($topics))
  231. {
  232. // Fetch info for the redirect topic
  233. $result = $db->query('SELECT poster, subject, posted, last_post FROM '.$db->prefix.'topics WHERE id='.$cur_topic) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
  234. $moved_to = $db->fetch_assoc($result);
  235. // Create the redirect topic
  236. $db->query('INSERT INTO '.$db->prefix.'topics (poster, subject, posted, last_post, moved_to, forum_id) VALUES(\''.$db->escape($moved_to['poster']).'\', \''.$db->escape($moved_to['subject']).'\', '.$moved_to['posted'].', '.$moved_to['last_post'].', '.$cur_topic.', '.$fid.')') or error('Unable to create redirect topic', __FILE__, __LINE__, $db->error());
  237. }
  238. }
  239. update_forum($fid); // Update the forum FROM which the topic was moved
  240. update_forum($move_to_forum); // Update the forum TO which the topic was moved
  241. $redirect_msg = (count($topics) > 1) ? $lang_misc['Move topics redirect'] : $lang_misc['Move topic redirect'];
  242. redirect('viewforum.php?id='.$move_to_forum, $redirect_msg);
  243. }
  244. if (isset($_POST['move_topics']))
  245. {
  246. $topics = isset($_POST['topics']) ? $_POST['topics'] : array();
  247. if (empty($topics))
  248. message($lang_misc['No topics selected']);
  249. $topics = implode(',', array_keys($topics));
  250. $action = 'multi';
  251. }
  252. else
  253. {
  254. $topics = intval($_GET['move_topics']);
  255. if ($topics < 1)
  256. message($lang_common['Bad request']);
  257. $action = 'single';
  258. }
  259. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_misc['Moderate'];
  260. require PUN_ROOT.'header.php';
  261. ?>
  262. <div class="blockform">
  263. <h2><span><?php echo ($action == 'single') ? $lang_misc['Move topic'] : $lang_misc['Move topics'] ?></span></h2>
  264. <div class="box">
  265. <form method="post" action="moderate.php?fid=<?php echo $fid ?>">
  266. <div class="inform">
  267. <input type="hidden" name="topics" value="<?php echo $topics ?>" />
  268. <fieldset>
  269. <legend><?php echo $lang_misc['Move legend'] ?></legend>
  270. <div class="infldset">
  271. <label><?php echo $lang_misc['Move to'] ?>
  272. <br /><select name="move_to_forum">
  273. <?php
  274. $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
  275. $cur_category = 0;
  276. while ($cur_forum = $db->fetch_assoc($result))
  277. {
  278. if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
  279. {
  280. if ($cur_category)
  281. echo "\t\t\t\t\t\t\t".'</optgroup>'."\n";
  282. echo "\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
  283. $cur_category = $cur_forum['cid'];
  284. }
  285. if ($cur_forum['fid'] != $fid)
  286. echo "\t\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</option>'."\n";
  287. }
  288. ?>
  289. </optgroup>
  290. </select>
  291. <br /></label>
  292. <div class="rbox">
  293. <label><input type="checkbox" name="with_redirect" value="1"<?php if ($action == 'single') echo ' checked="checked"' ?> /><?php echo $lang_misc['Leave redirect'] ?><br /></label>
  294. </div>
  295. </div>
  296. </fieldset>
  297. </div>
  298. <p><input type="submit" name="move_topics_to" value="<?php echo $lang_misc['Move'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  299. </form>
  300. </div>
  301. </div>
  302. <?php
  303. require PUN_ROOT.'footer.php';
  304. }
  305. // Delete one or more topics
  306. if (isset($_REQUEST['delete_topics']) || isset($_POST['delete_topics_comply']))
  307. {
  308. $topics = isset($_POST['topics']) ? $_POST['topics'] : array();
  309. if (empty($topics))
  310. message($lang_misc['No topics selected']);
  311. if (isset($_POST['delete_topics_comply']))
  312. {
  313. confirm_referrer('moderate.php');
  314. if (@preg_match('/[^0-9,]/', $topics))
  315. message($lang_common['Bad request']);
  316. require PUN_ROOT.'include/search_idx.php';
  317. // Verify that the topic IDs are valid
  318. $result = $db->query('SELECT 1 FROM '.$db->prefix.'topics WHERE id IN('.$topics.') AND forum_id='.$fid) or error('Unable to check topics', __FILE__, __LINE__, $db->error());
  319. if ($db->num_rows($result) != substr_count($topics, ',') + 1)
  320. message($lang_common['Bad request']);
  321. // Delete the topics and any redirect topics
  322. $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.$topics.') OR moved_to IN('.$topics.')') or error('Unable to delete topic', __FILE__, __LINE__, $db->error());
  323. // Delete any subscriptions
  324. $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE topic_id IN('.$topics.')') or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
  325. // Create a list of the post ID's in this topic and then strip the search index
  326. $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.')') or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
  327. $post_ids = '';
  328. while ($row = $db->fetch_row($result))
  329. $post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];
  330. // We have to check that we actually have a list of post ID's since we could be deleting just a redirect topic
  331. if ($post_ids != '')
  332. strip_search_index($post_ids);
  333. // Delete posts
  334. $db->query('DELETE FROM '.$db->prefix.'posts WHERE topic_id IN('.$topics.')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
  335. update_forum($fid);
  336. redirect('viewforum.php?id='.$fid, $lang_misc['Delete topics redirect']);
  337. }
  338. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_misc['Moderate'];
  339. require PUN_ROOT.'header.php';
  340. ?>
  341. <div class="blockform">
  342. <h2><?php echo $lang_misc['Delete topics'] ?></h2>
  343. <div class="box">
  344. <form method="post" action="moderate.php?fid=<?php echo $fid ?>">
  345. <input type="hidden" name="topics" value="<?php echo implode(',', array_keys($topics)) ?>" />
  346. <div class="inform">
  347. <fieldset>
  348. <legend><?php echo $lang_misc['Confirm delete legend'] ?></legend>
  349. <div class="infldset">
  350. <p><?php echo $lang_misc['Delete topics comply'] ?></p>
  351. </div>
  352. </fieldset>
  353. </div>
  354. <p><input type="submit" name="delete_topics_comply" value="<?php echo $lang_misc['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
  355. </form>
  356. </div>
  357. </div>
  358. <?php
  359. require PUN_ROOT.'footer.php';
  360. }
  361. // Open or close one or more topics
  362. else if (isset($_REQUEST['open']) || isset($_REQUEST['close']))
  363. {
  364. $action = (isset($_REQUEST['open'])) ? 0 : 1;
  365. // There could be an array of topic ID's in $_POST
  366. if (isset($_POST['open']) || isset($_POST['close']))
  367. {
  368. confirm_referrer('moderate.php');
  369. $topics = isset($_POST['topics']) ? @array_map('intval', @array_keys($_POST['topics'])) : array();
  370. if (empty($topics))
  371. message($lang_misc['No topics selected']);
  372. $db->query('UPDATE '.$db->prefix.'topics SET closed='.$action.' WHERE id IN('.implode(',', $topics).') AND forum_id='.$fid) or error('Unable to close topics', __FILE__, __LINE__, $db->error());
  373. $redirect_msg = ($action) ? $lang_misc['Close topics redirect'] : $lang_misc['Open topics redirect'];
  374. redirect('moderate.php?fid='.$fid, $redirect_msg);
  375. }
  376. // Or just one in $_GET
  377. else
  378. {
  379. confirm_referrer('viewtopic.php');
  380. $topic_id = ($action) ? intval($_GET['close']) : intval($_GET['open']);
  381. if ($topic_id < 1)
  382. message($lang_common['Bad request']);
  383. $db->query('UPDATE '.$db->prefix.'topics SET closed='.$action.' WHERE id='.$topic_id.' AND forum_id='.$fid) or error('Unable to close topic', __FILE__, __LINE__, $db->error());
  384. $redirect_msg = ($action) ? $lang_misc['Close topic redirect'] : $lang_misc['Open topic redirect'];
  385. redirect('viewtopic.php?id='.$topic_id, $redirect_msg);
  386. }
  387. }
  388. // Stick a topic
  389. else if (isset($_GET['stick']))
  390. {
  391. confirm_referrer('viewtopic.php');
  392. $stick = intval($_GET['stick']);
  393. if ($stick < 1)
  394. message($lang_common['Bad request']);
  395. $db->query('UPDATE '.$db->prefix.'topics SET sticky=\'1\' WHERE id='.$stick.' AND forum_id='.$fid) or error('Unable to stick topic', __FILE__, __LINE__, $db->error());
  396. redirect('viewtopic.php?id='.$stick, $lang_misc['Stick topic redirect']);
  397. }
  398. // Unstick a topic
  399. else if (isset($_GET['unstick']))
  400. {
  401. confirm_referrer('viewtopic.php');
  402. $unstick = intval($_GET['unstick']);
  403. if ($unstick < 1)
  404. message($lang_common['Bad request']);
  405. $db->query('UPDATE '.$db->prefix.'topics SET sticky=\'0\' WHERE id='.$unstick.' AND forum_id='.$fid) or error('Unable to unstick topic', __FILE__, __LINE__, $db->error());
  406. redirect('viewtopic.php?id='.$unstick, $lang_misc['Unstick topic redirect']);
  407. }
  408. // No specific forum moderation action was specified in the query string, so we'll display the moderator forum
  409. // Load the viewforum.php language file
  410. require PUN_ROOT.'lang/'.$pun_user['language'].'/forum.php';
  411. // Fetch some info about the forum
  412. $result = $db->query('SELECT f.forum_name, f.redirect_url, f.num_topics FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$fid) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  413. if (!$db->num_rows($result))
  414. message($lang_common['Bad request']);
  415. $cur_forum = $db->fetch_assoc($result);
  416. // Is this a redirect forum? In that case, abort!
  417. if ($cur_forum['redirect_url'] != '')
  418. message($lang_common['Bad request']);
  419. $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.pun_htmlspecialchars($cur_forum['forum_name']);
  420. require PUN_ROOT.'header.php';
  421. // Determine the topic offset (based on $_GET['p'])
  422. $num_pages = ceil($cur_forum['num_topics'] / $pun_user['disp_topics']);
  423. $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : $_GET['p'];
  424. $start_from = $pun_user['disp_topics'] * ($p - 1);
  425. // Generate paging links
  426. $paging_links = $lang_common['Pages'].': '.paginate($num_pages, $p, 'moderate.php?fid='.$fid)
  427. ?>
  428. <div class="linkst">
  429. <div class="inbox">
  430. <p class="pagelink conl"><?php echo $paging_links ?></p>
  431. <ul><li><a href="index.php"><?php echo $lang_common['Index'] ?></a>&nbsp;</li><li>&raquo;&nbsp;<?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></li></ul>
  432. <div class="clearer"></div>
  433. </div>
  434. </div>
  435. <form method="post" action="moderate.php?fid=<?php echo $fid ?>">
  436. <div id="vf" class="blocktable">
  437. <h2><span><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></span></h2>
  438. <div class="box">
  439. <div class="inbox">
  440. <table cellspacing="0">
  441. <thead>
  442. <tr>
  443. <th class="tcl" scope="col"><?php echo $lang_common['Topic'] ?></th>
  444. <th class="tc2" scope="col"><?php echo $lang_common['Replies'] ?></th>
  445. <th class="tc3" scope="col"><?php echo $lang_forum['Views'] ?></th>
  446. <th class="tcr"><?php echo $lang_common['Last post'] ?></th>
  447. <th class="tcmod" scope="col"><?php echo $lang_misc['Select'] ?></th>
  448. </tr>
  449. </thead>
  450. <tbody>
  451. <?php
  452. // Select topics
  453. $result = $db->query('SELECT id, poster, subject, posted, last_post, last_post_id, last_poster, num_views, num_replies, closed, sticky, moved_to FROM '.$db->prefix.'topics WHERE forum_id='.$fid.' ORDER BY sticky DESC, last_post DESC LIMIT '.$start_from.', '.$pun_user['disp_topics']) or error('Unable to fetch topic list for forum', __FILE__, __LINE__, $db->error());
  454. // If there are topics in this forum.
  455. if ($db->num_rows($result))
  456. {
  457. $button_status = '';
  458. while ($cur_topic = $db->fetch_assoc($result))
  459. {
  460. $icon_text = $lang_common['Normal icon'];
  461. $item_status = '';
  462. $icon_type = 'icon';
  463. if ($cur_topic['moved_to'] == null)
  464. {
  465. $last_post = '<a href="viewtopic.php?pid='.$cur_topic['last_post_id'].'#p'.$cur_topic['last_post_id'].'">'.format_time($cur_topic['last_post']).'</a> '.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['last_poster']);
  466. $ghost_topic = false;
  467. }
  468. else
  469. {
  470. $last_post = '&nbsp;';
  471. $ghost_topic = true;
  472. }
  473. if ($pun_config['o_censoring'] == '1')
  474. $cur_topic['subject'] = censor_words($cur_topic['subject']);
  475. if ($cur_topic['moved_to'] != 0)
  476. $subject = $lang_forum['Moved'].': <a href="viewtopic.php?id='.$cur_topic['moved_to'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  477. else if ($cur_topic['closed'] == '0')
  478. $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span>'.$lang_common['by'].'&nbsp;'.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  479. else
  480. {
  481. $subject = '<a href="viewtopic.php?id='.$cur_topic['id'].'">'.pun_htmlspecialchars($cur_topic['subject']).'</a> <span class="byuser">'.$lang_common['by'].' '.pun_htmlspecialchars($cur_topic['poster']).'</span>';
  482. $icon_text = $lang_common['Closed icon'];
  483. $item_status = 'iclosed';
  484. }
  485. if ($cur_topic['last_post'] > $pun_user['last_visit'] && !$ghost_topic)
  486. {
  487. $icon_text .= ' '.$lang_common['New icon'];
  488. $item_status .= ' inew';
  489. $icon_type = 'icon inew';
  490. $subject = '<strong>'.$subject.'</strong>';
  491. $subject_new_posts = '<span class="newtext">[&nbsp;<a href="viewtopic.php?id='.$cur_topic['id'].'&amp;action=new" title="'.$lang_common['New posts info'].'">'.$lang_common['New posts'].'</a>&nbsp;]</span>';
  492. }
  493. else
  494. $subject_new_posts = null;
  495. // We won't display "the dot", but we add the spaces anyway
  496. if ($pun_config['o_show_dot'] == '1')
  497. $subject = '&nbsp;&nbsp;'.$subject;
  498. if ($cur_topic['sticky'] == '1')
  499. {
  500. $subject = '<span class="stickytext">'.$lang_forum['Sticky'].': </span>'.$subject;
  501. $item_status .= ' isticky';
  502. $icon_text .= ' '.$lang_forum['Sticky'];
  503. }
  504. $num_pages_topic = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
  505. if ($num_pages_topic > 1)
  506. $subject_multipage = '[ '.paginate($num_pages_topic, -1, 'viewtopic.php?id='.$cur_topic['id']).' ]';
  507. else
  508. $subject_multipage = null;
  509. // Should we show the "New posts" and/or the multipage links?
  510. if (!empty($subject_new_posts) || !empty($subject_multipage))
  511. {
  512. $subject .= '&nbsp; '.(!empty($subject_new_posts) ? $subject_new_posts : '');
  513. $subject .= !empty($subject_multipage) ? ' '.$subject_multipage : '';
  514. }
  515. ?>
  516. <tr<?php if ($item_status != '') echo ' class="'.trim($item_status).'"'; ?>>
  517. <td class="tcl">
  518. <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo trim($icon_text) ?></div></div>
  519. <div class="tclcon">
  520. <?php echo $subject."\n" ?>
  521. </div>
  522. </td>
  523. <td class="tc2"><?php echo (!$ghost_topic) ? $cur_topic['num_replies'] : '&nbsp;' ?></td>
  524. <td class="tc3"><?php echo (!$ghost_topic) ? $cur_topic['num_views'] : '&nbsp;' ?></td>
  525. <td class="tcr"><?php echo $last_post ?></td>
  526. <td class="tcmod"><input type="checkbox" name="topics[<?php echo $cur_topic['id'] ?>]" value="1" /></td>
  527. </tr>
  528. <?php
  529. }
  530. }
  531. else
  532. {
  533. $button_status = ' disabled';
  534. echo "\t\t\t\t\t".'<tr><td class="tcl" colspan="5">'.$lang_forum['Empty forum'].'</td></tr>'."\n";
  535. }
  536. ?>
  537. </tbody>
  538. </table>
  539. </div>
  540. </div>
  541. </div>
  542. <div class="linksb">
  543. <div class="inbox">
  544. <p class="pagelink conl"><?php echo $paging_links ?></p>
  545. <p class="conr"><input type="submit" name="move_topics" value="<?php echo $lang_misc['Move'] ?>"<?php echo $button_status ?> />&nbsp;&nbsp;<input type="submit" name="delete_topics" value="<?php echo $lang_misc['Delete'] ?>"<?php echo $button_status ?> />&nbsp;&nbsp;<input type="submit" name="open" value="<?php echo $lang_misc['Open'] ?>"<?php echo $button_status ?> />&nbsp;&nbsp;<input type="submit" name="close" value="<?php echo $lang_misc['Close'] ?>"<?php echo $button_status ?> /></p>
  546. <div class="clearer"></div>
  547. </div>
  548. </div>
  549. </form>
  550. <?php
  551. require PUN_ROOT.'footer.php';