Fixed bug in removing attachments. Fixed editing attachmetns. Closes #66

This commit is contained in:
Karl Cordes 2013-03-29 12:38:50 +11:00
parent 0793d5b088
commit a73fd66440
7 changed files with 19 additions and 15 deletions

View file

@ -43,7 +43,7 @@ Router::connect('/', array('controller' => 'enquiries', 'action' => 'index'));
* Then we connect url '/test' to our test controller. This is helpful in * Then we connect url '/test' to our test controller. This is helpful in
* developement. * developement.
*/ */
Router::connect('/tests', array('controller' => 'tests', 'action' => 'index')); # Router::connect('/tests', array('controller' => 'tests', 'action' => 'index'));
Router::connect('/admin', array('controller'=>'pages','action'=>'display','admin')); //Display the admin page Router::connect('/admin', array('controller'=>'pages','action'=>'display','admin')); //Display the admin page

View file

@ -43,8 +43,7 @@ class AttachmentsController extends AppController {
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} }
if (!empty($this->data)) { if (!empty($this->data)) {
$attachment = $this->Attachment->process_attachment($this->data); if ($this->Attachment->save($this->data)) {
if ($this->Attachment->save($attachment)) {
$this->Session->setFlash(__('The Attachment has been saved', true)); $this->Session->setFlash(__('The Attachment has been saved', true));
$this->redirect(array('action'=>'index')); $this->redirect(array('action'=>'index'));
} else { } else {
@ -54,9 +53,8 @@ class AttachmentsController extends AppController {
if (empty($this->data)) { if (empty($this->data)) {
$this->data = $this->Attachment->read(null, $id); $this->data = $this->Attachment->read(null, $id);
} }
$products = $this->Attachment->Product->find('list');
$principles = $this->Attachment->Principle->find('list'); $principles = $this->Attachment->Principle->find('list');
$this->set(compact('products','principles')); $this->set(compact('principles'));
} }
function delete($id = null) { function delete($id = null) {

View file

@ -139,9 +139,11 @@ class DocumentsController extends AppController {
function removeAttachments() { function removeAttachments() {
$this->layout = 'ajax'; $this->layout = 'ajax';
foreach($this->data as $attachment) { foreach($this->data as $attachment) {
$this->Document->DocumentAttachment->delete($attachment); $this->Document->DocumentAttachment->delete($attachment);
} }
echo 'SUCCESS';
} }

View file

@ -6,9 +6,13 @@
echo $form->input('id'); echo $form->input('id');
echo $form->input('principle_id'); echo $form->input('principle_id');
echo $form->input('name'); echo $form->input('name');
echo $form->input('filename'); ?>
echo $form->input('type'); <div class="input text">
echo $form->input('size'); <label>Filename</label>
<?php echo $this->data['Attachment']['filename']; ?>
</div>
<?php
echo $form->input('description'); echo $form->input('description');
echo $form->input('archived'); echo $form->input('archived');
?> ?>

View file

@ -1,4 +1,4 @@
<?php if (file_exists($attachment['Attachment']['filename'])) { <?php if (file_exists($attachment['Attachment']['file'])) {
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream'); header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($attachment['Attachment']['filename'])); header('Content-Disposition: attachment; filename='.basename($attachment['Attachment']['filename']));
@ -6,10 +6,10 @@
header('Expires: 0'); header('Expires: 0');
header('Cache-Control: must-revalidate'); header('Cache-Control: must-revalidate');
header('Pragma: public'); header('Pragma: public');
header('Content-Length: ' . filesize($attachment['Attachment']['filename'])); header('Content-Length: ' . filesize($attachment['Attachment']['file']));
ob_clean(); ob_clean();
flush(); flush();
readfile($attachment['Attachment']['filename']); readfile($attachment['Attachment']['file']);
exit; exit;
} }

View file

@ -10,7 +10,7 @@
foreach($attachments as $attachment) { foreach($attachments as $attachment) {
?> ?>
<tr> <tr>
<td><?php echo $form->input('DocumentAttachment.id', array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false)); ?></td> <td><?php echo $form->input('DocumentAttachment.id', array('type'=>'checkbox', 'value'=> $attachment['DocumentAttachment']['id'], 'label' => false, 'class'=>'documentAttachment-checkbox')); ?></td>
<td> <td>
<?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?> <?php echo $html->link($attachment['Attachment']['filename'], '/attachments/view/'.$attachment['Attachment']['id']); ?>
</td> </td>

0
app/webroot/js/document_attachments.js Normal file → Executable file
View file