Inudstries working ok

This commit is contained in:
Karl Cordes 2009-07-03 11:11:22 +10:00
parent cc2476dd7b
commit 1456d4ff04
16 changed files with 434 additions and 37 deletions

View file

@ -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
*/

View file

@ -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');
}
}
}
?>

View file

@ -0,0 +1,74 @@
<?php
class IndustriesController extends AppController {
var $name = 'Industries';
var $helpers = array('Html', 'Form');
function index() {
$this->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'));
}
}
}
?>

View file

@ -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'
)
);
}
?>

View file

@ -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,21 +140,42 @@ 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);

View file

@ -133,3 +133,7 @@
</div>
</div>
<? debug($customer, true); ?>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

21
views/industries/add.ctp Normal file
View file

@ -0,0 +1,21 @@
<div class="industries form">
<?php echo $form->create('Industry');?>
<fieldset>
<legend><?php __('Add Industry');?></legend>
<?php
echo $form->input('name');
echo $form->input('parent_id');
echo $form->input('Customer');
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('List Industries', true), array('action'=>'index'));?></li>
<li><?php echo $html->link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Parent Industry', true), array('controller'=> 'industries', '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>

25
views/industries/edit.ctp Normal file
View file

@ -0,0 +1,25 @@
<div class="industries form">
<?php echo $form->create('Industry');?>
<fieldset>
<legend><?php __('Edit Industry');?></legend>
<?php
echo $form->input('id');
echo $form->input('name');
echo $form->input('parent_id');
echo $form->input('Customer');
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Delete', true), array('action'=>'delete', $form->value('Industry.id')), null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('Industry.id'))); ?></li>
<li><?php echo $html->link(__('List Industries', true), array('action'=>'index'));?></li>
<li><?php echo $html->link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Parent Industry', true), array('controller'=> 'industries', '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>
<?php debug($this->data); ?>

View file

@ -0,0 +1,56 @@
<div class="industries index">
<h2><?php __('Industries');?></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><?php echo $paginator->sort('parent_id');?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($industries as $industry):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td>
<?php echo $industry['Industry']['id']; ?>
</td>
<td>
<?php echo $industry['Industry']['name']; ?>
</td>
<td>
<?php echo $html->link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id'])); ?>
</td>
<td class="actions">
<?php echo $html->link(__('View', true), array('action'=>'view', $industry['Industry']['id'])); ?>
<?php echo $html->link(__('Edit', true), array('action'=>'edit', $industry['Industry']['id'])); ?>
<?php echo $html->link(__('Delete', true), array('action'=>'delete', $industry['Industry']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $industry['Industry']['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 Industry', true), array('action'=>'add')); ?></li>
<li><?php echo $html->link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Parent Industry', true), array('controller'=> 'industries', '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>

120
views/industries/view.ctp Normal file
View file

@ -0,0 +1,120 @@
<div class="industries view">
<h2><?php
if($industry['ParentIndustry']['name']) {
__('Industry: '.$html->link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id']))
.': '.$industry['Industry']['name']); }
else {
__('Industry: '.$industry['Industry']['name']);
}
?></h2>
<dl><?php $i = 0; $class = ' class="altrow"';?>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Name'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $industry['Industry']['name']; ?>
&nbsp;
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Parent Industry'); ?></dt>
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $html->link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id'])); ?>
&nbsp;
</dd>
</dl>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Edit Industry', true), array('action'=>'edit', $industry['Industry']['id'])); ?> </li>
<li><?php echo $html->link(__('Delete Industry', true), array('action'=>'delete', $industry['Industry']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $industry['Industry']['id'])); ?> </li>
<li><?php echo $html->link(__('List Industries', true), array('action'=>'index')); ?> </li>
<li><?php echo $html->link(__('New Industry', true), array('action'=>'add')); ?> </li>
</ul>
</div>
<div class="related">
<h3><?php __('Sub-Industries');?></h3>
<?php if (!empty($industry['subIndustry'])):?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php __('Name'); ?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($industry['subIndustry'] as $subIndustry):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $subIndustry['name'];?></td>
<td class="actions">
<?php echo $html->link(__('View', true), array('controller'=> 'industries', 'action'=>'view', $subIndustry['id'])); ?>
<?php echo $html->link(__('Edit', true), array('controller'=> 'industries', 'action'=>'edit', $subIndustry['id'])); ?>
<?php echo $html->link(__('Delete', true), array('controller'=> 'industries', 'action'=>'delete', $subIndustry['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $subIndustry['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Sub Industry', true), array('controller'=> 'industries', 'action'=>'add'));?> </li>
</ul>
</div>
</div>
<div class="related">
<h3><?php __('Related Customers');?></h3>
<?php if (!empty($industry['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 ($industry['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

@ -1,7 +1,6 @@
<?php
/* SVN FILE: $Id: default.ctp 7118 2008-06-04 20:49:29Z gwoo $ */
/**
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
@ -64,9 +63,10 @@ if (window.attachEvent) window.attachEvent("onload", sfHover);
<body>
<div id="container">
<div id="header">
<h3>CMC Technologies</h3>
<h3 id="logo">CMC Technologies</h3>
<div id="username">
<div id="username">
<?php
if(isset($currentuser) == FALSE) {
echo $html->link('Login', '/users/login');
@ -77,12 +77,12 @@ if (window.attachEvent) window.attachEvent("onload", sfHover);
}
?>
</div>
<div id = "nav">
<ul id="nav">
<li><h3><?php echo $html->link('Enquiries', '/enquiries/index'); ?></h3>
<ul>
<li><?php echo $html->link('Enquiry Register', '/enquiries/index'); ?></li>
</ul>
</li>
@ -139,6 +139,18 @@ if (window.attachEvent) window.attachEvent("onload", sfHover);
</div>
<div id="searchbox-appear">
<?php echo $form->create('Enquiry', array('id'=>'searchbox', 'action'=>'search'));
echo $form->input('Enquiry No', array('label'=>false, 'id'=>'searchbox', 'div'=>false));
echo $form->submit('Quick Lookup', array('div'=>false));
echo $form->end();
?>
</div>
</div>
<div id="content">
<?php

View file

@ -32,7 +32,7 @@
/* General Style Info */
body {
background: #E9E9E9;
/* background: #E9E9E9; */
/* background: #7B9AB6; */
color: #000000;
font-family:'lucida grande',verdana,helvetica,arial,sans-serif;
@ -71,6 +71,11 @@ h2 {
/* padding-top: 0.8em; */
}
h2 a {
color: #e32;
font-weight: normal;
}
a.headerlinks {
color: #EE3322;
font-weight:normal;
@ -81,6 +86,10 @@ h3 {
font-size: 165%;
/* padding-top: 1.5em; */
}
h3#logo {
color: #FFFFFF;
}
h4 {
color: #993;
font-weight: normal;
@ -103,14 +112,15 @@ ul.principle-emails {
}
#header{
padding-bottom: 10px;
//background: #E9E9E9 url(../img/top-gradient2.png) repeat-x bottom;
background: url(../img/gradient-green.png) repeat-x bottom;
/* background: #E9E9E9 url(../img/top-gradient2.png) repeat-x bottom;
//background: #7bf47b url(../img/gradient-green2.png) repeat-x bottom; */
background: #6BBA70;
padding-bottom: 2%;
}
#header h1 {
/* background: #003d4c url('../img/cmclogo.png') no-repeat left; */
background: #E9E9E9;
/* background: #E9E9E9; */
color: #000000;
font-size: 200%;
padding: 0;
@ -128,6 +138,11 @@ ul.principle-emails {
text-decoration: underline;
}
#searchbox-appear {
display: none;
padding:0;
}
#username {
position: absolute;
right:0;
@ -141,13 +156,13 @@ ul.principle-emails {
#nav {
width: 100%;
}
}
#nav h3 {
font-size: 120%;
font-weight: bold;
color:#000000;
background: #E9E9E9;
/* background: #E9E9E9; */
padding-left: 0.1em;
padding-top: 0;
padding-right: 0;
@ -159,12 +174,12 @@ ul.principle-emails {
font-weight: bold;
color:#000000;
width: 100%;
background: #E9E9E9;
/* background: #E9E9E9; */
text-decoration:none;
}
#nav h3 a:hover {
background: #E9E9E9;
/* background: #E9E9E9; */
}
#nav, #nav ul { /* all lists */
@ -179,12 +194,10 @@ ul.principle-emails {
padding-bottom:0.5em;
display: block;
width: 10em;
background: #E9E9E9;
}
#nav a:hover {
background:#90EE90;
}
#nav li { /* all list items */
@ -197,15 +210,22 @@ ul.principle-emails {
#nav li ul { /* second-level lists */
position: absolute;
width: 10em;
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
left: -999em; /* using left instead of display to hide menus because display: none it read by screen readers */
}
#nav li:hover ul, #nav li.sfhover ul { /* lists nested under hovered list items */
left: auto;
}
#nav li ul a {
background: #6BBA70;
color: #000000;
}
#nav li ul a:hover {
background:#90EE90;
}
@ -538,6 +558,14 @@ form {
padding: 0;
width: 50%;
}
form#searchbox {
clear:auto;
width: auto;
margin-right: 0px;
}
fieldset {
border: 1px solid #ccc;
margin-top: 30px;
@ -570,6 +598,11 @@ form div {
padding: .5em;
vertical-align: text-top;
}
form div#searchbox {
clear: right;
margin-right: 0px;
}
form div.input {
color: #444;
}
@ -609,6 +642,13 @@ input, textarea {
padding: 1px;
width: 100%;
}
input#searchbox {
clear:auto;
display: inline;
margin-right:0;
display: auto;
width: 100px;
}
select {
clear: both;
font-size: 120%;