From ec382daafde770e5a7fd4bf9cee39f31c9931eff Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Fri, 2 Feb 2018 21:43:48 +0000 Subject: [PATCH] Implemented saving of week config settings. --- WEB-INF/lib/ttTeamHelper.class.php | 26 ++++++++++++ WEB-INF/resources/en.lang.php | 2 + WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/week_view.tpl | 52 ++++++------------------ week_view.php | 64 +++++++----------------------- 5 files changed, 56 insertions(+), 90 deletions(-) diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index e54aa9bf..d607ca1b 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -1024,4 +1024,30 @@ class ttTeamHelper { return true; } + + // enablePlugin either enables or disables a specific plugin for team. + function enablePlugin($plugin, $enable = true) + { + global $user; + if (!$user->canManageTeam()) + return false; + + $plugin_array = explode(',', $user->plugins); + if ($enable && !in_array($plugin, $plugin_array)) + $plugin_array[] = $plugin; // Add plugin to array. + + if (!$enable && in_array($plugin, $plugin_array)) { + $key = array_search($plugin, $plugin_array); + if ($key !== false) + unset($plugin_array[$key]); // Remove plugin from array. + } + + $plugins = implode(',', $plugin_array); + if ($plugins != $user->plugins) { + return ttTeamHelper::update($user->team_id, array( + 'name' => $user->team, + 'plugins' => $plugins)); + } + return true; + } } diff --git a/WEB-INF/resources/en.lang.php b/WEB-INF/resources/en.lang.php index f8bf112d..b8d30f3e 100644 --- a/WEB-INF/resources/en.lang.php +++ b/WEB-INF/resources/en.lang.php @@ -210,6 +210,8 @@ $i18n_key_words = array( 'label.paid_status' => 'Paid status', 'label.paid' => 'Paid', 'label.mark_paid' => 'Mark paid', +'label.week_note' => 'Week note', +'label.week_list' => 'Week list', // Form titles. 'title.login' => 'Login', diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index f6ce15c6..4022e582 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.17.10.3864 | Copyright © Anuko | +  Anuko Time Tracker 1.17.10.3865 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/week_view.tpl b/WEB-INF/templates/week_view.tpl index 5375a323..9cb14f3d 100644 --- a/WEB-INF/templates/week_view.tpl +++ b/WEB-INF/templates/week_view.tpl @@ -1,45 +1,19 @@ - - -
{$i18n.form.quota.hint}
+{$forms.weekViewForm.open} + + + + + + + + + -{$forms.monthlyQuotasForm.open} -
-
{$forms.weekViewForm.week_note.control} {$i18n.label.what_is_it}
{$forms.weekViewForm.week_list.control} {$i18n.label.what_is_it}
- - - -
- - - - - -
{$i18n.form.quota.workday_hours}:{$forms.monthlyQuotasForm.workdayHours.control}
-
- - - - + - - +
{$i18n.form.quota.year}:{$forms.monthlyQuotasForm.year.control} 
 
- - - - - -{foreach $months as $month} - - - - -{/foreach} - - -
{$i18n.form.quota.month}{$i18n.form.quota.quota}
{$month}:{$forms.monthlyQuotasForm.$month.control}
 
-
{$forms.weekViewForm.btn_save.control}
-{$forms.monthlyQuotasForm.close} +{$forms.weekViewForm.close} diff --git a/week_view.php b/week_view.php index 319235b4..8ca350f0 100644 --- a/week_view.php +++ b/week_view.php @@ -38,65 +38,29 @@ if (!ttAccessCheck(right_manage_team) || !$user->isPluginEnabled('wv')) { exit(); } - -// Get selected year from url parameter. -$selectedYear = $request->getParameter('year'); -if (!$selectedYear or !ttValidInteger($selectedYear)){ - $selectedYear = date('Y'); +if ($request->isPost()) { + $cl_week_note = $request->getParameter('week_note'); + $cl_week_list = $request->getParameter('week_list'); } else { - $selectedYear = (int) $selectedYear; + $plugins = explode(',', $user->plugins); + $cl_week_note = in_array('wn', $plugins); + $cl_week_list = in_array('wl', $plugins); } -// Months are zero indexed. -$months = $i18n->monthNames; -$quota = new MonthlyQuota(); +$form = new Form('weekViewForm'); +$form->addInput(array('type'=>'checkbox','name'=>'week_note','value'=>$cl_week_note)); +$form->addInput(array('type'=>'checkbox','name'=>'week_list','value'=>$cl_week_list)); +$form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->getKey('button.save'))); if ($request->isPost()){ - // Validate user input. - if (!ttTimeHelper::isValidDuration($request->getParameter('workdayHours'))) - $err->add($i18n->getKey('error.field'), $i18n->getKey('form.quota.workday_hours')); - - for ($i = 0; $i < count($months); $i++){ - $val = $request->getParameter($months[$i]); - if (!$quota->isValidQuota($val)) - $err->add($i18n->getKey('error.field'), $months[$i]); - } - // Finished validating user input. - - if ($err->no()) { - - // Handle workday hours. - $hours = $quota->quotaToFloat($request->getParameter('workdayHours')); - if ($hours != $user->workday_hours) { - if (!ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours))) - $err->add($i18n->getKey('error.db')); - } - - // Handle monthly quotas for a selected year. - $selectedYear = (int) $request->getParameter('year'); - for ($i = 0; $i < count($months); $i++){ - if (!$quota->update($selectedYear, $i+1, $request->getParameter($months[$i]))) - $err->add($i18n->getKey('error.db')); - } - - if ($err->no()) { - // Redisplay the form. - header('Location: quotas.php?year='.$selectedYear); - exit(); - } + if (!ttTeamHelper::enablePlugin('wn', $cl_week_note) || + !ttTeamHelper::enablePlugin('wl', $cl_week_list)) { + $err->add($i18n->getKey('error.db')); } } -// Get monthly quotas for the entire year. -$monthsData = $quota->get($selectedYear); -$workdayHours = ttTimeHelper::toAbsDuration($user->workday_hours * 60, true); - -$form = new Form('weekViewForm'); -$form->addInput(array('type'=>'checkbox','name'=>'week_note','value'=>$cl_week_note)); -$form->addInput(array('type'=>'checkbox','name'=>'week_list','value'=>$cl_week_list)); - $smarty->assign('forms', array($form->getName()=>$form->toArray())); -$smarty->assign('title', $i18n->getKey('label.week_view')); +$smarty->assign('title', $i18n->getKey('title.week_view')); $smarty->assign('content_page_name', 'week_view.tpl'); $smarty->display('index.tpl'); -- 2.20.1