From 6d83353fa74551fc2f03a1c669d03d25faa80014 Mon Sep 17 00:00:00 2001 From: Tim Wahrendorff Date: Tue, 24 Mar 2009 14:51:46 +0000 Subject: [PATCH] Added Feature: sSendEmail. You are able to send invitations, reminders and custom messenges with lsrc, to participants of a specific survey. Updated Feature: the .csv Files have been changed slightly. git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey181@6582 b72ed6b6-b9f8-46b5-92b4-906544132732 --- admin/remotecontrol/lsrc.config.php | 7 +- admin/remotecontrol/lsrc.helper.php | 342 +++++++++++++++++++--- admin/remotecontrol/lsrc.server.php | 71 ++++- admin/remotecontrol/lsrc.testclient.php | 4 +- admin/remotecontrol/lsrc_orig.wsdl | 6 +- admin/remotecontrol/surveys/Exkursion.csv | 2 +- admin/remotecontrol/surveys/Seminar.csv | 2 +- admin/remotecontrol/surveys/Uebung.csv | 2 +- admin/remotecontrol/surveys/Vorlesung.csv | 2 +- 9 files changed, 378 insertions(+), 60 deletions(-) diff --git a/admin/remotecontrol/lsrc.config.php b/admin/remotecontrol/lsrc.config.php index 7d2cbd496a2..75c06273d71 100644 --- a/admin/remotecontrol/lsrc.config.php +++ b/admin/remotecontrol/lsrc.config.php @@ -55,18 +55,13 @@ ### Variables -// Since this variable isn't per default in Limesurveys config.php any more, we need to set it ourselfs -//(the setting in LS config-defaults.php is not working for lsrc... no idea why) -// set the LS installation Dir relative to document root -//$relativeurl = "/limesource/limesurvey"; //default: "/limesurvey" //TODO: delete if no errors occure while commented - // path to the wsdl definition for this server... normally it is in the same directory, so you don't need to change it. $wsdl= $homedir."/remotecontrol/lsrc.wsdl"; //default: $homedir."/lsrc/lsrc.wsdl"; /** * These are the Dirs where the prepared survey csv's are or have to be. * one for the core surveys, - * one for addable modules, + * one for addable groups, * one for addable questions */ $coreDir = "./surveys/"; diff --git a/admin/remotecontrol/lsrc.helper.php b/admin/remotecontrol/lsrc.helper.php index 20445c3bc9a..9c593127507 100644 --- a/admin/remotecontrol/lsrc.helper.php +++ b/admin/remotecontrol/lsrc.helper.php @@ -106,15 +106,19 @@ function changeTable($table, $key, $value, $where, $mode='0')//XXX /* * Function to send Emails to participants of a specific survey */ - function emailSender($surveyid, $type, $maxemails='') //XXX + function emailSender($surveyid, $type, $maxLsrcEmails='') //XXX { - global $connect ; + global $connect,$sitename ; global $dbprefix ; include("lsrc.config.php"); include("../../classes/core/html_entity_decode_php4.php"); $lsrcHelper= new LsrcHelper(); + // wenn maxmails ber den lsrc gegeben wird das nurtzen, ansonsten die default werte aus der config.php + if($maxLsrcEmails!='') + $maxemails = $maxLsrcEmails; + switch ($type){ case "custom": @@ -281,54 +285,25 @@ function emailSender($surveyid, $type, $maxemails='') //XXX if($n==1) $failedAddresses .= ",".$to; else - $failedAddresses = $to; - - if ($debug>0) { - //$tokenoutput .= "
Subject : $modsubject

".htmlspecialchars($maildebugbody)."
"; - } - $n=1; + $failedAddresses = $to; + $n=1; + } } } $lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite "); if ($ctcount > $emcount) { $lefttosend = $ctcount-$maxemails; - //$tokenoutput .= "\t\t\n" - //."\t\n" - //."\t\n" - //."\t\t".$clang->gT("Warning")."
\n" - //."\t\t\t
" - //.$clang->gT("There are more emails pending than can be sent in one batch. Continue sending emails by clicking below.")."

\n"; - //$tokenoutput .= str_replace("{EMAILCOUNT}", "$lefttosend", $clang->gT("There are {EMAILCOUNT} emails still to be sent.")); - //$tokenoutput .= "

\n"; - //$tokenoutput .= "\t\t\t\n" - //."\t\t\t\n" - //."\t\t\t\n" - //."\t\t\t\n" - //."\t\t\t\n"; - foreach ($surveylangs as $language) - { - $message = html_escape($_POST['message_'.$language]); - $subject = html_escape($_POST['subject_'.$language]); - //$tokenoutput .="\t\t\t\n" - //."\t\t\t\n" - //."\t\t\t\n"; - } - //$tokenoutput .="\t\t\t
\n"; + }else{$lefttosend = 0;} } else - { - //$tokenoutput .= "
".$clang->gT("Warning")."
\n".$clang->gT("There were no eligible emails to send. This will be because none satisfied the criteria of - having an email address, not having been sent an invitation already, having already completed the survey and having a token.")."
\n"; - } - //$tokenoutput .= "\t\t\n"; - if($emcount==0) { return "No Mails to send"; - - } - if($maxemails>0) + } + + if($maxemails>0 && $maxemails!='') { $returnValue = "".$mailsSend." Mails send. ".$lefttosend." Mails left to send"; if(isset($failedAddresses)) @@ -349,11 +324,300 @@ function emailSender($surveyid, $type, $maxemails='') //XXX break; case "remind": + // XXX: + // TODO: +// if (!isset($_POST['ok']) || !$_POST['ok']) +// { + + /* + * look if there were reminders send in the past, and if some tokens got lesser reminders than others + * + * - if so: send reminders to the unremindet participants until they got the same remindcount than the others + * - if not: send reminders normally + */ + + $remSQL = "SELECT tid, remindercount " + . "FROM ".db_table_name("tokens_{$surveyid}")." " + . "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' " + . "ORDER BY remindercount desc LIMIT 1"; + $remResult = db_execute_assoc($remSQL); + $remRow = $remResult->FetchRow(); + + $lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$remRow['tid']."; ".$remRow['remindercount']." "); + + $sendOnlySQL = "SELECT tid, remindercount " + . "FROM ".db_table_name("tokens_{$surveyid}")." " + . "WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' AND remindercount < ".$remRow['remindercount']." " + . "ORDER BY tid asc LIMIT 1"; + $sendOnlyResult = db_execute_assoc($sendOnlySQL); + + + + if($sendOnlyResult->RecordCount()>0) + { + $sendOnlyRow = $sendOnlyResult->FetchRow(); + $starttokenid = $sendOnlyRow['tid']; + $lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", remind ".$sendOnlyRow['tid']."; ".$sendOnlyRow['remindercount']." "); + } + + if(isset($surveyid) && getEmailFormat($surveyid) == 'html') + { + $ishtml=true; + } + else + { + $ishtml=false; + } + + //GET SURVEY DETAILS + $thissurvey=getSurveyInfo($surveyid); + + $lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", $surveyid, $type"); + // Texte für Mails aus der Datenbank holen. + + $sql = "SELECT surveyls_language, surveyls_email_remind_subj, surveyls_email_remind ". + "FROM {$dbprefix}surveys_languagesettings ". + "WHERE surveyls_survey_id = ".$surveyid." "; + + $lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", invite "); + + $sqlResult = db_execute_assoc($sql); + + while($languageRow = $sqlResult->FetchRow()) + { + $_POST['message_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_remind']; + $_POST['subject_'.$languageRow['surveyls_language']] = $languageRow['surveyls_email_remind_subj']; + } + + + //$tokenoutput .= $clang->gT("Sending Reminders")."
\n"; + + $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid); + $baselanguage = GetBaseLanguageFromSurveyID($surveyid); + array_unshift($surveylangs,$baselanguage); + + foreach ($surveylangs as $language) + { + $_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]); + $_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]); + + } + +// if (isset($starttokenid)) {$tokenoutput .= " (".$clang->gT("From Token ID").": {$starttokenid})";} +// if (isset($tokenid)) {$tokenoutput .= " (".$clang->gT("Sending to Token ID").": {$tokenid})";} +// if (isset($_POST['bypassbademails']) && $_POST['bypassbademails'] == 'Y') +// { + $SQLemailstatuscondition = " AND emailstatus = 'OK'"; +// } +// else +// { +// $SQLemailstatuscondition = ""; +// } + if (isset($_POST['maxremindercount']) && + $_POST['maxremindercount'] != '' && + intval($_POST['maxremindercount']) != 0) + { + $SQLremindercountcondition = " AND remindercount < ".intval($_POST['maxremindercount']); + } + else + { + $SQLremindercountcondition = ""; + } + + if (isset($_POST['minreminderdelay']) && + $_POST['minreminderdelay'] != '' && + intval($_POST['minreminderdelay']) != 0) + { + // $_POST['minreminderdelay'] in days (86400 seconds per day) + $compareddate = date_shift( + date("Y-m-d H:i:s",time() - 86400 * intval($_POST['minreminderdelay'])), + "Y-m-d H:i", + $timeadjust); + $SQLreminderdelaycondition = " AND ( " + . " (remindersent = 'N' AND sent < '".$compareddate."') " + . " OR " + . " (remindersent < '".$compareddate."'))"; + } + else + { + $SQLreminderdelaycondition = ""; + } + + $ctquery = "SELECT * FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed ='N' or completed ='') AND sent<>'' AND sent<>'N' AND token <>'' AND email <> '' $SQLemailstatuscondition $SQLremindercountcondition $SQLreminderdelaycondition"; + + if (isset($starttokenid)) {$ctquery .= " AND tid >= '{$starttokenid}'";} +// if (isset($tokenid) && $tokenid) {$ctquery .= " AND tid = '{$tokenid}'";} +// //$tokenoutput .= "\n"; + + $ctresult = $connect->Execute($ctquery) or safe_die ("Database error!
\n" . $connect->ErrorMsg()); + $ctcount = $ctresult->RecordCount(); + $ctfieldcount = $ctresult->FieldCount(); + $emquery = "SELECT firstname, lastname, email, token, tid, language "; + if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";} + + // TLR change to put date into sent + $emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent <>'' AND token <>'' AND EMAIL <>'' $SQLemailstatuscondition $SQLremindercountcondition $SQLreminderdelaycondition"; + + if (isset($starttokenid)) {$emquery .= " AND tid >= '{$starttokenid}'";} + if (isset($tokenid) && $tokenid) {$emquery .= " AND tid = '{$tokenid}'";} + $emquery .= " ORDER BY tid "; + $emresult = db_select_limit_assoc($emquery, $maxemails); + //$emresult = db_execute_assoc($emquery); + $emcount = $emresult->RecordCount(); +// $tokenoutput .= "\n" +// ."\t\n" +// ."\t\t\n" +// ."\t\n" +// ."\t" +// ."\t\t\n" +// ."\t\n" +// ."\t\n" +// ."\t\n" +// ."\t\n"; +// foreach ($surveylangs as $language) +// { +// $message = html_escape($_POST['message_'.$language]); +//// $tokenoutput .="\t\t\t\n" +//// ."\t\t\t\n" +//// ."\t\t\t\n"; +// } +// $tokenoutput.="\t\n" +// ."\t\n"; + }else{$lefttosend = 0;} + } +// else +// { +//// $tokenoutput .= "
".$clang->gT("Warning")."
\n" +//// .$clang->gT("There were no eligible emails to send. This will be because none satisfied the criteria of - having an email address, having been sent an invitation, but not having yet completed the survey.")."\n" +//// ."

\n" +//// ."\t\t\n"; +// } + + if($emcount==0) + { + return "No Reminders to send"; + } + if($maxemails>0) + { + $returnValue = "".$mailsSend." Reminders send. ".$lefttosend." Reminders left to send"; + if(isset($failedAddresses)) + $returnValue .= "\nCould not send to: ".$failedAddresses; + return $returnValue; + } + + if(isset($mailsSend)) + { + $returnValue = "".$mailsSend." Reminders send. "; + if(isset($failedAddresses)) + $returnValue .= "\nCould not send to: ".$failedAddresses; + return $returnValue; + } + + break; default: - + break; } } diff --git a/admin/remotecontrol/lsrc.server.php b/admin/remotecontrol/lsrc.server.php index 0239f734eaf..d1187ae6fd2 100644 --- a/admin/remotecontrol/lsrc.server.php +++ b/admin/remotecontrol/lsrc.server.php @@ -105,12 +105,17 @@ function sChangeSurvey($sUser, $sPass, $table, $key, $value, $where, $mode='0') * $emailText = Text of custom mails * */ -function sSendEmail($sUser, $sPass, $iVid, $type, $maxemails='', $subject='', $emailText='') +function sSendEmail($sUser, $sPass, $iVid, $type, $maxLsrcEmails='', $subject='', $emailText='') { + global $sitename, $siteadminemail; include("lsrc.config.php"); $lsrcHelper = new lsrcHelper(); $lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", START OK "); + // wenn maxmails ber den lsrc gegeben wird das nurtzen, ansonsten die default werte aus der config.php + if($maxLsrcEmails!='') + $maxemails = $maxLsrcEmails; + if(!$lsrcHelper->checkUser($sUser, $sPass)) { throw new SoapFault("Authentication: ", "User or password wrong"); @@ -126,21 +131,75 @@ function sSendEmail($sUser, $sPass, $iVid, $type, $maxemails='', $subject='', $e if($type=='custom' && $subject!='' && $emailText!='') { + //GET SURVEY DETAILS not working here... don't know why... + //$thissurvey=getSurveyInfo($iVid); + $from = $siteadminemail; + + $lsrcHelper->debugLsrc("wir sind in ".__FUNCTION__." Line ".__LINE__.", Admin Email: $from ; survey: $iVid ; dump: ".print_r($thissurvey).""); $emquery = "SELECT firstname, lastname, email, token, tid, language"; - if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";} + //if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";} - $emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND token !='' AND email != '' $SQLemailstatuscondition"; + $emquery .= " FROM ".db_table_name("tokens_{$iVid}")." WHERE email != '' "; if (isset($tokenid)) {$emquery .= " and tid='{$tokenid}'";} $tokenoutput .= "\n\n\n\n"; $emresult = db_select_limit_assoc($emquery,$maxemails); + $emcount = $emresult->RecordCount(); - MailTextMessage(); + if ($emcount > 0) + { + $mailsSend = 0; + while ($emrow = $emresult->FetchRow()) + { + if (MailTextMessage($emailText, $subject, $emrow['email'] , $from, $sitename, $ishtml=false, getBounceEmail($iVid))) + { + $mailsSend++; + } + else + { + //$tokenoutput .= ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."
", $fieldsarray); + if($n==1) + $failedAddresses .= ",".$to; + else + { + $failedAddresses = $to; + $n=1; + } + + } + } + + } + else + { + return "No Mails to send"; + } +// if ($ctcount > $emcount) +// { +// $lefttosend = $ctcount-$maxemails; +// +// }else{$lefttosend = 0;} + +// if($maxemails>0) +// { +// $returnValue = "".$mailsSend." Mails send. ".$lefttosend." Mails left to send"; +// if(isset($failedAddresses)) +// $returnValue .= "\nCould not send to: ".$failedAddresses; +// return $returnValue; +// } + + if(isset($mailsSend)) + { + $returnValue = "".$mailsSend." Mails send. "; + if(isset($failedAddresses)) + $returnValue .= "\nCould not send to: ".$failedAddresses; + return $returnValue; + } } if($type=='invite' || $type=='remind') { - $emailSenderReturn = $lsrcHelper->emailSender($iVid, $type, $maxemails); + $emailSenderReturn = $lsrcHelper->emailSender($iVid, $type, $maxLsrcEmails); return $emailSenderReturn; // if($maxemails != '') @@ -801,7 +860,7 @@ function sImportMatrix($sUser, $sPass, $iVid, $qText, $qHelp, $sItems, $sMod='Ma * or if the question should be added to the last group in survey */ $newGroup=0; - + global $connect ; global $dbprefix ; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; diff --git a/admin/remotecontrol/lsrc.testclient.php b/admin/remotecontrol/lsrc.testclient.php index b6f67e523dd..038cd66a117 100644 --- a/admin/remotecontrol/lsrc.testclient.php +++ b/admin/remotecontrol/lsrc.testclient.php @@ -253,7 +253,7 @@ function soapCheck ($path2wsdl) try { - $sReturn = $client->sImportMatrix($user, $pass, $iVid, $qText, $qHelp, $items, "Matrix5", $mandatory,0); + $sReturn = $client->sImportMatrix($user, $pass, $iVid, $qText, $qHelp, $items, "Matrix5", $mandatory); } catch (SoapFault $fault) { @@ -275,7 +275,7 @@ function soapCheck ($path2wsdl) try { - $sReturn = $client->sImportFreetext($user, $pass, $iVid, $qTitle, $qText, $qHelp, "Freitext", $mandatory,0); + $sReturn = $client->sImportFreetext($user, $pass, $iVid, $qTitle, $qText, $qHelp, "Freitext", $mandatory); } catch (SoapFault $fault) { diff --git a/admin/remotecontrol/lsrc_orig.wsdl b/admin/remotecontrol/lsrc_orig.wsdl index c36cb7e0dd2..76ed1df67a6 100644 --- a/admin/remotecontrol/lsrc_orig.wsdl +++ b/admin/remotecontrol/lsrc_orig.wsdl @@ -232,12 +232,12 @@ - - + - + + diff --git a/admin/remotecontrol/surveys/Exkursion.csv b/admin/remotecontrol/surveys/Exkursion.csv index a0888e940b2..8659f7725dc 100644 --- a/admin/remotecontrol/surveys/Exkursion.csv +++ b/admin/remotecontrol/surveys/Exkursion.csv @@ -8,7 +8,7 @@ # SURVEYS TABLE # "sid","owner_id","admin","active","startdate","expires","adminemail","private","faxto","format","template","url","language","additional_languages","datestamp","usecookie","notification","allowregister","attribute1","attribute2","allowsave","printanswers","autonumber_start","autoredirect","allowprev","ipaddr","useexpiry","usestartdate","refurl","datecreated","listpublic","htmlemail","tokenanswerspersistence","usecaptcha","bounce_email" -"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","default","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" +"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","hisinone","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" # # GROUPS TABLE diff --git a/admin/remotecontrol/surveys/Seminar.csv b/admin/remotecontrol/surveys/Seminar.csv index a0888e940b2..8659f7725dc 100644 --- a/admin/remotecontrol/surveys/Seminar.csv +++ b/admin/remotecontrol/surveys/Seminar.csv @@ -8,7 +8,7 @@ # SURVEYS TABLE # "sid","owner_id","admin","active","startdate","expires","adminemail","private","faxto","format","template","url","language","additional_languages","datestamp","usecookie","notification","allowregister","attribute1","attribute2","allowsave","printanswers","autonumber_start","autoredirect","allowprev","ipaddr","useexpiry","usestartdate","refurl","datecreated","listpublic","htmlemail","tokenanswerspersistence","usecaptcha","bounce_email" -"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","default","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" +"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","hisinone","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" # # GROUPS TABLE diff --git a/admin/remotecontrol/surveys/Uebung.csv b/admin/remotecontrol/surveys/Uebung.csv index a0888e940b2..8659f7725dc 100644 --- a/admin/remotecontrol/surveys/Uebung.csv +++ b/admin/remotecontrol/surveys/Uebung.csv @@ -8,7 +8,7 @@ # SURVEYS TABLE # "sid","owner_id","admin","active","startdate","expires","adminemail","private","faxto","format","template","url","language","additional_languages","datestamp","usecookie","notification","allowregister","attribute1","attribute2","allowsave","printanswers","autonumber_start","autoredirect","allowprev","ipaddr","useexpiry","usestartdate","refurl","datecreated","listpublic","htmlemail","tokenanswerspersistence","usecaptcha","bounce_email" -"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","default","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" +"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","hisinone","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" # # GROUPS TABLE diff --git a/admin/remotecontrol/surveys/Vorlesung.csv b/admin/remotecontrol/surveys/Vorlesung.csv index a0888e940b2..8659f7725dc 100644 --- a/admin/remotecontrol/surveys/Vorlesung.csv +++ b/admin/remotecontrol/surveys/Vorlesung.csv @@ -8,7 +8,7 @@ # SURVEYS TABLE # "sid","owner_id","admin","active","startdate","expires","adminemail","private","faxto","format","template","url","language","additional_languages","datestamp","usecookie","notification","allowregister","attribute1","attribute2","allowsave","printanswers","autonumber_start","autoredirect","allowprev","ipaddr","useexpiry","usestartdate","refurl","datecreated","listpublic","htmlemail","tokenanswerspersistence","usecaptcha","bounce_email" -"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","default","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" +"35732","1","Tim Wahrendorff","N","2008-12-04","2008-12-04","wahrendorff@his.de","Y","","G","hisinone","www.his.de","de","","N","N","0","N","","","N","N","0","N","Y","N","N","N","N","2008-12-04","N","Y","N","D","wahrendorff@his.de" # # GROUPS TABLE
\n"; + + + + if ($emcount > 0) + { + while ($emrow = $emresult->FetchRow()) + { + unset($fieldsarray); + $to = $emrow['email']; + $fieldsarray["{EMAIL}"]=$emrow['email']; + $fieldsarray["{FIRSTNAME}"]=$emrow['firstname']; + $fieldsarray["{LASTNAME}"]=$emrow['lastname']; + $fieldsarray["{TOKEN}"]=$emrow['token']; + $fieldsarray["{LANGUAGE}"]=$emrow['language']; + $fieldsarray["{ATTRIBUTE_1}"]=$emrow['attribute_1']; + $fieldsarray["{ATTRIBUTE_2}"]=$emrow['attribute_2']; + + $emrow['language']=trim($emrow['language']); + if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default + if(!in_array($emrow['language'], $surveylangs)) {$emrow['language']=$baselanguage;} // if given language is not available use default + $found = array_search($emrow['language'], $surveylangs); + if ($found==false) {$emrow['language']=$baselanguage;} + + $from = $_POST['from_'.$emrow['language']]; + + if (getEmailFormat($surveyid) == 'html') + { + $ishtml=true; + } + else + { + $ishtml=false; + } + + if ($ishtml == false) + { + if ( $modrewrite ) + { + $fieldsarray["{SURVEYURL}"]="$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}"; + } + else + { + $fieldsarray["{SURVEYURL}"]="$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}"; + } + } + else + { + if ( $modrewrite ) + { + $fieldsarray["{SURVEYURL}"]="".htmlspecialchars("$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}").""; + } + else + { + $fieldsarray["{SURVEYURL}"]="".htmlspecialchars("$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}").""; + $_POST['message_'.$emrow['language']] = html_entity_decode_php4($_POST['message_'.$emrow['language']], ENT_QUOTES, $emailcharset); + } + } + + $msgsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray); + $sendmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray); + + if (MailTextMessage($sendmessage, $msgsubject, $to, $from, $sitename, $ishtml, getBounceEmail($surveyid))) + { + + // Put date into remindersent + $today = date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i", $timeadjust); + $udequery = "UPDATE ".db_table_name("tokens_{$surveyid}")."\n" + ."SET remindersent='$today',remindercount = remindercount+1 WHERE tid={$emrow['tid']}"; + // + $uderesult = $connect->Execute($udequery); // or safe_die ("Could not update tokens
$udequery
".$connect->ErrorMsg()); + //orig: $tokenoutput .= "\t\t\t({$emrow['tid']})[".$clang->gT("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']}]
\n"; + //$tokenoutput .= "\t\t\t({$emrow['tid']}) [".$clang->gT("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']} ($to)]
\n"; + $mailsSend++; + } + else + { + //$tokenoutput .= ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."
", $fieldsarray); + if($n==1) + $failedAddresses .= ",".$to; + else + { + $failedAddresses = $to; + $n=1; + } + + } + //$lasttid = $emrow['tid']; + + } + if ($ctcount > $emcount) + { + $lefttosend = $ctcount-$maxemails; +// $tokenoutput .= "\t\t
\n" +// ."\t\t\t".$clang->gT("Warning")."

\n" +// .$clang->gT("There are more emails pending than can be sent in one batch. Continue sending emails by clicking below.")."

\n" +// .str_replace("{EMAILCOUNT}", $lefttosend, $clang->gT("There are {EMAILCOUNT} emails still to be sent.")) +// ."
\n" +// ."\t\t\t\n" +// ."\t\t