From ce9446d66a1ebf12e5961dc59c5abdb1c6996164 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 2 Oct 2009 20:39:34 +0000 Subject: [PATCH] Updated to use an accordion style form for entering contacts. There is an issue with the wrong data being submitted from the form. Working on that next --- admin/donors.php | 89 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 20 deletions(-) diff --git a/admin/donors.php b/admin/donors.php index 707642e..f2d8aa3 100644 --- a/admin/donors.php +++ b/admin/donors.php @@ -78,7 +78,9 @@ break; case 'contactsinfo_load': + // make sure a donor id has been selected if($_GET['id']){ +// $sql = "SELECT draw_contactsinfo_form(); } exit; @@ -100,6 +102,7 @@ // save the contact info function save_contact(){ + global $config; //happy_("happy!"); if(validate_contactdata()){ // load or create the user, according to the situation @@ -109,34 +112,38 @@ function save_contact(){ $u = user_create("sponsor", $_POST['email']); $id = $u['id']; + }else if($_POST['recordtype'] == 'existing'){ // this is an existing record being updated. Load the user. - $successMessage = i18n("Contact updated successfully"); + $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']); + } - $sponsor_id = $_GET['sponsor_id']; + $sponsor_id = $_POST['sponsor_id']; $p = ($_POST['primary']=='yes')?'yes':'no'; if($p == 'no') { /* Make sure this sponsor ($sponsor_id) has a primary */ - $q = mysql_query("SELECT users_id + $query = "SELECT users_id FROM users_sponsor, users WHERE users_sponsor.users_id=users.id AND sponsors_id='$sponsor_id' AND `primary`='yes' AND year='".$config['FAIRYEAR']."' - AND users_id!='$id'"); + AND users_id!='$id'"; + $q = mysql_query($query); if(mysql_num_rows($q) == 0) { - /* This must be the primary */ + /* This has to be the primary since there isn't one already */ $p = 'yes'; - } + } } else { /* Unset all other primaries */ mysql_query("UPDATE users_sponsor SET `primary`='no' @@ -159,7 +166,6 @@ function save_contact(){ $u['sponsors_id']=$sponsor_id; user_save($u); - happy_($successMessage); }else{ // something's wrong with the user data submitted. Should flag the fields where @@ -175,11 +181,13 @@ function validate_contactdata(){ if($_POST['recordtype'] != 'new' && $_POST['recordtype'] != 'existing'){ $returnval = false; } + return $returnval; } -// draw a form for entering contact info +// draw a group of forms for editing and creating new contacts function draw_contactsinfo_form($contact = null){ + global $config; // echo "<< ".i18n("Back to %1 Contacts",array($sponsors_organization))."\n"; /* if($_GET['action']=="edit") @@ -195,18 +203,55 @@ function draw_contactsinfo_form($contact = null){ } $buttontext=i18n($buttontext); */ - if($_GET['sponsors_id']) - $sponsors_id=$_GET['sponsors_id']; - else if($_POST['sponsors_id']) - $sponsors_id=$_POST['sponsors_id']; - $buttontext = i18n("Add Contact"); + // make sure we know what sponsor we're dealing with here + if(!isset($sponsor_id)){ + if($_GET['id']) + $sponsor_id=$_GET['id']; + else if($_POST['id']) + $sponsor_id=$_POST['id']; + $buttontext = i18n("Add Contact"); + } + + // start our accordion + echo "
\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'] . "' + AND sponsors_id='" . $sponsor_id . "' + AND deleted='no' + ORDER BY lastname,firstname"); + while($contact = mysql_fetch_array($query)){ + // draw a header for this user + echo "

"; + echo $contact["firstname"] . " " . $contact["lastname"]; + echo "

\n"; + + // and draw the actual form + echo "
\n"; + draw_contact_form($sponsor_id, $contact); + echo "
\n"; + } + // and then draw an empty form in which to enter a new user + echo "

New Contact"; + echo "

\n"; + echo "
\n"; + draw_contact_form($sponsor_id); + echo "
\n"; + + // end the accordion + echo "
\n"; + +} + +// 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 "
\n"; echo "\n"; -// echo "\n"; -// if($_GET['action']=="edit") - // the value passed here should be dynamically changed depending on how this form was reached - echo "\n"; - echo "\n"; + echo "\n"; + if($contact != null) + echo "\n"; echo "\n"; echo "\n"; echo "\n"; @@ -224,7 +269,7 @@ function draw_contactsinfo_form($contact = null){ $sel = ($contact['primary'] == 'no') ? 'selected="selected"': ''; echo ""; echo "\n"; - echo "\n"; echo "
".i18n("Salutation")."
".i18n("First Name")."
\n"; + echo "
\n"; echo "
\n"; } @@ -357,7 +402,11 @@ function sponsorshipinfo_save() { function update_contactsinfo() { var id=sponsor_id; - $("#editor_tab_contacts").load("?action=contactsinfo_load&id="+id); + $("#editor_tab_contacts").load("?action=contactsinfo_load&id="+id, null, + function() { + $("#levelaccordion").accordion(); + } + ); } function contactsinfo_save() {