Added capability to add an attachment to time.php on first submit.
authorNik Okuntseff <support@anuko.com>
Tue, 16 Apr 2019 18:30:30 +0000 (18:30 +0000)
committerNik Okuntseff <support@anuko.com>
Tue, 16 Apr 2019 18:30:30 +0000 (18:30 +0000)
WEB-INF/lib/ttFileHelper.class.php
WEB-INF/templates/footer.tpl
WEB-INF/templates/time.tpl
time.php

index 45b5b23..61dd602 100644 (file)
@@ -277,6 +277,9 @@ class ttFileHelper {
   // deleteEntityFiles - deletes all files associated with an entity.
   function deleteEntityFiles($entity_id, $entity_type) {
 
+    if (!$this->entityHasFiles($entity_id, $entity_type))
+      return true; // No files to delete.
+    
     global $i18n;
     global $user;
     $mdb2 = getConnection();
@@ -349,6 +352,21 @@ class ttFileHelper {
     return true;
   }
 
+  // entityHasFiles determines if an entity has any files referenced in database.
+  private function entityHasFiles($entity_id, $entity_type) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
+    $sql = "select id from tt_files where org_id = $org_id and group_id = $group_id".
+      " and entity_type = ".$mdb2->quote($entity_type)." and entity_id = $entity_id limit 1";
+    $res = $mdb2->query($sql);
+    $val = $res->fetchRow();
+    return $val['id'] > 0;
+  }
+
   // getOrgKey obtains organization key from the database.
   private function getOrgKey() {
     global $user;
index 0cd9a3d..108c2b4 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.65.4949 | 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.65.4950 | 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 dd583ee..e32140a 100644 (file)
@@ -71,9 +71,9 @@
           <td>{$forms.timeRecordForm.duration.control}&nbsp;{if $user->getDecimalMark() == ','}{str_replace('.', ',', $i18n.form.time.duration_format)}{else}{$i18n.form.time.duration_format}{/if}</td>
         </tr>
 {/if}
-{if $show_files && false}
+{if $show_files}
         <tr>
-          <td align="right">{$i18n.label.files}:</td>
+          <td align="right">{$i18n.label.file}:</td>
           <td>{$forms.timeRecordForm.newfile.control}</td>
         </tr>
 {/if}
index a08e343..7b6376c 100644 (file)
--- a/time.php
+++ b/time.php
@@ -33,6 +33,7 @@ import('ttUserHelper');
 import('ttGroupHelper');
 import('ttClientHelper');
 import('ttTimeHelper');
+import('ttFileHelper');
 import('DateAndTime');
 
 // Access checks.
@@ -255,6 +256,8 @@ if ($showStart) {
 }
 if ($showDuration)
   $form->addInput(array('type'=>'text','name'=>'duration','value'=>$cl_duration,'onchange'=>"formDisable('duration');"));
+if ($showFiles)
+  $form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit')));
 if (!defined('NOTE_INPUT_HEIGHT'))
   define('NOTE_INPUT_HEIGHT', 40);
 $form->addInput(array('type'=>'textarea','name'=>'note','style'=>'width: 600px; height:'.NOTE_INPUT_HEIGHT.'px;','value'=>$cl_note));
@@ -390,7 +393,17 @@ if ($request->isPost()) {
         elseif ($custom_fields->fields[0]['type'] == CustomFields::TYPE_DROPDOWN)
           $result = $custom_fields->insert($id, $custom_fields->fields[0]['id'], $cl_cf_1, null);
       }
-      if ($id && $result) {
+
+      // Put a new file in storage if we have it.
+      if ($showFiles && $_FILES['newfile']['name']) {
+        $fileHelper = new ttFileHelper($err);
+        $fields = array('entity_type'=>'time',
+          'entity_id' => $id,
+          'file_name' => $_FILES['newfile']['name']);
+        $fileHelper->putFile($fields);
+      }
+
+      if ($id && $result && $err->no()) {
         header('Location: time.php');
         exit();
       }