diff --git a/.gitignore b/.gitignore
index be3f36d1..837bba12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@ tmp/cache/views/*
tmp/sessions/*
tmp/tests/*
*.tar.gz
+*.swp
+*.swo
diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php
index 491dc102..28b7cc8a 100755
--- a/controllers/customers_controller.php
+++ b/controllers/customers_controller.php
@@ -4,6 +4,8 @@ class CustomersController extends AppController {
var $name = 'Customers';
var $helpers = array('Html', 'Form', 'Time', 'Ajax');
var $components = array('RequestHandler');
+
+
var $paginate = array(
'Customer' => array('order' => array('Customer.name' => 'asc'),
'limit' => 200
@@ -59,10 +61,12 @@ class CustomersController extends AppController {
function edit($id = null) {
+
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Customer', true));
$this->redirect(array('action'=>'index'));
}
+
if (!empty($this->data)) {
if ($this->Customer->saveAll($this->data)) {
$this->Session->setFlash(__('The Customer has been saved', true));
@@ -103,9 +107,28 @@ class CustomersController extends AppController {
$this->redirect(array('action'=>'view/'.$customer['Customer']['id']));
}
}
-
-
}
+ function tagindustries($id = null) {
+ if (!$id && empty($this->data)) {
+ $this->Session->setFlash(__('Invalid Customer', true));
+ $this->redirect(array('action'=>'index'));
+ }
+ if(!empty($this->data)) {
+ if($this->Customer->saveAll($this->data)) {
+ $this->Session->setFlash(__('The Industry Tags have been Saved to the Customer', true));
+ $this->redirect(array('action'=>'view/'.$this->data['Customer']['id']));
+ }
+ else {
+ $this->Session->setFlash(__('Something went wrong saving the Tags. Call for help!', true));
+ $this->redirect(array('action'=>'index'));
+ }
+ }
+ else {
+ $this->set('industries', $this->Customer->Industry->find('list', array('fields'=>array('Industry.id', 'Industry.name', 'ParentIndustry.name'),'recursive' => 0,
+ 'order'=>'ParentIndustry.name ASC, Industry.name ASC')));
+ $this->data = $this->Customer->read(null, $id);
+ }
+ }
}
?>
diff --git a/controllers/industries_controller.php b/controllers/industries_controller.php
index b94df0a5..86cf321f 100644
--- a/controllers/industries_controller.php
+++ b/controllers/industries_controller.php
@@ -11,7 +11,19 @@ class IndustriesController extends AppController {
function index() {
$this->Industry->recursive = 0;
+ $industries = $this->Industry->find('all', array('order'=>'Industry.name ASC'));
$this->set('industries', $this->paginate());
+
+
+
+ foreach ($industries as $industry) {
+ if(!$industry['Industry']['parent_id']) {
+ $parents[] = $industry['Industry'];
+ }
+ }
+
+ $this->set('parents', $parents);
+
}
function view($id = null) {
@@ -24,19 +36,36 @@ class IndustriesController extends AppController {
function add() {
if (!empty($this->data)) {
- $this->Industry->create();
+
if ($this->Industry->save($this->data)) {
- $this->Session->setFlash(__('The Industry has been saved', true));
+
+ $newid = $this->Industry->id;
+ $new_industry = $this->Industry->findById($newid);
+
+ if($new_industry['Industry']['parent_id'] == 0) {
+
+ $this->Industry->create();
+ $this->data['Industry']['parent_id'] = $newid;
+ $this->data['Industry']['name'] = $new_industry['Industry']['name']." - General";
+ $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));
}
}
+
+ $this->Industry->create();
+ if(isset($this->params['named']['parentid'])) {
+ $parent = $this->Industry->find('first', array('conditions' => array('Industry.id' => $this->params['named']['parentid']),
+ 'fields' => 'Industry.id, Industry.name', 'recursive' => 0));
+ $this->set('parent', $parent);
+ }
+
+
+
- /* Parent Industries have NULL for their parent_id */
- $parents = $this->Industry->find('list', array('conditions' => array(
- 'Industry.parent_id' => null)));
- $this->set(compact('parents'));
}
function edit($id = null) {
@@ -55,13 +84,6 @@ class IndustriesController extends AppController {
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) {
diff --git a/models/customer.php b/models/customer.php
index c8e6bbee..5c0fe723 100755
--- a/models/customer.php
+++ b/models/customer.php
@@ -3,9 +3,7 @@ class Customer extends AppModel {
var $name = 'Customer';
-
-
var $validate = array(
'name' => array(
'rule' => 'isUnique',
@@ -76,7 +74,7 @@ class Customer extends AppModel {
'className' => 'Industry',
'joinTable' => 'industries_customers',
'foreignKey' => 'customer_id',
- 'associationForeignKey' => 'industry_id',
+ 'associationForeignKey' => 'industry_id'
)
);
diff --git a/views/customers/edit.ctp b/views/customers/edit.ctp
index e528efde..c15a2b62 100755
--- a/views/customers/edit.ctp
+++ b/views/customers/edit.ctp
@@ -16,7 +16,7 @@
- echo $form->input('Industry.Industry', array('multiple'=>'checkbox', 'showParents'=>false, 'options' => $industries));
+ echo $form->input('Industry.Industry', array('multiple'=>'checkbox', 'showParents'=> false, 'options' => $industries));
?>
diff --git a/views/customers/view.ctp b/views/customers/view.ctp
index 526e2ae9..e7c58c71 100755
--- a/views/customers/view.ctp
+++ b/views/customers/view.ctp
@@ -56,7 +56,8 @@
}
echo "";
endif;
-
+echo "
";
+echo "
-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'])); ?> - | -