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)); save_activityinfo("Created donor/sponsor", $id, $_SESSION['users_uid'],"System"); $createnew=true; } else $createnew=false; if($id) { $exec="UPDATE sponsors SET ". "donortype='".mysql_escape_string(stripslashes($_POST['donortype']))."', ". "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']))."', ". "proposalsubmissiondate='".mysql_escape_string(stripslashes($_POST['proposalsubmissiondate']))."', ". "waiveraccepted='".mysql_escape_string(stripslashes($_POST['waiveraccepted']))."' ". "WHERE id='$id'"; mysql_query($exec); echo mysql_error(); //FIXME accept the logo //"logo='".mysql_escape_string(stripslashes($_POST['logo']))."', ". //($comment , $donorId, $userId, $type, $campaign_id=null){ if(!$createnew) { 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 status='received' 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 status='received' 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("Donations/Sponsorships")."

\n"; echo "
"; $q=mysql_query("SELECT fundraising_donations.*, fundraising_campaigns.name AS campaignname FROM fundraising_donations LEFT JOIN fundraising_campaigns ON fundraising_donations.fundraising_campaigns_id=fundraising_campaigns.id WHERE sponsors_id='$id' AND status='received' AND fundraising_donations.fiscalyear='{$config['FISCALYEAR']}' ORDER BY datereceived DESC"); echo mysql_Error(); if(mysql_num_rows($q)) { echo ""; echo ""; echo ""; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo ""; echo ""; while($r=mysql_fetch_object($q)) { echo "\n"; echo " \n"; $goal=getGoal($r->fundraising_goal); echo " "; echo " "; echo " "; echo " "; echo "\n"; } echo "
".i18n("Date")."".i18n("Purpose")."".i18n("Appeal")."".i18n("Value")."".i18n("Remove")."
".format_date($r->datereceived)."$goal->name$r->campaignname".format_money($r->value,false).""; echo "id,$id)\" href=\"#\">"; echo "
\n"; }else{ echo i18n("No donations this year")."
"; } echo "".i18n("View full donation history").""; echo "
"; echo "
"; echo "".i18n("View this year's donation history").""; echo ""; echo ""; echo ""; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo ""; echo ""; $q=mysql_query("SELECT fundraising_donations.*, fundraising_campaigns.name AS campaignname FROM fundraising_donations LEFT JOIN fundraising_campaigns ON fundraising_donations.fundraising_campaigns_id=fundraising_campaigns.id WHERE sponsors_id='$id' AND status='received' ORDER BY datereceived DESC"); while($r=mysql_fetch_object($q)) { echo "\n"; echo " \n"; $goal=getGoal($r->fundraising_goal); echo " "; echo " "; echo " "; echo " "; echo "\n"; } echo "
".i18n("Date")."".i18n("Purpose")."".i18n("Appeal")."".i18n("Value")."".i18n("Remove")."
".format_date($r->datereceived)."$goal->name$r->campaignname".format_money($r->value,false).""; echo "id,$id)\" href=\"#\">"; echo "
\n"; echo "
\n"; echo "
\n"; echo "

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

\n"; echo "
"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; /* echo ""; echo "\n"; */ echo "\n"; echo "
"; echo i18n("Appeal").":"; echo ""; $query = mysql_query( "SELECT accounts.id as acc_id, users.id as usr_id, users.deleted, MAX(users.id) FROM accounts JOIN users ON" . " users.accounts_id = accounts.id" . " WHERE users.sponsors_id = '$id'" . " AND types LIKE '%sponsor%'" . " GROUP BY acc_id" . " HAVING deleted='no'" . " ORDER BY `primary` DESC, lastname, firstname" ); echo mysql_error(); $uids=array(); while($r=mysql_fetch_object($query)) { $uids[]=$r->usr_id; } $q=mysql_query("SELECT * FROM fundraising_campaigns WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name"); $str=""; 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(id) FROM users WHERE email='".trim($_POST['email'])."' GROUP BY accounts_id 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; case "donation_add": $campaignid=intval($_POST['fundraising_campaigns_id']); $sponsorid=intval($_POST['sponsors_id']); $goal=$_POST['fundraising_goal']; $value=intval($_POST['value']); $supporttype=$_POST['supporttype']; $datereceived=$_POST['datereceived']; if($goal && $value && $supporttype) { mysql_query("INSERT INTO fundraising_donations (sponsors_id,fundraising_goal,fundraising_campaigns_id,value,status,probability,fiscalyear,thanked,datereceived,supporttype) VALUES ( '$sponsorid', '".mysql_real_escape_string($goal)."', '$campaignid', '$value', 'received', '100', '{$config['FISCALYEAR']}', 'no', '".mysql_real_escape_string($datereceived)."', '".mysql_real_escape_string($supporttype)."' )"); $id=mysql_insert_id(); $logStr=getDonationString($id); save_activityinfo("Added donation/sponsorship: $logStr", $sponsorid, $_SESSION['users_uid'],"System"); echo mysql_error(); happy_("Donation/sponsorship added"); } else { error_("All fields are required"); } exit; break; case "donation_remove": //function save_activityinfo($comment, $donorId, $userId, $type, $campaign_id=null){ $id=intval($_POST['id']); $sponsorid=intval($_POST['sponsors_id']); if($logStr=getDonationString($id)) { save_activityinfo("Removed donation/sponsorship: $logStr", $sponsorid, $_SESSION['users_uid'],"System"); happy_("Donation/sponsorship removed"); mysql_query("DELETE FROM fundraising_donations WHERE id='$id' AND sponsors_id='$sponsorid'"); echo mysql_error(); } else { error_("Invalid donation/sponsorship to remove"); } 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,"sponsor"); 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() { $accid = intval($_POST['accounts_id']); $sponsors_id = intval($_POST['id']); echo "Linking accounts_id=$accid to sponsors_id=$sponsors_id
"; // echo "uid $uid has users.id {$u['id']}"; $u=user_load_by_accounts_id($accid); $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(id) FROM users WHERE email='".trim($_POST['email'])."' GROUP BY accounts_id 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 "; $acc = account_create($_POST['email']); $accid = $acc['id']; $usr = user_create($accid); user_add_role($usr, 'sponsor'); //sponsor }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 JOIN user_roles ON users_roles.users_id = users.id JOIN roles ON roles.id = user_roles.id WHERE roles.type = 'sponsor' AND users.sponsors_id='$sponsor_id' AND users.`primary`='yes' AND users.conferences_id = '{$conference['id']}' 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['address']=$_POST['address']; $u['address2']=$_POST['address2']; $u['city']=$_POST['city']; $u['postalcode']=$_POST['postalcode']; $u['province']=$_POST['province_code']; $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(conferences_id) FROM users JOIN user_roles ON user_roles.users_id = users.id JOIN roles ON roles.id = user_roles.id WHERE roles.type = 'sponsor' AND users.sponsors_id = '" . $sponsor_id . "' GROUP BY conferences_id HAVING deleted = 'no' ORDER BY `primary` DESC , 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"; } // draw an empty form in which to enter a new user echo "

New Contact"; echo "

\n"; echo "
\n"; //and do the blank one 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 $config; //grab the sponsor details, so we can do diff things for individual vs organization $q=mysql_query("SELECT * FROM sponsors WHERE id='$sponsor_id'"); $sponsor=mysql_fetch_object($q); if($contact != null){ $id = $contact["id"]; }else{ $id = "new"; if($sponsor->donortype=="individual") { list($firstname,$lastname)=explode(" ",$sponsor->organization,2); $contact['firstname']=$firstname; $contact['lastname']=$lastname; $contact['email']=$sponsor->email; $contact['phonehome']=$sponsor->phone; } else { $contact['phonework']=$sponsor->phone; } $contact['fax']=$sponsor->fax; $contact['address']=$sponsor->address; $contact['address2']=$sponsor->address2; $contact['city']=$sponsor->city; $contact['province']=$sponsor->province_code; $contact['postalcode']=$sponsor->postalcode; } echo "
\n"; echo "\n"; if($id == "new"){ echo "\n"; $newcontactsearch="onkeypress=\"return newcontactsearch()\""; $newcontactsave="id=\"contactnewsave\""; }else{ echo "\n"; echo "\n"; } ?> donortype=="individual") { $d="disabled=\"disabled\""; } else $d=""; ?> "; echo ""; ?>
value = "">
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 ""; } ?>
" onClick="return activityinfo_save()" /> "; echo "\n"; $logtypes=array("Appeal","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") . "
datereceived)." - "; $goal=getGoal($r->fundraising_goal); if($goal) { $str.=i18n("Goal: %1",array($goal->name)); } else { $str.=i18n("Goal: none"); } $str.= " - "; if($r->campaignname) { $str.= i18n("Campaign: %1",array($r->campaignname)); } else { $str.=i18n("Campaign: none"); } $str.= " - "; $str.= " Value: ".format_money($r->value,false); } else { return false; } return $str; } ?> "; echo ""; echo "Add New Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "View/Modify Donor(s)/Sponsor(s)\n"; echo ""; echo ""; echo "
"; ?>