science-ation/admin/fundraising_campaigns.php

168 lines
4.9 KiB
PHP
Raw Normal View History

<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
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
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');
switch($_GET['action']){
case "campaigninfo_save":
save_campaign_info();
exit;
break;
}
function save_campaign_info(){
if($_POST["campaign_id"] == -1){
// this is a new campaign. let's create it.
// first, we'll make sure we have some reasonable data
if(array_key_exists('name', $_POST)) $name = $_POST['name'];
if($name == NULL) $name = i18n("New Campaign");
if(array_key_exists('startdate', $_POST)) $startdate = $_POST['startdate'];
if($startdate == NULL) $startdate = date("Y-m-d");
if(array_key_exists('enddate', $_POST)) $enddate = $_POST['enddate'];
if($enddate == NULL) $enddate = date("Y-m-d");
// now we need to create some default data to fill the record
$type = ""; //FIXME - these need more sensible and controlled values
$active = "yes";
$target = 0;
$goal_id = "";
$fiscalyear = $config['FISCALYEAR'];
$query = "INSERT INTO fundraising_campaigns (name, type, startdate, enddate, followupdate, active, target, fundraising_goal, fiscalyear) VALUES (
'$campagin_name,'$type','$startdate',
'$enddate',
DATE_ADD('$startdate', INTERVAL 1 MONTH),
'$active',
'$target',
'$goal_id',
'$fiscalyear')";
mysql_query($query);
// Let's grab the new campaign ID for further use
$id = mysql_insert_id();
echo json_encode(array("id"=>$id));
}else{
$id = $_POST["campaign_id"];
// we are updating an existing campaign.
echo "Updating an existing campaign<br/>\n";
// build our query
$formfields = array('name', 'type', 'startdate', 'enddate', 'active', 'target', 'fundraising_goal', 'fiscalyear');
$updates = false;
$query = "UPDATE fundraising_campaigns SET ";
foreach($formfields AS $fieldname){
if(array_key_exists($fieldname, $_POST)){
$updates = true;
$query .= $fieldName . "='" . mysql_escape_string(stripslashes($_POST[$fieldname])) . ",";
}
}
if($updates = true){
$query = rtrim($query, ",") . " WHERE id=" . $id;
}
// and execute it
echo $query; //FIXME - not yet tested
}
}
send_header("Campaign Management",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php',
'Fundraising' => 'admin/fundraising.php'),
"fundraising"
);
?>
<script type="text/javascript">
$(document).ready(function() {
$("#campaignaccordion").accordion();
update_datefields();
});
function update_datefields(){
// create the date pickers for our form
$("#startdate").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
$("#enddate").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'yy-mm-dd'
});
}
function campaigninfo_save() {
//if we're creating we need to do the post, and get the id it returns, so we can re-open the popup window with that id
if($("#campaign_id").val()==-1) {
$.post("<?$_SERVER['PHP_SELF']?>?action=campaigninfo_save", $("#campaigninfo").serializeArray(),
function(json) {
open_editor(json.id);
},
"json");
} else {
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=campaigninfo_save", $("#campaigninfo").serializeArray());
}
return false;
}
function open_editor(id) {
alert("open_editor");
}
</script>
<div id="campaignaccordion" style="width: 780px;\">
<h3><a href="#"><?=i18n("Create New Campaign")?></a></h3>
<div id="campaignnew">
<form id="campaigninfo" method="post" action="<?=$_SERVER['PHP_SELF']?>" onsubmit="return campaigninfo_save(-1)">
<table class="tableedit">
<tr>
<td><?=i18n("Campaign Name")?></td>
<td><input type="text" name="name"></td>
<td><?=i18n("Start Date")?></td>
<td><input type="text" id="startdate" name="startdate" class="date" value="<?=date("Y-m-d")?>"/></td>
<td><?=i18n("End Date")?></td>
<td><input type="text" id="enddate" name="enddate" class="date"/></td>
<td><input type="submit" value="<?=i18n("add");?>"></td>
</tr>
</table>
<input type="hidden" name="campaign_id" value="-1" />
</form>
</div>
<h3><a href="#">Campaign 123</a></h3>
<div id="campaign_123">
</div>
</div>
<?
send_footer();
?>