diff --git a/config/core.php b/config/core.php index eda01742..8ca869eb 100755 --- a/config/core.php +++ b/config/core.php @@ -40,7 +40,7 @@ * In production mode, flash messages redirect after a time interval. * In development mode, you need to click the flash message to continue. */ - Configure::write('debug', 1); + Configure::write('debug', 2); /** * Application wide charset encoding */ diff --git a/controllers/enquiries_controller.php b/controllers/enquiries_controller.php index a5136848..5d828e11 100755 --- a/controllers/enquiries_controller.php +++ b/controllers/enquiries_controller.php @@ -375,7 +375,13 @@ class EnquiriesController extends AppController { } - + function search() { + if(empty($this->data)) { + $this->Session->setFlash('Enter part of the Enquiry number you want to find'); + } + + + } } ?> diff --git a/controllers/industries_controller.php b/controllers/industries_controller.php new file mode 100644 index 00000000..1098423b --- /dev/null +++ b/controllers/industries_controller.php @@ -0,0 +1,74 @@ +Industry->recursive = 0; + $this->set('industries', $this->paginate()); + } + + function view($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid Industry.', true)); + $this->redirect(array('action'=>'index')); + } + $this->set('industry', $this->Industry->read(null, $id)); + } + + function add() { + if (!empty($this->data)) { + $this->Industry->create(); + if ($this->Industry->save($this->data)) { + $this->Session->setFlash(__('The Industry has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true)); + } + } + $customers = $this->Industry->Customer->find('list'); + $parents = $this->Industry->find('list', array('conditions' => array( + 'Industry.parent_id' => null))); + $this->set(compact('customers', 'parents')); + } + + function edit($id = null) { + if (!$id && empty($this->data)) { + $this->Session->setFlash(__('Invalid Industry', true)); + $this->redirect(array('action'=>'index')); + } + if (!empty($this->data)) { + if ($this->Industry->save($this->data)) { + $this->Session->setFlash(__('The Industry has been saved', true)); + $this->redirect(array('action'=>'index')); + } else { + $this->Session->setFlash(__('The Industry could not be saved. Please, try again.', true)); + } + } + if (empty($this->data)) { + $this->data = $this->Industry->read(null, $id); + } + $parents = $this->Industry->find('list', array('conditions' => array( + 'Industry.parent_id' => null, + 'NOT' => array( + 'Industry.id' => $this->data['Industry']['id'] + )))); + $customers = $this->Industry->Customer->find('list'); + $this->set(compact('customers', 'parents')); + } + + function delete($id = null) { + if (!$id) { + $this->Session->setFlash(__('Invalid id for Industry', true)); + $this->redirect(array('action'=>'index')); + } + if ($this->Industry->del($id)) { + $this->Session->setFlash(__('Industry deleted', true)); + $this->redirect(array('action'=>'index')); + } + } + + +} +?> diff --git a/models/customer.php b/models/customer.php index 69486a5b..b19d62f8 100755 --- a/models/customer.php +++ b/models/customer.php @@ -69,5 +69,17 @@ class Customer extends AppModel { var $belongsTo = array('CustomerCategory'=>array('className' => 'CustomerCategory', 'foreignKey' => 'customer_category_id')); + + + var $hasAndBelongsToMany = array ( + 'Industry' => array( + 'className' => 'Industry', + 'joinTable' => 'industries_customers', + 'foreignKey' => 'customer_id', + 'associationForeignKey' => 'industry_id' + ) + ); + + } ?> diff --git a/vendors/shells/vault.php b/vendors/shells/vault.php index feae00fe..b67eded5 100644 --- a/vendors/shells/vault.php +++ b/vendors/shells/vault.php @@ -20,20 +20,27 @@ class VaultShell extends Shell { $email_dir = '/var/www/cakephp/app/emails/working'; $temp_filename = 'temp.eml'; - if($testing == 1) { + // if($testing == 1) { $email_dir = '/var/www/quotenik1.2/app/emails/working'; - } + // } $mbox = imap_open("{saturn:143/novalidate-cert}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"; + + if($number_of_messages == 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++) { - echo "Checking msg number $i\n"; $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) { //Process it and store the message and its attachments. @@ -107,9 +114,8 @@ class VaultShell extends Shell { } echo "Email stored in the DB under enquiry ".$enquiry['Enquiry']['title']." Will be moved to the stored folder\n"; - if($testing == 0) { //Testing Mode. Don't actually move these emails unless we're in production. - imap_mail_move($mbox, $i, 'INBOX/Stored'); //Move it to the stored folder. - } + $stored_msgs[] = imap_uid($mbox,$i); + @@ -134,26 +140,47 @@ class VaultShell extends Shell { /* 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. * */ - if($testing == 0) { - - if(imap_mail_move($mbox, $i, 'INBOX/Discarded')) { - echo "Message Number $i contains no valid Enquiry number. Has been discarded\n"; - } - else { - echo "Message Number $i contains no valid Enquiry number. But could not be discarded\n"; - } - } + + $discarded_msgs[] = imap_uid($mbox,$i); + + } + + } $this->rmdirr($email_dir); //delete all attachments from the working directory. Easiest way to stop random files persisting + + if(isset($stored_msgs)) { + + foreach($stored_msgs as $msg) { + $no = imap_msgno($mbox,$msg); + + $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 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); - + } diff --git a/views/customers/view.ctp b/views/customers/view.ctp index b9ca3e83..bb7e3061 100755 --- a/views/customers/view.ctp +++ b/views/customers/view.ctp @@ -133,3 +133,7 @@ + + + + debug($customer, true); ?> diff --git a/views/industries/.add.ctp.swp b/views/industries/.add.ctp.swp new file mode 100644 index 00000000..6d0f748e Binary files /dev/null and b/views/industries/.add.ctp.swp differ diff --git a/views/industries/.edit.ctp.swo b/views/industries/.edit.ctp.swo new file mode 100644 index 00000000..76d8b00d Binary files /dev/null and b/views/industries/.edit.ctp.swo differ diff --git a/views/industries/.edit.ctp.swp b/views/industries/.edit.ctp.swp new file mode 100644 index 00000000..a3ffcda5 Binary files /dev/null and b/views/industries/.edit.ctp.swp differ diff --git a/views/industries/.view.ctp.swp b/views/industries/.view.ctp.swp new file mode 100644 index 00000000..09b1902e Binary files /dev/null and b/views/industries/.view.ctp.swp differ diff --git a/views/industries/add.ctp b/views/industries/add.ctp new file mode 100644 index 00000000..fc9b4618 --- /dev/null +++ b/views/industries/add.ctp @@ -0,0 +1,21 @@ +
+counter(array( +'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) +)); +?>
+| sort('id');?> | +sort('name');?> | +sort('parent_id');?> | ++ |
|---|---|---|---|
| + + | ++ + | ++ link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id'])); ?> + | ++ link(__('View', true), array('action'=>'view', $industry['Industry']['id'])); ?> + link(__('Edit', true), array('action'=>'edit', $industry['Industry']['id'])); ?> + link(__('Delete', true), array('action'=>'delete', $industry['Industry']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $industry['Industry']['id'])); ?> + | +