dolibarr  16.0.5
server_user.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
23 if (!defined("NOCSRFCHECK")) {
24  define("NOCSRFCHECK", '1');
25 }
26 
27 require_once '../master.inc.php';
28 require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
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';
34 
35 
36 dol_syslog("Call User webservices interfaces");
37 
38 $langs->load("main");
39 
40 // Enable and test if module web services is enabled
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");
46  exit;
47 }
48 
49 // Create the soap Object
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;
56 
57 
58 // Define WSDL Authentication object
59 $server->wsdl->addComplexType(
60  'authentication',
61  'complexType',
62  'struct',
63  'all',
64  '',
65  array(
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'),
71  )
72 );
73 
74 // Define WSDL Return object
75 $server->wsdl->addComplexType(
76  'result',
77  'complexType',
78  'struct',
79  'all',
80  '',
81  array(
82  'result_code' => array('name'=>'result_code', 'type'=>'xsd:string'),
83  'result_label' => array('name'=>'result_label', 'type'=>'xsd:string'),
84  )
85 );
86 
87 // Define other specific objects
88 $server->wsdl->addComplexType(
89  'user',
90  'complexType',
91  'struct',
92  'all',
93  '',
94  array(
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'),
121  //'rights' => array('name'=>'rights','type'=>'xsd:string'),
122  'canvas' => array('name'=>'canvas', 'type'=>'xsd:string')
123  )
124 );
125 
126 // Define other specific objects
127 $server->wsdl->addComplexType(
128  'group',
129  'complexType',
130  'struct',
131  'all',
132  '',
133  array(
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')
138  )
139 );
140 
141 $server->wsdl->addComplexType(
142  'GroupsArray',
143  'complexType',
144  'array',
145  '',
146  'SOAP-ENC:Array',
147  array(),
148  array(
149  array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'tns:group[]')
150  ),
151  'tns:group'
152 );
153 
154 $thirdpartywithuser_fields = array(
155  // For thirdparty and contact
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'),
181  // For user
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')
185 );
186 
187 $elementtype = 'socpeople';
188 
189 //Retrieve all extrafield for contact
190 // fetch optionals attributes and labels
191 $extrafields = new ExtraFields($db);
192 $extrafields->fetch_name_optionals_label($elementtype, true);
193 $extrafield_array = null;
194 if (is_array($extrafields) && count($extrafields) > 0) {
195  $extrafield_array = array();
196 }
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';
202  } else {
203  $type = 'xsd:string';
204  }
205 
206  $extrafield_array['contact_options_'.$key] = array('name'=>'contact_options_'.$key, 'type'=>$type);
207  }
208 }
209 
210 if (is_array($extrafield_array)) {
211  $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
212 }
213 
214 
215 $server->wsdl->addComplexType(
216  'thirdpartywithuser',
217  'complexType',
218  'struct',
219  'all',
220  '',
221  $thirdpartywithuser_fields
222 );
223 
224 // Define WSDL user short object
225 $server->wsdl->addComplexType(
226  'shortuser',
227  'complexType',
228  'struct',
229  'all',
230  '',
231  array(
232  'login' => array('name'=>'login', 'type'=>'xsd:string'),
233  'password' => array('name'=>'password', 'type'=>'xsd:string'),
234  'entity' => array('name'=>'entity', 'type'=>'xsd:string'),
235  )
236 );
237 
238 
239 
240 // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
241 // Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
242 // http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
243 $styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
244 $styleuse = 'encoded'; // encoded/literal/literal wrapped
245 // Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
246 
247 
248 // Register WSDL
249 $server->register(
250  'getUser',
251  // Entry values
252  array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'),
253  // Exit values
254  array('result'=>'tns:result', 'user'=>'tns:user'),
255  $ns,
256  $ns.'#getUser',
257  $styledoc,
258  $styleuse,
259  'WS to get user'
260 );
261 
262 $server->register(
263  'getListOfGroups',
264  // Entry values
265  array('authentication'=>'tns:authentication'),
266  // Exit values
267  array('result'=>'tns:result', 'groups'=>'tns:GroupsArray'),
268  $ns,
269  $ns.'#getListOfGroups',
270  $styledoc,
271  $styleuse,
272  'WS to get list of groups'
273 );
274 
275 $server->register(
276  'createUserFromThirdparty',
277  // Entry values
278  array('authentication'=>'tns:authentication', 'thirdpartywithuser'=>'tns:thirdpartywithuser'),
279  // Exit values
280  array('result'=>'tns:result', 'id'=>'xsd:string'),
281  $ns,
282  $ns.'#createUserFromThirdparty',
283  $styledoc,
284  $styleuse,
285  'WS to create an external user with thirdparty and contact'
286 );
287 
288 $server->register(
289  'setUserPassword',
290  // Entry values
291  array('authentication'=>'tns:authentication', 'shortuser'=>'tns:shortuser'),
292  // Exit values
293  array('result'=>'tns:result', 'id'=>'xsd:string'),
294  $ns,
295  $ns.'#setUserPassword',
296  $styledoc,
297  $styleuse,
298  'WS to change password of an user'
299 );
300 
301 
302 
303 
313 function getUser($authentication, $id, $ref = '', $ref_ext = '')
314 {
315  global $db, $conf;
316 
317  dol_syslog("Function: getUser login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
318 
319  if ($authentication['entity']) {
320  $conf->entity = $authentication['entity'];
321  }
322 
323  // Init and check authentication
324  $objectresp = array();
325  $errorcode = ''; $errorlabel = '';
326  $error = 0;
327  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
328  // Check parameters
329  if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
330  $error++;
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.";
332  }
333 
334  if (!$error) {
335  $fuser->getrights();
336 
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);
343  if ($result > 0) {
344  // Create
345  $objectresp = array(
346  'result'=>array('result_code'=>'OK', 'result_label'=>''),
347  'user'=>array(
348  'id' => $user->id,
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,
362  'datec' => dol_print_date($user->datec, 'dayhourrfc'),
363  'datem' => dol_print_date($user->datem, 'dayhourrfc'),
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,
372  //'rights' => $user->rights,
373  'canvas' => $user->canvas
374  )
375  );
376  } else {
377  $error++;
378  $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
379  }
380  } else {
381  $error++;
382  $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
383  }
384  }
385 
386  if ($error) {
387  $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
388  }
389 
390  return $objectresp;
391 }
392 
399 function getListOfGroups($authentication)
400 {
401  global $db, $conf;
402 
403  dol_syslog("Function: getListOfGroups login=".$authentication['login']);
404 
405  if ($authentication['entity']) {
406  $conf->entity = $authentication['entity'];
407  }
408 
409  // Init and check authentication
410  $objectresp = array();
411  $arraygroups = array();
412  $errorcode = ''; $errorlabel = '';
413  $error = 0;
414  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
415  // Check parameters
416 
417  if (!$error) {
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 || ($fuser->admin && !$fuser->entity))) {
422  $sql .= " WHERE g.entity IS NOT NULL";
423  } else {
424  $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
425  }
426  $sql .= " GROUP BY g.rowid, g.nom, g.entity, g.datec";
427  $resql = $db->query($sql);
428  if ($resql) {
429  $num = $db->num_rows($resql);
430 
431  $i = 0;
432  while ($i < $num) {
433  $obj = $db->fetch_object($resql);
434  $arraygroups[] = array('id'=>$obj->rowid, 'name'=>$obj->name, 'datec'=>$obj->datec, 'nb'=>$obj->nb);
435  $i++;
436  }
437  } else {
438  $error++;
439  $errorcode = $db->lasterrno();
440  $errorlabel = $db->lasterror();
441  }
442  }
443 
444  if ($error) {
445  $objectresp = array(
446  'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
447  'groups'=>$arraygroups
448  );
449  } else {
450  $objectresp = array(
451  'result'=>array('result_code' => 'OK', 'result_label' => ''),
452  'groups'=>$arraygroups
453  );
454  }
455 
456  return $objectresp;
457 }
458 
459 
467 function createUserFromThirdparty($authentication, $thirdpartywithuser)
468 {
469  global $db, $conf, $langs;
470 
471  dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']);
472 
473  if ($authentication['entity']) {
474  $conf->entity = $authentication['entity'];
475  }
476 
477  $objectresp = array();
478  $errorcode = ''; $errorlabel = '';
479  $error = 0;
480 
481  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
482 
483  if ($fuser->socid) {
484  $socid = $fuser->socid;
485  }
486 
487  if (!$error && !$thirdpartywithuser) {
488  $error++;
489  $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter thirdparty must be provided.";
490  }
491 
492  if (!$error) {
493  $fuser->getrights();
494 
495  if ($fuser->rights->societe->creer) {
496  $thirdparty = new Societe($db);
497 
498  // If a contact / company already exists with the email, return the corresponding socid
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);
505 
506  $resql = $db->query($sql);
507  if ($resql) {
508  // If a company or contact is found with the same email we return an error
509  $row = $db->fetch_object($resql);
510  if ($row) {
511  $error++;
512  $errorcode = 'ALREADY_EXIST'; $errorlabel = 'Object not create : company or contact exists '.$thirdpartywithuser['email'];
513  } else {
514  $db->begin();
515  /*
516  * Company creation
517  */
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'];
525 
526  // find the country id by code
527  $langs->load("dict");
528 
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)."'";
533 
534  $resql = $db->query($sql);
535  if ($resql) {
536  $num = $db->num_rows($resql);
537  if ($num) {
538  $obj = $db->fetch_object($resql);
539  $thirdparty->country_id = $obj->rowid;
540  }
541  }
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'];
553 
554  $thirdparty->client = $thirdpartywithuser['client'];
555  $thirdparty->fournisseur = $thirdpartywithuser['fournisseur'];
556 
557  $socid_return = $thirdparty->create($fuser);
558 
559  if ($socid_return > 0) {
560  $thirdparty->fetch($socid_return);
561 
562  /*
563  * Contact creation
564  *
565  */
566  $contact = new Contact($db);
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;
581 
582  $elementtype = 'socpeople';
583 
584  //Retrieve all extrafield for thirdsparty
585  // fetch optionals attributes and labels
586  $extrafields = new ExtraFields($db);
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); // Remove 'contact_' prefix
592  $contact->array_options[$key] = $thirdpartywithuser[$key];
593  }
594  }
595 
596  $contact_id = $contact->create($fuser);
597 
598  if ($contact_id > 0) {
599  /*
600  * User creation
601  *
602  */
603  $edituser = new User($db);
604 
605  $id = $edituser->create_from_contact($contact, $thirdpartywithuser["login"]);
606  if ($id > 0) {
607  $edituser->setPassword($fuser, trim($thirdpartywithuser['password']));
608 
609  if ($thirdpartywithuser['group_id'] > 0) {
610  $edituser->SetInGroup($thirdpartywithuser['group_id'], $conf->entity);
611  }
612  } else {
613  $error++;
614  $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : '.$edituser->error;
615  }
616  } else {
617  $error++;
618  $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : '.$contact->error;
619  }
620 
621  if (!$error) {
622  $db->commit();
623  $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>'SUCCESS'), 'id'=>$socid_return);
624  $error = 0;
625  }
626  } else {
627  $error++;
628  $errorcode = join(', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
629  }
630  }
631  } else {
632  // retour creation KO
633  $error++;
634  $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create';
635  }
636  } else {
637  $error++;
638  $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
639  }
640  }
641 
642  if ($error) {
643  $db->rollback();
644  $objectresp = array(
645  'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
646  );
647  }
648 
649  return $objectresp;
650 }
651 
652 
660 function setUserPassword($authentication, $shortuser)
661 {
662 
663  global $db, $conf;
664 
665  dol_syslog("Function: setUserPassword login=".$authentication['login']);
666 
667  if ($authentication['entity']) {
668  $conf->entity = $authentication['entity'];
669  }
670 
671  $objectresp = array();
672  $errorcode = ''; $errorlabel = '';
673  $error = 0;
674 
675  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
676 
677  if ($fuser->socid) {
678  $socid = $fuser->socid;
679  }
680 
681  if (!$error && !$shortuser) {
682  $error++;
683  $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter shortuser must be provided.";
684  }
685 
686  if (!$error) {
687  $fuser->getrights();
688 
689  if ($fuser->rights->user->user->password || $fuser->rights->user->self->password) {
690  $userstat = new User($db);
691  $res = $userstat->fetch('', $shortuser['login']);
692  if ($res) {
693  $res = $userstat->setPassword($userstat, $shortuser['password']);
694  if ($res) {
695  $objectresp = array(
696  'result'=>array('result_code' => 'OK', 'result_label' => ''),
697  );
698  } else {
699  $error++;
700  $errorcode = 'NOT_MODIFIED'; $errorlabel = 'Error when changing password';
701  }
702  } else {
703  $error++;
704  $errorcode = 'NOT_FOUND'; $errorlabel = 'User not found';
705  }
706  } else {
707  $error++;
708  $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
709  }
710  }
711 
712 
713  if ($error) {
714  $objectresp = array(
715  'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
716  );
717  }
718 
719  return $objectresp;
720 }
721 
722 // Return the results.
723 $server->service(file_get_contents("php://input"));
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
setUserPassword
setUserPassword($authentication, $shortuser)
Set password of an user.
Definition: server_user.php:660
getListOfGroups
getListOfGroups($authentication)
getListOfGroups
Definition: server_user.php:399
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
User
Class to manage Dolibarr users.
Definition: user.class.php:44
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
check_authentication
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition: ws.lib.php:35
createUserFromThirdparty
createUserFromThirdparty($authentication, $thirdpartywithuser)
Create an external user with thirdparty and contact.
Definition: server_user.php:467
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
getUser
getUser($authentication, $id, $ref='', $ref_ext='')
Get produt or service.
Definition: server_user.php:313