FIX: User id correction on holiday request

This commit is contained in:
fmarcet 2017-06-19 16:23:44 +02:00 committed by Ferran Marcet
parent 03eadcebf1
commit c4546b6da6

View File

@ -39,7 +39,6 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
$myparam = GETPOST("myparam"); $myparam = GETPOST("myparam");
$action=GETPOST('action', 'alpha'); $action=GETPOST('action', 'alpha');
$id=GETPOST('id', 'int'); $id=GETPOST('id', 'int');
$userID = GETPOST('userID')?GETPOST('userID'):$user->id;
// Protection if external user // Protection if external user
if ($user->societe_id > 0) accessforbidden(); if ($user->societe_id > 0) accessforbidden();
@ -57,8 +56,8 @@ if ($action == 'create')
$cp = new Holiday($db); $cp = new Holiday($db);
// If no right to create a request // If no right to create a request
$userid = GETPOST('userid'); $fuserid = GETPOST('fuserid');
if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all)))
{ {
$error++; $error++;
setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); setEventMessages($langs->trans('CantCreateCP'), null, 'errors');
@ -112,7 +111,7 @@ if ($action == 'create')
} }
// Check if there is already holiday for this period // Check if there is already holiday for this period
$verifCP = $cp->verifDateHolidayCP($userid, $date_debut, $date_fin, $halfday); $verifCP = $cp->verifDateHolidayCP($fuserid, $date_debut, $date_fin, $halfday);
if (! $verifCP) if (! $verifCP)
{ {
header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=alreadyCP'); header('Location: '.$_SERVER["PHP_SELF"].'?action=request&error=alreadyCP');
@ -140,7 +139,7 @@ if ($action == 'create')
if (! $error) if (! $error)
{ {
$cp->fk_user = $userid; $cp->fk_user = $fuserid;
$cp->description = $description; $cp->description = $description;
$cp->date_debut = $date_debut; $cp->date_debut = $date_debut;
$cp->date_fin = $date_fin; $cp->date_fin = $date_fin;
@ -682,7 +681,7 @@ llxHeader(array(),$langs->trans('CPTitreMenu'));
if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create') if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create')
{ {
// Si l'utilisateur n'a pas le droit de faire une demande // Si l'utilisateur n'a pas le droit de faire une demande
if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all)))
{ {
$errors[]=$langs->trans('CantCreateCP'); $errors[]=$langs->trans('CantCreateCP');
} }
@ -762,7 +761,6 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
// Formulaire de demande // Formulaire de demande
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="return valider()" name="demandeCP">'."\n"; print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" onsubmit="return valider()" name="demandeCP">'."\n";
print '<input type="hidden" name="action" value="create" />'."\n"; print '<input type="hidden" name="action" value="create" />'."\n";
print '<input type="hidden" name="userID" value="'.$userID.'" />'."\n";
dol_fiche_head(); dol_fiche_head();
@ -793,10 +791,10 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create
print '<td>'; print '<td>';
if (empty($user->rights->holiday->write_all)) if (empty($user->rights->holiday->write_all))
{ {
print $form->select_dolusers($userid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); print $form->select_dolusers($fuserid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
print '<input type="hidden" name="userid" value="'.$userid.'">'; print '<input type="hidden" name="fuserid" value="'.$fuserid.'">';
} }
else print $form->select_dolusers(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0); else print $form->select_dolusers(GETPOST('fuserid')?GETPOST('fuserid'):$user->id,'fuserid',0,'',0);
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';