Copyright (C) 2005 James Grant 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. */ ?> >../data/logs/emailqueue.log 2>&1 &"); } /* dialog_choose * select: comm_dialog_choose_select(emails_id) * cancel: comm_dialog_choose_cancel() */ switch($_GET['action']) { case 'dialog_choose_load': $emails_id = intval($_GET['emails_id']); $q = mysql_query("SELECT * FROM emails WHERE id='$emails_id'"); $e = mysql_fetch_assoc($q); ?>
:
:
:
name)); } 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'"); 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']); 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 = nl2br($body); } ?> "); $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); ?> "; echo ""; echo " ".i18n("Name").""; echo " ".i18n("Type").""; echo " ".i18n("Actions").""; echo ""; 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 "val)."',$r->id,$fcid)\">",htmlspecialchars($name).""; echo "$r->type"; echo " "; //only user emails can be deleted, system ones are required and cannot be removed if($r->type=="user") { echo " "; echo "id\">"; echo " "; echo "id\">".i18n("Send").""; } echo " \n"; echo ""; } echo ""; exit; case 'cancel': if($_GET['cancel']) { mysql_query("UPDATE emailqueue SET finished=NOW() WHERE id='".intval($_GET['cancel'])."'"); mysql_query("UPDATE emailqueue_recipients SET result='cancelled' WHERE emailqueue_id='".intval($_GET['cancel'])."' AND sent IS NULL AND result IS NULL"); echo "ok"; } exit; } include "communication.inc.php"; if($_GET['action']=="sendqueue") { $fcid=intval($_POST['fundraising_campaigns_id']); $emailid=intval($_POST['emails_id']); $fcq=mysql_query("SELECT * FROM fundraising_campaigns WHERE id='$fcid'"); $fc=mysql_fetch_object($fcq); $emailq=mysql_query("SELECT * FROM emails WHERE id='$emailid'"); $email=mysql_fetch_object($emailq); $recipq=mysql_query("SELECT * FROM fundraising_campaigns_users_link WHERE fundraising_campaigns_id='$fcid'"); echo mysql_error(); $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)."', $fcid, NOW(), NULL, $numtotal, 0)"); $emailqueueid=mysql_insert_id(); echo mysql_error(); $urlproto = $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $urlmain = "$urlproto{$_SERVER['HTTP_HOST']}{$config['SFIABDIRECTORY']}"; $urllogin = "$urlmain/login.php"; while($r=mysql_fetch_object($recipq)) { $u=user_load_by_uid($r->users_uid); $confirmationLink = account_build_email_confirmation_link($u['accounts_id']); $replacements=array( "FAIRNAME"=>$config['fairname'], "SALUTATION"=>$u['salutation'], "FIRSTNAME"=>$u['firstname'], "LASTNAME"=>$u['lastname'], "NAME"=>$u['name'], "EMAIL"=>$u['email'], "ORGANIZATION"=>$u['sponsor']['organization'], "URLMAIN"=>$urlmain, "URLLOGIN"=>$urllogin, "EMAILCONFIRMATIONLINK" => $confirmationLink, ); if($u['email'] && $u['email'][0] != '*') { mysql_query("INSERT INTO emailqueue_recipients (emailqueue_id,toemail,toname,replacements,sent) VALUES ( '$emailqueueid', '".mysql_real_escape_string($u['email'])."', '".mysql_real_escape_string($u['name'])."', '".mysql_real_escape_string(json_encode($replacements))."', NULL)"); echo mysql_error(); } mysql_query("UPDATE emails SET lastsent=NOW() WHERE id='$emailid'"); } echo "ok"; launchQueue(); exit; } send_header("Communication", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php'), "communication" ); echo "
"; if($_GET['action']=="delete" && $_GET['delete']) { mysql_query("DELETE FROM emails WHERE id='".$_GET['delete']."' AND `type`='user'"); echo happy("Email successfully deleted"); } if($_GET['action']=="send" && $_GET['send']) { $q=mysql_query("SELECT * FROM emails WHERE id='".$_GET['send']."'"); $r=mysql_fetch_object($q); echo i18n("Please confirm you would like to send the following email, and choose who to send it to"); echo "
"; echo "
"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; if($r->bodyhtml) { $body=$r->bodyhtml; } else { $body=nl2br(htmlspecialchars($r->body)); } echo ""; echo "
From:".htmlspecialchars($r->from)."
To:"; echo ""; echo "
Date:".date("r")."
Subject:".htmlspecialchars($r->subject)."
".$body."
"; if(!function_exists("exec")) { echo "
Sending requires php's exec() function to be available
\n"; } else { echo ""; echo ""; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
"; echo ""; echo "
"; echo "
"; } //echo $str; } 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']); } $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(); $urlproto = $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $urlmain = "$urlproto{$_SERVER['HTTP_HOST']}{$config['SFIABDIRECTORY']}"; $urllogin = "$urlmain/login.php"; while($r=mysql_fetch_object($recipq)) { if($r->id) $u=user_load($r->id); else 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, "ORGANIZATION"=>$r->organization, "URLMAIN"=>$urlmain, "URLLOGIN"=>$urllogin, ); } if($u) { $a=account_load($u['accounts_id']); $apassword=account_get_password($u['accounts_id']); $confirmationLink = account_build_email_confirmation_link($u['accounts_id']); if($a['email']) { $e=$a['email']; } else if ($a['pendingemail']) { $e=$a['pendingemail']; } else { $e=""; } if($u['registrations_id']) { $regq=mysql_query("SELECT num FROM registrations WHERE id='{$u['registrations_id']}'"); $regr=mysql_fetch_assoc($regq); } $replacements=array( "FAIRNAME"=>$config['fairname'], "SALUTATION"=>$u['salutation'], "FIRSTNAME"=>$u['firstname'], "LASTNAME"=>$u['lastname'], "NAME"=>$u['name'], "EMAIL"=>$e, "USERNAME"=>$a['username'], "PASSWORD"=>$apassword, "REGNUM"=>$regq['num'], "ORGANIZATION"=>$u['sponsor']['organization'], "URLMAIN"=>$urlmain, "URLLOGIN"=>$urllogin, "EMAILCONFIRMATIONLINK" => $confirmationLink, ); $toname=$u['name']; $toemail=$e; } 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)."', '".mysql_real_escape_string(json_encode($replacements))."', NULL)"); echo mysql_error(); } mysql_query("UPDATE emails SET lastsent=NOW() WHERE id='$emailid'"); } launchQueue(); echo "
"; echo happy("Email Communication sending has started!"); echo "
"; echo "Click here to see the sending progress"; } else if($_GET['action']=="restartqueue") { launchQueue(); echo "
"; echo happy("Email Communication sending has started!"); echo "
"; echo "Click here to see the sending progress"; } 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 "".i18n("Email Queue Status and History")."
"; echo "".i18n("Add New Email").""; echo "
\n"; echo "
\n"; echo "
"; ?>