From 997b32f47f535f6e801bb220749826f1c179bfba Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Wed, 28 Nov 2018 14:59:19 +0000 Subject: [PATCH] A bit more refactoring on time entry pages. --- WEB-INF/templates/footer.tpl | 2 +- mobile/time.php | 12 +++++++----- mobile/time_delete.php | 8 +++----- mobile/time_edit.php | 9 +++++---- time_delete.php | 8 +++----- time_edit.php | 15 ++++++++------- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 312131d2..ae1e68c7 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.28.4533 | Copyright © Anuko | +  Anuko Time Tracker 1.18.28.4534 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/mobile/time.php b/mobile/time.php index 6aa97330..2b8e01f0 100644 --- a/mobile/time.php +++ b/mobile/time.php @@ -41,6 +41,8 @@ if (!ttAccessAllowed('track_own_time')) { } // End of access checks. +$user_id = $user->getUser(); + // Initialize and store date in session. $cl_date = $request->getParameter('date', @$_SESSION['date']); $selected_date = new DateAndTime(DB_DATEFORMAT, $cl_date); @@ -238,20 +240,20 @@ if ($request->isPost()) { // Prohibit creating another uncompleted record. if ($err->no()) { - if (($not_completed_rec = ttTimeHelper::getUncompleted($user->getUser())) && (($cl_finish == '') && ($cl_duration == ''))) + if (($not_completed_rec = ttTimeHelper::getUncompleted($user_id)) && (($cl_finish == '') && ($cl_duration == ''))) $err->add($i18n->get('error.uncompleted_exists')." ".$i18n->get('error.goto_uncompleted').""); } // Prohibit creating an overlapping record. if ($err->no()) { - if (ttTimeHelper::overlaps($user->getUser(), $cl_date, $cl_start, $cl_finish)) + if (ttTimeHelper::overlaps($user_id, $cl_date, $cl_start, $cl_finish)) $err->add($i18n->get('error.overlap')); } if ($err->no()) { $id = ttTimeHelper::insert(array( 'date' => $cl_date, - 'user_id' => $user->getUser(), + 'user_id' => $user_id, 'group_id' => $user->getGroup(), 'org_id' => $user->org_id, 'client' => $cl_client, @@ -283,8 +285,8 @@ if ($request->isPost()) { $smarty->assign('next_date', $next_date); $smarty->assign('prev_date', $prev_date); -$smarty->assign('time_records', ttTimeHelper::getRecords($user->getUser(), $cl_date)); -$smarty->assign('day_total', ttTimeHelper::getTimeForDay($user->getUser(), $cl_date)); +$smarty->assign('time_records', ttTimeHelper::getRecords($user_id, $cl_date)); +$smarty->assign('day_total', ttTimeHelper::getTimeForDay($user_id, $cl_date)); $smarty->assign('client_list', $client_list); $smarty->assign('project_list', $project_list); $smarty->assign('task_list', $task_list); diff --git a/mobile/time_delete.php b/mobile/time_delete.php index 55bdffe6..f5305bc6 100644 --- a/mobile/time_delete.php +++ b/mobile/time_delete.php @@ -38,7 +38,8 @@ if (!ttAccessAllowed('track_own_time')) { exit(); } $cl_id = (int)$request->getParameter('id'); -$time_rec = ttTimeHelper::getRecord($cl_id, $user->getUser()); +$user_id = $user->getUser(); +$time_rec = ttTimeHelper::getRecord($cl_id, $user_id); if (!$time_rec || $time_rec['invoice_id']) { // Prohibit deleting not ours or invoiced records. header('Location: access_denied.php'); @@ -62,11 +63,8 @@ if ($request->isPost()) { $err->add($i18n->get('error.range_locked')); if ($err->no()) { - // Delete the record. - $result = ttTimeHelper::delete($cl_id, $user->getUser()); - - if ($result) { + if (ttTimeHelper::delete($cl_id, $user_id)) { header('Location: time.php'); exit(); } else { diff --git a/mobile/time_edit.php b/mobile/time_edit.php index 56d373ff..b2655e8f 100644 --- a/mobile/time_edit.php +++ b/mobile/time_edit.php @@ -40,7 +40,8 @@ if (!ttAccessAllowed('track_own_time')) { exit(); } $cl_id = (int)$request->getParameter('id'); -$time_rec = ttTimeHelper::getRecord($cl_id, $user->getUser()); +$user_id = $user->getUser(); +$time_rec = ttTimeHelper::getRecord($cl_id, $user_id); if (!$time_rec || $time_rec['invoice_id']) { // Prohibit editing not ours or invoiced records. header('Location: access_denied.php'); @@ -279,7 +280,7 @@ if ($request->isPost()) { // 3) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists. $uncompleted = ($cl_finish == '' && $cl_duration == ''); if ($uncompleted) { - $not_completed_rec = ttTimeHelper::getUncompleted($user->getUser()); + $not_completed_rec = ttTimeHelper::getUncompleted($user_id); if ($not_completed_rec && ($time_rec['id'] <> $not_completed_rec['id'])) { // We have another not completed record. $err->add($i18n->get('error.uncompleted_exists')." ".$i18n->get('error.goto_uncompleted').""); @@ -289,7 +290,7 @@ if ($request->isPost()) { // Prohibit creating an overlapping record. if ($err->no()) { - if (ttTimeHelper::overlaps($user->getUser(), $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish, $cl_id)) + if (ttTimeHelper::overlaps($user_id, $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish, $cl_id)) $err->add($i18n->get('error.overlap')); } @@ -298,7 +299,7 @@ if ($request->isPost()) { $res = ttTimeHelper::update(array( 'id'=>$cl_id, 'date'=>$new_date->toString(DB_DATEFORMAT), - 'user_id'=>$user->getUser(), + 'user_id'=>$user_id, 'client'=>$cl_client, 'project'=>$cl_project, 'task'=>$cl_task, diff --git a/time_delete.php b/time_delete.php index 4e368df2..385e4f11 100644 --- a/time_delete.php +++ b/time_delete.php @@ -38,7 +38,8 @@ if (!(ttAccessAllowed('track_own_time') || ttAccessAllowed('track_time'))) { exit(); } $cl_id = (int)$request->getParameter('id'); -$time_rec = ttTimeHelper::getRecord($cl_id, $user->getUser()); +$user_id = $user->getUser(); +$time_rec = ttTimeHelper::getRecord($cl_id, $user_id); if (!$time_rec || $time_rec['invoice_id']) { // Prohibit deleting not ours or invoiced records. header('Location: access_denied.php'); @@ -62,11 +63,8 @@ if ($request->isPost()) { $err->add($i18n->get('error.range_locked')); if ($err->no()) { - // Delete the record. - $result = ttTimeHelper::delete($cl_id, $user->getUser()); - - if ($result) { + if (ttTimeHelper::delete($cl_id, $user_id)) { header('Location: time.php'); exit(); } else { diff --git a/time_edit.php b/time_edit.php index 99110096..5670f193 100644 --- a/time_edit.php +++ b/time_edit.php @@ -40,7 +40,8 @@ if (!(ttAccessAllowed('track_own_time') || ttAccessAllowed('track_time'))) { exit(); } $cl_id = (int)$request->getParameter('id'); -$time_rec = ttTimeHelper::getRecord($cl_id, $user->getUser()); +$user_id = $user->getUser(); +$time_rec = ttTimeHelper::getRecord($cl_id, $user_id); if (!$time_rec || $time_rec['invoice_id']) { // Prohibit editing not ours or invoiced records. header('Location: access_denied.php'); @@ -285,7 +286,7 @@ if ($request->isPost()) { // 3) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists. $uncompleted = ($cl_finish == '' && $cl_duration == ''); if ($uncompleted) { - $not_completed_rec = ttTimeHelper::getUncompleted($user->getUser()); + $not_completed_rec = ttTimeHelper::getUncompleted($user_id); if ($not_completed_rec && ($time_rec['id'] <> $not_completed_rec['id'])) { // We have another not completed record. $err->add($i18n->get('error.uncompleted_exists')." ".$i18n->get('error.goto_uncompleted').""); @@ -295,7 +296,7 @@ if ($request->isPost()) { // Prohibit creating an overlapping record. if ($err->no()) { - if (ttTimeHelper::overlaps($user->getUser(), $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish, $cl_id)) + if (ttTimeHelper::overlaps($user_id, $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish, $cl_id)) $err->add($i18n->get('error.overlap')); } @@ -304,7 +305,7 @@ if ($request->isPost()) { $res = ttTimeHelper::update(array( 'id'=>$cl_id, 'date'=>$new_date->toString(DB_DATEFORMAT), - 'user_id'=>$user->getUser(), + 'user_id'=>$user_id, 'client'=>$cl_client, 'project'=>$cl_project, 'task'=>$cl_task, @@ -345,7 +346,7 @@ if ($request->isPost()) { // 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists. $uncompleted = ($cl_finish == '' && $cl_duration == ''); if ($uncompleted) { - $not_completed_rec = ttTimeHelper::getUncompleted($user->getUser()); + $not_completed_rec = ttTimeHelper::getUncompleted($user_id); if ($not_completed_rec) { // We have another not completed record. $err->add($i18n->get('error.uncompleted_exists')." ".$i18n->get('error.goto_uncompleted').""); @@ -355,7 +356,7 @@ if ($request->isPost()) { // Prohibit creating an overlapping record. if ($err->no()) { - if (ttTimeHelper::overlaps($user->getUser(), $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish)) + if (ttTimeHelper::overlaps($user_id, $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish)) $err->add($i18n->get('error.overlap')); } @@ -364,7 +365,7 @@ if ($request->isPost()) { $id = ttTimeHelper::insert(array( 'date'=>$new_date->toString(DB_DATEFORMAT), - 'user_id'=>$user->getUser(), + 'user_id'=>$user_id, 'group_id'=>$user->getGroup(), 'org_id' => $user->org_id, 'client'=>$cl_client, -- 2.20.1