24 if (!defined(
"NOCSRFCHECK")) {
25 define(
"NOCSRFCHECK",
'1');
28 require
"../master.inc.php";
29 require_once NUSOAP_PATH.
'/nusoap.php';
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";
35 dol_syslog(
"Call Contact webservices interfaces");
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");
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;
56 $server->wsdl->addComplexType(
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'),
72 $server->wsdl->addComplexType(
79 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
80 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
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')
120 $elementtype =
'socpeople';
126 $extrafields->fetch_name_optionals_label($elementtype,
true);
127 $extrafield_array =
null;
128 if (is_array($extrafields) && count($extrafields) > 0) {
129 $extrafield_array = array();
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';
137 $type =
'xsd:string';
140 $extrafield_array[
'options_'.$key] = array(
'name'=>
'options_'.$key,
'type'=>$type);
143 if (is_array($extrafield_array)) {
144 $contact_fields = array_merge($contact_fields, $extrafield_array);
148 $server->wsdl->addComplexType(
157 $server->wsdl->addComplexType(
166 'type' =>
'tns:contact',
168 'maxOccurs' =>
'unbounded'
180 $styleuse =
'encoded';
188 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref_ext'=>
'xsd:string'),
190 array(
'result'=>
'tns:result',
'contact'=>
'tns:contact'),
195 'WS to get a contact'
202 array(
'authentication'=>
'tns:authentication',
'contact'=>
'tns:contact'),
204 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
206 $ns.
'#createContact',
209 'WS to create a contact'
213 'getContactsForThirdParty',
215 array(
'authentication'=>
'tns:authentication',
'idthirdparty'=>
'xsd:string'),
217 array(
'result'=>
'tns:result',
'contacts'=>
'tns:ContactsArray2'),
219 $ns.
'#getContactsForThirdParty',
222 'WS to get all contacts of a third party'
229 array(
'authentication'=>
'tns:authentication',
'contact'=>
'tns:contact'),
231 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
233 $ns.
'#updateContact',
236 'WS to update a contact'
250 global $db, $conf, $langs;
252 dol_syslog(
"Function: getContact login=".$authentication[
'login'].
" id=".$id.
" ref_ext=".$ref_ext);
254 if ($authentication[
'entity']) {
255 $conf->entity = $authentication[
'entity'];
259 $objectresp = array();
260 $errorcode =
''; $errorlabel =
'';
264 if (!$error && ($id && $ref_ext)) {
266 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
273 $result = $contact->fetch($id, 0, $ref_ext);
277 if ($fuser->rights->societe->contact->lire && !$fuser->socid
278 || ($fuser->rights->societe->contact->lire && ($fuser->socid == $contact->socid))
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
315 $elementtype =
'socpeople';
320 $extrafields->fetch_name_optionals_label($elementtype,
true);
322 $contact->fetch_optionals();
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]));
332 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
333 'contact'=>$contact_result_fields
337 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
341 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref_ext='.$ref_ext;
346 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
362 global $db, $conf, $langs;
366 dol_syslog(
"Function: createContact login=".$authentication[
'login']);
368 if ($authentication[
'entity']) {
369 $conf->entity = $authentication[
'entity'];
373 $objectresp = array();
374 $errorcode =
''; $errorlabel =
'';
378 if (empty($contact[
'lastname'])) {
379 $error++; $errorcode =
'KO'; $errorlabel =
"Name is mandatory.";
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'];
418 $elementtype =
'socpeople';
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];
436 $result = $newobject->create($fuser);
443 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
448 $errorlabel = $newobject->error;
453 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
468 global $db, $conf, $langs;
470 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
472 if ($authentication[
'entity']) {
473 $conf->entity = $authentication[
'entity'];
477 $objectresp = array();
478 $errorcode =
''; $errorlabel =
'';
482 if (!$error && empty($idthirdparty)) {
484 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
'Parameter id is not provided';
488 $linesinvoice = array();
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);
507 $resql = $db->query($sql);
509 $num = $db->num_rows(
$resql);
513 $obj = $db->fetch_object(
$resql);
516 $contact->fetch($obj->rowid);
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 :
'',
529 'state_id' => $contact->state_id ? $contact->state_id :
'',
530 'state_code' => $contact->state_code ? $contact->state_code :
'',
531 'state' => $contact->state ? $contact->state :
'',
533 'country_id' => $contact->country_id ? $contact->country_id :
'',
534 'country_code' => $contact->country_code ? $contact->country_code :
'',
535 'country' => $contact->country ? $contact->country :
'',
537 'socid' => $contact->socid ? $contact->socid :
'',
538 'socname' => $contact->socname ? $contact->socname :
'',
539 'poste' => $contact->poste ? $contact->poste :
'',
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 :
'',
546 'email' => $contact->email ? $contact->email :
'',
547 'priv' => $contact->priv ? $contact->priv :
'',
548 'mail' => $contact->mail ? $contact->mail :
'',
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 :
''
566 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
567 'contacts'=>$linescontact
572 $errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
577 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
593 global $db, $conf, $langs;
597 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
599 if ($authentication[
'entity']) {
600 $conf->entity = $authentication[
'entity'];
604 $objectresp = array();
605 $errorcode =
''; $errorlabel =
'';
609 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
610 $error++; $errorcode =
'KO'; $errorlabel =
"Contact id or ref_ext is mandatory.";
613 if (!$error && ($id && $ref_ext)) {
615 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
619 $objectfound =
false;
621 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
624 $result = $object->fetch($contact[
'id'], 0, $contact[
'ref_ext']);
626 if (!empty($object->id)) {
629 $object->ref_ext = $contact[
'ref_ext'];
631 $object->firstname = $contact[
'firstname'];
632 $object->lastname = $contact[
'lastname'];
634 $object->address = $contact[
'address'];
635 $object->zip = $contact[
'zip'];
636 $object->town = $contact[
'town'];
638 $object->country_id = $contact[
'country_id'];
639 if ($contact[
'country_code']) {
640 $object->country_id =
getCountry($contact[
'country_code'], 3);
642 $object->province_id = $contact[
'province_id'];
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'];
651 $object->civility_id = $contact[
'civility_id'];
652 $object->poste = $contact[
'poste'];
654 $object->statut = $contact[
'status'];
656 $elementtype =
'socpeople';
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];
671 $result = $object->update($contact[
'id'], $fuser);
677 if ((!$error) && ($objectfound)) {
680 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
683 } elseif ($objectfound) {
687 $errorlabel = $object->error;
690 $errorcode =
'NOT_FOUND';
691 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
696 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
703 $server->service(file_get_contents(
"php://input"));
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.