示例#1
0
 public function delete()
 {
     global $DB;
     $taskId = (int) $this->oTaskItem->getId();
     $executiveUserId = (int) $this->oTaskItem->getExecutiveUserId();
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $curDatetime = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time() + CTimeZone::GetOffset());
     if (!$this->isActionAllowed(self::ACTION_REMOVE)) {
         throw new TasksException('', TasksException::TE_ACTION_NOT_ALLOWED);
     }
     $arCurrentData = $this->getData();
     $rc = $DB->Query("DELETE FROM b_tasks_checklist_items \n\t\t\tWHERE ID = " . $this->itemId . " AND TASK_ID = " . $taskId, $bIgnoreErrors = true);
     // Reset cache
     $this->resetCache();
     if ($rc === false) {
         throw new TasksException('', TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED);
     }
     $occurAsUserId = CTasksTools::getOccurAsUserId();
     if (!$occurAsUserId) {
         $occurAsUserId = $executiveUserId;
     }
     // changes log
     $arLogFields = array('TASK_ID' => $taskId, 'USER_ID' => $occurAsUserId, 'CREATED_DATE' => $curDatetime, 'FIELD' => 'CHECKLIST_ITEM_REMOVE', 'FROM_VALUE' => $arCurrentData['~TITLE'], 'TO_VALUE' => '');
     $log = new CTaskLog();
     $log->Add($arLogFields);
 }
示例#2
0
 public static function SyncModifyTaskItem($arModifyEventArray)
 {
     global $DB;
     $ID = $arModifyEventArray["ID"];
     $arFields = array("RESPONSIBLE_ID" => $arModifyEventArray["USER_ID"], "SITE_ID" => SITE_ID, "EXCHANGE_ID" => $arModifyEventArray["XML_ID"], "EXCHANGE_MODIFIED" => $arModifyEventArray["MODIFICATION_LABEL"], "TITLE" => $arModifyEventArray["SUBJECT"], "DESCRIPTION" => $arModifyEventArray["BODY"], "CREATED_DATE" => $arModifyEventArray["DATE_CREATE"], "PRIORITY" => self::$PriorityMapping[strtolower($arModifyEventArray["IMPORTANCE"])], "DURATION_FACT" => ceil($arModifyEventArray["ACTUAL_WORK"] / 60), "START_DATE_PLAN" => $arModifyEventArray["START_DATE"], "DEADLINE" => $arModifyEventArray["DUE_DATE"], "STATUS" => self::$StatusMapping[strtolower($arModifyEventArray["STATUS"])], "DURATION_PLAN" => ceil($arModifyEventArray["TOTAL_WORK"] / 60), "DURATION_TYPE" => "hours");
     $arExtraFields = array();
     if (isset($arModifyEventArray['ExtendedProperty']) && is_array($arModifyEventArray['ExtendedProperty'])) {
         foreach ($arModifyEventArray['ExtendedProperty'] as $arExtendedProperty) {
             $arExtraFields[$arExtendedProperty['Name']] = $arExtendedProperty['Value'];
         }
     }
     if ($ID == 0) {
         $arFields["STATUS_CHANGED_BY"] = $arFields["CHANGED_BY"] = $arFields["CREATED_BY"] = $arFields["RESPONSIBLE_ID"];
         $arFields["STATUS_CHANGED_DATE"] = $arFields["CHANGED_DATE"] = $arFields["CREATED_DATE"];
         $ID = $DB->Add("b_tasks", $arFields, array("DESCRIPTION"), "tasks");
         if ($ID) {
             $arFields["ID"] = $ID;
             CTaskNotifications::SendAddMessage($arFields);
             $arLogFields = array("TASK_ID" => $ID, "USER_ID" => $arFields["CREATED_BY"], "CREATED_DATE" => $arFields["CREATED_DATE"], "FIELD" => "NEW");
             $log = new CTaskLog();
             $log->Add($arLogFields);
         }
     } else {
         $strUpdate = $DB->PrepareUpdate("b_tasks", $arFields, "tasks");
         $strSql = "UPDATE b_tasks SET " . $strUpdate . " WHERE ID=" . $ID;
         $arBinds = array('DESCRIPTION' => $arFields['DESCRIPTION']);
         $result = $DB->QueryBind($strSql, $arBinds, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($result) {
             $rsTask = CTasks::GetByID($ID, false);
             if ($arTask = $rsTask->Fetch()) {
                 $arFields["CHANGED_BY"] = $arFields["RESPONSIBLE_ID"];
                 $arFields["CHANGED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time() + CTimeZone::GetOffset());
                 CTaskNotifications::SendUpdateMessage($arFields, $arTask);
                 $arChanges = CTaskLog::GetChanges($arTask, $arFields);
                 foreach ($arChanges as $key => $value) {
                     $arLogFields = array("TASK_ID" => $ID, "USER_ID" => $arFields["CHANGED_BY"], "CREATED_DATE" => $arFields["CHANGED_DATE"], "FIELD" => $key, "FROM_VALUE" => $value["FROM_VALUE"], "TO_VALUE" => $value["TO_VALUE"]);
                     $log = new CTaskLog();
                     $log->Add($arLogFields);
                 }
             }
         }
     }
 }
示例#3
0
 /**
  * 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
 }
示例#4
0
 /**
  * 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
 }
示例#5
0
 public static function Delete($ID, $arParams = array())
 {
     global $DB, $USER;
     $ID = intval($ID);
     if ($ID < 1) {
         return false;
     }
     $executiveUserId = null;
     if (isset($arParams['USER_ID'])) {
         $executiveUserId = (int) $arParams['USER_ID'];
     } elseif (is_object($USER) && method_exists($USER, 'getId')) {
         $executiveUserId = (int) $USER->getId();
     }
     /** @noinspection PhpDeprecationInspection */
     $rsRemovingLogItem = self::getByID($ID);
     if ($rsRemovingLogItem && ($arRemovingLogItem = $rsRemovingLogItem->fetch())) {
         $taskId = $arRemovingLogItem['TASK_ID'];
     } else {
         return false;
     }
     $curDuration = 0;
     $rsTask = CTasks::getList(array(), array('ID' => $taskId), array('ID', 'TIME_SPENT_IN_LOGS'));
     if ($rsTask && ($arTask = $rsTask->fetch())) {
         $curDuration = (int) $arTask['TIME_SPENT_IN_LOGS'];
     }
     foreach (GetModuleEvents('tasks', 'OnBeforeTaskElapsedTimeDelete', true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID, $arRemovingLogItem)) === false) {
             return false;
         }
     }
     $strSql = "DELETE FROM b_tasks_elapsed_time WHERE ID = " . $ID;
     $rc = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $occurAsUserId = CTasksTools::getOccurAsUserId();
     if (!$occurAsUserId) {
         $occurAsUserId = $executiveUserId ? $executiveUserId : 1;
     }
     $oLog = new CTaskLog();
     $oLog->Add(array('TASK_ID' => $taskId, 'USER_ID' => $occurAsUserId, '~CREATED_DATE' => $DB->currentTimeFunction(), 'FIELD' => 'TIME_SPENT_IN_LOGS', 'FROM_VALUE' => $curDuration, 'TO_VALUE' => $curDuration - (int) $arRemovingLogItem['SECONDS']));
     foreach (GetModuleEvents('tasks', 'OnTaskElapsedTimeDelete', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, &$arRemovingLogItem));
     }
     return $rc;
 }
示例#6
0
 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);
 }
示例#7
0
 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);
 }
示例#8
0
 /**
  * This method is deprecated. Use CTaskItem::update() instead.
  * @deprecated
  */
 public function Update($ID, $arFields, $arParams = array())
 {
     global $DB, $USER, $USER_FIELD_MANAGER, $CACHE_MANAGER, $APPLICATION;
     if (isset($arFields['META::EVENT_GUID'])) {
         $eventGUID = $arFields['META::EVENT_GUID'];
         unset($arFields['META::EVENT_GUID']);
     } else {
         $eventGUID = sha1(uniqid('AUTOGUID', true));
     }
     $bWasFatalError = false;
     $ID = intval($ID);
     if ($ID < 1) {
         return false;
     }
     $userID = null;
     $bCheckRightsOnFiles = false;
     // for backward compatibility
     if (is_array($arParams)) {
         if (isset($arParams['USER_ID']) && $arParams['USER_ID'] > 0) {
             $userID = (int) $arParams['USER_ID'];
         }
         if (isset($arParams['CHECK_RIGHTS_ON_FILES'])) {
             if ($arParams['CHECK_RIGHTS_ON_FILES'] === 'Y' || $arParams['CHECK_RIGHTS_ON_FILES'] === true) {
                 $bCheckRightsOnFiles = true;
             } else {
                 $bCheckRightsOnFiles = false;
             }
         }
     }
     if ($userID === null) {
         $userID = is_object($USER) ? intval($USER->GetID()) : 1;
     }
     $rsTask = CTasks::GetByID($ID, false);
     if ($arTask = $rsTask->Fetch()) {
         if ($this->CheckFields($arFields, $ID, $userID)) {
             if ($USER_FIELD_MANAGER->CheckFields("TASKS_TASK", $ID, $arFields)) {
                 unset($arFields["ID"]);
                 $arBinds = array("DESCRIPTION" => $arFields["DESCRIPTION"], "DECLINE_REASON" => $arFields["DECLINE_REASON"]);
                 $time = time() + CTasksTools::getTimeZoneOffset();
                 $arFields["CHANGED_BY"] = $userID;
                 $arFields["CHANGED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                 $occurAsUserId = CTasksTools::getOccurAsUserId();
                 if (!$occurAsUserId) {
                     $occurAsUserId = $arFields["CHANGED_BY"] ? $arFields["CHANGED_BY"] : 1;
                 }
                 if (!$arFields["OUTLOOK_VERSION"]) {
                     $arFields["OUTLOOK_VERSION"] = ($arTask["OUTLOOK_VERSION"] ? $arTask["OUTLOOK_VERSION"] : 1) + 1;
                 }
                 // If new status code given AND new status code != current status => than update
                 if (isset($arFields["STATUS"]) && (int) $arTask['STATUS'] !== (int) $arFields['STATUS']) {
                     $arFields["STATUS_CHANGED_BY"] = $userID;
                     $arFields["STATUS_CHANGED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                     if ($arFields["STATUS"] == 5 || $arFields["STATUS"] == 4) {
                         $arFields["CLOSED_BY"] = $userID;
                         $arFields["CLOSED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                     } else {
                         $arFields["CLOSED_BY"] = false;
                         $arFields["CLOSED_DATE"] = false;
                         if ($arFields["STATUS"] == 3) {
                             $arFields["DATE_START"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                         }
                     }
                 }
                 if ($arFields["REPLICATE"] == "Y") {
                     $arFields["REPLICATE_PARAMS"] = serialize($arFields["REPLICATE_PARAMS"]);
                 }
                 $arTaskCopy = $arTask;
                 // this will allow transfer data by pointer for speed-up
                 foreach (GetModuleEvents('tasks', 'OnBeforeTaskUpdate', true) as $arEvent) {
                     if (ExecuteModuleEventEx($arEvent, array($ID, &$arFields, &$arTaskCopy)) === false) {
                         $errmsg = GetMessage("TASKS_UNKNOWN_UPDATE_ERROR");
                         $errno = 'ERROR_UNKNOWN_UPDATE_TASK_ERROR';
                         if ($ex = $APPLICATION->getException()) {
                             $errmsg = $ex->getString();
                             $errno = $ex->getId();
                         }
                         $this->_errors[] = array('text' => $errmsg, 'id' => $errno);
                         return false;
                     }
                 }
                 $oTaskList = CTaskCountersProcessor::getInstance();
                 $oTaskList->onBeforeTaskUpdate($ID, $arTask, $arFields);
                 $strUpdate = $DB->PrepareUpdate("b_tasks", $arFields, "tasks");
                 $strSql = "UPDATE b_tasks SET " . $strUpdate . " WHERE ID=" . $ID;
                 $result = $DB->QueryBind($strSql, $arBinds, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 if ($result) {
                     CTaskCountersProcessor::onAfterTaskUpdate($ID, $arTask, $arFields);
                     $arParticipants = array_merge(array($arTask['CREATED_BY'], $arTask['RESPONSIBLE_ID']), (array) $arTask['ACCOMPLICES'], (array) $arTask['AUDITORS']);
                     if (isset($arFields['CREATED_BY'])) {
                         $arParticipants[] = $arFields['CREATED_BY'];
                     }
                     if (isset($arFields['RESPONSIBLE_ID'])) {
                         $arParticipants[] = $arFields['RESPONSIBLE_ID'];
                     }
                     if (isset($arFields['ACCOMPLICES'])) {
                         $arParticipants = array_merge($arParticipants, (array) $arFields['ACCOMPLICES']);
                     }
                     if (isset($arFields['AUDITORS'])) {
                         $arParticipants = array_merge($arParticipants, (array) $arFields['AUDITORS']);
                     }
                     $arParticipants = array_unique($arParticipants);
                     // Emit pull event
                     try {
                         $arPullRecipients = array();
                         foreach ($arParticipants as $userId) {
                             $arPullRecipients[] = (int) $userId;
                         }
                         $taskGroupId = 0;
                         // no group
                         $taskGroupIdBeforeUpdate = 0;
                         // no group
                         if (isset($arTask['GROUP_ID']) && $arTask['GROUP_ID'] > 0) {
                             $taskGroupId = (int) $arTask['GROUP_ID'];
                         }
                         // if $arFields['GROUP_ID'] not given, than it means,
                         // that group not changed during this update, so
                         // we must take existing group_id (from $arTask)
                         if (!array_key_exists('GROUP_ID', $arFields)) {
                             if (isset($arTask['GROUP_ID']) && $arTask['GROUP_ID'] > 0) {
                                 $taskGroupIdBeforeUpdate = (int) $arTask['GROUP_ID'];
                             } else {
                                 $taskGroupIdBeforeUpdate = 0;
                             }
                             // no group
                         } else {
                             if ($arFields['GROUP_ID'] > 0) {
                                 $taskGroupIdBeforeUpdate = (int) $arFields['GROUP_ID'];
                             } else {
                                 $taskGroupIdBeforeUpdate = 0;
                             }
                             // no group
                         }
                         $arPullData = array('TASK_ID' => (int) $ID, 'BEFORE' => array('GROUP_ID' => $taskGroupId), 'AFTER' => array('GROUP_ID' => $taskGroupIdBeforeUpdate), 'TS' => time(), 'event_GUID' => $eventGUID);
                         self::EmitPullWithTagPrefix($arPullRecipients, 'TASKS_GENERAL_', 'task_update', $arPullData);
                         self::EmitPullWithTag($arPullRecipients, 'TASKS_TASK_' . (int) $ID, 'task_update', $arPullData);
                     } catch (Exception $e) {
                         $bWasFatalError = true;
                         $this->_errors[] = 'at line ' . $e->GetLine() . ', ' . $e->GetMessage();
                     }
                     // changes log
                     $arTmp = array('arTask' => $arTask, 'arFields' => $arFields);
                     if (isset($arFields['DURATION_PLAN']) && isset($arFields['DURATION_TYPE'])) {
                         if ($arFields['DURATION_TYPE'] === 'hours') {
                             $arTmp['arFields']['DURATION_PLAN_SECONDS'] = $arFields['DURATION_PLAN'] * 3600;
                             unset($arTmp['arFields']['DURATION_PLAN']);
                         } elseif ($arFields['DURATION_TYPE'] === 'days') {
                             $arTmp['arFields']['DURATION_PLAN_SECONDS'] = $arFields['DURATION_PLAN'] * 3600 * 24;
                             unset($arTmp['arFields']['DURATION_PLAN']);
                         }
                     }
                     if (isset($arTask['DURATION_PLAN']) && isset($arTask['DURATION_TYPE'])) {
                         if ($arTask['DURATION_TYPE'] === 'hours') {
                             $arTmp['arTask']['DURATION_PLAN_SECONDS'] = $arTask['DURATION_PLAN'] * 3600;
                             unset($arTmp['arTask']['DURATION_PLAN']);
                         } elseif ($arTask['DURATION_TYPE'] === 'days') {
                             $arTmp['arTask']['DURATION_PLAN_SECONDS'] = $arTask['DURATION_PLAN'] * 3600 * 24;
                             unset($arTmp['arTask']['DURATION_PLAN']);
                         }
                     }
                     $arChanges = CTaskLog::GetChanges($arTmp['arTask'], $arTmp['arFields']);
                     unset($arTmp);
                     foreach ($arChanges as $key => $value) {
                         $arLogFields = array("TASK_ID" => $ID, "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arFields["CHANGED_DATE"], "FIELD" => $key, "FROM_VALUE" => $value["FROM_VALUE"], "TO_VALUE" => $value["TO_VALUE"]);
                         $log = new CTaskLog();
                         $log->Add($arLogFields);
                     }
                     if (isset($arFields["ACCOMPLICES"]) && isset($arChanges["ACCOMPLICES"])) {
                         CTaskMembers::DeleteByTaskID($ID, "A");
                         CTasks::AddAccomplices($ID, $arFields["ACCOMPLICES"]);
                     }
                     if (isset($arFields["AUDITORS"]) && isset($arChanges["AUDITORS"])) {
                         CTaskMembers::DeleteByTaskID($ID, "U");
                         CTasks::AddAuditors($ID, $arFields["AUDITORS"]);
                     }
                     if (isset($arFields["FILES"]) && (isset($arChanges["NEW_FILES"]) || isset($arChanges["DELETED_FILES"]))) {
                         $arNotDeleteFiles = $arFields["FILES"];
                         CTaskFiles::DeleteByTaskID($ID, $arNotDeleteFiles);
                         CTasks::AddFiles($ID, $arFields["FILES"], array('USER_ID' => $userID, 'CHECK_RIGHTS_ON_FILES' => $bCheckRightsOnFiles));
                     }
                     if (isset($arFields["TAGS"]) && isset($arChanges["TAGS"])) {
                         CTaskTags::DeleteByTaskID($ID);
                         CTasks::AddTags($ID, $arTask["CREATED_BY"], $arFields["TAGS"], $userID);
                     }
                     if (isset($arFields["DEPENDS_ON"]) && isset($arChanges["DEPENDS_ON"])) {
                         CTaskDependence::DeleteByTaskID($ID);
                         CTasks::AddPrevious($ID, $arFields["DEPENDS_ON"]);
                     }
                     $USER_FIELD_MANAGER->Update("TASKS_TASK", $ID, $arFields, $userID);
                     $notifArFields = array_merge($arFields, array('CHANGED_BY' => $occurAsUserId));
                     if (($status = intval($arFields["STATUS"])) && $status > 0 && $status < 8 && (int) $arTask['STATUS'] !== (int) $arFields['STATUS']) {
                         if ($status == 7) {
                             $arTask["DECLINE_REASON"] = $arFields["DECLINE_REASON"];
                         }
                         CTaskNotifications::SendStatusMessage($arTask, $status, $notifArFields);
                     }
                     CTaskNotifications::SendUpdateMessage($notifArFields, $arTask);
                     CTaskComments::onAfterTaskUpdate($ID, $arTask, $arFields);
                     $arFields["ID"] = $ID;
                     $arMergedFields = array_merge($arTask, $arFields);
                     CTaskSync::UpdateItem($arFields, $arTask);
                     // MS Exchange
                     $arFields['META:PREV_FIELDS'] = $arTask;
                     try {
                         $lastEventName = '';
                         foreach (GetModuleEvents('tasks', 'OnTaskUpdate', true) as $arEvent) {
                             $lastEventName = $arEvent['TO_CLASS'] . '::' . $arEvent['TO_METHOD'] . '()';
                             ExecuteModuleEventEx($arEvent, array($ID, &$arFields, &$arTaskCopy));
                         }
                     } catch (Exception $e) {
                         CTaskAssert::logWarning('[0xee8999a8] exception in module event: ' . $lastEventName . '; at file: ' . $e->getFile() . ':' . $e->getLine() . ";\n");
                     }
                     unset($arFields['META:PREV_FIELDS']);
                     CTasks::Index($arMergedFields, $arFields["TAGS"]);
                     // search index
                     // clear cache
                     if ($arTask["GROUP_ID"]) {
                         $CACHE_MANAGER->ClearByTag("tasks_group_" . $arTask["GROUP_ID"]);
                     }
                     if ($arFields['GROUP_ID'] && $arFields['GROUP_ID'] != $arTask['GROUP_ID']) {
                         $CACHE_MANAGER->ClearByTag('tasks_group_' . $arFields['GROUP_ID']);
                     }
                     foreach ($arParticipants as $userId) {
                         $CACHE_MANAGER->ClearByTag("tasks_user_" . $userId);
                     }
                     if ($bWasFatalError) {
                         soundex('push&pull: bWasFatalError === true');
                     }
                     return true;
                 }
             } else {
                 $e = $APPLICATION->GetException();
                 foreach ($e->messages as $msg) {
                     $this->_errors[] = $msg;
                 }
             }
         }
     }
     if (sizeof($this->_errors) == 0) {
         $this->_errors[] = array("text" => GetMessage("TASKS_UNKNOWN_UPDATE_ERROR"), "id" => "ERROR_UNKNOWN_UPDATE_TASK_ERROR");
     }
     return false;
 }
示例#9
0
 /**
  * This method is deprecated. Use CTaskItem::update() instead.
  * @deprecated
  */
 public function Update($ID, $arFields, $arParams = array('CORRECT_DATE_PLAN_DEPENDENT_TASKS' => true, 'CORRECT_DATE_PLAN' => true, 'THROTTLE_MESSAGES' => false))
 {
     global $DB, $USER, $USER_FIELD_MANAGER, $APPLICATION;
     if (!isset($arParams['CORRECT_DATE_PLAN'])) {
         $arParams['CORRECT_DATE_PLAN'] = true;
     }
     if (!isset($arParams['CORRECT_DATE_PLAN_DEPENDENT_TASKS'])) {
         $arParams['CORRECT_DATE_PLAN_DEPENDENT_TASKS'] = true;
     }
     if (!isset($arParams['THROTTLE_MESSAGES'])) {
         $arParams['THROTTLE_MESSAGES'] = false;
     }
     $this->lastOperationResultData = array();
     if (isset($arFields['META::EVENT_GUID'])) {
         $eventGUID = $arFields['META::EVENT_GUID'];
         unset($arFields['META::EVENT_GUID']);
     } else {
         $eventGUID = sha1(uniqid('AUTOGUID', true));
     }
     $bWasFatalError = false;
     $ID = intval($ID);
     if ($ID < 1) {
         return false;
     }
     $userID = null;
     $bCheckRightsOnFiles = false;
     // for backward compatibility
     if (!is_array($arParams)) {
         $arParams = array();
     }
     if (isset($arParams['USER_ID']) && $arParams['USER_ID'] > 0) {
         $userID = (int) $arParams['USER_ID'];
     }
     if (isset($arParams['CHECK_RIGHTS_ON_FILES'])) {
         if ($arParams['CHECK_RIGHTS_ON_FILES'] === 'Y' || $arParams['CHECK_RIGHTS_ON_FILES'] === true) {
             $bCheckRightsOnFiles = true;
         } else {
             $bCheckRightsOnFiles = false;
         }
     }
     if (!isset($arParams['CORRECT_DATE_PLAN_DEPENDENT_TASKS'])) {
         $arParams['CORRECT_DATE_PLAN_DEPENDENT_TASKS'] = true;
     }
     if (!isset($arParams['CORRECT_DATE_PLAN'])) {
         $arParams['CORRECT_DATE_PLAN'] = true;
     }
     if ($userID === null) {
         $userID = is_object($USER) ? intval($USER->GetID()) : 1;
     }
     $rsTask = CTasks::GetByID($ID, false);
     if ($arTask = $rsTask->Fetch()) {
         // check if there are userfields in $arFields
         $hasUfs = false;
         foreach ($arFields as $fld => $value) {
             $fld = trim($fld);
             if (strpos($fld, 'UF_') == 0) {
                 $hasUfs = true;
                 break;
             }
         }
         if ($this->CheckFields($arFields, $ID, $userID)) {
             $okay = $hasUfs ? $USER_FIELD_MANAGER->CheckFields("TASKS_TASK", $ID, $arFields) : true;
             if ($okay) {
                 $scheduler = null;
                 unset($arFields["ID"]);
                 $arBinds = array("DESCRIPTION" => $arFields["DESCRIPTION"], "DECLINE_REASON" => $arFields["DECLINE_REASON"]);
                 $time = time() + CTasksTools::getTimeZoneOffset();
                 $arFields["CHANGED_BY"] = $userID;
                 $arFields["CHANGED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                 $occurAsUserId = CTasksTools::getOccurAsUserId();
                 if (!$occurAsUserId) {
                     $occurAsUserId = $arFields["CHANGED_BY"] ? $arFields["CHANGED_BY"] : 1;
                 }
                 if (!$arFields["OUTLOOK_VERSION"]) {
                     $arFields["OUTLOOK_VERSION"] = ($arTask["OUTLOOK_VERSION"] ? $arTask["OUTLOOK_VERSION"] : 1) + 1;
                 }
                 // If new status code given AND new status code != current status => than update
                 if (isset($arFields["STATUS"]) && (int) $arTask['STATUS'] !== (int) $arFields['STATUS']) {
                     $arFields["STATUS_CHANGED_BY"] = $userID;
                     $arFields["STATUS_CHANGED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                     if ($arFields["STATUS"] == 5 || $arFields["STATUS"] == 4) {
                         $arFields["CLOSED_BY"] = $userID;
                         $arFields["CLOSED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                     } else {
                         $arFields["CLOSED_BY"] = false;
                         $arFields["CLOSED_DATE"] = false;
                         if ($arFields["STATUS"] == 3) {
                             $arFields["DATE_START"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), $time);
                         }
                     }
                 }
                 if ($arFields["REPLICATE"] == "Y") {
                     $arFields["REPLICATE_PARAMS"] = serialize($arFields["REPLICATE_PARAMS"]);
                 }
                 // when updating end or start date plan, we need to be sure the time is correct
                 if ((string) $arFields['START_DATE_PLAN'] != '' || (string) $arFields['END_DATE_PLAN'] != '') {
                     if ($arParams['CORRECT_DATE_PLAN']) {
                         /*
                         print_r('Try to update '.$ID.' to:'.PHP_EOL);
                         print_r($arFields['START_DATE_PLAN']->getInfoGmt().PHP_EOL);
                         print_r($arFields['END_DATE_PLAN']->getInfoGmt().PHP_EOL);
                         */
                         $arTaskDPCopy = $arTask;
                         if ((string) $arFields['START_DATE_PLAN'] == '') {
                             // start date will be dropped, scheduler should be informed about that
                             $arTaskDPCopy['START_DATE_PLAN'] = '';
                         }
                         if ((string) $arFields['END_DATE_PLAN'] == '') {
                             // end date will be dropped, scheduler should be informed about that
                             $arTaskDPCopy['END_DATE_PLAN'] = '';
                         }
                         $scheduler = new Scheduler($userID, $ID, $arTaskDPCopy);
                         $data = $scheduler->reScheduleTask($arFields);
                         /*
                         print_r('Actual moving '.$ID.' to:'.PHP_EOL);
                         print_r($data['START_DATE_PLAN']->getInfoGmt().PHP_EOL);
                         print_r($data['END_DATE_PLAN']->getInfoGmt().PHP_EOL);
                         */
                         // to database:
                         if ($data['START_DATE_PLAN']) {
                             if ($data['START_DATE_PLAN']->toString() != (string) $arTask['CREATED_DATE']) {
                                 $arFields['START_DATE_PLAN'] = $data['START_DATE_PLAN']->toString();
                             }
                             $data['START_DATE_PLAN_STRUCT'] = $data['START_DATE_PLAN']->getTimeStruct();
                             $data['START_DATE_PLAN'] = $data['START_DATE_PLAN']->toString();
                         }
                         if ($data['END_DATE_PLAN']) {
                             $arFields['END_DATE_PLAN'] = $data['END_DATE_PLAN']->toString();
                             $data['END_DATE_PLAN_STRUCT'] = $data['END_DATE_PLAN']->getTimeStruct();
                             $data['END_DATE_PLAN'] = $data['END_DATE_PLAN']->toString();
                         }
                         if (isset($data['DURATION_PLAN_SECONDS'])) {
                             $arFields['DURATION_PLAN_SECONDS'] = $data['DURATION_PLAN_SECONDS'];
                         }
                         unset($data['ID']);
                         unset($data['MATCH_WORK_TIME']);
                         $this->lastOperationResultData['SHIFT_RESULT'][$ID] = $data;
                     }
                 }
                 // END_DATE_PLAN will be dropped
                 if (isset($arFields['END_DATE_PLAN']) && (string) $arFields['END_DATE_PLAN'] == '') {
                     // duration is no longer adequate
                     $arFields['DURATION_PLAN'] = 0;
                 }
                 self::processDurationPlanFields($arFields, (string) $arFields['DURATION_TYPE'] != '' ? $arFields['DURATION_TYPE'] : $arTask['DURATION_TYPE']);
                 $arTaskCopy = $arTask;
                 // this will allow transfer data by pointer for speed-up
                 foreach (GetModuleEvents('tasks', 'OnBeforeTaskUpdate', true) as $arEvent) {
                     if (ExecuteModuleEventEx($arEvent, array($ID, &$arFields, &$arTaskCopy)) === false) {
                         $errmsg = GetMessage("TASKS_UNKNOWN_UPDATE_ERROR");
                         $errno = 'ERROR_UNKNOWN_UPDATE_TASK_ERROR';
                         if ($ex = $APPLICATION->getException()) {
                             $errmsg = $ex->getString();
                             $errno = $ex->getId();
                         }
                         $this->_errors[] = array('text' => $errmsg, 'id' => $errno);
                         return false;
                     }
                 }
                 $oTaskList = CTaskCountersProcessor::getInstance();
                 $oTaskList->onBeforeTaskUpdate($ID, $arTask, $arFields);
                 $strUpdate = $DB->PrepareUpdate("b_tasks", $arFields, "tasks");
                 $strSql = "UPDATE b_tasks SET " . $strUpdate . " WHERE ID=" . $ID;
                 $result = $DB->QueryBind($strSql, $arBinds, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 if ($result) {
                     CTaskCountersProcessor::onAfterTaskUpdate($ID, $arTask, $arFields);
                     $arParticipants = array_merge(array($arTask['CREATED_BY'], $arTask['RESPONSIBLE_ID']), (array) $arTask['ACCOMPLICES'], (array) $arTask['AUDITORS']);
                     if (isset($arFields['CREATED_BY'])) {
                         $arParticipants[] = $arFields['CREATED_BY'];
                     }
                     if (isset($arFields['RESPONSIBLE_ID'])) {
                         $arParticipants[] = $arFields['RESPONSIBLE_ID'];
                     }
                     if (isset($arFields['ACCOMPLICES'])) {
                         $arParticipants = array_merge($arParticipants, (array) $arFields['ACCOMPLICES']);
                     }
                     if (isset($arFields['AUDITORS'])) {
                         $arParticipants = array_merge($arParticipants, (array) $arFields['AUDITORS']);
                     }
                     $arParticipants = array_unique($arParticipants);
                     // Emit pull event
                     try {
                         $arPullRecipients = array();
                         foreach ($arParticipants as $userId) {
                             $arPullRecipients[] = (int) $userId;
                         }
                         $taskGroupId = 0;
                         // no group
                         $taskGroupIdBeforeUpdate = 0;
                         // no group
                         if (isset($arTask['GROUP_ID']) && $arTask['GROUP_ID'] > 0) {
                             $taskGroupId = (int) $arTask['GROUP_ID'];
                         }
                         // if $arFields['GROUP_ID'] not given, than it means,
                         // that group not changed during this update, so
                         // we must take existing group_id (from $arTask)
                         if (!array_key_exists('GROUP_ID', $arFields)) {
                             if (isset($arTask['GROUP_ID']) && $arTask['GROUP_ID'] > 0) {
                                 $taskGroupIdBeforeUpdate = (int) $arTask['GROUP_ID'];
                             } else {
                                 $taskGroupIdBeforeUpdate = 0;
                             }
                             // no group
                         } else {
                             if ($arFields['GROUP_ID'] > 0) {
                                 $taskGroupIdBeforeUpdate = (int) $arFields['GROUP_ID'];
                             } else {
                                 $taskGroupIdBeforeUpdate = 0;
                             }
                             // no group
                         }
                         $arPullData = array('TASK_ID' => (int) $ID, 'BEFORE' => array('GROUP_ID' => $taskGroupId), 'AFTER' => array('GROUP_ID' => $taskGroupIdBeforeUpdate), 'TS' => time(), 'event_GUID' => $eventGUID);
                         self::EmitPullWithTagPrefix($arPullRecipients, 'TASKS_GENERAL_', 'task_update', $arPullData);
                         self::EmitPullWithTag($arPullRecipients, 'TASKS_TASK_' . (int) $ID, 'task_update', $arPullData);
                     } catch (Exception $e) {
                         $bWasFatalError = true;
                         $this->_errors[] = 'at line ' . $e->GetLine() . ', ' . $e->GetMessage();
                     }
                     // changes log
                     $arTmp = array('arTask' => $arTask, 'arFields' => $arFields);
                     if (isset($arTask['DURATION_PLAN'])) {
                         $arTmp['arTask']['DURATION_PLAN_SECONDS'] = $arTask['DURATION_PLAN_SECONDS'];
                         unset($arTmp['arTask']['DURATION_PLAN']);
                     }
                     if (isset($arFields['DURATION_PLAN'])) {
                         // at this point, $arFields['DURATION_PLAN'] in seconds
                         $arTmp['arFields']['DURATION_PLAN_SECONDS'] = $arFields['DURATION_PLAN'];
                         unset($arTmp['arFields']['DURATION_PLAN']);
                     }
                     $arChanges = CTaskLog::GetChanges($arTmp['arTask'], $arTmp['arFields']);
                     unset($arTmp);
                     foreach ($arChanges as $key => $value) {
                         $arLogFields = array("TASK_ID" => $ID, "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arFields["CHANGED_DATE"], "FIELD" => $key, "FROM_VALUE" => $value["FROM_VALUE"], "TO_VALUE" => $value["TO_VALUE"]);
                         $log = new CTaskLog();
                         $log->Add($arLogFields);
                     }
                     if (isset($arFields["ACCOMPLICES"]) && isset($arChanges["ACCOMPLICES"])) {
                         CTaskMembers::DeleteByTaskID($ID, "A");
                         CTasks::AddAccomplices($ID, $arFields["ACCOMPLICES"]);
                     }
                     if (isset($arFields["AUDITORS"]) && isset($arChanges["AUDITORS"])) {
                         CTaskMembers::DeleteByTaskID($ID, "U");
                         CTasks::AddAuditors($ID, $arFields["AUDITORS"]);
                     }
                     if (isset($arFields["FILES"]) && (isset($arChanges["NEW_FILES"]) || isset($arChanges["DELETED_FILES"]))) {
                         $arNotDeleteFiles = $arFields["FILES"];
                         CTaskFiles::DeleteByTaskID($ID, $arNotDeleteFiles);
                         CTasks::AddFiles($ID, $arFields["FILES"], array('USER_ID' => $userID, 'CHECK_RIGHTS_ON_FILES' => $bCheckRightsOnFiles));
                     }
                     if (isset($arFields["TAGS"]) && isset($arChanges["TAGS"])) {
                         CTaskTags::DeleteByTaskID($ID);
                         CTasks::AddTags($ID, $arTask["CREATED_BY"], $arFields["TAGS"], $userID);
                     }
                     if (isset($arFields["DEPENDS_ON"]) && isset($arChanges["DEPENDS_ON"])) {
                         CTaskDependence::DeleteByTaskID($ID);
                         CTasks::AddPrevious($ID, $arFields["DEPENDS_ON"]);
                     }
                     if ($hasUfs) {
                         $USER_FIELD_MANAGER->Update("TASKS_TASK", $ID, $arFields, $userID);
                     }
                     // tasks dependence
                     if ($arParams['CORRECT_DATE_PLAN'] && $arParams['CORRECT_DATE_PLAN_DEPENDENT_TASKS'] && (isset($arFields["START_DATE_PLAN"]) || isset($arFields["END_DATE_PLAN"]))) {
                         if ($scheduler === null) {
                             $scheduler = new Scheduler($userID, $ID, $arTask);
                         }
                         $relatedTaskUpdate = $scheduler->reScheduleRelatedTasks();
                         if (is_array($relatedTaskUpdate)) {
                             $relatedUpdateParams = $arParams;
                             $relatedUpdateParams['CORRECT_DATE_PLAN'] = false;
                             // no self-correction
                             $relatedUpdateParams['CORRECT_DATE_PLAN_DEPENDENT_TASKS'] = false;
                             // no sub-correction
                             foreach ($relatedTaskUpdate as $relatedTaskId => $relatedTaskData) {
                                 $relatedTaskData['START_DATE_PLAN_STRUCT'] = $relatedTaskData['START_DATE_PLAN']->getTimeStruct();
                                 // as struct
                                 $relatedTaskData['END_DATE_PLAN_STRUCT'] = $relatedTaskData['END_DATE_PLAN']->getTimeStruct();
                                 // as struct
                                 $relatedTaskData['START_DATE_PLAN'] = $relatedTaskData['START_DATE_PLAN']->toString();
                                 // as string, not object
                                 $relatedTaskData['END_DATE_PLAN'] = $relatedTaskData['END_DATE_PLAN']->toString();
                                 // as string, not object
                                 $relatedTask = new CTasks();
                                 $relatedTask->update($relatedTaskId, $relatedTaskData, $relatedUpdateParams);
                                 $this->lastOperationResultData['SHIFT_RESULT'][$relatedTaskId] = $relatedTaskData;
                             }
                         }
                     }
                     $notifArFields = array_merge($arFields, array('CHANGED_BY' => $occurAsUserId));
                     if (($status = intval($arFields["STATUS"])) && $status > 0 && $status < 8 && (int) $arTask['STATUS'] !== (int) $arFields['STATUS']) {
                         if ($status == 7) {
                             $arTask["DECLINE_REASON"] = $arFields["DECLINE_REASON"];
                         }
                         CTaskNotifications::SendStatusMessage($arTask, $status, $notifArFields);
                     }
                     CTaskNotifications::SendUpdateMessage($notifArFields, $arTask, false, $arParams);
                     CTaskComments::onAfterTaskUpdate($ID, $arTask, $arFields);
                     $arFields["ID"] = $ID;
                     $arMergedFields = array_merge($arTask, $arFields);
                     CTaskSync::UpdateItem($arFields, $arTask);
                     // MS Exchange
                     $arFields['META:PREV_FIELDS'] = $arTask;
                     try {
                         $lastEventName = '';
                         foreach (GetModuleEvents('tasks', 'OnTaskUpdate', true) as $arEvent) {
                             $lastEventName = $arEvent['TO_CLASS'] . '::' . $arEvent['TO_METHOD'] . '()';
                             ExecuteModuleEventEx($arEvent, array($ID, &$arFields, &$arTaskCopy));
                         }
                     } catch (Exception $e) {
                         CTaskAssert::logWarning('[0xee8999a8] exception in module event: ' . $lastEventName . '; at file: ' . $e->getFile() . ':' . $e->getLine() . ";\n");
                     }
                     unset($arFields['META:PREV_FIELDS']);
                     // clear cache
                     static::addCacheIdToClear("tasks_" . $ID);
                     if ($arTask["GROUP_ID"]) {
                         static::addCacheIdToClear("tasks_group_" . $arTask["GROUP_ID"]);
                     }
                     if ($arFields['GROUP_ID'] && $arFields['GROUP_ID'] != $arTask['GROUP_ID']) {
                         static::addCacheIdToClear("tasks_group_" . $arFields["GROUP_ID"]);
                     }
                     foreach ($arParticipants as $userId) {
                         static::addCacheIdToClear("tasks_user_" . $userId);
                     }
                     static::clearCache();
                     if ($bWasFatalError) {
                         soundex('push&pull: bWasFatalError === true');
                     }
                     $this->previousData = $arTask;
                     return true;
                 }
             } else {
                 $e = $APPLICATION->GetException();
                 foreach ($e->messages as $msg) {
                     $this->_errors[] = $msg;
                 }
             }
         }
     }
     if (sizeof($this->_errors) == 0) {
         $this->_errors[] = array("text" => GetMessage("TASKS_UNKNOWN_UPDATE_ERROR"), "id" => "ERROR_UNKNOWN_UPDATE_TASK_ERROR");
     }
     return false;
 }