25if (!defined(
'NOCSRFCHECK')) {
26 define(
'NOCSRFCHECK',
'1');
28if (!defined(
'NOTOKENRENEWAL')) {
29 define(
'NOTOKENRENEWAL',
'1');
31if (!defined(
'NOREQUIREMENU')) {
32 define(
'NOREQUIREMENU',
'1');
34if (!defined(
'NOREQUIREHTML')) {
35 define(
'NOREQUIREHTML',
'1');
37if (!defined(
'NOREQUIREAJAX')) {
38 define(
'NOREQUIREAJAX',
'1');
40if (!defined(
"NOLOGIN")) {
41 define(
"NOLOGIN",
'1');
43if (!defined(
"NOSESSION")) {
44 define(
"NOSESSION",
'1');
47require
'../main.inc.php';
48require_once NUSOAP_PATH.
'/nusoap.php';
49require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
50require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
51require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
52require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
53require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
66 $langs->load(
"admin");
67 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
68 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
69 print $langs->trans(
"ToActivateModule");
74$server =
new nusoap_server();
75$server->soap_defencoding =
'UTF-8';
76$server->decode_utf8 =
false;
77$ns =
'http://www.dolibarr.org/ns/';
78$server->configureWSDL(
'WebServicesDolibarrUser', $ns);
80$server->wsdl->schemaTargetNamespace = $ns;
84$server->wsdl->addComplexType(
91 'dolibarrkey' => array(
'name' =>
'dolibarrkey',
'type' =>
'xsd:string'),
92 'sourceapplication' => array(
'name' =>
'sourceapplication',
'type' =>
'xsd:string'),
93 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
94 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
95 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
100$server->wsdl->addComplexType(
107 'result_code' => array(
'name' =>
'result_code',
'type' =>
'xsd:string'),
108 'result_label' => array(
'name' =>
'result_label',
'type' =>
'xsd:string'),
113$server->wsdl->addComplexType(
120 'element' => array(
'name' =>
'element',
'type' =>
'xsd:string'),
121 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
122 'lastname' => array(
'name' =>
'lastname',
'type' =>
'xsd:string'),
123 'firstname' => array(
'name' =>
'firstname',
'type' =>
'xsd:string'),
124 'note' => array(
'name' =>
'note',
'type' =>
'xsd:string'),
125 'email' => array(
'name' =>
'email',
'type' =>
'xsd:string'),
126 'signature' => array(
'name' =>
'signature',
'type' =>
'xsd:string'),
127 'office_phone' => array(
'name' =>
'office_phone',
'type' =>
'xsd:string'),
128 'office_fax' => array(
'name' =>
'office_fax',
'type' =>
'xsd:string'),
129 'user_mobile' => array(
'name' =>
'user_mobile',
'type' =>
'xsd:string'),
130 'admin' => array(
'name' =>
'admin',
'type' =>
'xsd:string'),
131 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
132 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
133 'pass_indatabase' => array(
'name' =>
'pass_indatabase',
'type' =>
'xsd:string'),
134 'pass_indatabase_crypted' => array(
'name' =>
'pass_indatabase_crypted',
'type' =>
'xsd:string'),
135 'datec' => array(
'name' =>
'datec',
'type' =>
'xsd:dateTime'),
136 'datem' => array(
'name' =>
'datem',
'type' =>
'xsd:dateTime'),
137 'fk_thirdparty' => array(
'name' =>
'fk_thirdparty',
'type' =>
'xsd:string'),
138 'fk_contact' => array(
'name' =>
'fk_contact',
'type' =>
'xsd:string'),
139 'fk_member' => array(
'name' =>
'fk_member',
'type' =>
'xsd:string'),
140 'datelastlogin' => array(
'name' =>
'datelastlogin',
'type' =>
'xsd:dateTime'),
141 'datepreviouslogin' => array(
'name' =>
'datepreviouslogin',
'type' =>
'xsd:dateTime'),
142 'statut' => array(
'name' =>
'statut',
'type' =>
'xsd:string'),
143 'photo' => array(
'name' =>
'photo',
'type' =>
'xsd:string'),
144 'lang' => array(
'name' =>
'lang',
'type' =>
'xsd:string'),
145 'entrepots' => array(
'name' =>
'entrepots',
'type' =>
'xsd:string'),
147 'canvas' => array(
'name' =>
'canvas',
'type' =>
'xsd:string')
152$server->wsdl->addComplexType(
159 'name' => array(
'name' =>
'name',
'type' =>
'xsd:string'),
160 'id' => array(
'name' =>
'id',
'type' =>
'xsd:string'),
161 'datec' => array(
'name' =>
'datec',
'type' =>
'xsd:string'),
162 'nb' => array(
'name' =>
'nb',
'type' =>
'xsd:string')
166$server->wsdl->addComplexType(
174 array(
'ref' =>
'SOAP-ENC:arrayType',
'wsdl:arrayType' =>
'tns:group[]')
179$thirdpartywithuser_fields = array(
181 'name' => array(
'name' =>
'name',
'type' =>
'xsd:string'),
182 'firstname' => array(
'name' =>
'firstname',
'type' =>
'xsd:string'),
183 'name_thirdparty' => array(
'name' =>
'name_thirdparty',
'type' =>
'xsd:string'),
184 'ref_ext' => array(
'name' =>
'ref_ext',
'type' =>
'xsd:string'),
185 'client' => array(
'name' =>
'client',
'type' =>
'xsd:string'),
186 'fournisseur' => array(
'name' =>
'fournisseur',
'type' =>
'xsd:string'),
187 'address' => array(
'name' =>
'address',
'type' =>
'xsd:string'),
188 'zip' => array(
'name' =>
'zip',
'type' =>
'xsd:string'),
189 'town' => array(
'name' =>
'town',
'type' =>
'xsd:string'),
190 'country_id' => array(
'name' =>
'country_id',
'type' =>
'xsd:string'),
191 'country_code' => array(
'name' =>
'country_code',
'type' =>
'xsd:string'),
192 'phone' => array(
'name' =>
'phone',
'type' =>
'xsd:string'),
193 'phone_mobile' => array(
'name' =>
'phone_mobile',
'type' =>
'xsd:string'),
194 'fax' => array(
'name' =>
'fax',
'type' =>
'xsd:string'),
195 'email' => array(
'name' =>
'email',
'type' =>
'xsd:string'),
196 'url' => array(
'name' =>
'url',
'type' =>
'xsd:string'),
197 'profid1' => array(
'name' =>
'profid1',
'type' =>
'xsd:string'),
198 'profid2' => array(
'name' =>
'profid2',
'type' =>
'xsd:string'),
199 'profid3' => array(
'name' =>
'profid3',
'type' =>
'xsd:string'),
200 'profid4' => array(
'name' =>
'profid4',
'type' =>
'xsd:string'),
201 'profid5' => array(
'name' =>
'profid5',
'type' =>
'xsd:string'),
202 'profid6' => array(
'name' =>
'profid6',
'type' =>
'xsd:string'),
203 'capital' => array(
'name' =>
'capital',
'type' =>
'xsd:string'),
204 'tva_assuj' => array(
'name' =>
'tva_assuj',
'type' =>
'xsd:string'),
205 'tva_intra' => array(
'name' =>
'tva_intra',
'type' =>
'xsd:string'),
207 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
208 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
209 'group_id' => array(
'name' =>
'group_id',
'type' =>
'xsd:string')
212$elementtype =
'socpeople';
217$extrafields->fetch_name_optionals_label($elementtype,
true);
218$extrafield_array =
null;
219if (is_array($extrafields->attributes) && $extrafields->attributes[$elementtype][
'count'] > 0) {
220 $extrafield_array = array();
222if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
223 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
224 $type = $extrafields->attributes[$elementtype][
'type'][$key];
225 if ($type ==
'date' || $type ==
'datetime') {
226 $type =
'xsd:dateTime';
228 $type =
'xsd:string';
231 $extrafield_array[
'contact_options_'.$key] = array(
'name' =>
'contact_options_'.$key,
'type' => $type);
235if (is_array($extrafield_array)) {
236 $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
240$server->wsdl->addComplexType(
241 'thirdpartywithuser',
246 $thirdpartywithuser_fields
250$server->wsdl->addComplexType(
257 'login' => array(
'name' =>
'login',
'type' =>
'xsd:string'),
258 'password' => array(
'name' =>
'password',
'type' =>
'xsd:string'),
259 'entity' => array(
'name' =>
'entity',
'type' =>
'xsd:string'),
269$styleuse =
'encoded';
277 array(
'authentication' =>
'tns:authentication',
'id' =>
'xsd:string',
'ref' =>
'xsd:string',
'ref_ext' =>
'xsd:string'),
279 array(
'result' =>
'tns:result',
'user' =>
'tns:user'),
290 array(
'authentication' =>
'tns:authentication'),
292 array(
'result' =>
'tns:result',
'groups' =>
'tns:GroupsArray'),
294 $ns.
'#getListOfGroups',
297 'WS to get list of groups'
301 'createUserFromThirdparty',
303 array(
'authentication' =>
'tns:authentication',
'thirdpartywithuser' =>
'tns:thirdpartywithuser'),
305 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
307 $ns.
'#createUserFromThirdparty',
310 'WS to create an external user with thirdparty and contact'
316 array(
'authentication' =>
'tns:authentication',
'shortuser' =>
'tns:shortuser'),
318 array(
'result' =>
'tns:result',
'id' =>
'xsd:string'),
320 $ns.
'#setUserPassword',
323 'WS to change password of an user'
338function getUser($authentication,
$id, $ref =
'', $ref_ext =
'')
342 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
344 if ($authentication[
'entity']) {
345 $conf->entity = $authentication[
'entity'];
349 $objectresp = array();
355 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
357 $errorcode =
'BAD_PARAMETERS';
358 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
362 $fuser->loadRights();
364 if ($fuser->hasRight(
'user',
'user',
'lire')
365 || ($fuser->hasRight(
'user',
'self',
'creer') &&
$id &&
$id == $fuser->id)
366 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref && $ref == $fuser->login)
367 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref_ext && $ref_ext == $fuser->ref_ext)) {
369 $result = $user->fetch(
$id, $ref, $ref_ext);
373 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
376 'lastname' => $user->lastname,
377 'firstname' => $user->firstname,
378 'note' => $user->note,
379 'email' => $user->email,
380 'signature' => $user->signature,
381 'office_phone' => $user->office_phone,
382 'office_fax' => $user->office_fax,
383 'user_mobile' => $user->user_mobile,
384 'admin' => $user->admin,
385 'login' => $user->login,
386 'entity' => $user->entity,
387 'pass_indatabase' => $user->pass_indatabase,
388 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
391 'fk_thirdparty' => $user->socid,
392 'fk_contact' => $user->contact_id,
393 'fk_member' => $user->fk_member,
394 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
395 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
396 'statut' => (
int) $user->statut,
397 'status' => (
int) $user->status,
398 'photo' => $user->photo,
399 'lang' => $user->lang,
401 'canvas' => $user->canvas
406 $errorcode =
'NOT_FOUND';
407 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
411 $errorcode =
'PERMISSION_DENIED';
412 $errorlabel =
'User does not have permission for this request';
417 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
433 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
435 if ($authentication[
'entity']) {
436 $conf->entity = $authentication[
'entity'];
440 $objectresp = array();
441 $arraygroups = array();
449 $sql =
"SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
450 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as g";
451 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
453 $sql .=
" WHERE g.entity IS NOT NULL";
455 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
457 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
458 $resql =
$db->query($sql);
460 $num =
$db->num_rows($resql);
464 $obj =
$db->fetch_object($resql);
465 $arraygroups[] = array(
'id' => $obj->rowid,
'name' => $obj->name,
'datec' => $obj->datec,
'nb' => $obj->nb);
470 $errorcode =
$db->lasterrno();
471 $errorlabel =
$db->lasterror();
477 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
478 'groups' => $arraygroups
482 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
483 'groups' => $arraygroups
502 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
504 if ($authentication[
'entity']) {
505 $conf->entity = $authentication[
'entity'];
508 $objectresp = array();
516 $socid = $fuser->socid;
519 if (!$error && !$thirdpartywithuser) {
521 $errorcode =
'BAD_PARAMETERS';
522 $errorlabel =
"Parameter thirdparty must be provided.";
526 $fuser->loadRights();
528 if ($fuser->hasRight(
'societe',
'creer')) {
532 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
533 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
534 $sql .=
" WHERE s.entity=".$conf->entity;
535 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
536 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
537 $sql .=
$db->plimit(1);
539 $resql =
$db->query($sql);
542 $row =
$db->fetch_object($resql);
545 $errorcode =
'ALREADY_EXIST';
546 $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
552 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
553 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
554 $thirdparty->address = $thirdpartywithuser[
'address'];
555 $thirdparty->zip = $thirdpartywithuser[
'zip'];
556 $thirdparty->town = $thirdpartywithuser[
'town'];
557 $thirdparty->country_id = (int) $thirdpartywithuser[
'country_id'];
558 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
561 $langs->load(
"dict");
563 $sql =
"SELECT rowid";
564 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
565 $sql .=
" WHERE active = 1";
566 $sql .=
" AND code = '".$db->escape($thirdparty->country_code).
"'";
568 $resql =
$db->query($sql);
570 $num =
$db->num_rows($resql);
572 $obj =
$db->fetch_object($resql);
573 $thirdparty->country_id = $obj->rowid;
576 $thirdparty->phone = $thirdpartywithuser[
'phone'];
577 $thirdparty->fax = $thirdpartywithuser[
'fax'];
578 $thirdparty->email = $thirdpartywithuser[
'email'];
579 $thirdparty->url = $thirdpartywithuser[
'url'];
580 $thirdparty->idprof1 = $thirdpartywithuser[
'profid1'];
581 $thirdparty->idprof2 = $thirdpartywithuser[
'profid2'];
582 $thirdparty->idprof3 = $thirdpartywithuser[
'profid3'];
583 $thirdparty->idprof4 = $thirdpartywithuser[
'profid4'];
584 $thirdparty->idprof5 = $thirdpartywithuser[
'profid5'];
585 $thirdparty->idprof6 = $thirdpartywithuser[
'profid6'];
587 $thirdparty->client = (int) $thirdpartywithuser[
'client'];
588 $thirdparty->fournisseur = (int) $thirdpartywithuser[
'fournisseur'];
590 $socid_return = $thirdparty->create($fuser);
592 if ($socid_return > 0) {
593 $thirdparty->fetch($socid_return);
600 $contact->socid = $thirdparty->id;
601 $contact->lastname = $thirdpartywithuser[
'name'];
602 $contact->firstname = $thirdpartywithuser[
'firstname'];
603 $contact->civility_id = $thirdparty->civility_id;
604 $contact->address = $thirdparty->address;
605 $contact->zip = $thirdparty->zip;
606 $contact->town = $thirdparty->town;
607 $contact->email = $thirdparty->email;
608 $contact->phone_pro = $thirdparty->phone;
609 $contact->phone_mobile = $thirdpartywithuser[
'phone_mobile'];
610 $contact->fax = $thirdparty->fax;
611 $contact->status = 1;
612 $contact->statut = 1;
613 $contact->country_id = $thirdparty->country_id;
614 $contact->country_code = $thirdparty->country_code;
616 $elementtype =
'socpeople';
621 $extrafields->fetch_name_optionals_label($elementtype,
true);
622 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
623 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
624 $key =
'contact_options_'.$key;
625 $key = substr($key, 8);
626 $contact->array_options[$key] = $thirdpartywithuser[$key];
630 $contact_id = $contact->create($fuser);
632 if ($contact_id > 0) {
639 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
641 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
643 if ($thirdpartywithuser[
'group_id'] > 0) {
644 $edituser->SetInGroup((
int) $thirdpartywithuser[
'group_id'],
$conf->entity);
648 $errorcode =
'NOT_CREATE';
649 $errorlabel =
'Object not create : '.$edituser->error;
653 $errorcode =
'NOT_CREATE';
654 $errorlabel =
'Object not create : '.$contact->error;
659 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
'SUCCESS'),
'id' => $socid_return);
663 $errorcode = implode(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
669 $errorcode =
'NOT_CREATE';
670 $errorlabel =
'Object not create';
674 $errorcode =
'PERMISSION_DENIED';
675 $errorlabel =
'User does not have permission for this request';
682 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
701 dol_syslog(
"Function: setUserPassword login=".$authentication[
'login']);
703 if ($authentication[
'entity']) {
704 $conf->entity = $authentication[
'entity'];
707 $objectresp = array();
715 $socid = $fuser->socid;
718 if (!$error && !$shortuser) {
720 $errorcode =
'BAD_PARAMETERS';
721 $errorlabel =
"Parameter shortuser must be provided.";
725 $fuser->loadRights();
727 if ($fuser->hasRight(
'user',
'user',
'password')
728 || ($fuser->hasRight(
'user',
'self',
'password') && $fuser->login == $shortuser[
'login'])) {
730 $res = $userstat->fetch(0, $shortuser[
'login']);
732 $res = $userstat->setPassword($userstat, $shortuser[
'password']);
733 if (is_int($res) && $res < 0) {
735 $errorcode =
'NOT_MODIFIED';
736 $errorlabel =
'Error when changing password';
739 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
744 $errorcode =
'NOT_FOUND';
745 $errorlabel =
'User not found';
749 $errorcode =
'PERMISSION_DENIED';
750 $errorlabel =
'User does not have permission for this request';
757 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
765$server->service(file_get_contents(
"php://input"));
$id
Support class for third parties, contacts, members, users or resources.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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 product 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.