From ce87d5ef0cd23ad967652cce89b5c2819206f2c2 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Thu, 1 Feb 2007 20:27:32 +0000 Subject: [PATCH] Added ability to remove files from a request. --- .../controllers/NewrequestController.php | 15 +++++++++++++++ application/models/rows/Request.php | 15 +++++++++++++++ .../views/request/supportive_material.xhtml | 19 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/application/controllers/NewrequestController.php b/application/controllers/NewrequestController.php index ebe5495d..0b9ad320 100644 --- a/application/controllers/NewrequestController.php +++ b/application/controllers/NewrequestController.php @@ -136,6 +136,13 @@ class NewRequestController extends Nmc_Controller_Action $request->$key = $val; } } } + + $filesToRemove = null; + if(array_key_exists('removeFiles', $_POST)) { + $filesToRemove = $_POST['removeFiles']; + unset($_POST['removeFiles']); + } + unset($_POST['request']); unset($_POST['submit']); @@ -336,6 +343,14 @@ class NewRequestController extends Nmc_Controller_Action } } + if (is_array($filesToRemove)) { + foreach ($filesToRemove as $fileType => $doRemove) { + if ($doRemove == 'yes') { + $request->removeFileByType($fileType); + } + } + } + if($submit == 'Submit') { return $this->_submitRequestAction(); } diff --git a/application/models/rows/Request.php b/application/models/rows/Request.php index f4bc1b82..bd599be1 100644 --- a/application/models/rows/Request.php +++ b/application/models/rows/Request.php @@ -91,6 +91,21 @@ class Request extends Nmc_Db_Table_Row $this->files[$key] = $newFile; } + public function removeFileByType($type) { + $key = null; + foreach($this->files as $currentKey => $file) + { + if($file->type == $type) { + $key = $currentKey; + break; + } + } + + if($key !== null) { + unset($this->files[$key]); + } + } + protected function _preSave() { // should only need to worry about this when dealing with a new request diff --git a/application/views/request/supportive_material.xhtml b/application/views/request/supportive_material.xhtml index c4774f04..dd86c5d5 100644 --- a/application/views/request/supportive_material.xhtml +++ b/application/views/request/supportive_material.xhtml @@ -11,6 +11,11 @@ <?php echo $this->request->getFileByType(RequestFile::SYLLABUS_TYPE)->title; ?> <input type="file" name="request[<?php echo RequestFile::SYLLABUS_TYPE; ?>]" /> </label> + <label> + Remove + <input type="hidden" name="removeFiles[<?php echo RequestFile::SYLLABUS_TYPE; ?>]" value="no" /> + <input type="checkbox" name="removeFiles[<?php echo RequestFile::SYLLABUS_TYPE; ?>]" value="yes" /> + </label> </fieldset> <fieldset> @@ -19,6 +24,11 @@ <?php echo $this->request->getFileByType(RequestFile::CROSSLIST_MEMO_TYPE)->title; ?> <input type="file" name="request[<?php echo RequestFile::CROSSLIST_MEMO_TYPE; ?>]" /> </label> + <label> + Remove + <input type="hidden" name="removeFiles[<?php echo RequestFile::CROSSLIST_MEMO_TYPE; ?>]" value="no" /> + <input type="checkbox" name="removeFiles[<?php echo RequestFile::CROSSLIST_MEMO_TYPE; ?>]" value="yes" /> + </label> </fieldset> <?php if($this->request->type == 5) { ?> @@ -28,6 +38,11 @@ <?php echo $this->request->getFileByType(RequestFile::IS_NARRATIVE_TYPE)->title; ?> <input type="file" name="request[<?php echo RequestFile::IS_NARRATIVE_TYPE; ?>]" /> </label> + <label> + Remove + <input type="hidden" name="removeFiles[<?php echo RequestFile::IS_NARRATIVE_TYPE; ?>]" value="no" /> + <input type="checkbox" name="removeFiles[<?php echo RequestFile::IS_NARRATIVE_TYPE; ?>]" value="yes" /> + </label> </fieldset> <?php } ?> @@ -36,4 +51,8 @@ <h2>Additional Documentation (opt.)</h2> <input type="file" name="request[additionalDocumentation]" /> </label> + <label> + Remove + <input type="checkbox" name="removeFile[additionalDocumentation]" /> + </label> </fieldset> -- GitLab