Exemplo n.º 1
9
 case 'CONTACT':
     $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arResult['ENTITY_ID']));
     if ($arRes = $dbRes->Fetch()) {
         $arResult['ENTITY_TITLE'] = $arRes['LAST_NAME'] . ' ' . $arRes['NAME'];
     }
     break;
 case 'COMPANY':
     $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), array('ID' => $arResult['ENTITY_ID']));
     if ($arRes = $dbRes->Fetch()) {
         $arResult['ENTITY_TITLE'] = $arRes['TITLE'];
     }
     break;
 case 'DEAL':
     $arEntityAttr = $CCrmPerms->GetEntityAttr('DEAL', $arResult['ENTITY_ID']);
     if ($CCrmPerms->CheckEnityAccess('DEAL', 'WRITE', $arEntityAttr[$arResult['ENTITY_ID']])) {
         $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), array('ID' => $arResult['ENTITY_ID']));
         if ($arRes = $dbRes->Fetch()) {
             $arResult['ENTITY_TITLE'] = $arRes['TITLE'];
             $arResult['STAGE_ID'] = $arRes['STAGE_ID'];
         }
         $arResult['STAGE_LIST'] = array();
         $arEventType = CCrmStatus::GetStatusList('DEAL_STAGE');
         foreach ($arEventType as $key => $value) {
             if ($CCrmPerms->GetPermType('DEAL', 'WRITE', array('DEAL_STAGE' . $key)) > BX_CRM_PERM_NONE) {
                 $arResult['STAGE_LIST']['REFERENCE'][] = $value;
                 $arResult['STAGE_LIST']['REFERENCE_ID'][] = $key;
             }
         }
         if ($arParams['EVENT_TYPE'] === 'PHONE') {
             $contactID = isset($arRes['CONTACT_ID']) ? intval($arRes['CONTACT_ID']) : 0;
             if ($contactID > 0) {
Exemplo n.º 2
9
 public static function GetDocumentType($documentId)
 {
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     switch ($arDocumentID['TYPE']) {
         case 'CONTACT':
             $dbDocumentList = CCrmContact::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
         case 'COMPANY':
             $dbDocumentList = CCrmCompany::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
         case 'DEAL':
             $dbDocumentList = CCrmDeal::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
         case 'LEAD':
             $dbDocumentList = CCrmLead::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
             break;
     }
     $arResult = $dbDocumentList->Fetch();
     if (!$arResult) {
         throw new Exception(GetMessage('CRM_DOCUMENT_ELEMENT_IS_NOT_FOUND'));
     }
     return $arDocumentID['TYPE'];
 }
Exemplo n.º 3
6
    if (isset($arCalList['LEAD']) && !empty($arCalList['LEAD'])) {
        $dbRes = CCrmLead::GetList(array('TITLE' => 'ASC', 'LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => array_keys($arCalList['LEAD'])));
        while ($arRes = $dbRes->Fetch()) {
            $arCalList['LEAD'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_SHOW'], array('lead_id' => $arRes['ID'])));
        }
    }
    if (isset($arCalList['CONTACT']) && !empty($arCalList['CONTACT'])) {
        $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => array_keys($arCalList['CONTACT'])));
        while ($arRes = $dbRes->Fetch()) {
            $arCalList['CONTACT'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['LAST_NAME'] . ' ' . $arRes['NAME'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_SHOW'], array('contact_id' => $arRes['ID'])));
        }
    }
    if (isset($arCalList['COMPANY']) && !empty($arCalList['COMPANY'])) {
        $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), array('ID' => array_keys($arCalList['COMPANY'])));
        while ($arRes = $dbRes->Fetch()) {
            $arCalList['COMPANY'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_COMPANY_SHOW'], array('company_id' => $arRes['ID'])));
        }
    }
    if (isset($arCalList['DEAL']) && !empty($arCalList['DEAL'])) {
        $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), array('ID' => array_keys($arCalList['DEAL'])));
        while ($arRes = $dbRes->Fetch()) {
            $arCalList['DEAL'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_SHOW'], array('deal_id' => $arRes['ID'])));
        }
    }
    foreach ($arResult['CAL'] as $key => $ar) {
        $arResult['CAL'][$key]['ENTITY_TITLE'] = htmlspecialcharsbx($arCalList[$ar['ENTITY_TYPE']][$ar['ENTITY_ID']]['ENTITY_TITLE']);
        $arResult['CAL'][$key]['ENTITY_LINK'] = $arCalList[$ar['ENTITY_TYPE']][$ar['ENTITY_ID']]['ENTITY_LINK'];
    }
}
$this->IncludeComponentTemplate();
return $arResult['ROWS_COUNT'];
Exemplo n.º 4
0
 public static function UpdateDocument($documentId, $arFields)
 {
     global $DB;
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     $dbDocumentList = CCrmDeal::GetList(array(), array('ID' => $arDocumentID['ID'], "CHECK_PERMISSIONS" => "N"), array('ID'));
     $arResult = $dbDocumentList->Fetch();
     if (!$arResult) {
         throw new Exception(GetMessage('CRM_DOCUMENT_ELEMENT_IS_NOT_FOUND'));
     }
     $arDocumentFields = self::GetDocumentFields($arDocumentID['TYPE']);
     $arKeys = array_keys($arFields);
     foreach ($arKeys as $key) {
         if (!array_key_exists($key, $arDocumentFields)) {
             //Fix for issue #40374
             unset($arFields[$key]);
             continue;
         }
         $arFields[$key] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]);
         if ($arDocumentFields[$key]["Type"] == "user") {
             $ar = array();
             foreach ($arFields[$key] as $v1) {
                 if (substr($v1, 0, strlen("user_")) == "user_") {
                     $ar[] = substr($v1, strlen("user_"));
                 } else {
                     $a1 = self::GetUsersFromUserGroup($v1, $documentId);
                     foreach ($a1 as $a11) {
                         $ar[] = $a11;
                     }
                 }
             }
             $arFields[$key] = $ar;
         } elseif ($arDocumentFields[$key]["Type"] == "select" && substr($key, 0, 3) == "UF_") {
             self::InternalizeEnumerationField('CRM_DEAL', $arFields, $key);
         } elseif ($arDocumentFields[$key]["Type"] == "file") {
             $arFileOptions = array('ENABLE_ID' => true);
             foreach ($arFields[$key] as &$value) {
                 //Issue #40380. Secure URLs and file IDs are allowed.
                 $file = false;
                 CCrmFileProxy::TryResolveFile($value, $file, $arFileOptions);
                 $value = $file;
             }
             unset($value);
         } elseif ($arDocumentFields[$key]["Type"] == "S:HTML") {
             foreach ($arFields[$key] as &$value) {
                 $value = array("VALUE" => $value);
             }
             unset($value);
         }
         if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key])) {
             if (count($arFields[$key]) > 0) {
                 $a = array_values($arFields[$key]);
                 $arFields[$key] = $a[0];
             } else {
                 $arFields[$key] = null;
             }
         }
     }
     /*if (isset($arFields['CONTACT_ID']) && !is_array($arFields['CONTACT_ID']))
     			$arFields['CONTACT_ID'] = array($arFields['CONTACT_ID']);
     		if (isset($arFields['COMPANY_ID']) && !is_array($arFields['COMPANY_ID']))
     			$arFields['COMPANY_ID'] = array($arFields['COMPANY_ID']);*/
     if (isset($arFields['COMMENTS']) && $arFields['COMMENTS'] !== '') {
         $arFields['COMMENTS'] = preg_replace("/[\r\n]+/" . BX_UTF_PCRE_MODIFIER, "<br/>", $arFields['COMMENTS']);
     }
     $DB->StartTransaction();
     $CCrmEntity = new CCrmDeal(false);
     $res = $CCrmEntity->Update($arDocumentID['ID'], $arFields);
     if (!$res) {
         $DB->Rollback();
         throw new Exception($CCrmEntity->LAST_ERROR);
     }
     if (COption::GetOptionString("crm", "start_bp_within_bp", "N") == "Y") {
         $CCrmBizProc = new CCrmBizProc('DEAL');
         if (false === $CCrmBizProc->CheckFields($arDocumentID['ID'], true)) {
             throw new Exception($CCrmBizProc->LAST_ERROR);
         }
         if ($res && !$CCrmBizProc->StartWorkflow($arDocumentID['ID'])) {
             $DB->Rollback();
             throw new Exception($CCrmBizProc->LAST_ERROR);
         }
     }
     if ($res) {
         $DB->Commit();
     }
 }
 private function SaveOrderDataDeal($arOrder, $contactId = null, $companyId = null)
 {
     $dealId = 0;
     $dealTitle = "";
     $dbDeal = CCrmDeal::GetList(array(), array("ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => $arOrder["ID"], "CHECK_PERMISSIONS" => "N"));
     if ($arDeal = $dbDeal->Fetch()) {
         $dealId = $arDeal["ID"];
         $dealTitle = $arDeal["TITLE"];
     }
     $newDeal = $dealId == 0;
     if ($this->arExternalSale == null) {
         $this->arExternalSale = CCrmExternalSale::GetDefaultSettings($this->externalSaleId);
     }
     $arFields = array('ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => $arOrder["ID"], 'BEGINDATE' => $arOrder["DATE_INSERT"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'EXCH_RATE' => $arOrder["CURRENCY_RATE"], 'OPPORTUNITY' => $arOrder["PRICE"]);
     // Prevent reset comment if order comment is empty
     if (isset($arOrder["COMMENT"]) && $arOrder["COMMENT"] !== "") {
         $arFields["COMMENTS"] = $arOrder["COMMENT"];
     }
     if ($contactId != null && intval($contactId) > 0) {
         $arFields["CONTACT_ID"] = $contactId;
     }
     if ($companyId != null && intval($companyId) > 0) {
         $arFields["COMPANY_ID"] = $companyId;
     }
     static $arStageList = null;
     if ($arStageList == null) {
         $arStageList = CCrmStatus::GetStatusList('DEAL_STAGE');
     }
     // Prevent reset stage for existed deals
     if ($newDeal && array_key_exists("NEW", $arStageList)) {
         $arFields["STAGE_ID"] = "NEW";
     }
     $arAdditionalInfo = array();
     if ($contactId != null && intval($contactId) > 0) {
         if (isset($arOrder["CONTRACTOR"]["FULL_NAME"]) && $arOrder["CONTRACTOR"]["FULL_NAME"] != "") {
             $arAdditionalInfo['CONTACT_FULL_NAME'] = $arOrder["CONTRACTOR"]["FULL_NAME"];
         } elseif (isset($arOrder["CONTRACTOR"]["NAME"]) && $arOrder["CONTRACTOR"]["NAME"] != "") {
             $arAdditionalInfo['CONTACT_FULL_NAME'] = $arOrder["CONTRACTOR"]["NAME"];
         }
     }
     if ($companyId != null && intval($companyId) > 0) {
         if (isset($arOrder["CONTRACTOR"]["OFFICIAL_NAME"]) && $arOrder["CONTRACTOR"]["OFFICIAL_NAME"] != "") {
             $arAdditionalInfo['COMPANY_FULL_NAME'] = $arOrder["CONTRACTOR"]["OFFICIAL_NAME"];
         } elseif (isset($arOrder["CONTRACTOR"]["NAME"]) && $arOrder["CONTRACTOR"]["NAME"] != "") {
             $arAdditionalInfo['COMPANY_FULL_NAME'] = $arOrder["CONTRACTOR"]["NAME"];
         }
     }
     if (is_array($arOrder["PROPERTIES"])) {
         foreach ($arOrder["PROPERTIES"] as $arProp) {
             if (!empty($arProp["VALUE"])) {
                 $arAdditionalInfo[strtoupper($arProp["NAME"])] = $arProp["VALUE"];
                 if ($arAdditionalInfo[strtoupper($arProp["NAME"])] == "true") {
                     $arAdditionalInfo[strtoupper($arProp["NAME"])] = true;
                 } elseif ($arAdditionalInfo[strtoupper($arProp["NAME"])] == "false") {
                     $arAdditionalInfo[strtoupper($arProp["NAME"])] = false;
                 }
             }
             switch (strtoupper($arProp["NAME"])) {
                 case 'FINALSTATUS':
                     if ($arProp["VALUE"] == 'true') {
                         $arFields["CLOSED"] = "Y";
                         //$arFields["CLOSEDATE"] = $arOrder["DATE_UPDATE"];
                     } else {
                         $arFields["CLOSED"] = "N";
                         //$arFields["CLOSEDATE"] = false;
                     }
                     break;
                 case 'CANCELED':
                     if ($arProp["VALUE"] == 'true') {
                         if (array_key_exists("LOSE", $arStageList)) {
                             $arFields["STAGE_ID"] = "LOSE";
                         }
                         $arFields["PROBABILITY"] = 0;
                     }
                     break;
                 case 'ORDERPAID':
                     if ($arProp["VALUE"] == 'true') {
                         if (array_key_exists("WON", $arStageList)) {
                             $arFields["STAGE_ID"] = "WON";
                         }
                         $arFields["PROBABILITY"] = 100;
                     }
                     break;
                 case 'ORDERSTATUS':
                     //$arFields["CLOSED"] = "Y";
                     //$arFields["CLOSEDATE"] = $arOrder["DATE_UPDATE"];
                     break;
             }
         }
     }
     $arFields["ADDITIONAL_INFO"] = serialize($arAdditionalInfo);
     $accountNumber = isset($arOrder["ACCOUNT_NUMBER"]) && $arOrder["ACCOUNT_NUMBER"] !== '' ? $arOrder["ACCOUNT_NUMBER"] : $arOrder["ID"];
     $obj = new CCrmDeal(false);
     if ($dealId == 0) {
         $arFields['TITLE'] = sprintf("%s #%s", $this->arExternalSale["PREFIX"], $accountNumber);
         $arFields['OPENED'] = $this->arExternalSale["PUBLIC"];
         $arFields["TYPE_ID"] = 'SALE';
         $arFields["CLOSEDATE"] = ConvertTimeStamp(time() + CTimeZone::GetOffset() + 86400, "FULL");
         if (!isset($arFields["PROBABILITY"])) {
             $arFields["PROBABILITY"] = $this->arExternalSale["PROBABILITY"];
         }
         $assignedById = $this->arExternalSale["RESPONSIBLE"];
         if ($assignedById > 0) {
             $arFields["ASSIGNED_BY_ID"] = $assignedById;
         }
         $res = $obj->Add($arFields, true, array('DISABLE_USER_FIELD_CHECK' => true));
         if ($res > 0) {
             $dealId = (int) $res;
             $this->arImportResult->numberOfCreatedDeals++;
         }
     } else {
         if ($dealTitle === 'Deal') {
             $arFields['TITLE'] = sprintf("%s #%s", $this->arExternalSale["PREFIX"], $accountNumber);
         }
         // Disable properties change events generation ($bCompare = false) and user fields check 'DISABLE_USER_FIELD_CHECK' = true.
         $res = $obj->Update($dealId, $arFields, false, true, array('DISABLE_USER_FIELD_CHECK' => true));
         if ($res) {
             $this->arImportResult->numberOfUpdatedDeals++;
         }
     }
     if (!$res) {
         if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
             $this->AddError($ex->GetID(), $ex->GetString());
         } else {
             $this->AddError("CDA", "Deal creation error");
         }
         if (!empty($obj->LAST_ERROR)) {
             $this->AddError("CDA", $obj->LAST_ERROR);
         }
         return false;
     }
     return array($dealId, $newDeal);
 }
Exemplo n.º 6
0
 function InstallService($serviceID, $serviceStage)
 {
     $wizard =& $this->GetWizard();
     if (CModule::IncludeModule("iblock")) {
         $type = substr($serviceID, 0, -1);
         if ($type == "iblockElement") {
             $dbItem = CIBlockElement::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, false, array("ID"));
             while ($arItem = $dbItem->Fetch()) {
                 CIBlockElement::Delete($arItem["ID"]);
             }
         } elseif ($type == "iblockSectionElement") {
             $dbItem = CIBlockElement::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, false, array("ID"));
             while ($arItem = $dbItem->Fetch()) {
                 CIBlockElement::Delete($arItem["ID"]);
             }
             $dbItem = CIBlockSection::GetList(array(), array("=IBLOCK_CODE" => $serviceStage), false, array("ID"));
             while ($arItem = $dbItem->Fetch()) {
                 CIBlockSection::Delete($arItem["ID"]);
             }
         } elseif ($serviceID == "iblockDepartmentsElement") {
             $dbItem = CIBlockSection::GetList(array(), array("=IBLOCK_CODE" => "departments"));
             while ($arItem = $dbItem->Fetch()) {
                 if ($arItem["DEPTH_LEVEL"] > 2) {
                     CIBlockSection::Delete($arItem["ID"]);
                 }
             }
         } elseif ($serviceID == "tasks") {
             if (CModule::IncludeModule("tasks")) {
                 $dbItem = CTasks::GetList(array(), array("SITE_ID" => $wizard->GetVar("siteID")));
                 while ($arItem = $dbItem->Fetch()) {
                     CTasks::Delete($arItem["ID"]);
                 }
             }
         } elseif ($serviceID == "calendar") {
             if (CModule::IncludeModule("calendar")) {
                 $dbItem = CCalendarEvent::GetList();
                 foreach ($dbItem as $arItem) {
                     CCalendarEvent::Delete(array("id" => $arItem["ID"]));
                 }
             }
         } elseif ($serviceID == "meeting") {
             if (CModule::IncludeModule("meeting")) {
                 $dbItem = CMeeting::GetList(array(), array());
                 while ($arItem = $dbItem->Fetch()) {
                     if ($arItem["ID"]) {
                         CMeeting::Delete($arItem["ID"]);
                     }
                 }
             }
         } elseif ($serviceID == "user") {
             if ($serviceStage == "user") {
                 $dbUser = CUser::GetList($by = "ID", $order = "DESC", array(">ID" => 1));
                 while ($arUser = $dbUser->Fetch()) {
                     CUser::Delete($arUser["ID"]);
                 }
             }
         } elseif ($serviceID == "crm") {
             if ($serviceStage == "crm") {
                 if (CModule::IncludeModule('crm')) {
                     $CCrmLead = new CCrmLead();
                     $resLead = CCrmLead::GetList(array(), array(), array(), false);
                     while ($rowLead = $resLead->Fetch()) {
                         $CCrmLead->Delete($rowLead["ID"]);
                     }
                     $CCrmContact = new CCrmContact();
                     $resContact = CCrmContact::GetList(array(), array(), array(), false);
                     while ($rowContact = $resContact->Fetch()) {
                         $CCrmContact->Delete($rowContact["ID"]);
                     }
                     $CCrmCompany = new CCrmCompany();
                     $resCompany = CCrmCompany::GetList(array(), array(), array(), false);
                     while ($rowCompany = $resCompany->Fetch()) {
                         $CCrmCompany->Delete($rowCompany["ID"]);
                     }
                     $CCrmDeal = new CCrmDeal();
                     $resDeal = CCrmDeal::GetList(array(), array(), array(), false);
                     while ($rowDeal = $resDeal->Fetch()) {
                         $CCrmDeal->Delete($rowDeal["ID"]);
                     }
                 }
             }
         } elseif ($serviceID == "cache") {
             require_once $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/classes/general/cache_html.php";
             if ($serviceStage == "cache1") {
                 BXClearCache(true);
             } elseif ($serviceStage == "cache2") {
                 $GLOBALS["CACHE_MANAGER"]->CleanAll();
             } elseif ($serviceStage == "cache3") {
                 $GLOBALS["stackCacheManager"]->CleanAll();
             } elseif ($serviceStage == "cache4") {
                 CHTMLPagesCache::CleanAll();
             }
             COption::SetOptionString("main", "wizard_clear_exec", "Y", false, $wizard->GetVar("siteID"));
         }
     }
 }
Exemplo n.º 7
0
 protected function prepareCrmSelectorItem($ufInfo)
 {
     /** @global CUser $USER */
     global $USER;
     $result = false;
     $selectorItem = array();
     if (!CModule::IncludeModule('crm')) {
         return $result;
     }
     $CCrmPerms = new CCrmPerms($USER->GetID());
     $nPermittedEntityTypes = 0;
     if ($ufInfo['SETTINGS']['LEAD'] == 'Y' && !$CCrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['CONTACT'] == 'Y' && !$CCrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['COMPANY'] == 'Y' && !$CCrmPerms->HavePerm('COMPANY', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['DEAL'] == 'Y' && !$CCrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['QUOTE'] == 'Y' && !$CCrmPerms->HavePerm('QUOTE', BX_CRM_PERM_NONE, 'READ')) {
         $nPermittedEntityTypes++;
     }
     if ($ufInfo['SETTINGS']['PRODUCT'] == 'Y' && $CCrmPerms->HavePerm('CONFIG', BX_CRM_PERM_CONFIG, 'READ')) {
         $nPermittedEntityTypes++;
     }
     $usePrefix = true;
     /*$nPermittedEntityTypes > 1;*/
     // last 50 entity
     $entityTypes = array();
     $elements = array();
     $arSettings = $ufInfo['SETTINGS'];
     if (isset($arSettings['LEAD']) && $arSettings['LEAD'] == 'Y') {
         $entityTypes[] = 'lead';
         $arSelect = array('ID', 'TITLE', 'FULL_NAME', 'STATUS_ID');
         $obRes = CCrmLead::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         $arFiles = array();
         while ($arRes = $obRes->Fetch()) {
             $arRes['SID'] = $usePrefix ? 'L_' . $arRes['ID'] : $arRes['ID'];
             $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $arRes['FULL_NAME'], 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID'])), 'type' => 'lead', 'selected' => 'N');
         }
     }
     if (isset($arSettings['CONTACT']) && $arSettings['CONTACT'] == 'Y') {
         $entityTypes[] = 'contact';
         $arSelect = array('ID', 'FULL_NAME', 'COMPANY_TITLE', 'PHOTO');
         $obRes = CCrmContact::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         while ($arRes = $obRes->Fetch()) {
             $strImg = '';
             if (!empty($arRes['PHOTO']) && !isset($arFiles[$arRes['PHOTO']])) {
                 if ($arFile = CFile::GetFileArray($arRes['PHOTO'])) {
                     $arImg = CFile::ResizeImageGet($arFile, array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT);
                     if (is_array($arImg) && isset($arImg['src'])) {
                         $strImg = CHTTP::URN2URI($arImg['src'], '', true);
                     }
                 }
             }
             $arRes['SID'] = $usePrefix ? 'C_' . $arRes['ID'] : $arRes['ID'];
             $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['FULL_NAME']), 'desc' => empty($arRes['COMPANY_TITLE']) ? '' : $arRes['COMPANY_TITLE'], 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $arRes['ID'])), 'image' => $strImg, 'type' => 'contact', 'selected' => 'N');
         }
     }
     if (isset($arSettings['COMPANY']) && $arSettings['COMPANY'] == 'Y') {
         $entityTypes[] = 'company';
         $arCompanyTypeList = CCrmStatus::GetStatusListEx('COMPANY_TYPE');
         $arCompanyIndustryList = CCrmStatus::GetStatusListEx('INDUSTRY');
         $arSelect = array('ID', 'TITLE', 'COMPANY_TYPE', 'INDUSTRY', 'LOGO');
         $obRes = CCrmCompany::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         $arFiles = array();
         while ($arRes = $obRes->Fetch()) {
             $strImg = '';
             if (!empty($arRes['LOGO']) && !isset($arFiles[$arRes['LOGO']])) {
                 if ($arFile = CFile::GetFileArray($arRes['LOGO'])) {
                     $arImg = CFile::ResizeImageGet($arFile, array('width' => 25, 'height' => 25), BX_RESIZE_IMAGE_EXACT);
                     if (is_array($arImg) && isset($arImg['src'])) {
                         $strImg = CHTTP::URN2URI($arImg['src'], '', true);
                     }
                 }
                 $arFiles[$arRes['LOGO']] = $strImg;
             }
             $arRes['SID'] = $usePrefix ? 'CO_' . $arRes['ID'] : $arRes['ID'];
             $arDesc = array();
             if (isset($arCompanyTypeList[$arRes['COMPANY_TYPE']])) {
                 $arDesc[] = $arCompanyTypeList[$arRes['COMPANY_TYPE']];
             }
             if (isset($arCompanyIndustryList[$arRes['INDUSTRY']])) {
                 $arDesc[] = $arCompanyIndustryList[$arRes['INDUSTRY']];
             }
             $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => implode(', ', $arDesc), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $arRes['ID'])), 'image' => $strImg, 'type' => 'company', 'selected' => 'N');
         }
     }
     if (isset($arSettings['DEAL']) && $arSettings['DEAL'] == 'Y') {
         $entityTypes[] = 'deal';
         $arDealStageList = CCrmStatus::GetStatusListEx('DEAL_STAGE');
         $arSelect = array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME');
         $obRes = CCrmDeal::GetList(array('ID' => 'DESC'), array(), $arSelect, 50);
         while ($arRes = $obRes->Fetch()) {
             $arRes['SID'] = $usePrefix ? 'D_' . $arRes['ID'] : $arRes['ID'];
             $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
             $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
             $elements[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])), 'type' => 'deal', 'selected' => 'N');
         }
     }
     if (isset($arSettings['QUOTE']) && $arSettings['QUOTE'] == 'Y') {
         $entityTypes[] = 'quote';
         $arSelect = array('ID', 'QUOTE_NUMBER', 'TITLE', 'COMPANY_TITLE', 'CONTACT_FULL_NAME');
         $obRes = CCrmQuote::GetList(array('ID' => 'DESC'), array(), false, array('nTopCount' => 50), array('ID', 'QUOTE_NUMBER', 'TITLE', 'COMPANY_TITLE', 'CONTACT_FULL_NAME'));
         while ($arRes = $obRes->Fetch()) {
             $arRes['SID'] = $usePrefix ? 'Q_' . $arRes['ID'] : $arRes['ID'];
             $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
             $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
             $quoteTitle = empty($arRes['TITLE']) ? $arRes['QUOTE_NUMBER'] : $arRes['QUOTE_NUMBER'] . ' - ' . $arRes['TITLE'];
             $elements[] = array('title' => empty($quoteTitle) ? '' : str_replace(array(';', ','), ' ', $quoteTitle), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_show'), array('quote_id' => $arRes['ID'])), 'type' => 'quote', 'selected' => 'N');
         }
     }
     if (isset($arSettings['PRODUCT']) && $arSettings['PRODUCT'] == 'Y') {
         $entityTypes[] = 'product';
         $arSelect = array('ID', 'NAME', 'PRICE', 'CURRENCY_ID');
         $arPricesSelect = $arVatsSelect = array();
         $arSelect = CCrmProduct::DistributeProductSelect($arSelect, $arPricesSelect, $arVatsSelect);
         $obRes = CCrmProduct::GetList(array('ID' => 'DESC'), array('ACTIVE' => 'Y'), $arSelect, 50);
         $arProducts = $arProductId = array();
         while ($arRes = $obRes->Fetch()) {
             foreach ($arPricesSelect as $fieldName) {
                 $arRes[$fieldName] = null;
             }
             foreach ($arVatsSelect as $fieldName) {
                 $arRes[$fieldName] = null;
             }
             $arProductId[] = $arRes['ID'];
             $arProducts[$arRes['ID']] = $arRes;
         }
         CCrmProduct::ObtainPricesVats($arProducts, $arProductId, $arPricesSelect, $arVatsSelect);
         unset($arProductId, $arPricesSelect, $arVatsSelect);
         foreach ($arProducts as $arRes) {
             $arRes['SID'] = $usePrefix ? 'PROD_' . $arRes['ID'] : $arRes['ID'];
             $elements[] = array('title' => $arRes['NAME'], 'desc' => CCrmProduct::FormatPrice($arRes), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_product_show'), array('product_id' => $arRes['ID'])), 'type' => 'product', 'selected' => 'N');
         }
         unset($arProducts);
     }
     $selectorItem['USER_TYPE_ID'] = $ufInfo['USER_TYPE_ID'];
     $selectorItem['ENTITY_ID'] = $ufInfo['ENTITY_ID'];
     $selectorItem['FIELD_NAME'] = $ufInfo['FIELD_NAME'];
     $selectorItem['PREFIX'] = $usePrefix ? 'Y' : 'N';
     $selectorItem['MULTIPLE'] = 'Y';
     //$ufInfo['MULTIPLE'];
     $selectorItem['ENTITY_TYPE'] = $entityTypes;
     $selectorItem['ELEMENT'] = $elements;
     $result = $selectorItem;
     return $result;
 }
Exemplo n.º 8
0
 if (COption::GetOptionString('crm', '~crm_11_0_6_convertion', 'N') !== 'Y') {
     $baseCurrencyID = "USD";
     $rsLang = CLanguage::GetByID("ru");
     if ($arLang = $rsLang->Fetch()) {
         $baseCurrencyID = "RUB";
     } else {
         $rsLang = CLanguage::GetByID("de");
         if ($arLang = $rsLang->Fetch()) {
             $baseCurrencyID = "EUR";
         }
     }
     $arProducts = CCrmStatus::GetStatusList('PRODUCT', true);
     foreach ($arProducts as $prodCode => $prodName) {
         CCrmProduct::Add(array('NAME' => $prodName, 'ACTIVE' => 'Y', 'CURRENCY_ID' => $baseCurrencyID, 'PRICE' => 1, 'ORIGIN_ID' => 'CRM_PROD_' . $prodCode, 'ORIGINATOR_ID' => 'CRM_PRODUCT_REFERENCE'));
     }
     $rsDeals = CCrmDeal::GetList(array('ID' => 'ASC'), array("CHECK_PERMISSIONS" => "N"), array('ID', 'PRODUCT_ID', 'OPPORTUNITY', 'CURRENCY_ID'));
     while ($arDeal = $rsDeals->Fetch()) {
         $ID = isset($arDeal['ID']) ? intval($arDeal['ID']) : 0;
         if ($ID <= 0) {
             continue;
         }
         $productID = isset($arDeal['PRODUCT_ID']) ? $arDeal['PRODUCT_ID'] : '';
         if (isset($productID[0])) {
             $arProductRows = CCrmDeal::LoadProductRows($ID);
             if (count($arProductRows) > 0) {
                 // Already converted
                 continue;
             }
             $arProduct = CCrmProduct::GetByOriginID('CRM_PROD_' . $productID);
             if (!is_array($arProduct)) {
                 continue;
Exemplo n.º 9
0
 public function ListAddEnumFieldsValue($arParams, &$arValue, &$arReplaceValue, $delimiter = '<br />', $textonly = false, $arOptions = array())
 {
     global $APPLICATION;
     $arUserFields = $this->GetUserFields($this->sEntityID, 0, LANGUAGE_ID);
     $bSecondLoop = false;
     $arValuePrepare = array();
     if (!is_array($arOptions)) {
         $arOptions = array();
     }
     // The first loop to collect all the data fields
     foreach ($arUserFields as $FIELD_NAME => &$arUserField) {
         foreach ($arValue as $ID => $data) {
             if (!isset($arValue[$ID][$FIELD_NAME]) && $arUserField['USER_TYPE']['USER_TYPE_ID'] != 'boolean') {
                 continue;
             }
             if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'boolean') {
                 if (isset($arValue[$ID][$FIELD_NAME])) {
                     $arValue[$ID][$FIELD_NAME] == ($arValue[$ID][$FIELD_NAME] == 1 || $arValue[$ID][$FIELD_NAME] == 'Y' ? 'Y' : 'N');
                 }
                 $arVal = $arValue[$ID][$FIELD_NAME];
                 if (!is_array($arVal)) {
                     $arVal = array($arVal);
                 }
                 foreach ($arVal as $val) {
                     $val = (string) $val;
                     if (strlen($val) <= 0) {
                         //Empty value is always 'N' (not default field value)
                         $val = 'N';
                     }
                     $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . ($val == 1 ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'));
                     if ($arUserField['MULTIPLE'] == 'Y') {
                         $arValue[$ID][$FIELD_NAME][] = $val == 1 || $val == 'Y' ? 'Y' : 'N';
                     } else {
                         $arValue[$ID][$FIELD_NAME] = $val == 1 || $val == 'Y' ? 'Y' : 'N';
                     }
                 }
             } elseif ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'crm_status') {
                 $ar = CCrmStatus::GetStatusList($arUserField['SETTINGS']['ENTITY_TYPE']);
                 $arReplaceValue[$ID][$FIELD_NAME] = isset($ar[$arValue[$ID][$FIELD_NAME]]) ? $ar[$arValue[$ID][$FIELD_NAME]] : '';
             } else {
                 if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'crm') {
                     $arParams['CRM_ENTITY_TYPE'] = array();
                     if ($arUserField['SETTINGS']['LEAD'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'LEAD';
                     }
                     if ($arUserField['SETTINGS']['CONTACT'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'CONTACT';
                     }
                     if ($arUserField['SETTINGS']['COMPANY'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'COMPANY';
                     }
                     if ($arUserField['SETTINGS']['DEAL'] == 'Y') {
                         $arParams['CRM_ENTITY_TYPE'][] = 'DEAL';
                     }
                     $arParams['CRM_PREFIX'] = false;
                     if (count($arParams['CRM_ENTITY_TYPE']) > 1) {
                         $arParams['CRM_PREFIX'] = true;
                     }
                     $bSecondLoop = true;
                     $arVal = $arValue[$ID][$FIELD_NAME];
                     if (!is_array($arVal)) {
                         $arVal = array($arVal);
                     }
                     foreach ($arVal as $value) {
                         if ($arParams['CRM_PREFIX']) {
                             $ar = explode('_', $value);
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']][CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][CUserTypeCrm::GetLongEntityType($ar[0])][intval($ar[1])] = intval($ar[1]);
                         } else {
                             if (is_numeric($value)) {
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']][$arParams['CRM_ENTITY_TYPE'][0]][] = $value;
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][$arParams['CRM_ENTITY_TYPE'][0]][$value] = $value;
                             } else {
                                 $ar = explode('_', $value);
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']][CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
                                 $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][CUserTypeCrm::GetLongEntityType($ar[0])][intval($ar[1])] = intval($ar[1]);
                             }
                         }
                     }
                     $arReplaceValue[$ID][$FIELD_NAME] = '';
                 } else {
                     if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'file' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'employee' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'iblock_element' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'enumeration' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'iblock_section') {
                         $bSecondLoop = true;
                         $arVal = $arValue[$ID][$FIELD_NAME];
                         $arReplaceValue[$ID][$FIELD_NAME] = '';
                         if (!is_array($arVal)) {
                             $arVal = array($arVal);
                         }
                         foreach ($arVal as $value) {
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['FIELD'][$ID][$FIELD_NAME][$value] = $value;
                             $arValuePrepare[$arUserField['USER_TYPE']['USER_TYPE_ID']]['ID'][] = $value;
                         }
                     } else {
                         if ($arUserField['MULTIPLE'] == 'Y' && is_array($arValue[$ID][$FIELD_NAME])) {
                             array_walk($arValue[$ID][$FIELD_NAME], create_function('&$v', '$v = htmlspecialcharsbx($v);'));
                             $arReplaceValue[$ID][$FIELD_NAME] = implode($delimiter, $arValue[$ID][$FIELD_NAME]);
                         }
                     }
                 }
             }
         }
     }
     unset($arUserField);
     // The second loop for special field
     if ($bSecondLoop) {
         $arValueReplace = array();
         $arList = array();
         foreach ($arValuePrepare as $KEY => $VALUE) {
             // collect multi data
             if ($KEY == 'iblock_section') {
                 $dbRes = CIBlockSection::GetList(array('left_margin' => 'asc'), array('ID' => $VALUE['ID']), false);
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'file') {
                 $dbRes = CFile::GetList(array(), array('@ID' => implode(',', $VALUE['ID'])));
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'iblock_element') {
                 $dbRes = CIBlockElement::GetList(array('SORT' => 'DESC', 'NAME' => 'ASC'), array('ID' => $VALUE['ID']), false);
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'employee') {
                 $dbRes = CUser::GetList($by = 'last_name', $order = 'asc', array('ID' => implode('|', $VALUE['ID'])));
                 while ($arRes = $dbRes->Fetch()) {
                     $arList[$KEY][$arRes['ID']] = $arRes;
                 }
             } elseif ($KEY == 'enumeration') {
                 foreach ($VALUE['ID'] as $___value) {
                     $rsEnum = CUserFieldEnum::GetList(array(), array('ID' => $___value));
                     while ($arRes = $rsEnum->Fetch()) {
                         $arList[$KEY][$arRes['ID']] = $arRes;
                     }
                 }
             } elseif ($KEY == 'crm') {
                 if (isset($VALUE['LEAD']) && !empty($VALUE['LEAD'])) {
                     $dbRes = CCrmLead::GetList(array('TITLE' => 'ASC', 'LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $VALUE['LEAD']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['LEAD'][$arRes['ID']] = $arRes;
                     }
                 }
                 if (isset($VALUE['CONTACT']) && !empty($VALUE['CONTACT'])) {
                     $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $VALUE['CONTACT']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['CONTACT'][$arRes['ID']] = $arRes;
                     }
                 }
                 if (isset($VALUE['COMPANY']) && !empty($VALUE['COMPANY'])) {
                     $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), array('ID' => $VALUE['COMPANY']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['COMPANY'][$arRes['ID']] = $arRes;
                     }
                 }
                 if (isset($VALUE['DEAL']) && !empty($VALUE['DEAL'])) {
                     $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), array('ID' => $VALUE['DEAL']));
                     while ($arRes = $dbRes->Fetch()) {
                         $arList[$KEY]['DEAL'][$arRes['ID']] = $arRes;
                     }
                 }
             }
             // assemble multi data
             foreach ($VALUE['FIELD'] as $ID => $arFIELD_NAME) {
                 foreach ($arFIELD_NAME as $FIELD_NAME => $FIELD_VALUE) {
                     foreach ($FIELD_VALUE as $FIELD_VALUE_NAME => $FIELD_VALUE_ID) {
                         if ($KEY == 'iblock_section') {
                             $sname = htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['NAME']);
                             $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                         }
                         if ($KEY == 'iblock_element') {
                             $sname = htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['NAME']);
                             if (!$textonly) {
                                 $surl = GetIBlockElementLinkById($arList[$KEY][$FIELD_VALUE_ID]['ID']);
                                 if ($surl && strlen($surl) > 0) {
                                     $sname = '<a href="' . $surl . '">' . $sname . '</a>';
                                 }
                             }
                             $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                         } else {
                             if ($KEY == 'employee') {
                                 $sname = CUser::FormatName(CSite::GetNameFormat(false), $arList[$KEY][$FIELD_VALUE_ID], false, true);
                                 if (!$textonly) {
                                     $ar['PATH_TO_USER_PROFILE'] = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_user_profile'), array('user_id' => $arList[$KEY][$FIELD_VALUE_ID]['ID']));
                                     $sname = '<a href="' . $ar['PATH_TO_USER_PROFILE'] . '" id="balloon_' . $arParams['GRID_ID'] . '_' . $arList[$KEY][$FIELD_VALUE_ID]['ID'] . '">' . $sname . '</a>' . '<script type="text/javascript">BX.tooltip(' . $arList[$KEY][$FIELD_VALUE_ID]['ID'] . ', "balloon_' . $arParams['GRID_ID'] . '_' . $arList[$KEY][$FIELD_VALUE_ID]['ID'] . '", "");</script>';
                                 }
                                 $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                             } else {
                                 if ($KEY == 'enumeration') {
                                     $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['VALUE']);
                                 } else {
                                     if ($KEY == 'file') {
                                         $fileInfo = $arList[$KEY][$FIELD_VALUE_ID];
                                         if ($textonly) {
                                             $fileUrl = CFile::GetFileSRC($fileInfo);
                                         } else {
                                             $fileUrlTemplate = isset($arOptions['FILE_URL_TEMPLATE']) ? $arOptions['FILE_URL_TEMPLATE'] : '';
                                             $fileUrl = $fileUrlTemplate === '' ? CFile::GetFileSRC($fileInfo) : CComponentEngine::MakePathFromTemplate($fileUrlTemplate, array('owner_id' => $ID, 'field_name' => $FIELD_NAME, 'file_id' => $fileInfo['ID']));
                                         }
                                         $sname = $textonly ? $fileUrl : '<a href="' . htmlspecialcharsbx($fileUrl) . '" target="_blank">' . htmlspecialcharsbx($arList[$KEY][$FIELD_VALUE_ID]['FILE_NAME']) . '</a>';
                                         $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                                     } else {
                                         if ($KEY == 'crm') {
                                             foreach ($FIELD_VALUE_ID as $CID) {
                                                 $link = '';
                                                 $title = '';
                                                 $prefix = '';
                                                 if ($FIELD_VALUE_NAME == 'LEAD') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $CID));
                                                     $title = $arList[$KEY]['LEAD'][$CID]['TITLE'];
                                                     $prefix = 'L';
                                                 } elseif ($FIELD_VALUE_NAME == 'CONTACT') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $CID));
                                                     $title = CCrmContact::GetFullName($arList[$KEY]['CONTACT'][$CID], true);
                                                     $prefix = 'C';
                                                 } elseif ($FIELD_VALUE_NAME == 'COMPANY') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $CID));
                                                     $title = $arList[$KEY]['COMPANY'][$CID]['TITLE'];
                                                     $prefix = 'CO';
                                                 } elseif ($FIELD_VALUE_NAME == 'DEAL') {
                                                     $link = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $CID));
                                                     $title = $arList[$KEY]['DEAL'][$CID]['TITLE'];
                                                     $prefix = 'D';
                                                 }
                                                 $sname = htmlspecialcharsbx($title);
                                                 if (!$textonly) {
                                                     $tooltip = '<script type="text/javascript">BX.tooltip(' . $CID . ', "balloon_' . $ID . '_' . $FIELD_NAME . '_' . $FIELD_VALUE_NAME . '_' . $CID . '", "/bitrix/components/bitrix/crm.' . strtolower($FIELD_VALUE_NAME) . '.show/card.ajax.php", "crm_balloon' . ($FIELD_VALUE_NAME == 'LEAD' || $FIELD_VALUE_NAME == 'DEAL' || $FIELD_VALUE_NAME == 'QUOTE' ? '_no_photo' : '_' . strtolower($FIELD_VALUE_NAME)) . '", true);</script>';
                                                     $sname = '<a href="' . $link . '" target="_blank" id="balloon_' . $ID . '_' . $FIELD_NAME . '_' . $FIELD_VALUE_NAME . '_' . $CID . '">' . $sname . '</a>' . $tooltip;
                                                 } else {
                                                     $sname = "[{$prefix}]{$sname}";
                                                 }
                                                 $arReplaceValue[$ID][$FIELD_NAME] .= (!empty($arReplaceValue[$ID][$FIELD_NAME]) ? $delimiter : '') . $sname;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
        }
    }
    if (isset($arEntityList['CONTACT']) && !empty($arEntityList['CONTACT'])) {
        $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arEntityList['CONTACT']));
        while ($arRes = $dbRes->Fetch()) {
            $arEntityList['CONTACT'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['LAST_NAME'] . ' ' . $arRes['NAME'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_SHOW'], array('contact_id' => $arRes['ID'])));
        }
    }
    if (isset($arEntityList['COMPANY']) && !empty($arEntityList['COMPANY'])) {
        $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), array('ID' => $arEntityList['COMPANY']));
        while ($arRes = $dbRes->Fetch()) {
            $arEntityList['COMPANY'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_COMPANY_SHOW'], array('company_id' => $arRes['ID'])));
        }
    }
    if (isset($arEntityList['DEAL']) && !empty($arEntityList['DEAL'])) {
        $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), array('ID' => $arEntityList['DEAL']));
        while ($arRes = $dbRes->Fetch()) {
            $arEntityList['DEAL'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_SHOW'], array('deal_id' => $arRes['ID'])));
        }
    }
    if (isset($arEntityList['QUOTE']) && !empty($arEntityList['QUOTE'])) {
        $dbRes = CCrmQuote::GetList(array('TITLE' => 'ASC'), array('ID' => $arEntityList['QUOTE']));
        while ($arRes = $dbRes->Fetch()) {
            $arEntityList['QUOTE'][$arRes['ID']] = array('ENTITY_TITLE' => empty($arRes['TITLE']) ? $arRes['QUOTE_NUMBER'] : $arRes['QUOTE_NUMBER'] . ' - ' . $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_QUOTE_SHOW'], array('quote_id' => $arRes['ID'])));
        }
    }
    foreach ($arResult['EVENT'] as $key => $ar) {
        $arResult['EVENT'][$key]['ENTITY_TITLE'] = htmlspecialcharsbx($arEntityList[$ar['ENTITY_TYPE']][$ar['ENTITY_ID']]['ENTITY_TITLE']);
        $arResult['EVENT'][$key]['ENTITY_LINK'] = $arEntityList[$ar['ENTITY_TYPE']][$ar['ENTITY_ID']]['ENTITY_LINK'];
    }
}
Exemplo n.º 11
0
    if (is_numeric($search)) {
        $arFilter['ID'] = (int) $search;
    } else {
        if (preg_match('/(.*)\\[(\\d+?)\\]/i' . BX_UTF_PCRE_MODIFIER, $search, $arMatches)) {
            $arFilter['ID'] = (int) $arMatches[2];
            $arFilter['%TITLE'] = trim($arMatches[1]);
            $arFilter['LOGIC'] = 'OR';
        } else {
            $arFilter['%TITLE'] = $search;
        }
    }
    $arDealStageList = CCrmStatus::GetStatusListEx('DEAL_STAGE');
    $arSelect = array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME');
    $arOrder = array('TITLE' => 'ASC');
    $arData = array();
    $obRes = CCrmDeal::GetList($arOrder, $arFilter, $arSelect, $nPageTop);
    $arFiles = array();
    while ($arRes = $obRes->Fetch()) {
        $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
        $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
        $arData[] = array('id' => $multi ? 'D_' . $arRes['ID'] : $arRes['ID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])), 'title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $clientTitle, 'type' => 'deal');
    }
    Header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET);
    echo CUtil::PhpToJsObject($arData);
    die;
} elseif ($action === 'SAVE_PROGRESS') {
    $ID = isset($_REQUEST['ID']) ? intval($_REQUEST['ID']) : 0;
    $typeName = isset($_REQUEST['TYPE']) ? $_REQUEST['TYPE'] : '';
    $stageID = isset($_REQUEST['VALUE']) ? $_REQUEST['VALUE'] : '';
    $targetTypeName = CCrmOwnerType::ResolveName(CCrmOwnerType::Deal);
    if ($stageID === '' || $ID <= 0 || $typeName !== $targetTypeName) {
Exemplo n.º 12
0
 private static function TryInternalizeCrmEntityID($type, $value, &$ID)
 {
     if (preg_match('/^\\[([A-Z]+)\\]/i', $value, $m) > 0) {
         $valueType = CCrmOwnerType::Undefined;
         $prefix = strtoupper($m[1]);
         if ($prefix === 'L') {
             $valueType = CCrmOwnerType::Lead;
         } elseif ($prefix === 'C') {
             $valueType = CCrmOwnerType::Contact;
         } elseif ($prefix === 'CO') {
             $valueType = CCrmOwnerType::Company;
         } elseif ($prefix === 'D') {
             $valueType = CCrmOwnerType::Deal;
         }
         if ($valueType !== CCrmOwnerType::Undefined && $valueType !== $type) {
             return false;
         }
         $value = substr($value, strlen($m[0]));
     }
     // 1. Try to interpret data as entity ID
     // 2. Try to interpret data as entity name
     if ($type === CCrmOwnerType::Lead) {
         if (is_numeric($value)) {
             $arEntity = CCrmLead::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         $rsEntities = CCrmLead::GetListEx(array(), array('=TITLE' => $value), false, false, array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
     } elseif ($type === CCrmOwnerType::Contact) {
         if (is_numeric($value)) {
             $arEntity = CCrmContact::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         // Try to interpret value as FULL_NAME
         $rsEntities = CCrmContact::GetListEx(array(), array('=FULL_NAME' => $value), false, false, array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
         if (preg_match('/\\s*([^\\s]+)\\s+([^\\s]+)\\s*/', $value, $match) > 0) {
             // Try to interpret value as '#NAME# #LAST_NAME#'
             $rsEntities = CCrmContact::GetListEx(array(), array('=NAME' => $match[1], '=LAST_NAME' => $match[2]), false, false, array('ID'));
             while ($arEntity = $rsEntities->Fetch()) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
             // Try to interpret value as '#LAST_NAME# #NAME#'
             $rsEntities = CCrmContact::GetListEx(array(), array('=LAST_NAME' => $match[1], '=NAME' => $match[2]), false, false, array('ID'));
             while ($arEntity = $rsEntities->Fetch()) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         } else {
             // Try to interpret value as '#LAST_NAME#'
             $rsEntities = CCrmContact::GetListEx(array(), array('=LAST_NAME' => $value), false, false, array('ID'));
             while ($arEntity = $rsEntities->Fetch()) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
     } elseif ($type === CCrmOwnerType::Company) {
         if (is_numeric($value)) {
             $arEntity = CCrmCompany::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         $rsEntities = CCrmCompany::GetList(array(), array('=TITLE' => $value), array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
     } elseif ($type === CCrmOwnerType::Deal) {
         if (is_numeric($value)) {
             $arEntity = CCrmDeal::GetByID($value);
             if ($arEntity) {
                 $ID = intval($arEntity['ID']);
                 return true;
             }
         }
         $rsEntities = CCrmDeal::GetList(array(), array('=TITLE' => $value), array('ID'));
         while ($arEntity = $rsEntities->Fetch()) {
             $ID = intval($arEntity['ID']);
             return true;
         }
     }
     return false;
 }
Exemplo n.º 13
0
        $arCompany = array();
        while ($arCompany = $dbRes->Fetch()) {
            if (isset($arCompanyList[$arCompany['ID']]) && is_array($arCompanyList[$arCompany['ID']]) && count($arCompanyList[$arCompany['ID']]) > 0) {
                foreach ($arCompanyList[$arCompany['ID']] as $invoiceId) {
                    $arResult['INVOICE'][$invoiceId]['COMPANY_TITLE'] = $arCompany['TITLE'];
                    $arResult['INVOICE'][$invoiceId]['COMPANY_LINK_HTML'] = CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Company, 'ENTITY_ID' => $arCompany['ID'], 'PREFIX' => uniqid("crm_company_link_"), 'TITLE' => $arCompany['TITLE'], 'CLASS_NAME' => ''));
                }
                unset($invoiceId);
            }
        }
        unset($arCompany);
    }
    unset($dbRes);
}
if (count($arDealList) > 0) {
    $dbRes = CCrmDeal::GetList(array(), array('ID' => array_keys($arDealList)), array('TITLE'));
    if ($dbRes) {
        $arDeal = array();
        while ($arDeal = $dbRes->Fetch()) {
            if (isset($arDealList[$arDeal['ID']]) && is_array($arDealList[$arDeal['ID']]) && count($arDealList[$arDeal['ID']]) > 0) {
                foreach ($arDealList[$arDeal['ID']] as $invoiceId) {
                    $arResult['INVOICE'][$invoiceId]['DEAL_TITLE'] = $arDeal['TITLE'];
                    $arResult['INVOICE'][$invoiceId]['DEAL_LINK_HTML'] = CCrmViewHelper::PrepareEntityBaloonHtml(array('ENTITY_TYPE_ID' => CCrmOwnerType::Deal, 'ENTITY_ID' => $arDeal['ID'], 'PREFIX' => uniqid("crm_deal_link_"), 'TITLE' => $arDeal['TITLE'], 'CLASS_NAME' => ''));
                }
                unset($invoiceId);
            }
        }
        unset($arDeal);
    }
    unset($dbRes);
}
Exemplo n.º 14
0
 public static function CompareFields($arFieldsOrig, $arFieldsModif, $bCheckPerms = true)
 {
     $arMsg = array();
     if (array_key_exists('QUOTE_NUMBER', $arFieldsModif)) {
         $origQuoteNumber = isset($arFieldsOrig['QUOTE_NUMBER']) ? $arFieldsOrig['QUOTE_NUMBER'] : '';
         $modifQuoteNumber = isset($arFieldsModif['QUOTE_NUMBER']) ? $arFieldsModif['QUOTE_NUMBER'] : '';
         if ($origQuoteNumber != $modifQuoteNumber) {
             $arMsg[] = array('ENTITY_FIELD' => 'QUOTE_NUMBER', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_QUOTE_NUMBER'), 'EVENT_TEXT_1' => !empty($origQuoteNumber) ? $origQuoteNumber : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($modifQuoteNumber) ? $modifQuoteNumber : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
         }
         unset($origQuoteNumber, $modifQuoteNumber);
     }
     if (array_key_exists('TITLE', $arFieldsModif)) {
         $origTitle = isset($arFieldsOrig['TITLE']) ? $arFieldsOrig['TITLE'] : '';
         $modifTitle = isset($arFieldsModif['TITLE']) ? $arFieldsModif['TITLE'] : '';
         if ($origTitle != $modifTitle) {
             $arMsg[] = array('ENTITY_FIELD' => 'TITLE', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_TITLE'), 'EVENT_TEXT_1' => !empty($origTitle) ? $origTitle : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($modifTitle) ? $modifTitle : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
         }
         unset($origTitle, $modifTitle);
     }
     if (array_key_exists('LEAD_ID', $arFieldsModif)) {
         $origLeadId = isset($arFieldsOrig['LEAD_ID']) ? intval($arFieldsOrig['LEAD_ID']) : 0;
         $modifLeadId = isset($arFieldsModif['LEAD_ID']) ? intval($arFieldsModif['LEAD_ID']) : 0;
         if ($origLeadId != $modifLeadId) {
             $arLead = array();
             $arFilterTmp = array('@ID' => array($origLeadId, $modifLeadId));
             if (!$bCheckPerms) {
                 $arFilterTmp["CHECK_PERMISSIONS"] = "N";
             }
             $dbRes = CCrmLead::GetListEx(array('TITLE' => 'ASC'), $arFilterTmp);
             while ($arRes = $dbRes->Fetch()) {
                 $arLead[$arRes['ID']] = $arRes['TITLE'];
             }
             $arMsg[] = array('ENTITY_FIELD' => 'LEAD_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_LEAD_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arLead, $origLeadId), 'EVENT_TEXT_2' => CrmCompareFieldsList($arLead, $modifLeadId));
         }
         unset($origLeadId, $modifLeadId);
     }
     if (array_key_exists('DEAL_ID', $arFieldsModif)) {
         $origDealId = isset($arFieldsOrig['DEAL_ID']) ? intval($arFieldsOrig['DEAL_ID']) : 0;
         $modifDealId = isset($arFieldsModif['DEAL_ID']) ? intval($arFieldsModif['DEAL_ID']) : 0;
         if ($origDealId != $modifDealId) {
             $arDeal = array();
             $arFilterTmp = array('ID' => array($origDealId, $modifDealId));
             if (!$bCheckPerms) {
                 $arFilterTmp["CHECK_PERMISSIONS"] = "N";
             }
             $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), $arFilterTmp);
             while ($arRes = $dbRes->Fetch()) {
                 $arDeal[$arRes['ID']] = $arRes['TITLE'];
             }
             $arMsg[] = array('ENTITY_FIELD' => 'DEAL_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_DEAL_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arDeal, $origDealId), 'EVENT_TEXT_2' => CrmCompareFieldsList($arDeal, $modifDealId));
         }
         unset($origDealId, $modifDealId);
     }
     if (array_key_exists('COMPANY_ID', $arFieldsModif)) {
         $origCompanyId = isset($arFieldsOrig['COMPANY_ID']) ? intval($arFieldsOrig['COMPANY_ID']) : 0;
         $modifCompanyId = isset($arFieldsModif['COMPANY_ID']) ? intval($arFieldsModif['COMPANY_ID']) : 0;
         if ($origCompanyId != $modifCompanyId) {
             $arCompany = array();
             $arFilterTmp = array('ID' => array($origCompanyId, $modifCompanyId));
             if (!$bCheckPerms) {
                 $arFilterTmp["CHECK_PERMISSIONS"] = "N";
             }
             $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), $arFilterTmp);
             while ($arRes = $dbRes->Fetch()) {
                 $arCompany[$arRes['ID']] = $arRes['TITLE'];
             }
             $arMsg[] = array('ENTITY_FIELD' => 'COMPANY_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_COMPANY_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arCompany, $origCompanyId), 'EVENT_TEXT_2' => CrmCompareFieldsList($arCompany, $modifCompanyId));
         }
         unset($origCompanyId, $modifCompanyId);
     }
     if (array_key_exists('CONTACT_ID', $arFieldsModif)) {
         $origContactId = isset($arFieldsOrig['CONTACT_ID']) ? intval($arFieldsOrig['CONTACT_ID']) : 0;
         $modifContactId = isset($arFieldsModif['CONTACT_ID']) ? intval($arFieldsModif['CONTACT_ID']) : 0;
         if ($origContactId != $modifContactId) {
             $arContact = array();
             $arFilterTmp = array('@ID' => array($origContactId, $modifContactId));
             if (!$bCheckPerms) {
                 $arFilterTmp["CHECK_PERMISSIONS"] = "N";
             }
             $dbRes = CCrmContact::GetListEx(array(), $arFilterTmp);
             while ($arRes = $dbRes->Fetch()) {
                 $arContact[$arRes['ID']] = CCrmContact::PrepareFormattedName($arRes);
             }
             $arMsg[] = array('ENTITY_FIELD' => 'CONTACT_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CONTACT_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arContact, $origContactId), 'EVENT_TEXT_2' => CrmCompareFieldsList($arContact, $modifContactId));
         }
         unset($origContactId, $modifContactId);
     }
     if (array_key_exists('ASSIGNED_BY_ID', $arFieldsModif)) {
         $origAssignedById = isset($arFieldsOrig['ASSIGNED_BY_ID']) ? intval($arFieldsOrig['ASSIGNED_BY_ID']) : 0;
         $modifAssignedById = isset($arFieldsModif['ASSIGNED_BY_ID']) ? intval($arFieldsModif['ASSIGNED_BY_ID']) : 0;
         if ($origAssignedById != $modifAssignedById) {
             $arUser = array();
             $dbUsers = CUser::GetList($sort_by = 'last_name', $sort_dir = 'asc', array('ID' => implode('|', array(intval($origAssignedById), intval($modifAssignedById)))), array('FIELDS' => array('ID', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'LOGIN', 'TITLE', 'EMAIL')));
             while ($arRes = $dbUsers->Fetch()) {
                 $arUser[$arRes['ID']] = CUser::FormatName(CSite::GetNameFormat(false), $arRes);
             }
             $arMsg[] = array('ENTITY_FIELD' => 'ASSIGNED_BY_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_ASSIGNED_BY_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arUser, $origAssignedById), 'EVENT_TEXT_2' => CrmCompareFieldsList($arUser, $modifAssignedById));
         }
         unset($origAssignedById, $modifAssignedById);
     }
     if (array_key_exists('STATUS_ID', $arFieldsModif)) {
         $origStatusId = isset($arFieldsOrig['STATUS_ID']) ? $arFieldsOrig['STATUS_ID'] : '';
         $modifStatusId = isset($arFieldsModif['STATUS_ID']) ? $arFieldsModif['STATUS_ID'] : '';
         if ($origStatusId != $modifStatusId) {
             $arStatus = CCrmStatus::GetStatusList('QUOTE_STATUS');
             $arMsg[] = array('ENTITY_FIELD' => 'STATUS_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_STATUS_ID'), 'EVENT_TEXT_1' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $origStatusId)), 'EVENT_TEXT_2' => htmlspecialcharsbx(CrmCompareFieldsList($arStatus, $modifStatusId)));
         }
         unset($origStatusId, $modifStatusId);
     }
     if (array_key_exists('COMMENTS', $arFieldsModif)) {
         $origComments = isset($arFieldsOrig['COMMENTS']) ? $arFieldsOrig['COMMENTS'] : '';
         $modifComments = isset($arFieldsModif['COMMENTS']) ? $arFieldsModif['COMMENTS'] : '';
         if ($origComments != $modifComments) {
             $arMsg[] = array('ENTITY_FIELD' => 'COMMENTS', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_COMMENTS'), 'EVENT_TEXT_1' => !empty($origComments) ? $origComments : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($modifComments) ? $modifComments : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
         }
         unset($origComments, $modifComments);
     }
     if (array_key_exists('CONTENT', $arFieldsModif)) {
         $origContent = isset($arFieldsOrig['CONTENT']) ? $arFieldsOrig['CONTENT'] : '';
         $modifContent = isset($arFieldsModif['CONTENT']) ? $arFieldsModif['CONTENT'] : '';
         if ($origContent != $modifContent) {
             $arMsg[] = array('ENTITY_FIELD' => 'CONTENT', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CONTENT'), 'EVENT_TEXT_1' => !empty($origContent) ? $origContent : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($modifContent) ? $modifContent : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
         }
         unset($origContent, $modifContent);
     }
     if (array_key_exists('TERMS', $arFieldsModif)) {
         $origTerms = isset($arFieldsOrig['TERMS']) ? $arFieldsOrig['TERMS'] : '';
         $modifTerms = isset($arFieldsModif['TERMS']) ? $arFieldsModif['TERMS'] : '';
         if ($origTerms != $modifTerms) {
             $arMsg[] = array('ENTITY_FIELD' => 'TERMS', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_TERMS'), 'EVENT_TEXT_1' => !empty($origTerms) ? $origTerms : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($modifTerms) ? $modifTerms : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
         }
         unset($origTerms, $modifTerms);
     }
     if (array_key_exists('OPPORTUNITY', $arFieldsModif) || array_key_exists('CURRENCY_ID', $arFieldsModif)) {
         $origOpportunity = isset($arFieldsOrig['OPPORTUNITY']) ? round(doubleval($arFieldsOrig['OPPORTUNITY']), 2) : 0.0;
         $modifOpportunity = isset($arFieldsModif['OPPORTUNITY']) ? round(doubleval($arFieldsModif['OPPORTUNITY']), 2) : $origOpportunity;
         $origCurrencyId = isset($arFieldsOrig['CURRENCY_ID']) ? $arFieldsOrig['CURRENCY_ID'] : '';
         $modifCurrencyId = isset($arFieldsModif['CURRENCY_ID']) ? $arFieldsModif['CURRENCY_ID'] : $origCurrencyId;
         if ($origOpportunity != $modifOpportunity || $origCurrencyId != $modifCurrencyId) {
             $arStatus = CCrmCurrencyHelper::PrepareListItems();
             $arMsg[] = array('ENTITY_FIELD' => 'OPPORTUNITY', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_OPPORTUNITY'), 'EVENT_TEXT_1' => floatval($arFieldsOrig['OPPORTUNITY']) . (($val = CrmCompareFieldsList($arStatus, $origCurrencyId, '')) != '' ? ' (' . $val . ')' : ''), 'EVENT_TEXT_2' => floatval($arFieldsModif['OPPORTUNITY']) . (($val = CrmCompareFieldsList($arStatus, $modifCurrencyId, '')) != '' ? ' (' . $val . ')' : ''));
         }
         unset($origOpportunity, $modifOpportunity, $origCurrencyId, $modifCurrencyId);
     }
     if (array_key_exists('TAX_VALUE', $arFieldsModif) || array_key_exists('CURRENCY_ID', $arFieldsModif)) {
         if (isset($arFieldsOrig['TAX_VALUE']) && isset($arFieldsModif['TAX_VALUE']) && $arFieldsOrig['TAX_VALUE'] != $arFieldsModif['TAX_VALUE'] || isset($arFieldsOrig['CURRENCY_ID']) && isset($arFieldsModif['CURRENCY_ID']) && $arFieldsOrig['CURRENCY_ID'] != $arFieldsModif['CURRENCY_ID']) {
             $arStatus = CCrmCurrencyHelper::PrepareListItems();
             $arMsg[] = array('ENTITY_FIELD' => 'TAX_VALUE', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_TAX_VALUE'), 'EVENT_TEXT_1' => floatval($arFieldsOrig['TAX_VALUE']) . (($val = CrmCompareFieldsList($arStatus, $arFieldsOrig['CURRENCY_ID'], '')) != '' ? ' (' . $val . ')' : ''), 'EVENT_TEXT_2' => floatval($arFieldsModif['TAX_VALUE']) . (($val = CrmCompareFieldsList($arStatus, $arFieldsModif['CURRENCY_ID'], '')) != '' ? ' (' . $val . ')' : ''));
         }
     }
     if (array_key_exists('BEGINDATE', $arFieldsOrig) && array_key_exists('BEGINDATE', $arFieldsModif) && ConvertTimeStamp(strtotime($arFieldsOrig['BEGINDATE'])) != $arFieldsModif['BEGINDATE'] && $arFieldsOrig['BEGINDATE'] != $arFieldsModif['BEGINDATE']) {
         $arMsg[] = array('ENTITY_FIELD' => 'BEGINDATE', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_BEGINDATE'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['BEGINDATE']) ? ConvertTimeStamp(strtotime($arFieldsOrig['BEGINDATE'])) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['BEGINDATE']) ? $arFieldsModif['BEGINDATE'] : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
     }
     if (array_key_exists('CLOSEDATE', $arFieldsOrig) && array_key_exists('CLOSEDATE', $arFieldsModif) && ConvertTimeStamp(strtotime($arFieldsOrig['CLOSEDATE'])) != $arFieldsModif['CLOSEDATE'] && $arFieldsOrig['CLOSEDATE'] != $arFieldsModif['CLOSEDATE']) {
         $arMsg[] = array('ENTITY_FIELD' => 'CLOSEDATE', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CLOSEDATE'), 'EVENT_TEXT_1' => !empty($arFieldsOrig['CLOSEDATE']) ? ConvertTimeStamp(strtotime($arFieldsOrig['CLOSEDATE'])) : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($arFieldsModif['CLOSEDATE']) ? $arFieldsModif['CLOSEDATE'] : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
     }
     if (array_key_exists('OPENED', $arFieldsModif)) {
         if (isset($arFieldsOrig['OPENED']) && isset($arFieldsModif['OPENED']) && $arFieldsOrig['OPENED'] != $arFieldsModif['OPENED']) {
             $arMsg[] = array('ENTITY_FIELD' => 'OPENED', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_OPENED'), 'EVENT_TEXT_1' => $arFieldsOrig['OPENED'] == 'Y' ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'), 'EVENT_TEXT_2' => $arFieldsModif['OPENED'] == 'Y' ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'));
         }
     }
     if (array_key_exists('CLOSED', $arFieldsModif)) {
         if (isset($arFieldsOrig['CLOSED']) && isset($arFieldsModif['CLOSED']) && $arFieldsOrig['CLOSED'] != $arFieldsModif['CLOSED']) {
             $arMsg[] = array('ENTITY_FIELD' => 'CLOSED', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_CLOSED'), 'EVENT_TEXT_1' => $arFieldsOrig['CLOSED'] == 'Y' ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'), 'EVENT_TEXT_2' => $arFieldsModif['CLOSED'] == 'Y' ? GetMessage('MAIN_YES') : GetMessage('MAIN_NO'));
         }
     }
     // person type
     if (array_key_exists('PERSON_TYPE_ID', $arFieldsModif)) {
         $bPersonTypeChanged = isset($arFieldsOrig['PERSON_TYPE_ID']) && isset($arFieldsModif['PERSON_TYPE_ID']) && intval($arFieldsOrig['PERSON_TYPE_ID']) !== intval($arFieldsModif['PERSON_TYPE_ID']);
         if ($bPersonTypeChanged) {
             $arPersonTypes = CCrmPaySystem::getPersonTypesList();
             if ($bPersonTypeChanged) {
                 $arMsg[] = array('ENTITY_FIELD' => 'PERSON_TYPE_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_PERSON_TYPE_ID'), 'EVENT_TEXT_1' => CrmCompareFieldsList($arPersonTypes, $arFieldsOrig['PERSON_TYPE_ID']), 'EVENT_TEXT_2' => CrmCompareFieldsList($arPersonTypes, $arFieldsModif['PERSON_TYPE_ID']));
             }
         }
     }
     if (array_key_exists('LOCATION_ID', $arFieldsModif)) {
         $origLocationId = isset($arFieldsOrig['LOCATION_ID']) ? $arFieldsOrig['LOCATION_ID'] : '';
         $modifLocationId = isset($arFieldsModif['LOCATION_ID']) ? $arFieldsModif['LOCATION_ID'] : '';
         if ($origLocationId != $modifLocationId) {
             $origLocationString = $modifLocationString = '';
             if (IsModuleInstalled('sale') && CModule::IncludeModule('sale')) {
                 $location = new CSaleLocation();
                 $origLocationString = $origLocationId > 0 ? $location->GetLocationString($origLocationId) : '';
                 $modifLocationString = $modifLocationId > 0 ? $location->GetLocationString($modifLocationId) : '';
             }
             if (empty($origLocationString) && intval($origLocationId) > 0) {
                 $origLocationString = '[' . $origLocationId . ']';
             }
             if (empty($modifLocationString) && intval($modifLocationId) > 0) {
                 $modifLocationString = '[' . $modifLocationId . ']';
             }
             $arMsg[] = array('ENTITY_FIELD' => 'LOCATION_ID', 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_LOCATION_ID'), 'EVENT_TEXT_1' => $origLocationString, 'EVENT_TEXT_2' => $modifLocationString);
             unset($origLocationString, $modifLocationString);
         }
         unset($origLocationId, $modifLocationId);
     }
     $origClientFieldValue = $modifClientFieldValue = '';
     foreach (self::$clientFields as $fieldName) {
         if (array_key_exists($fieldName, $arFieldsModif)) {
             $origClientFieldValue = isset($arFieldsOrig[$fieldName]) ? $arFieldsOrig[$fieldName] : '';
             $modifClientFieldValue = isset($arFieldsModif[$fieldName]) ? $arFieldsModif[$fieldName] : '';
             if ($origClientFieldValue != $modifClientFieldValue) {
                 $arMsg[] = array('ENTITY_FIELD' => $fieldName, 'EVENT_NAME' => GetMessage('CRM_QUOTE_FIELD_COMPARE_' . $fieldName), 'EVENT_TEXT_1' => !empty($origClientFieldValue) ? $origClientFieldValue : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => !empty($modifClientFieldValue) ? $modifClientFieldValue : GetMessage('CRM_QUOTE_FIELD_COMPARE_EMPTY'));
             }
         }
     }
     unset($fieldName, $origClientFieldValue, $modifClientFieldValue);
     // Processing of the files
     if (array_key_exists('STORAGE_TYPE_ID', $arFieldsModif) && array_key_exists('STORAGE_ELEMENT_IDS', $arFieldsModif) && strlen($arFieldsModif['STORAGE_ELEMENT_IDS']) > 0) {
         $newStorageTypeID = isset($arFieldsModif['STORAGE_TYPE_ID']) ? intval($arFieldsModif['STORAGE_TYPE_ID']) : CCrmQuoteStorageType::Undefined;
         $oldStorageTypeID = isset($arFieldsOrig['STORAGE_TYPE_ID']) ? intval($arFieldsOrig['STORAGE_TYPE_ID']) : CCrmQuoteStorageType::Undefined;
         self::PrepareStorageElementIDs($arFieldsModif);
         $newElementIDs = $arFieldsModif['STORAGE_ELEMENT_IDS'];
         self::PrepareStorageElementIDs($arFieldsOrig);
         $oldElementIDs = $arFieldsOrig['STORAGE_ELEMENT_IDS'];
         if ($newStorageTypeID === $oldStorageTypeID && is_array($newElementIDs) && is_array($oldElementIDs)) {
             $arRemovedElementIDs = array_values(array_diff($oldElementIDs, $newElementIDs));
             if (!empty($arRemovedElementIDs)) {
                 foreach ($arRemovedElementIDs as $elementID) {
                     self::PrepareFileEvent($oldStorageTypeID, $elementID, 'REMOVE', $arFieldsModif, $arMsg);
                 }
                 unset($elementID);
             }
             unset($arRemovedElementIDs);
             $arAddedElementIDs = array_values(array_diff($newElementIDs, $oldElementIDs));
             if (!empty($arAddedElementIDs)) {
                 foreach ($arAddedElementIDs as $elementID) {
                     self::PrepareFileEvent($newStorageTypeID, $elementID, 'ADD', $arFieldsModif, $arMsg);
                 }
                 unset($elementID);
             }
             unset($arAddedElementIDs);
         } else {
             if ($newStorageTypeID !== $oldStorageTypeID && is_array($newElementIDs) && is_array($oldElementIDs)) {
                 foreach ($oldElementIDs as $elementID) {
                     self::PrepareFileEvent($oldStorageTypeID, $elementID, 'REMOVE', $arFieldsModif, $arMsg);
                 }
                 unset($elementID);
                 foreach ($newElementIDs as $elementID) {
                     self::PrepareFileEvent($newStorageTypeID, $elementID, 'ADD', $arFieldsModif, $arMsg);
                 }
                 unset($elementID);
             }
         }
         unset($newStorageTypeID, $oldStorageTypeID, $newElementIDs, $oldElementIDs);
     }
     return $arMsg;
 }
 public static function PrepareEntityInfo($entityTypeName, $entityID, $options = array())
 {
     $entityTypeName = strtoupper(strval($entityTypeName));
     $entityID = intval($entityID);
     if (!is_array($options)) {
         $options = array();
     }
     $result = array('TITLE' => "{$entityTypeName}_{$entityID}", 'URL' => '');
     if ($entityTypeName === '' || $entityID <= 0) {
         return $result;
     }
     if ($entityTypeName === 'CONTACT') {
         $contactTypes = CCrmStatus::GetStatusList('CONTACT_TYPE');
         $obRes = CCrmContact::GetList(array(), array('=ID' => $entityID), array('NAME', 'SECOND_NAME', 'LAST_NAME', 'TYPE_ID'));
         if ($arRes = $obRes->Fetch()) {
             $nameTemplate = isset($options['NAME_TEMPLATE']) ? $options['NAME_TEMPLATE'] : '';
             if ($nameTemplate === '') {
                 $nameTemplate = \Bitrix\Crm\Format\PersonNameFormatter::getFormat();
             }
             $result['TITLE'] = CUser::FormatName($nameTemplate, array('LOGIN' => '', 'NAME' => isset($arRes['NAME']) ? $arRes['NAME'] : '', 'LAST_NAME' => isset($arRes['LAST_NAME']) ? $arRes['LAST_NAME'] : '', 'SECOND_NAME' => isset($arRes['SECOND_NAME']) ? $arRes['SECOND_NAME'] : ''), false, false);
             $result['URL'] = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $entityID));
             // advanced info
             $advancedInfo = array();
             if (isset($arRes['TYPE_ID']) && $arRes['TYPE_ID'] != '' && isset($contactTypes[$arRes['TYPE_ID']])) {
                 $advancedInfo['CONTACT_TYPE'] = array('ID' => $arRes['TYPE_ID'], 'NAME' => $contactTypes[$arRes['TYPE_ID']]);
             }
             if (!empty($advancedInfo)) {
                 $result['ADVANCED_INFO'] = $advancedInfo;
             }
             // advanced info - phone number, e-mail
             $obRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'CONTACT', 'ELEMENT_ID' => $entityID));
             while ($arRes = $obRes->Fetch()) {
                 if ($arRes['TYPE_ID'] === 'PHONE' || $arRes['TYPE_ID'] === 'EMAIL') {
                     if (!is_array($result['ADVANCED_INFO'])) {
                         $result['ADVANCED_INFO'] = array();
                     }
                     if (!is_array($result['ADVANCED_INFO']['MULTY_FIELDS'])) {
                         $result['ADVANCED_INFO']['MULTY_FIELDS'] = array();
                     }
                     $result['ADVANCED_INFO']['MULTY_FIELDS'][] = array('ID' => $arRes['ID'], 'TYPE_ID' => $arRes['TYPE_ID'], 'VALUE_TYPE' => $arRes['VALUE_TYPE'], 'VALUE' => $arRes['VALUE']);
                 }
             }
         }
     } elseif ($entityTypeName === 'COMPANY') {
         $obRes = CCrmCompany::GetList(array(), array('=ID' => $entityID), array('TITLE'));
         if ($arRes = $obRes->Fetch()) {
             $result['TITLE'] = $arRes['TITLE'];
             $result['URL'] = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $entityID));
             // advanced info - phone number, e-mail
             $obRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => $entityID));
             while ($arRes = $obRes->Fetch()) {
                 if ($arRes['TYPE_ID'] === 'PHONE' || $arRes['TYPE_ID'] === 'EMAIL') {
                     if (!is_array($result['ADVANCED_INFO'])) {
                         $result['ADVANCED_INFO'] = array();
                     }
                     if (!is_array($result['ADVANCED_INFO']['MULTY_FIELDS'])) {
                         $result['ADVANCED_INFO']['MULTY_FIELDS'] = array();
                     }
                     $result['ADVANCED_INFO']['MULTY_FIELDS'][] = array('ID' => $arRes['ID'], 'TYPE_ID' => $arRes['TYPE_ID'], 'VALUE_TYPE' => $arRes['VALUE_TYPE'], 'VALUE' => $arRes['VALUE']);
                 }
             }
         }
     } elseif ($entityTypeName === 'LEAD') {
         $obRes = CCrmLead::GetList(array(), array('=ID' => $entityID), array('TITLE'));
         if ($arRes = $obRes->Fetch()) {
             $result['TITLE'] = $arRes['TITLE'];
             $result['URL'] = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $entityID));
             // advanced info - phone number, e-mail
             $obRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'LEAD', 'ELEMENT_ID' => $entityID));
             while ($arRes = $obRes->Fetch()) {
                 if ($arRes['TYPE_ID'] === 'PHONE' || $arRes['TYPE_ID'] === 'EMAIL') {
                     if (!is_array($result['ADVANCED_INFO'])) {
                         $result['ADVANCED_INFO'] = array();
                     }
                     if (!is_array($result['ADVANCED_INFO']['MULTY_FIELDS'])) {
                         $result['ADVANCED_INFO']['MULTY_FIELDS'] = array();
                     }
                     $result['ADVANCED_INFO']['MULTY_FIELDS'][] = array('ID' => $arRes['ID'], 'TYPE_ID' => $arRes['TYPE_ID'], 'VALUE_TYPE' => $arRes['VALUE_TYPE'], 'VALUE' => $arRes['VALUE']);
                 }
             }
         }
     } elseif ($entityTypeName === 'DEAL') {
         $obRes = CCrmDeal::GetList(array(), array('=ID' => $entityID), array('TITLE'));
         if ($arRes = $obRes->Fetch()) {
             $result['TITLE'] = $arRes['TITLE'];
             $result['URL'] = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $entityID));
         }
     } elseif ($entityTypeName === 'QUOTE') {
         $obRes = CCrmQuote::GetList(array(), array('=ID' => $entityID), false, false, array('QUOTE_NUMBER', 'TITLE'));
         if ($arRes = $obRes->Fetch()) {
             $result['TITLE'] = empty($arRes['TITLE']) ? $arRes['QUOTE_NUMBER'] : $arRes['QUOTE_NUMBER'] . ' - ' . $arRes['TITLE'];
             $result['URL'] = CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_quote_show'), array('quote_id' => $entityID));
         }
     }
     return $result;
 }
Exemplo n.º 16
0
global $APPLICATION;
$CCrmPerms = new CCrmPerms($USER->GetID());
if (!$USER->IsAuthorized() || $CCrmPerms->HavePerm('DEAL', BX_CRM_PERM_NONE)) {
    return;
}
$arResult = array();
$_GET['USER_ID'] = preg_replace('/^(CONTACT|COMPANY|LEAD|DEAL)_/i' . BX_UTF_PCRE_MODIFIER, '', $_GET['USER_ID']);
$iDealId = (int) $_GET['USER_ID'];
if ($iDealId > 0) {
    __IncludeLang(dirname(__FILE__) . '/lang/' . LANGUAGE_ID . '/' . basename(__FILE__));
    $arParams['PATH_TO_DEAL_SHOW'] = CrmCheckPath('PATH_TO_DEAL_SHOW', $arParams['PATH_TO_DEAL_SHOW'], $APPLICATION->GetCurPage() . '?deal_id=#deal_id#&show');
    $arParams['PATH_TO_DEAL_EDIT'] = CrmCheckPath('PATH_TO_DEAL_EDIT', $arParams['PATH_TO_DEAL_EDIT'], $APPLICATION->GetCurPage() . '?deal_id=#deal_id#&edit');
    $arParams['PATH_TO_CONTACT_SHOW'] = CrmCheckPath('PATH_TO_CONTACT_SHOW', $arParams['PATH_TO_CONTACT_SHOW'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&show');
    $arParams['PATH_TO_COMPANY_SHOW'] = CrmCheckPath('PATH_TO_COMPANY_SHOW', $arParams['PATH_TO_COMPANY_SHOW'], $APPLICATION->GetCurPage() . '?company_id=#company_id#&show');
    $arResult['STAGE_LIST'] = CCrmStatus::GetStatusListEx('DEAL_STAGE');
    $obRes = CCrmDeal::GetList(array(), array('ID' => $iDealId));
    $arDeal = $obRes->Fetch();
    if ($arDeal == false) {
        return;
    }
    $res = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'DEAL', 'ELEMENT_ID' => $iDealId));
    while ($ar = $res->Fetch()) {
        if (empty($arDeal[$ar['COMPLEX_ID']])) {
            $arDeal[$ar['COMPLEX_ID']] = CCrmFieldMulti::GetTemplateByComplex($ar['COMPLEX_ID'], $ar['VALUE']);
        }
    }
    $arDeal['PATH_TO_DEAL_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_SHOW'], array('deal_id' => $iDealId));
    $arDeal['PATH_TO_DEAL_EDIT'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_DEAL_EDIT'], array('deal_id' => $iDealId));
    $arDeal['PATH_TO_CONTACT_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_CONTACT_SHOW'], array('contact_id' => $arDeal['CONTACT_ID']));
    $arDeal['PATH_TO_COMPANY_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_COMPANY_SHOW'], array('company_id' => $arDeal['COMPANY_ID']));
    $arDeal['CONTACT_NAME'] = CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('NAME' => $arDeal['NAME'], 'LAST_NAME' => $arDeal['LAST_NAME'], 'SECOND_NAME' => $arDeal['SECOND_NAME']), true, false);
Exemplo n.º 17
0
}
$arParams['RESULT_TAB'] = trim($arParams['RESULT_TAB']);
$arResult['FORM_TYPE'] = ToUpper($arParams['FORM_TYPE']);
if (!in_array($arResult['FORM_TYPE'], array('LIST', 'SHOW', 'EDIT'))) {
    $arResult['FORM_TYPE'] = 'LIST';
}
$arResult['ENTITY_TYPE'] = ToUpper($arParams['ENTITY_TYPE']);
$arResult['ENTITY_ID'] = $arParams['ENTITY_ID'];
$arResult['ENTITY_ID'] = is_array($arResult['ENTITY_ID']) ? $arResult['ENTITY_ID'] : array($arResult['ENTITY_ID']);
$arFilter = array('ID' => $arResult['ENTITY_ID']);
switch ($arResult['ENTITY_TYPE']) {
    case 'CONTACT':
        $obRes = CCrmContact::GetList(array('ID' => 'ASC'), $arFilter, array('ID', 'ASSIGNED_BY_ID'));
        break;
    case 'DEAL':
        $obRes = CCrmDeal::GetList(array('ID' => 'ASC'), $arFilter, array('ID', 'ASSIGNED_BY_ID'));
        break;
    case 'COMPANY':
        $obRes = CCrmCompany::GetList(array('ID' => 'ASC'), $arFilter, array('ID', 'ASSIGNED_BY_ID'));
        break;
    default:
    case 'LEAD':
        $obRes = CCrmLead::GetList(array('ID' => 'ASC'), $arFilter, array('ID', 'ASSIGNED_BY_ID'));
        $arResult['ENTITY_TYPE'] = 'LEAD';
        break;
}
$arID = array();
while ($arRow = $obRes->Fetch()) {
    $arID[$arRow['ID']] = $arRow['ASSIGNED_BY_ID'];
}
if (empty($arID)) {
Exemplo n.º 18
0
         $arDesc = array();
         if (isset($arCompanyTypeList[$arRes['COMPANY_TYPE']])) {
             $arDesc[] = $arCompanyTypeList[$arRes['COMPANY_TYPE']];
         }
         if (isset($arCompanyIndustryList[$arRes['INDUSTRY']])) {
             $arDesc[] = $arCompanyIndustryList[$arRes['INDUSTRY']];
         }
         $ar[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => implode(', ', $arDesc), 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $arRes['ID'])), 'image' => $arImg['src'], 'type' => 'company', 'selected' => $sSelected);
     }
     $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']);
 }
 if ($arSettings['DEAL'] == 'Y' && isset($arSelected['DEAL']) && !empty($arSelected['DEAL'])) {
     $arDealStageList = CCrmStatus::GetStatusListEx('DEAL_STAGE');
     $arSelect = array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME');
     $ar = array();
     $obRes = CCrmDeal::GetList(array('ID' => 'DESC'), array('ID' => $arSelected['DEAL']), $arSelect);
     while ($arRes = $obRes->Fetch()) {
         $arRes['SID'] = $arResult['PREFIX'] == 'Y' ? 'D_' . $arRes['ID'] : $arRes['ID'];
         if (isset($arResult['SELECTED'][$arRes['SID']])) {
             unset($arResult['SELECTED'][$arRes['SID']]);
             $sSelected = 'Y';
         } else {
             $sSelected = 'N';
         }
         $clientTitle = !empty($arRes['COMPANY_TITLE']) ? $arRes['COMPANY_TITLE'] : '';
         $clientTitle .= ($clientTitle !== '' && !empty($arRes['CONTACT_FULL_NAME']) ? ', ' : '') . $arRes['CONTACT_FULL_NAME'];
         $ar[] = array('title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $clientTitle, 'id' => $arRes['SID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])), 'type' => 'deal', 'selected' => $sSelected);
     }
     $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']);
 }
 if ($arSettings['QUOTE'] == 'Y' && isset($arSelected['QUOTE']) && !empty($arSelected['QUOTE'])) {
Exemplo n.º 19
0
 public static function UpdateSearch($arFilter, $ENTITY_TYPE, $bOverWrite = false)
 {
     if (!CModule::IncludeModule('search')) {
         return false;
     }
     $limit = 1000;
     switch ($ENTITY_TYPE) {
         case 'CONTACT':
             $obRes = CCrmContact::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'FULL_NAME';
             break;
         case 'DEAL':
             $obRes = CCrmDeal::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'TITLE';
             break;
         case 'INVOICE':
             $obRes = CCrmInvoice::GetList(array('ID' => 'DESC'), $arFilter, false, array('nTopCount' => $limit), array('*'));
             $sTitleID = 'ORDER_TOPIC';
             break;
         case 'QUOTE':
             $obRes = CCrmQuote::GetList(array('ID' => 'ASC'), $arFilter, false, array('nTopCount' => intval($limit)), array());
             $sTitleID = 'TITLE';
             break;
         case 'COMPANY':
             $obRes = CCrmCompany::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'TITLE';
             break;
         default:
         case 'LEAD':
             $obRes = CCrmLead::GetList(array('ID' => 'ASC'), $arFilter, array(), $limit);
             $sTitleID = 'TITLE';
             $ENTITY_TYPE = 'LEAD';
             break;
     }
     if (!isset(self::$arMess[$ENTITY_TYPE])) {
         self::$arMess[$ENTITY_TYPE] = __IncludeLang($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/components/bitrix/crm.' . strtolower($ENTITY_TYPE) . '.show/lang/' . LANGUAGE_ID . '/component.php', true);
     }
     $arAllResult = array();
     $qty = 0;
     $lastItemID = '';
     if (is_object($obRes)) {
         while (($arRow = $obRes->Fetch()) !== false) {
             $elementID = $arRow['ID'];
             $lastItemID = $ENTITY_TYPE . '.' . $elementID;
             if ($ENTITY_TYPE === 'INVOICE') {
                 $arResult = CCrmInvoice::BuildSearchCard($arRow, self::$bReIndex);
             } elseif ($ENTITY_TYPE === 'QUOTE') {
                 $arResult = CCrmQuote::BuildSearchCard($arRow, self::$bReIndex);
             } else {
                 $multiFields = array();
                 if ($ENTITY_TYPE === 'CONTACT' || $ENTITY_TYPE === 'COMPANY' || $ENTITY_TYPE === 'LEAD') {
                     $obMultiFieldRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => $ENTITY_TYPE, 'ELEMENT_ID' => $elementID));
                     while ($multiField = $obMultiFieldRes->Fetch()) {
                         $fieldValue = $multiField['VALUE'];
                         $fieldTypeID = $multiField['TYPE_ID'];
                         if ($fieldValue === '' || $fieldTypeID !== 'PHONE' && $fieldTypeID !== 'EMAIL') {
                             continue;
                         }
                         if (!isset($multiFields[$fieldTypeID])) {
                             $multiFields[$fieldTypeID] = array();
                         }
                         $multiFields[$fieldTypeID][] = $fieldValue;
                     }
                 }
                 $arResult = self::_buildEntityCard($arRow, $sTitleID, $ENTITY_TYPE, array('FM' => $multiFields));
             }
             if (self::$bReIndex) {
                 if (self::$oCallback) {
                     $res = call_user_func(array(self::$oCallback, self::$callback_method), $arResult);
                     if (!$res) {
                         return $lastItemID;
                     }
                 }
             } else {
                 CSearch::Index('crm', $ENTITY_TYPE . '.' . $arRow['ID'], $arResult, $bOverWrite);
             }
             $arAllResult[] = $arResult;
             $qty++;
         }
     }
     if (!self::$bReIndex && !empty($arFilter['ID']) && $qty === 0) {
         CSearch::DeleteIndex('crm', (int) $arFilter['ID']);
     }
     if (self::$bReIndex && $qty === $limit && $lastItemID !== '') {
         return $lastItemID;
     }
     return $arAllResult;
 }
Exemplo n.º 20
0
                $ar = explode('_', $value);
                $arValue[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
            }
        }
    }
    $arResult['VALUE'] = array();
    if ($arParams['arUserField']['SETTINGS']['LEAD'] == 'Y' && isset($arValue['LEAD']) && !empty($arValue['LEAD'])) {
        $dbRes = CCrmLead::GetList(array('TITLE' => 'ASC', 'LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arValue['LEAD']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['LEAD'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID'])));
        }
    }
    if ($arParams['arUserField']['SETTINGS']['CONTACT'] == 'Y' && isset($arValue['CONTACT']) && !empty($arValue['CONTACT'])) {
        $dbRes = CCrmContact::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arValue['CONTACT']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['CONTACT'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['FULL_NAME'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_contact_show'), array('contact_id' => $arRes['ID'])));
        }
    }
    if ($arParams['arUserField']['SETTINGS']['COMPANY'] == 'Y' && isset($arValue['COMPANY']) && !empty($arValue['COMPANY'])) {
        $dbRes = CCrmCompany::GetList(array('TITLE' => 'ASC'), array('ID' => $arValue['COMPANY']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['COMPANY'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_company_show'), array('company_id' => $arRes['ID'])));
        }
    }
    if ($arParams['arUserField']['SETTINGS']['DEAL'] == 'Y' && isset($arValue['DEAL']) && !empty($arValue['DEAL'])) {
        $dbRes = CCrmDeal::GetList(array('TITLE' => 'ASC'), array('ID' => $arValue['DEAL']));
        while ($arRes = $dbRes->Fetch()) {
            $arResult['VALUE']['DEAL'][$arRes['ID']] = array('ENTITY_TITLE' => $arRes['TITLE'], 'ENTITY_LINK' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_deal_show'), array('deal_id' => $arRes['ID'])));
        }
    }
}
Exemplo n.º 21
0
 public static function collectUFValues($rows, $columnInfo, $total)
 {
     // uf columns
     $fileColumns = array();
     $diskFileColumns = array();
     $employeeColumns = array();
     $crmColumns = array();
     $crmStatusColumns = array();
     $iblockElementColumns = array();
     $iblockSectionColumns = array();
     if (is_array($columnInfo)) {
         foreach ($columnInfo as $k => $cInfo) {
             if ($cInfo['isUF'] && is_array($cInfo['ufInfo']) && isset($cInfo['ufInfo']['USER_TYPE_ID'])) {
                 switch ($cInfo['ufInfo']['USER_TYPE_ID']) {
                     case 'file':
                         $fileColumns[$k] = true;
                         break;
                     case 'disk_file':
                         $diskFileColumns[$k] = true;
                         break;
                     case 'employee':
                         $employeeColumns[$k] = true;
                         break;
                     case 'crm':
                         $crmColumns[$k] = true;
                         break;
                     case 'crm_status':
                         $crmStatusColumns[$k] = true;
                         break;
                     case 'iblock_element':
                         $iblockElementColumns[$k] = true;
                         break;
                     case 'iblock_section':
                         $iblockSectionColumns[$k] = true;
                         break;
                 }
             }
         }
     }
     $arFileID = array();
     $arDiskFileID = array();
     $arEmployeeID = array();
     $arCrmID = array();
     $arCrmStatusID = array();
     $arCrmStatusEntityType = array();
     $arIblockElementID = array();
     $arIblockSectionID = array();
     if (count($fileColumns) > 0 || count($diskFileColumns) > 0 || count($employeeColumns) > 0 || count($crmColumns) > 0 || count($crmStatusColumns) > 0 || count($iblockElementColumns) > 0 || count($iblockSectionColumns) > 0) {
         foreach ($rows as $row) {
             foreach ($row as $k => $v) {
                 // file
                 if (isset($fileColumns[$k])) {
                     if (is_array($v)) {
                         foreach ($v as $subv) {
                             $value = intval($subv);
                             if ($value > 0) {
                                 $arFileID[] = $value;
                             }
                         }
                     } else {
                         $value = intval($v);
                         if ($value > 0) {
                             $arFileID[] = $value;
                         }
                     }
                 }
                 // disk file
                 if (isset($diskFileColumns[$k])) {
                     if (is_array($v)) {
                         foreach ($v as $subv) {
                             $value = intval($subv);
                             if ($value > 0) {
                                 $arDiskFileID[] = $value;
                             }
                         }
                     } else {
                         $value = intval($v);
                         if ($value > 0) {
                             $arDiskFileID[] = $value;
                         }
                     }
                 }
                 // employee
                 if (isset($employeeColumns[$k])) {
                     if (is_array($v)) {
                         foreach ($v as $subv) {
                             $value = intval($subv);
                             if ($value > 0) {
                                 $arEmployeeID[] = $value;
                             }
                         }
                     } else {
                         $value = intval($v);
                         if ($value > 0) {
                             $arEmployeeID[] = $value;
                         }
                     }
                 }
                 // crm
                 if (isset($crmColumns[$k])) {
                     $prefixByType = array('lead' => 'L', 'contact' => 'C', 'company' => 'CO', 'deal' => 'D', 'quote' => 'Q');
                     $maxPrefixLength = 2;
                     // 'CO'
                     $singleTypePrefix = '';
                     if (is_array($columnInfo[$k]['ufInfo']['SETTINGS'])) {
                         $supportedTypes = array();
                         foreach ($columnInfo[$k]['ufInfo']['SETTINGS'] as $type => $supported) {
                             if ($supported === 'Y') {
                                 $supportedTypes[$type] = true;
                             }
                         }
                         $supportedTypes = array_keys($supportedTypes);
                         if (count($supportedTypes) === 1) {
                             if (isset($prefixByType[strtolower($supportedTypes[0])])) {
                                 $singleTypePrefix = $prefixByType[strtolower($supportedTypes[0])];
                             }
                         }
                         unset($supportedTypes, $type, $supported);
                     }
                     if (is_array($v)) {
                         foreach ($v as $subv) {
                             if (strlen($subv) > 0) {
                                 $prefix = '';
                                 if (($pos = strpos(substr($subv, 0, $maxPrefixLength + 1), '_')) !== false && $pos > 0) {
                                     $prefix = substr($subv, 0, $pos);
                                 }
                                 if (empty($prefix)) {
                                     $subv = $singleTypePrefix . '_' . $subv;
                                 }
                                 unset($prefix, $pos);
                                 $value = explode('_', trim(strval($subv)));
                                 if (strlen($value[0]) > 0 && strlen($value[1]) > 0) {
                                     if (!is_array($arCrmID[$value[0]])) {
                                         $arCrmID[$value[0]] = array();
                                     }
                                     $arCrmID[$value[0]][] = $value[1];
                                 }
                             }
                         }
                     } else {
                         if (strlen($v) > 0) {
                             $prefix = '';
                             if (($pos = strpos(substr($v, 0, $maxPrefixLength + 1), '_')) !== false && $pos > 0) {
                                 $prefix = substr($v, 0, $pos);
                             }
                             if (empty($prefix)) {
                                 $v = $singleTypePrefix . '_' . $v;
                             }
                             unset($prefix, $pos);
                             $value = explode('_', trim(strval($v)));
                             if (strlen($value[0]) > 0 && strlen($value[1]) > 0) {
                                 if (!is_array($arCrmID[$value[0]])) {
                                     $arCrmID[$value[0]] = array();
                                 }
                                 $arCrmID[$value[0]][] = $value[1];
                             }
                         }
                     }
                     unset($maxPrefixLength);
                 }
                 // crm_status
                 if (isset($crmStatusColumns[$k])) {
                     if (!isset($arCrmStatusEntityType[$k])) {
                         if (isset($columnInfo[$k]['ufInfo']['SETTINGS']['ENTITY_TYPE'])) {
                             $arCrmStatusEntityType[$k] = strval($columnInfo[$k]['ufInfo']['SETTINGS']['ENTITY_TYPE']);
                         }
                     }
                     if (!empty($arCrmStatusEntityType[$k])) {
                         if (is_array($v)) {
                             foreach ($v as $subv) {
                                 if (strlen($subv) > 0) {
                                     if (!is_array($arCrmStatusID[$arCrmStatusEntityType[$k]])) {
                                         $arCrmStatusID[$arCrmStatusEntityType[$k]] = array();
                                     }
                                     $arCrmStatusID[$arCrmStatusEntityType[$k]][] = $subv;
                                 }
                             }
                         } else {
                             if (strlen($v) > 0) {
                                 if (!is_array($arCrmStatusID[$arCrmStatusEntityType[$k]])) {
                                     $arCrmStatusID[$arCrmStatusEntityType[$k]] = array();
                                 }
                                 $arCrmStatusID[$arCrmStatusEntityType[$k]][] = $v;
                             }
                         }
                     }
                 }
                 // iblock_element
                 if (isset($iblockElementColumns[$k])) {
                     if (is_array($v)) {
                         foreach ($v as $subv) {
                             $value = intval($subv);
                             if ($value > 0) {
                                 $arIblockElementID[] = $value;
                             }
                         }
                     } else {
                         $value = intval($v);
                         if ($value > 0) {
                             $arIblockElementID[] = $value;
                         }
                     }
                 }
                 // iblock_section
                 if (isset($iblockSectionColumns[$k])) {
                     if (is_array($v)) {
                         foreach ($v as $subv) {
                             $value = intval($subv);
                             if ($value > 0) {
                                 $arIblockSectionID[] = $value;
                             }
                         }
                     } else {
                         $value = intval($v);
                         if ($value > 0) {
                             $arIblockSectionID[] = $value;
                         }
                     }
                 }
             }
         }
     }
     // collect files
     if (count($fileColumns) > 0) {
         if (count($arFileID) > 0) {
             $arFileID = array_unique($arFileID);
         }
         $i = 0;
         $cnt = 0;
         $stepCnt = 500;
         $nIDs = count($arFileID);
         $arID = array();
         $file = new CFile();
         foreach ($arFileID as $fileID) {
             $arID[$cnt++] = $fileID;
             $i++;
             if ($cnt === $stepCnt || $i === $nIDs) {
                 $res = $file->GetList(array(), array('@ID' => implode(',', $arID)));
                 if (is_object($res)) {
                     while ($arFile = $res->Fetch()) {
                         if ($arFile) {
                             if (array_key_exists("~src", $arFile)) {
                                 if ($arFile["~src"]) {
                                     $arFile["SRC"] = $arFile["~src"];
                                 } else {
                                     $arFile["SRC"] = $file->GetFileSRC($arFile, false, false);
                                 }
                             } else {
                                 $arFile["SRC"] = $file->GetFileSRC($arFile, false);
                             }
                             self::$ufFiles[intval($arFile['ID'])] = $arFile;
                         }
                     }
                 }
                 $cnt = 0;
                 $arID = array();
             }
         }
     }
     // collect disk files
     if (count($diskFileColumns) > 0) {
         if (count($arDiskFileID) > 0) {
             $arDiskFileID = array_unique($arDiskFileID);
         }
         $i = 0;
         $cnt = 0;
         $stepCnt = 500;
         $nIDs = count($arDiskFileID);
         $arID = array();
         foreach ($arDiskFileID as $diskFileID) {
             $arID[$cnt++] = $diskFileID;
             $i++;
             if ($cnt === $stepCnt || $i === $nIDs) {
                 $res = \Bitrix\Disk\AttachedObject::getList(array('filter' => array('ID' => $arID), 'select' => array('ID', 'NAME' => 'OBJECT.NAME', 'SIZE' => 'OBJECT.SIZE')));
                 $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
                 if (is_object($res)) {
                     while ($arDiskFile = $res->Fetch()) {
                         if ($arDiskFile) {
                             $arDiskFile['DOWNLOAD_URL'] = $urlManager->getUrlUfController('download', array('attachedId' => $arDiskFile['ID']));
                             self::$ufDiskFiles[intval($arDiskFile['ID'])] = $arDiskFile;
                         }
                     }
                 }
                 $cnt = 0;
                 $arID = array();
             }
         }
     }
     // collect employees
     if (count($employeeColumns) > 0) {
         if (count($arEmployeeID) > 0) {
             $arEmployeeID = array_unique($arEmployeeID);
         }
         $i = 0;
         $cnt = 0;
         $stepCnt = 500;
         $nIDs = count($arEmployeeID);
         $arID = array();
         foreach ($arEmployeeID as $employeeID) {
             $arID[$cnt++] = $employeeID;
             $i++;
             if ($cnt === $stepCnt || $i === $nIDs) {
                 $res = \Bitrix\Main\UserTable::getList(array('filter' => array('ID' => $arID), 'select' => array('ID', 'LOGIN', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'TITLE')));
                 if (is_object($res)) {
                     while ($arUser = $res->fetch()) {
                         self::$ufEmployees[intval($arUser['ID'])] = $arUser;
                     }
                 }
                 $cnt = 0;
                 $arID = array();
             }
         }
     }
     // collect crm elements
     if (count($crmColumns) > 0 && CModule::IncludeModule('crm')) {
         foreach ($arCrmID as $typeIndex => $arSubID) {
             if (count($arSubID) > 0) {
                 $arCrmID[$typeIndex] = array_unique($arSubID);
             }
             $i = 0;
             $cnt = 0;
             $stepCnt = 500;
             $nIDs = count($arSubID);
             $arID = array();
             foreach ($arSubID as $crmID) {
                 $arID[$cnt++] = $crmID;
                 $i++;
                 if ($cnt === $stepCnt || $i === $nIDs) {
                     $res = null;
                     switch ($typeIndex) {
                         case 'L':
                             $res = CCrmLead::GetList(array('ID' => 'DESC'), array('ID' => $arID), array('ID', 'TITLE', 'FULL_NAME', 'STATUS_ID'));
                             break;
                         case 'C':
                             $res = CCrmContact::GetList(array('ID' => 'DESC'), array('ID' => $arID), array('ID', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'FULL_NAME', 'COMPANY_TITLE', 'PHOTO'));
                             break;
                         case 'CO':
                             $res = CCrmCompany::GetList(array('ID' => 'DESC'), array('ID' => $arID), array('ID', 'TITLE', 'COMPANY_TYPE', 'INDUSTRY', 'LOGO'));
                             break;
                         case 'D':
                             $res = CCrmDeal::GetList(array('ID' => 'DESC'), array('ID' => $arID), array('ID', 'TITLE', 'STAGE_ID', 'COMPANY_TITLE', 'CONTACT_FULL_NAME'));
                             break;
                     }
                     if (is_object($res)) {
                         while ($arCrmElement = $res->Fetch()) {
                             self::$ufCrmElements[$typeIndex . '_' . $arCrmElement['ID']] = $arCrmElement;
                         }
                     }
                     $cnt = 0;
                     $arID = array();
                 }
             }
         }
     }
     // collect crm statuses
     if (count($crmStatusColumns) > 0 && CModule::IncludeModule('crm')) {
         foreach ($arCrmStatusID as $entityType => $arSubID) {
             if (count($arSubID) > 0) {
                 $arCrmID[$entityType] = array_unique($arSubID);
             }
             $res = null;
             $res = CCrmStatus::GetStatusList($entityType);
             if (is_array($res) && count($res) > 0) {
                 foreach ($arSubID as $crmStatusID) {
                     if (isset($res[$crmStatusID])) {
                         if (!isset(self::$ufCrmStatuses[$entityType])) {
                             self::$ufCrmStatuses[$entityType] = array();
                         }
                     }
                     self::$ufCrmStatuses[$entityType][$crmStatusID] = $res[$crmStatusID];
                 }
             }
         }
     }
     // collect iblock elements
     if (count($iblockElementColumns) > 0 && CModule::IncludeModule('iblock')) {
         if (count($arIblockElementID) > 0) {
             $arIblockElementID = array_unique($arIblockElementID);
         }
         $i = 0;
         $cnt = 0;
         $stepCnt = 500;
         $nIDs = count($arIblockElementID);
         $arID = array();
         foreach ($arIblockElementID as $iblockElementID) {
             $arID[$cnt++] = $iblockElementID;
             $i++;
             if ($cnt === $stepCnt || $i === $nIDs) {
                 $res = CIBlockElement::GetList(array('SORT' => 'ASC'), array('=ID' => $arID));
                 if (is_object($res)) {
                     while ($arIblockElement = $res->GetNext()) {
                         self::$ufIblockElements[intval($arIblockElement['ID'])] = $arIblockElement;
                     }
                 }
                 $cnt = 0;
                 $arID = array();
             }
         }
     }
     // collect iblock sections
     if (count($iblockSectionColumns) > 0 && CModule::IncludeModule('iblock')) {
         if (count($arIblockSectionID) > 0) {
             $arIblockSectionID = array_unique($arIblockSectionID);
         }
         $i = 0;
         $cnt = 0;
         $stepCnt = 500;
         $nIDs = count($arIblockSectionID);
         $arID = array();
         foreach ($arIblockSectionID as $iblockSectionID) {
             $arID[$cnt++] = $iblockSectionID;
             $i++;
             if ($cnt === $stepCnt || $i === $nIDs) {
                 $res = CIBlockSection::GetList(array('left_margin' => 'asc'), array('ID' => $arID), false, array('ID', 'NAME', 'SECTION_PAGE_URL'));
                 if (is_object($res)) {
                     while ($arIblockSection = $res->GetNext()) {
                         self::$ufIblockSections[intval($arIblockSection['ID'])] = $arIblockSection;
                     }
                 }
                 $cnt = 0;
                 $arID = array();
             }
         }
     }
 }