Create fundraising setup page

Move fundraising levels editor into the setup
Remove the old level editor
This commit is contained in:
james 2009-10-02 19:21:43 +00:00
parent f140ce05a0
commit 1fa368293f
3 changed files with 201 additions and 79 deletions

183
admin/fundraising_setup.php Normal file
View File

@ -0,0 +1,183 @@
<?
/*
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>
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.
*/
?>
<?
require("../common.inc.php");
require_once("../user.inc.php");
user_auth_required('committee', 'admin');
//first, insert any defaults
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE fiscalyear='".$config['FISCALYEAR']."'");
if(!mysql_num_rows($q)) {
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE fiscalyear='-1'");
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO fundraising_donor_levels (`level`,`min`,`max`,`description`,`fiscalyear`) VALUES (
'".mysql_real_escape_string($r->level)."',
'".mysql_real_escape_string($r->min)."',
'".mysql_real_escape_string($r->max)."',
'".mysql_real_escape_string($r->description)."',
'".$config['FISCALYEAR']."')");
}
}
switch($_GET['gettab']) {
case "levels":
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY max");
echo "<div id=\"levelaccordion\" style=\"width: 75%;\">\n";
while($r=mysql_fetch_object($q)) {
echo "<h3><a href=\"#\">$r->level (".format_money($r->min,false)." to ".format_money($r->max,false).")</a></h3>\n";
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 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 "</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 i18n("Description/Benefits").":<br /><textarea name=\"description\" rows=\"4\" style=\"width: 100%;\"></textarea>";
echo "<input type=\"submit\" value=\"".i18n("Save")."\">";
echo "</form>\n";
echo "</div>\n";
echo "</div>\n";
exit;
break;
case "goals":
break;
}
switch($_GET['action']) {
case "level_save":
$id=$_POST['id'];
if($id) {
mysql_query("UPDATE fundraising_donor_levels SET
min='".mysql_real_escape_string($_POST['min'])."',
max='".mysql_real_escape_string($_POST['max'])."',
level='".mysql_real_escape_string($_POST['level'])."',
description='".mysql_real_escape_string($_POST['description'])."'
WHERE id='$id' AND fiscalyear='{$config['FISCALYEAR']}'
");
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");
}
}
exit;
break;
}
send_header("Fundraising Setup",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Fundraising' => 'admin/fundraising.php')
);
?>
<script type="text/javascript">
/* Setup the popup window */
$(document).ready(function() {
$("#editor_tabs").tabs({
show: function(event, ui) {
switch(ui.panel.id) {
case 'editor_tab_levels':
update_levels();
break;
case 'editor_tab_goals':
update_goals();
break;
break;
}
},
selected: 0,
});
// $("#organizationinfo_fundingselectiondate").datepicker({ dateFormat: 'yy-mm-dd', showOn: 'button', buttonText: "<?=i18n("calendar")?>" });
});
function update_levels() {
$("#editor_tab_levels").load("fundraising_setup.php?gettab=levels",null,
function() {
$("#levelaccordion").accordion();
}
);
}
function level_save(id) {
if(id) var f=$("#level_form_"+id);
else var f=$("#level_form");
$("#debug").load("fundraising_setup.php?action=level_save",f.serializeArray(), function() { update_levels(); });
return false;
}
function update_goals() {
$("#editor_tab_levels").load("fundraising_setup.php?gettab=goals");
}
</script>
<div id="setup" style="width: 780px;">
<div id="editor_tabs">
<ul>
<li><a href="#editor_tab_levels"><span><?=i18n('Fundraising Levels')?></span></a></li>
<li><a href="#editor_tab_goals"><span><?=i18n('Fundraising Goals')?></span></a></li>
</ul>
<div id="editor_tab_levels">
</div>
<div id="editor_tab_goals">
</div>
</div>
</div>
<?
send_footer();
?>

View File

@ -1,71 +0,0 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2008 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
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.
*/
?>
<?
require("../common.inc.php");
require("../tableeditor.class.php");
require_once("../user.inc.php");
//first, insert any defaults
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE year='".$config['FISCALYEAR']."'");
if(!mysql_num_rows($q)) {
$q=mysql_query("SELECT * FROM fundraising_donor_levels WHERE year='-1'");
while($r=mysql_fetch_object($q)) {
mysql_query("INSERT INTO fundraising_donor_levels (`level`,`min`,`max`,`description`,`year`) VALUES (
'".mysql_real_escape_string($r->level)."',
'".mysql_real_escape_string($r->min)."',
'".mysql_real_escape_string($r->max)."',
'".mysql_real_escape_string($r->description)."',
'".$config['FISCALYEAR']."')");
}
}
user_auth_required('committee', 'admin');
send_header("Donation Levels",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Fundraising' => 'admin/fundraising.php'),
"internal_document_management"
);
$editor=new TableEditor("fundraising_donor_levels",
array("level"=>"Level Name",
"min"=>"Minimum Amount",
"max"=>"Maximum Amount",
)
,
array("level"=>"Level Name",
"min"=>"Minimum Amount",
"max"=>"Maximum Amount",
"description"=>"Description / Benefits",
)
,array("year"=>$config['FISCALYEAR'])
);
$editor->setPrimaryKey("id");
$editor->setDefaultSortField("max");
$editor->setRecordType("Level");
$editor->filterList('year',$config['FISCALYEAR']);
$editor->execute();
send_footer();
?>

View File

@ -460,6 +460,7 @@ if(is_array($nav)) {
echo "<ul class=\"mainnav\">\n";
echo "<li><h4 style=\"text-align: center;\">".i18n("Fundraising")."</h4></li>\n";
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising.php\">".i18n("Fundraising Dashboard").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising_setup.php\">".i18n("Fundraising Setup").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/fundraising_campaigns.php\">".i18n("Manage Campaigns").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/donors.php\">".i18n("Manage Donors/Sponsors").'</a></li>';
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/admin/reports.php?area=fundraising\">".i18n("Fundraising Reports").'</a></li>';
@ -1123,7 +1124,7 @@ function format_datetime($dt) {
}
}
function format_money($n)
function format_money($n,$decimals=true)
{
if($n<0){
$neg=true;
@ -1145,14 +1146,23 @@ function format_money($n)
if($neg) $negdisp="-"; else $negdisp="";
//get everything after the decimal place, and %02f it.
$after=substr(strstr(sprintf("%.02f",$n),"."),1);
if($decimals) {
//get everything after the decimal place, and %02f it.
$after=substr(strstr(sprintf("%.02f",$n),"."),1);
//finally display it with the right language localization
if($_SESSION['lang']=="fr")
return sprintf("%s%s,%s \$",$negdisp,$out,$after);
else
return sprintf("%s\$%s.%s",$negdisp,$out,$after);
//finally display it with the right language localization
if($_SESSION['lang']=="fr")
return sprintf("%s%s,%s \$",$negdisp,$out,$after);
else
return sprintf("%s\$%s.%s",$negdisp,$out,$after);
}
else {
if($_SESSION['lang']=="fr")
return sprintf("%s%s \$",$negdisp,$out);
else
return sprintf("%s\$%s",$negdisp,$out);
}
}
function message_push($m)