Exemple #1
0
 public static function CreateLogMessage(&$fields, $options = array())
 {
     if (!CModule::IncludeModule('socialnetwork')) {
         return false;
     }
     global $APPLICATION, $DB;
     if (!is_array($options)) {
         $options = array();
     }
     $entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined;
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         $fields['ERROR'] = GetMessage('CRM_LF_MSG_ENTITY_TYPE_NOT_FOUND');
         return false;
     }
     $entityType = CCrmOwnerType::ResolveName($entityTypeID);
     $entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;
     if ($entityID < 0) {
         $fields['ERROR'] = GetMessage('CRM_LF_MSG_ENTITY_TYPE_NOT_FOUND');
         return false;
     }
     $message = isset($fields['MESSAGE']) && is_string($fields['MESSAGE']) ? $fields['MESSAGE'] : '';
     if ($message === '') {
         $fields['ERROR'] = GetMessage('CRM_LF_MSG_EMPTY');
         return false;
     }
     $title = isset($fields['TITLE']) && is_string($fields['TITLE']) ? $fields['TITLE'] : '';
     if ($title === '') {
         $title = self::UntitledMessageStub;
     }
     $userID = isset($fields['USER_ID']) ? intval($fields['USER_ID']) : 0;
     if ($userID <= 0) {
         $userID = CCrmSecurityHelper::GetCurrentUserID();
     }
     $bbCodeParser = new CTextParser();
     $bbCodeParser->allow["HTML"] = "Y";
     $eventText = $bbCodeParser->convert4mail($message);
     $CCrmEvent = new CCrmEvent();
     $eventID = $CCrmEvent->Add(array('ENTITY_TYPE' => $entityType, 'ENTITY_ID' => $entityID, 'EVENT_ID' => 'INFO', 'EVENT_TYPE' => 0, 'EVENT_TEXT_1' => $eventText, 'DATE_CREATE' => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL', SITE_ID), 'FILES' => array()));
     if (is_string($eventID)) {
         //MS SQL RETURNS STRING INSTEAD INT
         $eventID = intval($eventID);
     }
     if (!(is_int($eventID) && $eventID > 0)) {
         $fields['ERROR'] = 'Could not create event';
         return false;
     }
     $liveFeedEntityType = CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID);
     $eventID = CCrmLiveFeedEvent::GetEventID($liveFeedEntityType, CCrmLiveFeedEvent::Message);
     $eventFields = array('EVENT_ID' => $eventID, '=LOG_DATE' => $DB->CurrentTimeFunction(), 'TITLE' => $title, 'MESSAGE' => $message, 'TEXT_MESSAGE' => '', 'MODULE_ID' => 'crm_shared', 'CALLBACK_FUNC' => false, 'ENABLE_COMMENTS' => 'Y', 'PARAMS' => '', 'USER_ID' => $userID, 'ENTITY_TYPE' => $liveFeedEntityType, 'ENTITY_ID' => $entityID, 'SOURCE_ID' => $eventID, 'URL' => CCrmUrlUtil::AddUrlParams(CCrmOwnerType::GetShowUrl($entityTypeID, $entityID), array()));
     if (isset($fields['WEB_DAV_FILES']) && is_array($fields['WEB_DAV_FILES'])) {
         $eventFields = array_merge($eventFields, $fields['WEB_DAV_FILES']);
     }
     $sendMessage = isset($options['SEND_MESSAGE']) && is_bool($options['SEND_MESSAGE']) ? $options['SEND_MESSAGE'] : false;
     $logEventID = CSocNetLog::Add($eventFields, $sendMessage);
     if (is_int($logEventID) && $logEventID > 0) {
         $arSocnetRights = $fields["RIGHTS"];
         if (!empty($arSocnetRights)) {
             $socnetPermsAdd = array();
             foreach ($arSocnetRights as $perm_tmp) {
                 if (preg_match('/^SG(\\d+)$/', $perm_tmp, $matches)) {
                     if (!in_array("SG" . $matches[1] . "_" . SONET_ROLES_USER, $arSocnetRights)) {
                         $socnetPermsAdd[] = "SG" . $matches[1] . "_" . SONET_ROLES_USER;
                     }
                     if (!in_array("SG" . $matches[1] . "_" . SONET_ROLES_MODERATOR, $arSocnetRights)) {
                         $socnetPermsAdd[] = "SG" . $matches[1] . "_" . SONET_ROLES_MODERATOR;
                     }
                     if (!in_array("SG" . $matches[1] . "_" . SONET_ROLES_OWNER, $arSocnetRights)) {
                         $socnetPermsAdd[] = "SG" . $matches[1] . "_" . SONET_ROLES_OWNER;
                     }
                 }
             }
             if (count($socnetPermsAdd) > 0) {
                 $arSocnetRights = array_merge($arSocnetRights, $socnetPermsAdd);
             }
             CSocNetLogRights::DeleteByLogID($logEventID);
             CSocNetLogRights::Add($logEventID, $arSocnetRights);
             if (array_key_exists("UF_SONET_LOG_DOC", $eventFields) && is_array($eventFields["UF_SONET_LOG_DOC"]) && count($eventFields["UF_SONET_LOG_DOC"]) > 0) {
                 if (!in_array("U" . $userID, $arSocnetRights)) {
                     $arSocnetRights[] = "U" . $userID;
                 }
                 CSocNetLogTools::SetUFRights($eventFields["UF_SONET_LOG_DOC"], $arSocnetRights);
             }
         }
         $arUpdateFields = array("RATING_TYPE_ID" => "LOG_ENTRY", "RATING_ENTITY_ID" => $logEventID);
         CSocNetLog::Update($logEventID, $arUpdateFields);
         self::RegisterOwnershipRelations($logEventID, $eventID, $fields);
         $eventFields["LOG_ID"] = $logEventID;
         CCrmLiveFeed::CounterIncrement($eventFields);
         return $logEventID;
     }
     $ex = $APPLICATION->GetException();
     $fields['ERROR'] = $ex->GetString();
     return false;
 }
Exemple #2
0
             if (!isset($_POST['COMPANY_ID']) && isset($_POST['COMPANY_NAME'])) {
                 if (CCrmCompany::CheckCreatePermission()) {
                     $arFields = array('TITLE' => trim($_POST['COMPANY_NAME']), 'CONTACT_ID' => array($ID));
                     $CCrmCompany = new CCrmCompany();
                     $companyId = $CCrmCompany->Add($arFields);
                     $CCrmContact->UpdateCompanyId($ID, $companyId);
                 }
             }
             if (isset($_POST['apply'])) {
                 if (CCrmContact::CheckUpdatePermission($ID)) {
                     LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_EDIT'], array('contact_id' => $ID)));
                 }
             } elseif (isset($_POST['saveAndAdd'])) {
                 $redirectUrl = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_EDIT'], array('contact_id' => 0));
                 if ($companyID > 0) {
                     $redirectUrl = CCrmUrlUtil::AddUrlParams($redirectUrl, array('company_id' => $companyID));
                 }
                 LocalRedirect($redirectUrl);
             } elseif (isset($_POST['saveAndView'])) {
                 if (CCrmContact::CheckReadPermission($ID)) {
                     LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_SHOW'], array('contact_id' => $ID)));
                 }
             }
             //save
             LocalRedirect(isset($_REQUEST['backurl']) && $_REQUEST['backurl'] !== '' ? $_REQUEST['backurl'] : CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_LIST'], array()));
         }
     }
 } else {
     if (isset($_GET['delete']) && check_bitrix_sessid()) {
         if ($isEditMode) {
             $arResult['ERROR_MESSAGE'] = '';
Exemple #3
0
    $emailOwnerTypeName = CCrmOwnerType::ContactName;
    $emailOwnerID = $contactID;
    if ($dealID > 0) {
        $emailOwnerTypeName = CCrmOwnerType::DealName;
        $emailOwnerID = $dealID;
    }
    $arFields['CONTACT_EMAIL_EDIT_URL'] = CCrmUrlUtil::AddUrlParams(CComponentEngine::makePathFromTemplate($arParams['ACTIVITY_EDIT_URL_TEMPLATE'], array('owner_type' => $emailOwnerTypeName, 'owner_id' => $emailOwnerID, 'type_id' => CCrmActivityType::Email)), array('comm[]' => strtolower(CCrmOwnerType::ContactName) . '_' . $contactID));
}
if ($companyID <= 0) {
    $arResult['COMPANY_CALLTO'] = $arFields['COMPANY_SHOW_URL'] = $arFields['COMPANY_EMAIL_EDIT_URL'] = '';
} else {
    $arResult['COMPANY_CALLTO'] = CCrmMobileHelper::PrepareCalltoParams(array('COMMUNICATION_LIST_URL_TEMPLATE' => $arParams['COMMUNICATION_LIST_URL_TEMPLATE'], 'ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $companyID, 'FM' => $arFields['COMPANY_FM']));
    $arFields['COMPANY_SHOW_URL'] = CComponentEngine::makePathFromTemplate($arParams['COMPANY_SHOW_URL_TEMPLATE'], array('company_id' => $companyID));
    $emailOwnerTypeName = CCrmOwnerType::ContactName;
    $emailOwnerID = $contactID;
    if ($dealID > 0) {
        $emailOwnerTypeName = CCrmOwnerType::DealName;
        $emailOwnerID = $dealID;
    }
    $arFields['COMPANY_EMAIL_EDIT_URL'] = CCrmUrlUtil::AddUrlParams(CComponentEngine::makePathFromTemplate($arParams['ACTIVITY_EDIT_URL_TEMPLATE'], array('owner_type' => $emailOwnerTypeName, 'owner_id' => $emailOwnerID, 'type_id' => CCrmActivityType::Email)), array('comm[]' => strtolower(CCrmOwnerType::CompanyName) . '_' . $companyID));
}
/*$arFields['PRODUCT_ROWS_QUANTITY'] = CAllCrmProductRow::GetRowQuantity(
	CCrmOwnerTypeAbbr::ResolveByTypeID(CCrmOwnerType::Invoice),
	$entityID
);*/
$arFields['PRODUCT_ROWS_URL'] = CComponentEngine::makePathFromTemplate($arParams['PRODUCT_ROW_LIST_URL_TEMPLATE'], array('entity_type_id' => CCrmOwnerType::Invoice, 'entity_id' => $entityID));
$arFields['EVENT_LIST_URL'] = CComponentEngine::makePathFromTemplate($arParams['EVENT_LIST_URL_TEMPLATE'], array('entity_type_id' => CCrmOwnerType::Invoice, 'entity_id' => $entityID));
$arResult['INVOICE_STATUS_SELECTOR_URL'] = CComponentEngine::makePathFromTemplate($arParams['INVOICE_STATUS_SELECTOR_URL_TEMPLATE'], array('context_id' => ''));
$arResult['ENTITY'] =& $arFields;
unset($arFields);
$this->IncludeComponentTemplate();
 public static function GetDataForPopup($callId, $phone, $userId = 0)
 {
     if (strlen($phone) <= 0 || !CModule::IncludeModule('crm')) {
         return false;
     }
     if ($userId > 0) {
         $findParams = array('USER_ID' => $userId);
     } else {
         $findParams = array('ENABLE_EXTENDED_MODE' => false);
     }
     $crm = CCrmSipHelper::findByPhoneNumber((string) $phone, $findParams);
     if ($crm) {
         $dealStatuses = CCrmViewHelper::GetDealStageInfos();
         $entity = '';
         $entityData = array();
         $entities = array();
         $arResult = array('FOUND' => 'Y', 'CONTACT' => array(), 'COMPANY' => array(), 'ACTIVITIES' => array(), 'DEALS' => array(), 'RESPONSIBILITY' => array());
         if (isset($crm['CONTACT'])) {
             $entity = 'CONTACT';
             $entityData = $crm[$entity][0];
             $arResult['CONTACT'] = array('NAME' => $entityData['FORMATTED_NAME'], 'POST' => $entityData['POST'], 'PHOTO' => '');
             if (intval($entityData['PHOTO']) > 0) {
                 $arPhoto = CFile::ResizeImageGet($entityData['PHOTO'], array('width' => 37, 'height' => 37), BX_RESIZE_IMAGE_EXACT, false, false, true);
                 $arResult['CONTACT']['PHOTO'] = $arPhoto['src'];
             }
             $arResult['COMPANY'] = $entityData['COMPANY_TITLE'];
             $arResult['CONTACT_DATA'] = array('ID' => $entityData['ID']);
         } else {
             if (isset($crm['LEAD'])) {
                 $entity = 'LEAD';
                 $entityData = $crm[$entity][0];
                 $arResult['CONTACT'] = array('ID' => 0, 'NAME' => !empty($entityData['FORMATTED_NAME']) ? $entityData['FORMATTED_NAME'] : $entityData['TITLE'], 'POST' => $entityData['POST'], 'PHOTO' => '');
                 $arResult['COMPANY'] = $entityData['COMPANY_TITLE'];
                 $arResult['LEAD_DATA'] = array('ID' => $entityData['ID'], 'ASSIGNED_BY_ID' => $entityData['ASSIGNED_BY_ID']);
             } else {
                 if (isset($crm['COMPANY'])) {
                     $entity = 'COMPANY';
                     $entityData = $crm[$entity][0];
                     $arResult['COMPANY'] = $entityData['TITLE'];
                     $arResult['COMPANY_DATA'] = array('ID' => $entityData['ID']);
                 }
             }
         }
         if ($entityData['ASSIGNED_BY_ID'] > 0) {
             $ar = Bitrix\Main\UserTable::getById($entityData['ASSIGNED_BY_ID']);
             if ($user = $ar->fetch()) {
                 $arPhoto = CFile::ResizeImageGet($user['PERSONAL_PHOTO'], array('width' => 37, 'height' => 37), BX_RESIZE_IMAGE_EXACT, false, false, true);
                 $arResult['RESPONSIBILITY'] = array('ID' => $user['ID'], 'NAME' => CUser::FormatName(CSite::GetNameFormat(false), $user, true, false), 'PHOTO' => $arPhoto ? $arPhoto['src'] : '', 'POST' => $user['WORK_POSITION']);
             }
         }
         if (isset($entityData['SHOW_URL'])) {
             $arResult['SHOW_URL'] = $entityData['SHOW_URL'];
         }
         if (isset($entityData['ACTIVITY_LIST_URL'])) {
             $arResult['ACTIVITY_URL'] = $entityData['ACTIVITY_LIST_URL'];
         }
         if (isset($entityData['INVOICE_LIST_URL'])) {
             $arResult['INVOICE_URL'] = $entityData['INVOICE_LIST_URL'];
         }
         if (isset($entityData['DEAL_LIST_URL'])) {
             $arResult['DEAL_URL'] = $entityData['DEAL_LIST_URL'];
         }
         $activityId = CCrmActivity::GetIDByOrigin('VI_' . $callId);
         if ($activityId) {
             $arResult['CURRENT_CALL_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Activity, $activityId);
             if ($arResult['CURRENT_CALL_URL'] !== '') {
                 $arResult['CURRENT_CALL_URL'] = CCrmUrlUtil::AddUrlParams($arResult['CURRENT_CALL_URL'], array("disable_storage_edit" => 'Y'));
             }
         }
         if (isset($crm['CONTACT']) && isset($crm['COMPANY'])) {
             $entities = array('CONTACT', 'COMPANY', 'LEAD');
         } else {
             if (isset($crm['CONTACT']) && isset($crm['LEAD']) && !isset($crm['COMPANY'])) {
                 $entities = array('CONTACT', 'LEAD');
             } else {
                 if (isset($crm['LEAD']) && isset($crm['COMPANY']) && !isset($crm['CONTACT'])) {
                     $entities = array('LEAD', 'COMPANY');
                 } else {
                     $entities = array($entity);
                 }
             }
         }
         foreach ($entities as $entity) {
             if (isset($crm[$entity][0]['ACTIVITIES'])) {
                 foreach ($crm[$entity][0]['ACTIVITIES'] as $activity) {
                     if ($activity['ID'] == $activityId) {
                         continue;
                     }
                     $overdue = 'N';
                     if (strlen($activity['DEADLINE']) > 0 && MakeTimeStamp($activity['DEADLINE']) < time()) {
                         $overdue = 'Y';
                     }
                     $arResult['ACTIVITIES'][$activity['ID']] = array('TITLE' => $activity['SUBJECT'], 'DATE' => strlen($activity['DEADLINE']) > 0 ? $activity['DEADLINE'] : $activity['END_TIME'], 'OVERDUE' => $overdue, 'URL' => $activity['SHOW_URL']);
                 }
                 if (!empty($arResult['ACTIVITIES'])) {
                     $arResult['ACTIVITIES'] = array_values($arResult['ACTIVITIES']);
                 }
             }
             if (isset($crm[$entity][0]['DEALS'])) {
                 foreach ($crm[$entity][0]['DEALS'] as $deal) {
                     $opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID']);
                     if (strpos('&', $opportunity)) {
                         $opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID'], '#') . ' ' . $deal['CURRENCY_ID'];
                     }
                     $opportunity = str_replace('.00', '', $opportunity);
                     $arResult['DEALS'][$deal['ID']] = array('ID' => $deal['ID'], 'TITLE' => $deal['TITLE'], 'STAGE' => $dealStatuses[$deal['STAGE_ID']]['NAME'], 'STAGE_COLOR' => $dealStatuses[$deal['STAGE_ID']]['COLOR'] ? $dealStatuses[$deal['STAGE_ID']]['COLOR'] : "#5fa0ce", 'OPPORTUNITY' => $opportunity, 'URL' => $deal['SHOW_URL']);
                 }
                 if (!empty($arResult['DEALS'])) {
                     $arResult['DEALS'] = array_values($arResult['DEALS']);
                 }
             }
         }
     } else {
         $arResult = array('FOUND' => 'N');
         $userPermissions = CCrmPerms::GetUserPermissions($userId);
         if (CCrmLead::CheckCreatePermission($userPermissions)) {
             $arResult['LEAD_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Lead, 0);
             if ($arResult['LEAD_URL'] !== '') {
                 $arResult['LEAD_URL'] = CCrmUrlUtil::AddUrlParams($arResult['LEAD_URL'], array("phone" => (string) $phone, 'origin_id' => 'VI_' . $callId));
             }
         }
         if (CCrmContact::CheckCreatePermission($userPermissions)) {
             $arResult['CONTACT_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Contact, 0);
             if ($arResult['CONTACT_URL'] !== '') {
                 $arResult['CONTACT_URL'] = CCrmUrlUtil::AddUrlParams($arResult['CONTACT_URL'], array("phone" => (string) $phone, 'origin_id' => 'VI_' . $callId));
             }
         }
     }
     return $arResult;
 }
Exemple #5
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;
 }
Exemple #6
0
}
if ($arParams['TYPE'] === 'list') {
    if ($bAdd) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_ADD'), 'TITLE' => GetMessage('CRM_CONTACT_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_EDIT'], array('contact_id' => 0)), 'HIGHLIGHT' => true);
    }
    if ($bImport) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_VCARD'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_VCARD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_IMPORTVCARD'], array()), 'ICON' => 'btn-import');
        $importUrl = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_IMPORT'], array());
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_GMAIL'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_GMAIL_TITLE'), 'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'gmail')), 'ICON' => 'btn-import');
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_OUTLOOK'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_OUTLOOK_TITLE'), 'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'outlook')), 'ICON' => 'btn-import');
        if (LANGUAGE_ID === 'ru' || LANGUAGE_ID === 'ua') {
            $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_YANDEX'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_YANDEX_TITLE'), 'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'yandex')), 'ICON' => 'btn-import');
        }
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_YAHOO'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_YAHOO_TITLE'), 'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'yahoo')), 'ICON' => 'btn-import');
        if (LANGUAGE_ID === 'ru' || LANGUAGE_ID === 'ua') {
            $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_MAILRU'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_MAILRU_TITLE'), 'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'mailru')), 'ICON' => 'btn-import');
        }
        /*
        		* LIVEMAIL is temporary disabled due to implementation error
        		* $arResult['BUTTONS'][] = array(
        		*  'TEXT' => GetMessage('CRM_CONTACT_IMPORT_LIVEMAIL'),
        		*  'TITLE' => GetMessage('CRM_CONTACT_IMPORT_LIVEMAIL_TITLE'),
        		*  'LINK' => CCrmUrlUtil::AddUrlParams($importUrl, array('origin' => 'livemail')),
        		*  'ICON' => 'btn-import'
        		);*/
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('CRM_CONTACT_IMPORT_CUSTOM'), 'TITLE' => GetMessage('CRM_CONTACT_IMPORT_CUSTOM_TITLE'), 'LINK' => $importUrl, 'ICON' => 'btn-import', 'MENU' => array(array('TITLE' => 'X', 'TEXT' => 'X', 'ONCLICK' => 'alert();')));
    }
    if ($bExport) {
        if ($bImport) {
            $arResult['BUTTONS'][] = array('SEPARATOR' => true);
        }