enable deleting of fundraising campaigns under certain conditions

This commit is contained in:
justin 2010-07-12 19:02:49 +00:00
parent 54b258e793
commit 8c12e443b0

View File

@ -36,19 +36,29 @@ switch($_GET['action']){
echo "<div id=\"campaignaccordion\" style=\"width: 780px;\">\n"; echo "<div id=\"campaignaccordion\" style=\"width: 780px;\">\n";
$q=mysql_query("SELECT * FROM fundraising_campaigns WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name"); $q=mysql_query("SELECT * FROM fundraising_campaigns WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name");
while($r=mysql_fetch_object($q)) { while($r=mysql_fetch_object($q)) {
echo "<h3><a href=\"#\">".htmlspecialchars($r->name)."</a></h3>\n"; echo "<h3 id=\"campaigntitle_{$r->id}\"><a href=\"#\">".htmlspecialchars($r->name)."</a></h3>\n";
echo "<div id=\"campaign_{$r->id}\">\n"; echo "<div id=\"campaign_{$r->id}\">\n";
echo "<table>\n";
echo "<form id=\"campaigninfo_{$r->id}\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\" onsubmit=\"return campaigninfo_save($r->id)\">\n"; echo "<form id=\"campaigninfo_{$r->id}\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\" onsubmit=\"return campaigninfo_save($r->id)\">\n";
echo "<input type=\"hidden\" name=\"campaign_id\" value=\"{$r->id}\" />\n"; echo "<input type=\"hidden\" name=\"campaign_id\" value=\"{$r->id}\" />\n";
echo "<table>\n";
display_campaign_form($r); display_campaign_form($r);
?> ?>
<tr><td colspan="6" style="text-align: center;"> <tr><td colspan="6" style="text-align: center;">
<br /> <br />
<input type="submit" value="<?=i18n("Save Appeal")?>"></td> <input type="submit" value="<?=i18n("Save Appeal")?>"></td>
</tr> </tr>
</table>
</form> </form>
<tr><td colspan="6" style="text-align: center;">
<br />
<?php
echo "<form id=\"campaignremove_{$r->id}\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\" onsubmit=\"return campaigninfo_remove($r->id)\">\n";
echo "<input type=\"hidden\" name=\"campaign_id\" value=\"{$r->id}\" />\n";
?>
<br />
<input type="submit" value="<?=i18n("Delete Appeal")?>"></td>
</form>
</td></tr>
</table>
</div> </div>
<? <?
} }
@ -493,8 +503,35 @@ switch($_GET['action']){
mysql_query("DELETE FROM emails WHERE id='$emails_id'"); mysql_query("DELETE FROM emails WHERE id='$emails_id'");
happy_("Communicaton removed"); happy_("Communicaton removed");
} }
exit;
break;
case "campaign_remove":
$campaign_id = $_POST['campaign_id'];
if(is_numeric($campaign_id)) {
mysql_query("DELETE FROM fundraising_campaigns WHERE
(SELECT COUNT(*) FROM fundraising_donations WHERE fundraising_campaigns_id = $campaign_id) = 0 AND
(SELECT count(*) FROM emails WHERE fundraising_campaigns_id = $campaign_id) = 0 AND
id = $campaign_id");
if(mysql_affected_rows() == 0) {
error_("Cannot delete campaign. It is in use.");
} else {
mysql_query("DELETE FROM fundraising_campaigns_users_link WHERE fundraising_campaigns_id = $campaign_id");
mysql_query("DELETE FROM fundraising_donations WHERE fundraising_campaigns_id = $campaign_id");
mysql_query("DELETE FROM fundraising_donor_logs WHERE fundraising_campaigns_id = $campaign_id");
mysql_query("DELETE FROM emailqueue WHERE fundraising_campaigns_id = $campaign_id");
mysql_query("DELETE FROM emails WHERE fundraising_campaigns_id = $campaign_id");
happy_("Campaign removed");
echo "<script type=\"text/javascript\">";
echo " $('#campaigntitle_$campaign_id').remove();";
echo " $('#campaign_$campaign_id').remove();";
echo "</script>";
}
} else {
error_("Invalid Campaign ID");
}
exit;
break; break;
} }
@ -612,6 +649,11 @@ function campaigninfo_save(id) {
return false; return false;
} }
function campaigninfo_remove(id) {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=campaign_remove", $("#campaignremove_"+id).serializeArray());
return false;
}
function update_tab_overview() { function update_tab_overview() {
$("#campaign_tab_overview").load("<?$_SERVER['PHP_SELF']?>?action=manage_tab_overview&id="+currentcampaignid); $("#campaign_tab_overview").load("<?$_SERVER['PHP_SELF']?>?action=manage_tab_overview&id="+currentcampaignid);
} }