333function getUser($authentication,
$id, $ref =
'', $ref_ext =
'')
337 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".
$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
339 if ($authentication[
'entity']) {
340 $conf->entity = $authentication[
'entity'];
344 $objectresp = array();
350 if (!$error && ((
$id && $ref) || (
$id && $ref_ext) || ($ref && $ref_ext))) {
352 $errorcode =
'BAD_PARAMETERS';
353 $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
357 $fuser->loadRights();
359 if ($fuser->hasRight(
'user',
'user',
'lire')
360 || ($fuser->hasRight(
'user',
'self',
'creer') &&
$id &&
$id == $fuser->id)
361 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref && $ref == $fuser->login)
362 || ($fuser->hasRight(
'user',
'self',
'creer') && $ref_ext && $ref_ext == $fuser->ref_ext)) {
363 $user =
new User($db);
364 $result = $user->fetch(
$id, $ref, $ref_ext);
368 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
371 'lastname' => $user->lastname,
372 'firstname' => $user->firstname,
373 'note' => $user->note,
374 'email' => $user->email,
375 'signature' => $user->signature,
376 'office_phone' => $user->office_phone,
377 'office_fax' => $user->office_fax,
378 'user_mobile' => $user->user_mobile,
379 'admin' => $user->admin,
380 'login' => $user->login,
381 'entity' => $user->entity,
382 'pass_indatabase' => $user->pass_indatabase,
383 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
386 'fk_thirdparty' => $user->socid,
387 'fk_contact' => $user->contact_id,
388 'fk_member' => $user->fk_member,
389 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
390 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
391 'statut' => $user->statut,
392 'photo' => $user->photo,
393 'lang' => $user->lang,
395 'canvas' => $user->canvas
400 $errorcode =
'NOT_FOUND';
401 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
405 $errorcode =
'PERMISSION_DENIED';
406 $errorlabel =
'User does not have permission for this request';
411 $objectresp = array(
'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
425 global $db, $conf, $user;
427 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
429 if ($authentication[
'entity']) {
430 $conf->entity = $authentication[
'entity'];
434 $objectresp = array();
435 $arraygroups = array();
443 $sql =
"SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
444 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as g";
445 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
446 if (isModEnabled(
'multicompany') && $conf->entity == 1 && (
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
447 $sql .=
" WHERE g.entity IS NOT NULL";
449 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
451 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
452 $resql = $db->query($sql);
454 $num = $db->num_rows($resql);
458 $obj = $db->fetch_object($resql);
459 $arraygroups[] = array(
'id' => $obj->rowid,
'name' => $obj->name,
'datec' => $obj->datec,
'nb' => $obj->nb);
464 $errorcode = $db->lasterrno();
465 $errorlabel = $db->lasterror();
471 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
472 'groups' => $arraygroups
476 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
477 'groups' => $arraygroups
494 global $db, $conf, $langs;
496 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
498 if ($authentication[
'entity']) {
499 $conf->entity = $authentication[
'entity'];
502 $objectresp = array();
510 $socid = $fuser->socid;
513 if (!$error && !$thirdpartywithuser) {
515 $errorcode =
'BAD_PARAMETERS';
516 $errorlabel =
"Parameter thirdparty must be provided.";
520 $fuser->loadRights();
522 if ($fuser->hasRight(
'societe',
'creer')) {
523 $thirdparty =
new Societe($db);
526 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
527 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
528 $sql .=
" WHERE s.entity=".$conf->entity;
529 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
530 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
531 $sql .= $db->plimit(1);
533 $resql = $db->query($sql);
536 $row = $db->fetch_object($resql);
539 $errorcode =
'ALREADY_EXIST';
540 $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
546 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
547 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
548 $thirdparty->address = $thirdpartywithuser[
'address'];
549 $thirdparty->zip = $thirdpartywithuser[
'zip'];
550 $thirdparty->town = $thirdpartywithuser[
'town'];
551 $thirdparty->country_id = $thirdpartywithuser[
'country_id'];
552 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
555 $langs->load(
"dict");
557 $sql =
"SELECT rowid";
558 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
559 $sql .=
" WHERE active = 1";
560 $sql .=
" AND code='".$db->escape($thirdparty->country_code).
"'";
562 $resql = $db->query($sql);
564 $num = $db->num_rows($resql);
566 $obj = $db->fetch_object($resql);
567 $thirdparty->country_id = $obj->rowid;
570 $thirdparty->phone = $thirdpartywithuser[
'phone'];
571 $thirdparty->fax = $thirdpartywithuser[
'fax'];
572 $thirdparty->email = $thirdpartywithuser[
'email'];
573 $thirdparty->url = $thirdpartywithuser[
'url'];
574 $thirdparty->ape = $thirdpartywithuser[
'ape'];
575 $thirdparty->idprof1 = $thirdpartywithuser[
'prof1'];
576 $thirdparty->idprof2 = $thirdpartywithuser[
'prof2'];
577 $thirdparty->idprof3 = $thirdpartywithuser[
'prof3'];
578 $thirdparty->idprof4 = $thirdpartywithuser[
'prof4'];
579 $thirdparty->idprof5 = $thirdpartywithuser[
'prof5'];
580 $thirdparty->idprof6 = $thirdpartywithuser[
'prof6'];
582 $thirdparty->client = $thirdpartywithuser[
'client'];
583 $thirdparty->fournisseur = $thirdpartywithuser[
'fournisseur'];
585 $socid_return = $thirdparty->create($fuser);
587 if ($socid_return > 0) {
588 $thirdparty->fetch($socid_return);
595 $contact->socid = $thirdparty->id;
596 $contact->lastname = $thirdpartywithuser[
'name'];
597 $contact->firstname = $thirdpartywithuser[
'firstname'];
598 $contact->civility_id = $thirdparty->civility_id;
599 $contact->address = $thirdparty->address;
600 $contact->zip = $thirdparty->zip;
601 $contact->town = $thirdparty->town;
602 $contact->email = $thirdparty->email;
603 $contact->phone_pro = $thirdparty->phone;
604 $contact->phone_mobile = $thirdpartywithuser[
'phone_mobile'];
605 $contact->fax = $thirdparty->fax;
606 $contact->statut = 1;
607 $contact->country_id = $thirdparty->country_id;
608 $contact->country_code = $thirdparty->country_code;
610 $elementtype =
'socpeople';
615 $extrafields->fetch_name_optionals_label($elementtype,
true);
616 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
617 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
618 $key =
'contact_options_'.$key;
619 $key = substr($key, 8);
620 $contact->array_options[$key] = $thirdpartywithuser[$key];
624 $contact_id = $contact->create($fuser);
626 if ($contact_id > 0) {
631 $edituser =
new User($db);
633 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
635 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
637 if ($thirdpartywithuser[
'group_id'] > 0) {
638 $edituser->SetInGroup($thirdpartywithuser[
'group_id'], $conf->entity);
642 $errorcode =
'NOT_CREATE';
643 $errorlabel =
'Object not create : '.$edituser->error;
647 $errorcode =
'NOT_CREATE';
648 $errorlabel =
'Object not create : '.$contact->error;
653 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
'SUCCESS'),
'id' => $socid_return);
657 $errorcode = implode(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
663 $errorcode =
'NOT_CREATE';
664 $errorlabel =
'Object not create';
668 $errorcode =
'PERMISSION_DENIED';
669 $errorlabel =
'User does not have permission for this request';
676 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)