23 if (!defined(
"NOCSRFCHECK")) {
24 define(
"NOCSRFCHECK",
'1');
27 require_once
'../master.inc.php';
28 require_once NUSOAP_PATH.
'/nusoap.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
36 dol_syslog(
"Call User webservices interfaces");
41 if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
42 $langs->load(
"admin");
43 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
44 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
45 print $langs->trans(
"ToActivateModule");
50 $server =
new nusoap_server();
51 $server->soap_defencoding =
'UTF-8';
52 $server->decode_utf8 =
false;
53 $ns =
'http://www.dolibarr.org/ns/';
54 $server->configureWSDL(
'WebServicesDolibarrUser', $ns);
55 $server->wsdl->schemaTargetNamespace = $ns;
59 $server->wsdl->addComplexType(
66 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
67 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
68 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
69 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
70 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
75 $server->wsdl->addComplexType(
82 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
83 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
88 $server->wsdl->addComplexType(
95 'element' => array(
'name'=>
'element',
'type'=>
'xsd:string'),
96 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
97 'lastname' => array(
'name'=>
'lastname',
'type'=>
'xsd:string'),
98 'firstname' => array(
'name'=>
'firstname',
'type'=>
'xsd:string'),
99 'note' => array(
'name'=>
'note',
'type'=>
'xsd:string'),
100 'email' => array(
'name'=>
'email',
'type'=>
'xsd:string'),
101 'signature' => array(
'name'=>
'signature',
'type'=>
'xsd:string'),
102 'office_phone' => array(
'name'=>
'office_phone',
'type'=>
'xsd:string'),
103 'office_fax' => array(
'name'=>
'office_fax',
'type'=>
'xsd:string'),
104 'user_mobile' => array(
'name'=>
'user_mobile',
'type'=>
'xsd:string'),
105 'admin' => array(
'name'=>
'admin',
'type'=>
'xsd:string'),
106 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
107 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
108 'pass_indatabase' => array(
'name'=>
'pass_indatabase',
'type'=>
'xsd:string'),
109 'pass_indatabase_crypted' => array(
'name'=>
'pass_indatabase_crypted',
'type'=>
'xsd:string'),
110 'datec' => array(
'name'=>
'datec',
'type'=>
'xsd:dateTime'),
111 'datem' => array(
'name'=>
'datem',
'type'=>
'xsd:dateTime'),
112 'fk_thirdparty' => array(
'name'=>
'fk_thirdparty',
'type'=>
'xsd:string'),
113 'fk_contact' => array(
'name'=>
'fk_contact',
'type'=>
'xsd:string'),
114 'fk_member' => array(
'name'=>
'fk_member',
'type'=>
'xsd:string'),
115 'datelastlogin' => array(
'name'=>
'datelastlogin',
'type'=>
'xsd:dateTime'),
116 'datepreviouslogin' => array(
'name'=>
'datepreviouslogin',
'type'=>
'xsd:dateTime'),
117 'statut' => array(
'name'=>
'statut',
'type'=>
'xsd:string'),
118 'photo' => array(
'name'=>
'photo',
'type'=>
'xsd:string'),
119 'lang' => array(
'name'=>
'lang',
'type'=>
'xsd:string'),
120 'entrepots' => array(
'name'=>
'entrepots',
'type'=>
'xsd:string'),
122 'canvas' => array(
'name'=>
'canvas',
'type'=>
'xsd:string')
127 $server->wsdl->addComplexType(
134 'name' => array(
'name'=>
'name',
'type'=>
'xsd:string'),
135 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
136 'datec' => array(
'name'=>
'datec',
'type'=>
'xsd:string'),
137 'nb' => array(
'name'=>
'nb',
'type'=>
'xsd:string')
141 $server->wsdl->addComplexType(
149 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:group[]')
154 $thirdpartywithuser_fields = array(
156 'name' => array(
'name'=>
'name',
'type'=>
'xsd:string'),
157 'firstname' => array(
'name'=>
'firstname',
'type'=>
'xsd:string'),
158 'name_thirdparty' => array(
'name'=>
'name_thirdparty',
'type'=>
'xsd:string'),
159 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
160 'client' => array(
'name'=>
'client',
'type'=>
'xsd:string'),
161 'fournisseur' => array(
'name'=>
'fournisseur',
'type'=>
'xsd:string'),
162 'address' => array(
'name'=>
'address',
'type'=>
'xsd:string'),
163 'zip' => array(
'name'=>
'zip',
'type'=>
'xsd:string'),
164 'town' => array(
'name'=>
'town',
'type'=>
'xsd:string'),
165 'country_id' => array(
'name'=>
'country_id',
'type'=>
'xsd:string'),
166 'country_code' => array(
'name'=>
'country_code',
'type'=>
'xsd:string'),
167 'phone' => array(
'name'=>
'phone',
'type'=>
'xsd:string'),
168 'phone_mobile' => array(
'name'=>
'phone_mobile',
'type'=>
'xsd:string'),
169 'fax' => array(
'name'=>
'fax',
'type'=>
'xsd:string'),
170 'email' => array(
'name'=>
'email',
'type'=>
'xsd:string'),
171 'url' => array(
'name'=>
'url',
'type'=>
'xsd:string'),
172 'profid1' => array(
'name'=>
'profid1',
'type'=>
'xsd:string'),
173 'profid2' => array(
'name'=>
'profid2',
'type'=>
'xsd:string'),
174 'profid3' => array(
'name'=>
'profid3',
'type'=>
'xsd:string'),
175 'profid4' => array(
'name'=>
'profid4',
'type'=>
'xsd:string'),
176 'profid5' => array(
'name'=>
'profid5',
'type'=>
'xsd:string'),
177 'profid6' => array(
'name'=>
'profid6',
'type'=>
'xsd:string'),
178 'capital' => array(
'name'=>
'capital',
'type'=>
'xsd:string'),
179 'tva_assuj' => array(
'name'=>
'tva_assuj',
'type'=>
'xsd:string'),
180 'tva_intra' => array(
'name'=>
'tva_intra',
'type'=>
'xsd:string'),
182 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
183 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
184 'group_id' => array(
'name'=>
'group_id',
'type'=>
'xsd:string')
187 $elementtype =
'socpeople';
192 $extrafields->fetch_name_optionals_label($elementtype,
true);
193 $extrafield_array =
null;
194 if (is_array($extrafields) && count($extrafields) > 0) {
195 $extrafield_array = array();
197 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
198 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
199 $type = $extrafields->attributes[$elementtype][
'type'][$key];
200 if ($type ==
'date' || $type ==
'datetime') {
201 $type =
'xsd:dateTime';
203 $type =
'xsd:string';
206 $extrafield_array[
'contact_options_'.$key] = array(
'name'=>
'contact_options_'.$key,
'type'=>$type);
210 if (is_array($extrafield_array)) {
211 $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
215 $server->wsdl->addComplexType(
216 'thirdpartywithuser',
221 $thirdpartywithuser_fields
225 $server->wsdl->addComplexType(
232 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
233 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
234 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
244 $styleuse =
'encoded';
252 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string',
'ref_ext'=>
'xsd:string'),
254 array(
'result'=>
'tns:result',
'user'=>
'tns:user'),
265 array(
'authentication'=>
'tns:authentication'),
267 array(
'result'=>
'tns:result',
'groups'=>
'tns:GroupsArray'),
269 $ns.
'#getListOfGroups',
272 'WS to get list of groups'
276 'createUserFromThirdparty',
278 array(
'authentication'=>
'tns:authentication',
'thirdpartywithuser'=>
'tns:thirdpartywithuser'),
280 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
282 $ns.
'#createUserFromThirdparty',
285 'WS to create an external user with thirdparty and contact'
291 array(
'authentication'=>
'tns:authentication',
'shortuser'=>
'tns:shortuser'),
293 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
295 $ns.
'#setUserPassword',
298 'WS to change password of an user'
313 function getUser($authentication, $id, $ref =
'', $ref_ext =
'')
317 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
319 if ($authentication[
'entity']) {
320 $conf->entity = $authentication[
'entity'];
324 $objectresp = array();
325 $errorcode =
''; $errorlabel =
'';
329 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
331 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
337 if ($fuser->rights->user->user->lire
338 || ($fuser->rights->user->self->creer && $id && $id == $fuser->id)
339 || ($fuser->rights->user->self->creer && $ref && $ref == $fuser->login)
340 || ($fuser->rights->user->self->creer && $ref_ext && $ref_ext == $fuser->ref_ext)) {
341 $user =
new User($db);
342 $result = $user->fetch($id, $ref, $ref_ext);
346 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
349 'lastname' => $user->lastname,
350 'firstname' => $user->firstname,
351 'note' => $user->note,
352 'email' => $user->email,
353 'signature' => $user->signature,
354 'office_phone' => $user->office_phone,
355 'office_fax' => $user->office_fax,
356 'user_mobile' => $user->user_mobile,
357 'admin' => $user->admin,
358 'login' => $user->login,
359 'entity' => $user->entity,
360 'pass_indatabase' => $user->pass_indatabase,
361 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
364 'fk_thirdparty' => $user->socid,
365 'fk_contact' => $user->contact_id,
366 'fk_member' => $user->fk_member,
367 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
368 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
369 'statut' => $user->statut,
370 'photo' => $user->photo,
371 'lang' => $user->lang,
373 'canvas' => $user->canvas
378 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
382 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
387 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
401 global $db, $conf, $user;
403 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
405 if ($authentication[
'entity']) {
406 $conf->entity = $authentication[
'entity'];
410 $objectresp = array();
411 $arraygroups = array();
412 $errorcode =
''; $errorlabel =
'';
418 $sql =
"SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
419 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as g";
420 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
421 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity))) {
422 $sql .=
" WHERE g.entity IS NOT NULL";
424 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
426 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
427 $resql = $db->query($sql);
429 $num = $db->num_rows(
$resql);
433 $obj = $db->fetch_object(
$resql);
434 $arraygroups[] = array(
'id'=>$obj->rowid,
'name'=>$obj->name,
'datec'=>$obj->datec,
'nb'=>$obj->nb);
439 $errorcode = $db->lasterrno();
440 $errorlabel = $db->lasterror();
446 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
447 'groups'=>$arraygroups
451 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
452 'groups'=>$arraygroups
469 global $db, $conf, $langs;
471 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
473 if ($authentication[
'entity']) {
474 $conf->entity = $authentication[
'entity'];
477 $objectresp = array();
478 $errorcode =
''; $errorlabel =
'';
484 $socid = $fuser->socid;
487 if (!$error && !$thirdpartywithuser) {
489 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter thirdparty must be provided.";
495 if ($fuser->rights->societe->creer) {
496 $thirdparty =
new Societe($db);
499 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
500 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
501 $sql .=
" WHERE s.entity=".$conf->entity;
502 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
503 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
504 $sql .= $db->plimit(1);
506 $resql = $db->query($sql);
509 $row = $db->fetch_object(
$resql);
512 $errorcode =
'ALREADY_EXIST'; $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
518 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
519 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
520 $thirdparty->address = $thirdpartywithuser[
'address'];
521 $thirdparty->zip = $thirdpartywithuser[
'zip'];
522 $thirdparty->town = $thirdpartywithuser[
'town'];
523 $thirdparty->country_id = $thirdpartywithuser[
'country_id'];
524 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
527 $langs->load(
"dict");
529 $sql =
"SELECT rowid";
530 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
531 $sql .=
" WHERE active = 1";
532 $sql .=
" AND code='".$db->escape($thirdparty->country_code).
"'";
534 $resql = $db->query($sql);
536 $num = $db->num_rows(
$resql);
538 $obj = $db->fetch_object(
$resql);
539 $thirdparty->country_id = $obj->rowid;
542 $thirdparty->phone = $thirdpartywithuser[
'phone'];
543 $thirdparty->fax = $thirdpartywithuser[
'fax'];
544 $thirdparty->email = $thirdpartywithuser[
'email'];
545 $thirdparty->url = $thirdpartywithuser[
'url'];
546 $thirdparty->ape = $thirdpartywithuser[
'ape'];
547 $thirdparty->idprof1 = $thirdpartywithuser[
'prof1'];
548 $thirdparty->idprof2 = $thirdpartywithuser[
'prof2'];
549 $thirdparty->idprof3 = $thirdpartywithuser[
'prof3'];
550 $thirdparty->idprof4 = $thirdpartywithuser[
'prof4'];
551 $thirdparty->idprof5 = $thirdpartywithuser[
'prof5'];
552 $thirdparty->idprof6 = $thirdpartywithuser[
'prof6'];
554 $thirdparty->client = $thirdpartywithuser[
'client'];
555 $thirdparty->fournisseur = $thirdpartywithuser[
'fournisseur'];
557 $socid_return = $thirdparty->create($fuser);
559 if ($socid_return > 0) {
560 $thirdparty->fetch($socid_return);
567 $contact->socid = $thirdparty->id;
568 $contact->lastname = $thirdpartywithuser[
'name'];
569 $contact->firstname = $thirdpartywithuser[
'firstname'];
570 $contact->civility_id = $thirdparty->civility_id;
571 $contact->address = $thirdparty->address;
572 $contact->zip = $thirdparty->zip;
573 $contact->town = $thirdparty->town;
574 $contact->email = $thirdparty->email;
575 $contact->phone_pro = $thirdparty->phone;
576 $contact->phone_mobile = $thirdpartywithuser[
'phone_mobile'];
577 $contact->fax = $thirdparty->fax;
578 $contact->statut = 1;
579 $contact->country_id = $thirdparty->country_id;
580 $contact->country_code = $thirdparty->country_code;
582 $elementtype =
'socpeople';
587 $extrafields->fetch_name_optionals_label($elementtype,
true);
588 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
589 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
590 $key =
'contact_options_'.$key;
591 $key = substr($key, 8);
592 $contact->array_options[$key] = $thirdpartywithuser[$key];
596 $contact_id = $contact->create($fuser);
598 if ($contact_id > 0) {
603 $edituser =
new User($db);
605 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
607 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
609 if ($thirdpartywithuser[
'group_id'] > 0) {
610 $edituser->SetInGroup($thirdpartywithuser[
'group_id'], $conf->entity);
614 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$edituser->error;
618 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$contact->error;
623 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
'SUCCESS'),
'id'=>$socid_return);
628 $errorcode = join(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
634 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create';
638 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
645 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
665 dol_syslog(
"Function: setUserPassword login=".$authentication[
'login']);
667 if ($authentication[
'entity']) {
668 $conf->entity = $authentication[
'entity'];
671 $objectresp = array();
672 $errorcode =
''; $errorlabel =
'';
678 $socid = $fuser->socid;
681 if (!$error && !$shortuser) {
683 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter shortuser must be provided.";
689 if ($fuser->rights->user->user->password || $fuser->rights->user->self->password) {
690 $userstat =
new User($db);
691 $res = $userstat->fetch(
'', $shortuser[
'login']);
693 $res = $userstat->setPassword($userstat, $shortuser[
'password']);
696 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
700 $errorcode =
'NOT_MODIFIED'; $errorlabel =
'Error when changing password';
704 $errorcode =
'NOT_FOUND'; $errorlabel =
'User not found';
708 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
715 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
723 $server->service(file_get_contents(
"php://input"));
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getUser($authentication, $id, $ref='', $ref_ext='')
Get produt or service.
getListOfGroups($authentication)
getListOfGroups
setUserPassword($authentication, $shortuser)
Set password of an user.
createUserFromThirdparty($authentication, $thirdpartywithuser)
Create an external user with thirdparty and contact.
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.