function Del_topic($idtopic, $generate_rss = true) { try { $topic = PersistenceContext::get_querier()->select_single_row(PREFIX . 'forum_topics', array('idcat', 'user_id'), 'WHERE id=:id', array('id' => $idtopic)); } catch (RowNotFoundException $e) { $error_controller = PHPBoostErrors::unexisting_element(); DispatchManager::redirect($error_controller); } $topic['user_id'] = (int) $topic['user_id']; //On ne supprime pas de msg aux membres ayant postés dans le topic => trop de requêtes. //On compte le nombre de messages du topic. $nbr_msg = PersistenceContext::get_querier()->count(PREFIX . "forum_msg", 'WHERE idtopic = :idtopic', array('idtopic' => $idtopic)); $nbr_msg = !empty($nbr_msg) ? NumberHelper::numeric($nbr_msg) : 1; //On rippe le topic ainsi que les messages du topic. PersistenceContext::get_querier()->delete(PREFIX . 'forum_msg', 'WHERE idtopic=:id', array('id' => $idtopic)); PersistenceContext::get_querier()->delete(PREFIX . 'forum_topics', 'WHERE id=:id', array('id' => $idtopic)); PersistenceContext::get_querier()->delete(PREFIX . 'forum_poll', 'WHERE idtopic=:id', array('id' => $idtopic)); //On met maintenant a jour le last_topic_id dans les catégories. $this->Update_last_topic_id($topic['idcat']); //Topic supprimé, on supprime les marqueurs de messages lus pour ce topic. PersistenceContext::get_querier()->delete(PREFIX . 'forum_view', 'WHERE idtopic=:id', array('id' => $idtopic)); //On supprime l'alerte. $this->Del_alert_topic($idtopic); //Insertion de l'action dans l'historique. if ($topic['user_id'] != AppContext::get_current_user()->get_id()) { forum_history_collector(H_DELETE_TOPIC, $topic['user_id'], 'forum' . url('.php?id=' . $topic['idcat'], '-' . $topic['idcat'] . '.php', '&')); } if ($generate_rss) { forum_generate_feeds(); } //Regénération des flux flux }
} else { $clause_parent = "id IN (" . $list_parent_cats . ")"; } $id_left = $CAT_FORUM[$parent_category]['id_right']; $Sql->query_inject("UPDATE " . PREFIX . "forum_cats SET id_right = id_right + 2 WHERE " . $clause_parent, __LINE__, __FILE__); $Sql->query_inject("UPDATE " . PREFIX . "forum_cats SET id_right = id_right + 2, id_left = id_left + 2 WHERE id_left > '" . $id_left . "'", __LINE__, __FILE__); $level = $CAT_FORUM[$parent_category]['level'] + 1; } else { $id_left = $Sql->query("SELECT MAX(id_right) FROM " . PREFIX . "forum_cats", __LINE__, __FILE__); $id_left++; $level = 0; } $Sql->query_inject("INSERT INTO " . PREFIX . "forum_cats (id_left, id_right, level, name, subname, url, nbr_topic, nbr_msg, last_topic_id, status, aprob, auth) VALUES('" . $id_left . "', '" . ($id_left + 1) . "', '" . $level . "', '" . $name . "', '" . $subname . "', '" . $url . "', 0, 0, 0, '" . $status . "', '" . $aprob . "', '" . addslashes(serialize($array_auth_all)) . "')", __LINE__, __FILE__); ###### Regénération du cache des catégories (liste déroulante dans le forum) ####### $Cache->Generate_module_file('forum'); forum_generate_feeds(); redirect(HOST . DIR . '/forum/admin_forum.php'); } else { redirect(HOST . DIR . '/forum/admin_forum_add.php?error=incomplete#errorh'); } } else { $Template->set_filenames(array('admin_forum_add' => 'forum/admin_forum_add.tpl')); $forums = '<option value="0" checked="checked" disabled="disabled">' . $LANG['root'] . '</option>'; $result = $Sql->query_while("SELECT id, name, level\n\tFROM " . PREFIX . "forum_cats\n\tORDER BY id_left", __LINE__, __FILE__); while ($row = $Sql->fetch_assoc($result)) { $margin = $row['level'] > 0 ? str_repeat('--------', $row['level']) : '--'; $forums .= '<option value="' . $row['id'] . '">' . $margin . ' ' . $row['name'] . '</option>'; } $Sql->query_close($result); $get_error = retrieve(GET, 'error', ''); if ($get_error == 'incomplete') {
function Del_topic($idtopic, $generate_rss = true) { global $Sql, $User, $CAT_FORUM; $topic = $Sql->query_array(PREFIX . 'forum_topics', 'idcat', 'user_id', "WHERE id = '" . $idtopic . "'", __LINE__, __FILE__); $topic['user_id'] = (int) $topic['user_id']; $nbr_msg = $Sql->query("SELECT COUNT(*) FROM " . PREFIX . "forum_msg WHERE idtopic = '" . $idtopic . "'", __LINE__, __FILE__); $nbr_msg = !empty($nbr_msg) ? numeric($nbr_msg) : 1; $Sql->query_inject("DELETE FROM " . PREFIX . "forum_msg WHERE idtopic = '" . $idtopic . "'", __LINE__, __FILE__); $Sql->query_inject("DELETE FROM " . PREFIX . "forum_topics WHERE id = '" . $idtopic . "'", __LINE__, __FILE__); $Sql->query_inject("DELETE FROM " . PREFIX . "forum_poll WHERE idtopic = '" . $idtopic . "'", __LINE__, __FILE__); $Sql->query_inject("UPDATE " . PREFIX . "forum_cats SET nbr_topic = nbr_topic - 1, nbr_msg = nbr_msg - '" . $nbr_msg . "' WHERE id_left <= '" . $CAT_FORUM[$topic['idcat']]['id_left'] . "' AND id_right >= '" . $CAT_FORUM[$topic['idcat']]['id_right'] . "' AND level <= '" . $CAT_FORUM[$topic['idcat']]['level'] . "'", __LINE__, __FILE__); $this->Update_last_topic_id($topic['idcat']); $Sql->query_inject("DELETE FROM " . PREFIX . "forum_view WHERE idtopic = '" . $idtopic . "'", __LINE__, __FILE__); $this->Del_alert_topic($idtopic); if ($topic['user_id'] != $User->get_attribute('user_id')) { forum_history_collector(H_DELETE_TOPIC, $topic['user_id'], 'forum' . url('.php?id=' . $topic['idcat'], '-' . $topic['idcat'] . '.php', '&')); } if ($generate_rss) { forum_generate_feeds(); } }