Пример #1
0
 public static function GetStorageTypeID($ID)
 {
     $ID = intval($ID);
     $dbRes = CCrmActivity::GetList(array(), array('ID' => $ID), false, false, array('STORAGE_TYPE_ID'));
     $arRes = $dbRes->Fetch();
     return is_array($arRes) && isset($arRes['STORAGE_TYPE_ID']) ? intval($arRes['STORAGE_TYPE_ID']) : StorageType::Undefined;
 }
Пример #2
0
 /**
  * This is not a part of public API.
  * This function is for internal use only.
  *
  * @access private
  */
 public static function onAfterCommentUpdate($entityType, $taskID, $arData)
 {
     // 'TK' is our entity type
     if ($entityType !== 'TK') {
         return;
     }
     if (empty($arData["MESSAGE_ID"])) {
         return;
     }
     $arMessage = false;
     if (CModule::IncludeModule("socialnetwork")) {
         $parser = new CTextParser();
         $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");
         $oTask = CTaskItem::getInstance($taskID, CTasksTools::GetCommanderInChief());
         $arTask = $oTask->getData();
         $bCrmTask = isset($arTask["UF_CRM_TASK"]) && (is_array($arTask["UF_CRM_TASK"]) && (isset($arTask["UF_CRM_TASK"][0]) && strlen($arTask["UF_CRM_TASK"][0]) > 0) || !is_array($arTask["UF_CRM_TASK"]) && strlen($arTask["UF_CRM_TASK"]) > 0);
         switch ($arData["ACTION"]) {
             case "DEL":
             case "HIDE":
                 $dbLogComment = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => $bCrmTask ? array('crm_activity_add_comment') : array('tasks_comment'), "SOURCE_ID" => intval($arData["MESSAGE_ID"])), false, false, array("ID"));
                 while ($arLogComment = $dbLogComment->Fetch()) {
                     CSocNetLogComments::Delete($arLogComment["ID"]);
                 }
                 break;
             case "SHOW":
                 $dbLogComment = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => $bCrmTask ? array('crm_activity_add_comment') : array('tasks_comment'), "SOURCE_ID" => intval($arData["MESSAGE_ID"])), false, false, array("ID"));
                 $arLogComment = $dbLogComment->Fetch();
                 if (!$arLogComment) {
                     $arMessage = CForumMessage::GetByID(intval($arData["MESSAGE_ID"]));
                     if ($arMessage) {
                         $arFilter = false;
                         if (!$bCrmTask) {
                             $arFilter = array("EVENT_ID" => "tasks", "SOURCE_ID" => $taskID);
                         } elseif (CModule::IncludeModule("crm")) {
                             $dbCrmActivity = CCrmActivity::GetList(array(), array('TYPE_ID' => CCrmActivityType::Task, 'ASSOCIATED_ENTITY_ID' => $taskID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID'));
                             if ($arCrmActivity = $dbCrmActivity->Fetch()) {
                                 $arFilter = array("EVENT_ID" => "crm_activity_add", "ENTITY_ID" => $arCrmActivity["ID"]);
                             }
                         }
                         if ($arFilter) {
                             $dbLog = CSocNetLog::GetList(array("ID" => "DESC"), $arFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
                             if ($arLog = $dbLog->Fetch()) {
                                 $log_id = $arLog["ID"];
                                 $entity_type = $arLog["ENTITY_TYPE"];
                                 $entity_id = $arLog["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" => $arTask["TITLE"], "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $taskID, "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $taskID), "PARAMS" => serialize(array("TYPE" => "create")));
                                     $log_id = CSocNetLog::Add($arSoFields, false);
                                     if (intval($log_id) > 0) {
                                         $arRights = CTaskNotifications::__UserIDs2Rights(self::getTaskMembersByTaskId($taskID));
                                         if ($arTask["GROUP_ID"]) {
                                             $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"];
                                         }
                                         CSocNetLogRights::Add($log_id, $arRights);
                                     }
                                 }
                             }
                         }
                         if ($log_id > 0) {
                             $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"];
                             $strURL = $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result"));
                             $strURL = ForumAddPageParams($strURL, array("MID" => intval($arData["MESSAGE_ID"]), "result" => "reply"), false, false);
                             $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => $bCrmTask ? 'crm_activity_add_comment' : '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" => intval($arData["MESSAGE_ID"]), "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => intval($arData["MESSAGE_ID"]));
                             $arFieldsForSocnet["USER_ID"] = $arMessage["AUTHOR_ID"];
                             $arFieldsForSocnet["=LOG_DATE"] = $GLOBALS["DB"]->CurrentTimeFunction();
                             $ufFileID = array();
                             $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => intval($arData["MESSAGE_ID"])));
                             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", intval($arData["MESSAGE_ID"]), LANGUAGE_ID);
                             if ($ufDocID) {
                                 $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
                             }
                             $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                             CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
                         }
                     }
                 }
                 break;
             case "EDIT":
                 $arMessage = CForumMessage::GetByID(intval($arData["MESSAGE_ID"]));
                 if ($arMessage) {
                     $dbLogComment = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => $bCrmTask ? 'crm_activity_add_comment' : 'tasks_comment', "SOURCE_ID" => intval($arData["MESSAGE_ID"])), false, false, array("ID", "LOG_ID"));
                     $arLogComment = $dbLogComment->Fetch();
                     if ($arLogComment) {
                         $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"];
                         $arFieldsForSocnet = array("LOG_ID" => intval($arLogComment["LOG_ID"]), "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText));
                         $ufFileID = array();
                         $arFilesIds = array();
                         $taskId = null;
                         if (isset($arData['PARAMS']['PARAM2']) && !empty($arData['PARAMS']['PARAM2'])) {
                             $taskId = (int) $arData['PARAMS']['PARAM2'];
                         }
                         $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => intval($arData["MESSAGE_ID"])));
                         while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                             $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                             $arFilesIds[] = $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", intval($arData["MESSAGE_ID"]), LANGUAGE_ID);
                         if ($ufDocID) {
                             $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
                             if (is_array($ufDocID)) {
                                 $arFilesIds = array_merge($arFilesIds, $ufDocID);
                             }
                         }
                         $ufUrlPreview = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MES_URL_PRV", intval($arData["MESSAGE_ID"]), LANGUAGE_ID);
                         if ($ufUrlPreview) {
                             $arFieldsForSocnet["UF_SONET_COM_URL_PRV"] = $ufUrlPreview;
                         }
                         if ($taskId && !empty($arFilesIds)) {
                             self::addFilesRights($taskId, $arFilesIds);
                         }
                         CSocNetLogComments::Update($arLogComment["ID"], $arFieldsForSocnet);
                     }
                 }
                 break;
             default:
         }
     }
     // add records to log. only EDIT and DEL actions handled
     // here may be edit or delete
     if ($arData['ACTION'] == 'EDIT' || $arData['ACTION'] == 'DEL') {
         $messageAuthorId = null;
         $messageEditDate = null;
         $messagePostDate = null;
         if ($arData['ACTION'] == 'EDIT') {
             if (array_key_exists('AUTHOR_ID', $arData['PARAMS']) && array_key_exists('EDIT_DATE', $arData['PARAMS']) && array_key_exists('POST_DATE', $arData['PARAMS'])) {
                 $messageAuthorId = $arData['PARAMS']['AUTHOR_ID'];
                 $messageEditDate = $arData['PARAMS']['EDIT_DATE'];
                 $messageEditDate = $arData['PARAMS']['POST_DATE'];
             } else {
                 if ($arMessage === false) {
                     $arMessage = CForumMessage::GetByID($messageId);
                 }
                 $messageAuthorId = $arMessage['AUTHOR_ID'];
                 $messageEditDate = $arMessage['EDIT_DATE'];
                 $messageEditDate = $arMessage['POST_DATE'];
             }
             $createdDate = $messageEditDate ? ConvertTimeStamp(MakeTimeStamp($messageEditDate, CSite::GetDateFormat()), "FULL") : $messagePostDate;
         } else {
             // in case of DEL action, there is no PARAMS passed in $arData, so this is a temporal fix
             $messageAuthorId = is_object($GLOBALS['USER']) && method_exists($GLOBALS['USER'], 'getId') ? $GLOBALS['USER']->getId() : CTasksTools::GetCommanderInChief();
             //$arData['PARAMS']['AUTHOR_ID'];
             $createdDate = ConvertTimeStamp(time(), "FULL");
         }
         // Tasks log
         $arLogFields = array("TASK_ID" => (int) $taskID, "USER_ID" => static::getOccurAsUserId($messageAuthorId), "CREATED_DATE" => $createdDate, "FIELD" => "COMMENT_" . $arData['ACTION'], "TO_VALUE" => $arData['MESSAGE_ID']);
         $log = new CTaskLog();
         $log->Add($arLogFields);
     }
 }
Пример #3
0
     $arResult["arLogTmpID"][] = $arEventsID["ID"];
     $arTmpEventsNew[] = $arEventsID;
     if (in_array($arEventsID["EVENT_ID"], array("blog_post", "blog_post_important", "idea")) && intval($arEventsID["SOURCE_ID"]) > 0) {
         $arDiskUFEntity["BLOG_POST"][] = $arEventsID["SOURCE_ID"];
     } elseif (!in_array($arEventsID["EVENT_ID"], array("data", "photo", "photo_photo", "bitrix24_new_user", "intranet_new_user", "news"))) {
         $arDiskUFEntity["SONET_LOG"][] = $arEventsID["ID"];
     }
 }
 if (isset($arDiskUFEntity) && (!empty($arDiskUFEntity["SONET_LOG"]) || !empty($arDiskUFEntity["BLOG_POST"]))) {
     $events = GetModuleEvents("socialnetwork", "OnAfterFetchDiskUfEntity");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array($arDiskUFEntity));
     }
 }
 if (!empty($arActivity2Log) && CModule::IncludeModule('crm') && CModule::IncludeModule('tasks')) {
     $rsActivity = CCrmActivity::GetList(array(), array("@ID" => array_keys($arActivity2Log), "TYPE_ID" => CCrmActivityType::Task, "CHECK_PERMISSIONS" => "N"), false, false, array("ID", "ASSOCIATED_ENTITY_ID"));
     while (($arActivity = $rsActivity->Fetch()) && intval($arActivity["ASSOCIATED_ENTITY_ID"]) > 0) {
         $taskItem = new CTaskItem(intval($arActivity["ASSOCIATED_ENTITY_ID"]), $GLOBALS["USER"]->GetId());
         if (!$taskItem->CheckCanRead()) {
             unset($arActivity2Log[$arActivity["ID"]]);
         }
     }
 }
 if ($bFirstPage) {
     $last_date = $arTmpEventsNew[count($arTmpEventsNew) - 1][$arParams["USE_FOLLOW"] == "Y" ? "DATE_FOLLOW" : "LOG_UPDATE"];
 } elseif ($dbEventsID && $dbEventsID->NavContinue() && ($arEvents = $dbEventsID->GetNext())) {
     $next_page_date = $arParams["USE_FOLLOW"] == "Y" ? $arEvents["DATE_FOLLOW"] : $arEvents["LOG_UPDATE"];
     if ($GLOBALS["USER"]->IsAuthorized() && $arResult["LAST_LOG_TS"] < MakeTimeStamp($next_page_date)) {
         $next_page_date = $arResult["LAST_LOG_TS"];
     }
 }
Пример #4
0
    $arResult['GRID_FILTER_NAME'] = '';
}
if (isset($filter['SUBJECT'])) {
    if ($filter['SUBJECT'] !== '') {
        $filter['%SUBJECT'] = $arResult['SEARCH_VALUE'] = $filter['SUBJECT'];
    }
    unset($filter['SUBJECT']);
}
if ($entityTypeID > 0 && $entityID > 0) {
    $arResult['RUBRIC']['ENABLED'] = true;
    $filter['BINDINGS'] = array(array('OWNER_TYPE_ID' => $entityTypeID, 'OWNER_ID' => $entityID));
    $arResult['RUBRIC']['TITLE'] = CCrmOwnerType::GetCaption($entityTypeID, $entityID);
    $arResult['RUBRIC']['FILTER_PRESETS'] = array('clear_filter', 'filter_not_completed', 'filter_completed');
}
$arResult['ITEMS'] = array();
$dbRes = CCrmActivity::GetList($sort, $filter, false, $navParams, $select);
$dbRes->NavStart($navParams['nPageSize'], false);
$arResult['PAGE_NAVNUM'] = intval($dbRes->NavNum);
// pager index
$arResult['PAGE_NUMBER'] = intval($dbRes->NavPageNomer);
// current page index
$arResult['PAGE_NAVCOUNT'] = intval($dbRes->NavPageCount);
// page count
$arResult['PAGER_PARAM'] = "PAGEN_{$arResult['PAGE_NAVNUM']}";
$arResult['PAGE_NEXT_NUMBER'] = $arResult['PAGE_NUMBER'] + 1;
while ($item = $dbRes->Fetch()) {
    $itemID = intval($item['ID']);
    $ownerID = intval($item['OWNER_ID']);
    $ownerTypeID = intval($item['OWNER_TYPE_ID']);
    CCrmMobileHelper::PrepareActivityItem($item, $arParams, array('ENABLE_COMMUNICATIONS' => false));
    $arResult['ITEMS'][] =& $item;
Пример #5
0
 public static function DeleteCrmActivityComment($arFields)
 {
     if (!isset($arFields["SOURCE_ID"]) || intval($arFields["SOURCE_ID"]) <= 0) {
         return array("NO_SOURCE" => "Y");
     }
     $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array('ID', 'ENTITY_ID'));
     if ($arLog = $dbResult->Fetch()) {
         $dbCrmActivity = CCrmActivity::GetList(array(), array('ID' => $arLog['ENTITY_ID'], 'CHECK_PERMISSIONS' => 'N'));
         if ($arCrmActivity = $dbCrmActivity->Fetch()) {
             if ($arCrmActivity['TYPE_ID'] == CCrmActivityType::Task) {
                 if (CModule::IncludeModule("forum")) {
                     $res = ForumActions("DEL", array("MID" => intval($arFields["SOURCE_ID"])), $strErrorMessage, $strOKMessage);
                     return array("ERROR" => $strErrorMessage, "NOTES" => $strOKMessage);
                 } else {
                     return array("ERROR" => GetMessage("CRM_SL_DELETE_COMMENT_SOURCE_ERROR_FORUM_NOT_INSTALLED"), "NOTES" => false);
                 }
             } else {
                 return array("NO_SOURCE" => "Y");
             }
         } else {
             return array("NO_SOURCE" => "Y");
         }
     } else {
         return array("NO_SOURCE" => "Y");
     }
 }
Пример #6
0
        $userName = is_array($user = $dbResUser->Fetch()) ? CUser::FormatName(CSite::GetNameFormat(false), $user, true, false) : '';
    }
    echo CUtil::PhpToJSObject(array('ACTIVITY' => array('ID' => $arActivity['ID'], 'typeID' => CCrmActivityType::Task, 'associatedEntityID' => $taskID, 'subject' => $arActivity['SUBJECT'], 'description' => $arActivity['DESCRIPTION'], 'start' => !empty($arActivity['START_TIME']) ? $arActivity['START_TIME'] : '', 'end' => !empty($arActivity['END_TIME']) ? $arActivity['END_TIME'] : '', 'completed' => $arActivity['COMPLETED'] === 'Y', 'notifyType' => CCrmActivityNotifyType::None, 'notifyValue' => 0, 'priority' => $arActivity['PRIORITY'], 'responsibleName' => $userName)));
} elseif ($action == 'GET_ACTIVITIES') {
    $ownerTypeName = isset($_POST['OWNER_TYPE']) ? strtoupper(strval($_POST['OWNER_TYPE'])) : '';
    $ownerID = isset($_POST['OWNER_ID']) ? intval($_POST['OWNER_ID']) : 0;
    if ($ownerTypeName === '' || $ownerID <= 0) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'Invalid data'));
        die;
    }
    $completed = isset($_POST['COMPLETED']) ? intval($_POST['COMPLETED']) : 0;
    if (!CCrmActivity::CheckReadPermission(CCrmOwnerType::ResolveID($ownerTypeName), $ownerID)) {
        echo CUtil::PhpToJSObject(array('ERROR' => GetMessage('CRM_PERMISSION_DENIED')));
        die;
    }
    $dbRes = CCrmActivity::GetList(array('deadline' => 'asc'), array('OWNER_ID' => $ownerID, 'OWNER_TYPE_ID' => CCrmOwnerType::ResolveID($ownerTypeName), 'COMPLETED' => $completed > 0 ? 'Y' : 'N'));
    $arItems = array();
    while ($arRes = $dbRes->GetNext()) {
        $responsibleID = isset($arRes['~RESPONSIBLE_ID']) ? intval($arRes['~RESPONSIBLE_ID']) : 0;
        if ($responsibleID > 0) {
            $dbResUser = CUser::GetByID($responsibleID);
            $arRes['RESPONSIBLE'] = $dbResUser->Fetch();
            $arRes['RESPONSIBLE_FULL_NAME'] = is_array($arRes['RESPONSIBLE']) ? CUser::FormatName(CSite::GetNameFormat(false), $arRes['RESPONSIBLE'], true, false) : '';
        } else {
            $arRes['RESPONSIBLE'] = false;
            $arRes['RESPONSIBLE_FULL_NAME'] = '';
            $arRes['PATH_TO_RESPONSIBLE'] = '';
        }
        $arRes['FILES'] = array();
        CCrmActivity::PrepareStorageElementIDs($arRes);
        $arFileID = $arRes['STORAGE_ELEMENT_IDS'];
Пример #7
0
 public static function GetResponsibleID($typeID, $ID, $checkRights = true)
 {
     $typeID = intval($typeID);
     $ID = intval($ID);
     if (!(self::IsDefined($typeID) && $ID > 0)) {
         return 0;
     }
     $key = "{$typeID}_{$ID}";
     if (isset(self::$RESPONSIBLES[$key])) {
         return self::$RESPONSIBLES[$key];
     }
     $result = 0;
     switch ($typeID) {
         case self::Lead:
             $dbRes = CCrmLead::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $checkRights ? 'Y' : 'N'), false, false, array('ASSIGNED_BY_ID'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             $result = $arRes ? intval($arRes['ASSIGNED_BY_ID']) : 0;
             break;
         case self::Contact:
             $dbRes = CCrmContact::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $checkRights ? 'Y' : 'N'), false, false, array('ASSIGNED_BY_ID'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             $result = $arRes ? intval($arRes['ASSIGNED_BY_ID']) : 0;
             break;
         case self::Company:
             $dbRes = CCrmCompany::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $checkRights ? 'Y' : 'N'), false, false, array('ASSIGNED_BY_ID'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             $result = $arRes ? intval($arRes['ASSIGNED_BY_ID']) : 0;
             break;
         case self::Deal:
             $dbRes = CCrmDeal::GetListEx(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $checkRights ? 'Y' : 'N'), false, false, array('ASSIGNED_BY_ID'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             $result = $arRes ? intval($arRes['ASSIGNED_BY_ID']) : 0;
             break;
         case self::Invoice:
             $dbRes = CCrmInvoice::GetList(array(), array('ID' => $ID), false, false, array('RESPONSIBLE_ID'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             $result = $arRes ? intval($arRes['RESPONSIBLE_ID']) : 0;
             break;
         case self::Activity:
             $dbRes = CCrmActivity::GetList(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $checkRights ? 'Y' : 'N'), false, false, array('RESPONSIBLE_ID'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             $result = $arRes ? intval($arRes['RESPONSIBLE_ID']) : 0;
             break;
         case self::Quote:
             $dbRes = CCrmQuote::GetList(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => $checkRights ? 'Y' : 'N'), false, false, array('ASSIGNED_BY_ID'));
             $arRes = $dbRes ? $dbRes->Fetch() : null;
             $result = $arRes ? intval($arRes['ASSIGNED_BY_ID']) : 0;
             break;
     }
     self::$RESPONSIBLES[$key] = $result;
     return $result;
 }
Пример #8
0
 protected static function SendMessageToSocNet($arFields, $bSpawnedByAgent, $arChanges = null, $arTask = null, array $parameters = array())
 {
     global $USER, $DB;
     $effectiveUserId = self::getEffectiveUserId($arFields, array(), $bSpawnedByAgent, $parameters);
     if (!CModule::IncludeModule('socialnetwork')) {
         return null;
     }
     $bCrmTask = isset($arTask) && isset($arTask["UF_CRM_TASK"]) && (is_array($arTask["UF_CRM_TASK"]) && (isset($arTask["UF_CRM_TASK"][0]) && strlen($arTask["UF_CRM_TASK"][0]) > 0) || !is_array($arTask["UF_CRM_TASK"]) && strlen($arTask["UF_CRM_TASK"]) > 0);
     $arLogFilter = false;
     if (!$bCrmTask) {
         $arLogFilter = array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]);
     } elseif (CModule::IncludeModule("crm")) {
         $dbCrmActivity = CCrmActivity::GetList(array(), array('TYPE_ID' => CCrmActivityType::Task, 'ASSOCIATED_ENTITY_ID' => $arTask["ID"], 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID'));
         if ($arCrmActivity = $dbCrmActivity->Fetch()) {
             $arLogFilter = array("EVENT_ID" => "crm_activity_add", "ENTITY_ID" => $arCrmActivity["ID"]);
         }
     }
     if (!$arLogFilter) {
         return null;
     }
     static $arCheckedUsers = array();
     // users that checked for their existing
     static $cachedSiteTimeFormat = -1;
     // select "real" author
     $occurAsUserId = CTasksTools::getOccurAsUserId();
     if (!$occurAsUserId) {
         $occurAsUserId = $effectiveUserId;
     }
     if ($cachedSiteTimeFormat === -1) {
         $cachedSiteTimeFormat = CSite::GetDateFormat('FULL', SITE_ID);
     }
     static $cachedAllSitesIds = -1;
     if ($cachedAllSitesIds === -1) {
         $cachedAllSitesIds = array();
         $dbSite = CSite::GetList($by = 'sort', $order = 'desc', array('ACTIVE' => 'Y'));
         while ($arSite = $dbSite->Fetch()) {
             $cachedAllSitesIds[] = $arSite['ID'];
         }
     }
     // Check that user exists
     if (!in_array((int) $arFields["CREATED_BY"], $arCheckedUsers, true)) {
         $rsUser = CUser::GetList($by = 'ID', $order = 'ASC', array('ID' => $arFields["CREATED_BY"]), array('FIELDS' => array('ID')));
         if (!($arUser = $rsUser->Fetch())) {
             return false;
         }
         $arCheckedUsers[] = (int) $arFields["CREATED_BY"];
     }
     if (is_array($arChanges)) {
         if (count($arChanges) == 0) {
             $rsSocNetLogItems = CSocNetLog::GetList(array("ID" => "DESC"), $arLogFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
             while ($arRes = $rsSocNetLogItems->Fetch()) {
                 $authorUserId = false;
                 if (isset($arFields['CREATED_BY'])) {
                     $authorUserId = (int) $arFields['CREATED_BY'];
                 } elseif (isset($arTask['CREATED_BY'])) {
                     $authorUserId = (int) $arTask['CREATED_BY'];
                 }
                 // Add author to list of users that view log about task in livefeed
                 // But only when some other person change task
                 // or if added FORUM_TOPIC_ID
                 if ($authorUserId !== $effectiveUserId || $arTask['FORUM_TOPIC_ID'] == 0 && isset($arFields['FORUM_TOPIC_ID']) && $arFields['FORUM_TOPIC_ID'] > 0) {
                     $authorGroupCode = 'U' . $authorUserId;
                     $rsRights = CSocNetLogRights::GetList(array(), array('LOG_ID' => $arRes['ID'], 'GROUP_CODE' => $authorGroupCode));
                     // If task's author hasn't rights yet, give them
                     if (!($arRights = $rsRights->fetch())) {
                         CSocNetLogRights::Add($arRes["ID"], array($authorGroupCode));
                     }
                 }
             }
             return null;
         } elseif (count($arChanges) == 1 && isset($arChanges['STATUS'])) {
             return null;
             // if only status changes - don't send message, because it will be sent by SendStatusMessage()
         }
     }
     if ($bSpawnedByAgent === 'Y') {
         $bSpawnedByAgent = true;
     } elseif ($bSpawnedByAgent === 'N') {
         $bSpawnedByAgent = false;
     }
     if (!is_bool($bSpawnedByAgent)) {
         return false;
     }
     $taskId = false;
     if (is_array($arFields) && isset($arFields['ID']) && $arFields['ID'] > 0) {
         $taskId = $arFields['ID'];
     } elseif (is_array($arTask) && isset($arTask['ID']) && $arTask['ID'] > 0) {
         $taskId = $arTask['ID'];
     }
     // We will mark this to false, if we send update message and log item already exists
     $bSocNetAddNewItem = true;
     $logDate = $DB->CurrentTimeFunction();
     $curTimeTimestamp = time() + CTimeZone::GetOffset();
     if (!$bCrmTask) {
         $arSoFields = array('EVENT_ID' => 'tasks', 'TITLE' => $arFields['TITLE'], 'MESSAGE' => '', 'MODULE_ID' => 'tasks');
     } else {
         $arSoFields = array();
     }
     // If changes and task data given => we are prepare "update" message,
     // or "add" message otherwise
     if (is_array($arChanges) && is_array($arTask)) {
         // Prepare "update" message here
         if (strlen($arFields["CHANGED_DATE"]) > 0) {
             $createdDateTimestamp = MakeTimeStamp($arFields["CHANGED_DATE"], $cachedSiteTimeFormat);
             if ($createdDateTimestamp > $curTimeTimestamp) {
                 $logDate = $DB->CharToDateFunction($arFields["CHANGED_DATE"], "FULL", SITE_ID);
             }
         }
         $arChangesFields = array_keys($arChanges);
         $arSoFields['TEXT_MESSAGE'] = str_replace('#CHANGES#', implode(', ', CTaskNotifications::__Fields2Names($arChangesFields)), GetMessage('TASKS_SONET_TASK_CHANGED_MESSAGE'));
         if (!$bCrmTask) {
             if ($arFields["GROUP_ID"] === NULL && $arTask['GROUP_ID'] || $arFields['GROUP_ID']) {
                 $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_GROUP;
                 $arSoFields["ENTITY_ID"] = $arFields["GROUP_ID"] ? $arFields["GROUP_ID"] : $arTask['GROUP_ID'];
             } else {
                 $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_USER;
                 $arSoFields["ENTITY_ID"] = $arFields["CREATED_BY"] ? $arFields["CREATED_BY"] : $arTask["CREATED_BY"];
             }
         }
         $arSoFields['PARAMS'] = serialize(array('TYPE' => 'modify', 'CHANGED_FIELDS' => $arChangesFields, 'CREATED_BY' => $arFields["CREATED_BY"] ? $arFields["CREATED_BY"] : $arTask["CREATED_BY"], 'CHANGED_BY' => $occurAsUserId ? $occurAsUserId : $arFields['CHANGED_BY'], 'PREV_REAL_STATUS' => isset($arTask['REAL_STATUS']) ? $arTask['REAL_STATUS'] : false));
         // Determine, does item exists in sonet log
         $rsSocNetLogItems = CSocNetLog::GetList(array("ID" => "DESC"), $arLogFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
         if ($rsSocNetLogItems->Fetch()) {
             $bSocNetAddNewItem = false;
             // item already exists, update it, not create.
         }
     } else {
         if (strlen($arFields["CREATED_DATE"]) > 0) {
             $createdDateTimestamp = MakeTimeStamp($arFields["CREATED_DATE"], $cachedSiteTimeFormat);
             if ($createdDateTimestamp > $curTimeTimestamp) {
                 $logDate = $DB->CharToDateFunction($arFields["CREATED_DATE"], "FULL", SITE_ID);
             }
         }
         $arSoFields['TEXT_MESSAGE'] = GetMessage('TASKS_SONET_NEW_TASK_MESSAGE');
         if ($arFields["GROUP_ID"]) {
             $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_GROUP;
             $arSoFields["ENTITY_ID"] = $arFields["GROUP_ID"];
         } else {
             $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_USER;
             $arSoFields["ENTITY_ID"] = $arFields["CREATED_BY"];
         }
         $arParamsLog = array('TYPE' => 'create', 'CREATED_BY' => $arFields["CREATED_BY"] ? $arFields["CREATED_BY"] : $arTask["CREATED_BY"], 'PREV_REAL_STATUS' => isset($arTask['REAL_STATUS']) ? $arTask['REAL_STATUS'] : false);
         if ($occurAsUserId) {
             $arParamsLog["CREATED_BY"] = $occurAsUserId;
         }
         $arSoFields['PARAMS'] = serialize($arParamsLog);
     }
     // rating entity id (ilike)
     $arSoFields["RATING_ENTITY_ID"] = $taskId;
     $arSoFields["RATING_TYPE_ID"] = "TASK";
     // Do we need add new item to socnet?
     // We adds new item, if it is not exists.
     $logID = false;
     if (IsModuleInstalled("webdav") || IsModuleInstalled("disk")) {
         $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("TASKS_TASK", "UF_TASK_WEBDAV_FILES", $taskId, LANGUAGE_ID);
         if ($ufDocID) {
             $arSoFields["UF_SONET_LOG_DOC"] = $ufDocID;
         }
     }
     if ($bSocNetAddNewItem) {
         $arSoFields['=LOG_DATE'] = $logDate;
         $arSoFields['CALLBACK_FUNC'] = false;
         $arSoFields['SOURCE_ID'] = $taskId;
         $arSoFields['ENABLE_COMMENTS'] = 'Y';
         $arSoFields['URL'] = CTaskNotifications::GetNotificationPath(array('ID' => (int) $arFields["CREATED_BY"]), $taskId, false);
         $arSoFields['USER_ID'] = $arFields['CREATED_BY'];
         $arSoFields['TITLE_TEMPLATE'] = '#TITLE#';
         // Set all sites because any user from any site may be
         // added to task in future. For example, new auditor, etc.
         $arSoFields['SITE_ID'] = $cachedAllSitesIds;
         $logID = CSocNetLog::Add($arSoFields, false);
         if (intval($logID) > 0) {
             CSocNetLog::Update($logID, array("TMP_ID" => $logID));
             $arTaskParticipant = CTaskNotifications::GetRecipientsIDs($arFields, false);
             // Exclude author
             $arLogCanViewedBy = array_diff($arTaskParticipant, array($arFields['CREATED_BY']));
             $arRights = CTaskNotifications::__UserIDs2Rights($arLogCanViewedBy);
             if (isset($arFields['GROUP_ID'])) {
                 $arRights = array_merge($arRights, self::prepareRightsCodesForViewInGroupLiveFeed($logID, $arFields['GROUP_ID']));
             }
             CSocNetLogRights::Add($logID, $arRights);
             CSocNetLog::SendEvent($logID, "SONET_NEW_EVENT", $logID);
         }
     } else {
         $arSoFields['=LOG_DATE'] = $logDate;
         $arSoFields['=LOG_UPDATE'] = $logDate;
         // All tasks posts in live feed should be from director
         if (isset($arFields['CREATED_BY'])) {
             $arSoFields['USER_ID'] = $arFields['CREATED_BY'];
         } elseif (isset($arTask['CREATED_BY'])) {
             $arSoFields['USER_ID'] = $arTask['CREATED_BY'];
         } elseif ($occurAsUserId) {
             $arSoFields['USER_ID'] = $occurAsUserId;
         } else {
             unset($arSoFields['USER_ID']);
         }
         $rsSocNetLogItems = CSocNetLog::GetList(array("ID" => "DESC"), $arLogFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
         while ($arRes = $rsSocNetLogItems->Fetch()) {
             CSocNetLog::Update($arRes["ID"], $arSoFields);
             $arTaskParticipant = CTaskNotifications::GetRecipientsIDs($arFields, false, true);
             $bAuthorMustBeExcluded = false;
             $authorUserId = false;
             if (isset($arFields['CREATED_BY'])) {
                 $authorUserId = (int) $arFields['CREATED_BY'];
             } elseif (isset($arTask['CREATED_BY'])) {
                 $authorUserId = (int) $arTask['CREATED_BY'];
             }
             // Get current rights
             $rsRights = CSocNetLogRights::GetList(array(), array('LOG_ID' => $arRes['ID']));
             $arCurrentRights = array();
             while ($arRights = $rsRights->fetch()) {
                 $arCurrentRights[] = $arRights['GROUP_CODE'];
             }
             // If author changes the task and author doesn't have
             // access to task yet, don't give access to him.
             if ($authorUserId === $effectiveUserId) {
                 $authorGroupCode = 'U' . $authorUserId;
                 // If task's author hasn't rights yet, still exclude him
                 if (!in_array($authorGroupCode, $arCurrentRights, true)) {
                     $bAuthorMustBeExcluded = true;
                 }
             }
             if ($bAuthorMustBeExcluded) {
                 $arLogCanViewedBy = array_diff($arTaskParticipant, array($authorUserId));
             } else {
                 $arLogCanViewedBy = $arTaskParticipant;
             }
             $arNewRights = CTaskNotifications::__UserIDs2Rights($arLogCanViewedBy);
             $bGroupChanged = false;
             if (isset($arFields['GROUP_ID'], $arTask['GROUP_ID']) && $arFields['GROUP_ID'] && $arFields['GROUP_ID'] != $arTask['GROUP_ID']) {
                 $bGroupChanged = true;
             }
             // If rights really changed, update them
             if (count(array_diff($arCurrentRights, $arNewRights)) || count(array_diff($arNewRights, $arCurrentRights)) || $bGroupChanged) {
                 if (isset($arFields['GROUP_ID'])) {
                     $arNewRights = array_merge($arNewRights, self::prepareRightsCodesForViewInGroupLiveFeed($logID, $arFields['GROUP_ID']));
                 } elseif (isset($arTask['GROUP_ID'])) {
                     $arNewRights = array_merge($arNewRights, self::prepareRightsCodesForViewInGroupLiveFeed($logID, $arTask['GROUP_ID']));
                 }
                 CSocNetLogRights::DeleteByLogID($arRes["ID"], true);
                 CSocNetLogRights::Add($arRes["ID"], $arNewRights);
             }
         }
     }
     return $logID;
 }
Пример #9
0
 public static function findByPhoneNumber($number, $params = array())
 {
     if (!is_string($number)) {
         throw new \Bitrix\Main\ArgumentTypeException('number', 'string');
     }
     if ($number === '') {
         throw new \Bitrix\Main\ArgumentException('Is empty', 'number');
     }
     if (!is_array($params)) {
         $params = array();
     }
     $userID = isset($params['USER_ID']) ? intval($params['USER_ID']) : 0;
     if ($userID <= 0) {
         $userID = CCrmPerms::GetCurrentUserID();
     }
     $isAdmin = CCrmPerms::IsAdmin($userID);
     $userPermissions = CCrmPerms::GetUserPermissions($userID);
     $enableExtendedMode = isset($params['ENABLE_EXTENDED_MODE']) ? (bool) $params['ENABLE_EXTENDED_MODE'] : true;
     $contactFormID = isset($params['CONTACT_FORM_ID']) ? intval($params['CONTACT_FORM_ID']) : '';
     if ($contactFormID === '') {
         $contactFormID = CCrmContact::DEFAULT_FORM_ID;
     }
     $dups = array();
     $criterion = new \Bitrix\Crm\Integrity\DuplicateCommunicationCriterion('PHONE', $number);
     $entityTypes = array(CCrmOwnerType::Contact, CCrmOwnerType::Company, CCrmOwnerType::Lead);
     foreach ($entityTypes as $entityType) {
         $duplicate = $criterion->find($entityType, 1);
         if ($duplicate !== null) {
             $dups[] = $duplicate;
         }
     }
     $entityByType = array();
     foreach ($dups as &$dup) {
         /** @var \Bitrix\Crm\Integrity\Duplicate $dup */
         $entities = $dup->getEntities();
         if (!(is_array($entities) && !empty($entities))) {
             continue;
         }
         //Each entity type limited by 50 items
         foreach ($entities as &$entity) {
             /** @var \Bitrix\Crm\Integrity\DuplicateEntity $entity */
             $entityTypeID = $entity->getEntityTypeID();
             $entityID = $entity->getEntityID();
             $fields = null;
             if ($entityTypeID === CCrmOwnerType::Contact) {
                 $dbEntity = CCrmContact::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'PHOTO', 'POST', 'COMPANY_ID', 'COMPANY_TITLE', 'ASSIGNED_BY_ID'));
                 $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null;
                 if (is_array($entityFields)) {
                     $formattedName = CCrmContact::PrepareFormattedName(array('HONORIFIC' => isset($entityFields['HONORIFIC']) ? $entityFields['HONORIFIC'] : '', 'NAME' => isset($entityFields['NAME']) ? $entityFields['NAME'] : '', 'SECOND_NAME' => isset($entityFields['SECOND_NAME']) ? $entityFields['SECOND_NAME'] : '', 'LAST_NAME' => isset($entityFields['LAST_NAME']) ? $entityFields['LAST_NAME'] : ''));
                     $fields = array('ID' => intval($entityFields['ID']), 'FORMATTED_NAME' => $formattedName, 'PHOTO' => isset($entityFields['PHOTO']) ? intval($entityFields['PHOTO']) : 0, 'COMPANY_ID' => isset($entityFields['COMPANY_ID']) ? intval($entityFields['COMPANY_ID']) : 0, 'COMPANY_TITLE' => isset($entityFields['COMPANY_TITLE']) ? $entityFields['COMPANY_TITLE'] : '', 'POST' => isset($entityFields['POST']) ? $entityFields['POST'] : '', 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmContact::CheckReadPermission($entityID, $userPermissions));
                     if ($fields['CAN_READ'] && $enableExtendedMode) {
                         $deals = array();
                         $dbDeal = CCrmDeal::GetListEx(array('BEGINDATE' => 'ASC'), array('=CONTACT_ID' => $entityID, 'CLOSED' => 'N', 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 2), array('ID', 'TITLE', 'STAGE_ID'), array('PERMS' => $userPermissions));
                         if (is_object($dbDeal)) {
                             while ($dealFields = $dbDeal->Fetch()) {
                                 $dealID = intval($dealFields['ID']);
                                 //$dealFields['CAN_READ'] = CCrmDeal::CheckReadPermission($dealID, $userPermissions);
                                 $dealFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $dealID);
                                 $deals[] = $dealFields;
                             }
                         }
                         $fields['DEALS'] =& $deals;
                         unset($deals);
                     }
                 }
             } elseif ($entityTypeID === CCrmOwnerType::Company) {
                 $dbEntity = CCrmCompany::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'TITLE', 'LOGO', 'ASSIGNED_BY_ID'));
                 $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null;
                 if (is_array($entityFields)) {
                     $fields = array('ID' => intval($entityFields['ID']), 'TITLE' => isset($entityFields['TITLE']) ? $entityFields['TITLE'] : '', 'LOGO' => isset($entityFields['LOGO']) ? intval($entityFields['LOGO']) : 0, 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmCompany::CheckReadPermission($entityID, $userPermissions));
                     if ($fields['CAN_READ'] && $enableExtendedMode) {
                         $deals = array();
                         $dbDeal = CCrmDeal::GetListEx(array('BEGINDATE' => 'ASC'), array('=COMPANY_ID' => $entityID, 'CLOSED' => 'N', 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 2), array('ID', 'TITLE', 'STAGE_ID'), array('PERMS' => $userPermissions));
                         if (is_object($dbDeal)) {
                             while ($dealFields = $dbDeal->Fetch()) {
                                 $dealID = intval($dealFields['ID']);
                                 //$dealFields['CAN_READ'] = CCrmDeal::CheckReadPermission($dealID, $userPermissions);
                                 $dealFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Deal, $dealID);
                                 $deals[] = $dealFields;
                             }
                         }
                         $fields['DEALS'] =& $deals;
                         unset($deals);
                     }
                 }
             } elseif ($entityTypeID === CCrmOwnerType::Lead) {
                 $dbEntity = CCrmLead::GetListEx(array(), array('=ID' => $entityID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'TITLE', 'HONORIFIC', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'POST', 'COMPANY_TITLE', 'ASSIGNED_BY_ID'));
                 $entityFields = is_object($dbEntity) ? $dbEntity->Fetch() : null;
                 if (is_array($entityFields)) {
                     $formattedName = '';
                     if (!empty($entityFields['NAME']) || !empty($entityFields['SECOND_NAME']) || !empty($entityFields['LAST_NAME'])) {
                         $formattedName = CCrmLead::PrepareFormattedName(array('HONORIFIC' => isset($entityFields['HONORIFIC']) ? $entityFields['HONORIFIC'] : '', 'NAME' => isset($entityFields['NAME']) ? $entityFields['NAME'] : '', 'SECOND_NAME' => isset($entityFields['SECOND_NAME']) ? $entityFields['SECOND_NAME'] : '', 'LAST_NAME' => isset($entityFields['LAST_NAME']) ? $entityFields['LAST_NAME'] : ''));
                     }
                     $fields = array('ID' => intval($entityFields['ID']), 'TITLE' => isset($entityFields['TITLE']) ? $entityFields['TITLE'] : '', 'FORMATTED_NAME' => $formattedName, 'COMPANY_TITLE' => isset($entityFields['COMPANY_TITLE']) ? $entityFields['COMPANY_TITLE'] : '', 'POST' => isset($entityFields['POST']) ? $entityFields['POST'] : '', 'ASSIGNED_BY_ID' => isset($entityFields['ASSIGNED_BY_ID']) ? intval($entityFields['ASSIGNED_BY_ID']) : 0, 'CAN_READ' => CCrmLead::CheckReadPermission($entityID, $userPermissions));
                 }
             }
             if (!is_array($fields)) {
                 continue;
             }
             if ($fields['CAN_READ'] && $enableExtendedMode) {
                 $showUrl = $fields['SHOW_URL'] = CCrmOwnerType::GetShowUrl($entityTypeID, $entityID);
                 if ($showUrl !== '') {
                     $fields['ACTIVITY_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_activity'));
                     $fields['INVOICE_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_invoice'));
                     if ($entityTypeID === CCrmOwnerType::Contact || $entityTypeID === CCrmOwnerType::Company) {
                         $fields['DEAL_LIST_URL'] = CCrmUrlUtil::AddUrlParams($showUrl, array("{$contactFormID}_active_tab" => 'tab_deal'));
                     }
                 }
                 $activities = array();
                 $dbActivity = CCrmActivity::GetList(array('DEADLINE' => 'ASC'), array('COMPLETED' => 'N', 'BINDINGS' => array(array('OWNER_TYPE_ID' => $entityTypeID, 'OWNER_ID' => $entityID)), 'CHECK_PERMISSIONS' => $isAdmin ? 'N' : 'Y'), false, array('nTopCount' => 4), array('ID', 'SUBJECT', 'START_TIME', 'END_TIME', 'DEADLINE'), array('PERMS' => $userPermissions));
                 if (is_object($dbActivity)) {
                     while ($activityFields = $dbActivity->Fetch()) {
                         $activityFields['SHOW_URL'] = CCrmOwnerType::GetShowUrl(CCrmOwnerType::Activity, $activityFields['ID']);
                         $activities[] =& $activityFields;
                         unset($activityFields);
                     }
                 }
                 $fields['ACTIVITIES'] =& $activities;
                 unset($activities);
             }
             $entityTypeName = CCrmOwnerType::ResolveName($entityTypeID);
             if (!isset($entityByType[$entityTypeName])) {
                 $entityByType[$entityTypeName] = array($fields);
             } elseif (!in_array($entityID, $entityByType[$entityTypeName], true)) {
                 $entityByType[$entityTypeName][] = $fields;
             }
         }
     }
     unset($dup);
     return $entityByType;
 }
Пример #10
0
    $data = isset($_REQUEST['ENTITY_DATA']) && is_array($_REQUEST['ENTITY_DATA']) ? $_REQUEST['ENTITY_DATA'] : array();
    if (count($data) == 0) {
        __CrmMobileActivityEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_DATA_NOT_FOUND')));
    }
    $ID = isset($data['ID']) ? intval($data['ID']) : 0;
    if ($ID <= 0) {
        __CrmMobileActivityEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_ID_NOT_FOUND')));
    }
    $dbItem = CCrmActivity::GetList(array(), array('=ID' => $ID), false, false, array('OWNER_TYPE_ID', 'OWNER_ID'));
    $item = $dbItem->Fetch();
    if (!is_array($item)) {
        __CrmMobileActivityEditEndResonse(array('ERROR' => GetMessage('CRM_ACTIVITY_NOT_FOUND', array('#ID#' => $ID))));
    }
    $ownerTypeID = isset($item['OWNER_TYPE_ID']) ? intval($item['OWNER_TYPE_ID']) : 0;
    $ownerID = isset($item['OWNER_ID']) ? intval($item['OWNER_ID']) : 0;
    if (!CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID)) {
        __CrmMobileActivityEditEndResonse(array('ERROR' => 'Access denied.'));
    }
    $completed = (isset($data['COMPLETED']) ? intval($data['COMPLETED']) : 0) > 0;
    if (CCrmActivity::Complete($ID, $completed, array('REGISTER_SONET_EVENT' => true))) {
        $dbRes = CCrmActivity::GetList(array(), array('=ID' => $ID, 'CHECK_PERMISSIONS' => 'N'));
        $currentItem = $dbRes->Fetch();
        $formatParams = isset($_REQUEST['FORMAT_PARAMS']) ? $_REQUEST['FORMAT_PARAMS'] : array();
        CCrmMobileHelper::PrepareActivityItem($currentItem, $formatParams, array('ENABLE_COMMUNICATIONS' => true));
        __CrmMobileActivityEditEndResonse(array('SAVED_ENTITY_ID' => $ID, 'SAVED_ENTITY_DATA' => CCrmMobileHelper::PrepareActivityData($currentItem)));
    } else {
        __CrmMobileActivityEditEndResonse(array('ERROR' => CCrmActivity::GetLastErrorMessage()));
    }
} else {
    __CrmMobileActivityEditEndResonse(array('ERROR' => 'Action is not supported in current context.'));
}
Пример #11
0
$arParams['CONTACT_SHOW_URL_TEMPLATE'] = isset($arParams['CONTACT_SHOW_URL_TEMPLATE']) ? $arParams['CONTACT_SHOW_URL_TEMPLATE'] : '';
$arParams['COMPANY_SHOW_URL_TEMPLATE'] = isset($arParams['COMPANY_SHOW_URL_TEMPLATE']) ? $arParams['COMPANY_SHOW_URL_TEMPLATE'] : '';
$arParams['USER_PROFILE_URL_TEMPLATE'] = isset($arParams['USER_PROFILE_URL_TEMPLATE']) ? $arParams['USER_PROFILE_URL_TEMPLATE'] : '';
$arParams['COMMUNICATION_LIST_URL_TEMPLATE'] = isset($arParams['COMMUNICATION_LIST_URL_TEMPLATE']) ? $arParams['COMMUNICATION_LIST_URL_TEMPLATE'] : '';
$arParams['NAME_TEMPLATE'] = $arResult['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array('#NOBR#', '#/NOBR#'), array('', ''), $arParams['NAME_TEMPLATE']);
$entityID = $arParams['ENTITY_ID'] = isset($arParams['ENTITY_ID']) ? intval($arParams['ENTITY_ID']) : 0;
if ($entityID <= 0 && isset($_GET['activity_id'])) {
    $entityID = $arParams['ENTITY_ID'] = intval($_GET['activity_id']);
}
$arResult['ENTITY_ID'] = $entityID;
$arParams['UID'] = isset($arParams['UID']) ? $arParams['UID'] : '';
if (!isset($arParams['UID']) || $arParams['UID'] === '') {
    $arParams['UID'] = 'mobile_crm_activity_view';
}
$arResult['UID'] = $arParams['UID'];
$dbFields = CCrmActivity::GetList(array(), array('ID' => $entityID));
$arFields = $dbFields->Fetch();
if (!$arFields) {
    ShowError(GetMessage('CRM_ACTIVITY_VIEW_NOT_FOUND', array('#ID#' => $arParams['ENTITY_ID'])));
    return;
}
$ownerTypeID = intval($arFields['OWNER_TYPE_ID']);
$ownerID = intval($arFields['OWNER_ID']);
if (!CCrmActivity::CheckReadPermission($ownerTypeID, $ownerID, $userPerms)) {
    ShowError(GetMessage('CRM_PERMISSION_DENIED'));
    return;
}
$typeID = isset($arFields['TYPE_ID']) ? intval($arFields['TYPE_ID']) : CCrmActivityType::Undefined;
//Permissions -->
$canChange = CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID, $userPerms);
$arResult['PERMISSIONS'] = array('EDIT' => $canChange && $typeID !== CCrmActivityType::Email, 'DELETE' => $canChange);
Пример #12
0
 protected function innerGetList($order, $filter, $select, $navigation, &$errors)
 {
     if (!is_array($order)) {
         $order = array();
     }
     if (empty($order)) {
         $order['START_TIME'] = 'ASC';
     }
     // Permissions will be checked by default
     return CCrmActivity::GetList($order, $filter, false, $navigation, $select, array('IS_EXTERNAL_CONTEXT' => true));
 }
Пример #13
0
$arResult['NAME_TEMPLATE'] = isset($arParams['NAME_TEMPLATE']) ? $arParams['NAME_TEMPLATE'] : CSite::GetNameFormat(false);
$arResult['PATH_TO_USER_PROFILE'] = $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/');
$uid = isset($arParams['UID']) ? $arParams['UID'] : '';
if ($uid === '') {
    $uid = 'crm_' . strtolower(CCrmOwnerType::ResolveName($entityTypeID)) . '_' . $entityID . '_feed_activities';
}
$arResult['UID'] = $arParams['UID'] = $uid;
//--> ACTIVITIES
$arResult['ACTIVITIES'] = array();
$activityFilter = array('COMPLETED' => 'N');
if (CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) {
    $activityFilter['BINDINGS'] = array(array('OWNER_TYPE_ID' => $entityTypeID, 'OWNER_ID' => $entityID));
} else {
    $activityFilter['RESPONSIBLE_ID'] = CCrmSecurityHelper::GetCurrentUserID();
}
$dbActivity = CCrmActivity::GetList(array('DEADLINE' => 'ASC'), $activityFilter, false, array('nTopCount' => 5), array('ID', 'TYPE_ID', 'DIRECTION', 'SUBJECT', 'RESPONSIBLE_ID', 'START_TIME', 'END_TIME', 'DEADLINE', 'COMPLETED', 'OWNER_TYPE_ID', 'OWNER_ID'));
if (is_object($dbActivity)) {
    $userPermissions = CCrmPerms::GetCurrentUserPermissions();
    $responsibleIDs = array();
    $activities = array();
    while ($activityFields = $dbActivity->GetNext()) {
        $itemID = intval($activityFields['~ID']);
        $activityIDs[] = $itemID;
        $ownerID = intval($activityFields['~OWNER_ID']);
        $ownerTypeID = intval($activityFields['~OWNER_TYPE_ID']);
        if ($arResult['READ_ONLY']) {
            $activityFields['CAN_EDIT'] = $activityFields['CAN_DELETE'] = false;
        } else {
            if ($ownerID > 0 && $ownerTypeID > 0) {
                $activityFields['CAN_EDIT'] = CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID, $userPermissions);
                $activityFields['CAN_DELETE'] = CCrmActivity::CheckDeletePermission($ownerTypeID, $ownerID, $userPermissions);
Пример #14
0
        } else {
            $innerFilter["__INNER_FILTER_TYPE_{$i}"] = array('LOGIC' => 'AND', 'TYPE_ID' => intval($ary[0]));
        }
    }
    unset($arFilter['TYPE_ID']);
    $innerFilter['LOGIC'] = 'OR';
    $arFilter['__INNER_FILTER'] = $innerFilter;
    break;
}
$ownerInfoKey = array_search('OWNER_INFO', $arSelect, true);
if ($ownerInfoKey !== false) {
    unset($arSelect[$ownerInfoKey]);
}
$skipFiles = isset($arParams['SKIP_FILES']) && $arParams['SKIP_FILES'] === true;
// Ignore select: we need all fields for editor
$dbRes = CCrmActivity::GetList($arSort, $arFilter, false, $arNavParams, array(), array());
$arResult['ITEMS'] = array();
$bbCodeParser = new CTextParser();
$responsibleIDs = array();
$items = array();
while ($arRes = $dbRes->GetNext()) {
    $itemID = intval($arRes['~ID']);
    $ownerID = intval($arRes['~OWNER_ID']);
    $ownerTypeID = intval($arRes['~OWNER_TYPE_ID']);
    if ($arResult['READ_ONLY']) {
        $arRes['CAN_EDIT'] = $arRes['CAN_COMPLETE'] = $arRes['CAN_DELETE'] = false;
    } else {
        if ($ownerID > 0 && $ownerTypeID > 0) {
            $arRes['CAN_EDIT'] = CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID, $currentUserPermissions);
            $arRes['CAN_COMPLETE'] = (int) $arRes['~TYPE_ID'] !== CCrmActivityType::Task ? $arRes['CAN_EDIT'] : CCrmActivity::CheckCompletePermission($ownerTypeID, $ownerID, $currentUserPermissions, array('FIELDS' => $arRes));
            $arRes['CAN_DELETE'] = CCrmActivity::CheckDeletePermission($ownerTypeID, $ownerID, $currentUserPermissions);