public function Execute() { if (!CModule::IncludeModule("forum")) { return CBPActivityExecutionStatus::Closed; } if (!CModule::IncludeModule("iblock")) { return CBPActivityExecutionStatus::Closed; } $forumId = intval($this->ForumId); if ($forumId <= 0) { return CBPActivityExecutionStatus::Closed; } $rootActivity = $this->GetRootActivity(); $documentId = $rootActivity->GetDocumentId(); $iblockId = $this->IBlockId; $dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID")); $arResult = $dbResult->Fetch(); if (!$arResult) { $obProperty = new CIBlockProperty(); $obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum topic", "CODE" => "FORUM_TOPIC_ID")); $obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum message count", "CODE" => "FORUM_MESSAGE_CNT")); $dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID")); $arResult = $dbResult->Fetch(); } $forumTopicId = intval($arResult["VALUE"]); $arForumUserTmp = $this->ForumUser; $arForumUser = CBPHelper::ExtractUsers($arForumUserTmp, $documentId, true); $forumUserId = 1; $forumUserName = "******"; if ($arForumUser != null) { $forumUserId = $arForumUser; $dbResult = CUser::GetByID($forumUserId); if ($arResult = $dbResult->Fetch()) { $forumUserName = CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arResult, true); } } $newTopic = "N"; if ($forumTopicId <= 0) { $documentService = $this->workflow->GetService("DocumentService"); $document = $documentService->GetDocument($documentId); $newTopic = "Y"; $arFields = array("TITLE" => $document["NAME"], "FORUM_ID" => $forumId, "USER_START_ID" => $forumUserId, "USER_START_NAME" => $forumUserName, "LAST_POSTER_NAME" => $forumUserName, "APPROVED" => "Y"); $forumTopicId = CForumTopic::Add($arFields); CIBlockElement::SetPropertyValues($documentId[2], $iblockId, $forumTopicId, "FORUM_TOPIC_ID"); } $arFields = array("POST_MESSAGE" => $this->ForumPostMessage, "AUTHOR_ID" => $forumUserId, "AUTHOR_NAME" => $forumUserName, "FORUM_ID" => $forumId, "TOPIC_ID" => $forumTopicId, "APPROVED" => "Y", "NEW_TOPIC" => $newTopic, "PARAM2" => $documentId[2]); $forumMessageId = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")); return CBPActivityExecutionStatus::Closed; }
} else { $authorName = "admin"; } $arForums = array(array("XML_ID" => "NEWS_COMMENTS", "NAME" => GetMessage("NEWS_COMMENTS_FORUM_NAME"), "DESCRIPTION" => GetMessage("NEWS_COMMENTS_FORUM_DESCRIPTION"), "SORT" => 2, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "Y", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "DEDUPLICATION" => "N", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroupID["COMMENTS"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "N", "SITES" => array(WIZARD_SITE_ID => WIZARD_SITE_DIR . "community/forum/messages/forum#FORUM_ID#/topic#TOPIC_ID#/message#MESSAGE_ID#/#message#MESSAGE_ID#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "M", WIZARD_PORTAL_ADMINISTRATION_GROUP => "Y")), array("XML_ID" => "PHOTOGALLERY_COMMENTS", "NAME" => GetMessage("PHOTOGALLERY_COMMENTS_FORUM_NAME"), "DESCRIPTION" => GetMessage("PHOTOGALLERY_COMMENTS_FORUM_DESCRIPTION"), "SORT" => 3, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "Y", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "DEDUPLICATION" => "N", "FORUM_GROUP_ID" => $arGroupID["HIDDEN"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "N", "SITES" => array(WIZARD_SITE_ID => WIZARD_SITE_DIR . "community/forum/messages/forum#FORUM_ID#/topic#TOPIC_ID#/message#MESSAGE_ID#/#message#MESSAGE_ID#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "M", WIZARD_PORTAL_ADMINISTRATION_GROUP => "Y")), array("XML_ID" => "USERS_AND_GROUPS", "NAME" => GetMessage("USERS_AND_GROUPS_FORUM_NAME"), "DESCRIPTION" => GetMessage("USERS_AND_GROUPS_FORUM_DESCRIPTION"), "SORT" => 4, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "A", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "DEDUPLICATION" => "N", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroupID["HIDDEN"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "N", "SITES" => array(WIZARD_SITE_ID => WIZARD_SITE_DIR . "community/forum/messages/forum#FORUM_ID#/topic#TOPIC_ID#/message#MESSAGE_ID#/#message#MESSAGE_ID#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array(WIZARD_PORTAL_ADMINISTRATION_GROUP => "Y")), array("XML_ID" => "DOCS_SHARED_COMMENTS", "NAME" => GetMessage("DOCS_SHARED_COMMENTS_NAME"), "DESCRIPTION" => GetMessage("DOCS_SHARED_COMMENTS_DECRIPTION"), "SORT" => 5, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "Y", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "DEDUPLICATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroupID["HIDDEN"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "N", "SITES" => array(WIZARD_SITE_ID => WIZARD_SITE_DIR . "community/forum/messages/forum#FORUM_ID#/topic#TOPIC_ID#/message#MESSAGE_ID#/#message#MESSAGE_ID#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "M", WIZARD_PORTAL_ADMINISTRATION_GROUP => "Y")), array("XML_ID" => "DOCS_SALES_COMMENTS", "NAME" => GetMessage("DOCS_SALES_COMMENTS_NAME"), "DESCRIPTION" => GetMessage("DOCS_SALES_COMMENTS_DECRIPTION"), "SORT" => 6, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "Y", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "DEDUPLICATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroupID["HIDDEN"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "N", "SITES" => array(WIZARD_SITE_ID => WIZARD_SITE_DIR . "community/forum/messages/forum#FORUM_ID#/topic#TOPIC_ID#/message#MESSAGE_ID#/#message#MESSAGE_ID#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "A", WIZARD_PORTAL_ADMINISTRATION_GROUP => "Y", WIZARD_EMPLOYEES_GROUP => "M", WIZARD_MARKETING_AND_SALES_GROUP => "M")), array("XML_ID" => "DOCS_DIRECTORS_COMMENTS", "NAME" => GetMessage("DOCS_DIRECTORS_COMMENTS_NAME"), "DESCRIPTION" => GetMessage("DOCS_DIRECTORS_COMMENTS_DECRIPTION"), "SORT" => 6, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "Y", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "DEDUPLICATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroupID["HIDDEN"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "N", "SITES" => array(WIZARD_SITE_ID => WIZARD_SITE_DIR . "community/forum/messages/forum#FORUM_ID#/topic#TOPIC_ID#/message#MESSAGE_ID#/#message#MESSAGE_ID#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "A", WIZARD_PORTAL_ADMINISTRATION_GROUP => "Y", WIZARD_DIRECTION_GROUP => "M")), array("XML_ID" => "GROUPS_AND_USERS_FILES_COMMENTS", "NAME" => GetMessage("GROUPS_AND_USERS_COMMENTS_NAME"), "DESCRIPTION" => GetMessage("GROUPS_AND_USERS_COMMENTS_DESCRIPTION"), "SORT" => 6, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "Y", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "DEDUPLICATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroupID["HIDDEN"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "N", "SITES" => array(WIZARD_SITE_ID => WIZARD_SITE_DIR . "community/forum/messages/forum#FORUM_ID#/topic#TOPIC_ID#/message#MESSAGE_ID#/#message#MESSAGE_ID#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "M", WIZARD_PORTAL_ADMINISTRATION_GROUP => "Y"))); foreach ($arForums as $arForum) { $dbForum = CForumNew::GetList(array(), array("SITE_ID" => WIZARD_SITE_ID, "XML_ID" => $arForum["XML_ID"])); if ($dbForum->Fetch()) { continue; } $forumID = CForumNew::Add($arForum); if ($forumID < 1 || !isset($arForum["TOPICS"]) || !is_array($arForum["TOPICS"])) { continue; } foreach ($arForum["TOPICS"] as $arTopic) { $arTopic["FORUM_ID"] = $forumID; $topicID = CForumTopic::Add($arTopic); if ($topicID < 1 || !isset($arTopic["MESSAGES"]) || !is_array($arTopic["MESSAGES"])) { continue; } foreach ($arTopic["MESSAGES"] as $arMessage) { $arMessage["FORUM_ID"] = $forumID; $arMessage["TOPIC_ID"] = $topicID; $messageID = CForumMessage::Add($arMessage, false); if ($messageID < 1) { CForumTopic::Delete($topicID); continue 2; } } CForumTopic::SetStat($topicID); } }
public static function AddComment_Report_Forum($arFields, $FORUM_ID, $arLog) { global $USER, $DB; $mess_id = false; $dbReport = CTimeManReportFull::GetByID($arLog["SOURCE_ID"]); $arReport = $dbReport->Fetch(); if (CModule::IncludeModule("forum") && $arReport) { $ufFileID = array(); $ufDocID = array(); if (!($userName = trim($USER->GetFormattedName(false)))) { $userName = $USER->GetLogin(); } if (!$arReport["FORUM_TOPIC_ID"]) { $arTopicFields = array("TITLE" => $arReport["DATE_FROM"] . "-" . $arReport["DATE_TO"], "USER_START_ID" => $arFields["USER_ID"], "STATE" => "Y", "FORUM_ID" => $FORUM_ID, "USER_START_NAME" => $userName, "START_DATE" => ConvertTimeStamp(time(), "FULL"), "POSTS" => 0, "VIEWS" => 0, "APPROVED" => "Y", "LAST_POSTER_NAME" => $userName, "LAST_POST_DATE" => ConvertTimeStamp(time(), "FULL"), "LAST_MESSAGE_ID" => 0, "XML_ID" => "TIMEMAN_REPORT_" . $arLog["SOURCE_ID"]); $TOPIC_ID = CForumTopic::Add($arTopicFields); if ($TOPIC_ID) { CTimeManReportFull::Update($arLog["SOURCE_ID"], array("FORUM_TOPIC_ID" => $TOPIC_ID)); } } else { $TOPIC_ID = $arReport["FORUM_TOPIC_ID"]; } if ($TOPIC_ID) { $arFieldsP = array("AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $userName, "POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "PARAM2" => $arLog["SOURCE_ID"]); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsP["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsP["FILES"][] = array("FILE_ID" => $file_id); } } } $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $arFieldsP); $mess_id = CForumMessage::Add($arFieldsP); // get UF DOC value and FILE_ID there if ($mess_id > 0) { $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $mess_id)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $mess_id, LANGUAGE_ID); } } } return array("SOURCE_ID" => $mess_id, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID)); }
function SocnetEMailMessageAdd($arMessageFields, $ACTION_VARS) { if (!is_array($arMessageFields["FORUM_EMAIL_FILTER"])) { return false; } if (!CModule::IncludeModule("socialnetwork")) { return false; } $arParams = $arMessageFields["FORUM_EMAIL_FILTER"]; if (!CSocNetFeatures::IsActiveFeature(SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum")) { return false; } // Найдем кто отправитель $message_email = strlen($arMessageFields["FIELD_REPLY_TO"]) > 0 ? $arMessageFields["FIELD_REPLY_TO"] : $arMessageFields["FIELD_FROM"]; $message_email_addr = strtolower(CMailUtil::ExtractMailAddress($message_email)); $o = "LAST_LOGIN"; $b = "DESC"; $res = CUser::GetList($o, $b, array("ACTIVE" => "Y", "EMAIL" => $message_email_addr)); if (($arUser = $res->Fetch()) && strtolower(CMailUtil::ExtractMailAddress($arUser["EMAIL"])) == $message_email_addr) { $AUTHOR_USER_ID = $arUser["ID"]; } elseif ($arParams["NOT_MEMBER_POST"] == "Y") { $AUTHOR_USER_ID = false; } else { CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR1") . ": " . $message_email_addr)); return false; } if ($arParams["NOT_MEMBER_POST"] != "Y") { // Проверим права доступа if (CSocNetFeaturesPerms::CanPerformOperation($AUTHOR_USER_ID, SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum", "full")) { $PERMISSION = "Y"; } elseif (CSocNetFeaturesPerms::CanPerformOperation($AUTHOR_USER_ID, SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum", "newtopic")) { $PERMISSION = "M"; } elseif (CSocNetFeaturesPerms::CanPerformOperation($AUTHOR_USER_ID, SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum", "answer")) { $PERMISSION = "I"; } else { CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR2") . " " . $arUser["LOGIN"] . " [" . $AUTHOR_USER_ID . "] (" . $message_email_addr . ")")); return false; } } $body = $arMessageFields["BODY"]; //$body = preg_replace("/(\r\n)+/", "\r\n", $body); $p = strpos($body, "\r\nFrom:"); if ($p > 0) { $body = substr($body, 0, $p) . "\r\n[CUT]" . substr($body, $p) . "[/CUT]"; } $subject = $arMessageFields["SUBJECT"]; // обрежем все RE и FW $subject = trim(preg_replace('#^\\s*((RE[0-9\\[\\]]*:\\s*)|(FW:\\s*))+(.*)$#i', '\\4', $subject)); if ($subject == '') { $subject = GetMessage("FORUM_MAIL_EMPTY_TOPIC_TITLE") . " " . rand(); } // Найдем какая тема $arFields = array(); $FORUM_ID = IntVal($arParams["FORUM_ID"]); $SOCNET_GROUP_ID = IntVal($arParams["SOCNET_GROUP_ID"]); $TOPIC_ID = 0; global $DB; if ($arMessageFields["IN_REPLY_TO"] != '') { $dbTopic = $DB->Query("SELECT FT.ID FROM b_forum_topic FT INNER JOIN b_forum_message FM ON FM.TOPIC_ID=FT.ID WHERE FM.XML_ID='" . $DB->ForSQL($arMessageFields["IN_REPLY_TO"], 255) . "' AND FT.FORUM_ID=" . $FORUM_ID . " AND FT.SOCNET_GROUP_ID=" . $SOCNET_GROUP_ID); if ($arTopic = $dbTopic->Fetch()) { $TOPIC_ID = $arTopic["ID"]; } } if ($arParams["USE_SUBJECT"] == "Y" && $TOPIC_ID <= 0) { $dbTopic = $DB->Query("SELECT ID FROM b_forum_topic WHERE TITLE='" . $DB->ForSQL($subject, 255) . "' AND FORUM_ID=" . $FORUM_ID . " AND SOCNET_GROUP_ID=" . $SOCNET_GROUP_ID); // ограничить по старости? if ($arTopic = $dbTopic->Fetch()) { $TOPIC_ID = $arTopic["ID"]; } } if ($AUTHOR_USER_ID > 0) { if ($TOPIC_ID < 0 && $PERMISSION <= "I") { CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR3") . " " . $arUser["LOGIN"] . " [" . $AUTHOR_USER_ID . "] (" . $message_email_addr . ")")); return false; } $bSHOW_NAME = true; $res = CForumUser::GetByUSER_ID($AUTHOR_USER_ID); if ($res) { $bSHOW_NAME = $res["SHOW_NAME"] == "Y"; } if ($bSHOW_NAME) { $AUTHOR_NAME = $arUser["NAME"] . (strlen($arUser["NAME"]) <= 0 || strlen($arUser["LAST_NAME"]) <= 0 ? "" : " ") . $arUser["LAST_NAME"]; } if (strlen(Trim($AUTHOR_NAME)) <= 0) { $AUTHOR_NAME = $arUser["LOGIN"]; } } else { $AUTHOR_NAME = $arMessageFields["FIELD_FROM"]; $arFields["AUTHOR_EMAIL"] = $arMessageFields["FIELD_FROM"]; } $arFields["NEW_TOPIC"] = "N"; if ($PERMISSION >= "Q") { $arFields["APPROVED"] = "Y"; } else { $arFields["APPROVED"] = $arParams["MODERATION"] == "Y" ? "N" : "Y"; } // Добавим новую тему if ($TOPIC_ID <= 0) { $arTopicFields = array("TITLE" => $subject, "FORUM_ID" => $FORUM_ID, "USER_START_ID" => $AUTHOR_USER_ID, "OWNER_ID" => $AUTHOR_USER_ID, "SOCNET_GROUP_ID" => $SOCNET_GROUP_ID); $arTopicFields["XML_ID"] = $arMessageFields["MSG_ID"]; $arTopicFields["APPROVED"] = $arFields['APPROVED']; $arTopicFields["USER_START_NAME"] = $AUTHOR_NAME; $arTopicFields["LAST_POSTER_NAME"] = $AUTHOR_NAME; $TOPIC_ID = CForumTopic::Add($arTopicFields); if (IntVal($TOPIC_ID) <= 0) { CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR4"))); return false; } $arFields["NEW_TOPIC"] = "Y"; } // Добавим сообщение $arFields["POST_MESSAGE"] = $body; // Аттаченные файлы $arFILES = array(); $rsAttach = CMailAttachment::GetList(array(), array("MESSAGE_ID" => $arMessageFields["ID"])); while ($arAttach = $rsAttach->Fetch()) { $filename = CTempFile::GetFileName(md5(uniqid("")) . ".tmp"); CheckDirPath($filename); if (file_put_contents($filename, $arAttach["FILE_DATA"]) !== false) { $arFile = array("name" => $arAttach["FILE_NAME"], "type" => $arAttach["CONTENT_TYPE"], "size" => @filesize($filename), "tmp_name" => $filename, "MODULE_ID" => "forum"); $arFilter = array("FORUM_ID" => $FORUM_ID); $arFiles = array($arFile); if (CForumFiles::CheckFields($arFiles, $arFilter)) { $arFILES[] = $arFiles[0]; } else { $oError = $GLOBALS["APPLICATION"]->GetException(); CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR6") . " (" . $arAttach["FILE_NAME"] . "): " . ($oError && $oError->GetString() ? $oError->GetString() : ""))); } } } if (count($arFILES) > 0) { $arFields["FILES"] = $arFILES; } $arFields["AUTHOR_NAME"] = $AUTHOR_NAME; $arFields["AUTHOR_ID"] = $AUTHOR_USER_ID; $arFields["FORUM_ID"] = $FORUM_ID; $arFields["TOPIC_ID"] = $TOPIC_ID; $arFields["XML_ID"] = $arMessageFields["MSG_ID"]; $arFields["SOURCE_ID"] = "EMAIL"; $arRes = array(); if (!empty($arMessageFields["FIELD_FROM"])) { $arRes[] = "From: " . $arMessageFields["FIELD_FROM"]; } if (!empty($arMessageFields["FIELD_TO"])) { $arRes[] = "To: " . $arMessageFields["FIELD_TO"]; } if (!empty($arMessageFields["FIELD_CC"])) { $arRes[] = "Cc: " . $arMessageFields["FIELD_CC"]; } if (!empty($arMessageFields["FIELD_BCC"])) { $arRes[] = "Bcc: " . $arMessageFields["FIELD_BCC"]; } $arRes[] = "Subject: " . $arMessageFields["SUBJECT"]; $arRes[] = "Date: " . $arMessageFields["FIELD_DATE"]; $arFields["MAIL_HEADER"] = implode("\r\n", $arRes); preg_match_all('#Received:\\s+from\\s+(.*)by.*#i', $arMessageFields["HEADER"], $regs); if (is_array($regs) && is_array($regs[1])) { $arFields["AUTHOR_IP"] = $arFields["AUTHOR_REAL_IP"] = '<email: ' . $regs[1][count($regs[1]) - 1] . '>'; } else { $arFields["AUTHOR_IP"] = $arFields["AUTHOR_REAL_IP"] = '<email: no address>'; } /* $AUTHOR_IP = ForumGetRealIP(); $AUTHOR_IP_tmp = $AUTHOR_IP; $AUTHOR_REAL_IP = $_SERVER['REMOTE_ADDR']; if (COption::GetOptionString("forum", "FORUM_GETHOSTBYADDR", "N") == "Y") { $AUTHOR_IP = @gethostbyaddr($AUTHOR_IP); if ($AUTHOR_IP_tmp==$AUTHOR_REAL_IP) $AUTHOR_REAL_IP = $AUTHOR_IP; else $AUTHOR_REAL_IP = @gethostbyaddr($AUTHOR_REAL_IP); } $arFields["AUTHOR_IP"] = ($AUTHOR_IP!==False) ? $AUTHOR_IP : "<no address>"; $arFields["AUTHOR_REAL_IP"] = ($AUTHOR_REAL_IP!==False) ? $AUTHOR_REAL_IP : "<no address>"; */ $strErrorMessage = ''; $MESSAGE_ID = CForumMessage::Add($arFields, false); if (intVal($MESSAGE_ID) <= 0) { $str = $GLOBALS['APPLICATION']->GetException(); if ($str && $str->GetString()) { $strErrorMessage .= "[" . $str->GetString() . "]"; } if ($arFields["NEW_TOPIC"] == 'Y') { CForumTopic::Delete($TOPIC_ID); } CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR5") . " " . $strErrorMessage)); } if ($MESSAGE_ID > 0) { CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_COMPLETE", "MESSAGE" => GetMessage("FORUM_MAIL_OK") . " " . $MESSAGE_ID . " (TID#" . $TOPIC_ID . ")")); CForumMessage::SendMailMessage($MESSAGE_ID, array(), false, "NEW_FORUM_MESSAGE"); $dbSite = CSite::GetById($arMessageFields["LID"]); if ($arSite = $dbSite->Fetch()) { $lang = $arSite['LANGUAGE_ID']; } else { $lang = $LANGUAGE_ID; } $parser = new forumTextParser(); $arForum = CForumNew::GetByID($FORUM_ID); $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "LIST" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => "N", "TABLE" => "N", "ALIGN" => "N"); if ($arFields["NEW_TOPIC"] == "Y") { $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_GROUP, "ENTITY_ID" => $SOCNET_GROUP_ID, "EVENT_ID" => "forum", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $AUTHOR_NAME, CForumEmail::GetLangMessage("FORUM_MAIL_SOCNET_TITLE_TOPIC", $lang)), "TITLE" => $subject, "MESSAGE" => $parser->convert($body, $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($body), "URL" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("UID" => $AUTHOR_USER_ID, "FID" => $FORUM_ID, "TID" => $TOPIC_ID, "MID" => $MESSAGE_ID)), "PARAMS" => serialize(array("PATH_TO_MESSAGE" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("TID" => $TOPIC_ID)))), "MODULE_ID" => false, "CALLBACK_FUNC" => false, "SOURCE_ID" => $MESSAGE_ID, "RATING_TYPE_ID" => "FORUM_TOPIC", "RATING_ENTITY_ID" => intval($TOPIC_ID)); if (intVal($AUTHOR_USER_ID) > 0) { $arFieldsForSocnet["USER_ID"] = $AUTHOR_USER_ID; } $logID = CSocNetLog::Add($arFieldsForSocnet, false); if (intval($logID) > 0) { CSocNetLog::Update($logID, array("TMP_ID" => $logID)); CSocNetLogRights::SetForSonet($logID, $arFieldsForSocnet["ENTITY_TYPE"], $arFieldsForSocnet["ENTITY_ID"], "forum", "view", true); CSocNetLog::SendEvent($logID, "SONET_NEW_EVENT", $logID); } } else { $dbForumMessage = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID)); if ($arForumMessage = $dbForumMessage->Fetch()) { $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "forum", "SOURCE_ID" => $arForumMessage["ID"]), false, false, array("ID", "TMP_ID")); if ($arRes = $dbRes->Fetch()) { $log_id = $arRes["TMP_ID"]; } else { $dbFirstMessage = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $arForumMessage["TOPIC_ID"]), false, 1); if ($arFirstMessage = $dbFirstMessage->Fetch()) { $arTopic = CForumTopic::GetByID($arFirstMessage["TOPIC_ID"]); $sFirstMessageText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arFirstMessage["POST_MESSAGE_FILTER"] : $arFirstMessage["POST_MESSAGE"]; $sFirstMessageURL = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("UID" => $arFirstMessage["AUTHOR_ID"], "FID" => $arFirstMessage["FORUM_ID"], "TID" => $arFirstMessage["TOPIC_ID"], "MID" => $arFirstMessage["ID"])); $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_GROUP, "ENTITY_ID" => $SOCNET_GROUP_ID, "EVENT_ID" => "forum", "LOG_DATE" => $arFirstMessage["POST_DATE"], "LOG_UPDATE" => $arFirstMessage["POST_DATE"], "TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $arFirstMessage["AUTHOR_NAME"], GetMessage("SONET_FORUM_LOG_TOPIC_TEMPLATE")), "TITLE" => $arTopic["TITLE"], "MESSAGE" => $parser->convert($sFirstMessageText, $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($sFirstMessageText), "URL" => $sFirstMessageURL, "PARAMS" => serialize(array("PATH_TO_MESSAGE" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("TID" => $arFirstMessage["TOPIC_ID"])))), "MODULE_ID" => false, "CALLBACK_FUNC" => false, "SOURCE_ID" => $arFirstMessage["ID"], "RATING_TYPE_ID" => "FORUM_TOPIC", "RATING_ENTITY_ID" => intval($arFirstMessage["TOPIC_ID"])); if (intVal($arFirstMessage["AUTHOR_ID"]) > 0) { $arFieldsForSocnet["USER_ID"] = $arFirstMessage["AUTHOR_ID"]; } $log_id = CSocNetLog::Add($arFieldsForSocnet, false); if (intval($log_id) > 0) { CSocNetLog::Update($log_id, array("TMP_ID" => $log_id)); CSocNetLogRights::SetForSonet($log_id, $arFieldsForSocnet["ENTITY_TYPE"], $arFieldsForSocnet["ENTITY_ID"], "forum", "view", true); } } } if (intval($log_id) > 0) { $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_GROUP, "ENTITY_ID" => $SOCNET_GROUP_ID, "EVENT_ID" => "forum", "LOG_ID" => $log_id, "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $parser->convert($body, $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($body), "URL" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("UID" => $AUTHOR_USER_ID, "FID" => $FORUM_ID, "TID" => $TOPIC_ID, "MID" => $MESSAGE_ID)), "MODULE_ID" => false, "SOURCE_ID" => $MESSAGE_ID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => intval($MESSAGE_ID)); if (intVal($AUTHOR_USER_ID) > 0) { $arFieldsForSocnet["USER_ID"] = $AUTHOR_USER_ID; } CSocNetLogComments::Add($arFieldsForSocnet); } } } } }
/** * WARNING! This method is transitional and can be changed without * any notifications! Don't use it. * * @deprecated */ public static function __deprecated_Add($commentText, $forumTopicId, $forumId, $nameTemplate, $arTask, $permissions, $commentId, $givenUserId, $imageWidth, $imageHeight, $arSmiles, $arForum, $messagesPerPage, $arUserGroupArray, $backPage, $strMsgAddComment, $strMsgEditComment, $strMsgNewTask, $componentName, &$outForumTopicId, &$arErrorCodes, &$outStrUrl, $arFieldsAdditional = array()) { global $DB; if (is_array($arTask)) { if (!array_key_exists('~TITLE', $arTask)) { $arTmpTask = $arTask; foreach ($arTmpTask as $key => $value) { if (substr($key, 0, 1) !== '~') { $arTask['~' . $key] = $arTmpTask[$key]; } } } } $MID = 0; $TID = 0; if ($forumTopicId > 0 && CForumTopic::GetByID($forumTopicId) === false) { $forumTopicId = false; } if ($forumTopicId <= 0) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim(CUser::FormatName($nameTemplate, $res)) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arFields = array("TITLE" => $arTask["~TITLE"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions, "NAME_TEMPLATE" => $nameTemplate, 'XML_ID' => 'TASK_' . $arTask['ID']); $TID = CForumTopic::Add($arFields); if (intVal($TID) <= 0) { $arErrorCodes[] = array('code' => 'topic is not created'); } else { $arFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arFields); } if (!empty($arErrorCodes)) { $DB->Rollback(); return false; } else { $DB->Commit(); } } $arFieldsG = array("POST_MESSAGE" => $commentText, "AUTHOR_NAME" => '', "AUTHOR_EMAIL" => $GLOBALS['USER']->GetEmail(), "USE_SMILES" => NULL, "PARAM2" => $arTask['ID'], "TITLE" => $arTask["~TITLE"], "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions); // UF_* forwarding if (is_array($arFieldsAdditional)) { foreach ($arFieldsAdditional as $field => $value) { if (strlen($field) && substr($field, 0, 3) == 'UF_') { $arFieldsG[$field] = $value; $GLOBALS[$field] = $value; // strange behaviour required for ForumMessageAdd() to handle UF_* properly } } } if (!empty($_FILES["REVIEW_ATTACH_IMG"])) { $arFieldsG["ATTACH_IMG"] = $_FILES["REVIEW_ATTACH_IMG"]; } else { $arFiles = array(); if (!empty($_REQUEST["FILES"])) { foreach ($_REQUEST["FILES"] as $key) { $arFiles[$key] = array("FILE_ID" => $key); if (!in_array($key, $_REQUEST["FILES_TO_UPLOAD"])) { $arFiles[$key]["del"] = "Y"; } } } if (!empty($_FILES)) { $res = array(); foreach ($_FILES as $key => $val) { if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) { $arFiles[] = $_FILES[$key]; } } } if (!empty($arFiles)) { $arFieldsG["FILES"] = $arFiles; } } $TOPIC_ID = $forumTopicId > 0 ? $forumTopicId : $TID; $MESSAGE_ID = 0; $MESSAGE_TYPE = $TOPIC_ID > 0 ? "REPLY" : "NEW"; if (COption::GetOptionString("tasks", "task_comment_allow_edit") && ($MESSAGE_ID = intval($commentId))) { $MESSAGE_TYPE = "EDIT"; } $strErrorMessage = ''; $strOKMessage = ''; $MID = ForumAddMessage($MESSAGE_TYPE, $forumId, $TOPIC_ID, $MESSAGE_ID, $arFieldsG, $strErrorMessage, $strOKMessage, false, $_POST["captcha_word"], 0, $_POST["captcha_code"], $nameTemplate); if ($MID <= 0 || !empty($strErrorMessage)) { $arErrorCodes[] = array('code' => 'message is not added 2', 'title' => empty($strErrorMessage) ? NULL : $strErrorMessage); } else { $arMessage = CForumMessage::GetByID($MID); if ($forumTopicId <= 0) { $forumTopicId = $TID = intVal($arMessage["TOPIC_ID"]); } $outForumTopicId = intVal($forumTopicId); if ($componentName !== null) { ForumClearComponentCache($componentName); } // NOTIFICATION $arTask["ACCOMPLICES"] = $arTask["AUDITORS"] = array(); $rsMembers = CTaskMembers::GetList(array(), array("TASK_ID" => $arTask["ID"])); while ($arMember = $rsMembers->Fetch()) { if ($arMember["TYPE"] == "A") { $arTask["ACCOMPLICES"][] = $arMember["USER_ID"]; } elseif ($arMember["TYPE"] == "U") { $arTask["AUDITORS"][] = $arMember["USER_ID"]; } } $arEmailUserIDs = array($arTask["RESPONSIBLE_ID"], $arTask["CREATED_BY"]); $arEmailUserIDs = array_unique(array_merge($arEmailUserIDs, $arTask["ACCOMPLICES"], $arTask["AUDITORS"])); $currentUserPos = array_search($givenUserId, $arEmailUserIDs); if ($currentUserPos !== false) { unset($arEmailUserIDs[$currentUserPos]); } $parser = new CTextParser(); $parser->imageWidth = $imageWidth; $parser->imageHeight = $imageHeight; $parser->smiles = $arSmiles; $parser->allow = array("HTML" => $arForum["ALLOW_HTML"], "ANCHOR" => $arForum["ALLOW_ANCHOR"], "BIU" => $arForum["ALLOW_BIU"], "IMG" => "N", "VIDEO" => "N", "LIST" => $arForum["ALLOW_LIST"], "QUOTE" => $arForum["ALLOW_QUOTE"], "CODE" => $arForum["ALLOW_CODE"], "FONT" => $arForum["ALLOW_FONT"], "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => $arForum["ALLOW_NL2BR"], "TABLE" => "Y"); $arAllow = NULL; $MESSAGE = HTMLToTxt($parser->convertText($commentText, $arAllow)); // remove [ url] for socialnetwork log $MESSAGE = preg_replace("/(\\s\\[\\s(http:\\/\\/|https:\\/\\/|ftp:\\/\\/))(.*?)(\\s\\])/is", "", $MESSAGE); $parser->allow = array("HTML" => 'Y', "ANCHOR" => 'Y', "BIU" => 'Y', "IMG" => "Y", "VIDEO" => "Y", "LIST" => 'N', "QUOTE" => 'Y', "CODE" => 'Y', "FONT" => 'Y', "SMILES" => "N", "UPLOAD" => 'N', "NL2BR" => 'N', "TABLE" => "Y"); $message_notify = $parser->convertText($commentText); $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); // Instant Messages if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { // this entire class is deprecated. disable edit message, add only here if ($MESSAGE_TYPE != 'EDIT') { CTaskComments::sendAddMessage(array('ID' => $MID, 'POST_MESSAGE' => $message_notify), $arTask, $givenUserId, $arRecipientsIDs, array()); } } $strURL = !empty($backPage) ? $backPage : $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result")); $strURL = ForumAddPageParams($strURL, array("MID" => $MID, "result" => $arForum["MODERATION"] != "Y" || CForumNew::CanUserModerateForum($forumId, $arUserGroupArray) ? "reply" : "not_approved"), false, false); $outStrUrl = $strURL; // sonet log if (CModule::IncludeModule("socialnetwork")) { $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID")); if ($arRes = $dbRes->Fetch()) { $log_id = $arRes["TMP_ID"]; $entity_type = $arRes["ENTITY_TYPE"]; $entity_id = $arRes["ENTITY_ID"]; } else { $entity_type = $arTask["GROUP_ID"] ? SONET_ENTITY_GROUP : SONET_ENTITY_USER; $entity_id = $arTask["GROUP_ID"] ? $arTask["GROUP_ID"] : $arTask["CREATED_BY"]; $rsUser = CUser::GetByID($arTask["CREATED_BY"]); if ($arUser = $rsUser->Fetch()) { $arSoFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks", "LOG_DATE" => $arTask["CREATED_DATE"], "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => htmlspecialcharsBack($arTask["~TITLE"]), "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $arTask["ID"], "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]), "PARAMS" => serialize(array("TYPE" => "create"))); $log_id = CSocNetLog::Add($arSoFields, false); if (intval($log_id) > 0) { CSocNetLog::Update($log_id, array("TMP_ID" => $log_id)); $arRights = CTaskNotifications::__UserIDs2Rights(CTaskNotifications::GetRecipientsIDs($arTask, false)); if ($arTask["GROUP_ID"]) { $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"]; } CSocNetLogRights::Add($log_id, $arRights); } } } if (intval($log_id) > 0) { $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]; CSocNetLog::Update($log_id, array('PARAMS' => serialize(array('TYPE' => 'comment')))); $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "tasks", "SOURCE_ID" => $MID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $MID); if ($MESSAGE_TYPE == "EDIT") { $dbRes = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => array("tasks_comment"), "SOURCE_ID" => $MID), false, false, array("ID")); while ($arRes = $dbRes->Fetch()) { CSocNetLogComments::Update($arRes["ID"], $arFieldsForSocnet); } } else { $arFieldsForSocnet['USER_ID'] = $givenUserId; $arFieldsForSocnet['=LOG_DATE'] = $GLOBALS['DB']->CurrentTimeFunction(); $ufFileID = array(); $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $MID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } if (count($ufFileID) > 0) { $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $MID, LANGUAGE_ID); if ($ufDocID) { $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID; } $ufDocVer = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_VER", $MID, LANGUAGE_ID); if ($ufDocVer) { $arFieldsForSocnet["UF_SONET_COM_VER"] = $ufDocVer; } if (isset($arFieldsAdditional["ANCILLARY"]) && $arFieldsAdditional["ANCILLARY"]) { CSocNetLogComments::Add($arFieldsForSocnet, false, false, false); } else { $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); CSocNetLog::CounterIncrement($comment_id, false, false, "LC"); } } } } $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $arMessage["AUTHOR_ID"] ? $arMessage["AUTHOR_ID"] : 1; } // Tasks log $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arMessage["EDIT_DATE"] ? ConvertTimeStamp(MakeTimeStamp($arMessage["EDIT_DATE"], CSite::GetDateFormat()), "FULL") : $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $MID); $log = new CTaskLog(); $log->Add($arLogFields); } return $MID; // Message id }
public static function AddCrmActivityComment($arFields) { if (!CModule::IncludeModule("forum")) { return false; } $ufFileID = array(); $ufDocID = array(); $messageID = false; $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array('ID', 'ENTITY_ID', 'SOURCE_ID', 'SITE_ID', 'TITLE', 'PARAMS')); if ($arLog = $dbResult->Fetch()) { $dbCrmActivity = CCrmActivity::GetList(array(), array('ID' => $arLog['ENTITY_ID'], 'CHECK_PERMISSIONS' => 'N')); if ($arCrmActivity = $dbCrmActivity->Fetch()) { if ($arCrmActivity['TYPE_ID'] == CCrmActivityType::Task && CModule::IncludeModule('tasks')) { $userID = $GLOBALS["USER"]->GetID(); $dbTask = CTasks::GetByID($arCrmActivity["ASSOCIATED_ENTITY_ID"], false); if ($arTaskFields = $dbTask->Fetch()) { if (!($userName = trim($GLOBALS["USER"]->GetFormattedName(false)))) { $userName = $GLOBALS["USER"]->GetLogin(); } $FORUM_ID = CTasksTools::GetForumIdForIntranet(); if (!$arTaskFields["FORUM_TOPIC_ID"]) { $arTopicFields = array("TITLE" => $arTaskFields["TITLE"], "USER_START_ID" => $arFields["USER_ID"], "STATE" => "Y", "FORUM_ID" => $FORUM_ID, "USER_START_NAME" => $userName, "START_DATE" => ConvertTimeStamp(time(), "FULL"), "POSTS" => 0, "VIEWS" => 0, "APPROVED" => "Y", "LAST_POSTER_NAME" => $userName, "LAST_POST_DATE" => ConvertTimeStamp(time(), "FULL"), "LAST_MESSAGE_ID" => 0, "XML_ID" => 'TASK_' . $arTaskFields['ID']); $TOPIC_ID = CForumTopic::Add($arTopicFields); if ($TOPIC_ID) { $arFieldsFirstMessage = array("POST_MESSAGE" => $arTopicFields["XML_ID"], "AUTHOR_ID" => $arTopicFields["USER_START_ID"], "AUTHOR_NAME" => $arTopicFields["USER_START_NAME"], "FORUM_ID" => $arTopicFields["FORUM_ID"], "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => 'TK', "PARAM2" => $arTaskFields['ID'], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E'); CForumMessage::Add($arFieldsFirstMessage, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")); $oTask = new CTasks(); $oTask->Update($arTaskFields["ID"], array("FORUM_TOPIC_ID" => $TOPIC_ID)); } } else { $TOPIC_ID = $arTaskFields["FORUM_TOPIC_ID"]; } if ($TOPIC_ID) { $arFieldsP = array("AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $userName, "POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y"); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsP["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsP["FILES"][] = array("FILE_ID" => $file_id); } } } $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $arFieldsP); $messageID = CForumMessage::Add($arFieldsP); // get UF DOC value and FILE_ID there if ($messageID > 0) { $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID); } } } } else { return array("NO_SOURCE" => "Y"); } } else { $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } } else { $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } return array("SOURCE_ID" => $messageID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $sError, "NOTES" => $sNote, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID)); }
public static function addCommentLists($fields) { if (!CModule::IncludeModule('forum') || !CModule::IncludeModule('bizproc')) { return false; } $ufFileId = array(); $ufDocId = array(); $fieldsMessage = array(); $messageId = array(); $error = array(); $note = array(); $sonetLogQuery = CSocNetLog::GetList(array(), array('ID' => $fields['LOG_ID']), false, false, array('ID', 'SOURCE_ID', 'SITE_ID', 'MESSAGE', 'USER_ID')); if ($sonetLog = $sonetLogQuery->fetch()) { $users = CBPTaskService::getWorkflowParticipants($sonetLog['MESSAGE'], CBPTaskUserStatus::Waiting); if (preg_match_all("/(?<=\\[USER=)(?P<id>[0-9]+)(?=\\])/", $fields['TEXT_MESSAGE'], $matches)) { $users = array_unique(array_merge($users, $matches['id'])); } $users[] = $sonetLog['USER_ID']; self::setSocnetFollow($users, $sonetLog['ID'], 'Y', false, true); $forumId = CBPHelper::getForumId(); if ($forumId) { $topicQuery = CForumTopic::GetList(array(), array('FORUM_ID' => $forumId, 'XML_ID' => 'WF_' . $sonetLog['MESSAGE'])); if ($topicQuery && ($topic = $topicQuery->fetch())) { $topicId = $topic['ID']; } else { $arTopic = array('AUTHOR_ID' => 0, 'TITLE' => 'WF_' . $sonetLog['MESSAGE'], 'TAGS' => '', 'MESSAGE' => 'WF_' . $sonetLog['MESSAGE'], 'XML_ID' => 'WF_' . $sonetLog['MESSAGE']); $arUserStart = array("ID" => $arTopic["AUTHOR_ID"], "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); $GLOBALS["DB"]->StartTransaction(); $arTopicFields = array("TITLE" => $arTopic["TITLE"], "TAGS" => $arTopic["TAGS"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "XML_ID" => $arTopic["XML_ID"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => 'Q', "PERMISSION" => 'Y'); $topicId = CForumTopic::Add($arTopicFields); if (intval($topicId) > 0) { $arTopic['MESSAGE'] = strip_tags($arTopic['MESSAGE']); $arFields = array("POST_MESSAGE" => $arTopic['MESSAGE'], "AUTHOR_ID" => $arUserStart["ID"], "AUTHOR_NAME" => $arUserStart["NAME"], "FORUM_ID" => $forumId, "TOPIC_ID" => $topicId, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "WF", "PARAM2" => 0, "PERMISSION_EXTERNAL" => 'Q', "PERMISSION" => 'Y'); $startMessageId = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")); if (intVal($startMessageId) <= 0) { CForumTopic::Delete($topicId); $topicId = 0; } } if (intval($topicId) <= 0) { $GLOBALS["DB"]->Rollback(); } else { $GLOBALS["DB"]->Commit(); } } if ($topicId) { $fieldsMessage = array('POST_MESSAGE' => $fields['TEXT_MESSAGE'], 'USE_SMILES' => 'Y', 'PERMISSION_EXTERNAL' => 'Q', 'PERMISSION' => 'Y', 'APPROVED' => 'Y'); $tmp = false; $GLOBALS['USER_FIELD_MANAGER']->editFormAddFields('SONET_COMMENT', $tmp); if (is_array($tmp)) { if (array_key_exists('UF_SONET_COM_DOC', $tmp)) { $GLOBALS['UF_FORUM_MESSAGE_DOC'] = $tmp['UF_SONET_COM_DOC']; } elseif (array_key_exists('UF_SONET_COM_FILE', $tmp)) { $fieldsMessage['FILES'] = array(); foreach ($tmp['UF_SONET_COM_FILE'] as $fileId) { $fieldsMessage['FILES'][] = array('FILE_ID' => $fileId); } } if (array_key_exists("UF_SONET_COM_URL_PRV", $tmp)) { $GLOBALS["UF_FORUM_MES_URL_PRV"] = $tmp["UF_SONET_COM_URL_PRV"]; } } $messageId = ForumAddMessage("REPLY", $forumId, $topicId, 0, $fieldsMessage, $error, $note); if ($messageId > 0) { $addedMessageFilesQuery = CForumFiles::getList(array('ID' => 'ASC'), array('MESSAGE_ID' => $messageId)); while ($addedMessageFiles = $addedMessageFilesQuery->fetch()) { $ufFileId[] = $addedMessageFiles['FILE_ID']; } $ufDocId = $GLOBALS['USER_FIELD_MANAGER']->getUserFieldValue('FORUM_MESSAGE', 'UF_FORUM_MESSAGE_DOC', $messageId, LANGUAGE_ID); $ufUrlPreview = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MES_URL_PRV", $messageID, LANGUAGE_ID); } } } } if (!$messageId) { $error = Loc::getMessage('LISTS_LF_ADD_COMMENT_SOURCE_ERROR'); } return array('SOURCE_ID' => $messageId, 'MESSAGE' => $fieldsMessage ? $fieldsMessage['POST_MESSAGE'] : false, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => $messageId, 'ERROR' => $error, 'NOTES' => $note, 'UF' => array('FILE' => $ufFileId, 'DOC' => $ufDocId, 'URL_PREVIEW' => $ufUrlPreview)); }
if (strlen($_POST["comment_body"]) <= 0) { $strErrorMessage .= GetMessage("TFC_NO_BODY") . ". "; } $sTransStarted = False; if (strlen($strErrorMessage) <= 0) { $strDescription = $_POST["comment_body"] . "\n"; if (strlen($_POST["comment_phone"]) > 0) { $strDescription .= "\n" . GetMessage("COMM_PHONE") . " " . $_POST["comment_phone"]; } if (strlen($_POST["comment_email"]) > 0) { $strDescription .= "\n" . GetMessage("COMM_EMAIL") . " " . $_POST["comment_email"]; } $DB->StartTransaction(); $sTransStarted = True; $arFields = array("TITLE" => TruncateText($strDescription, 40), "FORUM_ID" => $INQUERY_FORUM_ID, "USER_START_NAME" => $_POST["comment_author"], "LAST_POSTER_NAME" => $_POST["comment_author"]); $TID1 = CForumTopic::Add($arFields); if (IntVal($TID1) <= 0) { $strErrorMessage .= GetMessage("ADDMESS_ERROR_ADD_TOPIC") . ". \n"; } } if (strlen($strErrorMessage) <= 0) { $AUTHOR_IP = ForumGetRealIP(); $AUTHOR_IP_tmp = $AUTHOR_IP; $AUTHOR_REAL_IP = $_SERVER['REMOTE_ADDR']; $AUTHOR_IP = @gethostbyaddr($AUTHOR_IP); if ($AUTHOR_IP_tmp == $AUTHOR_REAL_IP) { $AUTHOR_REAL_IP = $AUTHOR_IP; } else { $AUTHOR_REAL_IP = @gethostbyaddr($AUTHOR_REAL_IP); } $arFields = array("POST_MESSAGE" => $strDescription, "AUTHOR_NAME" => $_POST["comment_author"], "AUTHOR_EMAIL" => $_POST["comment_email"], "FORUM_ID" => $INQUERY_FORUM_ID, "TOPIC_ID" => $TID1, "AUTHOR_IP" => $AUTHOR_IP !== False ? $AUTHOR_IP : "<no address>", "AUTHOR_REAL_IP" => $AUTHOR_REAL_IP !== False ? $AUTHOR_REAL_IP : "<no address>", "NEW_TOPIC" => "Y", "GUEST_ID" => $_SESSION["SESS_GUEST_ID"]);
/** * WARNING! This method is transitional and can be changed without * any notifications! Don't use it. * * @deprecated */ public static function __deprecated_Add($commentText, $forumTopicId, $forumId, $nameTemplate, $arTask, $permissions, $commentId, $givenUserId, $imageWidth, $imageHeight, $arSmiles, $arForum, $messagesPerPage, $arUserGroupArray, $backPage, $strMsgAddComment, $strMsgEditComment, $strMsgNewTask, $componentName, &$outForumTopicId, &$arErrorCodes, &$outStrUrl, $arFieldsAdditional) { global $DB; if (is_array($arTask)) { if (!array_key_exists('~TITLE', $arTask)) { $arTmpTask = $arTask; foreach ($arTmpTask as $key => $value) { if (substr($key, 0, 1) !== '~') { $arTask['~' . $key] = $arTmpTask[$key]; } } } } $MID = 0; $TID = 0; if ($forumTopicId > 0 && CForumTopic::GetByID($forumTopicId) === false) { $forumTopicId = false; } if ($forumTopicId <= 0) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim(CUser::FormatName($nameTemplate, $res)) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arFields = array("TITLE" => $arTask["~TITLE"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions, "NAME_TEMPLATE" => $nameTemplate, 'XML_ID' => 'TASK_' . $arTask['ID']); $TID = CForumTopic::Add($arFields); if (intVal($TID) <= 0) { $arErrorCodes[] = array('code' => 'topic is not created'); } else { $arFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arFields); } if (!empty($arErrorCodes)) { $DB->Rollback(); return false; } else { $DB->Commit(); } } $arFieldsG = array("POST_MESSAGE" => $commentText, "AUTHOR_NAME" => '', "AUTHOR_EMAIL" => $GLOBALS['USER']->GetEmail(), "USE_SMILES" => NULL, "PARAM2" => $arTask['ID'], "TITLE" => $arTask["~TITLE"], "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions); // UF_* forwarding if (is_array($arFieldsAdditional)) { foreach ($arFieldsAdditional as $field => $value) { if (strlen($field) && substr($field, 0, 3) == 'UF_') { $arFieldsG[$field] = $value; $GLOBALS[$field] = $value; // strange behaviour required for ForumMessageAdd() to handle UF_* properly } } } if (!empty($_FILES["REVIEW_ATTACH_IMG"])) { $arFieldsG["ATTACH_IMG"] = $_FILES["REVIEW_ATTACH_IMG"]; } else { $arFiles = array(); if (!empty($_REQUEST["FILES"])) { foreach ($_REQUEST["FILES"] as $key) { $arFiles[$key] = array("FILE_ID" => $key); if (!in_array($key, $_REQUEST["FILES_TO_UPLOAD"])) { $arFiles[$key]["del"] = "Y"; } } } if (!empty($_FILES)) { $res = array(); foreach ($_FILES as $key => $val) { if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) { $arFiles[] = $_FILES[$key]; } } } if (!empty($arFiles)) { $arFieldsG["FILES"] = $arFiles; } } $TOPIC_ID = $forumTopicId > 0 ? $forumTopicId : $TID; $MESSAGE_ID = 0; $MESSAGE_TYPE = $TOPIC_ID > 0 ? "REPLY" : "NEW"; if (COption::GetOptionString("tasks", "task_comment_allow_edit") && ($MESSAGE_ID = intval($commentId))) { $MESSAGE_TYPE = "EDIT"; } $strErrorMessage = ''; $strOKMessage = ''; $MID = ForumAddMessage($MESSAGE_TYPE, $forumId, $TOPIC_ID, $MESSAGE_ID, $arFieldsG, $strErrorMessage, $strOKMessage, false, $_POST["captcha_word"], 0, $_POST["captcha_code"], $nameTemplate); if ($MID <= 0 || !empty($strErrorMessage)) { $arErrorCodes[] = array('code' => 'message is not added 2', 'title' => empty($strErrorMessage) ? NULL : $strErrorMessage); } else { $arMessage = CForumMessage::GetByID($MID); if ($forumTopicId <= 0) { $forumTopicId = $TID = intVal($arMessage["TOPIC_ID"]); } $outForumTopicId = intVal($forumTopicId); if ($componentName !== null) { ForumClearComponentCache($componentName); } // NOTIFICATION $arTask["ACCOMPLICES"] = $arTask["AUDITORS"] = array(); $rsMembers = CTaskMembers::GetList(array(), array("TASK_ID" => $arTask["ID"])); while ($arMember = $rsMembers->Fetch()) { if ($arMember["TYPE"] == "A") { $arTask["ACCOMPLICES"][] = $arMember["USER_ID"]; } elseif ($arMember["TYPE"] == "U") { $arTask["AUDITORS"][] = $arMember["USER_ID"]; } } $arEmailUserIDs = array($arTask["RESPONSIBLE_ID"], $arTask["CREATED_BY"]); $arEmailUserIDs = array_unique(array_merge($arEmailUserIDs, $arTask["ACCOMPLICES"], $arTask["AUDITORS"])); $currentUserPos = array_search($givenUserId, $arEmailUserIDs); if ($currentUserPos !== false) { unset($arEmailUserIDs[$currentUserPos]); } $parser = new CTextParser(); $parser->imageWidth = $imageWidth; $parser->imageHeight = $imageHeight; $parser->smiles = $arSmiles; $parser->allow = array("HTML" => $arForum["ALLOW_HTML"], "ANCHOR" => $arForum["ALLOW_ANCHOR"], "BIU" => $arForum["ALLOW_BIU"], "IMG" => "N", "VIDEO" => "N", "LIST" => $arForum["ALLOW_LIST"], "QUOTE" => $arForum["ALLOW_QUOTE"], "CODE" => $arForum["ALLOW_CODE"], "FONT" => $arForum["ALLOW_FONT"], "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => $arForum["ALLOW_NL2BR"], "TABLE" => "Y"); $arAllow = NULL; $MESSAGE = HTMLToTxt($parser->convertText($commentText, $arAllow)); // remove [ url] for socialnetwork log $MESSAGE = preg_replace("/(\\s\\[\\s(http:\\/\\/|https:\\/\\/|ftp:\\/\\/))(.*?)(\\s\\])/is", "", $MESSAGE); $parser->allow = array("HTML" => 'Y', "ANCHOR" => 'Y', "BIU" => 'Y', "IMG" => "Y", "VIDEO" => "Y", "LIST" => 'N', "QUOTE" => 'Y', "CODE" => 'Y', "FONT" => 'Y', "SMILES" => "N", "UPLOAD" => 'N', "NL2BR" => 'N', "TABLE" => "Y"); $message_notify = $parser->convertText($commentText); $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); // Instant Messages if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { $pageNumber = CForumMessage::GetMessagePage($MID, $messagesPerPage, $arUserGroupArray); // There are different links for extranet users $isExtranetEnabled = false; if (CModule::IncludeModule("extranet")) { $isExtranetEnabled = true; } if ($isExtranetEnabled) { $arSites = array(); $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { if (strlen(trim($arSite["DIR"])) > 0) { $arSites[$arSite['ID']]['DIR'] = $arSite['DIR']; } else { $arSites[$arSite['ID']]['DIR'] = '/'; } if (strlen(trim($arSite["SERVER_NAME"])) > 0) { $arSites[$arSite['ID']]['SERVER_NAME'] = $arSite["SERVER_NAME"]; } else { $arSites[$arSite['ID']]['SERVER_NAME'] = COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"]); } $arSites[$arSite['ID']]['urlPrefix'] = $arSites[$arSite['ID']]['SERVER_NAME'] . $arSites[$arSite['ID']]['DIR']; // remove last '/' if (strlen($arSites[$arSite['ID']]['urlPrefix']) > 0 && substr($arSites[$arSite['ID']]['urlPrefix'], -1) === '/') { $arSites[$arSite['ID']]['urlPrefix'] = substr($arSites[$arSite['ID']]['urlPrefix'], 0, -1); } } $extranet_site_id = CExtranet::GetExtranetSiteID(); $intranet_site_id = CSite::GetDefSite(); $arIntranetUsers = CExtranet::GetIntranetUsers(); } else { if ($arTask["GROUP_ID"]) { $pathTemplateWoExtranet = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"])); } else { $pathTemplateWoExtranet = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"]); } } foreach ($arRecipientsIDs as $userID) { $urlPrefixForUser = tasksServerName(); if ($isExtranetEnabled) { if (!in_array($userID, $arIntranetUsers) && $extranet_site_id) { $userSiteId = $extranet_site_id; } else { $userSiteId = $intranet_site_id; } if (isset($arSites[$userSiteId]['SERVER_NAME'])) { $urlPrefixForUser = tasksServerName($arSites[$userSiteId]['SERVER_NAME']); } if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace('#group_id#', $arTask['GROUP_ID'], CTasksTools::GetOptionPathTaskGroupEntry($userSiteId, '')); } else { $pathTemplate = CTasksTools::GetOptionPathTaskUserEntry($userSiteId, ''); } } else { $pathTemplate = $pathTemplateWoExtranet; } $NOTIFY_MESSAGE_TITLE_TEMPLATE = ''; $messageUrl = ''; if (strlen($pathTemplate) > 0) { $groupId = 0; if (isset($arTask['GROUP_ID'])) { $groupId = (int) $arTask['GROUP_ID']; } $messageUrl = $urlPrefixForUser . CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $userID, "task_id" => $arTask["ID"], "action" => "view", "USER_ID" => $userID, "TASK_ID" => $arTask["ID"], "ACTION" => "view", 'GROUP_ID' => $groupId, 'group_id' => $groupId)); if ($pageNumber > 1) { $messageUrl .= (strpos($messageUrl, "?") === false ? "?" : "&") . "MID=" . $MID; } $NOTIFY_MESSAGE_TITLE_TEMPLATE = '[URL=' . $messageUrl . "#message" . $MID . ']' . $arTask["~TITLE"] . '[/URL]'; } else { $NOTIFY_MESSAGE_TITLE_TEMPLATE = $arTask["~TITLE"]; } $MESSAGE_SITE = trim(htmlspecialcharsbx(strip_tags(str_replace(array("\r\n", "\n", "\r"), ' ', htmlspecialcharsback($message_notify))))); $MESSAGE_EMAIL = $MESSAGE_SITE; // full message to email if (strlen($MESSAGE_SITE) >= 100) { $dot = '...'; $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99); if (($lastLinkPosition = strrpos($MESSAGE_SITE, 'http://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'https://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftp://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftps://')) !== false) { if (strpos($MESSAGE_SITE, ' ', $lastLinkPosition) === false) { $MESSAGE_SITE = substr($MESSAGE_SITE, 0, $lastLinkPosition); } } $MESSAGE_SITE .= $dot; } $arMessageFields = array("TO_USER_ID" => $userID, "FROM_USER_ID" => $givenUserId, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($NOTIFY_MESSAGE_TITLE_TEMPLATE, '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($arTask["~TITLE"], $MESSAGE_EMAIL . ' #BR# ' . $messageUrl . "#message" . $MID . ' '), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment)); CIMNotify::Add($arMessageFields); } } $strURL = !empty($backPage) ? $backPage : $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result")); $strURL = ForumAddPageParams($strURL, array("MID" => $MID, "result" => $arForum["MODERATION"] != "Y" || CForumNew::CanUserModerateForum($forumId, $arUserGroupArray) ? "reply" : "not_approved"), false, false); $outStrUrl = $strURL; // sonet log if (CModule::IncludeModule("socialnetwork")) { $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID")); if ($arRes = $dbRes->Fetch()) { $log_id = $arRes["TMP_ID"]; $entity_type = $arRes["ENTITY_TYPE"]; $entity_id = $arRes["ENTITY_ID"]; } else { $entity_type = $arTask["GROUP_ID"] ? SONET_ENTITY_GROUP : SONET_ENTITY_USER; $entity_id = $arTask["GROUP_ID"] ? $arTask["GROUP_ID"] : $arTask["CREATED_BY"]; $rsUser = CUser::GetByID($arTask["CREATED_BY"]); if ($arUser = $rsUser->Fetch()) { $arSoFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks", "LOG_DATE" => $arTask["CREATED_DATE"], "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => htmlspecialcharsBack($arTask["~TITLE"]), "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $arTask["ID"], "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]), "PARAMS" => serialize(array("TYPE" => "create"))); $log_id = CSocNetLog::Add($arSoFields, false); if (intval($log_id) > 0) { CSocNetLog::Update($log_id, array("TMP_ID" => $log_id)); $arRights = CTaskNotifications::__UserIDs2Rights(CTaskNotifications::GetRecipientsIDs($arTask, false)); if ($arTask["GROUP_ID"]) { $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"]; } CSocNetLogRights::Add($log_id, $arRights); } } } if (intval($log_id) > 0) { $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]; CSocNetLog::Update($log_id, array('PARAMS' => serialize(array('TYPE' => 'comment')))); $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "tasks", "SOURCE_ID" => $MID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $MID); if ($MESSAGE_TYPE == "EDIT") { $dbRes = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => array("tasks_comment"), "SOURCE_ID" => $MID), false, false, array("ID")); while ($arRes = $dbRes->Fetch()) { CSocNetLogComments::Update($arRes["ID"], $arFieldsForSocnet); } } else { $arFieldsForSocnet['USER_ID'] = $givenUserId; $arFieldsForSocnet['=LOG_DATE'] = $GLOBALS['DB']->CurrentTimeFunction(); $ufFileID = array(); $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $MID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } if (count($ufFileID) > 0) { $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $MID, LANGUAGE_ID); if ($ufDocID) { $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID; } $ufDocVer = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_VER", $MID, LANGUAGE_ID); if ($ufDocVer) { $arFieldsForSocnet["UF_SONET_COM_VER"] = $ufDocVer; } $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false); CSocNetLog::CounterIncrement($comment_id, false, false, "LC"); } } } $occurAsUserId = CTasksTools::getOccurAsUserId(); if (!$occurAsUserId) { $occurAsUserId = $arMessage["AUTHOR_ID"] ? $arMessage["AUTHOR_ID"] : 1; } // Tasks log $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arMessage["EDIT_DATE"] ? ConvertTimeStamp(MakeTimeStamp($arMessage["EDIT_DATE"], CSite::GetDateFormat()), "FULL") : $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $MID); $log = new CTaskLog(); $log->Add($arLogFields); } return $MID; // Message id }
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; }
} } // Forum № 3 if (in_array(GetMessage("F_FORUM_3_NAME"), $arForums)) { foreach ($arForums as $key => $val) { if ($val == GetMessage("F_FORUM_3_NAME")) { $arReplaceForums[] = $key; } } } else { $arFields = array("NAME" => GetMessage("F_FORUM_3_NAME"), "DESCRIPTION" => GetMessage("F_FORUM_3_DECRIPTION"), "SORT" => 200, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "N", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroup["PARTNER"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "Y", "SITES" => array($SITE_ID => "/communication/forum/messages/forum#FID#/message#MID#/#TITLE_SEO#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "M", "4" => "A", "5" => "A", "11" => "A", "15" => "A", "16" => "A", "17" => "A", "18" => "A", "19" => "Q", "20" => "A")); $FID = CForumNew::Add($arFields); if ($FID > 0) { $arReplaceForums[] = $FID; $arFields = array("FORUM_ID" => $FID, "TITLE" => GetMessage("F_FORUM_3_TOPIC_1_TITLE"), "DESCRIPTION" => GetMessage("F_FORUM_3_TOPIC_1_DESCRIPTION"), "ICON_ID" => 0, "TAGS" => GetMessage("F_FORUM_3_TOPIC_1_TAGS"), "USER_START_ID" => 1, "USER_START_NAME" => GetMessage("F_FORUM_3_TOPIC_1_AUTHOR"), "LAST_POSTER_NAME" => GetMessage("F_FORUM_3_TOPIC_1_AUTHOR"), "APPROVED" => "Y"); $TID = intVal(CForumTopic::Add($arFields)); if ($TID > 0) { $arFields = array("POST_MESSAGE" => GetMessage("F_FORUM_3_TOPIC_1_MESSAGE_1_POSTMESS"), "USE_SMILES" => "Y", "APPROVED" => "Y", "AUTHOR_NAME" => GetMessage("F_FORUM_3_TOPIC_1_AUTHOR"), "AUTHOR_EMAIL" => "", "AUTHOR_ID" => "1", "FORUM_ID" => $FID, "TOPIC_ID" => $TID, "AUTHOR_IP" => "SWAMP", "AUTHOR_REAL_IP" => "SWAMP", "NEW_TOPIC" => "Y", "GUEST_ID" => 58); $MID = CForumMessage::Add($arFields, false); if (IntVal($MID) <= 0) { CForumTopic::Delete($TID); } } } } //Copy public files with "on the fly" translation $source = "/public/forum/"; $target = "/communication/forum/"; $source_base = dirname(__FILE__); $source_abs = $source_base . $source; $source_abs = str_replace(array("\\", "//"), "/", $source_base . $source . "/");
public static function AddCommentMessage($arFields, $FORUM_ID, $arLog) { global $USER, $DB; $dbRes = CTimeManEntry::GetList(array(), array('ID' => $arLog['SOURCE_ID'])); $arEntry = $dbRes->Fetch(); if ($arEntry && CModule::IncludeModule("forum")) { $ufFileID = array(); $ufDocID = array(); if (!($userName = trim($USER->GetFormattedName(false)))) { $userName = $USER->GetLogin(); } if ($arEntry["FORUM_TOPIC_ID"] <= 0) { $t = ConvertTimeStamp(time(), "FULL"); $arTopicFields = array("TITLE" => $arEntry["DATE_START"], "USER_START_ID" => $arFields["USER_ID"], "STATE" => "Y", "FORUM_ID" => $FORUM_ID, "USER_START_NAME" => $userName, "START_DATE" => $t, "POSTS" => 0, "VIEWS" => 0, "APPROVED" => "Y", "LAST_POSTER_NAME" => $userName, "LAST_POST_DATE" => $t, "LAST_MESSAGE_ID" => 0, "XML_ID" => "TIMEMAN_ENTRY_" . $arLog["SOURCE_ID"]); $TOPIC_ID = CForumTopic::Add($arTopicFields); if ($TOPIC_ID > 0) { CTimeManEntry::Update($arLog['SOURCE_ID'], array("FORUM_TOPIC_ID" => $TOPIC_ID)); } } else { $TOPIC_ID = $arEntry["FORUM_TOPIC_ID"]; } if ($TOPIC_ID) { $arFieldsP = array("AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $userName, "POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "POST_DATE" => date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL")), time() - 1), "FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "PARAM2" => $arLog["SOURCE_ID"]); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsP["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsP["FILES"][] = array("FILE_ID" => $file_id); } } } $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $arFieldsP); $mess_id = CForumMessage::Add($arFieldsP); // get UF DOC value and FILE_ID there if ($mess_id > 0) { $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $mess_id)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $mess_id, LANGUAGE_ID); } if (IsModuleInstalled("im")) { CTimeManNotify::AddCommentToIM(array("USER_ID" => $arFieldsP["AUTHOR_ID"], "ENTRY_ID" => $arEntry["ID"], "LOG_ID" => $arLog["ID"], "MESSAGE" => $arFields["TEXT_MESSAGE"])); } } return array("SOURCE_ID" => $mess_id, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID)); } return false; }
function AddComment_Tasks($arFields) { global $DB; if (!CModule::IncludeModule("forum")) { return false; } if (!CModule::IncludeModule("tasks")) { return false; } $ufFileID = array(); $ufDocID = array(); $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "SOURCE_ID", "SITE_ID")); if ($arLog = $dbResult->Fetch()) { $rsTask = CTasks::GetById($arLog["SOURCE_ID"]); if ($arTask = $rsTask->Fetch()) { // read shared cross-site FORUM_ID $forumID = COption::GetOptionString("tasks", "task_forum_id", 0, $siteId = ''); if ($forumID) { if (!$arTask["FORUM_TOPIC_ID"]) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim($res["NAME"] . " " . $res["LAST_NAME"]) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arTopicFields = array("TITLE" => $arTask["TITLE"], "FORUM_ID" => $forumID, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E', "APPROVED" => "Y", 'XML_ID' => 'TASK_' . $arTask['ID']); $TID = CForumTopic::Add($arTopicFields); if (intVal($TID) > 0) { $arFieldsFirstMessage = array("POST_MESSAGE" => $arTopicFields['XML_ID'], "AUTHOR_ID" => $arTopicFields["USER_START_ID"], "AUTHOR_NAME" => $arTopicFields["USER_START_NAME"], "FORUM_ID" => $arTopicFields["FORUM_ID"], "TOPIC_ID" => $TID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => 'TK', "PARAM2" => $arTask['ID'], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E'); CForumMessage::Add($arFieldsFirstMessage, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")); $arTask["FORUM_TOPIC_ID"] = $TID; $arTaskFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arTaskFields); } if (!$arTask["FORUM_TOPIC_ID"]) { $DB->Rollback(); } else { $DB->Commit(); } } else { // override forumId by fact forum, attached to the task if ($arTopic = CForumTopic::getByID($arTask['FORUM_TOPIC_ID'])) { $forumID = $arTopic['FORUM_ID']; } } if ($forumID && $arTask["FORUM_TOPIC_ID"]) { $userID = $GLOBALS["USER"]->GetID(); $arLogSites = array(); $rsLogSite = CSocNetLog::GetSite($arLog["ID"]); while ($arLogSite = $rsLogSite->Fetch()) { $arLogSites[] = $arLogSite["LID"]; } $bCurrentUserIsAdmin = CSocNetUser::IsCurrentUserModuleAdmin($arLogSites); if ($arFields["ENTITY_TYPE"] == SONET_ENTITY_GROUP) { if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) { $strPermission = "I"; } } else { if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) { $strPermission = "I"; } } $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PERMISSION_EXTERNAL" => "Q", "PERMISSION" => $strPermission, "APPROVED" => "Y"); $MESSAGE_TYPE = 'REPLY'; $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsMessage["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id); } } } $messageID = ForumAddMessage($MESSAGE_TYPE, $forumID, $arTask["FORUM_TOPIC_ID"], 0, $arFieldsMessage, $sError, $sNote); // get UF DOC value and FILE_ID there if ($messageID > 0) { $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID); } if ($messageID && ($arMessage = CForumMessage::GetByID($messageID))) { $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $userID, "CREATED_DATE" => $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $messageID); $log = new CTaskLog(); $log->Add($arLogFields); // notification to IM $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); $arUnFollowers = array(); $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arRecipientsIDs, "CODE" => "L" . $arFields["LOG_ID"], "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arUnFollowers[] = $arUnFollower["USER_ID"]; } $arRecipientsIDs = array_diff($arRecipientsIDs, $arUnFollowers); if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { $extranetSiteId = false; if (CModule::IncludeModule('extranet') && method_exists('CExtranet', 'GetExtranetSiteID')) { $extranetSiteId = CExtranet::GetExtranetSiteID(); } foreach ($arRecipientsIDs as $recipientUserID) { $arFilter = array("UF_DEPARTMENT" => false, "ID" => $recipientUserID); $rsUser = CUser::GetList($by = "last_name", $order = "asc", $arFilter, array("SELECT" => array("UF_DEPARTMENT"))); $isExtranetUser = false; if ($arUser = $rsUser->Fetch()) { $isExtranetUser = true; } if ($isExtranetUser && $extranetSiteId !== false) { if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/extranet/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $extranetSiteId)); $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate); } else { $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/extranet/contacts/personal/user/#user_id#/tasks/task/view/#task_id#/", $extranetSiteId); } } else { if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"])); $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate); } else { $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"]); } } $messageUrl = CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $recipientUserID, "task_id" => $arTask["ID"], "action" => "view")); if (strpos($messageUrl, "?") === false) { $messageUrl .= "?"; } else { $messageUrl .= "&"; } $messageUrl .= "MID=" . $messageID; $MESSAGE_SITE = preg_replace(array('|\\[\\/USER\\]|', '|\\[USER=\\d+\\]|', '|\\[DISK\\sFILE\\sID=[n]*\\d+\\]|', '|\\[DOCUMENT\\sID=\\d+\\]|'), '', $arFields['TEXT_MESSAGE']); if (strlen($MESSAGE_SITE) >= 100) { $dot = '...'; $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99); if (substr($MESSAGE_SITE, -1) === '[') { $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 98); } if (($lastLinkPosition = strrpos($MESSAGE_SITE, '[u')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'http://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'https://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftp://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftps://')) !== false) { if (strpos($MESSAGE_SITE, ' ', $lastLinkPosition) === false) { $MESSAGE_SITE = substr($MESSAGE_SITE, 0, $lastLinkPosition); } } $MESSAGE_SITE .= $dot; } $rsUser = CUser::GetList($by = 'id', $order = 'asc', array('ID_EQUAL_EXACT' => (int) $userID), array('FIELDS' => array('PERSONAL_GENDER'))); $strMsgAddComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD"); $strMsgEditComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT"); if ($arUser = $rsUser->fetch()) { switch ($arUser['PERSONAL_GENDER']) { case "F": case "M": $strMsgAddComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD" . '_' . $arUser['PERSONAL_GENDER']); $strMsgEditComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT" . '_' . $arUser['PERSONAL_GENDER']); break; default: break; } } $arMessageFields = array("TO_USER_ID" => $recipientUserID, "FROM_USER_ID" => $userID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array('[URL=' . tasksServerName() . $messageUrl . "#message" . $messageID . ']' . htmlspecialcharsbx($arTask["TITLE"]) . '[/URL]', '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array(htmlspecialcharsbx($arTask["TITLE"]), $MESSAGE_SITE . ' #BR# ' . tasksServerName() . $messageUrl . "#message" . $messageID . ' '), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment) . "#BR##BR#" . $arFields["TEXT_MESSAGE"], "NOTIFY_TAG" => "TASKS|COMMENT|" . intval($arTask["ID"]) . "|" . intval($recipientUserID)); CIMNotify::Add($arMessageFields); } } CSocNetLog::Update($arFields["LOG_ID"], array('PARAMS' => serialize(array('TYPE' => 'comment')))); $arFilesIds = array_merge($ufFileID, is_array($ufDocID) ? $ufDocID : array()); CTaskComments::fireOnAfterCommentAddEvent($messageID, $arTask['ID'], $arFields["TEXT_MESSAGE"], $arFilesIds); } } } } } if (!$messageID) { $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } return array("SOURCE_ID" => $messageID, "MESSAGE" => $arFieldsMessage ? $arFieldsMessage["POST_MESSAGE"] : false, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $sError, "NOTES" => $sNote, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID), "URL" => $messageUrl); }
function ForumMoveMessage($FID, $TID, $Message, $NewTID = 0, $arFields, &$strErrorMessage, &$strOKMessage, $iFileSize = false) { global $USER, $DB; $arError = array(); $arOK = array(); $NewFID = 0; $arForum = array(); $arTopic = array(); $arNewForum = array(); $arNewTopic = array(); $arCurrUser = array(); $SendSubscribe = false; //************************* Input params ************************************************************************** $TID = IntVal($TID); $FID = IntVal($FID); $NewTID = IntVal($NewTID); $Message = ForumDataToArray($Message); if (empty($Message)) { $arError[] = GetMessage("FMM_NO_MESSAGE"); } if ($TID <= 0) { $arError[] = GetMessage("FMM_NO_TOPIC_SOURCE0"); } else { $arTopic = CForumTopic::GetByID($TID); if ($arTopic) { $FID = IntVal($arTopic["FORUM_ID"]); $arForum = CForumNew::GetByID($FID); } else { $arError[] = GetMessage("FMM_NO_TOPIC_SOURCE1"); } } if ($NewTID <= 0 && strLen(trim($arFields["TITLE"])) <= 0) { $arError[] = GetMessage("FMM_NO_TOPIC_RECIPIENT0"); } elseif ($NewTID > 0) { if ($NewTID == $TID) { $arError[] = GetMessage("FMM_NO_TOPIC_EQUAL"); } $arNewTopic = CForumTopic::GetByID($NewTID); if (!$arNewTopic) { $arError[] = GetMessage("FMM_NO_TOPIC_RECIPIENT1"); } elseif ($arNewTopic["STATE"] == "L") { $arError[] = GetMessage("FMM_TOPIC_IS_LINK"); } else { $NewFID = $arNewTopic["FORUM_ID"]; $arNewForum = CForumNew::GetByID($NewFID); } } //*************************/Input params ************************************************************************** //*************************!Proverka prav pol'zovatelya na forume-istochnike i forume-poluchatele********************* // Tak kak realizovan mehanizm peremeweniya tem s forumov, gde tekuwij pol'zovatel' yavlyaetsya moderatorom na forumy, // gde on moderatorov ne yavlyaetsya, to v dannom sluchae budet ispol'zovan tot zhe samyj shablon dejstvij. Isklyucheniem // yavlyaetsya to, chto esli pol'zovatel' na forume-poluchatele ne obladaet pravami moderirovaniya, tema budet neaktivna. //*************************!Proverka prav pol'zovatelya************************************************************* $arCurrUser["Perms"]["FID"] = ForumCurrUserPermissions($FID); $arCurrUser["Perms"]["NewFID"] = ForumCurrUserPermissions($NewFID); if ($arCurrUser["Perms"]["FID"] < "Q") { $arError[] = GetMessage("FMM_NO_MODERATE"); } //************************* Actions ******************************************************************************* $DB->StartTransaction(); if (count($arError) <= 0) { // Create topic if ($NewTID <= 0) { $arFields["APPROVED"] = $arNewForum["MODERATION"] == "Y" ? "N" : "Y"; if ($arCurrUser["Perms"]["NewFID"] >= "Q") { $arFields["APPROVED"] = "Y"; } $arRes = array("NAME" => GetMessage("FR_GUEST")); $ShowName = GetMessage("FR_GUEST"); $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("@ID" => implode(",", $Message), "TOPIC_ID" => $TID)); if ($db_res && ($res = $db_res->Fetch())) { $arRes["NAME"] = $res["AUTHOR_NAME"]; $arRes["ID"] = $res["AUTHOR_ID"]; } $arFieldsTopic = array("TITLE" => $arFields["TITLE"], "TITLE_SEO" => $arFields["TITLE_SEO"], "DESCRIPTION" => $arFields["DESCRIPTION"], "ICON" => $arFields["ICON"], "TAGS" => $arFields["TAGS"], "FORUM_ID" => $FID, "USER_START_ID" => $arRes["ID"], "USER_START_NAME" => $arRes["NAME"], "LAST_POSTER_NAME" => $arRes["NAME"], "LAST_POSTER_ID" => $arRes["ID"], "APPROVED" => $arFields["APPROVED"]); $NewTID = CForumTopic::Add($arFieldsTopic); if (IntVal($NewTID) <= 0) { $arError[] = GetMessage("FMM_NO_TOPIC_NOT_CREATED"); } else { $arNewTopic = CForumTopic::GetByID($NewTID); if ($arNewTopic) { $NewFID = $FID; $arNewForum = $arForum; $SendSubscribe = true; } else { $arError[] = GetMessage("FMM_NO_TOPIC_NOT_CREATED"); } } } } if (count($arError) <= 0) { // Move message $db_res = CForumMessage::GetList(array(), array("@ID" => implode(",", $Message), "TOPIC_ID" => $TID)); if ($db_res && ($res = $db_res->Fetch())) { do { // echo "NewFID: ".$NewFID." -- FID:".$FID."<br/>"; $arMessage = array(); if ($NewFID != $FID) { $arMessage["APPROVED"] = $arNewForum["MODERATION"] == "Y" ? "N" : "Y"; if ($arCurrUser["Perms"]["NewFID"] >= "Q") { $arMessage["APPROVED"] = "Y"; } $arMessage["FORUM_ID"] = $NewFID; $arMessage["POST_MESSAGE_HTML"] = ""; } if ($NewTID != $TID) { $arMessage["NEW_TOPIC"] = "N"; $arMessage["TOPIC_ID"] = $NewTID; } if (count($arMessage) > 0) { $MID = CForumMessage::Update($res["ID"], $arMessage, true); $res_log = $SendSubscribe == true ? GetMessage("F_MESSAGE_WAS_MOVED_TO_NEW") : GetMessage("F_MESSAGE_WAS_MOVED"); $res_log = str_replace(array("#ID#", "#TOPIC_TITLE#", "#TOPIC_ID#", "#NEW_TOPIC_TITLE#", "#NEW_TOPIC_ID#"), array($MID, $arTopic["TITLE"], $arTopic["ID"], $arNewTopic['TITLE'], $arNewTopic['ID']), $res_log); $res["TITLE"] = $arNewTopic['TITLE']; $res["TOPIC_ID"] = $arNewTopic['ID']; $res["beforeTITLE"] = $arTopic["TITLE"]; $res["DESCRIPTION"] = $res_log; CForumEventLog::Log("message", "move", $MID, serialize($res)); $db_res2 = CForumFiles::GetList(array(), array("FILE_MESSAGE_ID" => $res["ID"])); if ($db_res2 && ($res2 = $db_res2->Fetch())) { $arFiles = array(); do { $arFiles[] = $res2["FILE_ID"]; } while ($res2 = $db_res2->Fetch()); CForumFiles::UpdateByID($arFiles, $arMessage); } if (IntVal($MID) <= 0) { $arError[] = str_replace("##", $res["ID"], GetMessage("FMM_NO_MESSAGE_MOVE")); break; } } } while ($res = $db_res->Fetch()); } } if (count($arError) <= 0) { $db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $TID), false, 1); if (!($db_res && ($res = $db_res->Fetch()))) { CForumTopic::Delete($TID); } else { CForumTopic::SetStat($TID); } $db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $NewTID), false, 1); if (!($db_res && ($res = $db_res->Fetch()))) { CForumTopic::Delete($NewTID); } else { CForumTopic::SetStat($NewTID); } CForumNew::SetStat($FID); if ($NewFID != $FID) { CForumNew::SetStat($NewFID); } } if (count($arError) <= 0) { $DB->Commit(); } else { $DB->Rollback(); } if (count($arError) > 0) { $strErrorMessage .= implode(". \n", $arError) . ". \n"; } else { $strOKMessage .= GetMessage("FMM_YES_MESSAGE_MOVE"); if ($SendSubscribe) { foreach ($Message as $MID) { CForumMessage::SendMailMessage($MID, array(), false, "NEW_FORUM_MESSAGE"); } } return true; } return false; }
function AddForumLog($taskId, $taskName, $arFields, &$arError) { $arError = array(); $iblockId = COption::GetOptionInt("intranet", "iblock_tasks", 0); if ($iblockId <= 0) { return; } $taskId = intval($taskId); if ($taskId <= 0) { return; } $db = CIBlockElement::GetProperty($iblockId, $taskId, "", "", array("CODE" => "FORUM_TOPIC_ID")); $ar = $db->Fetch(); $forumTopicId = intval($ar["VALUE"]); if ($forumTopicId <= 0) { $arFields = array("TITLE" => $taskName, "FORUM_ID" => $arFields["FORUM_ID"], "USER_START_ID" => $arFields["USER_ID"], "USER_START_NAME" => $arFields["USER_NAME"], "LAST_POSTER_NAME" => $arFields["USER_NAME"], "APPROVED" => "Y"); $forumTopicId = CForumTopic::Add($arFields); CIBlockElement::SetPropertyValues($taskId, $iblockId, $forumTopicId, "FORUM_TOPIC_ID"); } $arFields = array("POST_MESSAGE" => $arFields["POST_MESSAGE"], "AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $arFields["USER_NAME"], "FORUM_ID" => $arFields["FORUM_ID"], "TOPIC_ID" => $forumTopicId, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "IB", "PARAM2" => $taskId); CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")); }
function AddComment_Tasks($arFields) { global $DB; if (!CModule::IncludeModule("forum")) { return false; } if (!CModule::IncludeModule("tasks")) { return false; } $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "SOURCE_ID", "SITE_ID")); if ($arLog = $dbResult->Fetch()) { $rsTask = CTasks::GetById($arLog["SOURCE_ID"]); if ($arTask = $rsTask->Fetch()) { $forumID = COption::GetOptionString("tasks", "task_forum_id"); if ($forumID) { if (!$arTask["FORUM_TOPIC_ID"]) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim($res["NAME"] . " " . $res["LAST_NAME"]) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arTopicFields = array("TITLE" => $arTask["TITLE"], "FORUM_ID" => $forumID, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y"); $TID = CForumTopic::Add($arTopicFields); if (intVal($TID) > 0) { $arTask["FORUM_TOPIC_ID"] = $TID; $arTaskFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arTaskFields); } if (!$arTask["FORUM_TOPIC_ID"]) { $DB->Rollback(); } else { $DB->Commit(); } } if ($arTask["FORUM_TOPIC_ID"]) { $userID = $GLOBALS["USER"]->GetID(); $arLogSites = array(); $rsLogSite = CSocNetLog::GetSite($arLog["ID"]); while ($arLogSite = $rsLogSite->Fetch()) { $arLogSites[] = $arLogSite["LID"]; } $bCurrentUserIsAdmin = CSocNetUser::IsCurrentUserModuleAdmin($arLogSites); if ($arFields["ENTITY_TYPE"] == SONET_ENTITY_GROUP) { if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) { $strPermission = "I"; } } else { if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) { $strPermission = "I"; } } $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PERMISSION_EXTERNAL" => $strPermission, "PERMISSION" => $strPermission); $MESSAGE_TYPE = 'REPLY'; $messageID = ForumAddMessage($MESSAGE_TYPE, $forumID, $arTask["FORUM_TOPIC_ID"], 0, $arFieldsMessage, $sError, $sNote); if ($messageID && ($arMessage = CForumMessage::GetByID($messageID))) { $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $userID, "CREATED_DATE" => $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $messageID); $log = new CTaskLog(); $log->Add($arLogFields); // notification to IM $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { $extranetSiteId = false; if (CModule::IncludeModule('extranet') && method_exists('CExtranet', 'GetExtranetSiteID')) { $extranetSiteId = CExtranet::GetExtranetSiteID(); } foreach ($arRecipientsIDs as $recipientUserID) { $arFilter = array('UF_DEPARTMENT' => false, 'ID' => $recipientUserID); $rsUser = CUser::GetList($by = 'last_name', $order = 'asc', $arFilter, array('SELECT' => array('UF_DEPARTMENT'))); $isExtranetUser = false; if ($arUser = $rsUser->Fetch()) { $isExtranetUser = true; } if ($isExtranetUser && $extranetSiteId !== false) { if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/extranet/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $extranetSiteId)); $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate); } else { $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/extranet/contacts/personal/user/#user_id#/tasks/task/view/#task_id#/", $extranetSiteId); } } else { if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"])); $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate); } else { $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"]); } } $messageUrl = tasksServerName() . CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $recipientUserID, "task_id" => $arTask["ID"], "action" => "view")); if (strpos($messageUrl, "?") === false) { $messageUrl .= "?"; } else { $messageUrl .= "&"; } $messageUrl .= "MID=" . $messageID; $MESSAGE_SITE = trim(htmlspecialcharsbx(strip_tags(str_replace(array("\r\n", "\n", "\r"), ' ', htmlspecialcharsback($arFields['TEXT_MESSAGE']))))); $dot = strlen($MESSAGE_SITE) >= 100 ? '...' : ''; $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99) . $dot; $arMessageFields = array("TO_USER_ID" => $recipientUserID, "FROM_USER_ID" => $userID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array('[URL=' . $messageUrl . "#message" . $messageID . ']' . htmlspecialcharsbx($arTask["TITLE"]) . '[/URL]', '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD") : GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT")), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array(htmlspecialcharsbx($arTask["TITLE"]), $MESSAGE_SITE . ' #BR# ' . $messageUrl . "#message" . $messageID . ' '), $MESSAGE_TYPE != "EDIT" ? GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD") : GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT"))); CIMNotify::Add($arMessageFields); } } } } } } } if (!$messageID) { $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } return array("SOURCE_ID" => $messageID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $sError, "NOTES" => $sNote); }