dolibarr 21.0.0-alpha
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 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 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
54
55dol_syslog("Call Contact webservices interfaces");
56
57// Enable and test if module web services is enabled
58if (!getDolGlobalString('MAIN_MODULE_WEBSERVICES')) {
59 $langs->load("admin");
60 dol_syslog("Call Dolibarr webservices interfaces with module webservices disabled");
61 print $langs->trans("WarningModuleNotActive", 'WebServices').'.<br><br>';
62 print $langs->trans("ToActivateModule");
63 exit;
64}
65
66// Create the soap Object
67$server = new nusoap_server();
68$server->soap_defencoding = 'UTF-8';
69$server->decode_utf8 = false;
70$ns = 'http://www.dolibarr.org/ns/';
71$server->configureWSDL('WebServicesDolibarrContact', $ns);
72$server->wsdl->schemaTargetNamespace = $ns;
73
74
75// Define WSDL Authentication object
76$server->wsdl->addComplexType(
77 'authentication',
78 'complexType',
79 'struct',
80 'all',
81 '',
82 array(
83 'dolibarrkey' => array('name' => 'dolibarrkey', 'type' => 'xsd:string'),
84 'sourceapplication' => array('name' => 'sourceapplication', 'type' => 'xsd:string'),
85 'login' => array('name' => 'login', 'type' => 'xsd:string'),
86 'password' => array('name' => 'password', 'type' => 'xsd:string'),
87 'entity' => array('name' => 'entity', 'type' => 'xsd:string'),
88 )
89);
90
91// Define WSDL Return object
92$server->wsdl->addComplexType(
93 'result',
94 'complexType',
95 'struct',
96 'all',
97 '',
98 array(
99 'result_code' => array('name' => 'result_code', 'type' => 'xsd:string'),
100 'result_label' => array('name' => 'result_label', 'type' => 'xsd:string'),
101 )
102);
103
104$contact_fields = array(
105 'id' => array('name' => 'id', 'type' => 'xsd:string'),
106 'ref_ext' => array('name' => 'ref_ext', 'type' => 'xsd:string'),
107 'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
108 'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
109 'address' => array('name' => 'address', 'type' => 'xsd:string'),
110 'zip' => array('name' => 'zip', 'type' => 'xsd:string'),
111 'town' => array('name' => 'town', 'type' => 'xsd:string'),
112 'state_id' => array('name' => 'state_id', 'type' => 'xsd:string'),
113 'state_code' => array('name' => 'state_code', 'type' => 'xsd:string'),
114 'state' => array('name' => 'state', 'type' => 'xsd:string'),
115 'country_id' => array('name' => 'country_id', 'type' => 'xsd:string'),
116 'country_code' => array('name' => 'country_code', 'type' => 'xsd:string'),
117 'country' => array('name' => 'country', 'type' => 'xsd:string'),
118 'socid' => array('name' => 'socid', 'type' => 'xsd:string'),
119 'status' => array('name' => 'status', 'type' => 'xsd:string'),
120 'phone_pro' => array('name' => 'phone_pro', 'type' => 'xsd:string'),
121 'fax' => array('name' => 'fax', 'type' => 'xsd:string'),
122 'phone_perso' => array('name' => 'phone_perso', 'type' => 'xsd:string'),
123 'phone_mobile' => array('name' => 'phone_mobile', 'type' => 'xsd:string'),
124 'code' => array('name' => 'code', 'type' => 'xsd:string'),
125 'email' => array('name' => 'email', 'type' => 'xsd:string'),
126 'birthday' => array('name' => 'birthday', 'type' => 'xsd:string'),
127 'default_lang' => array('name' => 'default_lang', 'type' => 'xsd:string'),
128 'note' => array('name' => 'note', 'type' => 'xsd:string'),
129 'ref_facturation' => array('name' => 'ref_facturation', 'type' => 'xsd:string'),
130 'ref_contrat' => array('name' => 'ref_contrat', 'type' => 'xsd:string'),
131 'ref_commande' => array('name' => 'ref_commande', 'type' => 'xsd:string'),
132 'ref_propal' => array('name' => 'ref_propal', 'type' => 'xsd:string'),
133 'user_id' => array('name' => 'user_id', 'type' => 'xsd:string'),
134 'user_login' => array('name' => 'user_login', 'type' => 'xsd:string'),
135 'civility_id' => array('name' => 'civility_id', 'type' => 'xsd:string'),
136 'poste' => array('name' => 'poste', 'type' => 'xsd:string')
137 //...
138);
139
140$elementtype = 'socpeople';
141
142
143//Retrieve all extrafield for contact
144// fetch optionals attributes and labels
145$extrafields = new ExtraFields($db);
146$extrafields->fetch_name_optionals_label($elementtype, true);
147$extrafield_array = null;
148if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype]['count'] > 0) {
149 $extrafield_array = array();
150}
151if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
152 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
153 $type = $extrafields->attributes[$elementtype]['type'][$key];
154 if ($type == 'date' || $type == 'datetime') {
155 $type = 'xsd:dateTime';
156 } else {
157 $type = 'xsd:string';
158 }
159
160 $extrafield_array['options_'.$key] = array('name' => 'options_'.$key, 'type' => $type);
161 }
162}
163if (is_array($extrafield_array)) {
164 $contact_fields = array_merge($contact_fields, $extrafield_array);
165}
166
167// Define other specific objects
168$server->wsdl->addComplexType(
169 'contact',
170 'complexType',
171 'struct',
172 'all',
173 '',
174 $contact_fields
175);
176
177$server->wsdl->addComplexType(
178 'ContactsArray2',
179 'complexType',
180 'array',
181 'sequence',
182 '',
183 array(
184 'contact' => array(
185 'name' => 'contact',
186 'type' => 'tns:contact',
187 'minOccurs' => '0',
188 'maxOccurs' => 'unbounded'
189 )
190 )
191);
192
193
194
195
196// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
197// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
198// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
199$styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
200$styleuse = 'encoded'; // encoded/literal/literal wrapped
201// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
202
203
204// Register WSDL
205$server->register(
206 'getContact',
207 // Entry values
208 array('authentication' => 'tns:authentication', 'id' => 'xsd:string', 'ref_ext' => 'xsd:string'),
209 // Exit values
210 array('result' => 'tns:result', 'contact' => 'tns:contact'),
211 $ns,
212 $ns.'#getContact',
213 $styledoc,
214 $styleuse,
215 'WS to get a contact'
216);
217
218// Register WSDL
219$server->register(
220 'createContact',
221 // Entry values
222 array('authentication' => 'tns:authentication', 'contact' => 'tns:contact'),
223 // Exit values
224 array('result' => 'tns:result', 'id' => 'xsd:string'),
225 $ns,
226 $ns.'#createContact',
227 $styledoc,
228 $styleuse,
229 'WS to create a contact'
230);
231
232$server->register(
233 'getContactsForThirdParty',
234 // Entry values
235 array('authentication' => 'tns:authentication', 'idthirdparty' => 'xsd:string'),
236 // Exit values
237 array('result' => 'tns:result', 'contacts' => 'tns:ContactsArray2'),
238 $ns,
239 $ns.'#getContactsForThirdParty',
240 $styledoc,
241 $styleuse,
242 'WS to get all contacts of a third party'
243);
244
245// Register WSDL
246$server->register(
247 'updateContact',
248 // Entry values
249 array('authentication' => 'tns:authentication', 'contact' => 'tns:contact'),
250 // Exit values
251 array('result' => 'tns:result', 'id' => 'xsd:string'),
252 $ns,
253 $ns.'#updateContact',
254 $styledoc,
255 $styleuse,
256 'WS to update a contact'
257);
258
259
268function getContact($authentication, $id, $ref_ext)
269{
270 global $db, $conf, $langs;
271
272 dol_syslog("Function: getContact login=".$authentication['login']." id=".$id." ref_ext=".$ref_ext);
273
274 if ($authentication['entity']) {
275 $conf->entity = $authentication['entity'];
276 }
277
278 // Init and check authentication
279 $objectresp = array();
280 $errorcode = '';
281 $errorlabel = '';
282 $error = 0;
283 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
284 // Check parameters
285 if (!$error && ($id && $ref_ext)) {
286 $error++;
287 $errorcode = 'BAD_PARAMETERS';
288 $errorlabel = "Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
289 }
290
291 if (!$error) {
292 $fuser->loadRights();
293
294 $contact = new Contact($db);
295 $result = $contact->fetch($id, null, $ref_ext);
296 if ($result > 0) {
297 // Only internal user who have contact read permission
298 // Or for external user who have contact read permission, with restrict on socid
299 if ($fuser->hasRight('societe', 'contact', 'lire') && !$fuser->socid
300 || ($fuser->hasRight('societe', 'contact', 'lire') && ($fuser->socid == $contact->socid))
301 ) {
302 $contact_result_fields = array(
303 'id' => $contact->id,
304 'ref_ext' => $contact->ref_ext,
305 'lastname' => $contact->lastname,
306 'firstname' => $contact->firstname,
307 'address' => $contact->address,
308 'zip' => $contact->zip,
309 'town' => $contact->town,
310 'state_id' => $contact->state_id,
311 'state_code' => $contact->state_code,
312 'state' => $contact->state,
313 'country_id' => $contact->country_id,
314 'country_code' => $contact->country_code,
315 'country' => $contact->country,
316 'socid' => $contact->socid,
317 'status' => $contact->statut,
318 'phone_pro' => $contact->phone_pro,
319 'fax' => $contact->fax,
320 'phone_perso' => $contact->phone_perso,
321 'phone_mobile' => $contact->phone_mobile,
322 'code' => $contact->code,
323 'email' => $contact->email,
324 'birthday' => $contact->birthday,
325 'default_lang' => $contact->default_lang,
326 'note' => $contact->note,
327 'ref_facturation' => $contact->ref_facturation,
328 'ref_contrat' => $contact->ref_contrat,
329 'ref_commande' => $contact->ref_commande,
330 'ref_propal' => $contact->ref_propal,
331 'user_id' => $contact->user_id,
332 'user_login' => $contact->user_login,
333 'civility_id' => $contact->civility_id,
334 'poste' => $contact->poste
335 );
336
337 $elementtype = 'socpeople';
338
339 //Retrieve all extrafield for thirdsparty
340 // fetch optionals attributes and labels
341 $extrafields = new ExtraFields($db);
342 $extrafields->fetch_name_optionals_label($elementtype, true);
343 //Get extrafield values
344 $contact->fetch_optionals();
345
346 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
347 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
348 $contact_result_fields = array_merge($contact_result_fields, array('options_'.$key => $contact->array_options['options_'.$key]));
349 }
350 }
351
352 // Create
353 $objectresp = array(
354 'result' => array('result_code' => 'OK', 'result_label' => ''),
355 'contact' => $contact_result_fields
356 );
357 } else {
358 $error++;
359 $errorcode = 'PERMISSION_DENIED';
360 $errorlabel = 'User does not have permission for this request';
361 }
362 } else {
363 $error++;
364 $errorcode = 'NOT_FOUND';
365 $errorlabel = 'Object not found for id='.$id.' nor ref_ext='.$ref_ext;
366 }
367 }
368
369 if ($error) {
370 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
371 }
372
373 return $objectresp;
374}
375
376
384function createContact($authentication, $contact)
385{
386 global $db, $conf;
387
388 $now = dol_now();
389
390 dol_syslog("Function: createContact login=".$authentication['login']);
391
392 if ($authentication['entity']) {
393 $conf->entity = $authentication['entity'];
394 }
395
396 // Init and check authentication
397 $objectresp = array();
398 $errorcode = '';
399 $errorlabel = '';
400 $error = 0;
401 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
402 // Check parameters
403 if (empty($contact['lastname'])) {
404 $error++;
405 $errorcode = 'KO';
406 $errorlabel = "Name is mandatory.";
407 }
408
409 if (!$error) {
410 $newobject = new Contact($db);
411
412 $newobject->id = $contact['id'];
413 $newobject->ref_ext = $contact['ref_ext'];
414 $newobject->civility_id = $contact['civility_id'];
415 $newobject->lastname = $contact['lastname'];
416 $newobject->firstname = $contact['firstname'];
417 $newobject->address = $contact['address'];
418 $newobject->zip = $contact['zip'];
419 $newobject->town = $contact['town'];
420 $newobject->state_id = $contact['state_id'];
421 $newobject->state_code = $contact['state_code'];
422 $newobject->state = $contact['state'];
423 $newobject->country_id = $contact['country_id'];
424 $newobject->country_code = $contact['country_code'];
425 $newobject->country = $contact['country'];
426 $newobject->socid = $contact['socid'];
427 $newobject->statut = $contact['status'];
428 $newobject->phone_pro = $contact['phone_pro'];
429 $newobject->fax = $contact['fax'];
430 $newobject->phone_perso = $contact['phone_perso'];
431 $newobject->phone_mobile = $contact['phone_mobile'];
432 $newobject->code = $contact['code'];
433 $newobject->email = $contact['email'];
434 $newobject->birthday = $contact['birthday'];
435 $newobject->default_lang = $contact['default_lang'];
436 $newobject->note = $contact['note'];
437 $newobject->ref_facturation = $contact['ref_facturation'];
438 $newobject->ref_contrat = $contact['ref_contrat'];
439 $newobject->ref_commande = $contact['ref_commande'];
440 $newobject->ref_propal = $contact['ref_propal'];
441 $newobject->user_id = $contact['user_id'];
442 $newobject->user_login = $contact['user_login'];
443 $newobject->poste = $contact['poste'];
444
445 $elementtype = 'socpeople';
446
447 //Retrieve all extrafield for thirdsparty
448 // fetch optionals attributes and labels
449 $extrafields = new ExtraFields($db);
450 $extrafields->fetch_name_optionals_label($elementtype, true);
451 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
452 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
453 $key = 'options_'.$key;
454 $newobject->array_options[$key] = $contact[$key];
455 }
456 }
457
458
459 //...
460
461 $db->begin();
462
463 $result = $newobject->create($fuser);
464 if ($result <= 0) {
465 $error++;
466 }
467
468 if (!$error) {
469 $db->commit();
470 $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref);
471 } else {
472 $db->rollback();
473 $error++;
474 $errorcode = 'KO';
475 $errorlabel = $newobject->error;
476 }
477 }
478
479 if ($error) {
480 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
481 }
482
483 return $objectresp;
484}
485
493function getContactsForThirdParty($authentication, $idthirdparty)
494{
495 global $db, $conf;
496
497 dol_syslog("Function: getContactsForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
498
499 if ($authentication['entity']) {
500 $conf->entity = $authentication['entity'];
501 }
502
503 // Init and check authentication
504 $objectresp = array();
505 $errorcode = '';
506 $errorlabel = '';
507 $error = 0;
508 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
509 // Check parameters
510 if (!$error && empty($idthirdparty)) {
511 $error++;
512 $errorcode = 'BAD_PARAMETERS';
513 $errorlabel = 'Parameter id is not provided';
514 }
515
516 if (!$error) {
517 $linesinvoice = array();
518
519 $sql = "SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
520 $sql .= " c.address, c.zip, c.town,";
521 $sql .= " c.fk_pays as country_id,";
522 $sql .= " c.fk_departement as state_id,";
523 $sql .= " c.birthday,";
524 $sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
525 $sql .= " co.label as country, co.code as country_code,";
526 $sql .= " d.nom as state, d.code_departement as state_code,";
527 $sql .= " u.rowid as user_id, u.login as user_login,";
528 $sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
529 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
530 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
531 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
532 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
533 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
534 $sql .= " WHERE c.fk_soc = ".((int) $idthirdparty);
535
536 $resql = $db->query($sql);
537 if ($resql) {
538 $linescontact = array();
539 $num = $db->num_rows($resql);
540 $i = 0;
541 while ($i < $num) {
542 // En attendant remplissage par boucle
543 $obj = $db->fetch_object($resql);
544
545 $contact = new Contact($db);
546 $contact->fetch($obj->rowid);
547
548 // Now define invoice
549 $linescontact[] = array(
550 'id' => $contact->id,
551 'ref' => $contact->ref,
552 'civility_id' => $contact->civility_id ? $contact->civility_id : '',
553 'lastname' => $contact->lastname ? $contact->lastname : '',
554 'firstname' => $contact->firstname ? $contact->firstname : '',
555 'address' => $contact->address ? $contact->address : '',
556 'zip' => $contact->zip ? $contact->zip : '',
557 'town' => $contact->town ? $contact->town : '',
558
559 'state_id' => $contact->state_id ? $contact->state_id : '',
560 'state_code' => $contact->state_code ? $contact->state_code : '',
561 'state' => $contact->state ? $contact->state : '',
562
563 'country_id' => $contact->country_id ? $contact->country_id : '',
564 'country_code' => $contact->country_code ? $contact->country_code : '',
565 'country' => $contact->country ? $contact->country : '',
566
567 'socid' => $contact->socid ? $contact->socid : '',
568 'socname' => $contact->socname ? $contact->socname : '',
569 'poste' => $contact->poste ? $contact->poste : '',
570
571 'phone_pro' => $contact->phone_pro ? $contact->phone_pro : '',
572 'fax' => $contact->fax ? $contact->fax : '',
573 'phone_perso' => $contact->phone_perso ? $contact->phone_perso : '',
574 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile : '',
575
576 'email' => $contact->email ? $contact->email : '',
577 'priv' => $contact->priv ? $contact->priv : '',
578 'mail' => $contact->mail ? $contact->mail : '',
579
580 'birthday' => $contact->birthday ? $contact->birthday : '',
581 'default_lang' => $contact->default_lang ? $contact->default_lang : '',
582 'note' => $contact->note ? $contact->note : '',
583 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation : '',
584 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat : '',
585 'ref_commande' => $contact->ref_commande ? $contact->ref_commande : '',
586 'ref_propal' => $contact->ref_propal ? $contact->ref_propal : '',
587 'user_id' => $contact->user_id ? $contact->user_id : '',
588 'user_login' => $contact->user_login ? $contact->user_login : '',
589 'status' => $contact->statut ? $contact->statut : ''
590 );
591
592 $i++;
593 }
594
595 $objectresp = array(
596 'result' => array('result_code' => 'OK', 'result_label' => ''),
597 'contacts' => $linescontact
598
599 );
600 } else {
601 $error++;
602 $errorcode = $db->lasterrno();
603 $errorlabel = $db->lasterror();
604 }
605 }
606
607 if ($error) {
608 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
609 }
610
611 return $objectresp;
612}
613
614
622function updateContact($authentication, $contact)
623{
624 global $db, $conf;
625
626 $now = dol_now();
627
628 dol_syslog("Function: updateContact login=".$authentication['login']);
629
630 if ($authentication['entity']) {
631 $conf->entity = $authentication['entity'];
632 }
633
634 // Init and check authentication
635 $objectresp = array();
636 $errorcode = '';
637 $errorlabel = '';
638 $error = 0;
639 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
640 // Check parameters
641 if (empty($contact['id']) && empty($contact['ref_ext'])) {
642 $error++;
643 $errorcode = 'KO';
644 $errorlabel = "Contact id or ref_ext is mandatory.";
645 }
646 // Check parameters
647 if (!$error && ($contact['id'] && $contact['ref_ext'])) {
648 $error++;
649 $errorcode = 'BAD_PARAMETERS';
650 $errorlabel = "Parameter id and ref_ext can't be all provided. You must choose one of them.";
651 }
652
653 if (!$error) {
654 $objectfound = false;
655
656 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
657
658 $object = new Contact($db);
659 $result = $object->fetch($contact['id'], null, $contact['ref_ext']);
660
661 if (!empty($object->id)) {
662 $objectfound = true;
663
664 $object->ref_ext = $contact['ref_ext'];
665
666 $object->firstname = $contact['firstname'];
667 $object->lastname = $contact['lastname'];
668
669 $object->address = $contact['address'];
670 $object->zip = $contact['zip'];
671 $object->town = $contact['town'];
672
673 $object->country_id = $contact['country_id'];
674 if ($contact['country_code']) {
675 $object->country_id = getCountry($contact['country_code'], 3);
676 }
677 $object->province_id = $contact['province_id'];
678
679
680 $object->phone_pro = $contact['phone_pro'];
681 $object->phone_perso = $contact['phone_perso'];
682 $object->phone_mobile = $contact['phone_mobile'];
683 $object->fax = $contact['fax'];
684 $object->email = $contact['email'];
685
686 $object->civility_id = $contact['civility_id'];
687 $object->poste = $contact['poste'];
688
689 $object->statut = $contact['status'];
690
691 $elementtype = 'socpeople';
692
693 //Retrieve all extrafield for contact
694 // fetch optionals attributes and labels
695 $extrafields = new ExtraFields($db);
696 $extrafields->fetch_name_optionals_label($elementtype, true);
697 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
698 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
699 $key = 'options_'.$key;
700 $object->array_options[$key] = $contact[$key];
701 }
702 }
703
704 $db->begin();
705
706 $result = $object->update($contact['id'], $fuser);
707 if ($result <= 0) {
708 $error++;
709 }
710 }
711 '@phan-var-force array{id:string} $contact';
712
713 if ((!$error) && ($objectfound)) {
714 $db->commit();
715 $objectresp = array(
716 'result' => array('result_code' => 'OK', 'result_label' => ''),
717 'id' => $object->id
718 );
719 } elseif ($objectfound) {
720 $db->rollback();
721 $error++;
722 $errorcode = 'KO';
723 $errorlabel = $object->error;
724 } else {
725 $error++;
726 $errorcode = 'NOT_FOUND';
727 $errorlabel = 'Contact id='.$contact['id'].' cannot be found';
728 }
729 }
730
731 if ($error) {
732 $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
733 }
734
735 return $objectresp;
736}
737
738// Return the results.
739$server->service(file_get_contents("php://input"));
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.
dol_now($mode='auto')
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:36