dolibarr  13.0.2
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")) define("NOCSRFCHECK", '1');
24 
25 require_once '../master.inc.php';
26 require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
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';
32 
33 
34 dol_syslog("Call User webservices interfaces");
35 
36 $langs->load("main");
37 
38 // Enable and test if module web services is enabled
39 if (empty($conf->global->MAIN_MODULE_WEBSERVICES))
40 {
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");
45  exit;
46 }
47 
48 // Create the soap Object
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;
55 
56 
57 // Define WSDL Authentication object
58 $server->wsdl->addComplexType(
59  'authentication',
60  'complexType',
61  'struct',
62  'all',
63  '',
64  array(
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'),
70  )
71 );
72 
73 // Define WSDL Return object
74 $server->wsdl->addComplexType(
75  'result',
76  'complexType',
77  'struct',
78  'all',
79  '',
80  array(
81  'result_code' => array('name'=>'result_code', 'type'=>'xsd:string'),
82  'result_label' => array('name'=>'result_label', 'type'=>'xsd:string'),
83  )
84 );
85 
86 // Define other specific objects
87 $server->wsdl->addComplexType(
88  'user',
89  'complexType',
90  'struct',
91  'all',
92  '',
93  array(
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'),
120  //'rights' => array('name'=>'rights','type'=>'xsd:string'),
121  'canvas' => array('name'=>'canvas', 'type'=>'xsd:string')
122  )
123 );
124 
125 // Define other specific objects
126 $server->wsdl->addComplexType(
127  'group',
128  'complexType',
129  'struct',
130  'all',
131  '',
132  array(
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')
137  )
138 );
139 
140 $server->wsdl->addComplexType(
141  'GroupsArray',
142  'complexType',
143  'array',
144  '',
145  'SOAP-ENC:Array',
146  array(),
147  array(
148  array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'tns:group[]')
149  ),
150  'tns:group'
151 );
152 
153 $thirdpartywithuser_fields = array(
154  // For thirdparty and contact
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'),
180  // For user
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')
184 );
185 
186 $elementtype = 'socpeople';
187 
188 //Retrieve all extrafield for contact
189 // fetch optionals attributes and labels
190 $extrafields = new ExtraFields($db);
191 $extrafields->fetch_name_optionals_label($elementtype, true);
192 $extrafield_array = null;
193 if (is_array($extrafields) && count($extrafields) > 0) {
194  $extrafield_array = array();
195 }
196 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label']))
197 {
198  foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
199  {
200  $type = $extrafields->attributes[$elementtype]['type'][$key];
201  if ($type == 'date' || $type == 'datetime') {$type = 'xsd:dateTime'; }
202  else {$type = 'xsd:string'; }
203 
204  $extrafield_array['contact_options_'.$key] = array('name'=>'contact_options_'.$key, 'type'=>$type);
205  }
206 }
207 
208 if (is_array($extrafield_array)) $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
209 
210 
211 $server->wsdl->addComplexType(
212  'thirdpartywithuser',
213  'complexType',
214  'struct',
215  'all',
216  '',
217  $thirdpartywithuser_fields
218 );
219 
220 // Define WSDL user short object
221 $server->wsdl->addComplexType(
222  'shortuser',
223  'complexType',
224  'struct',
225  'all',
226  '',
227  array(
228  'login' => array('name'=>'login', 'type'=>'xsd:string'),
229  'password' => array('name'=>'password', 'type'=>'xsd:string'),
230  'entity' => array('name'=>'entity', 'type'=>'xsd:string'),
231  )
232 );
233 
234 
235 
236 // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
237 // Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
238 // http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
239 $styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
240 $styleuse = 'encoded'; // encoded/literal/literal wrapped
241 // Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
242 
243 
244 // Register WSDL
245 $server->register(
246  'getUser',
247  // Entry values
248  array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'),
249  // Exit values
250  array('result'=>'tns:result', 'user'=>'tns:user'),
251  $ns,
252  $ns.'#getUser',
253  $styledoc,
254  $styleuse,
255  'WS to get user'
256 );
257 
258 $server->register(
259  'getListOfGroups',
260  // Entry values
261  array('authentication'=>'tns:authentication'),
262  // Exit values
263  array('result'=>'tns:result', 'groups'=>'tns:GroupsArray'),
264  $ns,
265  $ns.'#getListOfGroups',
266  $styledoc,
267  $styleuse,
268  'WS to get list of groups'
269 );
270 
271 $server->register(
272  'createUserFromThirdparty',
273  // Entry values
274  array('authentication'=>'tns:authentication', 'thirdpartywithuser'=>'tns:thirdpartywithuser'),
275  // Exit values
276  array('result'=>'tns:result', 'id'=>'xsd:string'),
277  $ns,
278  $ns.'#createUserFromThirdparty',
279  $styledoc,
280  $styleuse,
281  'WS to create an external user with thirdparty and contact'
282 );
283 
284 $server->register(
285  'setUserPassword',
286  // Entry values
287  array('authentication'=>'tns:authentication', 'shortuser'=>'tns:shortuser'),
288  // Exit values
289  array('result'=>'tns:result', 'id'=>'xsd:string'),
290  $ns,
291  $ns.'#setUserPassword',
292  $styledoc,
293  $styleuse,
294  'WS to change password of an user'
295 );
296 
297 
298 
299 
309 function getUser($authentication, $id, $ref = '', $ref_ext = '')
310 {
311  global $db, $conf;
312 
313  dol_syslog("Function: getUser login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
314 
315  if ($authentication['entity']) $conf->entity = $authentication['entity'];
316 
317  // Init and check authentication
318  $objectresp = array();
319  $errorcode = ''; $errorlabel = '';
320  $error = 0;
321  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
322  // Check parameters
323  if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext)))
324  {
325  $error++;
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.";
327  }
328 
329  if (!$error)
330  {
331  $fuser->getrights();
332 
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))
337  {
338  $user = new User($db);
339  $result = $user->fetch($id, $ref, $ref_ext);
340  if ($result > 0)
341  {
342  // Create
343  $objectresp = array(
344  'result'=>array('result_code'=>'OK', 'result_label'=>''),
345  'user'=>array(
346  'id' => $user->id,
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,
360  'datec' => dol_print_date($user->datec, 'dayhourrfc'),
361  'datem' => dol_print_date($user->datem, 'dayhourrfc'),
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,
370  //'rights' => $user->rights,
371  'canvas' => $user->canvas
372  )
373  );
374  }
375  else {
376  $error++;
377  $errorcode = 'NOT_FOUND'; $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
378  }
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  {
388  $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
389  }
390 
391  return $objectresp;
392 }
393 
400 function getListOfGroups($authentication)
401 {
402  global $db, $conf;
403 
404  dol_syslog("Function: getListOfGroups login=".$authentication['login']);
405 
406  if ($authentication['entity']) $conf->entity = $authentication['entity'];
407 
408  // Init and check authentication
409  $objectresp = array();
410  $arraygroups = array();
411  $errorcode = ''; $errorlabel = '';
412  $error = 0;
413  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
414  // Check parameters
415 
416  if (!$error)
417  {
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)))
422  {
423  $sql .= " WHERE g.entity IS NOT NULL";
424  }
425  else {
426  $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
427  }
428  $sql .= " GROUP BY g.rowid, g.nom, g.entity, g.datec";
429  $resql = $db->query($sql);
430  if ($resql)
431  {
432  $num = $db->num_rows($resql);
433 
434  $i = 0;
435  while ($i < $num)
436  {
437  $obj = $db->fetch_object($resql);
438  $arraygroups[] = array('id'=>$obj->rowid, 'name'=>$obj->name, 'datec'=>$obj->datec, 'nb'=>$obj->nb);
439  $i++;
440  }
441  }
442  else {
443  $error++;
444  $errorcode = $db->lasterrno();
445  $errorlabel = $db->lasterror();
446  }
447  }
448 
449  if ($error)
450  {
451  $objectresp = array(
452  'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
453  'groups'=>$arraygroups
454  );
455  }
456  else {
457  $objectresp = array(
458  'result'=>array('result_code' => 'OK', 'result_label' => ''),
459  'groups'=>$arraygroups
460  );
461  }
462 
463  return $objectresp;
464 }
465 
466 
474 function createUserFromThirdparty($authentication, $thirdpartywithuser)
475 {
476  global $db, $conf, $langs;
477 
478  dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']);
479 
480  if ($authentication['entity']) $conf->entity = $authentication['entity'];
481 
482  $objectresp = array();
483  $errorcode = ''; $errorlabel = '';
484  $error = 0;
485 
486  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
487 
488  if ($fuser->socid) $socid = $fuser->socid;
489 
490  if (!$error && !$thirdpartywithuser)
491  {
492  $error++;
493  $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter thirdparty must be provided.";
494  }
495 
496  if (!$error)
497  {
498  $fuser->getrights();
499 
500  if ($fuser->rights->societe->creer)
501  {
502  $thirdparty = new Societe($db);
503 
504  // If a contact / company already exists with the email, return the corresponding socid
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);
511 
512  $resql = $db->query($sql);
513  if ($resql)
514  {
515  // If a company or contact is found with the same email we return an error
516  $row = $db->fetch_object($resql);
517  if ($row)
518  {
519  $error++;
520  $errorcode = 'ALREADY_EXIST'; $errorlabel = 'Object not create : company or contact exists '.$thirdpartywithuser['email'];
521  }
522  else {
523  $db->begin();
524  /*
525  * Company creation
526  */
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'];
534 
535  // find the country id by code
536  $langs->load("dict");
537 
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)."'";
542 
543  $resql = $db->query($sql);
544  if ($resql)
545  {
546  $num = $db->num_rows($resql);
547  if ($num)
548  {
549  $obj = $db->fetch_object($resql);
550  $thirdparty->country_id = $obj->rowid;
551  }
552  }
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'];
564 
565  $thirdparty->client = $thirdpartywithuser['client'];
566  $thirdparty->fournisseur = $thirdpartywithuser['fournisseur'];
567 
568  $socid_return = $thirdparty->create($fuser);
569 
570  if ($socid_return > 0)
571  {
572  $thirdparty->fetch($socid_return);
573 
574  /*
575  * Contact creation
576  *
577  */
578  $contact = new Contact($db);
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;
593 
594  $elementtype = 'socpeople';
595 
596  //Retrieve all extrafield for thirdsparty
597  // fetch optionals attributes and labels
598  $extrafields = new ExtraFields($db);
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']))
601  {
602  foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label)
603  {
604  $key = 'contact_options_'.$key;
605  $key = substr($key, 8); // Remove 'contact_' prefix
606  $contact->array_options[$key] = $thirdpartywithuser[$key];
607  }
608  }
609 
610  $contact_id = $contact->create($fuser);
611 
612  if ($contact_id > 0)
613  {
614  /*
615  * User creation
616  *
617  */
618  $edituser = new User($db);
619 
620  $id = $edituser->create_from_contact($contact, $thirdpartywithuser["login"]);
621  if ($id > 0)
622  {
623  $edituser->setPassword($fuser, trim($thirdpartywithuser['password']));
624 
625  if ($thirdpartywithuser['group_id'] > 0)
626  $edituser->SetInGroup($thirdpartywithuser['group_id'], $conf->entity);
627  }
628  else {
629  $error++;
630  $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : '.$edituser->error;
631  }
632  }
633  else {
634  $error++;
635  $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : '.$contact->error;
636  }
637 
638  if (!$error) {
639  $db->commit();
640  $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>'SUCCESS'), 'id'=>$socid_return);
641  $error = 0;
642  }
643  } else {
644  $error++;
645  $errorcode = join(', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
646  }
647  }
648  } else {
649  // retour creation KO
650  $error++;
651  $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create';
652  }
653  } else {
654  $error++;
655  $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
656  }
657  }
658 
659  if ($error)
660  {
661  $db->rollback();
662  $objectresp = array(
663  'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
664  );
665  }
666 
667  return $objectresp;
668 }
669 
670 
678 function setUserPassword($authentication, $shortuser)
679 {
680 
681  global $db, $conf;
682 
683  dol_syslog("Function: setUserPassword login=".$authentication['login']);
684 
685  if ($authentication['entity']) $conf->entity = $authentication['entity'];
686 
687  $objectresp = array();
688  $errorcode = ''; $errorlabel = '';
689  $error = 0;
690 
691  $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
692 
693  if ($fuser->socid) $socid = $fuser->socid;
694 
695  if (!$error && !$shortuser)
696  {
697  $error++;
698  $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter shortuser must be provided.";
699  }
700 
701  if (!$error)
702  {
703  $fuser->getrights();
704 
705  if ($fuser->rights->user->user->password || $fuser->rights->user->self->password)
706  {
707  $userstat = new User($db);
708  $res = $userstat->fetch('', $shortuser['login']);
709  if ($res)
710  {
711  $res = $userstat->setPassword($userstat, $shortuser['password']);
712  if ($res)
713  {
714  $objectresp = array(
715  'result'=>array('result_code' => 'OK', 'result_label' => ''),
716  );
717  }
718  else {
719  $error++;
720  $errorcode = 'NOT_MODIFIED'; $errorlabel = 'Error when changing password';
721  }
722  }
723  else {
724  $error++;
725  $errorcode = 'NOT_FOUND'; $errorlabel = 'User not found';
726  }
727  }
728  else {
729  $error++;
730  $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request';
731  }
732  }
733 
734 
735  if ($error)
736  {
737  $objectresp = array(
738  'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
739  );
740  }
741 
742  return $objectresp;
743 }
744 
745 // Return the results.
746 $server->service(file_get_contents("php://input"));
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition: ws.lib.php:35
getUser($authentication, $id, $ref= '', $ref_ext= '')
Get produt or service.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
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 standard extra fields.
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.
Definition: index.php:89
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.
Definition: index.php:1232