} if (is_set($arFields, "FORUM_ID")) { if ($res["FORUM_ID"] != $arFields["FORUM_ID"]) { $result = CForumTopic::MoveTopic2Forum(array($res["ID"]), $arFields["FORUM_ID"], "N"); } unset($arFields["FORUM_ID"]); } foreach ($arFields as $key => $val) { if ($val == $res[$key]) { unset($arFields[$key]); } } if (empty($arFields)) { continue; } if (!CForumTopic::Update($ID, $arFields)) { if ($ex = $APPLICATION->GetException()) { $lAdmin->AddUpdateError($ex->GetString(), $ID); } else { $lAdmin->AddUpdateError(GetMessage("FM_WRONG_UPDATE"), $ID); } } else { if (is_set($arFields, "STATE") && $arFields["STATE"] != $res["STATE"]) { $res = serialize($res); if ($arFields["STATE"] == "Y") { CForumEventLog::Log("topic", "open", $ID, $res); } else { CForumEventLog::Log("topic", "close", $ID, $res); } unset($arFields["STATE"]); }
function ForumTopOrdinaryTopic($topic, $TYPE, &$strErrorMessage, &$strOKMessage, $arAddParams = array()) { global $USER; $arError = array(); $arOk = array(); $arFields = array("SORT" => $TYPE == "TOP" ? 100 : 150); $arAddParams = !is_array($arAddParams) ? array($arAddParams) : $arAddParams; $arAddParams["PERMISSION"] = !empty($arAddParams["PERMISSION"]) ? $arAddParams["PERMISSION"] : false; $topic = ForumDataToArray($topic); $forumID = 0; if (empty($topic)) { $arError[] = GetMessage("TOTOP_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 ($arAddParams["PERMISSION"] && !CForumTopic::CanUserUpdateTopic($res["ID"], $USER->GetUserGroupArray(), $USER->GetID(), $arAddParams["PERMISSION"])) { $arError[] = GetMessage("FMT_NO_PERMS_MODERATE") . " (TID=" . intVal($res["ID"]) . ")"; continue; } $ID = CForumTopic::Update($res["ID"], $arFields, True); if (IntVal($ID) <= 0) { if ($TYPE == "TOP") { $arError[] = GetMessage("TOTOP_ERROR_TOP") . " (TID=" . intVal($res["ID"]) . ")"; } else { $arError[] = GetMessage("TOTOP_ERROR_TOP1") . " (TID=" . intVal($res["ID"]) . ")"; } } else { $forumID = $res['FORUM_ID']; $arTopic["SORT"] = $arFields["SORT"]; $res = serialize($res); if ($TYPE == "TOP") { $arOk[] = GetMessage("TOTOP_SUCCESS_TOP") . " (TID=" . intVal($res["ID"]) . ")"; CForumEventLog::Log("topic", "stick", $ID, $res); } else { $arOk[] = GetMessage("TOTOP_SUCCESS_TOP1") . " (TID=" . intVal($res["ID"]) . ")"; CForumEventLog::Log("topic", "unstick", $ID, $res); } } } while ($res = $db_res->Fetch()); if (intval($forumID) > 0) { CForumCacheManager::ClearTag("F", $forumID); } } 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 (empty($arError)) { return true; } else { return false; } }
function SetStat($ID = 0, $arParams = array()) { global $DB; $ID = intVal($ID); if ($ID <= 0) { return false; } $arParams = is_array($arParams) ? $arParams : array(); $arMessage = is_array($arParams["MESSAGE"]) ? $arParams["MESSAGE"] : array(); if ($arMessage["TOPIC_ID"] != $ID) { $arMessage = array(); } $arFields = array(); if (!empty($arMessage)) { $arFields = array("ABS_LAST_POSTER_ID" => intVal($arMessage["AUTHOR_ID"]) > 0 ? $arMessage["AUTHOR_ID"] : false, "ABS_LAST_POSTER_NAME" => $arMessage["AUTHOR_NAME"], "ABS_LAST_POST_DATE" => $arMessage["POST_DATE"], "ABS_LAST_MESSAGE_ID" => $arMessage["ID"]); if ($arMessage["APPROVED"] == "Y") { $arFields["APPROVED"] = "Y"; $arFields["LAST_POSTER_ID"] = $arFields["ABS_LAST_POSTER_ID"]; $arFields["LAST_POSTER_NAME"] = $arFields["ABS_LAST_POSTER_NAME"]; $arFields["LAST_POST_DATE"] = $arFields["ABS_LAST_POST_DATE"]; $arFields["LAST_MESSAGE_ID"] = $arFields["ABS_LAST_MESSAGE_ID"]; if ($arMessage["NEW_TOPIC"] != "Y") { $arFields["=POSTS"] = "POSTS+1"; } } else { $arFields["=POSTS_UNAPPROVED"] = "POSTS_UNAPPROVED+1"; } } else { $res = CForumMessage::GetList(array(), array("TOPIC_ID" => $ID), "cnt_not_approved"); $res["CNT"] = intVal($res["CNT"]) - intVal($res["CNT_NOT_APPROVED"]); $res["CNT"] = $res["CNT"] > 0 ? $res["CNT"] : 0; if (intval($res["ABS_FIRST_MESSAGE_ID"]) > 0 && intval($res["ABS_FIRST_MESSAGE_ID"]) != intval($res["FIRST_MESSAGE_ID"])) { $strSQL = "UPDATE b_forum_message SET NEW_TOPIC = (CASE WHEN ID=" . intval($res["ABS_FIRST_MESSAGE_ID"]) . " THEN 'Y' ELSE 'N' END) WHERE TOPIC_ID=" . $ID; $GLOBALS["DB"]->Query($strSQL, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $arFields = array("APPROVED" => $res["CNT"] > 0 ? "Y" : "N", "POSTS" => $res["CNT"] > 0 ? $res["CNT"] - 1 : 0, "LAST_POSTER_ID" => false, "LAST_POSTER_NAME" => false, "LAST_POST_DATE" => false, "LAST_MESSAGE_ID" => intVal($res["LAST_MESSAGE_ID"]), "POSTS_UNAPPROVED" => intVal($res["CNT_NOT_APPROVED"]), "ABS_LAST_POSTER_ID" => false, "ABS_LAST_POSTER_NAME" => false, "ABS_LAST_POST_DATE" => false, "ABS_LAST_MESSAGE_ID" => intVal($res["ABS_LAST_MESSAGE_ID"])); if ($arFields["ABS_LAST_MESSAGE_ID"] > 0) { $res = CForumMessage::GetByID($arFields["ABS_LAST_MESSAGE_ID"], array("FILTER" => "N")); $arFields["ABS_LAST_POSTER_ID"] = intVal($res["AUTHOR_ID"]) > 0 ? $res["AUTHOR_ID"] : false; $arFields["ABS_LAST_POSTER_NAME"] = $res["AUTHOR_NAME"]; $arFields["ABS_LAST_POST_DATE"] = $res["POST_DATE"]; if (intVal($arFields["LAST_MESSAGE_ID"]) > 0) { if ($arFields["LAST_MESSAGE_ID"] < $arFields["ABS_LAST_MESSAGE_ID"]) { $res = CForumMessage::GetByID($arFields["LAST_MESSAGE_ID"], array("FILTER" => "N")); } $arFields["LAST_POSTER_ID"] = intVal($res["AUTHOR_ID"]) > 0 ? $res["AUTHOR_ID"] : false; $arFields["LAST_POSTER_NAME"] = $res["AUTHOR_NAME"]; $arFields["LAST_POST_DATE"] = $res["POST_DATE"]; } } foreach (array("LAST_POST_DATE" => "START_DATE", "ABS_LAST_POST_DATE" => "START_DATE", "LAST_POSTER_NAME" => "USER_START_NAME", "ABS_LAST_POSTER_NAME" => "USER_START_NAME") as $key => $val) { if ($arFields[$key] == false) { $arFields["=" . $key] = $val; unset($arFields[$key]); } } } return CForumTopic::Update($ID, $arFields); }
$sName = empty($sName) ? $nameProperty : $sName; $res = $obProperty->Add(array("IBLOCK_ID" => $PRODUCT_IBLOCK_ID, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => $sName, "CODE" => $nameProperty)); if ($res) { ${strToUpper($nameProperty)} = 0; } } } // 1.5 Set NULL for topic_id if it was deleted if ($FORUM_TOPIC_ID > 0) { $arTopic = CForumTopic::GetByID($FORUM_TOPIC_ID); if (!$arTopic || !is_array($arTopic) || count($arTopic) <= 0 || $arTopic["FORUM_ID"] != $arParams["FORUM_ID"]) { CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $PRODUCT_IBLOCK_ID, 0, "FORUM_TOPIC_ID"); CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $PRODUCT_IBLOCK_ID, 0, "FORUM_MESSAGE_CNT"); $FORUM_TOPIC_ID = 0; } elseif ($arTopic["XML_ID"] !== "IBLOCK_" . $arParams["ELEMENT_ID"]) { CForumTopic::Update($FORUM_TOPIC_ID, array("XML_ID" => "IBLOCK_" . $arParams["ELEMENT_ID"])); } } elseif (($arTopic = CForumTopic::GetList(array(), array("XML_ID" => "IBLOCK_" . $arParams["ELEMENT_ID"]))->fetch()) && $arTopic) { $FORUM_TOPIC_ID = intval($arTopic["ID"]); CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $PRODUCT_IBLOCK_ID, $arTopic["ID"], "FORUM_TOPIC_ID"); CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $PRODUCT_IBLOCK_ID, $arTopic["POSTS"], "FORUM_MESSAGE_CNT"); } // 1.6 Create New topic and add messages $MID = 0; $TID = 0; if ($FORUM_TOPIC_ID <= 0) { // 1.6.a Create New topic // 1.6.a.1 Get author info $arUserStart = array("ID" => intVal($arResult["ELEMENT"]["~CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array();