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";
55dol_syslog(
"Call Contact webservices interfaces");
59 $langs->load(
"admin");
60 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
61 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
62 print $langs->trans(
"ToActivateModule");
67$server =
new nusoap_server();
68$server->soap_defencoding =
'UTF-8';
69$server->decode_utf8 =
false;
70$ns =
'http://www.dolibarr.org/ns/';
71$server->configureWSDL(
'WebServicesDolibarrContact', $ns);
72$server->wsdl->schemaTargetNamespace = $ns;
76$server->wsdl->addComplexType(
83 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
84 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
85 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
86 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
87 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
92$server->wsdl->addComplexType(
99 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
100 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
104$contact_fields = array(
105 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
106 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
107 'lastname' => array(
'name' =>
'lastname',
'type' =>
'xsd:string'),
108 'firstname' => array(
'name' =>
'firstname',
'type' =>
'xsd:string'),
109 'address' => array(
'name' =>
'address',
'type' =>
'xsd:string'),
110 'zip' => array(
'name' =>
'zip',
'type' =>
'xsd:string'),
111 'town' => array(
'name' =>
'town',
'type' =>
'xsd:string'),
112 'state_id' => array(
'name' =>
'state_id',
'type' =>
'xsd:string'),
113 'state_code' => array(
'name' =>
'state_code',
'type' =>
'xsd:string'),
114 'state' => array(
'name' =>
'state',
'type' =>
'xsd:string'),
115 'country_id' => array(
'name' =>
'country_id',
'type' =>
'xsd:string'),
116 'country_code' => array(
'name' =>
'country_code',
'type' =>
'xsd:string'),
117 'country' => array(
'name' =>
'country',
'type' =>
'xsd:string'),
118 'socid' => array(
'name' =>
'socid',
'type' =>
'xsd:string'),
119 'status' => array(
'name' =>
'status',
'type' =>
'xsd:string'),
120 'phone_pro' => array(
'name' =>
'phone_pro',
'type' =>
'xsd:string'),
121 'fax' => array(
'name' =>
'fax',
'type' =>
'xsd:string'),
122 'phone_perso' => array(
'name' =>
'phone_perso',
'type' =>
'xsd:string'),
123 'phone_mobile' => array(
'name' =>
'phone_mobile',
'type' =>
'xsd:string'),
124 'code' => array(
'name' =>
'code',
'type' =>
'xsd:string'),
125 'email' => array(
'name' =>
'email',
'type' =>
'xsd:string'),
126 'birthday' => array(
'name' =>
'birthday',
'type' =>
'xsd:string'),
127 'default_lang' => array(
'name' =>
'default_lang',
'type' =>
'xsd:string'),
128 'note' => array(
'name' =>
'note',
'type' =>
'xsd:string'),
129 'ref_facturation' => array(
'name' =>
'ref_facturation',
'type' =>
'xsd:string'),
130 'ref_contrat' => array(
'name' =>
'ref_contrat',
'type' =>
'xsd:string'),
131 'ref_commande' => array(
'name' =>
'ref_commande',
'type' =>
'xsd:string'),
132 'ref_propal' => array(
'name' =>
'ref_propal',
'type' =>
'xsd:string'),
133 'user_id' => array(
'name' =>
'user_id',
'type' =>
'xsd:string'),
134 'user_login' => array(
'name' =>
'user_login',
'type' =>
'xsd:string'),
135 'civility_id' => array(
'name' =>
'civility_id',
'type' =>
'xsd:string'),
136 'poste' => array(
'name' =>
'poste',
'type' =>
'xsd:string')
140$elementtype =
'socpeople';
146$extrafields->fetch_name_optionals_label($elementtype,
true);
147$extrafield_array =
null;
148if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype][
'count'] > 0) {
149 $extrafield_array = array();
151if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
152 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
153 $type = $extrafields->attributes[$elementtype][
'type'][$key];
154 if ($type ==
'date' || $type ==
'datetime') {
155 $type =
'xsd:dateTime';
157 $type =
'xsd:string';
160 $extrafield_array[
'options_'.$key] = array(
'name' =>
'options_'.$key,
'type' => $type);
163if (is_array($extrafield_array)) {
164 $contact_fields = array_merge($contact_fields, $extrafield_array);
168$server->wsdl->addComplexType(
177$server->wsdl->addComplexType(
186 'type' =>
'tns:contact',
188 'maxOccurs' =>
'unbounded'
200$styleuse =
'encoded';
208 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
210 array(
'result' =>
'tns:result',
'contact' =>
'tns:contact'),
215 'WS to get a contact'
222 array(
'authentication' =>
'tns:authentication',
'contact' =>
'tns:contact'),
224 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
226 $ns.
'#createContact',
229 'WS to create a contact'
233 'getContactsForThirdParty',
235 array(
'authentication' =>
'tns:authentication',
'idthirdparty' =>
'xsd:string'),
237 array(
'result' =>
'tns:result',
'contacts' =>
'tns:ContactsArray2'),
239 $ns.
'#getContactsForThirdParty',
242 'WS to get all contacts of a third party'
249 array(
'authentication' =>
'tns:authentication',
'contact' =>
'tns:contact'),
251 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
253 $ns.
'#updateContact',
256 'WS to update a contact'
270 global $db, $conf, $langs;
272 dol_syslog(
"Function: getContact login=".$authentication[
'login'].
" id=".
$id.
" ref_ext=".$ref_ext);
274 if ($authentication[
'entity']) {
275 $conf->entity = $authentication[
'entity'];
279 $objectresp = array();
285 if (!$error && (
$id && $ref_ext)) {
287 $errorcode =
'BAD_PARAMETERS';
288 $errorlabel =
"Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
292 $fuser->loadRights();
295 $result = $contact->fetch(
$id,
null, $ref_ext);
299 if ($fuser->hasRight(
'societe',
'contact',
'lire') && !$fuser->socid
300 || ($fuser->hasRight(
'societe',
'contact',
'lire') && ($fuser->socid == $contact->socid))
302 $contact_result_fields = array(
303 'id' => $contact->id,
304 'ref_ext' => $contact->ref_ext,
305 'lastname' => $contact->lastname,
306 'firstname' => $contact->firstname,
307 'address' => $contact->address,
308 'zip' => $contact->zip,
309 'town' => $contact->town,
310 'state_id' => $contact->state_id,
311 'state_code' => $contact->state_code,
312 'state' => $contact->state,
313 'country_id' => $contact->country_id,
314 'country_code' => $contact->country_code,
315 'country' => $contact->country,
316 'socid' => $contact->socid,
317 'status' => $contact->statut,
318 'phone_pro' => $contact->phone_pro,
319 'fax' => $contact->fax,
320 'phone_perso' => $contact->phone_perso,
321 'phone_mobile' => $contact->phone_mobile,
322 'code' => $contact->code,
323 'email' => $contact->email,
324 'birthday' => $contact->birthday,
325 'default_lang' => $contact->default_lang,
326 'note' => $contact->note,
327 'ref_facturation' => $contact->ref_facturation,
328 'ref_contrat' => $contact->ref_contrat,
329 'ref_commande' => $contact->ref_commande,
330 'ref_propal' => $contact->ref_propal,
331 'user_id' => $contact->user_id,
332 'user_login' => $contact->user_login,
333 'civility_id' => $contact->civility_id,
334 'poste' => $contact->poste
337 $elementtype =
'socpeople';
342 $extrafields->fetch_name_optionals_label($elementtype,
true);
344 $contact->fetch_optionals();
346 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
347 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
348 $contact_result_fields = array_merge($contact_result_fields, array(
'options_'.$key => $contact->array_options[
'options_'.$key]));
354 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
355 'contact' => $contact_result_fields
359 $errorcode =
'PERMISSION_DENIED';
360 $errorlabel =
'User does not have permission for this request';
364 $errorcode =
'NOT_FOUND';
365 $errorlabel =
'Object not found for id='.$id.
' nor ref_ext='.$ref_ext;
370 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
390 dol_syslog(
"Function: createContact login=".$authentication[
'login']);
392 if ($authentication[
'entity']) {
393 $conf->entity = $authentication[
'entity'];
397 $objectresp = array();
403 if (empty($contact[
'lastname'])) {
406 $errorlabel =
"Name is mandatory.";
412 $newobject->id = $contact[
'id'];
413 $newobject->ref_ext = $contact[
'ref_ext'];
414 $newobject->civility_id = $contact[
'civility_id'];
415 $newobject->lastname = $contact[
'lastname'];
416 $newobject->firstname = $contact[
'firstname'];
417 $newobject->address = $contact[
'address'];
418 $newobject->zip = $contact[
'zip'];
419 $newobject->town = $contact[
'town'];
420 $newobject->state_id = $contact[
'state_id'];
421 $newobject->state_code = $contact[
'state_code'];
422 $newobject->state = $contact[
'state'];
423 $newobject->country_id = $contact[
'country_id'];
424 $newobject->country_code = $contact[
'country_code'];
425 $newobject->country = $contact[
'country'];
426 $newobject->socid = $contact[
'socid'];
427 $newobject->statut = $contact[
'status'];
428 $newobject->phone_pro = $contact[
'phone_pro'];
429 $newobject->fax = $contact[
'fax'];
430 $newobject->phone_perso = $contact[
'phone_perso'];
431 $newobject->phone_mobile = $contact[
'phone_mobile'];
432 $newobject->code = $contact[
'code'];
433 $newobject->email = $contact[
'email'];
434 $newobject->birthday = $contact[
'birthday'];
435 $newobject->default_lang = $contact[
'default_lang'];
436 $newobject->note = $contact[
'note'];
437 $newobject->ref_facturation = $contact[
'ref_facturation'];
438 $newobject->ref_contrat = $contact[
'ref_contrat'];
439 $newobject->ref_commande = $contact[
'ref_commande'];
440 $newobject->ref_propal = $contact[
'ref_propal'];
441 $newobject->user_id = $contact[
'user_id'];
442 $newobject->user_login = $contact[
'user_login'];
443 $newobject->poste = $contact[
'poste'];
445 $elementtype =
'socpeople';
450 $extrafields->fetch_name_optionals_label($elementtype,
true);
451 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
452 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
453 $key =
'options_'.$key;
454 $newobject->array_options[$key] = $contact[$key];
463 $result = $newobject->create($fuser);
470 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref);
475 $errorlabel = $newobject->error;
480 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
497 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
499 if ($authentication[
'entity']) {
500 $conf->entity = $authentication[
'entity'];
504 $objectresp = array();
510 if (!$error && empty($idthirdparty)) {
512 $errorcode =
'BAD_PARAMETERS';
513 $errorlabel =
'Parameter id is not provided';
517 $linesinvoice = array();
519 $sql =
"SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
520 $sql .=
" c.address, c.zip, c.town,";
521 $sql .=
" c.fk_pays as country_id,";
522 $sql .=
" c.fk_departement as state_id,";
523 $sql .=
" c.birthday,";
524 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
525 $sql .=
" co.label as country, co.code as country_code,";
526 $sql .=
" d.nom as state, d.code_departement as state_code,";
527 $sql .=
" u.rowid as user_id, u.login as user_login,";
528 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
529 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
530 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
531 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
532 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
533 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
534 $sql .=
" WHERE c.fk_soc = ".((int) $idthirdparty);
536 $resql = $db->query($sql);
538 $linescontact = array();
539 $num = $db->num_rows($resql);
543 $obj = $db->fetch_object($resql);
546 $contact->fetch($obj->rowid);
549 $linescontact[] = array(
550 'id' => $contact->id,
551 'ref' => $contact->ref,
552 'civility_id' => $contact->civility_id ? $contact->civility_id :
'',
553 'lastname' => $contact->lastname ? $contact->lastname :
'',
554 'firstname' => $contact->firstname ? $contact->firstname :
'',
555 'address' => $contact->address ? $contact->address :
'',
556 'zip' => $contact->zip ? $contact->zip :
'',
557 'town' => $contact->town ? $contact->town :
'',
559 'state_id' => $contact->state_id ? $contact->state_id :
'',
560 'state_code' => $contact->state_code ? $contact->state_code :
'',
561 'state' => $contact->state ? $contact->state :
'',
563 'country_id' => $contact->country_id ? $contact->country_id :
'',
564 'country_code' => $contact->country_code ? $contact->country_code :
'',
565 'country' => $contact->country ? $contact->country :
'',
567 'socid' => $contact->socid ? $contact->socid :
'',
568 'socname' => $contact->socname ? $contact->socname :
'',
569 'poste' => $contact->poste ? $contact->poste :
'',
571 'phone_pro' => $contact->phone_pro ? $contact->phone_pro :
'',
572 'fax' => $contact->fax ? $contact->fax :
'',
573 'phone_perso' => $contact->phone_perso ? $contact->phone_perso :
'',
574 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile :
'',
576 'email' => $contact->email ? $contact->email :
'',
577 'priv' => $contact->priv ? $contact->priv :
'',
578 'mail' => $contact->mail ? $contact->mail :
'',
580 'birthday' => $contact->birthday ? $contact->birthday :
'',
581 'default_lang' => $contact->default_lang ? $contact->default_lang :
'',
582 'note' => $contact->note ? $contact->note :
'',
583 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation :
'',
584 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat :
'',
585 'ref_commande' => $contact->ref_commande ? $contact->ref_commande :
'',
586 'ref_propal' => $contact->ref_propal ? $contact->ref_propal :
'',
587 'user_id' => $contact->user_id ? $contact->user_id :
'',
588 'user_login' => $contact->user_login ? $contact->user_login :
'',
589 'status' => $contact->statut ? $contact->statut :
''
596 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
597 'contacts' => $linescontact
602 $errorcode = $db->lasterrno();
603 $errorlabel = $db->lasterror();
608 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
628 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
630 if ($authentication[
'entity']) {
631 $conf->entity = $authentication[
'entity'];
635 $objectresp = array();
641 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
644 $errorlabel =
"Contact id or ref_ext is mandatory.";
647 if (!$error && ($contact[
'id'] && $contact[
'ref_ext'])) {
649 $errorcode =
'BAD_PARAMETERS';
650 $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
654 $objectfound =
false;
656 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
659 $result =
$object->fetch($contact[
'id'],
null, $contact[
'ref_ext']);
664 $object->ref_ext = $contact[
'ref_ext'];
666 $object->firstname = $contact[
'firstname'];
667 $object->lastname = $contact[
'lastname'];
669 $object->address = $contact[
'address'];
670 $object->zip = $contact[
'zip'];
671 $object->town = $contact[
'town'];
673 $object->country_id = $contact[
'country_id'];
674 if ($contact[
'country_code']) {
677 $object->province_id = $contact[
'province_id'];
680 $object->phone_pro = $contact[
'phone_pro'];
681 $object->phone_perso = $contact[
'phone_perso'];
682 $object->phone_mobile = $contact[
'phone_mobile'];
683 $object->fax = $contact[
'fax'];
684 $object->email = $contact[
'email'];
686 $object->civility_id = $contact[
'civility_id'];
687 $object->poste = $contact[
'poste'];
689 $object->statut = $contact[
'status'];
691 $elementtype =
'socpeople';
696 $extrafields->fetch_name_optionals_label($elementtype,
true);
697 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
698 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
699 $key =
'options_'.$key;
700 $object->array_options[$key] = $contact[$key];
706 $result =
$object->update($contact[
'id'], $fuser);
711 '@phan-var-force array{id:string} $contact';
713 if ((!$error) && ($objectfound)) {
716 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
719 } elseif ($objectfound) {
726 $errorcode =
'NOT_FOUND';
727 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
732 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
739$server->service(file_get_contents(
"php://input"));
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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='auto')
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.