EnquiryFile added
45
controllers/enquiry_files_controller.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php class EnquiryFilesController extends AppController {
|
||||
|
||||
var $name = 'EnquiryFiles';
|
||||
var $helpers = array('Html', 'Form', 'Time');
|
||||
|
||||
function add($enquiryid = null) {
|
||||
if(isset($this->params['named']['enquiryid'])) {
|
||||
$enquiryid = $this->params['named']['enquiryid'];
|
||||
$this->set('enquiry', $this->EnquiryFile->Enquiry->findById($enquiryid));
|
||||
}
|
||||
|
||||
if (!$enquiryid && empty($this->data)) {
|
||||
$this->Session->setFlash(__('Invalid Enquiry ID', true));
|
||||
$this->redirect(array('controller'=>'Enquiries', 'action'=>'index'));
|
||||
}
|
||||
|
||||
if (!empty($this->data) &&
|
||||
is_uploaded_file($this->data['EnquiryFile']['File']['tmp_name'])) {
|
||||
$fileData = fread(fopen($this->data['EnquiryFile']['File']['tmp_name'], "r"),
|
||||
$this->data['EnquiryFile']['File']['size']);
|
||||
|
||||
$this->data['EnquiryFile']['name'] = $this->data['EnquiryFile']['File']['name'];
|
||||
$this->data['EnquiryFile']['type'] = $this->data['EnquiryFile']['File']['type'];
|
||||
$this->data['EnquiryFile']['size'] = $this->data['EnquiryFile']['File']['size'];
|
||||
$this->data['EnquiryFile']['data'] = $fileData;
|
||||
|
||||
$this->EnquiryFile->save($this->data);
|
||||
|
||||
$this->redirect(array('controller' => 'enquiries', 'action' => 'view/'.$enquiryid));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function download($id) {
|
||||
Configure::write('debug', 0);
|
||||
$file = $this->EnquiryFile->findById($id);
|
||||
header('Content-type: ' . $file['EnquiryFile']['type']);
|
||||
header('Content-length: ' . $file['EnquiryFile']['size']);
|
||||
header('Content-Disposition: attachment; filename="'.$file['EnquiryFile']['name'].'"');
|
||||
echo $file['EnquiryFile']['data'];
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
6
models/enquiry_file.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class EnquiryFile extends AppModel {
|
||||
var $name = 'EnquiryFile';
|
||||
var $belongsTo = array('Enquiry');
|
||||
}
|
||||
58
views/elements/enquiry_file_table.ctp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php if (!empty($files)):?>
|
||||
<table cellpadding = "0" cellspacing = "0" class="filetable">
|
||||
<tr>
|
||||
<th><?php __('Date Added'); ?></th>
|
||||
<th><?php __('Name'); ?></th>
|
||||
<th><?php __('Type'); ?></th>
|
||||
<th><?php __('Size'); ?></th>
|
||||
<th><?php __('Description'); ?></th>
|
||||
<th class="actions"><?php __('Actions');?></th>
|
||||
</tr>
|
||||
<?php
|
||||
$i = 0;
|
||||
foreach ($files as $file):
|
||||
$class = null;
|
||||
|
||||
if ($i % 2 == 0) {
|
||||
$class = ' class="altrow"';
|
||||
}
|
||||
$i++;
|
||||
?>
|
||||
<tr<?php echo $class;?>>
|
||||
<td><?php echo $time->nice($file['EnquiryFile']['created']);?></td>
|
||||
<td><?php echo $html->link($file['EnquiryFile']['name'], array('controller'=>'enquiry_files', 'action' => 'download/', $file['EnquiryFile']['id']));?></td>
|
||||
<td><?php
|
||||
if($file['EnquiryFile']['type'] == 'application/pdf') {
|
||||
echo $html->image('pdf_type.png');
|
||||
}
|
||||
else if($file['EnquiryFile']['type'] == 'application/msword') {
|
||||
echo $html->image('document_type.png');
|
||||
}
|
||||
else if($file['EnquiryFile']['type'] == 'message/rfc822') {
|
||||
echo $html->image('message_type.png');
|
||||
}
|
||||
else if($file['EnquiryFile']['type'] == 'application/vnd.ms-excel') {
|
||||
echo $html->image('spreadsheet_document_type.png');
|
||||
}
|
||||
else if($file['EnquiryFile']['type'] == 'image/jpeg') {
|
||||
echo $html->image('image_type.png');
|
||||
}
|
||||
else {
|
||||
echo $html->image('unknown_type.png');
|
||||
}
|
||||
?></td>
|
||||
<td><?php echo $number->toReadableSize($file['EnquiryFile']['size']);?></td>
|
||||
<td><?php echo $file['EnquiryFile']['description'];?></td>
|
||||
<td class="actions">
|
||||
<?php echo $html->link(__('View', true), array('controller'=> 'enquiry_files', 'action'=>'download/', $file['EnquiryFile']['id'])); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="actions">
|
||||
<ul>
|
||||
<li><?php echo $html->link(__('Add File to this Enquiry', true), array('controller'=> 'enquiry_files', 'action'=>'add/enquiryid:'.$enquiry['Enquiry']['id']));?> </li>
|
||||
</ul>
|
||||
</div>
|
||||
13
views/enquiry_files/add.ctp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
echo $form->create('EnquiryFile', array('action' => 'add/enquiryid:'.$enquiry['Enquiry']['id'], 'type' => 'file'));
|
||||
echo '<fieldset>';
|
||||
echo'<legend>';
|
||||
__("Add File to Enquiry ".$enquiry['Enquiry']['title']);
|
||||
echo '</legend>';
|
||||
echo $form->file('File');
|
||||
echo $form->input('description');
|
||||
echo $form->input('enquiry_id', array('type'=>'hidden', 'value' => $enquiry['Enquiry']['id']));
|
||||
//echo $form->submit('Upload');
|
||||
echo $form->end('Upload');
|
||||
echo '</fieldset>';
|
||||
?>
|
||||
BIN
webroot/img/address-book-new.png
Executable file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
webroot/img/document.png
Executable file
|
After Width: | Height: | Size: 4 KiB |
BIN
webroot/img/document_type.png
Executable file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
webroot/img/image_type.png
Executable file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
webroot/img/kaddressbook.png
Executable file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
webroot/img/message_type.png
Executable file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
webroot/img/pdf_type.png
Executable file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
webroot/img/spreadsheet_document_type.png
Executable file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
webroot/img/txt_type.png
Executable file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
webroot/img/unknown_type.png
Executable file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
webroot/img/x-office-address-book.png
Executable file
|
After Width: | Height: | Size: 1.3 KiB |