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 "