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': if($_GET['id']){ 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(){ //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"); ///////////////////////////////////////////////////////////////////// // FIXME: userid not yet getting posted, so the rest of this if won't work. ///////////////////////////////////////////////////////////////////// exit(1); $u = user_load($_POST['userid']); $id = intval($_POST['userid']); } $sponsor_id = $_GET['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 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'"); if(mysql_num_rows($q) == 0) { /* This must be the primary */ $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 form for entering contact info function draw_contactsinfo_form($contact = null){ // 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); */ if($_GET['sponsors_id']) $sponsors_id=$_GET['sponsors_id']; else if($_POST['sponsors_id']) $sponsors_id=$_POST['sponsors_id']; $buttontext = i18n("Add Contact"); 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"; 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 "
\n"; } ?> "; echo ""; echo "Add New Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "View/Modify Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "
"; ?>