Copyright (C) 2008 James Grant This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ?> $id)); } if($id) { $exec="UPDATE sponsors SET ". "organization='".mysql_escape_string(stripslashes($_POST['organization']))."', ". "address='".mysql_escape_string(stripslashes($_POST['address']))."', ". "city='".mysql_escape_string(stripslashes($_POST['city']))."', ". "province_code='".mysql_escape_string(stripslashes($_POST['province_code']))."', ". "postalcode='".mysql_escape_string(stripslashes($_POST['postalcode']))."', ". "phone='".mysql_escape_string(stripslashes($_POST['phone']))."', ". "tollfree='".mysql_escape_string(stripslashes($_POST['tollfree']))."', ". "fax='".mysql_escape_string(stripslashes($_POST['fax']))."', ". "email='".mysql_escape_string(stripslashes($_POST['email']))."', ". "website='".mysql_escape_string(stripslashes($_POST['website']))."', ". "notes='".mysql_escape_string(stripslashes($_POST['notes']))."', ". "donationpolicyurl='".mysql_escape_string(stripslashes($_POST['donationpolicyurl']))."', ". "fundingselectiondate='".mysql_escape_string(stripslashes($_POST['fundingselectiondate']))."', ". "waiveraccepted='".mysql_escape_string(stripslashes($_POST['waiveraccepted']))."', ". "taxreceiptrequired='".mysql_escape_string(stripslashes($_POST['taxreceiptrequired']))."' ". "WHERE id='$id'"; mysql_query($exec); //FIXME accept the logo //"logo='".mysql_escape_string(stripslashes($_POST['logo']))."', ". } exit; break; case 'sponsorshipinfo_load': $id=intval($_GET['id']); $ret=array(); echo json_encode($ret); exit; break; case 'contactsinfo_load': // make sure a donor id has been selected if($_GET['id']){ // $sql = "SELECT draw_contactsinfo_form(); } exit; break; case 'contactsinfo_save': save_contact(); // draw_contactsinfo_form(); exit; break; } send_header("Donor/Sponsor Management", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', 'Fundraising' => 'admin/fundraising.php') ); // save the contact info function save_contact(){ global $config; //happy_("happy!"); if(validate_contactdata()){ // load or create the user, according to the situation if($_POST['recordtype'] == 'new'){ // this is a new record being submitted. Create the user. $successMessage = i18n("Contact created successfully"); $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: " . $_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 = $_POST['sponsor_id']; $p = ($_POST['primary']=='yes')?'yes':'no'; if($p == 'no') { /* Make sure this sponsor ($sponsor_id) has a primary */ $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'"; $q = mysql_query($query); if(mysql_num_rows($q) == 0) { /* 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' WHERE sponsors_id='$sponsor_id'"); } // we now know whether or not they're the primary user. Update them with that, // along with all of the user info that's been submitted. $u['primary']=$p; $u['salutation']=$_POST['salutation']; $u['firstname']=$_POST['firstname']; $u['lastname']=$_POST['lastname']; $u['position']=$_POST['position']; $u['phonework']=$_POST['phonework']; $u['phonecell']=$_POST['phonecell']; $u['phonehome']=$_POST['phonehome']; $u['fax']=$_POST['fax']; $u['email']=$_POST['email']; $u['notes']=$_POST['notes']; $u['sponsors_id']=$sponsor_id; user_save($u); happy_($successMessage); }else{ // something's wrong with the user data submitted. Should flag the fields where // appropriate, but for now just pop up an error error_("Form not filled out"); } } // FIXME: dummy filler function for now. Should go through all of the fields // submitted and validate before hitting the database function validate_contactdata(){ $returnval = true; if($_POST['recordtype'] != 'new' && $_POST['recordtype'] != 'existing'){ $returnval = false; } return $returnval; } // 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") { echo "

".i18n("Edit %1 Contact",array($sponsors_organization))."

\n"; $buttontext="Save Contact"; $u=user_load(intval($_GET['edit'])); } else if($_GET['action']=="add") { echo "

".i18n("Add %1 Contact",array($sponsors_organization))."

\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']) $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($contact != null) echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
".i18n("Salutation")."
".i18n("First Name")."
".i18n("Last Name")."
".i18n("Position")."
".i18n("Phone (Work)")."
".i18n("Phone (Cell)")."
".i18n("Phone (Home)")."
".i18n("Fax")."
".i18n("Email")."
".i18n("Notes")."
".i18n("Primary Contact")."
\n"; echo "
\n"; } ?> "; echo ""; echo "Add New Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "View/Modify Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "
"; ?>