From: Nik Okuntseff Date: Tue, 4 Dec 2018 16:40:34 +0000 (+0000) Subject: Some more progress with refactoring for subgroups. X-Git-Tag: timetracker_1.19-1~482 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6289820a41e9ab79635294c1d6a22583aacf6e77;p=timetracker.git Some more progress with refactoring for subgroups. --- diff --git a/WEB-INF/lib/ttExpenseHelper.class.php b/WEB-INF/lib/ttExpenseHelper.class.php index bfc3ab72..9f5e838d 100644 --- a/WEB-INF/lib/ttExpenseHelper.class.php +++ b/WEB-INF/lib/ttExpenseHelper.class.php @@ -123,11 +123,14 @@ class ttExpenseHelper { } // getItem - retrieves an entry from tt_expense_items table. - static function getItem($id, $user_id) { + static function getItem($id) { global $user; - $mdb2 = getConnection(); + $user_id = $user->getUser(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + $client_field = null; if ($user->isPluginEnabled('cl')) $client_field = ", c.name as client_name"; @@ -137,17 +140,16 @@ class ttExpenseHelper { if ($user->isPluginEnabled('cl')) $left_joins .= " left join tt_clients c on (ei.client_id = c.id)"; - $sql = "select ei.id, ei.date, ei.client_id, ei.project_id, ei.name, ei.cost, ei.invoice_id, ei.paid $client_field, p.name as project_name - from tt_expense_items ei - $left_joins - where ei.id = $id and ei.user_id = $user_id and ei.status = 1"; + $sql = "select ei.id, ei.date, ei.client_id, ei.project_id, ei.name, ei.cost, ei.invoice_id, ei.paid $client_field, p.name as project_name". + " from tt_expense_items ei $left_joins". + " where ei.id = $id and ei.group_id = $group_id and ei.org_id = $org_id and ei.user_id = $user_id and ei.status = 1"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { if (!$res->numRows()) { return false; } if ($val = $res->fetchRow()) { - $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']); + $val['cost'] = str_replace('.', $user->getDecimalMark(), $val['cost']); return $val; } } @@ -155,11 +157,15 @@ class ttExpenseHelper { } // getItems - returns expense items for a user for a given date. - static function getItems($user_id, $date) { + static function getItems($date) { global $user; + $mdb2 = getConnection(); + + $user_id = $user->getUser(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; $result = array(); - $mdb2 = getConnection(); $client_field = null; if ($user->isPluginEnabled('cl')) @@ -170,16 +176,15 @@ class ttExpenseHelper { if ($user->isPluginEnabled('cl')) $left_joins .= " left join tt_clients c on (ei.client_id = c.id)"; - $sql = "select ei.id as id $client_field, p.name as project, ei.name as item, ei.cost as cost, - ei.invoice_id from tt_expense_items ei - $left_joins - where ei.date = ".$mdb2->quote($date)." and ei.user_id = $user_id and ei.status = 1 - order by ei.id"; + $sql = "select ei.id as id $client_field, p.name as project, ei.name as item, ei.cost as cost,". + " ei.invoice_id from tt_expense_items ei $left_joins". + " where ei.date = ".$mdb2->quote($date)." and ei.user_id = $user_id". + " and ei.group_id = $group_id and ei.org_id = $org_id and ei.status = 1 order by ei.id"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { - $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']); + $val['cost'] = str_replace('.', $user->getDecimalMark(), $val['cost']); $result[] = $val; } } else return false; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 05f357bc..747f7201 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4582 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4583 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/expense_delete.php b/expense_delete.php index 32b9ab67..d5eccf79 100644 --- a/expense_delete.php +++ b/expense_delete.php @@ -42,7 +42,7 @@ if (!$user->isPluginEnabled('ex')) { } $cl_id = (int)$request->getParameter('id'); // Get the expense item we are deleting. -$expense_item = ttExpenseHelper::getItem($cl_id, $user->getUser()); +$expense_item = ttExpenseHelper::getItem($cl_id); if (!$expense_item || $expense_item['invoice_id']) { // Prohibit deleting not ours or invoiced items. header('Location: access_denied.php'); diff --git a/expense_edit.php b/expense_edit.php index 80f861c8..dd4a133b 100644 --- a/expense_edit.php +++ b/expense_edit.php @@ -44,7 +44,7 @@ if (!$user->isPluginEnabled('ex')) { } $cl_id = (int)$request->getParameter('id'); // Get the expense item we are editing. -$expense_item = ttExpenseHelper::getItem($cl_id, $user->getUser()); +$expense_item = ttExpenseHelper::getItem($cl_id); if (!$expense_item || $expense_item['invoice_id']) { // Prohibit editing not ours or invoiced items. header('Location: access_denied.php'); diff --git a/expenses.php b/expenses.php index eea55d1c..1c70a5a3 100644 --- a/expenses.php +++ b/expenses.php @@ -212,7 +212,7 @@ if ($request->isPost()) { } $smarty->assign('day_total', ttExpenseHelper::getTotalForDay($cl_date)); -$smarty->assign('expense_items', ttExpenseHelper::getItems($user->getUser(), $cl_date)); +$smarty->assign('expense_items', ttExpenseHelper::getItems($cl_date)); $smarty->assign('predefined_expenses', $predefined_expenses); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); diff --git a/mobile/expense_delete.php b/mobile/expense_delete.php index 93d6d59f..c33f5232 100644 --- a/mobile/expense_delete.php +++ b/mobile/expense_delete.php @@ -42,7 +42,7 @@ if (!$user->isPluginEnabled('ex')) { } $cl_id = (int)$request->getParameter('id'); // Get the expense item we are deleting. -$expense_item = ttExpenseHelper::getItem($cl_id, $user->getUser()); +$expense_item = ttExpenseHelper::getItem($cl_id); if (!$expense_item || $expense_item['invoice_id']) { // Prohibit deleting not ours or invoiced items. header('Location: access_denied.php'); diff --git a/mobile/expense_edit.php b/mobile/expense_edit.php index fa00b586..7938a4f1 100644 --- a/mobile/expense_edit.php +++ b/mobile/expense_edit.php @@ -44,7 +44,7 @@ if (!$user->isPluginEnabled('ex')) { } $cl_id = (int)$request->getParameter('id'); // Get the expense item we are editing. -$expense_item = ttExpenseHelper::getItem($cl_id, $user->getUser()); +$expense_item = ttExpenseHelper::getItem($cl_id); if (!$expense_item || $expense_item['invoice_id']) { // Prohibit editing not ours or invoiced items. header('Location: access_denied.php'); diff --git a/mobile/expenses.php b/mobile/expenses.php index 656b20e0..15f914b2 100644 --- a/mobile/expenses.php +++ b/mobile/expenses.php @@ -218,7 +218,7 @@ if ($request->isPost()) { $smarty->assign('next_date', $next_date); $smarty->assign('prev_date', $prev_date); $smarty->assign('day_total', ttExpenseHelper::getTotalForDay($cl_date)); -$smarty->assign('expense_items', ttExpenseHelper::getItems($user->getUser(), $cl_date)); +$smarty->assign('expense_items', ttExpenseHelper::getItems($cl_date)); $smarty->assign('predefined_expenses', $predefined_expenses); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list);