root/phpBB2/modcp.php

Revision 324, 71.8 kB (checked in by Nafania, 1 year ago)

Много мелких изменений. Если используется xbtt, то надо обязательно скачать новую версию на форуме.
Добавлен файл cron.php - если есть возможность, то пускайте cron таски через него. Особенно если используете массовую рассылку почты.

Line 
1 <?php
2 /***************************************************************************</span>
3 <span class="code-comment"> *                                 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 if ( !defined('IN_PHPBB2_BRIDGE') ) {</span>
32 <span class="code-keyword">    trigger_error('Invalid access');
33 }
34
35 define('IN_PHPBB', true);
36 $root_path = './';</span>
37 <span class="code-lang">include($root_path . 'extension.inc');
38 include($root_path . 'phpBB2/includes/bbcode.'.$phpEx);
39 require($root_path . 'include/functions_admin.'.$phpEx);
40 include($root_path . 'include/bbcode/bbcode.lib.php');
41
42 //</span>
43 <span class="code-comment">// Obtain initial var settings
44 //
45 if ( isset($_GET[POST_FORUM_URL]) || isset($_POST[POST_FORUM_URL]) )</span>
46 <span class="code-keyword">{
47         $forum_id = (isset($_POST[POST_FORUM_URL])) ? intval($_POST[POST_FORUM_URL]) : intval($_GET[POST_FORUM_URL]);
48 }
49 else
50 {
51         $forum_id = '';
52 }
53
54 if ( isset($_GET[POST_POST_URL]) || isset($_POST[POST_POST_URL]) )
55 {
56         $post_id = (isset($_POST[POST_POST_URL])) ? intval($_POST[POST_POST_URL]) : intval($_GET[POST_POST_URL]);
57 }
58 else
59 {
60         $post_id = '';
61 }
62
63 if ( isset($_GET[POST_TOPIC_URL]) || isset($_POST[POST_TOPIC_URL]) )
64 {
65         $topic_id = (isset($_POST[POST_TOPIC_URL])) ? intval($_POST[POST_TOPIC_URL]) : intval($_GET[POST_TOPIC_URL]);
66 }
67 else
68 {
69         $topic_id = '';
70 }
71
72 $confirm = ( isset($_POST['confirm']) ) ? TRUE : 0;
73
74 //</span>
75 <span class="code-comment">// Continue var definitions
76 //
77 $start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
78 $start = ($start < 0) ? 0 : $start;
79
80 $delete = ( isset($_POST['delete']) ) ? TRUE : FALSE;
81 $move = ( isset($_POST['move']) ) ? TRUE : FALSE;
82 $lock = ( isset($_POST['lock']) ) ? TRUE : FALSE;
83 $unlock = ( isset($_POST['unlock']) ) ? TRUE : FALSE;
84 // [begin] Mass Delete Posts (From Topic) Mod
85 $delete_posts = ( isset($_POST['delete_posts']) ) ? TRUE : FALSE;
86 // [end] Mass Delete Posts (From Topic) Mod
87
88 if ( isset($_POST['mode']) || isset($_GET['mode']) )</span>
89 <span class="code-keyword">{
90         $mode = ( isset($_POST['mode']) ) ? $_POST['mode'] : $_GET['mode'];
91         $mode = htmlspecialchars($mode);
92 }
93 else
94 {
95         if ( $delete )
96         {
97                 $mode = 'delete';
98         }
99         else if ( $move )
100         {
101                 $mode = 'move';
102         }
103         else if ( $lock )
104         {
105                 $mode = 'lock';
106         }
107         else if ( $unlock )
108         {
109                 $mode = 'unlock';
110         }
111         // [begin] Mass Delete Posts (From Topic) Mod
112         else if ( $delete_posts )
113         {
114                 $mode = 'delete_posts';
115         }
116         // [end] Mass Delete Posts (From Topic) Mod
117         else
118         {
119                 $mode = '';
120         }
121 }
122
123 // session id check
124 $sid = request_var('sid', '');
125
126 //</span>
127 <span class="code-comment">// Obtain relevant data
128 //
129 if ( !empty($topic_id) )</span>
130 <span class="code-keyword">{
131         $sql = "SELECT f.forum_id, f.forum_name, f.forum_topics
132                 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
133                 WHERE t.topic_id = " . $topic_id . "
134                         AND f.forum_id = t.forum_id";
135         $result = $db->sql_query($sql);
136         $topic_row = $db->sql_fetchrow($result);
137
138         if (!$topic_row)
139         {
140                 trigger_error($lang['topic_post_not_exist']);
141                 return;
142         }
143
144         $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
145         $forum_id = $topic_row['forum_id'];
146         $forum_name = $topic_row['forum_name'];
147 }
148 else if ( !empty($forum_id) )
149 {
150         $sql = "SELECT forum_name, forum_topics
151                 FROM " . FORUMS_TABLE . "
152                 WHERE forum_id = " . $forum_id;
153         $result = $db->sql_query($sql);
154         $topic_row = $db->sql_fetchrow($result);
155
156         if (!$topic_row)
157         {
158                 trigger_error($lang['forum_not_exist']);
159                 return;
160         }
161
162         $forum_topics = ( $topic_row['forum_topics'] == 0 ) ? 1 : $topic_row['forum_topics'];
163         $forum_name = $topic_row['forum_name'];
164 }
165 else
166 {
167         trigger_error($lang['forum_not_exist']);
168         return;
169 }
170 // www.phpBB-SEO.com SEO TOOLKIT BEGIN
171 $seo->set_url($forum_name, $forum_id, $seo->seo_static['forum']);
172 // www.phpBB-SEO.com SEO TOOLKIT END</span>
173 <span class="code-comment">
174 //
175 // Start session management
176 //
177 $userdata = session_pagestart($user_ip, $forum_id);
178 init_userprefs($userdata);
179 //</span>
180 <span class="code-comment">// End session management
181 //
182
183 /* */
184 $bb_code = new bbcode;
185 /* */</span>
186 <span class="code-comment">
187 // session id check
188 if ($sid == '' || $sid != $userdata['session_id'])</span>
189 <span class="code-keyword">{
190         trigger_error($lang['invalid_session']);
191         return;
192 }
193
194 //</span>
195 <span class="code-comment">// Check if user did or did not confirm
196 // If they did not, forward them to the last page they were on
197 //
198 if ( isset($_POST['cancel']) )</span>
199 <span class="code-keyword">{
200         if ( $topic_id )
201         {
202                 //$redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id";
203                 $redirect = $root_path . "phpbb2.php?page=viewtopic&" . POST_TOPIC_URL . "=$topic_id";
204         }
205         else if ( $forum_id )
206         {
207                 //$redirect = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id";
208                 $redirect = $root_path . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$forum_id";
209         }
210         else
211         {
212                 //$redirect = "index.$phpEx";
213                 $redirect = $root_path . "phpbb2.php?page=index";
214         }
215
216         redirect(append_sid($redirect));
217 }
218
219 //</span>
220 <span class="code-comment">// Start auth check
221 //
222 $is_auth = auth(AUTH_ALL, $forum_id, $userdata);</span>
223 <span class="code-lang">
224 if ( !$is_auth['auth_mod'] )
225 {
226         trigger_error($lang['not_moderator']);
227         return;
228 }
229 //</span>
230 <span class="code-comment">// End Auth Check
231 //
232
233 //
234 // Do major work ...
235 //
236 switch( $mode )</span>
237 <span class="code-keyword">{
238         case 'delete':
239                 if (!$is_auth['auth_delete'])
240                 {
241                         trigger_error(sprintf($lang['sorry_auth_delete'], $is_auth['auth_delete_type']));
242                         return;
243                 }
244
245                 if ( $confirm )
246                 {
247                     if ( empty($_POST['topic_id_list']) && empty($topic_id) )
248                         {
249                                 trigger_error($lang['none_selected']);
250                         }
251                         include($root_path . 'phpBB2/includes/functions_search.'.$phpEx);
252
253                         $topics = ( isset($_POST['topic_id_list']) ) ? $_POST['topic_id_list'] : array($topic_id);
254
255                         $topic_id_sql = '';
256                         for($i = 0; $i < count($topics); $i++)
257                         {
258                                 $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
259                         }
260
261                         $sql = "SELECT topic_id
262                                 FROM " . TOPICS_TABLE . "
263                                 WHERE topic_id IN ($topic_id_sql)
264                                         AND forum_id = $forum_id";
265                         $result = $db->sql_query($sql);
266
267                         $topic_id_sql = '';
268                         while ($row = $db->sql_fetchrow($result))
269                         {
270                                 $topic_id_sql .= (($topic_id_sql != '') ? ', ' : '') . intval($row['topic_id']);
271                         }
272                         $db->sql_freeresult($result);
273                         if ( $topic_id_sql == '')
274                         {
275                                 trigger_error($lang['none_selected']);
276                         }
277
278                         $sql = "SELECT poster_id, COUNT(post_id) AS posts
279                                 FROM " . POSTS_TABLE . "
280                                 WHERE topic_id IN ($topic_id_sql) AND poster_id <> " . ANONYMOUS . "
281                                 GROUP BY poster_id";
282                         $result = $db->sql_query($sql);
283
284                         $count_sql = array();
285                         while ( $row = $db->sql_fetchrow($result) )
286                         {
287                                 $count_sql[] = "UPDATE " . USERS_TABLE . "
288                                         SET user_posts = user_posts - " . $row['posts'] . "
289                                         WHERE uid = " . $row['poster_id'];
290                         }
291                         $db->sql_freeresult($result);
292
293                         if ( sizeof($count_sql) )
294                         {
295                                 for($i = 0; $i < sizeof($count_sql); $i++)
296                                 {
297                                         $db->sql_query($count_sql[$i]);
298                                 }
299                         }
300
301                         $sql = "SELECT post_id
302                                 FROM " . POSTS_TABLE . "
303                                 WHERE topic_id IN ($topic_id_sql)";
304                         $result = $db->sql_query($sql);
305
306                         $post_id_sql = '';
307                         while ( $row = $db->sql_fetchrow($result) )
308                         {
309                                 $post_id_sql .= ( ( $post_id_sql != '' ) ? ', ' : '' ) . intval($row['post_id']);
310                         }
311                         $db->sql_freeresult($result);
312
313                         $sql = "SELECT vote_id
314                                 FROM " . VOTE_DESC_TABLE . "
315                                 WHERE topic_id IN ($topic_id_sql)";
316                         $result = $db->sql_query($sql);
317
318                         $vote_id_sql = '';
319                         while ( $row = $db->sql_fetchrow($result) )
320                         {
321                                 $vote_id_sql .= ( ( $vote_id_sql != '' ) ? ', ' : '' ) . $row['vote_id'];
322                         }
323                         $db->sql_freeresult($result);
324
325                         //
326                         // Got all required info so go ahead and start deleting everything
327                         //
328                         $sql = "DELETE
329                                 FROM " . TOPICS_TABLE . "
330                                 WHERE topic_id IN ($topic_id_sql)
331                                         OR topic_moved_id IN ($topic_id_sql)";
332                         $db->sql_query($sql);
333
334                         if ( $post_id_sql != '' )
335                         {
336                                 $sql = "DELETE
337                                         FROM " . POSTS_TABLE . "
338                                         WHERE post_id IN ($post_id_sql)";
339                                 $db->sql_query($sql);
340
341                                 $sql = "DELETE
342                                         FROM " . POSTS_TEXT_TABLE . "
343                                         WHERE post_id IN ($post_id_sql)";
344                                 $db->sql_query($sql);
345                                 $sql = 'DELETE
346                                         FROM ' . SIMPATY_TABLE . '
347                                         WHERE simpid IN (' . $post_id_sql . ') AND type = 5';
348                                 $db->sql_query($sql);
349
350
351                                 remove_search_post($post_id_sql);
352                         }
353
354                         if ( $vote_id_sql != '' )
355                         {
356                                 $sql = "DELETE
357                                         FROM " . VOTE_DESC_TABLE . "
358                                         WHERE vote_id IN ($vote_id_sql)";
359                                 $db->sql_query($sql);
360
361                                 $sql = "DELETE
362                                         FROM " . VOTE_RESULTS_TABLE . "
363                                         WHERE vote_id IN ($vote_id_sql)";
364                                 $db->sql_query($sql);
365
366                                 $sql = "DELETE
367                                         FROM " . VOTE_USERS_TABLE . "
368                                         WHERE vote_id IN ($vote_id_sql)";
369                                 $db->sql_query($sql);
370                         }
371
372                         $sql = "DELETE FROM " . COMMENTS_NOTIFY_TABLE . "
373                                 WHERE checkcomm_for_id IN ($topic_id_sql) AND checkcomm_type = " . TYPE_FORUM_POST;
374                         $db->sql_query($sql);
375
376                         sync('forum', $forum_id);
377
378                         if ( !empty($topic_id) )
379                         {
380                                 //$redirect_page = "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
381                                 $redirect_page = $root_path . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
382                                 $l_redirect = sprintf($lang['click_return_forum'], '<a href="' . $redirect_page . '">', '</a>');
383                         }
384                         else
385                         {
386                                 //$redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
387                                 $redirect_page = $root_path . "phpbb2.php?page=modcp&" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
388                                 $l_redirect = sprintf($lang['click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
389                         }
390                         meta_refresh(3, append_sid($redirect_page));
391
392                         trigger_error($lang['topics_removed'] . '<br /><br />' . $l_redirect);
393                         return;
394                 }
395                 else
396                 {
397                         // Not confirmed, show confirmation message
398                         if ( empty($_POST['topic_id_list']) && empty($topic_id) )
399                         {
400                                 trigger_error($lang['none_selected']);
401                                 return;
402                         }
403
404                         $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 . '" />';
405
406                         if ( isset($_POST['topic_id_list']) )
407                         {
408                                 $topics = $_POST['topic_id_list'];
409                                 for($i = 0; $i < count($topics); $i++)
410                                 {
411                                         $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
412                                 }
413                         }
414                         else
415                         {
416                                 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
417                         }
418
419                         //
420                         // Set template files
421                         //
422
423                         $template->assign_vars(array(
424                                 'MESSAGE_TITLE' => $lang['confirm'],
425                                 'MESSAGE_TEXT' => $lang['confirm_delete_topic'],
426                                 'S_CONFIRM_ACTION' => append_sid($root_path . "phpbb2.php?page=modcp"),
427                                 'S_HIDDEN_FIELDS' => $hidden_fields)
428                         );
429
430                         stdhead($lang['forums'] . ' :: ' . $lang['mod_cp'], false);
431
432                         $template->set_filenames(array(
433                                 'body' => 'forum/confirm_body.tpl')
434                         );
435                         return;
436                 }
437                 break;
438
439         case 'move':
440
441                 if ( $confirm )
442                 {
443                         if ( empty($_POST['topic_id_list']) && empty($topic_id) )
444                         {
445                                 trigger_error($lang['none_selected']);
446                                 return;
447                         }
448
449                         $new_forum_id = intval($_POST['new_forum']);
450                         $old_forum_id = $forum_id;
451
452                         $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
453                                 WHERE forum_id = ' . $new_forum_id;
454                         $result = $db->sql_query($sql);
455
456                         if (!$db->sql_fetchrow($result))
457                         {
458                                 trigger_error('New forum does not exist');
459                                 return;
460                         }
461
462                         $db->sql_freeresult($result);
463
464                         if ( $new_forum_id != $old_forum_id )
465                         {
466                                 $topics = ( isset($_POST['topic_id_list']) ) ?  $_POST['topic_id_list'] : array($topic_id);
467
468                                 $topic_list = '';
469                                 for($i = 0; $i < count($topics); $i++)
470                                 {
471                                         $topic_list .= ( ( $topic_list != '' ) ? ', ' : '' ) . intval($topics[$i]);
472                                 }
473
474                                 $sql = "SELECT *
475                                         FROM " . TOPICS_TABLE . "
476                                         WHERE topic_id IN ($topic_list)
477                                                 AND forum_id = $old_forum_id
478                                                 AND topic_status <> " . TOPIC_MOVED;
479                                 $result = $db->sql_query($sql);
480
481                                 $row = $db->sql_fetchrowset($result);
482                                 $db->sql_freeresult($result);
483
484                                 for($i = 0; $i < count($row); $i++)
485                                 {
486                                         $topic_id = $row[$i]['topic_id'];
487
488                                         if ( isset($_POST['move_leave_shadow']) )
489                                         {
490                                             $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
491                                                 'forum_id' => $old_forum_id,
492                                                 'topic_title' => str_replace("\'", "''", $row[$i]['topic_title']),
493                                                 'topic_poster' => str_replace("\'", "''", $row[$i]['topic_poster']),
494                                                 'topic_time' => $row[$i]['topic_time'],
495                                                 'topic_status' => TOPIC_MOVED,
496                                                 'topic_type' => POST_NORMAL,
497                                                 'topic_vote' => $row[$i]['topic_vote'],
498                                                 'topic_views' => $row[$i]['topic_views'],
499                                                 'topic_replies' => $row[$i]['topic_replies'],
500                                                 'topic_first_post_id' => $row[$i]['topic_first_post_id'],
501                                                 'topic_last_post_id' => $row[$i]['topic_last_post_id'],
502                                                 'topic_last_post_time' => $row[$i]['topic_last_post_time'],
503                                                 'topic_moved_id' => $topic_id,
504                                     ));
505                                                 // Insert topic in the old forum that indicates that the forum has moved.
506                                                 $db->sql_query($sql);
507                                         }
508
509                                         $sql = "UPDATE " . TOPICS_TABLE . "
510                                                 SET forum_id = $new_forum_id
511                                                 WHERE topic_id = $topic_id";
512                                         $db->sql_query($sql);
513
514                                         $sql = "UPDATE " . POSTS_TABLE . "
515                                                 SET forum_id = $new_forum_id
516                                                 WHERE topic_id = $topic_id";
517                                         $db->sql_query($sql);
518                                 }
519
520                                 // Sync the forum indexes
521                                 sync('forum', $new_forum_id);
522                                 sync('forum', $old_forum_id);
523
524                                 $message = $lang['topics_moved'] . '<br /><br />';
525
526                         }
527                         else
528                         {
529                                 $message = $lang['no_topics_moved'] . '<br /><br />';
530                         }
531
532                         if ( !empty($topic_id) )
533                         {
534                                 //$redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
535                                 $redirect_page = append_sid($root_path . "phpbb2.php?page=viewtopic&" . POST_TOPIC_URL . "=$topic_id");
536                                 $message .= sprintf($lang['click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
537                         }
538                         else
539                         {
540                                 //$redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
541                                 $redirect_page = append_sid($root_path . "phpbb2.php?page=modcp&" . POST_FORUM_URL . "=$forum_id");
542                                 $message .= sprintf($lang['click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
543                         }
544
545                         //$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>');
546                         $message = $message . '<br \><br \>' . sprintf($lang['click_return_forum'], '<a href="' . append_sid($root_path . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$old_forum_id") . '">', '</a>');
547
548                         meta_refresh(3, $redirect_page);
549
550                         trigger_error($message);
551                         return;
552                 }
553                 else
554                 {
555                         if ( empty($_POST['topic_id_list']) && empty($topic_id) )
556                         {
557                                 trigger_error($lang['none_selected']);
558                                 return;
559                         }
560
561                         $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 . '" />';
562
563                         if ( isset($_POST['topic_id_list']) )
564                         {
565                                 $topics = $_POST['topic_id_list'];
566
567                                 for($i = 0; $i < count($topics); $i++)
568                                 {
569                                         $hidden_fields .= '<input type="hidden" name="topic_id_list[]" value="' . intval($topics[$i]) . '" />';
570                                 }
571                         }
572                         else
573                         {
574                                 $hidden_fields .= '<input type="hidden" name="' . POST_TOPIC_URL . '" value="' . $topic_id . '" />';
575                         }
576
577                         //
578                         // Set template files
579                         //
580
581                         $template->assign_vars(array(
582                                 'MESSAGE_TITLE' => $lang['confirm'],
583                                 'MESSAGE_TEXT' => $lang['confirm_move_topic'],
584                                 'S_FORUM_SELECT' => make_forum_select('new_forum', $forum_id),
585                                 //'S_MODCP_ACTION' => append_sid("modcp.$phpEx"),
586                                 'S_MODCP_ACTION' => append_sid($root_path . "phpbb2.php?page=modcp"),
587                                 'S_HIDDEN_FIELDS' => $hidden_fields)
588                         );
589
590                         stdhead($lang['forums'] . ' :: ' . $lang['mod_cp'], false);
591
592                         $template->set_filenames(array(
593                                 'body' => 'forum/modcp_move.tpl')
594                         );
595
596                         return;
597                 }
598                 break;
599
600         case 'lock':
601                 if ( empty($_POST['topic_id_list']) && empty($topic_id) )
602                 {
603                         trigger_error($lang['none_selected']);
604                         return;
605                 }
606
607                 $topics = ( isset($_POST['topic_id_list']) ) ?  $_POST['topic_id_list'] : array($topic_id);
608
609                 $topic_id_sql = '';
610                 for($i = 0; $i < count($topics); $i++)
611                 {
612                         $topic_id_sql .= ( ( $topic_id_sql != '' ) ? ', ' : '' ) . intval($topics[$i]);
613                 }
614
615                 $sql = "UPDATE " . TOPICS_TABLE . "
616                         SET topic_status = " . TOPIC_LOCKED . "
617                         WHERE topic_id IN ($topic_id_sql)
618                                 AND forum_id = $forum_id
619                                 AND topic_moved_id = 0";
620                 $result = $db->sql_query($sql);
621
622                 if ( !empty($topic_id) )
623                 {
624                         //$redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
625                         $redirect_page = "phpbb2.php?page=viewtopic&" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
626                         $message = sprintf($lang['click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
627                 }
628                 else
629                 {
630                         //$redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
631                         $redirect_page = "phpbb2.php?page=modcp&" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
632                         $message = sprintf($lang['click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
633                 }
634
635                 //$message = $message . '<br \><br \>' . sprintf($lang['click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
636                 $message = $message . '<br \><br \>' . sprintf($lang['click_return_forum'], '<a href="' . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
637
638                 meta_refresh(3, append_sid($redirect_page));
639
640                 trigger_error($lang['topics_locked'] . '<br /><br />' . $message);
641                 return;
642
643                 break;
644
645         case 'unlock':
646                 if ( empty($_POST['topic_id_list']) && empty($topic_id) )
647                 {
648                         trigger_error($lang['none_selected']);
649                         return;
650                 }
651
652                 $topics = ( isset($_POST['topic_id_list']) ) ?  $_POST['topic_id_list'] : array($topic_id);
653
654                 $topic_id_sql = '';
655                 for($i = 0; $i < count($topics); $i++)
656                 {
657                         $topic_id_sql .= ( ( $topic_id_sql != "") ? ', ' : '' ) . intval($topics[$i]);
658                 }
659
660                 $sql = "UPDATE " . TOPICS_TABLE . "
661                         SET topic_status = " . TOPIC_UNLOCKED . "
662                         WHERE topic_id IN ($topic_id_sql)
663                                 AND forum_id = $forum_id
664                                 AND topic_moved_id = 0";
665                 $result = $db->sql_query($sql);
666
667                 if ( !empty($topic_id) )
668                 {
669                         //$redirect_page = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
670                         $redirect_page = "phpbb2.php?page=viewtopic&" . POST_TOPIC_URL . "=$topic_id";
671                         $redirect_page = append_sid($redirect_page, false, true, $userdata['session_id']);
672                         $message = sprintf($lang['click_return_topic'], '<a href="' . $redirect_page . '">', '</a>');
673                 }
674                 else
675                 {
676                         //$redirect_page = "modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'];
677                         $redirect_page = "phpbb2.php?page=modcp&" . POST_FORUM_URL . "=$forum_id";
678                         $redirect_page = append_sid($root_path . $redirect_page, false, true, $userdata['session_id']);
679                         $message = sprintf($lang['click_return_modcp'], '<a href="' . $redirect_page . '">', '</a>');
680                 }
681
682                 //$message = $message . '<br \><br \>' . sprintf($lang['click_return_forum'], '<a href="' . "viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'] . '">', '</a>');
683                 $url = append_sid($root_path . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$forum_id", false, true, $userdata['session_id']);
684                 $message = $message . '<br \><br \>' . sprintf($lang['click_return_forum'], '<a href="' . $url . '">', '</a>');
685
686                 meta_refresh(3, append_sid($redirect_page));
687
688                 trigger_error($lang['topics_unlocked'] . '<br /><br />' . $message);
689                 return;
690
691                 break;
692
693         case 'split':
694
695                 $post_id_sql = '';
696
697                 if (isset($_POST['split_type_all']) || isset($_POST['split_type_beyond']))
698                 {
699                         $posts = request_var('post_id_list', array( '' => '' ) );
700
701                         for ($i = 0; $i < sizeof($posts); $i++)
702                         {
703                                 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($posts[$i]);
704                         }
705                 }
706
707                 if ($post_id_sql != '')
708                 {
709                         $sql = "SELECT post_id
710                                 FROM " . POSTS_TABLE . "
711                                 WHERE post_id IN ($post_id_sql)
712                                         AND forum_id = $forum_id";
713                         $result = $db->sql_query($sql);
714
715                         $post_id_sql = '';
716                         while ($row = $db->sql_fetchrow($result))
717                         {
718                                 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
719                         }
720                         if ($post_id_sql == '')
721                         {
722                                 trigger_error($lang['none_selected']);
723                         }
724                         $db->sql_freeresult($result);
725
726                         // start mod split posts and merge in one step
727                         // check to see if subject (new title of split topic) is empty...if so, and if there is a destination topic, do the regular split (copied from the regular modcp code) and then change the split posts to the destination topic
728                         if (empty($_POST['subject']))
729                         {
730                                 if (!empty($_POST['destination_topic']))
731                                 {
732                                         $destination_topic = $_POST['destination_topic'];
733
734                                         // the next block of code is borrowed from the simply merge mod...it extracts the topic id from topic_id, topic url or post url
735                                         // is this a direct value ?
736                                         $num_topic = intval($destination_topic);
737                                         if ($destination_topic == "$num_topic")
738                                         {
739                                                 $destination_topic_id = $num_topic;
740                                         }
741                                         // is this a url with topic id or post id ?
742                                         else
743                                         {
744                                                 $name = explode('?', $destination_topic);
745                                                 $parms = ( isset($name[1]) ) ? $name[1] : $name[0];
746                                                 parse_str($parms, $parm);
747                                                 $found = false;
748                                                 $destination_topic_id = 0;
749                                                 while ((list($key, $val) = each($parm)) && !$found)
750                                                 {
751                                                         $vals = explode('#', $val);
752                                                         $val = $vals[0];
753                                                         if (empty($val))
754                                                         {
755                                                                 $val = 0;
756                                                         }
757                                                         else $val = intval($val);
758                                                         switch($key)
759                                                         {
760                                                                 case POST_POST_URL:
761                                                                 $sql = "SELECT topic_id FROM " . POSTS_TABLE . " WHERE post_id=$val";
762                                                                 $result = $db->sql_query($sql);
763                                                                 if ($row = $db->sql_fetchrow($result))
764                                                                 {
765                                                                         $val = $row['topic_id'];
766                                                                         $found = true;
767                                                                 }
768                                                                 break;
769
770                                                                 case POST_TOPIC_URL:
771                                                                 $found = true;
772                                                                 break;
773                                                         }
774                                                         if ($found)
775                                                         {
776                                                                 $destination_topic_id = $val;
777                                                         }
778                                                 }
779                                         }
780
781                                         // done with getting topic_id
782                                         // now, get forum id for destination topic
783                                         $sql = "SELECT t.forum_id, f.forum_name, t.topic_title
784                                                 FROM " . TOPICS_TABLE . " t, " . FORUMS_TABLE . " f
785                                                 WHERE topic_id = $destination_topic_id
786                                        AND t.forum_id = f.forum_id";
787                                         $result = $db->sql_query($sql);
788                                         $row = $db->sql_fetchrow($result);
789                                         $destination_forum_id = $row['forum_id'];
790                                         $destination_forum_name = $row['forum_name'];
791                                         $destination_topic_title = $row['topic_title'];
792                                         $db->sql_freeresult($result);
793
794                                         // if there is no forum_id (probably because there is no such topic_id), give error message
795                                         if ($destination_forum_id == '') {
796                                             trigger_error('Could not get forum information (no such topic_id?)');
797                                         }
798
799                                         // now get the posts that are being spit....
800                                         $sql = "SELECT post_id, poster_id, post_time
801                                                 FROM " . POSTS_TABLE . "
802                                                 WHERE post_id IN ($post_id_sql)
803                                                 ORDER BY post_time ASC";
804                                         $result = $db->sql_query($sql);
805
806                                         if ($row = $db->sql_fetchrow($result))
807                                         {
808                                         $post_time = $row['post_time'];
809                                         $user_id_sql = intval($row['poster_id']);
810                                         $post_id_sql = intval($row['post_id']);
811                                         }
812
813                                         do
814                                         {
815                                                 $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
816                                                 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
817                                         }
818                                         while ($row = $db->sql_fetchrow($result));
819
820                                         // Update topic watch table, switch users whose posts
821                                         // have moved, over to watching the destination topic
822                                         $sql = "UPDATE " . COMMENTS_NOTIFY_TABLE . "
823                                                 SET checkcomm_for_id = $destination_topic_id
824                                                 WHERE checkcomm_for_id = $topic_id
825                                                 AND checkcomm_type = " . TYPE_FORUM_POST . "
826                                                 AND checkcomm_userid IN ($user_id_sql)";
827                                         $db->sql_query($sql);
828
829                                         $sql_where = (!empty($_POST['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
830
831                                         // now do a sql for switching the split posts over to the destination topic and forum
832                                         $sql =         "UPDATE " . POSTS_TABLE . "
833                                                 SET topic_id = $destination_topic_id, forum_id = $destination_forum_id
834                                                 WHERE $sql_where";
835                                         $db->sql_query($sql);
836                                         sync('topic', $destination_topic_id);
837                                         sync('topic', $topic_id);
838                                         sync('forum', $destination_forum_id);
839                                         sync('forum', $forum_id);
840
841                                 // www.phpBB-SEO.com SEO TOOLKIT BEGIN
842                                 $seo->set_url($destination_forum_name, $destination_forum_id, $seo->seo_static['forum']);
843                                 $seo->set_parent($destination_topic_id, $seo->seo_static['topic'], $destination_forum_id, $seo->seo_static['forum']);
844                                 $seo->set_url($destination_topic_title, $destination_topic_id, $seo->seo_static['topic']);
845                                 // www.phpBB-SEO.com SEO TOOLKIT END
846
847                                 $url = append_sid($root_path . "phpbb2.php?page=viewtopic&" . POST_TOPIC_URL . "=$destination_topic_id", false, true, $userdata['session_id']);
848
849                                         meta_refresh(3, $url);
850
851                                         $message = $lang['topic_split'] . '<br /><br />' . sprintf($lang['click_return_topic'], '<a href="' . $url . '">', '</a>');
852                                         trigger_error($message);
853                                 }
854                         }
855                         // end mod split posts and merge in one step
856
857                         $sql = "SELECT post_id, poster_id, topic_id, post_time
858                                 FROM " . POSTS_TABLE . "
859                                 WHERE post_id IN ($post_id_sql)
860                                 ORDER BY post_time ASC";
861                         $result = $db->sql_query($sql);
862
863                         if ($row = $db->sql_fetchrow($result))
864                         {
865                                 $first_poster = $row['poster_id'];
866                                 $topic_id = $row['topic_id'];
867                                 $post_time = $row['post_time'];
868
869                                 $user_id_sql = '';
870                                 $post_id_sql = '';
871                                 do
872                                 {
873                                         $user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
874                                         $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);;
875                                 }
876                                 while ($row = $db->sql_fetchrow($result));
877
878                                 $post_subject = request_var('subject', '');
879                                 if (empty($post_subject))
880                                 {
881                                         trigger_error($lang['empty_subject']);
882                                         return;
883                                 }
884
885                                 $new_forum_id = request_var('new_forum_id', 0);
886
887                                 $topic_time = time();
888
889                                 $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . '
890                                         WHERE forum_id = ' . $new_forum_id;
891                                 $result = $db->sql_query($sql);
892
893                                 if (!$db->sql_fetchrow($result))
894                                 {
895                                         trigger_error('New forum does not exist');
896                                         return;
897                                 }
898
899                                 $db->sql_freeresult($result);
900
901                                 $sql  = "INSERT INTO " . TOPICS_TABLE . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type)
902                                         VALUES ('" . str_replace("\'", "''", $post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ")";
903                                 $db->sql_query($sql);
904
905                                 $new_topic_id = $db->sql_nextid();
906
907                                 // Update topic watch table, switch users whose posts
908                                 // have moved, over to watching the new topic
909                                 $sql = "UPDATE " . COMMENTS_NOTIFY_TABLE . "
910                                         SET checkcomm_for_id = $new_topic_id
911                                         WHERE checkcomm_for_id = $topic_id
912                                         AND checkcomm_type = " . TYPE_FORUM_POST . "
913                                                 AND checkcomm_userid IN ($user_id_sql)";
914                                 $db->sql_query($sql);
915
916                                 $sql_where = (!empty($_POST['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
917
918                                 $sql =         "UPDATE " . POSTS_TABLE . "
919                                         SET topic_id = $new_topic_id, forum_id = $new_forum_id
920                                         WHERE $sql_where";
921                                 $db->sql_query($sql);
922
923                                 sync('topic', $new_topic_id);
924                                 sync('topic', $topic_id);
925                                 sync('forum', $new_forum_id);
926                                 sync('forum', $forum_id);
927
928                             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
929                             $seo->set_parent($topic_id, $seo->seo_static['topic'], $forum_id, $seo->seo_static['forum']);
930                             $seo->set_url($post_subject, $topic_id, $seo->seo_static['topic']);
931                             // www.phpBB-SEO.com SEO TOOLKIT END
932
933                                 $url = append_sid($root_path . "phpbb2.php?page=viewtopic&" . POST_TOPIC_URL . "=$topic_id", false, true, $userdata['session_id']);
934                           meta_refresh(3, $url);
935
936                                 //$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>');
937                                 $message = $lang['topic_split'] . '<br /><br />' . sprintf($lang['click_return_topic'], '<a href="' . $url . '">', '</a>');
938                                 trigger_error($message);
939                                 return;
940                         }
941                 }
942                 else
943                 {
944                         //
945                         // Set template files
946                         //
947                         // Begin Simple Subforums MOD
948                     $all_forums = array();
949                     make_jumpbox_ref('phpbb2.php?page=modcp', $forum_id, $all_forums);
950
951                     $parent_id = 0;
952                     for( $i = 0; $i < count($all_forums); $i++ )
953                     {
954                         if( $all_forums[$i]['forum_id'] == $forum_id )
955                         {
956                             $parent_id = $all_forums[$i]['forum_parent'];
957                         }
958                     }
959
960                     if( $parent_id )
961                     {
962                         for( $i = 0; $i < count($all_forums); $i++)
963                         {
964                             if( $all_forums[$i]['forum_id'] == $parent_id )
965                             {
966                                 // www.phpBB-SEO.com SEO TOOLKIT BEGIN
967                                 //$seo->set_parent($topic_id, $seo->seo_static['topic'], $forum_id, $seo->seo_static['forum']);
968                                 $seo->set_url($all_forums[$i]['forum_name'], $all_forums[$i]['forum_id'], $seo->seo_static['forum']);
969                                 // www.phpBB-SEO.com SEO TOOLKIT END
970
971                                 $template->assign_vars(array(
972                                     'PARENT_FORUM'            => 1,
973                                     'U_VIEW_PARENT_FORUM'    => append_sid($root_path . "phpbb2.php?page=viewforum&amp;" . POST_FORUM_URL .'=' . $all_forums[$i]['forum_id']),
974                                     'PARENT_FORUM_NAME'        => $all_forums[$i]['forum_name'],
975                                 ));
976                             }
977                         }
978                     }
979                     // End Simple Subforums MOD
980
981                         $sql = "SELECT u.name AS username, p.*, pt.post_text, pt.post_subject, p.post_username
982                                 FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
983                                 WHERE p.topic_id = $topic_id
984                                         AND p.poster_id = u.uid
985                                         AND p.post_id = pt.post_id
986                                 ORDER BY p.post_time ASC";
987                         $result = $db->sql_query($sql);
988
989                         $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" />';
990
991                         if( $postrow = $db->sql_fetchrow($result) )
992                         {
993                         // www.phpBB-SEO.com SEO TOOLKIT BEGIN
994                         $seo->set_url($forum_name, $forum_id, $seo->seo_static['forum']);
995                         // www.phpBB-SEO.com SEO TOOLKIT END
996
997                                 $template->assign_vars(array(
998                                         'FORUM_NAME' => $forum_name,
999                                         'U_VIEW_FORUM' => append_sid($root_path . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$forum_id"),
1000                                         'S_SPLIT_ACTION' => append_sid($root_path . "phpbb2.php?page=modcp"),
1001                                         'S_HIDDEN_FIELDS' => $s_hidden_fields,
1002                                         'S_FORUM_SELECT' => make_forum_select("new_forum_id", false, $forum_id))
1003                                 );
1004
1005                             $i = 0;
1006
1007                                 do
1008                               {
1009                                   $post_id = $postrow['post_id'];
1010                                         $poster_id = $postrow['poster_id'];
1011                                         $poster = ( $poster_id == ANONYMOUS ) ? $lang['guest'] : $postrow['username'];
1012
1013                                         $post_date = create_date($postrow['post_time']);
1014
1015                                         $message = $postrow['post_text'];
1016                                         $post_subject = $postrow['post_subject'];
1017
1018                                         //
1019                                         // If the board has HTML off but the post has HTML
1020                                         // on then we process it, else leave it alone
1021                                         //
1022                                         if ( !$config['allow_html'] )
1023                                         {
1024                                                 if ( $postrow['enable_html'] )
1025                                                 {
1026                                                         $message = preg_replace('#(<)([\/]?.*?)(>)#is', '&lt;\\2&gt;', $message);
1027                                                 }
1028                                         }
1029
1030                                 $bb_code->parse($message);
1031                                 $message = $bb_code->get_html();
1032
1033                                         $post_subject = censor_text($post_subject);
1034                                         $message = censor_text($message);
1035
1036                                         $message = str_replace("\n", '<br />', $message);
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                                         $checkbox = ( $i > 0 ) ? '<input type="checkbox" name="post_id_list[]" value="' . $post_id . '" />' : '&nbsp;';
1042
1043                                         $template->assign_block_vars('postrow', array(
1044                                                 'ROW_COLOR' => '#' . $row_color,
1045                                                 'ROW_CLASS' => $row_class,
1046                                                 'POSTER_NAME' => $poster,
1047                                                 'POST_DATE' => $post_date,
1048                                                 'POST_SUBJECT' => $post_subject,
1049                                                 'MESSAGE' => $message,
1050                                                 'POST_ID' => $post_id,
1051
1052                                                 'S_SPLIT_CHECKBOX' => $checkbox)
1053                                         );
1054
1055                                     ++$i;
1056                                 }
1057                                 while ( $postrow = $db->sql_fetchrow($result) ) ;
1058
1059                                 stdhead($lang['forums'] . ' :: ' . $lang['mod_cp'], false);
1060
1061                             $template->set_filenames(array(
1062                                     'body' => 'forum/modcp_split.tpl')
1063                             );
1064                         }
1065                         else {
1066                             trigger_error('invalid topic');
1067                         }
1068                 }
1069                 break;
1070
1071         // [begin] Mass Delete Posts (From Topic) Mod
1072         case 'delete_posts':
1073                 if (!$is_auth['auth_delete'])
1074                 {
1075                         trigger_error(sprintf($lang['sorry_auth_delete'], $is_auth['auth_delete_type']));
1076                 }
1077
1078                 include($root_path . 'phpBB2/includes/functions_search.'.$phpEx);
1079
1080                 $post_id_sql = '';
1081
1082                 if (isset($_POST['delete_posts']))
1083                 {
1084                         $posts = $_POST['post_id_list'];
1085
1086                         for ($i = 0; $i < count($posts); $i++)
1087                         {
1088                                 $post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($posts[$i]);
1089                         }
1090                 }
1091
1092                 if ( $post_id_sql != '' )
1093                 {
1094                         $sql = "SELECT poster_id, COUNT(post_id) AS posts FROM " . POSTS_TABLE . " WHERE post_id IN ($post_id_sql) GROUP BY poster_id";
1095                         $result = $db->sql_query($sql);
1096
1097                         $count_sql = array();
1098                         while ( $row = $db->sql_fetchrow($result) )
1099                         {
1100                                 $count_sql[] = "UPDATE " . USERS_TABLE . " SET user_posts = user_posts - " . $row['posts'] . " WHERE uid = " . $row['poster_id'];
1101                         }
1102                         $db->sql_freeresult($result);
1103
1104                         if ( sizeof($count_sql) )
1105                         {
1106                                 for($i = 0; $i < sizeof($count_sql); $i++)
1107                                 {
1108                                         $db->sql_query($count_sql[$i]);
1109                                 }
1110                         }
1111
1112                         $sql = "DELETE FROM " . POSTS_TABLE . " WHERE post_id IN ($post_id_sql)";
1113                         $db->sql_query($sql);
1114                         $sql = "DELETE FROM " . POSTS_TEXT_TABLE . " WHERE post_id IN ($post_id_sql)";
1115                         $db->sql_query($sql);
1116                         $sql = 'DELETE FROM ' . SIMPATY_TABLE . ' WHERE simpid IN (' . $post_id_sql . ') AND type = 5';
1117                         $db->sql_query($sql);
1118
1119                         remove_search_post($post_id_sql);
1120
1121                         sync('topic', $topic_id);
1122                         sync('forum', $forum_id);
1123
1124                     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
1125                     $seo->set_url($forum_name, $forum_id, $seo->seo_static['forum']);
1126                     // www.phpBB-SEO.com SEO TOOLKIT END
1127
1128                     $url = append_sid($root_path . "phpbb2.php?page=viewtopic&" . POST_TOPIC_URL . "=$topic_id", false, true, $userdata['session_id']);
1129
1130                         meta_refresh(3, $url);
1131
1132                         $message = $lang['delete_posts_succesfully'] . '<br /><br />' . sprintf($lang['click_return_topic'], '<a href="' . $url . '">', '</a>');
1133                         trigger_error($message);
1134
1135                 }
1136                 else
1137                 {
1138                         //
1139                         // Set template files
1140                         //
1141
1142                         $sql = "SELECT u.name AS username, p.*, pt.post_text, pt.post_subject, p.post_username
1143                                 FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u, " . POSTS_TEXT_TABLE . " pt
1144                                 WHERE p.topic_id = $topic_id
1145                                         AND p.poster_id = u.uid
1146                                         AND p.post_id = pt.post_id
1147                                 ORDER BY p.post_time ASC";
1148                         $result = $db->sql_query($sql);
1149
1150                         $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="delete_posts" />';
1151
1152                         if( $postrow = $db->sql_fetchrow($result) )
1153                         {
1154                             $i = 0;
1155
1156                                 $template->assign_vars(array(
1157                                         'FORUM_NAME' => $forum_name,
1158
1159                                         'U_VIEW_FORUM' => append_sid($root_path . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$forum_id"),
1160
1161                                         'S_DELETE_POSTS_ACTION' => append_sid($root_path . "phpbb2.php?page=modcp"),
1162                                         'S_HIDDEN_FIELDS' => $s_hidden_fields)
1163                                 );
1164
1165
1166                                 do
1167                                 {
1168                                         $post_id = $postrow['post_id'];
1169                                         $poster_id = $postrow['poster_id'];
1170                                         $poster = ( $poster_id == ANONYMOUS ) ? $lang['guest'] : $postrow['username'];
1171
1172                                         $post_date = create_date($postrow['post_time']);
1173
1174                                         $message = $postrow['post_text'];
1175                                         $post_subject = ( $postrow['post_subject'] != '' ) ? $postrow['post_subject'] : '';
1176
1177                                         //
1178                                         // If the board has HTML off but the post has HTML
1179                                         // on then we process it, else leave it alone
1180                                         //
1181                                         if ( !$config['allow_html'] )
1182                                         {
1183                                                 if ( $postrow['enable_html'] )
1184                                                 {
1185                                                         $message = preg_replace('#(<)([\/]?.*?)(>)#is', '&lt;\\2&gt;', $message);
1186                                                 }
1187                                         }
1188
1189                                 $bb_code->parse($message);
1190                                 $message = $bb_code->get_html();
1191
1192                                         $post_subject = censor_text($post_subject);
1193                                         $message = censor_text($message);
1194
1195                                         $message = str_replace("\n", '<br />', $message);
1196
1197                                         $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1198                                         $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1199
1200                                         $checkbox = ( $i > 0 ) ? '<input type="checkbox" name="post_id_list[]" value="' . $post_id . '" />' : '&nbsp;';
1201
1202                                         $template->assign_block_vars('postrow', array(
1203                                                 'ROW_COLOR' => '#' . $row_color,
1204                                                 'ROW_CLASS' => $row_class,
1205                                                 'POSTER_NAME' => $poster,
1206                                                 'POST_DATE' => $post_date,
1207                                                 'POST_SUBJECT' => $post_subject,
1208                                                 'MESSAGE' => $message,
1209                                                 'POST_ID' => $post_id,
1210
1211                                                 'S_DELETE_POST_CHECKBOX' => $checkbox)
1212                                         );
1213                                         ++$i;
1214                                 }
1215                                 while ( $postrow = $db->sql_fetchrow($result) ) ;
1216
1217                         stdhead($lang['forums'] . ' :: ' . $lang['mod_cp'], false);;
1218
1219                             $template->set_filenames(array(
1220                                     'body' => 'forum/modcp_delete_posts.tpl')
1221                             );
1222                         }
1223                 }
1224                 break;
1225                 // [end] Mass Delete Posts (From Topic) Mod
1226
1227         case 'ip':
1228
1229                 $rdns_ip_num = ( isset($_GET['rdns']) ) ? $_GET['rdns'] : "";
1230
1231                 if ( !$post_id )
1232                 {
1233                         trigger_error($lang['no_such_post']);
1234                         return;
1235                 }
1236
1237                 //
1238                 // Set template files
1239                 //
1240
1241                 // Look up relevent data for this post
1242                 $sql = "SELECT poster_ip, poster_id
1243                         FROM " . POSTS_TABLE . "
1244                         WHERE post_id = $post_id
1245                                 AND forum_id = $forum_id";
1246                 $result = $db->sql_query($sql);
1247
1248                 if ( !($post_row = $db->sql_fetchrow($result)) )
1249                 {
1250                         trigger_error($lang['no_such_post']);
1251                         return;
1252                 }
1253
1254                 $ip_this_post = $post_row['poster_ip'];
1255                 $ip_this_post = ( $rdns_ip_num == $ip_this_post ) ? htmlspecialchars(gethostbyaddr($ip_this_post)) : $ip_this_post;
1256
1257                 $poster_id = $post_row['poster_id'];
1258
1259                 $template->assign_vars(array(
1260                         'SEARCH_IMG' => $images['icon_search'],
1261                         'IP' => $ip_this_post,
1262                         'U_LOOKUP_IP' => "phpbb2.php?page=modcp&mode=ip&amp;" . POST_POST_URL . "=$post_id&amp;" . POST_TOPIC_URL . "=$topic_id&amp;rdns=$ip_this_post&amp;sid=" . $userdata['session_id'])
1263                 );
1264
1265                 //
1266                 // Get other IP's this user has posted under
1267                 //
1268                 $sql = "SELECT poster_ip, COUNT(*) AS postings
1269                         FROM " . POSTS_TABLE . "
1270                         WHERE poster_id = $poster_id
1271                         GROUP BY poster_ip
1272                         ORDER BY " . (( $db_type == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1273                 $result = $db->sql_query($sql);
1274
1275                 if ( $row = $db->sql_fetchrow($result) )
1276                 {
1277                         $i = 0;
1278                         do
1279                         {
1280                                 if ( $row['poster_ip'] == $post_row['poster_ip'] )
1281                                 {
1282                                         $template->assign_vars(array(
1283                                                 'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['post'] : $lang['posts'] ))
1284                                         );
1285                                         continue;
1286                                 }
1287
1288                                 $ip = $row['poster_ip'];
1289                                 $ip = ( $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? htmlspecialchars(gethostbyaddr($ip)) : $ip;
1290
1291                                 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1292                                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1293
1294                                 $template->assign_block_vars('iprow', array(
1295                                         'ROW_COLOR' => '#' . $row_color,
1296                                         'ROW_CLASS' => $row_class,
1297                                         'IP' => $ip,
1298                                         'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['post'] : $lang['posts'] ),
1299
1300                                         //'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'])
1301                                         'U_LOOKUP_IP' => "phpbb2.php?page=modcp&mode=ip&amp;" . POST_POST_URL . "=$post_id&amp;" . POST_TOPIC_URL . "=$topic_id&amp;rdns=" . $row['poster_ip'] . "&amp;sid=" . $userdata['session_id'])
1302                                 );
1303
1304                                 $i++;
1305                         }
1306                         while ( $row = $db->sql_fetchrow($result) );
1307                 }
1308
1309                 //
1310                 // Get other users who've posted under this IP
1311                 //
1312                 $sql = "SELECT u.uid, u.name AS username, COUNT(*) AS postings
1313                         FROM " . USERS_TABLE ." u, " . POSTS_TABLE . " p
1314                         WHERE p.poster_id = u.uid
1315                                 AND p.poster_ip = '" . $post_row['poster_ip'] . "'
1316                         GROUP BY u.uid, u.name
1317                         ORDER BY " . (( $db_type == 'msaccess' ) ? 'COUNT(*)' : 'postings' ) . " DESC";
1318                 $result = $db->sql_query($sql);
1319
1320                 if ( $row = $db->sql_fetchrow($result) )
1321                 {
1322                         $i = 0;
1323                         do
1324                         {
1325                                 $id = $row['uid'];
1326                                 $username = ( $id == ANONYMOUS ) ? $lang['guest'] : $row['username'];
1327
1328                                 $row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
1329                                 $row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
1330
1331                                 $template->assign_block_vars('userrow', array(
1332                                         'ROW_COLOR' => '#' . $row_color,
1333                                         'ROW_CLASS' => $row_class,
1334                                         'USERNAME' => $username,
1335                                         'POSTS' => $row['postings'] . ' ' . ( ( $row['postings'] == 1 ) ? $lang['post'] : $lang['posts'] ),
1336                                         'L_SEARCH_POSTS' => sprintf($lang['search_user_posts'], $username),
1337
1338                                         //'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"),
1339                                         'U_PROFILE' => ($id == ANONYMOUS) ? "phpbb2.php?page=modcp&mode=ip&amp;" . POST_POST_URL . "=" . $post_id . "&amp;" . POST_TOPIC_URL . "=" . $topic_id . "&amp;sid=" . $userdata['session_id'] : append_sid($root_path . "userdetails.php?id=$id"),
1340                                         // FIXME:
1341                                         //'U_SEARCHPOSTS' => append_sid("search.$phpEx?search_author=" . (($id == ANONYMOUS) ? 'Anonymous' : urlencode($username)) . "&amp;showresults=topics"))
1342                                         'U_SEARCHPOSTS' => append_sid($root_path . "phpbb2.php?page=search&search_author=" . urlencode($username) . "&amp;showresults=topics"))
1343                                 );
1344
1345                                 $i++;
1346                         }
1347                         while ( $row = $db->sql_fetchrow($result) );
1348                 }
1349
1350                 stdhead($lang['forums'] . ' :: ' . $lang['mod_cp'], false);
1351
1352                 $template->set_filenames(array(
1353                         'body' => 'forum/modcp_viewip.tpl')
1354                 );
1355
1356                 break;
1357
1358         default:
1359
1360                 $template->assign_vars(array(
1361                         'FORUM_NAME' => $forum_name,
1362
1363                         //'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
1364                         'U_VIEW_FORUM' => append_sid($root_path . "phpbb2.php?page=viewforum&" . POST_FORUM_URL . "=$forum_id"),
1365                         'S_HIDDEN_FIELDS' => '<input type="hidden" name="sid" value="' . $userdata['session_id'] . '" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />',
1366                         //'S_MODCP_ACTION' => append_sid("modcp.$phpEx"))
1367                         'S_MODCP_ACTION' => append_sid($root_path . "phpbb2.php?page=modcp"))
1368                 );
1369
1370                 //make_jumpbox('modcp.'.$phpEx);
1371                 //make_jumpbox('phpbb2.php?page=modcp');
1372                 // Begin Simple Subforums MOD
1373         $all_forums = array();
1374         make_jumpbox_ref('phpbb2.php?page=modcp', $forum_id, $all_forums);
1375
1376         $parent_id = 0;
1377         for( $i = 0; $i < count($all_forums); $i++ )
1378         {
1379             if( $all_forums[$i]['forum_id'] == $forum_id )
1380             {
1381                 $parent_id = $all_forums[$i]['forum_parent'];
1382             }
1383         }
1384
1385         if( $parent_id )
1386         {
1387             for( $i = 0; $i < count($all_forums); $i++)
1388             {
1389                 if( $all_forums[$i]['forum_id'] == $parent_id )
1390                 {
1391                     $template->assign_vars(array(
1392                         'PARENT_FORUM'            => 1,
1393                         'U_VIEW_PARENT_FORUM'    => append_sid($root_path . 'phpbb2.php?page=viewforum&amp;' . POST_FORUM_URL .'=' . $all_forums[$i]['forum_id']),
1394                         'PARENT_FORUM_NAME'        => $all_forums[$i]['forum_name'],
1395                     ));
1396                 }
1397             }
1398         }
1399         // End Simple Subforums MOD
1400
1401                 $sql = "SELECT t.*, u.name AS username, u.uid
1402                         FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u
1403                         WHERE t.forum_id = $forum_id
1404                                 AND t.topic_poster = u.uid
1405                         ORDER BY t.topic_type DESC, t.topic_last_post_time DESC
1406                         LIMIT $start, " . $config['topics_per_page'];
1407                 $result = $db->sql_query($sql);
1408
1409                 while ( $row = $db->sql_fetchrow($result) )
1410                 {
1411                         $topic_title = '';
1412
1413                         if ( $row['topic_status'] == TOPIC_LOCKED )
1414                         {
1415                                 $folder_img = $images['folder_locked'];
1416                                 $folder_alt = $lang['topic_locked'];
1417                         }
1418                         else
1419                         {
1420                                 if ( $row['topic_type'] == POST_ANNOUNCE )
1421                                 {
1422                                         $folder_img = $images['folder_announce'];
1423                                         $folder_alt = $lang['topic_announcement'];
1424                                 }
1425                                 else if ( $row['topic_type'] == POST_STICKY )
1426                                 {
1427                                         $folder_img = $images['folder_sticky'];
1428                                         $folder_alt = $lang['topic_sticky'];
1429                                 }
1430                                 else
1431                                 {
1432                                         $folder_img = $images['folder'];
1433                                         $folder_alt = $lang['no_new_posts'];
1434                                 }
1435                         }
1436
1437                         $topic_id = $row['topic_id'];
1438                         $topic_type = $row['topic_type'];
1439                         $topic_status = $row['topic_status'];
1440
1441                         if ( $topic_type == POST_ANNOUNCE )
1442                         {
1443                                 $topic_type = $lang['topic_announcement'] . ' ';
1444                         }
1445                         else if ( $topic_type == POST_STICKY )
1446                         {
1447                                 $topic_type = $lang['topic_sticky'] . ' ';
1448                         }
1449                         else if ( $topic_status == TOPIC_MOVED )
1450                         {
1451                                 $topic_type = $lang['topic_moved'] . ' ';
1452                         }
1453                         else
1454                         {
1455                                 $topic_type = '';
1456                         }
1457
1458                         if ( $row['topic_vote'] )
1459                         {
1460                                 $topic_type .= $lang['topic_poll'] . ' ';
1461                         }
1462
1463                         $topic_title = censor_text($row['topic_title']);
1464
1465                         //$u_view_topic = "modcp.$phpEx?mode=split&amp;" . POST_TOPIC_URL . "=$topic_id&amp;sid=" . $userdata['session_id'];
1466
1467                         $u_view_topic = append_sid("phpbb2.php?page=modcp&mode=split&amp;" . POST_TOPIC_URL . "=$topic_id", false, true, $userdata['session_id']);
1468                         $topic_replies = $row['topic_replies'];
1469
1470                         $last_post_time = create_date($row['topic_last_post_time']);
1471
1472                         $template->assign_block_vars('topicrow', array(
1473                                 'U_VIEW_TOPIC' => $u_view_topic,
1474
1475                                 'TOPIC_FOLDER_IMG' => $folder_img,
1476                                 'TOPIC_TYPE' => $topic_type,
1477                                 'TOPIC_TITLE' => $topic_title,
1478                                 'REPLIES' => $topic_replies,
1479                                 'LAST_POST_TIME' => $last_post_time,
1480                                 'TOPIC_ID' => $topic_id,
1481
1482                                 'L_TOPIC_FOLDER_ALT' => $folder_alt)
1483                         );
1484                 }
1485
1486                 $template->assign_vars(array(
1487                         //'PAGINATION' => generate_pagination("modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'], $forum_topics, $config['topics_per_page'], $start),
1488                         'PAGINATION' => generate_pagination($root_path . "phpbb2.php?page=modcp&" . POST_FORUM_URL . "=$forum_id&amp;sid=" . $userdata['session_id'], $forum_topics, $config['topics_per_page'], $start),
1489                         'PAGE_NUMBER' => sprintf($lang['page_of'], ( floor( $start / $config['topics_per_page'] ) + 1 ), ceil( $forum_topics / $config['topics_per_page'] )),
1490                         'L_GOTO_PAGE' => $lang['goto_page'])
1491                 );
1492
1493                 stdhead($lang['forums'] . ' :: ' . $lang['mod_cp'], false);
1494
1495                 $template->set_filenames(array(
1496                         'body' => 'forum/modcp_body.tpl')
1497                 );
1498
1499                 break;
1500 }
1501 return;
1502
1503 ?>
Note: See TracBrowser for help on using the browser.