science-ation/admin/fundraising_setup.php
james 1fa368293f Create fundraising setup page
Move fundraising levels editor into the setup
Remove the old level editor
2009-10-02 19:21:43 +00:00

184 lines
6.6 KiB
PHP

<?
/*
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();
?>