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