2012-11-18 12:19:55 -08:00
|
|
|
<?php
|
|
|
|
|
class AttachmentsController extends AppController {
|
|
|
|
|
|
|
|
|
|
var $name = 'Attachments';
|
|
|
|
|
var $helpers = array('Html', 'Form','Number','Time');
|
|
|
|
|
|
2013-04-04 04:06:16 -07:00
|
|
|
|
2013-04-08 05:28:27 -07:00
|
|
|
var $paginate = array(
|
|
|
|
|
|
|
|
|
|
'contain' => false,
|
|
|
|
|
'limit' => 5000,
|
|
|
|
|
);
|
2013-04-04 04:06:16 -07:00
|
|
|
|
|
|
|
|
|
2012-11-18 12:19:55 -08:00
|
|
|
function index() {
|
|
|
|
|
$this->Attachment->recursive = 1;
|
2013-04-04 03:54:28 -07:00
|
|
|
$this->set('attachments', $this->paginate());
|
2012-11-18 12:19:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function view($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid Attachment.', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
2013-04-04 03:54:28 -07:00
|
|
|
$this->set('attachment', $this->Attachment->read(null, $id));
|
|
|
|
|
$this->layout = 'pdf';
|
|
|
|
|
}
|
2012-11-18 12:19:55 -08:00
|
|
|
|
|
|
|
|
function add() {
|
|
|
|
|
if (!empty($this->data)) {
|
|
|
|
|
|
2013-04-04 03:54:28 -07:00
|
|
|
$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();
|
2012-11-18 12:19:55 -08:00
|
|
|
|
2013-04-04 03:54:28 -07:00
|
|
|
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));
|
|
|
|
|
}
|
2012-11-18 12:19:55 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$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)) {
|
2013-04-08 05:28:27 -07:00
|
|
|
//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');
|
2012-11-18 12:19:55 -08:00
|
|
|
}
|
2013-04-08 05:28:27 -07:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-18 12:19:55 -08:00
|
|
|
}
|
2013-04-08 05:28:27 -07:00
|
|
|
else {
|
2012-11-18 12:19:55 -08:00
|
|
|
$this->data = $this->Attachment->read(null, $id);
|
|
|
|
|
}
|
|
|
|
|
$principles = $this->Attachment->Principle->find('list');
|
2013-03-28 18:38:50 -07:00
|
|
|
$this->set(compact('principles'));
|
2012-11-18 12:19:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete($id = null) {
|
|
|
|
|
if (!$id) {
|
|
|
|
|
$this->Session->setFlash(__('Invalid id for Attachment', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
2013-04-04 03:54:28 -07:00
|
|
|
$attachment = $this->Attachment->read(null, $id);
|
2012-11-18 12:19:55 -08:00
|
|
|
if ($this->Attachment->del($id)) {
|
2013-04-04 03:54:28 -07:00
|
|
|
unlink($attachment['Attachment']['file']);
|
2012-11-18 12:19:55 -08:00
|
|
|
$this->Session->setFlash(__('Attachment deleted', true));
|
|
|
|
|
$this->redirect(array('action'=>'index'));
|
|
|
|
|
}
|
2013-04-04 03:54:28 -07:00
|
|
|
}
|
2012-11-18 12:19:55 -08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|