Vault now runs forever, watching for new files

This commit is contained in:
Karl Cordes 2011-03-21 13:26:07 +11:00
parent b233ead647
commit e370e1f54e
12 changed files with 425 additions and 270 deletions

View file

@ -93,11 +93,27 @@ class EmailsController extends AppController {
return;
}
else {
$fromEmails = $this->Email->find('list', array('fields'=>array('Email.id'), 'recursive'=>0, 'conditions'=>array('Email.user_id'=>$id)));
$recEmails = $this->Email->EmailRecipient->find('all', array('fields'=>array('Email.id'),'recursive'=>0, 'conditions'=>array('EmailRecipient.user_id'=>$id)));
//$this->set('emails', $this->paginate());
$fromMailIDs = $this->Email->find('list', array('conditions'=>array('Email.user_id'=>$id)));
$recMailIDs = $this->Email->EmailRecipient->find('list', array('conditions'=>array('EmailRecipient.user_id'=>$id)));
$this->set('emails', $fromEmails);
$this->set('recEmails', $recEmails);
$allIDs = $fromMailIDs + $recMailIDs;
sort($allIDs);
$this->set('allIDs', $allIDs);
$this->paginate = array(
'conditions' => array('Email.id'=>$allIDs),
'order'=>array('Email.udate DESC')
);
$userMail = $this->paginate('Email');
//$userMail = $this->Email->find('all', array('conditions'=>array('Email.id'=>$allIDs), 'order'=>array('Email.udate DESC')));
$this->set('userMail', $userMail);
}
}

View file

@ -51,5 +51,7 @@ class Email extends AppModel {
}
}
?>

View file

@ -44,338 +44,358 @@ class VaultShell extends Shell {
$processed_dir = '/var/www/cakephp/app/processed_vaultmsgs';
}
$emails = scandir($vault_dir);
$processed = scandir($processed_dir);
$new = array_diff($emails, $processed);
while(true) {
$emails = scandir($vault_dir);
$processed = scandir($processed_dir);
$new = array_diff($emails, $processed);
/* Find the strings we want to look for in the subjects. Build arrays
/* Find the strings we want to look for in the subjects. Build arrays
* using the string as the keys, IDs as the value
*/
*/
$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')));
$invoices = $this->Invoice->find('all', array('recursive'=>0, '
$invoices = $this->Invoice->find('all', array('recursive'=>0, '
fields'=>array('Invoice.id', 'Invoice.title')));
$purchaseOrders = $this->PurchaseOrder->find('all',
array('recursive'=>0,
'fields'=>array('PurchaseOrder.id', 'PurchaseOrder.title')));
$purchaseOrders = $this->PurchaseOrder->find('all',
array('recursive'=>0,
'fields'=>array('PurchaseOrder.id', 'PurchaseOrder.title')));
$users = $this->User->find('all', array('recursive'=>0,
'fields'=>array('User.id', 'User.email')));
$users = $this->User->find('all', array('recursive'=>0,
'fields'=>array('User.id', 'User.email')));
$jobs = $this->Job->find('all', array('recursive'=>0, 'fields'=>array('Job.id', 'Job.title')));
$jobs = $this->Job->find('all', array('recursive'=>0, 'fields'=>array('Job.id', 'Job.title')));
$enquiryMap = $this->makeMap($enquiries,'Enquiry', 'title');
$invoiceMap = $this->makeMap($invoices, 'Invoice', 'title');
$poMap = $this->makeMap($purchaseOrders, 'PurchaseOrder', 'title');
$userMap = $this->makeMap($users, 'User', 'email');
$jobMap = $this->makeMap($jobs, 'Job', 'title');
$enquiryMap = $this->makeMap($enquiries,'Enquiry', 'title');
$invoiceMap = $this->makeMap($invoices, 'Invoice', 'title');
$poMap = $this->makeMap($purchaseOrders, 'PurchaseOrder', 'title');
$userMap = $this->makeMap($users, 'User', 'email');
$jobMap = $this->makeMap($jobs, 'Job', 'title');
/**
* Loop through the messages.
*
* Procedure:
*
* 1. Check to see if the recipients (CC, or to), or Sender is in the $userMap.
* 1a. If one of these is true, we need to capture this email. Else, delete it.
*
* 2. This email is either to/from/CC a user in the system.
* We need to associate it with the right PO/Invoice/Enquiries etc.
* Check the subject for patterns that match Identifiers.
*
*/
foreach($new as $email_filename) {
echo "Handling $email_filename\n";
if( ($email_filename == '.') || ($email_filename == '..') ) {
continue;
}
/**
* Loop through the messages.
*
* Procedure:
*
* 1. Check to see if the recipients (CC, or to), or Sender is in the $userMap.
* 1a. If one of these is true, we need to capture this email. Else, delete it.
*
* 2. This email is either to/from/CC a user in the system.
* We need to associate it with the right PO/Invoice/Enquiries etc.
* Check the subject for patterns that match Identifiers.
*
*/
foreach($new as $email_filename) {
echo "Handling $email_filename\n";
if( ($email_filename == '.') || ($email_filename == '..') ) {
continue;
}
if(!$this->isEmlFile($vault_dir, $email_filename)) {
echo "Incorrect file extension. Skipping this file";
continue;
}
/*if(file_exists($processed_dir."/".$email_filename)) {
/*if(file_exists($processed_dir."/".$email_filename)) {
continue;
}*/
$content = file_get_contents($vault_dir."/".$email_filename);
$content = file_get_contents($vault_dir."/".$email_filename);
if(!$content) {
echo "No Content Found. Ignoring this email\n";
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
die("Unable to make symlink to process this email Critical error: {$email_filename}");
}
else {
continue;
}
}
$content = str_replace("\r", "", $content);
$headers = imap_rfc822_parse_headers($content);
$recipients = $this->getRecipients($headers, true);
$unix_time = strtotime($headers->date); //Used for filing attachments into month-year folders.
//MM-YYYY used For lack of a better option really.
$saveThis = false; //Set to true, if To,From,CC is a Known User.
$fromKnownUser = false;
foreach($recipients['to'] as $email) {
$saveThis = $this->userExists($email, $userMap);
}
foreach($recipients['from'] as $email) {
$saveThis = $this->userExists($email, $userMap);
$fromKnownUser = $saveThis;
}
foreach($recipients['cc'] as $email) {
$saveThis = $this->userExists($email, $userMap);
}
if(!isset($headers->subject)) { //Emails without a subject are not welcome. Skip it.
echo "No Subject Found. Ignoring this email\n";
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
die("Unable to make symlink to process this email Critical error: {$email_filename}");
}
else {
continue;
}
}
$subjDecoded = imap_mime_header_decode($headers->subject);
$foundIdent = false;
foreach($subjDecoded as $sub) {
$found_enquiries = $this->checkValidIdentifier($sub->text, $enquiryMap, 'enquiry');
$foundIdent = $this->foundIdentifier($found_enquiries);
$found_invoices = $this->checkValidIdentifier($sub->text, $invoiceMap, 'invoice');
$foundIdent = $this->foundIdentifier($found_invoices);
$found_pos = $this->checkValidIdentifier($sub->text, $poMap, 'purchaseorder');
$foundIdent = $this->foundIdentifier($found_pos);
$found_jobs = $this->checkValidIdentifier($sub->text, $jobMap, 'job');
$foundIdent = $this->foundIdentifier($found_jobs);
}
//We're going to save this Email.
//Lets grab the attachments (if any) then create the appropiate Objects.
if($fromKnownUser == true || $saveThis == true || $foundIdent == true) {
$recipientsIDs['to'] = array();
$recipientsIDs['from'] = array();
$recipientsIDs['cc'] = array();
/**
* Loop over each recipient email found. Build an array containing the User IDs of that user.
*
* If that email doesn't have a corresponding User ID. We need to create a new User for this email address.
*
*
*/
foreach($recipients as $type => $recipientArray) {
foreach($recipientArray as $recEmail) {
$recEmailLC = strtolower($recEmail);
if(isset($userMap[$recEmailLC])) {
$recipientsIDs[$type][] = $userMap[$recEmailLC]; //Existing User ID.
}
else {
//$recipientsIDs[$type][] = "NEW User: $recEmail"; //Need to make a new user ID.
echo "Making a new User for: '{$recEmailLC}'\n";
$newUser['User'] = array(
'type' => 'contact',
'email' => $recEmailLC,
'by_vault' => 1
);
$this->User->create();
if($this->User->save($newUser, false)) {
$newID = $this->User->id;
echo "New User '{$recEmail}' Added with ID: {$newID}\n";
$recipientsIDs[$type][] = $newID;
//Add it to the userMap
$userMap[$recEmailLC] = $newID;
}
else {
echo "Serious Error: Unable to create user for email '{$recEmailLC}'\n";
continue;
}
}
if(!$content) {
echo "No Content Found. Ignoring this email\n";
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
die("Unable to make symlink to process this email Critical error: {$email_filename}");
}
else {
continue;
}
}
echo "---------START MESSAGE -----------------\n";
echo "Subject: ".$subjDecoded[0]->text."\n";
$content = str_replace("\r", "", $content);
$newEmail = array();
/** Testing creating the Email, Recipient and Attachments */
$newEmail['Email'] = array();
$headers = imap_rfc822_parse_headers($content);
if(isset($recipientsIDs['from'][0])) {
$newEmail['Email']['user_id'] = $recipientsIDs['from'][0]; //We should never have more than one 'from' user ID.
$recipients = $this->getRecipients($headers, true);
$unix_time = strtotime($headers->date); //Used for filing attachments into month-year folders.
//MM-YYYY used For lack of a better option really.
$saveThis = false; //Set to true, if To,From,CC is a Known User.
$fromKnownUser = false;
foreach($recipients['to'] as $email) {
$saveThis = $this->userExists($email, $userMap);
}
else {
print_r($recipientsIDs);
echo "Email has no From Recipient ID. Ignoring this email\n";
$this->makeSymlink($email_filename, $vault_dir, $processed_dir);
continue;
foreach($recipients['from'] as $email) {
$saveThis = $this->userExists($email, $userMap);
$fromKnownUser = $saveThis;
}
foreach($recipients['cc'] as $email) {
$saveThis = $this->userExists($email, $userMap);
}
if(!isset($headers->subject)) { //Emails without a subject are not welcome. Skip it.
echo "No Subject Found. Ignoring this email\n";
if(!$this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
die("Unable to make symlink to process this email Critical error: {$email_filename}");
}
else {
continue;
}
}
$subjDecoded = imap_mime_header_decode($headers->subject);
$foundIdent = false;
foreach($subjDecoded as $sub) {
$found_enquiries = $this->checkValidIdentifier($sub->text, $enquiryMap, 'enquiry');
$foundIdent = $this->foundIdentifier($found_enquiries);
$found_invoices = $this->checkValidIdentifier($sub->text, $invoiceMap, 'invoice');
$foundIdent = $this->foundIdentifier($found_invoices);
$found_pos = $this->checkValidIdentifier($sub->text, $poMap, 'purchaseorder');
$foundIdent = $this->foundIdentifier($found_pos);
$found_jobs = $this->checkValidIdentifier($sub->text, $jobMap, 'job');
$foundIdent = $this->foundIdentifier($found_jobs);
}
//We're going to save this Email.
//Lets grab the attachments (if any) then create the appropiate Objects.
if($fromKnownUser == true || $saveThis == true || $foundIdent == true) {
$recipientsIDs['to'] = array();
$recipientsIDs['from'] = array();
$recipientsIDs['cc'] = array();
/**
* Loop over each recipient email found. Build an array containing the User IDs of that user.
*
* If that email doesn't have a corresponding User ID. We need to create a new User for this email address.
*
*
*/
foreach($recipients as $type => $recipientArray) {
foreach($recipientArray as $recEmail) {
$recEmailLC = strtolower($recEmail);
if(isset($userMap[$recEmailLC])) {
$recipientsIDs[$type][] = $userMap[$recEmailLC]; //Existing User ID.
}
else {
//$recipientsIDs[$type][] = "NEW User: $recEmail"; //Need to make a new user ID.
echo "Making a new User for: '{$recEmailLC}'\n";
$newUser['User'] = array(
'type' => 'contact',
'email' => $recEmailLC,
'by_vault' => 1
);
$this->User->create();
if($this->User->save($newUser, false)) {
$newID = $this->User->id;
echo "New User '{$recEmail}' Added with ID: {$newID}\n";
$recipientsIDs[$type][] = $newID;
//Add it to the userMap
$userMap[$recEmailLC] = $newID;
}
else {
echo "Serious Error: Unable to create user for email '{$recEmailLC}'\n";
continue;
}
}
}
}
echo "---------START MESSAGE -----------------\n";
echo "Subject: ".$subjDecoded[0]->text."\n";
$newEmail = array();
/** Testing creating the Email, Recipient and Attachments */
$newEmail['Email'] = array();
if(isset($recipientsIDs['from'][0])) {
$newEmail['Email']['user_id'] = $recipientsIDs['from'][0]; //We should never have more than one 'from' user ID.
}
else {
print_r($recipientsIDs);
echo "Email has no From Recipient ID. Ignoring this email\n";
$this->makeSymlink($email_filename, $vault_dir, $processed_dir);
continue;
}
//die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment.
$newEmail['Email']['udate'] = $unix_time;
$newEmail['Email']['udate'] = $unix_time;
$allowedChars = array('@', ';', ':', '.', '$', '%', '*','#','!',',','[', ']',' ','{','}','|', '(', ')');
$newEmail['Email']['subject'] = Sanitize::paranoid($subjDecoded[0]->text, $allowedChars);
$newEmail['Email']['filename'] = $email_filename;
$allowedChars = array('@', ';', ':', '.', '$', '%', '*','#','!',',','[', ']',' ','{','}','|', '(', ')');
$newEmail['Email']['subject'] = Sanitize::paranoid($subjDecoded[0]->text, $allowedChars);
$newEmail['Email']['filename'] = $email_filename;
$recipientCount = 0;
foreach($recipientsIDs as $type => $typeEmails) {
foreach($typeEmails as $userID) {
$recipientCount = 0;
foreach($recipientsIDs as $type => $typeEmails) {
foreach($typeEmails as $userID) {
$newEmail['EmailRecipient'][$recipientCount]['user_id'] = $userID;
switch($type) {
case 'to':
$newEmail['EmailRecipient'][$recipientCount]['type'] = 'to';
$recipientCount++;
break;
$newEmail['EmailRecipient'][$recipientCount]['user_id'] = $userID;
switch($type) {
case 'to':
$newEmail['EmailRecipient'][$recipientCount]['type'] = 'to';
$recipientCount++;
break;
case 'cc':
$newEmail['EmailRecipient'][$recipientCount]['type'] = 'cc';
$recipientCount++;
break;
default:
case 'cc':
$newEmail['EmailRecipient'][$recipientCount]['type'] = 'cc';
$recipientCount++;
break;
default:
}
}
}
}
/** End Email creation **/
/** End Email creation **/
/** Start Attachments **/
/** Start Attachments **/
$relative_path = $this->getAttachmentDirectory($email_dir, $unix_time);
$relative_path = $this->getAttachmentDirectory($email_dir, $unix_time);
$attachments = $this->fetchBodyAttachments($email_filename, $vault_dir, $email_dir, $relative_path, $ripmime_path);
$attachments = $this->fetchBodyAttachments($email_filename, $vault_dir, $email_dir, $relative_path, $ripmime_path);
$attachmentCount = 0;
$attachmentCount = 0;
$biggestHTML = 0;
$biggestHTML = 0;
foreach($attachments as $attachment) {
if(empty($attachment['type'])) {
continue;
foreach($attachments as $attachment) {
if(empty($attachment['type'])) {
continue;
}
$newEmail['EmailAttachment'][$attachmentCount]['name'] = $attachment['name'];
$newEmail['EmailAttachment'][$attachmentCount]['type'] = $attachment['type'];
$newEmail['EmailAttachment'][$attachmentCount]['size'] = $attachment['size'];
$newEmail['EmailAttachment'][$attachmentCount]['filename'] = $attachment['filename'];
$newEmail['EmailAttachment'][$attachmentCount]['is_message_body'] = $attachment['is_message_body'];
$attachmentCount++;
}
$newEmail['EmailAttachment'][$attachmentCount]['name'] = $attachment['name'];
$newEmail['EmailAttachment'][$attachmentCount]['type'] = $attachment['type'];
$newEmail['EmailAttachment'][$attachmentCount]['size'] = $attachment['size'];
$newEmail['EmailAttachment'][$attachmentCount]['filename'] = $attachment['filename'];
$newEmail['EmailAttachment'][$attachmentCount]['is_message_body'] = $attachment['is_message_body'];
$attachmentCount++;
}
/** End attachments */
/** End attachments */
/* If we found Identifiers for this Email. Create the HABTM associations.
/* If we found Identifiers for this Email. Create the HABTM associations.
*
*/
if(count($found_jobs) > 0) {
// echo "Found Job IDs: \n";
// print_r($found_jobs);
*/
if(count($found_jobs) > 0) {
// echo "Found Job IDs: \n";
// print_r($found_jobs);
foreach($found_jobs as $jobID) {
$newEmail['Job'][] = array('job_id'=> $jobID);
}
foreach($found_jobs as $jobID) {
$newEmail['Job'][] = array('job_id'=> $jobID);
}
}
if(count($found_pos) > 0) {
// echo "Found PO IDs: \n";
// print_r($found_pos);
foreach($found_pos as $poID) {
$newEmail['PurchaseOrder'][] = array('purchase_order_id'=> $poID);
if(count($found_pos) > 0) {
// echo "Found PO IDs: \n";
// print_r($found_pos);
foreach($found_pos as $poID) {
$newEmail['PurchaseOrder'][] = array('purchase_order_id'=> $poID);
}
}
}
if(count($found_enquiries) > 0) {
// echo "Found enquiry IDs: \n";
// print_r($found_enquiries);
foreach($found_enquiries as $enqID) {
$newEmail['Enquiry'][] = array('enquiry_id'=> $enqID);
if(count($found_enquiries) > 0) {
// echo "Found enquiry IDs: \n";
// print_r($found_enquiries);
foreach($found_enquiries as $enqID) {
$newEmail['Enquiry'][] = array('enquiry_id'=> $enqID);
}
}
}
if(count($found_invoices) > 0) {
// echo "Found Invoice IDs: \n";
// print_r($found_invoices);
foreach($found_invoices as $invID) {
$newEmail['Invoice'][] = array('invoice_id'=> $invID);
if(count($found_invoices) > 0) {
// echo "Found Invoice IDs: \n";
// print_r($found_invoices);
foreach($found_invoices as $invID) {
$newEmail['Invoice'][] = array('invoice_id'=> $invID);
}
}
}
//print_r($newEmail);
//print_r($newEmail);
$this->Email->create();
$emailID = $this->Email->saveAll($newEmail);
if(!empty($emailID)) {
echo "Success. We made an email\n";
$this->Email->create();
$emailID = $this->Email->saveAll($newEmail);
if(!empty($emailID)) {
echo "Success. We made an email\n";
}
else {
echo "Error! Didn't save the email\n";
}
echo "--------END MESSAGE ------\n";
}
else {
echo "Error! Didn't save the email\n";
echo "email will not be saved. Subject: ".$subjDecoded[0]->text."\n";
}
echo "--------END MESSAGE ------\n";
}
else {
echo "email will not be saved. Subject: ".$subjDecoded[0]->text."\n";
}
if($this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
echo "Created Symlink Sucessfully. Email has been processed\n";
}
else {
echo "Unable to create Symlink for {$email_filename}. Critical Error! \n";
}
if($this->makeSymlink($email_filename, $vault_dir, $processed_dir)) {
echo "Created Symlink Sucessfully. Email has been processed\n";
}
else {
echo "Unable to create Symlink for {$email_filename}. Critical Error! \n";
}
}
}
function isEmlFile($vault_dir, $filename) {
$info = pathinfo($vault_dir."/".$filename);
if($info['extension'] == 'eml') {
return true;
}
else {
return false;
}
}

View file

@ -37,11 +37,12 @@
?>
</td>
<td><?php //echo $text->highlight($html->link($email['Email']['subject'], array('controller'=> 'emails', 'action'=>'frame/', $email['Email']['id'])), 'Quotation');
echo $text->highlight($html->link(Sanitize::clean($email['Email']['subject']), '#', array('class'=>'viewLink', 'id'=>$email['Email']['id'])), 'Quotation');?>
echo $text->highlight($html->link($email['Email']['subject'], '#', array('class'=>'viewLink', 'id'=>$email['Email']['id'])), 'Quotation');?>
<span class='viewLink' id="<? echo $email['Email']['id']?>">(<? echo $email['Email']['id']?>)</span>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>

View file

@ -1,6 +1,6 @@
<?php echo $javascript->link('jquery.jeditable.mini'); ?>
<?=$javascript->link('ajax_pagination'); ?>
<?=$javascript->link('ajax_pagination_enquiry'); ?>
<?php echo $paginator->options(array('url'=>$this->passedArgs)); ?>

View file

@ -0,0 +1,35 @@
<?=$javascript->link('view_user_email'); ?>
<?php echo $paginator->options(array('url'=>$this->passedArgs)); ?>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% Enquiries out of %count% total, starting on record %start%, ending on %end%', true)
));
?>
<div class="pagingEmail">
<?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
</div>
<div class="related">
<h3>
User Email<?php echo $html->image('internet-mail.png'); ?>
</h3>
<?php echo $this->element('email_table_ajax', array('emails' => $userMail)); ?>
<?php //echo $this->element('email_table_ajax', $enquiry, array('cache'=>'+1 day')); ?>
</div>
<? //debug($userMail); ?>
<hr>
<?// debug($allIDs); ?>

View file

@ -3,7 +3,7 @@
<div class="enquiriesindex">
<h2><?php __('Master Enquiry Register');?></h2>
<? echo $this->element('enquiry_table', $enquiries, $status_list, array('cache'=>'+1 day')); ?>
<? echo $this->element('enquiry_table', $enquiries, $status_list); ?>
</div>
</div>

View file

@ -1,5 +1,5 @@
<?=$javascript->link('view_user'); ?>
<?=$javascript->link('view_user_email'); ?>
<span id="userID" style="display: none;"><?=$user['User']['id']?></span>
<div class="users view">
@ -37,9 +37,22 @@
<button id="show" class="showHide">Show</button>
<button id="hide" class="showHide">Hide</button>
<div id="ajaxLoad" style="display:none;"><?php echo $html->image('ajax-loader.gif'); ?></div>
<div id="ajaxLoadEnquiry" style="display:none;"><?php echo $html->image('ajax-loader.gif'); ?></div>
<div id="enquiryTable">
</div>
</div>
<div class="related">
<h3>Email Correspondence with this User.</h3>
<button id="showEmail" class="showHide">Show</button>
<button id="hideEmail" class="showHide">Hide</button>
<div id="ajaxLoadEmail" style="display:none;"><?php echo $html->image('ajax-loader.gif'); ?></div>
<div id="emailTable">
</div>
</div>

View file

@ -0,0 +1,26 @@
$(function() {
/* Everything about this JS violates DRY. But it will work for now */
$(".pagingEmail").find('a').click(function() {
$('#emailTable').fadeOut('slow');
$("#ajaxLoadEmail").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxComplete", function() {
$(this).hide();
});
$.get($(this).attr('href'), function(data) {
$('#emailTable').html(data);
$('#emailTable').fadeIn('slow');
});
return false;
});
});

View file

@ -1,11 +1,13 @@
$(function() {
/* Everything about this JS violates DRY. But it will work for now */
$(".paging").find('a').click(function() {
$('#enquiryTable').fadeOut('slow');
$("#ajaxLoad").bind("ajaxSend", function() {
$("#ajaxLoadEnquiry").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxComplete", function() {
$(this).hide();

View file

@ -3,8 +3,8 @@ $(function() {
$('#show').hide();
$('#enquiryTable').hide();
$("#ajaxLoad").hide();
$("#ajaxLoad").bind("ajaxSend", function() {
$("#ajaxLoadEnquiry").hide();
$("#ajaxLoadEnquiry").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxComplete", function() {
$(this).hide();
@ -32,7 +32,6 @@ $(function() {
$('#show').click(function() {
$(this).hide();
$('#hide').show();
$('#enquiryTable').slideDown('fast');
});

View file

@ -0,0 +1,41 @@
$(function() {
$('#hideEmail').hide();
$('#emailTable').hide();
$("#ajaxLoadEmail").hide();
$("#ajaxLoadEmail").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxComplete", function() {
$(this).hide();
});
var userID = $('#userID').text();
$('#hideEmail').click(function() {
$(this).hide();
$('#showEmail').show();
$('#emailTable').slideUp('fast');
});
$('#showEmail').click(function() {
$(this).hide();
$('#hideEmail').show();
$.get('/emails/view_user_emails/'+userID, function(data) {
$('#emailTable').html(data);
$('#emailTable').slideDown('fast');
});
});
});