// Création du topic d'accueil
$sujet = '- Fusion - '.getformatmsg($TabTopic1['sujet'],false);
$pseudo = $_USER['username'];
$idmembre = $_USER['userid'];
$icon = 'icon2';
$message = "Fusion des sujets :<br><br>- ".getformatmsg($TabTopic1['sujet'],false)."<br>- ".getformatmsg($TabTopic2['sujet'],false);
$notifyme = "N";
$nbrep = $nbrep1+$nbrep2;
$datederrep = $TabTopic1['datederrep']>$TabTopic2['datederrep'] ? $TabTopic1['datederrep'] : $TabTopic2['datederrep'];
$derposter = $TabTopic1['datederrep']>$TabTopic2['datederrep'] ? $TabTopic1['derposter'] : $TabTopic2['derposter'];
$date = $TabTopic1['date']>$TabTopic2['date'] ? $TabTopic2['date']-1 : $TabTopic1['date']-1;
// Enregistrement du sujet "Fusion"
$query = $sql->query('INSERT INTO '.$_PRE.'topics (idforum, sujet, date, nbrep, nbvues, datederrep, derposter, icone, idmembre, pseudo, opentopic, poll) VALUES ("'.$forumdest.'", "'.$sujet.'", "'.$date.'", "'.$nbrep.'", "0", "'.$datederrep.'", "'.$derposter.'", "'.$icon.'", "'.$idmembre.'", "'.$pseudo.'", "Y", "0") ');
// ID du nouveau topic
$tinsertid = mysql_insert_id();
// Enregistrement du message
$query = $sql->query('INSERT INTO '.$_PRE.'posts (idforum, sujet, date, parent, msg, icone, idmembre, pseudo, postip, smiles, bbcode, notifyme) VALUES ("'.$forumdest.'", "'.$sujet.'", "'.$date.'", "'.$tinsertid.'", "'.$message.'", "'.$icon.'", "'.$idmembre.'", "'.$pseudo.'", "'.$_SERVER['REMOTE_ADDR'].'", "Y", "Y", "N") ');
// ID du nouveau message
$minsertid = mysql_insert_id();
// Mise à jour du forum
$sql->query('UPDATE '.$_PRE.'forums SET lastforumposter="'.$pseudo.'", lastdatepost="'.$date.'", lastidpost="'.$minsertid.'", forumtopic=forumtopic+1 WHERE forumid="'.$forumdest.'" ');
// Mise à jour du topic
$sql->query('UPDATE '.$_PRE.'topics SET idderpost="'.$minsertid.'" WHERE idtopic="'.$tinsertid.'" ');
// Mise à jour stats
updatenbtopics();
// Suppression des 2 topics fussionés
$sql->query('DELETE FROM '.$_PRE.'topics WHERE idtopic="'.$TabTopic1['idtopic'].'" ');
$sql->query('DELETE FROM '.$_PRE.'topics WHERE idtopic="'.$TabTopic2['idtopic'].'" ');
// On attache les réponses des topics fusionnés au nouveau topic
$sql->query('UPDATE '.$_PRE.'posts SET parent="'.$tinsertid.'" WHERE parent="'.$TabTopic1['idtopic'].'" ');
$sql->query('UPDATE '.$_PRE.'posts SET parent="'.$tinsertid.'" WHERE parent="'.$TabTopic2['idtopic'].'" ');
// Optimisation des tables
$sql->query('OPTIMIZE TABLE '.$_PRE.'topics');
$sql->query('OPTIMIZE TABLE '.$_PRE.'posts');
$tpl->box['msg'] = $tpl->attlang("topicmoved");
$tpl->box['editcontent'] = $tpl->gettemplate("editpost","msgbox");
$tpl->box['editcontent'] .= getjsredirect("list.php?forumid=".$forumdest,3000);
}