Some improvements to confirm save feature.
authorNik Okuntseff <support@anuko.com>
Fri, 30 Nov 2018 21:27:42 +0000 (21:27 +0000)
committerNik Okuntseff <support@anuko.com>
Fri, 30 Nov 2018 21:27:42 +0000 (21:27 +0000)
WEB-INF/lib/ttUser.class.php
WEB-INF/templates/expense_edit.tpl
WEB-INF/templates/footer.tpl
WEB-INF/templates/mobile/expense_edit.tpl
WEB-INF/templates/mobile/time_edit.tpl
WEB-INF/templates/time_edit.tpl
expense_edit.php
mobile/expense_edit.php
mobile/time_edit.php
time_edit.php

index 8b98caa..692d80e 100644 (file)
@@ -202,6 +202,12 @@ class ttUser {
     return ($this->behalfGroup ? $this->behalfGroup->config : $this->config);
   }
 
+  // getConfirmSave returns confirm_save option for user.
+  function getConfirmSave() {
+    return true; // TODO: implement this properly.
+    // return ($this->behalfGroup ? $this->behalfGroup->config : $this->config);
+  }
+
   // can - determines whether user has a right to do something.
   function can($do_something) {
     return in_array($do_something, $this->rights);
index 9e447a3..d3a2737 100644 (file)
@@ -34,8 +34,8 @@ var defined_expenses = new Array();
   idx++;
 {/foreach}
 
-// TODO: improve on conditional confirmSave.
-// Existing entry date for confirm save warnings.
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
 var original_date = "{$entry_date}";
 
 function confirmSave() {
@@ -44,7 +44,7 @@ function confirmSave() {
     return confirm("{$i18n.warn.confirm_save}");
   }
 }
-// TODO: improve on conditional confirmSave above.
+{/if}
 
 // The fillProjectDropdown function populates the project combo box with
 // projects associated with a selected client (client id is passed here as id).
index b54e881..9d88e93 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.18.28.4551 | Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.18.28.4552 | 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 ea29723..9714050 100644 (file)
@@ -34,6 +34,18 @@ var defined_expenses = new Array();
   idx++;
 {/foreach}
 
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
+var original_date = "{$entry_date}";
+
+function confirmSave() {
+  var date_on_save = document.getElementById("date").value;
+  if (original_date != date_on_save) {
+    return confirm("{$i18n.warn.confirm_save}");
+  }
+}
+{/if}
+
 // The fillProjectDropdown function populates the project combo box with
 // projects associated with a selected client (client id is passed here as id).
 function fillProjectDropdown(id) {
index 8c6a141..79c5c03 100644 (file)
@@ -1,5 +1,19 @@
 {include file="time_script.tpl"}
 
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
+<script>
+var original_date = "{$entry_date}";
+
+function confirmSave() {
+  var date_on_save = document.getElementById("date").value;
+  if (original_date != date_on_save) {
+    return confirm("{$i18n.warn.confirm_save}");
+  }
+}
+</script>
+{/if}
+
 {$forms.timeRecordForm.open}
 <table cellspacing="4" cellpadding="7" border="0">
 <tr>
@@ -41,7 +55,7 @@
     <tr><td>{$forms.timeRecordForm.date.control}</td></tr>
     <tr><td>{$i18n.label.note}:</td></tr>
     <tr><td>{$forms.timeRecordForm.note.control}</td></tr>
-    <tr><td align="center">{$forms.timeRecordForm.btn_save.control}&nbsp;{$forms.timeRecordForm.btn_delete.control}</td></tr>
+    <tr><td align="center">{$forms.timeRecordForm.btn_save.control} {$forms.timeRecordForm.btn_copy.control} {$forms.timeRecordForm.btn_delete.control}</td></tr>
     </table>
     </td>
     </tr>
index f6f4693..bc563e9 100644 (file)
@@ -1,8 +1,8 @@
 {include file="time_script.tpl"}
 
+{* Conditional include of confirmSave handler. *}
+{if $confirm_save}
 <script>
-// TODO: improve on conditional confirmSave.
-// Existing entry date for confirm save warnings.
 var original_date = "{$entry_date}";
 
 function confirmSave() {
@@ -11,8 +11,8 @@ function confirmSave() {
     return confirm("{$i18n.warn.confirm_save}");
   }
 }
-// TODO: improve on conditional confirmSave above.
 </script>
+{/if}
 
 {$forms.timeRecordForm.open}
 <table cellspacing="4" cellpadding="7" border="0">
index cca8225..a4bb6a4 100644 (file)
@@ -51,6 +51,7 @@ if (!$expense_item || $expense_item['invoice_id']) {
 }
 
 $item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']);
+$confirm_save = $user->getConfirmSave();
 
 // Initialize variables.
 $cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null;
@@ -147,9 +148,10 @@ $form->addInput(array('type'=>'datefield','name'=>'date','maxlength'=>'20','valu
 // Hidden control for record id.
 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
-// TODO: improve on conditional confirmSave.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date();return(confirmSave())','value'=>$i18n->get('button.save')));
-$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
 $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
 
 if ($request->isPost()) {
@@ -221,9 +223,10 @@ if ($request->isPost()) {
   }
 } // isPost
 
-// TODO: improve on conditional confirmSave.
-$smarty->assign('entry_date', $cl_date);
-
+if ($confirm_save) {
+  $smarty->assign('confirm_save', true);
+  $smarty->assign('entry_date', $cl_date);
+}
 $smarty->assign('predefined_expenses', $predefined_expenses);
 $smarty->assign('client_list', $client_list);
 $smarty->assign('project_list', $project_list);
index a039f42..9cae018 100644 (file)
@@ -51,6 +51,7 @@ if (!$expense_item || $expense_item['invoice_id']) {
 }
 
 $item_date = new DateAndTime(DB_DATEFORMAT, $expense_item['date']);
+$confirm_save = $user->getConfirmSave();
 
 // Initialize variables.
 $cl_date = $cl_client = $cl_project = $cl_item_name = $cl_cost = null;
@@ -142,8 +143,10 @@ $form->addInput(array('type'=>'datefield','name'=>'date','maxlength'=>'20','valu
 // Hidden control for record id.
 $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.save')));
-$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
 $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
 
 if ($request->isPost()) {
@@ -215,6 +218,10 @@ if ($request->isPost()) {
   }
 } // isPost
 
+if ($confirm_save) {
+  $smarty->assign('confirm_save', true);
+  $smarty->assign('entry_date', $cl_date);
+}
 $smarty->assign('predefined_expenses', $predefined_expenses);
 $smarty->assign('client_list', $client_list);
 $smarty->assign('project_list', $project_list);
index b2655e8..3094df6 100644 (file)
@@ -57,6 +57,7 @@ if ($user->isPluginEnabled('cf')) {
 }
 
 $item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']);
+$confirm_save = $user->getConfirmSave();
 
 // Initialize variables.
 $cl_start = $cl_finish = $cl_duration = $cl_date = $cl_note = $cl_project = $cl_task = $cl_billable = null;
@@ -205,7 +206,10 @@ $form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_id));
 if ($user->isPluginEnabled('iv'))
   $form->addInput(array('type'=>'checkbox','name'=>'billable','value'=>$cl_billable));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save click.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.save')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
 $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
 
 if ($request->isPost()) {
@@ -324,12 +328,79 @@ if ($request->isPost()) {
     }
   }
 
+  // Save as new record.
+  if ($request->getParameter('btn_copy')) {
+    // We need to:
+    // 1) Prohibit saving into locked range.
+    // 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists.
+
+    // Now, step by step.
+    if ($err->no()) {
+      // 1) Prohibit saving into locked range.
+      if ($user->isDateLocked($new_date))
+        $err->add($i18n->get('error.range_locked'));
+
+      // 2) Prohibit saving uncompleted unlocked entries when another uncompleted entry exists.
+      $uncompleted = ($cl_finish == '' && $cl_duration == '');
+      if ($uncompleted) {
+        $not_completed_rec = ttTimeHelper::getUncompleted($user_id);
+        if ($not_completed_rec) {
+          // We have another not completed record.
+          $err->add($i18n->get('error.uncompleted_exists')." <a href = 'time_edit.php?id=".$not_completed_rec['id']."'>".$i18n->get('error.goto_uncompleted')."</a>");
+        }
+      }
+    }
+
+    // Prohibit creating an overlapping record.
+    if ($err->no()) {
+      if (ttTimeHelper::overlaps($user_id, $new_date->toString(DB_DATEFORMAT), $cl_start, $cl_finish))
+        $err->add($i18n->get('error.overlap'));
+    }
+
+    // Now, a new insert.
+    if ($err->no()) {
+
+      $id = ttTimeHelper::insert(array(
+        'date'=>$new_date->toString(DB_DATEFORMAT),
+        'user_id'=>$user_id,
+        'group_id'=>$user->getGroup(),
+        'org_id' => $user->org_id,
+        'client'=>$cl_client,
+        'project'=>$cl_project,
+        'task'=>$cl_task,
+        'start'=>$cl_start,
+        'finish'=>$cl_finish,
+        'duration'=>$cl_duration,
+        'note'=>$cl_note,
+        'billable'=>$cl_billable,
+        'paid'=>$cl_paid));
+
+      // Insert a custom field if we have it.
+      $res = true;
+      if ($id && $custom_fields && $cl_cf_1) {
+        if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT)
+          $res = $custom_fields->insert($id, $custom_fields->fields[0]['id'], null, $cl_cf_1);
+        elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)
+          $res = $custom_fields->insert($id, $custom_fields->fields[0]['id'], $cl_cf_1, null);
+      }
+      if ($id && $res) {
+        header('Location: time.php?date='.$new_date->toString(DB_DATEFORMAT));
+        exit();
+      }
+      $err->add($i18n->get('error.db'));
+    }
+  }
+
   if ($request->getParameter('btn_delete')) {
     header("Location: time_delete.php?id=$cl_id");
     exit();
   }
 } // isPost
 
+if ($confirm_save) {
+  $smarty->assign('confirm_save', true);
+  $smarty->assign('entry_date', $cl_date);
+}
 $smarty->assign('client_list', $client_list);
 $smarty->assign('project_list', $project_list);
 $smarty->assign('task_list', $task_list);
index 17ba34b..5dd958b 100644 (file)
@@ -57,6 +57,7 @@ if ($user->isPluginEnabled('cf')) {
 }
 
 $item_date = new DateAndTime(DB_DATEFORMAT, $time_rec['date']);
+$confirm_save = $user->getConfirmSave();
 
 // Initialize variables.
 $cl_start = $cl_finish = $cl_duration = $cl_date = $cl_note = $cl_project = $cl_task = $cl_billable = null;
@@ -210,9 +211,10 @@ if ($user->isPluginEnabled('iv'))
 if ($user->can('manage_invoices') && $user->isPluginEnabled('ps'))
   $form->addInput(array('type'=>'checkbox','name'=>'paid','value'=>$cl_paid));
 $form->addInput(array('type'=>'hidden','name'=>'browser_today','value'=>'')); // User current date, which gets filled in on btn_save or btn_copy click.
-// TODO: improve on conditional confirmSave.
-$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>'browser_today.value=get_date();return(confirmSave())','value'=>$i18n->get('button.save')));
-$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>'browser_today.value=get_date()','value'=>$i18n->get('button.copy')));
+$on_click_action = 'browser_today.value=get_date();';
+$form->addInput(array('type'=>'submit','name'=>'btn_copy','onclick'=>$on_click_action,'value'=>$i18n->get('button.copy')));
+if ($confirm_save) $on_click_action .= 'return(confirmSave());';
+$form->addInput(array('type'=>'submit','name'=>'btn_save','onclick'=>$on_click_action,'value'=>$i18n->get('button.save')));
 $form->addInput(array('type'=>'submit','name'=>'btn_delete','value'=>$i18n->get('label.delete')));
 
 if ($request->isPost()) {
@@ -401,9 +403,10 @@ if ($request->isPost()) {
   }
 } // isPost
 
-// TODO: improve on conditional confirmSave.
-$smarty->assign('entry_date', $cl_date);
-
+if ($confirm_save) {
+  $smarty->assign('confirm_save', true);
+  $smarty->assign('entry_date', $cl_date);
+}
 $smarty->assign('client_list', $client_list);
 $smarty->assign('project_list', $project_list);
 $smarty->assign('task_list', $task_list);