From 5c582eb5bacc8b3d9d2775ade454590c71b113ec Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Tue, 16 Apr 2019 18:30:30 +0000 Subject: [PATCH] Added capability to add an attachment to time.php on first submit. --- WEB-INF/lib/ttFileHelper.class.php | 18 ++++++++++++++++++ WEB-INF/templates/footer.tpl | 2 +- WEB-INF/templates/time.tpl | 4 ++-- time.php | 15 ++++++++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/WEB-INF/lib/ttFileHelper.class.php b/WEB-INF/lib/ttFileHelper.class.php index 45b5b237..61dd6028 100644 --- a/WEB-INF/lib/ttFileHelper.class.php +++ b/WEB-INF/lib/ttFileHelper.class.php @@ -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; diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index 0cd9a3d1..108c2b4f 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
- {/if} -{if $show_files && false} +{if $show_files} - + {/if} diff --git a/time.php b/time.php index a08e343f..7b6376c8 100644 --- 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(); } -- 2.20.1
 Anuko Time Tracker 1.18.65.4949 | Copyright © Anuko | +  Anuko Time Tracker 1.18.65.4950 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/WEB-INF/templates/time.tpl b/WEB-INF/templates/time.tpl index dd583ee3..e32140a9 100644 --- a/WEB-INF/templates/time.tpl +++ b/WEB-INF/templates/time.tpl @@ -71,9 +71,9 @@ {$forms.timeRecordForm.duration.control} {if $user->getDecimalMark() == ','}{str_replace('.', ',', $i18n.form.time.duration_format)}{else}{$i18n.form.time.duration_format}{/if}
{$i18n.label.files}:{$i18n.label.file}: {$forms.timeRecordForm.newfile.control}