338function getUser($authentication,
$id, $ref =
'', $ref_ext =
'')
342 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
344 if ($authentication[
'entity']) {
345 $conf->entity = $authentication[
'entity'];
349 $objectresp = array();
355 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
357 $errorcode =
'BAD_PARAMETERS';
358 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
362 $fuser->loadRights();
364 if ($fuser->hasRight(
'user',
'user',
'lire')
365 || ($fuser->hasRight(
'user',
'self',
'creer') &&
$id &&
$id == $fuser->id)
366 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref && $ref == $fuser->login)
367 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref_ext && $ref_ext == $fuser->ref_ext)) {
368 $user =
new User($db);
369 $result = $user->fetch(
$id, $ref, $ref_ext);
373 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
376 'lastname' => $user->lastname,
377 'firstname' => $user->firstname,
378 'note' => $user->note,
379 'email' => $user->email,
380 'signature' => $user->signature,
381 'office_phone' => $user->office_phone,
382 'office_fax' => $user->office_fax,
383 'user_mobile' => $user->user_mobile,
384 'admin' => $user->admin,
385 'login' => $user->login,
386 'entity' => $user->entity,
387 'pass_indatabase' => $user->pass_indatabase,
388 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
391 'fk_thirdparty' => $user->socid,
392 'fk_contact' => $user->contact_id,
393 'fk_member' => $user->fk_member,
394 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
395 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
396 'statut' => $user->statut,
397 'photo' => $user->photo,
398 'lang' => $user->lang,
400 'canvas' => $user->canvas
405 $errorcode =
'NOT_FOUND';
406 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
410 $errorcode =
'PERMISSION_DENIED';
411 $errorlabel =
'User does not have permission for this request';
416 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
430 global $db, $conf, $user;
432 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
434 if ($authentication[
'entity']) {
435 $conf->entity = $authentication[
'entity'];
439 $objectresp = array();
440 $arraygroups = array();
448 $sql =
"SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
449 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as g";
450 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
451 if (
isModEnabled(
'multicompany') && $conf->entity == 1 && (
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
452 $sql .=
" WHERE g.entity IS NOT NULL";
454 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
456 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
457 $resql = $db->query($sql);
459 $num = $db->num_rows($resql);
463 $obj = $db->fetch_object($resql);
464 $arraygroups[] = array(
'id' => $obj->rowid,
'name' => $obj->name,
'datec' => $obj->datec,
'nb' => $obj->nb);
469 $errorcode = $db->lasterrno();
470 $errorlabel = $db->lasterror();
476 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
477 'groups' => $arraygroups
481 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
482 'groups' => $arraygroups
499 global $db, $conf, $langs;
501 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
503 if ($authentication[
'entity']) {
504 $conf->entity = $authentication[
'entity'];
507 $objectresp = array();
515 $socid = $fuser->socid;
518 if (!$error && !$thirdpartywithuser) {
520 $errorcode =
'BAD_PARAMETERS';
521 $errorlabel =
"Parameter thirdparty must be provided.";
525 $fuser->loadRights();
527 if ($fuser->hasRight(
'societe',
'creer')) {
528 $thirdparty =
new Societe($db);
531 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
532 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
533 $sql .=
" WHERE s.entity=".$conf->entity;
534 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
535 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
536 $sql .= $db->plimit(1);
538 $resql = $db->query($sql);
541 $row = $db->fetch_object($resql);
544 $errorcode =
'ALREADY_EXIST';
545 $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
551 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
552 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
553 $thirdparty->address = $thirdpartywithuser[
'address'];
554 $thirdparty->zip = $thirdpartywithuser[
'zip'];
555 $thirdparty->town = $thirdpartywithuser[
'town'];
556 $thirdparty->country_id = (int) $thirdpartywithuser[
'country_id'];
557 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
560 $langs->load(
"dict");
562 $sql =
"SELECT rowid";
563 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
564 $sql .=
" WHERE active = 1";
565 $sql .=
" AND code = '".$db->escape($thirdparty->country_code).
"'";
567 $resql = $db->query($sql);
569 $num = $db->num_rows($resql);
571 $obj = $db->fetch_object($resql);
572 $thirdparty->country_id = $obj->rowid;
575 $thirdparty->phone = $thirdpartywithuser[
'phone'];
576 $thirdparty->fax = $thirdpartywithuser[
'fax'];
577 $thirdparty->email = $thirdpartywithuser[
'email'];
578 $thirdparty->url = $thirdpartywithuser[
'url'];
579 $thirdparty->idprof1 = $thirdpartywithuser[
'profid1'];
580 $thirdparty->idprof2 = $thirdpartywithuser[
'profid2'];
581 $thirdparty->idprof3 = $thirdpartywithuser[
'profid3'];
582 $thirdparty->idprof4 = $thirdpartywithuser[
'profid4'];
583 $thirdparty->idprof5 = $thirdpartywithuser[
'profid5'];
584 $thirdparty->idprof6 = $thirdpartywithuser[
'profid6'];
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->status = 1;
611 $contact->statut = 1;
612 $contact->country_id = $thirdparty->country_id;
613 $contact->country_code = $thirdparty->country_code;
615 $elementtype =
'socpeople';
620 $extrafields->fetch_name_optionals_label($elementtype,
true);
621 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
622 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
623 $key =
'contact_options_'.$key;
624 $key = substr($key, 8);
625 $contact->array_options[$key] = $thirdpartywithuser[$key];
629 $contact_id = $contact->create($fuser);
631 if ($contact_id > 0) {
636 $edituser =
new User($db);
638 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
640 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
642 if ($thirdpartywithuser[
'group_id'] > 0) {
643 $edituser->SetInGroup((
int) $thirdpartywithuser[
'group_id'], $conf->entity);
647 $errorcode =
'NOT_CREATE';
648 $errorlabel =
'Object not create : '.$edituser->error;
652 $errorcode =
'NOT_CREATE';
653 $errorlabel =
'Object not create : '.$contact->error;
658 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
'SUCCESS'),
'id' => $socid_return);
662 $errorcode = implode(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
668 $errorcode =
'NOT_CREATE';
669 $errorlabel =
'Object not create';
673 $errorcode =
'PERMISSION_DENIED';
674 $errorlabel =
'User does not have permission for this request';
681 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)