diff --git a/site/controllers/contacts_controller.php b/site/controllers/contacts_controller.php
index 84f319d..f045412 100644
--- a/site/controllers/contacts_controller.php
+++ b/site/controllers/contacts_controller.php
@@ -141,6 +141,12 @@ class ContactsController extends AppController {
$contact_phones = $this->Contact->ContactPhone->phoneList();
$this->set(compact('contact_phones'));
+ $contact_addresses = $this->Contact->ContactAddress->addressList();
+ $this->set(compact('contact_addresses'));
+
+ $contact_emails = $this->Contact->ContactEmail->emailList();
+ $this->set(compact('contact_emails'));
+
// Prepare to render.
//pr($this->data);
$title = $this->data['Contact']['display_name'] . " : Edit";
diff --git a/site/models/contact_address.php b/site/models/contact_address.php
index d064016..161b938 100644
--- a/site/models/contact_address.php
+++ b/site/models/contact_address.php
@@ -17,5 +17,23 @@ class ContactAddress extends AppModel {
'conditions' => "method = 'POST'",
)
);
+
+ function addressList() {
+ $results = $this->find('all',
+ array('contain' => false,
+ 'fields' => array('id', 'address', 'city', 'state', 'postcode'),
+ 'order' => array('state', 'city', 'postcode', 'address')));
+
+ $list = array();
+ foreach ($results as $key => $val) {
+ $list[$val['ContactAddress']['id']]
+ = preg_replace("/\n/", ", ", $val['ContactAddress']['address'])
+ . ', ' . $val['ContactAddress']['city']
+ . ', ' . $val['ContactAddress']['state']
+ . ' ' . $val['ContactAddress']['postcode']
+ ;
+ }
+ return $list;
+ }
}
?>
\ No newline at end of file
diff --git a/site/models/contact_email.php b/site/models/contact_email.php
index f2bbf75..6a8e4a1 100644
--- a/site/models/contact_email.php
+++ b/site/models/contact_email.php
@@ -2,6 +2,7 @@
class ContactEmail extends AppModel {
var $name = 'ContactEmail';
+ var $displayField = 'email';
var $validate = array(
'id' => array('numeric'),
'email' => array('email')
@@ -18,5 +19,9 @@ class ContactEmail extends AppModel {
)
);
+ function emailList() {
+ return $this->find('list');
+ }
+
}
?>
\ No newline at end of file
diff --git a/site/views/contacts/edit.ctp b/site/views/contacts/edit.ctp
index c0db5d2..c41b48d 100644
--- a/site/views/contacts/edit.ctp
+++ b/site/views/contacts/edit.ctp
@@ -6,7 +6,9 @@
* we can access them.
*/
$this->varstore = compact('methodTypes', 'methodPreferences',
- 'contactPhones', 'phoneTypes');
+ 'contactPhones', 'phoneTypes',
+ 'contactAddresses',
+ 'contactEmails');
//pr($this->data);
/**********************************************************************
@@ -38,7 +40,7 @@ function contactMethodDiv($obj, $type, $legend, $values = null) {
$stype = strtolower($sname);
$div .=
' array('name' => 'Address',
+ 'opts' => array('options' => $obj->varstore['contactAddresses'])),
+ );
+ }
+ elseif ($stype === 'new') {
+ $fields = array
+ ('address' => null,
+ 'city' => null,
+ 'state' => null,
+ 'postcode' => array('name' => 'Zip Code'),
+ 'country' => null,
+ 'comment' => null,
+ );
+ }
+ elseif ($stype === 'show') {
+ $element = 'table';
+ $column_class = array('field', 'value');
+ $rows = array
+ (array('Address', preg_replace("/\n/", "
", $values['address'])),
+ array('City', $values['city']),
+ array('State', $values['state']),
+ array('Zip Code', $values['postcode']),
+ array('Country', $values['country']),
+ array('Comment', $values['comment']),
+ );
+ }
+ else {
+ die("\n\nInvalid stype ($stype)\n\n");
+ }
+ }
+ elseif ($type === 'email') {
+/* [email] => abijah@PerkinsHouse.com */
+/* [comment] => */
+
+ if ($stype === 'existing') {
+ $fields = array
+ ('id' => array('name' => 'Email',
+ 'opts' => array('options' => $obj->varstore['contactEmails'])),
+ );
+ }
+ elseif ($stype === 'new') {
+ $fields = array
+ ('email' => null,
+ 'comment' => null,
+ );
+ }
+ elseif ($stype === 'show') {
+ $element = 'table';
+ $column_class = array('field', 'value');
+ $rows = array
+ (array('Email', $values['email']),
+ array('Comment', $values['comment']),
+ );
+ }
+ }
else {
- die("Invalid type ($type)");
+ die("\n\nInvalid type ($type)\n\n");
}
return
@@ -183,10 +243,36 @@ function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
);
}
+ function addAddress(flash) {
+ addDiv('address-entry-id', 'address', 'addresses', flash,
+ );
+ }
+
+ function addEmail(flash) {
+ addDiv('email-entry-id', 'email', 'emails', flash,
+ );
+ }
+
// Reset the form
function resetForm() {
$('#phones').html('');
+ $('#addresses').html('');
+ $('#emails').html('');
$('#phone-entry-id').val(1);
+ $('#address-entry-id').val(1);
+ $('#email-entry-id').val(1);
data['ContactPhone'] AS $phone): ?>
addDiv('phone-entry-id', 'phone', 'phones', false,
+ data['ContactAddress'] AS $address): ?>
+ addDiv('address-entry-id', 'address', 'addresses', false,
+ );
+
+
+ data['ContactEmail'] AS $email): ?>
+ addDiv('email-entry-id', 'email', 'emails', false,
+ );
+
+
}
function switchMethodSource(id, type, source) {
@@ -264,6 +376,28 @@ echo($this->element
+