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