From 643d5c1a1d7868ebccc984147be1afe12708f046 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Tue, 11 Jan 2011 19:52:52 +1100 Subject: [PATCH] Refactoring the vault --- .gitignore | 1 + controllers/documents_controller.php | 0 controllers/invoices_controller.php | 0 controllers/issue_actions_controller.php | 0 controllers/issues_controller.php | 0 controllers/jobs_controller.php | 0 controllers/line_items_controller.php | 0 controllers/pages_controller.php | 0 controllers/purchase_orders_controller.php | 0 models/document.php | 0 models/invoice.php | 0 models/job.php | 0 models/line_item.php | 0 models/page.php | 0 models/purchase_order.php | 0 models/user.php | 67 +-- vendors/shells/firstpass.php | 0 vendors/shells/users_migrate.php | 52 +- vendors/shells/vault.php | 542 ++++++++++-------- vendors/shells/vault_two.php | 0 .../doc/classtrees_com-tecnick-tcpdf.html | 0 .../tcpdf/doc/com-tecnick-tcpdf/TCPDF.html | 0 .../doc/com-tecnick-tcpdf/TCPDFBarcode.html | 0 .../doc/com-tecnick-tcpdf/_barcodes.php.html | 0 .../_config---tcpdf_config.php.html | 0 .../com-tecnick-tcpdf/_htmlcolors.php.html | 0 .../doc/com-tecnick-tcpdf/_tcpdf.php.html | 0 .../com-tecnick-tcpdf/_unicode_data.php.html | 0 vendors/tcpdf/doc/elementindex.html | 0 .../doc/elementindex_com-tecnick-tcpdf.html | 0 vendors/tcpdf/doc/errors.html | 0 vendors/tcpdf/doc/index.html | 0 vendors/tcpdf/doc/li_com-tecnick-tcpdf.html | 0 vendors/tcpdf/doc/media/background.png | Bin vendors/tcpdf/doc/media/empty.png | Bin vendors/tcpdf/doc/media/style.css | 0 vendors/xfpdi.php | 0 views/countries/complete_country.ctp | 0 views/currencies/jsonlist.ctp | 0 views/customers/csv.ctp | 0 views/customers/similar_customers.ctp | 0 views/documents/add.ctp | 0 views/documents/edit.ctp | 0 views/documents/index.ctp | 0 views/documents/view.ctp | 0 views/documents/viewDEFAULT.ctp | 0 views/elements/info_table.ctp | 0 views/elements/isEmptyDate.ctp | 0 views/elements/issue_priority_select.ctp | 0 views/enquiries/do_search.ctp | 0 views/enquiries/search.ctp | 0 views/invoices/add.ctp | 0 views/invoices/edit.ctp | 0 views/invoices/index.ctp | 0 views/invoices/view.ctp | 0 views/jobs/add.ctp | 0 views/jobs/edit.ctp | 0 views/jobs/index.ctp | 0 views/jobs/view.ctp | 0 views/layouts/csv.ctp | 0 views/line_items/view_table.ctp | 0 views/pages/add.ctp | 0 views/pages/edit.ctp | 0 views/pages/index.ctp | 0 views/pages/view.ctp | 0 views/products/.LCKindex.ctp~ | 0 views/products/get_principle_products.ctp | 0 views/products/get_product_options.ctp | 0 views/products/view_principle.ctp | 0 views/purchase_orders/add.ctp | 0 views/purchase_orders/edit.ctp | 0 views/purchase_orders/index.ctp | 0 views/purchase_orders/view.ctp | 0 views/quotes/ajaxpdf.ctp | 0 views/statuses/status_list.ctp | 0 webroot/js/addLineItem.js | 0 webroot/js/add_costing.js | 0 webroot/js/addjob.js | 0 webroot/js/addpurchaseorder.js | 0 webroot/js/autocomplete-customer.js | 0 webroot/js/costing_dialog.js | 0 webroot/js/editLineItem.js | 0 webroot/js/email_table.js | 0 webroot/js/enquiry_table.js | 0 webroot/js/findcustomer.js | 0 webroot/js/globalsearch.js | 0 webroot/js/jobindex.js | 0 webroot/js/jquery.form.js | 0 webroot/js/jquery.jeditable.mini.js | 0 webroot/js/jquery.validate.min.js | 0 webroot/js/lineItemPriceNoCosting.js | 0 webroot/js/menu.js | 0 webroot/js/product-model-number-builder.js | 0 webroot/js/search.js | 0 94 files changed, 382 insertions(+), 280 deletions(-) mode change 100644 => 100755 controllers/documents_controller.php mode change 100644 => 100755 controllers/invoices_controller.php mode change 100644 => 100755 controllers/issue_actions_controller.php mode change 100644 => 100755 controllers/issues_controller.php mode change 100644 => 100755 controllers/jobs_controller.php mode change 100644 => 100755 controllers/line_items_controller.php mode change 100644 => 100755 controllers/pages_controller.php mode change 100644 => 100755 controllers/purchase_orders_controller.php mode change 100644 => 100755 models/document.php mode change 100644 => 100755 models/invoice.php mode change 100644 => 100755 models/job.php mode change 100644 => 100755 models/line_item.php mode change 100644 => 100755 models/page.php mode change 100644 => 100755 models/purchase_order.php mode change 100644 => 100755 vendors/shells/firstpass.php mode change 100644 => 100755 vendors/shells/users_migrate.php mode change 100644 => 100755 vendors/shells/vault_two.php mode change 100644 => 100755 vendors/tcpdf/doc/classtrees_com-tecnick-tcpdf.html mode change 100644 => 100755 vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html mode change 100644 => 100755 vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDFBarcode.html mode change 100644 => 100755 vendors/tcpdf/doc/com-tecnick-tcpdf/_barcodes.php.html mode change 100644 => 100755 vendors/tcpdf/doc/com-tecnick-tcpdf/_config---tcpdf_config.php.html mode change 100644 => 100755 vendors/tcpdf/doc/com-tecnick-tcpdf/_htmlcolors.php.html mode change 100644 => 100755 vendors/tcpdf/doc/com-tecnick-tcpdf/_tcpdf.php.html mode change 100644 => 100755 vendors/tcpdf/doc/com-tecnick-tcpdf/_unicode_data.php.html mode change 100644 => 100755 vendors/tcpdf/doc/elementindex.html mode change 100644 => 100755 vendors/tcpdf/doc/elementindex_com-tecnick-tcpdf.html mode change 100644 => 100755 vendors/tcpdf/doc/errors.html mode change 100644 => 100755 vendors/tcpdf/doc/index.html mode change 100644 => 100755 vendors/tcpdf/doc/li_com-tecnick-tcpdf.html mode change 100644 => 100755 vendors/tcpdf/doc/media/background.png mode change 100644 => 100755 vendors/tcpdf/doc/media/empty.png mode change 100644 => 100755 vendors/tcpdf/doc/media/style.css mode change 100644 => 100755 vendors/xfpdi.php mode change 100644 => 100755 views/countries/complete_country.ctp mode change 100644 => 100755 views/currencies/jsonlist.ctp mode change 100644 => 100755 views/customers/csv.ctp mode change 100644 => 100755 views/customers/similar_customers.ctp mode change 100644 => 100755 views/documents/add.ctp mode change 100644 => 100755 views/documents/edit.ctp mode change 100644 => 100755 views/documents/index.ctp mode change 100644 => 100755 views/documents/view.ctp mode change 100644 => 100755 views/documents/viewDEFAULT.ctp mode change 100644 => 100755 views/elements/info_table.ctp mode change 100644 => 100755 views/elements/isEmptyDate.ctp mode change 100644 => 100755 views/elements/issue_priority_select.ctp mode change 100644 => 100755 views/enquiries/do_search.ctp mode change 100644 => 100755 views/enquiries/search.ctp mode change 100644 => 100755 views/invoices/add.ctp mode change 100644 => 100755 views/invoices/edit.ctp mode change 100644 => 100755 views/invoices/index.ctp mode change 100644 => 100755 views/invoices/view.ctp mode change 100644 => 100755 views/jobs/add.ctp mode change 100644 => 100755 views/jobs/edit.ctp mode change 100644 => 100755 views/jobs/index.ctp mode change 100644 => 100755 views/jobs/view.ctp mode change 100644 => 100755 views/layouts/csv.ctp mode change 100644 => 100755 views/line_items/view_table.ctp mode change 100644 => 100755 views/pages/add.ctp mode change 100644 => 100755 views/pages/edit.ctp mode change 100644 => 100755 views/pages/index.ctp mode change 100644 => 100755 views/pages/view.ctp mode change 100644 => 100755 views/products/.LCKindex.ctp~ mode change 100644 => 100755 views/products/get_principle_products.ctp mode change 100644 => 100755 views/products/get_product_options.ctp mode change 100644 => 100755 views/products/view_principle.ctp mode change 100644 => 100755 views/purchase_orders/add.ctp mode change 100644 => 100755 views/purchase_orders/edit.ctp mode change 100644 => 100755 views/purchase_orders/index.ctp mode change 100644 => 100755 views/purchase_orders/view.ctp mode change 100644 => 100755 views/quotes/ajaxpdf.ctp mode change 100644 => 100755 views/statuses/status_list.ctp mode change 100644 => 100755 webroot/js/addLineItem.js mode change 100644 => 100755 webroot/js/add_costing.js mode change 100644 => 100755 webroot/js/addjob.js mode change 100644 => 100755 webroot/js/addpurchaseorder.js mode change 100644 => 100755 webroot/js/autocomplete-customer.js mode change 100644 => 100755 webroot/js/costing_dialog.js mode change 100644 => 100755 webroot/js/editLineItem.js mode change 100644 => 100755 webroot/js/email_table.js mode change 100644 => 100755 webroot/js/enquiry_table.js mode change 100644 => 100755 webroot/js/findcustomer.js mode change 100644 => 100755 webroot/js/globalsearch.js mode change 100644 => 100755 webroot/js/jobindex.js mode change 100644 => 100755 webroot/js/jquery.form.js mode change 100644 => 100755 webroot/js/jquery.jeditable.mini.js mode change 100644 => 100755 webroot/js/jquery.validate.min.js mode change 100644 => 100755 webroot/js/lineItemPriceNoCosting.js mode change 100644 => 100755 webroot/js/menu.js mode change 100644 => 100755 webroot/js/product-model-number-builder.js mode change 100644 => 100755 webroot/js/search.js diff --git a/.gitignore b/.gitignore index 0b0d4abd..96c43853 100755 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ tmp/* *.swp *.swo vendors/tcpdf/cache/* +tests/* diff --git a/controllers/documents_controller.php b/controllers/documents_controller.php old mode 100644 new mode 100755 diff --git a/controllers/invoices_controller.php b/controllers/invoices_controller.php old mode 100644 new mode 100755 diff --git a/controllers/issue_actions_controller.php b/controllers/issue_actions_controller.php old mode 100644 new mode 100755 diff --git a/controllers/issues_controller.php b/controllers/issues_controller.php old mode 100644 new mode 100755 diff --git a/controllers/jobs_controller.php b/controllers/jobs_controller.php old mode 100644 new mode 100755 diff --git a/controllers/line_items_controller.php b/controllers/line_items_controller.php old mode 100644 new mode 100755 diff --git a/controllers/pages_controller.php b/controllers/pages_controller.php old mode 100644 new mode 100755 diff --git a/controllers/purchase_orders_controller.php b/controllers/purchase_orders_controller.php old mode 100644 new mode 100755 diff --git a/models/document.php b/models/document.php old mode 100644 new mode 100755 diff --git a/models/invoice.php b/models/invoice.php old mode 100644 new mode 100755 diff --git a/models/job.php b/models/job.php old mode 100644 new mode 100755 diff --git a/models/line_item.php b/models/line_item.php old mode 100644 new mode 100755 diff --git a/models/page.php b/models/page.php old mode 100644 new mode 100755 diff --git a/models/purchase_order.php b/models/purchase_order.php old mode 100644 new mode 100755 diff --git a/models/user.php b/models/user.php index fa82aa97..efd32d93 100755 --- a/models/user.php +++ b/models/user.php @@ -1,13 +1,12 @@ array( 'rule' => 'unique', @@ -19,41 +18,35 @@ class User extends AppModel { 'email' => array('email'), // 'job_title' => array('custom') ); - */ - //The Associations below have been created with all possible keys, those that are not needed can be removed - var $hasMany = array( - 'Enquiry' => array('className' => 'Enquiry', - 'foreignKey' => 'user_id', - 'dependent' => false, - 'conditions' => '', - 'fields' => '', - 'order' => '', - 'limit' => '', - 'offset' => '', - 'exclusive' => '', - 'finderQuery' => '', - 'counterQuery' => '' - ) - ); + */ + //The Associations below have been created with all possible keys, those that are not needed can be removed + var $hasMany = array( + 'Enquiry' => array('className' => 'Enquiry', + 'foreignKey' => 'user_id', + 'dependent' => false, + 'conditions' => '', + 'fields' => '', + 'order' => '', + 'limit' => '', + 'offset' => '', + 'exclusive' => '', + 'finderQuery' => '', + 'counterQuery' => '' + ) + ); - var $actsAs = array('Acl' => array('requester')); + var $belongsTo = array( + 'Principle' => array('className'=>'Principle', + 'foreignKey' =>'principle_id', + + ), + 'Customer' => array('className'=>'Customer', + 'foreignKey' =>'customer_id', + + ) + ); - function parentNode() { - if (!$this->id && empty($this->data)) { - return null; - } - $data = $this->data; - if (empty($this->data)) { - $data = $this->read(); - } - if (!$data['User']['group_id']) { - return null; - } - else { - return array('Group' => array('id' => $data['User']['group_id'])); - } - } diff --git a/vendors/shells/firstpass.php b/vendors/shells/firstpass.php old mode 100644 new mode 100755 diff --git a/vendors/shells/users_migrate.php b/vendors/shells/users_migrate.php old mode 100644 new mode 100755 index 777966ea..1e331a3d --- a/vendors/shells/users_migrate.php +++ b/vendors/shells/users_migrate.php @@ -24,8 +24,56 @@ class UsersMigrateShell extends Shell { $this->printCountLine($usersCount, 'Users'); $totalCount = $principleContactsCount + $contactsCount + $usersCount; - $this->printCountLine($totalCount, 'Total Users after migration'); - + $this->printCountLine($totalCount, 'Total Users we should have after migration'); + + $principleContacts = $this->PrincipleContact->find('all'); + $newPrincipleUsers = array(); + foreach($principleContacts as $contact) { + $newUser = array(); + + $newUser['User']['principle_id'] = $contact['PrincipleContact']['principle_id']; + $newUser['User']['type'] = 'principle'; + $newUser['User']['username'] = trim($contact['PrincipleContact']['first_name']).' '.trim($contact['PrincipleContact']['last_name']); + $newUser['User']['first_name'] = $contact['PrincipleContact']['first_name']; + $newUser['User']['last_name'] = $contact['PrincipleContact']['last_name']; + $newUser['User']['email'] = $contact['PrincipleContact']['email']; + $newUser['User']['phone'] = $contact['PrincipleContact']['phone']; + $newUser['User']['fax'] = $contact['PrincipleContact']['fax']; + $newUser['User']['notes'] = $contact['PrincipleContact']['notes']; + $newUser['User']['job_title'] = $contact['PrincipleContact']['job_title']; + $this->User->create(); + //$newPrincipleUsers[] = $newUser; + $this->User->save($newUser); + } + + $customerContacts = $this->Contact->find('all'); + $newCustomerUsers = array(); + foreach($customerContacts as $contact) { + $newUser = array(); + + $newUser['User']['customer_id'] = $contact['Contact']['customer_id']; + $newUser['User']['type'] = 'contact'; + $newUser['User']['username'] = trim($contact['Contact']['first_name']).' '.trim($contact['Contact']['last_name']); + $newUser['User']['first_name'] = $contact['Contact']['first_name']; + $newUser['User']['last_name'] = $contact['Contact']['last_name']; + $newUser['User']['email'] = $contact['Contact']['email']; + $newUser['User']['phone'] = $contact['Contact']['phone']; + $newUser['User']['fax'] = $contact['Contact']['fax']; + $newUser['User']['notes'] = $contact['Contact']['notes']; + $newUser['User']['job_title'] = $contact['Contact']['job_title']; + $newUser['User']['phone_extension'] = $contact['Contact']['phone_extension']; + $newUser['User']['direct_phone'] = $contact['Contact']['direct_phone']; + $this->User->create(); + //$newPrincipleUsers[] = $newUser; + $this->User->save($newUser); + } + $newCount = $this->User->find('count'); + $this->printCountLine($newCount, 'Now have Total Users after migration'); + + //print_r($newPrincipleUsers); + + //$this->User->save($newPrincipleUsers); + } diff --git a/vendors/shells/vault.php b/vendors/shells/vault.php index b0b04c3c..179e630b 100755 --- a/vendors/shells/vault.php +++ b/vendors/shells/vault.php @@ -5,215 +5,215 @@ class VaultShell extends Shell { * then loads the data into the 'emails' table and the attachments in the 'email_attachments' table. * Emails are discared or moved to a subfolder once processed */ - + var $uses = array('Enquiry', 'Email', 'EmailAttachment'); function main() { - /****************************************************** + /****************************************************** * Config Variables * *****************************************************/ - $testing = 1; //Whether to actually move the emails. 1=test, 0=production - /* Setup Connection to the IMAP server */ - $username = 'vault'; - $password = 'xjdYOsmJWc37'; /* The password for the account to be checked */ - $email_dir = '/var/www/cakephp/app/emails'; + $testing = 1; //Whether to actually move the emails. 1=test, 0=production + /* Setup Connection to the IMAP server */ + $username = 'vault'; + $password = 'xjdYOsmJWc37'; /* The password for the account to be checked */ + $email_dir = '/var/www/cakephp/app/emails'; - $ripmime_path = '/usr/local/bin/ripmime'; + $ripmime_path = '/usr/local/bin/ripmime'; - if($testing == 1) { - $email_dir = '/Users/karlcordes/Sites/quotenik/app/emails'; - $ripmime_path = '/opt/local/bin/ripmime'; - $mbox = imap_open("{192.168.0.8:143}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); - } - else { - $mbox = imap_open("{192.168.0.8:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); - } + if($testing == 1) { + $email_dir = '/Users/karlcordes/Sites/quotenik/app/emails'; + $ripmime_path = '/opt/local/bin/ripmime'; + $mbox = imap_open("{192.168.0.8:143}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); + } + else { + $mbox = imap_open("{192.168.0.8:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); + } - $MC = imap_check($mbox); - $number_of_messages = $MC->Nmsgs; + $MC = imap_check($mbox); + $number_of_messages = $MC->Nmsgs; - echo "Number of messages to Process ".$number_of_messages."\n"; + echo "Number of messages to Process ".$number_of_messages."\n"; - if($number_of_messages == 0) { - exit(0); - } + if($number_of_messages == 0) { + exit(0); + } - $enquiries = $this->Enquiry->find('all', array('recursive'=>0,'fields' => array('Enquiry.title', 'Enquiry.id'))); + $enquiries = $this->Enquiry->find('all', array('recursive'=>0,'fields' => array('Enquiry.title', 'Enquiry.id'))); - foreach ($enquiries as $enq) { - $enqNumber = $enq['Enquiry']['title']; - $id = $enq['Enquiry']['id']; - $enquiryList[$enqNumber] = $id; - } + foreach ($enquiries as $enq) { + $enqNumber = $enq['Enquiry']['title']; + $id = $enq['Enquiry']['id']; + $enquiryList[$enqNumber] = $id; + } - $storedArray = array(); - $discardArray = array(); + $storedArray = array(); + $discardArray = array(); - //exit(0); + //exit(0); - /* Loop through the messages and sort them into ones to be processed or discarded */ - - - for($i=1; $i <= $number_of_messages; $i++) { - $this_header = imap_headerinfo($mbox, $i); - $message = $this->getMessage($mbox, $i, $this_header); - - //echo "Checking msg number: $i\tSubject: ".$message['subject']."\n"; - echo "Checking msg number: $i\n"; - - $enqID = $this->checkIfValidEnquiry($message['subject'], $enquiryList); + /* Loop through the messages and sort them into ones to be processed or discarded */ - if($enqID != false) { - echo "Found Message with enquiry ID: ".$enqID." Processing.\n"; - //Process it and store the message and its attachments. + for($i=1; $i <= $number_of_messages; $i++) { + $this_header = imap_headerinfo($mbox, $i); + $message = $this->getMessage($mbox, $i, $this_header); - //Generate a Uniqid for this email. - // $uniqid = $this->getUniqId($email_dir); + //echo "Checking msg number: $i\tSubject: ".$message['subject']."\n"; + echo "Checking msg number: $i\n"; - $this->Email->create(); - $this->data['Email']['enquiry_id'] = $enqID; - $this->data['Email']['to'] = $message['to']; - $this->data['Email']['cc'] = $message['cc']; - $this->data['Email']['from'] = $message['from']; - $this->data['Email']['date'] = $message['date']; - $this->data['Email']['subject'] = $message['subject']; - $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, $email_dir, $uniqid, $ripmime_path); - 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.'/'.$uniqid.'/'.$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; - } - - } - } - - } - } + $enqID = $this->checkIfValidEnquiry($message['subject'], $enquiryList); - if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") || ($attachments != 1) ) { + if($enqID != false) { + echo "Found Message with enquiry ID: ".$enqID." Processing.\n"; + //Process it and store the message and its attachments. - if($this->Email->save($this->data)) { - $email_id = $this->Email->id; - if($attachments != 1) { - foreach ($attachments as $attachment) { - if(file_exists($email_dir.'/'.$attachment['name']) != FALSE) { + //Generate a Uniqid for this email. + // $uniqid = $this->getUniqId($email_dir); - if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') && - ($attachment['type'] != 'multipart/alternative') && - ($attachment['type'] != 'multipart/report') && - ($attachment['type'] != 'text/plain') && - ($attachment['type'] != 'text/rfc822-headers') && - ($attachment['type'] != 'message/delivery-status') + $this->Email->create(); + $this->data['Email']['enquiry_id'] = $enqID; + $this->data['Email']['to'] = $message['to']; + $this->data['Email']['cc'] = $message['cc']; + $this->data['Email']['from'] = $message['from']; + $this->data['Email']['date'] = $message['date']; + $this->data['Email']['subject'] = $message['subject']; + $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, $email_dir, $uniqid, $ripmime_path); + 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.'/'.$uniqid.'/'.$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; + } + + } + } + + } + } - ) { - $this->EmailAttachment->create(); - $this->data['EmailAttachment']['email_id'] = $email_id; - $this->data['EmailAttachment']['name'] = $attachment['name']; - $this->data['EmailAttachment']['type'] = $attachment['type']; - $this->data['EmailAttachment']['size'] = filesize($email_dir.'/'.$attachment['name']); - $this->data['EmailAttachment']['filename'] = $email_dir.'/'.$attachment['name']; - if ($this->EmailAttachment->save($this->data)) { - echo "Saved file successfully to database\n"; - } - else { - echo "Error saving the file to the DB\n"; - } - } + if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") || ($attachments != 1) ) { - } - } - } - echo "Email stored in the DB under enquiry ID".$enqID." Message will now be deleted\n"; + if($this->Email->save($this->data)) { + $email_id = $this->Email->id; + if($attachments != 1) { + foreach ($attachments as $attachment) { + if(file_exists($email_dir.'/'.$attachment['name']) != FALSE) { - //$storedArray[] = $i; + if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') && + ($attachment['type'] != 'multipart/alternative') && + ($attachment['type'] != 'multipart/report') && + ($attachment['type'] != 'text/plain') && + ($attachment['type'] != 'text/rfc822-headers') && + ($attachment['type'] != 'message/delivery-status') - } - 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 + ) { + $this->EmailAttachment->create(); + $this->data['EmailAttachment']['email_id'] = $email_id; + $this->data['EmailAttachment']['name'] = $attachment['name']; + $this->data['EmailAttachment']['type'] = $attachment['type']; + $this->data['EmailAttachment']['size'] = filesize($email_dir.'/'.$attachment['name']); + $this->data['EmailAttachment']['filename'] = $email_dir.'/'.$attachment['name']; + if ($this->EmailAttachment->save($this->data)) { + echo "Saved file successfully to database\n"; + } + else { + echo "Error saving the file to the DB\n"; + } + } + + } + } + } + echo "Email stored in the DB under enquiry ID".$enqID." Message will now be deleted\n"; + + //$storedArray[] = $i; + + + } + 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. * */ - // $discardArray[] = $i; + // $discardArray[] = $i; - } + } - } + } - /* Finished working with the IMAP server. Make the changes and close the connection */ + /* Finished working with the IMAP server. Make the changes and close the connection */ - //if($testing == 0) { + //if($testing == 0) { - echo "Tidying up now. Moving messages to Stored or Discarded\n"; + echo "Tidying up now. Moving messages to Stored or Discarded\n"; - reset($discardArray); - reset($storedArray); + reset($discardArray); + reset($storedArray); - $numberToStore = count($storedArray); - $numberToDiscard= count($discardArray); + $numberToStore = count($storedArray); + $numberToDiscard= count($discardArray); - if($numberToStore > 0) { - echo "Got $numberToStore messages to store\n"; - $storeSet = implode(",", $storedArray); - imap_mail_move($mbox, $storeSet, 'INBOX/Stored'); - } + if($numberToStore > 0) { + echo "Got $numberToStore messages to store\n"; + $storeSet = implode(",", $storedArray); + imap_mail_move($mbox, $storeSet, 'INBOX/Stored'); + } - if($numberToDiscard > 0) { - echo "Going to discard $numberToDiscard messages\n"; - $discardSet = implode(",",$discardArray); + if($numberToDiscard > 0) { + echo "Going to discard $numberToDiscard messages\n"; + $discardSet = implode(",",$discardArray); - imap_mail_move($mbox, $discardSet, 'INBOX/Discarded'); - } + imap_mail_move($mbox, $discardSet, 'INBOX/Discarded'); + } @@ -222,10 +222,10 @@ class VaultShell extends Shell { - //} + //} - imap_expunge($mbox); - imap_close($mbox); + imap_expunge($mbox); + imap_close($mbox); } @@ -239,137 +239,197 @@ class VaultShell extends Shell { - $email_file = $email_dir.'/'.$uniqid.'.eml'; - imap_savebody($mailbox, $email_file, $msg_number); - $command = "$ripmime_path -i $email_file -d $email_dir --prefix --paranoid -v --verbose-contenttype"; + $email_file = $email_dir.'/'.$uniqid.'.eml'; + imap_savebody($mailbox, $email_file, $msg_number); + $command = "$ripmime_path -i $email_file -d $email_dir --prefix --paranoid -v --verbose-contenttype"; - $output = array(); - exec($command, $output, $status); + $output = array(); + exec($command, $output, $status); - /* Check the $output array and find the filenames of the attachments */ + /* Check the $output array and find the filenames of the attachments */ - if($status == 0) { - $attachments = array(); + 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]); + for($i=0, $j=0; $i< count($output); $i++, $j++) { + $words = explode(' ', $output[$i]); + $type = explode('=', $words[1]); + $name = explode('=', $words[2]); - if($type[1] == "" || $name[1] == "") { - continue; - } + if($type[1] == "" || $name[1] == "") { + continue; + } - $attachments[$j]['type'] = $type[1]; - $attachments[$j]['name'] = $name[1]; - //echo "in message number $msg_number ($uniqid): found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n"; - } - unlink($email_file); - return $attachments; + $attachments[$j]['type'] = $type[1]; + $attachments[$j]['name'] = $name[1]; + //echo "in message number $msg_number ($uniqid): found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n"; + } + unlink($email_file); + return $attachments; - } - else { - unlink($email_file); - return 1; - } + } + else { + unlink($email_file); + return 1; + } } function getMessage($mbox, $msgnumber, $headers) { - $subject = $headers->subject; - //$subject = iconv_mime_decode($subject, 0, "ISO-8859-1//IGNORE"); - // $subject = mb_convert_encoding($subject, "ISO-8859-1"); - // $subject = mb_convert_encoding($subject, "UTF-8"); - $subject = mb_decode_mimeheader($subject); + $subject = $headers->subject; + //$subject = iconv_mime_decode($subject, 0, "ISO-8859-1//IGNORE"); + // $subject = mb_convert_encoding($subject, "ISO-8859-1"); + // $subject = mb_convert_encoding($subject, "UTF-8"); + $subject = mb_decode_mimeheader($subject); - $date = $headers->date; - $recipients = $this->getRecipients($headers); - $message['subject'] = $subject; - $message['date'] = $date; - $message['to'] = $recipients['to']; - $message['from'] = $recipients['from']; - $message['cc'] = $recipients['cc']; - return $message; + $date = $headers->date; + $recipients = $this->getRecipients($headers); + $message['subject'] = $subject; + $message['date'] = $date; + $message['to'] = $recipients['to']; + $message['from'] = $recipients['from']; + $message['cc'] = $recipients['cc']; + return $message; } /* get Recipients from the headers of an email */ function getRecipients($headers) { - $recipients = array(); - $recipients['to'] = ""; - $recipients['from'] = ""; - $recipients['cc'] = ""; + $recipients = array(); + $recipients['to'] = ""; + $recipients['from'] = ""; + $recipients['cc'] = ""; - if(isset($headers->to)) { - $to = $headers->to; - if(count($to) > 0) { - foreach ($to as $id => $object) { - $recipients['to'] .= "$object->mailbox@$object->host "; - } - } - } - if(isset($headers->cc)) { - $cc = $headers->cc; - if(count($cc) > 0) { - foreach ($cc as $id => $object) { - $recipients['cc'] .= "$object->mailbox@$object->host "; - } + if(isset($headers->to)) { + $to = $headers->to; + if(count($to) > 0) { + foreach ($to as $id => $object) { + $recipients['to'] .= "$object->mailbox@$object->host "; + } + } + } + if(isset($headers->cc)) { + $cc = $headers->cc; + if(count($cc) > 0) { + foreach ($cc as $id => $object) { + $recipients['cc'] .= "$object->mailbox@$object->host "; + } - } - } + } + } - if(isset($headers->from)) { - $from = $headers->from; - if(count($from) > 0) { - foreach ($from as $id => $object) { - $recipients['from'] .= "$object->mailbox@$object->host"; - } - } - } + if(isset($headers->from)) { + $from = $headers->from; + if(count($from) > 0) { + foreach ($from as $id => $object) { + $recipients['from'] .= "$object->mailbox@$object->host"; + } + } + } - return $recipients; + return $recipients; } function getBody($mbox, $msgnumber) { - $structure = imap_fetchstructure($mbox, $msgnumber); - if (!empty($structure->parts)) { - $body = $this->getParts($structure->parts, $mbox, $msgnumber); - } - else { - $body = imap_body($mbox, $msgnumber); /* Or get the plaintext */ - } - return $body; + $structure = imap_fetchstructure($mbox, $msgnumber); + if (!empty($structure->parts)) { + $body = $this->getParts($structure->parts, $mbox, $msgnumber); + } + else { + $body = imap_body($mbox, $msgnumber); /* Or get the plaintext */ + } + return $body; } function checkIfValidEnquiry($subject, &$enqList) { - $subject = iconv_mime_decode($subject, 0, "ISO-8859-1"); + $subject = iconv_mime_decode($subject, 0, "ISO-8859-1"); - $output = array(); + $output = array(); // $decoded_subject = iconv_mime_decode($subject, 2, "ISO-8859-1"); - preg_match("/CMC\d+([NVQWSOT]|ACT|NT)E\d+-\d+/", $subject, $output); + preg_match("/CMC\d+([NVQWSOT]|ACT|NT)E\d+-\d+/", $subject, $output); - if(isset($output[0])) { //Found a valid-looking Enquiry Number - $fetched_enquirynumber = $output[0]; + if(isset($output[0])) { //Found a valid-looking Enquiry Number + $fetched_enquirynumber = $output[0]; - if(array_key_exists($fetched_enquirynumber, $enqList)) { //check if it actually exists. - $enqid = $enqList[$fetched_enquirynumber]; + if(array_key_exists($fetched_enquirynumber, $enqList)) { //check if it actually exists. + $enqid = $enqList[$fetched_enquirynumber]; - return $enqid; - } - else { - return false; - } - } - else { - return false; - } + return $enqid; + } + else { + return false; + } + } + else { + return false; + } } + /** + * Adapted from + * http://www.electrictoolbox.com/function-extract-email-attachments-php-imap/ + * @param $connection + * @param $message_number + * @return + */ + function extract_attachments($connection, $message_number) { + + $attachments = array(); + $structure = imap_fetchstructure($connection, $message_number); + + if(isset($structure->parts) && count($structure->parts)) { + + for($i = 0; $i < count($structure->parts); $i++) { + + $attachments[$i] = array( + 'is_attachment' => false, + 'filename' => '', + 'name' => '', + 'attachment' => '' + ); + + if($structure->parts[$i]->ifparameters) { + foreach($structure->parts[$i]->dparameters as $object) { + if(strtolower($object->attribute) == 'filename') { + $attachments[$i]['is_attachment'] = true; + $attachments[$i]['filename'] = $object->value; + } + } + } + + if($structure->parts[$i]->ifparameters) { + foreach($structure->parts[$i]->parameters as $object) { + if(strtolower($object->attribute) == 'name') { + $attachments[$i]['is_attachment'] = true; + $attachments[$i]['name'] = $object->value; + } + } + } + + if($attachments[$i]['is_attachment']) { + $attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1); + if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 + $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); + } + elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE + $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); + } + } + + } + + } + + return $attachments; + + } + + } ?> diff --git a/vendors/shells/vault_two.php b/vendors/shells/vault_two.php old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/classtrees_com-tecnick-tcpdf.html b/vendors/tcpdf/doc/classtrees_com-tecnick-tcpdf.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html b/vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDF.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDFBarcode.html b/vendors/tcpdf/doc/com-tecnick-tcpdf/TCPDFBarcode.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/com-tecnick-tcpdf/_barcodes.php.html b/vendors/tcpdf/doc/com-tecnick-tcpdf/_barcodes.php.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/com-tecnick-tcpdf/_config---tcpdf_config.php.html b/vendors/tcpdf/doc/com-tecnick-tcpdf/_config---tcpdf_config.php.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/com-tecnick-tcpdf/_htmlcolors.php.html b/vendors/tcpdf/doc/com-tecnick-tcpdf/_htmlcolors.php.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/com-tecnick-tcpdf/_tcpdf.php.html b/vendors/tcpdf/doc/com-tecnick-tcpdf/_tcpdf.php.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/com-tecnick-tcpdf/_unicode_data.php.html b/vendors/tcpdf/doc/com-tecnick-tcpdf/_unicode_data.php.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/elementindex.html b/vendors/tcpdf/doc/elementindex.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/elementindex_com-tecnick-tcpdf.html b/vendors/tcpdf/doc/elementindex_com-tecnick-tcpdf.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/errors.html b/vendors/tcpdf/doc/errors.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/index.html b/vendors/tcpdf/doc/index.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/li_com-tecnick-tcpdf.html b/vendors/tcpdf/doc/li_com-tecnick-tcpdf.html old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/media/background.png b/vendors/tcpdf/doc/media/background.png old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/media/empty.png b/vendors/tcpdf/doc/media/empty.png old mode 100644 new mode 100755 diff --git a/vendors/tcpdf/doc/media/style.css b/vendors/tcpdf/doc/media/style.css old mode 100644 new mode 100755 diff --git a/vendors/xfpdi.php b/vendors/xfpdi.php old mode 100644 new mode 100755 diff --git a/views/countries/complete_country.ctp b/views/countries/complete_country.ctp old mode 100644 new mode 100755 diff --git a/views/currencies/jsonlist.ctp b/views/currencies/jsonlist.ctp old mode 100644 new mode 100755 diff --git a/views/customers/csv.ctp b/views/customers/csv.ctp old mode 100644 new mode 100755 diff --git a/views/customers/similar_customers.ctp b/views/customers/similar_customers.ctp old mode 100644 new mode 100755 diff --git a/views/documents/add.ctp b/views/documents/add.ctp old mode 100644 new mode 100755 diff --git a/views/documents/edit.ctp b/views/documents/edit.ctp old mode 100644 new mode 100755 diff --git a/views/documents/index.ctp b/views/documents/index.ctp old mode 100644 new mode 100755 diff --git a/views/documents/view.ctp b/views/documents/view.ctp old mode 100644 new mode 100755 diff --git a/views/documents/viewDEFAULT.ctp b/views/documents/viewDEFAULT.ctp old mode 100644 new mode 100755 diff --git a/views/elements/info_table.ctp b/views/elements/info_table.ctp old mode 100644 new mode 100755 diff --git a/views/elements/isEmptyDate.ctp b/views/elements/isEmptyDate.ctp old mode 100644 new mode 100755 diff --git a/views/elements/issue_priority_select.ctp b/views/elements/issue_priority_select.ctp old mode 100644 new mode 100755 diff --git a/views/enquiries/do_search.ctp b/views/enquiries/do_search.ctp old mode 100644 new mode 100755 diff --git a/views/enquiries/search.ctp b/views/enquiries/search.ctp old mode 100644 new mode 100755 diff --git a/views/invoices/add.ctp b/views/invoices/add.ctp old mode 100644 new mode 100755 diff --git a/views/invoices/edit.ctp b/views/invoices/edit.ctp old mode 100644 new mode 100755 diff --git a/views/invoices/index.ctp b/views/invoices/index.ctp old mode 100644 new mode 100755 diff --git a/views/invoices/view.ctp b/views/invoices/view.ctp old mode 100644 new mode 100755 diff --git a/views/jobs/add.ctp b/views/jobs/add.ctp old mode 100644 new mode 100755 diff --git a/views/jobs/edit.ctp b/views/jobs/edit.ctp old mode 100644 new mode 100755 diff --git a/views/jobs/index.ctp b/views/jobs/index.ctp old mode 100644 new mode 100755 diff --git a/views/jobs/view.ctp b/views/jobs/view.ctp old mode 100644 new mode 100755 diff --git a/views/layouts/csv.ctp b/views/layouts/csv.ctp old mode 100644 new mode 100755 diff --git a/views/line_items/view_table.ctp b/views/line_items/view_table.ctp old mode 100644 new mode 100755 diff --git a/views/pages/add.ctp b/views/pages/add.ctp old mode 100644 new mode 100755 diff --git a/views/pages/edit.ctp b/views/pages/edit.ctp old mode 100644 new mode 100755 diff --git a/views/pages/index.ctp b/views/pages/index.ctp old mode 100644 new mode 100755 diff --git a/views/pages/view.ctp b/views/pages/view.ctp old mode 100644 new mode 100755 diff --git a/views/products/.LCKindex.ctp~ b/views/products/.LCKindex.ctp~ old mode 100644 new mode 100755 diff --git a/views/products/get_principle_products.ctp b/views/products/get_principle_products.ctp old mode 100644 new mode 100755 diff --git a/views/products/get_product_options.ctp b/views/products/get_product_options.ctp old mode 100644 new mode 100755 diff --git a/views/products/view_principle.ctp b/views/products/view_principle.ctp old mode 100644 new mode 100755 diff --git a/views/purchase_orders/add.ctp b/views/purchase_orders/add.ctp old mode 100644 new mode 100755 diff --git a/views/purchase_orders/edit.ctp b/views/purchase_orders/edit.ctp old mode 100644 new mode 100755 diff --git a/views/purchase_orders/index.ctp b/views/purchase_orders/index.ctp old mode 100644 new mode 100755 diff --git a/views/purchase_orders/view.ctp b/views/purchase_orders/view.ctp old mode 100644 new mode 100755 diff --git a/views/quotes/ajaxpdf.ctp b/views/quotes/ajaxpdf.ctp old mode 100644 new mode 100755 diff --git a/views/statuses/status_list.ctp b/views/statuses/status_list.ctp old mode 100644 new mode 100755 diff --git a/webroot/js/addLineItem.js b/webroot/js/addLineItem.js old mode 100644 new mode 100755 diff --git a/webroot/js/add_costing.js b/webroot/js/add_costing.js old mode 100644 new mode 100755 diff --git a/webroot/js/addjob.js b/webroot/js/addjob.js old mode 100644 new mode 100755 diff --git a/webroot/js/addpurchaseorder.js b/webroot/js/addpurchaseorder.js old mode 100644 new mode 100755 diff --git a/webroot/js/autocomplete-customer.js b/webroot/js/autocomplete-customer.js old mode 100644 new mode 100755 diff --git a/webroot/js/costing_dialog.js b/webroot/js/costing_dialog.js old mode 100644 new mode 100755 diff --git a/webroot/js/editLineItem.js b/webroot/js/editLineItem.js old mode 100644 new mode 100755 diff --git a/webroot/js/email_table.js b/webroot/js/email_table.js old mode 100644 new mode 100755 diff --git a/webroot/js/enquiry_table.js b/webroot/js/enquiry_table.js old mode 100644 new mode 100755 diff --git a/webroot/js/findcustomer.js b/webroot/js/findcustomer.js old mode 100644 new mode 100755 diff --git a/webroot/js/globalsearch.js b/webroot/js/globalsearch.js old mode 100644 new mode 100755 diff --git a/webroot/js/jobindex.js b/webroot/js/jobindex.js old mode 100644 new mode 100755 diff --git a/webroot/js/jquery.form.js b/webroot/js/jquery.form.js old mode 100644 new mode 100755 diff --git a/webroot/js/jquery.jeditable.mini.js b/webroot/js/jquery.jeditable.mini.js old mode 100644 new mode 100755 diff --git a/webroot/js/jquery.validate.min.js b/webroot/js/jquery.validate.min.js old mode 100644 new mode 100755 diff --git a/webroot/js/lineItemPriceNoCosting.js b/webroot/js/lineItemPriceNoCosting.js old mode 100644 new mode 100755 diff --git a/webroot/js/menu.js b/webroot/js/menu.js old mode 100644 new mode 100755 diff --git a/webroot/js/product-model-number-builder.js b/webroot/js/product-model-number-builder.js old mode 100644 new mode 100755 diff --git a/webroot/js/search.js b/webroot/js/search.js old mode 100644 new mode 100755