From 801da0e379cfd72ee9b3f9d6e2718989bb5a1d80 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 16 Mar 2019 16:04:19 +0000 Subject: [PATCH] Work in progress on project attachments. --- WEB-INF/lib/ttFileHelper.class.php | 62 ++++++++++++++++ WEB-INF/templates/project_files.tpl | 107 +++++++--------------------- project_files.php | 28 ++++++++ 3 files changed, 116 insertions(+), 81 deletions(-) create mode 100644 WEB-INF/lib/ttFileHelper.class.php diff --git a/WEB-INF/lib/ttFileHelper.class.php b/WEB-INF/lib/ttFileHelper.class.php new file mode 100644 index 00000000..7273d808 --- /dev/null +++ b/WEB-INF/lib/ttFileHelper.class.php @@ -0,0 +1,62 @@ +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; + } + }*/ + } +} diff --git a/WEB-INF/templates/project_files.tpl b/WEB-INF/templates/project_files.tpl index 0313e030..d092e3cb 100644 --- a/WEB-INF/templates/project_files.tpl +++ b/WEB-INF/templates/project_files.tpl @@ -1,102 +1,47 @@ - - + +
-{if $user->can('manage_projects')} - {if $inactive_projects} - - {/if} - {if $show_files} - - {/if} +{if $can_manage} +{/if} - {if $active_projects} - {foreach $active_projects as $project} +{if $files} + {foreach $files as $file} - - - {if $show_files} - - {/if} - - - - {/foreach} - {/if} -
{$i18n.form.projects.active_projects}
{$i18n.label.image} {$i18n.label.description}{$i18n.label.files}{$i18n.label.edit} {$i18n.label.delete}
{$project.name|escape}{$project.description|escape}{$i18n.label.view}{$i18n.label.edit}{$i18n.label.delete}
- - - - - -

-
-
- - {if $inactive_projects} - - - - - - {if $show_files} - + + + {if $can_manage} + + {/if} - - - - {foreach $inactive_projects as $project} - - - - {if $show_files} - - {/if} - - - {/foreach} + {/foreach} +{/if}
{$i18n.form.projects.inactive_projects}
{$i18n.label.thing_name}{$i18n.label.description}{$i18n.label.files}{$file.name|escape}{$file.description|escape}{$i18n.label.edit}{$i18n.label.delete}{$i18n.label.edit}{$i18n.label.delete}
{$project.name|escape}{$project.description|escape}{$i18n.label.view}{$i18n.label.edit}{$i18n.label.delete}
+
- - - - -

-
-
- {/if} -{else} - +{if $can_manage} +{$forms.fileUploadForm.open} +
+ +
+ - - - {if $show_files} - - {/if} + + + - {if $active_projects} - {foreach $active_projects as $project} - - - - {if $show_files} - - {/if} - - {/foreach} - {/if} +
{$i18n.label.thing_name}{$i18n.label.description}{$i18n.label.files}{$i18n.label.description}:{$forms.fileUploadForm.description.control}{$forms.fileUploadForm.newfile.control}
{$project.name|escape}{$project.description|escape}{$i18n.label.view}
{$forms.fileUploadForm.btn_submit.control}
-{/if}
+{$forms.fileUploadForm.close} +{/if} diff --git a/project_files.php b/project_files.php index b069acb7..08e9b5f2 100644 --- a/project_files.php +++ b/project_files.php @@ -27,7 +27,9 @@ // +----------------------------------------------------------------------+ require_once('initialize.php'); +import('form.Form'); import('ttProjectHelper'); +import('ttFileHelper'); // Access checks. if (!(ttAccessAllowed('view_own_projects') || ttAccessAllowed('manage_projects'))) { @@ -46,9 +48,35 @@ if (!$project) { } // 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'); -- 2.20.1