.
*/
include("./include/include.php");
admin_header();
if( !in_array("massmail_sendaschair", $_SESSION['sess_functions']) && !in_array("massmail_sendaslocalorg", $_SESSION['sess_functions']) ) {
echoln("You are not authorized to see this page.");
}else {
$sendAsChair = in_array("massmail_sendaschair", $_SESSION['sess_functions']);
include("./include/Appl.php");
include("./include/g_accesstxt.php");
include("./include/g_accepted.php");
include("./include/g_workshop.php");
include("./include/g_country.php");
include("./include/g_body.php");
echoln("
Mass mailer
");
echoln("
Important note: there is a maximum of one mail per ".($sendAsChair?$setup['MailallDaysIntervalChair']:$setup['MailallDaysIntervalOrganiser'])." days. In case you want to send to more than one group of 'accepted' status, ");
echoln("make sure you mail to all of them without logging out in between. As soon as you send the first mail, the system will not allow another mail to a person until ");
echoln(($sendAsChair?$setup['MailallDaysIntervalChair']:$setup['MailallDaysIntervalOrganiser'])." days have passed. But, until the time you log out, you still have the possibility to mail others.");
echoln(" Visa mails are excluded from this limit, but, at the moment it is not possible to use the visa mailer when the mass mailer has been used in the last days. If you ");
echoln("want to send special mails for visa people, as well as a mail to all people, first send the visa mails, log out, and only then send to all the accepted people ");
echoln("(if you skip the logout between visa and mail to all the mail will not be send to the people that already received a mail (the visa people)).
");
if( getMailBatchCount() > 0 ) {
showSendMails();
}elseif( get_sql_date(($sendAsChair?$setup['MailallNextAllowedChair']:$setup['MailallNextAllowedOrganiser']))>date("Y-m-d") AND !$_SESSION['mailall_permission'] ) {
// Trying to mail too soon after previous
echoln("You cannot send a mail to all participants now.");
echoln("
There is a limit of one mail per ".($sendAsChair?$setup['MailallDaysIntervalChair']:$setup['MailallDaysIntervalOrganiser'])." days. You can mail again on ".get_date(($sendAsChair?$setup['MailallNextAllowedChair']:$setup['MailallNextAllowedOrganiser']))."
");
}else {
// $domail:
// - [empty]: show form
// - yes: start submitting
// - run: we were restarted for some reason, go on where we were
$domail = "";
if( strlen( get_var("domail") )>0 ) $domail=get_var("domail");
elseif( isset($_SESSION['mailall_domail']) ) $domail=$_SESSION['mailall_domail'];
$Error = false;
if( isset($_SESSION['mailall_domail']) && $_SESSION['mailall_domail']!="" ) {
$Accepted = $_SESSION['mailall_Accepted'];
$Nationality = $_SESSION['mailall_Nationality'];
$FirstAgora = $_SESSION['mailall_FirstAgora'];
$From = $_SESSION['mailall_From'];
$Subject = $_SESSION['mailall_Subject'];
$Message = $_SESSION['mailall_Message'];
}else {
$Accepted = get_var("accepted");
$Nationality = get_int("nationality");
$FirstAgora = isset($_POST['firstAgora']);
$From = stripslashes(get_var("from"));
$Subject = stripslashes(get_var("subject"));
$Message = stripslashes(get_var("message"));
}
if( $domail=="yes" OR $domail=="preview" OR $domail=="run") {
// Check input
if( !in_array( $Accepted, array_keys($Accepted_img) ) AND $Accepted!="visa" ) {
// Error
echoln(" - Invalid 'To participants' given, please select from the list.");
$Error = true;
}
if( $Accepted=="visa" AND $Nationality<1 ) {
// Error
echoln(" - Invalid nationality selected.");
$Error = true;
}
if( strlen( $From )<3 ) {
// Error
echoln(" - No from given, please enter a from name.");
$Error = true;
}
if( strlen( $Subject )<3 ) {
// Error
echoln(" - No subject given, please enter a subject.");
$Error = true;
}
if( strlen( $Message )<10 ) {
// Error
echoln(" - No message to send given, please enter a message.");
$Error = true;
}
if( $Error==false ) {
// Save in case sending mail fails
if( $domail=="yes" ) {
$_SESSION['mailall_domail'] = "run";
if( $Accepted!="visa" ) {
$NextAllowed=date("d.m.Y", strtotime("+ ".($sendAsChair?$setup['MailallDaysIntervalChair']:$setup['MailallDaysIntervalOrganiser'])." days"));
$query = "UPDATE `setup` SET `Value`='".addslashes($NextAllowed)."' WHERE `Name`='".($sendAsChair?"MailallNextAllowedChair":"MailallNextAllowedOrganiser")."'";
doquery($query);
$_SESSION['mailall_permission']=true;
}
$query = "INSERT INTO `mailallhistory` SET `date` = '".addslashes(date("Y-m-d H:i:s"))."'";
$query .= ", `user` = '".addslashes($_SESSION['sess_name'])."'";
$query .= ", `fromname` = '".addslashes($From)."'";
$query .= ", `fromemail` = '".addslashes($sendAsChair?$setup['MailChair']:$setup['EventApplFromEmail'])."'";
$query .= ", `accepted` = '".addslashes($Accepted)."'";
if( isset($Nationality) && is_numeric($Nationality) ) {
$query .= ", `nationality` = ".addslashes($Nationality);
}
$query .= ", `firstAgora` = '".($FirstAgora?"yes":"undefined")."'";
$query .= ", `subject` = '".addslashes($Subject)."'";
$query .= ", `message` = '".addslashes($Message)."'";
doquery($query);
}else {
$_SESSION['mailall_domail'] = "preview";
}
$_SESSION['mailall_Accepted'] = $Accepted;
$_SESSION['mailall_Nationality'] = $Nationality;
$_SESSION['mailall_FirstAgora'] = $FirstAgora;
$_SESSION['mailall_From'] = $From;
$_SESSION['mailall_Subject'] = $Subject;
$_SESSION['mailall_Message'] = $Message;
}
}elseif( $domail=="run" ) {
}else { // New mail
if( strlen($Accepted)<1 ) $Accepted = "yes";
}
if( $Error==true OR ($domail!="yes" AND $domail!="run" AND $domail!="preview") ) {
// Show form
$_SESSION['mailall_domail']="";
echoln("");
}elseif( $domail=="preview" ) {
// Preview
$query="SELECT COUNT(`id`) as `total` FROM `applications` ";
if( $Accepted=="visa" )
$query.="WHERE (`Accepted`='yes' OR `Accepted`='pending' OR `Accepted`='confirmed' OR `Accepted`='arrived') AND `Visa`='yes' AND `Nationality`=".addslashes($Nationality);
else
$query.="WHERE `Accepted`='".addslashes($Accepted)."'";
if( $FirstAgora ) $query .= " AND `AgoraVisited`=0";
$row=mysql_fetch_array(doquery($query));
$total=$row['total'];
if( strlen(get_var('start'))>0 ) $start = get_var('start');
elseif( isset($_SESSION['mailall_start']) ) $start = $_SESSION['mailall_start'];
else $start = 0;
if( $start>=$total ) $start=$total-1;
if( $start<1 ) $start=0;
$_SESSION['mailall_start']=$start;
$joins = "";
$query="SELECT ";
for($i=0; $i0 ) {
$row=mysql_fetch_array($res);
echoln("Previewing with application ".($start+1)."/".$total." (".$row['FirstName']." ".$row['LastName']." (ID ".$row['id']."))");
echoln("