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);
76$server->wsdl->schemaTargetNamespace = $ns;
80$server->wsdl->addComplexType(
87 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
88 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
89 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
90 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
91 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
96$server->wsdl->addComplexType(
103 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
104 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
108$contact_fields = array(
109 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
110 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
111 'lastname' => array(
'name' =>
'lastname',
'type' =>
'xsd:string'),
112 'firstname' => array(
'name' =>
'firstname',
'type' =>
'xsd:string'),
113 'address' => array(
'name' =>
'address',
'type' =>
'xsd:string'),
114 'zip' => array(
'name' =>
'zip',
'type' =>
'xsd:string'),
115 'town' => array(
'name' =>
'town',
'type' =>
'xsd:string'),
116 'state_id' => array(
'name' =>
'state_id',
'type' =>
'xsd:string'),
117 'state_code' => array(
'name' =>
'state_code',
'type' =>
'xsd:string'),
118 'state' => array(
'name' =>
'state',
'type' =>
'xsd:string'),
119 'country_id' => array(
'name' =>
'country_id',
'type' =>
'xsd:string'),
120 'country_code' => array(
'name' =>
'country_code',
'type' =>
'xsd:string'),
121 'country' => array(
'name' =>
'country',
'type' =>
'xsd:string'),
122 'socid' => array(
'name' =>
'socid',
'type' =>
'xsd:string'),
123 'status' => array(
'name' =>
'status',
'type' =>
'xsd:string'),
124 'phone_pro' => array(
'name' =>
'phone_pro',
'type' =>
'xsd:string'),
125 'fax' => array(
'name' =>
'fax',
'type' =>
'xsd:string'),
126 'phone_perso' => array(
'name' =>
'phone_perso',
'type' =>
'xsd:string'),
127 'phone_mobile' => array(
'name' =>
'phone_mobile',
'type' =>
'xsd:string'),
128 'code' => array(
'name' =>
'code',
'type' =>
'xsd:string'),
129 'email' => array(
'name' =>
'email',
'type' =>
'xsd:string'),
130 'birthday' => array(
'name' =>
'birthday',
'type' =>
'xsd:string'),
131 'default_lang' => array(
'name' =>
'default_lang',
'type' =>
'xsd:string'),
132 'note' => array(
'name' =>
'note',
'type' =>
'xsd:string'),
133 'ref_facturation' => array(
'name' =>
'ref_facturation',
'type' =>
'xsd:string'),
134 'ref_contrat' => array(
'name' =>
'ref_contrat',
'type' =>
'xsd:string'),
135 'ref_commande' => array(
'name' =>
'ref_commande',
'type' =>
'xsd:string'),
136 'ref_propal' => array(
'name' =>
'ref_propal',
'type' =>
'xsd:string'),
137 'user_id' => array(
'name' =>
'user_id',
'type' =>
'xsd:string'),
138 'user_login' => array(
'name' =>
'user_login',
'type' =>
'xsd:string'),
139 'civility_id' => array(
'name' =>
'civility_id',
'type' =>
'xsd:string'),
140 'poste' => array(
'name' =>
'poste',
'type' =>
'xsd:string')
144$elementtype =
'socpeople';
150$extrafields->fetch_name_optionals_label($elementtype,
true);
151$extrafield_array =
null;
152if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype][
'count'] > 0) {
153 $extrafield_array = array();
155if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
156 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
157 $type = $extrafields->attributes[$elementtype][
'type'][$key];
158 if ($type ==
'date' || $type ==
'datetime') {
159 $type =
'xsd:dateTime';
161 $type =
'xsd:string';
164 $extrafield_array[
'options_'.$key] = array(
'name' =>
'options_'.$key,
'type' => $type);
167if (is_array($extrafield_array)) {
168 $contact_fields = array_merge($contact_fields, $extrafield_array);
172$server->wsdl->addComplexType(
181$server->wsdl->addComplexType(
190 'type' =>
'tns:contact',
192 'maxOccurs' =>
'unbounded'
204$styleuse =
'encoded';
212 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
214 array(
'result' =>
'tns:result',
'contact' =>
'tns:contact'),
219 'WS to get a contact'
226 array(
'authentication' =>
'tns:authentication',
'contact' =>
'tns:contact'),
228 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
230 $ns.
'#createContact',
233 'WS to create a contact'
237 'getContactsForThirdParty',
239 array(
'authentication' =>
'tns:authentication',
'idthirdparty' =>
'xsd:string'),
241 array(
'result' =>
'tns:result',
'contacts' =>
'tns:ContactsArray2'),
243 $ns.
'#getContactsForThirdParty',
246 'WS to get all contacts of a third party'
253 array(
'authentication' =>
'tns:authentication',
'contact' =>
'tns:contact'),
255 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
257 $ns.
'#updateContact',
260 'WS to update a contact'
274 global $db,
$conf, $langs;
276 dol_syslog(
"Function: getContact login=".$authentication[
'login'].
" id=".
$id.
" ref_ext=".$ref_ext);
278 if ($authentication[
'entity']) {
279 $conf->entity = $authentication[
'entity'];
283 $objectresp = array();
289 if (!$error && (
$id && $ref_ext)) {
291 $errorcode =
'BAD_PARAMETERS';
292 $errorlabel =
"Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
296 $fuser->loadRights();
299 $result = $contact->fetch(
$id,
null, $ref_ext);
303 if ($fuser->hasRight(
'societe',
'contact',
'lire') && !$fuser->socid
304 || ($fuser->hasRight(
'societe',
'contact',
'lire') && ($fuser->socid == $contact->socid))
306 $contact_result_fields = array(
307 'id' => $contact->id,
308 'ref_ext' => $contact->ref_ext,
309 'lastname' => $contact->lastname,
310 'firstname' => $contact->firstname,
311 'address' => $contact->address,
312 'zip' => $contact->zip,
313 'town' => $contact->town,
314 'state_id' => $contact->state_id,
315 'state_code' => $contact->state_code,
316 'state' => $contact->state,
317 'country_id' => $contact->country_id,
318 'country_code' => $contact->country_code,
319 'country' => $contact->country,
320 'socid' => $contact->socid,
321 'status' => $contact->statut,
322 'phone_pro' => $contact->phone_pro,
323 'fax' => $contact->fax,
324 'phone_perso' => $contact->phone_perso,
325 'phone_mobile' => $contact->phone_mobile,
326 'code' => $contact->code,
327 'email' => $contact->email,
328 'birthday' => $contact->birthday,
329 'default_lang' => $contact->default_lang,
330 'note' => $contact->note,
331 'ref_facturation' => $contact->ref_facturation,
332 'ref_contrat' => $contact->ref_contrat,
333 'ref_commande' => $contact->ref_commande,
334 'ref_propal' => $contact->ref_propal,
335 'user_id' => $contact->user_id,
336 'user_login' => $contact->user_login,
337 'civility_id' => $contact->civility_id,
338 'poste' => $contact->poste
341 $elementtype =
'socpeople';
346 $extrafields->fetch_name_optionals_label($elementtype,
true);
348 $contact->fetch_optionals();
350 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
351 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
352 $contact_result_fields = array_merge($contact_result_fields, array(
'options_'.$key => $contact->array_options[
'options_'.$key]));
358 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
359 'contact' => $contact_result_fields
363 $errorcode =
'PERMISSION_DENIED';
364 $errorlabel =
'User does not have permission for this request';
368 $errorcode =
'NOT_FOUND';
369 $errorlabel =
'Object not found for id='.$id.
' nor ref_ext='.$ref_ext;
374 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
394 dol_syslog(
"Function: createContact login=".$authentication[
'login']);
396 if ($authentication[
'entity']) {
397 $conf->entity = $authentication[
'entity'];
401 $objectresp = array();
407 if (empty($contact[
'lastname'])) {
410 $errorlabel =
"Name is mandatory.";
416 $newobject->id = (int) $contact[
'id'];
417 $newobject->ref_ext = $contact[
'ref_ext'];
418 $newobject->civility_id = $contact[
'civility_id'];
419 $newobject->lastname = $contact[
'lastname'];
420 $newobject->firstname = $contact[
'firstname'];
421 $newobject->address = $contact[
'address'];
422 $newobject->zip = $contact[
'zip'];
423 $newobject->town = $contact[
'town'];
424 $newobject->state_id = (int) $contact[
'state_id'];
425 $newobject->state_code = $contact[
'state_code'];
426 $newobject->state = $contact[
'state'];
427 $newobject->country_id = (int) $contact[
'country_id'];
428 $newobject->country_code = $contact[
'country_code'];
429 $newobject->country = $contact[
'country'];
430 $newobject->socid = (int) $contact[
'socid'];
431 $newobject->statut = (int) $contact[
'status'];
432 $newobject->phone_pro = $contact[
'phone_pro'];
433 $newobject->fax = $contact[
'fax'];
434 $newobject->phone_perso = $contact[
'phone_perso'];
435 $newobject->phone_mobile = $contact[
'phone_mobile'];
436 $newobject->code = $contact[
'code'];
437 $newobject->email = $contact[
'email'];
438 $newobject->birthday = $contact[
'birthday'];
439 $newobject->default_lang = $contact[
'default_lang'];
440 $newobject->note = $contact[
'note'];
441 $newobject->ref_facturation = (int) $contact[
'ref_facturation'];
442 $newobject->ref_contrat = (int) $contact[
'ref_contrat'];
443 $newobject->ref_commande = (int) $contact[
'ref_commande'];
444 $newobject->ref_propal = (int) $contact[
'ref_propal'];
445 $newobject->user_id = (int) $contact[
'user_id'];
446 $newobject->user_login = $contact[
'user_login'];
447 $newobject->poste = $contact[
'poste'];
449 $elementtype =
'socpeople';
454 $extrafields->fetch_name_optionals_label($elementtype,
true);
455 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
456 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
457 $key =
'options_'.$key;
458 $newobject->array_options[$key] = $contact[$key];
467 $result = $newobject->create($fuser);
474 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
'id' => $newobject->id,
'ref' => $newobject->ref);
479 $errorlabel = $newobject->error;
484 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
501 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
503 if ($authentication[
'entity']) {
504 $conf->entity = $authentication[
'entity'];
508 $objectresp = array();
514 if (!$error && empty($idthirdparty)) {
516 $errorcode =
'BAD_PARAMETERS';
517 $errorlabel =
'Parameter id is not provided';
521 $linesinvoice = array();
523 $sql =
"SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
524 $sql .=
" c.address, c.zip, c.town,";
525 $sql .=
" c.fk_pays as country_id,";
526 $sql .=
" c.fk_departement as state_id,";
527 $sql .=
" c.birthday,";
528 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
529 $sql .=
" co.label as country, co.code as country_code,";
530 $sql .=
" d.nom as state, d.code_departement as state_code,";
531 $sql .=
" u.rowid as user_id, u.login as user_login,";
532 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
533 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
534 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
535 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
536 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
537 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
538 $sql .=
" WHERE c.fk_soc = ".((int) $idthirdparty);
540 $resql = $db->query($sql);
542 $linescontact = array();
543 $num = $db->num_rows($resql);
547 $obj = $db->fetch_object($resql);
550 $contact->fetch($obj->rowid);
553 $linescontact[] = array(
554 'id' => $contact->id,
555 'ref' => $contact->ref,
556 'civility_id' => $contact->civility_id ? $contact->civility_id :
'',
557 'lastname' => $contact->lastname ? $contact->lastname :
'',
558 'firstname' => $contact->firstname ? $contact->firstname :
'',
559 'address' => $contact->address ? $contact->address :
'',
560 'zip' => $contact->zip ? $contact->zip :
'',
561 'town' => $contact->town ? $contact->town :
'',
563 'state_id' => $contact->state_id ? $contact->state_id :
'',
564 'state_code' => $contact->state_code ? $contact->state_code :
'',
565 'state' => $contact->state ? $contact->state :
'',
567 'country_id' => $contact->country_id ? $contact->country_id :
'',
568 'country_code' => $contact->country_code ? $contact->country_code :
'',
569 'country' => $contact->country ? $contact->country :
'',
571 'socid' => $contact->socid ? $contact->socid :
'',
572 'socname' => $contact->socname ? $contact->socname :
'',
573 'poste' => $contact->poste ? $contact->poste :
'',
575 'phone_pro' => $contact->phone_pro ? $contact->phone_pro :
'',
576 'fax' => $contact->fax ? $contact->fax :
'',
577 'phone_perso' => $contact->phone_perso ? $contact->phone_perso :
'',
578 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile :
'',
580 'email' => $contact->email ? $contact->email :
'',
581 'priv' => $contact->priv ? $contact->priv :
'',
582 'mail' => $contact->mail ? $contact->mail :
'',
584 'birthday' => $contact->birthday ? $contact->birthday :
'',
585 'default_lang' => $contact->default_lang ? $contact->default_lang :
'',
586 'note' => $contact->note ? $contact->note :
'',
587 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation :
'',
588 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat :
'',
589 'ref_commande' => $contact->ref_commande ? $contact->ref_commande :
'',
590 'ref_propal' => $contact->ref_propal ? $contact->ref_propal :
'',
591 'user_id' => $contact->user_id ? $contact->user_id :
'',
592 'user_login' => $contact->user_login ? $contact->user_login :
'',
593 'status' => $contact->statut ? $contact->statut :
''
600 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
601 'contacts' => $linescontact
606 $errorcode = $db->lasterrno();
607 $errorlabel = $db->lasterror();
612 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
632 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
634 if ($authentication[
'entity']) {
635 $conf->entity = $authentication[
'entity'];
639 $objectresp = array();
645 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
648 $errorlabel =
"Contact id or ref_ext is mandatory.";
651 if (!$error && ($contact[
'id'] && $contact[
'ref_ext'])) {
653 $errorcode =
'BAD_PARAMETERS';
654 $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
658 $objectfound =
false;
660 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
663 $result =
$object->fetch($contact[
'id'],
null, $contact[
'ref_ext']);
668 $object->ref_ext = $contact[
'ref_ext'];
670 $object->firstname = $contact[
'firstname'];
671 $object->lastname = $contact[
'lastname'];
673 $object->address = $contact[
'address'];
674 $object->zip = $contact[
'zip'];
675 $object->town = $contact[
'town'];
677 $object->country_id = (int) $contact[
'country_id'];
678 if ($contact[
'country_code']) {
681 $object->province_id = isset($contact[
'province_id']) ? $contact[
'province_id'] :
null;
684 $object->phone_pro = $contact[
'phone_pro'];
685 $object->phone_perso = $contact[
'phone_perso'];
686 $object->phone_mobile = $contact[
'phone_mobile'];
687 $object->fax = $contact[
'fax'];
688 $object->email = $contact[
'email'];
690 $object->civility_id = $contact[
'civility_id'];
691 $object->poste = $contact[
'poste'];
693 $object->statut = (int) $contact[
'status'];
695 $elementtype =
'socpeople';
700 $extrafields->fetch_name_optionals_label($elementtype,
true);
701 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
702 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
703 $key =
'options_'.$key;
704 $object->array_options[$key] = $contact[$key];
710 $result =
$object->update($contact[
'id'], $fuser);
715 '@phan-var-force array{id:string} $contact';
717 if ((!$error) && ($objectfound)) {
720 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
723 } elseif ($objectfound) {
730 $errorcode =
'NOT_FOUND';
731 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
736 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
743$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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.