diff --git a/ChangeLog b/ChangeLog index 9a5a532146a..8bf7668ec2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -60,6 +60,7 @@ For users: - New: When a subscription is recorded with invoice and payment: - the document (PDF) of invoice is also generated. - the invoice is set to status paid. +- New: Can enter holiday for someone else if user has permission for. - Fix: Project Task numbering customs rule works. - Fix: Add actions events not implemented. - Fix: Price min of composition is not supplier price min by quantity. diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 4bf687c9704..eadfa84ba6c 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -134,42 +134,42 @@ class modHoliday extends DolibarrModules $r=0; $this->rights[$r][0] = 20001; // Permission id (must not be already used) - $this->rights[$r][1] = 'Lire/créer/modifier ses demandes de congés payés'; // Permission label + $this->rights[$r][1] = 'Create/modify your own holidays'; // Permission label $this->rights[$r][3] = 1; // Permission by default for new user (0/1) $this->rights[$r][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20002; // Permission id (must not be already used) - $this->rights[$r][1] = 'Lire/créer/modifier toutes les demandes de congés payés'; // Permission label + $this->rights[$r][1] = 'Create/modify hollidays for everybody'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) - $this->rights[$r][4] = 'lire_tous'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + $this->rights[$r][4] = 'write_all'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20003; // Permission id (must not be already used) - $this->rights[$r][1] = 'Supprimer des demandes de congés payés'; // Permission label + $this->rights[$r][1] = 'Delete holidays'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'delete'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20004; // Permission id (must not be already used) - $this->rights[$r][1] = 'Définir les congés payés des utilisateurs'; // Permission label + $this->rights[$r][1] = 'Setup holidays of users'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'define_holiday'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20005; // Permission id (must not be already used) - $this->rights[$r][1] = 'Voir les logs de modification des congés payés'; // Permission label + $this->rights[$r][1] = 'See logs for holidays requests'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'view_log'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $r++; $this->rights[$r][0] = 20006; // Permission id (must not be already used) - $this->rights[$r][1] = 'Accéder au rapport mensuel des congés payés'; // Permission label + $this->rights[$r][1] = 'Read holidays monthly report'; // Permission label $this->rights[$r][3] = 0; // Permission by default for new user (0/1) $this->rights[$r][4] = 'month_report'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) @@ -179,7 +179,7 @@ class modHoliday extends DolibarrModules $this->menus = array(); // List of menus to add $r=0; - + /* Move to HRM menu // Add here entries to declare new menus $this->menu[$r]=array( 'fk_menu'=>0, // Put 0 if this is a top menu @@ -261,7 +261,7 @@ class modHoliday extends DolibarrModules 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both $r++; */ - + // Exports $r=1; diff --git a/htdocs/holiday/fiche.php b/htdocs/holiday/fiche.php index 10fb4121147..d66d1c8cfbd 100644 --- a/htdocs/holiday/fiche.php +++ b/htdocs/holiday/fiche.php @@ -6,7 +6,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or + * the Free Software Foundation; either version 3 of the License, orwrite * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -38,11 +38,11 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; $myparam = GETPOST("myparam"); $action=GETPOST('action', 'alpha'); $id=GETPOST('id', 'int'); +$userid = GETPOST('userid')?GETPOST('userid'):$user->id; // Protection if external user if ($user->societe_id > 0) accessforbidden(); -$user_id = $user->id; $now=dol_now(); @@ -56,93 +56,96 @@ if ($action == 'create') $cp = new Holiday($db); // Si pas le droit de créer une demande - if(!$user->rights->holiday->write) + if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) { - header('Location: fiche.php?action=request&error=CantCreate'); - exit; + $error++; + setEventMessage($langs->trans('CantCreateCP')); + $action='request'; } - $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')); - $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); - $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); - $starthalfday=GETPOST('starthalfday'); - $endhalfday=GETPOST('endhalfday'); - $halfday=0; - if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; - else if ($starthalfday == 'afternoon') $halfday=-1; - else if ($endhalfday == 'morning') $halfday=1; - - $valideur = GETPOST('valideur'); - $description = trim(GETPOST('description')); - $userID = GETPOST('userID'); - - // Si pas de date de début - if (empty($date_debut)) + if (! $error) { - header('Location: fiche.php?action=request&error=nodatedebut'); - exit; + $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')); + $date_debut_gmt = dol_mktime(0, 0, 0, GETPOST('date_debut_month'), GETPOST('date_debut_day'), GETPOST('date_debut_year'), 1); + $date_fin_gmt = dol_mktime(0, 0, 0, GETPOST('date_fin_month'), GETPOST('date_fin_day'), GETPOST('date_fin_year'), 1); + $starthalfday=GETPOST('starthalfday'); + $endhalfday=GETPOST('endhalfday'); + $halfday=0; + if ($starthalfday == 'afternoon' && $endhalfday == 'morning') $halfday=2; + else if ($starthalfday == 'afternoon') $halfday=-1; + else if ($endhalfday == 'morning') $halfday=1; + + $valideur = GETPOST('valideur'); + $description = trim(GETPOST('description')); + $userID = GETPOST('userID'); + + // Si pas de date de début + if (empty($date_debut)) + { + header('Location: fiche.php?action=request&error=nodatedebut'); + exit; + } + + // Si pas de date de fin + if (empty($date_fin)) + { + header('Location: fiche.php?action=request&error=nodatefin'); + exit; + } + + // Si date de début après la date de fin + if ($date_debut > $date_fin) + { + header('Location: fiche.php?action=request&error=datefin'); + exit; + } + + // Check if there is already holiday for this period + $verifCP = $cp->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday); + if (! $verifCP) + { + header('Location: fiche.php?action=request&error=alreadyCP'); + exit; + } + + // Si aucun jours ouvrés dans la demande + $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); + if($nbopenedday < 1) + { + header('Location: fiche.php?action=request&error=DureeHoliday'); + exit; + } + + // Si pas de validateur choisi + if ($valideur < 1) + { + header('Location: fiche.php?action=request&error=Valideur'); + exit; + } + + $cp->fk_user = $userid; + $cp->description = $description; + $cp->date_debut = $date_debut; + $cp->date_fin = $date_fin; + $cp->fk_validator = $valideur; + $cp->halfday = $halfday; + + $verif = $cp->create($userid); + + // Si pas d'erreur SQL on redirige vers la fiche de la demande + if ($verif > 0) + { + header('Location: fiche.php?id='.$verif); + exit; + } + else + { + // Sinon on affiche le formulaire de demande avec le message d'erreur SQL + header('Location: fiche.php?action=request&error=SQL_Create&msg='.$cp->error); + exit; + } } - - // Si pas de date de fin - if (empty($date_fin)) - { - header('Location: fiche.php?action=request&error=nodatefin'); - exit; - } - - // Si date de début après la date de fin - if ($date_debut > $date_fin) - { - header('Location: fiche.php?action=request&error=datefin'); - exit; - } - - // Check if there is already holiday for this period - $verifCP = $cp->verifDateHolidayCP($userID, $date_debut, $date_fin, $halfday); - if (! $verifCP) - { - header('Location: fiche.php?action=request&error=alreadyCP'); - exit; - } - - // Si aucun jours ouvrés dans la demande - $nbopenedday=num_open_day($date_debut_gmt, $date_fin_gmt, 0, 1, $halfday); - if($nbopenedday < 1) - { - header('Location: fiche.php?action=request&error=DureeHoliday'); - exit; - } - - // Si pas de validateur choisi - if ($valideur < 1) - { - header('Location: fiche.php?action=request&error=Valideur'); - exit; - } - - $cp->fk_user = $user_id; - $cp->description = $description; - $cp->date_debut = $date_debut; - $cp->date_fin = $date_fin; - $cp->fk_validator = $valideur; - $cp->halfday = $halfday; - - $verif = $cp->create($user_id); - - // Si pas d'erreur SQL on redirige vers la fiche de la demande - if ($verif > 0) - { - header('Location: fiche.php?id='.$verif); - exit; - } - else - { - // Sinon on affiche le formulaire de demande avec le message d'erreur SQL - header('Location: fiche.php?action=request&error=SQL_Create&msg='.$cp->error); - exit; - } - } if ($action == 'update') @@ -159,7 +162,7 @@ if ($action == 'update') else if ($endhalfday == 'morning') $halfday=1; // Si pas le droit de modifier une demande - if(!$user->rights->holiday->write) + if (! $user->rights->holiday->write) { header('Location: fiche.php?action=request&error=CantUpdate'); exit; @@ -168,11 +171,13 @@ if ($action == 'update') $cp = new Holiday($db); $cp->fetch($_POST['holiday_id']); - // Si en attente de validation + $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); + + // Si en attente de validation if ($cp->statut == 1) { // Si c'est le créateur ou qu'il a le droit de tout lire / modifier - if ($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) + if ($canedit) { $valideur = $_POST['valideur']; $description = trim($_POST['description']); @@ -247,11 +252,13 @@ if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes') $cp = new Holiday($db); $cp->fetch($id); + $canedit=(($user->id == $cp->fk_user && $user->rights->holiday->write) || ($user->id != $cp->fk_user && $user->rights->holiday->write_all)); + // Si c'est bien un brouillon if ($cp->statut == 1 || $cp->statut == 3) { // Si l'utilisateur à le droit de lire cette demande, il peut la supprimer - if ($user->id == $cp->fk_user || $user->rights->holiday->lire_tous) + if ($canedit) { $result=$cp->delete($id); } @@ -653,13 +660,12 @@ $cp = new Holiday($db); $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon")); - llxHeader(array(),$langs->trans('CPTitreMenu')); -if (empty($id) || $action == 'add' || $action == 'request') +if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create') { // Si l'utilisateur n'a pas le droit de faire une demande - if(!$user->rights->holiday->write) + if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) { $errors[]=$langs->trans('CantCreateCP'); } @@ -739,16 +745,26 @@ if (empty($id) || $action == 'add' || $action == 'request') // Formulaire de demande print '