From 02fc896612ef247d5288ffb459cd9af2304d52f6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 27 May 2019 20:12:33 +0200 Subject: [PATCH] FIX Even with permission, can't validate leave once validator defined. --- htdocs/holiday/card.php | 75 ++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 2ac212527b3..6aa78445766 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -67,6 +67,11 @@ if (! empty($conf->global->HOLIDAY_FOR_NON_SALARIES_TOO)) $morefilter = ''; * Actions */ +if (GETPOST('cancel', 'alpha')) +{ + $action = ''; +} + // If create a request if ($action == 'create') { @@ -189,7 +194,35 @@ if ($action == 'create') } } -if ($action == 'update') +if ($action == 'update' && GETPOSTISSET('savevalidator') && ! empty($user->rights->holiday->approve)) +{ + $object = new Holiday($db); + $object->fetch($id); + + $object->oldcopy = dol_clone($object); + + $object->fk_validator = GETPOST('valideur', 'int'); + + if ($object->fk_validator != $object->oldcopy->fk_validator) + { + $verif = $object->update($user); + + if ($verif <= 0) + { + setEventMessages($object->error, $object->errors, 'warnings'); + $action='editvalidator'; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id); + exit; + } + } + + $action = ''; +} + +if ($action == 'update' && ! GETPOSTISSET('savevalidator')) { $date_debut = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year')); $date_fin = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year')); @@ -1047,9 +1080,9 @@ else { $head=holiday_prepare_head($object); - if ($action == 'edit' && $object->statut == 1) + if (($action == 'edit' && $object->statut == 1) || ($action == 'editvalidator')) { - $edit = true; + if ($action == 'edit' && $object->statut == 1) $edit = true; print '
'."\n"; print ''."\n"; print ''."\n"; @@ -1089,7 +1122,7 @@ else $starthalfday=($object->halfday == -1 || $object->halfday == 2)?'afternoon':'morning'; $endhalfday=($object->halfday == 1 || $object->halfday == 2)?'morning':'afternoon'; - if(!$edit) + if (!$edit) { print ''; print ''.$langs->trans('DateDebCP').' ('.$langs->trans("FirstDayOfHoliday").')'; @@ -1188,25 +1221,40 @@ else } // Validator - if (!$edit) { + if (!$edit && $action != 'editvalidator') { print ''; print ''; if ($object->statut == 3 || $object->statut == 4) print $langs->trans('ApprovedBy'); else print $langs->trans('ReviewedByCP'); print ''; - print ''.$valideur->getNomUrl(-1).''; + print ''.$valideur->getNomUrl(-1); + $include_users = $object->fetch_users_approver_holiday(); + if (in_array($user->id, $include_users)) + { + print ''.img_edit($langs->trans("Edit")).''; + } + print ''; print ''; } else { print ''; print ''.$langs->trans('ReviewedByCP').''; print ''; $include_users = $object->fetch_users_approver_holiday(); + if (! in_array($object->fk_validator, $include_users)) // Add the current validator to the list to not lose it when editing. + { + $include_users[]=$object->fk_validator; + } if (empty($include_users)) print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateHolidays"); else { $s=$form->select_dolusers($object->fk_validator, "valideur", 1, ($user->admin ? '' : array($user->id)), 0, $include_users); print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate")); } + if ($action == 'editvalidator') + { + print ''; + print ''; + } print ''; print ''; } @@ -1285,20 +1333,21 @@ else print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("TitleSetToDraft"),$langs->trans("ConfirmSetToDraft"),"confirm_draft", '', 1, 1); } - - if ($action == 'edit' && $object->statut == 1) + if (($action == 'edit' && $object->statut == 1) || ($action == 'editvalidator')) { - print '
'; - if ($cancreate && $object->statut == 1) + if ($action == 'edit' && $object->statut == 1) { - print ''; + print '
'; + if ($cancreate && $object->statut == 1) + { + print ''; + } + print '
'; } - print '
'; print '
'; } - if (! $edit) { print '
';