public static function NormalizeUserFields(&$arFields, $entityID, $manager = null, $arOptions = null) { $entityID = strval($entityID); if (!$manager) { $manager = $GLOBALS['USER_FIELD_MANAGER']; } $userType = new CCrmUserType($manager, $entityID); $userType->PrepareUpdate($arFields, $arOptions); }
public static function GetDocumentFields($documentType) { $arDocumentID = self::GetDocumentInfo($documentType . '_0'); if (empty($arDocumentID)) { throw new CBPArgumentNullException('documentId'); } __IncludeLang($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/components/bitrix/crm.' . strtolower($arDocumentID['TYPE']) . '.edit/lang/' . LANGUAGE_ID . '/component.php'); $printableFieldNameSuffix = ' (' . GetMessage('CRM_FIELD_BP_TEXT') . ')'; $emailFieldNameSuffix = ' (' . GetMessage('CRM_FIELD_BP_EMAIL') . ')'; $arResult = array('ID' => array('Name' => GetMessage('CRM_FIELD_ID'), 'Type' => 'int', 'Filterable' => true, 'Editable' => false, 'Required' => false), 'TITLE' => array('Name' => GetMessage('CRM_FIELD_TITLE_DEAL'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => true), 'OPPORTUNITY' => array('Name' => GetMessage('CRM_FIELD_OPPORTUNITY'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'CURRENCY_ID' => array('Name' => GetMessage('CRM_FIELD_CURRENCY_ID'), 'Type' => 'select', 'Options' => CCrmCurrencyHelper::PrepareListItems(), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'OPPORTUNITY_ACCOUNT' => array('Name' => GetMessage('CRM_FIELD_OPPORTUNITY_ACCOUNT'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ACCOUNT_CURRENCY_ID' => array('Name' => GetMessage('CRM_FIELD_ACCOUNT_CURRENCY_ID'), 'Type' => 'select', 'Options' => CCrmCurrencyHelper::PrepareListItems(), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'PROBABILITY' => array('Name' => GetMessage('CRM_FIELD_PROBABILITY'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ASSIGNED_BY_ID' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID'), 'Type' => 'user', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ASSIGNED_BY_PRINTABLE' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID') . $printableFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'ASSIGNED_BY_EMAIL' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID') . $emailFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'STAGE_ID' => array('Name' => GetMessage('CRM_FIELD_STAGE_ID'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('DEAL_STAGE'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'STAGE_ID_PRINTABLE' => array('Name' => GetMessage('CRM_FIELD_STAGE_ID') . $printableFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'CLOSED' => array('Name' => GetMessage('CRM_FIELD_CLOSED'), 'Type' => 'bool', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'TYPE_ID' => array('Name' => GetMessage('CRM_FIELD_TYPE_ID'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('DEAL_TYPE'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'COMMENTS' => array('Name' => GetMessage('CRM_FIELD_COMMENTS'), 'Type' => 'text', 'Filterable' => false, 'Editable' => true, 'Required' => false), 'BEGINDATE' => array('Name' => GetMessage('CRM_FIELD_BEGINDATE'), 'Type' => 'datetime', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'CLOSEDATE' => array('Name' => GetMessage('CRM_FIELD_CLOSEDATE'), 'Type' => 'datetime', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'EVENT_DATE' => array('Name' => GetMessage('CRM_FIELD_EVENT_DATE'), 'Type' => 'datetime', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'EVENT_ID' => array('Name' => GetMessage('CRM_FIELD_EVENT_ID'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('EVENT_TYPE'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'EVENT_DESCRIPTION' => array('Name' => GetMessage('CRM_FIELD_EVENT_DESCRIPTION'), 'Type' => 'text', 'Filterable' => false, 'Editable' => true, 'Required' => false), "OPENED" => array("Name" => GetMessage("CRM_FIELD_OPENED"), "Type" => "bool", "Filterable" => true, "Editable" => true, "Required" => false), "LEAD_ID" => array("Name" => GetMessage("CRM_FIELD_LEAD_ID"), "Type" => "int", "Filterable" => true, "Editable" => true, "Required" => false), "ORIGINATOR_ID" => array("Name" => GetMessage("CRM_FIELD_ORIGINATOR_ID"), "Type" => "string", "Filterable" => true, "Editable" => true, "Required" => false), "ORIGIN_ID" => array("Name" => GetMessage("CRM_FIELD_ORIGIN_ID"), "Type" => "string", "Filterable" => true, "Editable" => true, "Required" => false), "CONTACT_ID" => array("Name" => GetMessage("CRM_FIELD_CONTACT_ID"), "Type" => "UF:crm", "Options" => array('CONTACT' => 'Y'), "Filterable" => true, "Editable" => true, "Required" => false, "Multiple" => false), "COMPANY_ID" => array("Name" => GetMessage("CRM_FIELD_COMPANY_ID"), "Type" => "UF:crm", "Options" => array('COMPANY' => 'Y'), "Filterable" => true, "Editable" => true, "Required" => false, "Multiple" => false), "DATE_CREATE" => array("Name" => GetMessage("CRM_DEAL_EDIT_FIELD_DATE_CREATE"), "Type" => "datetime", "Filterable" => true, "Editable" => false, "Required" => false), "DATE_MODIFY" => array("Name" => GetMessage("CRM_DEAL_EDIT_FIELD_DATE_MODIFY"), "Type" => "datetime", "Filterable" => true, "Editable" => false, "Required" => false)); global $USER_FIELD_MANAGER; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, 'CRM_DEAL'); $CCrmUserType->AddBPFields($arResult, array('PRINTABLE_SUFFIX' => GetMessage("CRM_FIELD_BP_TEXT"))); return $arResult; }
public static function GetDocumentFields($documentType) { $arDocumentID = self::GetDocumentInfo($documentType . '_0'); if (empty($arDocumentID)) { throw new CBPArgumentNullException('documentId'); } __IncludeLang($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/components/bitrix/crm.' . strtolower($arDocumentID['TYPE']) . '.edit/lang/' . LANGUAGE_ID . '/component.php'); $printableFieldNameSuffix = ' (' . GetMessage('CRM_FIELD_BP_TEXT') . ')'; $emailFieldNameSuffix = ' (' . GetMessage('CRM_FIELD_BP_EMAIL') . ')'; $arResult = array('ID' => array('Name' => GetMessage('CRM_FIELD_ID'), 'Type' => 'int', 'Filterable' => true, 'Editable' => false, 'Required' => false), 'TITLE' => array('Name' => GetMessage('CRM_FIELD_TITLE'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => true), 'COMPANY_TYPE' => array('Name' => GetMessage('CRM_FIELD_COMPANY_TYPE'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('COMPANY_TYPE'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'INDUSTRY' => array('Name' => GetMessage('CRM_FIELD_INDUSTRY'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('INDUSTRY'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'EMPLOYEES' => array('Name' => GetMessage('CRM_FIELD_EMPLOYEES'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('EMPLOYEES'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'REVENUE' => array('Name' => GetMessage('CRM_FIELD_REVENUE'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'CURRENCY_ID' => array('Name' => GetMessage('CRM_FIELD_CURRENCY_ID'), 'Type' => 'select', 'Options' => CCrmCurrencyHelper::PrepareListItems(), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ASSIGNED_BY_ID' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID'), 'Type' => 'user', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ASSIGNED_BY_PRINTABLE' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID') . $printableFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'ASSIGNED_BY_EMAIL' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID') . $emailFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'COMMENTS' => array('Name' => GetMessage('CRM_FIELD_COMMENTS'), 'Type' => 'text', 'Filterable' => false, 'Editable' => true, 'Required' => false), 'EMAIL' => array('Name' => GetMessage('CRM_FIELD_EMAIL'), 'Type' => 'email', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'PHONE' => array('Name' => GetMessage('CRM_FIELD_PHONE'), 'Type' => 'phone', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'WEB' => array('Name' => GetMessage('CRM_FIELD_WEB'), 'Type' => 'web', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'IM' => array('Name' => GetMessage('CRM_FIELD_MESSENGER'), 'Type' => 'im', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS' => array('Name' => GetMessage('CRM_FIELD_ADDRESS'), 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS_LEGAL' => array('Name' => GetMessage('CRM_FIELD_ADDRESS_LEGAL'), 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'BANKING_DETAILS' => array('Name' => GetMessage('CRM_FIELD_BANKING_DETAILS'), 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), "OPENED" => array("Name" => GetMessage("CRM_FIELD_OPENED"), "Type" => "bool", "Filterable" => true, "Editable" => true, "Required" => false), "LEAD_ID" => array("Name" => GetMessage("CRM_FIELD_LEAD_ID"), "Type" => "int", "Filterable" => true, "Editable" => true, "Required" => false), "ORIGINATOR_ID" => array("Name" => GetMessage("CRM_FIELD_ORIGINATOR_ID"), "Type" => "string", "Filterable" => true, "Editable" => true, "Required" => false), "ORIGIN_ID" => array("Name" => GetMessage("CRM_FIELD_ORIGIN_ID"), "Type" => "string", "Filterable" => true, "Editable" => true, "Required" => false), "CONTACT_ID" => array("Name" => GetMessage("CRM_FIELD_CONTACT_ID"), "Type" => "UF:crm", "Options" => array('CONTACT' => 'Y'), "Filterable" => true, "Editable" => true, "Required" => false, "Multiple" => false), "DATE_CREATE" => array("Name" => GetMessage("CRM_COMPANY_EDIT_FIELD_DATE_CREATE"), "Type" => "datetime", "Filterable" => true, "Editable" => false, "Required" => false), "DATE_MODIFY" => array("Name" => GetMessage("CRM_COMPANY_EDIT_FIELD_DATE_MODIFY"), "Type" => "datetime", "Filterable" => true, "Editable" => false, "Required" => false)); $ar = CCrmFieldMulti::GetEntityTypeList(); foreach ($ar as $typeId => $arFields) { $arResult[$typeId . '_PRINTABLE'] = array('Name' => GetMessage("CRM_FIELD_MULTI_" . $typeId) . $printableFieldNameSuffix, 'Type' => 'string', "Filterable" => true, "Editable" => false, "Required" => false); foreach ($arFields as $valueType => $valueName) { $arResult[$typeId . '_' . $valueType] = array('Name' => $valueName, 'Type' => 'string', "Filterable" => true, "Editable" => false, "Required" => false); $arResult[$typeId . '_' . $valueType . '_PRINTABLE'] = array('Name' => $valueName . $printableFieldNameSuffix, 'Type' => 'string', "Filterable" => true, "Editable" => false, "Required" => false); } } global $USER_FIELD_MANAGER; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, 'CRM_COMPANY'); $CCrmUserType->AddBPFields($arResult, array('PRINTABLE_SUFFIX' => GetMessage("CRM_FIELD_BP_TEXT"))); return $arResult; }
public static function GetDocumentFields($documentType) { $arDocumentID = self::GetDocumentInfo($documentType . '_0'); if (empty($arDocumentID)) { throw new CBPArgumentNullException('documentId'); } __IncludeLang($_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/components/bitrix/crm.' . strtolower($arDocumentID['TYPE']) . '.edit/lang/' . LANGUAGE_ID . '/component.php'); $addressLabels = Bitrix\Crm\EntityAddress::getShortLabels(); $printableFieldNameSuffix = ' (' . GetMessage('CRM_FIELD_BP_TEXT') . ')'; $emailFieldNameSuffix = ' (' . GetMessage('CRM_FIELD_BP_EMAIL') . ')'; $arResult = array('ID' => array('Name' => GetMessage('CRM_FIELD_ID'), 'Type' => 'int', 'Filterable' => true, 'Editable' => false, 'Required' => false), 'TITLE' => array('Name' => GetMessage('CRM_FIELD_TITLE'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => true), 'STATUS_ID' => array('Name' => GetMessage('CRM_FIELD_STATUS_ID'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('STATUS'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'STATUS_ID_PRINTABLE' => array('Name' => GetMessage('CRM_FIELD_STATUS_ID') . $printableFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'STATUS_DESCRIPTION' => array('Name' => GetMessage('CRM_FIELD_STATUS_DESCRIPTION'), 'Type' => 'text', 'Filterable' => false, 'Editable' => true, 'Required' => false), 'OPPORTUNITY' => array('Name' => GetMessage('CRM_FIELD_OPPORTUNITY'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'CURRENCY_ID' => array('Name' => GetMessage('CRM_FIELD_CURRENCY_ID'), 'Type' => 'select', 'Options' => CCrmCurrencyHelper::PrepareListItems(), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ASSIGNED_BY_ID' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID'), 'Type' => 'user', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ASSIGNED_BY_PRINTABLE' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID') . $printableFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'ASSIGNED_BY_EMAIL' => array('Name' => GetMessage('CRM_FIELD_ASSIGNED_BY_ID') . $emailFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'CREATED_BY_ID' => array('Name' => GetMessage('CRM_FIELD_CREATED_BY_ID'), 'Type' => 'user', 'Filterable' => true, 'Editable' => false, 'Required' => false), 'CREATED_BY_PRINTABLE' => array('Name' => GetMessage('CRM_FIELD_CREATED_BY_ID') . $printableFieldNameSuffix, 'Type' => 'string', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'COMMENTS' => array('Name' => GetMessage('CRM_FIELD_COMMENTS'), 'Type' => 'text', 'Filterable' => false, 'Editable' => true, 'Required' => false), 'NAME' => array('Name' => GetMessage('CRM_FIELD_NAME'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'LAST_NAME' => array('Name' => GetMessage('CRM_FIELD_LAST_NAME'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'SECOND_NAME' => array('Name' => GetMessage('CRM_FIELD_SECOND_NAME'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'BIRTHDATE' => array('Name' => GetMessage('CRM_LEAD_EDIT_FIELD_BIRTHDATE'), 'Type' => 'datetime', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'EMAIL' => array('Name' => GetMessage('CRM_FIELD_EMAIL'), 'Type' => 'email', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'PHONE' => array('Name' => GetMessage('CRM_FIELD_PHONE'), 'Type' => 'phone', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'WEB' => array('Name' => GetMessage('CRM_FIELD_WEB'), 'Type' => 'web', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'IM' => array('Name' => GetMessage('CRM_FIELD_MESSENGER'), 'Type' => 'im', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'COMPANY_TITLE' => array('Name' => GetMessage('CRM_FIELD_COMPANY_TITLE'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'POST' => array('Name' => GetMessage('CRM_FIELD_POST'), 'Type' => 'string', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'FULL_ADDRESS' => array('Name' => GetMessage('CRM_FIELD_ADDRESS'), 'Type' => 'text', 'Filterable' => false, 'Editable' => false, 'Required' => false), 'ADDRESS' => array('Name' => $addressLabels['ADDRESS'], 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS_2' => array('Name' => $addressLabels['ADDRESS_2'], 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS_CITY' => array('Name' => $addressLabels['CITY'], 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS_POSTAL_CODE' => array('Name' => $addressLabels['POSTAL_CODE'], 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS_REGION' => array('Name' => $addressLabels['REGION'], 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS_PROVINCE' => array('Name' => $addressLabels['PROVINCE'], 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'ADDRESS_COUNTRY' => array('Name' => $addressLabels['COUNTRY'], 'Type' => 'text', 'Filterable' => true, 'Editable' => true, 'Required' => false), 'SOURCE_ID' => array('Name' => GetMessage('CRM_FIELD_SOURCE_ID'), 'Type' => 'select', 'Options' => CCrmStatus::GetStatusListEx('SOURCE'), 'Filterable' => true, 'Editable' => true, 'Required' => false), 'SOURCE_DESCRIPTION' => array('Name' => GetMessage('CRM_FIELD_SOURCE_DESCRIPTION'), 'Type' => 'text', 'Filterable' => false, 'Editable' => true, 'Required' => false), "DATE_CREATE" => array("Name" => GetMessage("CRM_LEAD_EDIT_FIELD_DATE_CREATE"), "Type" => "datetime", "Filterable" => true, "Editable" => false, "Required" => false), "DATE_MODIFY" => array("Name" => GetMessage("CRM_LEAD_EDIT_FIELD_DATE_MODIFY"), "Type" => "datetime", "Filterable" => true, "Editable" => false, "Required" => false)); $ar = CCrmFieldMulti::GetEntityTypeList(); foreach ($ar as $typeId => $arFields) { $arResult[$typeId . '_PRINTABLE'] = array('Name' => GetMessage('CRM_FIELD_MULTI_' . $typeId) . $printableFieldNameSuffix, 'Type' => 'string', "Filterable" => true, "Editable" => false, "Required" => false); foreach ($arFields as $valueType => $valueName) { $arResult[$typeId . '_' . $valueType] = array('Name' => $valueName, 'Type' => 'string', "Filterable" => true, "Editable" => false, "Required" => false); $arResult[$typeId . '_' . $valueType . '_PRINTABLE'] = array('Name' => $valueName . $printableFieldNameSuffix, 'Type' => 'string', "Filterable" => true, "Editable" => false, "Required" => false); } } global $USER_FIELD_MANAGER; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, 'CRM_LEAD'); $CCrmUserType->AddBPFields($arResult, array('PRINTABLE_SUFFIX' => GetMessage("CRM_FIELD_BP_TEXT"))); return $arResult; }
public static function OnBeforeSocNetLogEntryGetRights($arEntryParams, &$arRights) { if ((!isset($arEntryParams["ENTITY_TYPE"]) || !isset($arEntryParams["ENTITY_ID"])) && isset($arEntryParams["LOG_ID"]) && intval($arEntryParams["LOG_ID"]) > 0) { if ($arLog = CSocNetLog::GetByID($arEntryParams["LOG_ID"])) { $arEntryParams["ENTITY_TYPE"] = $arLog["ENTITY_TYPE"]; $arEntryParams["ENTITY_ID"] = $arLog["ENTITY_ID"]; $arEntryParams["EVENT_ID"] = $arLog["EVENT_ID"]; } } if (!isset($arEntryParams["ENTITY_TYPE"]) || !in_array($arEntryParams["ENTITY_TYPE"], CCrmLiveFeedEntity::GetAll()) || !isset($arEntryParams["ENTITY_ID"])) { return true; } if ($arEntryParams["ENTITY_TYPE"] == CCrmLiveFeedEntity::Activity) { if (!isset($arEntryParams["ACTIVITY"])) { $arActivity = CCrmActivity::GetByID($arEntryParams["ENTITY_ID"]); if (!$arActivity) { return true; } $arEntryParams["ACTIVITY"] = $arActivity; $arEntryParams["ACTIVITY"]["COMMUNICATIONS"] = CCrmActivity::GetCommunications($arActivity["ID"]); } $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID($arEntryParams["ACTIVITY"]["OWNER_TYPE_ID"]) . $arEntryParams["ACTIVITY"]["OWNER_ID"]; $ownerEntityCode = $arEntryParams["ACTIVITY"]["OWNER_TYPE_ID"] . "_" . $arEntryParams["ACTIVITY"]["OWNER_ID"]; if (!empty($arEntryParams["ACTIVITY"]["COMMUNICATIONS"])) { foreach ($arEntryParams["ACTIVITY"]["COMMUNICATIONS"] as $arActivityCommunication) { if ($arActivityCommunication["ENTITY_TYPE_ID"] . "_" . $arActivityCommunication["ENTITY_ID"] == $ownerEntityCode) { $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID($arActivityCommunication["ENTITY_TYPE_ID"]) . $arActivityCommunication["ENTITY_ID"]; } } } if ($arEntryParams["ACTIVITY"]["TYPE_ID"] == CCrmActivityType::Task && intval($arEntryParams["ACTIVITY"]["ASSOCIATED_ENTITY_ID"]) > 0 && CModule::IncludeModule("tasks")) { $dbTask = CTasks::GetByID($arEntryParams["ACTIVITY"]["ASSOCIATED_ENTITY_ID"], false); if ($arTaskFields = $dbTask->Fetch()) { $arTaskOwners = isset($arTaskFields['UF_CRM_TASK']) ? $arTaskFields['UF_CRM_TASK'] : array(); $arOwnerData = array(); if (!is_array($arTaskOwners)) { $arTaskOwners = array($arTaskOwners); } $arFields['BINDINGS'] = array(); if (CCrmActivity::TryResolveUserFieldOwners($arTaskOwners, $arOwnerData, CCrmUserType::GetTaskBindingField())) { foreach ($arOwnerData as $arOwnerInfo) { $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID(CCrmOwnerType::ResolveID($arOwnerInfo['OWNER_TYPE_NAME'])) . $arOwnerInfo['OWNER_ID']; } } } } } elseif ($arEntryParams["ENTITY_TYPE"] == CCrmLiveFeedEntity::Invoice) { if (!isset($arEntryParams["INVOICE"])) { $arInvoice = CCrmInvoice::GetByID($arEntryParams["ENTITY_ID"]); if (!$arInvoice) { return true; } $arEntryParams["INVOICE"] = $arInvoice; } if (intval($arEntryParams["INVOICE"]["UF_CONTACT_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Contact . $arEntryParams["INVOICE"]["UF_CONTACT_ID"]; } if (intval($arEntryParams["INVOICE"]["UF_COMPANY_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Company . $arEntryParams["INVOICE"]["UF_COMPANY_ID"]; } if (intval($arEntryParams["INVOICE"]["UF_DEAL_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Deal . $arEntryParams["INVOICE"]["UF_DEAL_ID"]; } } else { $arRights[] = $arEntryParams["ENTITY_TYPE"] . $arEntryParams["ENTITY_ID"]; if (in_array($arEntryParams["EVENT_ID"], array("crm_lead_message", "crm_deal_message", "crm_contact_message", "crm_company_message"))) { $dbRight = CSocNetLogRights::GetList(array(), array("LOG_ID" => $arEntryParams["LOG_ID"])); while ($arRight = $dbRight->Fetch()) { $arRights[] = $arRight["GROUP_CODE"]; } } } return false; }
public static function OnBeforeTaskAdd(&$arTaskFields) { //Search for undefined or default title $title = isset($arTaskFields['TITLE']) ? trim($arTaskFields['TITLE']) : ''; if ($title !== '' && preg_match('/^\\s*CRM\\s*:\\s*$/i', $title) !== 1) { return; } $arTaskOwners = isset($arTaskFields['UF_CRM_TASK']) ? $arTaskFields['UF_CRM_TASK'] : array(); if (!is_array($arTaskOwners)) { $arTaskOwners = array($arTaskOwners); } $arOwnerData = array(); if (self::TryResolveUserFieldOwners($arTaskOwners, $arOwnerData, CCrmUserType::GetTaskBindingField())) { $arOwnerInfo = $arOwnerData[0]; $arTaskFields['TITLE'] = 'CRM: ' . CCrmOwnerType::GetCaption(CCrmOwnerType::ResolveID($arOwnerInfo['OWNER_TYPE_NAME']), $arOwnerInfo['OWNER_ID']); } }
$arResult['ELEMENT_ID'] = $arParams['ELEMENT_ID'] = isset($arParams['ELEMENT_ID']) ? intval($arParams['ELEMENT_ID']) : 0; $arResult['CAN_EDIT'] = CCrmCompany::CheckUpdatePermission($arResult['ELEMENT_ID'], $CCrmCompany->cPerms); $arParams['PATH_TO_COMPANY_LIST'] = CrmCheckPath('PATH_TO_COMPANY_LIST', $arParams['PATH_TO_COMPANY_LIST'], $APPLICATION->GetCurPage()); $arResult['PATH_TO_COMPANY_SHOW'] = $arParams['PATH_TO_COMPANY_SHOW'] = CrmCheckPath('PATH_TO_COMPANY_SHOW', $arParams['PATH_TO_COMPANY_SHOW'], $APPLICATION->GetCurPage() . '?company_id=#company_id#&show'); $arParams['PATH_TO_COMPANY_EDIT'] = CrmCheckPath('PATH_TO_COMPANY_EDIT', $arParams['PATH_TO_COMPANY_EDIT'], $APPLICATION->GetCurPage() . '?company_id=#company_id#&edit'); $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'); $arParams['PATH_TO_LEAD_CONVERT'] = CrmCheckPath('PATH_TO_LEAD_CONVERT', $arParams['PATH_TO_LEAD_CONVERT'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&convert'); $arParams['PATH_TO_CONTACT_SHOW'] = CrmCheckPath('PATH_TO_CONTACT_SHOW', $arParams['PATH_TO_CONTACT_SHOW'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&show'); $arParams['PATH_TO_CONTACT_EDIT'] = CrmCheckPath('PATH_TO_CONTACT_EDIT', $arParams['PATH_TO_CONTACT_EDIT'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&edit'); $arParams['PATH_TO_DEAL_SHOW'] = CrmCheckPath('PATH_TO_DEAL_SHOW', $arParams['PATH_TO_DEAL_SHOW'], $APPLICATION->GetCurPage() . '?deal_id=#deal_id#&show'); $arParams['PATH_TO_DEAL_EDIT'] = CrmCheckPath('PATH_TO_DEAL_EDIT', $arParams['PATH_TO_DEAL_EDIT'], $APPLICATION->GetCurPage() . '?deal_id=#deal_id#&edit'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); global $USER_FIELD_MANAGER; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmCompany::$sUFEntityID); $bEdit = false; $arResult['ELEMENT_ID'] = $arParams['ELEMENT_ID'] = (int) $arParams['ELEMENT_ID']; $obFields = CCrmCompany::GetListEx(array(), array('ID' => $arParams['ELEMENT_ID'])); $arFields = $obFields->GetNext(); if (!is_array($arFields)) { LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_COMPANY_LIST'], array())); } $arFields['FM'] = array(); $dbResMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'COMPANY', 'ELEMENT_ID' => $arResult['ELEMENT_ID'])); while ($arMultiFields = $dbResMultiFields->Fetch()) { $arFields['FM'][$arMultiFields['TYPE_ID']][$arMultiFields['ID']] = array('VALUE' => $arMultiFields['VALUE'], 'VALUE_TYPE' => $arMultiFields['VALUE_TYPE']); } $fullNameFormat = $arParams['NAME_TEMPLATE']; $arFields['~ASSIGNED_BY_FORMATTED_NAME'] = intval($arFields['~ASSIGNED_BY_ID']) > 0 ? CUser::FormatName($fullNameFormat, array('LOGIN' => $arFields['~ASSIGNED_BY_LOGIN'], 'NAME' => $arFields['~ASSIGNED_BY_NAME'], 'LAST_NAME' => $arFields['~ASSIGNED_BY_LAST_NAME'], 'SECOND_NAME' => $arFields['~ASSIGNED_BY_SECOND_NAME']), true, false) : GetMessage('RESPONSIBLE_NOT_ASSIGNED'); $arFields['ASSIGNED_BY_FORMATTED_NAME'] = htmlspecialcharsbx($arFields['~ASSIGNED_BY_FORMATTED_NAME']);
function GetFieldsList() { $fields = new CXMLCreator('Fields'); $fields->addChild(CXMLCreator::createTagAttributed('Field id="TITLE" name="' . GetMessage('CRM_FIELD_TITLE') . '" type="string" require="true" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="NAME" name="' . GetMessage('CRM_FIELD_NAME') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="LAST_NAME" name="' . GetMessage('CRM_FIELD_LAST_NAME') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="SECOND_NAME" name="' . GetMessage('CRM_FIELD_SECOND_NAME') . '" type="string" require="false" default=""', '')); $ar = CCrmFieldMulti::GetEntityComplexList(); foreach ($ar as $fieldId => $fieldName) { $fields->addChild(CXMLCreator::createTagAttributed('Field id="' . $fieldId . '" name="' . $fieldName . '" type="string" require="false" default=""', '')); } $fields->addChild(CXMLCreator::createTagAttributed('Field id="COMPANY_TITLE" name="' . GetMessage('CRM_FIELD_COMPANY_TITLE') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="POST" name="' . GetMessage('CRM_FIELD_POST') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="ADDRESS" name="' . GetMessage('CRM_FIELD_ADDRESS') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="COMMENTS" name="' . GetMessage('CRM_FIELD_COMMENTS') . '" type="string" require="false" default=""', '')); //$fieldList = CXMLCreator::createTagAttributed('Field id="PRODUCT_ID" name="'.GetMessage('CRM_FIELD_PRODUCT_ID').'" type="string" require="false" default=""', ''); // $fieldList->addChild(self::GetProductList()); //$fields->addChild($fieldList); $fieldList = CXMLCreator::createTagAttributed('Field id="STATUS_ID" name="' . GetMessage('CRM_FIELD_STATUS_ID') . '" type="string" require="false" default=""', ''); $fieldList->addChild(self::GetStatusList()); $fields->addChild($fieldList); $fields->addChild(CXMLCreator::createTagAttributed('Field id="OPPORTUNITY" name="' . GetMessage('CRM_FIELD_OPPORTUNITY') . '" type="double" require="false" default=""', '')); $fieldList = CXMLCreator::createTagAttributed('Field id="CURRENCY_ID" name="' . GetMessage('CRM_FIELD_CURRENCY_ID') . '" type="string" default=""', ''); $fieldList->addChild(self::GetCurrencyList()); $fields->addChild($fieldList); $fields->addChild(CXMLCreator::createTagAttributed('Field id="STATUS_DESCRIPTION" name="' . GetMessage('CRM_FIELD_STATUS_DESCRIPTION') . '" type="text" default=""', '')); $fieldList = CXMLCreator::createTagAttributed('Field id="SOURCE_ID" name="' . GetMessage('CRM_FIELD_SOURCE_ID') . '" type="string" default=""', ''); $fieldList->addChild(self::GetSourceList()); $fields->addChild($fieldList); $fields->addChild(CXMLCreator::createTagAttributed('Field id="SOURCE_DESCRIPTION" name="' . GetMessage('CRM_FIELD_SOURCE_DESCRIPTION') . '" type="text" default=""', '')); $CCrmUserType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], CCrmLead::$sUFEntityID); $CCrmUserType->AddWebserviceFields($fields); return array('GetFieldsListResult' => $fields); }
CUserOptions::SetOption('crm.deal.funnel', 'funnel_type', $funnelType, false, $arResult['CURRENT_USER_ID']); LocalRedirect($APPLICATION->GetCurPage()); } } //<-- Change of funnel type $arFilter = $arSort = array(); $bInternal = false; if (!empty($arParams['INTERNAL_FILTER']) || $arResult['GADGET'] == 'Y') { $bInternal = true; } $arResult['INTERNAL'] = $bInternal; if (!empty($arParams['INTERNAL_FILTER']) && is_array($arParams['INTERNAL_FILTER'])) { $arFilter = $arParams['INTERNAL_FILTER']; } global $USER_FIELD_MANAGER; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmDeal::$sUFEntityID); $arResult['STAGE_LIST'] = CCrmStatus::GetStatusListEx('DEAL_STAGE'); $arResult['CURRENCY_LIST'] = CCrmCurrencyHelper::PrepareListItems(); $arResult['FILTER'] = array(); $arResult['GRID_ID'] = 'CRM_DEAL_FUNNEL'; if (!$bInternal) { $arResult['FILTER2LOGIC'] = array(); ob_start(); $GLOBALS['APPLICATION']->IncludeComponent('bitrix:crm.entity.selector', '', array('ENTITY_TYPE' => 'CONTACT', 'INPUT_NAME' => 'CONTACT_ID', 'INPUT_VALUE' => isset($_REQUEST['CONTACT_ID']) ? intval($_REQUEST['CONTACT_ID']) : '', 'FORM_NAME' => $arResult['GRID_ID'], 'MULTIPLE' => 'N', 'FILTER' => true), false, array('HIDE_ICONS' => 'Y')); $sValContact = ob_get_contents(); ob_end_clean(); ob_start(); $GLOBALS['APPLICATION']->IncludeComponent('bitrix:crm.entity.selector', '', array('ENTITY_TYPE' => 'COMPANY', 'INPUT_NAME' => 'COMPANY_ID', 'INPUT_VALUE' => isset($_REQUEST['COMPANY_ID']) ? intval($_REQUEST['COMPANY_ID']) : '', 'FORM_NAME' => $arResult['GRID_ID'], 'MULTIPLE' => 'N', 'FILTER' => true), false, array('HIDE_ICONS' => 'Y')); $sValCompany = ob_get_contents(); ob_end_clean(); $arResult['FILTER'] = array(array('id' => 'OPPORTUNITY', 'name' => GetMessage('CRM_COLUMN_OPPORTUNITY'), 'type' => 'number'), array('id' => 'CURRENCY_ID', 'name' => GetMessage('CRM_COLUMN_CURRENCY_ID'), 'type' => 'list', 'items' => array('' => '') + CCrmCurrencyHelper::PrepareListItems()), array('id' => 'PROBABILITY', 'name' => GetMessage('CRM_COLUMN_PROBABILITY'), 'type' => 'number'), array('id' => 'CLOSED', 'name' => GetMessage('CRM_COLUMN_CLOSED'), 'type' => 'list', 'items' => array('' => '', 'Y' => GetMessage('MAIN_YES'), 'N' => GetMessage('MAIN_NO'))), array('id' => 'TYPE_ID', 'name' => GetMessage('CRM_COLUMN_TYPE_ID'), 'default' => 'Y', 'type' => 'list', 'items' => array('' => '') + CCrmStatus::GetStatusList('DEAL_TYPE')), array('id' => 'BEGINDATE', 'name' => GetMessage('CRM_COLUMN_BEGINDATE'), 'type' => 'date'), array('id' => 'CLOSEDATE', 'name' => GetMessage('CRM_COLUMN_CLOSEDATE'), 'type' => 'date'), array('id' => 'DATE_CREATE', 'name' => GetMessage('CRM_COLUMN_DATE_CREATE'), 'default' => 'Y', 'type' => 'date'), array('id' => 'DATE_MODIFY', 'name' => GetMessage('CRM_COLUMN_DATE_MODIFY'), 'default' => 'Y', 'type' => 'date'), array('id' => 'MODIFY_BY_ID', 'name' => GetMessage('CRM_COLUMN_MODIFY_BY'), 'enable_settings' => false, 'type' => 'user'), array('id' => 'ASSIGNED_BY_ID', 'name' => GetMessage('CRM_COLUMN_ASSIGNED_BY'), 'default' => 'Y', 'enable_settings' => false, 'type' => 'user'), array('id' => 'CONTACT_ID', 'name' => GetMessage('CRM_COLUMN_CONTACT_LIST'), 'type' => 'custom', 'value' => $sValContact), array('id' => 'COMPANY_ID', 'name' => GetMessage('CRM_COLUMN_COMPANY_LIST'), 'type' => 'custom', 'value' => $sValCompany));
function GetFieldsList() { $fields = new CXMLCreator('Fields'); $fields->addChild(CXMLCreator::createTagAttributed('Field id="NAME" name="' . GetMessage('CRM_FIELD_NAME') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="LAST_NAME" name="' . GetMessage('CRM_FIELD_LAST_NAME') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="SECOND_NAME" name="' . GetMessage('CRM_FIELD_SECOND_NAME') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="PHOTO" name="' . GetMessage('CRM_FIELD_PHOTO') . '" type="file" require="false" default=""', '')); $ar = CCrmFieldMulti::GetEntityComplexList(); foreach ($ar as $fieldId => $fieldName) { $fields->addChild(CXMLCreator::createTagAttributed('Field id="' . $fieldId . '" name="' . $fieldName . '" type="string" require="false" default=""', '')); } $fields->addChild(CXMLCreator::createTagAttributed('Field id="POST" name="' . GetMessage('CRM_FIELD_POST') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="ADDRESS" name="' . GetMessage('CRM_FIELD_ADDRESS') . '" type="string" require="false" default=""', '')); $fields->addChild(CXMLCreator::createTagAttributed('Field id="COMMENTS" name="' . GetMessage('CRM_FIELD_COMMENTS') . '" type="string" require="false" default=""', '')); $fieldList = CXMLCreator::createTagAttributed('Field id="TYPE_ID" name="' . GetMessage('CRM_FIELD_TYPE_ID') . '" type="int" default=""', ''); $fieldList->addChild(self::GetTypeList()); $fields->addChild($fieldList); $fieldList = CXMLCreator::createTagAttributed('Field id="SOURCE_ID" name="' . GetMessage('CRM_FIELD_SOURCE_ID') . '" type="int" default=""', ''); $fieldList->addChild(self::GetSourceList()); $fields->addChild($fieldList); $fields->addChild(CXMLCreator::createTagAttributed('Field id="SOURCE_DESCRIPTION" name="' . GetMessage('CRM_FIELD_SOURCE_DESCRIPTION') . '" type="text" default=""', '')); $CCrmUserType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], CCrmLead::$sUFEntityID); $CCrmUserType->AddWebserviceFields($fields); return array('GetFieldsListResult' => $fields); }
$arDemo = array('TITLE' => GetMessage('CRM_SAMPLE_TITLE'), 'COMPANY_TYPE' => $typeList['CUSTOMER'], 'INDUSTRY' => $industryList['IT'], 'EMPLOYEES' => $employeeList['EMPLOYEES_1'], 'REVENUE' => GetMessage('CRM_SAMPLE_REVENUE'), 'CURRENCY_ID' => GetMessage('CRM_SAMPLE_CURRENCY_ID'), 'PHONE_WORK' => GetMessage('CRM_SAMPLE_PHONE'), 'EMAIL_WORK' => GetMessage('CRM_SAMPLE_EMAIL'), 'OPENED' => GetMessage('MAIN_YES')); foreach ($arResult['HEADERS'] as $arField) { echo '"', str_replace('"', '""', $arField['name']), '";'; } echo "\n"; foreach ($arResult['HEADERS'] as $arField) { echo isset($arDemo[$arField['id']]) ? '"' . str_replace('"', '""', $arDemo[$arField['id']]) . '";' : '"";'; } echo "\n"; die; } else { if (isset($_REQUEST['import']) && isset($_SESSION['CRM_IMPORT_FILE'])) { $APPLICATION->RestartBuffer(); global $USER_FIELD_MANAGER; $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmCompany::$sUFEntityID); require_once $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/main/classes/general/csv_data.php'; $arStatus['COMPANY_TYPE_LIST'] = CCrmStatus::GetStatusListEx('COMPANY_TYPE'); $arStatus['EMPLOYEES_LIST'] = CCrmStatus::GetStatusListEx('EMPLOYEES'); $arStatus['INDUSTRY_LIST'] = CCrmStatus::GetStatusListEx('INDUSTRY'); $arStatus['OPENED_LIST'] = array('Y' => GetMessage('MAIN_YES'), 'N' => GetMessage('MAIN_NO')); $csvFile = new CCSVData(); $csvFile->LoadFile($_SESSION['CRM_IMPORT_FILE']); $csvFile->SetFieldsType('R'); $csvFile->SetPos($_SESSION['CRM_IMPORT_FILE_POS']); $csvFile->SetFirstHeader($_SESSION['CRM_IMPORT_FILE_FIRST_HEADER']); $csvFile->SetDelimiter($_SESSION['CRM_IMPORT_FILE_SEPORATOR']); $arResult = array(); $arResult['import'] = 0; $arResult['duplicate'] = 0; $arResult['duplicate_url'] = '';
die; } if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } CModule::IncludeModule('fileman'); if (IsModuleInstalled('bizproc')) { if (!CModule::IncludeModule('bizproc')) { ShowError(GetMessage('BIZPROC_MODULE_NOT_INSTALLED')); return; } } global $USER_FIELD_MANAGER, $DB, $USER, $APPLICATION; $CCrmLead = new CCrmLead(); $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmLead::$sUFEntityID); $CCrmBizProc = new CCrmBizProc('LEAD'); $userPermissions = CCrmPerms::GetCurrentUserPermissions(); $arParams['PATH_TO_LEAD_LIST'] = CrmCheckPath('PATH_TO_LEAD_LIST', $arParams['PATH_TO_LEAD_LIST'], $APPLICATION->GetCurPage()); $arParams['PATH_TO_LEAD_EDIT'] = CrmCheckPath('PATH_TO_LEAD_EDIT', $arParams['PATH_TO_LEAD_EDIT'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&edit'); $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_CONVERT'] = CrmCheckPath('PATH_TO_LEAD_CONVERT', $arParams['PATH_TO_LEAD_CONVERT'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&convert'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['PATH_TO_PRODUCT_EDIT'] = CrmCheckPath('PATH_TO_PRODUCT_EDIT', $arParams['PATH_TO_PRODUCT_EDIT'], $APPLICATION->GetCurPage() . '?product_id=#product_id#&edit'); $arParams['PATH_TO_PRODUCT_SHOW'] = CrmCheckPath('PATH_TO_PRODUCT_SHOW', $arParams['PATH_TO_PRODUCT_SHOW'], $APPLICATION->GetCurPage() . '?product_id=#product_id#&show'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); $arParams['ELEMENT_ID'] = isset($arParams['ELEMENT_ID']) ? (int) $arParams['ELEMENT_ID'] : 0; $bEdit = false; $bCopy = false; $bVarsFromForm = false; if (!empty($arParams['ELEMENT_ID'])) {
/** * @param array $arOrder * @param array $arFilter * @param array $arSelect * @return CDBResult * Obsolete. Always select all record from database. Please use GetListEx instead. */ public static function GetList($arOrder = array('DATE_CREATE' => 'DESC'), $arFilter = array(), $arSelect = array(), $nPageTop = false) { global $DB, $USER_FIELD_MANAGER; // fields $arFields = array('ID' => 'L.ID', 'COMMENTS' => 'L.COMMENTS', 'ADDITIONAL_INFO' => 'L.ADDITIONAL_INFO', 'LOCATION_ID' => 'L.LOCATION_ID', 'TITLE' => 'L.TITLE', 'LEAD_ID' => 'L.LEAD_ID', 'COMPANY_ID' => 'L.COMPANY_ID', 'COMPANY_TITLE' => 'C.TITLE', 'CONTACT_ID' => 'L.CONTACT_ID', 'CONTACT_FULL_NAME' => 'CT.FULL_NAME', 'STAGE_ID' => 'L.STAGE_ID', 'CLOSED' => 'L.CLOSED', 'TYPE_ID' => 'L.TYPE_ID', 'PRODUCT_ID' => 'L.PRODUCT_ID', 'PROBABILITY' => 'L.PROBABILITY', 'OPPORTUNITY' => 'L.OPPORTUNITY', 'TAX_VALUE' => 'L.TAX_VALUE', 'CURRENCY_ID' => 'L.CURRENCY_ID', 'OPPORTUNITY_ACCOUNT' => 'L.OPPORTUNITY_ACCOUNT', 'TAX_VALUE_ACCOUNT' => 'L.TAX_VALUE_ACCOUNT', 'ACCOUNT_CURRENCY_ID' => 'L.ACCOUNT_CURRENCY_ID', 'BEGINDATE' => $DB->DateToCharFunction('L.BEGINDATE'), 'CLOSEDATE' => $DB->DateToCharFunction('L.CLOSEDATE'), 'EVENT_ID' => 'L.EVENT_ID', 'EVENT_DATE' => $DB->DateToCharFunction('L.EVENT_DATE'), 'EVENT_DESCRIPTION' => 'L.EVENT_DESCRIPTION', 'ASSIGNED_BY' => 'L.ASSIGNED_BY_ID', 'ASSIGNED_BY_ID' => 'L.ASSIGNED_BY_ID', 'CREATED_BY' => 'L.CREATED_BY_ID', 'CREATED_BY_ID' => 'L.CREATED_BY_ID', 'MODIFY_BY' => 'L.MODIFY_BY_ID', 'MODIFY_BY_ID' => 'L.MODIFY_BY_ID', 'DATE_CREATE' => $DB->DateToCharFunction('L.DATE_CREATE'), 'DATE_MODIFY' => $DB->DateToCharFunction('L.DATE_MODIFY'), 'OPENED' => 'L.OPENED', 'EXCH_RATE' => 'L.EXCH_RATE', 'ORIGINATOR_ID' => 'L.ORIGINATOR_ID', 'ORIGIN_ID' => 'L.ORIGIN_ID', 'ASSIGNED_BY_LOGIN' => 'U.LOGIN', 'ASSIGNED_BY_NAME' => 'U.NAME', 'ASSIGNED_BY_LAST_NAME' => 'U.LAST_NAME', 'ASSIGNED_BY_SECOND_NAME' => 'U.SECOND_NAME', 'CREATED_BY_LOGIN' => 'U2.LOGIN', 'CREATED_BY_NAME' => 'U2.NAME', 'CREATED_BY_LAST_NAME' => 'U2.LAST_NAME', 'CREATED_BY_SECOND_NAME' => 'U2.SECOND_NAME', 'MODIFY_BY_LOGIN' => 'U3.LOGIN', 'MODIFY_BY_NAME' => 'U3.NAME', 'MODIFY_BY_LAST_NAME' => 'U3.LAST_NAME', 'MODIFY_BY_SECOND_NAME' => 'U3.SECOND_NAME'); $arSqlSelect = array(); $sSqlJoin = ''; if (count($arSelect) == 0) { $arSelect = array_merge(array_keys($arFields), array('UF_*')); } $obQueryWhere = new CSQLWhere(); $arFilterField = $arSelect; foreach ($arFilter as $sKey => $sValue) { $arField = $obQueryWhere->MakeOperation($sKey); $arFilterField[] = $arField['FIELD']; } if (in_array('ASSIGNED_BY_LOGIN', $arFilterField) || in_array('ASSIGNED_BY', $arFilterField)) { $arSelect[] = 'ASSIGNED_BY_LOGIN'; $arSelect[] = 'ASSIGNED_BY_NAME'; $arSelect[] = 'ASSIGNED_BY_LAST_NAME'; $arSelect[] = 'ASSIGNED_BY_SECOND_NAME'; $sSqlJoin .= ' LEFT JOIN b_user U ON L.ASSIGNED_BY_ID = U.ID '; } if (in_array('CREATED_BY_LOGIN', $arFilterField)) { $arSelect[] = 'CREATED_BY'; $arSelect[] = 'CREATED_BY_LOGIN'; $arSelect[] = 'CREATED_BY_NAME'; $arSelect[] = 'CREATED_BY_LAST_NAME'; $arSelect[] = 'CREATED_BY_SECOND_NAME'; $sSqlJoin .= ' LEFT JOIN b_user U2 ON L.CREATED_BY_ID = U2.ID '; } if (in_array('MODIFY_BY_LOGIN', $arFilterField)) { $arSelect[] = 'MODIFY_BY'; $arSelect[] = 'MODIFY_BY_LOGIN'; $arSelect[] = 'MODIFY_BY_NAME'; $arSelect[] = 'MODIFY_BY_LAST_NAME'; $arSelect[] = 'MODIFY_BY_SECOND_NAME'; $sSqlJoin .= ' LEFT JOIN b_user U3 ON L.MODIFY_BY_ID = U3.ID '; } if (in_array('COMPANY_ID', $arFilterField) || in_array('COMPANY_TITLE', $arFilterField)) { $arSelect[] = 'COMPANY_ID'; $arSelect[] = 'COMPANY_TITLE'; $sSqlJoin .= ' LEFT JOIN b_crm_company C ON L.COMPANY_ID = C.ID '; } if (in_array('CONTACT_ID', $arFilterField) || in_array('CONTACT_FULL_NAME', $arFilterField)) { $arSelect[] = 'CONTACT_ID'; $arSelect[] = 'CONTACT_FULL_NAME'; $sSqlJoin .= ' LEFT JOIN b_crm_contact CT ON L.CONTACT_ID = CT.ID '; } foreach ($arSelect as $field) { $field = strtoupper($field); if (array_key_exists($field, $arFields)) { $arSqlSelect[$field] = $arFields[$field] . ($field != '*' ? ' AS ' . $field : ''); } } if (!isset($arSqlSelect['ID'])) { $arSqlSelect['ID'] = $arFields['ID']; } $sSqlSelect = implode(",\n", $arSqlSelect); $obUserFieldsSql = new CUserTypeSQL(); $obUserFieldsSql->SetEntity(self::$sUFEntityID, 'L.ID'); $obUserFieldsSql->SetSelect($arSelect); $obUserFieldsSql->SetFilter($arFilter); $obUserFieldsSql->SetOrder($arOrder); $arSqlSearch = array(); // check permissions $sSqlPerm = ''; if (!CCrmPerms::IsAdmin() && (!array_key_exists('CHECK_PERMISSIONS', $arFilter) || $arFilter['CHECK_PERMISSIONS'] !== 'N')) { $arPermType = array(); if (!isset($arFilter['PERMISSION'])) { $arPermType[] = 'READ'; } else { $arPermType = is_array($arFilter['PERMISSION']) ? $arFilter['PERMISSION'] : array($arFilter['PERMISSION']); } $sSqlPerm = self::BuildPermSql('L', $arPermType); if ($sSqlPerm === false) { $CDBResult = new CDBResult(); $CDBResult->InitFromArray(array()); return $CDBResult; } if (strlen($sSqlPerm) > 0) { $sSqlPerm = ' AND ' . $sSqlPerm; } } // where $arWhereFields = array('ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'LEAD_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.LEAD_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'CONTACT_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.CONTACT_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'CONTACT_FULL_NAME' => array('TABLE_ALIAS' => 'CT', 'FIELD_NAME' => 'CT.FULL_NAME', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'COMPANY_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.COMPANY_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'COMPANY_TITLE' => array('TABLE_ALIAS' => 'C', 'FIELD_NAME' => 'C.TITLE', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'STATE_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.STATE_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'STAGE_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.STAGE_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'TYPE_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.TYPE_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'PRODUCT_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.PRODUCT_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'CURRENCY_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.CURRENCY_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'OPPORTUNITY' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.OPPORTUNITY', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'TAX_VALUE' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.TAX_VALUE', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'ACCOUNT_CURRENCY_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.ACCOUNT_CURRENCY_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'OPPORTUNITY_ACCOUNT' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.OPPORTUNITY_ACCOUNT', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'TAX_VALUE_ACCOUNT' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.TAX_VALUE_ACCOUNT', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'TITLE' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.TITLE', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'CLOSED' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.CLOSED', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'COMMENTS' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.COMMENTS', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'ADDITIONAL_INFO' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.ADDITIONAL_INFO', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'LOCATION_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.LOCATION_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'DATE_CREATE' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.DATE_CREATE', 'FIELD_TYPE' => 'datetime', 'JOIN' => false), 'BEGINDATE' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.BEGINDATE', 'FIELD_TYPE' => 'datetime', 'JOIN' => false), 'CLOSEDATE' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.CLOSEDATE', 'FIELD_TYPE' => 'datetime', 'JOIN' => false), 'EVENT_DATE' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.EVENT_DATE', 'FIELD_TYPE' => 'datetime', 'JOIN' => false), 'DATE_MODIFY' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.DATE_MODIFY', 'FIELD_TYPE' => 'datetime', 'JOIN' => false), 'PROBABILITY' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.PROBABILITY', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'EVENT_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.EVENT_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'CREATED_BY_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.CREATED_BY_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'ASSIGNED_BY_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.ASSIGNED_BY_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'OPENED' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.OPENED', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'MODIFY_BY_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.MODIFY_BY_ID', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'EXCH_RATE' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.EXCH_RATE', 'FIELD_TYPE' => 'int', 'JOIN' => false), 'ORIGINATOR_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.ORIGINATOR_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false), 'ORIGIN_ID' => array('TABLE_ALIAS' => 'L', 'FIELD_NAME' => 'L.ORIGIN_ID', 'FIELD_TYPE' => 'string', 'JOIN' => false)); $obQueryWhere->SetFields($arWhereFields); if (!is_array($arFilter)) { $arFilter = array(); } $sQueryWhereFields = $obQueryWhere->GetQuery($arFilter); $sSqlSearch = ''; foreach ($arSqlSearch as $r) { if (strlen($r) > 0) { $sSqlSearch .= "\n\t\t\t\tAND ({$r}) "; } } $CCrmUserType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], self::$sUFEntityID); $CCrmUserType->ListPrepareFilter($arFilter); $r = $obUserFieldsSql->GetFilter(); if (strlen($r) > 0) { $sSqlSearch .= "\n\t\t\t\tAND ({$r}) "; } if (!empty($sQueryWhereFields)) { $sSqlSearch .= "\n\t\t\t\tAND ({$sQueryWhereFields}) "; } $arFieldsOrder = array('ASSIGNED_BY' => 'L.ASSIGNED_BY_ID', 'CREATED_BY' => 'L.CREATED_BY_ID', 'MODIFY_BY' => 'L.MODIFY_BY_ID', 'DATE_CREATE' => 'L.DATE_CREATE', 'DATE_MODIFY' => 'L.DATE_MODIFY'); // order $arSqlOrder = array(); if (!is_array($arOrder)) { $arOrder = array('DATE_CREATE' => 'DESC'); } foreach ($arOrder as $by => $order) { $by = strtoupper($by); $order = strtolower($order); if ($order != 'asc') { $order = 'desc'; } if (isset($arFieldsOrder[$by])) { $arSqlOrder[$by] = " {$arFieldsOrder[$by]} {$order} "; } else { if (isset($arFields[$by]) && $by != 'ADDRESS') { $arSqlOrder[$by] = " L.{$by} {$order} "; } else { if ($s = $obUserFieldsSql->GetOrder($by)) { $arSqlOrder[$by] = " {$s} {$order} "; } else { $by = 'date_create'; $arSqlOrder[$by] = " L.DATE_CREATE {$order} "; } } } } if (count($arSqlOrder) > 0) { $sSqlOrder = "\n\t\t\t\tORDER BY " . implode(', ', $arSqlOrder); } else { $sSqlOrder = ''; } $sSql = "\n\t\t\tSELECT\n\t\t\t\t{$sSqlSelect}\n\t\t\t\t{$obUserFieldsSql->GetSelect()}\n\t\t\tFROM\n\t\t\t\tb_crm_deal L {$sSqlJoin}\n\t\t\t\t{$obUserFieldsSql->GetJoin('L.ID')}\n\t\t\tWHERE\n\t\t\t\t1=1 {$sSqlSearch}\n\t\t\t\t{$sSqlPerm}\n\t\t\t{$sSqlOrder}"; if ($nPageTop !== false) { $nPageTop = (int) $nPageTop; $sSql = $DB->TopSql($sSql, $nPageTop); } $obRes = $DB->Query($sSql, false, 'FILE: ' . __FILE__ . '<br /> LINE: ' . __LINE__); $obRes->SetUserFields($USER_FIELD_MANAGER->GetUserFields(self::$sUFEntityID)); return $obRes; }
public function Prepare($arOrder = array(), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array(), $arOptions = array()) { global $DB; if (!is_array($arOrder)) { $arOrder = array(); } if (!is_array($arFilter)) { $arFilter = array(); } // ID must present in select (If select is empty it will be filled by CSqlUtil::PrepareSql) if (!is_array($arSelectFields)) { $arSelectFields = array(); } if (count($arSelectFields) > 0 && !in_array('*', $arSelectFields, true) && !in_array('ID', $arSelectFields, true)) { $arSelectFields[] = 'ID'; } if (!is_array($arOptions)) { $arOptions = array(); } $arOptions['DB_TYPE'] = $this->dbType; $isExternalContext = isset($arOptions['IS_EXTERNAL_CONTEXT']) && ($arOptions['IS_EXTERNAL_CONTEXT'] === true || $arOptions['IS_EXTERNAL_CONTEXT'] === 'Y'); if ($isExternalContext) { // Sanitizing of filter data if (isset($arFilter['__JOINS'])) { unset($arFilter['__JOINS']); } if (isset($arFilter['CHECK_PERMISSIONS'])) { unset($arFilter['CHECK_PERMISSIONS']); } } // Processing of special fields if ($this->fmEntityID !== '' && isset($arFilter['FM'])) { CCrmFieldMulti::PrepareExternalFilter($arFilter, array('ENTITY_ID' => $this->fmEntityID, 'MASTER_ALIAS' => $this->tableAlias, 'MASTER_IDENTITY' => 'ID')); } // Processing user fields $ufSelectSql = null; $ufFilterSql = null; if ($this->ufEntityID !== '') { $ufSelectSql = new CUserTypeSQL(); $ufSelectSql->SetEntity($this->ufEntityID, $this->tableAlias . '.ID'); $ufSelectSql->SetSelect($arSelectFields); $ufSelectSql->SetOrder($arOrder); $ufFilterSql = new CUserTypeSQL(); $ufFilterSql->SetEntity($this->ufEntityID, $this->tableAlias . '.ID'); $ufFilterSql->SetFilter($arFilter); $userType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], $this->ufEntityID); $userType->ListPrepareFilter($arFilter); } $this->sqlData = CSqlUtil::PrepareSql($this->fields, $arOrder, $arFilter, $arGroupBy, $arSelectFields, $arOptions); $this->sqlData['SELECT'] = str_replace('%%_DISTINCT_%% ', '', $this->sqlData['SELECT']); // 'Joins' implement custom filter logic $joins = array(); if (isset($arFilter['__JOINS'])) { if (is_array($arFilter['__JOINS'])) { $joins = $arFilter['__JOINS']; } unset($arFilter['__JOINS']); } if (count($joins) > 0) { foreach ($joins as &$join) { // INNER JOINs will be added tostart $this->Add2SqlData($join['SQL'], 'FROM', !isset($join['TYPE']) || $join['TYPE'] === 'INNER', isset($join['REPLACE']) ? $join['REPLACE'] : ''); } unset($join); } // Apply user permission logic if (count($this->permissionCallback) > 0) { if ((!array_key_exists('CHECK_PERMISSIONS', $arFilter) || $arFilter['CHECK_PERMISSIONS'] !== 'N') && !CCrmPerms::IsAdmin()) { $arPermType = !isset($arFilter['PERMISSION']) ? 'READ' : (is_array($arFilter['PERMISSION']) ? $arFilter['PERMISSION'] : array($arFilter['PERMISSION'])); $permissionSql = call_user_func_array($this->permissionCallback, array($this->tableAlias, $arPermType, $arOptions)); if (is_bool($permissionSql) && !$permissionSql) { $CDBResult = new CDBResult(); $CDBResult->InitFromArray(array()); return $CDBResult; } if ($permissionSql !== '') { $sqlType = isset($arOptions['PERMISSION_SQL_TYPE']) && $arOptions['PERMISSION_SQL_TYPE'] === 'FROM' ? 'FROM' : 'WHERE'; $this->Add2SqlData($permissionSql, $sqlType, $sqlType === 'FROM'); } } } // Apply custom SQL logic if (count($this->afterPrepareSqlCallback) > 0) { $arUserSql = call_user_func_array($this->afterPrepareSqlCallback, array($this, $arOrder, $arFilter, $arGroupBy, $arSelectFields)); if (is_array($arUserSql)) { if (isset($arUserSql['FROM'])) { $this->Add2SqlData($arUserSql['FROM'], 'FROM'); } if (isset($arUserSql['WHERE'])) { $this->Add2SqlData($arUserSql['WHERE'], 'WHERE'); } } } if ($ufSelectSql) { // Adding user fields to SELECT $this->Add2SqlData($ufSelectSql->GetSelect(), 'SELECT'); // Adding user fields to ORDER BY if (is_array($arOrder)) { foreach ($arOrder as $orderKey => $order) { $orderSql = $ufSelectSql->GetOrder($orderKey); if (!is_string($orderSql) || $orderSql === '') { continue; } $order = strtoupper($order); if ($order !== 'ASC' && $order !== 'DESC') { $order = 'ASC'; } $this->Add2SqlData("{$orderSql} {$order}", 'ORDERBY'); } } // Adding user fields to joins $this->Add2SqlData($ufSelectSql->GetJoin($this->tableAlias . '.ID'), 'FROM'); } if ($ufFilterSql) { // Adding user fields to WHERE $ufWhere = $ufFilterSql->GetFilter(); if ($ufWhere !== '') { $ufSql = $this->tableAlias . '.ID IN (SELECT ' . $this->tableAlias . '.ID FROM ' . $this->tableName . ' ' . $this->tableAlias . ' ' . $ufFilterSql->GetJoin($this->tableAlias . '.ID') . ' WHERE ' . $ufWhere . ')'; // Adding user fields to joins $this->Add2SqlData($ufSql, 'WHERE'); } } //Get count only if (is_array($arGroupBy) && count($arGroupBy) == 0) { return $this->GetRowCount(RestrictionManager::getSqlRestriction()->getRowCountThreshold()); } $sql = 'SELECT ' . $this->sqlData['SELECT'] . ' FROM ' . $this->tableName . ' ' . $this->tableAlias; if (isset($this->sqlData['FROM'][0])) { $sql .= ' ' . $this->sqlData['FROM']; } if (isset($this->sqlData['WHERE'][0])) { $sql .= ' WHERE ' . $this->sqlData['WHERE']; } if (isset($this->sqlData['GROUPBY'][0])) { $sql .= ' GROUP BY ' . $this->sqlData['GROUPBY']; } if (isset($this->sqlData['ORDERBY'][0])) { $sql .= ' ORDER BY ' . $this->sqlData['ORDERBY']; } $enableNavigation = is_array($arNavStartParams); $top = $enableNavigation && isset($arNavStartParams['nTopCount']) ? intval($arNavStartParams['nTopCount']) : 0; if ($enableNavigation && $top <= 0) { $dbRes = new CDBResult(); if ($this->ufEntityID !== '') { $dbRes->SetUserFields($GLOBALS['USER_FIELD_MANAGER']->GetUserFields($this->ufEntityID)); } elseif (!empty($this->userFields)) { $dbRes->SetUserFields($this->userFields); } //Trace('CCrmEntityListBuilder::Prepare, SQL', $sql, 1); $cnt = $this->GetRowCount(RestrictionManager::getSqlRestriction()->getRowCountThreshold()); $dbRes->NavQuery($sql, $cnt, $arNavStartParams); } else { $limit = $top; $offset = 0; if (isset($arOptions['QUERY_OPTIONS']) && is_array($arOptions['QUERY_OPTIONS'])) { $queryOptions = $arOptions['QUERY_OPTIONS']; $limit = isset($queryOptions['LIMIT']) ? (int) $queryOptions['LIMIT'] : 0; $offset = isset($queryOptions['OFFSET']) ? (int) $queryOptions['OFFSET'] : 0; } $threshold = RestrictionManager::getSqlRestriction()->getRowCountThreshold(); if ($threshold > 0 && $threshold < $limit + $offset) { $delta = $threshold - $offset; if ($delta <= 0) { $obRes = new CDBResult(); $obRes->InitFromArray(array()); return $obRes; } $limit = $delta; } if ($limit > 0) { $sql = Main\Application::getConnection()->getSqlHelper()->getTopSql($sql, $limit, $offset); } //Trace('CCrmEntityListBuilder::Prepare, SQL', $sql, 1); $dbRes = $DB->Query($sql, false, 'File: ' . __FILE__ . '<br/>Line: ' . __LINE__); if ($this->ufEntityID !== '') { $dbRes->SetUserFields($GLOBALS['USER_FIELD_MANAGER']->GetUserFields($this->ufEntityID)); } elseif (!empty($this->userFields)) { $dbRes->SetUserFields($this->userFields); } } return $dbRes; }
die; } if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } CModule::IncludeModule('fileman'); if (IsModuleInstalled('bizproc')) { if (!CModule::IncludeModule('bizproc')) { ShowError(GetMessage('BIZPROC_MODULE_NOT_INSTALLED')); return; } } global $USER_FIELD_MANAGER, $DB, $USER; $CCrmContact = new CCrmContact(); $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmContact::$sUFEntityID); $userPermissions = CCrmPerms::GetCurrentUserPermissions(); $arParams['PATH_TO_CONTACT_LIST'] = CrmCheckPath('PATH_TO_CONTACT_LIST', $arParams['PATH_TO_CONTACT_LIST'], $APPLICATION->GetCurPage()); $arParams['PATH_TO_CONTACT_SHOW'] = CrmCheckPath('PATH_TO_CONTACT_SHOW', $arParams['PATH_TO_CONTACT_SHOW'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&show'); $arParams['PATH_TO_CONTACT_EDIT'] = CrmCheckPath('PATH_TO_CONTACT_EDIT', $arParams['PATH_TO_CONTACT_EDIT'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&edit'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); $arParams['ELEMENT_ID'] = isset($arParams['ELEMENT_ID']) ? (int) $arParams['ELEMENT_ID'] : 0; $isEditMode = false; $isCopyMode = false; $varsFromForm = false; if ($arParams['ELEMENT_ID'] > 0) { $isEditMode = true; } if (!empty($_REQUEST['copy'])) { $isCopyMode = true;
/** * @return array */ public static function getBindingInfos() { global $USER_FIELD_MANAGER; $fieldInfos = array(); $userType = new \CCrmUserType($USER_FIELD_MANAGER, \CCrmDeal::GetUserFieldEntityID()); $userType->PrepareFieldsInfo($fieldInfos); $result = array(); $bindings = self::getSlotBindingMap()->getAll(); foreach ($bindings as $binding) { /** @var StatisticFieldBinding $binding */ $slotName = $binding->getSlotName(); if ($slotName === 'SUM_TOTAL') { continue; } $fieldName = $binding->getFieldName(); $fieldTitle = isset($fieldInfos[$fieldName]) ? $fieldInfos[$fieldName]['LABELS']['FORM'] : $fieldName; $result[] = array('SLOT_NAME' => $slotName, 'FEILD_NAME' => $fieldName, 'TITLE' => $fieldTitle); } return $result; }
public static function GetFields() { $fields = array(); $fields[] = array('ID' => 'TITLE', 'NAME' => GetMessage('CRM_FIELD_TITLE'), 'TYPE' => 'string', 'REQUIRED' => true); $fields[] = array('ID' => 'NAME', 'NAME' => GetMessage('CRM_FIELD_REST_NAME'), 'TYPE' => 'string', 'REQUIRED' => false); $fields[] = array('ID' => 'LAST_NAME', 'NAME' => GetMessage('CRM_FIELD_LAST_NAME'), 'TYPE' => 'string', 'REQUIRED' => false); $fields[] = array('ID' => 'SECOND_NAME', 'NAME' => GetMessage('CRM_FIELD_SECOND_NAME'), 'TYPE' => 'string', 'REQUIRED' => false); $ar = CCrmFieldMulti::GetEntityComplexList(); foreach ($ar as $fieldId => $fieldName) { $fields[] = array('ID' => $fieldId, 'NAME' => $fieldName, 'TYPE' => 'string', 'REQUIRED' => false); } $fields[] = array('ID' => 'COMPANY_TITLE', 'NAME' => GetMessage('CRM_FIELD_COMPANY_TITLE'), 'TYPE' => 'string', 'REQUIRED' => false); $fields[] = array('ID' => 'POST', 'NAME' => GetMessage('CRM_FIELD_POST'), 'TYPE' => 'string', 'REQUIRED' => false); $fields[] = array('ID' => 'ADDRESS', 'NAME' => GetMessage('CRM_FIELD_ADDRESS'), 'TYPE' => 'string', 'REQUIRED' => false); $fields[] = array('ID' => 'COMMENTS', 'NAME' => GetMessage('CRM_FIELD_COMMENTS'), 'TYPE' => 'string', 'REQUIRED' => false); $fields[] = array('ID' => 'STATUS_ID', 'NAME' => GetMessage('CRM_FIELD_STATUS_ID'), 'TYPE' => 'enum', 'VALUES' => self::_GetStatusList(), 'REQUIRED' => false); $fields[] = array('ID' => 'CURRENCY_ID', 'NAME' => GetMessage('CRM_FIELD_CURRENCY_ID'), 'TYPE' => 'enum', 'VALUES' => self::_GetCurrencyList(), 'REQUIRED' => false); $fields[] = array('ID' => 'SOURCE_ID', 'NAME' => GetMessage('CRM_FIELD_SOURCE_ID'), 'TYPE' => 'enum', 'VALUES' => self::_GetSourceList(), 'REQUIRED' => false); $fields[] = array('ID' => 'OPPORTUNITY', 'NAME' => GetMessage('CRM_FIELD_OPPORTUNITY'), 'TYPE' => 'double', 'REQUIRED' => false); $fields[] = array('ID' => 'STATUS_DESCRIPTION', 'NAME' => GetMessage('CRM_FIELD_STATUS_DESCRIPTION'), 'TYPE' => 'string', 'REQUIRED' => false); $fields[] = array('ID' => 'SOURCE_DESCRIPTION', 'NAME' => GetMessage('CRM_FIELD_SOURCE_DESCRIPTION'), 'TYPE' => 'string', 'REQUIRED' => false); $CCrmUserType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], CCrmLead::$sUFEntityID); $CCrmUserType->AddRestServiceFields($fields); return self::_out(array('error' => 201, 'FIELDS' => $fields)); }
} foreach ($arResult['HEADERS'] as $arField) { echo '"', str_replace('"', '""', $arField['name']), '";'; } echo "\n"; foreach ($arResult['HEADERS'] as $arField) { echo isset($arDemo[$arField['id']]) ? '"' . str_replace('"', '""', $arDemo[$arField['id']]) . '";' : '"";'; } echo "\n"; die; } else { if (isset($_REQUEST['import']) && isset($_SESSION['CRM_IMPORT_FILE'])) { $APPLICATION->RestartBuffer(); global $USER_FIELD_MANAGER; $CCrmFieldMulti = new CCrmFieldMulti(); $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmLead::$sUFEntityID); require_once $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/modules/main/classes/general/csv_data.php'; $arStatus['STATUS_LIST'] = CCrmStatus::GetStatusListEx('STATUS'); $arStatus['SOURCE_LIST'] = CCrmStatus::GetStatusListEx('SOURCE'); $arStatus['OPENED_LIST'] = array('Y' => GetMessage('MAIN_YES'), 'N' => GetMessage('MAIN_NO')); $csvFile = new CCSVData(); $csvFile->LoadFile($_SESSION['CRM_IMPORT_FILE']); $csvFile->SetFieldsType('R'); $csvFile->SetPos($_SESSION['CRM_IMPORT_FILE_POS']); $csvFile->SetFirstHeader($_SESSION['CRM_IMPORT_FILE_FIRST_HEADER']); $csvFile->SetDelimiter($_SESSION['CRM_IMPORT_FILE_SEPORATOR']); $arResult = array(); $arResult['import'] = 0; $arResult['duplicate'] = 0; $arResult['duplicate_url'] = ''; $arResult['error'] = 0;
} if (!empty($arParams['INTERNAL_SORT']) && is_array($arParams['INTERNAL_SORT'])) { $arSort = $arParams['INTERNAL_SORT']; } $sExportType = ''; if (!empty($_REQUEST['type'])) { $sExportType = strtolower(trim($_REQUEST['type'])); if (!in_array($sExportType, array('csv', 'excel'))) { $sExportType = ''; } } if (!empty($sExportType) && $CCrmPerms->HavePerm('INVOICE', BX_CRM_PERM_NONE, 'EXPORT')) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmInvoice::$sUFEntityID); $arResult['GRID_ID'] = 'CRM_INVOICE_LIST_V12' . ($bInternal && !empty($arParams['GRID_ID_SUFFIX']) ? '_' . $arParams['GRID_ID_SUFFIX'] : ''); $arResult['STATUS_LIST'] = CCrmStatus::GetStatusListEx('INVOICE_STATUS'); $arResult['CURRENCY_LIST'] = CCrmCurrencyHelper::PrepareListItems(); $arResult['PERSON_TYPES'] = CCrmPaySystem::getPersonTypesList(); $arPaySystems = array(); foreach (array_keys($arResult['PERSON_TYPES']) as $personTypeId) { $arPaySystems[$personTypeId] = CCrmPaySystem::GetPaySystemsListItems($personTypeId); } $arResult['PAY_SYSTEMS_LIST'] = $arPaySystems; unset($personTypeId, $arPaySystems); $arResult['EVENT_LIST'] = CCrmStatus::GetStatusListEx('EVENT_TYPE'); $arResult['CLOSED_LIST'] = array('Y' => GetMessage('MAIN_YES'), 'N' => GetMessage('MAIN_NO')); $arResult['FILTER'] = array(); $arResult['FILTER2LOGIC'] = array(); $arResult['FILTER_PRESETS'] = array();
$arParams['PATH_TO_QUOTE_SHOW'] = CrmCheckPath('PATH_TO_QUOTE_SHOW', $arParams['PATH_TO_QUOTE_SHOW'], $APPLICATION->GetCurPage() . '?quote_id=#quote_id#&show'); $arParams['PATH_TO_QUOTE_EDIT'] = CrmCheckPath('PATH_TO_QUOTE_EDIT', $arParams['PATH_TO_QUOTE_EDIT'], $APPLICATION->GetCurPage() . '?quote_id=#quote_id#&edit'); $arParams['PATH_TO_USER_PROFILE'] = CrmCheckPath('PATH_TO_USER_PROFILE', $arParams['PATH_TO_USER_PROFILE'], '/company/personal/user/#user_id#/'); $arParams['PATH_TO_CONTACT_SHOW'] = CrmCheckPath('PATH_TO_CONTACT_SHOW', $arParams['PATH_TO_CONTACT_SHOW'], $APPLICATION->GetCurPage() . '?contact_id=#contact_id#&show'); $arParams['PATH_TO_COMPANY_SHOW'] = CrmCheckPath('PATH_TO_COMPANY_SHOW', $arParams['PATH_TO_COMPANY_SHOW'], $APPLICATION->GetCurPage() . '?company_id=#company_id#&show'); $arParams['PATH_TO_PRODUCT_EDIT'] = CrmCheckPath('PATH_TO_PRODUCT_EDIT', $arParams['PATH_TO_PRODUCT_EDIT'], $APPLICATION->GetCurPage() . '?product_id=#product_id#&edit'); $arParams['PATH_TO_PRODUCT_SHOW'] = CrmCheckPath('PATH_TO_PRODUCT_SHOW', $arParams['PATH_TO_PRODUCT_SHOW'], $APPLICATION->GetCurPage() . '?product_id=#product_id#&show'); $arParams['NAME_TEMPLATE'] = empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]); $arResult['PREFIX'] = isset($arParams['~PREFIX']) ? $arParams['~PREFIX'] : 'crm_quote_edit'; $bInternal = false; if (isset($arParams['INTERNAL_FILTER']) && !empty($arParams['INTERNAL_FILTER'])) { $bInternal = true; } $arResult['INTERNAL'] = $bInternal; global $USER_FIELD_MANAGER, $DB, $USER; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmQuote::$sUFEntityID); $bEdit = false; $bCopy = false; $bVarsFromForm = false; $arParams['ELEMENT_ID'] = (int) $arParams['ELEMENT_ID']; if (!empty($arParams['ELEMENT_ID'])) { $bEdit = true; } if (!empty($_REQUEST['copy'])) { $bCopy = true; $bEdit = false; } /*$bConvert = isset($arParams['CONVERT']) && $arParams['CONVERT'];*/ $arPersonTypes = $arResult['PERSON_TYPE_IDS'] = CCrmPaySystem::getPersonTypeIDs(); $bTaxMode = CCrmTax::isTaxMode(); $arResult['TAX_MODE'] = $bTaxMode ? 'Y' : 'N';
protected static function prepareUserFieldsInfo(&$fieldsInfo, $entityTypeID) { $userType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], $entityTypeID); $userType->PrepareFieldsInfo($fieldsInfo); }
if (!empty($arParams['INTERNAL_SORT']) && is_array($arParams['INTERNAL_SORT'])) { $arSort = $arParams['INTERNAL_SORT']; } $sExportType = ''; if (!empty($_REQUEST['type'])) { $sExportType = strtolower(trim($_REQUEST['type'])); if (!in_array($sExportType, array('csv', 'excel'))) { $sExportType = ''; } } if (!empty($sExportType) && $CCrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'EXPORT')) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $isInExportMode = $sExportType !== ''; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmContact::$sUFEntityID); $CCrmFieldMulti = new CCrmFieldMulti(); $arResult['GRID_ID'] = 'CRM_CONTACT_LIST_V12' . ($bInternal && !empty($arParams['GRID_ID_SUFFIX']) ? '_' . $arParams['GRID_ID_SUFFIX'] : ''); $arResult['TYPE_LIST'] = CCrmStatus::GetStatusListEx('CONTACT_TYPE'); $arResult['SOURCE_LIST'] = CCrmStatus::GetStatusListEx('SOURCE'); $arResult['EXPORT_LIST'] = array('Y' => GetMessage('MAIN_YES'), 'N' => GetMessage('MAIN_NO')); $arResult['FILTER'] = array(); $arResult['FILTER2LOGIC'] = array(); $arResult['FILTER_PRESETS'] = array(); $arResult['AJAX_MODE'] = isset($arParams['AJAX_MODE']) ? $arParams['AJAX_MODE'] : ($arResult['INTERNAL'] ? 'N' : 'Y'); $arResult['AJAX_ID'] = isset($arParams['AJAX_ID']) ? $arParams['AJAX_ID'] : ''; $arResult['AJAX_OPTION_JUMP'] = isset($arParams['AJAX_OPTION_JUMP']) ? $arParams['AJAX_OPTION_JUMP'] : 'N'; $arResult['AJAX_OPTION_HISTORY'] = isset($arParams['AJAX_OPTION_HISTORY']) ? $arParams['AJAX_OPTION_HISTORY'] : 'N'; $addressLabels = EntityAddress::getShortLabels(); if (!$bInternal) { $arResult['FILTER2LOGIC'] = array('TITLE', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'POST', 'COMMENTS');
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) { die; } if (!CModule::IncludeModule('crm')) { ShowError(GetMessage('CRM_MODULE_NOT_INSTALLED')); return; } $CrmPerms = new CCrmPerms($USER->GetID()); if ($CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'ADD') || $CrmPerms->HavePerm('CONTACT', BX_CRM_PERM_NONE, 'ADD')) { ShowError(GetMessage('CRM_PERMISSION_DENIED')); return; } $arParams['PATH_TO_LEAD_LIST'] = CrmCheckPath('PATH_TO_LEAD_LIST', $arParams['PATH_TO_LEAD_LIST'], $APPLICATION->GetCurPage()); $arParams['PATH_TO_LEAD_CONVERT'] = CrmCheckPath('PATH_TO_LEAD_CONVERT', $arParams['PATH_TO_LEAD_CONVERT'], $APPLICATION->GetCurPage() . '?lead_id=#lead_id#&convert'); global $USER_FIELD_MANAGER; $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmLead::$sUFEntityID); $arParams['ELEMENT_ID'] = (int) $arParams['ELEMENT_ID']; $obFields = CCrmLead::GetListEx(array(), array('=ID' => $arParams['ELEMENT_ID'], 'CHECK_PERMISSIONS' => 'N'), false, false, array('*', 'UF_*')); $arLead = $arFields = is_object($obFields) ? $obFields->GetNext() : false; if ($arLead === false) { LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_LIST'], array())); } foreach ($arFields as $key => $value) { if (isset($arFields['~' . $key])) { $arFields[$key] = $arFields['~' . $key]; } } $arFieldsReplace = array(); $CCrmUserType->ListAddEnumFieldsValue($arFields, $arFieldsReplace, $arFields['ID']); $CCrmUserType->PrepareUpdate($arFields); $arResult['ELEMENT']['ID'] = $arFields['ID'];