Implement adding donations and add some misisng i18ns

This commit is contained in:
james 2009-10-13 01:02:17 +00:00
parent ebf6c0e79b
commit 60d8922ff2

View File

@ -126,7 +126,7 @@ switch($_GET['action']) {
echo "<br />\n";
echo "<h4>".i18n("Donations/Sponsorships")."</h4>\n";
echo "<div id=\"thisyeardonationhistory\">";
$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 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 "<table class=\"tableview\">";
@ -179,21 +179,56 @@ switch($_GET['action']) {
echo "<h4>".i18n("Add New Donation/Sponsorship")."</h4>\n";
echo "<form id=\"addnewdonationform\" onsubmit=\"return adddonation()\">";
echo "<input type=\"hidden\" name=\"sponsors_id\" value=\"$id\" />\n";
echo "<table cellspacing=3 cellpadding=3>";
echo "<tr><td>";
echo i18n("Appeal").":";
echo "</td><td>";
// loop through each contact in the donor
$query = mysql_query("SELECT users.id,users.uid,users.deleted,MAX(year)
FROM users
LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id
WHERE
sponsors_id='$id'
AND types LIKE '%sponsor%'
GROUP BY uid
HAVING deleted='no'
ORDER BY users_sponsor.primary DESC,lastname,firstname
");
echo mysql_error();
$uids=array();
while($r=mysql_fetch_object($query)) {
$uids[]=$r->uid;
}
$q=mysql_query("SELECT * FROM fundraising_campaigns
WHERE fiscalyear='{$config['FISCALYEAR']}'
ORDER BY name");
$str="";
echo "<select id=\"fundraising_campaign_id\" name=\"fundraising_campaigns_id\" onchange=\"campaignchange()\">";
echo "<option value=\"\">".i18n("Choose an appeal")."</option>\n";
//FIXME: only show campaigns that they were included as part of
//we need a campaigns_users_link or campaigns_sponsors_link or something
$q=mysql_query("SELECT * FROM fundraising_campaigns WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name");
$str="";
while($r=mysql_fetch_object($q)) {
echo "<option value=\"$r->id\">$r->name</option>\n";
//if there's uids, we can check if this sponsor is in the campaign
//if there's no uids, (aka no contacts) then there's no way we could have included them in a cmomunication
//but they could still get here fors ome reason, so we still need to show all the campaigns
if(count($uids)) {
$tq=mysql_query("SELECT * FROM fundraising_campaigns_users_link
WHERE fundraising_campaigns_id='$r->id'
AND users_uid IN (".implode(",",$uids).")
");
if(mysql_num_rows($tq)) {
$incampaign=i18n("*In Appeal*").": ";
}
else $incampaign="";
}
else $incampaign="";
echo "<option value=\"$r->id\">{$incampaign}{$r->name}</option>\n";
$str.="defaultgoals[$r->id]='$r->fundraising_goal';\n";
}
echo "<option value=\"\">".i18n("Other/No Appeal")."</option>\n";
echo "</select>\n";
echo "</td></tr>\n";
@ -204,7 +239,7 @@ switch($_GET['action']) {
echo " var defaultgoals=Array();\n";
echo $str;
echo "</script>\n";
echo "<select name=\"fundraising_goal\">";
echo "<select id=\"fundraising_goal\" name=\"fundraising_goal\">";
echo "<option value=\"\">".i18n("Choose a purpose")."</option>\n";
//FIXME: only show campaigns that they were included as part of
//we need a campaigns_users_link or campaigns_sponsors_link or something
@ -229,13 +264,13 @@ switch($_GET['action']) {
echo "<option value=\"$st\">".i18n($st)."</option>\n";
}
echo "</select>\n";
echo "</td></tr>\n";
/*
echo "<tr><td></td><td>";
echo "<a href=\"#\" onclick=\"return false;\">".i18n("Generate Thank You")."</a></td>";
echo "</tr>\n";
*/
echo "<tr><td colspan=\"2\" style=\"text-align: center;\"><input type=\"submit\" value=\"".i18n("Add donation/sponsorship")."\" /></td></tr>\n";
echo "</table>\n";
@ -340,6 +375,36 @@ switch($_GET['action']) {
echo "<br />";
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)."'
)");
echo mysql_error();
happy_("Donation/sponsorship added");
} else {
error_("All fields are required");
}
exit;
break;
}
send_header("Donor/Sponsor Management",
@ -657,11 +722,11 @@ function draw_activityinfo_form(){
<form id="activityinfo">
<table class="tableview" style="width:99%">
<thead><tr>
<th>Date</th>
<th>Committee Member</th>
<th>Contact Type</th>
<th>Appeal</th>
<th>Notes</th>
<th><?=i18n("Date")?>/></th>
<th><?=i18n("Committee Member")?></th>
<th><?=i18n("Contact Type")?></th>
<th><?=i18n("Appeal")?></th>
<th><?=i18n("Notes")?></th>
</tr></thead>
<tbody>
@ -969,6 +1034,9 @@ function togglefulldonationhistory() {
}
function campaignchange() {
var campaignid=$("#fundraising_campaign_id").val();
var goal=defaultgoals[campaignid];
$("#fundraising_goal").val(goal);
}
function donortypechange() {
@ -991,7 +1059,8 @@ function donortypechange() {
function adddonation() {
var id=sponsor_id;
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=donation_add", $("#donationaddform").serializeArray(),function() { update_contactsinfo(); });
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=donation_add", $("#addnewdonationform").serializeArray(),function() { update_sponsorshipinfo(); });
return false;
}
</script>