. */ 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( 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` (`id`, `date`, `user`, `fromname`, `fromemail`, `accepted`, `nationality`, `firstAgora`, `subject`, `message`) VALUES (NULL, '".addslashes(date("Y-m-d H:i:s"))."', '".addslashes($_SESSION['sess_name'])."', '".addslashes($From)."', '".addslashes($sendAsChair?$setup['MailChair']:$setup['EventApplFromEmail'])."', '".addslashes($Accepted)."', ".addslashes($Nationality).", '".($FirstAgora?"yes":"undefined")."', '".addslashes($Subject)."', '".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("

"); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln("
To participants:"); $acc=array_keys($Accepted_img); for( $i=0; $i" : "" ).""); } echoln("
"); echoln(" "); echoln("
"); #echoln("
"); #echoln("
"); #echoln("
"); echoln("
From (name only, no e-mail):
From e-mail:
Note: this e-mail address is taken from setup.
Subject:
Message:
Fields from application:
"); echoln("

"); echoln("
"); }elseif( $domail=="preview" ) { // Preview $query="SELECT COUNT(`PersonID`) as `total` FROM `persons` "; 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; $query="SELECT "; for($i=0; $i0 ) { $row=mysql_fetch_array($res); echoln("Previewing with application ".($start+1)."/".$total." (".$row['FirstName']." ".$row['LastName']." (ID ".$row['PersonID']."))"); echoln("

Edit"); if( $start>0 ) { echoln("  Previous"); }else { echoln("  Previous"); } if( $start<$total-1 ) { echoln("  Next"); }else { echoln("  Next"); } echoln("

"); $srch=array(); $repl=array(); for($i=0; $i64 ) $repl[]="yes"; else $repl[]="no"; }else { //Other $repl[]=$row[ $_SESSION['mailall_fields'][$i] ]; } } if( $sendAsChair ) $from="\"".$From."\" <".$setup['MailChair'].">"; else $from="\"".$From."\" <".$setup['EventApplFromEmail'].">"; $to = "\"".$row['FirstName']." ".$row['LastName']."\" <".$row['Email'].">"; echoln("

"); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln("
From:".$from."
To:".$to."
Subject:".str_replace($srch, $repl, $Subject)."
Message:".nl2br(str_replace($srch, $repl, $Message))."
"); echoln("

"); echoln("
"); }else { // No application found echoln("No applications found."); echoln("

Edit

"); } }else { // Send the mail $query="SELECT "; for($i=0; $iIf you don't get \"Finished\" at the end, you most probably had a time-out. In that case you have to press "); echoln("the 'Refresh' button (only after the browser stopped loading the page). This will continue the process at the "); echoln("position where processing stopped.

"); flush(); if( @mysql_num_rows( $res=doquery($query) )>0 ) { dolog("mailall", "Mail to ".mysql_num_rows($res)." people, target: ".$Accepted.", nationality: ".$Nationality, "info"); while( $row=mysql_fetch_array($res) ) { echoln("
".$row['FirstName']." ".$row['LastName'].": "); if( check_email($row['Email']) ) { if( isset($_SESSION[ 'mailall_sendid'.$row['PersonID'] ]) && $_SESSION[ 'mailall_sendid'.$row['PersonID'] ]=="done" ) { echoln("already done before"); }else { $srch=array(); $repl=array(); for($i=0; $i64 ) $repl[]="yes"; else $repl[]="no"; }else { //Other $repl[]=$row[ $_SESSION['mailall_fields'][$i] ]; } } $mail = new Mail($setup['MailReturnpath'], $row['Email']); $mail->setSubject(Mail::encodeHeader(utf8_decode(str_replace($srch, $repl, $Subject)))); $mail->addHeader("To", Mail::encodeHeader(utf8_decode($row['FirstName']." ".$row['LastName']))." <".$row['Email'].">"); $mail->addHeader("From", Mail::encodeHeader(utf8_decode($From))." <".($sendAsChair?$setup['MailChair']:$setup['EventApplFromEmail']).">"); $mail->addHeader("X-Content", "mailall to participant"); $mail->addHeader("X-ApplicationID", $row['PersonID']); $mail->addHeader("X-Signature", get_signature("mailall to participant", $row['PersonID'])); $mail->setMessage(str_replace($srch, $repl, $Message)); switch( $mail->send(true) ) { case Mail::MAIL_OK: $_SESSION[ 'mailall_sendid'.$row['PersonID'] ]="done"; echoln("send"); break; case Mail::MAIL_QUEUE: $_SESSION[ 'mailall_sendid'.$row['PersonID'] ]="done"; echoln("queued for later sending; smtp failure"); break; default: echoln("failed"); } } }else { echoln("error (no valid e-mail address available)"); } } echoln("

Finished

"); $_SESSION['mailall_domail'] = ""; }else { echoln("There are no participants to send a mail to in the current selection."); } } } } admin_footer(); ?>