Completely convert the old communication module over to the new system... (almost).

TODO: switch the "send" to the new dialog-style preview and confirmation, instead of the old one, but at least it works!
This commit is contained in:
james 2009-12-02 22:17:20 +00:00
parent 06d9e74190
commit 99114c7242
10 changed files with 420 additions and 326 deletions

View File

@ -134,7 +134,6 @@ case 'dialog_choose':
exit;
case 'email_save':
print_r($_POST);
$id = intval($_POST['emails_id']);
$name = mysql_real_escape_string(stripslashes($_POST['name']));
$description = mysql_real_escape_string(stripslashes($_POST['description']));
@ -146,15 +145,35 @@ case 'email_save':
$fcid = mysql_real_escape_string($_POST['fcid']);
if($id == 0) {
mysql_query("INSERT INTO emails(type,val) VALUES('$type','$key')");
echo mysql_error();
$id = mysql_insert_id();
if($key && $name) {
mysql_query("INSERT INTO emails(type,val) VALUES('$type','$key')");
echo mysql_error();
$id = mysql_insert_id();
} else {
error_("Email Key and Name are required");
exit;
}
}
/* 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',
//first, replace an </p> with </p><br />
$body=str_replace("</p>","</p><br />",$bodyhtml);
//now replace any <br /> with newlines
$body=eregi_replace('<br[[:space:]]*/?[[:space:]]*>',chr(13).chr(10),$body);
//and strip the rest of the tags
$body=strip_tags($body);
//and replace &nbsp;
$body=str_replace("&nbsp;"," ",$body);
mysql_query("UPDATE emails SET
name='$name',
description='$description',
`from`='$from',
subject='$subject',
body='$body',
bodyhtml='$bodyhtml',
fundraising_campaigns_id=$fcstr
WHERE id='$id'");
echo mysql_error();
@ -179,11 +198,12 @@ case 'dialog_edit':
$q=mysql_query("SELECT * FROM fundraising_campaigns WHERE id='$fcid'");
$fc=mysql_fetch_object($q);
$name=i18n("%1 communication for %2",array(ucfirst($key),$fc->name));
$from=$_SESSION['name']." <".$_SESSION['email'].">";
} else {
$fcid = 0;
$type = (array_key_exists('type',$_GET)) ? $_GET['type'] : 'user';
}
$from=$_SESSION['name']." <".$_SESSION['email'].">";
}
if($id) {
$q = mysql_query("SELECT * FROM emails WHERE id='$id'");
@ -205,11 +225,12 @@ case 'dialog_edit':
$key = htmlspecialchars($e['val']);
$description = htmlspecialchars($e['description']);
$from = htmlspecialchars($e['from']);
if(!$from && $config['fairmanageremail']) $from="Fair Manager <".$config['fairmanageremail'].">";
$subject = htmlspecialchars($e['subject']);
$body = $e['body'];
$bodyhtml = $e['bodyhtml'];
$fcid = intval($e['fundraising_campaigns_id']);
if($bodyhtml == '') $bodyhtml = $body;
if($bodyhtml == '') $bodyhtml = nl2br($body);
}
@ -217,15 +238,35 @@ case 'dialog_edit':
<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>
<table class="editor" style="width: 95%">
<?
if($emails_id) {
?>
<input type="hidden" name="emails_id" value="<?=$emails_id?>" />
<input type="hidden" name="key" value="<?=$key?>" />
<tr>
<td class="label"><?=i18n("Email Key")?>:</td>
<td class="input"><?=$key?></td>
</tr>
<?
}
else {
?>
<tr>
<td class="label"><?=i18n("Email Key")?>:</td>
<td class="input"><input type="text" name="key" size="60" value="" /></td>
</tr>
<?
}
/* ="fcid=$fcid, key=$key, type=$type"*/ ?>
<tr>
<td class="label"><?=i18n("Name")?>:</td>
<td class="input"><input type="text" name="name" size="60" value="<?=$name?>" /></td>
</tr><tr>
</tr>
<tr>
<td class="label"><?=i18n("Description")?>:</td>
<td class="input"><input type="text" name="description" size="60" value="<?=$description?>" /></td>
</tr><tr>
@ -249,11 +290,11 @@ case 'dialog_edit':
<option value="FIRSTNAME">[FIRSTNAME]</option>
<option value="LASTNAME">[LASTNAME]</option>
<option value="NAME">[NAME]</option>
<option value="SALUTATION">[SALUTATION]</option>
<option value="PASSWORD">[PASSWORD]</option>
<option value="SALUTATION">[LASTNAME]</option>
<option value="REGNUM">[REGNUM]</option>
</select>
</td></tr></table>
</td>
</tr></table>
<hr />
@ -303,6 +344,9 @@ case 'dialog_edit':
comm_dialog_edit_cancel();
}
}
if(typeof(refreshEmailList) == 'function') {
refreshEmailList();
}
}
});
@ -431,6 +475,149 @@ case 'dialog_send':
</script>
<?
exit;
//dialog_sender is used to send a one-off communication based on a given template to a given user
//receives 'uid' and an optional 'template'
case 'dialog_sender':
$u=user_load_by_uid(intval($_GET['uid']));
if($_GET['template']) {
$emailq=mysql_query("SELECT * FROM emails WHERE `val`='".mysql_real_escape_string($_GET['template'])."'");
$e=mysql_fetch_assoc($emailq);
}
else
$e=null;
$from=htmlspecialchars($_SESSION['name']." <".$_SESSION['email'].">");
$to=htmlspecialchars($u['emailrecipient']);
$subject = htmlspecialchars($e['subject']);
//useless but we might as well have it
$name = htmlspecialchars($e['name']);
$key = htmlspecialchars($e['val']);
$description = htmlspecialchars($e['description']);
//do the replacements from the template now, so what the person see's is what gets sent.
$body = communication_replace_vars($e['body'],$u);
$bodyhtml = communication_replace_vars($e['bodyhtml'],$u);
//if there's no html,. grab the html from the non-html version
if($bodyhtml == '') $bodyhtml = nl2br($body);
?>
<div id="comm_dialog_sender" title="Send an Email" style="display: none">
<br />
<form id="comm_dialog_sender_form">
<? /* ="fcid=$fcid, key=$key, type=$type"*/ ?>
<table class="editor" style="width:95%">
<?
if($e) {
echo "<tr><td class=\"label\">".i18n("Using Template").":</td><td class=\"input\"><a href=\"communication.php?action=edit&val=$key\">$name (".i18n("click to edit template").")</a></td></tr>\n";
echo "<tr><td colspan=\"2\"><hr /></td></tr>\n";
}
?>
<tr>
<td class="label"><?=i18n("From")?>:</td>
<td class="input"><input type="text" name="from" size="60" value="<?=$from?>" /></td>
</tr><tr>
<td class="label"><?=i18n("To")?>:</td>
<td class="input"><input type="text" name="to" size="60" value="<?=$to?>" /></td>
</tr><tr>
<td class="label"><?=i18n("Subject")?>:</td>
<td class="input"><input type="text" name="subject" size="60" value="<?=$subject?>" /></td>
</tr><tr>
<td colspan="2" class="input">
<div id="fck">
<textarea id="bodyhtml" name="bodyhtml" rows=6 cols=80><?=$bodyhtml?></textarea>
</div>
</td>
</tr></table>
<hr />
<div align="right">
<input type="submit" id="comm_dialog_sender_send_button" value="<?=i18n('Send')?>" />
<input type="submit" id="comm_dialog_sender_cancel_button" value="<?=i18n('Cancel')?>" />
</div>
</form>
</div>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/fckeditor/fckeditor.js"></script>
<script type="text/javascript">
$("#comm_dialog_sender_send_button").click(function () {
var oFCKeditor = FCKeditorAPI.GetInstance('bodyhtml') ;
var value = oFCKeditor.GetHTML();
$('#bodyhtml').val(value);
$("#debug").load("<?=$config['SFIABDIRECTORY']?>/admin/communication.php?action=email_send", $("#comm_dialog_sender_form").serializeArray(),
function() {
$('#comm_dialog_sender').dialog("close");
});
return false;
}
);
$("#comm_dialog_sender_cancel_button").click(function () {
$('#comm_dialog_sender').dialog("close");
return false;
}
);
$("#comm_dialog_sender").dialog({
bgiframe: true, autoOpen: true,
modal: true, resizable: false,
draggable: false,
width: 800, //(document.documentElement.clientWidth * 0.8);
close: function() {
$(this).dialog('destroy');
$('#comm_dialog_sender').remove();
/* Run callbacks */
}
});
var oFCKeditor = new FCKeditor( 'bodyhtml' ) ;
oFCKeditor.BasePath = "../fckeditor/" ;
oFCKeditor.ToolbarSet = 'sfiab';
oFCKeditor.Width="100%";
oFCKeditor.Height=300;
// $('#fck').html(oFCKeditor.CreateHtml());
oFCKeditor.ReplaceTextarea() ;
</script>
<?
exit;
case "email_send":
email_send_new($_POST['to'],$_POST['from'],$_POST['subject'],$_POST['body'],$_POST['bodyhtml']);
happy_("Email Successfully Sent");
exit;
case "email_get_list":
$q=mysql_query("SELECT * FROM emails ORDER BY type,name");
echo "<table class=\"tableview\">";
echo "<tr>";
echo " <th>".i18n("Name")."</th>";
echo " <th>".i18n("Type")."</th>";
echo " <th>".i18n("Actions")."</th>";
echo "</tr>";
while($r=mysql_fetch_object($q)) {
if($r->fundraising_campaigns_id) $fcid=$r->fundraising_campaigns_id;
else $fcid='null';
if($r->name) $name=$r->name;
else $name=i18n("no email name specified");
echo "<tr><td><a href=\"#\" onclick=\"return opencommunicationeditor('$r->val',$r->id,$fcid)\">$name</a></td>";
echo "<td>$r->type</td>";
echo " <td align=\"center\">";
//only user emails can be deleted, system ones are required and cannot be removed
if($r->type=="user") {
echo "&nbsp;";
echo "<a onclick=\"return confirmClick('Are you sure you want to remove email?')\" href=\"communication.php?action=delete&delete=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
echo "&nbsp;";
echo "<a href=\"communication.php?action=send&send=$r->id\">".i18n("Send")."</a>";
}
echo " </td>\n";
echo "</tr>";
}
echo "</table>";
exit;
}
include "communication.inc.php";
@ -501,10 +688,8 @@ case 'dialog_send':
echo "ok";
launchQueue();
exit;
}
send_header("Communication",
array('Committee Main' => 'committee_main.php',
'Administration' => 'admin/index.php'),
@ -512,59 +697,8 @@ case 'dialog_send':
);
echo "<br />";
if($_POST['action']=="add") {
if(!$_POST['val']) {
echo error(i18n("Email Key is required"));
$_GET['action']="add";
}
else if(!$_POST['name']) {
echo error(i18n("Email Name is required"));
$_GET['action']="add";
}
else if(!$_POST['from']) {
echo error(i18n("Email From is required"));
$_GET['action']="add";
}
else {
mysql_query("INSERT INTO emails (val,name,description,`from`,subject,body,type) VALUES (".
"'".mysql_escape_string(stripslashes($_POST['val']))."', ".
"'".mysql_escape_string(stripslashes($_POST['name']))."', ".
"'".mysql_escape_string(stripslashes($_POST['description']))."', ".
"'".mysql_escape_string(stripslashes($_POST['from']))."', ".
"'".mysql_escape_string(stripslashes($_POST['subject']))."', ".
"'".mysql_escape_string(stripslashes($_POST['body']))."', ".
"'user')");
echo mysql_error();
echo happy(i18n("Email successfully added"));
}
}
if($_POST['action']=="edit") {
if(!$_POST['name']) {
echo error(i18n("Email Name is required"));
$_GET['action']="edit";
$_GET['edit']=$_POST['edit'];
}
else if(!$_POST['from']) {
echo error(i18n("Email From is required"));
$_GET['action']="edit";
$_GET['edit']=$_POST['edit'];
}
else {
mysql_query("UPDATE emails SET ".
"name='".mysql_escape_string(stripslashes($_POST['name']))."', ".
"description='".mysql_escape_string(stripslashes($_POST['description']))."', ".
"`from`='".mysql_escape_string(stripslashes($_POST['from']))."', ".
"subject='".mysql_escape_string(stripslashes($_POST['subject']))."', ".
"body='".mysql_escape_string(stripslashes($_POST['body']))."' ".
" WHERE id='".$_POST['edit']."'");
echo mysql_error();
echo happy(i18n("Email successfully saved"));
}
}
if($_GET['action']=="delete" && $_GET['delete']) {
mysql_query("DELETE FROM emails WHERE id='".$_GET['delete']."'");
mysql_query("DELETE FROM emails WHERE id='".$_GET['delete']."' AND `type`='user'");
echo happy("Email successfully deleted");
}
@ -575,7 +709,7 @@ case 'dialog_send':
echo i18n("Please confirm you would like to send the following email, and choose who to send it to");
echo "<br>";
echo "<br>";
echo "<form method=\"get\" action=\"communication.php\">";
echo "<form method=\"post\" action=\"communication.php\">";
echo "<table cellspacing=0 cellpadding=3 border=1>";
echo "<tr><td><b>From:</b></td><td>".htmlspecialchars($r->from)."</td></tr>";
echo "<tr><td><b>To:</b></td><td>";
@ -599,9 +733,13 @@ case 'dialog_send':
echo "</td></tr>";
echo "<tr><td><b>Date:</b></td><td>".date("r")."</td></tr>";
echo "<tr><td><b>Subject:</b></td><td>".htmlspecialchars($r->subject)."</td></tr>";
$body=htmlspecialchars($r->body);
if($r->bodyhtml) {
$body=$r->bodyhtml;
}
else
$body=nl2br(htmlspecialchars($r->body));
echo "<tr><td colspan=2>".nl2br($body)."</td></tr>";
echo "<tr><td colspan=2>".$body."</td></tr>";
echo "</table>";
@ -625,167 +763,114 @@ case 'dialog_send':
}
//echo $str;
}
else if($_GET['action']=="reallysend" && $_GET['reallysend'] && $_GET['to'])
{
if(file_exists("../data/communication.lock"))
{
echo error("Another email communication is already in progress");
$lines=file("../data/communication.lock");
echo "<br>";
echo "<a href=\"communication_send_status.php\">Click here to see the status of the communication sending that is in progress</a>";
else if($_POST['action']=="reallysend" && $_POST['reallysend'] && $_POST['to']) {
$emailid=intval($_POST['reallysend']);
$emailq=mysql_query("SELECT * FROM emails WHERE id='$emailid'");
$email=mysql_fetch_object($emailq);
$to=$_POST['to'];
if(array_key_exists($to,$mailqueries)) {
$recipq=mysql_query($mailqueries[$to]['query']);
}
else
{
$to = $_GET['to'];
if(array_key_exists($to,$mailqueries))
{
$q=mysql_query($mailqueries[$to]['query']);
echo mysql_error();
$num_subscribed=mysql_num_rows($q);
if($num_subscribed)
{
$q=mysql_query("SELECT * FROM emails WHERE id='".$_GET['reallysend']."'");
$r=mysql_fetch_object($q);
//communcation lock file lines:
// 1: Email ID
// 2: Date it was started
// 3: Subject
// 4: Total Recipients
// 5: _GET['to']
$fp=fopen("../data/communication.lock","w");
fputs($fp,$r->id."\n");
fputs($fp,date("r")."\n");
fputs($fp,$r->subject."\n");
fputs($fp,$num_subscribed."\n");
fputs($fp,$_GET['to']."\n");
fclose($fp);
exec("php -q send_communication.php ".$_GET['reallysend']." >/dev/null 2>&1 &");
echo "<br />";
echo happy("Email Communication sending has started!");
echo "<br>";
echo "<a href=\"communication_send_status.php\">Click here to see the sending progress</a>";
}
else
{
echo error(i18n("No recipients"));
}
$numtotal=mysql_num_rows($recipq);
mysql_query("INSERT INTO emailqueue (val,name,users_uid,`from`,subject,body,bodyhtml,`type`,fundraising_campaigns_id,started,finished,numtotal,numsent) VALUES (
'".mysql_real_escape_string($email->val)."',
'".mysql_real_escape_string($email->name)."',
'".$_SESSION['users_uid']."',
'".mysql_real_escape_string($email->from)."',
'".mysql_real_escape_string($email->subject)."',
'".mysql_real_escape_string($email->body)."',
'".mysql_real_escape_string($email->bodyhtml)."',
'".mysql_real_escape_string($email->type)."',
NULL,
NOW(),
NULL,
$numtotal,
0)");
$emailqueueid=mysql_insert_id();
echo mysql_error();
while($r=mysql_fetch_object($recipq)) {
if($r->uid)
$u=user_load_by_uid($r->uid);
else if($r->users_uid)
$u=user_load_by_uid($r->users_uid);
else {
$toname=$r->firstname." ".$r->lastname;
$toemail=$r->email;
$replacements=array(
"FAIRNAME"=>$config['fairname'],
"FIRSTNAME"=>$r->firstname,
"LASTNAME"=>$r->lastname,
"NAME"=>$r->firstname." ".$r->lastname,
"EMAIL"=>$r->email,
"ORGANIZATION"=>$r->organization
);
}
else
echo error(i18n("Unknown 'to' to send email communication to (%1)",array($_GET['to'])));
if($u) {
$replacements=array(
"FAIRNAME"=>$config['fairname'],
"SALUTATION"=>$u['salutation'],
"FIRSTNAME"=>$u['firstname'],
"LASTNAME"=>$u['lastname'],
"NAME"=>$u['firstname']." ".$u['lastname'],
"EMAIL"=>$u['email'],
"ORGANIZATION"=>$u['sponsor']['organization']
);
if($u['firstname'] && $u['lastname'])
$toname=$u['firstname']." ".$u['lastname'];
else if($u['firstname'])
$toname=$u['firstname'];
else if($u['lastname'])
$toname=$u['lastname'];
$toemail=$u['email'];
}
if($toemail) {
mysql_query("INSERT INTO emailqueue_recipients (emailqueue_id,toemail,toname,replacements,sent) VALUES (
'$emailqueueid',
'".mysql_real_escape_string($toemail)."',
'".mysql_real_escape_string($toname)."',
'".json_encode($replacements)."',
NULL)");
echo mysql_error();
}
mysql_query("UPDATE emails SET lastsent=NOW() WHERE id='$emailid'");
}
launchQueue();
echo "<br />";
echo happy("Email Communication sending has started!");
echo "<br>";
echo "<a href=\"communication_send_status.php\">Click here to see the sending progress</a>";
}
else if($_GET['action']=="add" || $_GET['action']=="edit")
{
echo "<form method=\"post\" action=\"communication.php\">";
if($_GET['action']=="edit")
{
$q=mysql_query("SELECT * FROM emails WHERE id='".$_GET['edit']."'");
$r=mysql_fetch_object($q);
$buttontext=i18n("Save Email");
echo "<input type=\"hidden\" name=\"action\" value=\"edit\">\n";
echo "<input type=\"hidden\" name=\"edit\" value=\"".$_GET['edit']."\">\n";
echo "<h3>".i18n("Edit Email")."</h3>";
else {
if(!$config['fairmanageremail'])
echo notice(i18n("Warning: The 'Fair Manager Email' has not been set in SFIAB Configuration / Configuration Variables / Global. Please set it. The 'Fair Manager Email' is the default 'From' address for all emails and without a 'From' address, no emails can be sent!"));
$val=$r->val;
$name=$r->name;
$description=$r->description;
$subject=$r->subject;
$from=$r->from;
$body=$r->body;
}
else
{
$buttontext=i18n("Add Email");
echo "<input type=\"hidden\" name=\"action\" value=\"add\">\n";
echo "<h3>".i18n("Add Email")."</h3>";
}
if($_POST['val']) $val=stripslashes($_POST['val']);
if($_POST['name']) $name=stripslashes($_POST['name']);
if($_POST['description']) $description=stripslashes($_POST['description']);
if($_POST['subject']) $subject=stripslashes($_POST['subject']);
if($_POST['from']) $from=stripslashes($_POST['from']);
if($_POST['body']) $body=stripslashes($_POST['body']);
if(!$from && $config['fairmanageremail']) $from="Fair Manager <".$config['fairmanageremail'].">";
echo "<table class=\"editor\">";
echo "<tr><td style=\"width:10\%\">".i18n("Email Name").":</td><td><input type=\"text\" name=\"name\" size=\"60\" value=\"$name\" /></td></tr>\n";
echo "<tr><td>".i18n("Email Key").":</td><td>";
if($r->type=="system")
echo $val;
else
echo "<input type=\"text\" name=\"val\" size=\"40\" value=\"$val\" /> (must be unique)";
echo "</td></tr>\n";
echo "<tr><td>".i18n("Email Description").":</td><td><input type=\"text\" name=\"description\" size=\"60\" value=\"$description\" /></td></tr>\n";
echo "<tr><td colspan=\"2\"><hr /></td></tr>";
echo "<tr><td>".i18n("Email Subject").":</td><td><input type=\"text\" name=\"subject\" size=\"60\" value=\"$subject\" /></td></tr>\n";
echo "<tr><td>".i18n("Email From").":</td><td><input type=\"text\" name=\"from\" size=\"60\" value=\"$from\" /></td></tr>\n";
echo "<tr><td>".i18n("Email Body")."</td><td><textarea name=\"body\" cols=\"80\" rows=\"10\" style=\"font-size: 0.75em\">".htmlspecialchars($body)."</textarea></td></tr>";
/*
echo "<tr><td>".i18n("Email Body").":</td><td>";
require_once("../fckeditor/fckeditor.php");
$oFCKeditor = new FCKeditor("body") ;
$oFCKeditor->BasePath = "../fckeditor/";
$oFCKeditor->Value = $body;
$oFCKeditor->Width="100%";
$oFCKeditor->Height=300;
$oFCKeditor->Create();
echo "</td></tr>";
*/
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"".$buttontext."\"></td></tr>";
echo "</table>";
echo "</form>";
}
else
{
if(!$config['fairmanageremail'])
echo notice(i18n("Warning: The 'Fair Manager Email' has not been set in SFIAB Configuration / Configuration Variables / Global. Please set it. The 'Fair Manager Email' is the default 'From' address for all emails and without a 'From' address, no emails can be sent!"));
echo "<a href=\"communication_send_status.php\">".i18n("Email Queue Status and History")."</a><br /><br />\n";
$q=mysql_query("SELECT * FROM emails ORDER BY type,name");
echo "<A href=\"communication.php?action=add\">Add New Email</a>";
echo "<table class=\"summarytable\">";
echo "<tr>";
echo " <th>".i18n("Name")."</th>";
echo " <th>".i18n("Type")."</th>";
echo " <th>".i18n("Actions")."</th>";
echo "</tr>";
while($r=mysql_fetch_object($q))
{
echo "<tr><td>$r->name</td>";
echo "<td>$r->type</td>";
echo " <td align=\"center\">";
echo "<a href=\"communication.php?action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";
//only user emails can be deleted, system ones are required and cannot be removed
if($r->type=="user")
{
echo "&nbsp;";
echo "<a onclick=\"return confirmClick('Are you sure you want to remove email?')\" href=\"communication.php?action=delete&delete=$r->id\"><img border=0 src=\"".$config['SFIABDIRECTORY']."/images/16/button_cancel.".$config['icon_extension']."\"></a>";
echo "&nbsp;";
echo "<a href=\"communication.php?action=send&send=$r->id\">Send</a>";
echo "<a href=\"communication_send_status.php\">".i18n("Email Queue Status and History")."</a><br />";
echo "<a href=\"#\" onclick=\"return opencommunicationeditor(null,null,null)\">".i18n("Add New Email")."</a>";
echo "<br />\n";
echo "<br />\n";
echo "<div id=\"emaillist\"></div>";
?>
<script type="text/javascript">
function refreshEmailList() {
$("#emaillist").load("communication.php?action=email_get_list",null,function() {
});
}
echo " </td>\n";
echo "</tr>";
$(document).ready(function() {
refreshEmailList();
}
);
</script>
<?
}
echo "</table>";
}
send_footer();
send_footer();
?>

View File

@ -131,47 +131,6 @@
echo "<div id=\"queuestatus\" style=\"margin-left: 20px;\">";
echo "</div>";
echo "<br />";
echo "<br />";
echo "<h3>".i18n("Old Send Queue (to be removed / migrated to the above eventually)")."</h3>\n";
echo "<div style=\"margin-left: 20px\">";
if(file_exists("../data/communication.lock"))
{
$lines=file("../data/communication.lock");
echo "<b>Email ID:</b> ".$lines[0]." <br>";
echo "<b>Started:</b> ".$lines[1]." <br>";
echo "<b>Subject:</b> ".$lines[2]." <br>";
echo "<b>Total Recipients:</b> ".$lines[3]." <br>";
echo "<b>To:</b> ".$lines[4]." <br>";
echo "</div>";
$id=trim($lines[0]);
$total=trim($lines[3]);
echo "<h3>".i18n("Progress")."</h3>";
echo "<div style=\"margin-left: 20px\">";
if(file_exists("../data/communication.lock.$id"))
{
$progresslines=file("../data/communication.lock.$id");
$num=$progresslines[0];
$percent=round($num/$total*100,1);
echo i18n("%1 of %2 (%3%)",array($num,$total,$percent));
}
else
{
echo "Queued to start (should start within the next minute)";
}
echo "</div>";
echo "<br><br>Press your browsers 'Refresh' Button to see updated status";
}
else
{
echo notice("No Email Communications are currently being sent out");
echo "</div>";
}
send_footer();
?>

View File

@ -33,10 +33,37 @@
"fundraising"
);
function getUserForSponsor($sponsor_id) {
// loop through each contact and draw a form with their data in it.
$q = mysql_query("SELECT *,MAX(year) FROM users LEFT JOIN users_sponsor ON users_sponsor.users_id=users.id
WHERE
sponsors_id='" . $sponsor_id . "'
AND types LIKE '%sponsor%'
GROUP BY uid
HAVING deleted='no'
ORDER BY users_sponsor.primary DESC,lastname,firstname
LIMIT 1
");
$r=mysql_fetch_object($q);
return user_load_by_uid($r->uid);
}
?>
<script type="text/javascript">
$(document).ready(function() {
});
//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 opencommunicationsender(uid,template) {
$("#content").empty();
$("#content").load("communication.php?action=dialog_sender&uid="+uid+"&template=fundraising_thankyou_template",null,function() {
});
return false;
}
</script>
<h3><?=i18n("Fundraising Purposes and Progress Year to Date")?></h3>
@ -133,6 +160,7 @@ $q=mysql_query("SELECT value, thanked, status, sponsors_id, datereceived,
ORDER BY datereceived
");
echo mysql_error();
if(mysql_num_rows($q)) {
echo "<table class=\"tableview\">";
echo "<tr><th>".i18n("Name")."</th>\n";
@ -148,12 +176,18 @@ if(mysql_num_rows($q)) {
else if($r->onemonth) $s="style=\"background-color: ".colour_to_percent(50).";\"";
else $s="";
$u=getUserForSponsor($r->sponsors_id);
echo "<tr $s>";
echo " <td>$dr->name</td>";
echo " <td>".format_date($r->datereceived)."</td>";
echo " <td style=\"text-align: right;\">".format_money($r->value)."</td>";
echo " <td style=\"text-align: center;\">";
echo "<a href=\"#\" onclick=\"return false;\">".i18n("Generate Thank You")."</a></td>";
if($u) {
echo "<a href=\"#\" onclick=\"return opencommunicationsender('{$u['uid']}','fundraising_thankyou_template');\">".i18n("Generate Thank You")."</a></td>";
} else {
echo i18n("No contact");
}
echo "</tr>\n";
}
echo "</table>\n";

View File

@ -664,19 +664,6 @@ function prospect_removeall() {
return false;
}
//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,fcid) {
$("#content").empty();
if(id) {
$("#content").load("communication.php?action=dialog_edit&id="+id+"&fundraising_campaigns_id="+fcid,null,function() {
});
} else {
$("#content").load("communication.php?action=dialog_edit&key="+key+"&fundraising_campaigns_id="+fcid,null,function() {
});
}
}
var comm_chooser_key = null;
function opencommunicationchooser(key) {
comm_chooser_key = key;

View File

@ -23,9 +23,6 @@
<?
include "../common.inc.php";
include "communication.inc.php";
require_once("../Rmail/Rmail.php");
$sleepmin=500000; // 0.5 seconds
$sleepmax=2000000; // 2.0 second
@ -41,24 +38,20 @@ if(!$config['emailqueue_lock']) {
$eq=mysql_query("SELECT * FROM emailqueue WHERE id='$r->emailqueue_id'");
$email=mysql_fetch_object($eq);
$mail=new RMail();
$mail->setFrom($email->from);
$mail->setSubject($email->subject);
$blank=array();
$replacements=(array)json_decode($r->replacements);
if($email->body)
$mail->setText(communication_replace_vars($email->body,$blank,$replacements));
$body=communication_replace_vars($email->body,$blank,$replacements);
else if($email->bodyhtml) {
$mail->setText(strip_tags(communication_replace_vars($email->bodyhtml,$blank,$replacements)));
$body=strip_tags(communication_replace_vars($email->bodyhtml,$blank,$replacements));
}
else {
$mail->setText("No message body specified");
$body="No message body specified";
}
if($email->bodyhtml)
$mail->setHTML(communication_replace_vars($email->bodyhtml,$blank,$replacements));
$bodyhtml=communication_replace_vars($email->bodyhtml,$blank,$replacements);
if($r->toname) {
$to="\"$r->toname\" <$r->toemail>";
@ -66,8 +59,12 @@ if(!$config['emailqueue_lock']) {
else {
$to=$r->toemail;
}
echo "$email->id,$r->id,$to\n";
$result=$mail->send(array($to));
$result=email_send_new($to,$email->from,$email->subject,$body,$bodyhtml);
if($result) {
mysql_query("UPDATE emailqueue_recipients SET sent=NOW() WHERE id='$r->id'");
$newnumsent=$email->numsent+1;

View File

@ -890,7 +890,7 @@ function communication_get_user_replacements(&$u) {
function communication_replace_vars($text, &$u, $otherrep=array()) {
global $config;
if($u) {
$userrep=communicaton_get_user_replacements($u);
$userrep=communication_get_user_replacements($u);
}
else {
$userrep=array();
@ -912,46 +912,22 @@ function email_send($val,$to,$sub_subject=array(),$sub_body=array())
return false;
$q=mysql_query("SELECT * FROM emails WHERE val='$val'");
if($r=mysql_fetch_object($q))
{
if($r=mysql_fetch_object($q)) {
$subject=i18n($r->subject);
$body=i18n($r->body);
/* Eventually we should just do this with communication_replace_vars() */
if(count($sub_subject))
{
foreach($sub_subject AS $sub_k=>$sub_v)
{
if(count($sub_subject)) {
foreach($sub_subject AS $sub_k=>$sub_v) {
$subject=ereg_replace("\[$sub_k\]","$sub_v",$subject);
}
}
if(count($sub_body))
{
foreach($sub_body AS $sub_k=>$sub_v)
{
if(count($sub_body)) {
foreach($sub_body AS $sub_k=>$sub_v) {
$body=ereg_replace("\[$sub_k\]","$sub_v",$body);
}
}
//now word-wrap the body to 79 chars
//hmm forget the wordwrap for now, its not really needed, but could be done later if need be.
//i'll leave in the start of the function, but its not nearly complete
/*
$MAXCHARS=79;
$c=0;
$lastspace=0;
for($x=0;$x<strlen($body);$x++)
{
if($body[$x]==" ")
$lastspace=$x;
$c++;
if($c>$MAXCHARS)
{
}
}
*/
if($r->from)
$fr=$r->from;
else if ($config['fairmanageremail'])
@ -961,18 +937,39 @@ function email_send($val,$to,$sub_subject=array(),$sub_body=array())
//only send the email if we have a from
if($fr) {
$extraheaders="From: $fr\r\nReply-To: $fr\r\nReturn-Path: $fr";
mail($to,$subject,$body,$extraheaders);
//send using RMail
email_send_new($to,$fr,$subject,$body);
}
else
echo error(i18n("CRITICAL ERROR: email '%1' does not have a 'From' and the Fair Manager Email is not configured",array($val),array("email key name")));
}
else
{
else {
echo error(i18n("CRITICAL ERROR: email '%1' not found",array($val),array("email key name")));
}
}
require_once("Rmail/Rmail.php");
//this sends out an all-ready-to-go email, it does no substitution or changes or database lookups or anything
function email_send_new($to,$from,$subject,$body,$bodyhtml="") {
$mail=new RMail();
$mail->setFrom($from);
$mail->setSubject($subject);
$mail->setText($body);
//only add the html if we have it
if($bodyhtml) {
$mail->setHTML($bodyhtml);
}
if(is_array($to)) {
return $mail->send($to);
} else {
return $mail->send(array($to));
}
}
/*
returns an array of arrays
[ 0 ] = array ( to, firstname, lastname, email )

View File

@ -1 +1 @@
153
154

1
db/db.update.154.sql Normal file
View File

@ -0,0 +1 @@
INSERT INTO `emails` (`val`, `name`, `description`, `from`, `subject`, `body`, `bodyhtml`, `type`, `fundraising_campaigns_id`, `lastsent`) VALUES ('fundraising_thankyou_template', 'Fundraising Thank You Template', 'Fundraising thank you template to be used to send thank you emails to individual sponsor/donors once a donation is received', '', 'Thank You for your Contribution', 'Dear [FIRSTNAME],\r\n\r\nThank you for your contribution to the [FAIRNAME]\r\n\r\nSincerely,\r\n [FAIRNAME] Committee\r\n', NULL, 'system', NULL, NULL);

View File

@ -80,4 +80,22 @@ $(document).ready(function()
$(".tableview tr:odd").addClass('odd');
});
//key is 'val' from emails table, or id is id, fcid simply gets passed in and saved if needed
//only id or key are used to lookup which to open
function opencommunicationeditor(key,id,fcid) {
$("#content").empty();
var fcstr="";
if(fcid)
fcstr="&fundraising_campaigns_id="+fcid;
if(id) {
$("#content").load("communication.php?action=dialog_edit&id="+id+fcstr,null,function() {
});
} else {
$("#content").load("communication.php?action=dialog_edit&key="+key+fcstr,null,function() {
});
}
return false;
}

View File

@ -215,6 +215,22 @@ function user_load($user, $uid = false)
/* Convenience */
$ret['name'] = $ret['firstname'].' '.$ret['lastname'];
/* Email recipient for "to" field on emails */
if( ($ret['firstname'] || $ret['lastname']) && $ret['email']) {
//use their full name if we have it
//if the name contains anything non-standard, we need to quote it.
if(eregi("[^a-z0-9 ]",$ret['name']))
$ret['emailrecipient']="\"{$ret['name']}\" <{$ret['email']}>";
else
$ret['emailrecipient']="{$ret['name']} <{$ret['email']}>";
}
else if($ret['email']) {
//otherwise, just their email address
$ret['emailrecipient']=$ret['email'];
}
else
$ret['emailrecipient']="";
foreach($ret['types'] as $t) {
/* These all pass $ret by reference, and can modify
* $ret */