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