$firstname, 'cf_1157' => $secondname, 'lastname' => $lastname, 'mobile' => $mobile, 'email' => $email, 'phone' => $tgid, 'birthday' => $birthday, 'cf_1263' => $birthplace, 'mailingstreet' => $mailingstreet, 'cf_1257' => $inn, 'cf_1849' => $requisites, 'cf_1580' => $code ); global $adb, $current_user; $query = "select c.contactid from vtiger_contactdetails c left join vtiger_crmentity e on e.crmid = c.contactid where e.deleted = 0 and c.mobile = ? limit 1"; $result = $adb->pquery($query, array($mobile)); if ($adb->num_rows($result) > 0) { $params['id'] = '12x'.$adb->query_result($result, 0, 'contactid'); $logstring = date('Y-m-d H:i:s').' Массив для обновления Контакта: '.json_encode($params).PHP_EOL; file_put_contents('logs/CreateContact.log', $logstring, FILE_APPEND); try { $contact = vtws_revise($params, $current_user); $output = substr($contact['id'], 3); $logstring = date('Y-m-d H:i:s').' обновлен Контакт с id '.$output.PHP_EOL; file_put_contents('logs/CreateContact.log', $logstring, FILE_APPEND); } catch (WebServiceException $ex) { $logstring = date('Y-m-d H:i:s').' '.$ex->getMessage().PHP_EOL; file_put_contents('logs/CreateContact.log', $logstring, FILE_APPEND); } } else { $params['assigned_user_id'] = vtws_getWebserviceEntityId('Users', $current_user->id); $logstring = date('Y-m-d H:i:s').' Массив для создания Контакта: '.json_encode($params).PHP_EOL; file_put_contents('logs/CreateContact.log', $logstring, FILE_APPEND); try { $contact = vtws_create('Contacts', $params, $current_user); $output = substr($contact['id'], 3); $logstring = date('Y-m-d H:i:s').' создан Контакт с id '.$output.PHP_EOL; file_put_contents('logs/CreateContact.log', $logstring, FILE_APPEND); } catch (WebServiceException $ex) { $logstring = date('Y-m-d H:i:s').' '.$ex->getMessage().PHP_EOL; file_put_contents('logs/CreateContact.log', $logstring, FILE_APPEND); } } return $output; }