//批量合并
$modaction = 'MRGA';
checkreasonpm();//输入原因
$threadid = implode(",", $moderate);
$query = "SELECT * FROM {$tablepre}threads WHERE displayorder>='0' AND tid IN ($threadid) ORDER BY dateline";
$result = $db->query($query);
while($row = mysql_fetch_array($result))
{
$otherall[] = $row;
}
$mergeallnum = count($otherall);
if(!$otherall) {
showmessage('admin_merge_nonexistence');//主题不存在
} elseif($mergeallnum > 1) {
for($c=0;$c<=$mergeallnum;$c++)
{
if($otherall[$c]['special'])
showmessage('special_noaction');//无法操作特殊主题
}
}
if($mergeallnum > 1) {
for($c=0;$c<=$mergeallnum;$c++)
{
if($adminid == 3 && $otherall[$c]['fid'] != $forum['fid'])
showmessage('admin_merge_invalid');//请选择其他主题进行合并
}
}
$otherall[0]['views'] = intval($otherall[0]['views']);
$otherall[0]['replies']++;
$i=1;
$j=0;
$postsmerged=0;
while($i != $mergeallnum) {
$othertid= $otherall[$j]['tid'];
$tid = $otherall[$i]['tid'];
$views = $otherall[$i]['views'];
$replies = $otherall[$i]['replies'];
$firstpost = $db->fetch_first("SELECT pid, fid, authorid, author, subject, dateline FROM {$tablepre}posts WHERE tid='$tid' AND invisible='0' ORDER BY dateline LIMIT 1");//查询后续的帖子内容
$db->query("UPDATE {$tablepre}posts SET tid='$tid' WHERE tid='$othertid'");//回复表:把需要合并的目标帖子的回复内容的tid转换成当前帖子的id
$postsmerged += $db->affected_rows();
$db->query("UPDATE {$tablepre}attachments SET tid='$tid' WHERE tid='$othertid'");
$db->query("DELETE FROM {$tablepre}threads WHERE tid='$othertid'");
$db->query("DELETE FROM {$tablepre}threadsmod WHERE tid='$othertid'");
$db->query("UPDATE {$tablepre}posts SET first=(pid='$firstpost[pid]'), fid='$firstpost[fid]' WHERE tid='$tid'");
$db->query("UPDATE {$tablepre}threads SET authorid='$firstpost[authorid]', author='".addslashes($firstpost['author'])."', subject='".addslashes($otherall[0]['subject'])."', dateline='$firstpost[dateline]', views=views+$views, replies=replies+$replies, moderated='1' WHERE tid='$tid'");
if($fid == $otherall[0]['fid']) {
$db->query("UPDATE {$tablepre}forums SET threads=threads-1 WHERE fid='$fid'");
} else {
$db->query("UPDATE {$tablepre}forums SET threads=threads-1, posts=posts-$postsmerged WHERE fid='$otherall[0][fid]'");
$db->query("UPDATE {$tablepre}forums SET posts=$posts+$postsmerged WHERE fid='$fid'");
}
$forum['threadcaches'] && deletethreadcaches($thread['tid']);
$i++;
$j++;
|