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();
343 $errorcode =
''; $errorlabel =
'';
347 if (!$error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) {
349 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
355 if ($fuser->rights->user->user->lire
356 || ($fuser->rights->user->self->creer && $id && $id == $fuser->id)
357 || ($fuser->rights->user->self->creer && $ref && $ref == $fuser->login)
358 || ($fuser->rights->user->self->creer && $ref_ext && $ref_ext == $fuser->ref_ext)) {
359 $user =
new User($db);
360 $result = $user->fetch($id, $ref, $ref_ext);
364 'result'=>array(
'result_code'=>
'OK',
'result_label'=>
''),
367 'lastname' => $user->lastname,
368 'firstname' => $user->firstname,
369 'note' => $user->note,
370 'email' => $user->email,
371 'signature' => $user->signature,
372 'office_phone' => $user->office_phone,
373 'office_fax' => $user->office_fax,
374 'user_mobile' => $user->user_mobile,
375 'admin' => $user->admin,
376 'login' => $user->login,
377 'entity' => $user->entity,
378 'pass_indatabase' => $user->pass_indatabase,
379 'pass_indatabase_crypted' => $user->pass_indatabase_crypted,
382 'fk_thirdparty' => $user->socid,
383 'fk_contact' => $user->contact_id,
384 'fk_member' => $user->fk_member,
385 'datelastlogin' =>
dol_print_date($user->datelastlogin,
'dayhourrfc'),
386 'datepreviouslogin' =>
dol_print_date($user->datepreviouslogin,
'dayhourrfc'),
387 'statut' => $user->statut,
388 'photo' => $user->photo,
389 'lang' => $user->lang,
391 'canvas' => $user->canvas
396 $errorcode =
'NOT_FOUND'; $errorlabel =
'Object not found for id='.$id.
' nor ref='.$ref.
' nor ref_ext='.$ref_ext;
400 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
405 $objectresp = array(
'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel));
419 global $db, $conf, $user;
421 dol_syslog(
"Function: getListOfGroups login=".$authentication[
'login']);
423 if ($authentication[
'entity']) {
424 $conf->entity = $authentication[
'entity'];
428 $objectresp = array();
429 $arraygroups = array();
430 $errorcode =
''; $errorlabel =
'';
436 $sql =
"SELECT g.rowid, g.nom as name, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb";
437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup as g";
438 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
439 if (isModEnabled(
'multicompany') && $conf->entity == 1 && (
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
440 $sql .=
" WHERE g.entity IS NOT NULL";
442 $sql .=
" WHERE g.entity IN (0,".$conf->entity.
")";
444 $sql .=
" GROUP BY g.rowid, g.nom, g.entity, g.datec";
445 $resql = $db->query($sql);
447 $num = $db->num_rows($resql);
451 $obj = $db->fetch_object($resql);
452 $arraygroups[] = array(
'id'=>$obj->rowid,
'name'=>$obj->name,
'datec'=>$obj->datec,
'nb'=>$obj->nb);
457 $errorcode = $db->lasterrno();
458 $errorlabel = $db->lasterror();
464 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel),
465 'groups'=>$arraygroups
469 'result'=>array(
'result_code' =>
'OK',
'result_label' =>
''),
470 'groups'=>$arraygroups
487 global $db, $conf, $langs;
489 dol_syslog(
"Function: createUserFromThirdparty login=".$authentication[
'login']);
491 if ($authentication[
'entity']) {
492 $conf->entity = $authentication[
'entity'];
495 $objectresp = array();
496 $errorcode =
''; $errorlabel =
'';
502 $socid = $fuser->socid;
505 if (!$error && !$thirdpartywithuser) {
507 $errorcode =
'BAD_PARAMETERS'; $errorlabel =
"Parameter thirdparty must be provided.";
513 if ($fuser->rights->societe->creer) {
514 $thirdparty =
new Societe($db);
517 $sql =
"SELECT s.rowid as socid FROM ".MAIN_DB_PREFIX.
"societe as s";
518 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid";
519 $sql .=
" WHERE s.entity=".$conf->entity;
520 $sql .=
" AND s.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
521 $sql .=
" OR sp.email='".$db->escape($thirdpartywithuser[
'email']).
"'";
522 $sql .= $db->plimit(1);
524 $resql = $db->query($sql);
527 $row = $db->fetch_object($resql);
530 $errorcode =
'ALREADY_EXIST'; $errorlabel =
'Object not create : company or contact exists '.$thirdpartywithuser[
'email'];
536 $thirdparty->name = $thirdpartywithuser[
'name_thirdparty'];
537 $thirdparty->ref_ext = $thirdpartywithuser[
'ref_ext'];
538 $thirdparty->address = $thirdpartywithuser[
'address'];
539 $thirdparty->zip = $thirdpartywithuser[
'zip'];
540 $thirdparty->town = $thirdpartywithuser[
'town'];
541 $thirdparty->country_id = $thirdpartywithuser[
'country_id'];
542 $thirdparty->country_code = $thirdpartywithuser[
'country_code'];
545 $langs->load(
"dict");
547 $sql =
"SELECT rowid";
548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_country";
549 $sql .=
" WHERE active = 1";
550 $sql .=
" AND code='".$db->escape($thirdparty->country_code).
"'";
552 $resql = $db->query($sql);
554 $num = $db->num_rows($resql);
556 $obj = $db->fetch_object($resql);
557 $thirdparty->country_id = $obj->rowid;
560 $thirdparty->phone = $thirdpartywithuser[
'phone'];
561 $thirdparty->fax = $thirdpartywithuser[
'fax'];
562 $thirdparty->email = $thirdpartywithuser[
'email'];
563 $thirdparty->url = $thirdpartywithuser[
'url'];
564 $thirdparty->ape = $thirdpartywithuser[
'ape'];
565 $thirdparty->idprof1 = $thirdpartywithuser[
'prof1'];
566 $thirdparty->idprof2 = $thirdpartywithuser[
'prof2'];
567 $thirdparty->idprof3 = $thirdpartywithuser[
'prof3'];
568 $thirdparty->idprof4 = $thirdpartywithuser[
'prof4'];
569 $thirdparty->idprof5 = $thirdpartywithuser[
'prof5'];
570 $thirdparty->idprof6 = $thirdpartywithuser[
'prof6'];
572 $thirdparty->client = $thirdpartywithuser[
'client'];
573 $thirdparty->fournisseur = $thirdpartywithuser[
'fournisseur'];
575 $socid_return = $thirdparty->create($fuser);
577 if ($socid_return > 0) {
578 $thirdparty->fetch($socid_return);
585 $contact->socid = $thirdparty->id;
586 $contact->lastname = $thirdpartywithuser[
'name'];
587 $contact->firstname = $thirdpartywithuser[
'firstname'];
588 $contact->civility_id = $thirdparty->civility_id;
589 $contact->address = $thirdparty->address;
590 $contact->zip = $thirdparty->zip;
591 $contact->town = $thirdparty->town;
592 $contact->email = $thirdparty->email;
593 $contact->phone_pro = $thirdparty->phone;
594 $contact->phone_mobile = $thirdpartywithuser[
'phone_mobile'];
595 $contact->fax = $thirdparty->fax;
596 $contact->statut = 1;
597 $contact->country_id = $thirdparty->country_id;
598 $contact->country_code = $thirdparty->country_code;
600 $elementtype =
'socpeople';
605 $extrafields->fetch_name_optionals_label($elementtype,
true);
606 if (isset($extrafields->attributes[$elementtype][
'label']) && is_array($extrafields->attributes[$elementtype][
'label']) && count($extrafields->attributes[$elementtype][
'label'])) {
607 foreach ($extrafields->attributes[$elementtype][
'label'] as $key => $label) {
608 $key =
'contact_options_'.$key;
609 $key = substr($key, 8);
610 $contact->array_options[$key] = $thirdpartywithuser[$key];
614 $contact_id = $contact->create($fuser);
616 if ($contact_id > 0) {
621 $edituser =
new User($db);
623 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
625 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
627 if ($thirdpartywithuser[
'group_id'] > 0) {
628 $edituser->SetInGroup($thirdpartywithuser[
'group_id'], $conf->entity);
632 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$edituser->error;
636 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create : '.$contact->error;
641 $objectresp = array(
'result'=>array(
'result_code'=>
'OK',
'result_label'=>
'SUCCESS'),
'id'=>$socid_return);
646 $errorcode = join(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
652 $errorcode =
'NOT_CREATE'; $errorlabel =
'Object not create';
656 $errorcode =
'PERMISSION_DENIED'; $errorlabel =
'User does not have permission for this request';
663 'result'=>array(
'result_code' => $errorcode,
'result_label' => $errorlabel)