// 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();
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;
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.18.65.4949 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.18.65.4950 | Copyright © <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>
<td>{$forms.timeRecordForm.duration.control} {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}
import('ttGroupHelper');
import('ttClientHelper');
import('ttTimeHelper');
+import('ttFileHelper');
import('DateAndTime');
// Access checks.
}
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));
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();
}