From 356b9ef9bfb5cdf4adc5e6c674212bd059b198eb Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Mon, 8 Apr 2013 22:28:27 +1000 Subject: [PATCH] Removed attachment deleting. Attachments files can now be edited --- app/controllers/attachments_controller.php | 39 ++++++++++++++++------ app/models/email.php | 2 +- app/views/attachments/edit.ctp | 4 ++- app/views/attachments/index.ctp | 1 - 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/controllers/attachments_controller.php b/app/controllers/attachments_controller.php index 68cee02e..a797fe96 100644 --- a/app/controllers/attachments_controller.php +++ b/app/controllers/attachments_controller.php @@ -5,12 +5,12 @@ class AttachmentsController extends AppController { var $helpers = array('Html', 'Form','Number','Time'); - var $paginate = array( + var $paginate = array( + + 'contain' => false, + 'limit' => 5000, + ); - 'contain' => false, - 'limit' => 5000, - ); - function index() { $this->Attachment->recursive = 1; @@ -54,14 +54,31 @@ class AttachmentsController extends AppController { $this->redirect(array('action'=>'index')); } if (!empty($this->data)) { - if ($this->Attachment->save($this->data)) { - $this->Session->setFlash(__('The Attachment has been saved', true)); - $this->redirect(array('action'=>'index')); - } else { - $this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true)); + //Process editing the PDFs. + $existing = $this->Attachment->find('first', array('conditions'=>array('Attachment.id' => $this->data['Attachment']['id']))); + + if(!empty($existing)) { + //Delete old file + unlink($existing['Attachment']['file']); + } + $attachment = $this->Attachment->process_attachment($this->data); + + if(!$attachment) { + $this->Session->setFlash('The Attachment could not be saved. The filename exists'); + } + else { + if ($this->Attachment->save($attachment)) { + $this->Session->setFlash(__('The Attachment has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true)); + } + } + + } - if (empty($this->data)) { + else { $this->data = $this->Attachment->read(null, $id); } $principles = $this->Attachment->Principle->find('list'); diff --git a/app/models/email.php b/app/models/email.php index a4780488..d2a8a43b 100755 --- a/app/models/email.php +++ b/app/models/email.php @@ -50,7 +50,7 @@ class Email extends AppModel { function getEnquiryEmails($id) { - return $this->find('first', array('Enquiry.id'=>$id)); + return $this->find('first', array('Enquiry.id'=>$id)); } diff --git a/app/views/attachments/edit.ctp b/app/views/attachments/edit.ctp index 8109509d..d1ac4fc4 100644 --- a/app/views/attachments/edit.ctp +++ b/app/views/attachments/edit.ctp @@ -1,5 +1,5 @@
-create('Attachment');?> +create('Attachment', array('type'=>'file'));?>
Filename data['Attachment']['filename']; ?>
+ + file('file'); ?> input('description'); diff --git a/app/views/attachments/index.ctp b/app/views/attachments/index.ctp index af2adaa2..a8e93919 100644 --- a/app/views/attachments/index.ctp +++ b/app/views/attachments/index.ctp @@ -57,7 +57,6 @@ foreach ($attachments as $attachment): link(__('View', true), array('action' => 'view', $attachment['Attachment']['id'])); ?> link(__('Edit', true), array('action' => 'edit', $attachment['Attachment']['id'])); ?> - link(__('Delete', true), array('action' => 'delete', $attachment['Attachment']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $attachment['Attachment']['id'])); ?>