diff --git a/controllers/emails_controller.php b/controllers/emails_controller.php index 4286ca1e..8829a46a 100755 --- a/controllers/emails_controller.php +++ b/controllers/emails_controller.php @@ -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); } } diff --git a/models/email.php b/models/email.php index d507cc36..fec7ee40 100755 --- a/models/email.php +++ b/models/email.php @@ -51,5 +51,7 @@ class Email extends AppModel { } + + } ?> diff --git a/vendors/shells/vault.php b/vendors/shells/vault.php index 9b3220f7..054d1f3d 100755 --- a/vendors/shells/vault.php +++ b/vendors/shells/vault.php @@ -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; + } } diff --git a/views/elements/email_table_ajax.ctp b/views/elements/email_table_ajax.ctp index 605e08c7..738dafb5 100755 --- a/views/elements/email_table_ajax.ctp +++ b/views/elements/email_table_ajax.ctp @@ -37,11 +37,12 @@ ?> 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');?> () + diff --git a/views/elements/enquiry_table.ctp b/views/elements/enquiry_table.ctp index ed977ef0..95666126 100755 --- a/views/elements/enquiry_table.ctp +++ b/views/elements/enquiry_table.ctp @@ -1,6 +1,6 @@ link('jquery.jeditable.mini'); ?> -link('ajax_pagination'); ?> +link('ajax_pagination_enquiry'); ?> options(array('url'=>$this->passedArgs)); ?> diff --git a/views/emails/view_user_emails.ctp b/views/emails/view_user_emails.ctp new file mode 100644 index 00000000..2ec317f5 --- /dev/null +++ b/views/emails/view_user_emails.ctp @@ -0,0 +1,35 @@ +link('view_user_email'); ?> + + +options(array('url'=>$this->passedArgs)); ?> + +counter(array( +'format' => __('Page %page% of %pages%, showing %current% Enquiries out of %count% total, starting on record %start%, ending on %end%', true) +)); +?> + +
+prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> + | numbers();?> +next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?> +
+ + + + + + + + + + +
+ + diff --git a/views/enquiries/index.ctp b/views/enquiries/index.ctp index 32dec63b..6e00bcc7 100755 --- a/views/enquiries/index.ctp +++ b/views/enquiries/index.ctp @@ -3,7 +3,7 @@

- element('enquiry_table', $enquiries, $status_list, array('cache'=>'+1 day')); ?> + element('enquiry_table', $enquiries, $status_list); ?>
diff --git a/views/users/view_user.ctp b/views/users/view_user.ctp index 3a242307..97b91fc8 100644 --- a/views/users/view_user.ctp +++ b/views/users/view_user.ctp @@ -1,5 +1,5 @@ link('view_user'); ?> - +link('view_user_email'); ?>
@@ -37,9 +37,22 @@ - +
+ + + diff --git a/webroot/js/ajax_pagination_email.js b/webroot/js/ajax_pagination_email.js new file mode 100644 index 00000000..092e5c52 --- /dev/null +++ b/webroot/js/ajax_pagination_email.js @@ -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; + }); + + +}); + diff --git a/webroot/js/ajax_pagination.js b/webroot/js/ajax_pagination_enquiry.js similarity index 73% rename from webroot/js/ajax_pagination.js rename to webroot/js/ajax_pagination_enquiry.js index 1213a47b..d7a6feaf 100644 --- a/webroot/js/ajax_pagination.js +++ b/webroot/js/ajax_pagination_enquiry.js @@ -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(); diff --git a/webroot/js/view_user.js b/webroot/js/view_user.js index 9e135011..0cb79f1b 100644 --- a/webroot/js/view_user.js +++ b/webroot/js/view_user.js @@ -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'); }); diff --git a/webroot/js/view_user_email.js b/webroot/js/view_user_email.js new file mode 100644 index 00000000..52eaee6a --- /dev/null +++ b/webroot/js/view_user_email.js @@ -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'); + + }); + + }); + + +}); \ No newline at end of file