Multiple contacts implemented in donors

This commit is contained in:
jacob 2009-10-05 15:19:50 +00:00
parent abd5f1fcca
commit bfb4c1c586

View File

@ -81,8 +81,8 @@
// make sure a donor id has been selected
if($_GET['id']){
// $sql = "SELECT
draw_contactsinfo_form();
}
draw_contactsinfo_form();
}
exit;
break;
@ -92,6 +92,9 @@
// draw_contactsinfo_form();
exit;
break;
case 'contactsinfo_delete':
delete_contact();
break;
}
send_header("Donor/Sponsor Management",
@ -100,6 +103,11 @@
'Fundraising' => 'admin/fundraising.php')
);
// #FIXME should delete the contact who has been submitted in _POST
function delete_contact(){
error_("Not Implemented");
}
// save the contact info
function save_contact(){
global $config;
@ -117,11 +125,6 @@ function save_contact(){
// this is an existing record being updated. Load the user.
$successMessage = i18n("Contact updated successfully: " . $_POST['userid']);
/////////////////////////////////////////////////////////////////////
// FIXME: userid not yet getting posted, so the rest of this if won't work.
/////////////////////////////////////////////////////////////////////
happy_($successMessage);
exit(1);
$u = user_load($_POST['userid']);
$id = intval($_POST['userid']);
@ -188,21 +191,7 @@ function validate_contactdata(){
// draw a group of forms for editing and creating new contacts
function draw_contactsinfo_form($contact = null){
global $config;
// echo "<a href=\"sponsor_contacts.php?sponsors_id=$sponsors_id\">&lt;&lt; ".i18n("Back to %1 Contacts",array($sponsors_organization))."</a>\n";
/*
if($_GET['action']=="edit")
{
echo "<h3>".i18n("Edit %1 Contact",array($sponsors_organization))."</h3>\n";
$buttontext="Save Contact";
$u=user_load(intval($_GET['edit']));
}
else if($_GET['action']=="add")
{
echo "<h3>".i18n("Add %1 Contact",array($sponsors_organization))."</h3>\n";
$buttontext="Add Contact";
}
$buttontext=i18n($buttontext);
*/
// make sure we know what sponsor we're dealing with here
if(!isset($sponsor_id)){
if($_GET['id'])
@ -215,6 +204,13 @@ function draw_contactsinfo_form($contact = null){
// start our accordion
echo "<div id=\"levelaccordion\" style=\"width: 75%;\">\n";
// draw an empty form in which to enter a new user
echo "<h3><a href=\"#\">New Contact";
echo "</a></h3>\n";
echo "<div>\n";
draw_contact_form($sponsor_id);
echo "</div>\n";
// loop through each contact and draw a form with their data in it.
$query = mysql_query("SELECT * FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id
WHERE year='" . $config['FAIRYEAR'] . "'
@ -232,14 +228,8 @@ function draw_contactsinfo_form($contact = null){
draw_contact_form($sponsor_id, $contact);
echo "</div>\n";
}
// and then draw an empty form in which to enter a new user
echo "<h3><a href=\"#\">New Contact";
echo "</a></h3>\n";
echo "<div>\n";
draw_contact_form($sponsor_id);
echo "</div>\n";
// end the accordion
// and finally end the accordion
echo "</div>\n";
}
@ -247,11 +237,20 @@ function draw_contactsinfo_form($contact = null){
// draw a form in which to enter contact info
//FIXME - this form needs to be pretty
function draw_contact_form($sponsor_id, $contact = null){
echo "<form id=\"createcontact\" method=\"post\" action=\"donors.php?action=contactsinfo_save\">\n";
if($contact != null){
$id = $contact["id"];
}else{
$id = "new";
}
echo "<form id=\"contact_" . $id . "\" method=\"post\" action=\"donors.php?action=contactsinfo_save\">\n";
echo "<input type=\"hidden\" name=\"sponsor_id\" value=\"$sponsor_id\">\n";
echo "<input type=\"hidden\" name=\"recordtype\" value=\"existing\">\n";
if($contact != null)
echo "<input type=\"hidden\" name=\"userid\" value=\"" . $contact["id"] . "\">\n";
if($id == "new"){
echo "<input type=\"hidden\" name=\"recordtype\" value=\"new\">\n";
}else{
echo "<input type=\"hidden\" name=\"recordtype\" value=\"existing\">\n";
echo "<input type=\"hidden\" name=\"userid\" value=\"" . $id . "\">\n";
}
echo "<table>\n";
echo "<tr><td>".i18n("Salutation")."</td><td><input type=\"text\" name=\"salutation\" value=\"".htmlspecialchars($contact['salutation'])."\" size=\"4\" maxlength=\"8\" /></td></tr>\n";
echo "<tr><td>".i18n("First Name")."</td><td><input type=\"text\" name=\"firstname\" value=\"".htmlspecialchars($contact['firstname'])."\" size=\"32\" maxlength=\"32\" /></td></tr>\n";
@ -269,7 +268,15 @@ function draw_contact_form($sponsor_id, $contact = null){
$sel = ($contact['primary'] == 'no') ? 'selected="selected"': '';
echo "<option value=\"no\" $sel>".i18n('No')."</option>";
echo "</select></td></tr>\n";
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"" . i18n("Save") . "\" onClick=\"return contactsinfo_save()\" /></td></tr>\n";
echo "<tr>";
echo "<td align=\"center\"><input type=\"submit\" value=\"" . i18n("Save") . "\" onClick=\"return contactsinfo_save('" . $id . "')\" /></td>";
if( $id == "new"){
echo "<td></td>";
}else{
echo "<td align=\"center\"><input type=\"submit\" value=\"" . i18n("Remove") . "\" onClick=\"return contactsinfo_delete('" . $id . "')\" /></td>";
}
echo "</tr>\n";
echo "</table>\n";
echo "</form>\n";
}
@ -409,8 +416,13 @@ function update_contactsinfo()
);
}
function contactsinfo_save() {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_save", $("#createcontact").serializeArray());
function contactsinfo_save(id) {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_save", $("#contact_" + id).serializeArray());
return false;
}
function contactsinfo_delete(id) {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=contactsinfo_delete", $("#contact_" + id).serializeArray());
return false;
}