diff --git a/app/controllers/attachments_controller.php b/app/controllers/attachments_controller.php index a766d43e..539d50f5 100644 --- a/app/controllers/attachments_controller.php +++ b/app/controllers/attachments_controller.php @@ -9,9 +9,10 @@ class AttachmentsController extends AppController { 'limit' => 5000, 'order' => array( - array('Attachment.principle_id' => 'asc'), + array('Principle.short_name' => 'asc'), array('Attachment.name' => 'asc') - ) + ), + 'conditions' => array('Attachment.archived' => 0) ); @@ -29,6 +30,13 @@ class AttachmentsController extends AppController { $this->layout = 'pdf'; } + function archived() { + $this->set('archived', $this->Attachment->find('all', array('conditions'=> array('archived' => 1), 'order' => array( + array('Principle.short_name' => 'asc'), + array('Attachment.name' => 'asc') + )))); + } + function add() { if (!empty($this->data)) { @@ -57,27 +65,31 @@ class AttachmentsController extends AppController { $this->redirect(array('action'=>'index')); } if (!empty($this->data)) { - //Process editing the PDFs. + $attachment = $this->data; $existing = $this->Attachment->find('first', array('conditions'=>array('Attachment.id' => $this->data['Attachment']['id']))); + //Process editing the PDFs. + if(!empty($this->data['Attachment']['file']['tmp_name'])) { - if(!empty($existing)) { - //Delete old file - unlink($existing['Attachment']['file']); + if(!empty($existing)) { + //Delete old file + unlink($existing['Attachment']['file']); - } - $attachment = $this->Attachment->process_attachment($this->data); + } + $attachment = $this->Attachment->process_attachment($this->data); - if(!$attachment) { - $this->Session->setFlash('The Attachment could not be saved. The filename exists'); + 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)); - } + $attachment['Attachment']['file'] = $existing['Attachment']['file']; } + 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)); + } } diff --git a/app/views/attachments/archived.ctp b/app/views/attachments/archived.ctp new file mode 100644 index 00000000..524741ff --- /dev/null +++ b/app/views/attachments/archived.ctp @@ -0,0 +1,53 @@ + + + + + + + + + + + + > + + + + + + + + +
PrincipleCreatedNameTypeSizeActions
+ link($attachment['Principle']['short_name'], '/principles/view/'.$attachment['Principle']['id']); + } + else { + echo $html->link($attachment['Principle']['name'], '/principles/view/'.$attachment['Principle']['id']); + } + ?> + + nice($attachment['Attachment']['created']); ?> + + + + + + toReadAbleSize($attachment['Attachment']['size']); ?> + + link(__('View', true), array('action' => 'view', $attachment['Attachment']['id'])); ?> + link(__('Edit', true), array('action' => 'edit', $attachment['Attachment']['id'])); ?> +
+ + diff --git a/app/views/attachments/index.ctp b/app/views/attachments/index.ctp index a8e93919..c10f8a35 100644 --- a/app/views/attachments/index.ctp +++ b/app/views/attachments/index.ctp @@ -1,5 +1,13 @@

+ +
+ +
+

counter(array( @@ -8,7 +16,6 @@ echo $paginator->counter(array( ?>

- @@ -19,6 +26,9 @@ echo $paginator->counter(array( > -
sort('id');?> sort('principle_id');?> sort('created');?> sort('name');?>
- - link($attachment['Principle']['short_name'], '/principles/view/'.$attachment['Principle']['id']);