Esempio n. 1
0
 public static function AddLead($arData, $CCrmLead)
 {
     global $DB, $USER_FIELD_MANAGER;
     $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'];
     }
     $CCrmUserType = new CCrmUserType($USER_FIELD_MANAGER, CCrmLead::$sUFEntityID);
     $arFields = array_merge($arFields, $CCrmUserType->PrepareExternalFormFields($arData, ','));
     $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);
 }