forked from science-ation/science-ation
Getting started on building the "Manage Campaigns" forms
This commit is contained in:
parent
6c61b26b1f
commit
511562b5b7
@ -23,26 +23,142 @@
|
||||
<?
|
||||
require("../common.inc.php");
|
||||
require_once("../user.inc.php");
|
||||
|
||||
user_auth_required('committee', 'admin');
|
||||
|
||||
send_header("Campaign Management",
|
||||
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 = "no";
|
||||
$target = 0;
|
||||
$goal_id = "";
|
||||
$fiscalyear = -1;
|
||||
|
||||
$query = "INSERT INTO fundraising_campaigns (name, type, startdate, enddate, active, target, fundraising_goal, fiscalyear) VALUES(";
|
||||
$query .= '"' . $campagin_name . '",';
|
||||
$query .= '"' . $type . '",';
|
||||
$query .= '"' . $startdate . '",';
|
||||
$query .= '"' . $enddate . '",';
|
||||
$query .= '"' . $active . '",';
|
||||
$query .= $target . ',';
|
||||
$query .= '"' . $goal_id . '",';
|
||||
$query .= $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" style="border-width:1px;background-color:#DDD;width:68px"/></td>
|
||||
<td><?=i18n("End Date")?></td>
|
||||
<td><input type="text" id="enddate" name="enddate" style="border-width:1px;background-color:#DDD;width:68px"/></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>
|
||||
|
Loading…
Reference in New Issue
Block a user