Refactored quotas.php and quotas.tpl.
authorNik Okuntseff <support@anuko.com>
Fri, 22 Jul 2016 18:22:13 +0000 (18:22 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 22 Jul 2016 18:22:13 +0000 (18:22 +0000)
WEB-INF/templates/footer.tpl
WEB-INF/templates/quotas.tpl
quotas.php

index bb00543..adadd9b 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.9.27.3515 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.9.27.3516 | 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 eebeea5..94e598d 100644 (file)
@@ -2,7 +2,7 @@
   <tr><td valign="top">{$i18n.form.quota.hint}</td></tr>
 </table>
 
-{$forms.monthlyQuotaForm.open}
+{$forms.monthlyQuotasForm.open}
 <div style="padding: 0 0 10 0">
   <table border="0" class="divider">
     <tr>
@@ -10,8 +10,8 @@
         <table>
           <tr>
             <td>{$i18n.form.quota.workdayHours}:</td>
-            <td>{$forms.monthlyQuotaForm.dailyWorkingHours.control}</td>
-            <td><input type="submit" name="dailyHours" value="{$i18n.button.save}"></td>
+            <td>{$forms.monthlyQuotasForm.workdayHours.control}</td>
+            <td><input type="submit" name="btn_hours" value="{$i18n.button.save}"></td>
           </tr>
         </table>
       </td>
@@ -21,7 +21,7 @@
 <table>
   <tr>
     <td>{$i18n.form.quota.year}:</td>
-    <td>{$forms.monthlyQuotaForm.years.control}</td>
+    <td>{$forms.monthlyQuotasForm.year.control}</td>
   </tr>
   <tr><td>&nbsp;</td></tr>
   <tr>
 {foreach $months as $month}
         <tr>
           <td>{$month}:</td>
-          <td>{$forms.monthlyQuotaForm.$month.control}</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="quotas" value="{$i18n.button.save}"></td></tr>
+        <tr><td colspan="2" style="text-align:center;"><input type="submit" name="btn_submit" value="{$i18n.button.save}"></td></tr>
       </table>
     </td>
   </tr>
 </table>
-{$forms.monthlyQuotaForm.close}
+{$forms.monthlyQuotasForm.close}
 
 <script>
 function yearChange(value){
-    var url = window.location.href;
+  var url = window.location.href;
 
-    if (url.indexOf('?') > 0){
-        var parameter = url.substring(url.indexOf('?') + 1, url.length);
-        url = url.replace(parameter, 'year=' + value);
-    } else {
-        url = '?year=' + value;
-    }
+  if (url.indexOf('?') > 0){
+    var parameter = url.substring(url.indexOf('?') + 1, url.length);
+    url = url.replace(parameter, 'year=' + value);
+  } else {
+    url = '?year=' + value;
+  }
 
-    window.location = url;
+  window.location = url;
 }
 </script>
index edf064e..83107ad 100644 (file)
@@ -37,11 +37,11 @@ if (!ttAccessCheck(right_manage_team)) {
   exit();
 }
 
-// Fallback values for start and end year.
+// Start and end fallback values for the Year dropdown.
 $yearStart = 2015;
 $yearEnd = 2030;
 
-// If values are defined in config - get them.
+// If values are defined in config - use them.
 if (defined('MONTHLY_QUOTA_YEAR_START')){
   $yearStart = (int)MONTHLY_QUOTA_YEAR_START;
 }
@@ -49,7 +49,7 @@ if (defined('MONTHLY_QUOTA_YEAR_END')){
   $yearEnd = (int)MONTHLY_QUOTA_YEAR_END;
 }
 
-// Create values for year dropdown.
+// Create values for the Year dropdown.
 $years = array();
 for ($i = $yearStart; $i <= $yearEnd; $i++) {
   array_push($years, array('id'=>$i,'name'=>$i));
@@ -69,22 +69,22 @@ $months = $i18n->monthNames;
 $quota = new MonthlyQuota();
 
 if ($request->isPost()){
+  // TODO: Add parameter validation.
   $res = false;
-  if ($_POST["quotas"]){
+  if ($_POST['btn_hours']){
+
+    // User changed workday hours for team.
+    $hours = (int)$request->getParameter('workdayHours');
+    $res = ttTeamHelper::update($user->team_id, array('name'=>$user->team,'workday_hours'=>$hours));
+  }
+  if ($_POST['btn_submit']){
     // User pressed the Save button under monthly quotas table.
-    $postedYear = $request->getParameter('years');
+    $postedYear = $request->getParameter('year');
     $selectedYear = intval($postedYear);
     for ($i = 0; $i < count($months); $i++){
       $res = $quota->update($postedYear, $i+1, $request->getParameter($months[$i]));
     }
   }
-  // if user saved required working hours for a day
-  if ($_POST["dailyHours"]){
-    $hours = $request->getParameter("dailyWorkingHours");
-    $teamDetails = ttTeamHelper::getTeamDetails($quota->usersTeamId);
-    $res = ttTeamHelper::update($quota->usersTeamId, array('name'=>$teamDetails['team_name'], 
-                                                           'workday_hours'=>$hours));
-  }
   if ($res) {
     header('Location: profile_edit.php');
     exit();
@@ -93,21 +93,21 @@ if ($request->isPost()){
   }
 }
 
-// returns months where January is month 1, not 0
+// Returns monthly quotas where January is month 1, not 0.
 $monthsData = $quota->get($selectedYear);
 
-$form = new Form('monthlyQuotaForm');
-
-$form->addInput(array('type'=>'combobox', 'name'=>'years', 'data'=>$years, 'datakeys'=>array('id', 'name'), 'value'=>$selectedYear, 'onchange'=>'yearChange(this.value);'));
+$form = new Form('monthlyQuotasForm');
+$form->addInput(array('type'=>'text', 'name'=>'workdayHours', 'value'=>$quota->getDailyWorkingHours(), 'style'=>'width:50px'));
+$form->addInput(array('type'=>'combobox','name'=>'year','data'=>$years,'datakeys'=>array('id','name'),'value'=>$selectedYear,'onchange'=>'yearChange(this.value);'));
 for ($i=0; $i < count($months); $i++) { 
   $value = "";
   if (array_key_exists($i+1, $monthsData)){
     $value = $monthsData[$i+1];
   }
   $name = $months[$i];
-  $form->addInput(array('type'=>'text', 'name'=>$name, 'maxlength'=>3, 'value'=> $value, 'style'=>'width:50px'));
+  $form->addInput(array('type'=>'text','name'=>$name,'maxlength'=>3,'value'=> $value,'style'=>'width:50px'));
 }
-$form->addInput(array('type'=>'text', 'name'=>'dailyWorkingHours', 'value'=>$quota->getDailyWorkingHours(), 'style'=>'width:50px'));
+
 $smarty->assign('months', $months);
 $smarty->assign('forms', array($form->getName()=>$form->toArray()));
 $smarty->assign('title', $i18n->getKey('title.monthly_quotas'));