forked from science-ation/science-ation
Working campaign editor
This commit is contained in:
parent
f01eac5b7b
commit
087e89248a
@ -24,71 +24,82 @@
|
|||||||
require("../common.inc.php");
|
require("../common.inc.php");
|
||||||
require_once("../user.inc.php");
|
require_once("../user.inc.php");
|
||||||
user_auth_required('committee', 'admin');
|
user_auth_required('committee', 'admin');
|
||||||
|
|
||||||
switch($_GET['action']){
|
switch($_GET['action']){
|
||||||
case "campaigninfo_save":
|
case "campaigninfo_save":
|
||||||
save_campaign_info();
|
save_campaign_info();
|
||||||
exit;
|
exit;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "display":
|
||||||
|
echo "<div id=\"campaignaccordion\" style=\"width: 780px;\">\n";
|
||||||
|
$q=mysql_query("SELECT * FROM fundraising_campaigns WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name");
|
||||||
|
while($r=mysql_fetch_object($q)) {
|
||||||
|
echo "<h3><a href=\"#\">".htmlspecialchars($r->name)."</a></h3>\n";
|
||||||
|
echo "<div id=\"campaign_{$r->id}\">\n";
|
||||||
|
echo "<form id=\"campaigninfo_{$r->id}\" method=\"post\" action=\"{$_SERVER['PHP_SELF']}\" onsubmit=\"return campaigninfo_save($r->id)\">\n";
|
||||||
|
echo "<input type=\"hidden\" name=\"campaign_id\" value=\"{$r->id}\" />\n";
|
||||||
|
echo "<table>\n";
|
||||||
|
display_campaign_form($r);
|
||||||
|
?>
|
||||||
|
<tr><td colspan="6" style="text-align: center;">
|
||||||
|
<br />
|
||||||
|
<input type="submit" value="<?=i18n("Save Campaign")?>"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<h3><a href="#"><?=i18n("Create New Campaign")?></a></h3>
|
||||||
|
<div id="campaign_new">
|
||||||
|
<form id="campaigninfo_new" method="post" action="<?=$_SERVER['PHP_SELF']?>" onsubmit="return campaigninfo_save(-1)">
|
||||||
|
<input type="hidden" name="campaign_id" value="-1" />
|
||||||
|
<table>
|
||||||
|
<?
|
||||||
|
display_campaign_form();
|
||||||
|
?>
|
||||||
|
<tr><td colspan="6" style="text-align: center;">
|
||||||
|
<br />
|
||||||
|
<input type="submit" value="<?=i18n("Create Campaign")?>"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?
|
||||||
|
exit;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
function save_campaign_info(){
|
function save_campaign_info(){
|
||||||
if($_POST["campaign_id"] == -1){
|
global $config;
|
||||||
// this is a new campaign. let's create it.
|
if(!$_POST['name']){
|
||||||
|
error_("Campaign Name is required");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!$_POST['startdate']) $startdate=date("Y-m-d"); else $startdate=$_POST['startdate'];
|
||||||
|
|
||||||
// first, we'll make sure we have some reasonable data
|
if(!$_GET['id']) {
|
||||||
if(array_key_exists('name', $_POST)) $name = $_POST['name'];
|
$query = "INSERT INTO fundraising_campaigns (name,fiscalyear) VALUES (
|
||||||
if($name == NULL) $name = i18n("New Campaign");
|
'".mysql_real_escape_string($_POST['name'])."','{$config['FISCALYEAR']}')";
|
||||||
|
mysql_query($query);
|
||||||
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();
|
$id = mysql_insert_id();
|
||||||
echo json_encode(array("id"=>$id));
|
happy_("Campaign Created");
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
$id = $_POST["campaign_id"];
|
$id = $_GET["id"];
|
||||||
// we are updating an existing campaign.
|
happy_("Campaign Saved");
|
||||||
echo "Updating an existing campaign<br/>\n";
|
}
|
||||||
|
mysql_query("UPDATE fundraising_campaigns SET
|
||||||
// build our query
|
name='".mysql_real_escape_string($_POST['name'])."',
|
||||||
$formfields = array('name', 'type', 'startdate', 'enddate', 'active', 'target', 'fundraising_goal', 'fiscalyear');
|
`type`='".mysql_real_escape_string($_POST['type'])."',
|
||||||
$updates = false;
|
startdate='".mysql_real_escape_string($startdate)."',
|
||||||
$query = "UPDATE fundraising_campaigns SET ";
|
followupdate='".mysql_real_escape_string($_POST['followupdate'])."',
|
||||||
foreach($formfields AS $fieldname){
|
enddate='".mysql_real_escape_string($_POST['enddate'])."',
|
||||||
if(array_key_exists($fieldname, $_POST)){
|
target='".mysql_real_escape_string($_POST['target'])."',
|
||||||
$updates = true;
|
fundraising_goal='".mysql_real_escape_string($_POST['fundraising_goal'])."'
|
||||||
$query .= $fieldName . "='" . mysql_escape_string(stripslashes($_POST[$fieldname])) . ",";
|
WHERE id='$id'");
|
||||||
}
|
|
||||||
}
|
|
||||||
if($updates = true){
|
|
||||||
$query = rtrim($query, ",") . " WHERE id=" . $id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// and execute it
|
|
||||||
echo $query; //FIXME - not yet tested
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send_header("Campaign Management",
|
send_header("Campaign Management",
|
||||||
@ -101,67 +112,74 @@ send_header("Campaign Management",
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("#campaignaccordion").accordion();
|
loadcampaigns();
|
||||||
update_datefields();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function update_datefields(){
|
function loadcampaigns() {
|
||||||
|
$("#campaigndiv").load("<?$_SERVER['PHP_SELF']?>?action=display", null, function() {loadcampaignsfinish();});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadcampaignsfinish(){
|
||||||
|
$("#campaignaccordion").accordion();
|
||||||
// create the date pickers for our form
|
// create the date pickers for our form
|
||||||
$("#startdate").datepicker({
|
$(".date").datepicker({
|
||||||
changeMonth: true,
|
|
||||||
changeYear: true,
|
|
||||||
dateFormat: 'yy-mm-dd'
|
|
||||||
});
|
|
||||||
$("#enddate").datepicker({
|
|
||||||
changeMonth: true,
|
|
||||||
changeYear: true,
|
|
||||||
dateFormat: 'yy-mm-dd'
|
dateFormat: 'yy-mm-dd'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function campaigninfo_save() {
|
function campaigninfo_save(id) {
|
||||||
//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 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) {
|
if(id==-1) {
|
||||||
$.post("<?$_SERVER['PHP_SELF']?>?action=campaigninfo_save", $("#campaigninfo").serializeArray(),
|
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=campaigninfo_save", $("#campaigninfo_new").serializeArray(), function() { loadcampaigns(); });
|
||||||
function(json) {
|
|
||||||
open_editor(json.id);
|
|
||||||
},
|
|
||||||
"json");
|
|
||||||
} else {
|
} else {
|
||||||
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=campaigninfo_save", $("#campaigninfo").serializeArray());
|
$("#debug").load("<?$_SERVER['PHP_SELF']?>?action=campaigninfo_save&id="+id, $("#campaigninfo_"+id).serializeArray(), function() { loadcampaigns(); });
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function open_editor(id) {
|
|
||||||
alert("open_editor");
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="campaignaccordion" style="width: 780px;\">
|
<?
|
||||||
<h3><a href="#"><?=i18n("Create New Campaign")?></a></h3>
|
function display_campaign_form($r=null) {
|
||||||
<div id="campaignnew">
|
global $config;
|
||||||
<form id="campaigninfo" method="post" action="<?=$_SERVER['PHP_SELF']?>" onsubmit="return campaigninfo_save(-1)">
|
?>
|
||||||
<table class="tableedit">
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><?=i18n("Campaign Name")?></td>
|
<td><?=i18n("Name")?></td>
|
||||||
<td><input type="text" name="name"></td>
|
<td colspan="3"><input size="40" type="text" name="name" value="<?=$r->name?>"></td>
|
||||||
<td><?=i18n("Start Date")?></td>
|
<td><?=i18n("Type")?></td><td><input type="text" name="type" value="<?=$r->type?>"></td>
|
||||||
<td><input type="text" id="startdate" name="startdate" class="date" value="<?=date("Y-m-d")?>"/></td>
|
</tr>
|
||||||
<td><?=i18n("End Date")?></td>
|
<?
|
||||||
<td><input type="text" id="enddate" name="enddate" class="date"/></td>
|
if($r->startdate) $sd=$r->startdate;
|
||||||
<td><input type="submit" value="<?=i18n("add");?>"></td>
|
else $sd=date("Y-m-d");
|
||||||
</tr>
|
?>
|
||||||
</table>
|
<tr>
|
||||||
<input type="hidden" name="campaign_id" value="-1" />
|
<td><?=i18n("Start Date")?></td><td><input type="text" name="startdate" class="date" value="<?=$sd?>" /></td>
|
||||||
</form>
|
<td><?=i18n("Follow-Up Date")?></td><td><input type="text" name="followupdate" class="date" value="<?=$r->followupdate?>" /></td>
|
||||||
</div>
|
<td><?=i18n("End Date")?></td><td><input type="text" name="enddate" class="date" value="<?=$r->enddate?>" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><?=i18n("Target")?></td><td>$<input type="text" id="target" name="target" size="10" value="<?=$r->target?>" /></td>
|
||||||
|
<td><?=i18n("Default Goal")?></td><td colspan="3">
|
||||||
|
<?
|
||||||
|
$fgq=mysql_query("SELECT * FROM fundraising_goals WHERE fiscalyear='{$config['FISCALYEAR']}' ORDER BY name");
|
||||||
|
echo "<select name=\"fundraising_goal\">";
|
||||||
|
echo "<option value=\"\">".i18n("Choose Default Goal")."</option>\n";
|
||||||
|
while($fgr=mysql_fetch_object($fgq)) {
|
||||||
|
if($r->fundraising_goal==$fgr->goal) $sel="selected=\"selected\""; else $sel="";
|
||||||
|
echo "<option $sel value=\"$fgr->goal\">".i18n($fgr->name)."</option>\n";
|
||||||
|
}
|
||||||
|
echo "</select>\n";
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
<h3><a href="#">Campaign 123</a></h3>
|
<div id="campaigndiv" style="width: 780px;">
|
||||||
<div id="campaign_123">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?
|
<?
|
||||||
send_footer();
|
send_footer();
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user