Fix generation of user from member, contact, applications for job

This commit is contained in:
Laurent Destailleur 2020-11-04 13:33:52 +01:00
parent 1cc7b41de3
commit 7294a47ef5
7 changed files with 222 additions and 48 deletions

View File

@ -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 '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete")."</a></div>\n";
} else {
print '<div class="inline-block divButAction"><font class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Delete")."</font></div>";
}
// 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 '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$object->id.'&action=add_spip">'.$langs->trans("AddIntoSpip")."</a></div>\n";
}
}
// Delete
if ($user->rights->adherent->supprimer) {
print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete")."</a></div>\n";
} else {
print '<div class="inline-block divButAction"><font class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Delete")."</font></div>";
}
}
}
print '</div>';

View File

@ -1833,7 +1833,7 @@ if ($action == 'create')
{
//Form to close proposal (signed or not)
$formquestion = array(
array('type' => 'select', 'name' => 'statut', 'label' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', 'values' => array(2=>$object->LibStatut($object::STATUS_SIGNED), 3=>$object->LibStatut($object::STATUS_NOTSIGNED))),
array('type' => 'select', 'name' => 'statut', 'label' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', '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)
);

View File

@ -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;
}

View File

@ -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

View File

@ -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');
}

View File

@ -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' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', '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' => '<span class="fieldrequired">'.$langs->trans("CloseAs").'</span>', '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").'<br>';
} */
$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 '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_decline&confirm=yes">'.$langs->trans("Decline").'</a>';
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=makeofferordecline">'.$langs->trans("MakeOffer").' / '.$langs->trans("Decline").'</a>';
}
}
// Contract refused / accepted
if ($object->status == $object::STATUS_CONTRACT_PROPOSED)
{
if ($permissiontoadd)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=closeas">'.$langs->trans("Accept").' / '.$langs->trans("Decline").'</a>';
}
}
@ -515,30 +659,34 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&object=recruitmentcandidature">'.$langs->trans("ToClone").'</a>'."\n";
}
/*
if ($permissiontoadd)
// Button to convert into a user
if ($object->status == $object::STATUS_CONTRACT_SIGNED)
{
if ($object->status == $object::STATUS_ENABLED)
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable">'.$langs->trans("Disable").'</a>'."\n";
}
else
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable">'.$langs->trans("Enable").'</a>'."\n";
if ($user->rights->user->user->creer) {
// TODO Check if a user already exists
$useralreadyexists = 0;
if (empty($useralreadyexists)) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
}
} else {
print '<div class="inline-block divButAction"><font class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("CreateDolibarrLogin")."</font></div>";
}
}
// Cancel
if ($permissiontoadd)
{
if ($object->status == $object::STATUS_VALIDATED)
{
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close">'.$langs->trans("Cancel").'</a>'."\n";
}
else
elseif ($object->status == $object::STATUS_REFUSED || $object->status == $object::STATUS_CANCELED || $object->status == $object::STATUS_CONTRACT_REFUSED)
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen">'.$langs->trans("Re-Open").'</a>'."\n";
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("Re-Open").'</a>'."\n";
}
}
*/
// Delete (need delete permission, or if draft, just need create/modify permission)
if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd))

View File

@ -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();