24 if (!defined(
"NOCSRFCHECK")) define(
"NOCSRFCHECK",
'1');
26 require
"../master.inc.php";
27 require_once NUSOAP_PATH.
'/nusoap.php';
28 require_once DOL_DOCUMENT_ROOT.
"/core/lib/ws.lib.php";
29 require_once DOL_DOCUMENT_ROOT.
"/contact/class/contact.class.php";
30 require_once DOL_DOCUMENT_ROOT.
"/core/class/extrafields.class.php";
33 dol_syslog(
"Call Contact webservices interfaces");
36 if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
38 $langs->load(
"admin");
39 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
40 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
41 print $langs->trans(
"ToActivateModule");
46 $server =
new nusoap_server();
47 $server->soap_defencoding =
'UTF-8';
48 $server->decode_utf8 =
false;
49 $ns =
'http://www.dolibarr.org/ns/';
50 $server->configureWSDL(
'WebServicesDolibarrContact', $ns);
51 $server->wsdl->schemaTargetNamespace = $ns;
55 $server->wsdl->addComplexType(
62 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
63 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
64 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
65 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
66 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
71 $server->wsdl->addComplexType(
78 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
79 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
83 $contact_fields = array(
84 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
85 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
86 'lastname' => array(
'name'=>
'lastname',
'type'=>
'xsd:string'),
87 'firstname' => array(
'name'=>
'firstname',
'type'=>
'xsd:string'),
88 'address' => array(
'name'=>
'address',
'type'=>
'xsd:string'),
89 'zip' => array(
'name'=>
'zip',
'type'=>
'xsd:string'),
90 'town' => array(
'name'=>
'town',
'type'=>
'xsd:string'),
91 'state_id' => array(
'name'=>
'state_id',
'type'=>
'xsd:string'),
92 'state_code' => array(
'name'=>
'state_code',
'type'=>
'xsd:string'),
93 'state' => array(
'name'=>
'state',
'type'=>
'xsd:string'),
94 'country_id' => array(
'name'=>
'country_id',
'type'=>
'xsd:string'),
95 'country_code' => array(
'name'=>
'country_code',
'type'=>
'xsd:string'),
96 'country' => array(
'name'=>
'country',
'type'=>
'xsd:string'),
97 'socid' => array(
'name'=>
'socid',
'type'=>
'xsd:string'),
98 'status' => array(
'name'=>
'status',
'type'=>
'xsd:string'),
99 'phone_pro' => array(
'name'=>
'phone_pro',
'type'=>
'xsd:string'),
100 'fax' => array(
'name'=>
'fax',
'type'=>
'xsd:string'),
101 'phone_perso' => array(
'name'=>
'phone_perso',
'type'=>
'xsd:string'),
102 'phone_mobile' => array(
'name'=>
'phone_mobile',
'type'=>
'xsd:string'),
103 'code' => array(
'name'=>
'code',
'type'=>
'xsd:string'),
104 'email' => array(
'name'=>
'email',
'type'=>
'xsd:string'),
105 'birthday' => array(
'name'=>
'birthday',
'type'=>
'xsd:string'),
106 'default_lang' => array(
'name'=>
'default_lang',
'type'=>
'xsd:string'),
107 'note' => array(
'name'=>
'note',
'type'=>
'xsd:string'),
108 'ref_facturation' => array(
'name'=>
'ref_facturation',
'type'=>
'xsd:string'),
109 'ref_contrat' => array(
'name'=>
'ref_contrat',
'type'=>
'xsd:string'),
110 'ref_commande' => array(
'name'=>
'ref_commande',
'type'=>
'xsd:string'),
111 'ref_propal' => array(
'name'=>
'ref_propal',
'type'=>
'xsd:string'),
112 'user_id' => array(
'name'=>
'user_id',
'type'=>
'xsd:string'),
113 'user_login' => array(
'name'=>
'user_login',
'type'=>
'xsd:string'),
114 'civility_id' => array(
'name'=>
'civility_id',
'type'=>
'xsd:string'),
115 'poste' => array(
'name'=>
'poste',
'type'=>
'xsd:string')
119 $elementtype =
'socpeople';
125 $extrafields->fetch_name_optionals_label($elementtype,
true);
126 $extrafield_array = null;
127 if (is_array($extrafields) && count($extrafields) > 0) {
128 $extrafield_array = array();
130 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)
134 $type = $extrafields->attributes[$elementtype][
'type'][$key];
135 if ($type ==
'date' || $type ==
'datetime') {$type =
'xsd:dateTime'; }
136 else {$type =
'xsd:string'; }
138 $extrafield_array[
'options_'.$key] = array(
'name'=>
'options_'.$key,
'type'=>$type);
141 if (is_array($extrafield_array)) $contact_fields = array_merge($contact_fields, $extrafield_array);
144 $server->wsdl->addComplexType(
153 $server->wsdl->addComplexType(
162 'type' =>
'tns:contact',
164 'maxOccurs' =>
'unbounded'
176 $styleuse =
'encoded';
184 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref_ext'=>
'xsd:string'),
186 array(
'result'=>
'tns:result',
'contact'=>
'tns:contact'),
191 'WS to get a contact'
198 array(
'authentication'=>
'tns:authentication',
'contact'=>
'tns:contact'),
200 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
202 $ns.
'#createContact',
205 'WS to create a contact'
209 'getContactsForThirdParty',
211 array(
'authentication'=>
'tns:authentication',
'idthirdparty'=>
'xsd:string'),
213 array(
'result'=>
'tns:result',
'contacts'=>
'tns:ContactsArray2'),
215 $ns.
'#getContactsForThirdParty',
218 'WS to get all contacts of a third party'
225 array(
'authentication'=>
'tns:authentication',
'contact'=>
'tns:contact'),
227 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
229 $ns.
'#updateContact',
232 'WS to update a contact'
246 global $db, $conf, $langs;
248 dol_syslog(
"Function: getContact login=".$authentication[
'login'].
" id=".$id.
" ref_ext=".$ref_ext);
250 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
253 $objectresp = array();
254 $errorcode =
''; $errorlabel =
'';
258 if (!$error && ($id && $ref_ext))
261 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref_ext can't be both provided. You must choose one or other but not both.";
269 $result = $contact->fetch($id, 0, $ref_ext);
275 $fuser->rights->societe->contact->lire && !$fuser->socid
276 || ($fuser->rights->societe->contact->lire && ($fuser->socid == $contact->socid))
278 $contact_result_fields = array(
279 'id' => $contact->id,
280 'ref_ext' => $contact->ref_ext,
281 'lastname' => $contact->lastname,
282 'firstname' => $contact->firstname,
283 'address' => $contact->address,
284 'zip' => $contact->zip,
285 'town' => $contact->town,
286 'state_id' => $contact->state_id,
287 'state_code' => $contact->state_code,
288 'state' => $contact->state,
289 'country_id' => $contact->country_id,
290 'country_code' => $contact->country_code,
291 'country' => $contact->country,
292 'socid' => $contact->socid,
293 'status' => $contact->statut,
294 'phone_pro' => $contact->phone_pro,
295 'fax' => $contact->fax,
296 'phone_perso' => $contact->phone_perso,
297 'phone_mobile' => $contact->phone_mobile,
298 'code' => $contact->code,
299 'email' => $contact->email,
300 'birthday' => $contact->birthday,
301 'default_lang' => $contact->default_lang,
302 'note' => $contact->note,
303 'ref_facturation' => $contact->ref_facturation,
304 'ref_contrat' => $contact->ref_contrat,
305 'ref_commande' => $contact->ref_commande,
306 'ref_propal' => $contact->ref_propal,
307 'user_id' => $contact->user_id,
308 'user_login' => $contact->user_login,
309 'civility_id' => $contact->civility_id,
310 'poste' => $contact->poste
313 $elementtype =
'socpeople';
318 $extrafields->fetch_name_optionals_label($elementtype,
true);
320 $contact->fetch_optionals();
322 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label']))
324 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
338 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
343 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref_ext='.$ref_ext;
349 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
365 global $db, $conf, $langs;
369 dol_syslog(
"Function: createContact login=".$authentication[
'login']);
371 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
374 $objectresp = array();
375 $errorcode =
''; $errorlabel =
'';
379 if (empty($contact[
'lastname']))
381 $error++; $errorcode =
'KO'; $errorlabel =
"Name is mandatory.";
388 $newobject->id = $contact[
'id'];
389 $newobject->ref_ext = $contact[
'ref_ext'];
390 $newobject->civility_id = $contact[
'civility_id'];
391 $newobject->lastname = $contact[
'lastname'];
392 $newobject->firstname = $contact[
'firstname'];
393 $newobject->address = $contact[
'address'];
394 $newobject->zip = $contact[
'zip'];
395 $newobject->town = $contact[
'town'];
396 $newobject->state_id = $contact[
'state_id'];
397 $newobject->state_code = $contact[
'state_code'];
398 $newobject->state = $contact[
'state'];
399 $newobject->country_id = $contact[
'country_id'];
400 $newobject->country_code = $contact[
'country_code'];
401 $newobject->country = $contact[
'country'];
402 $newobject->socid = $contact[
'socid'];
403 $newobject->statut = $contact[
'status'];
404 $newobject->phone_pro = $contact[
'phone_pro'];
405 $newobject->fax = $contact[
'fax'];
406 $newobject->phone_perso = $contact[
'phone_perso'];
407 $newobject->phone_mobile = $contact[
'phone_mobile'];
408 $newobject->code = $contact[
'code'];
409 $newobject->email = $contact[
'email'];
410 $newobject->birthday = $contact[
'birthday'];
411 $newobject->default_lang = $contact[
'default_lang'];
412 $newobject->note = $contact[
'note'];
413 $newobject->ref_facturation = $contact[
'ref_facturation'];
414 $newobject->ref_contrat = $contact[
'ref_contrat'];
415 $newobject->ref_commande = $contact[
'ref_commande'];
416 $newobject->ref_propal = $contact[
'ref_propal'];
417 $newobject->user_id = $contact[
'user_id'];
418 $newobject->user_login = $contact[
'user_login'];
419 $newobject->poste = $contact[
'poste'];
421 $elementtype =
'socpeople';
426 $extrafields->fetch_name_optionals_label($elementtype,
true);
427 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label']))
429 foreach ($extrafields->attributes[$elementtype][
'label'] as $key=>$label)
431 $key =
'options_'.$key;
432 $newobject->array_options[$key] = $contact[$key];
441 $result = $newobject->create($fuser);
450 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
'id'=>$newobject->id,
'ref'=>$newobject->ref);
456 $errorlabel = $newobject->error;
462 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
477 global $db, $conf, $langs;
479 dol_syslog(
"Function: getContactsForThirdParty login=".$authentication[
'login'].
" idthirdparty=".$idthirdparty);
481 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
484 $objectresp = array();
485 $errorcode =
''; $errorlabel =
'';
489 if (!$error && empty($idthirdparty))
492 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
'Parameter id is not provided';
497 $linesinvoice = array();
499 $sql =
"SELECT c.rowid, c.fk_soc, c.civility as civility_id, c.lastname, c.firstname, c.statut as status,";
500 $sql .=
" c.address, c.zip, c.town,";
501 $sql .=
" c.fk_pays as country_id,";
502 $sql .=
" c.fk_departement as state_id,";
503 $sql .=
" c.birthday,";
504 $sql .=
" c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid,";
506 $sql .=
" co.label as country, co.code as country_code,";
507 $sql .=
" d.nom as state, d.code_departement as state_code,";
508 $sql .=
" u.rowid as user_id, u.login as user_login,";
509 $sql .=
" s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
510 $sql .=
" FROM ".MAIN_DB_PREFIX.
"socpeople as c";
511 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as co ON c.fk_pays = co.rowid";
512 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON c.fk_departement = d.rowid";
513 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u ON c.rowid = u.fk_socpeople";
514 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
515 $sql .=
" WHERE c.fk_soc = ".$idthirdparty;
517 $resql = $db->query($sql);
520 $num = $db->num_rows(
$resql);
525 $obj = $db->fetch_object(
$resql);
528 $contact->fetch($obj->rowid);
531 $linescontact[] = array(
532 'id' => $contact->id,
533 'ref' => $contact->ref,
534 'civility_id' => $contact->civility_id ? $contact->civility_id :
'',
535 'lastname' => $contact->lastname ? $contact->lastname :
'',
536 'firstname' => $contact->firstname ? $contact->firstname :
'',
537 'address' => $contact->address ? $contact->address :
'',
538 'zip' => $contact->zip ? $contact->zip :
'',
539 'town' => $contact->town ? $contact->town :
'',
541 'state_id' => $contact->state_id ? $contact->state_id :
'',
542 'state_code' => $contact->state_code ? $contact->state_code :
'',
543 'state' => $contact->state ? $contact->state :
'',
545 'country_id' => $contact->country_id ? $contact->country_id :
'',
546 'country_code' => $contact->country_code ? $contact->country_code :
'',
547 'country' => $contact->country ? $contact->country :
'',
549 'socid' => $contact->socid ? $contact->socid :
'',
550 'socname' => $contact->socname ? $contact->socname :
'',
551 'poste' => $contact->poste ? $contact->poste :
'',
553 'phone_pro' => $contact->phone_pro ? $contact->phone_pro :
'',
554 'fax' => $contact->fax ? $contact->fax :
'',
555 'phone_perso' => $contact->phone_perso ? $contact->phone_perso :
'',
556 'phone_mobile' => $contact->phone_mobile ? $contact->phone_mobile :
'',
558 'email' => $contact->email ? $contact->email :
'',
559 'jabberid' => $contact->jabberid ? $contact->jabberid :
'',
560 'priv' => $contact->priv ? $contact->priv :
'',
561 'mail' => $contact->mail ? $contact->mail :
'',
563 'birthday' => $contact->birthday ? $contact->birthday :
'',
564 'default_lang' => $contact->default_lang ? $contact->default_lang :
'',
565 'note' => $contact->note ? $contact->note :
'',
566 'ref_facturation' => $contact->ref_facturation ? $contact->ref_facturation :
'',
567 'ref_contrat' => $contact->ref_contrat ? $contact->ref_contrat :
'',
568 'ref_commande' => $contact->ref_commande ? $contact->ref_commande :
'',
569 'ref_propal' => $contact->ref_propal ? $contact->ref_propal :
'',
570 'user_id' => $contact->user_id ? $contact->user_id :
'',
571 'user_login' => $contact->user_login ? $contact->user_login :
'',
572 'status' => $contact->statut ? $contact->statut :
''
579 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
580 'contacts'=>$linescontact
586 $errorcode = $db->lasterrno(); $errorlabel = $db->lasterror();
592 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
608 global $db, $conf, $langs;
612 dol_syslog(
"Function: updateContact login=".$authentication[
'login']);
614 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
617 $objectresp = array();
618 $errorcode =
''; $errorlabel =
'';
622 if (empty($contact[
'id']) && empty($contact[
'ref_ext'])) {
623 $error++; $errorcode =
'KO'; $errorlabel =
"Contact id or ref_ext is mandatory.";
626 if (!$error && ($id && $ref_ext))
629 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id and ref_ext can't be all provided. You must choose one of them.";
634 $objectfound =
false;
636 include_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
639 $result = $object->fetch($contact[
'id'], 0, $contact[
'ref_ext']);
641 if (!empty($object->id)) {
645 $object->firstname = $contact[
'firstname'];
646 $object->lastname = $contact[
'lastname'];
648 $object->address = $contact[
'address'];
649 $object->zip = $contact[
'zip'];
650 $object->town = $contact[
'town'];
652 $object->country_id = $contact[
'country_id'];
653 if ($contact[
'country_code']) $object->country_id =
getCountry($contact[
'country_code'], 3);
654 $object->province_id = $contact[
'province_id'];
657 $object->phone_pro = $contact[
'phone_pro'];
658 $object->phone_perso = $contact[
'phone_perso'];
659 $object->phone_mobile = $contact[
'phone_mobile'];
660 $object->fax = $contact[
'fax'];
661 $object->email = $contact[
'email'];
663 $object->civility_id = $contact[
'civility_id'];
664 $object->poste = $contact[
'poste'];
666 $object->statut = $contact[
'status'];
668 $elementtype =
'socpeople';
673 $extrafields->fetch_name_optionals_label($elementtype,
true);
674 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label']))
676 foreach ($extrafields->attributes[$elementtype][
'label'] as $key=>$label)
678 $key =
'options_'.$key;
679 $object->array_options[$key] = $contact[$key];
685 $result = $object->update($contact[
'id'], $fuser);
691 if ((!$error) && ($objectfound))
695 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
699 elseif ($objectfound)
704 $errorlabel = $object->error;
707 $errorcode =
'NOT_FOUND';
708 $errorlabel =
'Contact id='.$contact[
'id'].
' cannot be found';
714 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
721 $server->service(file_get_contents(
"php://input"));
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
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.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.