Skip to content

Commit 801da0e

Browse files
committed
Work in progress on project attachments.
1 parent 26dd562 commit 801da0e

3 files changed

Lines changed: 116 additions & 81 deletions

File tree

WEB-INF/lib/ttFileHelper.class.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
// +----------------------------------------------------------------------+
3+
// | Anuko Time Tracker
4+
// +----------------------------------------------------------------------+
5+
// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6+
// +----------------------------------------------------------------------+
7+
// | LIBERAL FREEWARE LICENSE: This source code document may be used
8+
// | by anyone for any purpose, and freely redistributed alone or in
9+
// | combination with other software, provided that the license is obeyed.
10+
// |
11+
// | There are only two ways to violate the license:
12+
// |
13+
// | 1. To redistribute this code in source form, with the copyright
14+
// | notice or license removed or altered. (Distributing in compiled
15+
// | forms without embedded copyright notices is permitted).
16+
// |
17+
// | 2. To redistribute modified versions of this code in *any* form
18+
// | that bears insufficient indications that the modifications are
19+
// | not the work of the original author(s).
20+
// |
21+
// | This license applies to this document only, not any other software
22+
// | that it may be combined with.
23+
// |
24+
// +----------------------------------------------------------------------+
25+
// | Contributors:
26+
// | https://www.anuko.com/time_tracker/credits.htm
27+
// +----------------------------------------------------------------------+
28+
29+
// ttFileHelper class is used for attachment handling.
30+
class ttFileHelper {
31+
var $errors = null; // Errors go here. Set in constructor by reference.
32+
33+
// Constructor.
34+
function __construct(&$errors) {
35+
$this->errors = &$errors;
36+
}
37+
38+
// putFile - puts uploaded file in storage.
39+
function putFile() {
40+
41+
unlink($_FILES['newfile']['tmp_name']);
42+
return false; // Not implemented.
43+
/*
44+
// Create a temporary file.
45+
$dirName = dirname(TEMPLATE_DIR . '_c/.');
46+
$filename = tempnam($dirName, 'import_');
47+
48+
// If the file is compressed - uncompress it.
49+
if ($compressed) {
50+
if (!$this->uncompress($_FILES['xmlfile']['tmp_name'], $filename)) {
51+
$this->errors->add($i18n->get('error.sys'));
52+
return;
53+
}
54+
unlink($_FILES['newfile']['tmp_name']);
55+
} else {
56+
if (!move_uploaded_file($_FILES['xmlfile']['tmp_name'], $filename)) {
57+
$this->errors->add($i18n->get('error.upload'));
58+
return;
59+
}
60+
}*/
61+
}
62+
}
Lines changed: 26 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,47 @@
1-
<script>
2-
function chLocation(newLocation) { document.location = newLocation; }
3-
</script>
4-
51
<table cellspacing="0" cellpadding="7" border="0" width="720">
62
<tr>
73
<td valign="top">
8-
{if $user->can('manage_projects')}
94
<table cellspacing="1" cellpadding="3" border="0" width="100%">
10-
{if $inactive_projects}
11-
<tr><td class="sectionHeaderNoBorder">{$i18n.form.projects.active_projects}</td></tr>
12-
{/if}
135
<tr>
146
<td width="35%" class="tableHeader">{$i18n.label.image}</td>
157
<td width="35%" class="tableHeader">{$i18n.label.description}</td>
16-
{if $show_files}
17-
<td class="tableHeader">{$i18n.label.files}</td>
18-
{/if}
8+
{if $can_manage}
199
<td class="tableHeader">{$i18n.label.edit}</td>
2010
<td class="tableHeader">{$i18n.label.delete}</td>
11+
{/if}
2112
</tr>
22-
{if $active_projects}
23-
{foreach $active_projects as $project}
13+
{if $files}
14+
{foreach $files as $file}
2415
<tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
25-
<td>{$project.name|escape}</td>
26-
<td>{$project.description|escape}</td>
27-
{if $show_files}
28-
<td><a href="project_files.php?id={$project.id}">{$i18n.label.view}</a></td>
29-
{/if}
30-
<td><a href="project_edit.php?id={$project.id}">{$i18n.label.edit}</a></td>
31-
<td><a href="project_delete.php?id={$project.id}">{$i18n.label.delete}</a></td>
32-
</tr>
33-
{/foreach}
34-
{/if}
35-
</table>
36-
37-
<table width="100%">
38-
<tr>
39-
<td align="center"><br>
40-
<form><input type="button" onclick="chLocation('project_add.php');" value="{$i18n.button.add}"></form>
41-
</td>
42-
</tr>
43-
</table>
44-
45-
{if $inactive_projects}
46-
<table cellspacing="1" cellpadding="3" border="0" width="100%">
47-
<tr><td class="sectionHeaderNoBorder">{$i18n.form.projects.inactive_projects}</td></tr>
48-
<tr>
49-
<td width="35%" class="tableHeader">{$i18n.label.thing_name}</td>
50-
<td width="35%" class="tableHeader">{$i18n.label.description}</td>
51-
{if $show_files}
52-
<td class="tableHeader">{$i18n.label.files}</td>
16+
<td>{$file.name|escape}</td>
17+
<td>{$file.description|escape}</td>
18+
{if $can_manage}
19+
<td><a href="file_edit.php?id={$file.id}">{$i18n.label.edit}</a></td>
20+
<td><a href="file_delete.php?id={$file.id}">{$i18n.label.delete}</a></td>
5321
{/if}
54-
<td class="tableHeader">{$i18n.label.edit}</td>
55-
<td class="tableHeader">{$i18n.label.delete}</td>
56-
</tr>
57-
{foreach $inactive_projects as $project}
58-
<tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
59-
<td>{$project.name|escape}</td>
60-
<td>{$project.description|escape}</td>
61-
{if $show_files}
62-
<td><a href="project_files.php?id={$project.id}">{$i18n.label.view}</a></td>
63-
{/if}
64-
<td><a href="project_edit.php?id={$project.id}">{$i18n.label.edit}</a></td>
65-
<td><a href="project_delete.php?id={$project.id}">{$i18n.label.delete}</a></td>
6622
</tr>
67-
{/foreach}
23+
{/foreach}
24+
{/if}
6825
</table>
26+
</td>
27+
</tr>
28+
</table>
6929

70-
<table width="100%">
71-
<tr>
72-
<td align="center"><br>
73-
<form><input type="button" onclick="chLocation('project_add.php');" value="{$i18n.button.add}"></form>
74-
</td>
75-
</tr>
76-
</table>
77-
{/if}
78-
{else}
79-
<table cellspacing="1" cellpadding="3" border="0" width="100%">
30+
{if $can_manage}
31+
{$forms.fileUploadForm.open}
32+
<table cellspacing="0" cellpadding="7" border="0" width="720">
33+
<tr>
34+
<td align="center">
35+
<table border="0" width="60%">
8036
<tr>
81-
<td class="tableHeader">{$i18n.label.thing_name}</td>
82-
<td class="tableHeader">{$i18n.label.description}</td>
83-
{if $show_files}
84-
<td class="tableHeader">{$i18n.label.files}</td>
85-
{/if}
37+
<td align="right">{$i18n.label.description}:</td>
38+
<td>{$forms.fileUploadForm.description.control}</td>
39+
<td align="left">{$forms.fileUploadForm.newfile.control}</td>
8640
</tr>
87-
{if $active_projects}
88-
{foreach $active_projects as $project}
89-
<tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
90-
<td>{$project.name|escape}</td>
91-
<td>{$project.description|escape}</td>
92-
{if $show_files}
93-
<td><a href="project_files.php?id={$project.id}">{$i18n.label.view}</a></td>
94-
{/if}
95-
</tr>
96-
{/foreach}
97-
{/if}
41+
<tr><td height="50" align="center" colspan="3">{$forms.fileUploadForm.btn_submit.control}</td></tr>
9842
</table>
99-
{/if}
10043
</td>
10144
</tr>
10245
</table>
46+
{$forms.fileUploadForm.close}
47+
{/if}

project_files.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
// +----------------------------------------------------------------------+
2828

2929
require_once('initialize.php');
30+
import('form.Form');
3031
import('ttProjectHelper');
32+
import('ttFileHelper');
3133

3234
// Access checks.
3335
if (!(ttAccessAllowed('view_own_projects') || ttAccessAllowed('manage_projects'))) {
@@ -46,9 +48,35 @@
4648
}
4749
// End of access checks.
4850

51+
if ($request->isPost()) {
52+
$cl_description = trim($request->getParameter('description'));
53+
}
54+
4955
$files = null;
5056
// $files = ttAttachmentHelper::getProjectFiles();
5157

58+
$form = new Form('fileUploadForm');
59+
$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_project_id));
60+
$form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit'),'maxsize'=>67108864)); // 64 MB file upload limit.
61+
// Note: for the above limit to work make sure to set upload_max_filesize and post_max_size in php.ini to at least 64M.
62+
$form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
63+
$form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.add')));
64+
65+
if ($request->isPost()) {
66+
// We are adding a new file.
67+
68+
// Validate user input.
69+
if (!$_FILES['newfile']['name']) $err->add($i18n->get('error.upload'));
70+
if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
71+
// Finished validating user input.
72+
73+
$fileHelper = new ttFileHelper($err);
74+
$fileHelper->putFile();
75+
// if ($err->no()) $msg->add($i18n->get('form.import.success'));
76+
} // isPost
77+
78+
$smarty->assign('can_manage', $user->can('manage_projects'));
79+
$smarty->assign('forms', array($form->getName()=>$form->toArray()));
5280
$smarty->assign('files', $files);
5381
$smarty->assign('title', $i18n->get('title.project_files'));
5482
$smarty->assign('content_page_name', 'project_files.tpl');

0 commit comments

Comments
 (0)