diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php index 38c9330..845ac5c 100644 --- a/site/controllers/contacts_controller.php +++ b/site/controllers/contacts_controller.php @@ -98,14 +98,35 @@ class ContactsController extends AppController { * action: edit */ - function edit($id = null) { + function edit($id = null, $customer_id = null) { if (isset($this->data)) { if (isset($this->params['form']['cancel'])) { - $this->redirect(array('action'=>'view', $this->data['Contact']['id'])); + if (isset($this->data['Contact']['id'])) + $this->redirect(array('action'=>'view', $this->data['Contact']['id'])); +/* else */ +/* $this->redirect(array('controller' => 'customers', */ +/* 'action'=>'add', $this->data['Customer']['id'])); */ return; } + if (!$this->data['Contact']['display_name']) + $this->data['Contact']['display_name'] = + (($this->data['Contact']['first_name'] && + $this->data['Contact']['last_name']) + ? $this->data['Contact']['last_name'] . ', ' . $this->data['Contact']['first_name'] + : ($this->data['Contact']['first_name'] + ? $this->data['Contact']['first_name'] + : $this->data['Contact']['last_name'])); + + $this->Contact->create(); + if (!$this->Contact->save($this->data, false)) { + pr("CONTACT SAVE FAILED"); + $this->Session->setFlash("CONTACT SAVE FAILED", true); + return; + } + $this->data['Contact']['id'] = $this->Contact->id; + // Remove all associated ContactMethods, as it ensures // any entries deleted by the user actually get deleted // in the system. We'll recreate the needed ones anyway. @@ -158,22 +179,27 @@ class ContactsController extends AppController { return; } - if (!$id) { - $this->Session->setFlash(__('Invalid Item.', true)); - $this->redirect(array('action'=>'index')); + if ($id) { + $this->data = $this->Contact->find + ('first', array + ('contain' => array + (// Models + 'ContactPhone', + 'ContactEmail', + 'ContactAddress', + 'Customer'), + + 'conditions' => array('Contact.id' => $id), + )); + + $title = $this->data['Contact']['display_name'] . " : Edit"; + } + else { + $title = "Enter New Contact"; + $this->data = array('ContactPhone' => array(), + 'ContactAddress' => array(), + 'ContactEmail' => array()); } - - $this->data = $this->Contact->find - ('first', array - ('contain' => array - (// Models - 'ContactPhone', - 'ContactEmail', - 'ContactAddress', - 'Customer'), - - 'conditions' => array('Contact.id' => $id), - )); $phone_types = array_flip($this->Contact->ContactPhone->getEnumValues('type')); unset($phone_types[0]); @@ -208,7 +234,20 @@ class ContactsController extends AppController { // Prepare to render. //pr($this->data); - $title = $this->data['Contact']['display_name'] . " : Edit"; $this->set(compact('title')); + $this->render('edit'); } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: add + * - Adds a new contact + */ + + function add($customer_id = null) { + $this->edit(null, $customer_id); + } + } diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php index 997f9c5..24f7e3b 100644 --- a/site/controllers/customers_controller.php +++ b/site/controllers/customers_controller.php @@ -230,6 +230,17 @@ class CustomersController extends AppController { $this->sidemenu_links[] = array('name' => 'Operations', 'header' => true); + $this->sidemenu_links[] = + array('name' => 'Edit', + 'url' => array('action' => 'edit', + $id)); + + $this->sidemenu_links[] = + array('name' => 'Add Contact', + 'url' => array('controller' => 'contacts', + 'action' => 'add', + $id)); + $this->sidemenu_links[] = array('name' => 'Move-In', 'url' => array('action' => 'move_in', diff --git a/site/views/contacts/edit.ctp b/site/views/contacts/edit.ctp index 87b36d2..86e0592 100644 --- a/site/views/contacts/edit.ctp +++ b/site/views/contacts/edit.ctp @@ -342,13 +342,13 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) { echo '