331function getUser($authentication, $id, $ref =
'', $ref_ext =
'')
335 dol_syslog(
"Function: getUser login=".$authentication[
'login'].
" id=".$id.
" ref=".$ref.
" ref_ext=".$ref_ext);
337 if ($authentication[
'entity']) {
338 $conf->entity = $authentication[
'entity'];
342 $objectresp = array();
348 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
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.";
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);
366 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
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,
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,
393 'canvas' => $user->canvas
398 $errorcode =
'NOT_FOUND';
399 $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
403 $errorcode =
'PERMISSION_DENIED';
404 $errorlabel =
'User does not have permission for this request';
409 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
423 global $db, $conf, $user;
425 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
427 if ($authentication[
'entity']) {
428 $conf->entity = $authentication[
'entity'];
432 $objectresp = array();
433 $arraygroups = array();
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";
447 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
449 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
450 $resql = $db->query($sql);
452 $num = $db->num_rows($resql);
456 $obj = $db->fetch_object($resql);
457 $arraygroups[] = array(
'id'=>$obj->rowid,
'name'=>$obj->name,
'datec'=>$obj->datec,
'nb'=>$obj->nb);
462 $errorcode = $db->lasterrno();
463 $errorlabel = $db->lasterror();
469 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
470 'groups'=>$arraygroups
474 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
475 'groups'=>$arraygroups
492 global $db, $conf, $langs;
494 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
496 if ($authentication[
'entity']) {
497 $conf->entity = $authentication[
'entity'];
500 $objectresp = array();
508 $socid = $fuser->socid;
511 if (!$error && !$thirdpartywithuser) {
513 $errorcode =
'BAD_PARAMETERS';
514 $errorlabel =
"Parameter thirdparty must be provided.";
520 if ($fuser->hasRight(
'societe',
'creer')) {
521 $thirdparty =
new Societe($db);
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);
531 $resql = $db->query($sql);
534 $row = $db->fetch_object($resql);
537 $errorcode =
'ALREADY_EXIST';
538 $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
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'];
553 $langs->load(
"dict");
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).
"'";
560 $resql = $db->query($sql);
562 $num = $db->num_rows($resql);
564 $obj = $db->fetch_object($resql);
565 $thirdparty->country_id = $obj->rowid;
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'];
580 $thirdparty->client = $thirdpartywithuser[
'client'];
581 $thirdparty->fournisseur = $thirdpartywithuser[
'fournisseur'];
583 $socid_return = $thirdparty->create($fuser);
585 if ($socid_return > 0) {
586 $thirdparty->fetch($socid_return);
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;
608 $elementtype =
'socpeople';
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);
618 $contact->array_options[$key] = $thirdpartywithuser[$key];
622 $contact_id = $contact->create($fuser);
624 if ($contact_id > 0) {
629 $edituser =
new User($db);
631 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
633 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
635 if ($thirdpartywithuser[
'group_id'] > 0) {
636 $edituser->SetInGroup($thirdpartywithuser[
'group_id'], $conf->entity);
640 $errorcode =
'NOT_CREATE';
641 $errorlabel =
'Object not create : '.$edituser->error;
645 $errorcode =
'NOT_CREATE';
646 $errorlabel =
'Object not create : '.$contact->error;
651 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
'SUCCESS'),
'id'=>$socid_return);
656 $errorcode = join(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
662 $errorcode =
'NOT_CREATE';
663 $errorlabel =
'Object not create';
667 $errorcode =
'PERMISSION_DENIED';
668 $errorlabel =
'User does not have permission for this request';
675 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel)