23 if (!defined(
'NOCSRFCHECK')) {
24 define(
'NOCSRFCHECK',
'1');
26 if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL',
'1');
29 if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32 if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
35 if (!defined(
'NOREQUIREAJAX')) {
36 define(
'NOREQUIREAJAX',
'1');
38 if (!defined(
"NOLOGIN")) {
39 define(
"NOLOGIN",
'1');
41 if (!defined(
"NOSESSION")) {
42 define(
"NOSESSION",
'1');
45 require
'../main.inc.php';
46 require_once NUSOAP_PATH.
'/nusoap.php';
47 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
48 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
54 dol_syslog(
"Call User webservices interfaces");
59 if (empty($conf->global->MAIN_MODULE_WEBSERVICES)) {
60 $langs->load(
"admin");
61 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
62 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
63 print $langs->trans(
"ToActivateModule");
68 $server =
new nusoap_server();
69 $server->soap_defencoding =
'UTF-8';
70 $server->decode_utf8 =
false;
71 $ns =
'http://www.dolibarr.org/ns/';
72 $server->configureWSDL(
'WebServicesDolibarrUser', $ns);
73 $server->wsdl->schemaTargetNamespace = $ns;
77 $server->wsdl->addComplexType(
84 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
85 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
86 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
87 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
88 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
93 $server->wsdl->addComplexType(
100 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
101 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
106 $server->wsdl->addComplexType(
113 'element' => array(
'name'=>
'element',
'type'=>
'xsd:string'),
114 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
115 'lastname' => array(
'name'=>
'lastname',
'type'=>
'xsd:string'),
116 'firstname' => array(
'name'=>
'firstname',
'type'=>
'xsd:string'),
117 'note' => array(
'name'=>
'note',
'type'=>
'xsd:string'),
118 'email' => array(
'name'=>
'email',
'type'=>
'xsd:string'),
119 'signature' => array(
'name'=>
'signature',
'type'=>
'xsd:string'),
120 'office_phone' => array(
'name'=>
'office_phone',
'type'=>
'xsd:string'),
121 'office_fax' => array(
'name'=>
'office_fax',
'type'=>
'xsd:string'),
122 'user_mobile' => array(
'name'=>
'user_mobile',
'type'=>
'xsd:string'),
123 'admin' => array(
'name'=>
'admin',
'type'=>
'xsd:string'),
124 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
125 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
126 'pass_indatabase' => array(
'name'=>
'pass_indatabase',
'type'=>
'xsd:string'),
127 'pass_indatabase_crypted' => array(
'name'=>
'pass_indatabase_crypted',
'type'=>
'xsd:string'),
128 'datec' => array(
'name'=>
'datec',
'type'=>
'xsd:dateTime'),
129 'datem' => array(
'name'=>
'datem',
'type'=>
'xsd:dateTime'),
130 'fk_thirdparty' => array(
'name'=>
'fk_thirdparty',
'type'=>
'xsd:string'),
131 'fk_contact' => array(
'name'=>
'fk_contact',
'type'=>
'xsd:string'),
132 'fk_member' => array(
'name'=>
'fk_member',
'type'=>
'xsd:string'),
133 'datelastlogin' => array(
'name'=>
'datelastlogin',
'type'=>
'xsd:dateTime'),
134 'datepreviouslogin' => array(
'name'=>
'datepreviouslogin',
'type'=>
'xsd:dateTime'),
135 'statut' => array(
'name'=>
'statut',
'type'=>
'xsd:string'),
136 'photo' => array(
'name'=>
'photo',
'type'=>
'xsd:string'),
137 'lang' => array(
'name'=>
'lang',
'type'=>
'xsd:string'),
138 'entrepots' => array(
'name'=>
'entrepots',
'type'=>
'xsd:string'),
140 'canvas' => array(
'name'=>
'canvas',
'type'=>
'xsd:string')
145 $server->wsdl->addComplexType(
152 'name' => array(
'name'=>
'name',
'type'=>
'xsd:string'),
153 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
154 'datec' => array(
'name'=>
'datec',
'type'=>
'xsd:string'),
155 'nb' => array(
'name'=>
'nb',
'type'=>
'xsd:string')
159 $server->wsdl->addComplexType(
167 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:group[]')
172 $thirdpartywithuser_fields = array(
174 'name' => array(
'name'=>
'name',
'type'=>
'xsd:string'),
175 'firstname' => array(
'name'=>
'firstname',
'type'=>
'xsd:string'),
176 'name_thirdparty' => array(
'name'=>
'name_thirdparty',
'type'=>
'xsd:string'),
177 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
178 'client' => array(
'name'=>
'client',
'type'=>
'xsd:string'),
179 'fournisseur' => array(
'name'=>
'fournisseur',
'type'=>
'xsd:string'),
180 'address' => array(
'name'=>
'address',
'type'=>
'xsd:string'),
181 'zip' => array(
'name'=>
'zip',
'type'=>
'xsd:string'),
182 'town' => array(
'name'=>
'town',
'type'=>
'xsd:string'),
183 'country_id' => array(
'name'=>
'country_id',
'type'=>
'xsd:string'),
184 'country_code' => array(
'name'=>
'country_code',
'type'=>
'xsd:string'),
185 'phone' => array(
'name'=>
'phone',
'type'=>
'xsd:string'),
186 'phone_mobile' => array(
'name'=>
'phone_mobile',
'type'=>
'xsd:string'),
187 'fax' => array(
'name'=>
'fax',
'type'=>
'xsd:string'),
188 'email' => array(
'name'=>
'email',
'type'=>
'xsd:string'),
189 'url' => array(
'name'=>
'url',
'type'=>
'xsd:string'),
190 'profid1' => array(
'name'=>
'profid1',
'type'=>
'xsd:string'),
191 'profid2' => array(
'name'=>
'profid2',
'type'=>
'xsd:string'),
192 'profid3' => array(
'name'=>
'profid3',
'type'=>
'xsd:string'),
193 'profid4' => array(
'name'=>
'profid4',
'type'=>
'xsd:string'),
194 'profid5' => array(
'name'=>
'profid5',
'type'=>
'xsd:string'),
195 'profid6' => array(
'name'=>
'profid6',
'type'=>
'xsd:string'),
196 'capital' => array(
'name'=>
'capital',
'type'=>
'xsd:string'),
197 'tva_assuj' => array(
'name'=>
'tva_assuj',
'type'=>
'xsd:string'),
198 'tva_intra' => array(
'name'=>
'tva_intra',
'type'=>
'xsd:string'),
200 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
201 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
202 'group_id' => array(
'name'=>
'group_id',
'type'=>
'xsd:string')
205 $elementtype =
'socpeople';
210 $extrafields->fetch_name_optionals_label($elementtype,
true);
211 $extrafield_array =
null;
212 if (is_array($extrafields) && count($extrafields) > 0) {
213 $extrafield_array = array();
215 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
216 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
217 $type = $extrafields->attributes[$elementtype][
'type'][$key];
218 if ($type ==
'date' || $type ==
'datetime') {
219 $type =
'xsd:dateTime';
221 $type =
'xsd:string';
224 $extrafield_array[
'contact_options_'.$key] = array(
'name'=>
'contact_options_'.$key,
'type'=>$type);
228 if (is_array($extrafield_array)) {
229 $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
233 $server->wsdl->addComplexType(
234 'thirdpartywithuser',
239 $thirdpartywithuser_fields
243 $server->wsdl->addComplexType(
250 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
251 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
252 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
262 $styleuse =
'encoded';
270 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string',
'ref_ext'=>
'xsd:string'),
272 array(
'result'=>
'tns:result',
'user'=>
'tns:user'),
283 array(
'authentication'=>
'tns:authentication'),
285 array(
'result'=>
'tns:result',
'groups'=>
'tns:GroupsArray'),
287 $ns.
'#getListOfGroups',
290 'WS to get list of groups'
294 'createUserFromThirdparty',
296 array(
'authentication'=>
'tns:authentication',
'thirdpartywithuser'=>
'tns:thirdpartywithuser'),
298 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
300 $ns.
'#createUserFromThirdparty',
303 'WS to create an external user with thirdparty and contact'
309 array(
'authentication'=>
'tns:authentication',
'shortuser'=>
'tns:shortuser'),
311 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
313 $ns.
'#setUserPassword',
316 'WS to change password of an user'
331 function getUser($authentication, $id, $ref =
'', $ref_ext =
'')
335 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
337 if ($authentication[
'entity']) {
338 $conf->entity = $authentication[
'entity'];
342 $objectresp = array();
343 $errorcode =
''; $errorlabel =
'';
347 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
349 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
355 if ($fuser->rights->user->user->lire
356 || ($fuser->rights->user->self->creer && $id && $id == $fuser->id)
357 || ($fuser->rights->user->self->creer && $ref && $ref == $fuser->login)
358 || ($fuser->rights->user->self->creer && $ref_ext && $ref_ext == $fuser->ref_ext)) {
359 $user =
new User($db);
360 $result = $user->fetch($id, $ref, $ref_ext);
364 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
367 'lastname' => $user->lastname,
368 'firstname' => $user->firstname,
369 'note' => $user->note,
370 'email' => $user->email,
371 'signature' => $user->signature,
372 'office_phone' => $user->office_phone,
373 'office_fax' => $user->office_fax,
374 'user_mobile' => $user->user_mobile,
375 'admin' => $user->admin,
376 'login' => $user->login,
377 'entity' => $user->entity,
378 'pass_indatabase' => $user->pass_indatabase,
379 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
382 'fk_thirdparty' => $user->socid,
383 'fk_contact' => $user->contact_id,
384 'fk_member' => $user->fk_member,
385 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
386 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
387 'statut' => $user->statut,
388 'photo' => $user->photo,
389 'lang' => $user->lang,
391 'canvas' => $user->canvas
396 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
400 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
405 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
419 global $db, $conf, $user;
421 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
423 if ($authentication[
'entity']) {
424 $conf->entity = $authentication[
'entity'];
428 $objectresp = array();
429 $arraygroups = array();
430 $errorcode =
''; $errorlabel =
'';
436 $sql =
"SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as g";
438 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
439 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity))) {
440 $sql .=
" WHERE g.entity IS NOT NULL";
442 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
444 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
445 $resql = $db->query(
$sql);
447 $num = $db->num_rows($resql);
451 $obj = $db->fetch_object($resql);
452 $arraygroups[] = array(
'id'=>$obj->rowid,
'name'=>$obj->name,
'datec'=>$obj->datec,
'nb'=>$obj->nb);
457 $errorcode = $db->lasterrno();
458 $errorlabel = $db->lasterror();
464 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
465 'groups'=>$arraygroups
469 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
470 'groups'=>$arraygroups
487 global $db, $conf, $langs;
489 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
491 if ($authentication[
'entity']) {
492 $conf->entity = $authentication[
'entity'];
495 $objectresp = array();
496 $errorcode =
''; $errorlabel =
'';
502 $socid = $fuser->socid;
505 if (!$error && !$thirdpartywithuser) {
507 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter thirdparty must be provided.";
513 if ($fuser->rights->societe->creer) {
514 $thirdparty =
new Societe($db);
517 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
518 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
519 $sql .=
" WHERE s.entity=".$conf->entity;
520 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
521 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
522 $sql .= $db->plimit(1);
524 $resql = $db->query(
$sql);
527 $row = $db->fetch_object($resql);
530 $errorcode =
'ALREADY_EXIST'; $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
536 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
537 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
538 $thirdparty->address = $thirdpartywithuser[
'address'];
539 $thirdparty->zip = $thirdpartywithuser[
'zip'];
540 $thirdparty->town = $thirdpartywithuser[
'town'];
541 $thirdparty->country_id = $thirdpartywithuser[
'country_id'];
542 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
545 $langs->load(
"dict");
547 $sql =
"SELECT rowid";
548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
549 $sql .=
" WHERE active = 1";
550 $sql .=
" AND code='".$db->escape($thirdparty->country_code).
"'";
552 $resql = $db->query(
$sql);
554 $num = $db->num_rows($resql);
556 $obj = $db->fetch_object($resql);
557 $thirdparty->country_id = $obj->rowid;
560 $thirdparty->phone = $thirdpartywithuser[
'phone'];
561 $thirdparty->fax = $thirdpartywithuser[
'fax'];
562 $thirdparty->email = $thirdpartywithuser[
'email'];
563 $thirdparty->url = $thirdpartywithuser[
'url'];
564 $thirdparty->ape = $thirdpartywithuser[
'ape'];
565 $thirdparty->idprof1 = $thirdpartywithuser[
'prof1'];
566 $thirdparty->idprof2 = $thirdpartywithuser[
'prof2'];
567 $thirdparty->idprof3 = $thirdpartywithuser[
'prof3'];
568 $thirdparty->idprof4 = $thirdpartywithuser[
'prof4'];
569 $thirdparty->idprof5 = $thirdpartywithuser[
'prof5'];
570 $thirdparty->idprof6 = $thirdpartywithuser[
'prof6'];
572 $thirdparty->client = $thirdpartywithuser[
'client'];
573 $thirdparty->fournisseur = $thirdpartywithuser[
'fournisseur'];
575 $socid_return = $thirdparty->create($fuser);
577 if ($socid_return > 0) {
578 $thirdparty->fetch($socid_return);
585 $contact->socid = $thirdparty->id;
586 $contact->lastname = $thirdpartywithuser[
'name'];
587 $contact->firstname = $thirdpartywithuser[
'firstname'];
588 $contact->civility_id = $thirdparty->civility_id;
589 $contact->address = $thirdparty->address;
590 $contact->zip = $thirdparty->zip;
591 $contact->town = $thirdparty->town;
592 $contact->email = $thirdparty->email;
593 $contact->phone_pro = $thirdparty->phone;
594 $contact->phone_mobile = $thirdpartywithuser[
'phone_mobile'];
595 $contact->fax = $thirdparty->fax;
596 $contact->statut = 1;
597 $contact->country_id = $thirdparty->country_id;
598 $contact->country_code = $thirdparty->country_code;
600 $elementtype =
'socpeople';
605 $extrafields->fetch_name_optionals_label($elementtype,
true);
606 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
607 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
608 $key =
'contact_options_'.$key;
609 $key = substr($key, 8);
610 $contact->array_options[$key] = $thirdpartywithuser[$key];
614 $contact_id = $contact->create($fuser);
616 if ($contact_id > 0) {
621 $edituser =
new User($db);
623 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
625 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
627 if ($thirdpartywithuser[
'group_id'] > 0) {
628 $edituser->SetInGroup($thirdpartywithuser[
'group_id'], $conf->entity);
632 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$edituser->error;
636 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$contact->error;
641 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
'SUCCESS'),
'id'=>$socid_return);
646 $errorcode = join(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
652 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create';
656 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
663 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
683 dol_syslog(
"Function: setUserPassword login=".$authentication[
'login']);
685 if ($authentication[
'entity']) {
686 $conf->entity = $authentication[
'entity'];
689 $objectresp = array();
690 $errorcode =
''; $errorlabel =
'';
696 $socid = $fuser->socid;
699 if (!$error && !$shortuser) {
701 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter shortuser must be provided.";
707 if ($fuser->rights->user->user->password || $fuser->rights->user->self->password) {
708 $userstat =
new User($db);
709 $res = $userstat->fetch(
'', $shortuser[
'login']);
711 $res = $userstat->setPassword($userstat, $shortuser[
'password']);
712 if (is_numeric($res) && $res < 0) {
714 $errorcode =
'NOT_MODIFIED'; $errorlabel =
'Error when changing password';
717 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
722 $errorcode =
'NOT_FOUND'; $errorlabel =
'User not found';
726 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
733 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
741 $server->service(file_get_contents(
"php://input"));
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
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.