26if (!defined(
'NOCSRFCHECK')) {
27 define(
'NOCSRFCHECK',
'1');
29if (!defined(
'NOTOKENRENEWAL')) {
30 define(
'NOTOKENRENEWAL',
'1');
32if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38if (!defined(
'NOREQUIREAJAX')) {
39 define(
'NOREQUIREAJAX',
'1');
41if (!defined(
"NOLOGIN")) {
42 define(
"NOLOGIN",
'1');
44if (!defined(
"NOSESSION")) {
45 define(
"NOSESSION",
'1');
48require
'../main.inc.php';
49require_once NUSOAP_PATH.
'/nusoap.php';
50require_once DOL_DOCUMENT_ROOT.
"/core/lib/ws.lib.php";
51require_once DOL_DOCUMENT_ROOT.
"/contact/class/contact.class.php";
52require_once DOL_DOCUMENT_ROOT.
"/core/class/extrafields.class.php";
59dol_syslog(
"Call Contact webservices interfaces");
63 $langs->load(
"admin");
64 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
65 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
66 print $langs->trans(
"ToActivateModule");
71$server =
new nusoap_server();
72$server->soap_defencoding =
'UTF-8';
73$server->decode_utf8 =
false;
74$ns =
'http://www.dolibarr.org/ns/';
75$server->configureWSDL(
'WebServicesDolibarrContact', $ns);
77$server->wsdl->schemaTargetNamespace = $ns;
81$server->wsdl->addComplexType(
88 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
89 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
90 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
91 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
92 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
97$server->wsdl->addComplexType(
104 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
105 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
109$contact_fields = array(
110 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
111 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
112 'lastname' => array(
'name' =>
'lastname',
'type' =>
'xsd:string'),
113 'firstname' => array(
'name' =>
'firstname',
'type' =>
'xsd:string'),
114 'address' => array(
'name' =>
'address',
'type' =>
'xsd:string'),
115 'zip' => array(
'name' =>
'zip',
'type' =>
'xsd:string'),
116 'town' => array(
'name' =>
'town',
'type' =>
'xsd:string'),
117 'state_id' => array(
'name' =>
'state_id',
'type' =>
'xsd:string'),
118 'state_code' => array(
'name' =>
'state_code',
'type' =>
'xsd:string'),
119 'state' => array(
'name' =>
'state',
'type' =>
'xsd:string'),
120 'country_id' => array(
'name' =>
'country_id',
'type' =>
'xsd:string'),
121 'country_code' => array(
'name' =>
'country_code',
'type' =>
'xsd:string'),
122 'country' => array(
'name' =>
'country',
'type' =>
'xsd:string'),
123 'socid' => array(
'name' =>
'socid',
'type' =>
'xsd:string'),
124 'status' => array(
'name' =>
'status',
'type' =>
'xsd:string'),
125 'phone_pro' => array(
'name' =>
'phone_pro',
'type' =>
'xsd:string'),
126 'fax' => array(
'name' =>
'fax',
'type' =>
'xsd:string'),
127 'phone_perso' => array(
'name' =>
'phone_perso',
'type' =>
'xsd:string'),
128 'phone_mobile' => array(
'name' =>
'phone_mobile',
'type' =>
'xsd:string'),
129 'code' => array(
'name' =>
'code',
'type' =>
'xsd:string'),
130 'email' => array(
'name' =>
'email',
'type' =>
'xsd:string'),
131 'birthday' => array(
'name' =>
'birthday',
'type' =>
'xsd:string'),
132 'default_lang' => array(
'name' =>
'default_lang',
'type' =>
'xsd:string'),
133 'note' => array(
'name' =>
'note',
'type' =>
'xsd:string'),
134 'ref_facturation' => array(
'name' =>
'ref_facturation',
'type' =>
'xsd:string'),
135 'ref_contrat' => array(
'name' =>
'ref_contrat',
'type' =>
'xsd:string'),
136 'ref_commande' => array(
'name' =>
'ref_commande',
'type' =>
'xsd:string'),
137 'ref_propal' => array(
'name' =>
'ref_propal',
'type' =>
'xsd:string'),
138 'user_id' => array(
'name' =>
'user_id',
'type' =>
'xsd:string'),
139 'user_login' => array(
'name' =>
'user_login',
'type' =>
'xsd:string'),
140 'civility_id' => array(
'name' =>
'civility_id',
'type' =>
'xsd:string'),
141 'poste' => array(
'name' =>
'poste',
'type' =>
'xsd:string')
145$elementtype =
'socpeople';
151$extrafields->fetch_name_optionals_label($elementtype,
true);
152$extrafield_array =
null;
153if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype][
'count'] > 0) {
154 $extrafield_array = array();
156if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
157 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
158 $type = $extrafields->attributes[$elementtype][
'type'][$key];
159 if ($type ==
'date' || $type ==
'datetime') {
160 $type =
'xsd:dateTime';
162 $type =
'xsd:string';
165 $extrafield_array[
'options_'.$key] = array(
'name' =>
'options_'.$key,
'type' => $type);
168if (is_array($extrafield_array)) {
169 $contact_fields = array_merge($contact_fields, $extrafield_array);
173$server->wsdl->addComplexType(
182$server->wsdl->addComplexType(
191 'type' =>
'tns:contact',
193 'maxOccurs' =>
'unbounded'
205$styleuse =
'encoded';
213 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
215 array(
'result' =>
'tns:result',
'contact' =>
'tns:contact'),
220 'WS to get a contact'
227 array(
'authentication' =>
'tns:authentication',
'contact' =>
'tns:contact'),
229 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
231 $ns.
'#createContact',
234 'WS to create a contact'
238 'getContactsForThirdParty',
240 array(
'authentication' =>
'tns:authentication',
'idthirdparty' =>
'xsd:string'),
242 array(
'result' =>
'tns:result',
'contacts' =>
'tns:ContactsArray2'),
244 $ns.
'#getContactsForThirdParty',
247 'WS to get all contacts of a third party'
254 array(
'authentication' =>
'tns:authentication',
'contact' =>
'tns:contact'),
256 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
258 $ns.
'#updateContact',
261 'WS to update a contact'
275 global $db,
$conf, $langs;
277 dol_syslog(
"Function: getContact login=".$authentication[
'login'].
" id=".
$id.
" ref_ext=".$ref_ext);
279 if ($authentication[
'entity']) {
280 $conf->entity = $authentication[
'entity'];
284 $objectresp = array();
290 if (!$error && (
$id && $ref_ext)) {
292 $errorcode =
'BAD_PARAMETERS';
293 $errorlabel =
"Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
297 $fuser->loadRights();
300 $result = $contact->fetch(
$id,
null, $ref_ext);
304 if ($fuser->hasRight(
'societe',
'contact',
'lire') && !$fuser->socid
305 || ($fuser->hasRight(
'societe',
'contact',
'lire') && ($fuser->socid == $contact->socid))
307 $contact_result_fields = array(
308 'id' => $contact->id,
309 'ref_ext' => $contact->ref_ext,
310 'lastname' => $contact->lastname,
311 'firstname' => $contact->firstname,
312 'address' => $contact->address,
313 'zip' => $contact->zip,
314 'town' => $contact->town,
315 'state_id' => $contact->state_id,
316 'state_code' => $contact->state_code,
317 'state' => $contact->state,
318 'country_id' => $contact->country_id,
319 'country_code' => $contact->country_code,
320 'country' => $contact->country,
321 'socid' => $contact->socid,
322 'status' => $contact->status,
323 'phone_pro' => $contact->phone_pro,
324 'fax' => $contact->fax,
325 'phone_perso' => $contact->phone_perso,
326 'phone_mobile' => $contact->phone_mobile,
327 'code' => $contact->code,
328 'email' => $contact->email,
329 'birthday' => $contact->birthday,
330 'default_lang' => $contact->default_lang,
331 'note' => $contact->note,
332 'ref_facturation' => $contact->ref_facturation,
333 'ref_contrat' => $contact->ref_contrat,
334 'ref_commande' => $contact->ref_commande,
335 'ref_propal' => $contact->ref_propal,
336 'user_id' => $contact->user_id,
337 'user_login' => $contact->user_login,
338 'civility_id' => $contact->civility_id,
339 'poste' => $contact->poste
342 $elementtype =
'socpeople';
347 $extrafields->fetch_name_optionals_label($elementtype,
true);
349 $contact->fetch_optionals();
351 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
352 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
353 $contact_result_fields = array_merge($contact_result_fields, array(
'options_'.$key => $contact->array_options[
'options_'.$key]));
359 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
360 'contact' => $contact_result_fields
364 $errorcode =
'PERMISSION_DENIED';
365 $errorlabel =
'User does not have permission for this request';
369 $errorcode =
'NOT_FOUND';
370 $errorlabel =
'Object not found for id='.$id.
' nor ref_ext='.$ref_ext;
375 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
395 dol_syslog(
"Function: createContact login=".$authentication[
'login']);
397 if ($authentication[
'entity']) {
398 $conf->entity = $authentication[
'entity'];
402 $objectresp = array();
408 if (empty($contact[
'lastname'])) {
411 $errorlabel =
"Name is mandatory.";
417 $newobject->id = (int) $contact[
'id'];
418 $newobject->ref_ext = $contact[
'ref_ext'];
419 $newobject->civility_id = $contact[
'civility_id'];
420 $newobject->lastname = $contact[
'lastname'];
421 $newobject->firstname = $contact[
'firstname'];
422 $newobject->address = $contact[
'address'];
423 $newobject->zip = $contact[
'zip'];
424 $newobject->town = $contact[
'town'];
425 $newobject->state_id = (int) $contact[
'state_id'];
426 $newobject->state_code = $contact[
'state_code'];
427 $newobject->state = $contact[
'state'];
428 $newobject->country_id = (int) $contact[
'country_id'];
429 $newobject->country_code = $contact[
'country_code'];
430 $newobject->country = $contact[
'country'];
431 $newobject->socid = (int) $contact[
'socid'];
432 $newobject->status = (int) $contact[
'status'];
433 $newobject->phone_pro = $contact[
'phone_pro'];
434 $newobject->fax = $contact[
'fax'];
435 $newobject->phone_perso = $contact[
'phone_perso'];
436 $newobject->phone_mobile = $contact[
'phone_mobile'];
437 $newobject->code = $contact[
'code'];
438 $newobject->email = $contact[
'email'];
439 $newobject->birthday = $contact[
'birthday'];
440 $newobject->default_lang = $contact[
'default_lang'];
441 $newobject->note_private = $contact[
'note'];
442 $newobject->ref_facturation = (int) $contact[
'ref_facturation'];
443 $newobject->ref_contrat = (int) $contact[
'ref_contrat'];
444 $newobject->ref_commande = (int) $contact[
'ref_commande'];
445 $newobject->ref_propal = (int) $contact[
'ref_propal'];
446 $newobject->user_id = (int) $contact[
'user_id'];
447 $newobject->user_login = $contact[
'user_login'];
448 $newobject->poste = $contact[
'poste'];
450 $elementtype =
'socpeople';
455 $extrafields->fetch_name_optionals_label($elementtype,
true);
456 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
457 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
458 $key =
'options_'.$key;
459 if (isset($contact[$key])) {
460 $newobject->array_options[$key] = $contact[$key];
470 $result = $newobject->create($fuser);
477 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref);
482 $errorlabel = $newobject->error;
487 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
504 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
506 if ($authentication[
'entity']) {
507 $conf->entity = $authentication[
'entity'];
511 $objectresp = array();
517 if (!$error && empty($idthirdparty)) {
519 $errorcode =
'BAD_PARAMETERS';
520 $errorlabel =
'Parameter id is not provided';
524 $linesinvoice = array();
526 $sql =
"SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
527 $sql .=
" c.address, c.zip, c.town,";
528 $sql .=
" c.fk_pays as country_id,";
529 $sql .=
" c.fk_departement as state_id,";
530 $sql .=
" c.birthday,";
531 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
532 $sql .=
" co.label as country, co.code as country_code,";
533 $sql .=
" d.nom as state, d.code_departement as state_code,";
534 $sql .=
" u.rowid as user_id, u.login as user_login,";
535 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
536 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
537 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
538 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
539 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
540 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
541 $sql .=
" WHERE c.fk_soc = ".((int) $idthirdparty);
543 $resql = $db->query($sql);
545 $linescontact = array();
546 $num = $db->num_rows($resql);
550 $obj = $db->fetch_object($resql);
553 $contact->fetch($obj->rowid);
556 $linescontact[] = array(
557 'id' => $contact->id,
558 'ref' => $contact->ref,
559 'civility_id' => $contact->civility_id ? $contact->civility_id :
'',
560 'lastname' => $contact->lastname ? $contact->lastname :
'',
561 'firstname' => $contact->firstname ? $contact->firstname :
'',
562 'address' => $contact->address ? $contact->address :
'',
563 'zip' => $contact->zip ? $contact->zip :
'',
564 'town' => $contact->town ? $contact->town :
'',
566 'state_id' => $contact->state_id ? $contact->state_id :
'',
567 'state_code' => $contact->state_code ? $contact->state_code :
'',
568 'state' => $contact->state ? $contact->state :
'',
570 'country_id' => $contact->country_id ? $contact->country_id :
'',
571 'country_code' => $contact->country_code ? $contact->country_code :
'',
572 'country' => $contact->country ? $contact->country :
'',
574 'socid' => $contact->socid ? $contact->socid :
'',
575 'socname' => $contact->socname ? $contact->socname :
'',
576 'poste' => $contact->poste ? $contact->poste :
'',
578 'phone_pro' => $contact->phone_pro ? $contact->phone_pro :
'',
579 'fax' => $contact->fax ? $contact->fax :
'',
580 'phone_perso' => $contact->phone_perso ? $contact->phone_perso :
'',
581 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile :
'',
583 'email' => $contact->email ? $contact->email :
'',
584 'priv' => $contact->priv ? $contact->priv :
'',
585 'mail' => $contact->mail ? $contact->mail :
'',
587 'birthday' => $contact->birthday ? $contact->birthday :
'',
588 'default_lang' => $contact->default_lang ? $contact->default_lang :
'',
589 'note' => $contact->note ? $contact->note :
'',
590 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation :
'',
591 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat :
'',
592 'ref_commande' => $contact->ref_commande ? $contact->ref_commande :
'',
593 'ref_propal' => $contact->ref_propal ? $contact->ref_propal :
'',
594 'user_id' => $contact->user_id ? $contact->user_id :
'',
595 'user_login' => $contact->user_login ? $contact->user_login :
'',
596 'status' => $contact->status ? $contact->status :
''
603 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
604 'contacts' => $linescontact
609 $errorcode = $db->lasterrno();
610 $errorlabel = $db->lasterror();
615 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
635 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
637 if ($authentication[
'entity']) {
638 $conf->entity = $authentication[
'entity'];
642 $objectresp = array();
648 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
651 $errorlabel =
"Contact id or ref_ext is mandatory.";
654 if (!$error && ($contact[
'id'] && $contact[
'ref_ext'])) {
656 $errorcode =
'BAD_PARAMETERS';
657 $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
661 $objectfound =
false;
663 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
666 $result =
$object->fetch((
int) $contact[
'id'],
null, $contact[
'ref_ext']);
671 $object->ref_ext = $contact[
'ref_ext'];
673 $object->firstname = $contact[
'firstname'];
674 $object->lastname = $contact[
'lastname'];
676 $object->address = $contact[
'address'];
677 $object->zip = $contact[
'zip'];
678 $object->town = $contact[
'town'];
680 $object->country_id = (int) $contact[
'country_id'];
681 if ($contact[
'country_code']) {
684 $object->province_id = isset($contact[
'province_id']) ? $contact[
'province_id'] :
null;
687 $object->phone_pro = $contact[
'phone_pro'];
688 $object->phone_perso = $contact[
'phone_perso'];
689 $object->phone_mobile = $contact[
'phone_mobile'];
690 $object->fax = $contact[
'fax'];
691 $object->email = $contact[
'email'];
693 $object->civility_id = $contact[
'civility_id'];
694 $object->poste = $contact[
'poste'];
696 $object->statut = (int) $contact[
'status'];
698 $elementtype =
'socpeople';
703 $extrafields->fetch_name_optionals_label($elementtype,
true);
704 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
705 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
706 $key =
'options_'.$key;
707 if (isset($contact[$key])) {
708 $object->array_options[$key] = $contact[$key];
715 $result =
$object->update((
int) $contact[
'id'], $fuser);
720 '@phan-var-force array{id:string} $contact';
722 if ((!$error) && ($objectfound)) {
725 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
728 } elseif ($objectfound) {
735 $errorcode =
'NOT_FOUND';
736 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
741 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
748$server->service(file_get_contents(
"php://input"));
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_now($mode='gmt')
Return date for now.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.