From d24d7483854015ce95488831aed43255261a7baf Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Tue, 4 Dec 2018 20:51:54 +0000 Subject: [PATCH] Refactored ttPredefinedExpenseHelper class. --- .../lib/ttPredefinedExpenseHelper.class.php | 34 ++++++++++--------- WEB-INF/templates/footer.tpl | 2 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/WEB-INF/lib/ttPredefinedExpenseHelper.class.php b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php index 670e061c..8ec8ccfe 100644 --- a/WEB-INF/lib/ttPredefinedExpenseHelper.class.php +++ b/WEB-INF/lib/ttPredefinedExpenseHelper.class.php @@ -31,21 +31,21 @@ class ttPredefinedExpenseHelper { // get - gets predefined expense details. - static function get($id) - { + static function get($id) { global $user; - $replaceDecimalMark = ('.' != $user->decimal_mark); - $mdb2 = getConnection(); - $sql = "select id, name, cost from tt_predefined_expenses - where id = $id and group_id = ".$user->getGroup(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select id, name, cost from tt_predefined_expenses". + " where id = $id and group_id = $group_id and org_id = $org_id"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { $val = $res->fetchRow(); if ($val && $val['id']) { - if ($replaceDecimalMark) - $val['cost'] = str_replace('.', $user->decimal_mark, $val['cost']); + if ('.' != $user->getDecimalMark()) + $val['cost'] = str_replace('.', $user->getDecimalMark(), $val['cost']); return $val; } } @@ -55,10 +55,13 @@ class ttPredefinedExpenseHelper { // delete - deletes a predefined expense from tt_predefined_expenses table. static function delete($id) { global $user; - $mdb2 = getConnection(); - $sql = "delete from tt_predefined_expenses where id = $id and group_id = ".$user->getGroup(); + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "delete from tt_predefined_expenses". + " where id = $id and group_id = $group_id and org_id = $org_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; @@ -77,7 +80,7 @@ class ttPredefinedExpenseHelper { $name = $fields['name']; $cost = $fields['cost']; if ('.' != $user->getDecimalMark()) - $cost = str_replace($user->getDecimalMark, '.', $cost); + $cost = str_replace($user->getDecimalMark(), '.', $cost); $sql = "insert into tt_predefined_expenses (group_id, org_id, name, cost)". " values ($group_id, $org_id, ".$mdb2->quote($name).", ".$mdb2->quote($cost).")"; @@ -89,19 +92,18 @@ class ttPredefinedExpenseHelper { } // update function - updates a predefined expense in database. - static function update($fields) - { + static function update($fields) { global $user; - $mdb2 = getConnection(); $group_id = $user->getGroup(); $org_id = $user->org_id; + $predefined_expense_id = (int) $fields['id']; $name = $fields['name']; $cost = $fields['cost']; - if ('.' != $user->decimal_mark) - $cost = str_replace($user->decimal_mark, '.', $cost); + if ('.' != $user->getDecimalMark()) + $cost = str_replace($user->getDecimalMark(), '.', $cost); $sql = "update tt_predefined_expenses set name = ".$mdb2->quote($name).", cost = ".$mdb2->quote($cost). " where id = $predefined_expense_id and group_id = $group_id and org_id = $org_id"; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index e74a6a5e..3af107e9 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.29.4585 | Copyright © Anuko | +  Anuko Time Tracker 1.18.29.4586 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} -- 2.20.1