phpBB 2.0.19-scripts
[autoinstalls/phpBB.git] / modcp.php
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.27 2005/09/14 18:14:30 acydburn 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 /**
23  * Moderator Control Panel
24  *
25  * From this 'Control Panel' the moderator of a forum will be able to do
26  * mass topic operations (locking/unlocking/moving/deleteing), and it will
27  * provide an interface to do quick locking/unlocking/moving/deleting of
28  * topics via the moderator operations buttons on all of the viewtopic pages.
29  */
30
31 define('IN_PHPBB', true);
32 $phpbb_root_path = './';
33 include($phpbb_root_path . 'extension.inc');
34 include($phpbb_root_path . 'common.'.$phpEx);
35 include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
36 include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
37
38 //
39 // Obtain initial var settings
40 //
41 if ( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )
42 {
43         $forum_id = (isset($HTTP_POST_VARS[POST_FORUM_URL])) ? intval($HTTP_POST_VARS[POST_FORUM_URL]) : intval($HTTP_GET_VARS[POST_FORUM_URL]);
44 }
45 else
46 {
47         $forum_id = '';
48 }
49
50 if ( isset($HTTP_GET_VARS[POST_POST_URL]) || isset($HTTP_POST_VARS[POST_POST_URL]) )
51 {
52         $post_id = (isset($HTTP_POST_VARS[POST_POST_URL])) ? intval($HTTP_POST_VARS[POST_POST_URL]) : intval($HTTP_GET_VARS[POST_POST_URL]);
53 }
54 else
55 {
56         $post_id = '';
57 }
58
59 if ( isset($HTTP_GET_VARS[POST_TOPIC_URL]) || isset($HTTP_POST_VARS[POST_TOPIC_URL]) )
60 {
61         $topic_id = (isset($HTTP_POST_VARS[POST_TOPIC_URL])) ? intval($HTTP_POST_VARS[POST_TOPIC_URL]) : intval($HTTP_GET_VARS[POST_TOPIC_URL]);
62 }
63 else
64 {
65         $topic_id = '';
66 }
67
68 $confirm = ( $HTTP_POST_VARS['confirm'] ) ? TRUE : 0;
69
70 //
71 // Continue var definitions
72 //
73 $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
74
75 $delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : FALSE;
76 $move = ( isset($HTTP_POST_VARS['move']) ) ? TRUE : FALSE;
77 $lock = ( isset($HTTP_POST_VARS['lock']) ) ? TRUE : FALSE;
78 $unlock = ( isset($HTTP_POST_VARS['unlock']) ) ? TRUE : FALSE;
79
80 if ( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
81 {
82         $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
83         $mode = htmlspecialchars($mode);
84 }
85 else
86 {
87         if ( $delete )
88         {
89                 $mode = 'delete';
90         }
91         else if ( $move )
92         {
93                 $mode = 'move';
94         }
95         else if ( $lock )
96         {
97                 $mode = 'lock';
98         }
99         else if ( $unlock )
100         {
101                 $mode = 'unlock';
102         }
103         else
104         {
105                 $mode = '';
106         }
107 }
108
109 // session id check
110 if (!empty($HTTP_POST_VARS['sid']) || !empty($HTTP_GET_VARS['sid']))
111 {
112         $sid = (!empty($HTTP_POST_VARS['sid'])) ? $HTTP_POST_VARS['sid'] : $HTTP_GET_VARS['sid'];
113 }
114 else
115 {
116         $sid = '';
117 }
118
119 //
120 // Obtain relevant data
121 //
122 if ( !empty($topic_id) )
123 {
124         $sql = "SELECT f.forum_id, f.forum_name, f.forum_topics
125                 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
126                 WHERE t.topic_id = " . $topic_id . "
127                         AND f.forum_id = t.forum_id";
128         if ( !($result = $db->sql_query($sql)) )
129         {
130                 message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
131         }
132         $topic_row = $db->sql_fetchrow($result);
133
134         if (!$topic_row)
135         {
136                 message_die(GENERAL_MESSAGE, 'Topic_post_not_exist');
137         }
138
139         $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
140         $forum_id = $topic_row['forum_id'];
141         $forum_name = $topic_row['forum_name'];
142 }
143 else if ( !empty($forum_id) )
144 {
145         $sql = "SELECT forum_name, forum_topics
146                 FROM " . FORUMS_TABLE . "
147                 WHERE forum_id = " . $forum_id;
148         if ( !($result = $db->sql_query($sql)) )
149         {
150                 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
151         }
152         $topic_row = $db->sql_fetchrow($result);
153
154         if (!$topic_row)
155         {
156                 message_die(GENERAL_MESSAGE, 'Forum_not_exist');
157         }
158
159         $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
160         $forum_name = $topic_row['forum_name'];
161 }
162 else
163 {
164         message_die(GENERAL_MESSAGE, 'Forum_not_exist');
165 }
166
167 //
168 // Start session management
169 //
170 $userdata = session_pagestart($user_ip, $forum_id);
171 init_userprefs($userdata);
172 //
173 // End session management
174 //
175
176 // session id check
177 if ($sid == '' || $sid != $userdata['session_id'])
178 {
179         message_die(GENERAL_ERROR, 'Invalid_session');
180 }
181
182 //
183 // Check if user did or did not confirm
184 // If they did not, forward them to the last page they were on
185 //
186 if ( isset($HTTP_POST_VARS['cancel']) )
187 {
188         if ( $topic_id )
189         {
190                 $redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
191         }
192         else if ( $forum_id )
193         {
194                 $redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
195         }
196         else
197         {
198                 $redirect = "index.$phpEx";
199         }
200
201         redirect(append_sid($redirect, true));
202 }
203
204 //
205 // Start auth check
206 //
207 $is_auth = auth(AUTH_ALL, $forum_id, $userdata);
208
209 if ( !$is_auth['auth_mod'] )
210 {
211         message_die(GENERAL_MESSAGE, $lang['Not_Moderator'], $lang['Not_Authorised']);
212 }
213 //
214 // End Auth Check
215 //
216
217 //
218 // Do major work ...
219 //
220 switch( $mode )
221 {
222         case 'delete':
223                 if (!$is_auth['auth_delete'])
224                 {
225                         message_die(GENERAL_MESSAGE, sprintf($lang['Sorry_auth_delete'], $is_auth['auth_delete_type']));
226                 }
227
228                 $page_title = $lang['Mod_CP'];
229                 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
230
231                 if ( $confirm )
232                 {
233                         include($phpbb_root_path . 'includes/functions_search.'.$phpEx);
234
235                         $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ? $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
236
237                         $topic_id_sql = '';
238                         for($i = 0; $i < count($topics); $i++)
239                         {
240                                 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
241                         }
242
243                         $sql = "SELECT topic_id 
244                                 FROM " . TOPICS_TABLE . "
245                                 WHERE topic_id IN ($topic_id_sql)
246                                         AND forum_id = $forum_id";
247                         if ( !($result = $db->sql_query($sql)) )
248                         {
249                                 message_die(GENERAL_ERROR, 'Could not get topic id information', '', __LINE__, __FILE__, $sql);
250                         }
251                         
252                         $topic_id_sql = '';
253                         while ($row = $db->sql_fetchrow($result))
254                         {
255                                 $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($row['topic_id']);
256                         }
257                         $db->sql_freeresult($result);
258
259                         $sql = "SELECT poster_id, COUNT(post_id) AS posts 
260                                 FROM " . POSTS_TABLE . " 
261                                 WHERE topic_id IN ($topic_id_sql) 
262                                 GROUP BY poster_id";
263                         if ( !($result = $db->sql_query($sql)) )
264                         {
265                                 message_die(GENERAL_ERROR, 'Could not get poster id information', '', __LINE__, __FILE__, $sql);
266                         }
267
268                         $count_sql = array();
269                         while ( $row = $db->sql_fetchrow($result) )
270                         {
271                                 $count_sql[] = "UPDATE " . USERS_TABLE . " 
272                                         SET user_posts = user_posts - " . $row['posts'] . " 
273                                         WHERE user_id = " . $row['poster_id'];
274                         }
275                         $db->sql_freeresult($result);
276
277                         if ( sizeof($count_sql) )
278                         {
279                                 for($i = 0; $i < sizeof($count_sql); $i++)
280                                 {
281                                         if ( !$db->sql_query($count_sql[$i]) )
282                                         {
283                                                 message_die(GENERAL_ERROR, 'Could not update user post count information', '', __LINE__, __FILE__, $sql);
284                                         }
285                                 }
286                         }
287                         
288                         $sql = "SELECT post_id 
289                                 FROM " . POSTS_TABLE . " 
290                                 WHERE topic_id IN ($topic_id_sql)";
291                         if ( !($result = $db->sql_query($sql)) )
292                         {
293                                 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
294                         }
295
296                         $post_id_sql = '';
297                         while ( $row = $db->sql_fetchrow($result) )
298                         {
299                                 $post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . intval($row['post_id']);
300                         }
301                         $db->sql_freeresult($result);
302
303                         $sql = "SELECT vote_id 
304                                 FROM " . VOTE_DESC_TABLE . " 
305                                 WHERE topic_id IN ($topic_id_sql)";
306                         if ( !($result = $db->sql_query($sql)) )
307                         {
308                                 message_die(GENERAL_ERROR, 'Could not get vote id information', '', __LINE__, __FILE__, $sql);
309                         }
310
311                         $vote_id_sql = '';
312                         while ( $row = $db->sql_fetchrow($result) )
313                         {
314                                 $vote_id_sql .= ( ( $vote_id_sql != '' ) ? ', ' : '' ) . $row['vote_id'];
315                         }
316                         $db->sql_freeresult($result);
317
318                         //
319                         // Got all required info so go ahead and start deleting everything
320                         //
321                         $sql = "DELETE 
322                                 FROM " . TOPICS_TABLE . " 
323                                 WHERE topic_id IN ($topic_id_sql) 
324                                         OR topic_moved_id IN ($topic_id_sql)";
325                         if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
326                         {
327                                 message_die(GENERAL_ERROR, 'Could not delete topics', '', __LINE__, __FILE__, $sql);
328                         }
329
330                         if ( $post_id_sql != '' )
331                         {
332                                 $sql = "DELETE 
333                                         FROM " . POSTS_TABLE . " 
334                                         WHERE post_id IN ($post_id_sql)";
335                                 if ( !$db->sql_query($sql) )
336                                 {
337                                         message_die(GENERAL_ERROR, 'Could not delete posts', '', __LINE__, __FILE__, $sql);
338                                 }
339
340                                 $sql = "DELETE 
341                                         FROM " . POSTS_TEXT_TABLE . " 
342                                         WHERE post_id IN ($post_id_sql)";
343                                 if ( !$db->sql_query($sql) )
344                                 {
345                                         message_die(GENERAL_ERROR, 'Could not delete posts text', '', __LINE__, __FILE__, $sql);
346                                 }
347
348                                 remove_search_post($post_id_sql);
349                         }
350
351                         if ( $vote_id_sql != '' )
352                         {
353                                 $sql = "DELETE 
354                                         FROM " . VOTE_DESC_TABLE . " 
355                                         WHERE vote_id IN ($vote_id_sql)";
356                                 if ( !$db->sql_query($sql) )
357                                 {
358                                         message_die(GENERAL_ERROR, 'Could not delete vote descriptions', '', __LINE__, __FILE__, $sql);
359                                 }
360
361                                 $sql = "DELETE 
362                                         FROM " . VOTE_RESULTS_TABLE . " 
363                                         WHERE vote_id IN ($vote_id_sql)";
364                                 if ( !$db->sql_query($sql) )
365                                 {
366                                         message_die(GENERAL_ERROR, 'Could not delete vote results', '', __LINE__, __FILE__, $sql);
367                                 }
368
369                                 $sql = "DELETE 
370                                         FROM " . VOTE_USERS_TABLE . " 
371                                         WHERE vote_id IN ($vote_id_sql)";
372                                 if ( !$db->sql_query($sql) )
373                                 {
374                                         message_die(GENERAL_ERROR, 'Could not delete vote users', '', __LINE__, __FILE__, $sql);
375                                 }
376                         }
377
378                         $sql = "DELETE 
379                                 FROM " . TOPICS_WATCH_TABLE . " 
380                                 WHERE topic_id IN ($topic_id_sql)";
381                         if ( !$db->sql_query($sql, END_TRANSACTION) )
382                         {
383                                 message_die(GENERAL_ERROR, 'Could not delete watched post list', '', __LINE__, __FILE__, $sql);
384                         }
385
386                         sync('forum', $forum_id);
387
388                         if ( !empty($topic_id) )
389                         {
390                                 $redirect_page = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
391                                 $l_redirect = sprintf($lang['Click_return_forum'], '<a href="' . $redirect_page . '">', '</a>');
392                         }
393                         else
394                         {
395                                 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
396                                 $l_redirect = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
397                         }
398
399                         $template->assign_vars(array(
400                                 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
401                         );
402
403                         message_die(GENERAL_MESSAGE, $lang['Topics_Removed'] . '<br /><br />' . $l_redirect);
404                 }
405                 else
406                 {
407                         // Not confirmed, show confirmation message
408                         if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
409                         {
410                                 message_die(GENERAL_MESSAGE, $lang['None_selected']);
411                         }
412
413                         $hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
414
415                         if ( isset($HTTP_POST_VARS['topic_id_list']) )
416                         {
417                                 $topics = $HTTP_POST_VARS['topic_id_list'];
418                                 for($i = 0; $i < count($topics); $i++)
419                                 {
420                                         $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
421                                 }
422                         }
423                         else
424                         {
425                                 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
426                         }
427
428                         //
429                         // Set template files
430                         //
431                         $template->set_filenames(array(
432                                 'confirm' => 'confirm_body.tpl')
433                         );
434
435                         $template->assign_vars(array(
436                                 'MESSAGE_TITLE' => $lang['Confirm'],
437                                 'MESSAGE_TEXT' => $lang['Confirm_delete_topic'],
438
439                                 'L_YES' => $lang['Yes'],
440                                 'L_NO' => $lang['No'],
441
442                                 'S_CONFIRM_ACTION' => append_sid("modcp.$phpEx"),
443                                 'S_HIDDEN_FIELDS' => $hidden_fields)
444                         );
445
446                         $template->pparse('confirm');
447
448                         include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
449                 }
450                 break;
451
452         case 'move':
453                 $page_title = $lang['Mod_CP'];
454                 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
455
456                 if ( $confirm )
457                 {
458                         if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
459                         {
460                                 message_die(GENERAL_MESSAGE, $lang['None_selected']);
461                         }
462
463                         $new_forum_id = intval($HTTP_POST_VARS['new_forum']);
464                         $old_forum_id = $forum_id;
465
466                         $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
467                                 WHERE forum_id = ' . $new_forum_id;
468                         if ( !($result = $db->sql_query($sql)) )
469                         {
470                                 message_die(GENERAL_ERROR, 'Could not select from forums table', '', __LINE__, __FILE__, $sql);
471                         }
472                         
473                         if (!$db->sql_fetchrow($result))
474                         {
475                                 message_die(GENERAL_MESSAGE, 'New forum does not exist');
476                         }
477
478                         $db->sql_freeresult($result);
479
480                         if ( $new_forum_id != $old_forum_id )
481                         {
482                                 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ?  $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
483
484                                 $topic_list = '';
485                                 for($i = 0; $i < count($topics); $i++)
486                                 {
487                                         $topic_list .= ( ( $topic_list != '' ) ? ', ' : '' ) . intval($topics[$i]);
488                                 }
489
490                                 $sql = "SELECT * 
491                                         FROM " . TOPICS_TABLE . " 
492                                         WHERE topic_id IN ($topic_list)
493                                                 AND forum_id = $old_forum_id
494                                                 AND topic_status <> " . TOPIC_MOVED;
495                                 if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
496                                 {
497                                         message_die(GENERAL_ERROR, 'Could not select from topic table', '', __LINE__, __FILE__, $sql);
498                                 }
499
500                                 $row = $db->sql_fetchrowset($result);
501                                 $db->sql_freeresult($result);
502
503                                 for($i = 0; $i < count($row); $i++)
504                                 {
505                                         $topic_id = $row[$i]['topic_id'];
506                                         
507                                         if ( isset($HTTP_POST_VARS['move_leave_shadow']) )
508                                         {
509                                                 // Insert topic in the old forum that indicates that the forum has moved.
510                                                 $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)
511                                                         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)";
512                                                 if ( !$db->sql_query($sql) )
513                                                 {
514                                                         message_die(GENERAL_ERROR, 'Could not insert shadow topic', '', __LINE__, __FILE__, $sql);
515                                                 }
516                                         }
517
518                                         $sql = "UPDATE " . TOPICS_TABLE . " 
519                                                 SET forum_id = $new_forum_id  
520                                                 WHERE topic_id = $topic_id";
521                                         if ( !$db->sql_query($sql) )
522                                         {
523                                                 message_die(GENERAL_ERROR, 'Could not update old topic', '', __LINE__, __FILE__, $sql);
524                                         }
525
526                                         $sql = "UPDATE " . POSTS_TABLE . " 
527                                                 SET forum_id = $new_forum_id 
528                                                 WHERE topic_id = $topic_id";
529                                         if ( !$db->sql_query($sql) )
530                                         {
531                                                 message_die(GENERAL_ERROR, 'Could not update post topic ids', '', __LINE__, __FILE__, $sql);
532                                         }
533                                 }
534
535                                 // Sync the forum indexes
536                                 sync('forum', $new_forum_id);
537                                 sync('forum', $old_forum_id);
538
539                                 $message = $lang['Topics_Moved'] . '<br /><br />';
540
541                         }
542                         else
543                         {
544                                 $message = $lang['No_Topics_Moved'] . '<br /><br />';
545                         }
546
547                         if ( !empty($topic_id) )
548                         {
549                                 $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
550                                 $message .= sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
551                         }
552                         else
553                         {
554                                 $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
555                                 $message .= sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
556                         }
557
558                         $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$old_forum_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
559
560                         $template->assign_vars(array(
561                                 'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
562                         );
563
564                         message_die(GENERAL_MESSAGE, $message);
565                 }
566                 else
567                 {
568                         if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
569                         {
570                                 message_die(GENERAL_MESSAGE, $lang['None_selected']);
571                         }
572
573                         $hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="mode" value="' . $mode . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
574
575                         if ( isset($HTTP_POST_VARS['topic_id_list']) )
576                         {
577                                 $topics = $HTTP_POST_VARS['topic_id_list'];
578
579                                 for($i = 0; $i < count($topics); $i++)
580                                 {
581                                         $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
582                                 }
583                         }
584                         else
585                         {
586                                 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
587                         }
588
589                         //
590                         // Set template files
591                         //
592                         $template->set_filenames(array(
593                                 'movetopic' => 'modcp_move.tpl')
594                         );
595
596                         $template->assign_vars(array(
597                                 'MESSAGE_TITLE' => $lang['Confirm'],
598                                 'MESSAGE_TEXT' => $lang['Confirm_move_topic'],
599
600                                 'L_MOVE_TO_FORUM' => $lang['Move_to_forum'], 
601                                 'L_LEAVESHADOW' => $lang['Leave_shadow_topic'], 
602                                 'L_YES' => $lang['Yes'],
603                                 'L_NO' => $lang['No'],
604
605                                 'S_FORUM_SELECT' => make_forum_select('new_forum', $forum_id), 
606                                 'S_MODCP_ACTION' => append_sid("modcp.$phpEx"),
607                                 'S_HIDDEN_FIELDS' => $hidden_fields)
608                         );
609
610                         $template->pparse('movetopic');
611
612                         include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
613                 }
614                 break;
615
616         case 'lock':
617                 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
618                 {
619                         message_die(GENERAL_MESSAGE, $lang['None_selected']);
620                 }
621
622                 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ?  $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
623
624                 $topic_id_sql = '';
625                 for($i = 0; $i < count($topics); $i++)
626                 {
627                         $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
628                 }
629
630                 $sql = "UPDATE " . TOPICS_TABLE . " 
631                         SET topic_status = " . TOPIC_LOCKED . " 
632                         WHERE topic_id IN ($topic_id_sql) 
633                                 AND forum_id = $forum_id
634                                 AND topic_moved_id = 0";
635                 if ( !($result = $db->sql_query($sql)) )
636                 {
637                         message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
638                 }
639
640                 if ( !empty($topic_id) )
641                 {
642                         $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
643                         $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
644                 }
645                 else
646                 {
647                         $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
648                         $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
649                 }
650
651                 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
652
653                 $template->assign_vars(array(
654                         'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
655                 );
656
657                 message_die(GENERAL_MESSAGE, $lang['Topics_Locked'] . '<br /><br />' . $message);
658
659                 break;
660
661         case 'unlock':
662                 if ( empty($HTTP_POST_VARS['topic_id_list']) && empty($topic_id) )
663                 {
664                         message_die(GENERAL_MESSAGE, $lang['None_selected']);
665                 }
666
667                 $topics = ( isset($HTTP_POST_VARS['topic_id_list']) ) ?  $HTTP_POST_VARS['topic_id_list'] : array($topic_id);
668
669                 $topic_id_sql = '';
670                 for($i = 0; $i < count($topics); $i++)
671                 {
672                         $topic_id_sql .= ( ( $topic_id_sql != "") ? ', ' : '' ) . intval($topics[$i]);
673                 }
674
675                 $sql = "UPDATE " . TOPICS_TABLE . " 
676                         SET topic_status = " . TOPIC_UNLOCKED . " 
677                         WHERE topic_id IN ($topic_id_sql) 
678                                 AND forum_id = $forum_id
679                                 AND topic_moved_id = 0";
680                 if ( !($result = $db->sql_query($sql)) )
681                 {
682                         message_die(GENERAL_ERROR, 'Could not update topics table', '', __LINE__, __FILE__, $sql);
683                 }
684
685                 if ( !empty($topic_id) )
686                 {
687                         $redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
688                         $message = sprintf($lang['Click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
689                 }
690                 else
691                 {
692                         $redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
693                         $message = sprintf($lang['Click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
694                 }
695
696                 $message = $message . '<br \><br \>' . sprintf($lang['Click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
697
698                 $template->assign_vars(array(
699                         'META' => '<meta http-equiv="refresh" content="3;url=' . $redirect_page . '">')
700                 );
701
702                 message_die(GENERAL_MESSAGE, $lang['Topics_Unlocked'] . '<br /><br />' . $message);
703
704                 break;
705
706         case 'split':
707                 $page_title = $lang['Mod_CP'];
708                 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
709
710                 $post_id_sql = '';
711
712                 if (isset($HTTP_POST_VARS['split_type_all']) || isset($HTTP_POST_VARS['split_type_beyond']))
713                 {
714                         $posts = $HTTP_POST_VARS['post_id_list'];
715
716                         for ($i = 0; $i < count($posts); $i++)
717                         {
718                                 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($posts[$i]);
719                         }
720                 }
721
722                 if ($post_id_sql != '')
723                 {
724                         $sql = "SELECT post_id 
725                                 FROM " . POSTS_TABLE . "
726                                 WHERE post_id IN ($post_id_sql)
727                                         AND forum_id = $forum_id";
728                         if ( !($result = $db->sql_query($sql)) )
729                         {
730                                 message_die(GENERAL_ERROR, 'Could not get post id information', '', __LINE__, __FILE__, $sql);
731                         }
732                         
733                         $post_id_sql = '';
734                         while ($row = $db->sql_fetchrow($result))
735                         {
736                                 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
737                         }
738                         $db->sql_freeresult($result);
739
740                         $sql = "SELECT post_id, poster_id, topic_id, post_time
741                                 FROM " . POSTS_TABLE . "
742                                 WHERE post_id IN ($post_id_sql) 
743                                 ORDER BY post_time ASC";
744                         if (!($result = $db->sql_query($sql)))
745                         {
746                                 message_die(GENERAL_ERROR, 'Could not get post information', '', __LINE__, __FILE__, $sql);
747                         }
748
749                         if ($row = $db->sql_fetchrow($result))
750                         {
751                                 $first_poster = $row['poster_id'];
752                                 $topic_id = $row['topic_id'];
753                                 $post_time = $row['post_time'];
754
755                                 $user_id_sql = '';
756                                 $post_id_sql = '';
757                                 do
758                                 {
759                                         $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
760                                         $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);;
761                                 }
762                                 while ($row = $db->sql_fetchrow($result));
763
764                                 $post_subject = trim(htmlspecialchars($HTTP_POST_VARS['subject']));
765                                 if (empty($post_subject))
766                                 {
767                                         message_die(GENERAL_MESSAGE, $lang['Empty_subject']);
768                                 }
769
770                                 $new_forum_id = intval($HTTP_POST_VARS['new_forum_id']);
771                                 $topic_time = time();
772                                 
773                                 $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
774                                         WHERE forum_id = ' . $new_forum_id;
775                                 if ( !($result = $db->sql_query($sql)) )
776                                 {
777                                         message_die(GENERAL_ERROR, 'Could not select from forums table', '', __LINE__, __FILE__, $sql);
778                                 }
779                         
780                                 if (!$db->sql_fetchrow($result))
781                                 {
782                                         message_die(GENERAL_MESSAGE, 'New forum does not exist');
783                                 }
784
785                                 $db->sql_freeresult($result);
786
787                                 $sql  = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type)
788                                         VALUES ('" . str_replace("\'", "''", $post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ")";
789                                 if (!($db->sql_query($sql, BEGIN_TRANSACTION)))
790                                 {
791                                         message_die(GENERAL_ERROR, 'Could not insert new topic', '', __LINE__, __FILE__, $sql);
792                                 }
793
794                                 $new_topic_id = $db->sql_nextid();
795
796                                 // Update topic watch table, switch users whose posts
797                                 // have moved, over to watching the new topic
798                                 $sql = "UPDATE " . TOPICS_WATCH_TABLE . " 
799                                         SET topic_id = $new_topic_id 
800                                         WHERE topic_id = $topic_id 
801                                                 AND user_id IN ($user_id_sql)";
802                                 if (!$db->sql_query($sql))
803                                 {
804                                         message_die(GENERAL_ERROR, 'Could not update topics watch table', '', __LINE__, __FILE__, $sql);
805                                 }
806
807                                 $sql_where = (!empty($HTTP_POST_VARS['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
808
809                                 $sql =  "UPDATE " . POSTS_TABLE . "
810                                         SET topic_id = $new_topic_id, forum_id = $new_forum_id 
811                                         WHERE $sql_where";
812                                 if (!$db->sql_query($sql, END_TRANSACTION))
813                                 {
814                                         message_die(GENERAL_ERROR, 'Could not update posts table', '', __LINE__, __FILE__, $sql);
815                                 }
816
817                                 sync('topic', $new_topic_id);
818                                 sync('topic', $topic_id);
819                                 sync('forum', $new_forum_id);
820                                 sync('forum', $forum_id);
821
822                                 $template->assign_vars(array(
823                                         'META' => '<meta http-equiv="refresh" content="3;url=' . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'] . '">')
824                                 );
825
826                                 $message = $lang['Topic_split'] . '<br /><br />' . sprintf($lang['Click_return_topic'], '<a href="' . "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
827                                 message_die(GENERAL_MESSAGE, $message);
828                         }
829                 }
830                 else
831                 {
832                         //
833                         // Set template files
834                         //
835                         $template->set_filenames(array(
836                                 'split_body' => 'modcp_split.tpl')
837                         );
838
839                         $sql = "SELECT u.username, p.*, pt.post_text, pt.bbcode_uid, pt.post_subject, p.post_username
840                                 FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
841                                 WHERE p.topic_id = $topic_id
842                                         AND p.poster_id = u.user_id
843                                         AND p.post_id = pt.post_id
844                                 ORDER BY p.post_time ASC";
845                         if ( !($result = $db->sql_query($sql)) )
846                         {
847                                 message_die(GENERAL_ERROR, 'Could not get topic/post information', '', __LINE__, __FILE__, $sql);
848                         }
849
850                         $s_hidden_fields = '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" /><input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" /><input type="hidden" name="mode" value="split" />';
851
852                         if( ( $total_posts = $db->sql_numrows($result) ) > 0 )
853                         {
854                                 $postrow = $db->sql_fetchrowset($result);
855
856                                 $template->assign_vars(array(
857                                         'L_SPLIT_TOPIC' => $lang['Split_Topic'],
858                                         'L_SPLIT_TOPIC_EXPLAIN' => $lang['Split_Topic_explain'],
859                                         'L_AUTHOR' => $lang['Author'],
860                                         'L_MESSAGE' => $lang['Message'],
861                                         'L_SELECT' => $lang['Select'],
862                                         'L_SPLIT_SUBJECT' => $lang['Split_title'],
863                                         'L_SPLIT_FORUM' => $lang['Split_forum'],
864                                         'L_POSTED' => $lang['Posted'],
865                                         'L_SPLIT_POSTS' => $lang['Split_posts'],
866                                         'L_SUBMIT' => $lang['Submit'],
867                                         'L_SPLIT_AFTER' => $lang['Split_after'], 
868                                         'L_POST_SUBJECT' => $lang['Post_subject'], 
869                                         'L_MARK_ALL' => $lang['Mark_all'], 
870                                         'L_UNMARK_ALL' => $lang['Unmark_all'], 
871                                         'L_POST' => $lang['Post'], 
872
873                                         'FORUM_NAME' => $forum_name, 
874
875                                         'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"), 
876
877                                         'S_SPLIT_ACTION' => append_sid("modcp.$phpEx"),
878                                         'S_HIDDEN_FIELDS' => $s_hidden_fields,
879                                         'S_FORUM_SELECT' => make_forum_select("new_forum_id", false, $forum_id))
880                                 );
881
882                                 //
883                                 // Define censored word matches
884                                 //
885                                 $orig_word = array();
886                                 $replacement_word = array();
887                                 obtain_word_list($orig_word, $replacement_word);
888
889                                 for($i = 0; $i < $total_posts; $i++)
890                                 {
891                                         $post_id = $postrow[$i]['post_id'];
892                                         $poster_id = $postrow[$i]['poster_id'];
893                                         $poster = $postrow[$i]['username'];
894
895                                         $post_date = create_date($board_config['default_dateformat'], $postrow[$i]['post_time'], $board_config['board_timezone']);
896
897                                         $bbcode_uid = $postrow[$i]['bbcode_uid'];
898                                         $message = $postrow[$i]['post_text'];
899                                         $post_subject = ( $postrow[$i]['post_subject'] != '' ) ? $postrow[$i]['post_subject'] : $topic_title;
900
901                                         //
902                                         // If the board has HTML off but the post has HTML
903                                         // on then we process it, else leave it alone
904                                         //
905                                         if ( !$board_config['allow_html'] )
906                                         {
907                                                 if ( $postrow[$i]['enable_html'] )
908                                                 {
909                                                         $message = preg_replace('#(<)([\/]?.*?)(>)#is', '&lt;\\2&gt;', $message);
910                                                 }
911                                         }
912
913                                         if ( $bbcode_uid != '' )
914                                         {
915                                                 $message = ( $board_config['allow_bbcode'] ) ? bbencode_second_pass($message, $bbcode_uid) : preg_replace('/\:[0-9a-z\:]+\]/si', ']', $message);
916                                         }
917
918                                         if ( count($orig_word) )
919                                         {
920                                                 $post_subject = preg_replace($orig_word, $replacement_word, $post_subject);
921                                                 $message = preg_replace($orig_word, $replacement_word, $message);
922                                         }
923
924                                         $message = make_clickable($message);
925
926                                         if ( $board_config['allow_smilies'] && $postrow[$i]['enable_smilies'] )
927                                         {
928                                                 $message = smilies_pass($message);
929                                         }
930
931                                         $message = str_replace("\n", '<br />', $message);
932                                         
933                                         $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
934                                         $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
935
936                                         $checkbox = ( $i > 0 ) ? '<input type="checkbox" name="post_id_list[]" value="' . $post_id . '" />' : '&nbsp;';
937                                         
938                                         $template->assign_block_vars('postrow', array(
939                                                 'ROW_COLOR' => '#' . $row_color,
940                                                 'ROW_CLASS' => $row_class,
941                                                 'POSTER_NAME' => $poster,
942                                                 'POST_DATE' => $post_date,
943                                                 'POST_SUBJECT' => $post_subject,
944                                                 'MESSAGE' => $message,
945                                                 'POST_ID' => $post_id,
946                                                 
947                                                 'S_SPLIT_CHECKBOX' => $checkbox)
948                                         );
949                                 }
950
951                                 $template->pparse('split_body');
952                         }
953                 }
954                 break;
955
956         case 'ip':
957                 $page_title = $lang['Mod_CP'];
958                 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
959
960                 $rdns_ip_num = ( isset($HTTP_GET_VARS['rdns']) ) ? $HTTP_GET_VARS['rdns'] : "";
961
962                 if ( !$post_id )
963                 {
964                         message_die(GENERAL_MESSAGE, $lang['No_such_post']);
965                 }
966
967                 //
968                 // Set template files
969                 //
970                 $template->set_filenames(array(
971                         'viewip' => 'modcp_viewip.tpl')
972                 );
973
974                 // Look up relevent data for this post
975                 $sql = "SELECT poster_ip, poster_id 
976                         FROM " . POSTS_TABLE . " 
977                         WHERE post_id = $post_id
978                                 AND forum_id = $forum_id";
979                 if ( !($result = $db->sql_query($sql)) )
980                 {
981                         message_die(GENERAL_ERROR, 'Could not get poster IP information', '', __LINE__, __FILE__, $sql);
982                 }
983                 
984                 if ( !($post_row = $db->sql_fetchrow($result)) )
985                 {
986                         message_die(GENERAL_MESSAGE, $lang['No_such_post']);
987                 }
988
989                 $ip_this_post = decode_ip($post_row['poster_ip']);
990                 $ip_this_post = ( $rdns_ip_num == $ip_this_post ) ? gethostbyaddr($ip_this_post) : $ip_this_post;
991
992                 $poster_id = $post_row['poster_id'];
993
994                 $template->assign_vars(array(
995                         'L_IP_INFO' => $lang['IP_info'],
996                         'L_THIS_POST_IP' => $lang['This_posts_IP'],
997                         'L_OTHER_IPS' => $lang['Other_IP_this_user'],
998                         'L_OTHER_USERS' => $lang['Users_this_IP'],
999                         'L_LOOKUP_IP' => $lang['Lookup_IP'], 
1000                         'L_SEARCH' => $lang['Search'],
1001
1002                         'SEARCH_IMG' => $images['icon_search'], 
1003
1004                         'IP' => $ip_this_post, 
1005                                 
1006                         'U_LOOKUP_IP' => "modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=$post_id&amp;" . POST_TOPIC_URL . "=$topic_id&amp;rdns=$ip_this_post&amp;sid=" . $userdata['session_id'])
1007                 );
1008
1009                 //
1010                 // Get other IP's this user has posted under
1011                 //
1012                 $sql = "SELECT poster_ip, COUNT(*) AS postings 
1013                         FROM " . POSTS_TABLE . " 
1014                         WHERE poster_id = $poster_id 
1015                         GROUP BY poster_ip 
1016                         ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1017                 if ( !($result = $db->sql_query($sql)) )
1018                 {
1019                         message_die(GENERAL_ERROR, 'Could not get IP information for this user', '', __LINE__, __FILE__, $sql);
1020                 }
1021
1022                 if ( $row = $db->sql_fetchrow($result) )
1023                 {
1024                         $i = 0;
1025                         do
1026                         {
1027                                 if ( $row['poster_ip'] == $post_row['poster_ip'] )
1028                                 {
1029                                         $template->assign_vars(array(
1030                                                 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ))
1031                                         );
1032                                         continue;
1033                                 }
1034
1035                                 $ip = decode_ip($row['poster_ip']);
1036                                 $ip = ( $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? gethostbyaddr($ip) : $ip;
1037
1038                                 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1039                                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1040
1041                                 $template->assign_block_vars('iprow', array(
1042                                         'ROW_COLOR' => '#' . $row_color, 
1043                                         'ROW_CLASS' => $row_class, 
1044                                         'IP' => $ip,
1045                                         'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1046
1047                                         'U_LOOKUP_IP' => "modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=$post_id&amp;" . POST_TOPIC_URL . "=$topic_id&amp;rdns=" . $row['poster_ip'] . "&amp;sid=" . $userdata['session_id'])
1048                                 );
1049
1050                                 $i++; 
1051                         }
1052                         while ( $row = $db->sql_fetchrow($result) );
1053                 }
1054
1055                 //
1056                 // Get other users who've posted under this IP
1057                 //
1058                 $sql = "SELECT u.user_id, u.username, COUNT(*) as postings 
1059                         FROM " . USERS_TABLE ." u, " . POSTS_TABLE . " p 
1060                         WHERE p.poster_id = u.user_id 
1061                                 AND p.poster_ip = '" . $post_row['poster_ip'] . "'
1062                         GROUP BY u.user_id, u.username
1063                         ORDER BY " . (( SQL_LAYER == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1064                 if ( !($result = $db->sql_query($sql)) )
1065                 {
1066                         message_die(GENERAL_ERROR, 'Could not get posters information based on IP', '', __LINE__, __FILE__, $sql);
1067                 }
1068
1069                 if ( $row = $db->sql_fetchrow($result) )
1070                 {
1071                         $i = 0;
1072                         do
1073                         {
1074                                 $id = $row['user_id'];
1075                                 $username = ( $id == ANONYMOUS ) ? $lang['Guest'] : $row['username'];
1076
1077                                 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1078                                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1079
1080                                 $template->assign_block_vars('userrow', array(
1081                                         'ROW_COLOR' => '#' . $row_color, 
1082                                         'ROW_CLASS' => $row_class, 
1083                                         'USERNAME' => $username,
1084                                         'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['Post'] : $lang['Posts'] ),
1085                                         'L_SEARCH_POSTS' => sprintf($lang['Search_user_posts'], $username), 
1086
1087                                         'U_PROFILE' => ($id == ANONYMOUS) ? "modcp.$phpEx?mode=ip&amp;" . POST_POST_URL . "=" . $post_id . "&amp;" . POST_TOPIC_URL . "=" . $topic_id . "&amp;sid=" . $userdata['session_id'] : append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=$id"),
1088                                         'U_SEARCHPOSTS' => append_sid("search.$phpEx?search_author=" . (($id == ANONYMOUS) ? 'Anonymous' : urlencode($username)) . "&amp;showresults=topics"))
1089                                 );
1090
1091                                 $i++; 
1092                         }
1093                         while ( $row = $db->sql_fetchrow($result) );
1094                 }
1095
1096                 $template->pparse('viewip');
1097
1098                 break;
1099
1100         default:
1101                 $page_title = $lang['Mod_CP'];
1102                 include($phpbb_root_path . 'includes/page_header.'.$phpEx);
1103
1104                 $template->assign_vars(array(
1105                         'FORUM_NAME' => $forum_name,
1106
1107                         'L_MOD_CP' => $lang['Mod_CP'],
1108                         'L_MOD_CP_EXPLAIN' => $lang['Mod_CP_explain'],
1109                         'L_SELECT' => $lang['Select'],
1110                         'L_DELETE' => $lang['Delete'],
1111                         'L_MOVE' => $lang['Move'],
1112                         'L_LOCK' => $lang['Lock'],
1113                         'L_UNLOCK' => $lang['Unlock'],
1114                         'L_TOPICS' => $lang['Topics'], 
1115                         'L_REPLIES' => $lang['Replies'], 
1116                         'L_LASTPOST' => $lang['Last_Post'], 
1117                         'L_SELECT' => $lang['Select'], 
1118
1119                         'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"), 
1120                         'S_HIDDEN_FIELDS' => '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />',
1121                         'S_MODCP_ACTION' => append_sid("modcp.$phpEx"))
1122                 );
1123
1124                 $template->set_filenames(array(
1125                         'body' => 'modcp_body.tpl')
1126                 );
1127                 make_jumpbox('modcp.'.$phpEx);
1128
1129                 //
1130                 // Define censored word matches
1131                 //
1132                 $orig_word = array();
1133                 $replacement_word = array();
1134                 obtain_word_list($orig_word, $replacement_word);
1135
1136                 $sql = "SELECT t.*, u.username, u.user_id, p.post_time
1137                         FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p
1138                         WHERE t.forum_id = $forum_id
1139                                 AND t.topic_poster = u.user_id
1140                                 AND p.post_id = t.topic_last_post_id
1141                         ORDER BY t.topic_type DESC, p.post_time DESC
1142                         LIMIT $start, " . $board_config['topics_per_page'];
1143                 if ( !($result = $db->sql_query($sql)) )
1144                 {
1145                         message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
1146                 }
1147
1148                 while ( $row = $db->sql_fetchrow($result) )
1149                 {
1150                         $topic_title = '';
1151
1152                         if ( $row['topic_status'] == TOPIC_LOCKED )
1153                         {
1154                                 $folder_img = $images['folder_locked'];
1155                                 $folder_alt = $lang['Topic_locked'];
1156                         }
1157                         else
1158                         {
1159                                 if ( $row['topic_type'] == POST_ANNOUNCE )
1160                                 {
1161                                         $folder_img = $images['folder_announce'];
1162                                         $folder_alt = $lang['Topic_Announcement'];
1163                                 }
1164                                 else if ( $row['topic_type'] == POST_STICKY )
1165                                 {
1166                                         $folder_img = $images['folder_sticky'];
1167                                         $folder_alt = $lang['Topic_Sticky'];
1168                                 }
1169                                 else 
1170                                 {
1171                                         $folder_img = $images['folder'];
1172                                         $folder_alt = $lang['No_new_posts'];
1173                                 }
1174                         }
1175
1176                         $topic_id = $row['topic_id'];
1177                         $topic_type = $row['topic_type'];
1178                         $topic_status = $row['topic_status'];
1179                         
1180                         if ( $topic_type == POST_ANNOUNCE )
1181                         {
1182                                 $topic_type = $lang['Topic_Announcement'] . ' ';
1183                         }
1184                         else if ( $topic_type == POST_STICKY )
1185                         {
1186                                 $topic_type = $lang['Topic_Sticky'] . ' ';
1187                         }
1188                         else if ( $topic_status == TOPIC_MOVED )
1189                         {
1190                                 $topic_type = $lang['Topic_Moved'] . ' ';
1191                         }
1192                         else
1193                         {
1194                                 $topic_type = '';               
1195                         }
1196         
1197                         if ( $row['topic_vote'] )
1198                         {
1199                                 $topic_type .= $lang['Topic_Poll'] . ' ';
1200                         }
1201         
1202                         $topic_title = $row['topic_title'];
1203                         if ( count($orig_word) )
1204                         {
1205                                 $topic_title = preg_replace($orig_word, $replacement_word, $topic_title);
1206                         }
1207
1208                         $u_view_topic = "modcp.$phpEx?mode=split&amp;" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
1209                         $topic_replies = $row['topic_replies'];
1210
1211                         $last_post_time = create_date($board_config['default_dateformat'], $row['post_time'], $board_config['board_timezone']);
1212
1213                         $template->assign_block_vars('topicrow', array(
1214                                 'U_VIEW_TOPIC' => $u_view_topic,
1215
1216                                 'TOPIC_FOLDER_IMG' => $folder_img, 
1217                                 'TOPIC_TYPE' => $topic_type, 
1218                                 'TOPIC_TITLE' => $topic_title,
1219                                 'REPLIES' => $topic_replies,
1220                                 'LAST_POST_TIME' => $last_post_time,
1221                                 'TOPIC_ID' => $topic_id,
1222                                         
1223                                 'L_TOPIC_FOLDER_ALT' => $folder_alt)
1224                         );
1225                 }
1226
1227                 $template->assign_vars(array(
1228                         'PAGINATION' => generate_pagination("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'], $forum_topics, $board_config['topics_per_page'], $start),
1229                         'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $forum_topics / $board_config['topics_per_page'] )), 
1230                         'L_GOTO_PAGE' => $lang['Goto_page'])
1231                 );
1232
1233                 $template->pparse('body');
1234
1235                 break;
1236 }
1237
1238 include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
1239
1240 ?>