diff --git a/site/app_model.php b/site/app_model.php index 0f8aa86..64c398b 100644 --- a/site/app_model.php +++ b/site/app_model.php @@ -47,13 +47,15 @@ class AppModel extends Model { * * Gets the enum values for MySQL 4 and 5 to use in selectTag() */ - function getEnumValues($columnName=null, $respectDefault=false) + function getEnumValues($columnName=null, $tableName=null) { if ($columnName==null) { return array(); } //no field specified - //Get the name of the table - $db =& ConnectionManager::getDataSource($this->useDbConfig); - $tableName = $db->fullTableName($this, false); + if (!isset($tableName)) { + //Get the name of the table + $db =& ConnectionManager::getDataSource($this->useDbConfig); + $tableName = $db->fullTableName($this, false); + } //Get the values for the specified column (database and version specific, needs testing) $result = $this->query("SHOW COLUMNS FROM {$tableName} LIKE '{$columnName}'"); diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php index d61d64d..7baa3ae 100644 --- a/site/controllers/contacts_controller.php +++ b/site/controllers/contacts_controller.php @@ -46,6 +46,11 @@ class ContactsController extends AppController { return $order; } + function jqGridRecordLinks(&$params, &$model, &$records, $links) { + $links['Contact'] = array('id'); + return parent::jqGridRecordLinks($params, $model, $records, $links); + } + /************************************************************************** ************************************************************************** @@ -72,8 +77,69 @@ class ContactsController extends AppController { 'conditions' => array('Contact.id' => $id), )); + // Set up dynamic menu items + $this->sidemenu_links[] = + array('name' => 'Operations', 'header' => true); + + $this->sidemenu_links[] = + array('name' => 'Edit', + 'url' => array('action' => 'edit', + $id)); + // Prepare to render. $title = $contact['Contact']['display_name']; $this->set(compact('contact', 'title')); } + + + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: edit + */ + + function edit($id = null) { + if (isset($this->data)) { + pr($this->data); + $this->autoRender = false; + return; + } + + if (!$id) { + $this->Session->setFlash(__('Invalid Item.', true)); + $this->redirect(array('action'=>'index')); + } + + $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]); + $this->set(compact('phone_types')); + + $method_types = array_flip($this->Contact->getEnumValues('type', 'pmgr_contacts_methods')); + unset($method_types[0]); + $this->set(compact('method_types')); + + $method_preferences = array_flip($this->Contact->getEnumValues('preference', 'pmgr_contacts_methods')); + unset($method_preferences[0]); + $this->set(compact('method_preferences')); + + $contact_phones = $this->Contact->ContactPhone->phoneList(); + $this->set(compact('contact_phones')); + + // Prepare to render. + //pr($this->data); + $title = $this->data['Contact']['display_name'] . " : Edit"; + $this->set(compact('title')); + } } diff --git a/site/models/contact_phone.php b/site/models/contact_phone.php index f53b61d..012afcf 100644 --- a/site/models/contact_phone.php +++ b/site/models/contact_phone.php @@ -1,7 +1,6 @@ array('numeric'), //'type' => array('inlist'), @@ -20,5 +19,21 @@ class ContactPhone extends AppModel { ) ); + function phoneList() { + $results = $this->find('all', + array('contain' => false, + 'fields' => array('id', 'phone', 'ext'), + 'order' => array('phone', 'ext'))); + + App::Import('Helper', 'Format'); + $list = array(); + foreach ($results as $key => $val) { + $list[$val['ContactPhone']['id']] + = FormatHelper::phone($val['ContactPhone']['phone'], + $val['ContactPhone']['ext']); + } + return $list; + } + } ?> \ No newline at end of file diff --git a/site/views/contacts/edit.ctp b/site/views/contacts/edit.ctp index cee1f04..07ba1e1 100644 --- a/site/views/contacts/edit.ctp +++ b/site/views/contacts/edit.ctp @@ -1,21 +1,30 @@ +/********************************************************************** + ********************************************************************** + ********************************************************************** + ********************************************************************** + * Javascript + */ +