diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 096a0195668..bd3ad481cd8 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -191,6 +191,9 @@ if (empty($reshook)) { if ($result < 0) { $langs->load("errors"); setEventMessages($langs->trans($nuser->error), null, 'errors'); + } else { + setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs'); + $action = ''; } } else { setEventMessages($object->error, $object->errors, 'errors'); @@ -1272,7 +1275,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // Confirm create user if ($action == 'create_user') { - $login = $object->login; + $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login); if (empty($login)) { // Full firstname and name separated with a dot : firstname.name include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -1701,13 +1704,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { } } - // Delete - if ($user->rights->adherent->supprimer) { - print '
'.$langs->trans("Delete")."
\n"; - } else { - print '
'.$langs->trans("Delete")."
"; - } - // Action SPIP if (!empty($conf->mailmanspip->enabled) && !empty($conf->global->ADHERENT_USE_SPIP)) { $isinspip = $mailmanspip->is_in_spip($object); @@ -1719,6 +1715,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print '
'.$langs->trans("AddIntoSpip")."
\n"; } } + + // Delete + if ($user->rights->adherent->supprimer) { + print '
'.$langs->trans("Delete")."
\n"; + } else { + print '
'.$langs->trans("Delete")."
"; + } } } print ''; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index ecd93298898..9977910518b 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -1833,7 +1833,7 @@ if ($action == 'create') { //Form to close proposal (signed or not) $formquestion = array( - array('type' => 'select', 'name' => 'statut', 'label' => ''.$langs->trans("CloseAs").'', 'values' => array(2=>$object->LibStatut($object::STATUS_SIGNED), 3=>$object->LibStatut($object::STATUS_NOTSIGNED))), + array('type' => 'select', 'name' => 'statut', 'label' => ''.$langs->trans("CloseAs").'', 'values' => array($object::STATUS_SIGNED => $object->LibStatut($object::STATUS_SIGNED), $object::STATUS_NOTSIGNED => $object->LibStatut($object::STATUS_NOTSIGNED))), array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace) ); diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index edb0d256ea2..9d8673578dd 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1688,10 +1688,23 @@ function is_ip($ip) */ function dol_buildlogin($lastname, $firstname) { - $login = strtolower(dol_string_unaccent($firstname)); - $login .= ($login ? '.' : ''); - $login .= strtolower(dol_string_unaccent($lastname)); - $login = dol_string_nospecial($login, ''); // For special names + global $conf; + + //$conf->global->MAIN_BUILD_LOGIN_RULE = 'f.lastname'; + if (!empty($conf->global->MAIN_BUILD_LOGIN_RULE) && $conf->global->MAIN_BUILD_LOGIN_RULE == 'f.lastname') { // f.lastname + $login = strtolower(dol_string_unaccent(dol_trunc($firstname, 1, 'right', 'UTF-8', 1))); + $login .= ($login ? '.' : ''); + $login .= strtolower(dol_string_unaccent($lastname)); + $login = dol_string_nospecial($login, ''); // For special names + } else { // firstname.lastname + $login = strtolower(dol_string_unaccent($firstname)); + $login .= ($login ? '.' : ''); + $login .= strtolower(dol_string_unaccent($lastname)); + $login = dol_string_nospecial($login, ''); // For special names + } + + // TODO Add a hook to allow external modules to suggest new rules + return $login; } diff --git a/htdocs/langs/en_US/recruitment.lang b/htdocs/langs/en_US/recruitment.lang index bc709f678d0..ba86c8f9d85 100644 --- a/htdocs/langs/en_US/recruitment.lang +++ b/htdocs/langs/en_US/recruitment.lang @@ -61,6 +61,7 @@ RequestedRemuneration=Requested remuneration ProposedRemuneration=Proposed remuneration ContractProposed=Contract proposed ContractSigned=Contract signed +ContractRefused=Contract refused RecruitmentCandidature=Application JobPositions=Job positions RecruitmentCandidatures=Applications diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index 683587ddbf7..4d01bc4b0db 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -68,6 +68,7 @@ class RecruitmentCandidature extends CommonObject //const STATUS_INTERVIEW_SCHEDULED = 2; const STATUS_CONTRACT_PROPOSED = 3; const STATUS_CONTRACT_SIGNED = 5; + const STATUS_CONTRACT_REFUSED = 6; const STATUS_REFUSED = 8; const STATUS_CANCELED = 9; @@ -679,7 +680,7 @@ class RecruitmentCandidature extends CommonObject public function reopen($user, $notrigger = 0) { // Protection - if ($this->status != self::STATUS_CANCELED) + if ($this->status != self::STATUS_REFUSED && $this->status != self::STATUS_CANCELED && $this->status != self::STATUS_CONTRACT_REFUSED) { return 0; } @@ -821,13 +822,15 @@ class RecruitmentCandidature extends CommonObject $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Received').' ('.$langs->trans("InterviewToDo").')'; $this->labelStatus[self::STATUS_CONTRACT_PROPOSED] = $langs->trans('ContractProposed'); $this->labelStatus[self::STATUS_CONTRACT_SIGNED] = $langs->trans('ContractSigned'); - $this->labelStatus[self::STATUS_REFUSED] = $langs->trans('Refused'); + $this->labelStatus[self::STATUS_CONTRACT_REFUSED] = $langs->trans('ContractRefused'); $this->labelStatus[self::STATUS_REFUSED] = $langs->trans('Refused'); $this->labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled'); $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft'); $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Received'); $this->labelStatusShort[self::STATUS_CONTRACT_PROPOSED] = $langs->trans('ContractProposed'); $this->labelStatusShort[self::STATUS_CONTRACT_SIGNED] = $langs->trans('ContractSigned'); + $this->labelStatusShort[self::STATUS_CONTRACT_REFUSED] = $langs->trans('ContractRefused'); + $this->labelStatusShort[self::STATUS_REFUSED] = $langs->trans('Refused'); $this->labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Canceled'); } diff --git a/htdocs/recruitment/recruitmentcandidature_card.php b/htdocs/recruitment/recruitmentcandidature_card.php index 380b3da7729..d688ca31c8d 100644 --- a/htdocs/recruitment/recruitmentcandidature_card.php +++ b/htdocs/recruitment/recruitmentcandidature_card.php @@ -59,11 +59,12 @@ if (!$res) die("Include of main fails"); require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; dol_include_once('/recruitment/class/recruitmentcandidature.class.php'); dol_include_once('/recruitment/lib/recruitment_recruitmentcandidature.lib.php'); // Load translation files required by the page -$langs->loadLangs(array("recruitment", "other")); +$langs->loadLangs(array("recruitment", "other", "users")); // Get parameters $id = GETPOST('id', 'int'); @@ -165,6 +166,100 @@ if (empty($reshook)) } } + if ($action == 'confirm_makeofferordecline' && $permissiontoadd && !GETPOST('cancel', 'alpha')) { + if (!(GETPOST('status', 'int') > 0)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors'); + $action = 'makeofferordecline'; + } else { + // prevent browser refresh from closing proposal several times + if ($object->status == $object::STATUS_VALIDATED) + { + $db->begin(); + + if (GETPOST('status', 'int') == $object::STATUS_REFUSED) { + $result = $object->setStatut($object::STATUS_REFUSED, null, '', $triggermodname); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + $result = $object->setStatut($object::STATUS_CONTRACT_PROPOSED, null, '', $triggermodname); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + if (!$error) + { + $db->commit(); + } else { + $db->rollback(); + } + } + } + } + + if ($action == 'confirm_closeas' && $permissiontoadd && !GETPOST('cancel', 'alpha')) { + if (!(GETPOST('status', 'int') > 0)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CloseAs")), null, 'errors'); + $action = 'makeofferordecline'; + } else { + // prevent browser refresh from closing proposal several times + if ($object->status == $object::STATUS_CONTRACT_PROPOSED) + { + $db->begin(); + + if (GETPOST('status', 'int') == $object::STATUS_CONTRACT_REFUSED) { + $result = $object->setStatut($object::STATUS_CONTRACT_REFUSED, null, '', $triggermodname); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + $result = $object->setStatut($object::STATUS_CONTRACT_SIGNED, null, '', $triggermodname); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + if (!$error) + { + $db->commit(); + } else { + $db->rollback(); + } + } + } + } + + // Create user from a member + if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) { + if ($result > 0) { + // Creation user + $nuser = new User($db); + $nuser->login = GETPOST('login', 'alphanohtml'); + $nuser->fk_soc = 0; + $nuser->employee = 1; + $nuser->firstname = $object->firstname; + $nuser->lastname = $object->lastname; + $nuser->personal_mobile = $object->phone; + $nuser->birth = $object->date_birth; + $nuser->salary = $object->remuneration_proposed; + + $result = $nuser->create($user); + + if ($result < 0) { + $langs->load("errors"); + setEventMessages($langs->trans($nuser->error), null, 'errors'); + $action = 'create_user'; + } else { + setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs'); + $action = ''; + } + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create_user'; + } + } + // Actions to send emails $triggersendname = 'RECRUITMENTCANDIDATURE_SENTBYMAIL'; $autocopy = 'MAIN_MAIL_AUTOCOPY_RECRUITMENTCANDIDATURE_TO'; @@ -302,21 +397,61 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneAsk', $object->ref), 'confirm_clone', $formquestion, 'yes', 1); } - // Confirmation of action xxxx - if ($action == 'xxx') + if ($action == 'makeofferordecline') { - $formquestion = array(); - /* - $forcecombo=0; - if ($conf->browser->name == 'ie') $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy + $langs->load("propal"); + + //Form to close proposal (signed or not) $formquestion = array( - // 'text' => $langs->trans("ConfirmClone"), - // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), - // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), - // array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, '', 0, $forcecombo)) + array('type' => 'select', 'name' => 'status', 'label' => ''.$langs->trans("CloseAs").'', 'values' => array($object::STATUS_CONTRACT_PROPOSED => $object->LibStatut($object::STATUS_CONTRACT_PROPOSED), $object::STATUS_REFUSED => $object->LibStatut($object::STATUS_REFUSED))), + array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace) ); - */ - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('XXX'), $text, 'confirm_xxx', $formquestion, 0, 1, 220); + + $text = ''; + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_makeofferordecline', $formquestion, '', 1, 250); + } + + if ($action == 'closeas') + { + $langs->load("propal"); + + //Form to close proposal (signed or not) + $formquestion = array( + array('type' => 'select', 'name' => 'status', 'label' => ''.$langs->trans("CloseAs").'', 'values' => array($object::STATUS_CONTRACT_SIGNED => $object->LibStatut($object::STATUS_CONTRACT_PROPOSED), $object::STATUS_CONTRACT_REFUSED => $object->LibStatut($object::STATUS_CONTRACT_REFUSED))), + array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace) + ); + + $text = ''; + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetAcceptedRefused'), $text, 'confirm_closeas', $formquestion, '', 1, 250); + } + + // Confirm create user + if ($action == 'create_user') { + $login = (GETPOSTISSET('login') ? GETPOST('login', 'alphanohtml') : $object->login); + if (empty($login)) { + // Full firstname and name separated with a dot : firstname.name + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $login = dol_buildlogin($object->lastname, $object->firstname); + } + if (empty($login)) $login = strtolower(substr($object->firstname, 0, 4)).strtolower(substr($object->lastname, 0, 4)); + + // Create a form array + $formquestion = array( + array('label' => $langs->trans("LoginToCreate"), 'type' => 'text', 'name' => 'login', 'value' => $login) + ); + /* + if (!empty($conf->societe->enabled) && $object->socid > 0) { + $object->fetch_thirdparty(); + $formquestion[] = array('label' => $langs->trans("UserWillBe"), 'type' => 'radio', 'name' => 'internalorexternal', 'default'=>'external', 'values' => array('external'=>$langs->trans("External").' - '.$langs->trans("LinkedToDolibarrThirdParty").' '.$object->thirdparty->getNomUrl(1, '', 0, 1), 'internal'=>$langs->trans("Internal"))); + } + $text = ''; + if (!empty($conf->societe->enabled) && $object->socid <= 0) { + $text .= $langs->trans("UserWillBeInternalUser").'
'; + } */ + $text .= $langs->trans("ConfirmCreateLogin"); + print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("CreateDolibarrLogin"), $text, "confirm_create_user", $formquestion, 'yes'); } // Call Hook formConfirm @@ -500,12 +635,21 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } } - // Refuse - Decline - if ($object->status >= $object::STATUS_VALIDATED && $object->status < $object::STATUS_REFUSED) + // Make offer - Refuse - Decline + if ($object->status >= $object::STATUS_VALIDATED && $object->status < $object::STATUS_CONTRACT_PROPOSED) { if ($permissiontoadd) { - print ''.$langs->trans("Decline").''; + print ''.$langs->trans("MakeOffer").' / '.$langs->trans("Decline").''; + } + } + + // Contract refused / accepted + if ($object->status == $object::STATUS_CONTRACT_PROPOSED) + { + if ($permissiontoadd) + { + print ''.$langs->trans("Accept").' / '.$langs->trans("Decline").''; } } @@ -515,30 +659,34 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$langs->trans("ToClone").''."\n"; } - /* - if ($permissiontoadd) + // Button to convert into a user + if ($object->status == $object::STATUS_CONTRACT_SIGNED) { - if ($object->status == $object::STATUS_ENABLED) - { - print ''.$langs->trans("Disable").''."\n"; - } - else - { - print ''.$langs->trans("Enable").''."\n"; + if ($user->rights->user->user->creer) { + // TODO Check if a user already exists + $useralreadyexists = 0; + if (empty($useralreadyexists)) { + print '
'.$langs->trans("CreateDolibarrLogin").'
'; + } else { + print '
'.$langs->trans("CreateDolibarrLogin").'
'; + } + } else { + print '
'.$langs->trans("CreateDolibarrLogin")."
"; } } + + // Cancel if ($permissiontoadd) { if ($object->status == $object::STATUS_VALIDATED) { print ''.$langs->trans("Cancel").''."\n"; } - else + elseif ($object->status == $object::STATUS_REFUSED || $object->status == $object::STATUS_CANCELED || $object->status == $object::STATUS_CONTRACT_REFUSED) { - print ''.$langs->trans("Re-Open").''."\n"; + print ''.$langs->trans("Re-Open").''."\n"; } } - */ // Delete (need delete permission, or if draft, just need create/modify permission) if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 1f471e39ff2..067e7aff370 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1268,7 +1268,10 @@ class User extends CommonObject $this->country_id = $contact->country_id; $this->employee = 0; - if (empty($login)) $login = strtolower(substr($contact->firstname, 0, 4)).strtolower(substr($contact->lastname, 0, 4)); + if (empty($login)) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $login = dol_buildlogin($contact->lastname, $contact->firstname); + } $this->login = $login; $this->db->begin(); @@ -1315,9 +1318,9 @@ class User extends CommonObject * Create a user into database from a member object. * If $member->fk_soc is set, it will be an external user. * - * @param Adherent $member Object member source - * @param string $login Login to force - * @return int <0 if KO, if OK, return id of created account + * @param Adherent $member Object member source + * @param string $login Login to force + * @return int <0 if KO, if OK, return id of created account */ public function create_from_member($member, $login = '') { @@ -1341,7 +1344,10 @@ class User extends CommonObject $this->pass = $member->pass; $this->pass_crypted = $member->pass_indatabase_crypted; - if (empty($login)) $login = strtolower(substr($member->firstname, 0, 4)).strtolower(substr($member->lastname, 0, 4)); + if (empty($login)) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $login = dol_buildlogin($member->lastname, $member->firstname); + } $this->login = $login; $this->db->begin();