From d5cb432a6dbd995846a64b253980fe568eb65da4 Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Fri, 11 Mar 2011 12:22:57 +1100 Subject: [PATCH] Added Ajax Add and edit for Contact users. Will extend to regular users and principle contacts shortly --- controllers/users_controller.php | 35 ++++ vendors/shells/vault_two.php | 184 +++++++++--------- views/customers/view.ctp | 31 +-- views/users/add_edit.ctp | 61 ++++++ views/users/edit.ctp | 25 --- webroot/js/add_edit_user.js | 63 ++++++ .../js/{add_user.js => add_edit_user_ajax.js} | 53 +---- 7 files changed, 271 insertions(+), 181 deletions(-) create mode 100755 views/users/add_edit.ctp delete mode 100755 views/users/edit.ctp create mode 100644 webroot/js/add_edit_user.js rename webroot/js/{add_user.js => add_edit_user_ajax.js} (59%) diff --git a/controllers/users_controller.php b/controllers/users_controller.php index 9a197f0c..d71fe0df 100755 --- a/controllers/users_controller.php +++ b/controllers/users_controller.php @@ -115,6 +115,41 @@ class UsersController extends AppController { + } + + + function add_edit() { + Configure::write('debug', 0); + + if(isset($this->params['named']['type'])) { + $this->set('type', $this->params['named']['type']); + } + + if(isset($this->params['named']['principle_id'])) { + $this->set('principle_id', $this->params['named']['principle_id']); + } + + if(isset($this->params['named']['customer_id'])) { + $this->set('customer_id', $this->params['named']['customer_id']); + } + + if(isset($this->params['named']['user_id'])) { + $userID = $this->params['named']['user_id']; + $this->set('user_id', $userID); + } + + if(isset($this->params['named']['action'])) { + $action = $this->params['named']['action']; + $this->set('action', $action); + } + + if(isset($action) && isset($userID)) { + $this->data = $this->User->read(null, $userID); + } + + + + } diff --git a/vendors/shells/vault_two.php b/vendors/shells/vault_two.php index 6b598b23..0e4359a8 100755 --- a/vendors/shells/vault_two.php +++ b/vendors/shells/vault_two.php @@ -12,7 +12,7 @@ class VaultTwoShell extends Shell { var $uses = array('Enquiry', 'Contact', 'Invoice', 'PurchaseOrder', 'User', 'Email', 'EmailRecipient', 'Job'); - // var $email_dir = '/var/www/cakephp/app/emails'; + // var $email_dir = '/var/www/cakephp/app/emails'; function main() { @@ -214,7 +214,7 @@ class VaultTwoShell extends Shell { } else { echo "Fatal Error: Unable to create user for email '{$recEmailLC}'\n"; - die(); + continue; } } @@ -253,125 +253,129 @@ class VaultTwoShell extends Shell { $newEmail['Email']['user_id'] = $recipientsIDs['from'][0]; //We should never have more than one 'from' user ID. } else { - die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment. + print_r($recipientsIDs); + echo "Email has no From Recipient ID. Ignoring this.\n"; + continue; + } +//die("Email has no from Recipient!! Critical Failure"); //Change this to logging for deployment. // $newEmail['Email']['date'] = $this_header->date; - $newEmail['Email']['udate'] = $this_header->udate; - $newEmail['Email']['subject'] = $subjDecoded[0]->text; //Hacky. Will probably fix this quickly. + $newEmail['Email']['udate'] = $this_header->udate; + $newEmail['Email']['subject'] = $subjDecoded[0]->text; //Hacky. Will probably fix this quickly. - $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); - $attachments = $this->fetchBodyAttachments($mbox, $i, $email_dir, $relative_path, $ripmime_path); + $relative_path = $this->getAttachmentDirectory($email_dir, $unix_time); + $attachments = $this->fetchBodyAttachments($mbox, $i, $email_dir, $relative_path, $ripmime_path); - $attachmentCount = 0; + $attachmentCount = 0; - $biggestHTML = 0; + $biggestHTML = 0; - 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++; + foreach($attachments as $attachment) { + if(empty($attachment['type'])) { + continue; } - /** End attachments */ + + $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 */ - /* 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) { + */ + 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); - } + // print_r($found_jobs); + foreach($found_jobs as $jobID) { + $newEmail['Job'][] = array('job_id'=> $jobID); } + } - if(count($found_pos) > 0) { + + 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); - } + foreach($found_pos as $poID) { + $newEmail['PurchaseOrder'][] = array('purchase_order_id'=> $poID); } + } - if(count($found_enquiries) > 0) { + 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); - } + foreach($found_enquiries as $enqID) { + $newEmail['Enquiry'][] = array('enquiry_id'=> $enqID); } + } - if(count($found_invoices) > 0) { + 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); - } + 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. Storing Email UID $this_uid\n"; - } - else { - - echo "Error! Didn't save the email\n"; - } - $store[] = $this_uid; - - - echo "--------END MESSAGE ------\n"; + $this->Email->create(); + $emailID = $this->Email->saveAll($newEmail); + if(!empty($emailID)) { + echo "Success. We made an email. Storing Email UID $this_uid\n"; } else { - $discard[] = $this_uid; - echo "email {$i} will not be saved. Subject: ".$subjDecoded[0]->text."\n"; + + echo "Error! Didn't save the email\n"; } - // print_r($recipients); - // echo "----------------------\n"; + $store[] = $this_uid; + + + echo "--------END MESSAGE ------\n"; + } + else { + $discard[] = $this_uid; + echo "email {$i} will not be saved. Subject: ".$subjDecoded[0]->text."\n"; + } + // print_r($recipients); + // echo "----------------------\n"; } @@ -403,7 +407,7 @@ class VaultTwoShell extends Shell { imap_close($mbox); } - + /** * Make a 'HashMap' (array) in the format. @@ -596,7 +600,7 @@ class VaultTwoShell extends Shell { print_r($type); echo count($type)."\n"; -*/ + */ if(count($type) != 2) { //echo "Didnt find a proper type. Skipping it."; continue; @@ -606,7 +610,7 @@ class VaultTwoShell extends Shell { //echo "Didnt find a proper name. Skipping it"; continue; } - + $oldNamePath = $email_dir.'/'.$relative_path.'/'.$name[1]; $newNamePath = $email_dir.'/'.$relative_path.'/'.$uuid.'-'.$name[1]; $newName = $relative_path.'/'.$uuid.'-'.$name[1]; @@ -618,7 +622,7 @@ class VaultTwoShell extends Shell { $attachments[$j]['name'] = $newName; $attachments[$j]['filename'] = $name[1]; $attachments[$j]['size'] = $size; - $attachments[$j]['is_message_body'] = 0; + $attachments[$j]['is_message_body'] = 0; echo "in message number $msg_number: found attachment ".$attachments[$j]['name'].' '.$attachments[$j]['type']."\n"; @@ -693,22 +697,22 @@ class VaultTwoShell extends Shell { * * @param $attachments - function moveAttachments($attachments, $email_dir, $unix_time) { + function moveAttachments($attachments, $email_dir, $unix_time) { - $month_year = date('m-Y'); + $month_year = date('m-Y'); - $uuid = String::uuid(); + $uuid = String::uuid(); - foreach($attachments as $attachment) { - echo $email_dir.'/'.$attachment['name']."\n"; - } - die(); + foreach($attachments as $attachment) { + echo $email_dir.'/'.$attachment['name']."\n"; + } + die(); - }*/ + }*/ } diff --git a/views/customers/view.ctp b/views/customers/view.ctp index a9d44581..a27405a3 100755 --- a/views/customers/view.ctp +++ b/views/customers/view.ctp @@ -91,7 +91,8 @@