From bbd7900fc7885013c7e17607c4b5e1144dc50e12 Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Thu, 16 Jan 2020 10:34:45 +0100 Subject: [PATCH 1/4] Show holidays in agenda --- htdocs/comm/action/index.php | 106 ++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index c4750ef54db..a84ea741721 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -757,6 +757,95 @@ if ($showbirthday) } } +if($conf->global->AGENDA_SHOW_HOLIDAYS) +{ + $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status"; + $sql.= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u"; + $sql.= " WHERE u.rowid = x.fk_user"; + $sql.= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user) + $sql.= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved) + + if($action == 'show_day') + { + // Request only leaves for the current selected day + $sql.= " AND '".$year."-".$month."-".$day."' BETWEEN x.date_debut AND x.date_fin"; + } + elseif($action == 'show_week') + { + // TODO: Add filter to reduce database request + } + elseif($action == 'show_month') + { + // TODO: Add filter to reduce database request + } + + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $dateStartArray = dol_getdate(dol_stringtotime($obj->date_start, 1), true); + $dateEndArray = dol_getdate(dol_stringtotime($obj->date_end, 1), true); + + $event = new ActionComm($db); + + // Need the id of the leave object for link to it + $event->id = $obj->rowid; + + $event->type_code = 'HOLIDAY'; + $event->datep = dol_mktime(0, 0, 0, $dateStartArray['mon'], $dateStartArray['mday'], $dateStartArray['year'], true); + $event->datef = dol_mktime(0, 0, 0, $dateEndArray['mon'], $dateEndArray['mday'], $dateEndArray['year'], true); + $event->date_start_in_calendar = $event->datep; + $event->date_end_in_calendar = $event->datef; + + if($obj->status == 3) + { + // Show no symbol for leave with state "leave approved" + $event->percentage = -1; + } + elseif($obj->status == 2) + { + // Show TO-DO symbol for leave with state "leave wait for approval" + $event->percentage = 0; + } + + if($obj->halfday == 1) + { + $event->label = $obj->lastname.' ('.$langs->trans("Morning").')'; + } + elseif($obj->halfday == -1) + { + $event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')'; + } + else + { + $event->label = $obj->lastname; + } + + $annee = date('Y', $event->date_start_in_calendar); + $mois = date('m', $event->date_start_in_calendar); + $jour = date('d', $event->date_start_in_calendar); + $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee); + + do + { + $eventarray[$daykey][] = $event; + + $daykey += 60*60*24; + } + + while ($daykey <= $event->date_end_in_calendar); + + $i++; + } + } +} + // Complete $eventarray with external import Ical if (count($listofextcals)) { @@ -1512,7 +1601,11 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa { print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact'); } - if ($event->type_code != 'BIRTHDAY') + elseif ($event->type_code == 'HOLIDAY') + { + print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'holiday', 'user'); + } + elseif ($event->type_code != 'BIRTHDAY' && $event->type_code != 'HOLIDAY') { // Picto if (empty($event->fulldayevent)) @@ -1740,6 +1833,17 @@ function dol_color_minus($color, $minus, $minusunit = 16) */ function sort_events_by_date($a, $b) { + // Sort holidays at first + if($a->type_code === 'HOLIDAY') + { + return -1; + } + + if($b->type_code === 'HOLIDAY') + { + return 1; + } + // datep => Event start time // datef => Event end time From 72e227a543e290ddd2acb72b0286a16f03378cda Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Thu, 16 Jan 2020 10:37:16 +0100 Subject: [PATCH 2/4] Add link to leave request for holidays in agenda --- htdocs/comm/action/class/actioncomm.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 454a78979b0..2d0219ca4e1 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1378,13 +1378,13 @@ class ActionComm extends CommonObject * Return URL of event * Use $this->id, $this->type_code, $this->label and $this->type_label * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $withpicto 0 = No picto, 1 = Include picto into link, 2 = Only picto * @param int $maxlength Max number of charaters into label. If negative, use the ref as label. * @param string $classname Force style class on a link - * @param string $option ''=Link to action, 'birthday'=Link to contact - * @param int $overwritepicto 1=Overwrite picto - * @param int $notooltip 1=Disable tooltip - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param string $option '' = Link to action, 'birthday'= Link to contact, 'holiday' = Link to leave + * @param int $overwritepicto 1 = Overwrite picto + * @param int $notooltip 1 = Disable tooltip + * @param int $save_lastsearch_value -1 = Auto, 0 = No save of lastsearch_values when clicking, 1 = Save lastsearch_values whenclicking * @return string Chaine avec URL */ public function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1) @@ -1451,6 +1451,8 @@ class ActionComm extends CommonObject $url = ''; if ($option == 'birthday') $url = DOL_URL_ROOT.'/contact/perso.php?id='.$this->id; + elseif ($option == 'holiday') + $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id; else $url = DOL_URL_ROOT.'/comm/action/card.php?id='.$this->id; if ($option !== 'nolink') From b79c6fc84886f35eee49b0bf8c532a5d9ce07831 Mon Sep 17 00:00:00 2001 From: Tobias Sekan Date: Thu, 16 Jan 2020 10:38:20 +0100 Subject: [PATCH 3/4] Update German language --- htdocs/langs/de_DE/holiday.lang | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/langs/de_DE/holiday.lang b/htdocs/langs/de_DE/holiday.lang index 2143adfd5b3..23adf217284 100644 --- a/htdocs/langs/de_DE/holiday.lang +++ b/htdocs/langs/de_DE/holiday.lang @@ -129,3 +129,5 @@ FreeLegalTextOnHolidays=Freitext als PDF WatermarkOnDraftHolidayCards=Wasserzeichen auf Urlaubsantragsentwurf (leerlassen wenn keines benötigt wird) HolidaysToApprove=Urlaubstage zu genehmigen NobodyHasPermissionToValidateHolidays=Niemand hat die Erlaubnis, Feiertage zu bestätigen. +Morning=Vormittags +Afternoon=Nachmittags From eca59220d8dd2b260e93244c459f7cc3df02903b Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 16 Jan 2020 09:44:49 +0000 Subject: [PATCH 4/4] Fixing style errors. --- htdocs/comm/action/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index a84ea741721..7e4b800dbdd 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -764,7 +764,7 @@ if($conf->global->AGENDA_SHOW_HOLIDAYS) $sql.= " WHERE u.rowid = x.fk_user"; $sql.= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user) $sql.= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved) - + if($action == 'show_day') { // Request only leaves for the current selected day @@ -810,7 +810,7 @@ if($conf->global->AGENDA_SHOW_HOLIDAYS) } elseif($obj->status == 2) { - // Show TO-DO symbol for leave with state "leave wait for approval" + // Show TO-DO symbol for leave with state "leave wait for approval" $event->percentage = 0; } @@ -1843,7 +1843,7 @@ function sort_events_by_date($a, $b) { return 1; } - + // datep => Event start time // datef => Event end time