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=".((int)
$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 if (isset($thirdpartywithuser[$key])) {
626 $contact->array_options[$key] = $thirdpartywithuser[$key];
631 $contact_id = $contact->create($fuser);
633 if ($contact_id > 0) {
638 $edituser =
new User($db);
640 $id = $edituser->create_from_contact($contact, $thirdpartywithuser[
"login"]);
642 $edituser->setPassword($fuser, trim($thirdpartywithuser[
'password']));
644 if ($thirdpartywithuser[
'group_id'] > 0) {
645 $edituser->setInGroup((
int) $thirdpartywithuser[
'group_id'],
$conf->entity);
649 $errorcode =
'NOT_CREATE';
650 $errorlabel =
'Object not create : '.$edituser->error;
654 $errorcode =
'NOT_CREATE';
655 $errorlabel =
'Object not create : '.$contact->error;
660 $objectresp = array(
'result' => array(
'result_code' =>
'OK',
'result_label' =>
'SUCCESS'),
'id' => $socid_return);
664 $errorcode = implode(
', ', ($thirdparty->error ? array($thirdparty->error) : $thirdparty->errors));
670 $errorcode =
'NOT_CREATE';
671 $errorlabel =
'Object not create';
675 $errorcode =
'PERMISSION_DENIED';
676 $errorlabel =
'User does not have permission for this request';
683 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
702 dol_syslog(
"Function: setUserPassword login=".$authentication[
'login']);
704 if ($authentication[
'entity']) {
705 $conf->entity = $authentication[
'entity'];
708 $objectresp = array();
715 if (!$error && !$shortuser) {
717 $errorcode =
'BAD_PARAMETERS';
718 $errorlabel =
"Parameter shortuser must be provided.";
722 $fuser->loadRights();
724 if ($fuser->hasRight(
'user',
'user',
'password')
725 || ($fuser->hasRight(
'user',
'self',
'password') && $fuser->login == $shortuser[
'login'])) {
726 $userstat =
new User($db);
727 $res = $userstat->fetch(0, $shortuser[
'login']);
729 $res = $userstat->setPassword($userstat, $shortuser[
'password']);
730 if (is_int($res) && $res < 0) {
732 $errorcode =
'NOT_MODIFIED';
733 $errorlabel =
'Error when changing password';
736 'result' => array(
'result_code' =>
'OK',
'result_label' =>
''),
741 $errorcode =
'NOT_FOUND';
742 $errorlabel =
'User not found';
746 $errorcode =
'PERMISSION_DENIED';
747 $errorlabel =
'User does not have permission for this request';
754 'result' => array(
'result_code' => $errorcode,
'result_label' => $errorlabel)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined: