Ejemplo n.º 1
0
 protected function prepareFileUserFieldForSave($fieldName, array $fildInfo, array &$fields)
 {
     if (isset($fildInfo['MULTIPLE']) && $fildInfo['MULTIPLE'] === 'Y') {
         $results = array();
         if (is_array($fields[$fieldName])) {
             foreach ($fields[$fieldName] as $fileInfo) {
                 if ($fileInfo['tmp_name'] === '' && $fileInfo['old_id'] !== '' && \CCrmFileProxy::TryResolveFile($fileInfo['old_id'], $file, array('ENABLE_ID' => true))) {
                     $results[] = $file;
                 }
             }
         }
         $fields[$fieldName] = $results;
     } else {
         $fileInfo = $fields[$fieldName];
         if ($fileInfo['tmp_name'] === '' && $fileInfo['old_id'] !== '' && \CCrmFileProxy::TryResolveFile($fields[$fieldName]['old_id'], $file, array('ENABLE_ID' => true))) {
             $fields[$fieldName] = $file;
         }
     }
 }
Ejemplo n.º 2
0
 public static function UpdateDocument($documentId, $arFields)
 {
     global $DB;
     $arDocumentID = self::GetDocumentInfo($documentId);
     if (empty($arDocumentID)) {
         throw new CBPArgumentNullException('documentId');
     }
     $dbDocumentList = CCrmCompany::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_") {
             self::InternalizeEnumerationField('CRM_COMPANY', $arFields, $key);
         } 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['CONTACT_ID']) && !is_array($arFields['CONTACT_ID'])) {
         $arFields['CONTACT_ID'] = array($arFields['CONTACT_ID']);
     }
     if (isset($arFields['COMMENTS']) && $arFields['COMMENTS'] !== '') {
         $arFields['COMMENTS'] = preg_replace("/[\r\n]+/" . BX_UTF_PCRE_MODIFIER, "<br/>", $arFields['COMMENTS']);
     }
     $DB->StartTransaction();
     $CCrmEntity = new CCrmCompany(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('COMPANY');
         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();
     }
 }
Ejemplo n.º 3
0
 protected static function mapUserField($srcEntityTypeID, $srcFieldID, array &$srcFields, $dstEntityTypeID, $dstFieldID, array &$dstFields, array $options = null)
 {
     if (!isset($srcFields[$srcFieldID])) {
         return;
     }
     $srcField = self::getUserField($srcEntityTypeID, $srcFieldID);
     $dstField = self::getUserField($dstEntityTypeID, $dstFieldID);
     if ($srcField && $srcField['USER_TYPE_ID'] === 'enumeration' && $dstField && $dstField['USER_TYPE_ID'] === 'enumeration') {
         $srcValues = self::getEnumerationMap($srcField, false);
         $dstValues = self::getEnumerationMap($dstField, true);
         if (isset($srcField['MULTIPLE']) && $srcField['MULTIPLE'] === 'Y') {
             $enumIDs = $srcFields[$srcFieldID];
             if (!is_array($enumIDs)) {
                 $enumIDs = array($enumIDs);
             }
             if (isset($dstField['MULTIPLE']) && $dstField['MULTIPLE'] === 'Y') {
                 foreach ($enumIDs as $enumID) {
                     if (isset($srcValues[$enumID])) {
                         $xmlID = $srcValues[$enumID];
                         if (isset($dstValues[$xmlID])) {
                             if (!isset($dstFields[$dstFieldID])) {
                                 $dstFields[$dstFieldID] = array();
                             }
                             $dstFields[$dstFieldID][] = $dstValues[$xmlID];
                         }
                     }
                 }
             } elseif (!empty($enumIDs)) {
                 $enumID = $enumIDs[0];
                 if (isset($srcValues[$enumID])) {
                     $xmlID = $srcValues[$enumID];
                     if (isset($dstValues[$xmlID])) {
                         $dstFields[$dstFieldID] = $dstValues[$xmlID];
                     }
                 }
             }
         } else {
             $enumID = $srcFields[$srcFieldID];
             if (isset($srcValues[$enumID])) {
                 $xmlID = $srcValues[$enumID];
                 if (isset($dstValues[$xmlID])) {
                     $dstFields[$dstFieldID] = $dstValues[$xmlID];
                 }
             }
         }
         return;
     }
     $enableFiles = true;
     if (is_array($options) && isset($options['ENABLE_FILES'])) {
         $enableFiles = $options['ENABLE_FILES'];
     }
     if ($enableFiles && $srcField && $srcField['USER_TYPE_ID'] === 'file' && $dstField && $dstField['USER_TYPE_ID'] === 'file') {
         if (isset($srcField['MULTIPLE']) && $srcField['MULTIPLE'] === 'Y') {
             $fileIDs = $srcFields[$srcFieldID];
             if (!is_array($fileIDs)) {
                 $fileIDs = array($fileIDs);
             }
             if (isset($dstField['MULTIPLE']) && $dstField['MULTIPLE'] === 'Y') {
                 foreach ($fileIDs as $fileID) {
                     $file = null;
                     if (\CCrmFileProxy::TryResolveFile($fileID, $file, array('ENABLE_ID' => true))) {
                         if (!isset($dstFields[$dstFieldID])) {
                             $dstFields[$dstFieldID] = array();
                         }
                         $dstFields[$dstFieldID][] = $file;
                     }
                 }
             } elseif (!empty($fileIDs)) {
                 $fileID = $fileIDs[0];
                 $file = null;
                 if (\CCrmFileProxy::TryResolveFile($fileID, $file, array('ENABLE_ID' => true))) {
                     $dstFields[$dstFieldID] = $file;
                 }
             }
         } else {
             $file = null;
             if (\CCrmFileProxy::TryResolveFile($srcFields[$srcFieldID], $file, array('ENABLE_ID' => true))) {
                 $dstFields[$dstFieldID] = $file;
             }
         }
         return;
     }
     $dstFields[$dstFieldID] = $srcFields[$srcFieldID];
 }
Ejemplo n.º 4
0
<?php

define('NO_KEEP_STATISTIC', 'Y');
define('NO_AGENT_STATISTIC', 'Y');
define('NO_AGENT_CHECK', true);
define('DisableEventsCheck', true);
$authToken = isset($_REQUEST['auth']) ? $_REQUEST['auth'] : '';
if ($authToken !== '') {
    define('NOT_CHECK_PERMISSIONS', true);
}
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$errors = array();
if (CModule::IncludeModule('crm')) {
    $options = array();
    if ($authToken !== '') {
        $options['oauth_token'] = $authToken;
    }
    //By default treat field as dynamic (for backward compatibility)
    $options['is_dynamic'] = !isset($_REQUEST['dynamic']) || strtoupper($_REQUEST['dynamic']) !== 'N';
    CCrmFileProxy::WriteFileToResponse(CCrmOwnerType::Contact, isset($_REQUEST['ownerId']) ? intval($_REQUEST['ownerId']) : 0, isset($_REQUEST['fieldName']) ? $_REQUEST['fieldName'] : '', isset($_REQUEST['fileId']) ? intval($_REQUEST['fileId']) : 0, $errors, $options);
}
require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_after.php";
if (!empty($errors)) {
    foreach ($errors as $error) {
        echo $error;
    }
}
require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog.php";
Ejemplo n.º 5
0
 public function Internalize($name, $data, $delimiter = ',')
 {
     $delimiter = strval($delimiter);
     if ($delimiter === '') {
         $delimiter = ',';
     }
     $arUserFields = $this->GetUserFields($this->sEntityID, 0, LANGUAGE_ID);
     $arUserField = isset($arUserFields[$name]) ? $arUserFields[$name] : null;
     if (!$arUserField) {
         return $data;
         // return original data
     }
     $data = strval($data);
     if ($arUserField['MULTIPLE'] === 'Y') {
         $data = explode($delimiter, $data);
         foreach ($data as &$v) {
             $v = trim($v);
         }
         unset($v);
     }
     $typeID = $arUserField['USER_TYPE']['USER_TYPE_ID'];
     if ($typeID === 'file') {
         if (is_array($data)) {
             $files = array();
             foreach ($data as &$filePath) {
                 $file = null;
                 if (CCrmFileProxy::TryResolveFile($filePath, $file)) {
                     $files[] = $file;
                 }
             }
             unset($filePath);
             $data = $files;
         } elseif ($data !== '') {
             $file = null;
             if (CCrmFileProxy::TryResolveFile($data, $file)) {
                 $data = $file;
             }
         }
     } elseif ($typeID === 'enumeration') {
         // Processing for type 'enumeration'
         $enums = array();
         $rsEnum = CUserFieldEnum::GetList(array(), array('USER_FIELD_ID' => $arUserField['ID']));
         while ($arEnum = $rsEnum->Fetch()) {
             $enums[$arEnum['ID']] = $arEnum;
         }
         self::InternalizeEnumValue($data, $enums);
     } elseif ($typeID === 'employee') {
         // Processing for type 'employee' (we have to implement custom processing since CUserTypeEmployee::GetList doesn't provide VALUE property)
         $enums = array();
         $rsEnum = CUser::GetList($by = 'last_name', $order = 'asc');
         while ($arEnum = $rsEnum->Fetch()) {
             $arEnum['VALUE'] = CUser::FormatName(CSite::GetNameFormat(false), $arEnum, false, true);
             $enums[$arEnum['ID']] = $arEnum;
         }
         self::InternalizeEnumValue($data, $enums);
     } elseif ($typeID === 'crm') {
         // Processing for type 'crm' (is link to LEAD, CONTACT, COMPANY or DEAL)
         if (isset($arUserField['SETTINGS'])) {
             self::InternalizeCrmEntityValue($data, $arUserField['SETTINGS']);
         }
     } elseif ($typeID === 'boolean') {
         $yes = strtoupper(GetMessage('MAIN_YES'));
         //$no = strtoupper(GetMessage('MAIN_NO'));
         if (is_array($data)) {
             foreach ($data as &$v) {
                 $s = strtoupper($v);
                 $v = $s === $yes || $s === 'Y' || $s === 'YES' || is_numeric($s) && intval($s) > 0 ? 1 : 0;
             }
             unset($v);
         } elseif (is_string($data) && $data !== '') {
             $s = strtoupper($data);
             $data = $s === $yes || $s === 'Y' || $s === 'YES' || is_numeric($s) && intval($s) > 0 ? 1 : 0;
         } elseif (isset($arUserField['SETTINGS']['DEFAULT_VALUE'])) {
             $data = $arUserField['SETTINGS']['DEFAULT_VALUE'];
         } else {
             $data = 0;
         }
     } elseif ($typeID === 'datetime') {
         if (is_array($data)) {
             foreach ($data as &$v) {
                 if (!CheckDateTime($v)) {
                     $timestamp = strtotime($v);
                     $v = is_int($timestamp) && $timestamp > 0 ? ConvertTimeStamp($timestamp, 'FULL') : '';
                 }
             }
             unset($v);
         } elseif (is_string($data) && $data !== '') {
             if (!CheckDateTime($data)) {
                 $timestamp = strtotime($data);
                 $data = is_int($timestamp) && $timestamp > 0 ? ConvertTimeStamp($timestamp, 'FULL') : '';
             }
         }
     } elseif (is_callable(array($arUserField['USER_TYPE']['CLASS_NAME'], 'getlist'))) {
         // Processing for type user defined class
         $rsEnum = call_user_func_array(array($arUserField['USER_TYPE']['CLASS_NAME'], 'getlist'), array($arUserField));
         $enums = array();
         while ($arEnum = $rsEnum->GetNext()) {
             $enums[strval($arEnum['ID'])] = $arEnum;
         }
         $fieldName = 'VALUE';
         if ($arUserField['USER_TYPE']['USER_TYPE_ID'] === 'iblock_section' || $arUserField['USER_TYPE']['USER_TYPE_ID'] === 'iblock_element') {
             $fieldName = '~NAME';
         }
         self::InternalizeEnumValue($data, $enums, $fieldName);
     }
     return $data;
 }
Ejemplo n.º 6
0
<?php

define('NO_KEEP_STATISTIC', 'Y');
define('NO_AGENT_STATISTIC', 'Y');
define('NO_AGENT_CHECK', true);
define('DisableEventsCheck', true);
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$errors = array();
if (CModule::IncludeModule('crm')) {
    CCrmFileProxy::WriteEventFileToResponse(isset($_REQUEST['eventId']) ? intval($_REQUEST['eventId']) : 0, isset($_REQUEST['fileId']) ? intval($_REQUEST['fileId']) : 0, $errors);
}
require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/prolog_after.php";
if (!empty($errors)) {
    foreach ($errors as $error) {
        echo $error;
    }
}
require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog.php";