From 0fbf664f677fbcbd127224d040116eeab6749494 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 25 Feb 2010 15:44:04 +0000 Subject: [PATCH] Change JOIN to LEFT JOIN for donation/sponsorship list in the case that they don't specify an appeal. Add ability to REMOVE a donation Add activitylog for both adding and removing donations --- admin/donors.php | 88 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/admin/donors.php b/admin/donors.php index f9886879..a682ede0 100644 --- a/admin/donors.php +++ b/admin/donors.php @@ -128,7 +128,14 @@ switch($_GET['action']) { echo "
\n"; echo "

".i18n("Donations/Sponsorships")."

\n"; echo "
"; - $q=mysql_query("SELECT fundraising_donations.*, fundraising_campaigns.name AS campaignname FROM fundraising_donations 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"); + $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 ""; @@ -137,6 +144,7 @@ switch($_GET['action']) { echo " \n"; echo " \n"; echo " \n"; + echo " \n"; echo ""; while($r=mysql_fetch_object($q)) { echo "\n"; @@ -145,6 +153,9 @@ switch($_GET['action']) { echo " "; echo " "; echo " "; + echo " "; echo "\n"; } echo "
".i18n("Purpose")."".i18n("Appeal")."".i18n("Value")."".i18n("Remove")."
$goal->name$r->campaignname".format_money($r->value,false).""; + echo "id,$id)\" href=\"#\">"; + echo "
\n"; @@ -162,9 +173,16 @@ switch($_GET['action']) { echo " ".i18n("Purpose")."\n"; echo " ".i18n("Appeal")."\n"; echo " ".i18n("Value")."\n"; + echo " ".i18n("Remove")."\n"; echo ""; - $q=mysql_query("SELECT fundraising_donations.*, fundraising_campaigns.name AS campaignname FROM fundraising_donations JOIN fundraising_campaigns ON fundraising_donations.fundraising_campaigns_id=fundraising_campaigns.id WHERE sponsors_id='$id' AND status='received' ORDER BY datereceived DESC"); + $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 " ".format_date($r->datereceived)."\n"; @@ -172,6 +190,9 @@ switch($_GET['action']) { echo " $goal->name"; echo " $r->campaignname"; echo " ".format_money($r->value,false).""; + echo " "; + echo "id,$id)\" href=\"#\">"; + echo " "; echo "\n"; } echo "\n"; @@ -398,6 +419,9 @@ switch($_GET['action']) { '".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"); @@ -407,6 +431,21 @@ switch($_GET['action']) { 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", @@ -810,6 +849,44 @@ function save_activityinfo($comment, $donorId, $userId, $type, $campaign_id=null echo mysql_error(); } +function getDonationString($id) { + global $config; + $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 fundraising_donations.id='$id' + AND fundraising_donations.fiscalyear='{$config['FISCALYEAR']}' + "); + echo mysql_error(); + $str=""; + if($r=mysql_fetch_object($q)) { + $str.=format_date($r->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; +} + + + ?>