23 if (!defined(
"NOCSRFCHECK")) define(
"NOCSRFCHECK",
'1');
25 require_once
'../master.inc.php';
26 require_once NUSOAP_PATH.
'/nusoap.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ws.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
34 dol_syslog(
"Call User webservices interfaces");
39 if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
41 $langs->load(
"admin");
42 dol_syslog(
"Call Dolibarr webservices interfaces with module webservices disabled");
43 print $langs->trans(
"WarningModuleNotActive",
'WebServices').
'.<br><br>';
44 print $langs->trans(
"ToActivateModule");
49 $server =
new nusoap_server();
50 $server->soap_defencoding =
'UTF-8';
51 $server->decode_utf8 =
false;
52 $ns =
'http://www.dolibarr.org/ns/';
53 $server->configureWSDL(
'WebServicesDolibarrUser', $ns);
54 $server->wsdl->schemaTargetNamespace = $ns;
58 $server->wsdl->addComplexType(
65 'dolibarrkey' => array(
'name'=>
'dolibarrkey',
'type'=>
'xsd:string'),
66 'sourceapplication' => array(
'name'=>
'sourceapplication',
'type'=>
'xsd:string'),
67 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
68 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
69 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
74 $server->wsdl->addComplexType(
81 'result_code' => array(
'name'=>
'result_code',
'type'=>
'xsd:string'),
82 'result_label' => array(
'name'=>
'result_label',
'type'=>
'xsd:string'),
87 $server->wsdl->addComplexType(
94 'element' => array(
'name'=>
'element',
'type'=>
'xsd:string'),
95 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
96 'lastname' => array(
'name'=>
'lastname',
'type'=>
'xsd:string'),
97 'firstname' => array(
'name'=>
'firstname',
'type'=>
'xsd:string'),
98 'note' => array(
'name'=>
'note',
'type'=>
'xsd:string'),
99 'email' => array(
'name'=>
'email',
'type'=>
'xsd:string'),
100 'signature' => array(
'name'=>
'signature',
'type'=>
'xsd:string'),
101 'office_phone' => array(
'name'=>
'office_phone',
'type'=>
'xsd:string'),
102 'office_fax' => array(
'name'=>
'office_fax',
'type'=>
'xsd:string'),
103 'user_mobile' => array(
'name'=>
'user_mobile',
'type'=>
'xsd:string'),
104 'admin' => array(
'name'=>
'admin',
'type'=>
'xsd:string'),
105 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
106 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
107 'pass_indatabase' => array(
'name'=>
'pass_indatabase',
'type'=>
'xsd:string'),
108 'pass_indatabase_crypted' => array(
'name'=>
'pass_indatabase_crypted',
'type'=>
'xsd:string'),
109 'datec' => array(
'name'=>
'datec',
'type'=>
'xsd:dateTime'),
110 'datem' => array(
'name'=>
'datem',
'type'=>
'xsd:dateTime'),
111 'fk_thirdparty' => array(
'name'=>
'fk_thirdparty',
'type'=>
'xsd:string'),
112 'fk_contact' => array(
'name'=>
'fk_contact',
'type'=>
'xsd:string'),
113 'fk_member' => array(
'name'=>
'fk_member',
'type'=>
'xsd:string'),
114 'datelastlogin' => array(
'name'=>
'datelastlogin',
'type'=>
'xsd:dateTime'),
115 'datepreviouslogin' => array(
'name'=>
'datepreviouslogin',
'type'=>
'xsd:dateTime'),
116 'statut' => array(
'name'=>
'statut',
'type'=>
'xsd:string'),
117 'photo' => array(
'name'=>
'photo',
'type'=>
'xsd:string'),
118 'lang' => array(
'name'=>
'lang',
'type'=>
'xsd:string'),
119 'entrepots' => array(
'name'=>
'entrepots',
'type'=>
'xsd:string'),
121 'canvas' => array(
'name'=>
'canvas',
'type'=>
'xsd:string')
126 $server->wsdl->addComplexType(
133 'name' => array(
'name'=>
'name',
'type'=>
'xsd:string'),
134 'id' => array(
'name'=>
'id',
'type'=>
'xsd:string'),
135 'datec' => array(
'name'=>
'datec',
'type'=>
'xsd:string'),
136 'nb' => array(
'name'=>
'nb',
'type'=>
'xsd:string')
140 $server->wsdl->addComplexType(
148 array(
'ref'=>
'SOAP-ENC:arrayType',
'wsdl:arrayType'=>
'tns:group[]')
153 $thirdpartywithuser_fields = array(
155 'name' => array(
'name'=>
'name',
'type'=>
'xsd:string'),
156 'firstname' => array(
'name'=>
'firstname',
'type'=>
'xsd:string'),
157 'name_thirdparty' => array(
'name'=>
'name_thirdparty',
'type'=>
'xsd:string'),
158 'ref_ext' => array(
'name'=>
'ref_ext',
'type'=>
'xsd:string'),
159 'client' => array(
'name'=>
'client',
'type'=>
'xsd:string'),
160 'fournisseur' => array(
'name'=>
'fournisseur',
'type'=>
'xsd:string'),
161 'address' => array(
'name'=>
'address',
'type'=>
'xsd:string'),
162 'zip' => array(
'name'=>
'zip',
'type'=>
'xsd:string'),
163 'town' => array(
'name'=>
'town',
'type'=>
'xsd:string'),
164 'country_id' => array(
'name'=>
'country_id',
'type'=>
'xsd:string'),
165 'country_code' => array(
'name'=>
'country_code',
'type'=>
'xsd:string'),
166 'phone' => array(
'name'=>
'phone',
'type'=>
'xsd:string'),
167 'phone_mobile' => array(
'name'=>
'phone_mobile',
'type'=>
'xsd:string'),
168 'fax' => array(
'name'=>
'fax',
'type'=>
'xsd:string'),
169 'email' => array(
'name'=>
'email',
'type'=>
'xsd:string'),
170 'url' => array(
'name'=>
'url',
'type'=>
'xsd:string'),
171 'profid1' => array(
'name'=>
'profid1',
'type'=>
'xsd:string'),
172 'profid2' => array(
'name'=>
'profid2',
'type'=>
'xsd:string'),
173 'profid3' => array(
'name'=>
'profid3',
'type'=>
'xsd:string'),
174 'profid4' => array(
'name'=>
'profid4',
'type'=>
'xsd:string'),
175 'profid5' => array(
'name'=>
'profid5',
'type'=>
'xsd:string'),
176 'profid6' => array(
'name'=>
'profid6',
'type'=>
'xsd:string'),
177 'capital' => array(
'name'=>
'capital',
'type'=>
'xsd:string'),
178 'tva_assuj' => array(
'name'=>
'tva_assuj',
'type'=>
'xsd:string'),
179 'tva_intra' => array(
'name'=>
'tva_intra',
'type'=>
'xsd:string'),
181 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
182 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
183 'group_id' => array(
'name'=>
'group_id',
'type'=>
'xsd:string')
186 $elementtype =
'socpeople';
191 $extrafields->fetch_name_optionals_label($elementtype,
true);
192 $extrafield_array = null;
193 if (is_array($extrafields) && count($extrafields) > 0) {
194 $extrafield_array = array();
196 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)
200 $type = $extrafields->attributes[$elementtype][
'type'][$key];
201 if ($type ==
'date' || $type ==
'datetime') {$type =
'xsd:dateTime'; }
202 else {$type =
'xsd:string'; }
204 $extrafield_array[
'contact_options_'.$key] = array(
'name'=>
'contact_options_'.$key,
'type'=>$type);
208 if (is_array($extrafield_array)) $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
211 $server->wsdl->addComplexType(
212 'thirdpartywithuser',
217 $thirdpartywithuser_fields
221 $server->wsdl->addComplexType(
228 'login' => array(
'name'=>
'login',
'type'=>
'xsd:string'),
229 'password' => array(
'name'=>
'password',
'type'=>
'xsd:string'),
230 'entity' => array(
'name'=>
'entity',
'type'=>
'xsd:string'),
240 $styleuse =
'encoded';
248 array(
'authentication'=>
'tns:authentication',
'id'=>
'xsd:string',
'ref'=>
'xsd:string',
'ref_ext'=>
'xsd:string'),
250 array(
'result'=>
'tns:result',
'user'=>
'tns:user'),
261 array(
'authentication'=>
'tns:authentication'),
263 array(
'result'=>
'tns:result',
'groups'=>
'tns:GroupsArray'),
265 $ns.
'#getListOfGroups',
268 'WS to get list of groups'
272 'createUserFromThirdparty',
274 array(
'authentication'=>
'tns:authentication',
'thirdpartywithuser'=>
'tns:thirdpartywithuser'),
276 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
278 $ns.
'#createUserFromThirdparty',
281 'WS to create an external user with thirdparty and contact'
287 array(
'authentication'=>
'tns:authentication',
'shortuser'=>
'tns:shortuser'),
289 array(
'result'=>
'tns:result',
'id'=>
'xsd:string'),
291 $ns.
'#setUserPassword',
294 'WS to change password of an user'
309 function getUser($authentication, $id, $ref =
'', $ref_ext =
'')
313 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
315 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
318 $objectresp = array();
319 $errorcode =
''; $errorlabel =
'';
323 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
326 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
333 if ($fuser->rights->user->user->lire
334 || ($fuser->rights->user->self->creer && $id && $id == $fuser->id)
335 || ($fuser->rights->user->self->creer && $ref && $ref == $fuser->login)
336 || ($fuser->rights->user->self->creer && $ref_ext && $ref_ext == $fuser->ref_ext))
338 $user =
new User($db);
339 $result = $user->fetch($id, $ref, $ref_ext);
344 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
347 'lastname' => $user->lastname,
348 'firstname' => $user->firstname,
349 'note' => $user->note,
350 'email' => $user->email,
351 'signature' => $user->signature,
352 'office_phone' => $user->office_phone,
353 'office_fax' => $user->office_fax,
354 'user_mobile' => $user->user_mobile,
355 'admin' => $user->admin,
356 'login' => $user->login,
357 'entity' => $user->entity,
358 'pass_indatabase' => $user->pass_indatabase,
359 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
362 'fk_thirdparty' => $user->socid,
363 'fk_contact' => $user->contact_id,
364 'fk_member' => $user->fk_member,
365 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
366 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
367 'statut' => $user->statut,
368 'photo' => $user->photo,
369 'lang' => $user->lang,
371 'canvas' => $user->canvas
377 $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';
388 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
404 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
406 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
409 $objectresp = array();
410 $arraygroups = array();
411 $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 (!empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity)))
423 $sql .=
" WHERE g.entity IS NOT NULL";
426 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
428 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
429 $resql = $db->query($sql);
432 $num = $db->num_rows(
$resql);
437 $obj = $db->fetch_object(
$resql);
438 $arraygroups[] = array(
'id'=>$obj->rowid,
'name'=>$obj->name,
'datec'=>$obj->datec,
'nb'=>$obj->nb);
444 $errorcode = $db->lasterrno();
445 $errorlabel = $db->lasterror();
452 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
453 'groups'=>$arraygroups
458 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
459 'groups'=>$arraygroups
476 global $db, $conf, $langs;
478 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
480 if ($authentication[
'entity']) $conf->entity = $authentication[
'entity'];
482 $objectresp = array();
483 $errorcode =
''; $errorlabel =
'';
488 if ($fuser->socid) $socid = $fuser->socid;
490 if (!$error && !$thirdpartywithuser)
493 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter thirdparty must be provided.";
500 if ($fuser->rights->societe->creer)
502 $thirdparty =
new Societe($db);
505 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
506 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
507 $sql .=
" WHERE s.entity=".$conf->entity;
508 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
509 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
510 $sql .= $db->plimit(1);
512 $resql = $db->query($sql);
516 $row = $db->fetch_object(
$resql);
520 $errorcode =
'ALREADY_EXIST'; $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
527 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
528 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
529 $thirdparty->address = $thirdpartywithuser[
'address'];
530 $thirdparty->zip = $thirdpartywithuser[
'zip'];
531 $thirdparty->town = $thirdpartywithuser[
'town'];
532 $thirdparty->country_id = $thirdpartywithuser[
'country_id'];
533 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
536 $langs->load(
"dict");
538 $sql =
"SELECT rowid";
539 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
540 $sql .=
" WHERE active = 1";
541 $sql .=
" AND code='".$db->escape($thirdparty->country_code).
"'";
543 $resql = $db->query($sql);
546 $num = $db->num_rows(
$resql);
549 $obj = $db->fetch_object(
$resql);
550 $thirdparty->country_id = $obj->rowid;
553 $thirdparty->phone = $thirdpartywithuser[
'phone'];
554 $thirdparty->fax = $thirdpartywithuser[
'fax'];
555 $thirdparty->email = $thirdpartywithuser[
'email'];
556 $thirdparty->url = $thirdpartywithuser[
'url'];
557 $thirdparty->ape = $thirdpartywithuser[
'ape'];
558 $thirdparty->idprof1 = $thirdpartywithuser[
'prof1'];
559 $thirdparty->idprof2 = $thirdpartywithuser[
'prof2'];
560 $thirdparty->idprof3 = $thirdpartywithuser[
'prof3'];
561 $thirdparty->idprof4 = $thirdpartywithuser[
'prof4'];
562 $thirdparty->idprof5 = $thirdpartywithuser[
'prof5'];
563 $thirdparty->idprof6 = $thirdpartywithuser[
'prof6'];
565 $thirdparty->client = $thirdpartywithuser[
'client'];
566 $thirdparty->fournisseur = $thirdpartywithuser[
'fournisseur'];
568 $socid_return = $thirdparty->create($fuser);
570 if ($socid_return > 0)
572 $thirdparty->fetch($socid_return);
579 $contact->socid = $thirdparty->id;
580 $contact->lastname = $thirdpartywithuser[
'name'];
581 $contact->firstname = $thirdpartywithuser[
'firstname'];
582 $contact->civility_id = $thirdparty->civility_id;
583 $contact->address = $thirdparty->address;
584 $contact->zip = $thirdparty->zip;
585 $contact->town = $thirdparty->town;
586 $contact->email = $thirdparty->email;
587 $contact->phone_pro = $thirdparty->phone;
588 $contact->phone_mobile = $thirdpartywithuser[
'phone_mobile'];
589 $contact->fax = $thirdparty->fax;
590 $contact->statut = 1;
591 $contact->country_id = $thirdparty->country_id;
592 $contact->country_code = $thirdparty->country_code;
594 $elementtype =
'socpeople';
599 $extrafields->fetch_name_optionals_label($elementtype,
true);
600 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label']))
602 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label)
604 $key =
'contact_options_'.$key;
605 $key = substr($key, 8);
606 $contact->array_options[$key] = $thirdpartywithuser[$key];
610 $contact_id = $contact->create($fuser);
618 $edituser =
new User($db);
620 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
623 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
625 if ($thirdpartywithuser[
'group_id'] > 0)
626 $edituser->SetInGroup($thirdpartywithuser[
'group_id'], $conf->entity);
630 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$edituser->error;
635 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$contact->error;
640 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
'SUCCESS'),
'id'=>$socid_return);
645 $errorcode = join(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
651 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create';
655 $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']) $conf->entity = $authentication[
'entity'];
687 $objectresp = array();
688 $errorcode =
''; $errorlabel =
'';
693 if ($fuser->socid) $socid = $fuser->socid;
695 if (!$error && !$shortuser)
698 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter shortuser must be provided.";
705 if ($fuser->rights->user->user->password || $fuser->rights->user->self->password)
707 $userstat =
new User($db);
708 $res = $userstat->fetch(
'', $shortuser[
'login']);
711 $res = $userstat->setPassword($userstat, $shortuser[
'password']);
715 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
720 $errorcode =
'NOT_MODIFIED'; $errorlabel =
'Error when changing password';
725 $errorcode =
'NOT_FOUND'; $errorlabel =
'User not found';
730 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
738 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
746 $server->service(file_get_contents(
"php://input"));
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
getUser($authentication, $id, $ref= '', $ref_ext= '')
Get produt or service.
Class to manage Dolibarr users.
getListOfGroups($authentication)
getListOfGroups
createUserFromThirdparty($authentication, $thirdpartywithuser)
Create an external user with thirdparty and contact.
setUserPassword($authentication, $shortuser)
Set password of an user.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.