443
by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0 |
1 |
<?php
|
2 |
/**
|
|
3 |
*
|
|
4 |
* @package mcp
|
|
5 |
* @version $Id: mcp_main.php,v 1.73 2007/10/05 14:36:33 acydburn Exp $
|
|
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 |
*/
|
|
14 |
if (!defined('IN_PHPBB')) |
|
15 |
{
|
|
16 |
exit; |
|
17 |
}
|
|
18 |
||
19 |
/**
|
|
20 |
* mcp_main
|
|
21 |
* Handling mcp actions
|
|
22 |
* @package mcp
|
|
23 |
*/
|
|
24 |
class 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 |
*/
|
|
200 |
function 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('_f_', '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 |
*/
|
|
285 |
function 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('_f_', '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 |
*/
|
|
531 |
function 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('_f_', '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); |
|
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)) |
|
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 |
$topics_moved = sizeof($topic_ids); |
|
598 |
$topics_authed_moved = 0; |
|
599 |
$forum_sync_data = array(); |
|
600 |
||
601 |
$forum_sync_data[$forum_id] = current($topic_data); |
|
602 |
$forum_sync_data[$to_forum_id] = $forum_data; |
|
603 |
||
604 |
foreach ($topic_data as $topic_id => $topic_info) |
|
605 |
{
|
|
606 |
if ($topic_info['topic_approved'] == '1') |
|
607 |
{
|
|
608 |
$topics_authed_moved++; |
|
609 |
}
|
|
610 |
}
|
|
611 |
||
612 |
$db->sql_transaction('begin'); |
|
613 |
||
614 |
$sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts |
|
615 |
FROM ' . TOPICS_TABLE . ' t |
|
616 |
WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids); |
|
617 |
$result = $db->sql_query($sql); |
|
618 |
$row_data = $db->sql_fetchrow($result); |
|
619 |
$db->sql_freeresult($result); |
|
620 |
||
621 |
$sync_sql = array(); |
|
622 |
||
623 |
if ($row_data['topic_posts']) |
|
624 |
{
|
|
625 |
$sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts']; |
|
626 |
$sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts']; |
|
627 |
}
|
|
628 |
||
629 |
if ($topics_authed_moved) |
|
630 |
{
|
|
631 |
$sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved; |
|
632 |
}
|
|
633 |
||
634 |
$sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved; |
|
635 |
||
636 |
// Move topics, but do not resync yet
|
|
637 |
move_topics($topic_ids, $to_forum_id, false); |
|
638 |
||
639 |
$forum_ids = array($to_forum_id); |
|
640 |
foreach ($topic_data as $topic_id => $row) |
|
641 |
{
|
|
642 |
// Get the list of forums to resync, add a log entry
|
|
643 |
$forum_ids[] = $row['forum_id']; |
|
644 |
add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name']); |
|
645 |
||
646 |
// If we have moved a global announcement, we need to correct the topic type
|
|
647 |
if ($row['topic_type'] == POST_GLOBAL) |
|
648 |
{
|
|
649 |
$sql = 'UPDATE ' . TOPICS_TABLE . ' |
|
650 |
SET topic_type = ' . POST_ANNOUNCE . ' |
|
651 |
WHERE topic_id = ' . (int) $row['topic_id']; |
|
652 |
$db->sql_query($sql); |
|
653 |
}
|
|
654 |
||
655 |
// Leave a redirection if required and only if the topic is visible to users
|
|
656 |
if ($leave_shadow && $row['topic_approved'] && $row['topic_type'] != POST_GLOBAL) |
|
657 |
{
|
|
658 |
$shadow = array( |
|
659 |
'forum_id' => (int) $row['forum_id'], |
|
660 |
'icon_id' => (int) $row['icon_id'], |
|
661 |
'topic_attachment' => (int) $row['topic_attachment'], |
|
662 |
'topic_approved' => 1, |
|
663 |
'topic_reported' => (int) $row['topic_reported'], |
|
664 |
'topic_title' => (string) $row['topic_title'], |
|
665 |
'topic_poster' => (int) $row['topic_poster'], |
|
666 |
'topic_time' => (int) $row['topic_time'], |
|
667 |
'topic_time_limit' => (int) $row['topic_time_limit'], |
|
668 |
'topic_views' => (int) $row['topic_views'], |
|
669 |
'topic_replies' => (int) $row['topic_replies'], |
|
670 |
'topic_replies_real' => (int) $row['topic_replies_real'], |
|
671 |
'topic_status' => ITEM_MOVED, |
|
672 |
'topic_type' => POST_NORMAL, |
|
673 |
'topic_first_post_id' => (int) $row['topic_first_post_id'], |
|
674 |
'topic_first_poster_colour'=>(string) $row['topic_first_poster_colour'], |
|
675 |
'topic_first_poster_name'=> (string) $row['topic_first_poster_name'], |
|
676 |
'topic_last_post_id' => (int) $row['topic_last_post_id'], |
|
677 |
'topic_last_poster_id' => (int) $row['topic_last_poster_id'], |
|
678 |
'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'], |
|
679 |
'topic_last_poster_name'=> (string) $row['topic_last_poster_name'], |
|
680 |
'topic_last_post_subject'=> (string) $row['topic_last_post_subject'], |
|
681 |
'topic_last_post_time' => (int) $row['topic_last_post_time'], |
|
682 |
'topic_last_view_time' => (int) $row['topic_last_view_time'], |
|
683 |
'topic_moved_id' => (int) $row['topic_id'], |
|
684 |
'topic_bumped' => (int) $row['topic_bumped'], |
|
685 |
'topic_bumper' => (int) $row['topic_bumper'], |
|
686 |
'poll_title' => (string) $row['poll_title'], |
|
687 |
'poll_start' => (int) $row['poll_start'], |
|
688 |
'poll_length' => (int) $row['poll_length'], |
|
689 |
'poll_max_options' => (int) $row['poll_max_options'], |
|
690 |
'poll_last_vote' => (int) $row['poll_last_vote'] |
|
691 |
);
|
|
692 |
||
693 |
$db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow)); |
|
694 |
||
695 |
$topics_authed_moved--; |
|
696 |
$topics_moved--; |
|
697 |
}
|
|
698 |
}
|
|
699 |
unset($topic_data); |
|
700 |
||
701 |
$sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_moved; |
|
702 |
||
703 |
if ($topics_authed_moved) |
|
704 |
{
|
|
705 |
$sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_moved; |
|
706 |
}
|
|
707 |
||
708 |
$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS'; |
|
709 |
||
710 |
foreach ($sync_sql as $forum_id_key => $array) |
|
711 |
{
|
|
712 |
$sql = 'UPDATE ' . FORUMS_TABLE . ' |
|
713 |
SET ' . implode(', ', $array) . ' |
|
714 |
WHERE forum_id = ' . $forum_id_key; |
|
715 |
$db->sql_query($sql); |
|
716 |
}
|
|
717 |
||
718 |
$db->sql_transaction('commit'); |
|
719 |
||
720 |
sync('forum', 'forum_id', array($forum_id, $to_forum_id)); |
|
721 |
}
|
|
722 |
else
|
|
723 |
{
|
|
724 |
$template->assign_vars(array( |
|
725 |
'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true), |
|
726 |
'S_CAN_LEAVE_SHADOW' => true, |
|
727 |
'ADDITIONAL_MSG' => $additional_msg) |
|
728 |
);
|
|
729 |
||
730 |
confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); |
|
731 |
}
|
|
732 |
||
733 |
$redirect = request_var('redirect', "index.$phpEx"); |
|
734 |
$redirect = reapply_sid($redirect); |
|
735 |
||
736 |
if (!$success_msg) |
|
737 |
{
|
|
738 |
redirect($redirect); |
|
739 |
}
|
|
740 |
else
|
|
741 |
{
|
|
742 |
meta_refresh(3, $redirect); |
|
743 |
||
744 |
$message = $user->lang[$success_msg]; |
|
745 |
$message .= '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'); |
|
746 |
$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id") . '">', '</a>'); |
|
747 |
$message .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$to_forum_id") . '">', '</a>'); |
|
748 |
||
749 |
trigger_error($message); |
|
750 |
}
|
|
751 |
}
|
|
752 |
||
753 |
/**
|
|
754 |
* Delete Topics
|
|
755 |
*/
|
|
756 |
function mcp_delete_topic($topic_ids) |
|
757 |
{
|
|
758 |
global $auth, $user, $db, $phpEx, $phpbb_root_path; |
|
759 |
||
760 |
if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete'))) |
|
761 |
{
|
|
762 |
return; |
|
763 |
}
|
|
764 |
||
765 |
$redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod'))); |
|
766 |
$forum_id = request_var('f', 0); |
|
767 |
||
768 |
$s_hidden_fields = build_hidden_fields(array( |
|
769 |
'topic_id_list' => $topic_ids, |
|
770 |
'f' => $forum_id, |
|
771 |
'action' => 'delete_topic', |
|
772 |
'redirect' => $redirect) |
|
773 |
);
|
|
774 |
$success_msg = ''; |
|
775 |
||
776 |
if (confirm_box(true)) |
|
777 |
{
|
|
778 |
$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS'; |
|
779 |
||
780 |
$data = get_topic_data($topic_ids); |
|
781 |
||
782 |
foreach ($data as $topic_id => $row) |
|
783 |
{
|
|
784 |
add_log('mod', $row['forum_id'], 0, 'LOG_TOPIC_DELETED', $row['topic_title']); |
|
785 |
}
|
|
786 |
||
787 |
$return = delete_topics('topic_id', $topic_ids); |
|
788 |
}
|
|
789 |
else
|
|
790 |
{
|
|
791 |
confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields); |
|
792 |
}
|
|
793 |
||
794 |
$redirect = request_var('redirect', "index.$phpEx"); |
|
795 |
$redirect = reapply_sid($redirect); |
|
796 |
||
797 |
if (!$success_msg) |
|
798 |
{
|
|
799 |
redirect($redirect); |
|
800 |
}
|
|
801 |
else
|
|
802 |
{
|
|
803 |
$redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); |
|
804 |
meta_refresh(3, $redirect_url); |
|
805 |
trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>')); |
|
806 |
}
|
|
807 |
}
|
|
808 |
||
809 |
/**
|
|
810 |
* Delete Posts
|
|
811 |
*/
|
|
812 |
function mcp_delete_post($post_ids) |
|
813 |
{
|
|
814 |
global $auth, $user, $db, $phpEx, $phpbb_root_path; |
|
815 |
||
816 |
if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete'))) |
|
817 |
{
|
|
818 |
return; |
|
819 |
}
|
|
820 |
||
821 |
$redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod'))); |
|
822 |
$forum_id = request_var('f', 0); |
|
823 |
||
824 |
$s_hidden_fields = build_hidden_fields(array( |
|
825 |
'post_id_list' => $post_ids, |
|
826 |
'f' => $forum_id, |
|
827 |
'action' => 'delete_post', |
|
828 |
'redirect' => $redirect) |
|
829 |
);
|
|
830 |
$success_msg = ''; |
|
831 |
||
832 |
if (confirm_box(true)) |
|
833 |
{
|
|
834 |
if (!function_exists('delete_posts')) |
|
835 |
{
|
|
836 |
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); |
|
837 |
}
|
|
838 |
||
839 |
// Count the number of topics that are affected
|
|
840 |
// I did not use COUNT(DISTINCT ...) because I remember having problems
|
|
841 |
// with it on older versions of MySQL -- Ashe
|
|
842 |
||
843 |
$sql = 'SELECT DISTINCT topic_id |
|
844 |
FROM ' . POSTS_TABLE . ' |
|
845 |
WHERE ' . $db->sql_in_set('post_id', $post_ids); |
|
846 |
$result = $db->sql_query($sql); |
|
847 |
||
848 |
$topic_id_list = array(); |
|
849 |
while ($row = $db->sql_fetchrow($result)) |
|
850 |
{
|
|
851 |
$topic_id_list[] = $row['topic_id']; |
|
852 |
}
|
|
853 |
$affected_topics = sizeof($topic_id_list); |
|
854 |
$db->sql_freeresult($result); |
|
855 |
||
856 |
$post_data = get_post_data($post_ids); |
|
857 |
||
858 |
foreach ($post_data as $id => $row) |
|
859 |
{
|
|
860 |
add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject']); |
|
861 |
}
|
|
862 |
||
863 |
// Now delete the posts, topics and forums are automatically resync'ed
|
|
864 |
delete_posts('post_id', $post_ids); |
|
865 |
||
866 |
$sql = 'SELECT COUNT(topic_id) AS topics_left |
|
867 |
FROM ' . TOPICS_TABLE . ' |
|
868 |
WHERE ' . $db->sql_in_set('topic_id', $topic_id_list); |
|
869 |
$result = $db->sql_query_limit($sql, 1); |
|
870 |
||
871 |
$deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics; |
|
872 |
$db->sql_freeresult($result); |
|
873 |
||
874 |
$topic_id = request_var('t', 0); |
|
875 |
||
876 |
// Return links
|
|
877 |
$return_link = array(); |
|
878 |
if ($affected_topics == 1 && !$deleted_topics && $topic_id) |
|
879 |
{
|
|
880 |
$return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id") . '">', '</a>'); |
|
881 |
}
|
|
882 |
$return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>'); |
|
883 |
||
884 |
if (sizeof($post_ids) == 1) |
|
885 |
{
|
|
886 |
if ($deleted_topics) |
|
887 |
{
|
|
888 |
// We deleted the only post of a topic, which in turn has
|
|
889 |
// been removed from the database
|
|
890 |
$success_msg = $user->lang['TOPIC_DELETED_SUCCESS']; |
|
891 |
}
|
|
892 |
else
|
|
893 |
{
|
|
894 |
$success_msg = $user->lang['POST_DELETED_SUCCESS']; |
|
895 |
}
|
|
896 |
}
|
|
897 |
else
|
|
898 |
{
|
|
899 |
if ($deleted_topics) |
|
900 |
{
|
|
901 |
// Some of topics disappeared
|
|
902 |
$success_msg = $user->lang['POSTS_DELETED_SUCCESS'] . '<br /><br />' . $user->lang['EMPTY_TOPICS_REMOVED_WARNING']; |
|
903 |
}
|
|
904 |
else
|
|
905 |
{
|
|
906 |
$success_msg = $user->lang['POSTS_DELETED_SUCCESS']; |
|
907 |
}
|
|
908 |
}
|
|
909 |
}
|
|
910 |
else
|
|
911 |
{
|
|
912 |
confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields); |
|
913 |
}
|
|
914 |
||
915 |
$redirect = request_var('redirect', "index.$phpEx"); |
|
916 |
$redirect = reapply_sid($redirect); |
|
917 |
||
918 |
if (!$success_msg) |
|
919 |
{
|
|
920 |
redirect($redirect); |
|
921 |
}
|
|
922 |
else
|
|
923 |
{
|
|
924 |
meta_refresh(3, $redirect); |
|
925 |
trigger_error($success_msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>') . '<br /><br />' . implode('<br /><br />', $return_link)); |
|
926 |
}
|
|
927 |
}
|
|
928 |
||
929 |
/**
|
|
930 |
* Fork Topic
|
|
931 |
*/
|
|
932 |
function mcp_fork_topic($topic_ids) |
|
933 |
{
|
|
934 |
global $auth, $user, $db, $template, $config; |
|
935 |
global $phpEx, $phpbb_root_path; |
|
936 |
||
937 |
if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_'))) |
|
938 |
{
|
|
939 |
return; |
|
940 |
}
|
|
941 |
||
942 |
$to_forum_id = request_var('to_forum_id', 0); |
|
943 |
$forum_id = request_var('f', 0); |
|
944 |
$redirect = request_var('redirect', build_url(array('_f_', 'action', 'quickmod'))); |
|
945 |
$additional_msg = $success_msg = ''; |
|
946 |
||
947 |
$s_hidden_fields = build_hidden_fields(array( |
|
948 |
'topic_id_list' => $topic_ids, |
|
949 |
'f' => $forum_id, |
|
950 |
'action' => 'fork', |
|
951 |
'redirect' => $redirect) |
|
952 |
);
|
|
953 |
||
954 |
if ($to_forum_id) |
|
955 |
{
|
|
956 |
$forum_data = get_forum_data($to_forum_id); |
|
957 |
||
958 |
if (!sizeof($topic_ids)) |
|
959 |
{
|
|
960 |
$additional_msg = $user->lang['NO_TOPIC_SELECTED']; |
|
961 |
}
|
|
962 |
else if (!sizeof($forum_data)) |
|
963 |
{
|
|
964 |
$additional_msg = $user->lang['FORUM_NOT_EXIST']; |
|
965 |
}
|
|
966 |
else
|
|
967 |
{
|
|
968 |
$forum_data = $forum_data[$to_forum_id]; |
|
969 |
||
970 |
if ($forum_data['forum_type'] != FORUM_POST) |
|
971 |
{
|
|
972 |
$additional_msg = $user->lang['FORUM_NOT_POSTABLE']; |
|
973 |
}
|
|
974 |
else if (!$auth->acl_get('f_post', $to_forum_id)) |
|
975 |
{
|
|
976 |
$additional_msg = $user->lang['USER_CANNOT_POST']; |
|
977 |
}
|
|
978 |
}
|
|
979 |
}
|
|
980 |
else if (isset($_POST['confirm'])) |
|
981 |
{
|
|
982 |
$additional_msg = $user->lang['FORUM_NOT_EXIST']; |
|
983 |
}
|
|
984 |
||
985 |
if ($additional_msg) |
|
986 |
{
|
|
987 |
unset($_POST['confirm']); |
|
988 |
unset($_REQUEST['confirm_key']); |
|
989 |
}
|
|
990 |
||
991 |
if (confirm_box(true)) |
|
992 |
{
|
|
993 |
$topic_data = get_topic_data($topic_ids); |
|
994 |
||
995 |
$total_posts = 0; |
|
996 |
$new_topic_id_list = array(); |
|
997 |
||
998 |
foreach ($topic_data as $topic_id => $topic_row) |
|
999 |
{
|
|
1000 |
$sql_ary = array( |
|
1001 |
'forum_id' => (int) $to_forum_id, |
|
1002 |
'icon_id' => (int) $topic_row['icon_id'], |
|
1003 |
'topic_attachment' => (int) $topic_row['topic_attachment'], |
|
1004 |
'topic_approved' => 1, |
|
1005 |
'topic_reported' => 0, |
|
1006 |
'topic_title' => (string) $topic_row['topic_title'], |
|
1007 |
'topic_poster' => (int) $topic_row['topic_poster'], |
|
1008 |
'topic_time' => (int) $topic_row['topic_time'], |
|
1009 |
'topic_replies' => (int) $topic_row['topic_replies_real'], |
|
1010 |
'topic_replies_real' => (int) $topic_row['topic_replies_real'], |
|
1011 |
'topic_status' => (int) $topic_row['topic_status'], |
|
1012 |
'topic_type' => (int) $topic_row['topic_type'], |
|
1013 |
'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], |
|
1014 |
'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'], |
|
1015 |
'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'], |
|
1016 |
'topic_last_post_time' => (int) $topic_row['topic_last_post_time'], |
|
1017 |
'topic_last_view_time' => (int) $topic_row['topic_last_view_time'], |
|
1018 |
'topic_bumped' => (int) $topic_row['topic_bumped'], |
|
1019 |
'topic_bumper' => (int) $topic_row['topic_bumper'], |
|
1020 |
'poll_title' => (string) $topic_row['poll_title'], |
|
1021 |
'poll_start' => (int) $topic_row['poll_start'], |
|
1022 |
'poll_length' => (int) $topic_row['poll_length'] |
|
1023 |
);
|
|
1024 |
||
1025 |
$db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); |
|
1026 |
$new_topic_id = $db->sql_nextid(); |
|
1027 |
$new_topic_id_list[$topic_id] = $new_topic_id; |
|
1028 |
||
1029 |
if ($topic_row['poll_start']) |
|
1030 |
{
|
|
1031 |
$poll_rows = array(); |
|
1032 |
||
1033 |
$sql = 'SELECT * |
|
1034 |
FROM ' . POLL_OPTIONS_TABLE . " |
|
1035 |
WHERE topic_id = $topic_id"; |
|
1036 |
$result = $db->sql_query($sql); |
|
1037 |
||
1038 |
while ($row = $db->sql_fetchrow($result)) |
|
1039 |
{
|
|
1040 |
$sql_ary = array( |
|
1041 |
'poll_option_id' => (int) $row['poll_option_id'], |
|
1042 |
'topic_id' => (int) $new_topic_id, |
|
1043 |
'poll_option_text' => (string) $row['poll_option_text'], |
|
1044 |
'poll_option_total' => 0 |
|
1045 |
);
|
|
1046 |
||
1047 |
$db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); |
|
1048 |
}
|
|
1049 |
}
|
|
1050 |
||
1051 |
$sql = 'SELECT * |
|
1052 |
FROM ' . POSTS_TABLE . " |
|
1053 |
WHERE topic_id = $topic_id |
|
1054 |
ORDER BY post_time ASC"; |
|
1055 |
$result = $db->sql_query($sql); |
|
1056 |
||
1057 |
$post_rows = array(); |
|
1058 |
while ($row = $db->sql_fetchrow($result)) |
|
1059 |
{
|
|
1060 |
$post_rows[] = $row; |
|
1061 |
}
|
|
1062 |
$db->sql_freeresult($result); |
|
1063 |
||
1064 |
if (!sizeof($post_rows)) |
|
1065 |
{
|
|
1066 |
continue; |
|
1067 |
}
|
|
1068 |
||
1069 |
$total_posts += sizeof($post_rows); |
|
1070 |
foreach ($post_rows as $row) |
|
1071 |
{
|
|
1072 |
$sql_ary = array( |
|
1073 |
'topic_id' => (int) $new_topic_id, |
|
1074 |
'forum_id' => (int) $to_forum_id, |
|
1075 |
'poster_id' => (int) $row['poster_id'], |
|
1076 |
'icon_id' => (int) $row['icon_id'], |
|
1077 |
'poster_ip' => (string) $row['poster_ip'], |
|
1078 |
'post_time' => (int) $row['post_time'], |
|
1079 |
'post_approved' => 1, |
|
1080 |
'post_reported' => 0, |
|
1081 |
'enable_bbcode' => (int) $row['enable_bbcode'], |
|
1082 |
'enable_smilies' => (int) $row['enable_smilies'], |
|
1083 |
'enable_magic_url' => (int) $row['enable_magic_url'], |
|
1084 |
'enable_sig' => (int) $row['enable_sig'], |
|
1085 |
'post_username' => (string) $row['post_username'], |
|
1086 |
'post_subject' => (string) $row['post_subject'], |
|
1087 |
'post_text' => (string) $row['post_text'], |
|
1088 |
'post_edit_reason' => (string) $row['post_edit_reason'], |
|
1089 |
'post_edit_user' => (int) $row['post_edit_user'], |
|
1090 |
'post_checksum' => (string) $row['post_checksum'], |
|
1091 |
'post_attachment' => (int) $row['post_attachment'], |
|
1092 |
'bbcode_bitfield' => $row['bbcode_bitfield'], |
|
1093 |
'bbcode_uid' => (string) $row['bbcode_uid'], |
|
1094 |
'post_edit_time' => (int) $row['post_edit_time'], |
|
1095 |
'post_edit_count' => (int) $row['post_edit_count'], |
|
1096 |
'post_edit_locked' => (int) $row['post_edit_locked'], |
|
1097 |
'post_postcount' => 0, |
|
1098 |
);
|
|
1099 |
||
1100 |
$db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); |
|
1101 |
$new_post_id = $db->sql_nextid(); |
|
1102 |
||
1103 |
// Copy whether the topic is dotted
|
|
1104 |
markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']); |
|
1105 |
||
1106 |
// Copy Attachments
|
|
1107 |
if ($row['post_attachment']) |
|
1108 |
{
|
|
1109 |
$sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . " |
|
1110 |
WHERE post_msg_id = {$row['post_id']} |
|
1111 |
AND topic_id = $topic_id |
|
1112 |
AND in_message = 0"; |
|
1113 |
$result = $db->sql_query($sql); |
|
1114 |
||
1115 |
$sql_ary = array(); |
|
1116 |
while ($attach_row = $db->sql_fetchrow($result)) |
|
1117 |
{
|
|
1118 |
$sql_ary[] = array( |
|
1119 |
'post_msg_id' => (int) $new_post_id, |
|
1120 |
'topic_id' => (int) $new_topic_id, |
|
1121 |
'in_message' => 0, |
|
1122 |
'is_orphan' => (int) $attach_row['is_orphan'], |
|
1123 |
'poster_id' => (int) $attach_row['poster_id'], |
|
1124 |
'physical_filename' => (string) basename($attach_row['physical_filename']), |
|
1125 |
'real_filename' => (string) basename($attach_row['real_filename']), |
|
1126 |
'download_count' => (int) $attach_row['download_count'], |
|
1127 |
'attach_comment' => (string) $attach_row['attach_comment'], |
|
1128 |
'extension' => (string) $attach_row['extension'], |
|
1129 |
'mimetype' => (string) $attach_row['mimetype'], |
|
1130 |
'filesize' => (int) $attach_row['filesize'], |
|
1131 |
'filetime' => (int) $attach_row['filetime'], |
|
1132 |
'thumbnail' => (int) $attach_row['thumbnail'] |
|
1133 |
);
|
|
1134 |
}
|
|
1135 |
$db->sql_freeresult($result); |
|
1136 |
||
1137 |
if (sizeof($sql_ary)) |
|
1138 |
{
|
|
1139 |
$db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary); |
|
1140 |
}
|
|
1141 |
}
|
|
1142 |
}
|
|
1143 |
||
1144 |
$sql = 'SELECT user_id, notify_status |
|
1145 |
FROM ' . TOPICS_WATCH_TABLE . ' |
|
1146 |
WHERE topic_id = ' . $topic_id; |
|
1147 |
$result = $db->sql_query($sql); |
|
1148 |
||
1149 |
$sql_ary = array(); |
|
1150 |
while ($row = $db->sql_fetchrow($result)) |
|
1151 |
{
|
|
1152 |
$sql_ary[] = array( |
|
1153 |
'topic_id' => (int) $new_topic_id, |
|
1154 |
'user_id' => (int) $row['user_id'], |
|
1155 |
'notify_status' => (int) $row['notify_status'], |
|
1156 |
);
|
|
1157 |
}
|
|
1158 |
$db->sql_freeresult($result); |
|
1159 |
||
1160 |
if (sizeof($sql_ary)) |
|
1161 |
{
|
|
1162 |
$db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary); |
|
1163 |
}
|
|
1164 |
}
|
|
1165 |
||
1166 |
// Sync new topics, parent forums and board stats
|
|
1167 |
sync('topic', 'topic_id', $new_topic_id_list); |
|
1168 |
||
1169 |
$sync_sql = array(); |
|
1170 |
||
1171 |
$sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts; |
|
1172 |
$sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list); |
|
1173 |
$sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list); |
|
1174 |
||
1175 |
foreach ($sync_sql as $forum_id_key => $array) |
|
1176 |
{
|
|
1177 |
$sql = 'UPDATE ' . FORUMS_TABLE . ' |
|
1178 |
SET ' . implode(', ', $array) . ' |
|
1179 |
WHERE forum_id = ' . $forum_id_key; |
|
1180 |
$db->sql_query($sql); |
|
1181 |
}
|
|
1182 |
||
1183 |
sync('forum', 'forum_id', $to_forum_id); |
|
1184 |
set_config('num_topics', $config['num_topics'] + sizeof($new_topic_id_list), true); |
|
1185 |
set_config('num_posts', $config['num_posts'] + $total_posts, true); |
|
1186 |
||
1187 |
foreach ($new_topic_id_list as $topic_id => $new_topic_id) |
|
1188 |
{
|
|
1189 |
add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']); |
|
1190 |
}
|
|
1191 |
||
1192 |
$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS'; |
|
1193 |
}
|
|
1194 |
else
|
|
1195 |
{
|
|
1196 |
$template->assign_vars(array( |
|
1197 |
'S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true), |
|
1198 |
'S_CAN_LEAVE_SHADOW' => false, |
|
1199 |
'ADDITIONAL_MSG' => $additional_msg) |
|
1200 |
);
|
|
1201 |
||
1202 |
confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); |
|
1203 |
}
|
|
1204 |
||
1205 |
$redirect = request_var('redirect', "index.$phpEx"); |
|
1206 |
$redirect = reapply_sid($redirect); |
|
1207 |
||
1208 |
if (!$success_msg) |
|
1209 |
{
|
|
1210 |
redirect($redirect); |
|
1211 |
}
|
|
1212 |
else
|
|
1213 |
{
|
|
1214 |
$redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); |
|
1215 |
meta_refresh(3, $redirect_url); |
|
1216 |
$return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'); |
|
1217 |
||
1218 |
if ($forum_id != $to_forum_id) |
|
1219 |
{
|
|
1220 |
$return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $to_forum_id) . '">', '</a>'); |
|
1221 |
}
|
|
1222 |
||
1223 |
trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link); |
|
1224 |
}
|
|
1225 |
}
|
|
1226 |
||
1227 |
?>
|