Skip to content
Snippets Groups Projects
Commit ce87d5ef authored by Tim Steiner's avatar Tim Steiner
Browse files

Added ability to remove files from a request.

parent 47a6aa80
No related branches found
Tags
No related merge requests found
......@@ -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();
}
......
......@@ -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
......
......@@ -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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment