function MoveTopic2Forum($TID, $FID, $leaveLink = "N") { global $DB; $FID = intVal($FID); $arForum = CForumNew::GetByID($FID); $arTopics = is_array($TID) ? $TID : (intVal($TID) > 0 ? array($TID) : array()); $leaveLink = strToUpper($leaveLink) == "Y" ? "Y" : "N"; $arMsg = array(); $arForums = array(); if (empty($arForum)) { $arMsg[] = array("id" => "FORUM_NOT_EXIST", "text" => GetMessage("F_ERR_FORUM_NOT_EXIST", array("#FORUM_ID#" => $FID))); } if (empty($arTopics)) { $arMsg[] = array("id" => "TOPIC_EMPTY", "text" => GetMessage("F_ERR_EMPTY_TO_MOVE")); } if (!empty($arMsg)) { $e = new CAdminException($arMsg); $GLOBALS["APPLICATION"]->ThrowException($e); return false; } $arTopicsCopy = $arTopics; $arTopics = array(); foreach ($arTopicsCopy as $res) { $arTopics[intVal($res)] = array("ID" => intVal($res)); } $db_res = CForumTopic::GetList(array(), array("@ID" => implode(", ", array_keys($arTopics)))); if ($db_res && ($res = $db_res->Fetch())) { do { if (intVal($res["FORUM_ID"]) == $FID) { $arMsg[] = array("id" => "FORUM_ID_IDENTICAL", "text" => GetMessage("F_ERR_THIS_TOPIC_IS_NOT_MOVE", array("#TITLE#" => $res["TITLE"], "#ID#" => $res["ID"]))); continue; } // $DB->StartTransaction(); if ($leaveLink != "N") { CForumTopic::Add(array("TITLE" => $res["TITLE"], "DESCRIPTION" => $res["DESCRIPTION"], "STATE" => "L", "USER_START_NAME" => $res["USER_START_NAME"], "START_DATE" => $res["START_DATE"], "ICON_ID" => $res["ICON_ID"], "POSTS" => "0", "VIEWS" => "0", "FORUM_ID" => $res["FORUM_ID"], "TOPIC_ID" => $res["ID"], "APPROVED" => $res["APPROVED"], "SORT" => $res["SORT"], "LAST_POSTER_NAME" => $res["LAST_POSTER_NAME"], "LAST_POST_DATE" => $res["LAST_POST_DATE"], "HTML" => $res["HTML"], "USER_START_ID" => $res["USER_START_ID"], "SOCNET_GROUP_ID" => $res["SOCNET_GROUP_ID"], "OWNER_ID" => $res["OWNER_ID"])); } CForumTopic::Update($res["ID"], array("FORUM_ID" => $FID), true); // move message $strSql = "UPDATE b_forum_message SET FORUM_ID=" . $FID . ", POST_MESSAGE_HTML='' WHERE TOPIC_ID=" . $res["ID"]; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); // move subscribe $strSql = "UPDATE b_forum_subscribe SET FORUM_ID=" . intVal($FID) . " WHERE TOPIC_ID=" . $res["ID"]; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $arForums[$res["FORUM_ID"]] = $res["FORUM_ID"]; unset($GLOBALS["FORUM_CACHE"]["TOPIC"][$res["ID"]]); unset($GLOBALS["FORUM_CACHE"]["TOPIC_FILTER"][$res["ID"]]); $arTopics[intVal($res["ID"])] = $res; // $DB->Commit(); CForumCacheManager::ClearTag("F", $res["ID"]); $res_log["DESCRIPTION"] = str_replace(array("#TOPIC_TITLE#", "#TOPIC_ID#", "#FORUM_TITLE#", "#FORUM_ID#"), array($res["TITLE"], $res["ID"], $arForum["NAME"], $arForum["ID"]), $leaveLink != "N" ? GetMessage("F_LOGS_MOVE_TOPIC_WITH_LINK") : GetMessage("F_LOGS_MOVE_TOPIC")); $res_log["FORUM_ID"] = $arForum["ID"]; $res_log["TOPIC_ID"] = $res["ID"]; $res_log["TITLE"] = $res["TITLE"]; $res_log["FORUM_TITLE"] = $arForum["NAME"]; CForumEventLog::Log("topic", "move", $res["ID"], serialize($res_log)); } while ($res = $db_res->Fetch()); } /***************** Cleaning cache **********************************/ unset($GLOBALS["FORUM_CACHE"]["FORUM"][$FID]); if (CACHED_b_forum !== false) { $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum"); } /***************** Cleaning cache/**********************************/ CForumNew::SetStat($FID); foreach ($arForums as $key) { CForumNew::SetStat($key); } if (!empty($arMsg)) { $e = new CAdminException($arMsg); $GLOBALS["APPLICATION"]->ThrowException($e); } else { CForumCacheManager::ClearTag("F", $FID); if ($leaveLink != "Y") { foreach ($arTopics as $key => $res) { CForumCacheManager::ClearTag("F", $res["FORUM_ID"]); } } } return true; }
function ForumDeleteTopic($topic, &$strErrorMessage, &$strOKMessage, $arAddParams = array()) { global $USER; $arError = array(); $arOk = array(); $arAddParams = !is_array($arAddParams) ? array($arAddParams) : $arAddParams; $arAddParams["PERMISSION"] = !empty($arAddParams["PERMISSION"]) ? $arAddParams["PERMISSION"] : false; $topic = ForumDataToArray($topic); if (empty($topic)) { $arError[] = GetMessage("DELTOP_NO_TOPIC"); } else { if (!CForumUser::IsAdmin() && !$arAddParams["PERMISSION"]) { $db_res = CForumTopic::GetListEx(array(), array("@ID" => implode(",", $topic), "PERMISSION_STRONG" => true)); } else { $db_res = CForumTopic::GetListEx(array(), array("@ID" => implode(",", $topic))); } if ($db_res && ($res = $db_res->Fetch())) { do { if (CForumTopic::CanUserDeleteTopic($res["ID"], $USER->GetUserGroupArray(), $USER->GetID(), $arAddParams["PERMISSION"])) { if (CForumTopic::Delete($res["ID"])) { $arOk[] = GetMessage("DELTOP_OK") . " (TID=" . intVal($res["ID"]) . ")"; CForumCacheManager::ClearTag("F", $res['FORUM_ID']); CForumCacheManager::ClearTag("T", $res["ID"]); CForumEventLog::Log("topic", "delete", $res["ID"], serialize($res)); } else { $arError[] = GetMessage("DELTOP_NO") . " (TID=" . intVal($res["ID"]) . ")"; } } else { $arError[] = GetMessage("DELTOP_NO_PERMS") . " (TID=" . intVal($res["ID"]) . ")"; } } while ($res = $db_res->Fetch()); } else { $arError[] = GetMessage("FMT_NO_PERMS_EDIT"); } } if (count($arError) > 0) { $strErrorMessage .= implode(".\n", $arError) . ".\n"; } if (count($arOk) > 0) { $strOKMessage .= implode(".\n", $arOk) . ".\n"; } if (count($arError) > 0) { return false; } else { return true; } }