From 6152f4bd9a8f960c79ae025b775b719930574cc9 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sat, 30 Mar 2019 14:37:28 +0000 Subject: [PATCH] Implemented attachment edit. --- WEB-INF/lib/ttFileHelper.class.php | 17 ++++++ WEB-INF/templates/file_edit.tpl | 29 ++++++++++ WEB-INF/templates/footer.tpl | 2 +- file_edit.php | 91 ++++++++++++++++++++++++++++++ project_edit.php | 22 ++++---- 5 files changed, 149 insertions(+), 12 deletions(-) create mode 100644 WEB-INF/templates/file_edit.tpl create mode 100644 file_edit.php diff --git a/WEB-INF/lib/ttFileHelper.class.php b/WEB-INF/lib/ttFileHelper.class.php index 6a799ad8..ce24cd79 100644 --- a/WEB-INF/lib/ttFileHelper.class.php +++ b/WEB-INF/lib/ttFileHelper.class.php @@ -335,4 +335,21 @@ class ttFileHelper { } return false; } + + // update - updates file details in local database. + static function update($fields) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $file_id = (int) $fields['id']; + $description = $mdb2->quote($fields['description']); + + $sql = "update tt_files set description = $description where id = $file_id". + " and group_id = $group_id and org_id = $org_id and (status = 0 or status = 1)"; + $affected = $mdb2->exec($sql); + return !is_a($affected, 'PEAR_Error'); + } } diff --git a/WEB-INF/templates/file_edit.tpl b/WEB-INF/templates/file_edit.tpl new file mode 100644 index 00000000..697a650c --- /dev/null +++ b/WEB-INF/templates/file_edit.tpl @@ -0,0 +1,29 @@ +{$forms.fileForm.open} + + + + +
+ + + + + + + + + + + + + + + + + + + + +
{$i18n.label.thing_name} (*):{$forms.fileForm.file_name.control}
{$i18n.label.description}:{$forms.fileForm.description.control}
{$i18n.label.required_fields}
 
{$forms.fileForm.btn_save.control}
+
+{$forms.fileForm.close} diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index c62240bd..3c4bb39d 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.61.4894 | Copyright © Anuko | +  Anuko Time Tracker 1.18.61.4895 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/file_edit.php b/file_edit.php new file mode 100644 index 00000000..381508d1 --- /dev/null +++ b/file_edit.php @@ -0,0 +1,91 @@ +getParameter('id'); +$file = ttFileHelper::get($cl_file_id); +if (!$file) { + header('Location: access_denied.php'); + exit(); +} +// Entity-specific checks. +if ($file['entity_type'] == 'project') { + if (!ttAccessAllowed('manage_projects') || !ttProjectHelper::get($file['entity_id'])) { + header('Location: access_denied.php'); + exit(); + } +} +if ($file['entity_type'] != 'project') { + // Currently, files are only associated with projects. + // Improve access checks when the feature evolves. + header('Location: access_denied.php'); + exit(); +} +// End of access checks. + +if ($request->isPost()) { + $cl_description = trim($request->getParameter('description')); +} else { + $cl_description = $file['description']; +} +$cl_name = $file['file_name']; + +$form = new Form('fileForm'); +$form->addInput(array('type'=>'hidden','name'=>'id','value'=>$cl_file_id)); +$form->addInput(array('type'=>'text','maxlength'=>'100','name'=>'file_name','style'=>'width: 250px;','value'=>$cl_name)); +$form->getElement('file_name')->setEnabled(false); +$form->addInput(array('type'=>'textarea','name'=>'description','style'=>'width: 250px; height: 40px;','value'=>$cl_description)); +$form->addInput(array('type'=>'submit','name'=>'btn_save','value'=>$i18n->get('button.save'))); + +if ($request->isPost()) { + // Validate user input. + if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description')); + + if ($err->no()) { + if ($request->getParameter('btn_save')) { + // Update file information. + $updated = ttFileHelper::update(array('id' => $cl_file_id,'description' => $cl_description)); + if ($updated && $file['entity_type'] == 'project') { + header('Location: project_files.php?id='.$file['entity_id']); + exit(); + } else + $err->add($i18n->get('error.db')); + } + } +} // isPost + +$smarty->assign('forms', array($form->getName()=>$form->toArray())); +$smarty->assign('onload', 'onLoad="document.fileForm.description.focus()"'); +$smarty->assign('title', $i18n->get('title.edit_file')); +$smarty->assign('content_page_name', 'file_edit.tpl'); +$smarty->display('index.tpl'); diff --git a/project_edit.php b/project_edit.php index a2b27925..e1792e48 100644 --- a/project_edit.php +++ b/project_edit.php @@ -94,18 +94,18 @@ if ($request->isPost()) { if ($request->getParameter('btn_save')) { $existing_project = ttProjectHelper::getProjectByName($cl_name); if (!$existing_project || ($cl_project_id == $existing_project['id'])) { - // Update project information. - if (ttProjectHelper::update(array( - 'id' => $cl_project_id, - 'name' => $cl_name, - 'description' => $cl_description, - 'status' => $cl_status, - 'users' => $cl_users, - 'tasks' => $cl_tasks))) { - header('Location: projects.php'); - exit(); + // Update project information. + if (ttProjectHelper::update(array( + 'id' => $cl_project_id, + 'name' => $cl_name, + 'description' => $cl_description, + 'status' => $cl_status, + 'users' => $cl_users, + 'tasks' => $cl_tasks))) { + header('Location: projects.php'); + exit(); } else - $err->add($i18n->get('error.db')); + $err->add($i18n->get('error.db')); } else $err->add($i18n->get('error.object_exists')); } -- 2.20.1