From 06f5163f4a234e89b5d761e7f537160f40d4a2e8 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Thu, 13 Dec 2018 17:11:47 +0000 Subject: [PATCH] Some more refactoring for subgroups. --- WEB-INF/lib/ttReportHelper.class.php | 14 +++++++++----- WEB-INF/lib/ttTimeHelper.class.php | 10 ++++++++-- WEB-INF/templates/footer.tpl | 2 +- mobile/time.php | 2 +- mobile/timer.php | 2 +- time.php | 2 +- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/WEB-INF/lib/ttReportHelper.class.php b/WEB-INF/lib/ttReportHelper.class.php index 38da9879..26478c3b 100644 --- a/WEB-INF/lib/ttReportHelper.class.php +++ b/WEB-INF/lib/ttReportHelper.class.php @@ -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"; diff --git a/WEB-INF/lib/ttTimeHelper.class.php b/WEB-INF/lib/ttTimeHelper.class.php index f48ecc8a..5eeed1f0 100644 --- a/WEB-INF/lib/ttTimeHelper.class.php +++ b/WEB-INF/lib/ttTimeHelper.class.php @@ -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(); diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index e031d383..861431d9 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.30.4643 | Copyright © Anuko | +  Anuko Time Tracker 1.18.30.4644 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mobile/time.php b/mobile/time.php index 6bacd084..80049a9c 100644 --- a/mobile/time.php +++ b/mobile/time.php @@ -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); diff --git a/mobile/timer.php b/mobile/timer.php index 73035a39..682634c8 100644 --- a/mobile/timer.php +++ b/mobile/timer.php @@ -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); diff --git a/time.php b/time.php index 06665310..b85cad0e 100644 --- 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); -- 2.20.1