Implemented configurable holidays.
authorNik Okuntseff <support@anuko.com>
Sat, 27 Apr 2019 14:47:02 +0000 (14:47 +0000)
committerNik Okuntseff <support@anuko.com>
Sat, 27 Apr 2019 14:47:02 +0000 (14:47 +0000)
WEB-INF/lib/form/Calendar.class.php
WEB-INF/lib/ttGroup.class.php
WEB-INF/lib/ttTimeHelper.class.php
WEB-INF/lib/ttUser.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/group_edit.tpl

index a8455a8..f160cfa 100644 (file)
@@ -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
index c3a56e0..c6693be 100644 (file)
@@ -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'];
index 08ffc46..2b5b39b 100644 (file)
@@ -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;
index ab0affe..16e2d2d 100644 (file)
@@ -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);
index 4d89381..7efa4d6 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.19.4.4991 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.19.4.4992 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index 00cd816..a68e28e 100644 (file)
@@ -78,12 +78,10 @@ function handleTaskRequiredCheckbox() {
             <td align="right" nowrap>{$i18n.form.group_edit.show_holidays}:</td>
             <td>{$forms.groupForm.show_holidays.control} <a href="https://www.anuko.com/lp/tt_14.htm" target="_blank">{$i18n.label.what_is_it}</a></td>
           </tr>
-{if isTrue('HOLIDAYS_DEBUG')}
           <tr>
             <td align="right" nowrap>{$i18n.form.group_edit.holidays}:</td>
             <td>{$forms.groupForm.holidays.control} <a href="https://www.anuko.com/lp/tt_14.htm" target="_blank">{$i18n.label.what_is_it}</a></td>
           </tr>
-{/if}
           <tr>
             <td align="right" nowrap>{$i18n.form.group_edit.tracking_mode}:</td>
             <td>{$forms.groupForm.tracking_mode.control} {$forms.groupForm.task_required.control} <span id="task_required_label"><label for="task_required">{$i18n.label.required}</label></span></td>