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)); $from=$_SESSION['name']." <".$_SESSION['email'].">"; } else { $fcid = 0; $type = (array_key_exists('type',$_GET)) ? $_GET['type'] : 'user'; } } 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; } ?> 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(); while($r=mysql_fetch_object($recipq)) { $u=user_load_by_uid($r->users_uid); $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'"); } echo "ok"; launchQueue(); exit; } send_header("Communication", array('Committee Main' => 'committee_main.php', 'Administration' => 'admin/index.php'), "communication" ); echo "
"; 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']."'"); 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 ""; $body=htmlspecialchars($r->body); echo ""; echo "
From:".htmlspecialchars($r->from)."
To:"; echo ""; echo "
Date:".date("r")."
Subject:".htmlspecialchars($r->subject)."
".nl2br($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($_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 "
"; echo "Click here to see the status of the communication sending that is in progress"; } 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 "
"; echo happy("Email Communication sending has started!"); echo "
"; echo "Click here to see the sending progress"; } else { echo error(i18n("No recipients")); } } else echo error(i18n("Unknown 'to' to send email communication to (%1)",array($_GET['to']))); } } else if($_GET['action']=="add" || $_GET['action']=="edit") { echo "
"; if($_GET['action']=="edit") { $q=mysql_query("SELECT * FROM emails WHERE id='".$_GET['edit']."'"); $r=mysql_fetch_object($q); $buttontext=i18n("Save Email"); echo "\n"; echo "\n"; echo "

".i18n("Edit Email")."

"; $val=$r->val; $name=$r->name; $description=$r->description; $subject=$r->subject; $from=$r->from; $body=$r->body; } else { $buttontext=i18n("Add Email"); echo "\n"; echo "

".i18n("Add Email")."

"; } 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 ""; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo ""; /* echo ""; */ echo ""; echo "
".i18n("Email Name").":
".i18n("Email Key").":"; if($r->type=="system") echo $val; else echo " (must be unique)"; echo "
".i18n("Email Description").":

".i18n("Email Subject").":
".i18n("Email From").":
".i18n("Email Body")."
".i18n("Email Body").":"; require_once("../fckeditor/fckeditor.php"); $oFCKeditor = new FCKeditor("body") ; $oFCKeditor->BasePath = "../fckeditor/"; $oFCKeditor->Value = $body; $oFCKeditor->Width="100%"; $oFCKeditor->Height=300; $oFCKeditor->Create(); echo "
"; echo "
"; } 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")."

\n"; $q=mysql_query("SELECT * FROM emails ORDER BY type,name"); echo "Add New Email"; echo ""; echo ""; echo " "; echo " "; echo " "; echo ""; while($r=mysql_fetch_object($q)) { echo ""; echo ""; echo " \n"; echo ""; } echo "
".i18n("Name")."".i18n("Type")."".i18n("Actions")."
$r->name$r->type"; echo "id\">"; //only user emails can be deleted, system ones are required and cannot be removed if($r->type=="user") { echo " "; echo "id\">"; echo " "; echo "id\">Send"; } echo "
"; } send_footer(); ?>