PageRenderTime 88ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/doweneed/forums/modcp.php

https://bitbucket.org/natis/masscap-main
PHP | 1128 lines | 858 code | 180 blank | 90 comment | 150 complexity | df2ce4118b1b9602abf6a5db0bf455c2 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /***************************************************************************
  3. * modcp.php
  4. * -------------------
  5. * begin : July 4, 2001
  6. * copyright : (C) 2001 The phpBB Group
  7. * email : support@phpbb.com
  8. *
  9. * $Id: modcp.php,v 1.71.2.7 2002/07/19 22:19:34 psotfx Exp $
  10. *
  11. *
  12. ***************************************************************************/
  13. /***************************************************************************
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2 of the License, or
  18. * (at your option) any later version.
  19. *
  20. ***************************************************************************/
  21. /**
  22. * Moderator Control Panel
  23. *
  24. * From this 'Control Panel' the moderator of a forum will be able to do
  25. * mass topic operations (locking/unlocking/moving/deleteing), and it will
  26. * provide an interface to do quick locking/unlocking/moving/deleting of
  27. * topics via the moderator operations buttons on all of the viewtopic pages.
  28. */
  29. define('IN_PHPBB', true);
  30. $phpbb_root_path = './';
  31. include($phpbb_root_path . 'extension.inc');
  32. include($phpbb_root_path . 'common.'.$phpEx);
  33. include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
  34. include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
  35. //
  36. // Obtain initial var settings
  37. //
  38. if ( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )
  39. {
  40. $forum_id = (isset($HTTP_POST_VARS[POST_FORUM_URL])) ? intval($HTTP_POST_VARS[POST_FORUM_URL]) : intval($HTTP_GET_VARS[POST_FORUM_URL]);
  41. }
  42. else
  43. {
  44. $forum_id = '';
  45. }
  46. if ( isset($HTTP_GET_VARS[POST_POST_URL]) || isset($HTTP_POST_VARS[POST_POST_URL]) )
  47. {
  48. $post_id = (isset($HTTP_POST_VARS[POST_POST_URL])) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]);
  49. }
  50. else
  51. {
  52. $post_id = '';
  53. }
  54. if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) || isset($HTTP_POST_VARS[POST_TOPIC_URL]) )
  55. {
  56. $topic_id = (isset($HTTP_POST_VARS[POST_TOPIC_URL])) ? intval($HTTP_POST_VARS[POST_TOPIC_URL]) : intval($HTTP_GET_VARS[POST_TOPIC_URL]);
  57. }
  58. else
  59. {
  60. $topic_id = '';
  61. }
  62. $confirm = ( $HTTP_POST_VARS['confirm'] ) ? TRUE : 0;
  63. //
  64. // Continue var definitions
  65. //
  66. $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  67. $delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : FALSE;
  68. $move = ( isset($HTTP_POST_VARS['move']) ) ? TRUE : FALSE;
  69. $lock = ( isset($HTTP_POST_VARS['lock']) ) ? TRUE : FALSE;
  70. $unlock = ( isset($HTTP_POST_VARS['unlock']) ) ? TRUE : FALSE;
  71. if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
  72. {
  73. $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  74. }
  75. else
  76. {
  77. if ( $delete )
  78. {
  79. $mode = 'delete';
  80. }
  81. else if ( $move )
  82. {
  83. $mode = 'move';
  84. }
  85. else if ( $lock )
  86. {
  87. $mode = 'lock';
  88. }
  89. else if ( $unlock )
  90. {
  91. $mode = 'unlock';
  92. }
  93. else
  94. {
  95. $mode = '';
  96. }
  97. }
  98. //
  99. // Obtain relevant data
  100. //
  101. if ( !empty($topic_id) )
  102. {
  103. $sql = "SELECT f.forum_id, f.forum_name, f.forum_topics
  104. FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
  105. WHERE t.topic_id = " . $topic_id . "
  106. AND f.forum_id = t.forum_id";
  107. if ( !($result = $db->sql_query($sql)) )
  108. {
  109. message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
  110. }
  111. $topic_row = $db->sql_fetchrow($result);
  112. $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
  113. $forum_id = $topic_row['forum_id'];
  114. $forum_name = $topic_row['forum_name'];
  115. }
  116. else if ( !empty($forum_id) )
  117. {
  118. $sql = "SELECT forum_name, forum_topics
  119. FROM " . FORUMS_TABLE . "
  120. WHERE forum_id = " . $forum_id;
  121. if ( !($result = $db->sql_query($sql)) )
  122. {
  123. message_die(GENERAL_MESSAGE, 'Forum_not_exist');
  124. }
  125. $topic_row = $db->sql_fetchrow($result);
  126. $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
  127. $forum_name = $topic_row['forum_name'];
  128. }
  129. else
  130. {
  131. message_die(GENERAL_MESSAGE, 'Forum_not_exist');
  132. }
  133. //
  134. // Start session management
  135. //
  136. $userdata = session_pagestart($user_ip, $forum_id);
  137. init_userprefs($userdata);
  138. //
  139. // End session management
  140. //
  141. //
  142. // Check if user did or did not confirm
  143. // If they did not, forward them to the last page they were on
  144. //
  145. if ( isset($HTTP_POST_VARS['cancel']) )
  146. {
  147. if ( $topic_id )
  148. {
  149. $redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
  150. }
  151. else if ( $forum_id )
  152. {
  153. $redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
  154. }
  155. else
  156. {
  157. $redirect = "index.$phpEx";
  158. }
  159. $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
  160. header($header_location . append_sid($redirect, true));
  161. exit;
  162. }
  163. //
  164. // Start auth check
  165. //
  166. $is_auth = auth(AUTH_ALL, $forum_id, $userdata);
  167. if ( !$is_auth['auth_mod'] )
  168. {
  169. message_die(GENERAL_MESSAGE, $lang['Not_Moderator'], $lang['Not_Authorised']);
  170. }
  171. //
  172. // End Auth Check
  173. //
  174. //
  175. // Do major work ...
  176. //
  177. switch( $mode )
  178. {
  179. case 'delete':
  180. $page_title = $lang['Mod_CP'];
  181. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  182. if ( $confirm )
  183. {
  184. include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
  185. $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
  186. $topic_id_sql = '';
  187. for($i = 0; $i < count($topics); $i++)
  188. {
  189. $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . $topics[$i];
  190. }
  191. $sql = "SELECT poster_id, COUNT(post_id) AS posts
  192. FROM " . POSTS_TABLE . "
  193. WHERE topic_id IN ($topic_id_sql)
  194. GROUP BY poster_id";
  195. if ( !($result = $db->sql_query($sql)) )
  196. {
  197. message_die(GENERAL_ERROR, 'Could not get poster id information', '', __LINE__, __FILE__, $sql);
  198. }
  199. $count_sql = array();
  200. while ( $row = $db->sql_fetchrow($result) )
  201. {
  202. $count_sql[] = "UPDATE " . USERS_TABLE . "
  203. SET user_posts = user_posts - " . $row['posts'] . "
  204. WHERE user_id = " . $row['poster_id'];
  205. }
  206. $db->sql_freeresult($result);
  207. if ( sizeof($count_sql) )
  208. {
  209. for($i = 0; $i < sizeof($count_sql); $i++)
  210. {
  211. if ( !$db->sql_query($count_sql[$i]) )
  212. {
  213. message_die(GENERAL_ERROR, 'Could not update user post count information', '', __LINE__, __FILE__, $sql);
  214. }
  215. }
  216. }
  217. $sql = "SELECT post_id
  218. FROM " . POSTS_TABLE . "
  219. WHERE topic_id IN ($topic_id_sql)";
  220. if ( !($result = $db->sql_query($sql)) )
  221. {
  222. message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
  223. }
  224. $post_id_sql = '';
  225. while ( $row = $db->sql_fetchrow($result) )
  226. {
  227. $post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . $row['post_id'];
  228. }
  229. $db->sql_freeresult($result);
  230. $sql = "SELECT vote_id
  231. FROM " . VOTE_DESC_TABLE . "
  232. WHERE topic_id IN ($topic_id_sql)";
  233. if ( !($result = $db->sql_query($sql)) )
  234. {
  235. message_die(GENERAL_ERROR, 'Could not get vote id information', '', __LINE__, __FILE__, $sql);
  236. }
  237. $vote_id_sql = '';
  238. while ( $row = $db->sql_fetchrow($result) )
  239. {
  240. $vote_id_sql .= ( ( $vote_id_sql != '' ) ? ', ' : '' ) . $row['vote_id'];
  241. }
  242. $db->sql_freeresult($result);
  243. //
  244. // Got all required info so go ahead and start deleting everything
  245. //
  246. $sql = "DELETE
  247. FROM " . TOPICS_TABLE . "
  248. WHERE topic_id IN ($topic_id_sql)
  249. OR topic_moved_id IN ($topic_id_sql)";
  250. if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
  251. {
  252. message_die(GENERAL_ERROR, 'Could not delete topics', '', __LINE__, __FILE__, $sql);
  253. }
  254. if ( $post_id_sql != '' )
  255. {
  256. $sql = "DELETE
  257. FROM " . POSTS_TABLE . "
  258. WHERE post_id IN ($post_id_sql)";
  259. if ( !$db->sql_query($sql) )
  260. {
  261. message_die(GENERAL_ERROR, 'Could not delete posts', '', __LINE__, __FILE__, $sql);
  262. }
  263. $sql = "DELETE
  264. FROM " . POSTS_TEXT_TABLE . "
  265. WHERE post_id IN ($post_id_sql)";
  266. if ( !$db->sql_query($sql) )
  267. {
  268. message_die(GENERAL_ERROR, 'Could not delete posts text', '', __LINE__, __FILE__, $sql);
  269. }
  270. remove_search_post($post_id_sql);
  271. }
  272. if ( $vote_id_sql != '' )
  273. {
  274. $sql = "DELETE
  275. FROM " . VOTE_DESC_TABLE . "
  276. WHERE vote_id IN ($vote_id_sql)";
  277. if ( !$db->sql_query($sql) )
  278. {
  279. message_die(GENERAL_ERROR, 'Could not delete vote descriptions', '', __LINE__, __FILE__, $sql);
  280. }
  281. $sql = "DELETE
  282. FROM " . VOTE_RESULTS_TABLE . "
  283. WHERE vote_id IN ($vote_id_sql)";
  284. if ( !$db->sql_query($sql) )
  285. {
  286. message_die(GENERAL_ERROR, 'Could not delete vote results', '', __LINE__, __FILE__, $sql);
  287. }
  288. $sql = "DELETE
  289. FROM " . VOTE_USERS_TABLE . "
  290. WHERE vote_id IN ($vote_id_sql)";
  291. if ( !$db->sql_query($sql) )
  292. {
  293. message_die(GENERAL_ERROR, 'Could not delete vote users', '', __LINE__, __FILE__, $sql);
  294. }
  295. }
  296. $sql = "DELETE
  297. FROM " . TOPICS_WATCH_TABLE . "
  298. WHERE topic_id IN ($topic_id_sql)";
  299. if ( !$db->sql_query($sql, END_TRANSACTION) )
  300. {
  301. message_die(GENERAL_ERROR, 'Could not delete watched post list', '', __LINE__, __FILE__, $sql);
  302. }
  303. sync('forum', $forum_id);
  304. if ( !empty($topic_id) )
  305. {
  306. $redirect_page = append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id");
  307. $l_redirect = sprintf($lang['Click_return_forum'], '<a href="' . $redirect_page . '">', '</a>');
  308. }
  309. else
  310. {
  311. $redirect_page = append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id");
  312. $l_redirect = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
  313. }
  314. $template->assign_vars(array(
  315. 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
  316. );
  317. message_die(GENERAL_MESSAGE, $lang['Topics_Removed'] . '<br /><br />' . $l_redirect);
  318. }
  319. else
  320. {
  321. // Not confirmed, show confirmation message
  322. if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
  323. {
  324. message_die(GENERAL_MESSAGE, $lang['None_selected']);
  325. }
  326. $hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
  327. if ( isset($HTTP_POST_VARS['topic_id_list']) )
  328. {
  329. $topics = $HTTP_POST_VARS['topic_id_list'];
  330. for($i = 0; $i < count($topics); $i++)
  331. {
  332. $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
  333. }
  334. }
  335. else
  336. {
  337. $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
  338. }
  339. //
  340. // Set template files
  341. //
  342. $template->set_filenames(array(
  343. 'confirm' => 'confirm_body.tpl')
  344. );
  345. $template->assign_vars(array(
  346. 'MESSAGE_TITLE' => $lang['Confirm'],
  347. 'MESSAGE_TEXT' => $lang['Confirm_delete_topic'],
  348. 'L_YES' => $lang['Yes'],
  349. 'L_NO' => $lang['No'],
  350. 'S_CONFIRM_ACTION' => append_sid("modcp.$phpEx"),
  351. 'S_HIDDEN_FIELDS' => $hidden_fields)
  352. );
  353. $template->pparse('confirm');
  354. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  355. }
  356. break;
  357. case 'move':
  358. $page_title = $lang['Mod_CP'];
  359. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  360. if ( $confirm )
  361. {
  362. if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
  363. {
  364. message_die(GENERAL_MESSAGE, $lang['None_selected']);
  365. }
  366. $new_forum_id = $HTTP_POST_VARS['new_forum'];
  367. $old_forum_id = $forum_id;
  368. if ( $new_forum_id != $old_forum_id )
  369. {
  370. $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
  371. $topic_list = '';
  372. for($i = 0; $i < count($topics); $i++)
  373. {
  374. $topic_list .= ( ( $topic_list != '' ) ? ', ' : '' ) . intval($topics[$i]);
  375. }
  376. $sql = "SELECT *
  377. FROM " . TOPICS_TABLE . "
  378. WHERE topic_id IN ($topic_list)
  379. AND topic_status <> " . TOPIC_MOVED;
  380. if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
  381. {
  382. message_die(GENERAL_ERROR, 'Could not select from topic table', '', __LINE__, __FILE__, $sql);
  383. }
  384. $row = $db->sql_fetchrowset($result);
  385. $db->sql_freeresult($result);
  386. for($i = 0; $i < count($row); $i++)
  387. {
  388. $topic_id = $row[$i]['topic_id'];
  389. if ( isset($HTTP_POST_VARS['move_leave_shadow']) )
  390. {
  391. // Insert topic in the old forum that indicates that the forum has moved.
  392. $sql = "INSERT INTO " . TOPICS_TABLE . " (forum_id, topic_title, topic_poster, topic_time, topic_status, topic_type, topic_vote, topic_views, topic_replies, topic_first_post_id, topic_last_post_id, topic_moved_id)
  393. VALUES ($old_forum_id, '" . addslashes(str_replace("\'", "''", $row[$i]['topic_title'])) . "', '" . str_replace("\'", "''", $row[$i]['topic_poster']) . "', " . $row[$i]['topic_time'] . ", " . TOPIC_MOVED . ", " . POST_NORMAL . ", " . $row[$i]['topic_vote'] . ", " . $row[$i]['topic_views'] . ", " . $row[$i]['topic_replies'] . ", " . $row[$i]['topic_first_post_id'] . ", " . $row[$i]['topic_last_post_id'] . ", $topic_id)";
  394. if ( !$db->sql_query($sql) )
  395. {
  396. message_die(GENERAL_ERROR, 'Could not insert shadow topic', '', __LINE__, __FILE__, $sql);
  397. }
  398. }
  399. $sql = "UPDATE " . TOPICS_TABLE . "
  400. SET forum_id = $new_forum_id
  401. WHERE topic_id = $topic_id";
  402. if ( !$db->sql_query($sql) )
  403. {
  404. message_die(GENERAL_ERROR, 'Could not update old topic', '', __LINE__, __FILE__, $sql);
  405. }
  406. $sql = "UPDATE " . POSTS_TABLE . "
  407. SET forum_id = $new_forum_id
  408. WHERE topic_id = $topic_id";
  409. if ( !$db->sql_query($sql) )
  410. {
  411. message_die(GENERAL_ERROR, 'Could not update post topic ids', '', __LINE__, __FILE__, $sql);
  412. }
  413. }
  414. // Sync the forum indexes
  415. sync('forum', $new_forum_id);
  416. sync('forum', $old_forum_id);
  417. $message = $lang['Topics_Moved'] . '<br /><br />';
  418. }
  419. else
  420. {
  421. $message = $lang['No_Topics_Moved'] . '<br /><br />';
  422. }
  423. if ( !empty($topic_id) )
  424. {
  425. $redirect_page = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");
  426. $message .= sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
  427. }
  428. else
  429. {
  430. $redirect_page = append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id");
  431. $message .= sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
  432. }
  433. $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$old_forum_id") . '">', '</a>');
  434. $template->assign_vars(array(
  435. 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
  436. );
  437. message_die(GENERAL_MESSAGE, $message);
  438. }
  439. else
  440. {
  441. if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
  442. {
  443. message_die(GENERAL_MESSAGE, $lang['None_selected']);
  444. }
  445. $hidden_fields = '<input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
  446. if ( isset($HTTP_POST_VARS['topic_id_list']) )
  447. {
  448. $topics = $HTTP_POST_VARS['topic_id_list'];
  449. for($i = 0; $i < count($topics); $i++)
  450. {
  451. $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
  452. }
  453. }
  454. else
  455. {
  456. $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
  457. }
  458. //
  459. // Set template files
  460. //
  461. $template->set_filenames(array(
  462. 'movetopic' => 'modcp_move.tpl')
  463. );
  464. $template->assign_vars(array(
  465. 'MESSAGE_TITLE' => $lang['Confirm'],
  466. 'MESSAGE_TEXT' => $lang['Confirm_move_topic'],
  467. 'L_MOVE_TO_FORUM' => $lang['Move_to_forum'],
  468. 'L_LEAVESHADOW' => $lang['Leave_shadow_topic'],
  469. 'L_YES' => $lang['Yes'],
  470. 'L_NO' => $lang['No'],
  471. 'S_FORUM_SELECT' => make_forum_select('new_forum', $forum_id),
  472. 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"),
  473. 'S_HIDDEN_FIELDS' => $hidden_fields)
  474. );
  475. $template->pparse('movetopic');
  476. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  477. }
  478. break;
  479. case 'lock':
  480. if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
  481. {
  482. message_die(GENERAL_MESSAGE, $lang['None_selected']);
  483. }
  484. $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
  485. $topic_id_sql = '';
  486. for($i = 0; $i < count($topics); $i++)
  487. {
  488. $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . $topics[$i];
  489. }
  490. $sql = "UPDATE " . TOPICS_TABLE . "
  491. SET topic_status = " . TOPIC_LOCKED . "
  492. WHERE topic_id IN ($topic_id_sql)
  493. AND topic_moved_id = 0";
  494. if ( !($result = $db->sql_query($sql)) )
  495. {
  496. message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
  497. }
  498. if ( !empty($topic_id) )
  499. {
  500. $redirect_page = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");
  501. $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
  502. }
  503. else
  504. {
  505. $redirect_page = append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id");
  506. $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
  507. }
  508. $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
  509. $template->assign_vars(array(
  510. 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
  511. );
  512. message_die(GENERAL_MESSAGE, $lang['Topics_Locked'] . '<br /><br />' . $message);
  513. break;
  514. case 'unlock':
  515. if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
  516. {
  517. message_die(GENERAL_MESSAGE, $lang['None_selected']);
  518. }
  519. $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
  520. $topic_id_sql = '';
  521. for($i = 0; $i < count($topics); $i++)
  522. {
  523. $topic_id_sql .= ( ( $topic_id_sql != "") ? ', ' : '' ) . $topics[$i];
  524. }
  525. $sql = "UPDATE " . TOPICS_TABLE . "
  526. SET topic_status = " . TOPIC_UNLOCKED . "
  527. WHERE topic_id IN ($topic_id_sql)
  528. AND topic_moved_id = 0";
  529. if ( !($result = $db->sql_query($sql)) )
  530. {
  531. message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
  532. }
  533. if ( !empty($topic_id) )
  534. {
  535. $redirect_page = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");
  536. $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
  537. }
  538. else
  539. {
  540. $redirect_page = append_sid("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id");
  541. $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
  542. }
  543. $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a>');
  544. $template->assign_vars(array(
  545. 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
  546. );
  547. message_die(GENERAL_MESSAGE, $lang['Topics_Unlocked'] . '<br /><br />' . $message);
  548. break;
  549. case 'split':
  550. $page_title = $lang['Mod_CP'];
  551. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  552. if ( isset($HTTP_POST_VARS['split_type_all']) || isset($HTTP_POST_VARS['split_type_beyond']) )
  553. {
  554. $posts = $HTTP_POST_VARS['post_id_list'];
  555. $sql = "SELECT poster_id, topic_id, post_time
  556. FROM " . POSTS_TABLE . "
  557. WHERE post_id = " . $posts[0];
  558. if ( !($result = $db->sql_query($sql)) )
  559. {
  560. message_die(GENERAL_ERROR, 'Could not get post information', '', __LINE__, __FILE__, $sql);
  561. }
  562. $post_rowset = $db->sql_fetchrow($result);
  563. $first_poster = str_replace("\'", "''", $post_rowset['poster_id']);
  564. $topic_id = $post_rowset['topic_id'];
  565. $post_time = $post_rowset['post_time'];
  566. $post_subject = trim(htmlspecialchars($HTTP_POST_VARS['subject']));
  567. if ( empty($post_subject) )
  568. {
  569. message_die(GENERAL_MESSAGE, $lang['Empty_subject']);
  570. }
  571. $new_forum_id = intval($HTTP_POST_VARS['new_forum_id']);
  572. $topic_time = time();
  573. $sql = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type)
  574. VALUES ('" . str_replace("\'", "''", $post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ")";
  575. if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
  576. {
  577. message_die(GENERAL_ERROR, 'Could not insert new topic', '', __LINE__, __FILE__, $sql);
  578. }
  579. $new_topic_id = $db->sql_nextid();
  580. if( !empty($HTTP_POST_VARS['split_type_all']) )
  581. {
  582. $post_id_sql = '';
  583. for($i = 0; $i < count($posts); $i++)
  584. {
  585. $post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . $posts[$i];
  586. }
  587. $sql = "UPDATE " . POSTS_TABLE . "
  588. SET topic_id = $new_topic_id, forum_id = $new_forum_id
  589. WHERE post_id IN ($post_id_sql)";
  590. }
  591. else if( !empty($HTTP_POST_VARS['split_type_beyond']) )
  592. {
  593. $sql = "UPDATE " . POSTS_TABLE . "
  594. SET topic_id = $new_topic_id, forum_id = $new_forum_id
  595. WHERE post_time >= $post_time
  596. AND topic_id = $topic_id";
  597. }
  598. if( !$db->sql_query($sql, END_TRANSACTION) )
  599. {
  600. message_die(GENERAL_ERROR, 'Could not update posts table', '', __LINE__, __FILE__, $sql);
  601. }
  602. sync('topic', $new_topic_id);
  603. sync('topic', $topic_id);
  604. sync('forum', $new_forum_id);
  605. sync('forum', $forum_id);
  606. $template->assign_vars(array(
  607. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">')
  608. );
  609. $message = $lang['Topic_split'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id") . '">', '</a>');
  610. message_die(GENERAL_MESSAGE, $message);
  611. }
  612. else
  613. {
  614. //
  615. // Set template files
  616. //
  617. $template->set_filenames(array(
  618. 'split_body' => 'modcp_split.tpl')
  619. );
  620. $sql = "SELECT u.username, p.*, pt.post_text, pt.bbcode_uid, pt.post_subject, p.post_username
  621. FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
  622. WHERE p.topic_id = $topic_id
  623. AND p.poster_id = u.user_id
  624. AND p.post_id = pt.post_id
  625. ORDER BY p.post_time ASC";
  626. if ( !($result = $db->sql_query($sql)) )
  627. {
  628. message_die(GENERAL_ERROR, 'Could not get topic/post information', '', __LINE__, __FILE__, $sql);
  629. }
  630. $s_hidden_fields = '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" /><input type="hidden" name="mode" value="split" />';
  631. if( ( $total_posts = $db->sql_numrows($result) ) > 0 )
  632. {
  633. $postrow = $db->sql_fetchrowset($result);
  634. $template->assign_vars(array(
  635. 'L_SPLIT_TOPIC' => $lang['Split_Topic'],
  636. 'L_SPLIT_TOPIC_EXPLAIN' => $lang['Split_Topic_explain'],
  637. 'L_AUTHOR' => $lang['Author'],
  638. 'L_MESSAGE' => $lang['Message'],
  639. 'L_SELECT' => $lang['Select'],
  640. 'L_SPLIT_SUBJECT' => $lang['Split_title'],
  641. 'L_SPLIT_FORUM' => $lang['Split_forum'],
  642. 'L_POSTED' => $lang['Posted'],
  643. 'L_SPLIT_POSTS' => $lang['Split_posts'],
  644. 'L_SUBMIT' => $lang['Submit'],
  645. 'L_SPLIT_AFTER' => $lang['Split_after'],
  646. 'L_POST_SUBJECT' => $lang['Post_subject'],
  647. 'L_MARK_ALL' => $lang['Mark_all'],
  648. 'L_UNMARK_ALL' => $lang['Unmark_all'],
  649. 'L_POST' => $lang['Post'],
  650. 'FORUM_NAME' => $forum_name,
  651. 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
  652. 'S_SPLIT_ACTION' => append_sid("modcp.$phpEx"),
  653. 'S_HIDDEN_FIELDS' => $s_hidden_fields,
  654. 'S_FORUM_SELECT' => make_forum_select("new_forum_id", false, $forum_id))
  655. );
  656. for($i = 0; $i < $total_posts; $i++)
  657. {
  658. $post_id = $postrow[$i]['post_id'];
  659. $poster_id = $postrow[$i]['user_id'];
  660. $poster = $postrow[$i]['username'];
  661. $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
  662. $bbcode_uid = $postrow[$i]['bbcode_uid'];
  663. $message = $postrow[$i]['post_text'];
  664. $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : $topic_title;
  665. //
  666. // If the board has HTML off but the post has HTML
  667. // on then we process it, else leave it alone
  668. //
  669. if ( !$board_config['allow_html'] )
  670. {
  671. if ( $postrow[$i]['enable_html'] )
  672. {
  673. $message = preg_replace('#(<)([\/]?.*?)(>)#is', '&lt;\\2&gt;', $message);
  674. }
  675. }
  676. if ( $bbcode_uid != '' )
  677. {
  678. $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
  679. }
  680. //
  681. // Define censored word matches
  682. //
  683. $orig_word = array();
  684. $replacement_word = array();
  685. obtain_word_list($orig_word, $replacement_word);
  686. if ( count($orig_word) )
  687. {
  688. $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
  689. $message = preg_replace($orig_word, $replacement_word, $message);
  690. }
  691. $message = make_clickable($message);
  692. if ( $board_config['allow_smilies'] && $postrow[$i]['enable_smilies'] )
  693. {
  694. $message = smilies_pass($message);
  695. }
  696. $message = str_replace("\n", '<br />', $message);
  697. $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
  698. $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
  699. $checkbox = ( $i > 0 ) ? '<input type="checkbox" name="post_id_list[]" value="' . $post_id . '" />' : '&nbsp;';
  700. $template->assign_block_vars('postrow', array(
  701. 'ROW_COLOR' => '#' . $row_color,
  702. 'ROW_CLASS' => $row_class,
  703. 'POSTER_NAME' => $poster,
  704. 'POST_DATE' => $post_date,
  705. 'POST_SUBJECT' => $post_subject,
  706. 'MESSAGE' => $message,
  707. 'POST_ID' => $post_id,
  708. 'S_SPLIT_CHECKBOX' => $checkbox)
  709. );
  710. }
  711. $template->pparse('split_body');
  712. }
  713. }
  714. break;
  715. case 'ip':
  716. $page_title = $lang['Mod_CP'];
  717. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  718. $rdns_ip_num = ( isset($HTTP_GET_VARS['rdns']) ) ? $HTTP_GET_VARS['rdns'] : "";
  719. if ( !$post_id )
  720. {
  721. message_die(GENERAL_MESSAGE, $lang['No_such_post']);
  722. }
  723. //
  724. // Set template files
  725. //
  726. $template->set_filenames(array(
  727. 'viewip' => 'modcp_viewip.tpl')
  728. );
  729. // Look up relevent data for this post
  730. $sql = "SELECT poster_ip, poster_id
  731. FROM " . POSTS_TABLE . "
  732. WHERE post_id = $post_id";
  733. if ( !($result = $db->sql_query($sql)) )
  734. {
  735. message_die(GENERAL_ERROR, 'Could not get poster IP information', '', __LINE__, __FILE__, $sql);
  736. }
  737. if ( !($post_row = $db->sql_fetchrow($result)) )
  738. {
  739. message_die(GENERAL_MESSAGE, $lang['No_such_post']);
  740. }
  741. $ip_this_post = decode_ip($post_row['poster_ip']);
  742. $ip_this_post = ( $rdns_ip_num == $ip_this_post ) ? gethostbyaddr($ip_this_post) : $ip_this_post;
  743. $poster_id = $post_row['poster_id'];
  744. $template->assign_vars(array(
  745. 'L_IP_INFO' => $lang['IP_info'],
  746. 'L_THIS_POST_IP' => $lang['This_posts_IP'],
  747. 'L_OTHER_IPS' => $lang['Other_IP_this_user'],
  748. 'L_OTHER_USERS' => $lang['Users_this_IP'],
  749. 'L_LOOKUP_IP' => $lang['Lookup_IP'],
  750. 'L_SEARCH' => $lang['Search'],
  751. 'SEARCH_IMG' => $images['icon_search'],
  752. 'IP' => $ip_this_post,
  753. 'U_LOOKUP_IP' => append_sid("modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=$post_id&amp;" . POST_TOPIC_URL . "=$topic_id&amp;rdns=" . $ip_this_post))
  754. );
  755. //
  756. // Get other IP's this user has posted under
  757. //
  758. $sql = "SELECT poster_ip, COUNT(*) AS postings
  759. FROM " . POSTS_TABLE . "
  760. WHERE poster_id = $poster_id
  761. GROUP BY poster_ip
  762. ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
  763. if ( !($result = $db->sql_query($sql)) )
  764. {
  765. message_die(GENERAL_ERROR, 'Could not get IP information for this user', '', __LINE__, __FILE__, $sql);
  766. }
  767. if ( $row = $db->sql_fetchrow($result) )
  768. {
  769. $i = 0;
  770. do
  771. {
  772. if ( $row['poster_ip'] == $post_row['poster_ip'] )
  773. {
  774. $template->assign_vars(array(
  775. 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ))
  776. );
  777. continue;
  778. }
  779. $ip = decode_ip($row['poster_ip']);
  780. $ip = ( $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? gethostbyaddr($ip) : $ip;
  781. $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
  782. $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
  783. $template->assign_block_vars('iprow', array(
  784. 'ROW_COLOR' => '#' . $row_color,
  785. 'ROW_CLASS' => $row_class,
  786. 'IP' => $ip,
  787. 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
  788. 'U_LOOKUP_IP' => append_sid("modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=$post_id&amp;" . POST_TOPIC_URL . "=$topic_id&amp;rdns=" . $row['poster_ip']))
  789. );
  790. $i++;
  791. }
  792. while ( $row = $db->sql_fetchrow($result) );
  793. }
  794. //
  795. // Get other users who've posted under this IP
  796. //
  797. $sql = "SELECT u.user_id, u.username, COUNT(*) as postings
  798. FROM " . USERS_TABLE ." u, " . POSTS_TABLE . " p
  799. WHERE p.poster_id = u.user_id
  800. AND p.poster_ip = '" . $post_row['poster_ip'] . "'
  801. GROUP BY u.user_id, u.username
  802. ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
  803. if ( !($result = $db->sql_query($sql)) )
  804. {
  805. message_die(GENERAL_ERROR, 'Could not get posters information based on IP', '', __LINE__, __FILE__, $sql);
  806. }
  807. if ( $row = $db->sql_fetchrow($result) )
  808. {
  809. $i = 0;
  810. do
  811. {
  812. $id = $row['user_id'];
  813. $username = ( $id == ANONYMOUS ) ? $lang['Guest'] : $row['username'];
  814. $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
  815. $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
  816. $template->assign_block_vars('userrow', array(
  817. 'ROW_COLOR' => '#' . $row_color,
  818. 'ROW_CLASS' => $row_class,
  819. 'USERNAME' => $username,
  820. 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
  821. 'L_SEARCH_POSTS' => sprintf($lang['Search_user_posts'], $username),
  822. 'U_PROFILE' => append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$id"),
  823. 'U_SEARCHPOSTS' => append_sid("search.$phpEx?search_author=" . urlencode($username) . "&amp;showresults=topics"))
  824. );
  825. $i++;
  826. }
  827. while ( $row = $db->sql_fetchrow($result) );
  828. }
  829. $template->pparse('viewip');
  830. break;
  831. default:
  832. $page_title = $lang['Mod_CP'];
  833. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  834. $template->assign_vars(array(
  835. 'FORUM_NAME' => $forum_name,
  836. 'L_MOD_CP' => $lang['Mod_CP'],
  837. 'L_MOD_CP_EXPLAIN' => $lang['Mod_CP_explain'],
  838. 'L_SELECT' => $lang['Select'],
  839. 'L_DELETE' => $lang['Delete'],
  840. 'L_MOVE' => $lang['Move'],
  841. 'L_LOCK' => $lang['Lock'],
  842. 'L_UNLOCK' => $lang['Unlock'],
  843. 'L_TOPICS' => $lang['Topics'],
  844. 'L_REPLIES' => $lang['Replies'],
  845. 'L_LASTPOST' => $lang['Last_Post'],
  846. 'L_SELECT' => $lang['Select'],
  847. 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
  848. 'S_HIDDEN_FIELDS' => '<input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '">',
  849. 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"))
  850. );
  851. $template->set_filenames(array(
  852. 'body' => 'modcp_body.tpl')
  853. );
  854. //
  855. // Define censored word matches
  856. //
  857. $orig_word = array();
  858. $replacement_word = array();
  859. obtain_word_list($orig_word, $replacement_word);
  860. $sql = "SELECT t.*, u.username, u.user_id, p.post_time
  861. FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p
  862. WHERE t.forum_id = $forum_id
  863. AND t.topic_poster = u.user_id
  864. AND p.post_id = t.topic_last_post_id
  865. ORDER BY t.topic_type DESC, p.post_time DESC
  866. LIMIT $start, " . $board_config['topics_per_page'];
  867. if ( !($result = $db->sql_query($sql)) )
  868. {
  869. message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
  870. }
  871. while ( $row = $db->sql_fetchrow($result) )
  872. {
  873. $topic_title = '';
  874. if ( $row['topic_status'] == TOPIC_LOCKED )
  875. {
  876. $folder_img = $images['folder_locked'];
  877. $folder_alt = $lang['Topic_locked'];
  878. }
  879. else
  880. {
  881. if ( $row['topic_type'] == POST_ANNOUNCE )
  882. {
  883. $folder_img = $images['folder_announce'];
  884. $folder_alt = $lang['Topic_Announcement'];
  885. }
  886. else if ( $row['topic_type'] == POST_STICKY )
  887. {
  888. $folder_img = $images['folder_sticky'];
  889. $folder_alt = $lang['Topic_Sticky'];
  890. }
  891. else
  892. {
  893. $folder_img = $images['folder'];
  894. $folder_alt = $lang['No_new_posts'];
  895. }
  896. }
  897. $topic_id = $row['topic_id'];
  898. $topic_type = $row['topic_type'];
  899. $topic_status = $row['topic_status'];
  900. if ( $topic_type == POST_ANNOUNCE )
  901. {
  902. $topic_type = $lang['Topic_Announcement'] . ' ';
  903. }
  904. else if ( $topic_type == POST_STICKY )
  905. {
  906. $topic_type = $lang['Topic_Sticky'] . ' ';
  907. }
  908. else if ( $topic_status == TOPIC_MOVED )
  909. {
  910. $topic_type = $lang['Topic_Moved'] . ' ';
  911. }
  912. else
  913. {
  914. $topic_type = '';
  915. }
  916. if ( $row['topic_vote'] )
  917. {
  918. $topic_type .= $lang['Topic_Poll'] . ' ';
  919. }
  920. $topic_title = $row['topic_title'];
  921. if ( count($orig_word) )
  922. {
  923. $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
  924. }
  925. $u_view_topic = append_sid("modcp.$phpEx?mode=split&amp;" . POST_TOPIC_URL . "=$topic_id");
  926. $topic_replies = $row['topic_replies'];
  927. $last_post_time = create_date($board_config['default_dateformat'], $row['post_time'], $board_config['board_timezone']);
  928. $template->assign_block_vars('topicrow', array(
  929. 'U_VIEW_TOPIC' => $u_view_topic,
  930. 'TOPIC_FOLDER_IMG' => $folder_img,
  931. 'TOPIC_TYPE' => $topic_type,
  932. 'TOPIC_TITLE' => $topic_title,
  933. 'REPLIES' => $topic_replies,
  934. 'LAST_POST_TIME' => $last_post_time,
  935. 'TOPIC_ID' => $topic_id,
  936. 'L_TOPIC_FOLDER_ALT' => $folder_alt)
  937. );
  938. }
  939. $template->assign_vars(array(
  940. 'PAGINATION' => generate_pagination("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id", $forum_topics, $board_config['topics_per_page'], $start),
  941. 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $forum_topics / $board_config['topics_per_page'] )),
  942. 'L_GOTO_PAGE' => $lang['Goto_page'])
  943. );
  944. $template->pparse('body');
  945. break;
  946. }
  947. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  948. ?>