dolibarr 24.0.0-beta
server_contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2012 JF FERRY <jfefe@aternatik.fr>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
26if (!defined('NOCSRFCHECK')) {
27 define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
28}
29if (!defined('NOTOKENRENEWAL')) {
30 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
31}
32if (!defined('NOREQUIREMENU')) {
33 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
34}
35if (!defined('NOREQUIREHTML')) {
36 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
37}
38if (!defined('NOREQUIREAJAX')) {
39 define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
40}
41if (!defined("NOLOGIN")) {
42 define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
43}
44if (!defined("NOSESSION")) {
45 define("NOSESSION", '1');
46}
47
48require '../main.inc.php';
49require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
50require_once DOL_DOCUMENT_ROOT."/core/lib/ws.lib.php";
51require_once DOL_DOCUMENT_ROOT."/contact/class/contact.class.php";
52require_once DOL_DOCUMENT_ROOT."/core/class/extrafields.class.php";
53
59dol_syslog("Call Contact webservices interfaces");
60
61// Enable and test if module web services is enabled
62if (!getDolGlobalString('MAIN_MODULE_WEBSERVICES')) {
63 $langs->load("admin");
64 dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
65 print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
66 print $langs->trans("ToActivateModule");
67 exit;
68}
69
70// Create the soap Object
71$server = new nusoap_server();
72$server->soap_defencoding = 'UTF-8';
73$server->decode_utf8 = false;
74$ns = 'http://www.dolibarr.org/ns/';
75$server->configureWSDL('WebServicesDolibarrContact', $ns);
76// @phan-suppress-next-line PhanUndeclaredProperty
77$server->wsdl->schemaTargetNamespace = $ns;
78
79
80// Define WSDL Authentication object
81$server->wsdl->addComplexType(
82 'authentication',
83 'complexType',
84 'struct',
85 'all',
86 '',
87 array(
88 'dolibarrkey' => array('name' => 'dolibarrkey', 'type' => 'xsd:string'),
89 'sourceapplication' => array('name' => 'sourceapplication', 'type' => 'xsd:string'),
90 'login' => array('name' => 'login', 'type' => 'xsd:string'),
91 'password' => array('name' => 'password', 'type' => 'xsd:string'),
92 'entity' => array('name' => 'entity', 'type' => 'xsd:string'),
93 )
94);
95
96// Define WSDL Return object
97$server->wsdl->addComplexType(
98 'result',
99 'complexType',
100 'struct',
101 'all',
102 '',
103 array(
104 'result_code' => array('name' => 'result_code', 'type' => 'xsd:string'),
105 'result_label' => array('name' => 'result_label', 'type' => 'xsd:string'),
106 )
107);
108
109$contact_fields = array(
110 'id' => array('name' => 'id', 'type' => 'xsd:string'),
111 'ref_ext' => array('name' => 'ref_ext', 'type' => 'xsd:string'),
112 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
113 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
114 'address' => array('name' => 'address', 'type' => 'xsd:string'),
115 'zip' => array('name' => 'zip', 'type' => 'xsd:string'),
116 'town' => array('name' => 'town', 'type' => 'xsd:string'),
117 'state_id' => array('name' => 'state_id', 'type' => 'xsd:string'),
118 'state_code' => array('name' => 'state_code', 'type' => 'xsd:string'),
119 'state' => array('name' => 'state', 'type' => 'xsd:string'),
120 'country_id' => array('name' => 'country_id', 'type' => 'xsd:string'),
121 'country_code' => array('name' => 'country_code', 'type' => 'xsd:string'),
122 'country' => array('name' => 'country', 'type' => 'xsd:string'),
123 'socid' => array('name' => 'socid', 'type' => 'xsd:string'),
124 'status' => array('name' => 'status', 'type' => 'xsd:string'),
125 'phone_pro' => array('name' => 'phone_pro', 'type' => 'xsd:string'),
126 'fax' => array('name' => 'fax', 'type' => 'xsd:string'),
127 'phone_perso' => array('name' => 'phone_perso', 'type' => 'xsd:string'),
128 'phone_mobile' => array('name' => 'phone_mobile', 'type' => 'xsd:string'),
129 'code' => array('name' => 'code', 'type' => 'xsd:string'),
130 'email' => array('name' => 'email', 'type' => 'xsd:string'),
131 'birthday' => array('name' => 'birthday', 'type' => 'xsd:string'),
132 'default_lang' => array('name' => 'default_lang', 'type' => 'xsd:string'),
133 'note' => array('name' => 'note', 'type' => 'xsd:string'),
134 'ref_facturation' => array('name' => 'ref_facturation', 'type' => 'xsd:string'),
135 'ref_contrat' => array('name' => 'ref_contrat', 'type' => 'xsd:string'),
136 'ref_commande' => array('name' => 'ref_commande', 'type' => 'xsd:string'),
137 'ref_propal' => array('name' => 'ref_propal', 'type' => 'xsd:string'),
138 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
139 'user_login' => array('name' => 'user_login', 'type' => 'xsd:string'),
140 'civility_id' => array('name' => 'civility_id', 'type' => 'xsd:string'),
141 'poste' => array('name' => 'poste', 'type' => 'xsd:string')
142 //...
143);
144
145$elementtype = 'socpeople';
146
147
148//Retrieve all extrafield for contact
149// fetch optionals attributes and labels
150$extrafields = new ExtraFields($db);
151$extrafields->fetch_name_optionals_label($elementtype, true);
152$extrafield_array = null;
153if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype]['count'] > 0) {
154 $extrafield_array = array();
155}
156if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
157 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
158 $type = $extrafields->attributes[$elementtype]['type'][$key];
159 if ($type == 'date' || $type == 'datetime') {
160 $type = 'xsd:dateTime';
161 } else {
162 $type = 'xsd:string';
163 }
164
165 $extrafield_array['options_'.$key] = array('name' => 'options_'.$key, 'type' => $type);
166 }
167}
168if (is_array($extrafield_array)) {
169 $contact_fields = array_merge($contact_fields, $extrafield_array);
170}
171
172// Define other specific objects
173$server->wsdl->addComplexType(
174 'contact',
175 'complexType',
176 'struct',
177 'all',
178 '',
179 $contact_fields
180);
181
182$server->wsdl->addComplexType(
183 'ContactsArray2',
184 'complexType',
185 'array',
186 'sequence',
187 '',
188 array(
189 'contact' => array(
190 'name' => 'contact',
191 'type' => 'tns:contact',
192 'minOccurs' => '0',
193 'maxOccurs' => 'unbounded'
194 )
195 )
196);
197
198
199
200
201// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
202// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
203// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
204$styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
205$styleuse = 'encoded'; // encoded/literal/literal wrapped
206// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
207
208
209// Register WSDL
210$server->register(
211 'getContact',
212 // Entry values
213 array('authentication' => 'tns:authentication', 'id' => 'xsd:string', 'ref_ext' => 'xsd:string'),
214 // Exit values
215 array('result' => 'tns:result', 'contact' => 'tns:contact'),
216 $ns,
217 $ns.'#getContact',
218 $styledoc,
219 $styleuse,
220 'WS to get a contact'
221);
222
223// Register WSDL
224$server->register(
225 'createContact',
226 // Entry values
227 array('authentication' => 'tns:authentication', 'contact' => 'tns:contact'),
228 // Exit values
229 array('result' => 'tns:result', 'id' => 'xsd:string'),
230 $ns,
231 $ns.'#createContact',
232 $styledoc,
233 $styleuse,
234 'WS to create a contact'
235);
236
237$server->register(
238 'getContactsForThirdParty',
239 // Entry values
240 array('authentication' => 'tns:authentication', 'idthirdparty' => 'xsd:string'),
241 // Exit values
242 array('result' => 'tns:result', 'contacts' => 'tns:ContactsArray2'),
243 $ns,
244 $ns.'#getContactsForThirdParty',
245 $styledoc,
246 $styleuse,
247 'WS to get all contacts of a third party'
248);
249
250// Register WSDL
251$server->register(
252 'updateContact',
253 // Entry values
254 array('authentication' => 'tns:authentication', 'contact' => 'tns:contact'),
255 // Exit values
256 array('result' => 'tns:result', 'id' => 'xsd:string'),
257 $ns,
258 $ns.'#updateContact',
259 $styledoc,
260 $styleuse,
261 'WS to update a contact'
262);
263
264
273function getContact($authentication, $id, $ref_ext)
274{
275 global $db, $conf, $langs;
276
277 dol_syslog("Function: getContact login=".$authentication['login']." id=".$id." ref_ext=".$ref_ext);
278
279 if ($authentication['entity']) {
280 $conf->entity = $authentication['entity'];
281 }
282
283 // Init and check authentication
284 $objectresp = array();
285 $errorcode = '';
286 $errorlabel = '';
287 $error = 0;
288 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
289 // Check parameters
290 if (!$error && ($id && $ref_ext)) {
291 $error++;
292 $errorcode = 'BAD_PARAMETERS';
293 $errorlabel = "Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
294 }
295
296 if (!$error) {
297 $fuser->loadRights();
298
299 $contact = new Contact($db);
300 $result = $contact->fetch($id, null, $ref_ext);
301 if ($result > 0) {
302 // Only internal user who have contact read permission
303 // Or for external user who have contact read permission, with restrict on socid
304 if ($fuser->hasRight('societe', 'contact', 'lire') && !$fuser->socid
305 || ($fuser->hasRight('societe', 'contact', 'lire') && ($fuser->socid == $contact->socid))
306 ) {
307 $contact_result_fields = array(
308 'id' => $contact->id,
309 'ref_ext' => $contact->ref_ext,
310 'lastname' => $contact->lastname,
311 'firstname' => $contact->firstname,
312 'address' => $contact->address,
313 'zip' => $contact->zip,
314 'town' => $contact->town,
315 'state_id' => $contact->state_id,
316 'state_code' => $contact->state_code,
317 'state' => $contact->state,
318 'country_id' => $contact->country_id,
319 'country_code' => $contact->country_code,
320 'country' => $contact->country,
321 'socid' => $contact->socid,
322 'status' => $contact->status,
323 'phone_pro' => $contact->phone_pro,
324 'fax' => $contact->fax,
325 'phone_perso' => $contact->phone_perso,
326 'phone_mobile' => $contact->phone_mobile,
327 'code' => $contact->code,
328 'email' => $contact->email,
329 'birthday' => $contact->birthday,
330 'default_lang' => $contact->default_lang,
331 'note' => $contact->note,
332 'ref_facturation' => $contact->ref_facturation,
333 'ref_contrat' => $contact->ref_contrat,
334 'ref_commande' => $contact->ref_commande,
335 'ref_propal' => $contact->ref_propal,
336 'user_id' => $contact->user_id,
337 'user_login' => $contact->user_login,
338 'civility_id' => $contact->civility_id,
339 'poste' => $contact->poste
340 );
341
342 $elementtype = 'socpeople';
343
344 //Retrieve all extrafield for thirdsparty
345 // fetch optionals attributes and labels
346 $extrafields = new ExtraFields($db);
347 $extrafields->fetch_name_optionals_label($elementtype, true);
348 //Get extrafield values
349 $contact->fetch_optionals();
350
351 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
352 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
353 $contact_result_fields = array_merge($contact_result_fields, array('options_'.$key => $contact->array_options['options_'.$key]));
354 }
355 }
356
357 // Create
358 $objectresp = array(
359 'result' => array('result_code' => 'OK', 'result_label' => ''),
360 'contact' => $contact_result_fields
361 );
362 } else {
363 $error++;
364 $errorcode = 'PERMISSION_DENIED';
365 $errorlabel = 'User does not have permission for this request';
366 }
367 } else {
368 $error++;
369 $errorcode = 'NOT_FOUND';
370 $errorlabel = 'Object not found for id='.$id.' nor ref_ext='.$ref_ext;
371 }
372 }
373
374 if ($error) {
375 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
376 }
377
378 return $objectresp;
379}
380
381
389function createContact($authentication, $contact)
390{
391 global $db, $conf;
392
393 $now = dol_now();
394
395 dol_syslog("Function: createContact login=".$authentication['login']);
396
397 if ($authentication['entity']) {
398 $conf->entity = $authentication['entity'];
399 }
400
401 // Init and check authentication
402 $objectresp = array();
403 $errorcode = '';
404 $errorlabel = '';
405 $error = 0;
406 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
407 // Check parameters
408 if (empty($contact['lastname'])) {
409 $error++;
410 $errorcode = 'KO';
411 $errorlabel = "Name is mandatory.";
412 }
413
414 if (!$error) {
415 $newobject = new Contact($db);
416
417 $newobject->id = (int) $contact['id'];
418 $newobject->ref_ext = $contact['ref_ext'];
419 $newobject->civility_id = $contact['civility_id'];
420 $newobject->lastname = $contact['lastname'];
421 $newobject->firstname = $contact['firstname'];
422 $newobject->address = $contact['address'];
423 $newobject->zip = $contact['zip'];
424 $newobject->town = $contact['town'];
425 $newobject->state_id = (int) $contact['state_id'];
426 $newobject->state_code = $contact['state_code'];
427 $newobject->state = $contact['state'];
428 $newobject->country_id = (int) $contact['country_id'];
429 $newobject->country_code = $contact['country_code'];
430 $newobject->country = $contact['country'];
431 $newobject->socid = (int) $contact['socid'];
432 $newobject->status = (int) $contact['status'];
433 $newobject->phone_pro = $contact['phone_pro'];
434 $newobject->fax = $contact['fax'];
435 $newobject->phone_perso = $contact['phone_perso'];
436 $newobject->phone_mobile = $contact['phone_mobile'];
437 $newobject->code = $contact['code'];
438 $newobject->email = $contact['email'];
439 $newobject->birthday = $contact['birthday'];
440 $newobject->default_lang = $contact['default_lang'];
441 $newobject->note_private = $contact['note'];
442 $newobject->ref_facturation = (int) $contact['ref_facturation'];
443 $newobject->ref_contrat = (int) $contact['ref_contrat'];
444 $newobject->ref_commande = (int) $contact['ref_commande'];
445 $newobject->ref_propal = (int) $contact['ref_propal'];
446 $newobject->user_id = (int) $contact['user_id'];
447 $newobject->user_login = $contact['user_login'];
448 $newobject->poste = $contact['poste'];
449
450 $elementtype = 'socpeople';
451
452 //Retrieve all extrafield for thirdsparty
453 // fetch optionals attributes and labels
454 $extrafields = new ExtraFields($db);
455 $extrafields->fetch_name_optionals_label($elementtype, true);
456 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
457 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
458 $key = 'options_'.$key;
459 $newobject->array_options[$key] = $contact[$key];
460 }
461 }
462
463
464 //...
465
466 $db->begin();
467
468 $result = $newobject->create($fuser);
469 if ($result <= 0) {
470 $error++;
471 }
472
473 if (!$error) {
474 $db->commit();
475 $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref);
476 } else {
477 $db->rollback();
478 $error++;
479 $errorcode = 'KO';
480 $errorlabel = $newobject->error;
481 }
482 }
483
484 if ($error) {
485 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
486 }
487
488 return $objectresp;
489}
490
498function getContactsForThirdParty($authentication, $idthirdparty)
499{
500 global $db, $conf;
501
502 dol_syslog("Function: getContactsForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
503
504 if ($authentication['entity']) {
505 $conf->entity = $authentication['entity'];
506 }
507
508 // Init and check authentication
509 $objectresp = array();
510 $errorcode = '';
511 $errorlabel = '';
512 $error = 0;
513 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
514 // Check parameters
515 if (!$error && empty($idthirdparty)) {
516 $error++;
517 $errorcode = 'BAD_PARAMETERS';
518 $errorlabel = 'Parameter id is not provided';
519 }
520
521 if (!$error) {
522 $linesinvoice = array();
523
524 $sql = "SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
525 $sql .= " c.address, c.zip, c.town,";
526 $sql .= " c.fk_pays as country_id,";
527 $sql .= " c.fk_departement as state_id,";
528 $sql .= " c.birthday,";
529 $sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
530 $sql .= " co.label as country, co.code as country_code,";
531 $sql .= " d.nom as state, d.code_departement as state_code,";
532 $sql .= " u.rowid as user_id, u.login as user_login,";
533 $sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
534 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
535 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
536 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
537 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
538 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
539 $sql .= " WHERE c.fk_soc = ".((int) $idthirdparty);
540
541 $resql = $db->query($sql);
542 if ($resql) {
543 $linescontact = array();
544 $num = $db->num_rows($resql);
545 $i = 0;
546 while ($i < $num) {
547 // En attendant remplissage par boucle
548 $obj = $db->fetch_object($resql);
549
550 $contact = new Contact($db);
551 $contact->fetch($obj->rowid);
552
553 // Now define invoice
554 $linescontact[] = array(
555 'id' => $contact->id,
556 'ref' => $contact->ref,
557 'civility_id' => $contact->civility_id ? $contact->civility_id : '',
558 'lastname' => $contact->lastname ? $contact->lastname : '',
559 'firstname' => $contact->firstname ? $contact->firstname : '',
560 'address' => $contact->address ? $contact->address : '',
561 'zip' => $contact->zip ? $contact->zip : '',
562 'town' => $contact->town ? $contact->town : '',
563
564 'state_id' => $contact->state_id ? $contact->state_id : '',
565 'state_code' => $contact->state_code ? $contact->state_code : '',
566 'state' => $contact->state ? $contact->state : '',
567
568 'country_id' => $contact->country_id ? $contact->country_id : '',
569 'country_code' => $contact->country_code ? $contact->country_code : '',
570 'country' => $contact->country ? $contact->country : '',
571
572 'socid' => $contact->socid ? $contact->socid : '',
573 'socname' => $contact->socname ? $contact->socname : '',
574 'poste' => $contact->poste ? $contact->poste : '',
575
576 'phone_pro' => $contact->phone_pro ? $contact->phone_pro : '',
577 'fax' => $contact->fax ? $contact->fax : '',
578 'phone_perso' => $contact->phone_perso ? $contact->phone_perso : '',
579 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile : '',
580
581 'email' => $contact->email ? $contact->email : '',
582 'priv' => $contact->priv ? $contact->priv : '',
583 'mail' => $contact->mail ? $contact->mail : '',
584
585 'birthday' => $contact->birthday ? $contact->birthday : '',
586 'default_lang' => $contact->default_lang ? $contact->default_lang : '',
587 'note' => $contact->note ? $contact->note : '',
588 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation : '',
589 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat : '',
590 'ref_commande' => $contact->ref_commande ? $contact->ref_commande : '',
591 'ref_propal' => $contact->ref_propal ? $contact->ref_propal : '',
592 'user_id' => $contact->user_id ? $contact->user_id : '',
593 'user_login' => $contact->user_login ? $contact->user_login : '',
594 'status' => $contact->status ? $contact->status : ''
595 );
596
597 $i++;
598 }
599
600 $objectresp = array(
601 'result' => array('result_code' => 'OK', 'result_label' => ''),
602 'contacts' => $linescontact
603
604 );
605 } else {
606 $error++;
607 $errorcode = $db->lasterrno();
608 $errorlabel = $db->lasterror();
609 }
610 }
611
612 if ($error) {
613 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
614 }
615
616 return $objectresp;
617}
618
619
627function updateContact($authentication, $contact)
628{
629 global $db, $conf;
630
631 $now = dol_now();
632
633 dol_syslog("Function: updateContact login=".$authentication['login']);
634
635 if ($authentication['entity']) {
636 $conf->entity = $authentication['entity'];
637 }
638
639 // Init and check authentication
640 $objectresp = array();
641 $errorcode = '';
642 $errorlabel = '';
643 $error = 0;
644 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
645 // Check parameters
646 if (empty($contact['id']) && empty($contact['ref_ext'])) {
647 $error++;
648 $errorcode = 'KO';
649 $errorlabel = "Contact id or ref_ext is mandatory.";
650 }
651 // Check parameters
652 if (!$error && ($contact['id'] && $contact['ref_ext'])) {
653 $error++;
654 $errorcode = 'BAD_PARAMETERS';
655 $errorlabel = "Parameter id and ref_ext can't be all provided. You must choose one of them.";
656 }
657
658 if (!$error) {
659 $objectfound = false;
660
661 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
662
663 $object = new Contact($db);
664 $result = $object->fetch((int) $contact['id'], null, $contact['ref_ext']);
665
666 if (!empty($object->id)) {
667 $objectfound = true;
668
669 $object->ref_ext = $contact['ref_ext'];
670
671 $object->firstname = $contact['firstname'];
672 $object->lastname = $contact['lastname'];
673
674 $object->address = $contact['address'];
675 $object->zip = $contact['zip'];
676 $object->town = $contact['town'];
677
678 $object->country_id = (int) $contact['country_id'];
679 if ($contact['country_code']) {
680 $object->country_id = getCountry($contact['country_code'], '3');
681 }
682 $object->province_id = isset($contact['province_id']) ? $contact['province_id'] : null;
683
684
685 $object->phone_pro = $contact['phone_pro'];
686 $object->phone_perso = $contact['phone_perso'];
687 $object->phone_mobile = $contact['phone_mobile'];
688 $object->fax = $contact['fax'];
689 $object->email = $contact['email'];
690
691 $object->civility_id = $contact['civility_id'];
692 $object->poste = $contact['poste'];
693
694 $object->statut = (int) $contact['status'];
695
696 $elementtype = 'socpeople';
697
698 //Retrieve all extrafield for contact
699 // fetch optionals attributes and labels
700 $extrafields = new ExtraFields($db);
701 $extrafields->fetch_name_optionals_label($elementtype, true);
702 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
703 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
704 $key = 'options_'.$key;
705 $object->array_options[$key] = $contact[$key];
706 }
707 }
708
709 $db->begin();
710
711 $result = $object->update((int) $contact['id'], $fuser);
712 if ($result <= 0) {
713 $error++;
714 }
715 }
716 '@phan-var-force array{id:string} $contact';
717
718 if ((!$error) && ($objectfound)) {
719 $db->commit();
720 $objectresp = array(
721 'result' => array('result_code' => 'OK', 'result_label' => ''),
722 'id' => $object->id
723 );
724 } elseif ($objectfound) {
725 $db->rollback();
726 $error++;
727 $errorcode = 'KO';
728 $errorlabel = $object->error;
729 } else {
730 $error++;
731 $errorcode = 'NOT_FOUND';
732 $errorlabel = 'Contact id='.$contact['id'].' cannot be found';
733 }
734 }
735
736 if ($error) {
737 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
738 }
739
740 return $objectresp;
741}
742
743// Return the results.
744$server->service(file_get_contents("php://input"));
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage contact/addresses.
Class to manage standard extra fields.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getContactsForThirdParty($authentication, $idthirdparty)
Get list of contacts for third party.
getContact($authentication, $id, $ref_ext)
Get Contact.
updateContact($authentication, $contact)
Update a contact.
createContact($authentication, $contact)
Create Contact.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition ws.lib.php:37