Inserting new cells from already existing week view rows should now work with custom...
authoranuko <support@anuko.com>
Thu, 28 Dec 2017 23:05:57 +0000 (23:05 +0000)
committeranuko <support@anuko.com>
Thu, 28 Dec 2017 23:05:57 +0000 (23:05 +0000)
WEB-INF/lib/ttTimeHelper.class.php
WEB-INF/templates/footer.tpl
week.php

index c88ed6a..81a5ccf 100644 (file)
@@ -977,7 +977,7 @@ class ttTimeHelper {
   }
 
   // insertDurationFromWeekView - inserts a new record in log tables from a week view post.
-  static function insertDurationFromWeekView($fields, $err) {
+  static function insertDurationFromWeekView($fields, $custom_fields, $err) {
     global $i18n;
     global $user;
 
@@ -994,13 +994,6 @@ class ttTimeHelper {
       }
     }
 
-    // Temporary check for custom field and exit if one is found, as this is not yet implemented.
-    $temp = ttTimeHelper::parseFromWeekViewRow($fields['row_id'], 'cf_1');
-    if ($temp) {
-      $err->add("Week view is work in progress. Inserting records with custom fields is not yet implemented. Try again later.");
-      return false;
-    }
-
     // Prepare an array of fields for regular insert function.
     $fields4insert = array();
     $fields4insert['user_id'] = $user->getActiveUser();
@@ -1015,15 +1008,26 @@ class ttTimeHelper {
     $id = ttTimeHelper::insert($fields4insert);
     if (!$id) return false; // Something failed.
 
-    // TODO: Deal with custom fieeld log here. Currently not implemented.
+    // Insert custom field if we have it.
+    $result = true;
+    $cf_1 = ttTimeHelper::parseFromWeekViewRow($fields['row_id'], 'cf_1');
+    if ($custom_fields && $cf_1) {
+      if ($custom_fields->fields[0]['type'] == CustomFields::TYPE_TEXT)
+        $result = $custom_fields->insert($id, $custom_fields->fields[0]['id'], null, $cf_1);
+      elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)
+        $result = $custom_fields->insert($id, $custom_fields->fields[0]['id'], $cf_1, null);
+    }
 
-    return true; // Not implemented.
+    return $result;
   }
 
 
   // modifyFromWeekView - modifies a duration of an existing record from a week view post.
   static function modifyDurationFromWeekView($fields, $err) {
-    $err->add("Week view is work in progress. Editing records is not yet implemented. Try again later.");
+
+    // Possible error conditions. Overlap? What else?
+
+    $err->add("Week view is work in progress. Editing records is not yet implemented. Try deleting and then inserting a record instead.");
     return false;
 
   // static function modifyDurationFromWeekView($tt_log_id, $new_duration, $user_id) {
index 5b00397..825f144 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.13.0.3704| Copyright &copy; <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+          <td align="center">&nbsp;Anuko Time Tracker 1.13.0.3705| 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 34efd56..7cf1c94 100644 (file)
--- a/week.php
+++ b/week.php
@@ -394,14 +394,15 @@ if ($request->isPost()) {
           $fields['start_date'] = $startDate->toString(DB_DATEFORMAT); // To be able to determine date for the entry using $dayHeader.
           $fields['duration'] = $postedDuration;
           $fields['browser_today'] = $request->getParameter('browser_today', null);
-          $result = ttTimeHelper::insertDurationFromWeekView($fields, $err);
+          $result = ttTimeHelper::insertDurationFromWeekView($fields, $custom_fields, $err);
         } elseif ($postedDuration == null || 0 == ttTimeHelper::toMinutes($postedDuration)) {
           // Delete an already existing record here.
           $result = ttTimeHelper::delete($dataArray[$rowNumber][$dayHeader]['tt_log_id'], $user->getActiveUser());
         } else {
           $fields = array();
+          $fields['tt_log_id'] = $dataArray[$rowNumber][$dayHeader]['tt_log_id'];
+          $fields['duration'] = $postedDuration;
           $result = ttTimeHelper::modifyDurationFromWeekView($fields, $err);
-          //$result = ttTimeHelper::modifyDurationFromWeekView($dataArray[$rowNumber][$dayHeader]['tt_log_id'], $postedDuration, $user->getActiveUser());
         }
         if (!$result) break; // Break out of the loop in case of first error.
       }
@@ -412,7 +413,7 @@ if ($request->isPost()) {
       header('Location: week.php'); // Normal exit.
       exit();
     }
-    $err->add($i18n->getKey('error.db'));
+    // $err->add($i18n->getKey('error.db'));
     /*
     //
     //