Some more refactoring for subgroups.
authorNik Okuntseff <support@anuko.com>
Thu, 13 Dec 2018 17:11:47 +0000 (17:11 +0000)
committerNik Okuntseff <support@anuko.com>
Thu, 13 Dec 2018 17:11:47 +0000 (17:11 +0000)
WEB-INF/lib/ttReportHelper.class.php
WEB-INF/lib/ttTimeHelper.class.php
WEB-INF/templates/footer.tpl
mobile/time.php
mobile/timer.php
time.php

index 38da987..26478c3 100644 (file)
@@ -40,6 +40,9 @@ class ttReportHelper {
   static function getWhere($options) {
     global $user;
 
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
     // Prepare dropdown parts.
     $dropdown_parts = '';
     if ($options['client_id'])
@@ -61,17 +64,18 @@ class ttReportHelper {
     if ($user->can('view_reports') || $user->can('view_all_reports') || $user->isClient())
       $user_list_part = " and l.user_id in ($userlist)";
     else
-      $user_list_part = " and l.user_id = ".$user->id;
-    $user_list_part .= " and l.group_id = ".$user->getGroup();
+      $user_list_part = " and l.user_id = ".$user->getUser();
+    $user_list_part .= " and l.group_id = $group_id and l.org_id = $org_id";
 
     // Prepare sql query part for where.
+    $dateFormat = $user->getDateFormat();
     if ($options['period'])
-      $period = new Period($options['period'], new DateAndTime($user->date_format));
+      $period = new Period($options['period'], new DateAndTime($dateFormat));
     else {
       $period = new Period();
       $period->setPeriod(
-        new DateAndTime($user->date_format, $options['period_start']),
-        new DateAndTime($user->date_format, $options['period_end']));
+        new DateAndTime($dateFormat, $options['period_start']),
+        new DateAndTime($dateFormat, $options['period_end']));
     }
     $where = " where l.status = 1 and l.date >= '".$period->getStartDate(DB_DATEFORMAT)."' and l.date <= '".$period->getEndDate(DB_DATEFORMAT)."'".
       " $user_list_part $dropdown_parts";
index f48ecc8..5eeed1f 100644 (file)
@@ -530,10 +530,16 @@ class ttTimeHelper {
   }
 
   // getTimeForDay - gets total time for a user for a specific date.
-  static function getTimeForDay($user_id, $date) {
+  static function getTimeForDay($date) {
+    global $user;
     $mdb2 = getConnection();
 
-    $sql = "select sum(time_to_sec(duration)) as sm from tt_log where user_id = $user_id and date = '$date' and status = 1";
+    $user_id = $user->getUser();
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
+    $sql = "select sum(time_to_sec(duration)) as sm from tt_log".
+      " where user_id = $user_id and group_id = $group_id and org_id = $org_id and date = '$date' and status = 1";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       $val = $res->fetchRow();
index e031d38..861431d 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.18.30.4643 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.30.4644 | 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 6bacd08..80049a9 100644 (file)
@@ -286,7 +286,7 @@ if ($request->isPost()) {
 $smarty->assign('next_date', $next_date);
 $smarty->assign('prev_date', $prev_date);
 $smarty->assign('time_records', ttTimeHelper::getRecords($user_id, $cl_date));
-$smarty->assign('day_total', ttTimeHelper::getTimeForDay($user_id, $cl_date));
+$smarty->assign('day_total', ttTimeHelper::getTimeForDay($cl_date));
 $smarty->assign('client_list', $client_list);
 $smarty->assign('project_list', $project_list);
 $smarty->assign('task_list', $task_list);
index 73035a3..682634c 100644 (file)
@@ -291,7 +291,7 @@ $smarty->assign('uncompleted', $uncompleted);
 
 
 $smarty->assign('time_records', ttTimeHelper::getRecords($user->getUser(), $cl_date));
-$smarty->assign('day_total', ttTimeHelper::getTimeForDay($user->getUser(), $cl_date));
+$smarty->assign('day_total', ttTimeHelper::getTimeForDay($cl_date));
 $smarty->assign('client_list', $client_list);
 $smarty->assign('project_list', $project_list);
 $smarty->assign('task_list', $task_list);
index 0666531..b85cad0 100644 (file)
--- a/time.php
+++ b/time.php
@@ -398,7 +398,7 @@ $week_total = ttTimeHelper::getTimeForWeek($user_id, $selected_date);
 
 $smarty->assign('selected_date', $selected_date);
 $smarty->assign('week_total', $week_total);
-$smarty->assign('day_total', ttTimeHelper::getTimeForDay($user_id, $cl_date));
+$smarty->assign('day_total', ttTimeHelper::getTimeForDay($cl_date));
 $smarty->assign('time_records', ttTimeHelper::getRecords($user_id, $cl_date));
 $smarty->assign('client_list', $client_list);
 $smarty->assign('project_list', $project_list);