From 1456d4ff0437ced80b82118de5e4b89c1d0ef55f Mon Sep 17 00:00:00 2001 From: Karl Cordes Date: Fri, 3 Jul 2009 11:11:22 +1000 Subject: [PATCH] Inudstries working ok --- config/core.php | 2 +- controllers/enquiries_controller.php | 8 +- controllers/industries_controller.php | 74 ++++++++++++++++ models/customer.php | 12 +++ vendors/shells/vault.php | 61 +++++++++---- views/customers/view.ctp | 4 + views/industries/.add.ctp.swp | Bin 0 -> 12288 bytes views/industries/.edit.ctp.swo | Bin 0 -> 12288 bytes views/industries/.edit.ctp.swp | Bin 0 -> 12288 bytes views/industries/.view.ctp.swp | Bin 0 -> 16384 bytes views/industries/add.ctp | 21 +++++ views/industries/edit.ctp | 25 ++++++ views/industries/index.ctp | 56 ++++++++++++ views/industries/view.ctp | 120 ++++++++++++++++++++++++++ views/layouts/default.ctp | 22 +++-- webroot/css/quotenik.css | 66 +++++++++++--- 16 files changed, 434 insertions(+), 37 deletions(-) create mode 100644 controllers/industries_controller.php create mode 100644 views/industries/.add.ctp.swp create mode 100644 views/industries/.edit.ctp.swo create mode 100644 views/industries/.edit.ctp.swp create mode 100644 views/industries/.view.ctp.swp create mode 100644 views/industries/add.ctp create mode 100644 views/industries/edit.ctp create mode 100644 views/industries/index.ctp create mode 100644 views/industries/view.ctp 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 @@ + + + + diff --git a/views/industries/.add.ctp.swp b/views/industries/.add.ctp.swp new file mode 100644 index 0000000000000000000000000000000000000000..6d0f748e9bd9b3d31a91f69c00913a9138fe77e5 GIT binary patch literal 12288 zcmeI2&2AGh5XW5(h)5I=73$TbNZv?o+>`@I*=~dohoTlCAvnMxa@Q`gvR`<;S#s$M z@Gd+6Cr*6|PH^JP1HgE9l~m#*A>vfV(qF5!Co`U($CvCJ@4h%VqW8Kz0^+No}Z_|yN&zJlSnjrxsfCP{L5#jnVcXQ2LUp#OFh)#07N&_cX%xZIen45+*yUizL}+!Iz&wLqV%F*O=^&s!hiHp~ z9_rlAqB?J@goSQq_4Y3VyKJ8dqY_IG>SpNaqUiIc>3@=S6Bc@~R}H*M-WBjagq|Pf z%=;i{4%2sa)>FcNvb->!}GHq6$wcD}q$QWNh4Dv=(0RvgFLvQB?cmE(z4k<68a z7dO$W%dxiCNmf{o%?h#8|FuC@o!wAF!TrV}5wWTkt4$H=E`WLs`)MwLtN8~~&X3=1 k4>GN7;M&Z$`Ey#KQNk*ZH6*8XZs*wmzNW>Vy3Byl4->sjH2?qr literal 0 HcmV?d00001 diff --git a/views/industries/.edit.ctp.swo b/views/industries/.edit.ctp.swo new file mode 100644 index 0000000000000000000000000000000000000000..76d8b00d5377eb136292df47081b3f8a54cbfc24 GIT binary patch literal 12288 zcmeI2zi-n(6vwX&NCgTA286_Lv_*ELByP$;rMiv~KcoUhNC*~&>S|w_Q!lo;JI7=| zNU*`g|G>n+AHc)}e*pghBN8(MNbt@!O{CJML`=~;=_@DaclYjn?!6^>TT2huH|UjS zi@-Qd$ja@FTQ@(RBd-<+*2V`Ygc@gK-+O(gygbjn$5~={EOuJWWsjw)*B3n3 zo`|DN8zs2*cqB|SH0fb>MH?i51jZ7`OsBCjM=me7mKNqO(z9nCj9r2TNB{{S0VIF~ zkN^@u0!RP}Ocw!@&X8Xa(h<;k&`c$G;6MUM00|%gB!C2v01`j~NB{{S0VIF~ri1{C z2>Eu55Plp2g8%>RZvbCT5%M1N4)he%2R#A>pbMZMCkgou`U?64`T%+hdIS1AM@SC( zd4iBAwas>~&30>@(o@@kC#5?Zhrt940IlTsrvPq9C zr%sK^c&$#EQf%NlVG2@AQt)X4k9T zZ4$T8;LD%7~_CmWV-d3+-}hy;t~f8D zw%GYL9JMNVTi-XJ_kEb__UJ&NG=dn0A?yt~RGgWSdn)4|i2N(dGtqN{x&r(A4vKF4H0 zNU*W-KQJ*cBPJ&J1NaXZ`3D$4f_JfrBb7EKVk+;XubiBp-@Es@dmfUvw|0N~Hoe?j zCos+t^6ufzt(za0Np+WyK2y?6&l+JQ)GQlw-x)IHWLf4sP9x1j(O++FI4q8xq2O8K zh%iVKtpraT9thp^b$k@BXoCchz)S+E?l!J0lFg0vwUz2cx^({D%tz1w2_OL^fCP{L z55qii(b%BoYXQeLZ5rW705mLG*$MN-18Est7$VV8iR z#e6NI5aulw1XiuqqHT}54n&(BbVnq564iK{CoDAh@+W^8*krrQ6c07s&ijK$v!a)M z#Q!AgA}q8e&l`B2yvM)~30-dH#CzL2;$~jwl54&%o6=?Q+hDaDsX@aVGMRGQDwZ>9 z3UhqwG)$$e(1P*d#u5iGSRcvIgup!dBz>t^XdAvc0|M47_= ZlzqjSp4z88?`dvuR*DvTYO)4?zW~Jgo)rK9 literal 0 HcmV?d00001 diff --git a/views/industries/.view.ctp.swp b/views/industries/.view.ctp.swp new file mode 100644 index 0000000000000000000000000000000000000000..09b1902eed78b7f38b61faff8ee6b38601efc789 GIT binary patch literal 16384 zcmeI2UuYaf9LJ}%wLNXM>VpbCOfT1NjwZQFTBxL(3o(^iX-l-VB564GZs&4KHhb&t zUeBZSNf5LO;vf3rKlDk|C-Ffnh@b_Z{DUZhPa=X3>T?DEd}nqiySckwHZirW%)uvn z+5OGG@BHRBH#1u)o;-Y%?jIQ?`0OC$wa1P=c;Cf4$+-bS77Wkkw^#Z&4a-}}hCeTy zHoQWs)hayRYy`})7Dh+L3WnMm5owBDX^jf&7d}X z?{>0xY_vF#-AV7b{gD-uCJ_OH#r$7zt1H)i9xCi{am5^`11@HO>0uM*^m6tGEx&q|3YW!R&89b+PC#cot7VDG-;#^kOKP*hU z)}l}1b-J|{&0obs+I~grfhoN@b`mZIx;pX)(aX!a!{LK?E}YDSM_`yHjm1oe$J|-C zi)Aurg~B=U0Ap8MD$|CGx3by+{+y55oV8~U-9^Xf!~`wo=^1{1DH-p7ZW;L}w~hwS ztd^*tHb)JAS*!EoNR_itauMl8RfXfP%iP@+($+a>Eo)iNxOKc)8IA@^I2EK1T4Ah8 z5vt^1?DEB~NQ9^ohob&5@QCFHG63?LcZR??Z*(+!g2%a4>@0i28hiP^XgI@Ux{AA2{7^`e5r3^(a^mWC+(?T^ z0HQNSB`@e&a!F%9k&;%}605f1W z_ygEOHvh^X7g3%+fl6Cp^%R|i%q-n8mE`v%GKzMu*`Qj z61%Wno3=8=tY+f8ke?fsv3Jf-OUkZ1H%gg-8=fJR1966wGLa+BlTsR2qqC)y<_6B0 eQksVA>2yMMNO}!yY)?nwCfe1OeVXsFrTq_W;Z5BD literal 0 HcmV?d00001 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 @@ +
+create('Industry');?> +
+ + input('name'); + echo $form->input('parent_id'); + echo $form->input('Customer'); + ?> +
+end('Submit');?> +
+
+
    +
  • link(__('List Industries', true), array('action'=>'index'));?>
  • +
  • link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?>
  • +
  • link(__('New Parent Industry', true), array('controller'=> 'industries', 'action'=>'add')); ?>
  • +
  • link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?>
  • +
  • link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?>
  • +
+
diff --git a/views/industries/edit.ctp b/views/industries/edit.ctp new file mode 100644 index 00000000..b39b5b4f --- /dev/null +++ b/views/industries/edit.ctp @@ -0,0 +1,25 @@ +
+create('Industry');?> +
+ + input('id'); + echo $form->input('name'); + echo $form->input('parent_id'); + echo $form->input('Customer'); + ?> +
+end('Submit');?> +
+
+
    +
  • 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'))); ?>
  • +
  • link(__('List Industries', true), array('action'=>'index'));?>
  • +
  • link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?>
  • +
  • link(__('New Parent Industry', true), array('controller'=> 'industries', 'action'=>'add')); ?>
  • +
  • link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?>
  • +
  • link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?>
  • +
+
+ +data); ?> diff --git a/views/industries/index.ctp b/views/industries/index.ctp new file mode 100644 index 00000000..b9f26152 --- /dev/null +++ b/views/industries/index.ctp @@ -0,0 +1,56 @@ +
+

+

+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'])); ?> +
+
+
+ prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));?> + | numbers();?> + next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?> +
+
+
    +
  • link(__('New Industry', true), array('action'=>'add')); ?>
  • +
  • link(__('List Industries', true), array('controller'=> 'industries', 'action'=>'index')); ?>
  • +
  • link(__('New Parent Industry', true), array('controller'=> 'industries', 'action'=>'add')); ?>
  • +
  • link(__('List Customers', true), array('controller'=> 'customers', 'action'=>'index')); ?>
  • +
  • link(__('New Customer', true), array('controller'=> 'customers', 'action'=>'add')); ?>
  • +
+
diff --git a/views/industries/view.ctp b/views/industries/view.ctp new file mode 100644 index 00000000..1a7194f6 --- /dev/null +++ b/views/industries/view.ctp @@ -0,0 +1,120 @@ +
+

link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id'])) + .': '.$industry['Industry']['name']); } + else { + + __('Industry: '.$industry['Industry']['name']); + } + + ?>

+
+ > + > + +   + + > + > + link($industry['ParentIndustry']['name'], array('controller'=> 'industries', 'action'=>'view', $industry['ParentIndustry']['id'])); ?> +   + +
+
+
+
    +
  • link(__('Edit Industry', true), array('action'=>'edit', $industry['Industry']['id'])); ?>
  • +
  • link(__('Delete Industry', true), array('action'=>'delete', $industry['Industry']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $industry['Industry']['id'])); ?>
  • +
  • link(__('List Industries', true), array('action'=>'index')); ?>
  • +
  • link(__('New Industry', true), array('action'=>'add')); ?>
  • +
+
+ + + + + + diff --git a/views/layouts/default.ctp b/views/layouts/default.ctp index 8dc2c790..06253045 100755 --- a/views/layouts/default.ctp +++ b/views/layouts/default.ctp @@ -1,7 +1,6 @@ @@ -64,9 +63,10 @@ if (window.attachEvent) window.attachEvent("onload", sfHover);