Fixed up the vault and email handling. Added Customer Categories

This commit is contained in:
Karl Cordes 2009-02-12 15:02:05 +11:00
parent 5d757466eb
commit b6baa8ecd8
25 changed files with 618 additions and 179 deletions

View file

@ -0,0 +1,52 @@
<?php
class CustomerCategoriesController extends AppController {
var $name = 'CustomerCategories';
var $helpers = array('Html', 'Form');
function index() {
$this->CustomerCategory->recursive = 0;
$this->set('customerCategories', $this->paginate());
}
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid CustomerCategory.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('customerCategory', $this->CustomerCategory->read(null, $id));
}
function add() {
if (!empty($this->data)) {
$this->CustomerCategory->create();
if ($this->CustomerCategory->save($this->data)) {
$this->Session->setFlash(__('The CustomerCategory has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The CustomerCategory could not be saved. Please, try again.', true));
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid CustomerCategory', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
if ($this->CustomerCategory->save($this->data)) {
$this->Session->setFlash(__('The CustomerCategory has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The CustomerCategory could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->CustomerCategory->read(null, $id);
}
}
}
?>

View file

@ -14,6 +14,12 @@ class CustomersController extends AppController {
function index() { function index() {
$this->Customer->recursive = 0; $this->Customer->recursive = 0;
$this->set('customers', $this->paginate()); $this->set('customers', $this->paginate());
$this->set('customer_categories', $this->Customer->CustomerCategory->find('all'));
/* Show only customers from a particular category name */
if(isset($this->params['named']['showonly'])) {
$this->set('customers', $this->paginate('Customer', array('Customer.customer_category_id' => $this->params['named']['showonly'])));
}
} }
function view($id = null) { function view($id = null) {
@ -38,6 +44,7 @@ class CustomersController extends AppController {
$this->Session->setFlash(__('The Customer could not be saved. Please try again.', true)); $this->Session->setFlash(__('The Customer could not be saved. Please try again.', true));
} }
} }
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
$this->set('states', $this->Customer->Address->State->find('list')); $this->set('states', $this->Customer->Address->State->find('list'));
$this->set('countries', $this->Customer->Address->Country->find('list')); $this->set('countries', $this->Customer->Address->Country->find('list'));
@ -60,6 +67,7 @@ class CustomersController extends AppController {
} }
if (empty($this->data)) { if (empty($this->data)) {
$this->data = $this->Customer->read(null, $id); $this->data = $this->Customer->read(null, $id);
$this->set('customer_categories', $this->Customer->CustomerCategory->find('list'));
} }
} }

View file

@ -33,6 +33,7 @@ class EmailsController extends AppController {
function frame($id = null) { function frame($id = null) {
$this->set('id', $id); $this->set('id', $id);
$this->set('attachments', $this->Email->EmailAttachment->findAllByEmailId($id));
} }
function show($id = null) { function show($id = null) {

View file

@ -261,6 +261,7 @@ class EnquiriesController extends AppController {
$enquiry = $this->Enquiry->read(null, $id); $enquiry = $this->Enquiry->read(null, $id);
$this->Email->to = $enquiry['Contact']['email']; $this->Email->to = $enquiry['Contact']['email'];
$this->Email->cc = array($enquiry['User']['email']);
$this->Email->bcc = array('carpis@cmctechnologies.com.au'); $this->Email->bcc = array('carpis@cmctechnologies.com.au');
$this->Email->subject = $enquiry['Enquiry']['title'].' - Your Enquiry has been Entered in our System - CMC Technologies'; $this->Email->subject = $enquiry['Enquiry']['title'].' - Your Enquiry has been Entered in our System - CMC Technologies';

View file

@ -5,7 +5,11 @@ class UsersController extends AppController {
var $helpers = array('Html', 'Form'); var $helpers = array('Html', 'Form');
var $components = array('Acl','Auth'); var $components = array('Acl','Auth');
var $paginate = array( var $paginate = array(
'limit' => 250); 'Users' => array('order' => array('User.name' => 'asc'),
'limit' => 20
),
'Enquiry' => array('order' => array('Enquiry.id' => 'desc'), 'limit' => 250)
);
function beforeFilter() { function beforeFilter() {
$this->Auth->allow('add'); $this->Auth->allow('add');

View file

@ -66,5 +66,8 @@ class Customer extends AppModel {
) )
); );
var $belongsTo = array('CustomerCategory'=>array('className' => 'CustomerCategory',
'foreignKey' => 'customer_category_id'));
} }
?> ?>

View file

@ -0,0 +1,12 @@
<?php
class CustomerCategory extends AppModel {
var $name = 'CustomerCategory';
var $hasMany = array('Customer'=>array('className'=>'Customer',
'foreignKey'=>'customer_category_id'));
}

View file

@ -9,19 +9,17 @@ class VaultShell extends Shell {
var $uses = array('Enquiry', 'Email', 'EmailAttachment'); var $uses = array('Enquiry', 'Email', 'EmailAttachment');
function main() { function main() {
/******************************************************
* Config Variables
* *****************************************************/
$testing = 1; //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 */
$email_dir = '/var/www/quotenik1.2/app/emails/working'; $email_dir = '/var/www/quotenik1.2/app/emails/working';
$attachment_dir = '/var/www/quotenik1.2/app/emails/working/attachments';
$temp_filename = 'temp.eml'; $temp_filename = 'temp.eml';
$mbox = imap_open("{saturn:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error()); $mbox = imap_open("{saturn:143/novalidate-cert}INBOX", $username, $password) or die("can't connect: " . imap_last_error());
$MC = imap_check($mbox); $MC = imap_check($mbox);
$number_of_messages = $MC->Nmsgs; $number_of_messages = $MC->Nmsgs;
@ -29,19 +27,9 @@ class VaultShell extends Shell {
/* 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);
preg_match("/CMC\d+([NVQWSO]|ACT|NT)E\d+-\d+/", $this_header->subject, $output); $enquiry = $this->checkIfValidEnquiry($mbox, $i, $this_header, $testing);
if(isset($output[0])) { if($enquiry != FALSE) {
//Process it and store the message and its attachments.
$fetched_enquirynumber = $output[0];
$enquiry = $this->Enquiry->findByTitle($fetched_enquirynumber);
if($enquiry['Enquiry']['id'] == NULL) { //It passes the Regex - but we don't find an Enquiry for it in the MER.
if($testing == 0) { //testing mode.
imap_mail_move($mbox, $i, 'INBOX/Discarded'); //Discard it.
}
}
else { //Process it and store the message and its attachments.
$message = $this->getMessage($mbox, $i, $this_header); $message = $this->getMessage($mbox, $i, $this_header);
$this->Email->create(); $this->Email->create();
@ -51,43 +39,78 @@ class VaultShell extends Shell {
$this->data['Email']['from'] = $message['from']; $this->data['Email']['from'] = $message['from'];
$this->data['Email']['date'] = $message['date']; $this->data['Email']['date'] = $message['date'];
$this->data['Email']['subject'] = $message['subject']; $this->data['Email']['subject'] = $message['subject'];
$this->data['Email']['body'] = $message['body']; $this->data['Email']['body'] = "";
$this->data['Email']['plainbody'] = "";
$structure = imap_fetchstructure($mbox, $i);
if (empty($structure->parts)) { /* A single part message. No attachments and is plain text */
$this->data['Email']['body'] = imap_body($mbox, $i);
}
else {
$attachments = $this->fetchBodyAttachments($mbox, $i, $temp_filename, $email_dir);
foreach ($attachments as $attachment) {
if($attachment['type'] == 'text/html') { //Assuming All HTML attachments are the body of the email
$filecontents = file_get_contents($email_dir.'/'.$attachment['name']);
$size = filesize($email_dir.'/'.$attachment['name']);
$this->data['Email']['body'] .= $filecontents;
}
if($attachment['type'] == 'text/plain') { //Found plain text
$filecontents = file_get_contents($email_dir.'/'.$attachment['name']);
$size = filesize($email_dir.'/'.$attachment['name']);
$this->data['Email']['plainbody'] .= $filecontents;
}
}
}
//Sanitize::clean($this->data); //Sanitize::clean($this->data);
if($this->Email->save($this->data)) { if($this->Email->save($this->data)) {
$email_id = $this->Email->id; $email_id = $this->Email->id;
if(isset($attachments)) {
$attachment_files = $this->fetchAttachments($mbox, $i, $temp_filename, $email_dir, $attachment_dir); foreach ($attachments as $attachment) {
foreach ($attachment_files as $attachment) { if( ($attachment['type'] != 'text/html') && ($attachment['type'] != 'multipart/mixed') &&
($attachment['type'] != 'multipart/alternative') ) {
$this->EmailAttachment->create(); $this->EmailAttachment->create();
$this->data['EmailAttachment']['email_id'] = $email_id; $this->data['EmailAttachment']['email_id'] = $email_id;
$this->data['EmailAttachment']['name'] = $attachment; $this->data['EmailAttachment']['name'] = $attachment['name'];
$this->data['EmailAttachment']['type'] = mime_content_type("$attachment_dir/$attachment"); //Depreciated but works better than the new one $this->data['EmailAttachment']['type'] = $attachment['type'];
$this->data['EmailAttachment']['size'] = filesize("$attachment_dir/$attachment"); $this->data['EmailAttachment']['size'] = filesize($email_dir.'/'.$attachment['name']);
$this->data['EmailAttachment']['data'] = fread(fopen("$attachment_dir/$attachment", "r"), $this->data['EmailAttachment']['size']); $this->data['EmailAttachment']['data'] = file_get_contents($email_dir.'/'.$attachment['name']);
if ($this->EmailAttachment->save($this->data)) { if ($this->EmailAttachment->save($this->data)) {
echo "Saved file successfully to database\n"; echo "Saved file successfully to database\n";
} }
else { else {
echo "Something went wrong saving the file to the DB\n"; echo "Something went wrong saving the file to the DB\n";
} }
}
}
} }
echo "Email stored in the DB under enquiry ".$enquiry['Enquiry']['title']." Will be moved to the stored folder\n"; 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. 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. imap_mail_move($mbox, $i, 'INBOX/Stored'); //Move it to the stored folder.
} }
$this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachment_dir, $attachment_files);
if(isset($attachments)) {
$this->clearEmailAttachmentDirs($email_dir, $temp_filename, $attachments);
}
} }
else { else {
echo 'Unable to save the Email\n'; echo 'Unable to save the Email\n';
} }
}
} } else {
else {
/* Can't find a valid-looking CMC Enquiry Number. Move the message to the discarded folder /* 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. * 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.
* */ * */
@ -103,60 +126,50 @@ 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 */
imap_expunge($mbox); imap_expunge($mbox);
imap_close($mbox); imap_close($mbox);
}
}
/*
* Fetches the body and attachments from a MIME encoded email. Uses ripmime to do the decoding
*
*/
function fetchBodyAttachments($mailbox, $msg_number, $filename, $email_dir) {
/* Fetches and Writes attachements to a directory under $email_dir.
* Uses uudeview to do the decoding
* */
function fetchAttachments($mailbox, $msg_number, $filename, $email_dir, $attachment_dir) {
/* Make the temporary directory to store this email and the attachments */
if (!file_exists($email_dir)){
mkdir($email_dir);
}
if (!file_exists($attachment_dir)) {
mkdir($attachment_dir);
}
$email_file = $email_dir.'/'.$filename; $email_file = $email_dir.'/'.$filename;
imap_savebody($mailbox, $email_file, $msg_number); imap_savebody($mailbox, $email_file, $msg_number);
$command = "uudeview -i $email_file -p $attachment_dir"; $command = "ripmime -i $email_file -d $email_dir -v --verbose-contenttype --paranoid --prefix $msg_number";
$output = array(); $output = array();
exec($command, $output); exec($command, $output);
/* Check the $output array and find the filenames of the attachments */ /* Check the $output array and find the filenames of the attachments */
$filenames = array(); $attachments = array();
for($i=0; $i< count($output); $i++) { for($i=0, $j=0; $i< count($output); $i++, $j++) {
$matches = preg_match("/\bsuccessfully\b/", $output[$i]); $words = explode(' ', $output[$i]);
if($matches > 0) { $type = explode('=', $words[1]);
$result = explode("/", $output[$i]); $name = explode('=', $words[2]);
$filenames[] = $result[8]; // $attachments[$j]['type'] = $type[1];
} $attachments[$j]['name'] = $name[1];
}
return $filenames; }
return $attachments;
} }
/* clearEmailyAttachmentDirs($email_dir, $filename, $attachment_dir, $attachments) /* clearEmailyAttachmentDirs($email_dir, $filename, $attachment_dir, $attachments)
* *
* Deletes $email_dir/$filename.eml and the attachments specified in $attachment_dir * Deletes $email_dir/$filename.eml and the attachments specified by $attachments
* */ * */
function clearEmailAttachmentDirs($email_dir, $filename, $attachment_dir, $attachments) { function clearEmailAttachmentDirs($email_dir, $filename, $attachments) {
unlink("$email_dir/$filename"); unlink("$email_dir/$filename");
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
unlink("$attachment_dir/$attachment"); unlink($email_dir.'/'.$attachment['name']);
} }
} }
@ -172,9 +185,6 @@ function getMessage($mbox, $msgnumber, $headers) {
$message['to'] = $recipients['to']; $message['to'] = $recipients['to'];
$message['from'] = $recipients['from']; $message['from'] = $recipients['from'];
$message['cc'] = $recipients['cc']; $message['cc'] = $recipients['cc'];
$message['body'] = $this->getBody($mbox, $msgnumber);
return $message; return $message;
} }
@ -213,8 +223,6 @@ function getRecipients($headers) {
} }
} }
return $recipients; return $recipients;
} }
@ -230,59 +238,27 @@ function getBody($mbox, $msgnumber) {
return $body; return $body;
} }
function checkIfValidEnquiry($mbox, $msgnumber, $this_header, $testing) {
function getParts($parts, $mbox, $msgnumber) { preg_match("/CMC\d+([NVQWSO]|ACT|NT)E\d+-\d+/", $this_header->subject, $output);
for ($i = 0, $j = count($parts); $i < $j; $i++) { if(isset($output[0])) { //Found a valid-looking Enquiry Number
$part = $parts[$i]; $fetched_enquirynumber = $output[0];
$bodystruct = imap_bodystruct($mbox, $msgnumber, $i+1); $enquiry = $this->Enquiry->findByTitle($fetched_enquirynumber);
if ($part->subtype == 'HTML') { /* Find the HTML component of the body */ if($enquiry['Enquiry']['id'] == NULL) { //It passes the Regex - but we don't find an Enquiry for it in the MER.
$body = imap_fetchbody($mbox, $msgnumber, $i+1); if($testing == 0) { //testing mode == 1, production == 0.
imap_mail_move($mbox, $i, 'INBOX/Discarded'); //Discard it.
if($bodystruct->subtype != 'HTML') {
continue;
}
if($bodystruct->subtype == 'HTML') {
break; //Found HTML (preferred) So end the loop.
}
}
elseif($part->subtype == 'PLAIN') {
$body = imap_fetchbody($mbox, $msgnumber, $i+1);
break;
}
elseif(isset($part->parts)) {
$body = getParts($part->parts, $mbox, $msgnumber); /* Handle these goddamn Outlook messages */
} }
} }
return $body; else {
return $enquiry; // Valid Enquiry if we've found the enquiry in the Master Enquiry Register
}
}
else {
return FALSE;
}
} }
/*
function getParts($parts, $mbox, $msgnumber) {
for ($i = 0, $j = count($parts); $i < $j; $i++) {
$part = $parts[$i];
if ($part->subtype == 'HTML') { /* Find the HTML component of the body
$body = imap_fetchbody($mbox, $msgnumber, $i+1);
break; //Found HTML (preferred) So end the loop.
}
elseif($part->subtype == 'PLAIN') {
$body = imap_fetchbody($mbox, $msgnumber, $i+1);
}
elseif(isset($part->parts)) {
$body = $this->getParts($part->parts, $mbox, $msgnumber); /* Handle these goddamn Outlook messages
}
}
return $body;
}
*/
} }

View file

@ -0,0 +1,17 @@
<div class="customerCategories form">
<?php echo $form->create('CustomerCategory');?>
<fieldset>
<legend><?php __('Add CustomerCategory');?></legend>
<?php
echo $form->input('name');
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('List CustomerCategories', true), array('action'=>'index'));?></li>
<li><?php echo $html->link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
</ul>
</div>

View file

@ -0,0 +1,19 @@
<div class="customerCategories form">
<?php echo $form->create('CustomerCategory');?>
<fieldset>
<legend><?php __('Edit CustomerCategory');?></legend>
<?php
echo $form->input('id');
echo $form->input('name');
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Delete', true), array('action'=>'delete', $form->value('CustomerCategory.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('CustomerCategory.id'))); ?></li>
<li><?php echo $html->link(__('List CustomerCategories', true), array('action'=>'index'));?></li>
<li><?php echo $html->link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
</ul>
</div>

View file

@ -0,0 +1,50 @@
<div class="customerCategories index">
<h2><?php __('CustomerCategories');?></h2>
<p>
<?php
echo $paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?></p>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $paginator->sort('id');?></th>
<th><?php echo $paginator->sort('name');?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($customerCategories as $customerCategory):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td>
<?php echo $customerCategory['CustomerCategory']['id']; ?>
</td>
<td>
<?php echo $customerCategory['CustomerCategory']['name']; ?>
</td>
<td class="actions">
<?php echo $html->link(__('View', true), array('action'=>'view', $customerCategory['CustomerCategory']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('action'=>'edit', $customerCategory['CustomerCategory']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="paging">
<?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="actions">
<ul>
<li><?php echo $html->link(__('New CustomerCategory', true), array('action'=>'add')); ?></li>
<li><?php echo $html->link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
</ul>
</div>

View file

@ -0,0 +1,73 @@
<div class="customerCategories view">
<h2><?php __('CustomerCategory');?></h2>
<dl><?php $i = 0; $class = ' class="altrow"';?>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $customerCategory['CustomerCategory']['id']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Name'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $customerCategory['CustomerCategory']['name']; ?>
&nbsp;
</dd>
</dl>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Edit CustomerCategory', true), array('action'=>'edit', $customerCategory['CustomerCategory']['id'])); ?> </li>
<li><?php echo $html->link(__('Delete CustomerCategory', true), array('action'=>'delete', $customerCategory['CustomerCategory']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $customerCategory['CustomerCategory']['id'])); ?> </li>
<li><?php echo $html->link(__('List CustomerCategories', true), array('action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New CustomerCategory', true), array('action'=>'add')); ?> </li>
<li><?php echo $html->link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?> </li>
</ul>
</div>
<div class="related">
<h3><?php __('Related Customers');?></h3>
<?php if (!empty($customerCategory['Customer'])):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Id'); ?></th>
<th><?php __('Name'); ?></th>
<th><?php __('Abn'); ?></th>
<th><?php __('Created'); ?></th>
<th><?php __('Notes'); ?></th>
<th><?php __('Payment Terms'); ?></th>
<th><?php __('Discount Pricing Policies'); ?></th>
<th><?php __('Customer Category Id'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($customerCategory['Customer'] as $customer):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $customer['id'];?></td>
<td><?php echo $customer['name'];?></td>
<td><?php echo $customer['abn'];?></td>
<td><?php echo $customer['created'];?></td>
<td><?php echo $customer['notes'];?></td>
<td><?php echo $customer['payment_terms'];?></td>
<td><?php echo $customer['discount_pricing_policies'];?></td>
<td><?php echo $customer['customer_category_id'];?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'customers', 'action'=>'view', $customer['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'customers', 'action'=>'edit', $customer['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'customers', 'action'=>'delete', $customer['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $customer['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add'));?> </li>
</ul>
</div>
</div>

View file

@ -18,6 +18,10 @@
echo $this->element('payment_terms_box'); echo $this->element('payment_terms_box');
echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies')); echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies'));
echo '<div class="input select">';
echo $form->label('Customer.customer_category_id', 'Customer Category');
echo $form->select('customer_category_id', $customer_categories, 0, array('label'=>'Customer Category'), false);
echo '</div>';
echo $form->input('notes', array('label' => 'Notes about this Customer')); echo $form->input('notes', array('label' => 'Notes about this Customer'));
echo '<br><br>'; echo '<br><br>';

View file

@ -9,6 +9,10 @@
echo $this->element('payment_terms_box'); echo $this->element('payment_terms_box');
echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies')); echo $form->input('discount_pricing_policies', array('label'=>'Discount and Pricing Policies'));
echo $form->input('notes'); echo $form->input('notes');
echo '<div class="input select">';
echo $form->label('Customer.customer_category_id', 'Customer Category');
echo $form->select('customer_category_id', $customer_categories, 0, array('label'=>'Customer Category'), false);
echo '</div>';
?> ?>
</fieldset> </fieldset>
<?php echo $form->end('Submit');?> <?php echo $form->end('Submit');?>

View file

@ -1,5 +1,12 @@
<div class="customers index"> <div class="customers index">
<h2><?php __('Customers');?></h2> <h2><?php __('Customers');?></h2>
<span>
<?php echo 'Or Show Only: ';
foreach($customer_categories as $category) {
echo $html->link($category['CustomerCategory']['name'], array('action'=>"index/showonly:".$category['CustomerCategory']['id'])).' ';
}
?><br>
</span><br>
<p> <p>
<?php <?php
echo $paginator->counter(array( echo $paginator->counter(array(
@ -12,6 +19,7 @@ echo $paginator->counter(array(
<th><?php echo $paginator->sort('Company Name', 'name');?></th> <th><?php echo $paginator->sort('Company Name', 'name');?></th>
<th><?php echo $paginator->sort('ABN', 'abn');?></th> <th><?php echo $paginator->sort('ABN', 'abn');?></th>
<th><?php echo $paginator->sort('Payment Terms', 'payment_terms'); ?></th> <th><?php echo $paginator->sort('Payment Terms', 'payment_terms'); ?></th>
<th><?php echo $paginator->sort('Category', 'customer_category_id'); ?></th>
<th><?php echo $paginator->sort('Date Added', 'created');?></th> <th><?php echo $paginator->sort('Date Added', 'created');?></th>
<th class="actions"><?php __('Actions');?></th> <th class="actions"><?php __('Actions');?></th>
</tr> </tr>
@ -22,6 +30,18 @@ foreach ($customers as $customer):
if ($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class="altrow"'; $class = ' class="altrow"';
} }
if($customer['Customer']['customer_category_id'] == 1) {
$class = ' class="customer-suspect"';
}
if($customer['Customer']['customer_category_id'] == 2) {
$class = ' class="customer-prospect"';
}
if($customer['Customer']['customer_category_id'] == 3) {
$class = ' class="customer-customer"';
}
?> ?>
<tr<?php echo $class;?>> <tr<?php echo $class;?>>
@ -34,6 +54,10 @@ foreach ($customers as $customer):
<td> <td>
<?php echo $customer['Customer']['payment_terms']; ?> <?php echo $customer['Customer']['payment_terms']; ?>
</td> </td>
<td>
<?php echo $customer['CustomerCategory']['name']; ?>
</td>
<td> <td>
<?php echo date('j M Y',$time->toUnix($customer['Customer']['created'])); ?> <?php echo date('j M Y',$time->toUnix($customer['Customer']['created'])); ?>

View file

@ -31,6 +31,11 @@
<?php echo $customer['Customer']['notes']; ?> <?php echo $customer['Customer']['notes']; ?>
&nbsp; &nbsp;
</dd> </dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Category'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $customer['CustomerCategory']['name']; ?>
&nbsp;
</dd>
</dl> </dl>
</div> </div>

View file

@ -0,0 +1,57 @@
<div class="related">
<h3><?php __('Attachments in this Email');?></h3>
<?php if (!empty($attachments)):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Name'); ?></th>
<th><?php __('Type'); ?></th>
<th><?php __('Size'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($attachments as $emailAttachment):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $emailAttachment['EmailAttachment']['name'];?></td>
<td>
<? if($emailAttachment['EmailAttachment']['type'] == 'application/pdf') {
echo $html->image('pdf_type.png');
}
else if($emailAttachment['EmailAttachment']['type'] == 'application/msword') {
echo $html->image('document_type.png');
}
else if($emailAttachment['EmailAttachment']['type'] == 'application/vnd.ms-excel') {
echo $html->image('spreadsheet_document_type.png');
}
else if($emailAttachment['EmailAttachment']['type'] == 'image/jpeg') {
echo $html->image('image_type.png');
}
else if($emailAttachment['EmailAttachment']['type'] == 'text/plain') {
echo $html->image('text-x-generic.png');
}
else {
echo $html->image('unknown_type.png');
}
?>
</td>
<td><?php echo $number->toReadableSize($emailAttachment['EmailAttachment']['size']);?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'email_attachments', 'action'=>'download', $emailAttachment['EmailAttachment']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>

View file

@ -1,3 +1,11 @@
<div id="emailframe">
<h3>Email</h3>
<iframe src ="<?php echo $html->url("show/$id"); ?>" width="100%" height="500px"> <iframe src ="<?php echo $html->url("show/$id"); ?>" width="100%" height="500px">
<p>This function only works with a Modern Browser that uses Iframes. Sorry.</p> <p>This function only works with a Modern Browser that uses Iframes. Sorry.</p>
</iframe> </iframe>
</div>
<div id="emailattachments">
<?php echo $this->element('email_attachments', $attachments); ?>
</div>

52
views/emails/print.ctp Normal file
View file

@ -0,0 +1,52 @@
<? App::import('Sanitize'); ?>
<div id="viewemail">
Enquiry Number: <?php echo $email['Enquiry']['title']; ?> <br>
Date: <?php echo $email['Email']['date']; ?> <br>
Subject: <?php echo $email['Email']['subject']; ?> <br>
To: <?php echo $email['Email']['to']; ?> <br>
From: <?php echo $email['Email']['from']; ?> <br>
CC: <?php echo $email['Email']['cc']; ?> <br>
<div id="emailbody">
<?php
/* strip out thinks messing up my link styles! */
$cleanbody = Sanitize::html($email['Email']['body']);
?>
<?php echo $cleanbody; ?>
</div>
<div class="related">
<h3><?php __('Attachments');?></h3>
<?php if (!empty($email['EmailAttachment'])):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Name'); ?></th>
<th><?php __('Type'); ?></th>
<th><?php __('Size'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($email['EmailAttachment'] as $emailAttachment):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $emailAttachment['name'];?></td>
<td><?php echo $emailAttachment['type'];?></td>
<td><?php echo $number->toReadableSize($emailAttachment['size']);?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
</div>

View file

@ -41,40 +41,5 @@
<?php echo $cleanbody; ?> <?php echo $cleanbody; ?>
</div> </div>
<div class="related">
<h3><?php __('Attachments');?></h3>
<?php if (!empty($email['EmailAttachment'])):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Name'); ?></th>
<th><?php __('Type'); ?></th>
<th><?php __('Size'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($email['EmailAttachment'] as $emailAttachment):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $emailAttachment['name'];?></td>
<td><?php echo $emailAttachment['type'];?></td>
<td><?php echo $number->toReadableSize($emailAttachment['size']);?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'email_attachments', 'action'=>'download', $emailAttachment['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
</div> </div>

View file

@ -97,14 +97,16 @@
<li><?php echo $html->link(__('Edit Enquiry', true), array('action'=>'edit', $enquiry['Enquiry']['id'])); ?> </li> <li><?php echo $html->link(__('Edit Enquiry', true), array('action'=>'edit', $enquiry['Enquiry']['id'])); ?> </li>
</ul> </ul>
</div> </div>
<div id="showemail">
</div>
<div class="related"> <div class="related">
<h3><?php __($number_of_emails.' Emails for this Enquiry');?><?php echo $html->image('internet-mail.png'); ?></h3> <h3><?php __($number_of_emails.' Emails for this Enquiry');?><?php echo $html->image('internet-mail.png'); ?></h3>
<?php echo $this->element('email_table_ajax', $emails); ?> <?php echo $this->element('email_table_ajax', $emails); ?>
</div> </div>
<div id="showemail">
</div>
<div class="related"> <div class="related">
<h3><?php __($number_of_quotes.' Quotes in this Enquiry');?></h3> <h3><?php __($number_of_quotes.' Quotes in this Enquiry');?></h3>
<?php echo $this->element('quote_table', $quotes); ?> <?php echo $this->element('quote_table', $quotes); ?>

View file

@ -1,5 +1,5 @@
<? <?
echo $html->css('quotenik'); echo $html->css('email');
?> ?>
<body> <body>
<div id="content"> <div id="content">

86
webroot/css/email.css Normal file
View file

@ -0,0 +1,86 @@
#emailbody {
text-align: left;
font-size: 100%;
background-color: #FFFFFF;
color: #000000;
}
dl.mailheaders {
line-height: 2em;
margin: 0em 0em;
width: 100%;
color: #000000;
font-size: 85%;
}
dl.altrow {
background: #f4f4f4;
}
dt {
font-weight: bold;
padding-left: 4px;
vertical-align: top;
}
dt.altrow {
background: #E6F0F0;
}
dd {
margin-left: 20em;
margin-top: -2em;
vertical-align: top;
}
dd.altrow {
background: #E6F0F0;
}
/* Tables */
table {
background: #fff;
border:1px solid #ccc;
border-right:0;
clear: both;
color: #333;
margin-bottom: 10px;
width: 100%;
}
th {
background: #f2f2f2;
border:1px solid #bbb;
border-top: 1px solid #fff;
border-left: 1px solid #fff;
text-align: center;
}
th a {
background:#f2f2f2;
display: block;
padding: 2px 4px;
text-decoration: none;
}
th a:hover {
background: #ccc;
color: #333;
text-decoration: none;
}
table tr td {
background: #fff;
border-right: 1px solid #ccc;
text-align: center;
vertical-align: top;
padding: 1px;
}
table tr.altrow td {
background: #f4f4f4;
}
td.actions {
text-align: center;
white-space: nowrap;
}
td.actions a {
margin: 0px 6px;
}

View file

@ -212,12 +212,7 @@ a#mailheaders {
font-size: 80%; font-size: 80%;
} }
#emailbody {
text-align: left;
font-size: 100%;
background-color: #FFFFFF;
color: #000000;
}
#printemailbody { #printemailbody {
text-align: left; text-align: left;
@ -229,7 +224,17 @@ a#mailheaders {
#showemail { #showemail {
padding-top:1em; padding-top:1em;
width: 70%; width: 100%;
}
#emailframe {
float: left;
width: 50%;
}
#emailattachments {
padding-right: 2em;
float: right;
} }
dl#showemail { dl#showemail {
@ -281,6 +286,17 @@ table tr td {
table tr.altrow td { table tr.altrow td {
background: #f4f4f4; background: #f4f4f4;
} }
table tr.customer-suspect td {
background: #65BFDC;
}
table tr.customer-prospect td {
background: #F4F42F;
}
table tr.customer-customer td {
background: #63D463;
}
td.actions { td.actions {
text-align: center; text-align: center;
white-space: nowrap; white-space: nowrap;

Binary file not shown.

After

Width:  |  Height:  |  Size: 523 B