git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@497 97e9348a-65ac-dc4b-aefc-98561f571b83
275 lines
7.5 KiB
PHP
275 lines
7.5 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('contactTypes', 'contacts');
|
|
|
|
//pr($this->data);
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* Javascript
|
|
*/
|
|
|
|
function customerContactDiv($obj, $values = null, $primary = false) {
|
|
|
|
$div =
|
|
// BEGIN type-div
|
|
'<DIV>' . "\n" .
|
|
// BEGIN type-fieldset
|
|
'<FIELDSET CLASS="contact subset">' . "\n" .
|
|
'<LEGEND>Contact #%{id} (%{remove})</LEGEND>' . "\n" .
|
|
|
|
// BEGIN source-div
|
|
'<DIV ID="contact-%{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][%{id}][source]"' . "\n" .
|
|
' ONCLICK="switchContactSource(%{id}, '."'{$stype}'".')"' . "\n" .
|
|
' CLASS="contact-%{id}-source" ' . "\n" .
|
|
' ID="contact-%{id}-source-'.$stype.'"' . "\n" .
|
|
' VALUE="'.$stype.'"' . "\n" .
|
|
//' CHECKED' . "\n" .
|
|
' />' . "\n" .
|
|
' <LABEL FOR="contact-%{id}-source-'.$stype.'">'.$sname.'</LABEL>' . "\n" .
|
|
' ';
|
|
}
|
|
}
|
|
$div .= "\n";
|
|
|
|
if (isset($values)) {
|
|
$div .= customerContactTypeDiv($obj, 'show', $values);
|
|
}
|
|
else {
|
|
$div .= customerContactTypeDiv($obj, 'existing');
|
|
$div .= customerContactTypeDiv($obj, 'new');
|
|
}
|
|
|
|
$div .=
|
|
// END source-fieldset
|
|
'</FIELDSET>' . "\n" .
|
|
// END source-div
|
|
'</DIV>' . "\n" .
|
|
|
|
// BEGIN contact-div
|
|
'<div id="contact-%{id}-contact-div"' . "\n" .
|
|
|
|
$obj->element
|
|
('form_table',
|
|
array('class' => "item contact entry",
|
|
'field_prefix' => 'Contact.%{id}.ContactsCustomer',
|
|
'fields' => array
|
|
(
|
|
'Customer.primary_contact_entry' => array
|
|
('name' => 'Primary Contact',
|
|
'no_prefix' => true,
|
|
'opts' => array
|
|
('type' => 'radio',
|
|
'options' => array('%{id}' => false),
|
|
'value' => ($primary ? '%{id}' : 'bogus-value-to-suppress-hidden-input'),
|
|
)),
|
|
|
|
'type' => array
|
|
('opts' => array
|
|
('options' => $obj->varstore['contactTypes'],
|
|
'selected' => (isset($values) ? $values['ContactsCustomer']['type'] : null),
|
|
)),
|
|
|
|
'comment' => array
|
|
('opts' => array
|
|
('value' => (isset($values) ? $values['ContactsCustomer']['comment'] : null),
|
|
)),
|
|
|
|
))) . "\n" .
|
|
|
|
// END contact-div
|
|
'</div>' . "\n" .
|
|
|
|
// END type-fieldset
|
|
'</FIELDSET>' . "\n" .
|
|
// END type-div
|
|
'</DIV>'
|
|
;
|
|
|
|
return $div;
|
|
}
|
|
|
|
function customerContactTypeDiv($obj, $stype, $values = null) {
|
|
|
|
$element = 'form_table';
|
|
$class = $stype;
|
|
|
|
if ($stype === 'existing') {
|
|
$fields = array
|
|
('id' => array('name' => 'Contact',
|
|
'opts' => array('options' => $obj->varstore['contacts'])),
|
|
);
|
|
}
|
|
elseif ($stype === 'new') {
|
|
$fields = array
|
|
('first_name' => true,
|
|
'last_name' => true,
|
|
'middle_name' => true,
|
|
'display_name' => true,
|
|
'company_name' => array('name' => 'Company'),
|
|
'id_federal' => array('name' => 'SSN'),
|
|
'id_local' => array('name' => 'ID #'),
|
|
'id_local_state' => array('name' => 'ID State'),
|
|
/* 'id_local_exp' => array('name' => 'ID Expiration', */
|
|
/* 'opts' => array('empty' => true)), */
|
|
'comment' => true,
|
|
);
|
|
}
|
|
elseif ($stype === 'show') {
|
|
$element = 'table';
|
|
$class = 'detail';
|
|
$column_class = array('field', 'value');
|
|
$rows = array(array('First Name', $values['first_name']),
|
|
array('Last Name', $values['last_name']),
|
|
array('Company', $values['company_name']),
|
|
array('Comment', $values['comment']));
|
|
}
|
|
else {
|
|
die("\n\nInvalid stype ($stype)\n\n");
|
|
}
|
|
|
|
return
|
|
// BEGIN sourcetype-div
|
|
'<div ' . "\n" .
|
|
' class="contact-%{id}-div"' . "\n" .
|
|
' id="contact-%{id}-'.$stype.'-div"' . "\n" .
|
|
(isset($values) ? '' : ' STYLE="display:none;"' . "\n") .
|
|
'>' . "\n" .
|
|
|
|
$obj->element
|
|
($element,
|
|
array('class' => "item contact {$class}",
|
|
'field_prefix' => 'Contact.%{id}')
|
|
+ compact('rows', 'fields', 'column_class')) .
|
|
|
|
($stype === 'show'
|
|
? '<input type="hidden" name="data[Contact][%{id}][id]" value="'.$values['id'].'"/>' . "\n"
|
|
: '') .
|
|
|
|
// END sourcetype-div
|
|
'</div>' . "\n" .
|
|
'';
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
<script type="text/javascript"><!--
|
|
|
|
function addContact(flash) {
|
|
addDiv('contact-entry-id', 'contact', 'contacts', flash, <?php
|
|
echo FormatHelper::phpVarToJavascript
|
|
(customerContactDiv($this),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
}
|
|
|
|
// Reset the form
|
|
function resetForm() {
|
|
$('#contacts').html('');
|
|
$('#contact-entry-id').val(1);
|
|
|
|
<?php foreach ($this->data['Contact'] AS $contact): ?>
|
|
addDiv('contact-entry-id', 'contact', 'contacts', false, <?php
|
|
echo FormatHelper::phpVarToJavascript
|
|
(customerContactDiv($this,
|
|
$contact,
|
|
$contact['id'] == $this->data['Customer']['primary_contact_id']
|
|
),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
<?php endforeach; ?>
|
|
|
|
if ($("#contact-entry-id").val() == 1) {
|
|
addDiv('contact-entry-id', 'contact', 'contacts', false, <?php
|
|
echo FormatHelper::phpVarToJavascript
|
|
(customerContactDiv($this, null, true),
|
|
null,
|
|
' ');
|
|
?>
|
|
);
|
|
}
|
|
}
|
|
|
|
function switchContactSource(id, source) {
|
|
$(".contact-"+id+"-div")
|
|
.slideUp();
|
|
|
|
$("#contact-"+id+"-"+source+"-div")
|
|
.slideDown();
|
|
}
|
|
|
|
$(document).ready(function(){
|
|
resetForm();
|
|
});
|
|
|
|
--></script>
|
|
|
|
<?php
|
|
; // alignment
|
|
|
|
/**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
**********************************************************************
|
|
* Customer Edit
|
|
*/
|
|
|
|
echo '<div class="customer edit">' . "\n";
|
|
|
|
echo $form->create('Customer', array('action' => 'edit')) . "\n";
|
|
echo $form->input('id') . "\n";
|
|
|
|
echo($this->element
|
|
('form_table',
|
|
array('class' => 'item customer detail',
|
|
'caption' => isset($this->data['Customer']) ? 'Edit Customer' : 'New Customer',
|
|
'fields' => array
|
|
('name' => true,
|
|
'comment' => true,
|
|
))) . "\n");
|
|
|
|
echo $form->submit(isset($this->data['Customer']) ? 'Update' : 'Add New Customer') . "\n";
|
|
?>
|
|
|
|
<div CLASS="dynamic-set">
|
|
<fieldset CLASS="contact superset">
|
|
<legend>Contacts</legend>
|
|
<input type="hidden" id="contact-entry-id" value="0">
|
|
<div id="contacts"></div>
|
|
<fieldset> <legend>
|
|
<a href="#" onClick="addContact(true); return false;">Add a Contact</a>
|
|
</legend> </fieldset>
|
|
</fieldset>
|
|
</div>
|
|
|
|
<?php
|
|
; // Alignment
|
|
|
|
echo $form->submit(isset($this->data['Customer']) ? 'Update' : 'Add New Customer') . "\n";
|
|
echo $form->submit('Cancel', array('name' => 'cancel')) . "\n";
|
|
echo $form->end() . "\n";
|
|
echo '</div>' . "\n";
|