OK, here is the code I came up with, it is mostly based on the postings.php code, with some mods to make it suitable for more than two threads.
PHP Code:
case 'merge':
if (!can_moderate($vars['forumid'], 'canmanagethreads'))
{
print_no_permission();
}
if (!is_array($vars['threads']))
{
eval(print_standard_error('error_invalidid'));
}
if (empty($_POST['do']))
{
define('PRINT_TPL', 'inline_merge_thread');
}
else
{
toss_cookies();
$sqlthreads = implode(', ', $vars['threads']);
$firstpost = $DB_site->query_first("SELECT * FROM " . TABLE_PREFIX . "post WHERE threadid IN ($sqlthreads) ORDER BY dateline ASC");
$notes=$firstpost['notes'];
$thrd_firstpost=$firstpost['postid'];
$oldtitle=$firstpost['title'];
$notes=$firstpost['notes'];
$title=$_POST['title'];
$threadid=$firstpost['threadid'];
$newnotes = sprintf('Thread merged from other threads by %1$s on %2$s at %3$s via Moderation Tool.', $bbuserinfo['username'], vbdate($vboptions['dateformat'], TIMENOW), vbdate($vboptions['timeformat'], TIMENOW));
$newnotes .= $notes;
if ($title=='')
{
$title=$oldtitle;
}
foreach ($vars['threads'] AS $mergethreadid)
{
if ($mergethreadid!=$threadid)
{
$mergethreadid = verify_id('thread', $mergethreadid);
$mergethreadinfo = fetch_threadinfo($mergethreadid);
$mergeforuminfo = fetch_foruminfo($mergethreadinfo['forumid']);
if (!$mergethreadinfo['visible'] OR $mergethreadinfo['isdeleted'] OR $mergethreadid == $threadid)
{
eval(print_standard_error('error_invalidid'));
}
// check forum permissions for the merge forum
$mergeforumperms = fetch_permissions($mergethreadinfo['forumid']);
if (!($mergeforumperms & CANVIEW) OR !can_moderate($mergethreadinfo['forumid'], 'canmanagethreads'))
{
print_no_permission();
}
// check if there is a forum password and if so, ensure the user has it set
verify_forum_password($mergeforuminfo['forumid'], $mergeforuminfo['password']);
$mrgthrd_firstpost = $DB_site->query_first("
SELECT postid
FROM " . TABLE_PREFIX . "post
WHERE threadid = $mergethreadinfo[threadid]
ORDER BY dateline ASC
");
// sort out polls
$pollcode = '';
if ($mergethreadinfo['pollid'] != 0)
{ // merge thread has poll ...
if ($threadinfo['pollid'] == 0)
{ // ... and original thread doesn't
$pollcode = ',pollid = ' . $mergethreadinfo['pollid'];
}
else
{ // ... and original does
// if the poll isn't found anywhere else, delete the merge thread's poll
if (!$poll = $DB_site->query_first("
SELECT threadid
FROM " . TABLE_PREFIX . "thread
WHERE pollid = $mergethreadinfo[pollid] AND
threadid <> $mergethreadinfo[threadid]
"))
{
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "poll WHERE pollid = $mergethreadinfo[pollid]");
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "pollvote WHERE pollid = $mergethreadinfo[pollid]");
}
}
}
// move posts
$DB_site->query("UPDATE " . TABLE_PREFIX . "post SET threadid = $threadid WHERE threadid = $mergethreadid");
$DB_site->query("UPDATE " . TABLE_PREFIX . "post SET parentid = $thrd_firstpost[postid] WHERE postid = $mrgthrd_firstpost[postid]"); // make merge thread child of first post in other thread
$DB_site->query("UPDATE " . TABLE_PREFIX . "thread SET title = '" . addslashes(htmlspecialchars_uni($title)) . "'$pollcode WHERE threadid = $threadid");
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "thread WHERE threadid = $mergethreadid");
$DB_site->query("UPDATE " . TABLE_PREFIX . "thread SET pollid = $threadid WHERE open = 10 AND pollid = $mergethreadid"); // update redirects
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "threadrate WHERE threadid = $mergethreadid");
$DB_site->query("DELETE FROM " . TABLE_PREFIX . "subscribethread WHERE threadid = $mergethreadid");
// update postindex for the 2 posts who's titles may have changed (first post of each thread)
delete_post_index($thrd_firstpost['postid']);
delete_post_index($mrgthrd_firstpost['postid']);
build_post_index($thrd_firstpost['postid'] , $foruminfo);
build_post_index($mrgthrd_firstpost['postid'] , $foruminfo);
build_thread_counters($threadid);
build_forum_counters($threadinfo['forumid']);
if ($mergethreadinfo['forumid'] != $threadinfo['forumid'])
{
build_forum_counters($mergethreadinfo['forumid']);
}
}
}
if ($vars['forumid'])
{
$url = "forumdisplay.php?$session[sessionurl]f=$vars[forumid]&mod=1";
eval(print_standard_redirect('redirect_mergethread'));
}
}
break;
It works for me!
I just do not know what toss_cookies does!
Rgds