diff --git a/controllers/contacts_controller.php b/controllers/contacts_controller.php index 4be07d60..73fafd2c 100755 --- a/controllers/contacts_controller.php +++ b/controllers/contacts_controller.php @@ -23,6 +23,13 @@ class ContactsController extends AppController { //$enquiries = $this->Contact->Enquiry->findAllByContactId($id); $this->set('enquiries', $this->paginate('Enquiry', array('Enquiry.contact_id' => $id))); //$this->set('enquiries', $this->paginate($enquiries)); + $statuses = $this->Contact->Enquiry->Status->find('all'); + $status_list = array(); + foreach ($statuses as $status) { + $status_list[] = array($status['Status']['id'], $status['Status']['name']); + } + $this->set('status_list', $status_list); + } diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 2e3f595e..4ca286c3 100755 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -8,7 +8,7 @@ class CustomersController extends AppController { 'Customer' => array('order' => array('Customer.name' => 'asc'), 'limit' => 200 ), - 'Enquiry' => array('order' => array('Enquiry.id' => 'asc')) + 'Enquiry' => array('order' => array('Enquiry.id' => 'desc')) ); function index() { diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php index 2afd9529..68ca275f 100755 --- a/controllers/enquiries_controller.php +++ b/controllers/enquiries_controller.php @@ -297,6 +297,7 @@ class EnquiriesController extends AppController { $this->redirect(array('action'=>'index')); } if (!empty($this->data)) { + if ($this->Enquiry->save($this->data)) { $this->Session->setFlash(__('The Enquiry has been saved', true)); $this->redirect(array('action'=>'index')); diff --git a/controllers/product_attachments_controller.php b/controllers/product_attachments_controller.php new file mode 100644 index 00000000..beb00128 --- /dev/null +++ b/controllers/product_attachments_controller.php @@ -0,0 +1,46 @@ +params['named']['productid'])) { + $productid = $this->params['named']['productid']; + $this->set('product', $this->ProductAttachment->Product->findById($productid)); + } + + if (!$productid && empty($this->data)) { + $this->Session->setFlash(__('Invalid Product ID', true)); + $this->redirect(array('controller'=>'Products', 'action'=>'index')); + } + + if (!empty($this->data) && + is_uploaded_file($this->data['ProductAttachment']['File']['tmp_name'])) { + $fileData = fread(fopen($this->data['ProductAttachment']['File']['tmp_name'], "r"), + $this->data['ProductAttachment']['File']['size']); + + $this->data['ProductAttachment']['name'] = $this->data['ProductAttachment']['File']['name']; + $this->data['ProductAttachment']['type'] = $this->data['ProductAttachment']['File']['type']; + $this->data['ProductAttachment']['size'] = $this->data['ProductAttachment']['File']['size']; + $this->data['ProductAttachment']['data'] = $fileData; + + $this->ProductAttachment->save($this->data); + + $this->redirect(array('controller' => 'products', 'action' => 'view/'.$productid)); + } + } + + + function download($id) { + Configure::write('debug', 0); + $file = $this->ProductAttachment->findById($id); + header('Content-type: ' . $file['ProductAttachment']['type']); + header('Content-length: ' . $file['ProductAttachment']['size']); + header('Content-Disposition: attachment; filename="'.$file['ProductAttachment']['name'].'"'); + echo $file['ProductAttachment']['data']; + exit(); + } + + +} diff --git a/controllers/products_controller.php b/controllers/products_controller.php index 8c459bda..ca1a7367 100755 --- a/controllers/products_controller.php +++ b/controllers/products_controller.php @@ -2,7 +2,8 @@ class ProductsController extends AppController { var $name = 'Products'; - var $helpers = array('Html', 'Form'); + var $components = array('RequestHandler'); + var $helpers = array('Html', 'Form', 'Ajax', 'Number'); function index() { $this->Product->recursive = 0; @@ -15,6 +16,8 @@ class ProductsController extends AppController { $this->redirect(array('action'=>'index')); } $this->set('product', $this->Product->read(null, $id)); + $this->set('files', $this->Product->ProductAttachment->findAllByProductId($id)); + $this->set('number_of_files', $this->Product->ProductAttachment->find('count', array('conditions' => array('ProductAttachment.product_id'=>$id)))); } function add() { diff --git a/models/product.php b/models/product.php index 2ea42d28..5358cc14 100755 --- a/models/product.php +++ b/models/product.php @@ -4,7 +4,7 @@ class Product extends AppModel { var $name = 'Product'; - var $hasMany = array('ProductOption'); + var $hasMany = array('ProductOption', 'ProductAttachment'); //The Associations below have been created with all possible keys, those that are not needed can be removed var $belongsTo = array( diff --git a/models/product_attachment.php b/models/product_attachment.php new file mode 100644 index 00000000..c94f51ec --- /dev/null +++ b/models/product_attachment.php @@ -0,0 +1,17 @@ + array('className' => 'Product', + 'foreignKey' => 'product_id', + 'conditions' => '', + 'fields' => '', + 'order' => '' + ) + ); + +} +?> \ No newline at end of file diff --git a/vendors/shells/vault.php b/vendors/shells/vault.php index 85660944..5d39d324 100644 --- a/vendors/shells/vault.php +++ b/vendors/shells/vault.php @@ -41,37 +41,44 @@ class VaultShell extends Shell { $this->data['Email']['body'] = ""; $this->data['Email']['plainbody'] = ""; $structure = imap_fetchstructure($mbox, $i); + $attachments = 1; if (empty($structure->parts)) { /* A single part message. No attachments and is plain text */ $this->data['Email']['body'] = imap_body($mbox, $i); } else { - $attachments = $this->fetchBodyAttachments($mbox, $i, $temp_filename, $email_dir); - foreach ($attachments as $attachment) { - if($attachment['type'] == 'text/html') { //Assuming All HTML attachments are the body of the email - - $filecontents = file_get_contents($email_dir.'/'.$attachment['name']); - $size = filesize($email_dir.'/'.$attachment['name']); - $this->data['Email']['body'] .= $filecontents; - - + $attachments = $this->fetchBodyAttachments($mbox, $i, $temp_filename, $email_dir); + if($attachments != 1) { + foreach ($attachments as $attachment) { + if($attachment['type'] == 'text/html') { //Assuming All HTML attachments are the body of the email + if(file_exists($email_dir.'/'.$attachment['name'])) { + $filecontents = file_get_contents($email_dir.'/'.$attachment['name']); + $size = filesize($email_dir.'/'.$attachment['name']); + $this->data['Email']['body'] .= $filecontents; + } + + } + if($attachment['type'] == 'text/plain') { //Found plain text + if(file_exists($email_dir.'/'.$attachment['name'])) { + $filecontents = file_get_contents($email_dir.'/'.$attachment['name']); + $size = filesize($email_dir.'/'.$attachment['name']); + $this->data['Email']['plainbody'] .= $filecontents; + } + + } + } + } - if($attachment['type'] == 'text/plain') { //Found plain text - $filecontents = file_get_contents($email_dir.'/'.$attachment['name']); - $size = filesize($email_dir.'/'.$attachment['name']); - $this->data['Email']['plainbody'] .= $filecontents; - - - } } - - } //Sanitize::clean($this->data); + if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") ) { if($this->Email->save($this->data)) { $email_id = $this->Email->id; - if(isset($attachments)) { + if($attachments != 1) { foreach ($attachments as $attachment) { + if(file_exists($email_dir.'/'.$attachment['name']) != FALSE) { + if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') && ($attachment['type'] != 'multipart/alternative') ) { $this->EmailAttachment->create(); @@ -89,6 +96,7 @@ class VaultShell extends Shell { } } } + } echo "Email stored in the DB under enquiry ".$enquiry['Enquiry']['title']." Will be moved to the stored folder\n"; if($testing == 0) { //Testing Mode. Don't actually move these emails unless we're in production. @@ -97,19 +105,24 @@ class VaultShell extends Shell { - if(isset($attachments)) { + if($attachments != 1) { $this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachments); } } + else { echo 'Unable to save the Email\n'; } } else { + echo "Unable to find either HTML or Plaintext body to this email. Ignoring it"; + } + + } else { /* Can't find a valid-looking CMC Enquiry Number. Move the message to the discarded folder * I may change this to simply delete the emails. This will do for now, but it's doubling up on the storage for useless files. * */ @@ -142,22 +155,28 @@ function fetchBodyAttachments($mailbox, $msg_number, $filename, $email_dir) { $email_file = $email_dir.'/'.$filename; imap_savebody($mailbox, $email_file, $msg_number); - $command = "ripmime -i $email_file -d $email_dir -v --verbose-contenttype --paranoid --prefix $msg_number"; + $command = "/usr/local/bin/ripmime -i $email_file -d $email_dir -v --verbose-contenttype --paranoid --prefix $msg_number"; $output = array(); - exec($command, $output); + exec($command, $output, $status); /* Check the $output array and find the filenames of the attachments */ - $attachments = array(); - for($i=0, $j=0; $i< count($output); $i++, $j++) { - $words = explode(' ', $output[$i]); - $type = explode('=', $words[1]); - $name = explode('=', $words[2]); - $attachments[$j]['type'] = $type[1]; - $attachments[$j]['name'] = $name[1]; - echo "in message number $msg_number: found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n"; - } -return $attachments; + if($status == 0) { + $attachments = array(); + + for($i=0, $j=0; $i< count($output); $i++, $j++) { + $words = explode(' ', $output[$i]); + $type = explode('=', $words[1]); + $name = explode('=', $words[2]); + $attachments[$j]['type'] = $type[1]; + $attachments[$j]['name'] = $name[1]; + echo "in message number $msg_number: found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n"; + } + return $attachments; + } + else { + return 1; + } } diff --git a/views/elements/enquiry_table.ctp b/views/elements/enquiry_table.ctp index 68aa7501..785952d7 100644 --- a/views/elements/enquiry_table.ctp +++ b/views/elements/enquiry_table.ctp @@ -105,10 +105,10 @@ foreach ($enquiries as $enquiry):
| + | + | + | + | + | + |
|---|---|---|---|---|---|
| nice($file['ProductAttachment']['created']);?> | +link($file['ProductAttachment']['name'], array('controller'=>'product_attachments', 'action' => 'download/', $file['ProductAttachment']['id']));?> | +image('pdf_type.png'); + } + else if($file['ProductAttachment']['type'] == 'application/msword') { + echo $html->image('document_type.png'); + } + else if($file['ProductAttachment']['type'] == 'message/rfc822') { + echo $html->image('message_type.png'); + } + else if($file['ProductAttachment']['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'); + } + ?> | +toReadableSize($file['ProductAttachment']['size']);?> | ++ | + link(__('View', true), array('controller'=> 'product_attachments', 'action'=>'download/', $file['ProductAttachment']['id'])); ?> + | +
Developed by Karl Cordes
+Copyright (c) 2009 Karl Cordes +CMC Technologies Pty Ltd (CMC), and any future CMC subsidiary companies, have a licence to use this software. +Modifications are permitted for internal CMC use only. +Redistribution of any part of the software is strictly prohibited. +This software uses other software packages: CakePHP and mySQL. These software packages have their own licence and redistribution terms that are not affected by this licence. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +diff --git a/views/product_attachments/add.ctp b/views/product_attachments/add.ctp new file mode 100644 index 00000000..6312e5e7 --- /dev/null +++ b/views/product_attachments/add.ctp @@ -0,0 +1,14 @@ +create('ProductAttachment', array('action' => 'add/productid:'.$product['Product']['id'], 'type' => 'file')); + echo ''; +?> + diff --git a/views/product_options/add.ctp b/views/product_options/add.ctp index 64c9607f..9612f586 100644 --- a/views/product_options/add.ctp +++ b/views/product_options/add.ctp @@ -7,6 +7,12 @@ echo $form->input('title'); echo $form->input('description'); echo $form->input('cost_price'); + echo $form->input('our_discount'); + echo $form->input('packing_each'); + echo $form->input('shipping_weight_each'); + echo $form->input('shipping_cost_each'); + echo $form->input('duty'); + echo $form->input('sell_price_each'); ?> end('Submit');?> diff --git a/views/product_options/edit.ctp b/views/product_options/edit.ctp index d75c6b1c..e32b97d3 100644 --- a/views/product_options/edit.ctp +++ b/views/product_options/edit.ctp @@ -8,6 +8,12 @@ echo $form->input('title'); echo $form->input('description'); echo $form->input('cost_price'); + echo $form->input('our_discount'); + echo $form->input('packing_each'); + echo $form->input('shipping_weight_each'); + echo $form->input('shipping_cost_each'); + echo $form->input('duty'); + echo $form->input('sell_price_each'); ?> end('Submit');?> diff --git a/views/product_options/index.ctp b/views/product_options/index.ctp index 94415deb..3dbbfd4b 100644 --- a/views/product_options/index.ctp +++ b/views/product_options/index.ctp @@ -13,6 +13,12 @@ echo $paginator->counter(array(