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 $newobject->array_options[$key] = $contact[$key];
468 $result = $newobject->create($fuser);
475 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref);
480 $errorlabel = $newobject->error;
485 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
502 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
504 if ($authentication[
'entity']) {
505 $conf->entity = $authentication[
'entity'];
509 $objectresp = array();
515 if (!$error && empty($idthirdparty)) {
517 $errorcode =
'BAD_PARAMETERS';
518 $errorlabel =
'Parameter id is not provided';
522 $linesinvoice = array();
524 $sql =
"SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
525 $sql .=
" c.address, c.zip, c.town,";
526 $sql .=
" c.fk_pays as country_id,";
527 $sql .=
" c.fk_departement as state_id,";
528 $sql .=
" c.birthday,";
529 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
530 $sql .=
" co.label as country, co.code as country_code,";
531 $sql .=
" d.nom as state, d.code_departement as state_code,";
532 $sql .=
" u.rowid as user_id, u.login as user_login,";
533 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
534 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
535 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
536 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
537 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
538 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
539 $sql .=
" WHERE c.fk_soc = ".((int) $idthirdparty);
541 $resql = $db->query($sql);
543 $linescontact = array();
544 $num = $db->num_rows($resql);
548 $obj = $db->fetch_object($resql);
551 $contact->fetch($obj->rowid);
554 $linescontact[] = array(
555 'id' => $contact->id,
556 'ref' => $contact->ref,
557 'civility_id' => $contact->civility_id ? $contact->civility_id :
'',
558 'lastname' => $contact->lastname ? $contact->lastname :
'',
559 'firstname' => $contact->firstname ? $contact->firstname :
'',
560 'address' => $contact->address ? $contact->address :
'',
561 'zip' => $contact->zip ? $contact->zip :
'',
562 'town' => $contact->town ? $contact->town :
'',
564 'state_id' => $contact->state_id ? $contact->state_id :
'',
565 'state_code' => $contact->state_code ? $contact->state_code :
'',
566 'state' => $contact->state ? $contact->state :
'',
568 'country_id' => $contact->country_id ? $contact->country_id :
'',
569 'country_code' => $contact->country_code ? $contact->country_code :
'',
570 'country' => $contact->country ? $contact->country :
'',
572 'socid' => $contact->socid ? $contact->socid :
'',
573 'socname' => $contact->socname ? $contact->socname :
'',
574 'poste' => $contact->poste ? $contact->poste :
'',
576 'phone_pro' => $contact->phone_pro ? $contact->phone_pro :
'',
577 'fax' => $contact->fax ? $contact->fax :
'',
578 'phone_perso' => $contact->phone_perso ? $contact->phone_perso :
'',
579 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile :
'',
581 'email' => $contact->email ? $contact->email :
'',
582 'priv' => $contact->priv ? $contact->priv :
'',
583 'mail' => $contact->mail ? $contact->mail :
'',
585 'birthday' => $contact->birthday ? $contact->birthday :
'',
586 'default_lang' => $contact->default_lang ? $contact->default_lang :
'',
587 'note' => $contact->note ? $contact->note :
'',
588 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation :
'',
589 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat :
'',
590 'ref_commande' => $contact->ref_commande ? $contact->ref_commande :
'',
591 'ref_propal' => $contact->ref_propal ? $contact->ref_propal :
'',
592 'user_id' => $contact->user_id ? $contact->user_id :
'',
593 'user_login' => $contact->user_login ? $contact->user_login :
'',
594 'status' => $contact->status ? $contact->status :
''
601 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
602 'contacts' => $linescontact
607 $errorcode = $db->lasterrno();
608 $errorlabel = $db->lasterror();
613 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
633 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
635 if ($authentication[
'entity']) {
636 $conf->entity = $authentication[
'entity'];
640 $objectresp = array();
646 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
649 $errorlabel =
"Contact id or ref_ext is mandatory.";
652 if (!$error && ($contact[
'id'] && $contact[
'ref_ext'])) {
654 $errorcode =
'BAD_PARAMETERS';
655 $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
659 $objectfound =
false;
661 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
664 $result =
$object->fetch((
int) $contact[
'id'],
null, $contact[
'ref_ext']);
669 $object->ref_ext = $contact[
'ref_ext'];
671 $object->firstname = $contact[
'firstname'];
672 $object->lastname = $contact[
'lastname'];
674 $object->address = $contact[
'address'];
675 $object->zip = $contact[
'zip'];
676 $object->town = $contact[
'town'];
678 $object->country_id = (int) $contact[
'country_id'];
679 if ($contact[
'country_code']) {
682 $object->province_id = isset($contact[
'province_id']) ? $contact[
'province_id'] :
null;
685 $object->phone_pro = $contact[
'phone_pro'];
686 $object->phone_perso = $contact[
'phone_perso'];
687 $object->phone_mobile = $contact[
'phone_mobile'];
688 $object->fax = $contact[
'fax'];
689 $object->email = $contact[
'email'];
691 $object->civility_id = $contact[
'civility_id'];
692 $object->poste = $contact[
'poste'];
694 $object->statut = (int) $contact[
'status'];
696 $elementtype =
'socpeople';
701 $extrafields->fetch_name_optionals_label($elementtype,
true);
702 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
703 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
704 $key =
'options_'.$key;
705 $object->array_options[$key] = $contact[$key];
711 $result =
$object->update((
int) $contact[
'id'], $fuser);
716 '@phan-var-force array{id:string} $contact';
718 if ((!$error) && ($objectfound)) {
721 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
724 } elseif ($objectfound) {
731 $errorcode =
'NOT_FOUND';
732 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
737 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
744$server->service(file_get_contents(
"php://input"));
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
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.