From b94d9134402cf514d51eea44b30125505e5cbd96 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 15 Sep 2014 10:19:08 +0200 Subject: [PATCH] New: Add option AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS to automatically set end date of event to start date + delta on creation page. --- htdocs/comm/action/fiche.php | 4 ++++ htdocs/core/lib/date.lib.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index a12867c0800..e797c89760f 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -547,6 +547,10 @@ if ($action == 'create') // Date end $datef=($datef?$datef:$object->datef); if (GETPOST('datef','int',1)) $datef=dol_stringtotime(GETPOST('datef','int',1),0); + if (empty($datef) && ! empty($datep) && ! empty($conf->global->AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS)) + { + $datef=dol_time_plus_duree($datep, $conf->global->AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS, 'h'); + } print ''.$langs->trans("DateActionEnd").''; if (GETPOST("afaire") == 1) $form->select_date($datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend'); else if (GETPOST("afaire") == 2) $form->select_date($datef,'p2',1,1,1,"action",1,1,0,0,'fulldayend'); diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 2fae2b68952..eaf6b9e83dd 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -131,12 +131,13 @@ function getServerTimeZoneInt($refgmtdate='now') * * @param int $time Date timestamp (or string with format YYYY-MM-DD) * @param int $duration_value Value of delay to add - * @param int $duration_unit Unit of added delay (d, m, y, w) + * @param int $duration_unit Unit of added delay (d, m, y, w, h) * @return int New timestamp */ function dol_time_plus_duree($time,$duration_value,$duration_unit) { if ($duration_value == 0) return $time; + if ($duration_unit == 'h') return $time + (3600*$duration_value); if ($duration_unit == 'w') return $time + (3600*24*7*$duration_value); if ($duration_value > 0) $deltastring="+".abs($duration_value); if ($duration_value < 0) $deltastring="-".abs($duration_value);