$ownerTypeName = isset($data['ownerType']) ? strtoupper(strval($data['ownerType'])) : ''; if ($ownerTypeName === '') { echo CUtil::PhpToJSObject(array('ERROR' => 'OWNER TYPE IS NOT DEFINED!')); die; } $ownerTypeID = CCrmOwnerType::ResolveID($ownerTypeName); if (!CCrmOwnerType::IsDefined($ownerTypeID)) { echo CUtil::PhpToJSObject(array('ERROR' => 'OWNER TYPE IS NOT SUPPORTED!')); die; } $ownerID = isset($data['ownerID']) ? intval($data['ownerID']) : 0; if ($ownerID <= 0) { echo CUtil::PhpToJSObject(array('ERROR' => 'OWNER ID IS NOT DEFINED!')); die; } if (!CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID)) { $entityTitle = CCrmOwnerType::GetCaption($ownerTypeID, $ownerID, false); if ($ownerTypeID === CCrmOwnerType::Contact) { $errorMsg = GetMessage('CRM_CONTACT_UPDATE_PERMISSION_DENIED', array('#TITLE#' => $entityTitle)); } elseif ($ownerTypeID === CCrmOwnerType::Company) { $errorMsg = GetMessage('CRM_COMPANY_UPDATE_PERMISSION_DENIED', array('#TITLE#' => $entityTitle)); } elseif ($ownerTypeID === CCrmOwnerType::Lead) { $errorMsg = GetMessage('CRM_LEAD_UPDATE_PERMISSION_DENIED', array('#TITLE#' => $entityTitle)); } elseif ($ownerTypeID === CCrmOwnerType::Deal) { $errorMsg = GetMessage('CRM_DEAL_UPDATE_PERMISSION_DENIED', array('#TITLE#' => $entityTitle)); } else { $errorMsg = GetMessage('CRM_PERMISSION_DENIED'); } echo CUtil::PhpToJSObject(array('ERROR' => $errorMsg)); die; }
$ownerTypeID = CCrmOwnerType::ResolveID($ownerTypeName); $ownerID = isset($binding['ID']) ? (int) $binding['ID'] : 0; if ($ownerTypeID === CCrmOwnerType::Undefined || $ownerID <= 0) { die; } $userPermissions = CCrmPerms::GetCurrentUserPermissions(); if (!CCrmActivity::CheckReadPermission($ownerTypeID, $ownerID, $userPermissions)) { die; } if (count($bindings) > 1) { array_splice($bindings, 1); } $componentParams['BINDINGS'] = $componentData['params']['BINDINGS'] = $bindings; //Sanitaizing of Permission Type $permissionType = isset($componentParams['PERMISSION_TYPE']) ? strtoupper($componentParams['PERMISSION_TYPE']) : 'READ'; if ($permissionType !== 'READ' && !CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID, $userPermissions)) { $componentParams['PERMISSION_TYPE'] = $componentData['params']['PERMISSION_TYPE'] = 'READ'; } //For custom reload with params $ajaxLoaderParams = array('url' => '', 'method' => 'POST', 'dataType' => 'ajax', 'data' => array('PARAMS' => $componentData)); global $APPLICATION; Header('Content-Type: text/html; charset=' . LANG_CHARSET); $APPLICATION->ShowAjaxHead(); $componentParams['ENABLE_CONTROL_PANEL'] = false; //Force AJAX mode $componentParams['AJAX_MODE'] = 'Y'; $componentParams['AJAX_OPTION_JUMP'] = 'N'; $componentParams['AJAX_OPTION_HISTORY'] = 'N'; $componentParams['AJAX_LOADER'] = $ajaxLoaderParams; $APPLICATION->IncludeComponent('bitrix:crm.activity.list', isset($componentData['template']) ? $componentData['template'] : '', $componentParams, false, array('HIDE_ICONS' => 'Y', 'ACTIVE_COMPONENT' => 'Y')); require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_after.php';
} } if (empty($comms)) { $dbDeal = CCrmDeal::GetListEx(array(), array('=ID' => $ownerID, 'CHECK_PERMISSIONS' => 'N'), false, false, array('CONTACT_ID', 'CONTACT_NAME', 'CONTACT_SECOND_NAME', 'CONTACT_LAST_NAME', 'COMPANY_ID', 'COMPANY_TITLE')); $deal = $dbDeal->Fetch(); if (is_array($deal)) { $contactID = isset($deal['CONTACT_ID']) ? intval($deal['CONTACT_ID']) : 0; $companyID = isset($deal['COMPANY_ID']) ? intval($deal['COMPANY_ID']) : 0; $comms = array(); if ($contactID > 0 && CCrmActivity::CheckUpdatePermission(CCrmOwnerType::Contact, $contactID, $userPerms)) { $commValue = CCrmActivity::GetDefaultCommunicationValue(CCrmOwnerType::Contact, $contactID, $commType); if ($commValue !== '') { $comms[] = array('TYPE' => $commType, 'VALUE' => $commValue, 'ENTITY_TYPE_ID' => CCrmOwnerType::Contact, 'ENTITY_ID' => $contactID, 'ENTITY_SETTINGS' => array('NAME' => isset($deal['CONTACT_NAME']) ? $deal['CONTACT_NAME'] : '', 'SECOND_NAME' => isset($deal['CONTACT_SECOND_NAME']) ? $deal['CONTACT_SECOND_NAME'] : '', 'LAST_NAME' => isset($deal['CONTACT_LAST_NAME']) ? $deal['CONTACT_LAST_NAME'] : '')); } } if (empty($comms) && $companyID > 0 && CCrmActivity::CheckUpdatePermission(CCrmOwnerType::Company, $companyID, $userPerms)) { $commValue = CCrmActivity::GetDefaultCommunicationValue(CCrmOwnerType::Company, $companyID, $commType); if ($commValue !== '') { $comms[] = array('TYPE' => $commType, 'VALUE' => $commValue, 'ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID, 'ENTITY_SETTINGS' => array('COMPANY_TITLE' => isset($deal['COMPANY_TITLE']) ? $deal['COMPANY_TITLE'] : '')); } } } } $arFields['COMMUNICATIONS'] =& $comms; unset($comms); } } } } CCrmMobileHelper::PrepareActivityItem($arFields, $arParams, array('ENABLE_COMMUNICATIONS' => true, 'ENABLE_FILES' => true)); //Trim seconds
$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); //<-- Permissions CCrmMobileHelper::PrepareActivityItem($arFields, $arParams); //COMMUNICATION $arFields['CLIENT_TITLE'] = ''; $arFields['CLIENT_SHOW_URL'] = ''; $arFields['CLIENT_IMAGE_URL'] = ''; $arFields['CLIENT_LEGEND'] = ''; $arFields['CLIENT_COMPANY_TITLE'] = ''; $arFields['CLIENT_COMPANY_SHOW_URL'] = ''; $arFields['CLIENT_COMMUNICATION_VALUE'] = ''; $comm = is_array($arFields['COMMUNICATIONS']) && isset($arFields['COMMUNICATIONS'][0]) ? $arFields['COMMUNICATIONS'][0] : null; if ($comm) { $arFields['CLIENT_COMMUNICATION_VALUE'] = isset($comm['VALUE']) ? $comm['VALUE'] : ''; $commOwnerTypeID = isset($comm['ENTITY_TYPE_ID']) ? intval($comm['ENTITY_TYPE_ID']) : 0;
protected function innerUpdate($ID, &$fields, &$errors, array $params = null) { $currentFields = CCrmActivity::GetByID($ID); CCrmActivity::PrepareStorageElementIDs($currentFields); if (!is_array($currentFields)) { $errors[] = 'Activity is not found.'; return false; } $typeID = intval($currentFields['TYPE_ID']); $currentOwnerID = intval($currentFields['OWNER_ID']); $currentOwnerTypeID = intval($currentFields['OWNER_TYPE_ID']); if (!CCrmActivity::CheckUpdatePermission($currentOwnerTypeID, $currentOwnerID)) { $errors[] = 'Access denied.'; return false; } $ownerID = isset($fields['OWNER_ID']) ? intval($fields['OWNER_ID']) : 0; if ($ownerID <= 0) { $ownerID = $currentOwnerID; } $ownerTypeID = isset($fields['OWNER_TYPE_ID']) ? intval($fields['OWNER_TYPE_ID']) : 0; if ($ownerTypeID <= 0) { $ownerTypeID = $currentOwnerTypeID; } if (($ownerTypeID !== $currentOwnerTypeID || $ownerID !== $currentOwnerID) && !CCrmActivity::CheckUpdatePermission($ownerTypeID, $ownerID)) { $errors[] = 'Access denied.'; return false; } $communications = isset($fields['COMMUNICATIONS']) && is_array($fields['COMMUNICATIONS']) ? $fields['COMMUNICATIONS'] : null; if (is_array($communications)) { $bindings = array(); if ($ownerTypeID > 0 && $ownerID > 0) { $bindings["{$ownerTypeID}_{$ownerID}"] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID); } $this->prepareCommunications($ownerTypeID, $ownerID, $typeID, $communications, $bindings); if (empty($communications)) { $errors[] = 'The field COMMUNICATIONS is not defined or invalid.'; return false; } $fields['BINDINGS'] = array_values($bindings); $fields['COMMUNICATIONS'] = $communications; } $storageTypeID = $fields['STORAGE_TYPE_ID'] = CCrmActivity::GetDefaultStorageTypeID(); $fields['STORAGE_ELEMENT_IDS'] = array(); if ($storageTypeID === StorageType::WebDav) { $webdavElements = isset($fields['WEBDAV_ELEMENTS']) && is_array($fields['WEBDAV_ELEMENTS']) ? $fields['WEBDAV_ELEMENTS'] : array(); $prevStorageElementIDs = isset($currentFields['STORAGE_ELEMENT_IDS']) ? $currentFields['STORAGE_ELEMENT_IDS'] : array(); $oldStorageElementIDs = array(); foreach ($webdavElements as &$element) { $elementID = isset($element['ELEMENT_ID']) ? intval($element['ELEMENT_ID']) : 0; if ($elementID > 0) { $fields['STORAGE_ELEMENT_IDS'][] = $elementID; } $oldElementID = isset($element['OLD_ELEMENT_ID']) ? intval($element['OLD_ELEMENT_ID']) : 0; if ($oldElementID > 0 && ($elementID > 0 || isset($element['DELETE']) && $element['DELETE'] === true)) { if (in_array($oldElementID, $prevStorageElementIDs)) { $oldStorageElementIDs[] = $oldElementID; } } } unset($element); } else { if ($storageTypeID === StorageType::Disk) { $diskFiles = isset($fields['FILES']) && is_array($fields['FILES']) ? $fields['FILES'] : array(); if (empty($diskFiles)) { //For backward compatibility only $diskFiles = isset($fields['WEBDAV_ELEMENTS']) && is_array($fields['WEBDAV_ELEMENTS']) ? $fields['WEBDAV_ELEMENTS'] : array(); } foreach ($diskFiles as &$fileInfo) { $fileID = isset($fileInfo['FILE_ID']) ? (int) $fileInfo['FILE_ID'] : 0; if ($fileID > 0) { $fields['STORAGE_ELEMENT_IDS'][] = $fileID; } } unset($fileInfo); } } $result = CCrmActivity::Update($ID, $fields, false, true, array()); if ($result === false) { $errors[] = CCrmActivity::GetLastErrorMessage(); } else { if (is_array($communications)) { CCrmActivity::SaveCommunications($ID, $communications, $fields, false, false); } if (!empty($oldStorageElementIDs)) { $webdavIBlock = $this->prepareWebDavIBlock(); foreach ($oldStorageElementIDs as $elementID) { $webdavIBlock->Delete(array('element_id' => $elementID)); } } } return $result; }
} $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); } else { $activityFields['CAN_EDIT'] = $activityFields['CAN_DELETE'] = true; } } $responsibleID = isset($activityFields['~RESPONSIBLE_ID']) ? intval($activityFields['~RESPONSIBLE_ID']) : 0; $activityFields['~RESPONSIBLE_ID'] = $responsibleID; if ($responsibleID <= 0) { $activityFields['RESPONSIBLE_FULL_NAME'] = ''; $activityFields['PATH_TO_RESPONSIBLE'] = ''; } elseif (!in_array($responsibleID, $responsibleIDs, true)) { $responsibleIDs[] = $responsibleID; } $activityFields['REFERENCE_TITLE'] = $ownerTypeID > 0 && $ownerID > 0 && ($ownerTypeID === CCrmOwnerType::Lead || $ownerTypeID === CCrmOwnerType::Deal) ? CCrmOwnerType::GetCaption($ownerTypeID, $ownerID, false) : ''; $activityFields['CLIENT_TITLE'] = '';
$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); } else { $arRes['CAN_EDIT'] = $arRes['CAN_COMPLETE'] = $arRes['CAN_DELETE'] = true; } } $responsibleID = isset($arRes['~RESPONSIBLE_ID']) ? intval($arRes['~RESPONSIBLE_ID']) : 0; $arRes['~RESPONSIBLE_ID'] = $responsibleID; if ($responsibleID <= 0) { $arRes['RESPONSIBLE'] = false; $arRes['RESPONSIBLE_FULL_NAME'] = ''; $arRes['PATH_TO_RESPONSIBLE'] = ''; } elseif (!in_array($responsibleID, $responsibleIDs, true)) { $responsibleIDs[] = $responsibleID; }