function SendStatusMessage($arTask, $status, $arFields = array())
 {
     global $USER, $DB;
     $cacheWasEnabled = CTaskNotifications::enableStaticCache();
     $status = intval($status);
     if ($status > 0 && $status < 8) {
         $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs(array_merge($arTask, $arFields));
         if (sizeof($arRecipientsIDs) && (is_object($USER) && $USER->GetID() || $arTask["CREATED_BY"])) {
             $occurAsUserId = CTasksTools::getOccurAsUserId();
             if (!$occurAsUserId) {
                 $occurAsUserId = is_object($USER) && $USER->GetID() ? $USER->GetID() : $arTask["CREATED_BY"];
             }
             // If task was redoed
             if (($status == CTasks::STATE_NEW || $status == CTasks::STATE_PENDING) && $arTask['REAL_STATUS'] == CTasks::STATE_SUPPOSEDLY_COMPLETED) {
                 $redoedMessage = CTaskNotifications::getGenderMessage($occurAsUserId, 'TASKS_TASK_STATUS_MESSAGE_REDOED');
                 $message = str_replace("#TASK_TITLE#", self::formatTaskName($arTask['ID'], $arTask['TITLE'], $arTask['GROUP_ID'], false), $redoedMessage);
                 $message_email = str_replace("#TASK_TITLE#", self::formatTaskName($arTask['ID'], $arTask['TITLE'], $arTask['GROUP_ID'], false), $redoedMessage);
                 $messagePush = CTaskNotifications::makePushMessage('TASKS_TASK_STATUS_MESSAGE_REDOED', $occurAsUserId, $arTask);
             } else {
                 $statusMessage = CTaskNotifications::getGenderMessage($occurAsUserId, 'TASKS_TASK_STATUS_MESSAGE_' . $status);
                 $message = str_replace("#TASK_TITLE#", self::formatTaskName($arTask['ID'], $arTask['TITLE'], $arTask['GROUP_ID'], false), $statusMessage);
                 $message_email = str_replace("#TASK_TITLE#", self::formatTaskName($arTask['ID'], $arTask['TITLE'], $arTask['GROUP_ID'], false), $statusMessage);
                 $messagePush = CTaskNotifications::makePushMessage('TASKS_TASK_STATUS_MESSAGE_' . $status, $occurAsUserId, $arTask);
                 if ($status == CTasks::STATE_DECLINED) {
                     $message = str_replace("#TASK_DECLINE_REASON#", $arTask["DECLINE_REASON"], $message);
                     $message_email = str_replace("#TASK_DECLINE_REASON#", $arTask["DECLINE_REASON"], $message_email);
                     $messagePush = str_replace("#TASK_DECLINE_REASON#", $arTask["DECLINE_REASON"], $messagePush);
                 }
             }
             CTaskNotifications::sendMessageEx($arTask["ID"], $occurAsUserId, $arRecipientsIDs, array('INSTANT' => $message, 'EMAIL' => $message_email, 'PUSH' => $messagePush), array('EVENT_DATA' => array('ACTION' => 'TASK_STATUS_CHANGED_MESSAGE', 'arTask' => $arTask, 'arFields' => $arFields)));
             /*
             CTaskNotifications::SendMessage($occurAsUserId, $arRecipientsIDs, 
             	$message, $arTask["ID"], $message_email,
             	array(
             		'ACTION'   => 'TASK_STATUS_CHANGED_MESSAGE',
             		'arTask'   => $arTask,
             		'arFields' => $arFields
             	)
             );
             */
         }
     }
     // sonet log
     if (CModule::IncludeModule("socialnetwork")) {
         if ($status == CTasks::STATE_PENDING) {
             $message = GetMessage("TASKS_SONET_TASK_STATUS_MESSAGE_" . CTasks::STATE_NEW);
         } else {
             $message = GetMessage("TASKS_SONET_TASK_STATUS_MESSAGE_" . $status);
         }
         if ($status == CTasks::STATE_DECLINED) {
             $message = str_replace("#TASK_DECLINE_REASON#", $arTask["DECLINE_REASON"], $message);
         }
         $bCrmTask = isset($arTask) && isset($arTask["UF_CRM_TASK"]) && (is_array($arTask["UF_CRM_TASK"]) && (isset($arTask["UF_CRM_TASK"][0]) && strlen($arTask["UF_CRM_TASK"][0]) > 0) || !is_array($arTask["UF_CRM_TASK"]) && strlen($arTask["UF_CRM_TASK"]) > 0);
         $arSoFields = array("TITLE" => $arTask["TITLE"], "=LOG_UPDATE" => strlen($arTask["CHANGED_DATE"]) > 0 ? MakeTimeStamp($arTask["CHANGED_DATE"], CSite::GetDateFormat("FULL", SITE_ID)) > time() + CTimeZone::GetOffset() ? $DB->CharToDateFunction($arTask["CHANGED_DATE"], "FULL", SITE_ID) : $DB->CurrentTimeFunction() : $DB->CurrentTimeFunction(), "MESSAGE" => "", "TEXT_MESSAGE" => $message, "PARAMS" => serialize(array("TYPE" => "status", 'CHANGED_BY' => $arFields['CHANGED_BY'], 'PREV_REAL_STATUS' => isset($arTask['REAL_STATUS']) ? $arTask['REAL_STATUS'] : false)));
         $arSoFields['=LOG_DATE'] = $arSoFields['=LOG_UPDATE'];
         // All tasks posts in live feed should be from director
         if (isset($arFields['CREATED_BY'])) {
             $arSoFields["USER_ID"] = $arFields['CREATED_BY'];
         }
         $loggedInUserId = false;
         if (is_object($USER) && method_exists($USER, 'getId')) {
             $loggedInUserId = (int) $USER->getId();
         }
         $arLogFilter = false;
         if (!$bCrmTask) {
             $arLogFilter = array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]);
         } elseif (CModule::IncludeModule("crm")) {
             $dbCrmActivity = CCrmActivity::GetList(array(), array('TYPE_ID' => CCrmActivityType::Task, 'ASSOCIATED_ENTITY_ID' => $arTask["ID"], 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID'));
             if ($arCrmActivity = $dbCrmActivity->Fetch()) {
                 $arLogFilter = array("EVENT_ID" => "crm_activity_add", "ENTITY_ID" => $arCrmActivity["ID"]);
             }
         }
         if (!$arLogFilter) {
             return null;
         }
         $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), $arLogFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
         while ($arRes = $dbRes->Fetch()) {
             CSocNetLog::Update($arRes['ID'], $arSoFields);
             $authorUserId = (int) $arTask['CREATED_BY'];
             // Add author to list of users that view log about task in livefeed
             // But only when some other person change task
             if ($authorUserId !== $loggedInUserId) {
                 $authorGroupCode = 'U' . $authorUserId;
                 $rsRights = CSocNetLogRights::GetList(array(), array('LOG_ID' => $arRes['ID'], 'GROUP_CODE' => $authorGroupCode));
                 // If task's author hasn't rights yet, give them
                 if (!($arRights = $rsRights->fetch())) {
                     CSocNetLogRights::Add($arRes["ID"], array($authorGroupCode));
                 }
             }
         }
     }
     if ($cacheWasEnabled) {
         CTaskNotifications::disableStaticCache();
     }
 }