337function getUser($authentication,
$id, $ref =
'', $ref_ext =
'')
341 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
343 if ($authentication[
'entity']) {
344 $conf->entity = $authentication[
'entity'];
348 $objectresp = array();
354 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
356 $errorcode =
'BAD_PARAMETERS';
357 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
361 $fuser->loadRights();
363 if ($fuser->hasRight(
'user',
'user',
'lire')
364 || ($fuser->hasRight(
'user',
'self',
'creer') &&
$id &&
$id == $fuser->id)
365 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref && $ref == $fuser->login)
366 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref_ext && $ref_ext == $fuser->ref_ext)) {
367 $user =
new User($db);
368 $result = $user->fetch(
$id, $ref, $ref_ext);
372 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
375 'lastname' => $user->lastname,
376 'firstname' => $user->firstname,
377 'note' => $user->note,
378 'email' => $user->email,
379 'signature' => $user->signature,
380 'office_phone' => $user->office_phone,
381 'office_fax' => $user->office_fax,
382 'user_mobile' => $user->user_mobile,
383 'admin' => $user->admin,
384 'login' => $user->login,
385 'entity' => $user->entity,
386 'pass_indatabase' => $user->pass_indatabase,
387 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
390 'fk_thirdparty' => $user->socid,
391 'fk_contact' => $user->contact_id,
392 'fk_member' => $user->fk_member,
393 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
394 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
395 'statut' => $user->statut,
396 'photo' => $user->photo,
397 'lang' => $user->lang,
399 'canvas' => $user->canvas
404 $errorcode =
'NOT_FOUND';
405 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
409 $errorcode =
'PERMISSION_DENIED';
410 $errorlabel =
'User does not have permission for this request';
415 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
498 global $db,
$conf, $langs;
500 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
502 if ($authentication[
'entity']) {
503 $conf->entity = $authentication[
'entity'];
506 $objectresp = array();
514 $socid = $fuser->socid;
517 if (!$error && !$thirdpartywithuser) {
519 $errorcode =
'BAD_PARAMETERS';
520 $errorlabel =
"Parameter thirdparty must be provided.";
524 $fuser->loadRights();
526 if ($fuser->hasRight(
'societe',
'creer')) {
527 $thirdparty =
new Societe($db);
530 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
531 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
532 $sql .=
" WHERE s.entity=".$conf->entity;
533 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
534 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
535 $sql .= $db->plimit(1);
537 $resql = $db->query($sql);
540 $row = $db->fetch_object($resql);
543 $errorcode =
'ALREADY_EXIST';
544 $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
550 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
551 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
552 $thirdparty->address = $thirdpartywithuser[
'address'];
553 $thirdparty->zip = $thirdpartywithuser[
'zip'];
554 $thirdparty->town = $thirdpartywithuser[
'town'];
555 $thirdparty->country_id = (int) $thirdpartywithuser[
'country_id'];
556 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
559 $langs->load(
"dict");
561 $sql =
"SELECT rowid";
562 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
563 $sql .=
" WHERE active = 1";
564 $sql .=
" AND code='".$db->escape($thirdparty->country_code).
"'";
566 $resql = $db->query($sql);
568 $num = $db->num_rows($resql);
570 $obj = $db->fetch_object($resql);
571 $thirdparty->country_id = $obj->rowid;
574 $thirdparty->phone = $thirdpartywithuser[
'phone'];
575 $thirdparty->fax = $thirdpartywithuser[
'fax'];
576 $thirdparty->email = $thirdpartywithuser[
'email'];
577 $thirdparty->url = $thirdpartywithuser[
'url'];
578 $thirdparty->ape = $thirdpartywithuser[
'ape'];
579 $thirdparty->idprof1 = $thirdpartywithuser[
'prof1'];
580 $thirdparty->idprof2 = $thirdpartywithuser[
'prof2'];
581 $thirdparty->idprof3 = $thirdpartywithuser[
'prof3'];
582 $thirdparty->idprof4 = $thirdpartywithuser[
'prof4'];
583 $thirdparty->idprof5 = $thirdpartywithuser[
'prof5'];
584 $thirdparty->idprof6 = $thirdpartywithuser[
'prof6'];
586 $thirdparty->client = (int) $thirdpartywithuser[
'client'];
587 $thirdparty->fournisseur = (int) $thirdpartywithuser[
'fournisseur'];
589 $socid_return = $thirdparty->create($fuser);
591 if ($socid_return > 0) {
592 $thirdparty->fetch($socid_return);
599 $contact->socid = $thirdparty->id;
600 $contact->lastname = $thirdpartywithuser[
'name'];
601 $contact->firstname = $thirdpartywithuser[
'firstname'];
602 $contact->civility_id = $thirdparty->civility_id;
603 $contact->address = $thirdparty->address;
604 $contact->zip = $thirdparty->zip;
605 $contact->town = $thirdparty->town;
606 $contact->email = $thirdparty->email;
607 $contact->phone_pro = $thirdparty->phone;
608 $contact->phone_mobile = $thirdpartywithuser[
'phone_mobile'];
609 $contact->fax = $thirdparty->fax;
610 $contact->statut = 1;
611 $contact->country_id = $thirdparty->country_id;
612 $contact->country_code = $thirdparty->country_code;
614 $elementtype =
'socpeople';
619 $extrafields->fetch_name_optionals_label($elementtype,
true);
620 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
621 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
622 $key =
'contact_options_'.$key;
623 $key = substr($key, 8);
624 $contact->array_options[$key] = $thirdpartywithuser[$key];
628 $contact_id = $contact->create($fuser);
630 if ($contact_id > 0) {
635 $edituser =
new User($db);
637 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
639 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
641 if ($thirdpartywithuser[
'group_id'] > 0) {
642 $edituser->SetInGroup($thirdpartywithuser[
'group_id'],
$conf->entity);
646 $errorcode =
'NOT_CREATE';
647 $errorlabel =
'Object not create : '.$edituser->error;
651 $errorcode =
'NOT_CREATE';
652 $errorlabel =
'Object not create : '.$contact->error;
657 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
'SUCCESS'),
'id' => $socid_return);
661 $errorcode = implode(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
667 $errorcode =
'NOT_CREATE';
668 $errorlabel =
'Object not create';
672 $errorcode =
'PERMISSION_DENIED';
673 $errorlabel =
'User does not have permission for this request';
680 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)