Implemented saving of week config settings.
authorNik Okuntseff <support@anuko.com>
Fri, 2 Feb 2018 21:43:48 +0000 (21:43 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 2 Feb 2018 21:43:48 +0000 (21:43 +0000)
WEB-INF/lib/ttTeamHelper.class.php
WEB-INF/resources/en.lang.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/week_view.tpl
week_view.php

index e54aa9b..d607ca1 100644 (file)
@@ -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;
+  }
 }
index f8bf112..b8d30f3 100644 (file)
@@ -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',
index f6ce15c..4022e58 100644 (file)
@@ -12,7 +12,7 @@
       <br>
       <table cellspacing="0" cellpadding="4" width="100%" border="0">
         <tr>
-          <td align="center">&nbsp;Anuko Time Tracker 1.17.10.3864 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.17.10.3865 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
             <a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
             <a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
             <a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
index 5375a32..9cb14f3 100644 (file)
@@ -1,45 +1,19 @@
-<table cellspacing="0" cellpadding="7" border="0" width="720">
-  <tr><td valign="top">{$i18n.form.quota.hint}</td></tr>
-</table>
+{$forms.weekViewForm.open}
+<table cellspacing="1" cellpadding="2" border="0">
+  <tr>
+    <td align="right" nowrap>{$forms.weekViewForm.week_note.control}</td>
+    <td><label for="week_note">{$i18n.label.week_note}</label> <a href="https://www.anuko.com/lp/tt_11.htm" target="_blank">{$i18n.label.what_is_it}</a></td>
+  </tr>
+  <tr>
+    <td align="right" nowrap>{$forms.weekViewForm.week_list.control}</td>
+    <td><label for="week_note">{$i18n.label.week_list}</label> <a href="https://www.anuko.com/lp/tt_12.htm" target="_blank">{$i18n.label.what_is_it}</a></td>
+  </tr>
 
-{$forms.monthlyQuotasForm.open}
-<div style="padding: 0 0 10 0">
-  <table border="0" class="divider">
-    <tr>
-      <td align="center">
-        <table>
-          <tr>
-            <td>{$i18n.form.quota.workday_hours}:</td>
-            <td>{$forms.monthlyQuotasForm.workdayHours.control}</td>
-          </tr>
-        </table>
-      </td>
-    </tr>
-  </table>
-</div>
-<table>
   <tr>
-    <td>{$i18n.form.quota.year}:</td>
-    <td>{$forms.monthlyQuotasForm.year.control}</td>
+    <td colspan="2">&nbsp;</td>
   </tr>
-  <tr><td>&nbsp;</td></tr>
   <tr>
-    <td colspan="2">
-      <table>
-        <tr>
-          <td class="tableHeaderCentered">{$i18n.form.quota.month}</td>
-          <td class="tableHeaderCentered">{$i18n.form.quota.quota}</td>
-        </tr>
-{foreach $months as $month}
-        <tr>
-          <td>{$month}:</td>
-          <td>{$forms.monthlyQuotasForm.$month.control}</td>
-        </tr>
-{/foreach}
-        <tr><td colspan="2">&nbsp;</td></tr>
-        <tr><td colspan="2" style="text-align:center;"><input type="submit" name="btn_submit" value="{$i18n.button.save}"></td></tr>
-      </table>
-    </td>
+    <td colspan="2" height="50" align="center">{$forms.weekViewForm.btn_save.control}</td>
   </tr>
 </table>
-{$forms.monthlyQuotasForm.close}
+{$forms.weekViewForm.close}
index 319235b..8ca350f 100644 (file)
@@ -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');