Going into the vault to fix it up
This commit is contained in:
parent
11e240238c
commit
5622d8b94c
|
|
@ -25,7 +25,7 @@ class QuotesController extends AppController {
|
|||
|
||||
|
||||
$quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id),
|
||||
'order' => array('LineItem.item_number ASC'))
|
||||
'order' => array('LineItem.item_number ASC'))
|
||||
);
|
||||
|
||||
$this->set('customer', $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']));
|
||||
|
|
@ -116,7 +116,7 @@ class QuotesController extends AppController {
|
|||
|
||||
|
||||
function pdf($id = null) {
|
||||
//Configure::write('debug',0);
|
||||
//Configure::write('debug',0);
|
||||
if(!$id) {
|
||||
$this->Session->setFlash(__('Invalid Quote', true));
|
||||
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
|
||||
|
|
@ -127,7 +127,7 @@ class QuotesController extends AppController {
|
|||
|
||||
|
||||
$quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id),
|
||||
'order' => array('LineItem.item_number ASC'))
|
||||
'order' => array('LineItem.item_number ASC'))
|
||||
);
|
||||
|
||||
$user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id'])));
|
||||
|
|
@ -163,15 +163,15 @@ class QuotesController extends AppController {
|
|||
}
|
||||
|
||||
$commercialDetails = array (
|
||||
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
|
||||
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
|
||||
'dateIssued' => $quote['Quote']['date_issued'],
|
||||
'validFor' => $quote['Quote']['days_valid'],
|
||||
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
|
||||
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
|
||||
'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
|
||||
'gst' => strtoupper($gstPhrase),
|
||||
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
|
||||
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
|
||||
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
|
||||
'dateIssued' => $quote['Quote']['date_issued'],
|
||||
'validFor' => $quote['Quote']['days_valid'],
|
||||
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
|
||||
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
|
||||
'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
|
||||
'gst' => strtoupper($gstPhrase),
|
||||
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
|
||||
|
||||
|
||||
|
||||
|
|
@ -198,7 +198,93 @@ class QuotesController extends AppController {
|
|||
}
|
||||
|
||||
|
||||
function ajaxpdf() {
|
||||
function ajaxpdf($id = null) {
|
||||
//Configure::write('debug',0);
|
||||
if(empty($this->data)) {
|
||||
$this->Session->setFlash(__('Invalid Quote', true));
|
||||
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
|
||||
}
|
||||
else {
|
||||
$id = $this->data['Quote']['id'];
|
||||
|
||||
$quote = $this->Quote->findById($id);
|
||||
//$customer = $this->Quote->Enquiry->Customer->read(null, $quote['Enquiry']['customer_id']);
|
||||
$enquiry = $this->Quote->Enquiry->find('first', array('conditions' => array('Enquiry.id' => $quote['Quote']['enquiry_id'])));
|
||||
|
||||
|
||||
$quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id),
|
||||
'order' => array('LineItem.item_number ASC'))
|
||||
);
|
||||
|
||||
$user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id'])));
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Call the commercial Comments. Need to have already figured out what page to do this on..
|
||||
*
|
||||
* * Passing a data structure in the following format.
|
||||
*
|
||||
* $details = array(
|
||||
* 'deliveryTime' => (String) eg. 2-3
|
||||
* 'paymentTerms => (String) eg. 100% PAYMENT WITH ORDER || NET 30 DAYS FOR APPROVED ACCOUNTS
|
||||
* 'dateIssued' => (String) eg. 2009-05-20
|
||||
* 'daysValid' => (Int) eg. 30
|
||||
* 'deliveryPoint' => (String) eg. EX-CMC Technologies, NSW. || EX-SUPPLIER NAME
|
||||
* 'exchangeRate' => (String) eg. FIXED
|
||||
* 'customsDuty' => (String) eg. NIL || 5%
|
||||
* 'gst' => (String) eg. 10% EXTRA || Not Applicable for Export
|
||||
* 'salesEngineer' => (String) eg. Karl Cordes || Con Carpis || Kenan Fernandes etc
|
||||
* );
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
if($enquiry['Enquiry']['gst'] == 1) {
|
||||
$gstPhrase = "10% EXTRA";
|
||||
}
|
||||
else {
|
||||
$gstPhrase = "Not Applicable for Export";
|
||||
}
|
||||
|
||||
$commercialDetails = array (
|
||||
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
|
||||
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
|
||||
'dateIssued' => $quote['Quote']['date_issued'],
|
||||
'validFor' => $quote['Quote']['days_valid'],
|
||||
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
|
||||
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
|
||||
'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
|
||||
'gst' => strtoupper($gstPhrase),
|
||||
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
);
|
||||
|
||||
$this->set('commercialDetails', $commercialDetails);
|
||||
|
||||
//debug($quote);
|
||||
//debug($commercialDetails);
|
||||
|
||||
|
||||
|
||||
$this->set('quote', $quote);
|
||||
$this->set('enquiry', $enquiry);
|
||||
|
||||
|
||||
|
||||
$this->set('products', $quoteProducts);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function BROKENajaxpdf() {
|
||||
Configure::write('debug',0);
|
||||
|
||||
if($this->RequestHandler->isAjax()) {
|
||||
|
|
@ -211,7 +297,7 @@ class QuotesController extends AppController {
|
|||
|
||||
|
||||
$quoteProducts = $this->Quote->LineItem->find('all', array('recursive' => 0, 'conditions' => array('LineItem.quote_id' => $id),
|
||||
'order' => array('LineItem.item_number ASC'))
|
||||
'order' => array('LineItem.item_number ASC'))
|
||||
);
|
||||
|
||||
$user = $this->Quote->Enquiry->User->find('first', array('conditions' => array('User.id' => $enquiry['Enquiry']['user_id'])));
|
||||
|
|
@ -224,15 +310,15 @@ class QuotesController extends AppController {
|
|||
}
|
||||
|
||||
$commercialDetails = array (
|
||||
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
|
||||
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
|
||||
'dateIssued' => $quote['Quote']['date_issued'],
|
||||
'validFor' => $quote['Quote']['days_valid'],
|
||||
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
|
||||
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
|
||||
'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
|
||||
'gst' => strtoupper($gstPhrase),
|
||||
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
|
||||
'deliveryTime' => strtoupper($quote['Quote']['delivery_time']),
|
||||
'paymentTerms' => strtoupper($quote['Quote']['payment_terms']),
|
||||
'dateIssued' => $quote['Quote']['date_issued'],
|
||||
'validFor' => $quote['Quote']['days_valid'],
|
||||
'deliveryPoint' => strtoupper($quote['Quote']['delivery_point']),
|
||||
'exchangeRate' => strtoupper($quote['Quote']['exchange_rate']),
|
||||
'customsDuty' => strtoupper($quote['Quote']['customs_duty']),
|
||||
'gst' => strtoupper($gstPhrase),
|
||||
'salesEngineer' => strtoupper($user['User']['first_name'].' '.$user['User']['last_name'])
|
||||
|
||||
|
||||
|
||||
|
|
@ -260,70 +346,70 @@ class QuotesController extends AppController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Revise an existing quote.
|
||||
*
|
||||
* Might make this AJAXy in the future. For now, I just want to make it work
|
||||
* Process is:
|
||||
* 1.Check what Quote ID we're revising
|
||||
* 2. Find that quote
|
||||
* 3. find the Line Items in this quote
|
||||
* 4. Make a new Quote.
|
||||
* 5. Make new copies of the line items referring to that quote
|
||||
* 6. Make copies of the QuotePages
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Revise an existing quote.
|
||||
*
|
||||
* Might make this AJAXy in the future. For now, I just want to make it work
|
||||
* Process is:
|
||||
* 1.Check what Quote ID we're revising
|
||||
* 2. Find that quote
|
||||
* 3. find the Line Items in this quote
|
||||
* 4. Make a new Quote.
|
||||
* 5. Make new copies of the line items referring to that quote
|
||||
* 6. Make copies of the QuotePages
|
||||
*
|
||||
*/
|
||||
function revise($id) {
|
||||
|
||||
if(!$id) {
|
||||
if(!$id) {
|
||||
$this->Session->setFlash(__('Invalid Quote', true));
|
||||
$this->redirect(array('controller'=>'enquiries', 'action'=>'index'));
|
||||
}
|
||||
else {
|
||||
$quoteid = $id;
|
||||
$quote = $this->Quote->read(null,$id);
|
||||
$enquiryid = $quote['Quote']['enquiry_id'];
|
||||
else {
|
||||
$quoteid = $id;
|
||||
$quote = $this->Quote->read(null,$id);
|
||||
$enquiryid = $quote['Quote']['enquiry_id'];
|
||||
|
||||
|
||||
$number_of_revisions = $this->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
|
||||
$number_of_revisions++;
|
||||
|
||||
//debug($quote);
|
||||
//debug($quote);
|
||||
|
||||
// $this->Quote->create();
|
||||
$this->data['Quote'] = $quote['Quote'];
|
||||
$this->data['Quote']['id'] = null;
|
||||
$this->data['Quote']['created'] = null;
|
||||
$this->data['Quote']['modified'] = null;
|
||||
$this->data['Quote']['revision'] = $number_of_revisions;
|
||||
// $this->Quote->create();
|
||||
$this->data['Quote'] = $quote['Quote'];
|
||||
$this->data['Quote']['id'] = null;
|
||||
$this->data['Quote']['created'] = null;
|
||||
$this->data['Quote']['modified'] = null;
|
||||
$this->data['Quote']['revision'] = $number_of_revisions;
|
||||
$this->data['Quote']['enquiry_id'] = $enquiryid;
|
||||
|
||||
foreach($quote['LineItem'] as $item) {
|
||||
$item['id'] = null;
|
||||
$item['quote_id'] = null;
|
||||
$this->data['LineItem'][] = $item;
|
||||
}
|
||||
foreach($quote['LineItem'] as $item) {
|
||||
$item['id'] = null;
|
||||
$item['quote_id'] = null;
|
||||
$this->data['LineItem'][] = $item;
|
||||
}
|
||||
|
||||
foreach($quote['QuotePage'] as $page) {
|
||||
$page['id'] = null;
|
||||
$page['quote_id'] = null;
|
||||
$this->data['QuotePage'][] = $page;
|
||||
}
|
||||
foreach($quote['QuotePage'] as $page) {
|
||||
$page['id'] = null;
|
||||
$page['quote_id'] = null;
|
||||
$this->data['QuotePage'][] = $page;
|
||||
}
|
||||
|
||||
//debug($this->data);
|
||||
//debug($this->data);
|
||||
|
||||
if ($this->Quote->saveAll($this->data)) {
|
||||
$quoteid = $this->Quote->id;
|
||||
$this->Session->setFlash(__('Created Quote Revision '.$number_of_revisions, true));
|
||||
$this->redirect(array('action'=>'view/'.$quoteid));
|
||||
}
|
||||
if ($this->Quote->saveAll($this->data)) {
|
||||
$quoteid = $this->Quote->id;
|
||||
$this->Session->setFlash(__('Created Quote Revision '.$number_of_revisions, true));
|
||||
$this->redirect(array('action'=>'view/'.$quoteid));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
548
vendors/shells/vault.php
vendored
548
vendors/shells/vault.php
vendored
|
|
@ -1,363 +1,363 @@
|
|||
<?
|
||||
App::import('Sanitize');
|
||||
class VaultShell extends Shell {
|
||||
/* vault.php - To be run in CLI via Cron. Fetches the mail from a certain mailbox, searches for a CMC Technologies Enquiry Numbeer
|
||||
/* vault.php - To be run in CLI via Cron. Fetches the mail from a certain mailbox, searches for a CMC Technologies Enquiry Numbeer
|
||||
* 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');
|
||||
var $uses = array('Enquiry', 'Email', 'EmailAttachment');
|
||||
|
||||
function main() {
|
||||
/******************************************************
|
||||
function main() {
|
||||
/******************************************************
|
||||
* Config Variables
|
||||
* *****************************************************/
|
||||
$testing = 0; //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/working';
|
||||
$temp_filename = 'temp.eml';
|
||||
$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/working';
|
||||
$temp_filename = 'temp.eml';
|
||||
|
||||
if($testing == 1) {
|
||||
$email_dir = '/var/www/quotenik1.2/app/emails/working';
|
||||
}
|
||||
if($testing == 1) {
|
||||
$email_dir = '/Users/karlcordes/Sites/app/emails/working';
|
||||
}
|
||||
|
||||
$mbox = imap_open("{neptune:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
|
||||
$MC = imap_check($mbox);
|
||||
$number_of_messages = $MC->Nmsgs;
|
||||
$mbox = imap_open("{mail.cmctechnologies.com.au:143}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
|
||||
$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);
|
||||
}
|
||||
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);
|
||||
|
||||
/* 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";
|
||||
$enquiry = $this->checkIfValidEnquiry($message['subject'], $testing);
|
||||
if($enquiry) {
|
||||
|
||||
echo "Checking msg number: $i \tSubject: ".$message['subject']."\n";
|
||||
$enquiry = $this->checkIfValidEnquiry($message['subject'], $testing);
|
||||
if($enquiry) {
|
||||
//Process it and store the message and its attachments.
|
||||
//Process it and store the message and its attachments.
|
||||
|
||||
$this->Email->create();
|
||||
$this->data['Email']['enquiry_id'] = $enquiry['Enquiry']['id'];
|
||||
$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, $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;
|
||||
}
|
||||
$this->Email->create();
|
||||
$this->data['Email']['enquiry_id'] = $enquiry['Enquiry']['id'];
|
||||
$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, $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
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Sanitize::clean($this->data);
|
||||
if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") || ($attachments != 1) ) {
|
||||
//Sanitize::clean($this->data);
|
||||
if( ($this->data['Email']['body'] != "") || ($this->data['Email']['plainbody'] != "") || ($attachments != 1) ) {
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
||||
if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') &&
|
||||
($attachment['type'] != 'multipart/alternative') ) {
|
||||
$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']['data'] = file_get_contents($email_dir.'/'.$attachment['name']);
|
||||
if ($this->EmailAttachment->save($this->data)) {
|
||||
echo "Saved file successfully to database\n";
|
||||
}
|
||||
else {
|
||||
echo "Something went wrong saving the file to the DB\n";
|
||||
}
|
||||
}
|
||||
//unlink($email_dir.'/'.$attachment['name']); #Delete this attachment now we're done with it.
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "Email stored in the DB under enquiry ".$enquiry['Enquiry']['title']." Will be moved to the stored folder\n";
|
||||
if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') &&
|
||||
($attachment['type'] != 'multipart/alternative') ) {
|
||||
$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']['data'] = file_get_contents($email_dir.'/'.$attachment['name']);
|
||||
if ($this->EmailAttachment->save($this->data)) {
|
||||
echo "Saved file successfully to database\n";
|
||||
}
|
||||
else {
|
||||
echo "Something went wrong saving the file to the DB\n";
|
||||
}
|
||||
}
|
||||
//unlink($email_dir.'/'.$attachment['name']); #Delete this attachment now we're done with it.
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "Email stored in the DB under enquiry ".$enquiry['Enquiry']['title']." Will be moved to the stored folder\n";
|
||||
|
||||
$stored_msgs[] = imap_uid($mbox,$i);
|
||||
$stored_msgs[] = imap_uid($mbox,$i);
|
||||
|
||||
|
||||
|
||||
|
||||
// if($attachments != 1) {
|
||||
// $this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachments);
|
||||
//unlink($email_dir.'/'.$temp_filename); #remove the temp email. start again
|
||||
// }
|
||||
// if($attachments != 1) {
|
||||
// $this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachments);
|
||||
//unlink($email_dir.'/'.$temp_filename); #remove the temp email. start again
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
echo 'Unable to save the Email\n';
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo 'Unable to save the Email\n';
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
echo "Unable to find either HTML or Plaintext body to this email. Ignoring it";
|
||||
}
|
||||
} 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
|
||||
} 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.
|
||||
* */
|
||||
|
||||
$discarded_msgs[] = imap_uid($mbox,$i);
|
||||
$discarded_msgs[] = imap_uid($mbox,$i);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->rmdirr($email_dir); //delete all attachments from the working directory. Easiest way to stop random files persisting
|
||||
$this->rmdirr($email_dir); //delete all attachments from the working directory. Easiest way to stop random files persisting
|
||||
|
||||
|
||||
|
||||
if(isset($stored_msgs)) {
|
||||
if(isset($stored_msgs)) {
|
||||
|
||||
foreach($stored_msgs as $msg) {
|
||||
$no = imap_msgno($mbox,$msg);
|
||||
foreach($stored_msgs as $msg) {
|
||||
$no = imap_msgno($mbox,$msg);
|
||||
|
||||
$this_header = imap_headerinfo($mbox, $i);
|
||||
$this_header = imap_headerinfo($mbox, $i);
|
||||
|
||||
echo "Going to store: $no\t $msg\t".$this_header->subject."\n";
|
||||
if($testing == 0) {
|
||||
imap_mail_move($mbox, $no, 'INBOX/Stored');
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($discarded_msgs)) {
|
||||
foreach($discarded_msgs as $msg) {
|
||||
$no = imap_msgno($mbox,$msg);
|
||||
echo "Going to store: $no\t $msg\t".$this_header->subject."\n";
|
||||
if($testing == 0) {
|
||||
imap_mail_move($mbox, $no, 'INBOX/Stored');
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($discarded_msgs)) {
|
||||
foreach($discarded_msgs as $msg) {
|
||||
$no = imap_msgno($mbox,$msg);
|
||||
|
||||
echo "Going to discard: $no\t $msg\t".$this_header->subject."\n";
|
||||
if($testing == 0) {
|
||||
imap_mail_move($mbox,$no, 'INBOX/Discarded');
|
||||
}
|
||||
}
|
||||
echo "Going to discard: $no\t $msg\t".$this_header->subject."\n";
|
||||
if($testing == 0) {
|
||||
imap_mail_move($mbox,$no, 'INBOX/Discarded');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* Finished working with the IMAP server. Make the changes and close the connection */
|
||||
imap_expunge($mbox);
|
||||
imap_close($mbox);
|
||||
}
|
||||
/* Finished working with the IMAP server. Make the changes and close the connection */
|
||||
imap_expunge($mbox);
|
||||
imap_close($mbox);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* Fetches the body and attachments from a MIME encoded email. Uses ripmime to do the decoding
|
||||
*
|
||||
*/
|
||||
*/
|
||||
|
||||
function fetchBodyAttachments($mailbox, $msg_number, $filename, $email_dir) {
|
||||
function fetchBodyAttachments($mailbox, $msg_number, $filename, $email_dir) {
|
||||
|
||||
$email_file = $email_dir.'/'.$filename;
|
||||
imap_savebody($mailbox, $email_file, $msg_number);
|
||||
$command = "/usr/local/bin/ripmime -i $email_file -d $email_dir -v --verbose-contenttype --paranoid --prefix $msg_number";
|
||||
$email_file = $email_dir.'/'.$filename;
|
||||
imap_savebody($mailbox, $email_file, $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, $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]);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* clearEmailyAttachmentDirs($email_dir, $filename, $attachment_dir, $attachments)
|
||||
/* clearEmailyAttachmentDirs($email_dir, $filename, $attachment_dir, $attachments)
|
||||
*
|
||||
* Deletes $email_dir/$filename.eml and the attachments specified by $attachments
|
||||
* */
|
||||
function clearEmailAttachmentDirs($email_dir, $filename, $attachments) {
|
||||
unlink("$email_dir/$filename");
|
||||
foreach ($attachments as $attachment) {
|
||||
unlink($email_dir.'/'.$attachment['name']);
|
||||
}
|
||||
}
|
||||
function clearEmailAttachmentDirs($email_dir, $filename, $attachments) {
|
||||
unlink("$email_dir/$filename");
|
||||
foreach ($attachments as $attachment) {
|
||||
unlink($email_dir.'/'.$attachment['name']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getMessage($mbox, $msgnumber, $headers) {
|
||||
function getMessage($mbox, $msgnumber, $headers) {
|
||||
|
||||
$subject = $headers->subject;
|
||||
$subject = iconv_mime_decode($subject, 0, "ISO-8859-1");
|
||||
$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;
|
||||
$subject = $headers->subject;
|
||||
$subject = iconv_mime_decode($subject, 0, "ISO-8859-1");
|
||||
$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) {
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
function checkIfValidEnquiry($subject, $testing) {
|
||||
$subject = iconv_mime_decode($subject, 0, "ISO-8859-1");
|
||||
function checkIfValidEnquiry($subject, $testing) {
|
||||
$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];
|
||||
echo $fetched_enquirynumber."\n";
|
||||
$enquiry = $this->Enquiry->findByTitle($fetched_enquirynumber);
|
||||
if($enquiry) {
|
||||
return $enquiry;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(isset($output[0])) { //Found a valid-looking Enquiry Number
|
||||
$fetched_enquirynumber = $output[0];
|
||||
echo $fetched_enquirynumber."\n";
|
||||
$enquiry = $this->Enquiry->findByTitle($fetched_enquirynumber);
|
||||
if($enquiry) {
|
||||
return $enquiry;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a file, or a folder and its contents (recursive algorithm)
|
||||
*
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version 1.0.3
|
||||
* @link http://aidanlister.com/repos/v/function.rmdirr.php
|
||||
* @param string $dirname Directory to delete
|
||||
* @return bool Returns TRUE on success, FALSE on failure
|
||||
*/
|
||||
function rmdirr($dirname) {
|
||||
// Sanity check
|
||||
if (!file_exists($dirname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Simple delete for a file
|
||||
if (is_file($dirname) || is_link($dirname)) {
|
||||
return unlink($dirname);
|
||||
}
|
||||
|
||||
// Loop through the folder
|
||||
$dir = dir($dirname);
|
||||
while (false !== $entry = $dir->read()) {
|
||||
// Skip pointers
|
||||
if ($entry == '.' || $entry == '..') {
|
||||
continue;
|
||||
}
|
||||
// Recurse
|
||||
$this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
|
||||
}
|
||||
// Clean up
|
||||
$dir->close();
|
||||
return; //removing the last recursion - should remove the deletion of the last directory I hope. Lazy hack using this but should work
|
||||
//rmdir($dirname);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a file, or a folder and its contents (recursive algorithm)
|
||||
*
|
||||
* @author Aidan Lister <aidan@php.net>
|
||||
* @version 1.0.3
|
||||
* @link http://aidanlister.com/repos/v/function.rmdirr.php
|
||||
* @param string $dirname Directory to delete
|
||||
* @return bool Returns TRUE on success, FALSE on failure
|
||||
*/
|
||||
function rmdirr($dirname)
|
||||
{
|
||||
// Sanity check
|
||||
if (!file_exists($dirname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Simple delete for a file
|
||||
if (is_file($dirname) || is_link($dirname)) {
|
||||
return unlink($dirname);
|
||||
}
|
||||
|
||||
// Loop through the folder
|
||||
$dir = dir($dirname);
|
||||
while (false !== $entry = $dir->read()) {
|
||||
// Skip pointers
|
||||
if ($entry == '.' || $entry == '..') {
|
||||
continue;
|
||||
}
|
||||
// Recurse
|
||||
$this->rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
|
||||
}
|
||||
// Clean up
|
||||
$dir->close();
|
||||
return; //removing the last recursion - should remove the deletion of the last directory I hope. Lazy hack using this but should work
|
||||
//rmdir($dirname);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
|||
6
vendors/xtcpdf.php
vendored
6
vendors/xtcpdf.php
vendored
|
|
@ -421,12 +421,12 @@ ENDPRODUCT;
|
|||
|
||||
$heightNeeded = $this->getLastH();
|
||||
$this->MultiCell($qtyColwidth, $heightNeeded, "", 1, "C", 1, 0);
|
||||
$this->MultiCell($descColwidth, $heightNeeded, $principleName, 1, "C", 1, 0);
|
||||
$this->MultiCell($descColwidth, $heightNeeded, "", 1, "C", 1, 0); //Principle Name used to go here.
|
||||
$this->MultiCell($unitpriceColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 0);
|
||||
$this->MultiCell($totalPricColwidth, $heightNeeded, $currency['iso4217'], 1, "C", 1, 1);
|
||||
|
||||
|
||||
echo "<h2>$pageNo</h2>";
|
||||
// echo "<h2>$pageNo</h2>";
|
||||
// print_r($page);
|
||||
|
||||
//Start Printing Product cells, until we run out of room. Then continue on the next page
|
||||
|
|
@ -471,7 +471,7 @@ ENDPRODUCT;
|
|||
|
||||
|
||||
|
||||
debug($products);
|
||||
//debug($products);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
<h3><?php __($quote['Quote']['line_item_count'].' Items in this Quote');?></h3>
|
||||
<table cellpadding = "0" cellspacing = "0" id= "quoteTable" class="quoteproducts" ">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -120,6 +120,21 @@ $tcpdf->Output($output_dir.$filename, 'F');
|
|||
|
||||
echo "<br> Wrote: ".$output_dir.$filename;
|
||||
|
||||
App::import('Vendor', 'xfpdi');
|
||||
|
||||
|
||||
//$newpdf = new concat_pdf();
|
||||
|
||||
$newpdf = new XFPDI();
|
||||
|
||||
$newpdf->SetMargins(2, 2);
|
||||
$newpdf->setPrintHeader(false);
|
||||
$newpdf->setPrintFooter(false);
|
||||
|
||||
$newpdf->setFiles(array($output_dir.$filename, $output_dir.'CMC_terms_and_conditions2006_A4.pdf'));
|
||||
$newpdf->concat();
|
||||
$newpdf->Output($output_dir.$filename, "F");
|
||||
|
||||
//$tcpdf->Output('cmcquote.pdf', 'D');
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
|
||||
|
||||
<div class="quoteproducts">
|
||||
<h3><?php __($quote['Quote']['line_item_count'].' Items in this Quote');?></h3>
|
||||
|
||||
|
||||
<div id="productTable"></div>
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ foreach ($quote['QuotePage'] as $quotePage):
|
|||
<button id="addLineItem">Add a Product to this Quote</button>
|
||||
|
||||
<button id="generatePDF">Generate a PDF of this Quote</button>
|
||||
<li><?php echo $html->link(__('Generate PDF from this Quote', true), array('controller'=>'quotes', 'action'=>'pdf', $quote['Quote']['id'])); ?></li>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -85,8 +85,6 @@ $(function() {
|
|||
function getPrincipleProducts() {
|
||||
$.post("/products/getPrincipleProducts", $("#LineItemPrincipleId").serialize(), function(data) {
|
||||
|
||||
|
||||
|
||||
$('#productBox').html(data);
|
||||
$("#LineItemProductId").change(getProductOptions);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue