5000, 'order' => array( array('Attachment.principle_id' => 'asc'), array('Attachment.name' => 'asc') ) ); function index() { $this->Attachment->recursive = 1; $this->set('attachments', $this->paginate()); } function view($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid Attachment.', true)); $this->redirect(array('action'=>'index')); } $this->set('attachment', $this->Attachment->read(null, $id)); $this->layout = 'pdf'; } function add() { if (!empty($this->data)) { $attachment = $this->Attachment->process_attachment($this->data); if(!$attachment) { $this->Session->setFlash('The Attachment could not be saved. The filename exists'); } else { $this->Attachment->create(); 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)); } } } $principles = $this->Attachment->Principle->find('list'); $this->set(compact('products', 'principles')); } function edit($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash(__('Invalid Attachment', true)); $this->redirect(array('action'=>'index')); } if (!empty($this->data)) { //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)); } } } else { $this->data = $this->Attachment->read(null, $id); } $principles = $this->Attachment->Principle->find('list'); $this->set(compact('principles')); } function delete($id = null) { if (!$id) { $this->Session->setFlash(__('Invalid id for Attachment', true)); $this->redirect(array('action'=>'index')); } $attachment = $this->Attachment->read(null, $id); if ($this->Attachment->del($id)) { unlink($attachment['Attachment']['file']); $this->Session->setFlash(__('Attachment deleted', true)); $this->redirect(array('action'=>'index')); } } } ?>