2012-09-05 03:26:57 +02:00
< ? php
2016-03-03 08:41:39 +01:00
/* Copyright ( C ) 2011 Dimitri Mouillard < dmouillard @ teclib . com >
2016-09-01 11:29:30 +02:00
* Copyright ( C ) 2012 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2012 - 2016 Regis Houssin < regis . houssin @ inodbox . com >
2016-03-03 08:41:39 +01:00
* Copyright ( C ) 2013 Juanjo Menent < jmenent @ 2 byte . es >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2017 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2018-09-09 09:36:12 +02:00
* Copyright ( C ) 2014 - 2017 Ferran Marcet < fmarcet @ 2 byte . es >
* Copyright ( C ) 2018 Frédéric France < frederic . france @ netlogic . fr >
2021-03-17 18:17:03 +01:00
* Copyright ( C ) 2020 - 2021 Udo Tamm < dev @ dolibit . de >
2012-11-14 11:29:22 +01:00
*
* 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
2014-05-07 15:03:05 +02:00
* the Free Software Foundation ; either version 3 of the License , orwrite
2012-11-14 11:29:22 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
2012-09-05 03:57:26 +02:00
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2012-11-14 11:29:22 +01:00
*/
2012-09-05 03:26:57 +02:00
/**
2014-09-18 21:18:25 +02:00
* \file htdocs / holiday / card . php
2012-09-05 03:26:57 +02:00
* \ingroup holiday
* \brief Form and file creation of paid holiday .
*/
2018-07-26 11:57:25 +02:00
require '../main.inc.php' ;
2012-09-06 10:39:25 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php' ;
2012-09-07 17:23:16 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php' ;
2017-03-25 07:26:26 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2012-09-24 21:37:19 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2012-12-01 15:45:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/holiday.lib.php' ;
2020-12-04 14:53:52 +01:00
require_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php' ;
2019-09-24 16:26:15 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php' ;
2012-09-05 03:26:57 +02:00
// Get parameters
2020-01-18 16:17:07 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
2019-09-24 16:26:15 +02:00
$confirm = GETPOST ( 'confirm' , 'alpha' );
2020-01-18 16:17:07 +01:00
$id = GETPOST ( 'id' , 'int' );
$ref = GETPOST ( 'ref' , 'alpha' );
$fuserid = ( GETPOST ( 'fuserid' , 'int' ) ? GETPOST ( 'fuserid' , 'int' ) : $user -> id );
2012-09-05 03:26:57 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
2021-08-22 19:22:47 +02:00
$langs -> loadLangs ( array ( " other " , " holiday " , " mails " , " trips " ));
2019-09-24 16:26:15 +02:00
2021-03-16 10:59:01 +01:00
$error = 0 ;
2020-01-18 16:17:07 +01:00
$now = dol_now ();
2017-01-23 17:36:50 +01:00
2018-03-19 20:46:43 +01:00
$childids = $user -> getAllChildIds ( 1 );
2020-11-05 19:00:06 +01:00
$morefilter = '' ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $conf -> global -> HOLIDAY_HIDE_FOR_NON_SALARIES )) {
$morefilter = 'AND employee = 1' ;
}
2018-03-19 20:46:43 +01:00
2019-06-23 18:08:24 +02:00
$object = new Holiday ( $db );
2019-11-01 21:30:19 +01:00
2019-09-24 16:26:15 +02:00
$extrafields = new ExtraFields ( $db );
// fetch optionals attributes and labels
2019-10-06 14:41:52 +02:00
$extrafields -> fetch_name_optionals_label ( $object -> table_element );
2019-09-24 16:26:15 +02:00
2021-02-26 17:59:31 +01:00
if (( $id > 0 ) || $ref ) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id , $ref );
// Check current user can read this leave request
$canread = 0 ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $user -> rights -> holiday -> readall )) {
$canread = 1 ;
}
if ( ! empty ( $user -> rights -> holiday -> read ) && in_array ( $object -> fk_user , $childids )) {
$canread = 1 ;
}
if ( ! $canread ) {
2020-09-07 10:18:17 +02:00
accessforbidden ();
}
2019-06-23 18:08:24 +02:00
}
2021-08-06 16:22:19 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'holidaycard' , 'globalcard' ));
2019-09-05 22:48:33 +02:00
$cancreate = 0 ;
2020-10-10 15:45:04 +02:00
2021-02-26 17:59:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> holiday -> writeall_advance )) {
$cancreate = 1 ;
}
if ( ! empty ( $user -> rights -> holiday -> write ) && in_array ( $fuserid , $childids )) {
$cancreate = 1 ;
}
2019-09-05 22:48:33 +02:00
$candelete = 0 ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $user -> rights -> holiday -> delete )) {
$candelete = 1 ;
}
if ( $object -> statut == Holiday :: STATUS_DRAFT && $user -> rights -> holiday -> write && in_array ( $object -> fk_user , $childids )) {
$candelete = 1 ;
}
2019-06-23 18:08:24 +02:00
2019-11-01 21:27:19 +01:00
// Protection if external user
2021-02-26 17:59:31 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2019-11-01 21:27:19 +01:00
$result = restrictedArea ( $user , 'holiday' , $object -> id , 'holiday' );
2019-09-24 16:26:15 +02:00
2013-09-24 18:06:07 +02:00
/*
2012-09-05 03:26:57 +02:00
* Actions
2013-09-24 18:06:07 +02:00
*/
2012-09-05 03:26:57 +02:00
2019-09-24 16:26:15 +02:00
$parameters = array ( 'socid' => $socid );
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 17:59:31 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
if ( empty ( $reshook )) {
if ( $cancel ) {
if ( ! empty ( $backtopage )) {
2019-09-24 16:26:15 +02:00
header ( " Location: " . $backtopage );
exit ;
}
2020-09-08 21:27:28 +02:00
$action = '' ;
2019-09-24 16:26:15 +02:00
}
2019-06-23 18:08:24 +02:00
2020-09-18 04:53:43 +02:00
// Add leave request
2021-02-26 17:59:31 +01:00
if ( $action == 'add' ) {
2020-09-08 21:27:28 +02:00
// If no right to create a request
2021-02-26 17:59:31 +01:00
if ( ! $cancreate ) {
2020-09-08 21:27:28 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( 'CantCreateCP' ), null , 'errors' );
2020-09-18 04:53:43 +02:00
$action = 'create' ;
2020-09-08 21:27:28 +02:00
}
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-08 21:27:28 +02:00
$object = new Holiday ( $db );
$db -> begin ();
$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' );
$type = GETPOST ( 'type' );
$halfday = 0 ;
2021-02-26 17:59:31 +01:00
if ( $starthalfday == 'afternoon' && $endhalfday == 'morning' ) {
$halfday = 2 ;
} elseif ( $starthalfday == 'afternoon' ) {
$halfday = - 1 ;
} elseif ( $endhalfday == 'morning' ) {
$halfday = 1 ;
}
2020-09-08 21:27:28 +02:00
2021-08-18 00:12:25 +02:00
$approverid = GETPOST ( 'valideur' , 'int' );
2020-09-17 12:30:14 +02:00
$description = trim ( GETPOST ( 'description' , 'restricthtml' ));
2020-09-08 21:27:28 +02:00
2020-10-10 16:35:30 +02:00
// Check that leave is for a user inside the hierarchy or advanced permission for all is set
2021-06-01 16:34:39 +02:00
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS )) {
if ( empty ( $user -> rights -> holiday -> write )) {
$error ++ ;
setEventMessages ( $langs -> trans ( " NotEnoughPermissions " ), null , 'errors' );
} elseif ( ! in_array ( $fuserid , $childids )) {
$error ++ ;
setEventMessages ( $langs -> trans ( " UserNotInHierachy " ), null , 'errors' );
$action = 'create' ;
}
2020-10-10 16:35:30 +02:00
} else {
2021-06-01 16:34:39 +02:00
if ( empty ( $user -> rights -> holiday -> write ) && empty ( $user -> rights -> holiday -> writeall_advance )) {
$error ++ ;
setEventMessages ( $langs -> trans ( " NotEnoughPermissions " ), null , 'errors' );
} elseif ( empty ( $user -> rights -> holiday -> writeall_advance ) && ! in_array ( $fuserid , $childids )) {
$error ++ ;
setEventMessages ( $langs -> trans ( " UserNotInHierachy " ), null , 'errors' );
$action = 'create' ;
2020-10-10 16:35:30 +02:00
}
}
2020-09-08 21:27:28 +02:00
// If no type
2021-02-26 17:59:31 +01:00
if ( $type <= 0 ) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Type " )), null , 'errors' );
$error ++ ;
2020-10-10 16:35:30 +02:00
$action = 'create' ;
2020-09-08 21:27:28 +02:00
}
// If no start date
2021-02-26 17:59:31 +01:00
if ( empty ( $date_debut )) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $langs -> trans ( " NoDateDebut " ), null , 'errors' );
$error ++ ;
2020-10-10 16:35:30 +02:00
$action = 'create' ;
2020-09-08 21:27:28 +02:00
}
// If no end date
2021-02-26 17:59:31 +01:00
if ( empty ( $date_fin )) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $langs -> trans ( " NoDateFin " ), null , 'errors' );
$error ++ ;
2020-10-10 16:35:30 +02:00
$action = 'create' ;
2020-09-08 21:27:28 +02:00
}
// If start date after end date
2021-02-26 17:59:31 +01:00
if ( $date_debut > $date_fin ) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $langs -> trans ( " ErrorEndDateCP " ), null , 'errors' );
$error ++ ;
2020-10-10 16:35:30 +02:00
$action = 'create' ;
2020-09-08 21:27:28 +02:00
}
// Check if there is already holiday for this period
$verifCP = $object -> verifDateHolidayCP ( $fuserid , $date_debut , $date_fin , $halfday );
2021-02-26 17:59:31 +01:00
if ( ! $verifCP ) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $langs -> trans ( " alreadyCPexist " ), null , 'errors' );
$error ++ ;
2020-10-10 16:35:30 +02:00
$action = 'create' ;
2020-09-08 21:27:28 +02:00
}
// If there is no Business Days within request
$nbopenedday = num_open_day ( $date_debut_gmt , $date_fin_gmt , 0 , 1 , $halfday );
2021-02-26 17:59:31 +01:00
if ( $nbopenedday < 0.5 ) {
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " ErrorDureeCP " ), null , 'errors' ); // No working day
2020-09-08 21:27:28 +02:00
$error ++ ;
2020-10-10 16:35:30 +02:00
$action = 'create' ;
2020-09-08 21:27:28 +02:00
}
// If no validator designated
2021-08-18 00:12:25 +02:00
if ( $approverid < 1 ) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $langs -> transnoentitiesnoconv ( 'InvalidValidatorCP' ), null , 'errors' );
$error ++ ;
}
$result = 0 ;
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-08 21:27:28 +02:00
$object -> fk_user = $fuserid ;
$object -> description = $description ;
2021-08-18 00:12:25 +02:00
$object -> fk_validator = $approverid ;
2020-09-08 21:27:28 +02:00
$object -> fk_type = $type ;
$object -> date_debut = $date_debut ;
$object -> date_fin = $date_fin ;
$object -> halfday = $halfday ;
$result = $object -> create ( $user );
2021-02-26 17:59:31 +01:00
if ( $result <= 0 ) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
// If no SQL error we redirect to the request card
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2019-09-24 16:26:15 +02:00
$db -> commit ();
2020-09-08 21:27:28 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
} else {
$db -> rollback ();
}
}
2019-09-24 16:26:15 +02:00
}
2012-09-05 03:26:57 +02:00
2021-08-22 19:22:47 +02:00
// If update and we are an approver, we can update with another approver
2021-02-26 17:59:31 +01:00
if ( $action == 'update' && GETPOSTISSET ( 'savevalidator' ) && ! empty ( $user -> rights -> holiday -> approve )) {
2020-09-08 21:27:28 +02:00
$object -> fetch ( $id );
2012-09-05 03:26:57 +02:00
2020-09-08 21:27:28 +02:00
$object -> oldcopy = dol_clone ( $object );
2015-12-03 13:06:20 +01:00
2020-09-08 21:27:28 +02:00
$object -> fk_validator = GETPOST ( 'valideur' , 'int' );
2019-09-24 16:26:15 +02:00
2021-02-26 17:59:31 +01:00
if ( $object -> fk_validator != $object -> oldcopy -> fk_validator ) {
2020-09-08 21:27:28 +02:00
$verif = $object -> update ( $user );
2021-02-26 17:59:31 +01:00
if ( $verif <= 0 ) {
2020-09-08 21:27:28 +02:00
setEventMessages ( $object -> error , $object -> errors , 'warnings' );
$action = 'editvalidator' ;
} else {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
}
2016-03-03 08:41:39 +01:00
2020-09-08 21:27:28 +02:00
$action = '' ;
2019-09-24 16:26:15 +02:00
}
2015-06-21 23:25:01 +02:00
2021-02-26 17:59:31 +01:00
if ( $action == 'update' && ! GETPOSTISSET ( 'savevalidator' )) {
2019-09-24 16:26:15 +02:00
$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 );
2019-11-13 19:35:39 +01:00
$starthalfday = GETPOST ( 'starthalfday' );
$endhalfday = GETPOST ( 'endhalfday' );
$halfday = 0 ;
2021-02-26 17:59:31 +01:00
if ( $starthalfday == 'afternoon' && $endhalfday == 'morning' ) {
$halfday = 2 ;
} elseif ( $starthalfday == 'afternoon' ) {
$halfday = - 1 ;
} elseif ( $endhalfday == 'morning' ) {
$halfday = 1 ;
}
2019-09-24 16:26:15 +02:00
2020-09-07 10:18:17 +02:00
// If no right to modify a request
2021-02-26 17:59:31 +01:00
if ( ! $user -> rights -> holiday -> write ) {
2020-09-18 04:53:43 +02:00
setEventMessages ( $langs -> trans ( " CantUpdate " ), null , 'errors' );
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?action=create' );
2020-09-07 10:18:17 +02:00
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2019-05-27 20:12:33 +02:00
2019-09-24 16:26:15 +02:00
// If under validation
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_DRAFT ) {
2020-09-07 10:18:17 +02:00
// If this is the requestor or has read/write rights
2021-02-26 17:59:31 +01:00
if ( $cancreate ) {
2021-08-18 00:12:25 +02:00
$approverid = GETPOST ( 'valideur' , 'int' );
2021-08-22 19:34:13 +02:00
// TODO Check this approver user id has the permission for approval
2021-08-22 19:22:47 +02:00
2020-09-17 12:30:14 +02:00
$description = trim ( GETPOST ( 'description' , 'restricthtml' ));
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// If no start date
if ( empty ( $_POST [ 'date_debut_' ])) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit&error=nodatedebut' );
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// If no end date
if ( empty ( $_POST [ 'date_fin_' ])) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit&error=nodatefin' );
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// If start date after end date
if ( $date_debut > $date_fin ) {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit&error=datefin' );
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// If no validator designated
2021-08-18 00:12:25 +02:00
if ( $approverid < 1 ) {
2020-09-07 10:18:17 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit&error=Valideur' );
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// If there is no Business Days within request
$nbopenedday = num_open_day ( $date_debut_gmt , $date_fin_gmt , 0 , 1 , $halfday );
2021-02-26 17:59:31 +01:00
if ( $nbopenedday < 0.5 ) {
2020-09-07 10:18:17 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit&error=DureeHoliday' );
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$object -> description = $description ;
$object -> date_debut = $date_debut ;
$object -> date_fin = $date_fin ;
2021-08-18 00:12:25 +02:00
$object -> fk_validator = $approverid ;
2019-09-24 16:26:15 +02:00
$object -> halfday = $halfday ;
// Update
$verif = $object -> update ( $user );
2021-02-26 17:59:31 +01:00
if ( $verif <= 0 ) {
2019-09-24 16:26:15 +02:00
setEventMessages ( $object -> error , $object -> errors , 'warnings' );
2019-11-13 19:35:39 +01:00
$action = 'edit' ;
2020-05-21 15:05:19 +02:00
} else {
2019-09-24 16:26:15 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
2020-09-07 10:18:17 +02:00
} else {
setEventMessages ( $langs -> trans ( " NotEnoughPermissions " ), null , 'errors' );
$action = '' ;
}
} else {
setEventMessages ( $langs -> trans ( " ErrorBadStatus " ), null , 'errors' );
$action = '' ;
}
2019-09-24 16:26:15 +02:00
}
2012-09-05 03:26:57 +02:00
2019-09-24 16:26:15 +02:00
// If delete of request
2021-02-26 17:59:31 +01:00
if ( $action == 'confirm_delete' && GETPOST ( 'confirm' ) == 'yes' && $user -> rights -> holiday -> delete ) {
2019-11-13 19:35:39 +01:00
$error = 0 ;
2012-09-05 03:26:57 +02:00
2019-09-24 16:26:15 +02:00
$db -> begin ();
2012-12-19 20:59:08 +01:00
2019-09-24 16:26:15 +02:00
$object -> fetch ( $id );
2018-03-20 20:03:44 +01:00
2020-09-07 10:18:17 +02:00
// If this is a rough draft, approved, canceled or refused
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_DRAFT || $object -> statut == Holiday :: STATUS_CANCELED || $object -> statut == Holiday :: STATUS_REFUSED ) {
2019-09-24 16:26:15 +02:00
// Si l'utilisateur à le droit de lire cette demande, il peut la supprimer
2021-02-26 17:59:31 +01:00
if ( $candelete ) {
2019-11-13 19:35:39 +01:00
$result = $object -> delete ( $user );
2020-05-21 15:05:19 +02:00
} else {
2019-09-24 16:26:15 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( 'ErrorCantDeleteCP' ), null , 'errors' );
2019-11-13 19:35:39 +01:00
$action = '' ;
2018-03-20 20:03:44 +01:00
}
2019-09-24 16:26:15 +02:00
}
2014-05-07 15:03:05 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2019-09-24 16:26:15 +02:00
$db -> commit ();
header ( 'Location: list.php?restore_lastsearch_values=1' );
exit ;
2020-05-21 15:05:19 +02:00
} else {
2019-09-24 16:26:15 +02:00
$db -> rollback ();
2015-06-21 23:25:01 +02:00
}
}
2019-09-24 16:26:15 +02:00
// Action validate (+ send email for approval)
2021-02-26 17:59:31 +01:00
if ( $action == 'confirm_send' ) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2012-09-05 03:26:57 +02:00
2020-12-07 16:40:20 +01:00
// If draft and owner of leave
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_DRAFT && $cancreate ) {
2020-09-07 10:18:17 +02:00
$object -> oldcopy = dol_clone ( $object );
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$object -> statut = Holiday :: STATUS_VALIDATED ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$verif = $object -> validate ( $user );
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// If no SQL error, we redirect to the request form
2021-02-26 17:59:31 +01:00
if ( $verif > 0 ) {
2020-09-07 10:18:17 +02:00
// To
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_validator );
$emailTo = $destinataire -> email ;
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $emailTo ) {
2020-09-07 10:18:17 +02:00
dol_syslog ( " Expected validator has no email, so we redirect directly to finished page without sending email " );
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// From
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_user );
2020-12-07 16:40:20 +01:00
//$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
$emailFrom = $conf -> global -> MAIN_MAIL_EMAIL_FROM ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// Subject
2019-09-24 16:26:15 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
$societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$subject = $societeName . " - " . $langs -> transnoentitiesnoconv ( " HolidaysToValidate " );
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// Content
$message = $langs -> transnoentitiesnoconv ( " Hello " ) . " " . $destinataire -> firstname . " , \n " ;
$message .= " \n " ;
2020-12-07 16:40:20 +01:00
2020-09-07 10:18:17 +02:00
$message .= $langs -> transnoentities ( " HolidaysToValidateBody " ) . " \n " ;
2017-11-15 11:29:22 +01:00
2020-09-07 10:18:17 +02:00
$delayForRequest = $object -> getConfCP ( 'delayForRequest' );
//$delayForRequest = $delayForRequest * (60*60*24);
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$nextMonth = dol_time_plus_duree ( $now , $delayForRequest , 'd' );
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// option to warn the validator in case of too short delay
2021-02-26 17:59:31 +01:00
if ( $object -> getConfCP ( 'AlertValidatorDelay' )) {
if ( $object -> date_debut < $nextMonth ) {
2020-09-07 10:18:17 +02:00
$message .= " \n " ;
$message .= $langs -> transnoentities ( " HolidaysToValidateDelay " , $object -> getConfCP ( 'delayForRequest' )) . " \n " ;
}
}
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// option to notify the validator if the balance is less than the request
2021-02-26 17:59:31 +01:00
if ( $object -> getConfCP ( 'AlertValidatorSolde' )) {
2020-09-07 10:18:17 +02:00
$nbopenedday = num_open_day ( $object -> date_debut_gmt , $object -> date_fin_gmt , 0 , 1 , $object -> halfday );
2021-02-26 17:59:31 +01:00
if ( $nbopenedday > $object -> getCPforUser ( $object -> fk_user , $object -> fk_type )) {
2020-09-07 10:18:17 +02:00
$message .= " \n " ;
$message .= $langs -> transnoentities ( " HolidaysToValidateAlertSolde " ) . " \n " ;
}
}
2012-09-24 21:37:19 +02:00
2020-09-07 10:18:17 +02:00
$message .= " \n " ;
$message .= " - " . $langs -> transnoentitiesnoconv ( " Name " ) . " : " . dolGetFirstLastname ( $expediteur -> firstname , $expediteur -> lastname ) . " \n " ;
$message .= " - " . $langs -> transnoentitiesnoconv ( " Period " ) . " : " . dol_print_date ( $object -> date_debut , 'day' ) . " " . $langs -> transnoentitiesnoconv ( " To " ) . " " . dol_print_date ( $object -> date_fin , 'day' ) . " \n " ;
$message .= " - " . $langs -> transnoentitiesnoconv ( " Link " ) . " : " . $dolibarr_main_url_root . " /holiday/card.php?id= " . $object -> id . " \n \n " ;
$message .= " \n " ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$trackid = 'leav' . $object -> id ;
2018-10-25 12:45:13 +02:00
2020-09-07 10:18:17 +02:00
$mail = new CMailFile ( $subject , $emailTo , $emailFrom , $message , array (), array (), array (), '' , '' , 0 , 0 , '' , '' , $trackid );
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// Sending the email
2020-09-07 10:18:17 +02:00
$result = $mail -> sendfile ();
2019-02-08 14:47:03 +01:00
2021-02-26 17:59:31 +01:00
if ( ! $result ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $mail -> error , $mail -> errors , 'warnings' );
$action = '' ;
} else {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
} else {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$action = '' ;
}
}
2019-09-24 16:26:15 +02:00
}
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( $action == 'update_extras' ) {
2019-09-24 16:26:15 +02:00
$object -> oldcopy = dol_clone ( $object );
2019-02-08 14:47:03 +01:00
2019-09-24 16:26:15 +02:00
// Fill array 'array_options' with data from update form
2020-09-18 01:29:17 +02:00
$ret = $extrafields -> setOptionalsFromPost ( null , $object , GETPOST ( 'attribute' , 'restricthtml' ));
2021-02-26 17:59:31 +01:00
if ( $ret < 0 ) {
$error ++ ;
}
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2019-09-24 16:26:15 +02:00
// Actions on extra fields
$result = $object -> insertExtraFields ( 'HOLIDAY_MODIFY' );
2021-02-26 17:59:31 +01:00
if ( $result < 0 ) {
2019-09-24 16:26:15 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
}
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( $error ) {
2019-09-24 16:26:15 +02:00
$action = 'edit_extras' ;
2021-02-26 17:59:31 +01:00
}
2019-09-24 16:26:15 +02:00
}
2013-04-28 01:58:57 +02:00
2019-09-24 16:26:15 +02:00
// Approve leave request
2021-02-26 17:59:31 +01:00
if ( $action == 'confirm_valid' ) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2012-09-05 03:26:57 +02:00
2020-12-07 16:40:20 +01:00
// If status is waiting approval and approver is also user
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_VALIDATED && $user -> id == $object -> fk_validator ) {
2020-09-07 10:18:17 +02:00
$object -> oldcopy = dol_clone ( $object );
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$object -> date_valid = dol_now ();
$object -> fk_user_valid = $user -> id ;
$object -> statut = Holiday :: STATUS_APPROVED ;
2013-04-29 19:04:15 +02:00
2020-09-07 10:18:17 +02:00
$db -> begin ();
2013-04-29 19:04:15 +02:00
2020-09-07 10:18:17 +02:00
$verif = $object -> approve ( $user );
2021-02-26 17:59:31 +01:00
if ( $verif <= 0 ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
$error ++ ;
}
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// If no SQL error, we redirect to the request form
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
// Calculcate number of days consummed
$nbopenedday = num_open_day ( $object -> date_debut_gmt , $object -> date_fin_gmt , 0 , 1 , $object -> halfday );
$soldeActuel = $object -> getCpforUser ( $object -> fk_user , $object -> fk_type );
$newSolde = ( $soldeActuel - $nbopenedday );
2021-09-09 19:46:40 +02:00
$label = $langs -> transnoentitiesnoconv ( " Holidays " ) . ' - ' . $object -> ref ;
2020-09-07 10:18:17 +02:00
2021-03-17 18:17:03 +01:00
// The modification is added to the LOG
2021-09-09 19:46:40 +02:00
$result = $object -> addLogCP ( $user -> id , $object -> fk_user , $label , $newSolde , $object -> fk_type );
2021-02-26 17:59:31 +01:00
if ( $result < 0 ) {
2020-09-07 10:18:17 +02:00
$error ++ ;
setEventMessages ( null , $object -> errors , 'errors' );
}
2017-11-15 11:29:22 +01:00
2021-03-17 18:17:03 +01:00
// Update balance
2020-09-07 10:18:17 +02:00
$result = $object -> updateSoldeCP ( $object -> fk_user , $newSolde , $object -> fk_type );
2021-02-26 17:59:31 +01:00
if ( $result < 0 ) {
2020-09-07 10:18:17 +02:00
$error ++ ;
setEventMessages ( null , $object -> errors , 'errors' );
}
}
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
// To
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user );
$emailTo = $destinataire -> email ;
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $emailTo ) {
2020-09-07 10:18:17 +02:00
dol_syslog ( " User that request leave has no email, so we redirect directly to finished page without sending email " );
} else {
// From
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_validator );
2020-12-07 16:40:20 +01:00
//$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
$emailFrom = $conf -> global -> MAIN_MAIL_EMAIL_FROM ;
2019-02-08 14:47:03 +01:00
2020-09-07 10:18:17 +02:00
// Subject
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
$societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
}
2019-02-08 14:47:03 +01:00
2020-09-07 10:18:17 +02:00
$subject = $societeName . " - " . $langs -> transnoentitiesnoconv ( " HolidaysValidated " );
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// Content
$message = $langs -> transnoentitiesnoconv ( " Hello " ) . " " . $destinataire -> firstname . " , \n " ;
$message .= " \n " ;
2020-12-07 16:40:20 +01:00
2020-09-07 10:18:17 +02:00
$message .= $langs -> transnoentities ( " HolidaysValidatedBody " , dol_print_date ( $object -> date_debut , 'day' ), dol_print_date ( $object -> date_fin , 'day' )) . " \n " ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$message .= " - " . $langs -> transnoentitiesnoconv ( " ValidatedBy " ) . " : " . dolGetFirstLastname ( $expediteur -> firstname , $expediteur -> lastname ) . " \n " ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$message .= " - " . $langs -> transnoentitiesnoconv ( " Link " ) . " : " . $dolibarr_main_url_root . " /holiday/card.php?id= " . $object -> id . " \n \n " ;
$message .= " \n " ;
2019-02-08 14:47:03 +01:00
2020-09-07 10:18:17 +02:00
$trackid = 'leav' . $object -> id ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$mail = new CMailFile ( $subject , $emailTo , $emailFrom , $message , array (), array (), array (), '' , '' , 0 , 0 , '' , '' , $trackid );
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// Sending email
2020-09-07 10:18:17 +02:00
$result = $mail -> sendfile ();
2013-04-28 01:58:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $result ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $mail -> error , $mail -> errors , 'warnings' ); // Show error, but do no make rollback, so $error is not set to 1
$action = '' ;
}
}
}
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$db -> commit ();
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
2020-09-07 10:18:17 +02:00
} else {
$db -> rollback ();
$action = '' ;
}
}
2019-09-24 16:26:15 +02:00
}
2013-04-29 19:04:15 +02:00
2021-02-26 17:59:31 +01:00
if ( $action == 'confirm_refuse' && GETPOST ( 'confirm' , 'alpha' ) == 'yes' ) {
if ( ! empty ( $_POST [ 'detail_refuse' ])) {
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2013-04-29 19:04:15 +02:00
2021-03-17 18:17:03 +01:00
// If status pending validation and validator = user
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_VALIDATED && $user -> id == $object -> fk_validator ) {
2020-09-07 10:18:17 +02:00
$object -> date_refuse = dol_print_date ( 'dayhour' , dol_now ());
$object -> fk_user_refuse = $user -> id ;
$object -> statut = Holiday :: STATUS_REFUSED ;
$object -> detail_refuse = GETPOST ( 'detail_refuse' , 'alphanohtml' );
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$db -> begin ();
2017-11-15 11:29:22 +01:00
2020-09-07 10:18:17 +02:00
$verif = $object -> update ( $user );
2021-02-26 17:59:31 +01:00
if ( $verif <= 0 ) {
2020-09-07 10:18:17 +02:00
$error ++ ;
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// If no SQL error, we redirect to the request form
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
// To
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user );
$emailTo = $destinataire -> email ;
2021-02-26 17:59:31 +01:00
if ( ! $emailTo ) {
2020-09-07 10:18:17 +02:00
dol_syslog ( " User that request leave has no email, so we redirect directly to finished page without sending email " );
} else {
// From
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_validator );
2020-12-07 16:40:20 +01:00
//$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
$emailFrom = $conf -> global -> MAIN_MAIL_EMAIL_FROM ;
2020-09-07 10:18:17 +02:00
// Subject
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
$societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
}
2020-09-07 10:18:17 +02:00
$subject = $societeName . " - " . $langs -> transnoentitiesnoconv ( " HolidaysRefused " );
// Content
$message = $langs -> transnoentitiesnoconv ( " Hello " ) . " " . $destinataire -> firstname . " , \n " ;
$message .= " \n " ;
2020-12-07 16:40:20 +01:00
2020-09-07 10:18:17 +02:00
$message .= $langs -> transnoentities ( " HolidaysRefusedBody " , dol_print_date ( $object -> date_debut , 'day' ), dol_print_date ( $object -> date_fin , 'day' )) . " \n " ;
$message .= GETPOST ( 'detail_refuse' , 'alpha' ) . " \n \n " ;
$message .= " - " . $langs -> transnoentitiesnoconv ( " ModifiedBy " ) . " : " . dolGetFirstLastname ( $expediteur -> firstname , $expediteur -> lastname ) . " \n " ;
$message .= " - " . $langs -> transnoentitiesnoconv ( " Link " ) . " : " . $dolibarr_main_url_root . " /holiday/card.php?id= " . $object -> id . " \n \n " ;
$message .= " \n " ;
$trackid = 'leav' . $object -> id ;
$mail = new CMailFile ( $subject , $emailTo , $emailFrom , $message , array (), array (), array (), '' , '' , 0 , 0 , '' , '' , $trackid );
2021-03-17 18:17:03 +01:00
// sending email
2020-09-07 10:18:17 +02:00
$result = $mail -> sendfile ();
2021-02-26 17:59:31 +01:00
if ( ! $result ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $mail -> error , $mail -> errors , 'warnings' ); // Show error, but do no make rollback, so $error is not set to 1
$action = '' ;
}
}
} else {
$action = '' ;
}
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$db -> commit ();
2019-02-08 14:47:03 +01:00
2020-09-07 10:18:17 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
} else {
$db -> rollback ();
$action = '' ;
}
}
} else {
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " DetailRefusCP " )), null , 'errors' );
$action = 'refuse' ;
}
2019-09-24 16:26:15 +02:00
}
2019-02-08 14:47:03 +01:00
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// If the request is validated
2021-02-26 17:59:31 +01:00
if ( $action == 'confirm_draft' && GETPOST ( 'confirm' ) == 'yes' ) {
2019-09-24 16:26:15 +02:00
$error = 0 ;
2017-05-30 20:58:32 +02:00
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2018-03-20 20:03:44 +01:00
2020-09-07 10:18:17 +02:00
$oldstatus = $object -> statut ;
$object -> statut = Holiday :: STATUS_DRAFT ;
2017-06-13 15:34:18 +02:00
2020-09-07 10:18:17 +02:00
$result = $object -> update ( $user );
2021-02-26 17:59:31 +01:00
if ( $result < 0 ) {
2020-09-07 10:18:17 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( 'ErrorBackToDraft' ) . ' ' . $object -> error , $object -> errors , 'errors' );
}
2017-06-13 15:34:18 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$db -> commit ();
2017-06-13 15:34:18 +02:00
2020-09-07 10:18:17 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
} else {
$db -> rollback ();
}
2019-09-24 16:26:15 +02:00
}
2017-06-13 15:34:18 +02:00
2021-03-17 18:17:03 +01:00
// If confirmation of cancellation
2021-02-26 17:59:31 +01:00
if ( $action == 'confirm_cancel' && GETPOST ( 'confirm' ) == 'yes' ) {
2019-09-24 16:26:15 +02:00
$error = 0 ;
2017-05-30 20:58:32 +02:00
2020-09-07 10:18:17 +02:00
$object -> fetch ( $id );
2018-03-20 20:03:44 +01:00
2021-03-17 18:17:03 +01:00
// If status pending validation and validator = validator or user, or rights to do for others
2021-08-22 19:22:47 +02:00
if (( $object -> statut == Holiday :: STATUS_VALIDATED || $object -> statut == Holiday :: STATUS_APPROVED ) &&
2021-08-22 19:34:13 +02:00
( ! empty ( $user -> admin ) || $user -> id == $object -> fk_validator || in_array ( $object -> fk_user , $childids ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> holiday -> writeall_advance )))) {
2020-09-07 10:18:17 +02:00
$db -> begin ();
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$oldstatus = $object -> statut ;
$object -> date_cancel = dol_now ();
$object -> fk_user_cancel = $user -> id ;
$object -> statut = Holiday :: STATUS_CANCELED ;
2014-03-05 20:52:27 +01:00
2020-09-07 10:18:17 +02:00
$result = $object -> update ( $user );
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( $result >= 0 && $oldstatus == Holiday :: STATUS_APPROVED ) { // holiday was already validated, status 3, so we must increase back the balance
2021-02-26 18:14:26 +01:00
// Calculcate number of days consummed
2020-09-07 10:18:17 +02:00
$nbopenedday = num_open_day ( $object -> date_debut_gmt , $object -> date_fin_gmt , 0 , 1 , $object -> halfday );
2013-09-24 18:06:07 +02:00
2020-09-07 10:18:17 +02:00
$soldeActuel = $object -> getCpforUser ( $object -> fk_user , $object -> fk_type );
$newSolde = ( $soldeActuel + $nbopenedday );
2012-09-05 03:26:57 +02:00
2021-03-17 18:17:03 +01:00
// The modification is added to the LOG
2020-09-07 10:18:17 +02:00
$result1 = $object -> addLogCP ( $user -> id , $object -> fk_user , $langs -> transnoentitiesnoconv ( " HolidaysCancelation " ), $newSolde , $object -> fk_type );
2013-09-24 18:06:07 +02:00
2021-03-17 18:17:03 +01:00
// Update of the balance
2020-09-07 10:18:17 +02:00
$result2 = $object -> updateSoldeCP ( $object -> fk_user , $newSolde , $object -> fk_type );
2013-09-24 18:06:07 +02:00
2021-02-26 17:59:31 +01:00
if ( $result1 < 0 || $result2 < 0 ) {
2020-09-07 10:18:17 +02:00
$error ++ ;
setEventMessages ( $langs -> trans ( 'ErrorCantDeleteCP' ) . ' ' . $object -> error , $object -> errors , 'errors' );
}
}
2013-09-24 18:06:07 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2020-09-07 10:18:17 +02:00
$db -> commit ();
} else {
$db -> rollback ();
}
2014-03-05 20:52:27 +01:00
2021-03-17 18:17:03 +01:00
// If no SQL error, we redirect to the request form
2021-02-26 17:59:31 +01:00
if ( ! $error && $result > 0 ) {
2020-09-07 10:18:17 +02:00
// To
$destinataire = new User ( $db );
$destinataire -> fetch ( $object -> fk_user );
$emailTo = $destinataire -> email ;
2014-03-05 20:52:27 +01:00
2021-02-26 17:59:31 +01:00
if ( ! $emailTo ) {
2020-09-07 10:18:17 +02:00
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// From
$expediteur = new User ( $db );
$expediteur -> fetch ( $object -> fk_user_cancel );
2020-12-07 16:40:20 +01:00
//$emailFrom = $expediteur->email; Email of user can be an email into another company. Sending will fails, we must use the generic email.
$emailFrom = $conf -> global -> MAIN_MAIL_EMAIL_FROM ;
2013-04-28 01:58:57 +02:00
2020-09-07 10:18:17 +02:00
// Subject
2019-09-24 16:26:15 +02:00
$societeName = $conf -> global -> MAIN_INFO_SOCIETE_NOM ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) {
$societeName = $conf -> global -> MAIN_APPLICATION_TITLE ;
}
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$subject = $societeName . " - " . $langs -> transnoentitiesnoconv ( " HolidaysCanceled " );
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
// Content
2021-02-26 17:59:31 +01:00
$message = $langs -> transnoentitiesnoconv ( " Hello " ) . " " . $destinataire -> firstname . " , \n " ;
2020-09-07 10:18:17 +02:00
$message .= " \n " ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$message .= $langs -> transnoentities ( " HolidaysCanceledBody " , dol_print_date ( $object -> date_debut , 'day' ), dol_print_date ( $object -> date_fin , 'day' )) . " \n " ;
$message .= " - " . $langs -> transnoentitiesnoconv ( " ModifiedBy " ) . " : " . dolGetFirstLastname ( $expediteur -> firstname , $expediteur -> lastname ) . " \n " ;
2013-04-29 19:04:15 +02:00
2020-09-07 10:18:17 +02:00
$message .= " - " . $langs -> transnoentitiesnoconv ( " Link " ) . " : " . $dolibarr_main_url_root . " /holiday/card.php?id= " . $object -> id . " \n \n " ;
$message .= " \n " ;
2013-04-29 19:04:15 +02:00
2020-09-07 10:18:17 +02:00
$trackid = 'leav' . $object -> id ;
2012-09-05 03:26:57 +02:00
2020-09-07 10:18:17 +02:00
$mail = new CMailFile ( $subject , $emailTo , $emailFrom , $message , array (), array (), array (), '' , '' , 0 , 0 , '' , '' , $trackid );
2017-11-15 11:29:22 +01:00
2021-03-17 18:17:03 +01:00
// sending email
2020-09-07 10:18:17 +02:00
$result = $mail -> sendfile ();
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $result ) {
2020-09-07 10:18:17 +02:00
setEventMessages ( $mail -> error , $mail -> errors , 'warnings' );
$action = '' ;
} else {
header ( 'Location: ' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id );
exit ;
}
}
}
2019-09-24 16:26:15 +02:00
}
2012-09-05 03:26:57 +02:00
2019-09-24 16:26:15 +02:00
/*
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT . '/core/actions_printing.inc.php' ;
// Actions to send emails
2019-12-02 09:38:16 +01:00
$triggersendname = 'HOLIDAY_SENTBYMAIL' ;
2019-09-24 16:26:15 +02:00
$autocopy = 'MAIN_MAIL_AUTOCOPY_HOLIDAY_TO' ;
$trackid = 'leav' . $object -> id ;
include DOL_DOCUMENT_ROOT . '/core/actions_sendmails.inc.php' ;
// Actions to build doc
$upload_dir = $conf -> holiday -> dir_output ;
2019-11-05 19:41:30 +01:00
$permissiontoadd = $user -> rights -> holiday -> creer ;
2019-09-24 16:26:15 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_builddoc.inc.php' ;
*/
2012-09-05 03:26:57 +02:00
}
2012-11-20 13:14:16 +01:00
/*
2012-09-05 03:26:57 +02:00
* View
2012-11-20 13:14:16 +01:00
*/
2012-09-05 03:26:57 +02:00
2012-11-20 12:11:19 +01:00
$form = new Form ( $db );
2016-12-13 23:59:26 +01:00
$object = new Holiday ( $db );
2012-12-18 13:12:11 +01:00
2019-11-13 19:35:39 +01:00
$listhalfday = array ( 'morning' => $langs -> trans ( " Morning " ), " afternoon " => $langs -> trans ( " Afternoon " ));
2012-12-18 13:12:11 +01:00
2021-06-17 09:07:17 +02:00
$title = $langs -> trans ( 'CPTitreMenu' );
2021-03-17 18:17:03 +01:00
$help_url = 'EN:Module_Holiday' ;
2021-06-17 09:07:17 +02:00
llxHeader ( '' , $title , $help_url );
2012-09-05 03:26:57 +02:00
2021-02-26 17:59:31 +01:00
if (( empty ( $id ) && empty ( $ref )) || $action == 'create' || $action == 'add' ) {
2020-10-10 16:35:30 +02:00
// If user has no permission to create a leave
2021-02-26 17:59:31 +01:00
if (( in_array ( $fuserid , $childids ) && empty ( $user -> rights -> holiday -> write )) || ( ! in_array ( $fuserid , $childids ) && ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || empty ( $user -> rights -> holiday -> writeall_advance )))) {
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'CantCreateCP' );
} else {
2020-10-10 16:35:30 +02:00
// Form to add a leave request
2020-09-07 10:18:17 +02:00
print load_fiche_titre ( $langs -> trans ( 'MenuAddCP' ), '' , 'title_hrm.png' );
2020-10-10 16:35:30 +02:00
// Error management
2020-09-07 10:18:17 +02:00
if ( GETPOST ( 'error' )) {
switch ( GETPOST ( 'error' )) {
2021-02-26 17:59:31 +01:00
case 'datefin' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'ErrorEndDateCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'SQL_Create' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'ErrorSQLCreateCP' ) . ' <b>' . htmlentities ( $_GET [ 'msg' ]) . '</b>' ;
break ;
2021-02-26 17:59:31 +01:00
case 'CantCreate' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'CantCreateCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'Valideur' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'InvalidValidatorCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'nodatedebut' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'NoDateDebut' );
break ;
2021-02-26 17:59:31 +01:00
case 'nodatefin' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'NoDateFin' );
break ;
2021-02-26 17:59:31 +01:00
case 'DureeHoliday' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'ErrorDureeCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'alreadyCP' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> trans ( 'alreadyCPexist' );
break ;
}
setEventMessages ( $errors , null , 'errors' );
}
$delayForRequest = $object -> getConfCP ( 'delayForRequest' );
//$delayForRequest = $delayForRequest * (60*60*24);
$nextMonth = dol_time_plus_duree ( $now , $delayForRequest , 'd' );
2012-09-05 03:26:57 +02:00
2012-12-18 13:12:11 +01:00
print ' < script type = " text/javascript " >
function valider ()
{
2012-12-19 20:59:08 +01:00
if ( document . demandeCP . date_debut_ . value != " " )
2012-12-18 13:12:11 +01:00
{
2012-12-19 20:59:08 +01:00
if ( document . demandeCP . date_fin_ . value != " " )
2012-12-18 13:12:11 +01:00
{
if ( document . demandeCP . valideur . value != " -1 " ) {
return true ;
}
else {
alert ( " '.dol_escape_js( $langs->transnoentities ('InvalidValidatorCP')).' " );
return false ;
}
}
2012-12-19 20:59:08 +01:00
else
2012-12-18 13:12:11 +01:00
{
alert ( " '.dol_escape_js( $langs->transnoentities ('NoDateFin')).' " );
return false ;
}
}
2012-12-19 20:59:08 +01:00
else
2012-12-18 13:12:11 +01:00
{
alert ( " '.dol_escape_js( $langs->transnoentities ('NoDateDebut')).' " );
return false ;
}
}
2012-09-05 03:26:57 +02:00
</ script > ' . " \n " ;
2020-09-07 10:18:17 +02:00
// Formulaire de demande
print '<form method="POST" action="' . $_SERVER [ 'PHP_SELF' ] . '" onsubmit="return valider()" name="demandeCP">' . " \n " ;
print '<input type="hidden" name="token" value="' . newToken () . '" />' . " \n " ;
2020-09-18 04:53:43 +02:00
print '<input type="hidden" name="action" value="add" />' . " \n " ;
2015-06-21 03:19:15 +02:00
2020-12-07 14:46:33 +01:00
if ( empty ( $conf -> global -> HOLIDAY_HIDE_BALANCE )) {
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( '' , '' , '' , - 1 );
2018-03-19 15:00:50 +01:00
2020-09-07 10:18:17 +02:00
$out = '' ;
$typeleaves = $object -> getTypes ( 1 , 1 );
2021-02-26 17:59:31 +01:00
foreach ( $typeleaves as $key => $val ) {
2018-03-19 15:00:50 +01:00
$nb_type = $object -> getCPforUser ( $user -> id , $val [ 'rowid' ]);
$nb_holiday += $nb_type ;
2020-01-16 14:01:41 +01:00
2020-12-07 14:44:20 +01:00
$out .= ' - ' . ( $langs -> trans ( $val [ 'code' ]) != $val [ 'code' ] ? $langs -> trans ( $val [ 'code' ]) : $val [ 'label' ]) . ': <strong>' . ( $nb_type ? price2num ( $nb_type ) : 0 ) . '</strong><br>' ;
2020-01-16 14:01:41 +01:00
//$out .= ' - '.$val['label'].': <strong>'.($nb_type ?price2num($nb_type) : 0).'</strong><br>';
2018-03-19 15:00:50 +01:00
}
2020-09-07 10:18:17 +02:00
print $langs -> trans ( 'SoldeCPUser' , round ( $nb_holiday , 5 )) . '<br>' ;
2018-03-19 15:00:50 +01:00
print $out ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-12-07 14:46:33 +01:00
} elseif ( ! is_numeric ( $conf -> global -> HOLIDAY_HIDE_BALANCE )) {
2020-09-07 10:18:17 +02:00
print $langs -> trans ( $conf -> global -> HOLIDAY_HIDE_BALANCE ) . '<br>' ;
}
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ();
2020-09-07 10:18:17 +02:00
//print '<span>'.$langs->trans('DelayToRequestCP',$object->getConfCP('delayForRequest')).'</span><br><br>';
print '<table class="border centpercent">' ;
print '<tbody>' ;
// User for leave request
print '<tr>' ;
print '<td class="titlefield fieldrequired">' . $langs -> trans ( " User " ) . '</td>' ;
print '<td>' ;
2021-02-26 17:59:31 +01:00
if ( empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) || empty ( $user -> rights -> holiday -> writeall_advance )) {
2020-12-04 15:36:14 +01:00
print img_picto ( '' , 'user' ) . $form -> select_dolusers (( $fuserid ? $fuserid : $user -> id ), 'fuserid' , 0 , '' , 0 , 'hierarchyme' , '' , '0,' . $conf -> entity , 0 , 0 , $morefilter , 0 , '' , 'minwidth200 maxwidth500' );
2020-09-07 10:18:17 +02:00
//print '<input type="hidden" name="fuserid" value="'.($fuserid?$fuserid:$user->id).'">';
2020-10-10 15:45:04 +02:00
} else {
2020-12-04 15:36:14 +01:00
print img_picto ( '' , 'user' ) . $form -> select_dolusers ( GETPOST ( 'fuserid' , 'int' ) ? GETPOST ( 'fuserid' , 'int' ) : $user -> id , 'fuserid' , 0 , '' , 0 , '' , '' , '0,' . $conf -> entity , 0 , 0 , $morefilter , 0 , '' , 'minwidth200 maxwidth500' );
2020-10-10 15:45:04 +02:00
}
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '</tr>' ;
// Type
print '<tr>' ;
print '<td class="fieldrequired">' . $langs -> trans ( " Type " ) . '</td>' ;
print '<td>' ;
$typeleaves = $object -> getTypes ( 1 , - 1 );
$arraytypeleaves = array ();
2021-02-26 17:59:31 +01:00
foreach ( $typeleaves as $key => $val ) {
2020-09-07 10:18:17 +02:00
$labeltoshow = ( $langs -> trans ( $val [ 'code' ]) != $val [ 'code' ] ? $langs -> trans ( $val [ 'code' ]) : $val [ 'label' ]);
$labeltoshow .= ( $val [ 'delay' ] > 0 ? ' (' . $langs -> trans ( " NoticePeriod " ) . ': ' . $val [ 'delay' ] . ' ' . $langs -> trans ( " days " ) . ')' : '' );
2019-11-13 19:35:39 +01:00
$arraytypeleaves [ $val [ 'rowid' ]] = $labeltoshow ;
2020-09-07 10:18:17 +02:00
}
2020-12-04 15:28:12 +01:00
print $form -> selectarray ( 'type' , $arraytypeleaves , ( GETPOST ( 'type' , 'alpha' ) ? GETPOST ( 'type' , 'alpha' ) : '' ), 1 , 0 , 0 , '' , 0 , 0 , 0 , '' , '' , true );
2021-02-26 17:59:31 +01:00
if ( $user -> admin ) {
print info_admin ( $langs -> trans ( " YouCanChangeValuesForThisListFromDictionarySetup " ), 1 );
}
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '</tr>' ;
// Date start
print '<tr>' ;
print '<td class="fieldrequired">' ;
2020-09-18 04:53:43 +02:00
print $form -> textwithpicto ( $langs -> trans ( " DateDebCP " ), $langs -> trans ( " FirstDayOfHoliday " ));
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '<td>' ;
// Si la demande ne vient pas de l'agenda
if ( ! GETPOST ( 'date_debut_' )) {
print $form -> selectDate ( - 1 , 'date_debut_' , 0 , 0 , 0 , '' , 1 , 1 );
} else {
$tmpdate = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_debut_month' , 'int' ), GETPOST ( 'date_debut_day' , 'int' ), GETPOST ( 'date_debut_year' , 'int' ));
print $form -> selectDate ( $tmpdate , 'date_debut_' , 0 , 0 , 0 , '' , 1 , 1 );
}
print ' ' ;
print $form -> selectarray ( 'starthalfday' , $listhalfday , ( GETPOST ( 'starthalfday' , 'alpha' ) ? GETPOST ( 'starthalfday' , 'alpha' ) : 'morning' ));
print '</td>' ;
print '</tr>' ;
// Date end
print '<tr>' ;
print '<td class="fieldrequired">' ;
2020-09-18 04:53:43 +02:00
print $form -> textwithpicto ( $langs -> trans ( " DateFinCP " ), $langs -> trans ( " LastDayOfHoliday " ));
2020-09-07 10:18:17 +02:00
print '</td>' ;
print '<td>' ;
if ( ! GETPOST ( 'date_fin_' )) {
print $form -> selectDate ( - 1 , 'date_fin_' , 0 , 0 , 0 , '' , 1 , 1 );
} else {
$tmpdate = dol_mktime ( 0 , 0 , 0 , GETPOST ( 'date_fin_month' , 'int' ), GETPOST ( 'date_fin_day' , 'int' ), GETPOST ( 'date_fin_year' , 'int' ));
print $form -> selectDate ( $tmpdate , 'date_fin_' , 0 , 0 , 0 , '' , 1 , 1 );
}
print ' ' ;
print $form -> selectarray ( 'endhalfday' , $listhalfday , ( GETPOST ( 'endhalfday' , 'alpha' ) ? GETPOST ( 'endhalfday' , 'alpha' ) : 'afternoon' ));
print '</td>' ;
print '</tr>' ;
// Approver
print '<tr>' ;
print '<td class="fieldrequired">' . $langs -> trans ( " ReviewedByCP " ) . '</td>' ;
print '<td>' ;
$object = new Holiday ( $db );
$include_users = $object -> fetch_users_approver_holiday ();
2020-12-04 15:28:12 +01:00
if ( empty ( $include_users )) {
print img_warning () . ' ' . $langs -> trans ( " NobodyHasPermissionToValidateHolidays " );
} else {
2020-09-07 10:18:17 +02:00
$defaultselectuser = ( empty ( $user -> fk_user_holiday_validator ) ? $user -> fk_user : $user -> fk_user_holiday_validator ); // Will work only if supervisor has permission to approve so is inside include_users
2021-02-26 17:59:31 +01:00
if ( ! empty ( $conf -> global -> HOLIDAY_DEFAULT_VALIDATOR )) {
$defaultselectuser = $conf -> global -> HOLIDAY_DEFAULT_VALIDATOR ; // Can force default approver
}
if ( GETPOST ( 'valideur' , 'int' ) > 0 ) {
$defaultselectuser = GETPOST ( 'valideur' , 'int' );
}
2020-12-04 15:36:14 +01:00
$s = $form -> select_dolusers ( $defaultselectuser , " valideur " , 1 , '' , 0 , $include_users , '' , '0,' . $conf -> entity , 0 , 0 , '' , 0 , '' , 'minwidth200 maxwidth500' );
2020-12-04 15:28:12 +01:00
print img_picto ( '' , 'user' ) . $form -> textwithpicto ( $s , $langs -> trans ( " AnyOtherInThisListCanValidate " ));
2020-09-07 10:18:17 +02:00
}
//print $form->select_dolusers((GETPOST('valideur','int')>0?GETPOST('valideur','int'):$user->fk_user), "valideur", 1, ($user->admin ? '' : array($user->id)), 0, '', 0, 0, 0, 0, '', 0, '', '', 1); // By default, hierarchical parent
print '</td>' ;
print '</tr>' ;
// Description
print '<tr>' ;
print '<td>' . $langs -> trans ( " DescCP " ) . '</td>' ;
print '<td class="tdtop">' ;
2020-09-17 12:30:14 +02:00
$doleditor = new DolEditor ( 'description' , GETPOST ( 'description' , 'restricthtml' ), '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
2020-09-07 10:18:17 +02:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_add.tpl.php' ;
print '</tbody>' ;
print '</table>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-09-07 10:18:17 +02:00
print '<div class="center">' ;
print '<input type="submit" value="' . $langs -> trans ( " SendRequestCP " ) . '" name="bouton" class="button">' ;
print ' ' ;
2020-11-23 15:12:52 +01:00
print '<input type="button" value="' . $langs -> trans ( " Cancel " ) . '" class="button button-cancel" onclick="history.go(-1)">' ;
2020-09-07 10:18:17 +02:00
print '</div>' ;
print '</from>' . " \n " ;
}
2020-05-21 15:05:19 +02:00
} else {
2020-12-17 13:42:20 +01:00
if ( $error ) {
2020-09-07 10:18:17 +02:00
print '<div class="tabBar">' ;
print $error ;
print '<br><br><input type="button" value="' . $langs -> trans ( " ReturnCP " ) . '" class="button" onclick="history.go(-1)" />' ;
print '</div>' ;
} else {
// Affichage de la fiche d'une demande de congés payés
2021-02-26 17:59:31 +01:00
if (( $id > 0 ) || $ref ) {
2020-09-07 10:18:17 +02:00
$result = $object -> fetch ( $id , $ref );
2021-08-18 00:12:25 +02:00
$approverexpected = new User ( $db );
$approverexpected -> fetch ( $object -> fk_validator );
2020-09-07 10:18:17 +02:00
$userRequest = new User ( $db );
$userRequest -> fetch ( $object -> fk_user );
//print load_fiche_titre($langs->trans('TitreRequestCP'));
// Si il y a une erreur
2021-02-26 17:59:31 +01:00
if ( GETPOST ( 'error' )) {
switch ( GETPOST ( 'error' )) {
case 'datefin' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'ErrorEndDateCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'SQL_Create' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'ErrorSQLCreateCP' ) . ' ' . $_GET [ 'msg' ];
break ;
2021-02-26 17:59:31 +01:00
case 'CantCreate' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'CantCreateCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'Valideur' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'InvalidValidatorCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'nodatedebut' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'NoDateDebut' );
break ;
2021-02-26 17:59:31 +01:00
case 'nodatefin' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'NoDateFin' );
break ;
2021-02-26 17:59:31 +01:00
case 'DureeHoliday' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'ErrorDureeCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'NoMotifRefuse' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'NoMotifRefuseCP' );
break ;
2021-02-26 17:59:31 +01:00
case 'mail' :
2020-09-07 10:18:17 +02:00
$errors [] = $langs -> transnoentitiesnoconv ( 'ErrorMailNotSend' ) . " \n " . $_GET [ 'error_content' ];
break ;
}
setEventMessages ( $errors , null , 'errors' );
}
// On vérifie si l'utilisateur à le droit de lire cette demande
2021-06-01 16:34:39 +02:00
if ( $canread ) {
2020-09-07 10:18:17 +02:00
$head = holiday_prepare_head ( $object );
2021-02-26 17:59:31 +01:00
if (( $action == 'edit' && $object -> statut == Holiday :: STATUS_DRAFT ) || ( $action == 'editvalidator' )) {
if ( $action == 'edit' && $object -> statut == Holiday :: STATUS_DRAFT ) {
$edit = true ;
}
2020-09-07 10:18:17 +02:00
print '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' . " \n " ;
print '<input type="hidden" name="token" value="' . newToken () . '" />' . " \n " ;
print '<input type="hidden" name="action" value="update"/>' . " \n " ;
print '<input type="hidden" name="id" value="' . $object -> id . '" />' . " \n " ;
}
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $langs -> trans ( " CPTitreMenu " ), - 1 , 'holiday' );
2020-09-07 10:18:17 +02:00
$linkback = '<a href="' . DOL_URL_ROOT . '/holiday/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' );
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
print '<table class="border tableforfield centpercent">' ;
print '<tbody>' ;
// User
print '<tr>' ;
print '<td class="titlefield">' . $langs -> trans ( " User " ) . '</td>' ;
print '<td>' ;
print $userRequest -> getNomUrl ( - 1 , 'leave' );
print '</td></tr>' ;
// Type
print '<tr>' ;
print '<td>' . $langs -> trans ( " Type " ) . '</td>' ;
print '<td>' ;
$typeleaves = $object -> getTypes ( 1 , - 1 );
$labeltoshow = (( $typeleaves [ $object -> fk_type ][ 'code' ] && $langs -> trans ( $typeleaves [ $object -> fk_type ][ 'code' ]) != $typeleaves [ $object -> fk_type ][ 'code' ]) ? $langs -> trans ( $typeleaves [ $object -> fk_type ][ 'code' ]) : $typeleaves [ $object -> fk_type ][ 'label' ]);
print empty ( $labeltoshow ) ? $langs -> trans ( " TypeWasDisabledOrRemoved " , $object -> fk_type ) : $labeltoshow ;
print '</td>' ;
print '</tr>' ;
$starthalfday = ( $object -> halfday == - 1 || $object -> halfday == 2 ) ? 'afternoon' : 'morning' ;
$endhalfday = ( $object -> halfday == 1 || $object -> halfday == 2 ) ? 'morning' : 'afternoon' ;
2021-02-26 17:59:31 +01:00
if ( ! $edit ) {
2020-09-07 10:18:17 +02:00
print '<tr>' ;
2020-09-18 04:53:43 +02:00
print '<td class="nowrap">' ;
print $form -> textwithpicto ( $langs -> trans ( 'DateDebCP' ), $langs -> trans ( " FirstDayOfHoliday " ));
print '</td>' ;
2020-09-07 10:18:17 +02:00
print '<td>' . dol_print_date ( $object -> date_debut , 'day' );
print ' ' ;
print '<span class="opacitymedium">' . $langs -> trans ( $listhalfday [ $starthalfday ]) . '</span>' ;
print '</td>' ;
print '</tr>' ;
} else {
print '<tr>' ;
2020-09-18 04:53:43 +02:00
print '<td class="nowrap">' ;
print $form -> textwithpicto ( $langs -> trans ( 'DateDebCP' ), $langs -> trans ( " FirstDayOfHoliday " ));
print '</td>' ;
2020-09-07 10:18:17 +02:00
print '<td>' ;
print $form -> selectDate ( $object -> date_debut , 'date_debut_' );
print ' ' ;
print $form -> selectarray ( 'starthalfday' , $listhalfday , ( GETPOST ( 'starthalfday' ) ? GETPOST ( 'starthalfday' ) : $starthalfday ));
print '</td>' ;
print '</tr>' ;
}
2021-02-26 17:59:31 +01:00
if ( ! $edit ) {
2020-09-07 10:18:17 +02:00
print '<tr>' ;
2020-09-18 04:53:43 +02:00
print '<td class="nowrap">' ;
print $form -> textwithpicto ( $langs -> trans ( 'DateFinCP' ), $langs -> trans ( " LastDayOfHoliday " ));
print '</td>' ;
2020-09-07 10:18:17 +02:00
print '<td>' . dol_print_date ( $object -> date_fin , 'day' );
print ' ' ;
print '<span class="opacitymedium">' . $langs -> trans ( $listhalfday [ $endhalfday ]) . '</span>' ;
print '</td>' ;
print '</tr>' ;
} else {
print '<tr>' ;
2020-09-18 04:53:43 +02:00
print '<td class="nowrap">' ;
print $form -> textwithpicto ( $langs -> trans ( 'DateFinCP' ), $langs -> trans ( " LastDayOfHoliday " ));
print '</td>' ;
2020-09-07 10:18:17 +02:00
print '<td>' ;
print $form -> selectDate ( $object -> date_fin , 'date_fin_' );
print ' ' ;
print $form -> selectarray ( 'endhalfday' , $listhalfday , ( GETPOST ( 'endhalfday' ) ? GETPOST ( 'endhalfday' ) : $endhalfday ));
print '</td>' ;
print '</tr>' ;
}
// Nb of days
print '<tr>' ;
2020-09-18 04:53:43 +02:00
print '<td>' ;
2020-09-07 10:18:17 +02:00
$htmlhelp = $langs -> trans ( 'NbUseDaysCPHelp' );
$includesaturday = ( isset ( $conf -> global -> MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY ) ? $conf -> global -> MAIN_NON_WORKING_DAYS_INCLUDE_SATURDAY : 1 );
$includesunday = ( isset ( $conf -> global -> MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY ) ? $conf -> global -> MAIN_NON_WORKING_DAYS_INCLUDE_SUNDAY : 1 );
2021-02-26 17:59:31 +01:00
if ( $includesaturday ) {
$htmlhelp .= '<br>' . $langs -> trans ( " DayIsANonWorkingDay " , $langs -> trans ( " Saturday " ));
}
if ( $includesunday ) {
$htmlhelp .= '<br>' . $langs -> trans ( " DayIsANonWorkingDay " , $langs -> trans ( " Sunday " ));
}
2020-09-07 10:18:17 +02:00
print $form -> textwithpicto ( $langs -> trans ( 'NbUseDaysCP' ), $htmlhelp );
print '</td>' ;
print '<td>' ;
print num_open_day ( $object -> date_debut_gmt , $object -> date_fin_gmt , 0 , 1 , $object -> halfday );
print '</td>' ;
print '</tr>' ;
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_REFUSED ) {
2020-09-07 10:18:17 +02:00
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DetailRefusCP' ) . '</td>' ;
print '<td>' . $object -> detail_refuse . '</td>' ;
print '</tr>' ;
}
// Description
2021-02-26 17:59:31 +01:00
if ( ! $edit ) {
2020-09-07 10:18:17 +02:00
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DescCP' ) . '</td>' ;
print '<td>' . nl2br ( $object -> description ) . '</td>' ;
print '</tr>' ;
} else {
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DescCP' ) . '</td>' ;
print '<td class="tdtop">' ;
$doleditor = new DolEditor ( 'description' , $object -> description , '' , 80 , 'dolibarr_notes' , 'In' , 0 , false , true , ROWS_3 , '90%' );
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
}
// Other attributes
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php' ;
print '</tbody>' ;
print '</table>' . " \n " ;
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="ficheaddleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2017-06-13 15:34:18 +02:00
2014-05-07 15:03:05 +02:00
// Info workflow
2020-09-07 10:18:17 +02:00
print '<table class="border tableforfield centpercent">' . " \n " ;
print '<tbody>' ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $object -> fk_user_create )) {
2020-09-07 10:18:17 +02:00
$userCreate = new User ( $db );
$userCreate -> fetch ( $object -> fk_user_create );
print '<tr>' ;
print '<td class="titlefield">' . $langs -> trans ( 'RequestByCP' ) . '</td>' ;
print '<td>' . $userCreate -> getNomUrl ( - 1 ) . '</td>' ;
print '</tr>' ;
}
// Approver
if ( ! $edit && $action != 'editvalidator' ) {
print '<tr>' ;
print '<td class="titlefield">' ;
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_APPROVED || $object -> statut == Holiday :: STATUS_CANCELED ) {
print $langs -> trans ( 'ApprovedBy' );
} else {
print $langs -> trans ( 'ReviewedByCP' );
}
2020-09-07 10:18:17 +02:00
print '</td>' ;
2021-08-18 00:12:25 +02:00
print '<td>' ;
if ( $object -> statut == Holiday :: STATUS_APPROVED || $object -> statut == Holiday :: STATUS_CANCELED ) {
$approverdone = new User ( $db );
$approverdone -> fetch ( $object -> fk_user_valid );
print $approverdone -> getNomUrl ( - 1 );
} else {
print $approverexpected -> getNomUrl ( - 1 );
}
2020-09-07 10:18:17 +02:00
$include_users = $object -> fetch_users_approver_holiday ();
2021-02-26 17:59:31 +01:00
if ( is_array ( $include_users ) && in_array ( $user -> id , $include_users ) && $object -> statut == Holiday :: STATUS_VALIDATED ) {
2020-09-07 10:18:17 +02:00
print '<a class="editfielda paddingleft" href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=editvalidator">' . img_edit ( $langs -> trans ( " Edit " )) . '</a>' ;
}
print '</td>' ;
print '</tr>' ;
} else {
print '<tr>' ;
print '<td class="titlefield">' . $langs -> trans ( 'ReviewedByCP' ) . '</td>' ;
print '<td>' ;
$include_users = $object -> fetch_users_approver_holiday ();
2021-02-26 17:59:31 +01:00
if ( ! in_array ( $object -> fk_validator , $include_users )) { // Add the current validator to the list to not lose it when editing.
2020-09-07 10:18:17 +02:00
$include_users [] = $object -> fk_validator ;
}
2021-02-26 17:59:31 +01:00
if ( empty ( $include_users )) {
print img_warning () . ' ' . $langs -> trans ( " NobodyHasPermissionToValidateHolidays " );
} else {
2020-09-07 10:18:17 +02:00
$arrayofvalidatorstoexclude = (( $user -> admin || ( $user -> id != $userRequest -> id )) ? '' : array ( $user -> id )); // Nobody if we are admin or if we are not the user of the leave.
$s = $form -> select_dolusers ( $object -> fk_validator , " valideur " , (( $action == 'editvalidator' ) ? 0 : 1 ), $arrayofvalidatorstoexclude , 0 , $include_users );
print $form -> textwithpicto ( $s , $langs -> trans ( " AnyOtherInThisListCanValidate " ));
}
2021-02-26 17:59:31 +01:00
if ( $action == 'editvalidator' ) {
2020-11-19 20:23:38 +01:00
print '<input type="submit" class="button button-save" name="savevalidator" value="' . $langs -> trans ( " Save " ) . '">' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2020-09-07 10:18:17 +02:00
}
print '</td>' ;
print '</tr>' ;
}
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DateCreation' ) . '</td>' ;
2021-02-04 11:56:53 +01:00
print '<td>' . dol_print_date ( $object -> date_create , 'dayhour' , 'tzuser' ) . '</td>' ;
2020-09-07 10:18:17 +02:00
print '</tr>' ;
if ( $object -> statut == Holiday :: STATUS_APPROVED || $object -> statut == Holiday :: STATUS_CANCELED ) {
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DateValidCP' ) . '</td>' ;
2021-02-04 11:56:53 +01:00
print '<td>' . dol_print_date ( $object -> date_valid , 'dayhour' , 'tzuser' ) . '</td>' ; // warning: date_valid is approval date on holiday module
2020-09-07 10:18:17 +02:00
print '</tr>' ;
}
if ( $object -> statut == Holiday :: STATUS_CANCELED ) {
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DateCancelCP' ) . '</td>' ;
2021-02-04 11:56:53 +01:00
print '<td>' . dol_print_date ( $object -> date_cancel , 'dayhour' , 'tzuser' ) . '</td>' ;
2020-09-07 10:18:17 +02:00
print '</tr>' ;
}
if ( $object -> statut == Holiday :: STATUS_REFUSED ) {
print '<tr>' ;
print '<td>' . $langs -> trans ( 'DateRefusCP' ) . '</td>' ;
2021-02-04 11:56:53 +01:00
print '<td>' . dol_print_date ( $object -> date_refuse , 'dayhour' , 'tzuser' ) . '</td>' ;
2020-09-07 10:18:17 +02:00
print '</tr>' ;
}
print '</tbody>' ;
print '</table>' ;
print '</div>' ;
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2020-09-07 10:18:17 +02:00
// Confirmation messages
2021-02-26 17:59:31 +01:00
if ( $action == 'delete' ) {
if ( $user -> rights -> holiday -> delete ) {
2020-09-07 10:18:17 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " TitleDeleteCP " ), $langs -> trans ( " ConfirmDeleteCP " ), " confirm_delete " , '' , 0 , 1 );
}
}
// Si envoi en validation
2021-02-26 17:59:31 +01:00
if ( $action == 'sendToValidate' && $object -> statut == Holiday :: STATUS_DRAFT ) {
2020-09-07 10:18:17 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " TitleToValidCP " ), $langs -> trans ( " ConfirmToValidCP " ), " confirm_send " , '' , 1 , 1 );
}
// Si validation de la demande
2021-02-26 17:59:31 +01:00
if ( $action == 'valid' ) {
2020-09-07 10:18:17 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " TitleValidCP " ), $langs -> trans ( " ConfirmValidCP " ), " confirm_valid " , '' , 1 , 1 );
}
// Si refus de la demande
2021-02-26 17:59:31 +01:00
if ( $action == 'refuse' ) {
2020-09-07 10:18:17 +02:00
$array_input = array ( array ( 'type' => " text " , 'label' => $langs -> trans ( 'DetailRefusCP' ), 'name' => " detail_refuse " , 'size' => " 50 " , 'value' => " " ));
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id . " &action=confirm_refuse " , $langs -> trans ( " TitleRefuseCP " ), $langs -> trans ( 'ConfirmRefuseCP' ), " confirm_refuse " , $array_input , 1 , 0 );
}
// Si annulation de la demande
2021-02-26 17:59:31 +01:00
if ( $action == 'cancel' ) {
2020-09-07 10:18:17 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " TitleCancelCP " ), $langs -> trans ( " ConfirmCancelCP " ), " confirm_cancel " , '' , 1 , 1 );
}
// Si back to draft
2021-02-26 17:59:31 +01:00
if ( $action == 'backtodraft' ) {
2020-09-07 10:18:17 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( " TitleSetToDraft " ), $langs -> trans ( " ConfirmSetToDraft " ), " confirm_draft " , '' , 1 , 1 );
}
2021-02-26 17:59:31 +01:00
if (( $action == 'edit' && $object -> statut == Holiday :: STATUS_DRAFT ) || ( $action == 'editvalidator' )) {
if ( $action == 'edit' && $object -> statut == Holiday :: STATUS_DRAFT ) {
2020-09-07 10:18:17 +02:00
print '<div class="center">' ;
2021-02-26 17:59:31 +01:00
if ( $cancreate && $object -> statut == Holiday :: STATUS_DRAFT ) {
2020-11-19 20:23:38 +01:00
print '<input type="submit" value="' . $langs -> trans ( " Save " ) . '" class="button button-save">' ;
2020-09-07 10:18:17 +02:00
}
print '</div>' ;
}
print '</form>' ;
}
2021-02-26 17:59:31 +01:00
if ( ! $edit ) {
2020-09-07 10:18:17 +02:00
// Buttons for actions
print '<div class="tabsAction">' ;
2021-02-26 17:59:31 +01:00
if ( $cancreate && $object -> statut == Holiday :: STATUS_DRAFT ) {
2020-09-07 10:18:17 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=edit" class="butAction">' . $langs -> trans ( " EditCP " ) . '</a>' ;
}
2021-08-22 19:22:47 +02:00
2021-02-26 17:59:31 +01:00
if ( $cancreate && $object -> statut == Holiday :: STATUS_DRAFT ) { // If draft
2020-09-07 10:18:17 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=sendToValidate" class="butAction">' . $langs -> trans ( " Validate " ) . '</a>' ;
}
2021-08-22 19:22:47 +02:00
2021-02-26 17:59:31 +01:00
if ( $object -> statut == Holiday :: STATUS_VALIDATED ) { // If validated
2021-08-22 19:22:47 +02:00
// Button Approve / Refuse
2021-02-26 17:59:31 +01:00
if ( $user -> id == $object -> fk_validator ) {
2020-09-07 10:18:17 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=valid" class="butAction">' . $langs -> trans ( " Approve " ) . '</a>' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=refuse" class="butAction">' . $langs -> trans ( " ActionRefuseCP " ) . '</a>' ;
} else {
print '<a href="#" class="butActionRefused classfortooltip" title="' . $langs -> trans ( " NotTheAssignedApprover " ) . '">' . $langs -> trans ( " Approve " ) . '</a>' ;
print '<a href="#" class="butActionRefused classfortooltip" title="' . $langs -> trans ( " NotTheAssignedApprover " ) . '">' . $langs -> trans ( " ActionRefuseCP " ) . '</a>' ;
2021-08-22 19:22:47 +02:00
2021-08-22 19:34:13 +02:00
// Button Cancel (because we can't approve)
2021-08-22 19:22:47 +02:00
if ( in_array ( $object -> fk_user , $childids ) || ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> holiday -> writeall_advance ))) {
if (( $object -> date_debut > dol_now ()) || ! empty ( $user -> admin )) {
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=cancel&token=' . newToken () . '" class="butAction">' . $langs -> trans ( " ActionCancelCP " ) . '</a>' ;
} else {
print '<a href="#" class="butActionRefused classfortooltip" title="' . $langs -> trans ( " HolidayStarted " ) . '-' . $langs -> trans ( " NotAllowed " ) . '">' . $langs -> trans ( " ActionCancelCP " ) . '</a>' ;
}
}
2020-09-07 10:18:17 +02:00
}
}
2021-08-22 19:22:47 +02:00
if ( $object -> statut == Holiday :: STATUS_APPROVED ) { // If validated or approved
if ( $user -> id == $object -> fk_validator
|| in_array ( $object -> fk_user , $childids )
|| ( ! empty ( $conf -> global -> MAIN_USE_ADVANCED_PERMS ) && ! empty ( $user -> rights -> holiday -> writeall_advance ))) {
if (( $object -> date_debut > dol_now ()) || ! empty ( $user -> admin )) {
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=cancel&token=' . newToken () . '" class="butAction">' . $langs -> trans ( " ActionCancelCP " ) . '</a>' ;
} else {
print '<a href="#" class="butActionRefused classfortooltip" title="' . $langs -> trans ( " HolidayStarted " ) . '-' . $langs -> trans ( " NotAllowed " ) . '">' . $langs -> trans ( " ActionCancelCP " ) . '</a>' ;
}
} else { // I have no rights on the user of the holiday.
if ( ! empty ( $user -> admin )) { // If current validator can't cancel an approved leave, we allow admin user
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=cancel&token=' . newToken () . '" class="butAction">' . $langs -> trans ( " ActionCancelCP " ) . '</a>' ;
} else {
print '<a href="#" class="butActionRefused classfortooltip" title="' . $langs -> trans ( " NotAllowed " ) . '">' . $langs -> trans ( " ActionCancelCP " ) . '</a>' ;
}
2021-02-26 17:59:31 +01:00
}
2020-09-07 10:18:17 +02:00
}
2021-08-22 19:22:47 +02:00
2021-02-26 17:59:31 +01:00
if ( $cancreate && $object -> statut == Holiday :: STATUS_CANCELED ) {
2020-09-07 10:18:17 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=backtodraft" class="butAction">' . $langs -> trans ( " SetToDraft " ) . '</a>' ;
}
2021-02-26 17:59:31 +01:00
if ( $candelete && ( $object -> statut == Holiday :: STATUS_DRAFT || $object -> statut == Holiday :: STATUS_CANCELED || $object -> statut == Holiday :: STATUS_REFUSED )) { // If draft or canceled or refused
2020-10-01 10:50:54 +02:00
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $object -> id . '&action=delete&token=' . newToken () . '" class="butActionDelete">' . $langs -> trans ( " DeleteCP " ) . '</a>' ;
2020-09-07 10:18:17 +02:00
}
print '</div>' ;
}
} else {
print '<div class="tabBar">' ;
print $langs -> trans ( 'ErrorUserViewCP' );
print '<br><br><input type="button" value="' . $langs -> trans ( " ReturnCP " ) . '" class="button" onclick="history.go(-1)" />' ;
print '</div>' ;
}
} else {
print '<div class="tabBar">' ;
print $langs -> trans ( 'ErrorIDFicheCP' );
print '<br><br><input type="button" value="' . $langs -> trans ( " ReturnCP " ) . '" class="button" onclick="history.go(-1)" />' ;
print '</div>' ;
}
2020-12-17 13:42:20 +01:00
// Select mail models is same action as presend
if ( GETPOST ( 'modelselected' )) {
$action = 'presend' ;
}
2021-02-26 17:59:31 +01:00
if ( $action != 'presend' ) {
2020-12-17 13:42:20 +01:00
print '<div class="fichecenter"><div class="fichehalfleft">' ;
print '<a name="builddoc"></a>' ; // ancre
$includedocgeneration = 0 ;
// Documents
if ( $includedocgeneration ) {
$objref = dol_sanitizeFileName ( $object -> ref );
$relativepath = $objref . '/' . $objref . '.pdf' ;
$filedir = $conf -> holiday -> dir_output . '/' . $object -> element . '/' . $objref ;
$urlsource = $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id ;
$genallowed = ( $user -> rights -> holiday -> read && $object -> fk_user == $user -> id ) || ! empty ( $user -> rights -> holiday -> readall ); // If you can read, you can build the PDF to read content
$delallowed = ( $user -> rights -> holiday -> write && $object -> fk_user == $user -> id ) || ! empty ( $user -> rights -> holiday -> writeall_advance ); // If you can create/edit, you can remove a file on card
print $formfile -> showdocuments ( 'holiday:Holiday' , $object -> element . '/' . $objref , $filedir , $urlsource , $genallowed , $delallowed , $object -> model_pdf , 1 , 0 , 0 , 28 , 0 , '' , '' , '' , $langs -> defaultlang );
}
// Show links to link elements
//$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
//$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div><div class="fichehalfright"><div class="ficheaddleft">' ;
$MAXEVENT = 10 ;
/* $morehtmlright = '<a href="' . dol_buildpath ( '/holiday/myobject_agenda.php' , 1 ) . '?id=' . $object -> id . '">' ;
$morehtmlright .= $langs -> trans ( " SeeAll " );
$morehtmlright .= '</a>' ; */
// List of actions on element
include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php' ;
$formactions = new FormActions ( $db );
$somethingshown = $formactions -> showactions ( $object , $object -> element , ( is_object ( $object -> thirdparty ) ? $object -> thirdparty -> id : 0 ), 1 , '' , $MAXEVENT , '' , $morehtmlright );
print '</div></div></div>' ;
}
2020-09-07 10:18:17 +02:00
}
2012-09-05 03:26:57 +02:00
}
// End of page
llxFooter ();
2021-02-26 17:59:31 +01:00
if ( is_object ( $db )) {
$db -> close ();
}