Esempio n. 1
0
 public static function getList($userId, $taskId, array $parameters = array())
 {
     $data = array();
     $task = static::getTask($userId, $taskId);
     if ($task !== null && $task->checkCanRead()) {
         $res = \CTaskLog::GetList(array('CREATED_DATE' => 'DESC'), array('TASK_ID' => $taskId));
         $tzDisabled = !\CTimeZone::enabled();
         if ($tzDisabled) {
             \CTimeZone::enable();
         }
         $tzOffset = \CTimeZone::getOffset();
         if ($tzDisabled) {
             \CTimeZone::disable();
         }
         while (true) {
             if ($parameters['ESCAPE_DATA']) {
                 $item = $res->GetNext();
             } else {
                 $item = $res->fetch();
             }
             if (!$item) {
                 break;
             }
             // Adjust unix timestamps to "bitrix timestamps"
             if (isset(\CTaskLog::$arComparedFields[$item['FIELD']]) && \CTaskLog::$arComparedFields[$item['FIELD']] === 'date') {
                 $item['TO_VALUE'] = $item['TO_VALUE'] + $tzOffset;
                 $item['FROM_VALUE'] = $item['FROM_VALUE'] + $tzOffset;
             }
             $data[] = $item;
         }
     }
     return array('DATA' => $data, 'CAN' => array());
 }
Esempio n. 2
0
 protected function fetchListFromDb($taskData, $arOrder = array('ID' => 'ASC'), $arFilter = array())
 {
     CTaskAssert::assertLaxIntegers($taskData['ID']);
     if (!isset($arOrder)) {
         $arOrder = array('ID' => 'ASC');
     }
     if (!is_array($arFilter)) {
         $arFilter = array();
     }
     $arFilter['TASK_ID'] = (int) $taskData['ID'];
     $arItemsData = array();
     /** @noinspection PhpDeprecationInspection */
     $rsData = CTaskLog::GetList($arOrder, $arFilter);
     if (!is_object($rsData)) {
         throw new Exception();
     }
     $i = 1;
     while ($arData = $rsData->fetch()) {
         $arData['ID'] = $i;
         // emulate ID field that is required by CTaskSubItemAbstract::constructWithPreloadedData()
         $arItemsData[] = $arData;
         $i++;
     }
     return array($arItemsData, $rsData);
 }
Esempio n. 3
0
 /**
  * DEPRECATED! Migrated to tasks module.
  *
  * @deprecated
  */
 public static function GetTaskTime($arParams)
 {
     if ($arParams['EXPIRED_DATE'] > 0) {
         $arParams['EXPIRED_DATE'] += CTimeMan::RemoveHoursTS($arParams['DATE_START']);
     }
     if (CModule::IncludeModule('tasks')) {
         $time = 0;
         $arFilter = array('TASK_ID' => $arParams['TASK_ID'], 'USER_ID' => $arParams['USER_ID'], '>=CREATED_DATE' => ConvertTimeStamp($arParams['DATE_START'], 'FULL'));
         if ($arParams['DATE_FINISH']) {
             $arFilter['<CREATED_DATE'] = ConvertTimeStamp($arParams['DATE_FINISH'], 'FULL');
         } elseif ($arParams['EXPIRED_DATE']) {
             $arFilter['<CREATED_DATE'] = ConvertTimeStamp($arParams['EXPIRED_DATE']);
         }
         $dbRes = CTaskElapsedTime::GetList(array('CREATED_DATE' => 'ASC'), $arFilter);
         while ($arRes = $dbRes->Fetch()) {
             self::$arWasElapedCache[$arRes['TASK_ID']] = true;
             $time += $arRes['MINUTES'] * 60;
         }
         if ($time == 0) {
             $arFilter['FIELD'] = 'STATUS';
             $dbRes = CTaskLog::GetList(array('CREATED_DATE' => 'ASC'), $arFilter);
             $current_time = $arParams['DATE_START'];
             $last_status = $arParams['TASK_STATUS'];
             while ($arRes = $dbRes->Fetch()) {
                 if ($arRes['FROM_VALUE'] == 3) {
                     $time += MakeTimeStamp($arRes['CREATED_DATE']) - $current_time;
                 } elseif ($arRes['TO_VALUE'] == 3) {
                     $current_time = MakeTimeStamp($arRes['CREATED_DATE']);
                 }
                 $last_status = $arRes['TO_VALUE'];
             }
             if ($last_status == 3) {
                 if ($arParams['DATE_FINISH']) {
                     $time += $arParams['DATE_FINISH'] - $current_time;
                 } elseif ($arParams['EXPIRED_DATE']) {
                     $time += $arParams['EXPIRED_DATE'] - $current_time;
                 } else {
                     $time += time() + CTimeZone::GetOffset() - $current_time;
                 }
             }
         }
         return $time;
     }
     return false;
 }
Esempio n. 4
0
 public static function GetList($arOrder, $arFilter)
 {
     global $DB;
     $arSqlSearch = CTaskLog::GetFilter($arFilter);
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tTL.*,\n\t\t\t\t" . $DB->DateToCharFunction("TL.CREATED_DATE", "FULL") . " AS CREATED_DATE,\n\t\t\t\tU.NAME AS USER_NAME,\n\t\t\t\tU.LAST_NAME AS USER_LAST_NAME,\n\t\t\t\tU.SECOND_NAME AS USER_SECOND_NAME,\n\t\t\t\tU.LOGIN AS USER_LOGIN\n\t\t\tFROM\n\t\t\t\tb_tasks_log TL\n\t\t\tINNER JOIN\n\t\t\t\tb_user U\n\t\t\tON\n\t\t\t\tU.ID = TL.USER_ID\n\t\t\t" . (sizeof($arSqlSearch) ? "WHERE " . implode(" AND ", $arSqlSearch) : "") . "\n\t\t";
     if (!is_array($arOrder) || sizeof($arOrder) == 0) {
         $arOrder = array("CREATED_DATE" => "ASC");
     }
     foreach ($arOrder as $by => $order) {
         $by = strtolower($by);
         $order = strtolower($order);
         if ($order != "asc") {
             $order = "desc";
         }
         if ($by == "user" || $by == "user_id") {
             $arSqlOrder[] = " TL.USER_ID " . $order . " ";
         } elseif ($by == "field") {
             $arSqlOrder[] = " TL.FIELD " . $order . " ";
         } elseif ($by == "task_id") {
             $arSqlOrder[] = " TL.TASK_ID " . $order . " ";
         } elseif ($by == "rand") {
             $arSqlOrder[] = CTasksTools::getRandFunction();
         } else {
             $arSqlOrder[] = " TL.CREATED_DATE " . $order . " ";
         }
     }
     $strSqlOrder = "";
     DelDuplicateSort($arSqlOrder);
     for ($i = 0, $arSqlOrderCnt = count($arSqlOrder); $i < $arSqlOrderCnt; $i++) {
         if ($i == 0) {
             $strSqlOrder = " ORDER BY ";
         } else {
             $strSqlOrder .= ",";
         }
         $strSqlOrder .= $arSqlOrder[$i];
     }
     $strSql .= $strSqlOrder;
     return $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
 }
Esempio n. 5
0
 * costcodes sincE they are limited in size so saving a costcode as REDACI�N would actually 
 * save REDACI� since the accent takes two characters, so lets unaccent them, other languages 
 * should add to the replacements array too...
*/
function cleanText($text)
{
    //This text file is not utf, its iso so we have to decode/encode
    $text = utf8_decode($text);
    $trade = array('�' => 'a', '�' => 'a', '�' => 'a', '�' => 'a', '�' => 'a', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'A', '�' => 'e', '�' => 'e', '�' => 'e', '�' => 'e', '�' => 'E', '�' => 'E', '�' => 'E', '�' => 'E', '�' => 'i', '�' => 'i', '�' => 'i', '�' => 'i', '�' => 'I', '�' => 'I', '�' => 'I', '�' => 'I', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'o', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'O', '�' => 'u', '�' => 'u', '�' => 'u', '�' => 'u', '�' => 'U', '�' => 'U', '�' => 'U', '�' => 'U', '�' => 'N', '�' => 'n');
    $text = strtr($text, $trade);
    $text = utf8_encode($text);
    return $text;
}
$notify_owner = isset($_POST['task_log_notify_owner']) ? $_POST['task_log_notify_owner'] : 0;
$del = dPgetParam($_POST, 'del', 0);
$obj = new CTaskLog();
if (!$obj->bind($_POST)) {
    $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
    $AppUI->redirect();
}
if ($obj->task_log_date) {
    $date = new CDate($obj->task_log_date);
    $obj->task_log_date = $date->format(FMT_DATETIME_MYSQL);
}
$dot = mb_strpos($obj->task_log_hours, ':');
if ($dot > 0) {
    $log_duration_minutes = sprintf('%.3f', mb_substr($obj->task_log_hours, $dot + 1) / 60.0);
    $obj->task_log_hours = floor($obj->task_log_hours) + $log_duration_minutes;
}
$obj->task_log_hours = round($obj->task_log_hours, 3);
// prepare (and translate) the module name ready for the suffix
Esempio n. 6
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);
 }
Esempio n. 7
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
 }
Esempio n. 8
0
 public static function SendUpdateMessage($arFields, $arTask, $bSpawnedByAgent = false)
 {
     global $USER;
     $isBbCodeDescription = true;
     if (isset($arFields['DESCRIPTION_IN_BBCODE'])) {
         if ($arFields['DESCRIPTION_IN_BBCODE'] === 'N') {
             $isBbCodeDescription = false;
         }
     } elseif (isset($arTask['DESCRIPTION_IN_BBCODE'])) {
         if ($arTask['DESCRIPTION_IN_BBCODE'] === 'N') {
             $isBbCodeDescription = false;
         }
     }
     $taskReassignedTo = null;
     if (isset($arFields['RESPONSIBLE_ID']) && $arFields['RESPONSIBLE_ID'] > 0 && $arFields['RESPONSIBLE_ID'] != $arTask['RESPONSIBLE_ID']) {
         $taskReassignedTo = $arFields['RESPONSIBLE_ID'];
     }
     foreach (array('CREATED_BY', 'RESPONSIBLE_ID', 'ACCOMPLICES', 'AUDITORS', 'TITLE') as $field) {
         if (!isset($arFields[$field]) && isset($arTask[$field])) {
             $arFields[$field] = $arTask[$field];
         }
     }
     $arChanges = CTaskLog::GetChanges($arTask, $arFields);
     $arMerged = array('ADDITIONAL_RECIPIENTS' => array());
     if (isset($arTask['CREATED_BY'])) {
         $arMerged['ADDITIONAL_RECIPIENTS'][] = $arTask['CREATED_BY'];
     }
     if (isset($arTask['RESPONSIBLE_ID'])) {
         $arMerged['ADDITIONAL_RECIPIENTS'][] = $arTask['RESPONSIBLE_ID'];
     }
     if (isset($arTask['ACCOMPLICES']) && is_array($arTask['ACCOMPLICES'])) {
         foreach ($arTask['ACCOMPLICES'] as $userId) {
             $arMerged['ADDITIONAL_RECIPIENTS'][] = $userId;
         }
     }
     if (isset($arTask['AUDITORS']) && is_array($arTask['AUDITORS'])) {
         foreach ($arTask['AUDITORS'] as $userId) {
             $arMerged['ADDITIONAL_RECIPIENTS'][] = $userId;
         }
     }
     if (isset($arFields['ADDITIONAL_RECIPIENTS'])) {
         $arFields['ADDITIONAL_RECIPIENTS'] = array_merge($arFields['ADDITIONAL_RECIPIENTS'], $arMerged['ADDITIONAL_RECIPIENTS']);
     } else {
         $arFields['ADDITIONAL_RECIPIENTS'] = $arMerged['ADDITIONAL_RECIPIENTS'];
     }
     $arUsers = CTaskNotifications::__GetUsers($arFields);
     $arRecipientsIDs = array_unique(CTaskNotifications::GetRecipientsIDs($arFields));
     if (!empty($arRecipientsIDs) && (is_object($USER) && $USER->GetID() || $arFields["CREATED_BY"])) {
         $curUserTzOffset = (int) CTasksTools::getTimeZoneOffset();
         $arInvariantChangesStrs = array();
         $arVolatileDescriptions = array();
         $arRecipientsIDsByTimezone = array();
         $i = 0;
         foreach ($arChanges as $key => $value) {
             ++$i;
             $actionMessage = GetMessage("TASKS_MESSAGE_" . $key);
             if (strlen($actionMessage)) {
                 $tmpStr = $actionMessage . ": [COLOR=#000]";
                 switch ($key) {
                     case 'TIME_ESTIMATE':
                         $tmpStr .= self::formatTimeHHMM($value["FROM_VALUE"], true) . " -> " . self::formatTimeHHMM($value["TO_VALUE"], true);
                         break;
                     case "TITLE":
                         $tmpStr .= $value["FROM_VALUE"] . " -> " . $value["TO_VALUE"];
                         break;
                     case "RESPONSIBLE_ID":
                         $tmpStr .= CTaskNotifications::__Users2String($value["FROM_VALUE"], $arUsers, $arFields["NAME_TEMPLATE"]) . ' -> ' . CTaskNotifications::__Users2String($value["TO_VALUE"], $arUsers, $arFields["NAME_TEMPLATE"]);
                         break;
                     case "ACCOMPLICES":
                     case "AUDITORS":
                         $tmpStr .= CTaskNotifications::__Users2String(explode(",", $value["FROM_VALUE"]), $arUsers, $arFields["NAME_TEMPLATE"]) . ' -> ' . CTaskNotifications::__Users2String(explode(",", $value["TO_VALUE"]), $arUsers, $arFields["NAME_TEMPLATE"]);
                         break;
                     case "DEADLINE":
                     case "START_DATE_PLAN":
                     case "END_DATE_PLAN":
                         // CTasks::Log() returns bitrix timestamps for dates, so adjust them to correct unix timestamps.
                         $utsFromValue = $value['FROM_VALUE'] - $curUserTzOffset;
                         $utsToValue = $value['TO_VALUE'] - $curUserTzOffset;
                         // It will be replaced below to formatted string with correct dates for different timezones
                         $placeholder = '###PLACEHOLDER###' . $i . '###';
                         $tmpStr .= $placeholder;
                         // Collect recipients' timezones
                         foreach ($arRecipientsIDs as $userId) {
                             $tzOffset = (int) CTasksTools::getTimeZoneOffset($userId);
                             if (!isset($arVolatileDescriptions[$tzOffset])) {
                                 $arVolatileDescriptions[$tzOffset] = array();
                             }
                             if (!isset($arVolatileDescriptions[$tzOffset][$placeholder])) {
                                 // Make bitrix timestamps for given user
                                 $bitrixTsFromValue = $utsFromValue + $tzOffset;
                                 $bitrixTsToValue = $utsToValue + $tzOffset;
                                 $description = '';
                                 if ($utsFromValue > 360000) {
                                     $fromValueAsString = FormatDate('^' . CDatabase::DateFormatToPHP(FORMAT_DATETIME), $bitrixTsFromValue);
                                     $description .= $fromValueAsString;
                                 }
                                 $description .= ' --> ';
                                 if ($utsToValue > 360000) {
                                     $toValueAsString = FormatDate('^' . CDatabase::DateFormatToPHP(FORMAT_DATETIME), $bitrixTsToValue);
                                     $description .= $toValueAsString;
                                 }
                                 $arVolatileDescriptions[$tzOffset][$placeholder] = $description;
                             }
                             $arRecipientsIDsByTimezone[$tzOffset][] = $userId;
                         }
                         break;
                     case "DESCRIPTION":
                         $tmpStr .= HTMLToTxt($arFields["DESCRIPTION"]);
                         break;
                     case "TAGS":
                         $tmpStr .= ($value["FROM_VALUE"] ? str_replace(",", ", ", $value["FROM_VALUE"]) . " -> " : "") . ($value["TO_VALUE"] ? str_replace(",", ", ", $value["TO_VALUE"]) : GetMessage("TASKS_MESSAGE_NO_VALUE"));
                         break;
                     case "PRIORITY":
                         $tmpStr .= GetMessage("TASKS_PRIORITY_" . $value["FROM_VALUE"]) . " -> " . GetMessage("TASKS_PRIORITY_" . $value["TO_VALUE"]);
                         break;
                     case "GROUP_ID":
                         if ($value["FROM_VALUE"] && CSocNetGroup::CanUserViewGroup($USER->GetID(), $value["FROM_VALUE"])) {
                             $arGroupFrom = CSocNetGroup::GetByID($value["FROM_VALUE"]);
                             if ($arGroupFrom) {
                                 $tmpStr .= $arGroupFrom["NAME"] . " -> ";
                             }
                         }
                         if ($value["TO_VALUE"] && CSocNetGroup::CanUserViewGroup($USER->GetID(), $value["TO_VALUE"])) {
                             $arGroupTo = CSocNetGroup::GetByID($value["TO_VALUE"]);
                             if ($arGroupTo) {
                                 $tmpStr .= $arGroupTo["NAME"];
                             }
                         } else {
                             $tmpStr .= GetMessage("TASKS_MESSAGE_NO_VALUE");
                         }
                         break;
                     case "PARENT_ID":
                         if ($value["FROM_VALUE"]) {
                             $rsTaskFrom = CTasks::GetList(array(), array("ID" => $value["FROM_VALUE"]), array('ID', 'TITLE'));
                             if ($arTaskFrom = $rsTaskFrom->GetNext()) {
                                 $tmpStr .= $arTaskFrom["TITLE"] . " -> ";
                             }
                         }
                         if ($value["TO_VALUE"]) {
                             $rsTaskTo = CTasks::GetList(array(), array("ID" => $value["TO_VALUE"]), array('ID', 'TITLE'));
                             if ($arTaskTo = $rsTaskTo->GetNext()) {
                                 $tmpStr .= $arTaskTo["TITLE"];
                             }
                         } else {
                             $tmpStr .= GetMessage("TASKS_MESSAGE_NO_VALUE");
                         }
                         break;
                     case "DEPENDS_ON":
                         $arTasksFromStr = array();
                         if ($value["FROM_VALUE"]) {
                             $rsTasksFrom = CTasks::GetList(array(), array("ID" => explode(",", $value["FROM_VALUE"])), array('ID', 'TITLE'));
                             while ($arTaskFrom = $rsTasksFrom->GetNext()) {
                                 $arTasksFromStr[] = $arTaskFrom["TITLE"];
                             }
                         }
                         $arTasksToStr = array();
                         if ($value["TO_VALUE"]) {
                             $rsTasksTo = CTasks::GetList(array(), array("ID" => explode(",", $value["TO_VALUE"])), array('ID', 'TITLE'));
                             while ($arTaskTo = $rsTasksTo->GetNext()) {
                                 $arTasksToStr[] = $arTaskTo["TITLE"];
                             }
                         }
                         $tmpStr .= ($arTasksFromStr ? implode(", ", $arTasksFromStr) . " -> " : "") . ($arTasksToStr ? implode(", ", $arTasksToStr) : GetMessage("TASKS_MESSAGE_NO_VALUE"));
                         break;
                     case "MARK":
                         $tmpStr .= (!$value["FROM_VALUE"] ? GetMessage("TASKS_MARK_NONE") : GetMessage("TASKS_MARK_" . $value["FROM_VALUE"])) . " -> " . (!$value["TO_VALUE"] ? GetMessage("TASKS_MARK_NONE") : GetMessage("TASKS_MARK_" . $value["TO_VALUE"]));
                         break;
                     case "ADD_IN_REPORT":
                         $tmpStr .= ($value["FROM_VALUE"] == "Y" ? GetMessage("TASKS_MESSAGE_IN_REPORT_YES") : GetMessage("TASKS_MESSAGE_IN_REPORT_NO")) . " -> " . ($value["TO_VALUE"] == "Y" ? GetMessage("TASKS_MESSAGE_IN_REPORT_YES") : GetMessage("TASKS_MESSAGE_IN_REPORT_NO"));
                         break;
                     case "DELETED_FILES":
                         $tmpStr .= $value["FROM_VALUE"];
                         $tmpStr .= $value["TO_VALUE"];
                         break;
                     case "NEW_FILES":
                         $tmpStr .= $value["TO_VALUE"];
                         break;
                 }
                 $tmpStr .= "[/COLOR]";
                 $arInvariantChangesStrs[] = $tmpStr;
             }
         }
         $occurAsUserId = CTasksTools::getOccurAsUserId();
         if (!$occurAsUserId) {
             $occurAsUserId = is_object($USER) && $USER->GetID() ? $USER->GetID() : $arFields["CREATED_BY"];
         }
         $invariantDescription = null;
         if (!empty($arInvariantChangesStrs)) {
             $invariantDescription = implode("\r\n", $arInvariantChangesStrs);
         }
         if ($invariantDescription !== null && !empty($arRecipientsIDs)) {
             // If there is no volatile part of descriptions, send to all recipients at once
             if (empty($arVolatileDescriptions)) {
                 $arVolatileDescriptions['some_timezone'] = array();
                 $arRecipientsIDsByTimezone['some_timezone'] = $arRecipientsIDs;
             }
             foreach ($arVolatileDescriptions as $tzOffset => $arVolatileDescriptionsData) {
                 $strDescription = $invariantDescription;
                 foreach ($arVolatileDescriptionsData as $placeholder => $strReplaceTo) {
                     $strDescription = str_replace($placeholder, $strReplaceTo, $strDescription);
                 }
                 $message = str_replace(array("#TASK_TITLE#", "#TASK_EXTRA#"), array(self::formatTaskName($arTask['ID'], $arTask['TITLE'], $arTask['GROUP_ID'], true), $strDescription), GetMessage("TASKS_TASK_CHANGED_MESSAGE"));
                 if ($isBbCodeDescription) {
                     $parser = new CTextParser();
                     $htmlDescription = str_replace("\t", ' &nbsp; &nbsp;', $parser->convertText($strDescription));
                 } else {
                     $htmlDescription = $strDescription;
                 }
                 $message_email = str_replace(array("#TASK_TITLE#", "#TASK_EXTRA#"), array(self::formatTaskName($arTask['ID'], $arTask['TITLE'], $arTask['GROUP_ID']), $htmlDescription . "\r\n" . GetMessage('TASKS_MESSAGE_LINK') . ': #PATH_TO_TASK#'), GetMessage("TASKS_TASK_CHANGED_MESSAGE"));
                 CTaskNotifications::SendMessage($occurAsUserId, $arRecipientsIDsByTimezone[$tzOffset], $message, $arTask["ID"], $message_email, array('ACTION' => 'TASK_UPDATE', 'arFields' => $arFields, 'arChanges' => $arChanges), $taskReassignedTo);
             }
         }
     }
     // sonet log
     self::SendMessageToSocNet($arFields, $bSpawnedByAgent, $arChanges, $arTask);
 }
Esempio n. 9
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
 }
Esempio n. 10
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;
 }
Esempio n. 11
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);
 }
Esempio n. 12
0
         $arResult["CHILDREN_COUNT"]["PARENT_" . $arChildrenCount["PARENT_ID"]] = $arChildrenCount["CNT"];
     }
 }
 // groups
 $arResult["GROUPS"] = array();
 $arOpenedProjects = CUserOptions::GetOption("tasks", "opened_projects", array());
 if ($arResult["TASK_TYPE"] != "group" && sizeof($arGroupsIDs)) {
     $rsGroups = CSocNetGroup::GetList(array("ID" => "ASC"), array("ID" => $arGroupsIDs));
     while ($arGroup = $rsGroups->GetNext()) {
         $arGroup["EXPANDED"] = array_key_exists($arGroup["ID"], $arOpenedProjects) && $arOpenedProjects[$arGroup["ID"]] == "false" ? false : true;
         $arResult["GROUPS"][$arGroup["ID"]] = $arGroup;
     }
 }
 // log
 $arResult["LOG"] = array();
 $rsLog = CTaskLog::GetList(array('CREATED_DATE' => 'DESC'), array("TASK_ID" => $arResult["TASK"]["ID"]));
 $bTzWasDisabled = !CTimeZone::enabled();
 if ($bTzWasDisabled) {
     CTimeZone::enable();
 }
 $tzOffset = CTimeZone::getOffset();
 if ($bTzWasDisabled) {
     CTimeZone::disable();
 }
 while ($arLog = $rsLog->GetNext()) {
     // Adjust unix timestamps to "bitrix timestamps"
     if (isset(CTaskLog::$arComparedFields[$arLog['FIELD']]) && CTaskLog::$arComparedFields[$arLog['FIELD']] === 'date') {
         $arLog['~TO_VALUE'] = $arLog['TO_VALUE'] = $arLog['TO_VALUE'] + $tzOffset;
         $arLog['~FROM_VALUE'] = $arLog['FROM_VALUE'] = $arLog['FROM_VALUE'] + $tzOffset;
     }
     $arResult["LOG"][] = $arLog;
Esempio n. 13
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);
 }
Esempio n. 14
0
<?php

/* $Id: do_updatetask.php 2016 2011-08-07 07:08:46Z caseydk $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/tags/version2.4/modules/tasks/do_updatetask.php $ */
if (!defined('W2P_BASE_DIR')) {
    die('You should not access this file directly.');
}
$del = (int) w2PgetParam($_POST, 'del', 0);
$notify_owner = w2PgetParam($_POST, 'task_log_notify_owner', 'off');
$isNotNew = (int) w2PgetParam($_POST, 'task_log_id', 0);
$obj = new CTaskLog();
if (!$obj->bind($_POST)) {
    $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
    $AppUI->redirect();
}
$action = $del ? 'deleted' : 'stored';
$result = $del ? $obj->delete($AppUI) : $obj->store($AppUI);
if (is_array($result)) {
    $AppUI->setMsg($result, UI_MSG_ERROR, true);
    $AppUI->holdObject($obj);
    $AppUI->redirect('m=tasks&a=view&task_id=' . $obj->task_log_task);
}
if ($result) {
    $AppUI->setMsg('Task Log ' . $action, UI_MSG_OK, true);
    $task = new CTask();
    $task->load($obj->task_log_task);
    if ('on' == $notify_owner) {
        if ($msg = $task->notifyOwner()) {
            $AppUI->setMsg($msg, UI_MSG_ERROR);
        }
    }
    // Check if we need to email the task log to anyone.
Esempio n. 15
0
 public static function SendUpdateMessage($arFields, $arTask, $bSpawnedByAgent = false, array $parameters = array())
 {
     global $USER;
     $occurAsUserId = self::getOccurAsUserId($arFields, $arTask, $bSpawnedByAgent, $parameters);
     $effectiveUserId = self::getEffectiveUserId($arFields, $arTask, $bSpawnedByAgent, $parameters);
     // generally, $occurAsUserId === $effectiveUserId, but sometimes dont
     /*
     $bSpawnedByAgent === true means that this task was "created\updated" on angent, and 
     in case of that, message author is defined as $arTask['CRAETED_BY'] (below)
     */
     if (!$bSpawnedByAgent && $parameters['THROTTLE_MESSAGES']) {
         AgentManager::checkAgentIsAlive("notificationThrottleRelease()", 300);
         ThrottleTable::submitUpdateMessage($arTask['ID'], $occurAsUserId, $arTask, $arFields);
         return;
     }
     $isBbCodeDescription = true;
     if (isset($arFields['DESCRIPTION_IN_BBCODE'])) {
         if ($arFields['DESCRIPTION_IN_BBCODE'] === 'N') {
             $isBbCodeDescription = false;
         }
     } elseif (isset($arTask['DESCRIPTION_IN_BBCODE'])) {
         if ($arTask['DESCRIPTION_IN_BBCODE'] === 'N') {
             $isBbCodeDescription = false;
         }
     }
     $taskReassignedTo = null;
     if (isset($arFields['RESPONSIBLE_ID']) && $arFields['RESPONSIBLE_ID'] > 0 && $arFields['RESPONSIBLE_ID'] != $arTask['RESPONSIBLE_ID']) {
         $taskReassignedTo = $arFields['RESPONSIBLE_ID'];
     }
     foreach (array('CREATED_BY', 'RESPONSIBLE_ID', 'ACCOMPLICES', 'AUDITORS', 'TITLE') as $field) {
         if (!isset($arFields[$field]) && isset($arTask[$field])) {
             $arFields[$field] = $arTask[$field];
         }
     }
     $cacheWasEnabled = self::enableStaticCache();
     // $arChanges contains datetimes IN SERVER TIME, NOT CLIENT
     $arChanges = CTaskLog::GetChanges($arTask, $arFields);
     $arMerged = array('ADDITIONAL_RECIPIENTS' => array());
     if (isset($arTask['CREATED_BY'])) {
         $arMerged['ADDITIONAL_RECIPIENTS'][] = $arTask['CREATED_BY'];
     }
     if (isset($arTask['RESPONSIBLE_ID'])) {
         $arMerged['ADDITIONAL_RECIPIENTS'][] = $arTask['RESPONSIBLE_ID'];
     }
     if (isset($arTask['ACCOMPLICES']) && is_array($arTask['ACCOMPLICES'])) {
         foreach ($arTask['ACCOMPLICES'] as $userId) {
             $arMerged['ADDITIONAL_RECIPIENTS'][] = $userId;
         }
     }
     if (isset($arTask['AUDITORS']) && is_array($arTask['AUDITORS'])) {
         foreach ($arTask['AUDITORS'] as $userId) {
             $arMerged['ADDITIONAL_RECIPIENTS'][] = $userId;
         }
     }
     if (isset($arFields['ADDITIONAL_RECIPIENTS'])) {
         $arFields['ADDITIONAL_RECIPIENTS'] = array_merge($arFields['ADDITIONAL_RECIPIENTS'], $arMerged['ADDITIONAL_RECIPIENTS']);
     } else {
         $arFields['ADDITIONAL_RECIPIENTS'] = $arMerged['ADDITIONAL_RECIPIENTS'];
     }
     $arUsers = CTaskNotifications::__GetUsers($arFields);
     $ignoreAuthor = isset($parameters['IGNORE_AUTHOR']) ? !!$parameters['IGNORE_AUTHOR'] : true;
     $arRecipientsIDs = array_unique(CTaskNotifications::GetRecipientsIDs($arFields, $ignoreAuthor, false, $occurAsUserId));
     if (!empty($arRecipientsIDs) && (is_object($USER) && $USER->GetID() || $arFields["CREATED_BY"])) {
         $curUserTzOffset = (int) self::getUserTimeZoneOffset();
         $arInvariantChangesStrs = array();
         $arVolatileDescriptions = array();
         $arRecipientsIDsByTimezone = array();
         $i = 0;
         foreach ($arChanges as $key => $value) {
             ++$i;
             $actionMessage = GetMessage("TASKS_MESSAGE_" . $key);
             if (strlen($actionMessage)) {
                 $changeMessage = $actionMessage;
                 $tmpStr = '';
                 switch ($key) {
                     case 'TIME_ESTIMATE':
                         $tmpStr .= self::formatTimeHHMM($value["FROM_VALUE"], true) . " -> " . self::formatTimeHHMM($value["TO_VALUE"], true);
                         break;
                     case "TITLE":
                         $tmpStr .= $value["FROM_VALUE"] . " -> " . $value["TO_VALUE"];
                         break;
                     case "RESPONSIBLE_ID":
                         $tmpStr .= CTaskNotifications::__Users2String($value["FROM_VALUE"], $arUsers, $arFields["NAME_TEMPLATE"]) . ' -> ' . CTaskNotifications::__Users2String($value["TO_VALUE"], $arUsers, $arFields["NAME_TEMPLATE"]);
                         break;
                     case "ACCOMPLICES":
                     case "AUDITORS":
                         $tmpStr .= CTaskNotifications::__Users2String(explode(",", $value["FROM_VALUE"]), $arUsers, $arFields["NAME_TEMPLATE"]) . ' -> ' . CTaskNotifications::__Users2String(explode(",", $value["TO_VALUE"]), $arUsers, $arFields["NAME_TEMPLATE"]);
                         break;
                     case "DEADLINE":
                     case "START_DATE_PLAN":
                     case "END_DATE_PLAN":
                         // $arChanges ALREADY contains server time, no need to substract user timezone again
                         $utsFromValue = $value['FROM_VALUE'];
                         // - $curUserTzOffset;
                         $utsToValue = $value['TO_VALUE'];
                         // - $curUserTzOffset;
                         // It will be replaced below to formatted string with correct dates for different timezones
                         $placeholder = '###PLACEHOLDER###' . $i . '###';
                         $tmpStr .= $placeholder;
                         // Collect recipients' timezones
                         foreach ($arRecipientsIDs as $userId) {
                             $tzOffset = (int) self::getUserTimeZoneOffset($userId);
                             if (!isset($arVolatileDescriptions[$tzOffset])) {
                                 $arVolatileDescriptions[$tzOffset] = array();
                             }
                             if (!isset($arVolatileDescriptions[$tzOffset][$placeholder])) {
                                 // Make bitrix timestamps for given user
                                 $bitrixTsFromValue = $utsFromValue + $tzOffset;
                                 $bitrixTsToValue = $utsToValue + $tzOffset;
                                 $description = '';
                                 if ($utsFromValue > 360000) {
                                     $fromValueAsString = FormatDate('^' . CDatabase::DateFormatToPHP(FORMAT_DATETIME), $bitrixTsFromValue);
                                     $description .= $fromValueAsString;
                                 }
                                 $description .= ' --> ';
                                 if ($utsToValue > 360000) {
                                     $toValueAsString = FormatDate('^' . CDatabase::DateFormatToPHP(FORMAT_DATETIME), $bitrixTsToValue);
                                     $description .= $toValueAsString;
                                 }
                                 $arVolatileDescriptions[$tzOffset][$placeholder] = $description;
                             }
                             $arRecipientsIDsByTimezone[$tzOffset][] = $userId;
                         }
                         break;
                     case "DESCRIPTION":
                         $tmpStr .= HTMLToTxt($arFields["DESCRIPTION"]);
                         break;
                     case "TAGS":
                         $tmpStr .= ($value["FROM_VALUE"] ? str_replace(",", ", ", $value["FROM_VALUE"]) . " -> " : "") . ($value["TO_VALUE"] ? str_replace(",", ", ", $value["TO_VALUE"]) : GetMessage("TASKS_MESSAGE_NO_VALUE"));
                         break;
                     case "PRIORITY":
                         $tmpStr .= GetMessage("TASKS_PRIORITY_" . $value["FROM_VALUE"]) . " -> " . GetMessage("TASKS_PRIORITY_" . $value["TO_VALUE"]);
                         break;
                     case "GROUP_ID":
                         if ($value["FROM_VALUE"] && self::checkUserCanViewGroup($effectiveUserId, $value["FROM_VALUE"])) {
                             $arGroupFrom = self::getSocNetGroup($value["FROM_VALUE"]);
                             if ($arGroupFrom) {
                                 $tmpStr .= $arGroupFrom["NAME"] . " -> ";
                             }
                         }
                         if ($value["TO_VALUE"] && self::checkUserCanViewGroup($effectiveUserId, $value["TO_VALUE"])) {
                             $arGroupTo = self::getSocNetGroup($value["TO_VALUE"]);
                             if ($arGroupTo) {
                                 $tmpStr .= $arGroupTo["NAME"];
                             }
                         } else {
                             $tmpStr .= GetMessage("TASKS_MESSAGE_NO_VALUE");
                         }
                         break;
                     case "PARENT_ID":
                         if ($value["FROM_VALUE"]) {
                             $rsTaskFrom = CTasks::GetList(array(), array("ID" => $value["FROM_VALUE"]), array('ID', 'TITLE'));
                             if ($arTaskFrom = $rsTaskFrom->GetNext()) {
                                 $tmpStr .= $arTaskFrom["TITLE"] . " -> ";
                             }
                         }
                         if ($value["TO_VALUE"]) {
                             $rsTaskTo = CTasks::GetList(array(), array("ID" => $value["TO_VALUE"]), array('ID', 'TITLE'));
                             if ($arTaskTo = $rsTaskTo->GetNext()) {
                                 $tmpStr .= $arTaskTo["TITLE"];
                             }
                         } else {
                             $tmpStr .= GetMessage("TASKS_MESSAGE_NO_VALUE");
                         }
                         break;
                     case "DEPENDS_ON":
                         $arTasksFromStr = array();
                         if ($value["FROM_VALUE"]) {
                             $rsTasksFrom = CTasks::GetList(array(), array("ID" => explode(",", $value["FROM_VALUE"])), array('ID', 'TITLE'));
                             while ($arTaskFrom = $rsTasksFrom->GetNext()) {
                                 $arTasksFromStr[] = $arTaskFrom["TITLE"];
                             }
                         }
                         $arTasksToStr = array();
                         if ($value["TO_VALUE"]) {
                             $rsTasksTo = CTasks::GetList(array(), array("ID" => explode(",", $value["TO_VALUE"])), array('ID', 'TITLE'));
                             while ($arTaskTo = $rsTasksTo->GetNext()) {
                                 $arTasksToStr[] = $arTaskTo["TITLE"];
                             }
                         }
                         $tmpStr .= ($arTasksFromStr ? implode(", ", $arTasksFromStr) . " -> " : "") . ($arTasksToStr ? implode(", ", $arTasksToStr) : GetMessage("TASKS_MESSAGE_NO_VALUE"));
                         break;
                     case "MARK":
                         $tmpStr .= (!$value["FROM_VALUE"] ? GetMessage("TASKS_MARK_NONE") : GetMessage("TASKS_MARK_" . $value["FROM_VALUE"])) . " -> " . (!$value["TO_VALUE"] ? GetMessage("TASKS_MARK_NONE") : GetMessage("TASKS_MARK_" . $value["TO_VALUE"]));
                         break;
                     case "ADD_IN_REPORT":
                         $tmpStr .= ($value["FROM_VALUE"] == "Y" ? GetMessage("TASKS_MESSAGE_IN_REPORT_YES") : GetMessage("TASKS_MESSAGE_IN_REPORT_NO")) . " -> " . ($value["TO_VALUE"] == "Y" ? GetMessage("TASKS_MESSAGE_IN_REPORT_YES") : GetMessage("TASKS_MESSAGE_IN_REPORT_NO"));
                         break;
                     case "DELETED_FILES":
                         $tmpStr .= $value["FROM_VALUE"];
                         $tmpStr .= $value["TO_VALUE"];
                         break;
                     case "NEW_FILES":
                         $tmpStr .= $value["TO_VALUE"];
                         break;
                 }
                 if ((string) $tmpStr != '') {
                     $changeMessage .= ": [COLOR=#000]" . $tmpStr . "[/COLOR]";
                 }
                 $arInvariantChangesStrs[] = $changeMessage;
             }
         }
         $recp2tz = array();
         foreach ($arRecipientsIDsByTimezone as $tz => $rcp) {
             foreach ($rcp as $uid) {
                 $recp2tz[$uid] = $tz;
             }
         }
         $invariantDescription = null;
         if (!empty($arInvariantChangesStrs)) {
             $invariantDescription = implode("\r\n", $arInvariantChangesStrs);
         }
         if ($invariantDescription !== null && !empty($arRecipientsIDs)) {
             // If there is no volatile part of descriptions, send to all recipients at once
             if (empty($arVolatileDescriptions)) {
                 $arVolatileDescriptions['some_timezone'] = array();
                 $arRecipientsIDsByTimezone['some_timezone'] = $arRecipientsIDs;
             }
             $updateMessage = self::getGenderMessage($occurAsUserId, 'TASKS_TASK_CHANGED_MESSAGE');
             $taskName = self::formatTaskName($arTask['ID'], $arTask['TITLE'], $arTask['GROUP_ID'], false);
             $instant = str_replace(array("#TASK_TITLE#"), array($taskName), $updateMessage);
             $email = str_replace(array("#TASK_TITLE#"), array(strip_tags($taskName)), $updateMessage);
             //_dump_r('Sending UPDATE from '.$occurAsUserId.' TO '.implode(':', $arRecipientsIDs));
             CTaskNotifications::sendMessageEx($arTask["ID"], $occurAsUserId, $arRecipientsIDs, array('INSTANT' => $instant, 'EMAIL' => $email, 'PUSH' => self::makePushMessage('TASKS_TASK_CHANGED_MESSAGE', $occurAsUserId, $arTask)), array('EVENT_DATA' => array('ACTION' => 'TASK_UPDATE', 'arFields' => $arFields, 'arChanges' => $arChanges), 'TASK_ASSIGNED_TO' => $taskReassignedTo, 'CALLBACK' => array('BEFORE_SEND' => function ($message) use($isBbCodeDescription, $invariantDescription, $arVolatileDescriptions, $recp2tz) {
                 $rcp = $message['TO_USER_IDS'][0];
                 $volatile = $arVolatileDescriptions[$recp2tz[$rcp]];
                 if (is_array($volatile)) {
                     $description = str_replace(array_keys($volatile), $volatile, $invariantDescription);
                 } else {
                     $description = $invariantDescription;
                 }
                 $message['MESSAGE']['INSTANT'] = str_replace(array("#TASK_EXTRA#"), array($description), $message['MESSAGE']['INSTANT']);
                 if ($isBbCodeDescription) {
                     $parser = new CTextParser();
                     $description = str_replace("\t", ' &nbsp; &nbsp;', $parser->convertText($description));
                 }
                 $message['MESSAGE']['EMAIL'] = str_replace(array("#TASK_EXTRA#"), array($description), $message['MESSAGE']['EMAIL']);
                 return $message;
             })));
         }
     }
     // sonet log
     self::SendMessageToSocNet($arFields, $bSpawnedByAgent, $arChanges, $arTask, $parameters);
     if ($cacheWasEnabled) {
         self::disableStaticCache();
     }
 }
Esempio n. 16
0
                     '?E=>'o','?E=>'o',
                     'Ó'=>'O','Ò'=>'O','Õ'=>'O',
                     'Ö'=>'O','Ô'=>'O',
                     '?E=>'u','?E=>'u',
                     '?E=>'u','?E=>'u',
                     'Ú'=>'U','Ù'=>'U',
                     'Ü'=>'U','Û'=>'U',
                     'Ñ'=>'N','?E=>'n');
        $text = strtr($text,$trade);
    	$text = utf8_encode($text);
    */
    return $text;
}
require_once $AppUI->getModuleClass('tasks');
$del = dPgetParam($_POST, 'del', 0);
$obj = new CTaskLog();
if (!$obj->bind($_POST)) {
    $AppUI->setMsg($obj->getError(), UI_MSG_ERROR);
    $AppUI->redirect();
}
if ($obj->task_log_date) {
    $date = new CDate($obj->task_log_date);
    $obj->task_log_date = $date->format(FMT_DATETIME_MYSQL);
}
// prepare (and translate) the module name ready for the suffix
$AppUI->setMsg('Task Log');
if ($del) {
    if ($msg = $obj->delete()) {
        $AppUI->setMsg($msg, UI_MSG_ERROR);
    } else {
        $AppUI->setMsg("deleted", UI_MSG_ALERT);
Esempio n. 17
0
<?php

/* TASKS $Id: vw_log_update.php,v 1.1 2007/08/22 07:47:47 arcoz67 Exp $ */
if (!defined('DP_BASE_DIR')) {
    die('You should not access this file directly.');
}
global $AppUI, $task_id, $obj, $percent, $can_edit_time_information;
$perms =& $AppUI->acl();
// check permissions
$canEdit = $perms->checkModuleItem('task_log', 'edit', $task_id);
$canAdd = $perms->checkModuleItem('task_log', 'add', $task_id);
$task_log_id = intval(dPgetParam($_GET, 'task_log_id', 0));
$log = new CTaskLog();
if ($task_log_id) {
    if (!$canEdit) {
        $AppUI->redirect("m=public&a=access_denied");
    }
    $log->load($task_log_id);
} else {
    if (!$canAdd) {
        $AppUI->redirect("m=public&a=access_denied");
    }
    $log->task_log_task = $task_id;
    $log->task_log_name = $obj->task_name;
}
// Check that the user is at least assigned to a task
$task = new CTask();
$task->load($task_id);
if (!$task->canAccess($AppUI->user_id)) {
    $AppUI->redirect('m=public&a=access_denied');
}
Esempio n. 18
0
$arParams = array();
$arParams["NAME_TEMPLATE"] = $nameTemplate;
$loggedInUserId = 0;
if (isset($GLOBALS['USER']) && is_object($GLOBALS['USER']) && $GLOBALS['USER']->isAuthorized()) {
    $loggedInUserId = (int) $GLOBALS['USER']->GetID();
}
if (check_bitrix_sessid() && $loggedInUserId > 0) {
    $action = '';
    if (isset($_GET['action'])) {
        $action = $_GET['action'];
    }
    if ($action === 'render_task_log_last_row_with_date_change') {
        $arParams["PATH_TO_USER_PROFILE"] = (string) $_POST["PATH_TO_USER_PROFILE"];
        $authorUserId = (int) $loggedInUserId;
        $taskId = (int) $_POST['task_id'];
        $rsLog = CTaskLog::GetList(array('CREATED_DATE' => 'DESC'), array("TASK_ID" => $taskId));
        $arData = false;
        while ($arLog = $rsLog->GetNext()) {
            // wait for DEADLINE field
            if ($arLog['FIELD'] !== 'DEADLINE') {
                continue;
            }
            // Yeah, we found it!
            $arData = $arLog;
            break;
        }
        // If row found
        if ($arData !== false) {
            $rsCurUserData = $USER->GetByID($authorUserId);
            $arCurUserData = $rsCurUserData->Fetch();
            $strDateFrom = $strDateTo = '';
Esempio n. 19
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);
                 }
             }
         }
     }
 }
Esempio n. 20
0
 /**
  * @param $ID
  *
  * This method MUST be called after sync with all Outlook clients.
  * We can't determine such moment, so we should terminate zombies
  * for some time after task been deleted.
  */
 private static function terminateZombie($ID)
 {
     global $DB, $USER_FIELD_MANAGER;
     $res = CTasks::GetList(array(), array('ID' => (int) $ID, 'ZOMBIE' => 'Y'), array('ID'), array('bGetZombie' => true));
     if ($res && ($task = $res->fetch())) {
         CTaskCheckListItem::deleteByTaskId($ID);
         CTaskLog::DeleteByTaskId($ID);
         $USER_FIELD_MANAGER->Delete("TASKS_TASK", $ID);
         $strSql = "DELETE FROM b_tasks WHERE ID = " . (int) $ID;
         $DB->query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
 }