From 9819bb63bec83c13dd40ebb2ffc24df5fcfeda33 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 27 Apr 2019 14:47:02 +0000 Subject: [PATCH] Implemented configurable holidays. --- WEB-INF/lib/form/Calendar.class.php | 21 +++++++++-------- WEB-INF/lib/ttGroup.class.php | 2 ++ WEB-INF/lib/ttTimeHelper.class.php | 35 +++++++++++++++++++++++++++++ WEB-INF/lib/ttUser.class.php | 9 +++++++- WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/group_edit.tpl | 2 -- 6 files changed, 58 insertions(+), 13 deletions(-) diff --git a/WEB-INF/lib/form/Calendar.class.php b/WEB-INF/lib/form/Calendar.class.php index a8455a87..f160cfa6 100644 --- a/WEB-INF/lib/form/Calendar.class.php +++ b/WEB-INF/lib/form/Calendar.class.php @@ -171,15 +171,18 @@ class Calendar extends FormElement { $stl_cell = ' class="CalendarDay"'; } - // holidays - global $user; - if ($user->isOptionEnabled('show_holidays')) { - foreach ($this->holidays as $day) { - if($day == $date) { - $stl_cell = ' class="CalendarDayHoliday"'; - $stl_link = ' class="CalendarLinkHoliday"'; - } - } + // Handle holidays. + // Prepare a date to check in DB_DATEFORMAT. + $date_to_check = "$thisyear-"; + if (strlen($thismonth) == 1) $date_to_check .= '0'; + $date_to_check .= "$thismonth-"; + if (strlen($start_date+$j) == 1) $date_to_check .= '0'; + $date_to_check .= $start_date+$j; + + // Check if it falls on a holiday. + if (ttTimeHelper::isHoliday2($date_to_check)) { + $stl_cell = ' class="CalendarDayHoliday"'; + $stl_link = ' class="CalendarLinkHoliday"'; } // selected day diff --git a/WEB-INF/lib/ttGroup.class.php b/WEB-INF/lib/ttGroup.class.php index c3a56e05..c6693bec 100644 --- a/WEB-INF/lib/ttGroup.class.php +++ b/WEB-INF/lib/ttGroup.class.php @@ -60,6 +60,7 @@ class ttGroup { var $custom_logo = 0; // Whether to use a custom logo for group. var $lock_spec = null; // Cron specification for record locking. + var $holidays = null; // Holidays specification. var $workday_minutes = 480; // Number of work minutes in a regular day. var $active_users = 0; // Count of active users in group. @@ -103,6 +104,7 @@ class ttGroup { $this->currency = $val['currency']; $this->plugins = $val['plugins']; $this->lock_spec = $val['lock_spec']; + $this->holidays = $val['holidays']; $this->workday_minutes = $val['workday_minutes']; /* $this->custom_logo = $val['custom_logo']; diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index 08ffc46d..2b5b39bc 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -53,6 +53,41 @@ class ttTimeHelper { return false; } + // isHoliday determines if $date falls on a holiday. + static function isHoliday2($date) { + global $user; + + $holidays = $user->getHolidays(); + if (!$holidays) + return false; + + $holiday_dates = explode(',', $holidays); + foreach ($holiday_dates as $holiDateSpec) { + if (ttTimeHelper::holidayMatch($date, $holiDateSpec)) + return true; + } + return false; + } + + // holidayMatch determines if $date matches a single $holiDateSpec. + static function holidayMatch($date, $holiDateSpec) { + + $dateArray = explode('-', $date); + $holiDateSpecArray = explode('-', $holiDateSpec); + + // Check year. + if ($dateArray[0] != $holiDateSpecArray[0] && $holiDateSpecArray[0] != '****') // **** means all years. + return false; + // Check month. + if ($dateArray[1] != $holiDateSpecArray[1]) + return false; + // Check day. + if ($dateArray[2] != $holiDateSpecArray[2]) + return false; + + return true; + } + // isValidTime validates a value as a time string. static function isValidTime($value) { if (strlen($value)==0 || !isset($value)) return false; diff --git a/WEB-INF/lib/ttUser.class.php b/WEB-INF/lib/ttUser.class.php index ab0affe4..16e2d2d1 100644 --- a/WEB-INF/lib/ttUser.class.php +++ b/WEB-INF/lib/ttUser.class.php @@ -75,6 +75,7 @@ class ttUser { var $custom_logo = 0; // Whether to use a custom logo for group. var $lock_spec = null; // Cron specification for record locking. + var $holidays = null; // Holidays specification. var $workday_minutes = 480; // Number of work minutes in a regular day. var $rights = array(); // An array of user rights such as 'track_own_time', etc. var $is_client = false; // Whether user is a client as determined by missing 'track_own_time' right. @@ -94,7 +95,7 @@ class ttUser { $sql = "SELECT u.id, u.login, u.name, u.group_id, u.role_id, r.rank, r.name as role_name, r.rights, u.client_id,". " u.quota_percent, u.email, g.org_id, g.name as group_name, g.currency, g.lang, g.decimal_mark, g.date_format,". " g.time_format, g.week_start, g.tracking_mode, g.project_required, g.task_required, g.record_type,". - " g.bcc_email, g.allow_ip, g.password_complexity, g.plugins, g.config, g.lock_spec, g.workday_minutes, g.custom_logo". + " g.bcc_email, g.allow_ip, g.password_complexity, g.plugins, g.config, g.lock_spec, g.holidays, g.workday_minutes, g.custom_logo". " FROM tt_users u LEFT JOIN tt_groups g ON (u.group_id = g.id) LEFT JOIN tt_roles r on (r.id = u.role_id) WHERE "; if ($id) $sql .= "u.id = $id"; @@ -138,6 +139,7 @@ class ttUser { $this->currency = $val['currency']; $this->plugins = $val['plugins']; $this->lock_spec = $val['lock_spec']; + $this->holidays = $val['holidays']; $this->workday_minutes = $val['workday_minutes']; $this->custom_logo = $val['custom_logo']; @@ -228,6 +230,11 @@ class ttUser { return ($this->behalfGroup ? $this->behalfGroup->lock_spec : $this->lock_spec); } + // getHolidays returns holidays specification for active group. + function getHolidays() { + return ($this->behalfGroup ? $this->behalfGroup->holidays : $this->holidays); + } + // getWorkdayMinutes returns workday_minutes for active group. function getWorkdayMinutes() { return ($this->behalfGroup ? $this->behalfGroup->workday_minutes : $this->workday_minutes); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 4d893815..7efa4d66 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- -{if isTrue('HOLIDAYS_DEBUG')} -{/if} -- 2.20.1
 Anuko Time Tracker 1.19.4.4991 | Copyright © Anuko | +  Anuko Time Tracker 1.19.4.4992 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/group_edit.tpl b/WEB-INF/templates/group_edit.tpl index 00cd8169..a68e28eb 100644 --- a/WEB-INF/templates/group_edit.tpl +++ b/WEB-INF/templates/group_edit.tpl @@ -78,12 +78,10 @@ function handleTaskRequiredCheckbox() { {$i18n.form.group_edit.show_holidays}: {$forms.groupForm.show_holidays.control} {$i18n.label.what_is_it}
{$i18n.form.group_edit.holidays}: {$forms.groupForm.holidays.control} {$i18n.label.what_is_it}
{$i18n.form.group_edit.tracking_mode}: {$forms.groupForm.tracking_mode.control} {$forms.groupForm.task_required.control}