git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@763 97e9348a-65ac-dc4b-aefc-98561f571b83
463 lines
14 KiB
PHP
463 lines
14 KiB
PHP
<?php /* -*- mode:PHP -*- */
|
|
|
|
/**********************************************************************
|
|
* Because we make use of functions here,
|
|
* we need to put our top level variables somewhere
|
|
* we can access them.
|
|
*/
|
|
$this->varstore = compact('methodTypes', 'methodPreferences',
|
|
'contactPhones', 'phoneTypes',
|
|
'contactAddresses',
|
|
'contactEmails');
|
|
|
|
//pr($this->data);
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* Javascript
|
|
*/
|
|
|
|
function contactMethodDiv($obj, $type, $legend, $values = null) {
|
|
|
|
$div =
|
|
// BEGIN type-div
|
|
'<DIV>' . "\n" .
|
|
// BEGIN type-fieldset
|
|
'<FIELDSET CLASS="'.$type.' subset">' . "\n" .
|
|
'<LEGEND>'.$legend.' #%{id} (%{remove})</LEGEND>' . "\n" .
|
|
|
|
// BEGIN source-div
|
|
'<DIV ID="'.$type.'-%{id}-source-div">' . "\n" .
|
|
// BEGIN source-fieldset
|
|
'<FIELDSET>' . "\n" .
|
|
//'<LEGEND>Source</LEGEND>' . "\n" .
|
|
''
|
|
;
|
|
|
|
if (!isset($values)) {
|
|
foreach (array('Existing', 'New') AS $sname) {
|
|
$stype = strtolower($sname);
|
|
$div .=
|
|
'<INPUT TYPE="radio" ' . "\n" .
|
|
' NAME="data[Contact'.ucfirst($type).'][%{id}][source]"' . "\n" .
|
|
' ONCLICK="switchMethodSource(%{id}, '."'{$type}', '{$stype}'".')"' . "\n" .
|
|
' CLASS="'.$type.'-method-%{id}-source" ' . "\n" .
|
|
' ID="'.$type.'-method-%{id}-source-'.$stype.'"' . "\n" .
|
|
' VALUE="'.$stype.'"' . "\n" .
|
|
($stype == 'new' ? ' CHECKED' . "\n" : '') .
|
|
' />' . "\n" .
|
|
' <LABEL FOR="'.$type.'-method-%{id}-source-'.$stype.'">'.$sname.'</LABEL>' . "\n" .
|
|
' ';
|
|
}
|
|
}
|
|
$div .= "\n";
|
|
|
|
if (isset($values)) {
|
|
$div .= contactMethodTypeDiv($obj, $type, 'show', $values);
|
|
}
|
|
else {
|
|
$div .= contactMethodTypeDiv($obj, $type, 'existing');
|
|
$div .= contactMethodTypeDiv($obj, $type, 'new');
|
|
}
|
|
|
|
$div .=
|
|
// END source-fieldset
|
|
'</FIELDSET>' . "\n" .
|
|
// END source-div
|
|
'</DIV>' . "\n" .
|
|
|
|
// BEGIN method-div
|
|
'<div id="'.$type.'-%{id}-method-div"' . "\n" .
|
|
|
|
$obj->element
|
|
('form_table',
|
|
array('class' => "item contact-{$type} entry",
|
|
'field_prefix' => 'Contact'.ucfirst($type).'.%{id}.ContactsMethod',
|
|
'fields' => array
|
|
(
|
|
'preference' => array
|
|
('label_attributes' => array('class' => 'required'),
|
|
'opts' => array
|
|
('options' => $obj->varstore['methodPreferences'],
|
|
'selected' => (isset($values) ? $values['ContactsMethod']['preference'] : null),
|
|
),
|
|
'after' => "Intended purpose for this method of communication.",
|
|
),
|
|
|
|
'type' => array
|
|
('label_attributes' => array('class' => 'required'),
|
|
'opts' => array
|
|
('options' => $obj->varstore['methodTypes'],
|
|
'selected' => (isset($values) ? $values['ContactsMethod']['type'] : null),
|
|
),
|
|
'after' => "How / Where this communication reaches the contact.",
|
|
),
|
|
|
|
'comment' => array
|
|
('label_attributes' => array('class' => 'optional empty'),
|
|
'opts' => array
|
|
('value' => (isset($values) ? $values['ContactsMethod']['comment'] : null),
|
|
),
|
|
'after' => "Optional: Comments on how this form of communication relates to the contact.",
|
|
),
|
|
|
|
))) . "\n" .
|
|
|
|
// END method-div
|
|
'</div>' . "\n" .
|
|
|
|
// END type-fieldset
|
|
'</FIELDSET>' . "\n" .
|
|
// END type-div
|
|
'</DIV>'
|
|
;
|
|
|
|
return $div;
|
|
}
|
|
|
|
function contactMethodTypeDiv($obj, $type, $stype, $values = null) {
|
|
|
|
$element = 'form_table';
|
|
|
|
if ($type === 'phone') {
|
|
if ($stype === 'existing') {
|
|
$fields = array
|
|
('id' => array('label_attributes' => array('class' => 'required empty'),
|
|
'name' => 'Phone/Ext',
|
|
'opts' => array('options' => $obj->varstore['contactPhones'])),
|
|
);
|
|
}
|
|
elseif ($stype === 'new') {
|
|
$fields = array
|
|
('type' => array('label_attributes' => array('class' => 'required'),
|
|
'opts' => array('options' => $obj->varstore['phoneTypes']),
|
|
'after' => "Physical type of the phone."),
|
|
'phone' => array('label_attributes' => array('class' => 'required empty'),
|
|
'after' => "Required: Phone number."),
|
|
'ext' => array('name' => "Extension",
|
|
'label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: Extension number."),
|
|
'comment' => array('label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: Comments about this phone number."),
|
|
);
|
|
}
|
|
elseif ($stype === 'show') {
|
|
$element = 'table';
|
|
$column_class = array('field', 'value');
|
|
$rows = array
|
|
(array('Type', $values['type']),
|
|
array('Phone', $values['phone']),
|
|
array('Extension', $values['ext']),
|
|
array('Comment', $values['comment']),
|
|
);
|
|
}
|
|
else {
|
|
die("\n\nInvalid stype ($stype)\n\n");
|
|
}
|
|
|
|
}
|
|
elseif ($type === 'address') {
|
|
if ($stype === 'existing') {
|
|
$fields = array
|
|
('id' => array('name' => 'Address',
|
|
'opts' => array('options' => $obj->varstore['contactAddresses'])),
|
|
);
|
|
}
|
|
elseif ($stype === 'new') {
|
|
$fields = array
|
|
('address' => array('label_attributes' => array('class' => 'required empty'),
|
|
'after' => "Required: First line of mailing address."),
|
|
'city' => array('label_attributes' => array('class' => 'required empty'),
|
|
'after' => "Required."),
|
|
'state' => array('label_attributes' => array('class' => 'required empty'),
|
|
'after' => "Required."),
|
|
'postcode' => array('name' => 'Zip Code',
|
|
'label_attributes' => array('class' => 'required empty'),
|
|
'after' => "Required."),
|
|
'country' => array('label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: USA is presumed."),
|
|
'comment' => array('label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: Comments about this mailing address."),
|
|
);
|
|
}
|
|
elseif ($stype === 'show') {
|
|
$element = 'table';
|
|
$column_class = array('field', 'value');
|
|
$rows = array
|
|
(array('Address', preg_replace("/\n/", "<BR>", $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') {
|
|
if ($stype === 'existing') {
|
|
$fields = array
|
|
('id' => array('name' => 'Email',
|
|
'label_attributes' => array('class' => 'required'),
|
|
'opts' => array('options' => $obj->varstore['contactEmails'])),
|
|
);
|
|
}
|
|
elseif ($stype === 'new') {
|
|
$fields = array
|
|
('email' => array('label_attributes' => array('class' => 'required empty'),
|
|
'after' => "Required: E-mail address."),
|
|
'comment' => array('label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: Comments about this email address."),
|
|
);
|
|
}
|
|
elseif ($stype === 'show') {
|
|
$element = 'table';
|
|
$column_class = array('field', 'value');
|
|
$rows = array
|
|
(array('Email', $values['email']),
|
|
array('Comment', $values['comment']),
|
|
);
|
|
}
|
|
}
|
|
else {
|
|
die("\n\nInvalid type ($type)\n\n");
|
|
}
|
|
|
|
return
|
|
// BEGIN sourcetype-div
|
|
'<div ' . "\n" .
|
|
' class="'.$type.'-%{id}-div"' . "\n" .
|
|
' id="'.$type.'-%{id}-'.$stype.'-div"' . "\n" .
|
|
((isset($values) || $stype == 'new') ? '' : ' STYLE="display:none;"' . "\n") .
|
|
'>' . "\n" .
|
|
|
|
$obj->element
|
|
($element,
|
|
array('class' => "item contact-{$type} {$stype}",
|
|
'field_prefix' => 'Contact'.ucfirst($type).'.%{id}')
|
|
+ compact('rows', 'fields', 'column_class')) .
|
|
|
|
($stype === 'show'
|
|
? '<input type="hidden" name="data[Contact'.ucfirst($type).'][%{id}][id]" value="'.$values['id'].'"/>' . "\n"
|
|
: '') .
|
|
|
|
// END sourcetype-div
|
|
'</div>' . "\n" .
|
|
'';
|
|
}
|
|
|
|
|
|
//pr($this->data);
|
|
?>
|
|
|
|
<script type="text/javascript"><!--
|
|
|
|
function addPhone(flash) {
|
|
addDiv('phone-entry-id', 'phone', 'phones', flash, <?php
|
|
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
|
'phone',
|
|
'Phone Number'),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
}
|
|
|
|
function addAddress(flash) {
|
|
addDiv('address-entry-id', 'address', 'addresses', flash, <?php
|
|
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
|
'address',
|
|
'Address'),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
}
|
|
|
|
function addEmail(flash) {
|
|
addDiv('email-entry-id', 'email', 'emails', flash, <?php
|
|
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
|
'email',
|
|
'Email Address'),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
}
|
|
|
|
// 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);
|
|
|
|
<?php foreach ($this->data['ContactPhone'] AS $phone): ?>
|
|
addDiv('phone-entry-id', 'phone', 'phones', false, <?php
|
|
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
|
'phone',
|
|
'Phone Number',
|
|
$phone
|
|
),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
<?php endforeach; ?>
|
|
|
|
<?php foreach ($this->data['ContactAddress'] AS $address): ?>
|
|
addDiv('address-entry-id', 'address', 'addresses', false, <?php
|
|
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
|
'address',
|
|
'Address',
|
|
$address
|
|
),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
<?php endforeach; ?>
|
|
|
|
<?php foreach ($this->data['ContactEmail'] AS $email): ?>
|
|
addDiv('email-entry-id', 'email', 'emails', false, <?php
|
|
echo FormatHelper::phpVarToJavascript(contactMethodDiv($this,
|
|
'email',
|
|
'Email Address',
|
|
$email
|
|
),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
<?php endforeach; ?>
|
|
|
|
}
|
|
|
|
function switchMethodSource(id, type, source) {
|
|
$("."+type+"-"+id+"-div")
|
|
.slideUp();
|
|
|
|
$("#"+type+"-"+id+"-"+source+"-div")
|
|
.slideDown();
|
|
}
|
|
|
|
function setEmpty(input_elem) {
|
|
selector = "label[for=" + $(input_elem).attr("id") + "]";
|
|
if ($(input_elem).val() == '')
|
|
$(selector).addClass('empty');
|
|
else
|
|
$(selector).removeClass('empty');
|
|
}
|
|
|
|
$(document).ready(function(){
|
|
resetForm();
|
|
|
|
// In case refresh is hit with populated fields
|
|
$(":input").each(function(i,elem){ setEmpty(elem); });
|
|
|
|
// keyup doesn't catch cut from menu
|
|
$(":input").live('keyup', function(){
|
|
setEmpty(this);
|
|
});
|
|
$(":input").live('mouseup', function(){
|
|
setEmpty(this);
|
|
});
|
|
});
|
|
|
|
--></script>
|
|
|
|
<?php
|
|
; // alignment
|
|
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* Contact Edit
|
|
*/
|
|
|
|
echo '<div class="contact edit">' . "\n";
|
|
|
|
echo $form->create('Contact', array('action' => 'edit')) . "\n";
|
|
echo $form->input('id') . "\n";
|
|
|
|
echo($this->element
|
|
('form_table',
|
|
array('class' => 'item contact detail',
|
|
'caption' => isset($this->data['Contact']) ? 'Edit Contact' : 'New Contact',
|
|
'fields' => array
|
|
('last_name' => array('label_attributes' => array('class' => 'recommended empty'),
|
|
'after' => "Recommended."),
|
|
'first_name' => array('label_attributes' => array('class' => 'recommended empty'),
|
|
'after' => "Recommended."),
|
|
'middle_name' => array('label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional."),
|
|
'company_name' => array('name' => 'Company',
|
|
'label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: Company name, if corporate contact."),
|
|
'display_name' => array('label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional with first/last name; Required otherwise."),
|
|
'id_federal' => array('name' => 'SSN',
|
|
'label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: Social Security Number."),
|
|
'id_local' => array('name' => 'ID #',
|
|
'label_attributes' => array('class' => 'recommended empty'),
|
|
'after' => "Recommended: Driver's license, for example."),
|
|
'id_local_state' => array('name' => 'ID State',
|
|
'label_attributes' => array('class' => 'recommended empty'),
|
|
'after' => "Recommended: State which issued the ID."),
|
|
/* 'id_local_exp' => array('name' => 'ID Expiration', */
|
|
/* 'opts' => array('empty' => true)), */
|
|
'comment' => array('label_attributes' => array('class' => 'optional empty'),
|
|
'after' => "Optional: Comments about this contact."),
|
|
))) . "\n");
|
|
|
|
echo $form->submit('Update') . "\n";
|
|
?>
|
|
|
|
<div CLASS="dynamic-set">
|
|
<fieldset CLASS="phone superset">
|
|
<legend>Phone Numbers</legend>
|
|
<input type="hidden" id="phone-entry-id" value="0">
|
|
<div id="phones"></div>
|
|
<fieldset> <legend>
|
|
<a href="#" onClick="addPhone(true); return false;">Add a Phone Number</a>
|
|
</legend> </fieldset>
|
|
</fieldset>
|
|
</div>
|
|
|
|
<div CLASS="dynamic-set">
|
|
<fieldset CLASS="address superset">
|
|
<legend>Mailing Addresses</legend>
|
|
<input type="hidden" id="address-entry-id" value="0">
|
|
<div id="addresses"></div>
|
|
<fieldset> <legend>
|
|
<a href="#" onClick="addAddress(true); return false;">Add a Mailing Address</a>
|
|
</legend> </fieldset>
|
|
</fieldset>
|
|
</div>
|
|
|
|
<div CLASS="dynamic-set">
|
|
<fieldset CLASS="email superset">
|
|
<legend>Email Addresses</legend>
|
|
<input type="hidden" id="email-entry-id" value="0">
|
|
<div id="emails"></div>
|
|
<fieldset> <legend>
|
|
<a href="#" onClick="addEmail(true); return false;">Add an Email Address</a>
|
|
</legend> </fieldset>
|
|
</fieldset>
|
|
</div>
|
|
|
|
<?php
|
|
; // Alignment
|
|
|
|
echo $form->submit('Update') . "\n";
|
|
echo $form->submit('Cancel', array('name' => 'cancel')) . "\n";
|
|
echo $form->end() . "\n";
|
|
echo '</div>' . "\n";
|