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']))."', ". "address2='".mysql_escape_string(stripslashes($_POST['address2']))."', ". "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']))."', ". //($comment , $donorId, $userId, $type, $campaign_id=null){ save_activityinfo("Updated donor/sponsor details", $id, $_SESSION['users_uid'],"System"); happy_("Donor/Sponsor Details saved"); } exit; break; case 'sponsorshipinfo_load': $id=intval($_GET['id']); echo "

".i18n("Summary")."

\n"; echo "\n"; //LAST DONATION $q=mysql_query("SELECT * FROM fundraising_donations WHERE sponsors_id='$id' ORDER BY datereceived DESC LIMIT 1"); if($r=mysql_fetch_object($q)) $lastdonation=i18n("%1 on %2",array(format_money($r->value,false),format_date($r->datereceived)),array("Donation amount","Donation date")); else $lastdonation=i18n("Never"); //TOTAL THIS YEAR $q=mysql_query("SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id='$id' AND fiscalyear={$config['FISCALYEAR']} "); if($r=mysql_fetch_object($q)) $totalthisyear=format_money($r->total,false); else $totalthisyear=format_money(0); //TOTAL LAST YEAR $lastyear=$config['FISCALYEAR']-1; $q=mysql_query("SELECT SUM(value) AS total FROM fundraising_donations WHERE sponsors_id='$id' AND fiscalyear=$lastyear "); if($r=mysql_fetch_object($q)) $totallastyear=format_money($r->total,false); else $totallastyear=format_money(0); //OUTPUT echo "\n"; echo "\n"; echo "\n"; echo "
".i18n("Last Donation")."$lastdonation
".i18n("Total This Year")."$totalthisyear
".i18n("Total Last Year")."$totallastyear
\n"; echo "
\n"; echo "".i18n("View full donation history").""; echo "
"; $q=mysql_query("SELECT * FROM fundraising_donations WHERE sponsors_id='$id' ORDER BY datereceived DESC"); echo "FIXME: get the goal and campaign"; echo ""; echo ""; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo ""; while($r=mysql_fetch_object($q)) { echo "\n"; echo " \n"; echo " "; echo " "; echo " "; } echo "
".i18n("Date")."".i18n("Goal")."".i18n("Campaign")."".i18n("Value")."
".format_date($r->datereceived)."$r->fundraising_goal$r->fundraising_campaigns_id".format_money($r->value,false)."
\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "

".i18n("Add New Donation/Sponsorship")."

\n"; echo "
"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; /* echo ""; echo "\n"; */ echo "
"; echo i18n("Appeal").":"; echo ""; echo "\n"; echo "
"; echo i18n("Purpose").":"; echo ""; echo "\n"; echo "\n"; echo "
".i18n("Date Received").":
".i18n("Amount").":\$
".i18n("Type of Support").":"; $supporttypes=array("Gift - no receipt"); if($config['registered_charity']) $supporttypes[]="Donation - with receipt"; $supporttypes[]="Sponsorship"; echo "\n"; echo "
"; echo "".i18n("Generate Thank You")."
\n"; echo "
\n"; exit; break; case 'contactsinfo_load': // make sure a donor id has been selected if($_GET['id']){ draw_contactsinfo_form(); } exit; break; case 'contactsinfo_save': save_contact(); exit; break; case 'contactsinfo_delete': delete_contact(); exit; break; case 'contactsinfo_addexisting': addexisting_contact(); exit; break; case 'activityinfo_load': // make sure a donor id has been selected if($_GET['id']){ draw_activityinfo_form(); } exit; break; case 'activityinfo_save': //($comment , $donorId, $userId, $type, $campaign_id=null){ if(save_activityinfo( $_POST['comment'], $_GET['id'], $_SESSION['users_uid'], $_POST['type'], $_POST['fundraising_campaigns_id'] )){ happy_("Activity Logged"); }else{ error_("Unable to save activity log"); } exit; break; case 'newcontactsearch': if($_POST['email']) $q=mysql_query("SELECT *,MAX(year) FROM users WHERE email='".trim($_POST['email'])."' GROUP BY uid HAVING deleted='no'"); if($r=mysql_fetch_object($q)) { echo i18n("There is an exact email address match for %1",array($_POST['email'])); echo ""; ?> "; echo ""; } else { echo i18n("There are %1 existing users that match, please enter more details",array($num)); } } echo "
"; exit; break; } send_header("Donor/Sponsor Management", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php', 'Fundraising' => 'admin/fundraising.php') ); //delete the contact who has been submitted in _POST function delete_contact(){ if(array_key_exists('userid', $_POST)){ $uid = $_POST['userid']; $data = mysql_query("SELECT CONCAT_WS(' ', users.firstname, users.lastname) AS name FROM users WHERE id=" . $uid); $namedata = mysql_fetch_array($data); $name = trim($namedata['name']); user_delete($uid); happy_("Deleted contact %1", array($name)); //($comment , $donorId, $userId, $type, $campaign_id=null){ save_activityinfo("Deleted contact \"$name\"",$_GET['id'],$_SESSION['users_uid'],'System' ); } } function addexisting_contact() { $uid=intval($_POST['uid']); $sponsors_id=intval($_POST['id']); echo "Linking uid=$uid to sponsors_id=$sponsors_id
"; $u=user_load_by_uid($uid); echo "uid $uid has users.id {$u['id']}"; $u['sponsors_id']=$sponsors_id; $u['types'][]="sponsor"; user_save($u); save_activityinfo("Existing user (".$u['firstname']." ".$u['lastname'].") linked to donor/sponsor",$sponsors_id,$_SESSION['users_uid'],'System'); happy_("Added existing user to donor/sponsor"); } // 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'){ if($_POST['email']) { $q=mysql_query("SELECT *,MAX(year) FROM users WHERE email='".trim($_POST['email'])."' GROUP BY uid HAVING deleted='no'"); if(mysql_num_rows($q)) { error_("A user with that email address already exists"); exit; } } // this is a new record being submitted. Create the user. $successMessage = "Contact created successfully"; $successLog = "Added 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 = "Contact updated successfully"; $successLog = "Updated contact "; $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' AND users_id != '$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); $name = trim($u['firstname'] . ' ' . $u['lastname']); //($comment , $donorId, $userId, $type, $campaign_id=null){ save_activityinfo($successLog . '"' . $name . '"',$sponsor_id,$_SESSION['users_uid'],'System'); 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; // 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 *,MAX(year) FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id WHERE sponsors_id='" . $sponsor_id . "' GROUP BY uid HAVING deleted='no' ORDER BY users_sponsor.primary DESC,lastname,firstname "); echo mysql_error(); 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"; } // draw an empty form in which to enter a new user echo "

New Contact"; echo "

\n"; echo "
\n"; echo "
"; draw_contact_form($sponsor_id); echo "
\n"; // and finally end the accordion echo "
\n"; } // draw a form in which to enter information about the various contacts function draw_contact_form($sponsor_id, $contact = null){ global $salutations; if($contact != null){ $id = $contact["id"]; }else{ $id = "new"; } echo "
\n"; echo "\n"; if($id == "new"){ echo "\n"; $newcontactsearch="onkeypress=\"return newcontactsearch()\""; $newcontactsave="id=\"contactnewsave\""; }else{ echo "\n"; echo "\n"; } ?> "; echo ""; ?>
type="text" name="firstname" value = ""> type="text" name="lastname" value = "">
type="text" name="email" size="60" value = "">
"; if($id != "new") echo ""; echo "
"; $q = mysql_query($query); echo mysql_error(); if(mysql_num_rows($q)) { while($r = mysql_fetch_array($q)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; } }else{ echo ""; } ?>
Date Committee Member Contact Type Campaign Notes
" onClick="return activityinfo_save()" /> "; echo "\n"; $logtypes=array("Campaign","Phone Call","Email","Personal Visit","Other"); foreach($logtypes AS $lt) { echo "\n"; } echo "\n"; ?> "; echo "\n"; while($r=mysql_fetch_object($q)) { echo "\n"; } echo "\n"; ?>
" . $query . "
" . $r["dt"] . "" . $r["name"] . "" . $r["type"] . "" . $r["campaignname"] . "" . $r["log"] . "
" . i18n("No records") . "
"; echo ""; echo "Add New Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "View/Modify Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "
"; ?>