Exemple #1
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'];
 }
Exemple #2
0
             // Already converted
             continue;
         }
         $arProduct = CCrmProduct::GetByOriginID('CRM_PROD_' . $productID);
         if (!is_array($arProduct)) {
             continue;
         }
         $productID = isset($arProduct['ID']) ? $arProduct['ID'] : 0;
         if ($productID <= 0) {
             continue;
         }
         $arProductRows = array(array('PRODUCT_ID' => $productID, 'PRICE' => isset($arDeal['OPPORTUNITY']) ? doubleval($arDeal['OPPORTUNITY']) : 0.0, 'QUANTITY' => 1));
         CCrmDeal::SaveProductRows($ID, $arProductRows);
     }
 }
 $rsLeads = CCrmLead::GetList(array('ID' => 'ASC'), array("CHECK_PERMISSIONS" => "N"), array('ID', 'PRODUCT_ID', 'OPPORTUNITY', 'CURRENCY_ID'));
 while ($arLead = $rsLeads->Fetch()) {
     $ID = isset($arLead['ID']) ? intval($arLead['ID']) : 0;
     if ($ID <= 0) {
         continue;
     }
     $productID = isset($arLead['PRODUCT_ID']) ? $arLead['PRODUCT_ID'] : '';
     if (isset($productID[0])) {
         $arProductRows = CCrmLead::LoadProductRows($ID);
         if (count($arProductRows) > 0) {
             // already converted
             continue;
         }
         $arProduct = CCrmProduct::GetByOriginID('CRM_PROD_' . $productID);
         if (!is_array($arProduct)) {
             continue;
Exemple #3
0
            $arUser = $rsUser->Fetch();
            $arCal['OWNER_ID'] = CUser::FormatName($arParams["NAME_TEMPLATE"], $arUser, true);
        }
        $arCal['ENTITY_TYPE'] = $arCalEntityData['TYPE'];
        $arCal['ENTITY_ID'] = $arCalEntityData['ID'];
        $arCalList[$arCalEntityData['TYPE']][$arCalEntityData['ID']] = array();
        $arResult['CAL'][$arCal['ID'] . '_' . $sCalRel] = $arCal;
        $i++;
    }
    if ($iAddTask != 0) {
        $arResult['ROWS_COUNT'] += $iAddTask;
    }
}
if ($arResult['ACTIVITY_ENTITY_LINK'] == 'Y') {
    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'])));
        }
 public static function UpdateDocument($documentId, $arFields)
 {
     global $DB;
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     $dbDocumentList = CCrmLead::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;
         }
         $fieldType = $arDocumentFields[$key]["Type"];
         if (in_array($fieldType, array("phone", "email", "im", "web"), true)) {
             CCrmDocument::PrepareEntityMultiFields($arFields, strtoupper($fieldType));
             continue;
         }
         $arFields[$key] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]);
         if ($fieldType == "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 ($fieldType == "select" && substr($key, 0, 3) == "UF_") {
             $db = CUserTypeEntity::GetList(array(), array("ENTITY_ID" => "CRM_LEAD", "FIELD_NAME" => $key));
             if ($ar = $db->Fetch()) {
                 $arV = array();
                 $db = CUserTypeEnum::GetList($ar);
                 while ($ar = $db->GetNext()) {
                     $arV[$ar["XML_ID"]] = $ar["ID"];
                 }
                 foreach ($arFields[$key] as &$value) {
                     if (array_key_exists($value, $arV)) {
                         $value = $arV[$value];
                     }
                 }
                 unset($value);
             }
         } elseif ($fieldType == "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 ($fieldType == "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['COMMENTS']) && $arFields['COMMENTS'] !== '') {
         $arFields['COMMENTS'] = preg_replace("/[\r\n]+/" . BX_UTF_PCRE_MODIFIER, "<br/>", $arFields['COMMENTS']);
     }
     $DB->StartTransaction();
     $CCrmEntity = new CCrmLead(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('LEAD');
         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();
     }
 }
 foreach ($arResult['SELECTED'] as $value) {
     if ($arResult['PREFIX'] === 'Y') {
         $ar = explode('_', $value);
         $arSelected[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
     } else {
         if (is_numeric($value)) {
             $arSelected[$arParams['ENTITY_TYPE'][0]][] = $value;
         } else {
             $ar = explode('_', $value);
             $arSelected[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
         }
     }
 }
 if ($arSettings['LEAD'] == 'Y' && isset($arSelected['LEAD']) && !empty($arSelected['LEAD'])) {
     $arSelect = array('ID', 'TITLE', 'FULL_NAME', 'STATUS_ID');
     $obRes = CCrmLead::GetList(array('ID' => 'DESC'), array('ID' => $arSelected['LEAD']), $arSelect);
     $arFiles = array();
     $ar = array();
     while ($arRes = $obRes->Fetch()) {
         $arRes['SID'] = $arResult['PREFIX'] == 'Y' ? 'L_' . $arRes['ID'] : $arRes['ID'];
         if (isset($arResult['SELECTED'][$arRes['SID']])) {
             unset($arResult['SELECTED'][$arRes['SID']]);
             $sSelected = 'Y';
         } else {
             $sSelected = 'N';
         }
         $ar[] = 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' => $sSelected);
     }
     $arResult['ELEMENT'] = array_merge($ar, $arResult['ELEMENT']);
 }
 if ($arSettings['CONTACT'] == 'Y' && isset($arSelected['CONTACT']) && !empty($arSelected['CONTACT'])) {
Exemple #6
0
        }
    }
} else {
    $arResult['FORM_ID'] = isset($arParams['FORM_ID']) ? $arParams['FORM_ID'] : '';
    $arResult['FORM_TYPE'] = $arParams['FORM_TYPE'];
    $arResult['ENTITY_TYPE'] = $arParams['ENTITY_TYPE'];
    $arResult['ENTITY_ID'] = intval($arParams['ENTITY_ID']);
    $arResult['ENTITY_TITLE'] = GetMessage('CRM_EVENT_DEFAULT_TITLE');
    $arResult['EVENT_TYPE'] = $arParams['EVENT_TYPE'];
    $arResult['FREEZE_EVENT_ID'] = isset($arParams['FREEZE_EVENT_ID']) ? strtoupper($arParams['FREEZE_EVENT_ID']) : '';
    if ($arParams['EVENT_TYPE'] === 'PHONE') {
        $arResult['PHONE_GROUPS'] = array();
    }
    switch ($arParams['ENTITY_TYPE']) {
        case 'LEAD':
            $dbRes = CCrmLead::GetList(array('TITLE' => 'ASC', 'LAST_NAME' => 'ASC', 'NAME' => 'ASC'), array('ID' => $arResult['ENTITY_ID']));
            if ($arRes = $dbRes->Fetch()) {
                $arResult['ENTITY_TITLE'] = $arRes['TITLE'];
                $arResult['STATUS_ID'] = $arRes['STATUS_ID'];
                $arResult['ENTITY_CONVERTED'] = $arRes['STATUS_ID'] == 'CONVERTED' ? 'Y' : 'N';
            }
            $arEntityAttr = $CCrmPerms->GetEntityAttr('LEAD', $arResult['ENTITY_ID']);
            if ($CCrmPerms->CheckEnityAccess('LEAD', 'WRITE', $arEntityAttr[$arResult['ENTITY_ID']])) {
                $arResult['STATUS_LIST'] = array();
                $arResult['STATUS_LIST_EX'] = CCrmStatus::GetStatusList('STATUS');
                foreach ($arResult['STATUS_LIST_EX'] as $key => $value) {
                    if ($key == 'CONVERTED') {
                        continue;
                    }
                    if ($CCrmPerms->GetPermType('LEAD', 'WRITE', array('STATUS_ID' . $key)) > BX_CRM_PERM_NONE) {
                        $arResult['STATUS_LIST']['REFERENCE'][] = $value;
Exemple #7
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::GetList(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::GetList(array('LAST_NAME' => 'ASC', 'NAME' => 'ASC'), $arFilterTmp);
             while ($arRes = $dbRes->Fetch()) {
                 $arContact[$arRes['ID']] = $arRes['LAST_NAME'] . ' ' . $arRes['NAME'];
             }
             $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('SELECT' => array('NAME', 'SECOND_NAME', 'LAST_NAME', 'LOGIN', '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;
 }
Exemple #8
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"));
         }
     }
 }
 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;
 }
Exemple #10
0
$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)) {
    return;
}
$arResult['ERROR_MESSAGE'] = array();
$strCalendarDate = ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL', SITE_ID);
$arDefResult['VALUES'] = array('CALENDAR_TOPIC' => '', 'CALENDAR_FROM' => $strCalendarDate, 'CALENDAR_TO' => $strCalendarDate, 'CALENDAR_DESC' => '', 'REMIND_FLAG' => 'N', 'REMIND_LEN' => 15, 'REMIND_TYPE' => 'min', 'IMPORTANCE' => 'normal');
$arRemType = array('min', 'hour', 'day');
$arPriorityType = array('low', 'normal', 'high');
Exemple #11
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;
 }
Exemple #12
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;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #13
0
    return;
}
global $APPLICATION;
$CCrmPerms = new CCrmPerms($USER->GetID());
if (!$USER->IsAuthorized() || $CCrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE)) {
    return;
}
$arResult = array();
$_GET['USER_ID'] = preg_replace('/^(CONTACT|COMPANY|LEAD|DEAL)_/i' . BX_UTF_PCRE_MODIFIER, '', $_GET['USER_ID']);
$iLeadId = (int) $_GET['USER_ID'];
if ($iLeadId > 0) {
    __IncludeLang(dirname(__FILE__) . '/lang/' . LANGUAGE_ID . '/' . basename(__FILE__));
    $arParams['PATH_TO_LEAD_SHOW'] = CrmCheckPath('PATH_TO_LEAD_SHOW', $arParams['PATH_TO_LEAD_SHOW'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&show');
    $arParams['PATH_TO_LEAD_EDIT'] = CrmCheckPath('PATH_TO_LEAD_EDIT', $arParams['PATH_TO_LEAD_EDIT'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&edit');
    $arResult['STATUS_LIST'] = CCrmStatus::GetStatusListEx('STATUS');
    $obRes = CCrmLead::GetList(array(), array('ID' => $iLeadId));
    $arLead = $obRes->Fetch();
    if ($arLead == false) {
        return;
    }
    $res = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'LEAD', 'ELEMENT_ID' => $iLeadId));
    while ($ar = $res->Fetch()) {
        if (empty($arLead[$ar['COMPLEX_ID']])) {
            $arLead[$ar['COMPLEX_ID']] = CCrmFieldMulti::GetTemplateByComplex($ar['COMPLEX_ID'], $ar['VALUE']);
        }
    }
    $arLead['PATH_TO_LEAD_SHOW'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_SHOW'], array('lead_id' => $iLeadId));
    $arLead['PATH_TO_LEAD_EDIT'] = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_EDIT'], array('lead_id' => $iLeadId));
    $arLead['CONTACT_NAME'] = CUser::FormatName(\Bitrix\Crm\Format\PersonNameFormatter::getFormat(), array('NAME' => $arLead['NAME'], 'LAST_NAME' => $arLead['LAST_NAME'], 'SECOND_NAME' => $arLead['SECOND_NAME']), true, false);
    $strCard = '
<div class="bx-user-info-data-cont-video  bx-user-info-fields" id="bx_user_info_data_cont_1">
Exemple #14
0
 } else {
     if (preg_match('/(.*)\\[(\\d+?)\\]/i' . BX_UTF_PCRE_MODIFIER, $search, $arMatches)) {
         $arFilter['ID'] = (int) $arMatches[2];
         $arFilter['%TITLE'] = trim($arMatches[1]);
         $arFilter['%FULL_NAME'] = trim($arMatches[1]);
         $arFilter['LOGIC'] = 'OR';
     } else {
         $arFilter['%TITLE'] = trim($search);
         $arFilter['%FULL_NAME'] = trim($search);
         $arFilter['LOGIC'] = 'OR';
     }
 }
 $arSelect = array('ID', 'TITLE', 'FULL_NAME', 'STATUS_ID');
 $arOrder = array('TITLE' => 'ASC');
 $arData = array();
 $obRes = CCrmLead::GetList($arOrder, $arFilter, $arSelect, $nPageTop);
 $arFiles = array();
 $i = 0;
 $leadIndex = array();
 while ($arRes = $obRes->Fetch()) {
     $arData[$i] = array('id' => $multi ? 'L_' . $arRes['ID'] : $arRes['ID'], 'url' => CComponentEngine::MakePathFromTemplate(COption::GetOptionString('crm', 'path_to_lead_show'), array('lead_id' => $arRes['ID'])), 'title' => str_replace(array(';', ','), ' ', $arRes['TITLE']), 'desc' => $arRes['FULL_NAME'], 'type' => 'lead');
     $leadIndex[$arRes['ID']] =& $arData[$i];
     $i++;
 }
 // advanced info - phone number, e-mail
 $obRes = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'LEAD', 'ELEMENT_ID' => array_keys($leadIndex)));
 while ($arRes = $obRes->Fetch()) {
     if (isset($leadIndex[$arRes['ELEMENT_ID']]) && ($arRes['TYPE_ID'] === 'PHONE' || $arRes['TYPE_ID'] === 'EMAIL')) {
         $item =& $leadIndex[$arRes['ELEMENT_ID']];
         if (!is_array($item['advancedInfo'])) {
             $item['advancedInfo'] = array();
Exemple #15
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;
 }
 foreach ($arResult['VALUE'] as $value) {
     if ($arParams['PREFIX']) {
         $ar = explode('_', $value);
         $arValue[CUserTypeCrm::GetLongEntityType($ar[0])][] = intval($ar[1]);
     } else {
         if (is_numeric($value)) {
             $arValue[$arParams['ENTITY_TYPE'][0]][] = $value;
         } else {
             $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'])));
     }
Exemple #17
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();
             }
         }
     }
 }