Finished Quick Search

This commit is contained in:
Karl Cordes 2010-05-11 15:02:11 +10:00
parent 2eb2d5f293
commit 3cf7d230ea
11 changed files with 392 additions and 130 deletions

View file

@ -6,8 +6,14 @@ class EmailAttachmentsController extends AppController {
function download($id) { function download($id) {
Configure::write('debug', 0);
$file = $this->EmailAttachment->findById($id); $file = $this->EmailAttachment->findById($id);
if(file_exists($file['EmailAttachment']['filename'])) {
Configure::write('debug', 0);
header('Content-type: ' . $file['EmailAttachment']['type']); header('Content-type: ' . $file['EmailAttachment']['type']);
header('Content-length: ' . $file['EmailAttachment']['size']); header('Content-length: ' . $file['EmailAttachment']['size']);
header('Content-Disposition: attachment; filename='.$file['EmailAttachment']['name']); header('Content-Disposition: attachment; filename='.$file['EmailAttachment']['name']);
@ -17,6 +23,11 @@ class EmailAttachmentsController extends AppController {
readfile($file['EmailAttachment']['filename']); readfile($file['EmailAttachment']['filename']);
// echo $file['EmailAttachment']['filename'] // echo $file['EmailAttachment']['filename']
exit(); exit();
}
else {
echo "ERROR!! : File Not Found";
echo $file['EmailAttachment']['filename'];
}
} }
} }

View file

@ -7,9 +7,9 @@ class EnquiriesController extends AppController {
var $paginate = array( var $paginate = array(
'contain' => false, 'contain' => false,
'limit' => 150, 'limit' => 150,
'order'=>array('Enquiry.id' => 'desc') 'order'=>array('Enquiry.id' => 'desc')
); );
@ -29,8 +29,8 @@ class EnquiriesController extends AppController {
} }
$this->set('status_list', $status_list); $this->set('status_list', $status_list);
//debug($this->paginate()); //debug($this->paginate());
// $this->set('status_list', $this->Enquiry->Status->find('list')); // $this->set('status_list', $this->Enquiry->Status->find('list'));
} }
function view($id = null) { function view($id = null) {
@ -50,11 +50,11 @@ class EnquiriesController extends AppController {
//$this->set('files', $this->Enquiry->EnquiryFile->find('all', array('conditions' => array('EnquiryFile.enquiry_id'=>$id), 'order' => 'EnquiryFile.created ASC'))); //$this->set('files', $this->Enquiry->EnquiryFile->find('all', array('conditions' => array('EnquiryFile.enquiry_id'=>$id), 'order' => 'EnquiryFile.created ASC')));
/* Trying to optimise the queries for this part of the view - it's currently getting bogged down checking Email Attachments. /* Trying to optimise the queries for this part of the view - it's currently getting bogged down checking Email Attachments.
* Going to create an array describing whether a particular email ID has an attachment. Trying to avoid checking binary data in a find('all') call * Going to create an array describing whether a particular email ID has an attachment. Trying to avoid checking binary data in a find('all') call
*/ */
/* /*
$emails = $this->Enquiry->Email->find('all', array( $emails = $this->Enquiry->Email->find('all', array(
'recursive' => 0, 'recursive' => 0,
'contain' => 'EmailAttachment.id', 'EmailAttachment.email_id', 'contain' => 'EmailAttachment.id', 'EmailAttachment.email_id',
@ -67,7 +67,7 @@ class EnquiriesController extends AppController {
TO DO: TO DO:
* Fix up Email Attachment icon on email box. Currently broken -KC 6/8/09 * Fix up Email Attachment icon on email box. Currently broken -KC 6/8/09
$this->set('number_of_emails', $this->Enquiry->Email->find('count', array('conditions'=>array('Email.enquiry_id'=>$id)))); $this->set('number_of_emails', $this->Enquiry->Email->find('count', array('conditions'=>array('Email.enquiry_id'=>$id))));
*/ */
$this->set('emails', $this->Enquiry->Email->find('all', array('conditions'=>array('Email.enquiry_id' => $id)))); $this->set('emails', $this->Enquiry->Email->find('all', array('conditions'=>array('Email.enquiry_id' => $id))));
$this->set('number_of_quotes', $this->Enquiry->Quote->find('count', array('conditions'=>array('Quote.enquiry_id'=>$id)))); $this->set('number_of_quotes', $this->Enquiry->Quote->find('count', array('conditions'=>array('Quote.enquiry_id'=>$id))));
@ -100,7 +100,7 @@ class EnquiriesController extends AppController {
} }
if(isset($customer)) { if(isset($customer)) {
/* Check if the customer exists in the database - otherwise send the user back to step 1*/ /* Check if the customer exists in the database - otherwise send the user back to step 1*/
if(!$customer) { if(!$customer) {
$this->Session->setFlash(__('The customer must already exist in the database. Please try again', true)); $this->Session->setFlash(__('The customer must already exist in the database. Please try again', true));
$this->redirect(array('action'=>'add')); $this->redirect(array('action'=>'add'));
@ -155,12 +155,12 @@ class EnquiriesController extends AppController {
} }
} }
/* Internal function to display page 2 of the Add Enquiry Form Wizard /* Internal function to display page 2 of the Add Enquiry Form Wizard
* to help make the flow-control logic of the add function clearer. * to help make the flow-control logic of the add function clearer.
* */ * */
function __showPage2($customer) { function __showPage2($customer) {
/* Combine the first_name and last_name for the Contact Drop Down Box */ /* Combine the first_name and last_name for the Contact Drop Down Box */
$contacts = $this->Enquiry->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id']))); $contacts = $this->Enquiry->Contact->find('all', array('conditions' => array('Contact.customer_id' => $customer['Customer']['id'])));
$contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name')); $contacts = Set::Combine($contacts, '{n}.Contact.id', array('{0} {1}', '{n}.Contact.first_name', '{n}.Contact.last_name'));
$states = $this->Enquiry->State->find('list'); $states = $this->Enquiry->State->find('list');
@ -173,7 +173,7 @@ class EnquiriesController extends AppController {
$this->set('billing_addresses', $customerAddresses); $this->set('billing_addresses', $customerAddresses);
$this->set('shipping_addresses', $customerAddresses); $this->set('shipping_addresses', $customerAddresses);
$this->set('errors', $this->Enquiry->invalidFields()); $this->set('errors', $this->Enquiry->invalidFields());
/* Feels like an ugly hack. But it gets the desired effect and it will do for now */ /* Feels like an ugly hack. But it gets the desired effect and it will do for now */
if(isset($customerAddresses[0]['BillingAddress'])) { if(isset($customerAddresses[0]['BillingAddress'])) {
$billing_address_list[0] = "No Address Selected"; $billing_address_list[0] = "No Address Selected";
@ -192,7 +192,7 @@ class EnquiriesController extends AppController {
/* Add enquiry_id to the Email Queue */ /* Add enquiry_id to the Email Queue */
function __addToQueue($id) { function __addToQueue($id) {
$enquiry = $this->Enquiry->read(null, $id); $enquiry = $this->Enquiry->read(null, $id);
@ -209,13 +209,13 @@ class EnquiriesController extends AppController {
} }
} }
/* Generate Enquiry number and return it as a string */ /* Generate Enquiry number and return it as a string */
function __generateEnquiryNumber($data) { function __generateEnquiryNumber($data) {
$state = $this->Enquiry->State->findById($data['Enquiry']['state_id']); $state = $this->Enquiry->State->findById($data['Enquiry']['state_id']);
$principle = $this->Enquiry->Principle->findById($data['Enquiry']['principle_id']); $principle = $this->Enquiry->Principle->findById($data['Enquiry']['principle_id']);
/* Generate the enquiry number for this enquiry */ /* Generate the enquiry number for this enquiry */
/* CMC Enquiry number format is: /* CMC Enquiry number format is:
* CMC<INCREMENTAL_NUMBER><STATE_INITIAL>E<PRINCIPLE_CODE><NO_OF_ENQ_FOR_THIS_PRINCIPLE_CODE>-<NO_OF_ENQ_FOR_THIS_PRINCIPLE_CODE_IN_THIS_STATE> * CMC<INCREMENTAL_NUMBER><STATE_INITIAL>E<PRINCIPLE_CODE><NO_OF_ENQ_FOR_THIS_PRINCIPLE_CODE>-<NO_OF_ENQ_FOR_THIS_PRINCIPLE_CODE_IN_THIS_STATE>
* eg. CMC1245NE351234-456 */ * eg. CMC1245NE351234-456 */
@ -223,104 +223,104 @@ class EnquiriesController extends AppController {
$enquiryoffset = 7882; //What Number Enquiry we were at before using this package. $enquiryoffset = 7882; //What Number Enquiry we were at before using this package.
$enquiryid += $enquiryoffset; $enquiryid += $enquiryoffset;
$enquiryid++; $enquiryid++;
/* Find how many enquiries have been for this principle code */ /* Find how many enquiries have been for this principle code */
$principleenquiries = $this->Enquiry->findCount('principle_code ='. $principle['Principle']['code']); $principleenquiries = $this->Enquiry->findCount('principle_code ='. $principle['Principle']['code']);
/* Principle Code Offsets - Existing Number of Enquiries for each Principle Code */ /* Principle Code Offsets - Existing Number of Enquiries for each Principle Code */
$principlecode_offset = array( 15 => 207, //ELMAC, AMAL $principlecode_offset = array( 15 => 207, //ELMAC, AMAL
20 => 51, //T and B Electronic 20 => 51, //T and B Electronic
25 => 2062, //ATEX,Brilex,Marston 25 => 2062, //ATEX,Brilex,Marston
35 => 2067, //Mid-West Instrument, DP 35 => 2067, //Mid-West Instrument, DP
36 => 47, //Reading Technologies 36 => 47, //Reading Technologies
37 => 2040, //Eldridge, Smart Measurement, Alia 37 => 2040, //Eldridge, Smart Measurement, Alia
65 => 2212, //Papenmeier, Herberts Industrieglas 65 => 2212, //Papenmeier, Herberts Industrieglas
85 => 586, //Analytical Systems, Misc 85 => 586, //Analytical Systems, Misc
95 => 181); //Comet, T and D. 95 => 181); //Comet, T and D.
$principleenquiries += $principlecode_offset[$principle['Principle']['code']]; //Add the offset. $principleenquiries += $principlecode_offset[$principle['Principle']['code']]; //Add the offset.
$principleenquiries++; $principleenquiries++;
/* Find how many enquiries have been for this principle code in this state */ /* Find how many enquiries have been for this principle code in this state */
/* This aspect of the enquiry number is not useful anymore. Made redundant thanks to mySQL queries. /* This aspect of the enquiry number is not useful anymore. Made redundant thanks to mySQL queries.
* But this has been done for backwards-compatablity with existing enquiry numbers */ * But this has been done for backwards-compatablity with existing enquiry numbers */
$principleconditions = array $principleconditions = array
( (
"Enquiry.principle_code" => $principle['Principle']['code'], "Enquiry.principle_code" => $principle['Principle']['code'],
"Enquiry.state_id" => $data['Enquiry']['state_id'] "Enquiry.state_id" => $data['Enquiry']['state_id']
); );
$stateprincipleenquiries = $this->Enquiry->findCount($principleconditions); $stateprincipleenquiries = $this->Enquiry->findCount($principleconditions);
/*Add the offsets for the State Principle Enquiries for each Code */ /*Add the offsets for the State Principle Enquiries for each Code */
$stateprinciple_offset = array( $stateprinciple_offset = array(
//Elmac, Amal //Elmac, Amal
15 => array("NSW" => 39, "VIC" => 38, "TAS" => 58, 15 => array("NSW" => 39, "VIC" => 38, "TAS" => 58,
"ACT" => 0, "QLD" => 30, "NT" => 0, "ACT" => 0, "QLD" => 30, "NT" => 0,
"WA" => 19, "SA" => 8, "Overseas" => 1), "WA" => 19, "SA" => 8, "Overseas" => 1),
//T and B Electronic //T and B Electronic
20 => array("NSW" => 14, "VIC" => 6, "TAS" => 0, 20 => array("NSW" => 14, "VIC" => 6, "TAS" => 0,
"ACT" => 0, "QLD" => 8, "NT" => 0, "ACT" => 0, "QLD" => 8, "NT" => 0,
"WA" => 12, "SA" => 1, "Overseas" => 5), "WA" => 12, "SA" => 1, "Overseas" => 5),
//ATEX,Brilex,Marston //ATEX,Brilex,Marston
25 => array("NSW" => 580, "VIC" => 599, "TAS" => 186, 25 => array("NSW" => 580, "VIC" => 599, "TAS" => 186,
"ACT" => 0, "QLD" => 254, "NT" => 3, "ACT" => 0, "QLD" => 254, "NT" => 3,
"WA" => 541, "SA" => 72, "Overseas" => 625), "WA" => 541, "SA" => 72, "Overseas" => 625),
//Mid-West Instrument, DP //Mid-West Instrument, DP
35 => array("NSW" => 549, "VIC" => 851, "TAS" => 9, 35 => array("NSW" => 549, "VIC" => 851, "TAS" => 9,
"ACT" => 0, "QLD" => 245, "NT" => 15, "ACT" => 0, "QLD" => 245, "NT" => 15,
"WA" => 470, "SA" => 508, "Overseas" => 154), "WA" => 470, "SA" => 508, "Overseas" => 154),
//Reading Technologies //Reading Technologies
36 => array("NSW" => 1, "VIC" => 3, "TAS" => 0, 36 => array("NSW" => 1, "VIC" => 3, "TAS" => 0,
"ACT" => 0, "QLD" => 7, "NT" => 0, "ACT" => 0, "QLD" => 7, "NT" => 0,
"WA" => 0, "SA" => 4, "Overseas" => 2), "WA" => 0, "SA" => 4, "Overseas" => 2),
//Eldridge, Smart Measurement, Alia //Eldridge, Smart Measurement, Alia
37 => array("NSW" => 204, "VIC" => 60, "TAS" => 1, 37 => array("NSW" => 204, "VIC" => 60, "TAS" => 1,
"ACT" => 0, "QLD" => 130, "NT" => 1, "ACT" => 0, "QLD" => 130, "NT" => 1,
"WA" => 44, "SA" => 25, "Overseas" => 18), "WA" => 44, "SA" => 25, "Overseas" => 18),
//Papenmeier, Herberts Industrieglas //Papenmeier, Herberts Industrieglas
65 => array("NSW" => 498, "VIC" => 537, "TAS" => 44, 65 => array("NSW" => 498, "VIC" => 537, "TAS" => 44,
"ACT" => 0, "QLD" => 158, "NT" => 12, "ACT" => 0, "QLD" => 158, "NT" => 12,
"WA" => 138, "SA" => 25, "Overseas" => 174), "WA" => 138, "SA" => 25, "Overseas" => 174),
//Analytical Systems, Misc //Analytical Systems, Misc
85 => array("NSW" => 3, "VIC" => 6, "TAS" => 0, 85 => array("NSW" => 3, "VIC" => 6, "TAS" => 0,
"ACT" => 0, "QLD" => 1, "NT" => 0, "ACT" => 0, "QLD" => 1, "NT" => 0,
"WA" => 2, "SA" => 2, "Overseas" => 0), "WA" => 2, "SA" => 2, "Overseas" => 0),
//Comet, T and D. //Comet, T and D.
95 => array("NSW" => 34, "VIC" => 28, "TAS" => 6, 95 => array("NSW" => 34, "VIC" => 28, "TAS" => 6,
"ACT" => 0, "QLD" => 29, "NT" => 0, "ACT" => 0, "QLD" => 29, "NT" => 0,
"WA" => 9, "SA" => 8, "Overseas" => 31), "WA" => 9, "SA" => 8, "Overseas" => 31),
); );
$stateprincipleenquiries += $stateprinciple_offset[$principle['Principle']['code']][$state['State']['shortform']]; $stateprincipleenquiries += $stateprinciple_offset[$principle['Principle']['code']][$state['State']['shortform']];
$stateprincipleenquiries++; $stateprincipleenquiries++;
/* Generate/set the enquiry number */ /* Generate/set the enquiry number */
$enquiryno = 'CMC'.$enquiryid.$state['State']['enqform'].'E'.$principle['Principle']['code'].$principleenquiries. $enquiryno = 'CMC'.$enquiryid.$state['State']['enqform'].'E'.$principle['Principle']['code'].$principleenquiries.
'-'.$stateprincipleenquiries; '-'.$stateprincipleenquiries;
return $enquiryno; return $enquiryno;
} }
/* Autocomplete the customer name - Used in: add.ctp */ /* Autocomplete the customer name - Used in: add.ctp */
function completeCustomer() { function completeCustomer() {
$this->set('customers', $this->Enquiry->Customer->find('all', array( $this->set('customers', $this->Enquiry->Customer->find('all', array(
'conditions' => array( 'conditions' => array(
'Customer.name LIKE' => '%'.$this->data['Customer']['name'].'%' 'Customer.name LIKE' => '%'.$this->data['Customer']['name'].'%'
),'fields' => array('Customer.name') ),'fields' => array('Customer.name')
))); )));
$this->layout = 'ajax'; $this->layout = 'ajax';
} }
/* Moving this to the new Enquiry email sender. */ /* Moving this to the new Enquiry email sender. */
function __sendNewEnquiryEmail($id) { function __sendNewEnquiryEmail($id) {
//Setup the SMTP Options //Setup the SMTP Options
$this->Email->smtpOptions = array( $this->Email->smtpOptions = array(
'port' => '25', 'port' => '25',
'timeout' => '30', 'timeout' => '30',
'host' => '192.168.0.8', 'host' => '192.168.0.8',
'username' => 'sales', 'username' => 'sales',
'password' => '2seng33+02'); 'password' => '2seng33+02');
$this->Email->delivery = 'smtp'; $this->Email->delivery = 'smtp';
$enquiry = $this->Enquiry->read(null, $id); $enquiry = $this->Enquiry->read(null, $id);
@ -382,7 +382,7 @@ class EnquiriesController extends AppController {
$this->set('billing_addresses', $customerAddresses); $this->set('billing_addresses', $customerAddresses);
$this->set('shipping_addresses', $customerAddresses); $this->set('shipping_addresses', $customerAddresses);
/* Feels like an ugly hack. But it gets the desired effect and it will do for now */ /* Feels like an ugly hack. But it gets the desired effect and it will do for now */
if(isset($customerAddresses[0]['BillingAddress'])) { if(isset($customerAddresses[0]['BillingAddress'])) {
$billing_address_list[0] = "No Address Selected"; $billing_address_list[0] = "No Address Selected";
@ -402,7 +402,7 @@ class EnquiriesController extends AppController {
$this->set(compact('enquiry', 'users','contacts','principles','statuses', 'addresses')); $this->set(compact('enquiry', 'users','contacts','principles','statuses', 'addresses'));
} }
/* function update_status($enquiryid) { /* function update_status($enquiryid) {
$newid = $this->params['form']['value']; $newid = $this->params['form']['value'];
@ -420,21 +420,66 @@ class EnquiriesController extends AppController {
function update_status() { function update_status() {
if($this->data) { if($this->data) {
App::import('Core', 'Sanitize'); App::import('Core', 'Sanitize');
$new_status = Sanitize::clean($this->data['Enquiry']['status_id']); $new_status = Sanitize::clean($this->data['Enquiry']['status_id']);
$this->Enquiry->id = $this->data['Enquiry']['id']; $this->Enquiry->id = $this->data['Enquiry']['id'];
$this->Enquiry->saveField('status_id', $new_status); $this->Enquiry->saveField('status_id', $new_status);
$this->set('enquiry', $this->Enquiry->findById($this->data['Enquiry']['id'])); $this->set('enquiry', $this->Enquiry->findById($this->data['Enquiry']['id']));
} }
} }
/**
* For the search query form
*/
function search() { function search() {
if(empty($this->data)) {
$this->Session->setFlash('Enter part of the Enquiry number you want to find'); }
/**
* Actually performs the searches
*/
function doSearch() {
if(!empty($this->data)) {
$searchQuery = $this->data['Enquiry']['search_string'];
$custConditions = array('Customer.name LIKE' => "%$searchQuery%");
$enqConditions = array('Enquiry.title LIKE' => "%$searchQuery%");
$words = explode(" ", $searchQuery);
if(count($words) == 2) {
$contactConditions = array('AND'=>array('Contact.first_name LIKE' => "%$words[0]%",
'Contact.last_name LIKE' => "%$words[1]"));
}
else {
$contactConditions = array('OR'=>array('Contact.first_name LIKE' => "%$searchQuery%",
'Contact.last_name LIKE' => "%$searchQuery"));
}
$customerResults = $this->Enquiry->Customer->find('all', array('conditions' => $custConditions, 'recursive'=>0));
$enquiryResults = $this->Enquiry->find('all', array('conditions'=>$enqConditions, 'recursive'=>0));
$contactResults = $this->Enquiry->find('all', array('conditions'=>$contactConditions, 'recursive'=>0));
$searchDone = true;
$statuses = $this->Enquiry->Status->find('all', array('recursive'=>0));
$status_list = array();
foreach ($statuses as $status) {
$statusid = $status['Status']['id'];
$status_list[$statusid] = $status['Status']['name'];
}
$this->set('status_list', $status_list);
$this->set(compact('customerResults', 'enquiryResults', 'contactResults', 'searchDone', 'status_list'));
$this->layout = 'ajax';
} }
} }
function mark_submitted($id = null) { function mark_submitted($id = null) {

View file

@ -14,7 +14,7 @@ class VaultShell extends Shell {
/****************************************************** /******************************************************
* Config Variables * Config Variables
* *****************************************************/ * *****************************************************/
$testing = 0; //Whether to actually move the emails. 1=test, 0=production $testing = 1; //Whether to actually move the emails. 1=test, 0=production
/* Setup Connection to the IMAP server */ /* Setup Connection to the IMAP server */
$username = 'vault'; $username = 'vault';
$password = 'xjdYOsmJWc37'; /* The password for the account to be checked */ $password = 'xjdYOsmJWc37'; /* The password for the account to be checked */
@ -42,7 +42,7 @@ class VaultShell extends Shell {
$number_of_messages = $MC->Nmsgs; $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) { if($number_of_messages == 0) {
exit(0); exit(0);
} }
@ -61,9 +61,12 @@ class VaultShell extends Shell {
$discardArray = array(); $discardArray = array();
//exit(0);
/* Loop through the messages and sort them into ones to be processed or discarded */ /* Loop through the messages and sort them into ones to be processed or discarded */
for ($i=1; $i <= $number_of_messages; $i++) {
for($i=1; $i <= $number_of_messages; $i++) {
$this_header = imap_headerinfo($mbox, $i); $this_header = imap_headerinfo($mbox, $i);
$message = $this->getMessage($mbox, $i, $this_header); $message = $this->getMessage($mbox, $i, $this_header);
@ -185,19 +188,41 @@ class VaultShell extends Shell {
/* Finished working with the IMAP server. Make the changes and close the connection */ /* Finished working with the IMAP server. Make the changes and close the connection */
if($testing == 0) { //if($testing == 0) {
echo "Tidying up now. Moving messages to Stored or Discarded\n";
reset($discardArray); reset($discardArray);
reset($storedArray); reset($storedArray);
$storeSet = implode(",", $storedArray); $numberToStore = count($storedArray);
$discardSet = implode(",",$discardArray); $numberToDiscard= count($discardArray);
echo "Tidying up now. Moving messages to Stored or Discarded\n";
imap_mail_move($mbox, $storeSet, 'INBOX/Stored'); if($numberToStore > 0) {
imap_mail_move($mbox, $discardSet, 'INBOX/Discarded'); echo "Got $numberToStore messages to store\n";
} $storeSet = implode(",", $storedArray);
imap_mail_move($mbox, $storeSet, 'INBOX/Stored');
}
if($numberToDiscard > 0) {
echo "Going to discard $numberToDiscard messages\n";
$discardSet = implode(",",$discardArray);
imap_mail_move($mbox, $discardSet, 'INBOX/Discarded');
}
//}
imap_expunge($mbox); imap_expunge($mbox);
imap_close($mbox); imap_close($mbox);
@ -346,19 +371,5 @@ class VaultShell extends Shell {
} }
/**
* Generate a uniq id.
*
*
*/
function getUniqId($email_dir) {
$uniqid = uniqid(null,TRUE);
return $uniqid;
}
} }
?> ?>

View file

@ -9,7 +9,6 @@ echo $paginator->counter(array(
<table cellpadding="0" cellspacing="0"> <table cellpadding="0" cellspacing="0">
<tr> <tr>
<th><?php echo $paginator->sort('customer_id');?></th> <th><?php echo $paginator->sort('customer_id');?></th>
<th><?php echo $paginator->sort('id');?></th>
<th><?php echo $paginator->sort('first_name');?></th> <th><?php echo $paginator->sort('first_name');?></th>
<th><?php echo $paginator->sort('last_name');?></th> <th><?php echo $paginator->sort('last_name');?></th>
<th><?php echo $paginator->sort('email');?></th> <th><?php echo $paginator->sort('email');?></th>
@ -30,9 +29,7 @@ foreach ($contacts as $contact):
<td> <td>
<?php echo $html->link($contact['Customer']['name'], array('controller'=> 'customers', 'action'=>'view', $contact['Customer']['id'])); ?> <?php echo $html->link($contact['Customer']['name'], array('controller'=> 'customers', 'action'=>'view', $contact['Customer']['id'])); ?>
</td> </td>
<td>
<?php echo $contact['Contact']['id']; ?>
</td>
<td> <td>
<?php echo $contact['Contact']['first_name']; ?> <?php echo $contact['Contact']['first_name']; ?>

View file

@ -0,0 +1,124 @@
<?php $enqCount = count($enquiryResults);
$custCount = count($customerResults);
$contactCount = count($contactResults);
?>
<?php if($enqCount > 0):
?>
<h2><?php echo $enqCount;?> Matching Enquiries</h2>
<table class="mer">
<tr>
<th>Date</th>
<th>Principle</th>
<th>Enquiry Number</th>
<th>Customer</th>
<th>Contact</th>
<th class="actions">Actions</th>
</tr>
<?php foreach ($enquiryResults as $enquiryRes):?>
<?php
/* Set Row colour to Yellow if the Job has been won and turned into an order */
if($enquiryRes['Status']['id'] == 3) {
$class = ' class="jobwon"';
}
else if($enquiryRes['Status']['id'] == 4) {
$class = ' class="joblost"';
}
else if($enquiryRes['Status']['id'] == 8) {
$class = ' class="joblost"';
}
else if($enquiryRes['Status']['id'] == 9) {
$class = ' class="joblost"';
}
else if($enquiryRes['Status']['id'] == 10) {
$class = ' class="joblost"';
}
else if($enquiryRes['Status']['id'] == 6) {
$class = ' class="information"';
}
else if($enquiryRes['Status']['id'] == 11) {
$class = ' class="informationsent"';
}
else if($enquiryRes['Status']['id'] == 5) {
$class = ' class="quoted"';
}
else if($enquiryRes['Status']['id'] == 1) {
$class = ' class="requestforquote"';
}
?>
<tr <?php echo $class; ?>>
<td><?php echo date('j M Y',$time->toUnix($enquiryRes['Enquiry']['created'])); ?></td>
<td> <?php
if($enquiryRes['Principle']['short_name']) {
echo $html->link($enquiryRes['Principle']['short_name'], array('controller'=> 'principles', 'action'=>'view', $enquiryRes['Principle']['id']));
}
else {
echo $html->link($enquiryRes['Principle']['name'], array('controller'=> 'principles', 'action'=>'view', $enquiryRes['Principle']['id']));
}
?>
</td>
<td><?php echo $html->link($enquiryRes['Enquiry']['title'], array('controller'=>'enquiries', 'action'=>'view', $enquiryRes['Enquiry']['id'])); ?></td>
<td> <?php echo $html->link($enquiryRes['Customer']['name'], array('controller'=> 'customers', 'action'=>'view', $enquiryRes['Customer']['id'])); ?></td>
<td> <?php echo $html->link($enquiryRes['Contact']['first_name'].' '.$enquiryRes['Contact']['last_name'], array('controller'=> 'contacts', 'action'=>'view', $enquiryRes['Contact']['id'])); ?></td>
<td><?php echo $html->link('View', array('controller'=>'enquiries', 'action'=>'view', $enquiryRes['Enquiry']['id'])); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif;?>
<?php if($custCount > 0):
?>
<h2><?php echo $custCount; ?> Matching Customers</h2>
<table>
<tr>
<th>Name</th>
<th class="actions"></th>
</tr>
<?php foreach($customerResults as $custRes): ?>
<tr>
<td><?php echo $custRes['Customer']['name'];?></td>
<td><?php echo $html->link(__('View', true), array('action'=>'view', $custRes['Customer']['id'])); ?></td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>
<?php if($contactCount > 0): ?>
<h2><?php echo $contactCount; ?> Matching Contacts</h2>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Customer</th>
<th class="actions"></th>
</tr>
<?php foreach($contactResults as $contact): ?>
<tr>
<td><?php echo $contact['Contact']['first_name'];?></td>
<td><?php echo $contact['Contact']['last_name'];?></td>
<td><?php echo $html->link($contact['Customer']['name'], array('controller'=> 'customers', 'action'=>'view', $contact['Customer']['id'])); ?></td>
<td><?php echo $html->link(__('View', true), array('action'=>'view', $contact['Contact']['id'])); ?></td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>

View file

@ -0,0 +1,26 @@
<?php echo $javascript->link('search'); ?>
<div class="customers form">
<?php echo $form->create('Enquiry', array('default'=>false));
echo '<h2>Quick Search';
echo $html->image('system-search.png');
echo '</h2>';
echo $form->input('Enquiry.search_string', array('Label'=>'Search for:', 'id'=>'searchString'));
//echo $form->input('Customer.id', array('type'=>'hidden'));
//echo $form->end('Search');
?>
<div class ="ui-widget">
<button id="searchButton">Search</button>
</div>
</div>
<div id="results"></div>

View file

@ -14,9 +14,9 @@
echo $html->css('quotenik'); echo $html->css('quotenik');
echo $html->css('jquery-ui.custom.css'); echo $html->css('jquery-ui.custom.css');
echo $javascript->link('ckeditor/ckeditor'); echo $javascript->link('ckeditor/ckeditor');
echo $javascript->link('jquery'); echo $javascript->link('jquery');
echo $javascript->link('jquery-ui'); echo $javascript->link('jquery-ui');
@ -25,7 +25,7 @@
echo $javascript->link('ckeditor/adapters/jquery'); echo $javascript->link('ckeditor/adapters/jquery');
echo $scripts_for_layout; echo $scripts_for_layout;
?> ?>
@ -98,11 +98,15 @@
</ul> </ul>
</li> </li>
<li><?php echo $html->link('Users', '/users/index'); ?> <?php /*<li> echo $html->link('Users', '/users/index'); ?>
<ul> <ul>
<li><?php echo $html->link('Users Index', '/users/index'); ?></li> <li> echo $html->link('Users Index', '/users/index'); </li>
<li class="last"><?php echo $html->link('Add User', '/users/add'); ?></li> <li class="last"><?php echo $html->link('Add User', '/users/add'); </li>
</ul> </ul>
</li>*/
?>
<li><?php echo $html->link('Search', '/enquiries/search'); ?>
</li> </li>
<li><?php echo $html->link('Help', '/pages/help'); ?> <li><?php echo $html->link('Help', '/pages/help'); ?>
<ul> <ul>

View file

@ -8,7 +8,7 @@ echo $paginator->counter(array(
?></p> ?></p>
<table cellpadding="0" cellspacing="0"> <table cellpadding="0" cellspacing="0">
<tr> <tr>
<th><?php echo $paginator->sort('id');?></th>
<th><?php echo $paginator->sort('name');?></th> <th><?php echo $paginator->sort('name');?></th>
<th><?php echo $paginator->sort('code');?></th> <th><?php echo $paginator->sort('code');?></th>
<th><?php echo $paginator->sort('country_id');?></th> <th><?php echo $paginator->sort('country_id');?></th>
@ -24,9 +24,7 @@ foreach ($principles as $principle):
} }
?> ?>
<tr<?php echo $class;?>> <tr<?php echo $class;?>>
<td>
<?php echo $principle['Principle']['id']; ?>
</td>
<td> <td>
<?php echo $principle['Principle']['name']; ?> <?php echo $principle['Principle']['name']; ?>
</td> </td>

View file

@ -376,7 +376,7 @@ table {
clear: both; clear: both;
color: #333; color: #333;
margin-bottom: 10px; margin-bottom: 10px;
width: 100%; width: auto;
} }
th { th {
background: #f2f2f2; background: #f2f2f2;
@ -603,6 +603,7 @@ table.productTable {
} }
/* Paging */ /* Paging */
div.paging { div.paging {
background:#fff; background:#fff;

View file

@ -0,0 +1,10 @@
/*
* file: globalsearch.js
*
* Use the jquery plugin to allow keyboard shortcut search from anywhere
*
* @TODO this.
*
*/

35
webroot/js/search.js Normal file
View file

@ -0,0 +1,35 @@
/*
* file: search.js
* Powers AJAX search of records in the CMC Sales System.
*
*
*/
$(function() {
$("#searchButton").button().click(function() {
doSearch();
return false;
});
});
function doSearch() {
$.post("/enquiries/doSearch", $("#searchString").serialize(), function(data) {
$("#results").html(data);
});
}