示例#1
0
 public static function ProcessLogEventEditPOST($arPOST, $entityTypeID, $entityID, &$arResult)
 {
     $arEntityData = array();
     $errors = array();
     $enableTitle = isset($arPOST['ENABLE_POST_TITLE']) && strtoupper($arPOST['ENABLE_POST_TITLE']) === 'Y';
     $title = $enableTitle && isset($arPOST['POST_TITLE']) ? $arPOST['POST_TITLE'] : '';
     $message = isset($arPOST['MESSAGE']) ? htmlspecialcharsback($arPOST['MESSAGE']) : '';
     $arResult['EVENT']['MESSAGE'] = $message;
     $arResult['EVENT']['TITLE'] = $title;
     $arResult['ENABLE_TITLE'] = $enableTitle;
     $attachedFiles = array();
     $webDavFileFieldName = $arResult['WEB_DAV_FILE_FIELD_NAME'];
     if ($webDavFileFieldName !== '' && isset($GLOBALS[$webDavFileFieldName]) && is_array($GLOBALS[$webDavFileFieldName])) {
         foreach ($GLOBALS[$webDavFileFieldName] as $fileID) {
             if ($fileID === '') {
                 continue;
             }
             //fileID:  "888|165|16"
             $attachedFiles[] = $fileID;
         }
         if (!empty($attachedFiles) && is_array($arResult['WEB_DAV_FILE_FIELD'])) {
             $arResult['WEB_DAV_FILE_FIELD']['VALUE'] = $attachedFiles;
         }
     }
     $allowToAll = COption::GetOptionString('socialnetwork', 'allow_livefeed_toall', 'Y') === 'Y';
     if ($allowToAll) {
         $arToAllRights = unserialize(COption::GetOptionString("socialnetwork", "livefeed_toall_rights", 'a:1:{i:0;s:2:"AU";}'));
         if (!$arToAllRights) {
             $arToAllRights = array('AU');
         }
         $arUserGroupCode = array_merge(array('AU'), CAccess::GetUserCodesArray($arResult['USER_ID']));
         if (count(array_intersect($arToAllRights, $arUserGroupCode)) <= 0) {
             $allowToAll = false;
         }
     }
     $arSocnetRights = array();
     if (!empty($arPOST['SPERM'])) {
         foreach ($arPOST['SPERM'] as $v => $k) {
             if (strlen($v) > 0 && is_array($k) && !empty($k)) {
                 foreach ($k as $vv) {
                     if (strlen($vv) > 0) {
                         $arSocnetRights[] = $vv;
                     }
                 }
             }
         }
     }
     if (in_array('UA', $arSocnetRights) && !$allowToAll) {
         foreach ($arSocnetRights as $key => $value) {
             if ($value == 'UA') {
                 unset($arSocnetRights[$key]);
                 break;
             }
         }
     }
     foreach ($arSocnetRights as $key => $value) {
         if ($value == 'UA') {
             $arSocnetRights[] = 'AU';
             unset($arSocnetRights[$key]);
             break;
         }
     }
     $arSocnetRights = array_unique($arSocnetRights);
     $allFeedEtityTypes = CCrmLiveFeedEntity::GetAll();
     $userPerms = CCrmPerms::GetCurrentUserPermissions();
     foreach ($arSocnetRights as $key => $value) {
         $groupCodeData = array();
         if (CCrmLiveFeed::TryParseGroupCode($value, $groupCodeData) && in_array($groupCodeData['ENTITY_TYPE'], $allFeedEtityTypes, true)) {
             $groupCodeEntityType = $groupCodeData['ENTITY_TYPE'];
             $groupCodeEntityID = $groupCodeData['ENTITY_ID'];
             if (!CCrmLiveFeed::CheckCreatePermission($groupCodeEntityType, $groupCodeEntityID, $userPerms)) {
                 $canonicalEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($groupCodeEntityType);
                 $errors[] = GetMessage('CRM_SL_EVENT_EDIT_PERMISSION_DENIED', array('#TITLE#' => CCrmOwnerType::GetCaption($canonicalEntityTypeID, $groupCodeEntityID, false)));
             } else {
                 $arEntityData[] = array('ENTITY_TYPE' => $groupCodeEntityType, 'ENTITY_ID' => $groupCodeEntityID);
             }
         }
     }
     if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0) && !empty($arEntityData)) {
         $entityData = $arEntityData[0];
         $entityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']);
         $entityID = $entityData['ENTITY_ID'];
     }
     if (!empty($arEntityData)) {
         $arResult['ENTITY_DATA'] = $arEntityData;
     }
     if (!(CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0)) {
         $errors[] = GetMessage('CRM_SL_EVENT_EDIT_ENTITY_NOT_DEFINED');
     }
     if ($message === '') {
         $errors[] = GetMessage('CRM_SL_EVENT_EDIT_EMPTY_MESSAGE');
     }
     if (empty($errors)) {
         $fields = array('ENTITY_TYPE_ID' => $entityTypeID, 'ENTITY_ID' => $entityID, 'USER_ID' => $arResult['USER_ID'], 'TITLE' => $title, 'MESSAGE' => $message, 'RIGHTS' => $arSocnetRights);
         $parents = array();
         CCrmOwnerType::TryGetOwnerInfos($entityTypeID, $entityID, $parents, array('ENABLE_MAPPING' => true));
         foreach ($arEntityData as $entityData) {
             $curEntityTypeID = CCrmLiveFeedEntity::ResolveEntityTypeID($entityData['ENTITY_TYPE']);
             $curEntityID = $entityData['ENTITY_ID'];
             $entityKey = "{$curEntityTypeID}_{$curEntityID}";
             if (!isset($parents[$entityKey]) && !($curEntityTypeID === $entityTypeID && $curEntityID === $entityID)) {
                 $parents[$entityKey] = array('ENTITY_TYPE_ID' => $curEntityTypeID, 'ENTITY_ID' => $curEntityID);
             }
         }
         if (!empty($parents)) {
             $fields['PARENTS'] = array_values($parents);
         }
         if (!empty($attachedFiles)) {
             $fields['WEB_DAV_FILES'] = array($webDavFileFieldName => $attachedFiles);
         }
         $messageID = CCrmLiveFeed::CreateLogMessage($fields);
         if (!(is_int($messageID) && $messageID > 0)) {
             $errors[] = isset($fields['ERROR']) ? $fields['ERROR'] : 'UNKNOWN ERROR';
         } else {
             preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/is" . BX_UTF_PCRE_MODIFIER, $message, $arMention);
             if (!empty($arMention) && !empty($arMention[1]) && CModule::IncludeModule("im")) {
                 $arMention = $arMention[1];
                 $arMention = array_unique($arMention);
                 $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => "", "FROM_USER_ID" => $arResult['USER_ID'], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "NOTIFY_EVENT" => "mention");
                 $genderSuffix = "";
                 $dbUser = CUser::GetByID($arResult['USER_ID']);
                 if ($arUser = $dbUser->Fetch()) {
                     switch ($arUser["PERSONAL_GENDER"]) {
                         case "M":
                             $genderSuffix = "_M";
                             break;
                         case "F":
                             $genderSuffix = "_F";
                             break;
                         default:
                             $genderSuffix = "";
                     }
                 }
                 $strIMMessageTitle = str_replace(array("\r\n", "\n"), " ", strlen($title) > 0 ? $title : $message);
                 if (CModule::IncludeModule("blog")) {
                     $strIMMessageTitle = trim(blogTextParser::killAllTags($strIMMessageTitle));
                 }
                 $strIMMessageTitle = TruncateText($strIMMessageTitle, 100);
                 $strIMMessageTitleOut = TruncateText($strIMMessageTitle, 255);
                 $strLogEntryURL = COption::GetOptionString("socialnetwork", "log_entry_page", SITE_DIR . "company/personal/log/#log_id#/", SITE_ID);
                 $strLogEntryURL = CComponentEngine::MakePathFromTemplate($strLogEntryURL, array("log_id" => $messageID));
                 $strLogEntryCrmURL = CComponentEngine::MakePathFromTemplate(SITE_DIR . "crm/stream/?log_id=#log_id#", array("log_id" => $messageID));
                 $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                 foreach ($arMention as $val) {
                     $val = IntVal($val);
                     if ($val > 0 && $val != $arResult['USER_ID']) {
                         $bHasAccess = false;
                         if (in_array('U' . $val, $arSocnetRights)) {
                             $url = $strLogEntryURL;
                             $bHasAccess = true;
                         }
                         if (!$bHasAccess) {
                             $arAccessCodes = array();
                             $dbAccess = CAccess::GetUserCodes($val);
                             while ($arAccess = $dbAccess->Fetch()) {
                                 $arAccessCodes[] = $arAccess["ACCESS_CODE"];
                             }
                             $arTmp = array_intersect($arAccess, $arSocnetRights);
                             if (!empty($arTmp)) {
                                 $url = $strLogEntryURL;
                                 $bHasAccess = true;
                             }
                         }
                         if (!$bHasAccess) {
                             $userPermissions = CCrmPerms::GetUserPermissions($val);
                             foreach ($arEntityData as $arEntity) {
                                 if (CCrmAuthorizationHelper::CheckReadPermission(CCrmOwnerType::ResolveName(CCrmLiveFeedEntity::ResolveEntityTypeID($arEntity['ENTITY_TYPE'])), $arEntity['ENTITY_ID'], $userPermissions)) {
                                     $url = $strLogEntryCrmURL;
                                     $bHasAccess = true;
                                     break;
                                 }
                             }
                         }
                         if ($bHasAccess) {
                             $arMessageFields["TO_USER_ID"] = $val;
                             $arMessageFields["NOTIFY_TAG"] = "CRM|MESSAGE_MENTION|" . $messageID;
                             $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($strIMMessageTitle) . "</a>"));
                             $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_SL_EVENT_IM_MENTION_POST" . $genderSuffix, array("#title#" => htmlspecialcharsbx($strIMMessageTitleOut))) . " (" . $serverName . $url . ")";
                             CIMNotify::Add($arMessageFields);
                         }
                     }
                 }
             }
             return $messageID;
         }
     }
     return $errors;
 }
示例#2
0
 function UnInstallDB($arParams = array())
 {
     global $DB, $APPLICATION, $stackCacheManager, $USER_FIELD_MANAGER;
     $this->errors = false;
     if (!array_key_exists('savedata', $arParams) || $arParams['savedata'] != 'Y') {
         // delete extra fields for all entities
         require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/crm/include.php';
         $arEntityIds = CCrmFields::GetEntityTypes();
         foreach ($arEntityIds as $entityId => $ar) {
             $CCrmFields = new CCrmFields($USER_FIELD_MANAGER, $entityId);
             $arFields = $CCrmFields->GetFields();
             foreach ($arFields as $arField) {
                 $CCrmFields->DeleteField($arField['ID']);
             }
         }
         $this->errors = $DB->RunSQLBatch($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/crm/install/db/' . strtolower($DB->type) . '/uninstall.sql');
         if (CModule::IncludeModule('socialnetwork')) {
             $dbRes = CSocNetLog::GetList(array(), array("ENTITY_TYPE" => CCrmLiveFeedEntity::GetAll()), false, false, array("ID"));
             if ($dbRes) {
                 while ($arRes = $dbRes->Fetch()) {
                     CSocNetLog::Delete($arRes["ID"]);
                 }
             }
         }
     }
     $stackCacheManager->Clear('b_crm_status');
     $stackCacheManager->Clear('b_crm_perms');
     COption::RemoveOption('crm');
     UnRegisterModuleDependences('mail', 'OnGetFilterList', 'crm', 'CCrmEMail', 'OnGetFilterList');
     UnRegisterModuleDependences('main', 'OnUserTypeBuildList', 'crm', 'CUserTypeCrm', 'GetUserTypeDescription');
     UnRegisterModuleDependences('main', 'OnUserTypeBuildList', 'crm', 'CUserTypeCrmStatus', 'GetUserTypeDescription');
     UnRegisterModuleDependences('search', 'OnReindex', 'crm', 'CCrmSearch', 'OnSearchReindex');
     UnRegisterModuleDependences('search', 'OnSearchCheckPermissions', 'crm', 'CCrmSearch', 'OnSearchCheckPermissions');
     UnRegisterModuleDependences('report', 'OnReportAdd', 'crm', 'CCrmReportHelper', 'clearMenuCache');
     UnRegisterModuleDependences('report', 'OnReportUpdate', 'crm', 'CCrmReportHelper', 'clearMenuCache');
     UnRegisterModuleDependences('report', 'OnReportDelete', 'crm', 'CCrmReportHelper', 'clearMenuCache');
     UnRegisterModuleDependences('iblock', 'OnIBlockDelete', 'crm', 'CCrmCatalog', 'OnIBlockDelete');
     UnRegisterModuleDependences('iblock', 'OnAfterIBlockElementDelete', 'crm', 'CAllCrmProduct', 'OnIBlockElementDelete');
     UnRegisterModuleDependences('iblock', 'OnAfterIBlockElementDelete', 'crm', 'CCrmProduct', 'OnIBlockElementDelete');
     UnRegisterModuleDependences("socialnetwork", "OnFillSocNetLogEvents", "crm", "CCrmExternalSaleImport", "OnFillSocNetLogEvents");
     UnRegisterModuleDependences('tasks', 'OnBeforeTaskAdd', 'crm', 'CAllCrmActivity', 'OnBeforeTaskAdd');
     UnRegisterModuleDependences('tasks', 'OnTaskAdd', 'crm', 'CAllCrmActivity', 'OnTaskAdd');
     UnRegisterModuleDependences('tasks', 'OnTaskUpdate', 'crm', 'CAllCrmActivity', 'OnTaskUpdate');
     UnRegisterModuleDependences('tasks', 'OnTaskDelete', 'crm', 'CAllCrmActivity', 'OnTaskDelete');
     UnRegisterModuleDependences('webdav', 'OnFileDelete', 'crm', 'CCrmWebDavHelper', 'OnWebDavFileDelete');
     UnRegisterModuleDependences('subscribe', 'BeforePostingSendMail', 'crm', 'CCrmEMail', 'BeforeSendMail');
     UnRegisterModuleDependences('calendar', 'OnAfterCalendarEventEdit', 'crm', 'CAllCrmActivity', 'OnCalendarEventEdit');
     UnRegisterModuleDependences('calendar', 'OnAfterCalendarEventDelete', 'crm', 'CAllCrmActivity', 'OnCalendarEventDelete');
     UnRegisterModuleDependences('crm', 'OnCrmStatusGetList', 'crm', 'CCrmStatusInvoice', 'getStatusList');
     UnRegisterModuleDependences('crm', 'OnGetEntityTypes', 'crm', 'CCrmStatusInvoice', 'onGetEntityTypes');
     UnRegisterModuleDependences('crm', 'OnBeforeCrmStatusCreate', 'crm', 'CCrmStatusInvoice', 'createCrmStatus');
     UnRegisterModuleDependences('rest', 'onRestServiceBuildDescription', 'crm', 'CCrmRestService', 'onRestServiceBuildDescription');
     UnRegisterModuleDependences('socialnetwork', 'OnFillSocNetAllowedSubscribeEntityTypes', 'crm', 'CCrmLiveFeed', 'OnFillSocNetAllowedSubscribeEntityTypes');
     UnRegisterModuleDependences('socialnetwork', 'OnFillSocNetLogEvents', 'crm', 'CCrmLiveFeed', 'OnFillSocNetLogEvents');
     UnRegisterModuleDependences('socialnetwork', 'OnFillSocNetLogFields', 'crm', 'CCrmLiveFeed', 'OnFillSocNetLogFields');
     UnRegisterModuleDependences('socialnetwork', 'OnBuildSocNetLogFilter', 'crm', 'CCrmLiveFeed', 'OnBuildSocNetLogFilter');
     UnRegisterModuleDependences('socialnetwork', 'OnBuildSocNetLogOrder', 'crm', 'CCrmLiveFeed', 'OnBuildSocNetLogOrder');
     UnRegisterModuleDependences('socialnetwork', 'OnSocNetLogFormatDestination', 'crm', 'CCrmLiveFeed', 'OnSocNetLogFormatDestination');
     UnRegisterModuleDependences('socialnetwork', 'OnBuildSocNetLogPerms', 'crm', 'CCrmLiveFeed', 'OnBuildSocNetLogPerms');
     UnRegisterModuleDependences('socialnetwork', 'OnBeforeSocNetLogRightsAdd', 'crm', 'CCrmLiveFeed', 'OnBeforeSocNetLogRightsAdd');
     UnRegisterModuleDependences('socialnetwork', 'OnBeforeSocNetLogCommentCounterIncrement', 'crm', 'CCrmLiveFeed', 'OnBeforeSocNetLogCommentCounterIncrement');
     UnRegisterModuleDependences('socialnetwork', 'OnAfterSocNetLogEntryCommentAdd', 'crm', 'CCrmLiveFeed', 'OnAfterSocNetLogEntryCommentAdd');
     UnRegisterModuleDependences('socialnetwork', 'OnBeforeSocNetLogEntryGetRights', 'crm', 'CCrmLiveFeed', 'OnBeforeSocNetLogEntryGetRights');
     UnRegisterModuleDependences("socialnetwork", "OnSendMentionGetEntityFields", "crm", "CCrmLiveFeed", "OnSendMentionGetEntityFields");
     UnRegisterModuleDependences('main', 'OnAddRatingVote', 'crm', 'CCrmLiveFeed', 'OnAddRatingVote');
     UnRegisterModuleDependences('forum', 'OnAfterCommentAdd', 'crm', 'CCrmLiveFeed', 'onAfterCommentAdd');
     UnRegisterModuleDependences('disk', 'onAfterDeleteFile', 'crm', '\\Bitrix\\Crm\\Integration\\DiskManager', 'OnDiskFileDelete');
     if (CModule::IncludeModule('search')) {
         CSearch::DeleteIndex('crm');
     }
     UnRegisterModule('crm');
     if ($this->errors !== false) {
         $APPLICATION->ThrowException(implode('<br />', $this->errors));
         return false;
     }
     return true;
 }