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