--- /dev/null
+<?php
+// +----------------------------------------------------------------------+
+// | Anuko Time Tracker
+// +----------------------------------------------------------------------+
+// | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
+// +----------------------------------------------------------------------+
+// | LIBERAL FREEWARE LICENSE: This source code document may be used
+// | by anyone for any purpose, and freely redistributed alone or in
+// | combination with other software, provided that the license is obeyed.
+// |
+// | There are only two ways to violate the license:
+// |
+// | 1. To redistribute this code in source form, with the copyright
+// | notice or license removed or altered. (Distributing in compiled
+// | forms without embedded copyright notices is permitted).
+// |
+// | 2. To redistribute modified versions of this code in *any* form
+// | that bears insufficient indications that the modifications are
+// | not the work of the original author(s).
+// |
+// | This license applies to this document only, not any other software
+// | that it may be combined with.
+// |
+// +----------------------------------------------------------------------+
+// | Contributors:
+// | https://www.anuko.com/time_tracker/credits.htm
+// +----------------------------------------------------------------------+
+
+// ttFileHelper class is used for attachment handling.
+class ttFileHelper {
+ var $errors = null; // Errors go here. Set in constructor by reference.
+
+ // Constructor.
+ function __construct(&$errors) {
+ $this->errors = &$errors;
+ }
+
+ // putFile - puts uploaded file in storage.
+ function putFile() {
+
+ unlink($_FILES['newfile']['tmp_name']);
+ return false; // Not implemented.
+/*
+ // Create a temporary file.
+ $dirName = dirname(TEMPLATE_DIR . '_c/.');
+ $filename = tempnam($dirName, 'import_');
+
+ // If the file is compressed - uncompress it.
+ if ($compressed) {
+ if (!$this->uncompress($_FILES['xmlfile']['tmp_name'], $filename)) {
+ $this->errors->add($i18n->get('error.sys'));
+ return;
+ }
+ unlink($_FILES['newfile']['tmp_name']);
+ } else {
+ if (!move_uploaded_file($_FILES['xmlfile']['tmp_name'], $filename)) {
+ $this->errors->add($i18n->get('error.upload'));
+ return;
+ }
+ }*/
+ }
+}
-<script>
- function chLocation(newLocation) { document.location = newLocation; }
-</script>
-
<table cellspacing="0" cellpadding="7" border="0" width="720">
<tr>
<td valign="top">
-{if $user->can('manage_projects')}
<table cellspacing="1" cellpadding="3" border="0" width="100%">
- {if $inactive_projects}
- <tr><td class="sectionHeaderNoBorder">{$i18n.form.projects.active_projects}</td></tr>
- {/if}
<tr>
<td width="35%" class="tableHeader">{$i18n.label.image}</td>
<td width="35%" class="tableHeader">{$i18n.label.description}</td>
- {if $show_files}
- <td class="tableHeader">{$i18n.label.files}</td>
- {/if}
+{if $can_manage}
<td class="tableHeader">{$i18n.label.edit}</td>
<td class="tableHeader">{$i18n.label.delete}</td>
+{/if}
</tr>
- {if $active_projects}
- {foreach $active_projects as $project}
+{if $files}
+ {foreach $files as $file}
<tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
- <td>{$project.name|escape}</td>
- <td>{$project.description|escape}</td>
- {if $show_files}
- <td><a href="project_files.php?id={$project.id}">{$i18n.label.view}</a></td>
- {/if}
- <td><a href="project_edit.php?id={$project.id}">{$i18n.label.edit}</a></td>
- <td><a href="project_delete.php?id={$project.id}">{$i18n.label.delete}</a></td>
- </tr>
- {/foreach}
- {/if}
- </table>
-
- <table width="100%">
- <tr>
- <td align="center"><br>
- <form><input type="button" onclick="chLocation('project_add.php');" value="{$i18n.button.add}"></form>
- </td>
- </tr>
- </table>
-
- {if $inactive_projects}
- <table cellspacing="1" cellpadding="3" border="0" width="100%">
- <tr><td class="sectionHeaderNoBorder">{$i18n.form.projects.inactive_projects}</td></tr>
- <tr>
- <td width="35%" class="tableHeader">{$i18n.label.thing_name}</td>
- <td width="35%" class="tableHeader">{$i18n.label.description}</td>
- {if $show_files}
- <td class="tableHeader">{$i18n.label.files}</td>
+ <td>{$file.name|escape}</td>
+ <td>{$file.description|escape}</td>
+ {if $can_manage}
+ <td><a href="file_edit.php?id={$file.id}">{$i18n.label.edit}</a></td>
+ <td><a href="file_delete.php?id={$file.id}">{$i18n.label.delete}</a></td>
{/if}
- <td class="tableHeader">{$i18n.label.edit}</td>
- <td class="tableHeader">{$i18n.label.delete}</td>
- </tr>
- {foreach $inactive_projects as $project}
- <tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
- <td>{$project.name|escape}</td>
- <td>{$project.description|escape}</td>
- {if $show_files}
- <td><a href="project_files.php?id={$project.id}">{$i18n.label.view}</a></td>
- {/if}
- <td><a href="project_edit.php?id={$project.id}">{$i18n.label.edit}</a></td>
- <td><a href="project_delete.php?id={$project.id}">{$i18n.label.delete}</a></td>
</tr>
- {/foreach}
+ {/foreach}
+{/if}
</table>
+ </td>
+ </tr>
+</table>
- <table width="100%">
- <tr>
- <td align="center"><br>
- <form><input type="button" onclick="chLocation('project_add.php');" value="{$i18n.button.add}"></form>
- </td>
- </tr>
- </table>
- {/if}
-{else}
- <table cellspacing="1" cellpadding="3" border="0" width="100%">
+{if $can_manage}
+{$forms.fileUploadForm.open}
+<table cellspacing="0" cellpadding="7" border="0" width="720">
+ <tr>
+ <td align="center">
+ <table border="0" width="60%">
<tr>
- <td class="tableHeader">{$i18n.label.thing_name}</td>
- <td class="tableHeader">{$i18n.label.description}</td>
- {if $show_files}
- <td class="tableHeader">{$i18n.label.files}</td>
- {/if}
+ <td align="right">{$i18n.label.description}:</td>
+ <td>{$forms.fileUploadForm.description.control}</td>
+ <td align="left">{$forms.fileUploadForm.newfile.control}</td>
</tr>
- {if $active_projects}
- {foreach $active_projects as $project}
- <tr bgcolor="{cycle values="#f5f5f5,#ffffff"}">
- <td>{$project.name|escape}</td>
- <td>{$project.description|escape}</td>
- {if $show_files}
- <td><a href="project_files.php?id={$project.id}">{$i18n.label.view}</a></td>
- {/if}
- </tr>
- {/foreach}
- {/if}
+ <tr><td height="50" align="center" colspan="3">{$forms.fileUploadForm.btn_submit.control}</td></tr>
</table>
-{/if}
</td>
</tr>
</table>
+{$forms.fileUploadForm.close}
+{/if}
// +----------------------------------------------------------------------+
require_once('initialize.php');
+import('form.Form');
import('ttProjectHelper');
+import('ttFileHelper');
// Access checks.
if (!(ttAccessAllowed('view_own_projects') || ttAccessAllowed('manage_projects'))) {
}
// End of access checks.
+if ($request->isPost()) {
+ $cl_description = trim($request->getParameter('description'));
+}
+
$files = null;
// $files = ttAttachmentHelper::getProjectFiles();
+$form = new Form('fileUploadForm');
+$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_project_id));
+$form->addInput(array('type'=>'upload','name'=>'newfile','value'=>$i18n->get('button.submit'),'maxsize'=>67108864)); // 64 MB file upload limit.
+// 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.
+$form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description));
+$form->addInput(array('type'=>'submit','name'=>'btn_submit','value'=>$i18n->get('button.add')));
+
+if ($request->isPost()) {
+ // We are adding a new file.
+
+ // Validate user input.
+ if (!$_FILES['newfile']['name']) $err->add($i18n->get('error.upload'));
+ if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description'));
+ // Finished validating user input.
+
+ $fileHelper = new ttFileHelper($err);
+ $fileHelper->putFile();
+// if ($err->no()) $msg->add($i18n->get('form.import.success'));
+} // isPost
+
+$smarty->assign('can_manage', $user->can('manage_projects'));
+$smarty->assign('forms', array($form->getName()=>$form->toArray()));
$smarty->assign('files', $files);
$smarty->assign('title', $i18n->get('title.project_files'));
$smarty->assign('content_page_name', 'project_files.tpl');