Exemplo n.º 1
0
 public function Add($data)
 {
     global $DB;
     if (($r = self::CheckAuth()) !== false) {
         return $r;
     }
     $arFieldsInfo = CCrmLead::GetFields();
     $arFields = array();
     $arEl = $data->elementsByName('Field');
     foreach ($arEl as $child) {
         $children = $child->children();
         $sFieldName = $child->getAttribute('id');
         // Fix for issue #40193
         if (!isset($arFieldsInfo[$sFieldName])) {
             continue;
         }
         if (!is_null($children)) {
             $arFields[$sFieldName] = array();
             foreach ($children as $child) {
                 $arFields[$sFieldName][] = $child->content;
             }
         } else {
             $arFields[$sFieldName] = $child->content;
         }
     }
     CCrmFieldMulti::PrepareFields($arFields);
     $CCrmUserType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], CCrmLead::$sUFEntityID);
     $CCrmUserType->PrepareImport($arFields, ',');
     $CCrmBizProc = new CCrmBizProc('LEAD');
     if (false === $CCrmBizProc->CheckFields(false, true)) {
         return new CSoapFault('CCrmLead::Add Bizproc', htmlspecialcharsbx(strip_tags(nl2br($CCrmBizProc->LAST_ERROR))));
     }
     $CCrmLead = new CCrmLead();
     $DB->StartTransaction();
     $ID = $CCrmLead->Add($arFields);
     if ($ID !== false && !$CCrmBizProc->StartWorkflow($ID)) {
         $DB->Rollback();
         return new CSoapFault('CCrmLead::Add Bizproc', htmlspecialcharsbx(strip_tags(nl2br($CCrmBizProc->LAST_ERROR))));
     }
     if ($ID === false) {
         $DB->Rollback();
         return new CSoapFault('CCrmLead::Add', htmlspecialcharsbx(strip_tags(nl2br($arFields['RESULT_MESSAGE']))));
     }
     $DB->Commit();
     return 'ok';
 }
Exemplo n.º 2
0
 public static function AddLead($arData, $CCrmLead)
 {
     global $DB, $USER_FIELD_MANAGER;
     $CCrmBizProc = new CCrmBizProc('LEAD');
     $arData['CURRENCY_ID'] = trim($arData['CURRENCY_ID']);
     if (strlen($arData['CURRENCY_ID']) <= 0) {
         $arData['CURRENCY_ID'] = CCrmCurrency::GetBaseCurrencyID();
     }
     $arFields = array('TITLE' => trim($arData['TITLE']), 'COMPANY_TITLE' => trim($arData['COMPANY_TITLE']), 'NAME' => trim($arData['NAME']), 'LAST_NAME' => trim($arData['LAST_NAME']), 'SECOND_NAME' => trim($arData['SECOND_NAME']), 'POST' => trim($arData['POST']), 'ADDRESS' => trim($arData['ADDRESS']), 'COMMENTS' => trim($arData['COMMENTS']), 'SOURCE_DESCRIPTION' => trim($arData['SOURCE_DESCRIPTION']), 'STATUS_DESCRIPTION' => trim($arData['STATUS_DESCRIPTION']), 'OPPORTUNITY' => trim($arData['OPPORTUNITY']), 'CURRENCY_ID' => trim($arData['CURRENCY_ID']), 'ASSIGNED_BY_ID' => (int) (is_array($arData['ASSIGNED_BY_ID']) ? $arData['ASSIGNED_BY_ID'][0] : $arData['ASSIGNED_BY_ID']), 'OPENED' => 'Y');
     $arData['SOURCE_ID'] = trim($arData['SOURCE_ID']);
     $arData['STATUS_ID'] = trim($arData['STATUS_ID']);
     if (strlen($arData['STATUS_ID']) > 0) {
         $arFields['STATUS_ID'] = $arData['STATUS_ID'];
     }
     if (strlen($arData['SOURCE_ID']) > 0) {
         $arFields['SOURCE_ID'] = $arData['SOURCE_ID'];
     }
     $USER_FIELD_MANAGER->EditFormAddFields(CCrmLead::$sUFEntityID, $arFields);
     $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmLead::$sUFEntityID);
     $CCrmUserType->PrepareImport($arFields, ',');
     $arFields['FM'] = CCrmFieldMulti::PrepareFields($arData);
     $DB->StartTransaction();
     $ID = $CCrmLead->Add($arFields);
     if ($ID === false) {
         $DB->Rollback();
         if (!empty($arFields['RESULT_MESSAGE'])) {
             $sErrorMessage = $arFields['RESULT_MESSAGE'];
         } else {
             $sErrorMessage = GetMessage('UNKNOWN_ERROR');
         }
         $res = array('error' => 400, 'error_message' => strip_tags(nl2br($sErrorMessage)));
     } else {
         $DB->Commit();
         // Ignore all BizProc errors
         try {
             $arErrors = array();
             CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Lead, $ID, CCrmBizProcEventType::Create, $arErrors);
         } catch (Exception $e) {
         }
         $res = array('error' => 201, 'ID' => $ID, 'error_message' => GetMessage('CRM_REST_OK'));
     }
     return self::_out($res);
 }