- pass fundraising ids and keys into the editor.

- create new communication, clone, and save now work
This commit is contained in:
james 2009-10-14 04:56:28 +00:00
parent 03032c1d54
commit 51f95911ad
2 changed files with 92 additions and 57 deletions

View File

@ -74,15 +74,15 @@ case 'dialog_choose':
</form>
</div>
<script type="text/javascript">
var comm_dialog_choose_selected = -1;
$(".comm_dialog_choose_email_button").click(function () {
var sel = $("#comm_dialog_choose_emails_id").val();
comm_dialog_choose_selected = sel;
$('#comm_dialog_choose').dialog("close");
comm_dialog_choose_select(sel);
return false;
});
$(".comm_dialog_choose_cancel_button").click(function () {
$('#comm_dialog_choose').dialog("close");
comm_dialog_choose_close();
return false;
});
@ -100,29 +100,28 @@ case 'dialog_choose':
return false;
}
function dialog_choose_open()
{
var w = (document.documentElement.clientWidth * 0.8);
var h = (document.documentElement.clientHeight * 0.8);
$('#comm_dialog_choose').dialog('option', 'width', w);
$('#comm_dialog_choose').dialog('option', 'height', h);
$("#comm_dialog_choose").dialog('open');
}
$("#comm_dialog_choose").dialog({
bgiframe: true, autoOpen: false,
bgiframe: true, autoOpen: true,
modal: true, resizable: false,
draggable: false,
width: 700, //(document.documentElement.clientWidth * 0.8);
height: (document.documentElement.clientHeight * 0.8),
close: function() {
$(this).dialog('destroy');
$('#comm_dialog_choose').remove();
comm_dialog_choose_cancel();
/* Run callbacks */
if(comm_dialog_choose_selected != -1) {
if(typeof(comm_dialog_choose_select) == 'function') {
comm_dialog_choose_select(comm_dialog_choose_selected);
}
} else {
if(typeof(comm_dialog_choose_cancel) == 'function') {
comm_dialog_choose_cancel();
}
}
}
});
dialog_choose_open();
</script>
<?
exit;
@ -136,63 +135,82 @@ case 'email_save':
$subject = mysql_real_escape_string($_POST['subject']);
$bodyhtml = mysql_real_escape_string($_POST['bodyhtml']);
$type = mysql_real_escape_string($_POST['type']);
$key = mysql_real_escape_string($_POST['key']);
$fcid = mysql_real_escape_string($_POST['fcid']);
if($id == 0) {
mysql_query("INSERT INTO emails(type) VALUES('$type')");
mysql_query("INSERT INTO emails(type,val) VALUES('$type','$key')");
echo mysql_error();
$id = mysql_insert_id();
}
/* Allow the fundraising campaigns id to be NULL, it'll never be 0 */
$fcstr = ($fcid == 0) ? 'NULL' : "'$fcid'";
mysql_query("UPDATE emails SET name='$name',description='$description',
`from`='$from',subject='$subject',bodyhtml='$bodyhtml'
`from`='$from',subject='$subject',bodyhtml='$bodyhtml',
fundraising_campaigns_id=$fcstr
WHERE id='$id'");
echo mysql_error();
happy_("Email Saved");
exit;
case 'dialog_edit':
$clone_id = 0;
if(array_key_exists('id', $_GET)) {
$id = intval($_GET['id']);
$q = mysql_query("SELECT * FROM emails WHERE id='$id'");
} else if(array_key_exists('key', $_GET)) {
$key = mysql_real_escape_string($_GET['key']);
$q = mysql_query("SELECT * FROM emails WHERE val='$key'");
} else if(array_key_exists('clone_id', $_GET)) {
$clone_id = intval($_GET['clone_id']);
$q = mysql_query("SELECT * FROM emails WHERE id='$clone_id'");
$cloneid = 0;
} else if(array_key_exists('cloneid', $_GET)) {
$id = intval($_GET['cloneid']);
$clone_id = $id;
} else {
/* New email */
$q = NULL;
/* new email, set defaults which may be specified */
$id = 0;
$key = htmlspecialchars($_GET['key']);
if(array_key_exists('fundraising_campaigns_id', $_GET)) {
$fcid = intval( $_GET['fundraising_campaigns_id']);
$type = 'fundraising';
} else {
$fcid = 0;
$type = (array_key_exists('type',$_GET)) ? $_GET['type'] : 'user';
}
}
if($q != NULL) {
if($id) {
$q = mysql_query("SELECT * FROM emails WHERE id='$id'");
if(mysql_num_rows($q) != 1) {
echo "Ambiguous edit";
exit;
}
$e = mysql_fetch_assoc($q);
/* If we're supposed to clone it, load it then zero out the
* id so we make a new record on save, and override the key */
if($clone_id) {
$e['id'] = 0;
$e['val'] = $_GET['key'];
$e['fundraising_campaigns_id'] = $_GET['fundraising_campaigns_id'];
}
$emails_id = $e['id'];
$name = htmlspecialchars($e['name']);
$key = htmlspecialchars($e['val']);
$description = htmlspecialchars($e['description']);
$from = htmlspecialchars($e['from']);
$subject = htmlspecialchars($e['subject']);
$body = $e['body'];
$bodyhtml = $e['bodyhtml'];
$fcid = intval($e['fundraising_campaigns_id']);
if($bodyhtml == '') $bodyhtml = $body;
/* If we're supposed to clone it, load it then zero out the
* id so we make a new record on save */
if($clone_id) $emails_id = 0;
}
/* Load a type if specified, if not, default to use */
$type = (array_key_exists('type',$_GET)) ? $_GET['type'] : 'user';
?>
<div id="comm_dialog_edit" title="Edit a Communication" style="display: none">
<br />
<form id="comm_dialog_edit_form">
<?="fcid=$fcid, key=$key, type=$type"?>
<input type="hidden" name="emails_id" value="<?=$emails_id?>" />
<input type="hidden" name="type" value="<?=$type?>" />
<input type="hidden" name="key" value="<?=$key?>" />
<input type="hidden" name="fcid" value="<?=$fcid?>" />
<table class="editor" style="width:95%"><tr>
<td class="label"><?=i18n("Email Name")?>:</td>
<td class="input"><input type="text" name="name" size="60" value="<?=$name?>" /></td>
@ -232,9 +250,11 @@ case 'dialog_edit':
</form>
</div>
<script type="text/javascript">
var comm_dialog_edit_saved = false;
$("#comm_dialog_edit_save_button").click(function () {
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/admin/communication.php?action=email_save", $("#comm_dialog_edit_form").serializeArray(),
function() {
comm_dialog_edit_saved = true;
$('#comm_dialog_edit').dialog("close");
});
return false;
@ -246,26 +266,29 @@ case 'dialog_edit':
}
);
function comm_dialog_edit_open()
{
var w = 800; //(document.documentElement.clientWidth * 0.8);
var h = (document.documentElement.clientHeight * 0.8);
$('#comm_dialog_edit').dialog('option', 'width', w);
$('#comm_dialog_edit').dialog('option', 'height', h);
$("#comm_dialog_edit").dialog('open');
}
$("#comm_dialog_edit").dialog({
bgiframe: true, autoOpen: false,
bgiframe: true, autoOpen: true,
modal: true, resizable: false,
draggable: false,
width: 800, //(document.documentElement.clientWidth * 0.8);
height: (document.documentElement.clientHeight * 0.8),
close: function() {
$(this).dialog('destroy');
$('#comm_dialog_edit').remove();
/* Run callbacks */
if(comm_dialog_edit_saved == true) {
if(typeof(comm_dialog_edit_save) == 'function') {
comm_dialog_edit_save(<?=$emails_id?>);
}
} else {
if(typeof(comm_dialog_edit_cancel) == 'function') {
comm_dialog_edit_cancel();
}
}
}
});
comm_dialog_edit_open();
</script>
<?

View File

@ -408,7 +408,7 @@ switch($_GET['action']){
$q=mysql_query("SELECT * FROM emails WHERE fundraising_campaigns_id='$campaign_id' AND val='$key'");
if($email=mysql_fetch_object($q)) {
echo "<div style=\"float: right; margin-right: 15px;\">";
echo "<a title=\"Edit\" href=\"#\" onclick=\"return opencommunicationeditor(null,$email->id)\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\" border=0></a>";
echo "<a title=\"Edit\" href=\"#\" onclick=\"return opencommunicationeditor(null,$email->id,$campaign_id)\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\" border=0></a>";
echo "&nbsp;&nbsp;";
echo "<a title=\"Remove\" onClick=\"return removecommunication($email->id);\" href=\"\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\" border=0></a>";
echo "</div>";
@ -437,8 +437,8 @@ switch($_GET['action']){
}
else {
echo "<ul>\n";
echo " <li><a href=\"#\" onclick=\"return opencommunicationchooser();\">".i18n("Start from an existing communication")."</a></li>\n";
echo " <li><a href=\"#\" onclick=\"return opencommunicationeditor('$key');\">".i18n("Create a new communication")."</a></li>\n";
echo " <li><a href=\"#\" onclick=\"return opencommunicationchooser('$key');\">".i18n("Start from an existing communication")."</a></li>\n";
echo " <li><a href=\"#\" onclick=\"return opencommunicationeditor('$key',null,$campaign_id);\">".i18n("Create a new communication")."</a></li>\n";
echo "</ul>\n";
}
echo "<br />";
@ -663,20 +663,22 @@ function prospect_removeall() {
//key is initial or followup
//start is either 'new' to start with a blank, or 'existing' to load an existing email to start from
function opencommunicationeditor(key,id) {
function opencommunicationeditor(key,id,fcid) {
$("#dialog").empty();
if(id) {
$("#dialog").load("communication.php?action=dialog_edit&id="+id,null,function() {
$("#dialog").load("communication.php?action=dialog_edit&id="+id+"&fundraising_campaigns_id="+fcid,null,function() {
});
} else {
$("#dialog").load("communication.php?action=dialog_edit&key="+key,null,function() {
$("#dialog").load("communication.php?action=dialog_edit&key="+key+"&fundraising_campaigns_id="+fcid,null,function() {
});
}
}
function opencommunicationchooser() {
var comm_chooser_key = null;
function opencommunicationchooser(key) {
comm_chooser_key = key;
$("#dialog").empty();
$("#dialog").load("communication.php?action=dialog_choose&type=fundraising",null,function() {
$("#dialog").load("communication.php?action=dialog_choose&type=fundraising",null,function() {
});
}
@ -688,15 +690,25 @@ function removecommunication(id) {
}
function comm_dialog_choose_select(id) {
alert('im back with email id: '+id);
// alert('im back with email id: '+id);
//get rid of hte html
var key = comm_chooser_key;
$("#dialog").empty();
$("#dialog").load("communication.php?action=dialog_edit&cloneid="+id,null,function() {
$("#dialog").load("communication.php?action=dialog_edit&cloneid="+id+"&key="+key+"&fundraising_campaigns_id="+currentcampaignid,null,function() {
});
}
function comm_dialog_choose_cancel() {
alert('im cancelled');
// alert('im cancelled');
}
function comm_dialog_edit_save(id) {
// alert("saved!");
update_tab_communications();
}
function comm_dialog_edit_cancel() {
// alert("cancelled!");
}
</script>