source: trunk/forum/includes/mcp/mcp_main.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 35.0 KB
Line 
1<?php
2/**
3*
4* @package mcp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* mcp_main
21* Handling mcp actions
22* @package mcp
23*/
24class mcp_main
25{
26 var $p_master;
27 var $u_action;
28
29 function mcp_main(&$p_master)
30 {
31 $this->p_master = &$p_master;
32 }
33
34 function main($id, $mode)
35 {
36 global $auth, $db, $user, $template, $action;
37 global $config, $phpbb_root_path, $phpEx;
38
39 $quickmod = ($mode == 'quickmod') ? true : false;
40
41 switch ($action)
42 {
43 case 'lock':
44 case 'unlock':
45 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
46
47 if (!sizeof($topic_ids))
48 {
49 trigger_error('NO_TOPIC_SELECTED');
50 }
51
52 lock_unlock($action, $topic_ids);
53 break;
54
55 case 'lock_post':
56 case 'unlock_post':
57
58 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
59
60 if (!sizeof($post_ids))
61 {
62 trigger_error('NO_POST_SELECTED');
63 }
64
65 lock_unlock($action, $post_ids);
66 break;
67
68 case 'make_announce':
69 case 'make_sticky':
70 case 'make_global':
71 case 'make_normal':
72
73 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
74
75 if (!sizeof($topic_ids))
76 {
77 trigger_error('NO_TOPIC_SELECTED');
78 }
79
80 change_topic_type($action, $topic_ids);
81 break;
82
83 case 'move':
84 $user->add_lang('viewtopic');
85
86 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
87
88 if (!sizeof($topic_ids))
89 {
90 trigger_error('NO_TOPIC_SELECTED');
91 }
92
93 mcp_move_topic($topic_ids);
94 break;
95
96 case 'fork':
97 $user->add_lang('viewtopic');
98
99 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
100
101 if (!sizeof($topic_ids))
102 {
103 trigger_error('NO_TOPIC_SELECTED');
104 }
105
106 mcp_fork_topic($topic_ids);
107 break;
108
109 case 'delete_topic':
110 $user->add_lang('viewtopic');
111
112 $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
113
114 if (!sizeof($topic_ids))
115 {
116 trigger_error('NO_TOPIC_SELECTED');
117 }
118
119 mcp_delete_topic($topic_ids);
120 break;
121
122 case 'delete_post':
123 $user->add_lang('posting');
124
125 $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
126
127 if (!sizeof($post_ids))
128 {
129 trigger_error('NO_POST_SELECTED');
130 }
131
132 mcp_delete_post($post_ids);
133 break;
134 }
135
136 switch ($mode)
137 {
138 case 'front':
139 include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
140
141 $user->add_lang('acp/common');
142
143 mcp_front_view($id, $mode, $action);
144
145 $this->tpl_name = 'mcp_front';
146 $this->page_title = 'MCP_MAIN';
147 break;
148
149 case 'forum_view':
150 include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
151
152 $user->add_lang('viewforum');
153
154 $forum_id = request_var('f', 0);
155
156 $forum_info = get_forum_data($forum_id, 'm_', true);
157
158 if (!sizeof($forum_info))
159 {
160 $this->main('main', 'front');
161 return;
162 }
163
164 $forum_info = $forum_info[$forum_id];
165
166 mcp_forum_view($id, $mode, $action, $forum_info);
167
168 $this->tpl_name = 'mcp_forum';
169 $this->page_title = 'MCP_MAIN_FORUM_VIEW';
170 break;
171
172 case 'topic_view':
173 include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
174
175 mcp_topic_view($id, $mode, $action);
176
177 $this->tpl_name = 'mcp_topic';
178 $this->page_title = 'MCP_MAIN_TOPIC_VIEW';
179 break;
180
181 case 'post_details':
182 include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
183
184 mcp_post_details($id, $mode, $action);
185
186 $this->tpl_name = ($action == 'whois') ? 'mcp_whois' : 'mcp_post';
187 $this->page_title = 'MCP_MAIN_POST_DETAILS';
188 break;
189
190 default:
191 trigger_error('NO_MODE', E_USER_ERROR);
192 break;
193 }
194 }
195}
196
197/**
198* Lock/Unlock Topic/Post
199*/
200function lock_unlock($action, $ids)
201{
202 global $auth, $user, $db, $phpEx, $phpbb_root_path;
203
204 if ($action == 'lock' || $action == 'unlock')
205 {
206 $table = TOPICS_TABLE;
207 $sql_id = 'topic_id';
208 $set_id = 'topic_status';
209 $l_prefix = 'TOPIC';
210 }
211 else
212 {
213 $table = POSTS_TABLE;
214 $sql_id = 'post_id';
215 $set_id = 'post_edit_locked';
216 $l_prefix = 'POST';
217 }
218
219 $orig_ids = $ids;
220
221 if (!check_ids($ids, $table, $sql_id, array('m_lock')))
222 {
223 // Make sure that for f_user_lock only the lock action is triggered.
224 if ($action != 'lock')
225 {
226 return;
227 }
228
229 $ids = $orig_ids;
230
231 if (!check_ids($ids, $table, $sql_id, array('f_user_lock')))
232 {
233 return;
234 }
235 }
236 unset($orig_ids);
237
238 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
239
240 $s_hidden_fields = build_hidden_fields(array(
241 $sql_id . '_list' => $ids,
242 'action' => $action,
243 'redirect' => $redirect)
244 );
245 $success_msg = '';
246
247 if (confirm_box(true))
248 {
249 $sql = "UPDATE $table
250 SET $set_id = " . (($action == 'lock' || $action == 'lock_post') ? ITEM_LOCKED : ITEM_UNLOCKED) . '
251 WHERE ' . $db->sql_in_set($sql_id, $ids);
252 $db->sql_query($sql);
253
254 $data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids);
255
256 foreach ($data as $id => $row)
257 {
258 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']);
259 }
260
261 $success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';
262 }
263 else
264 {
265 confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
266 }
267
268 $redirect = request_var('redirect', "index.$phpEx");
269 $redirect = reapply_sid($redirect);
270
271 if (!$success_msg)
272 {
273 redirect($redirect);
274 }
275 else
276 {
277 meta_refresh(2, $redirect);
278 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
279 }
280}
281
282/**
283* Change Topic Type
284*/
285function change_topic_type($action, $topic_ids)
286{
287 global $auth, $user, $db, $phpEx, $phpbb_root_path;
288
289 // For changing topic types, we only allow operations in one forum.
290 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('f_announce', 'f_sticky', 'm_'), true);
291
292 if ($forum_id === false)
293 {
294 return;
295 }
296
297 switch ($action)
298 {
299 case 'make_announce':
300 $new_topic_type = POST_ANNOUNCE;
301 $check_acl = 'f_announce';
302 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_ANNOUNCEMENT' : 'MCP_MAKE_ANNOUNCEMENTS';
303 break;
304
305 case 'make_global':
306 $new_topic_type = POST_GLOBAL;
307 $check_acl = 'f_announce';
308 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';
309 break;
310
311 case 'make_sticky':
312 $new_topic_type = POST_STICKY;
313 $check_acl = 'f_sticky';
314 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_STICKY' : 'MCP_MAKE_STICKIES';
315 break;
316
317 default:
318 $new_topic_type = POST_NORMAL;
319 $check_acl = '';
320 $l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_NORMAL' : 'MCP_MAKE_NORMALS';
321 break;
322 }
323
324 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
325
326 $s_hidden_fields = array(
327 'topic_id_list' => $topic_ids,
328 'f' => $forum_id,
329 'action' => $action,
330 'redirect' => $redirect,
331 );
332 $success_msg = '';
333
334 if (confirm_box(true))
335 {
336 if ($new_topic_type != POST_GLOBAL)
337 {
338 $sql = 'UPDATE ' . TOPICS_TABLE . "
339 SET topic_type = $new_topic_type
340 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
341 AND forum_id <> 0';
342 $db->sql_query($sql);
343
344 // Reset forum id if a global topic is within the array
345 $to_forum_id = request_var('to_forum_id', 0);
346
347 if ($to_forum_id)
348 {
349 $sql = 'UPDATE ' . TOPICS_TABLE . "
350 SET topic_type = $new_topic_type, forum_id = $to_forum_id
351 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
352 AND forum_id = 0';
353 $db->sql_query($sql);
354
355 // Update forum_ids for all posts
356 $sql = 'UPDATE ' . POSTS_TABLE . "
357 SET forum_id = $to_forum_id
358 WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
359 AND forum_id = 0';
360 $db->sql_query($sql);
361
362 // Do a little forum sync stuff
363 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
364 FROM ' . TOPICS_TABLE . ' t
365 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
366 $result = $db->sql_query($sql);
367 $row_data = $db->sql_fetchrow($result);
368 $db->sql_freeresult($result);
369
370 $sync_sql = array();
371
372 if ($row_data['topic_posts'])
373 {
374 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
375 }
376
377 if ($row_data['topics_authed'])
378 {
379 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
380 }
381
382 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
383
384 foreach ($sync_sql as $forum_id_key => $array)
385 {
386 $sql = 'UPDATE ' . FORUMS_TABLE . '
387 SET ' . implode(', ', $array) . '
388 WHERE forum_id = ' . $forum_id_key;
389 $db->sql_query($sql);
390 }
391
392 sync('forum', 'forum_id', $to_forum_id);
393 }
394 }
395 else
396 {
397 // Get away with those topics already being a global announcement by re-calculating $topic_ids
398 $sql = 'SELECT topic_id
399 FROM ' . TOPICS_TABLE . '
400 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
401 AND forum_id <> 0';
402 $result = $db->sql_query($sql);
403
404 $topic_ids = array();
405 while ($row = $db->sql_fetchrow($result))
406 {
407 $topic_ids[] = $row['topic_id'];
408 }
409 $db->sql_freeresult($result);
410
411 if (sizeof($topic_ids))
412 {
413 // Delete topic shadows for global announcements
414 $sql = 'DELETE FROM ' . TOPICS_TABLE . '
415 WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
416 $db->sql_query($sql);
417
418 $sql = 'UPDATE ' . TOPICS_TABLE . "
419 SET topic_type = $new_topic_type, forum_id = 0
420 WHERE " . $db->sql_in_set('topic_id', $topic_ids);
421 $db->sql_query($sql);
422
423 // Update forum_ids for all posts
424 $sql = 'UPDATE ' . POSTS_TABLE . '
425 SET forum_id = 0
426 WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
427 $db->sql_query($sql);
428
429 // Do a little forum sync stuff
430 $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
431 FROM ' . TOPICS_TABLE . ' t
432 WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
433 $result = $db->sql_query($sql);
434 $row_data = $db->sql_fetchrow($result);
435 $db->sql_freeresult($result);
436
437 $sync_sql = array();
438
439 if ($row_data['topic_posts'])
440 {
441 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
442 }
443
444 if ($row_data['topics_authed'])
445 {
446 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
447 }
448
449 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
450
451 foreach ($sync_sql as $forum_id_key => $array)
452 {
453 $sql = 'UPDATE ' . FORUMS_TABLE . '
454 SET ' . implode(', ', $array) . '
455 WHERE forum_id = ' . $forum_id_key;
456 $db->sql_query($sql);
457 }
458
459 sync('forum', 'forum_id', $forum_id);
460 }
461 }
462
463 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
464
465 if (sizeof($topic_ids))
466 {
467 $data = get_topic_data($topic_ids);
468
469 foreach ($data as $topic_id => $row)
470 {
471 add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']);
472 }
473 }
474 }
475 else
476 {
477 // Global topic involved?
478 $global_involved = false;
479
480 if ($new_topic_type != POST_GLOBAL)
481 {
482 $sql = 'SELECT forum_id
483 FROM ' . TOPICS_TABLE . '
484 WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
485 AND forum_id = 0';
486 $result = $db->sql_query($sql);
487 $row = $db->sql_fetchrow($result);
488 $db->sql_freeresult($result);
489
490 if ($row)
491 {
492 $global_involved = true;
493 }
494 }
495
496 if ($global_involved)
497 {
498 global $template;
499
500 $template->assign_vars(array(
501 'S_FORUM_SELECT' => make_forum_select(request_var('f', $forum_id), false, false, true, true),
502 'S_CAN_LEAVE_SHADOW' => false,
503 'ADDITIONAL_MSG' => (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
504 );
505
506 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
507 }
508 else
509 {
510 confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
511 }
512 }
513
514 $redirect = request_var('redirect', "index.$phpEx");
515 $redirect = reapply_sid($redirect);
516
517 if (!$success_msg)
518 {
519 redirect($redirect);
520 }
521 else
522 {
523 meta_refresh(2, $redirect);
524 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
525 }
526}
527
528/**
529* Move Topic
530*/
531function mcp_move_topic($topic_ids)
532{
533 global $auth, $user, $db, $template;
534 global $phpEx, $phpbb_root_path;
535
536 // Here we limit the operation to one forum only
537 $forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);
538
539 if ($forum_id === false)
540 {
541 return;
542 }
543
544 $to_forum_id = request_var('to_forum_id', 0);
545 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
546 $additional_msg = $success_msg = '';
547
548 $s_hidden_fields = build_hidden_fields(array(
549 'topic_id_list' => $topic_ids,
550 'f' => $forum_id,
551 'action' => 'move',
552 'redirect' => $redirect)
553 );
554
555 if ($to_forum_id)
556 {
557 $forum_data = get_forum_data($to_forum_id, 'f_post');
558
559 if (!sizeof($forum_data))
560 {
561 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
562 }
563 else
564 {
565 $forum_data = $forum_data[$to_forum_id];
566
567 if ($forum_data['forum_type'] != FORUM_POST)
568 {
569 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
570 }
571 else if (!$auth->acl_get('f_post', $to_forum_id) || (!$auth->acl_get('m_approve', $to_forum_id) && !$auth->acl_get('f_noapprove', $to_forum_id)))
572 {
573 $additional_msg = $user->lang['USER_CANNOT_POST'];
574 }
575 else if ($forum_id == $to_forum_id)
576 {
577 $additional_msg = $user->lang['CANNOT_MOVE_SAME_FORUM'];
578 }
579 }
580 }
581 else if (isset($_POST['confirm']))
582 {
583 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
584 }
585
586 if (!$to_forum_id || $additional_msg)
587 {
588 unset($_POST['confirm']);
589 unset($_REQUEST['confirm_key']);
590 }
591
592 if (confirm_box(true))
593 {
594 $topic_data = get_topic_data($topic_ids);
595 $leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
596
597 $forum_sync_data = array();
598
599 $forum_sync_data[$forum_id] = current($topic_data);
600 $forum_sync_data[$to_forum_id] = $forum_data;
601
602 // Real topics added to target forum
603 $topics_moved = sizeof($topic_data);
604
605 // Approved topics added to target forum
606 $topics_authed_moved = 0;
607
608 // Posts (topic replies + topic post if approved) added to target forum
609 $topic_posts_added = 0;
610
611 // Posts (topic replies + topic post if approved and not global announcement) removed from source forum
612 $topic_posts_removed = 0;
613
614 // Real topics removed from source forum (all topics without global announcements)
615 $topics_removed = 0;
616
617 // Approved topics removed from source forum (except global announcements)
618 $topics_authed_removed = 0;
619
620 foreach ($topic_data as $topic_id => $topic_info)
621 {
622 if ($topic_info['topic_approved'])
623 {
624 $topics_authed_moved++;
625 $topic_posts_added++;
626 }
627
628 $topic_posts_added += $topic_info['topic_replies'];
629
630 if ($topic_info['topic_type'] != POST_GLOBAL)
631 {
632 $topics_removed++;
633 $topic_posts_removed += $topic_info['topic_replies'];
634
635 if ($topic_info['topic_approved'])
636 {
637 $topics_authed_removed++;
638 $topic_posts_removed++;
639 }
640 }
641 }
642
643 $db->sql_transaction('begin');
644
645 $sync_sql = array();
646
647 if ($topic_posts_added)
648 {
649 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added;
650 }
651
652 if ($topics_authed_moved)
653 {
654 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
655 }
656
657 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
658
659 // Move topics, but do not resync yet
660 move_topics($topic_ids, $to_forum_id, false);
661
662 $forum_ids = array($to_forum_id);
663 foreach ($topic_data as $topic_id => $row)
664 {
665 // Get the list of forums to resync, add a log entry
666 $forum_ids[] = $row['forum_id'];
667 add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']);
668
669 // If we have moved a global announcement, we need to correct the topic type
670 if ($row['topic_type'] == POST_GLOBAL)
671 {
672 $sql = 'UPDATE ' . TOPICS_TABLE . '
673 SET topic_type = ' . POST_ANNOUNCE . '
674 WHERE topic_id = ' . (int) $row['topic_id'];
675 $db->sql_query($sql);
676 }
677
678 // Leave a redirection if required and only if the topic is visible to users
679 if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL)
680 {
681 $shadow = array(
682 'forum_id' => (int) $row['forum_id'],
683 'icon_id' => (int) $row['icon_id'],
684 'topic_attachment' => (int) $row['topic_attachment'],
685 'topic_approved' => 1, // a shadow topic is always approved
686 'topic_reported' => 0, // a shadow topic is never reported
687 'topic_title' => (string) $row['topic_title'],
688 'topic_poster' => (int) $row['topic_poster'],
689 'topic_time' => (int) $row['topic_time'],
690 'topic_time_limit' => (int) $row['topic_time_limit'],
691 'topic_views' => (int) $row['topic_views'],
692 'topic_replies' => (int) $row['topic_replies'],
693 'topic_replies_real' => (int) $row['topic_replies_real'],
694 'topic_status' => ITEM_MOVED,
695 'topic_type' => POST_NORMAL,
696 'topic_first_post_id' => (int) $row['topic_first_post_id'],
697 'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'],
698 'topic_first_poster_name'=> (string) $row['topic_first_poster_name'],
699 'topic_last_post_id' => (int) $row['topic_last_post_id'],
700 'topic_last_poster_id' => (int) $row['topic_last_poster_id'],
701 'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],
702 'topic_last_poster_name'=> (string) $row['topic_last_poster_name'],
703 'topic_last_post_subject'=> (string) $row['topic_last_post_subject'],
704 'topic_last_post_time' => (int) $row['topic_last_post_time'],
705 'topic_last_view_time' => (int) $row['topic_last_view_time'],
706 'topic_moved_id' => (int) $row['topic_id'],
707 'topic_bumped' => (int) $row['topic_bumped'],
708 'topic_bumper' => (int) $row['topic_bumper'],
709 'poll_title' => (string) $row['poll_title'],
710 'poll_start' => (int) $row['poll_start'],
711 'poll_length' => (int) $row['poll_length'],
712 'poll_max_options' => (int) $row['poll_max_options'],
713 'poll_last_vote' => (int) $row['poll_last_vote']
714 );
715
716 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
717
718 // Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts
719 $topics_removed--;
720 $topics_authed_removed--;
721 }
722 }
723 unset($topic_data);
724
725 if ($topic_posts_removed)
726 {
727 $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed;
728 }
729
730 if ($topics_removed)
731 {
732 $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed;
733 }
734
735 if ($topics_authed_removed)
736 {
737 $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed;
738 }
739
740 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
741
742 foreach ($sync_sql as $forum_id_key => $array)
743 {
744 $sql = 'UPDATE ' . FORUMS_TABLE . '
745 SET ' . implode(', ', $array) . '
746 WHERE forum_id = ' . $forum_id_key;
747 $db->sql_query($sql);
748 }
749
750 $db->sql_transaction('commit');
751
752 sync('forum', 'forum_id', array($forum_id, $to_forum_id));
753 }
754 else
755 {
756 $template->assign_vars(array(
757 'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
758 'S_CAN_LEAVE_SHADOW' => true,
759 'ADDITIONAL_MSG' => $additional_msg)
760 );
761
762 confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
763 }
764
765 $redirect = request_var('redirect', "index.$phpEx");
766 $redirect = reapply_sid($redirect);
767
768 if (!$success_msg)
769 {
770 redirect($redirect);
771 }
772 else
773 {
774 meta_refresh(3, $redirect);
775
776 $message = $user->lang[$success_msg];
777 $message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
778 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>');
779 $message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>');
780
781 trigger_error($message);
782 }
783}
784
785/**
786* Delete Topics
787*/
788function mcp_delete_topic($topic_ids)
789{
790 global $auth, $user, $db, $phpEx, $phpbb_root_path;
791
792 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
793 {
794 return;
795 }
796
797 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
798 $forum_id = request_var('f', 0);
799
800 $s_hidden_fields = build_hidden_fields(array(
801 'topic_id_list' => $topic_ids,
802 'f' => $forum_id,
803 'action' => 'delete_topic',
804 'redirect' => $redirect)
805 );
806 $success_msg = '';
807
808 if (confirm_box(true))
809 {
810 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
811
812 $data = get_topic_data($topic_ids);
813
814 foreach ($data as $topic_id => $row)
815 {
816 if ($row['topic_moved_id'])
817 {
818 add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']);
819 }
820 else
821 {
822 add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
823 }
824 }
825
826 $return = delete_topics('topic_id', $topic_ids);
827 }
828 else
829 {
830 confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
831 }
832
833 if (!isset($_REQUEST['quickmod']))
834 {
835 $redirect = request_var('redirect', "index.$phpEx");
836 $redirect = reapply_sid($redirect);
837 $redirect_message = 'PAGE';
838 }
839 else
840 {
841 $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
842 $redirect_message = 'FORUM';
843 }
844
845 if (!$success_msg)
846 {
847 redirect($redirect);
848 }
849 else
850 {
851 meta_refresh(3, $redirect);
852 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
853 }
854}
855
856/**
857* Delete Posts
858*/
859function mcp_delete_post($post_ids)
860{
861 global $auth, $user, $db, $phpEx, $phpbb_root_path;
862
863 if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
864 {
865 return;
866 }
867
868 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
869 $forum_id = request_var('f', 0);
870
871 $s_hidden_fields = build_hidden_fields(array(
872 'post_id_list' => $post_ids,
873 'f' => $forum_id,
874 'action' => 'delete_post',
875 'redirect' => $redirect)
876 );
877 $success_msg = '';
878
879 if (confirm_box(true))
880 {
881 if (!function_exists('delete_posts'))
882 {
883 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
884 }
885
886 // Count the number of topics that are affected
887 // I did not use COUNT(DISTINCT ...) because I remember having problems
888 // with it on older versions of MySQL -- Ashe
889
890 $sql = 'SELECT DISTINCT topic_id
891 FROM ' . POSTS_TABLE . '
892 WHERE ' . $db->sql_in_set('post_id', $post_ids);
893 $result = $db->sql_query($sql);
894
895 $topic_id_list = array();
896 while ($row = $db->sql_fetchrow($result))
897 {
898 $topic_id_list[] = $row['topic_id'];
899 }
900 $affected_topics = sizeof($topic_id_list);
901 $db->sql_freeresult($result);
902
903 $post_data = get_post_data($post_ids);
904
905 foreach ($post_data as $id => $row)
906 {
907 $post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username'];
908 add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username);
909 }
910
911 // Now delete the posts, topics and forums are automatically resync'ed
912 delete_posts('post_id', $post_ids);
913
914 $sql = 'SELECT COUNT(topic_id) AS topics_left
915 FROM ' . TOPICS_TABLE . '
916 WHERE ' . $db->sql_in_set('topic_id', $topic_id_list);
917 $result = $db->sql_query_limit($sql, 1);
918
919 $deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
920 $db->sql_freeresult($result);
921
922 $topic_id = request_var('t', 0);
923
924 // Return links
925 $return_link = array();
926 if ($affected_topics == 1 && !$deleted_topics && $topic_id)
927 {
928 $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") . '">', '</a>');
929 }
930 $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
931
932 if (sizeof($post_ids) == 1)
933 {
934 if ($deleted_topics)
935 {
936 // We deleted the only post of a topic, which in turn has
937 // been removed from the database
938 $success_msg = $user->lang['TOPIC_DELETED_SUCCESS'];
939 }
940 else
941 {
942 $success_msg = $user->lang['POST_DELETED_SUCCESS'];
943 }
944 }
945 else
946 {
947 if ($deleted_topics)
948 {
949 // Some of topics disappeared
950 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING'];
951 }
952 else
953 {
954 $success_msg = $user->lang['POSTS_DELETED_SUCCESS'];
955 }
956 }
957 }
958 else
959 {
960 confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
961 }
962
963 $redirect = request_var('redirect', "index.$phpEx");
964 $redirect = reapply_sid($redirect);
965
966 if (!$success_msg)
967 {
968 redirect($redirect);
969 }
970 else
971 {
972 if ($affected_topics != 1 || $deleted_topics || !$topic_id)
973 {
974 $redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", false);
975 }
976
977 meta_refresh(3, $redirect);
978 trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link));
979 }
980}
981
982/**
983* Fork Topic
984*/
985function mcp_fork_topic($topic_ids)
986{
987 global $auth, $user, $db, $template, $config;
988 global $phpEx, $phpbb_root_path;
989
990 if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))
991 {
992 return;
993 }
994
995 $to_forum_id = request_var('to_forum_id', 0);
996 $forum_id = request_var('f', 0);
997 $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
998 $additional_msg = $success_msg = '';
999
1000 $s_hidden_fields = build_hidden_fields(array(
1001 'topic_id_list' => $topic_ids,
1002 'f' => $forum_id,
1003 'action' => 'fork',
1004 'redirect' => $redirect)
1005 );
1006
1007 if ($to_forum_id)
1008 {
1009 $forum_data = get_forum_data($to_forum_id, 'f_post');
1010
1011 if (!sizeof($topic_ids))
1012 {
1013 $additional_msg = $user->lang['NO_TOPIC_SELECTED'];
1014 }
1015 else if (!sizeof($forum_data))
1016 {
1017 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1018 }
1019 else
1020 {
1021 $forum_data = $forum_data[$to_forum_id];
1022
1023 if ($forum_data['forum_type'] != FORUM_POST)
1024 {
1025 $additional_msg = $user->lang['FORUM_NOT_POSTABLE'];
1026 }
1027 else if (!$auth->acl_get('f_post', $to_forum_id))
1028 {
1029 $additional_msg = $user->lang['USER_CANNOT_POST'];
1030 }
1031 }
1032 }
1033 else if (isset($_POST['confirm']))
1034 {
1035 $additional_msg = $user->lang['FORUM_NOT_EXIST'];
1036 }
1037
1038 if ($additional_msg)
1039 {
1040 unset($_POST['confirm']);
1041 unset($_REQUEST['confirm_key']);
1042 }
1043
1044 if (confirm_box(true))
1045 {
1046 $topic_data = get_topic_data($topic_ids, 'f_post');
1047
1048 $total_posts = 0;
1049 $new_topic_id_list = array();
1050
1051 foreach ($topic_data as $topic_id => $topic_row)
1052 {
1053 $sql_ary = array(
1054 'forum_id' => (int) $to_forum_id,
1055 'icon_id' => (int) $topic_row['icon_id'],
1056 'topic_attachment' => (int) $topic_row['topic_attachment'],
1057 'topic_approved' => 1,
1058 'topic_reported' => 0,
1059 'topic_title' => (string) $topic_row['topic_title'],
1060 'topic_poster' => (int) $topic_row['topic_poster'],
1061 'topic_time' => (int) $topic_row['topic_time'],
1062 'topic_replies' => (int) $topic_row['topic_replies_real'],
1063 'topic_replies_real' => (int) $topic_row['topic_replies_real'],
1064 'topic_status' => (int) $topic_row['topic_status'],
1065 'topic_type' => (int) $topic_row['topic_type'],
1066 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'],
1067 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'],
1068 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'],
1069 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'],
1070 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'],
1071 'topic_bumped' => (int) $topic_row['topic_bumped'],
1072 'topic_bumper' => (int) $topic_row['topic_bumper'],
1073 'poll_title' => (string) $topic_row['poll_title'],
1074 'poll_start' => (int) $topic_row['poll_start'],
1075 'poll_length' => (int) $topic_row['poll_length'],
1076 'poll_max_options' => (int) $topic_row['poll_max_options'],
1077 'poll_vote_change' => (int) $topic_row['poll_vote_change'],
1078 );
1079
1080 $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1081 $new_topic_id = $db->sql_nextid();
1082 $new_topic_id_list[$topic_id] = $new_topic_id;
1083
1084 if ($topic_row['poll_start'])
1085 {
1086 $poll_rows = array();
1087
1088 $sql = 'SELECT *
1089 FROM ' . POLL_OPTIONS_TABLE . "
1090 WHERE topic_id = $topic_id";
1091 $result = $db->sql_query($sql);
1092
1093 while ($row = $db->sql_fetchrow($result))
1094 {
1095 $sql_ary = array(
1096 'poll_option_id' => (int) $row['poll_option_id'],
1097 'topic_id' => (int) $new_topic_id,
1098 'poll_option_text' => (string) $row['poll_option_text'],
1099 'poll_option_total' => 0
1100 );
1101
1102 $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1103 }
1104 }
1105
1106 $sql = 'SELECT *
1107 FROM ' . POSTS_TABLE . "
1108 WHERE topic_id = $topic_id
1109 ORDER BY post_time ASC";
1110 $result = $db->sql_query($sql);
1111
1112 $post_rows = array();
1113 while ($row = $db->sql_fetchrow($result))
1114 {
1115 $post_rows[] = $row;
1116 }
1117 $db->sql_freeresult($result);
1118
1119 if (!sizeof($post_rows))
1120 {
1121 continue;
1122 }
1123
1124 $total_posts += sizeof($post_rows);
1125 foreach ($post_rows as $row)
1126 {
1127 $sql_ary = array(
1128 'topic_id' => (int) $new_topic_id,
1129 'forum_id' => (int) $to_forum_id,
1130 'poster_id' => (int) $row['poster_id'],
1131 'icon_id' => (int) $row['icon_id'],
1132 'poster_ip' => (string) $row['poster_ip'],
1133 'post_time' => (int) $row['post_time'],
1134 'post_approved' => 1,
1135 'post_reported' => 0,
1136 'enable_bbcode' => (int) $row['enable_bbcode'],
1137 'enable_smilies' => (int) $row['enable_smilies'],
1138 'enable_magic_url' => (int) $row['enable_magic_url'],
1139 'enable_sig' => (int) $row['enable_sig'],
1140 'post_username' => (string) $row['post_username'],
1141 'post_subject' => (string) $row['post_subject'],
1142 'post_text' => (string) $row['post_text'],
1143 'post_edit_reason' => (string) $row['post_edit_reason'],
1144 'post_edit_user' => (int) $row['post_edit_user'],
1145 'post_checksum' => (string) $row['post_checksum'],
1146 'post_attachment' => (int) $row['post_attachment'],
1147 'bbcode_bitfield' => $row['bbcode_bitfield'],
1148 'bbcode_uid' => (string) $row['bbcode_uid'],
1149 'post_edit_time' => (int) $row['post_edit_time'],
1150 'post_edit_count' => (int) $row['post_edit_count'],
1151 'post_edit_locked' => (int) $row['post_edit_locked'],
1152 'post_postcount' => 0,
1153 );
1154
1155 $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
1156 $new_post_id = $db->sql_nextid();
1157
1158 // Copy whether the topic is dotted
1159 markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
1160
1161 // Copy Attachments
1162 if ($row['post_attachment'])
1163 {
1164 $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "
1165 WHERE post_msg_id = {$row['post_id']}
1166 AND topic_id = $topic_id
1167 AND in_message = 0";
1168 $result = $db->sql_query($sql);
1169
1170 $sql_ary = array();
1171 while ($attach_row = $db->sql_fetchrow($result))
1172 {
1173 $sql_ary[] = array(
1174 'post_msg_id' => (int) $new_post_id,
1175 'topic_id' => (int) $new_topic_id,
1176 'in_message' => 0,
1177 'is_orphan' => (int) $attach_row['is_orphan'],
1178 'poster_id' => (int) $attach_row['poster_id'],
1179 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']),
1180 'real_filename' => (string) utf8_basename($attach_row['real_filename']),
1181 'download_count' => (int) $attach_row['download_count'],
1182 'attach_comment' => (string) $attach_row['attach_comment'],
1183 'extension' => (string) $attach_row['extension'],
1184 'mimetype' => (string) $attach_row['mimetype'],
1185 'filesize' => (int) $attach_row['filesize'],
1186 'filetime' => (int) $attach_row['filetime'],
1187 'thumbnail' => (int) $attach_row['thumbnail']
1188 );
1189 }
1190 $db->sql_freeresult($result);
1191
1192 if (sizeof($sql_ary))
1193 {
1194 $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary);
1195 }
1196 }
1197 }
1198
1199 $sql = 'SELECT user_id, notify_status
1200 FROM ' . TOPICS_WATCH_TABLE . '
1201 WHERE topic_id = ' . $topic_id;
1202 $result = $db->sql_query($sql);
1203
1204 $sql_ary = array();
1205 while ($row = $db->sql_fetchrow($result))
1206 {
1207 $sql_ary[] = array(
1208 'topic_id' => (int) $new_topic_id,
1209 'user_id' => (int) $row['user_id'],
1210 'notify_status' => (int) $row['notify_status'],
1211 );
1212 }
1213 $db->sql_freeresult($result);
1214
1215 if (sizeof($sql_ary))
1216 {
1217 $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary);
1218 }
1219 }
1220
1221 // Sync new topics, parent forums and board stats
1222 sync('topic', 'topic_id', $new_topic_id_list);
1223
1224 $sync_sql = array();
1225
1226 $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
1227 $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
1228 $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
1229
1230 foreach ($sync_sql as $forum_id_key => $array)
1231 {
1232 $sql = 'UPDATE ' . FORUMS_TABLE . '
1233 SET ' . implode(', ', $array) . '
1234 WHERE forum_id = ' . $forum_id_key;
1235 $db->sql_query($sql);
1236 }
1237
1238 sync('forum', 'forum_id', $to_forum_id);
1239 set_config_count('num_topics', sizeof($new_topic_id_list), true);
1240 set_config_count('num_posts', $total_posts, true);
1241
1242 foreach ($new_topic_id_list as $topic_id => $new_topic_id)
1243 {
1244 add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']);
1245 }
1246
1247 $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS';
1248 }
1249 else
1250 {
1251 $template->assign_vars(array(
1252 'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true),
1253 'S_CAN_LEAVE_SHADOW' => false,
1254 'ADDITIONAL_MSG' => $additional_msg)
1255 );
1256
1257 confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');
1258 }
1259
1260 $redirect = request_var('redirect', "index.$phpEx");
1261 $redirect = reapply_sid($redirect);
1262
1263 if (!$success_msg)
1264 {
1265 redirect($redirect);
1266 }
1267 else
1268 {
1269 $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
1270 meta_refresh(3, $redirect_url);
1271 $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>');
1272
1273 if ($forum_id != $to_forum_id)
1274 {
1275 $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>');
1276 }
1277
1278 trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
1279 }
1280}
1281
1282?>
Note: See TracBrowser for help on using the repository browser.