dolibarr 19.0.4
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
23if (!defined('NOCSRFCHECK')) {
24 define('NOCSRFCHECK', '1'); // Do not check anti CSRF attack test
25}
26if (!defined('NOTOKENRENEWAL')) {
27 define('NOTOKENRENEWAL', '1'); // Do not check anti POST attack test
28}
29if (!defined('NOREQUIREMENU')) {
30 define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu
31}
32if (!defined('NOREQUIREHTML')) {
33 define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php
34}
35if (!defined('NOREQUIREAJAX')) {
36 define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library
37}
38if (!defined("NOLOGIN")) {
39 define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
40}
41if (!defined("NOSESSION")) {
42 define("NOSESSION", '1');
43}
44
45require '../main.inc.php';
46require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
47require_once DOL_DOCUMENT_ROOT.'/core/lib/ws.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
49require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
51require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
52
53
54dol_syslog("Call User webservices interfaces");
55
56$langs->load("main");
57
58// Enable and test if module web services is enabled
59if (!getDolGlobalString('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");
64 exit;
65}
66
67// Create the soap Object
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;
74
75
76// Define WSDL Authentication object
77$server->wsdl->addComplexType(
78 'authentication',
79 'complexType',
80 'struct',
81 'all',
82 '',
83 array(
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'),
89 )
90);
91
92// Define WSDL Return object
93$server->wsdl->addComplexType(
94 'result',
95 'complexType',
96 'struct',
97 'all',
98 '',
99 array(
100 'result_code' => array('name'=>'result_code', 'type'=>'xsd:string'),
101 'result_label' => array('name'=>'result_label', 'type'=>'xsd:string'),
102 )
103);
104
105// Define other specific objects
106$server->wsdl->addComplexType(
107 'user',
108 'complexType',
109 'struct',
110 'all',
111 '',
112 array(
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'),
139 //'rights' => array('name'=>'rights','type'=>'xsd:string'),
140 'canvas' => array('name'=>'canvas', 'type'=>'xsd:string')
141 )
142);
143
144// Define other specific objects
145$server->wsdl->addComplexType(
146 'group',
147 'complexType',
148 'struct',
149 'all',
150 '',
151 array(
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')
156 )
157);
158
159$server->wsdl->addComplexType(
160 'GroupsArray',
161 'complexType',
162 'array',
163 '',
164 'SOAP-ENC:Array',
165 array(),
166 array(
167 array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType'=>'tns:group[]')
168 ),
169 'tns:group'
170);
171
172$thirdpartywithuser_fields = array(
173 // For thirdparty and contact
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'),
199 // For user
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')
203);
204
205$elementtype = 'socpeople';
206
207//Retrieve all extrafield for contact
208// fetch optionals attributes and labels
209$extrafields = new ExtraFields($db);
210$extrafields->fetch_name_optionals_label($elementtype, true);
211$extrafield_array = null;
212if (is_array($extrafields) && count($extrafields) > 0) {
213 $extrafield_array = array();
214}
215if (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';
220 } else {
221 $type = 'xsd:string';
222 }
223
224 $extrafield_array['contact_options_'.$key] = array('name'=>'contact_options_'.$key, 'type'=>$type);
225 }
226}
227
228if (is_array($extrafield_array)) {
229 $thirdpartywithuser_fields = array_merge($thirdpartywithuser_fields, $extrafield_array);
230}
231
232
233$server->wsdl->addComplexType(
234 'thirdpartywithuser',
235 'complexType',
236 'struct',
237 'all',
238 '',
239 $thirdpartywithuser_fields
240);
241
242// Define WSDL user short object
243$server->wsdl->addComplexType(
244 'shortuser',
245 'complexType',
246 'struct',
247 'all',
248 '',
249 array(
250 'login' => array('name'=>'login', 'type'=>'xsd:string'),
251 'password' => array('name'=>'password', 'type'=>'xsd:string'),
252 'entity' => array('name'=>'entity', 'type'=>'xsd:string'),
253 )
254);
255
256
257
258// 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped
259// Style merely dictates how to translate a WSDL binding to a SOAP message. Nothing more. You can use either style with any programming model.
260// http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/
261$styledoc = 'rpc'; // rpc/document (document is an extend into SOAP 1.0 to support unstructured messages)
262$styleuse = 'encoded'; // encoded/literal/literal wrapped
263// Better choice is document/literal wrapped but literal wrapped not supported by nusoap.
264
265
266// Register WSDL
267$server->register(
268 'getUser',
269 // Entry values
270 array('authentication'=>'tns:authentication', 'id'=>'xsd:string', 'ref'=>'xsd:string', 'ref_ext'=>'xsd:string'),
271 // Exit values
272 array('result'=>'tns:result', 'user'=>'tns:user'),
273 $ns,
274 $ns.'#getUser',
275 $styledoc,
276 $styleuse,
277 'WS to get user'
278);
279
280$server->register(
281 'getListOfGroups',
282 // Entry values
283 array('authentication'=>'tns:authentication'),
284 // Exit values
285 array('result'=>'tns:result', 'groups'=>'tns:GroupsArray'),
286 $ns,
287 $ns.'#getListOfGroups',
288 $styledoc,
289 $styleuse,
290 'WS to get list of groups'
291);
292
293$server->register(
294 'createUserFromThirdparty',
295 // Entry values
296 array('authentication'=>'tns:authentication', 'thirdpartywithuser'=>'tns:thirdpartywithuser'),
297 // Exit values
298 array('result'=>'tns:result', 'id'=>'xsd:string'),
299 $ns,
300 $ns.'#createUserFromThirdparty',
301 $styledoc,
302 $styleuse,
303 'WS to create an external user with thirdparty and contact'
304);
305
306$server->register(
307 'setUserPassword',
308 // Entry values
309 array('authentication'=>'tns:authentication', 'shortuser'=>'tns:shortuser'),
310 // Exit values
311 array('result'=>'tns:result', 'id'=>'xsd:string'),
312 $ns,
313 $ns.'#setUserPassword',
314 $styledoc,
315 $styleuse,
316 'WS to change password of an user'
317);
318
319
320
321
331function getUser($authentication, $id, $ref = '', $ref_ext = '')
332{
333 global $db, $conf;
334
335 dol_syslog("Function: getUser login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext);
336
337 if ($authentication['entity']) {
338 $conf->entity = $authentication['entity'];
339 }
340
341 // Init and check authentication
342 $objectresp = array();
343 $errorcode = '';
344 $errorlabel = '';
345 $error = 0;
346 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
347 // Check parameters
348 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
349 $error++;
350 $errorcode = 'BAD_PARAMETERS';
351 $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
352 }
353
354 if (!$error) {
355 $fuser->getrights();
356
357 if ($fuser->hasRight('user', 'user', 'lire')
358 || ($fuser->hasRight('user', 'self', 'creer') && $id && $id == $fuser->id)
359 || ($fuser->hasRight('user', 'self', 'creer') && $ref && $ref == $fuser->login)
360 || ($fuser->hasRight('user', 'self', 'creer') && $ref_ext && $ref_ext == $fuser->ref_ext)) {
361 $user = new User($db);
362 $result = $user->fetch($id, $ref, $ref_ext);
363 if ($result > 0) {
364 // Create
365 $objectresp = array(
366 'result'=>array('result_code'=>'OK', 'result_label'=>''),
367 'user'=>array(
368 'id' => $user->id,
369 'lastname' => $user->lastname,
370 'firstname' => $user->firstname,
371 'note' => $user->note,
372 'email' => $user->email,
373 'signature' => $user->signature,
374 'office_phone' => $user->office_phone,
375 'office_fax' => $user->office_fax,
376 'user_mobile' => $user->user_mobile,
377 'admin' => $user->admin,
378 'login' => $user->login,
379 'entity' => $user->entity,
380 'pass_indatabase' => $user->pass_indatabase,
381 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
382 'datec' => dol_print_date($user->datec, 'dayhourrfc'),
383 'datem' => dol_print_date($user->datem, 'dayhourrfc'),
384 'fk_thirdparty' => $user->socid,
385 'fk_contact' => $user->contact_id,
386 'fk_member' => $user->fk_member,
387 'datelastlogin' => dol_print_date($user->datelastlogin, 'dayhourrfc'),
388 'datepreviouslogin' => dol_print_date($user->datepreviouslogin, 'dayhourrfc'),
389 'statut' => $user->statut,
390 'photo' => $user->photo,
391 'lang' => $user->lang,
392 //'rights' => $user->rights,
393 'canvas' => $user->canvas
394 )
395 );
396 } else {
397 $error++;
398 $errorcode = 'NOT_FOUND';
399 $errorlabel = 'Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext;
400 }
401 } else {
402 $error++;
403 $errorcode = 'PERMISSION_DENIED';
404 $errorlabel = 'User does not have permission for this request';
405 }
406 }
407
408 if ($error) {
409 $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
410 }
411
412 return $objectresp;
413}
414
421function getListOfGroups($authentication)
422{
423 global $db, $conf, $user;
424
425 dol_syslog("Function: getListOfGroups login=".$authentication['login']);
426
427 if ($authentication['entity']) {
428 $conf->entity = $authentication['entity'];
429 }
430
431 // Init and check authentication
432 $objectresp = array();
433 $arraygroups = array();
434 $errorcode = '';
435 $errorlabel = '';
436 $error = 0;
437 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
438 // Check parameters
439
440 if (!$error) {
441 $sql = "SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
442 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
443 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
444 if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
445 $sql .= " WHERE g.entity IS NOT NULL";
446 } else {
447 $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
448 }
449 $sql .= " GROUP BY g.rowid, g.nom, g.entity, g.datec";
450 $resql = $db->query($sql);
451 if ($resql) {
452 $num = $db->num_rows($resql);
453
454 $i = 0;
455 while ($i < $num) {
456 $obj = $db->fetch_object($resql);
457 $arraygroups[] = array('id'=>$obj->rowid, 'name'=>$obj->name, 'datec'=>$obj->datec, 'nb'=>$obj->nb);
458 $i++;
459 }
460 } else {
461 $error++;
462 $errorcode = $db->lasterrno();
463 $errorlabel = $db->lasterror();
464 }
465 }
466
467 if ($error) {
468 $objectresp = array(
469 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel),
470 'groups'=>$arraygroups
471 );
472 } else {
473 $objectresp = array(
474 'result'=>array('result_code' => 'OK', 'result_label' => ''),
475 'groups'=>$arraygroups
476 );
477 }
478
479 return $objectresp;
480}
481
482
490function createUserFromThirdparty($authentication, $thirdpartywithuser)
491{
492 global $db, $conf, $langs;
493
494 dol_syslog("Function: createUserFromThirdparty login=".$authentication['login']);
495
496 if ($authentication['entity']) {
497 $conf->entity = $authentication['entity'];
498 }
499
500 $objectresp = array();
501 $errorcode = '';
502 $errorlabel = '';
503 $error = 0;
504
505 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
506
507 if ($fuser->socid) {
508 $socid = $fuser->socid;
509 }
510
511 if (!$error && !$thirdpartywithuser) {
512 $error++;
513 $errorcode = 'BAD_PARAMETERS';
514 $errorlabel = "Parameter thirdparty must be provided.";
515 }
516
517 if (!$error) {
518 $fuser->getrights();
519
520 if ($fuser->hasRight('societe', 'creer')) {
521 $thirdparty = new Societe($db);
522
523 // If a contact / company already exists with the email, return the corresponding socid
524 $sql = "SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX."societe as s";
525 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON sp.fk_soc = s.rowid";
526 $sql .= " WHERE s.entity=".$conf->entity;
527 $sql .= " AND s.email='".$db->escape($thirdpartywithuser['email'])."'";
528 $sql .= " OR sp.email='".$db->escape($thirdpartywithuser['email'])."'";
529 $sql .= $db->plimit(1);
530
531 $resql = $db->query($sql);
532 if ($resql) {
533 // If a company or contact is found with the same email we return an error
534 $row = $db->fetch_object($resql);
535 if ($row) {
536 $error++;
537 $errorcode = 'ALREADY_EXIST';
538 $errorlabel = 'Object not create : company or contact exists '.$thirdpartywithuser['email'];
539 } else {
540 $db->begin();
541 /*
542 * Company creation
543 */
544 $thirdparty->name = $thirdpartywithuser['name_thirdparty'];
545 $thirdparty->ref_ext = $thirdpartywithuser['ref_ext'];
546 $thirdparty->address = $thirdpartywithuser['address'];
547 $thirdparty->zip = $thirdpartywithuser['zip'];
548 $thirdparty->town = $thirdpartywithuser['town'];
549 $thirdparty->country_id = $thirdpartywithuser['country_id'];
550 $thirdparty->country_code = $thirdpartywithuser['country_code'];
551
552 // find the country id by code
553 $langs->load("dict");
554
555 $sql = "SELECT rowid";
556 $sql .= " FROM ".MAIN_DB_PREFIX."c_country";
557 $sql .= " WHERE active = 1";
558 $sql .= " AND code='".$db->escape($thirdparty->country_code)."'";
559
560 $resql = $db->query($sql);
561 if ($resql) {
562 $num = $db->num_rows($resql);
563 if ($num) {
564 $obj = $db->fetch_object($resql);
565 $thirdparty->country_id = $obj->rowid;
566 }
567 }
568 $thirdparty->phone = $thirdpartywithuser['phone'];
569 $thirdparty->fax = $thirdpartywithuser['fax'];
570 $thirdparty->email = $thirdpartywithuser['email'];
571 $thirdparty->url = $thirdpartywithuser['url'];
572 $thirdparty->ape = $thirdpartywithuser['ape'];
573 $thirdparty->idprof1 = $thirdpartywithuser['prof1'];
574 $thirdparty->idprof2 = $thirdpartywithuser['prof2'];
575 $thirdparty->idprof3 = $thirdpartywithuser['prof3'];
576 $thirdparty->idprof4 = $thirdpartywithuser['prof4'];
577 $thirdparty->idprof5 = $thirdpartywithuser['prof5'];
578 $thirdparty->idprof6 = $thirdpartywithuser['prof6'];
579
580 $thirdparty->client = $thirdpartywithuser['client'];
581 $thirdparty->fournisseur = $thirdpartywithuser['fournisseur'];
582
583 $socid_return = $thirdparty->create($fuser);
584
585 if ($socid_return > 0) {
586 $thirdparty->fetch($socid_return);
587
588 /*
589 * Contact creation
590 *
591 */
592 $contact = new Contact($db);
593 $contact->socid = $thirdparty->id;
594 $contact->lastname = $thirdpartywithuser['name'];
595 $contact->firstname = $thirdpartywithuser['firstname'];
596 $contact->civility_id = $thirdparty->civility_id;
597 $contact->address = $thirdparty->address;
598 $contact->zip = $thirdparty->zip;
599 $contact->town = $thirdparty->town;
600 $contact->email = $thirdparty->email;
601 $contact->phone_pro = $thirdparty->phone;
602 $contact->phone_mobile = $thirdpartywithuser['phone_mobile'];
603 $contact->fax = $thirdparty->fax;
604 $contact->statut = 1;
605 $contact->country_id = $thirdparty->country_id;
606 $contact->country_code = $thirdparty->country_code;
607
608 $elementtype = 'socpeople';
609
610 //Retrieve all extrafield for thirdsparty
611 // fetch optionals attributes and labels
612 $extrafields = new ExtraFields($db);
613 $extrafields->fetch_name_optionals_label($elementtype, true);
614 if (isset($extrafields->attributes[$elementtype]['label']) && is_array($extrafields->attributes[$elementtype]['label']) && count($extrafields->attributes[$elementtype]['label'])) {
615 foreach ($extrafields->attributes[$elementtype]['label'] as $key => $label) {
616 $key = 'contact_options_'.$key;
617 $key = substr($key, 8); // Remove 'contact_' prefix
618 $contact->array_options[$key] = $thirdpartywithuser[$key];
619 }
620 }
621
622 $contact_id = $contact->create($fuser);
623
624 if ($contact_id > 0) {
625 /*
626 * User creation
627 *
628 */
629 $edituser = new User($db);
630
631 $id = $edituser->create_from_contact($contact, $thirdpartywithuser["login"]);
632 if ($id > 0) {
633 $edituser->setPassword($fuser, trim($thirdpartywithuser['password']));
634
635 if ($thirdpartywithuser['group_id'] > 0) {
636 $edituser->SetInGroup($thirdpartywithuser['group_id'], $conf->entity);
637 }
638 } else {
639 $error++;
640 $errorcode = 'NOT_CREATE';
641 $errorlabel = 'Object not create : '.$edituser->error;
642 }
643 } else {
644 $error++;
645 $errorcode = 'NOT_CREATE';
646 $errorlabel = 'Object not create : '.$contact->error;
647 }
648
649 if (!$error) {
650 $db->commit();
651 $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>'SUCCESS'), 'id'=>$socid_return);
652 $error = 0;
653 }
654 } else {
655 $error++;
656 $errorcode = join(', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
657 }
658 }
659 } else {
660 // retour creation KO
661 $error++;
662 $errorcode = 'NOT_CREATE';
663 $errorlabel = 'Object not create';
664 }
665 } else {
666 $error++;
667 $errorcode = 'PERMISSION_DENIED';
668 $errorlabel = 'User does not have permission for this request';
669 }
670 }
671
672 if ($error) {
673 $db->rollback();
674 $objectresp = array(
675 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
676 );
677 }
678
679 return $objectresp;
680}
681
682
690function setUserPassword($authentication, $shortuser)
691{
692 global $db, $conf;
693
694 dol_syslog("Function: setUserPassword login=".$authentication['login']);
695
696 if ($authentication['entity']) {
697 $conf->entity = $authentication['entity'];
698 }
699
700 $objectresp = array();
701 $errorcode = '';
702 $errorlabel = '';
703 $error = 0;
704
705 $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
706
707 if ($fuser->socid) {
708 $socid = $fuser->socid;
709 }
710
711 if (!$error && !$shortuser) {
712 $error++;
713 $errorcode = 'BAD_PARAMETERS';
714 $errorlabel = "Parameter shortuser must be provided.";
715 }
716
717 if (!$error) {
718 $fuser->getrights();
719
720 if ($fuser->hasRight('user', 'user', 'password') || $fuser->hasRight('user', 'self', 'password')) {
721 $userstat = new User($db);
722 $res = $userstat->fetch('', $shortuser['login']);
723 if ($res) {
724 $res = $userstat->setPassword($userstat, $shortuser['password']);
725 if (is_int($res) && $res < 0) {
726 $error++;
727 $errorcode = 'NOT_MODIFIED';
728 $errorlabel = 'Error when changing password';
729 } else {
730 $objectresp = array(
731 'result'=>array('result_code' => 'OK', 'result_label' => ''),
732 );
733 }
734 } else {
735 $error++;
736 $errorcode = 'NOT_FOUND';
737 $errorlabel = 'User not found';
738 }
739 } else {
740 $error++;
741 $errorcode = 'PERMISSION_DENIED';
742 $errorlabel = 'User does not have permission for this request';
743 }
744 }
745
746
747 if ($error) {
748 $objectresp = array(
749 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)
750 );
751 }
752
753 return $objectresp;
754}
755
756// Return the results.
757$server->service(file_get_contents("php://input"));
Class to manage standard extra fields.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
Contact()
Old copy.
Definition index.php:572
check_authentication($authentication, &$error, &$errorcode, &$errorlabel)
Check authentication array and set error, errorcode, errorlabel.
Definition ws.lib.php:35