dolibarr 19.0.3
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 (!getDolGlobalString('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 = '';
279 $errorlabel = '';
280 $error = 0;
281 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
282 // Check parameters
283 if (!$error && ($id && $ref_ext)) {
284 $error++;
285 $errorcode = 'BAD_PARAMETERS';
286 $errorlabel = "Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
287 }
288
289 if (!$error) {
290 $fuser->getrights();
291
292 $contact = new Contact($db);
293 $result = $contact->fetch($id, 0, $ref_ext);
294 if ($result > 0) {
295 // Only internal user who have contact read permission
296 // Or for external user who have contact read permission, with restrict on socid
297 if ($fuser->hasRight('societe', 'contact', 'lire') && !$fuser->socid
298 || ($fuser->hasRight('societe', 'contact', 'lire') && ($fuser->socid == $contact->socid))
299 ) {
300 $contact_result_fields = array(
301 'id' => $contact->id,
302 'ref_ext' => $contact->ref_ext,
303 'lastname' => $contact->lastname,
304 'firstname' => $contact->firstname,
305 'address' => $contact->address,
306 'zip' => $contact->zip,
307 'town' => $contact->town,
308 'state_id' => $contact->state_id,
309 'state_code' => $contact->state_code,
310 'state' => $contact->state,
311 'country_id' => $contact->country_id,
312 'country_code' => $contact->country_code,
313 'country' => $contact->country,
314 'socid' => $contact->socid,
315 'status' => $contact->statut,
316 'phone_pro' => $contact->phone_pro,
317 'fax' => $contact->fax,
318 'phone_perso' => $contact->phone_perso,
319 'phone_mobile' => $contact->phone_mobile,
320 'code' => $contact->code,
321 'email' => $contact->email,
322 'birthday' => $contact->birthday,
323 'default_lang' => $contact->default_lang,
324 'note' => $contact->note,
325 'ref_facturation' => $contact->ref_facturation,
326 'ref_contrat' => $contact->ref_contrat,
327 'ref_commande' => $contact->ref_commande,
328 'ref_propal' => $contact->ref_propal,
329 'user_id' => $contact->user_id,
330 'user_login' => $contact->user_login,
331 'civility_id' => $contact->civility_id,
332 'poste' => $contact->poste
333 );
334
335 $elementtype = 'socpeople';
336
337 //Retrieve all extrafield for thirdsparty
338 // fetch optionals attributes and labels
339 $extrafields = new ExtraFields($db);
340 $extrafields->fetch_name_optionals_label($elementtype, true);
341 //Get extrafield values
342 $contact->fetch_optionals();
343
344 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
345 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
346 $contact_result_fields = array_merge($contact_result_fields, array('options_'.$key => $contact->array_options['options_'.$key]));
347 }
348 }
349
350 // Create
351 $objectresp = array(
352 'result'=>array('result_code'=>'OK', 'result_label'=>''),
353 'contact'=>$contact_result_fields
354 );
355 } else {
356 $error++;
357 $errorcode = 'PERMISSION_DENIED';
358 $errorlabel = 'User does not have permission for this request';
359 }
360 } else {
361 $error++;
362 $errorcode = 'NOT_FOUND';
363 $errorlabel = 'Object not found for id='.$id.' nor ref_ext='.$ref_ext;
364 }
365 }
366
367 if ($error) {
368 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
369 }
370
371 return $objectresp;
372}
373
374
382function createContact($authentication, $contact)
383{
384 global $db, $conf, $langs;
385
386 $now = dol_now();
387
388 dol_syslog("Function: createContact login=".$authentication['login']);
389
390 if ($authentication['entity']) {
391 $conf->entity = $authentication['entity'];
392 }
393
394 // Init and check authentication
395 $objectresp = array();
396 $errorcode = '';
397 $errorlabel = '';
398 $error = 0;
399 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
400 // Check parameters
401 if (empty($contact['lastname'])) {
402 $error++;
403 $errorcode = 'KO';
404 $errorlabel = "Name is mandatory.";
405 }
406
407 if (!$error) {
408 $newobject = new Contact($db);
409
410 $newobject->id = $contact['id'];
411 $newobject->ref_ext = $contact['ref_ext'];
412 $newobject->civility_id = $contact['civility_id'];
413 $newobject->lastname = $contact['lastname'];
414 $newobject->firstname = $contact['firstname'];
415 $newobject->address = $contact['address'];
416 $newobject->zip = $contact['zip'];
417 $newobject->town = $contact['town'];
418 $newobject->state_id = $contact['state_id'];
419 $newobject->state_code = $contact['state_code'];
420 $newobject->state = $contact['state'];
421 $newobject->country_id = $contact['country_id'];
422 $newobject->country_code = $contact['country_code'];
423 $newobject->country = $contact['country'];
424 $newobject->socid = $contact['socid'];
425 $newobject->statut = $contact['status'];
426 $newobject->phone_pro = $contact['phone_pro'];
427 $newobject->fax = $contact['fax'];
428 $newobject->phone_perso = $contact['phone_perso'];
429 $newobject->phone_mobile = $contact['phone_mobile'];
430 $newobject->code = $contact['code'];
431 $newobject->email = $contact['email'];
432 $newobject->birthday = $contact['birthday'];
433 $newobject->default_lang = $contact['default_lang'];
434 $newobject->note = $contact['note'];
435 $newobject->ref_facturation = $contact['ref_facturation'];
436 $newobject->ref_contrat = $contact['ref_contrat'];
437 $newobject->ref_commande = $contact['ref_commande'];
438 $newobject->ref_propal = $contact['ref_propal'];
439 $newobject->user_id = $contact['user_id'];
440 $newobject->user_login = $contact['user_login'];
441 $newobject->poste = $contact['poste'];
442
443 $elementtype = 'socpeople';
444
445 //Retrieve all extrafield for thirdsparty
446 // fetch optionals attributes and labels
447 $extrafields = new ExtraFields($db);
448 $extrafields->fetch_name_optionals_label($elementtype, true);
449 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
450 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
451 $key = 'options_'.$key;
452 $newobject->array_options[$key] = $contact[$key];
453 }
454 }
455
456
457 //...
458
459 $db->begin();
460
461 $result = $newobject->create($fuser);
462 if ($result <= 0) {
463 $error++;
464 }
465
466 if (!$error) {
467 $db->commit();
468 $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''), 'id'=>$newobject->id, 'ref'=>$newobject->ref);
469 } else {
470 $db->rollback();
471 $error++;
472 $errorcode = 'KO';
473 $errorlabel = $newobject->error;
474 }
475 }
476
477 if ($error) {
478 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
479 }
480
481 return $objectresp;
482}
483
491function getContactsForThirdParty($authentication, $idthirdparty)
492{
493 global $db, $conf, $langs;
494
495 dol_syslog("Function: getContactsForThirdParty login=".$authentication['login']." idthirdparty=".$idthirdparty);
496
497 if ($authentication['entity']) {
498 $conf->entity = $authentication['entity'];
499 }
500
501 // Init and check authentication
502 $objectresp = array();
503 $errorcode = '';
504 $errorlabel = '';
505 $error = 0;
506 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
507 // Check parameters
508 if (!$error && empty($idthirdparty)) {
509 $error++;
510 $errorcode = 'BAD_PARAMETERS';
511 $errorlabel = 'Parameter id is not provided';
512 }
513
514 if (!$error) {
515 $linesinvoice = array();
516
517 $sql = "SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
518 $sql .= " c.address, c.zip, c.town,";
519 $sql .= " c.fk_pays as country_id,";
520 $sql .= " c.fk_departement as state_id,";
521 $sql .= " c.birthday,";
522 $sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
523 $sql .= " co.label as country, co.code as country_code,";
524 $sql .= " d.nom as state, d.code_departement as state_code,";
525 $sql .= " u.rowid as user_id, u.login as user_login,";
526 $sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
527 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
528 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
529 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
530 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
531 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
532 $sql .= " WHERE c.fk_soc = ".((int) $idthirdparty);
533
534 $resql = $db->query($sql);
535 if ($resql) {
536 $num = $db->num_rows($resql);
537 $i = 0;
538 while ($i < $num) {
539 // En attendant remplissage par boucle
540 $obj = $db->fetch_object($resql);
541
542 $contact = new Contact($db);
543 $contact->fetch($obj->rowid);
544
545 // Now define invoice
546 $linescontact[] = array(
547 'id' => $contact->id,
548 'ref' => $contact->ref,
549 'civility_id' => $contact->civility_id ? $contact->civility_id : '',
550 'lastname' => $contact->lastname ? $contact->lastname : '',
551 'firstname' => $contact->firstname ? $contact->firstname : '',
552 'address' => $contact->address ? $contact->address : '',
553 'zip' => $contact->zip ? $contact->zip : '',
554 'town' => $contact->town ? $contact->town : '',
555
556 'state_id' => $contact->state_id ? $contact->state_id : '',
557 'state_code' => $contact->state_code ? $contact->state_code : '',
558 'state' => $contact->state ? $contact->state : '',
559
560 'country_id' => $contact->country_id ? $contact->country_id : '',
561 'country_code' => $contact->country_code ? $contact->country_code : '',
562 'country' => $contact->country ? $contact->country : '',
563
564 'socid' => $contact->socid ? $contact->socid : '',
565 'socname' => $contact->socname ? $contact->socname : '',
566 'poste' => $contact->poste ? $contact->poste : '',
567
568 'phone_pro' => $contact->phone_pro ? $contact->phone_pro : '',
569 'fax' => $contact->fax ? $contact->fax : '',
570 'phone_perso' => $contact->phone_perso ? $contact->phone_perso : '',
571 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile : '',
572
573 'email' => $contact->email ? $contact->email : '',
574 'priv' => $contact->priv ? $contact->priv : '',
575 'mail' => $contact->mail ? $contact->mail : '',
576
577 'birthday' => $contact->birthday ? $contact->birthday : '',
578 'default_lang' => $contact->default_lang ? $contact->default_lang : '',
579 'note' => $contact->note ? $contact->note : '',
580 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation : '',
581 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat : '',
582 'ref_commande' => $contact->ref_commande ? $contact->ref_commande : '',
583 'ref_propal' => $contact->ref_propal ? $contact->ref_propal : '',
584 'user_id' => $contact->user_id ? $contact->user_id : '',
585 'user_login' => $contact->user_login ? $contact->user_login : '',
586 'status' => $contact->statut ? $contact->statut : ''
587 );
588
589 $i++;
590 }
591
592 $objectresp = array(
593 'result'=>array('result_code'=>'OK', 'result_label'=>''),
594 'contacts'=>$linescontact
595
596 );
597 } else {
598 $error++;
599 $errorcode = $db->lasterrno();
600 $errorlabel = $db->lasterror();
601 }
602 }
603
604 if ($error) {
605 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
606 }
607
608 return $objectresp;
609}
610
611
619function updateContact($authentication, $contact)
620{
621 global $db, $conf;
622
623 $now = dol_now();
624
625 dol_syslog("Function: updateContact login=".$authentication['login']);
626
627 if ($authentication['entity']) {
628 $conf->entity = $authentication['entity'];
629 }
630
631 // Init and check authentication
632 $objectresp = array();
633 $errorcode = '';
634 $errorlabel = '';
635 $error = 0;
636 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
637 // Check parameters
638 if (empty($contact['id']) && empty($contact['ref_ext'])) {
639 $error++;
640 $errorcode = 'KO';
641 $errorlabel = "Contact id or ref_ext is mandatory.";
642 }
643 // Check parameters
644 if (!$error && ($contact['id'] && $contact['ref_ext'])) {
645 $error++;
646 $errorcode = 'BAD_PARAMETERS';
647 $errorlabel = "Parameter id and ref_ext can't be all provided. You must choose one of them.";
648 }
649
650 if (!$error) {
651 $objectfound = false;
652
653 include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
654
655 $object = new Contact($db);
656 $result = $object->fetch($contact['id'], 0, $contact['ref_ext']);
657
658 if (!empty($object->id)) {
659 $objectfound = true;
660
661 $object->ref_ext = $contact['ref_ext'];
662
663 $object->firstname = $contact['firstname'];
664 $object->lastname = $contact['lastname'];
665
666 $object->address = $contact['address'];
667 $object->zip = $contact['zip'];
668 $object->town = $contact['town'];
669
670 $object->country_id = $contact['country_id'];
671 if ($contact['country_code']) {
672 $object->country_id = getCountry($contact['country_code'], 3);
673 }
674 $object->province_id = $contact['province_id'];
675
676
677 $object->phone_pro = $contact['phone_pro'];
678 $object->phone_perso = $contact['phone_perso'];
679 $object->phone_mobile = $contact['phone_mobile'];
680 $object->fax = $contact['fax'];
681 $object->email = $contact['email'];
682
683 $object->civility_id = $contact['civility_id'];
684 $object->poste = $contact['poste'];
685
686 $object->statut = $contact['status'];
687
688 $elementtype = 'socpeople';
689
690 //Retrieve all extrafield for contact
691 // fetch optionals attributes and labels
692 $extrafields = new ExtraFields($db);
693 $extrafields->fetch_name_optionals_label($elementtype, true);
694 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
695 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
696 $key = 'options_'.$key;
697 $object->array_options[$key] = $contact[$key];
698 }
699 }
700
701 $db->begin();
702
703 $result = $object->update($contact['id'], $fuser);
704 if ($result <= 0) {
705 $error++;
706 }
707 }
708
709 if ((!$error) && ($objectfound)) {
710 $db->commit();
711 $objectresp = array(
712 'result'=>array('result_code'=>'OK', 'result_label'=>''),
713 'id'=>$object->id
714 );
715 } elseif ($objectfound) {
716 $db->rollback();
717 $error++;
718 $errorcode = 'KO';
719 $errorlabel = $object->error;
720 } else {
721 $error++;
722 $errorcode = 'NOT_FOUND';
723 $errorlabel = 'Contact id='.$contact['id'].' cannot be found';
724 }
725 }
726
727 if ($error) {
728 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
729 }
730
731 return $objectresp;
732}
733
734// Return the results.
735$server->service(file_get_contents("php://input"));
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.
getDolGlobalString($key, $default='')
Return 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.
Contact()
Old copy.
Definition index.php:572
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition ws.lib.php:35