forked from science-ation/science-ation
Implement the fundraising goals editor on the setup screen
This commit is contained in:
parent
ce9446d66a
commit
abd5f1fcca
@ -3,8 +3,7 @@
|
||||
This file is part of the 'Science Fair In A Box' project
|
||||
SFIAB Website: http://www.sfiab.ca
|
||||
|
||||
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
|
||||
Copyright (C) 2008 James Grant <james@lightbox.org>
|
||||
Copyright (C) 2009 James Grant <james@lightbox.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
@ -51,22 +50,44 @@
|
||||
echo "<div id=\"level_$r->id\">\n";
|
||||
echo "<form id=\"level_form_$r->id\" onsubmit=\"return level_save($r->id)\">\n";
|
||||
echo "<input type=\"hidden\" name=\"id\" value=\"$r->id\">\n";
|
||||
echo i18n("Level Name").": <input type=\"text\" name=\"level\" value=\"$r->level\"><br />";
|
||||
echo i18n("Value Range").": \$<input size=\"5\" type=\"text\" name=\"min\" value=\"$r->min\"> to \$<input size=\"5\" type=\"text\" name=\"max\" value=\"$r->max\"><br />\n";
|
||||
echo "<table style=\"width: 100%;\">";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Level Name").":</td><td><input type=\"text\" size=\"40\" name=\"level\" value=\"$r->level\"></td></tr>\n";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Value Range").":</td><td>\$<input size=\"5\" type=\"text\" name=\"min\" value=\"$r->min\"> to \$<input size=\"5\" type=\"text\" name=\"max\" value=\"$r->max\"><br />\n";
|
||||
echo "</td></tr>\n";
|
||||
echo "<tr><td colspan=\"2\">";
|
||||
echo i18n("Description/Benefits").":<br /><textarea name=\"description\" rows=\"4\" style=\"width: 100%;\">".htmlspecialchars($r->description)."</textarea>";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Save")."\" >";
|
||||
echo "</form>\n";
|
||||
echo "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
echo "<table style=\"width: 100%;\"><tr><td style=\"width: 50%; text-align: center;\">";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Save Level")."\" >";
|
||||
echo "</td><td style=\"width: 50%; text-align: right;\">";
|
||||
echo "<input type=\"button\" value=\"".i18n("Delete Level")."\" onclick=\"return level_delete($r->id)\" >";
|
||||
echo "</td></tr></table>\n";
|
||||
echo "</form>";
|
||||
echo "</div>\n";
|
||||
$x++;
|
||||
}
|
||||
|
||||
echo "<h3><a href=\"#\">Create New Level</a></h3>\n";
|
||||
echo "<div id=\"level_new\">\n";
|
||||
echo "<form id=\"level_form\" onsubmit=\"return level_save()\">\n";
|
||||
echo i18n("Level Name").": <input type=\"text\" name=\"level\"><br />";
|
||||
echo i18n("Value Range").": \$<input size=\"5\" type=\"text\" name=\"min\"> to \$<input size=\"5\" type=\"text\" name=\"max\"><br />\n";
|
||||
|
||||
echo "<table style=\"width: 100%;\">";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Level Name").":</td><td><input type=\"text\" size=\"40\" name=\"level\"></td></tr>\n";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Value Range").":</td><td>\$<input size=\"5\" type=\"text\" name=\"min\"> to \$<input size=\"5\" type=\"text\" name=\"max\"><br />\n";
|
||||
echo "</td></tr>\n";
|
||||
echo "<tr><td colspan=\"2\">";
|
||||
echo i18n("Description/Benefits").":<br /><textarea name=\"description\" rows=\"4\" style=\"width: 100%;\"></textarea>";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Save")."\">";
|
||||
echo "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo "<table style=\"width: 100%;\"><tr><td style=\"width: 50%; text-align: center;\">";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Create Level")."\">";
|
||||
echo "</td><td style=\"width: 50%; text-align: right;\">";
|
||||
echo "</td></tr></table>\n";
|
||||
echo "</form>\n";
|
||||
echo "</div>\n";
|
||||
|
||||
@ -76,14 +97,76 @@
|
||||
break;
|
||||
|
||||
case "goals":
|
||||
$q=mysql_query("SELECT * FROM fundraising_goals WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name");
|
||||
echo "<div id=\"goalaccordion\" style=\"width: 75%;\">\n";
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<h3><a href=\"#\">$r->name (".format_money($r->budget,false).") Deadline: ".format_date($r->deadline)."</a></h3>\n";
|
||||
echo "<div id=\"goal_$r->id\">\n";
|
||||
echo "<form id=\"goal_form_$r->id\" onsubmit=\"return goal_save($r->id)\">\n";
|
||||
echo "<input type=\"hidden\" name=\"id\" value=\"$r->id\">\n";
|
||||
|
||||
echo "<table style=\"width: 100%;\">";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Goal Name").":</td><td><input type=\"text\" size=\"40\" name=\"name\" value=\"$r->name\"></td></tr>\n";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Budget Amount").":</td><td>\$<input size=\"5\" type=\"text\" name=\"budget\" value=\"$r->budget\"></td></tr>";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Deadline").":</td><td><input size=\"9\" type=\"text\" name=\"deadline\" value=\"$r->deadline\"></td></tr>";
|
||||
echo "<tr><td colspan=\"2\">";
|
||||
echo i18n("Description").":<br /><textarea name=\"description\" rows=\"4\" style=\"width: 100%;\">".htmlspecialchars($r->description)."</textarea>";
|
||||
echo "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
echo "<table style=\"width: 100%;\"><tr><td style=\"width: 50%; text-align: center;\">";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Save Goal")."\" >";
|
||||
echo "</td><td style=\"width: 50%; text-align: right;\">";
|
||||
echo "<input type=\"button\" value=\"".i18n("Delete Goal")."\" onclick=\"return goal_delete($r->id)\" >";
|
||||
echo "</td></tr></table>\n";
|
||||
echo "</form>";
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
echo "<h3><a href=\"#\">Create New Goal</a></h3>\n";
|
||||
echo "<div id=\"goal_new\">\n";
|
||||
echo "<form id=\"goal_form\" onsubmit=\"return goal_save()\">\n";
|
||||
echo "<table style=\"width: 100%;\">";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Goal Name").":</td><td><input type=\"text\" size=\"40\" name=\"name\"></td></tr>\n";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Budget Amount").":</td><td>\$<input size=\"5\" type=\"text\" name=\"budget\"></td></tr>";
|
||||
echo "<tr><td>";
|
||||
echo i18n("Deadline").":</td><td><input size=\"9\" type=\"text\" name=\"deadline\"></td></tr>";
|
||||
echo "<tr><td colspan=\"2\">";
|
||||
echo i18n("Description").":<br /><textarea name=\"description\" rows=\"4\" style=\"width: 100%;\"></textarea>";
|
||||
echo "</td></tr>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo "<table style=\"width: 100%;\"><tr><td style=\"width: 50%; text-align: center;\">";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Create Goal")."\">";
|
||||
echo "</td><td style=\"width: 50%; text-align: right;\">";
|
||||
echo "</td></tr></table>\n";
|
||||
echo "</form>\n";
|
||||
echo "</div>\n";
|
||||
|
||||
echo "</div>\n";
|
||||
|
||||
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
switch($_GET['action']) {
|
||||
case "level_save":
|
||||
$id=$_POST['id'];
|
||||
if($id) {
|
||||
$id=$_POST['id'];
|
||||
if(! ($_POST['level'] && $_POST['min'] && $_POST['max'])) {
|
||||
error_("Level name, minimum and maximum value range are required");
|
||||
exit;
|
||||
}
|
||||
if($_POST['min']>=$_POST['max']) {
|
||||
error_("Value range minimum must be smaller than range maximum");
|
||||
exit;
|
||||
}
|
||||
|
||||
if($id) {
|
||||
mysql_query("UPDATE fundraising_donor_levels SET
|
||||
min='".mysql_real_escape_string($_POST['min'])."',
|
||||
max='".mysql_real_escape_string($_POST['max'])."',
|
||||
@ -94,21 +177,82 @@
|
||||
happy_("Level Saved");
|
||||
}
|
||||
else {
|
||||
if($_POST['level'] && $_POST['min'] && $_POST['max']) {
|
||||
mysql_query("INSERT INTO fundraising_donor_levels (`level`,`min`,`max`,`description`,`fiscalyear`) VALUES (
|
||||
'".mysql_real_escape_string($_POST['level'])."',
|
||||
'".mysql_real_escape_string($_POST['min'])."',
|
||||
'".mysql_real_escape_string($_POST['max'])."',
|
||||
'".mysql_real_escape_string($_POST['description'])."',
|
||||
'{$config['FISCALYEAR']}')");
|
||||
happy_("Level Created");
|
||||
}
|
||||
else {
|
||||
error_("Level name, minimum and maximum value range are required");
|
||||
}
|
||||
mysql_query("INSERT INTO fundraising_donor_levels (`level`,`min`,`max`,`description`,`fiscalyear`) VALUES (
|
||||
'".mysql_real_escape_string($_POST['level'])."',
|
||||
'".mysql_real_escape_string($_POST['min'])."',
|
||||
'".mysql_real_escape_string($_POST['max'])."',
|
||||
'".mysql_real_escape_string($_POST['description'])."',
|
||||
'{$config['FISCALYEAR']}')");
|
||||
happy_("Level Created");
|
||||
}
|
||||
exit;
|
||||
break;
|
||||
case "level_delete":
|
||||
$id=$_POST['id'];
|
||||
mysql_query("DELETE FROM fundraising_donor_levels WHERE id='$id' AND fiscalyear='{$config['FISCALYEAR']}'");
|
||||
happy_("Level Deleted");
|
||||
exit;
|
||||
break;
|
||||
|
||||
case "goal_save":
|
||||
$id=$_POST['id'];
|
||||
if(! ($_POST['name'] && $_POST['budget'])) {
|
||||
error_("Goal name and budget are required");
|
||||
exit;
|
||||
}
|
||||
if($id) {
|
||||
mysql_query("UPDATE fundraising_goals SET
|
||||
budget='".mysql_real_escape_string($_POST['budget'])."',
|
||||
deadline='".mysql_real_escape_string($_POST['deadline'])."',
|
||||
name='".mysql_real_escape_string($_POST['name'])."',
|
||||
description='".mysql_real_escape_string($_POST['description'])."'
|
||||
WHERE id='$id' AND fiscalyear='{$config['FISCALYEAR']}'
|
||||
");
|
||||
happy_("Goal Saved");
|
||||
}
|
||||
else {
|
||||
$goal=strtolower($_POST['name']);
|
||||
$goal=ereg_replace("[^a-z]","",$goal);
|
||||
$q=mysql_query("SELECT * FROM fundraising_goals WHERE goal='$goal' AND fiscalyear='{$config['FISCALYEAR']}'");
|
||||
echo mysql_error();
|
||||
if(mysql_num_rows($q)) {
|
||||
error_("The automatically generated goal key (%1) generated from (%2) is not unique. Please try a different Goal Name",array($goal,$_POST['name']));
|
||||
exit;
|
||||
}
|
||||
|
||||
mysql_query("INSERT INTO fundraising_goals (`goal`,`name`,`budget`,`deadline`,`description`,`fiscalyear`) VALUES (
|
||||
'".mysql_real_escape_string($goal)."',
|
||||
'".mysql_real_escape_string($_POST['name'])."',
|
||||
'".mysql_real_escape_string($_POST['budget'])."',
|
||||
'".mysql_real_escape_string($_POST['deadline'])."',
|
||||
'".mysql_real_escape_string($_POST['description'])."',
|
||||
'{$config['FISCALYEAR']}')");
|
||||
happy_("Goal Created");
|
||||
}
|
||||
exit;
|
||||
break;
|
||||
case "goal_delete":
|
||||
$id=$_POST['id'];
|
||||
//they cant delete system ones
|
||||
$q=mysql_query("SELECT * FROM fundraising_goals WHERE id='$id' AND fiscalyear='{$config['FISCALYEAR']}'");
|
||||
if(!$r=mysql_fetch_object($q)) {
|
||||
error_("Invalid goal to delete");
|
||||
exit;
|
||||
}
|
||||
if($r->system=="yes") {
|
||||
error_("Fundraising goals created automatically and used by the system cannot be deleted");
|
||||
exit;
|
||||
}
|
||||
$q=mysql_query("SELECT * FROM fundraising_donations WHERE fundraising_goal='$r->goal' AND fiscalyear='{$config['FISCALYEAR']}'");
|
||||
if(mysql_num_rows($q)) {
|
||||
error_("This goal already has donations assigned to it, it cannot be deleted");
|
||||
exit;
|
||||
}
|
||||
|
||||
mysql_query("DELETE FROM fundraising_goals WHERE id='$id' AND fiscalyear='{$config['FISCALYEAR']}'");
|
||||
happy_("Goal Deleted");
|
||||
exit;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
@ -158,10 +302,40 @@ function level_save(id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function update_goals() {
|
||||
$("#editor_tab_levels").load("fundraising_setup.php?gettab=goals");
|
||||
function level_delete(id) {
|
||||
if(confirmClick('Are you sure you want to delete this fundraising level?')) {
|
||||
var f=$("#level_form_"+id);
|
||||
$("#debug").load("fundraising_setup.php?action=level_delete",f.serializeArray(), function() { update_levels(); });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function update_goals() {
|
||||
$("#editor_tab_goals").load("fundraising_setup.php?gettab=goals",null,
|
||||
function() {
|
||||
$("#goalaccordion").accordion();
|
||||
$("[name=deadline]").datepicker({ dateFormat: 'yy-mm-dd'});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function goal_save(id) {
|
||||
if(id) var f=$("#goal_form_"+id);
|
||||
else var f=$("#goal_form");
|
||||
|
||||
$("#debug").load("fundraising_setup.php?action=goal_save",f.serializeArray(), function() { update_goals(); });
|
||||
return false;
|
||||
}
|
||||
|
||||
function goal_delete(id) {
|
||||
if(confirmClick('Are you sure you want to delete this fundraising goal?')) {
|
||||
var f=$("#goal_form_"+id);
|
||||
$("#debug").load("fundraising_setup.php?action=goal_delete",f.serializeArray(), function() { update_goals(); });
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<div id="setup" style="width: 780px;">
|
||||
|
Loading…
Reference in New Issue
Block a user