本文整理汇总了PHP中ReplaceFields函数的典型用法代码示例。如果您正苦于以下问题:PHP ReplaceFields函数的具体用法?PHP ReplaceFields怎么用?PHP ReplaceFields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReplaceFields函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
//.........这里部分代码省略.........
}
while ($mayinsert != true) {
$newtoken = randomChars($tokenlength);
$ntquery = "SELECT * FROM {{tokens_{$surveyid}}} WHERE token='{$newtoken}'";
$usrow = Yii::app()->db->createCommand($ntquery)->queryRow();
if (!$usrow) {
$mayinsert = true;
}
}
$postfirstname = sanitize_xss_string(strip_tags(Yii::app()->request->getPost('register_firstname')));
$postlastname = sanitize_xss_string(strip_tags(Yii::app()->request->getPost('register_lastname')));
$starttime = sanitize_xss_string(Yii::app()->request->getPost('startdate'));
$endtime = sanitize_xss_string(Yii::app()->request->getPost('enddate'));
/*$postattribute1=sanitize_xss_string(strip_tags(returnGlobal('register_attribute1')));
$postattribute2=sanitize_xss_string(strip_tags(returnGlobal('register_attribute2'))); */
// Insert new entry into tokens db
Tokens_dynamic::sid($thissurvey['sid']);
$token = new Tokens_dynamic();
$token->firstname = $postfirstname;
$token->lastname = $postlastname;
$token->email = Yii::app()->request->getPost('register_email');
$token->emailstatus = 'OK';
$token->token = $newtoken;
if ($starttime && $endtime) {
$token->validfrom = $starttime;
$token->validuntil = $endtime;
}
foreach ($attributeinsertdata as $k => $v) {
$token->{$k} = $v;
}
$result = $token->save();
/**
$result = $connect->Execute($query, array($postfirstname,
$postlastname,
returnGlobal('register_email'),
'OK',
$newtoken)
// $postattribute1, $postattribute2)
) or safeDie ($query."<br />".$connect->ErrorMsg()); //Checked - According to adodb docs the bound variables are quoted automatically
*/
$tid = getLastInsertID($token->tableName());
$fieldsarray["{ADMINNAME}"] = $thissurvey['adminname'];
$fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail'];
$fieldsarray["{SURVEYNAME}"] = $thissurvey['name'];
$fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description'];
$fieldsarray["{FIRSTNAME}"] = $postfirstname;
$fieldsarray["{LASTNAME}"] = $postlastname;
$fieldsarray["{EXPIRY}"] = $thissurvey["expiry"];
$message = $thissurvey['email_register'];
$subject = $thissurvey['email_register_subj'];
$from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
if (getEmailFormat($surveyid) == 'html') {
$useHtmlEmail = true;
$surveylink = $this->createAbsoluteUrl($surveyid . '/lang-' . $baselang . '/tk-' . $newtoken);
$optoutlink = $this->createAbsoluteUrl('optout/local/' . $surveyid . '/' . $baselang . '/' . $newtoken);
$optinlink = $this->createAbsoluteUrl('optin/local/' . $surveyid . '/' . $baselang . '/' . $newtoken);
$fieldsarray["{SURVEYURL}"] = "<a href='{$surveylink}'>" . $surveylink . "</a>";
$fieldsarray["{OPTOUTURL}"] = "<a href='{$optoutlink}'>" . $optoutlink . "</a>";
$fieldsarray["{OPTINURL}"] = "<a href='{$optinlink}'>" . $optinlink . "</a>";
} else {
$useHtmlEmail = false;
$fieldsarray["{SURVEYURL}"] = $this->createAbsoluteUrl('' . $surveyid . '/lang-' . $baselang . '/tk-' . $newtoken);
$fieldsarray["{OPTOUTURL}"] = $this->createAbsoluteUrl('optout/local/' . $surveyid . '/' . $baselang . '/' . $newtoken);
$fieldsarray["{OPTINURL}"] = $this->createAbsoluteUrl('optin/local/' . $surveyid . '/' . $baselang . '/' . $newtoken);
}
$message = ReplaceFields($message, $fieldsarray);
$subject = ReplaceFields($subject, $fieldsarray);
$html = "";
//Set variable
$sitename = Yii::app()->getConfig('sitename');
if (SendEmailMessage($message, $subject, Yii::app()->request->getPost('register_email'), $from, $sitename, $useHtmlEmail, getBounceEmail($surveyid))) {
// TLR change to put date into sent
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$query = "UPDATE {{tokens_{$surveyid}}}\n" . "SET sent='{$today}' WHERE tid={$tid}";
$result = dbExecuteAssoc($query) or show_error("Unable to execute this query : {$query}<br />");
//Checked
$html = "<center>" . $clang->gT("Thank you for registering to participate in this survey.") . "<br /><br />\n" . $clang->gT("An email has been sent to the address you provided with access details for this survey. Please follow the link in that email to proceed.") . "<br /><br />\n" . $clang->gT("Survey administrator") . " {ADMINNAME} ({ADMINEMAIL})";
$html = ReplaceFields($html, $fieldsarray);
$html .= "<br /><br /></center>\n";
} else {
$html = "Email Error";
}
//PRINT COMPLETED PAGE
if (!$thissurvey['template']) {
$thistpl = getTemplatePath(validateTemplateDir('default'));
} else {
$thistpl = getTemplatePath(validateTemplateDir($thissurvey['template']));
}
sendCacheHeaders();
doHeader();
Yii::app()->lang = $clang;
// fetch the defined variables and pass it to the header footer templates.
$redata = compact(array_keys(get_defined_vars()));
$this->_printTemplateContent($thistpl . '/startpage.pstpl', $redata, __LINE__);
$this->_printTemplateContent($thistpl . '/survey.pstpl', $redata, __LINE__);
echo $html;
$this->_printTemplateContent($thistpl . '/endpage.pstpl', $redata, __LINE__);
doFooter();
}
示例2: email
//.........这里部分代码省略.........
$fieldsarray["{TOKEN}"] = $emrow['token'];
$fieldsarray["{LANGUAGE}"] = $emrow['language'];
foreach ($attributes as $attributefield) {
$fieldsarray['{' . strtoupper($attributefield) . '}'] = $emrow[$attributefield];
$fieldsarray['{TOKEN:' . strtoupper($attributefield) . '}'] = $emrow[$attributefield];
}
$emrow['language'] = trim($emrow['language']);
$found = array_search($emrow['language'], $aSurveyLangs);
if ($emrow['language'] == '' || $found == false) {
$emrow['language'] = $sBaseLanguage;
}
$from = Yii::app()->request->getPost('from_' . $emrow['language']);
$fieldsarray["{OPTOUTURL}"] = $this->getController()->createAbsoluteUrl("/optout/tokens/langcode/" . trim($emrow['language']) . "/surveyid/{$iSurveyId}/token/{$emrow['token']}");
$fieldsarray["{OPTINURL}"] = $this->getController()->createAbsoluteUrl("/optin/tokens/langcode/" . trim($emrow['language']) . "/surveyid/{$iSurveyId}/token/{$emrow['token']}");
$fieldsarray["{SURVEYURL}"] = $this->getController()->createAbsoluteUrl("/survey/index/sid/{$iSurveyId}/token/{$emrow['token']}/lang/" . trim($emrow['language']) . "/");
foreach (array('OPTOUT', 'OPTIN', 'SURVEY') as $key) {
$url = $fieldsarray["{{$key}URL}"];
if ($bHtml) {
$fieldsarray["{{$key}URL}"] = "<a href='{$url}'>" . htmlspecialchars($url) . '</a>';
}
if ($key == 'SURVEY') {
$barebone_link = $url;
}
}
$customheaders = array('1' => "X-surveyid: " . $iSurveyId, '2' => "X-tokenid: " . $fieldsarray["{TOKEN}"]);
global $maildebug;
$modsubject = Replacefields($sSubject[$emrow['language']], $fieldsarray);
$modmessage = Replacefields($sMessage[$emrow['language']], $fieldsarray);
if (isset($barebone_link)) {
$modsubject = str_replace("@@SURVEYURL@@", $barebone_link, $modsubject);
$modmessage = str_replace("@@SURVEYURL@@", $barebone_link, $modmessage);
}
if (trim($emrow['validfrom']) != '' && convertDateTimeFormat($emrow['validfrom'], 'Y-m-d H:i:s', 'U') * 1 > date('U') * 1) {
$tokenoutput .= $emrow['tid'] . " " . ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) delayed: Token is not yet valid.") . "<br />", $fieldsarray);
} elseif (trim($emrow['validuntil']) != '' && convertDateTimeFormat($emrow['validuntil'], 'Y-m-d H:i:s', 'U') * 1 < date('U') * 1) {
$tokenoutput .= $emrow['tid'] . " " . ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) skipped: Token is not valid anymore.") . "<br />", $fieldsarray);
} else {
/*
* Get attachments.
*/
if ($sSubAction == 'email') {
$sTemplate = 'invitation';
} elseif ($sSubAction == 'remind') {
$sTemplate = 'reminder';
}
$aRelevantAttachments = array();
if (isset($aData['thissurvey'][$emrow['language']]['attachments'])) {
$aAttachments = unserialize($aData['thissurvey'][$emrow['language']]['attachments']);
if (!empty($aAttachments)) {
if (isset($aAttachments[$sTemplate])) {
LimeExpressionManager::singleton()->loadTokenInformation($aData['thissurvey']['sid'], $emrow['token']);
foreach ($aAttachments[$sTemplate] as $aAttachment) {
if (LimeExpressionManager::singleton()->ProcessRelevance($aAttachment['relevance'])) {
$aRelevantAttachments[] = $aAttachment['url'];
}
}
}
}
}
/**
* Event for email handling.
* Parameter type description:
* subject rw Body of the email
* to rw Recipient(s)
* from rw Sender(s)
* type r "invitation" or "reminder"
示例3: sendSubmitNotifications
/**
* Send a submit notification to the email address specified in the notifications tab in the survey settings
*/
function sendSubmitNotifications($surveyid)
{
// @todo: Remove globals
global $thissurvey, $maildebug, $tokensexist;
if (trim($thissurvey['adminemail']) == '') {
return;
}
$homeurl = Yii::app()->createAbsoluteUrl('/admin');
$clang = Yii::app()->lang;
$sitename = Yii::app()->getConfig("sitename");
$debug = Yii::app()->getConfig('debug');
$bIsHTML = $thissurvey['htmlemail'] == 'Y';
$aReplacementVars = array();
if ($thissurvey['allowsave'] == "Y" && isset($_SESSION['survey_' . $surveyid]['scid'])) {
$aReplacementVars['RELOADURL'] = "" . Yii::app()->getController()->createUrl("/survey/index/sid/{$surveyid}/loadall/reload/scid/" . $_SESSION['survey_' . $surveyid]['scid'] . "/loadname/" . urlencode($_SESSION['survey_' . $surveyid]['holdname']) . "/loadpass/" . urlencode($_SESSION['survey_' . $surveyid]['holdpass']) . "/lang/" . urlencode($clang->langcode));
if ($bIsHTML) {
$aReplacementVars['RELOADURL'] = "<a href='{$aReplacementVars['RELOADURL']}'>{$aReplacementVars['RELOADURL']}</a>";
}
} else {
$aReplacementVars['RELOADURL'] = '';
}
if (!isset($_SESSION['survey_' . $surveyid]['srid'])) {
$srid = null;
} else {
$srid = $_SESSION['survey_' . $surveyid]['srid'];
}
$aReplacementVars['ADMINNAME'] = $thissurvey['adminname'];
$aReplacementVars['ADMINEMAIL'] = $thissurvey['adminemail'];
$aReplacementVars['VIEWRESPONSEURL'] = Yii::app()->createAbsoluteUrl("/admin/responses/sa/view/surveyid/{$surveyid}/id/{$srid}");
$aReplacementVars['EDITRESPONSEURL'] = Yii::app()->createAbsoluteUrl("/admin/dataentry/sa/editdata/subaction/edit/surveyid/{$surveyid}/id/{$srid}");
$aReplacementVars['STATISTICSURL'] = Yii::app()->createAbsoluteUrl("/admin/statistics/sa/index/surveyid/{$surveyid}");
if ($bIsHTML) {
$aReplacementVars['VIEWRESPONSEURL'] = "<a href='{$aReplacementVars['VIEWRESPONSEURL']}'>{$aReplacementVars['VIEWRESPONSEURL']}</a>";
$aReplacementVars['EDITRESPONSEURL'] = "<a href='{$aReplacementVars['EDITRESPONSEURL']}'>{$aReplacementVars['EDITRESPONSEURL']}</a>";
$aReplacementVars['STATISTICSURL'] = "<a href='{$aReplacementVars['STATISTICSURL']}'>{$aReplacementVars['STATISTICSURL']}</a>";
}
$aReplacementVars['ANSWERTABLE'] = '';
$aEmailResponseTo = array();
$aEmailNotificationTo = array();
$sResponseData = "";
if (!empty($thissurvey['emailnotificationto'])) {
$aRecipient = explode(";", ReplaceFields($thissurvey['emailnotificationto'], array('ADMINEMAIL' => $thissurvey['adminemail']), true));
foreach ($aRecipient as $sRecipient) {
$sRecipient = trim($sRecipient);
if (validateEmailAddress($sRecipient)) {
$aEmailNotificationTo[] = $sRecipient;
}
}
}
if (!empty($thissurvey['emailresponseto'])) {
// there was no token used so lets remove the token field from insertarray
if (!isset($_SESSION['survey_' . $surveyid]['token']) && $_SESSION['survey_' . $surveyid]['insertarray'][0] == 'token') {
unset($_SESSION['survey_' . $surveyid]['insertarray'][0]);
}
//Make an array of email addresses to send to
$aRecipient = explode(";", ReplaceFields($thissurvey['emailresponseto'], array('ADMINEMAIL' => $thissurvey['adminemail']), true));
foreach ($aRecipient as $sRecipient) {
$sRecipient = trim($sRecipient);
if (validateEmailAddress($sRecipient)) {
$aEmailResponseTo[] = $sRecipient;
}
}
$aFullResponseTable = getFullResponseTable($surveyid, $_SESSION['survey_' . $surveyid]['srid'], $_SESSION['survey_' . $surveyid]['s_lang']);
$ResultTableHTML = "<table class='printouttable' >\n";
$ResultTableText = "\n\n";
$oldgid = 0;
$oldqid = 0;
foreach ($aFullResponseTable as $sFieldname => $fname) {
if (substr($sFieldname, 0, 4) == 'gid_') {
$ResultTableHTML .= "\t<tr class='printanswersgroup'><td colspan='2'>" . strip_tags($fname[0]) . "</td></tr>\n";
$ResultTableText .= "\n{$fname[0]}\n\n";
} elseif (substr($sFieldname, 0, 4) == 'qid_') {
$ResultTableHTML .= "\t<tr class='printanswersquestionhead'><td colspan='2'>" . strip_tags($fname[0]) . "</td></tr>\n";
$ResultTableText .= "\n{$fname[0]}\n";
} else {
$ResultTableHTML .= "\t<tr class='printanswersquestion'><td>" . strip_tags("{$fname[0]} {$fname[1]}") . "</td><td class='printanswersanswertext'>" . CHtml::encode($fname[2]) . "</td></tr>\n";
$ResultTableText .= " {$fname[0]} {$fname[1]}: {$fname[2]}\n";
}
}
$ResultTableHTML .= "</table>\n";
$ResultTableText .= "\n\n";
if ($bIsHTML) {
$aReplacementVars['ANSWERTABLE'] = $ResultTableHTML;
} else {
$aReplacementVars['ANSWERTABLE'] = $ResultTableText;
}
}
$sFrom = $thissurvey['adminname'] . ' <' . $thissurvey['adminemail'] . '>';
$aAttachments = unserialize($thissurvey['attachments']);
$aRelevantAttachments = array();
/*
* Iterate through attachments and check them for relevance.
*/
if (isset($aAttachments['admin_notification'])) {
foreach ($aAttachments['admin_notification'] as $aAttachment) {
$relevance = $aAttachment['relevance'];
// If the attachment is relevant it will be added to the mail.
//.........这里部分代码省略.........
示例4: elseif
}
elseif (SendEmailMessage($sendmessage, $msgsubject, $to, $from, $sitename,$ishtml,getBounceEmail($surveyid),null,$customheaders))
{
// 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<br />$udequery<br />".$connect->ErrorMsg());
//orig: $tokenoutput .= "({$emrow['tid']})[".$clang->gT("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']}]<br />\n";
$tokenoutput .= "({$emrow['tid']}) [".$clang->gT("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']} ($to)]<br />\n";
}
else
{
$tokenoutput .= $emrow['tid'] ." ".ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."<br />", $fieldsarray);
if ($debug>0)
{
$tokenoutput .= "<pre>Subject : $msgsubject<br /><br />".htmlspecialchars($maildebugbody)."<br /></pre>";
}
}
$lasttid = $emrow['tid'];
}
if ($ctcount > $emcount)
{
$lefttosend = $ctcount-$maxemails;
$tokenoutput .= "</td>\n"
."\t</tr>\n"
."\t<tr><form method='post' action='$scriptname?action=tokens&sid=$surveyid'>"
."<td align='center'>\n"
示例5: beforeSurveyPage
//.........这里部分代码省略.........
$aReplacementFields["{ADMINEMAIL}"]=$aSurveyInfo['adminemail'];
$aReplacementFields["{SURVEYNAME}"]=$aSurveyInfo['name'];
$aReplacementFields["{SURVEYDESCRIPTION}"]=$aSurveyInfo['description'];
$aReplacementFields["{EXPIRY}"]=$aSurveyInfo["expiry"];
$oToken=TokenDynamic::model($iSurveyId)->findByPk($iTokenId);
foreach($oToken->attributes as $attribute=>$value){
$aReplacementFields["{".strtoupper($attribute)."}"]=$value;
}
$sToken=$oToken->token;
$aMail['subject']=preg_replace("/{TOKEN:([A-Z0-9_]+)}/","{"."$1"."}",$aMail['subject']);
$aMail['message']=preg_replace("/{TOKEN:([A-Z0-9_]+)}/","{"."$1"."}",$aMail['message']);
$surveylink = App()->createAbsoluteUrl("/survey/index/sid/{$iSurveyId}",array('lang'=>$sLanguage,'token'=>$sToken));
$optoutlink = App()->createAbsoluteUrl("/optout/tokens/surveyid/{$iSurveyId}",array('langcode'=>$sLanguage,'token'=>$sToken));
$optinlink = App()->createAbsoluteUrl("/optin/tokens/surveyid/{$iSurveyId}",array('langcode'=>$sLanguage,'token'=>$sToken));
if (getEmailFormat($iSurveyId) == 'html')
{
$useHtmlEmail = true;
$aReplacementFields["{SURVEYURL}"]="<a href='$surveylink'>".$surveylink."</a>";
$aReplacementFields["{OPTOUTURL}"]="<a href='$optoutlink'>".$optoutlink."</a>";
$aReplacementFields["{OPTINURL}"]="<a href='$optinlink'>".$optinlink."</a>";
}
else
{
$useHtmlEmail = false;
$aReplacementFields["{SURVEYURL}"]= $surveylink;
$aReplacementFields["{OPTOUTURL}"]= $optoutlink;
$aReplacementFields["{OPTINURL}"]= $optinlink;
}
// Allow barebone link for all URL
$aMail['message'] = str_replace("@@SURVEYURL@@", $surveylink, $aMail['message']);
$aMail['message'] = str_replace("@@OPTOUTURL@@", $optoutlink, $aMail['message']);
$aMail['message'] = str_replace("@@OPTINURL@@", $optinlink, $aMail['message']);
// Replace the fields
$aMail['subject']=ReplaceFields($aMail['subject'], $aReplacementFields);
$aMail['message']=ReplaceFields($aMail['message'], $aReplacementFields);
// We have it, then try to send the mail.
$from = "{$aSurveyInfo['adminname']} <{$aSurveyInfo['adminemail']}>";
$sitename = Yii::app()->getConfig('sitename');
if (SendEmailMessage($aMail['message'], $aMail['subject'], $sR_email, $from, $sitename,$useHtmlEmail,getBounceEmail($iSurveyId)))
{
// TLR change to put date into sent
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$oToken->sent=$today;
$oToken->save();
$sReturnHtml="<div id='wrapper' class='message tokenmessage'>"
. "<p>".gT("Thank you for registering to participate in this survey.")."</p>\n"
. "<p>".$aMail['information']."</p>\n"
. "<p>".gT("Survey administrator")." {ADMINNAME} ({ADMINEMAIL})</p>"
. "</div>\n";
}
else
{
$sReturnHtml="<div id='wrapper' class='message tokenmessage'>"
. "<p>".gT("Thank you for registering to participate in this survey.")."</p>\n"
. "<p>"."We can not sent you an email actually, please contact the survey administrator"."</p>\n"
. "<p>".gT("Survey administrator")." {ADMINNAME} ({ADMINEMAIL})</p>"
. "</div>\n";
}
$sReturnHtml=ReplaceFields($sReturnHtml, $aReplacementFields);
$sTemplatePath=$aData['templatedir'] = getTemplatePath($aSurveyInfo['template']);
ob_start(function($buffer, $phase) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
示例6: date_shift
$message=ReplaceFields($message, $fieldsarray);
$subject=ReplaceFields($subject, $fieldsarray);
$html=""; //Set variable
if (SendEmailMessage($message, $subject, returnglobal('register_email'), $from, $sitename,$useHtmlEmail,getBounceEmail($surveyid)))
{
// TLR change to put date into sent
// $query = "UPDATE {$dbprefix}tokens_$surveyid\n"
// ."SET sent='Y' WHERE tid=$tid";
$today = date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i", $timeadjust);
$query = "UPDATE {$dbprefix}tokens_$surveyid\n"
."SET sent='$today' WHERE tid=$tid";
$result=$connect->Execute($query) or safe_die ("$query<br />".$connect->ErrorMsg()); //Checked
$html="<center>".$clang->gT("Thank you for registering to participate in this survey.")."<br /><br />\n".$clang->gT("An email has been sent to the address you provided with access details for this survey. Please follow the link in that email to proceed.")."<br /><br />\n".$clang->gT("Survey Administrator")." {ADMINNAME} ({ADMINEMAIL})";
$html=ReplaceFields($html, $fieldsarray);
$html .= "<br /><br /></center>\n";
}
else
{
$html="Email Error";
}
//PRINT COMPLETED PAGE
if (!$thissurvey['template'])
{
$thistpl=sGetTemplatePath(validate_templatedir('default'));
}
else
{
$thistpl=sGetTemplatePath(validate_templatedir($thissurvey['template']));
示例7: beforeSurveyPage
public function beforeSurveyPage() {
$oEvent = $this->event;
$iSurveyId = $oEvent->get('surveyId');
$bUse = $this->get('bUse', 'Survey', $iSurveyId);
if ($bUse) { //Only private surveys with authsaml plugin enabled
if ($this->ssp->isAuthenticated()) { //Only idp users
$sLanguage = Yii::app()->request->getParam('lang');
$aSurveyInfo = getSurveyInfo($iSurveyId, $sLanguage);
$aSurveyIdpAttributes = array_diff(json_decode($this->get('surveyIdpAttributes', 'Survey', $iSurveyId), true), array('none'));
if ($this->checkIdpAttributes($aSurveyIdpAttributes)) {
$oToken = TokenDynamic::model($iSurveyId)->find('email=:email', array(':email' => $this->getUserMail()));
if ($oToken) { //Allow survey access if the token is given
if (Yii::app()->request->getParam('token')) {
return;
}
$sToken = $oToken->token;
} else {//Creation of the token
$oToken = Token::create($iSurveyId);
$oToken->firstname = $this->getUserGivenName();
$oToken->lastname = $this->getUserSurName();
$oToken->email = $this->getUserMail();
$oToken->emailstatus = 'OK';
$oToken->language = $sLanguage;
if ($aSurveyInfo['startdate']) {
$oToken->validfrom = $aSurveyInfo['startdate'];
}
if ($aSurveyInfo['expires']) {
$oToken->validuntil = $aSurveyInfo['expires'];
}
$oToken->save();
$iTokenId = $oToken->tid;
$sToken = TokenDynamic::model($iSurveyId)->createToken($iTokenId);
}
if ($sToken) {
$surveylink = App()->createAbsoluteUrl("/survey/index/sid/{$iSurveyId}", array('token' => $sToken));
header('Location: ' . $surveylink);
}
} else {
$aReplacementFields = array();
$aReplacementFields["{ADMINNAME}"] = $aSurveyInfo['adminname'];
$aReplacementFields["{ADMINEMAIL}"] = $aSurveyInfo['adminemail'];
$sLanguage = Yii::app()->request->getParam('lang', '');
if ($sLanguage == "") {
$sLanguage = Survey::model()->findByPk($iSurveyId)->language;
}
$aSurveyInfo = getSurveyInfo($iSurveyId, $sLanguage);
$sTemplatePath = $aData['templatedir'] = getTemplatePath($aSurveyInfo['template']);
$sAttributesRequired = '';
$sAttributesReceived = '';
foreach ($aSurveyIdpAttributes as $key => $value) {
$sAttributesRequired .= "<li>{$key} = \"{$value}\"</li>";
}
foreach (array_intersect_key($this->attributes, $aSurveyIdpAttributes) as $key => $value) {
$sAttributesReceived .= "<li>{$key} = \"{$value[0]}\"</li>";
}
$sReturnHtml = "<div id='wrapper' class='message tokenmessage'>"
. "<h3>Acesso ao questionário não permitido!</h3>\n"
. "<p>Informações de usuário necessárias:</p>\n"
. "<ul>$sAttributesRequired</ul><br />"
. "<p>Informações de usuário recebidas:</p>\n"
. "<ul>$sAttributesReceived</ul><br />"
. "<p>Entre em contato com o administrador do questionário: {ADMINNAME} ({ADMINEMAIL})</p>"
. "</div>\n";
$sReturnHtml = ReplaceFields($sReturnHtml, $aReplacementFields);
ob_start(function($buffer, $phase) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
return $buffer;
});
ob_implicit_flush(false);
sendCacheHeaders();
doHeader();
$aData['thissurvey'] = $aSurveyInfo;
$aData['thissurvey'] = $aSurveyInfo;
echo templatereplace(file_get_contents($sTemplatePath . '/startpage.pstpl'), array(), $aData);
echo templatereplace(file_get_contents($sTemplatePath . '/survey.pstpl'), array(), $aData);
echo $sReturnHtml;
echo templatereplace(file_get_contents($sTemplatePath . '/endpage.pstpl'), array(), $aData);
doFooter();
ob_flush();
App()->end();
}
} else {// Asks idp authentication
header('Location: ' . $this->ssp->getLoginURL());
}
}
}
示例8: sendSubmitNotifications
/**
* Send a submit notification to the email address specified in the notifications tab in the survey settings
*/
function sendSubmitNotifications($surveyid)
{
global $thissurvey, $debug;
global $homeurl, $maildebug, $tokensexist;
$clang = Yii::app()->lang;
$sitename = Yii::app()->getConfig("sitename");
$bIsHTML = $thissurvey['htmlemail'] == 'Y';
$aReplacementVars = array();
if ($thissurvey['allowsave'] == "Y" && isset($_SESSION['survey_' . $surveyid]['scid'])) {
$aReplacementVars['RELOADURL'] = "" . Yii::app()->getController()->createUrl("/survey/index/sid/{$surveyid}/loadall/reload/scid/" . $_SESSION['survey_' . $surveyid]['scid'] . "/loadname/" . urlencode($_SESSION['survey_' . $surveyid]['holdname']) . "/loadpass/" . urlencode($_SESSION['survey_' . $surveyid]['holdpass']));
if ($bIsHTML) {
$aReplacementVars['RELOADURL'] = "<a href='{$aReplacementVars['RELOADURL']}'>{$aReplacementVars['RELOADURL']}</a>";
}
} else {
$aReplacementVars['RELOADURL'] = '';
}
if (!isset($_SESSION['survey_' . $surveyid]['srid'])) {
$srid = null;
} else {
$srid = $_SESSION['survey_' . $surveyid]['srid'];
}
$aReplacementVars['ADMINNAME'] = $thissurvey['adminname'];
$aReplacementVars['ADMINEMAIL'] = $thissurvey['adminemail'];
$aReplacementVars['VIEWRESPONSEURL'] = "{$homeurl}/admin.php?action=browse&sid={$surveyid}&subaction=id&id=" . $srid;
$aReplacementVars['EDITRESPONSEURL'] = "{$homeurl}/admin.php?action=dataentry&sid={$surveyid}&subaction=edit&surveytable=survey_{$surveyid}&id=" . $srid;
$aReplacementVars['STATISTICSURL'] = "{$homeurl}/admin.php?action=statistics&sid={$surveyid}";
if ($bIsHTML) {
$aReplacementVars['VIEWRESPONSEURL'] = "<a href='{$aReplacementVars['VIEWRESPONSEURL']}'>{$aReplacementVars['VIEWRESPONSEURL']}</a>";
$aReplacementVars['EDITRESPONSEURL'] = "<a href='{$aReplacementVars['EDITRESPONSEURL']}'>{$aReplacementVars['EDITRESPONSEURL']}</a>";
$aReplacementVars['STATISTICSURL'] = "<a href='{$aReplacementVars['STATISTICSURL']}'>{$aReplacementVars['STATISTICSURL']}</a>";
}
$aReplacementVars['ANSWERTABLE'] = '';
$aEmailResponseTo = array();
$aEmailNotificationTo = array();
$sResponseData = "";
if (!empty($thissurvey['emailnotificationto'])) {
$aRecipient = explode(";", $thissurvey['emailnotificationto']);
foreach ($aRecipient as $sRecipient) {
$sRecipient = ReplaceFields($sRecipient, array('ADMINEMAIL' => $thissurvey['adminemail']), true);
// Only need INSERTANS, ADMINMAIL and TOKEN
if (validateEmailAddress($sRecipient)) {
$aEmailNotificationTo[] = $sRecipient;
}
}
}
if (!empty($thissurvey['emailresponseto'])) {
if (isset($_SESSION['survey_' . $surveyid]['token']) && $_SESSION['survey_' . $surveyid]['token'] != '' && tableExists('{{tokens_' . $surveyid . '}}')) {
//Gather token data for tokenised surveys
$_SESSION['survey_' . $surveyid]['thistoken'] = getTokenData($surveyid, $_SESSION['survey_' . $surveyid]['token']);
} elseif ($_SESSION['survey_' . $surveyid]['insertarray'][0] == 'token') {
unset($_SESSION['survey_' . $surveyid]['insertarray'][0]);
}
//Make an array of email addresses to send to
$aRecipient = explode(";", $thissurvey['emailresponseto']);
foreach ($aRecipient as $sRecipient) {
$sRecipient = ReplaceFields($sRecipient, array('ADMINEMAIL' => $thissurvey['adminemail']), true);
// Only need INSERTANS, ADMINMAIL and TOKEN
if (validateEmailAddress($sRecipient)) {
$aEmailResponseTo[] = $sRecipient;
}
}
$aFullResponseTable = getFullResponseTable($surveyid, $_SESSION['survey_' . $surveyid]['srid'], $_SESSION['survey_' . $surveyid]['s_lang']);
$ResultTableHTML = "<table class='printouttable' >\n";
$ResultTableText = "\n\n";
$oldgid = 0;
$oldqid = 0;
foreach ($aFullResponseTable as $sFieldname => $fname) {
if (substr($sFieldname, 0, 4) == 'gid_') {
$ResultTableHTML .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n";
$ResultTableText .= "\n{$fname[0]}\n\n";
} elseif (substr($sFieldname, 0, 4) == 'qid_') {
$ResultTableHTML .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$fname[0]}</td></tr>\n";
$ResultTableText .= "\n{$fname[0]}\n";
} else {
$ResultTableHTML .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
$ResultTableText .= " {$fname[0]} {$fname[1]}: {$fname[2]}\n";
}
}
$ResultTableHTML .= "</table>\n";
$ResultTableText .= "\n\n";
if ($bIsHTML) {
$aReplacementVars['ANSWERTABLE'] = $ResultTableHTML;
} else {
$aReplacementVars['ANSWERTABLE'] = $ResultTableText;
}
}
$sFrom = $thissurvey['adminname'] . ' <' . $thissurvey['adminemail'] . '>';
$redata = compact(array_keys(get_defined_vars()));
if (count($aEmailNotificationTo) > 0) {
$sMessage = templatereplace($thissurvey['email_admin_notification'], $aReplacementVars, $redata, 'frontend_helper[1398]', $thissurvey['anonymized'] == "Y");
$sSubject = templatereplace($thissurvey['email_admin_notification_subj'], $aReplacementVars, $redata, 'frontend_helper[1399]', $thissurvey['anonymized'] == "Y");
foreach ($aEmailNotificationTo as $sRecipient) {
if (!SendEmailMessage($sMessage, $sSubject, $sRecipient, $sFrom, $sitename, true, getBounceEmail($surveyid))) {
if ($debug > 0) {
echo '<br />Email could not be sent. Reason: ' . $maildebug . '<br/>';
}
}
//.........这里部分代码省略.........
示例9: email
//.........这里部分代码省略.........
$_POST['message_' . $language] = html_entity_decode(Yii::app()->request->getPost('message_' . $language), ENT_QUOTES, Yii::app()->getConfig("emailcharset"));
}
}
$attributes = getTokenFieldsAndNames($iSurveyId);
$tokenoutput = "";
if ($emcount > 0) {
foreach ($emresult as $emrow) {
$to = array();
$aEmailaddresses = explode(';', $emrow['email']);
foreach ($aEmailaddresses as $sEmailaddress) {
$to[] = $emrow['firstname'] . " " . $emrow['lastname'] . " <{$sEmailaddress}>";
}
$fieldsarray["{EMAIL}"] = $emrow['email'];
$fieldsarray["{FIRSTNAME}"] = $emrow['firstname'];
$fieldsarray["{LASTNAME}"] = $emrow['lastname'];
$fieldsarray["{TOKEN}"] = $emrow['token'];
$fieldsarray["{LANGUAGE}"] = $emrow['language'];
foreach ($attributes as $attributefield => $attributedescription) {
$fieldsarray['{' . strtoupper($attributefield) . '}'] = $emrow[$attributefield];
$fieldsarray['{TOKEN:' . strtoupper($attributefield) . '}'] = $emrow[$attributefield];
}
$emrow['language'] = trim($emrow['language']);
$found = array_search($emrow['language'], $aSurveyLangs);
if ($emrow['language'] == '' || $found == false) {
$emrow['language'] = $sBaseLanguage;
}
$from = Yii::app()->request->getPost('from_' . $emrow['language']);
$fieldsarray["{OPTOUTURL}"] = $this->getController()->createAbsoluteUrl("/optout/tokens/langcode/" . trim($emrow['language']) . "/surveyid/{$iSurveyId}/token/{$emrow['token']}");
$fieldsarray["{OPTINURL}"] = $this->getController()->createAbsoluteUrl("/optin/tokens/langcode/" . trim($emrow['language']) . "/surveyid/{$iSurveyId}/token/{$emrow['token']}");
$fieldsarray["{SURVEYURL}"] = $this->getController()->createAbsoluteUrl("/survey/index/sid/{$iSurveyId}/token/{$emrow['token']}/langcode/" . trim($emrow['language']) . "/");
foreach (array('OPTOUT', 'OPTIN', 'SURVEY') as $key) {
$url = $fieldsarray["{{$key}URL}"];
if ($bHtml) {
$fieldsarray["{{$key}URL}"] = "<a href='{$url}'>" . htmlspecialchars($url) . '</a>';
}
if ($key == 'SURVEY') {
$barebone_link = $url;
}
}
$customheaders = array('1' => "X-surveyid: " . $iSurveyId, '2' => "X-tokenid: " . $fieldsarray["{TOKEN}"]);
global $maildebug;
$modsubject = Replacefields(Yii::app()->request->getPost('subject_' . $emrow['language']), $fieldsarray);
$modmessage = Replacefields(Yii::app()->request->getPost('message_' . $emrow['language']), $fieldsarray);
if (isset($barebone_link)) {
$modsubject = str_replace("@@SURVEYURL@@", $barebone_link, $modsubject);
$modmessage = str_replace("@@SURVEYURL@@", $barebone_link, $modmessage);
}
if (trim($emrow['validfrom']) != '' && convertDateTimeFormat($emrow['validfrom'], 'Y-m-d H:i:s', 'U') * 1 > date('U') * 1) {
$tokenoutput .= $emrow['tid'] . " " . ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) delayed: Token is not yet valid.") . "<br />", $fieldsarray);
} elseif (trim($emrow['validuntil']) != '' && convertDateTimeFormat($emrow['validuntil'], 'Y-m-d H:i:s', 'U') * 1 < date('U') * 1) {
$tokenoutput .= $emrow['tid'] . " " . ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) skipped: Token is not valid anymore.") . "<br />", $fieldsarray);
} else {
if (SendEmailMessage($modmessage, $modsubject, $to, $from, Yii::app()->getConfig("sitename"), $bHtml, getBounceEmail($iSurveyId), null, $customheaders)) {
// Put date into sent
$udequery = Tokens_dynamic::model($iSurveyId)->findByPk($emrow['tid']);
if ($bEmail) {
$tokenoutput .= $clang->gT("Invitation sent to:");
$udequery->sent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
} else {
$tokenoutput .= $clang->gT("Reminder sent to:");
$udequery->remindersent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$udequery->remindercount = $udequery->remindercount + 1;
}
$udequery->save();
//Update central participant survey_links
if (!empty($emrow['participant_id'])) {
$slquery = Survey_links::model()->find('participant_id = "' . $emrow['participant_id'] . '" AND survey_id = ' . $iSurveyId . ' AND token_id = ' . $emrow['tid']);
$slquery->date_invited = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust"));
$slquery->save();
}
$tokenoutput .= "{$emrow['tid']}: {$emrow['firstname']} {$emrow['lastname']} ({$emrow['email']})<br />\n";
if (Yii::app()->getConfig("emailsmtpdebug") == 2) {
$tokenoutput .= $maildebug;
}
} else {
$tokenoutput .= ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:") . " " . $maildebug . "<br />", $fieldsarray);
}
}
unset($fieldsarray);
}
$aViewUrls = array('tokenbar', 'emailpost');
$aData['tokenoutput'] = $tokenoutput;
if ($ctcount > $emcount) {
$i = 0;
if (isset($aTokenIds)) {
while ($i < $iMaxEmails) {
array_shift($aTokenIds);
$i++;
}
$aData['tids'] = implode('|', $aTokenIds);
}
$aData['lefttosend'] = $ctcount - $iMaxEmails;
$aViewUrls[] = 'emailwarning';
}
$this->_renderWrappedTemplate('token', $aViewUrls, $aData);
} else {
$this->_renderWrappedTemplate('token', array('tokenbar', 'message' => array('title' => $clang->gT("Warning"), 'message' => $clang->gT("There were no eligible emails to send. This will be because none satisfied the criteria of:") . "<br/> <ul><li>" . $clang->gT("having a valid email address") . "</li>" . "<li>" . $clang->gT("not having been sent an invitation already") . "</li>" . "<li>" . $clang->gT("having already completed the survey") . "</li>" . "<li>" . $clang->gT("having a token") . "</li></ul>")), $aData);
}
}
}
示例10: submittokens
/**
* Marks a tokens as completed and sends a confirmation email to the participiant.
* If $quotaexit is set to true then the user exited the survey due to a quota
* restriction and the according token is only marked as 'Q'
*
* @param mixed $quotaexit
*/
function submittokens($quotaexit = false)
{
global $thissurvey, $timeadjust, $emailcharset;
global $dbprefix, $surveyid, $connect;
global $sitename, $thistpl, $clang, $clienttoken;
// Shift the date due to global timeadjust setting
$today = date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i", $timeadjust);
// check how many uses the token has left
$usesquery = "SELECT usesleft FROM {$dbprefix}tokens_{$surveyid} WHERE token='" . db_quote($clienttoken) . "'";
$usesresult = db_execute_assoc($usesquery);
$usesrow = $usesresult->FetchRow();
if (isset($usesrow)) {
$usesleft = $usesrow['usesleft'];
}
$utquery = "UPDATE {$dbprefix}tokens_{$surveyid}\n";
if ($quotaexit == true) {
$utquery .= "SET completed='Q', usesleft=usesleft-1\n";
} elseif (bIsTokenCompletedDatestamped($thissurvey)) {
if (isset($usesleft) && $usesleft <= 1) {
$utquery .= "SET usesleft=usesleft-1, completed='{$today}'\n";
} else {
$utquery .= "SET usesleft=usesleft-1\n";
}
} else {
if (isset($usesleft) && $usesleft <= 1) {
$utquery .= "SET usesleft=usesleft-1, completed='Y'\n";
} else {
$utquery .= "SET usesleft=usesleft-1\n";
}
}
$utquery .= "WHERE token='" . db_quote($clienttoken) . "'";
$utresult = $connect->Execute($utquery) or safe_die("Couldn't update tokens table!<br />\n{$utquery}<br />\n" . $connect->ErrorMsg());
//Checked
if ($quotaexit == false) {
// TLR change to put date into sent and completed
$cnfquery = "SELECT * FROM " . db_table_name("tokens_{$surveyid}") . " WHERE token='" . db_quote($clienttoken) . "' AND completed!='N' AND completed!=''";
$cnfresult = db_execute_assoc($cnfquery);
//Checked
$cnfrow = $cnfresult->FetchRow();
if (isset($cnfrow)) {
$from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
$to = $cnfrow['email'];
$subject = $thissurvey['email_confirm_subj'];
$fieldsarray["{ADMINNAME}"] = $thissurvey['adminname'];
$fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail'];
$fieldsarray["{SURVEYNAME}"] = $thissurvey['name'];
$fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description'];
$fieldsarray["{FIRSTNAME}"] = $cnfrow['firstname'];
$fieldsarray["{LASTNAME}"] = $cnfrow['lastname'];
$fieldsarray["{TOKEN}"] = $clienttoken;
$attrfieldnames = GetAttributeFieldnames($surveyid);
foreach ($attrfieldnames as $attr_name) {
$fieldsarray["{" . strtoupper($attr_name) . "}"] = $cnfrow[$attr_name];
}
$dateformatdatat = getDateFormatData($thissurvey['surveyls_dateformat']);
$numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']);
$fieldsarray["{EXPIRY}"] = convertDateTimeFormat($thissurvey["expiry"], 'Y-m-d H:i:s', $dateformatdatat['phpdate']);
$subject = ReplaceFields($subject, $fieldsarray, true);
if ($thissurvey['anonymized'] == "N") {
// Survey is not anonymous, we can translate insertAns placeholder
$subject = dTexts::run($subject);
}
$subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset);
if (getEmailFormat($surveyid) == 'html') {
$ishtml = true;
} else {
$ishtml = false;
}
if (trim(strip_tags($thissurvey['email_confirm'])) != "") {
$message = $thissurvey['email_confirm'];
$message = ReplaceFields($message, $fieldsarray, true);
if ($thissurvey['anonymized'] == "N") {
// Survey is not anonymous, we can translate insertAns placeholder
$message = dTexts::run($message);
}
if (!$ishtml) {
$message = strip_tags(br2nl(html_entity_decode($message, ENT_QUOTES, $emailcharset)));
} else {
$message = html_entity_decode($message, ENT_QUOTES, $emailcharset);
}
//Only send confirmation email if there is a valid email address
if (validate_email($cnfrow['email'])) {
SendEmailMessage(null, $message, $subject, $to, $from, $sitename, $ishtml);
}
} else {
//There is nothing in the message, so don't send a confirmation email
//This section only here as placeholder to indicate new feature :-)
}
}
}
}
示例11: sendRegistrationEmail
/**
* Send the register email with $_POST value
* @param $iSurveyId Survey Id to register
* @return boolean : if email is set to sent (before SMTP problem)
*/
public function sendRegistrationEmail($iSurveyId, $iTokenId)
{
$sLanguage = App()->language;
$aSurveyInfo = getSurveyInfo($iSurveyId, $sLanguage);
$aMail['subject'] = $aSurveyInfo['email_register_subj'];
$aMail['message'] = $aSurveyInfo['email_register'];
$aReplacementFields = array();
$aReplacementFields["{ADMINNAME}"] = $aSurveyInfo['adminname'];
$aReplacementFields["{ADMINEMAIL}"] = $aSurveyInfo['adminemail'];
$aReplacementFields["{SURVEYNAME}"] = $aSurveyInfo['name'];
$aReplacementFields["{SURVEYDESCRIPTION}"] = $aSurveyInfo['description'];
$aReplacementFields["{EXPIRY}"] = $aSurveyInfo["expiry"];
$oToken = Token::model($iSurveyId)->findByPk($iTokenId);
// Reload the token (needed if just created)
foreach ($oToken->attributes as $attribute => $value) {
$aReplacementFields["{" . strtoupper($attribute) . "}"] = $value;
}
$sToken = $oToken->token;
$useHtmlEmail = getEmailFormat($iSurveyId) == 'html';
$aMail['subject'] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", $aMail['subject']);
$aMail['message'] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", $aMail['message']);
$aReplacementFields["{SURVEYURL}"] = App()->createAbsoluteUrl("/survey/index/sid/{$iSurveyId}", array('lang' => $sLanguage, 'token' => $sToken));
$aReplacementFields["{OPTOUTURL}"] = App()->createAbsoluteUrl("/optout/tokens/surveyid/{$iSurveyId}", array('langcode' => $sLanguage, 'token' => $sToken));
$aReplacementFields["{OPTINURL}"] = App()->createAbsoluteUrl("/optin/tokens/surveyid/{$iSurveyId}", array('langcode' => $sLanguage, 'token' => $sToken));
foreach (array('OPTOUT', 'OPTIN', 'SURVEY') as $key) {
$url = $aReplacementFields["{{$key}URL}"];
if ($useHtmlEmail) {
$aReplacementFields["{{$key}URL}"] = "<a href='{$url}'>" . htmlspecialchars($url) . '</a>';
}
$aMail['subject'] = str_replace("@@{$key}URL@@", $url, $aMail['subject']);
$aMail['message'] = str_replace("@@{$key}URL@@", $url, $aMail['message']);
}
// Replace the fields
$aMail['subject'] = ReplaceFields($aMail['subject'], $aReplacementFields);
$aMail['message'] = ReplaceFields($aMail['message'], $aReplacementFields);
$sFrom = "{$aSurveyInfo['adminname']} <{$aSurveyInfo['adminemail']}>";
$sBounce = getBounceEmail($iSurveyId);
$sTo = $oToken->email;
$sitename = Yii::app()->getConfig('sitename');
// Plugin event for email handling (Same than admin token but with register type)
$event = new PluginEvent('beforeTokenEmail');
$event->set('type', 'register');
$event->set('subject', $aMail['subject']);
$event->set('to', $sTo);
$event->set('body', $aMail['message']);
$event->set('from', $sFrom);
$event->set('bounce', $sBounce);
$event->set('token', $oToken->attributes);
$aMail['subject'] = $event->get('subject');
$aMail['message'] = $event->get('body');
$sTo = $event->get('to');
$sFrom = $event->get('from');
if ($event->get('send', true) == false) {
$this->sMessage = $event->get('message', '');
if ($event->get('error') == null) {
// mimic token system, set send to today
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$oToken->sent = $today;
$oToken->save();
}
} elseif (SendEmailMessage($aMail['message'], $aMail['subject'], $sTo, $sFrom, $sitename, $useHtmlEmail, $sBounce)) {
// TLR change to put date into sent
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$oToken->sent = $today;
$oToken->save();
$this->sMessage = "<div id='wrapper' class='message tokenmessage'>" . "<p>" . gT("Thank you for registering to participate in this survey.") . "</p>\n" . "<p>{$this->sMailMessage}</p>\n" . "<p>" . sprintf(gT("Survey administrator %s (%s)"), $aSurveyInfo['adminname'], $aSurveyInfo['adminemail']) . "</p>" . "</div>\n";
} else {
$this->sMessage = "<div id='wrapper' class='message tokenmessage'>" . "<p>" . gT("Thank you for registering to participate in this survey.") . "</p>\n" . "<p>" . gT("You are registered but an error happened when trying to send the email - please contact the survey administrator.") . "</p>\n" . "<p>" . sprintf(gT("Survey administrator %s (%s)"), $aSurveyInfo['adminname'], $aSurveyInfo['adminemail']) . "</p>" . "</div>\n";
}
// Allways return true : if we come here, we allways trye to send an email
return true;
}
示例12: actionIndex
//.........这里部分代码省略.........
// Get the survey settings for token length
$tokenlength = $thissurvey['tokenlength'];
//if tokenlength is not set or there are other problems use the default value (15)
if (!isset($tokenlength) || $tokenlength == '') {
$tokenlength = 15;
}
while ($mayinsert != true) {
$newtoken = randomChars($tokenlength);
$oTokenExist = TokenDynamic::model($iSurveyID)->find('token=:token', array(':token' => $newtoken));
if (!$oTokenExist) {
$mayinsert = true;
}
}
$postfirstname = sanitize_xss_string(strip_tags(Yii::app()->request->getPost('register_firstname')));
$postlastname = sanitize_xss_string(strip_tags(Yii::app()->request->getPost('register_lastname')));
$starttime = sanitize_xss_string(Yii::app()->request->getPost('startdate'));
$endtime = sanitize_xss_string(Yii::app()->request->getPost('enddate'));
/*$postattribute1=sanitize_xss_string(strip_tags(returnGlobal('register_attribute1')));
$postattribute2=sanitize_xss_string(strip_tags(returnGlobal('register_attribute2'))); */
// Insert new entry into tokens db
$oToken = Token::create($thissurvey['sid']);
$oToken->firstname = $postfirstname;
$oToken->lastname = $postlastname;
$oToken->email = Yii::app()->request->getPost('register_email');
$oToken->emailstatus = 'OK';
$oToken->token = $newtoken;
if ($starttime && $endtime) {
$oToken->validfrom = $starttime;
$oToken->validuntil = $endtime;
}
$oToken->setAttributes($attributeinsertdata, false);
$result = $oToken->save();
//$tid = $oToken->tid;// Not needed any more
$fieldsarray["{ADMINNAME}"] = $thissurvey['adminname'];
$fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail'];
$fieldsarray["{SURVEYNAME}"] = $thissurvey['name'];
$fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description'];
$fieldsarray["{FIRSTNAME}"] = $postfirstname;
$fieldsarray["{LASTNAME}"] = $postlastname;
$fieldsarray["{EXPIRY}"] = $thissurvey["expiry"];
$fieldsarray["{TOKEN}"] = $oToken->token;
$fieldsarray["{EMAIL}"] = $oToken->email;
$token = $oToken->token;
$message = $thissurvey['email_register'];
$subject = $thissurvey['email_register_subj'];
$from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>";
$surveylink = $this->createAbsoluteUrl("/survey/index/sid/{$iSurveyID}", array('lang' => $sBaseLanguage, 'token' => $newtoken));
$optoutlink = $this->createAbsoluteUrl("/optout/tokens/surveyid/{$iSurveyID}", array('langcode' => $sBaseLanguage, 'token' => $newtoken));
$optinlink = $this->createAbsoluteUrl("/optin/tokens/surveyid/{$iSurveyID}", array('langcode' => $sBaseLanguage, 'token' => $newtoken));
if (getEmailFormat($iSurveyID) == 'html') {
$useHtmlEmail = true;
$fieldsarray["{SURVEYURL}"] = "<a href='{$surveylink}'>" . $surveylink . "</a>";
$fieldsarray["{OPTOUTURL}"] = "<a href='{$optoutlink}'>" . $optoutlink . "</a>";
$fieldsarray["{OPTINURL}"] = "<a href='{$optinlink}'>" . $optinlink . "</a>";
} else {
$useHtmlEmail = false;
$fieldsarray["{SURVEYURL}"] = $surveylink;
$fieldsarray["{OPTOUTURL}"] = $optoutlink;
$fieldsarray["{OPTINURL}"] = $optinlink;
}
$message = ReplaceFields($message, $fieldsarray);
$subject = ReplaceFields($subject, $fieldsarray);
$html = "";
//Set variable
$sitename = Yii::app()->getConfig('sitename');
if (SendEmailMessage($message, $subject, Yii::app()->request->getPost('register_email'), $from, $sitename, $useHtmlEmail, getBounceEmail($iSurveyID))) {
// TLR change to put date into sent
$today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig('timeadjust'));
$oToken->sent = $today;
$oToken->save();
$html = "<div id='wrapper' class='message tokenmessage'>" . "<p>" . $clang->gT("Thank you for registering to participate in this survey.") . "</p>\n" . "<p>" . $clang->gT("An email has been sent to the address you provided with access details for this survey. Please follow the link in that email to proceed.") . "</p>\n" . "<p>" . $clang->gT("Survey administrator") . " {ADMINNAME} ({ADMINEMAIL})</p>" . "</div>\n";
$html = ReplaceFields($html, $fieldsarray);
} else {
$html = "Email Error";
}
//PRINT COMPLETED PAGE
if (!$thissurvey['template']) {
$thistpl = getTemplatePath(validateTemplateDir('default'));
} else {
$thistpl = getTemplatePath(validateTemplateDir($thissurvey['template']));
}
// Same fix than http://bugs.limesurvey.org/view.php?id=8441
ob_start(function ($buffer, $phase) {
App()->getClientScript()->render($buffer);
App()->getClientScript()->reset();
return $buffer;
});
ob_implicit_flush(false);
sendCacheHeaders();
doHeader();
Yii::app()->lang = $clang;
// fetch the defined variables and pass it to the header footer templates.
$redata = compact(array_keys(get_defined_vars()));
$this->_printTemplateContent($thistpl . '/startpage.pstpl', $redata, __LINE__);
$this->_printTemplateContent($thistpl . '/survey.pstpl', $redata, __LINE__);
echo $html;
$this->_printTemplateContent($thistpl . '/endpage.pstpl', $redata, __LINE__);
doFooter();
ob_flush();
}
示例13: SendSubmitNotifications
/**
* Send a submit notification to the email address specified in the notifications tab in the survey settings
*/
function SendSubmitNotifications()
{
global $thissurvey, $debug;
global $dbprefix, $clang, $emailcharset;
global $sitename, $homeurl, $surveyid, $publicurl, $maildebug, $tokensexist;
$bIsHTML = $thissurvey['htmlemail'] == 'Y';
$aReplacementVars = array();
if ($thissurvey['allowsave'] == "Y" && isset($_SESSION['scid'])) {
$aReplacementVars['RELOADURL'] = "{$publicurl}/index.php?sid={$surveyid}&loadall=reload&scid=" . $_SESSION['scid'] . "&loadname=" . urlencode($_SESSION['holdname']) . "&loadpass=" . urlencode($_SESSION['holdpass']);
if ($bIsHTML) {
$aReplacementVars['RELOADURL'] = "<a href='{$aReplacementVars['RELOADURL']}'>{$aReplacementVars['RELOADURL']}</a>";
}
} else {
$aReplacementVars['RELOADURL'] = '';
}
$aReplacementVars['ADMINNAME'] = $thissurvey['adminname'];
$aReplacementVars['ADMINEMAIL'] = $thissurvey['adminemail'];
$aReplacementVars['VIEWRESPONSEURL'] = "{$homeurl}/admin.php?action=browse&sid={$surveyid}&subaction=id&id={$_SESSION['srid']}";
$aReplacementVars['EDITRESPONSEURL'] = "{$homeurl}/admin.php?action=dataentry&sid={$surveyid}&subaction=edit&surveytable=survey_{$surveyid}&id=" . $_SESSION['srid'];
$aReplacementVars['STATISTICSURL'] = "{$homeurl}/admin.php?action=statistics&sid={$surveyid}";
if ($bIsHTML) {
$aReplacementVars['VIEWRESPONSEURL'] = "<a href='{$aReplacementVars['VIEWRESPONSEURL']}'>{$aReplacementVars['VIEWRESPONSEURL']}</a>";
$aReplacementVars['EDITRESPONSEURL'] = "<a href='{$aReplacementVars['EDITRESPONSEURL']}'>{$aReplacementVars['EDITRESPONSEURL']}</a>";
$aReplacementVars['STATISTICSURL'] = "<a href='{$aReplacementVars['STATISTICSURL']}'>{$aReplacementVars['STATISTICSURL']}</a>";
}
$aReplacementVars['ANSWERTABLE'] = '';
$aEmailResponseTo = array();
$aEmailNotificationTo = array();
$sResponseData = "";
if (!empty($thissurvey['emailnotificationto'])) {
$aRecipient = explode(";", $thissurvey['emailnotificationto']);
foreach ($aRecipient as $sRecipient) {
$sRecipient = ReplaceFields($sRecipient, array('ADMINEMAIL' => $thissurvey['adminemail']), true);
// Only need INSERTANS, ADMINMAIL and TOKEN
if (validate_email($sRecipient)) {
$aEmailNotificationTo[] = $sRecipient;
}
}
}
if (!empty($thissurvey['emailresponseto'])) {
if (isset($_SESSION['token']) && $_SESSION['token'] != '' && db_tables_exist($dbprefix . 'tokens_' . $surveyid)) {
//Gather token data for tokenised surveys
$_SESSION['thistoken'] = getTokenData($surveyid, $_SESSION['token']);
} elseif ($_SESSION['insertarray'][0] == 'token') {
unset($_SESSION['insertarray'][0]);
}
//Make an array of email addresses to send to
$aRecipient = explode(";", $thissurvey['emailresponseto']);
foreach ($aRecipient as $sRecipient) {
$sRecipient = ReplaceFields($sRecipient, array('ADMINEMAIL' => $thissurvey['adminemail']), true);
// Only need INSERTANS, ADMINMAIL and TOKEN
if (validate_email($sRecipient)) {
$aEmailResponseTo[] = $sRecipient;
}
}
$aFullResponseTable = aGetFullResponseTable($surveyid, $_SESSION['srid'], $_SESSION['s_lang']);
$ResultTableHTML = "<table class='printouttable' >\n";
$ResultTableText = "\n\n";
$oldgid = 0;
$oldqid = 0;
foreach ($aFullResponseTable as $sFieldname => $fname) {
if (substr($sFieldname, 0, 4) == 'gid_') {
$ResultTableHTML .= "\t<tr class='printanswersgroup'><td colspan='2'>{$fname[0]}</td></tr>\n";
$ResultTableText .= "\n{$fname[0]}\n\n";
} elseif (substr($sFieldname, 0, 4) == 'qid_') {
$ResultTableHTML .= "\t<tr class='printanswersquestionhead'><td colspan='2'>{$fname[0]}</td></tr>\n";
$ResultTableText .= "\n{$fname[0]}\n";
} else {
$ResultTableHTML .= "\t<tr class='printanswersquestion'><td>{$fname[0]} {$fname[1]}</td><td class='printanswersanswertext'>{$fname[2]}</td></tr>";
$ResultTableText .= " {$fname[0]} {$fname[1]}: {$fname[2]}\n";
}
}
$ResultTableHTML .= "</table>\n";
$ResultTableText .= "\n\n";
if ($bIsHTML) {
$aReplacementVars['ANSWERTABLE'] = $ResultTableHTML;
} else {
$aReplacementVars['ANSWERTABLE'] = $ResultTableText;
}
}
$sFrom = $thissurvey['adminname'] . ' <' . $thissurvey['adminemail'] . '>';
if (count($aEmailNotificationTo) > 0) {
$sMessage = templatereplace($thissurvey['email_admin_notification'], $aReplacementVars, $thissurvey['anonymized'] == "Y");
$sSubject = templatereplace($thissurvey['email_admin_notification_subj'], $aReplacementVars, $thissurvey['anonymized'] == "Y");
$oMail = new PHPMailer();
foreach ($aEmailNotificationTo as $sRecipient) {
if (!SendEmailMessage($oMail, $sMessage, $sSubject, $sRecipient, $sFrom, $sitename, true, getBounceEmail($surveyid))) {
if ($debug > 0) {
echo '<br />Email could not be sent. Reason: ' . $maildebug . '<br/>';
}
}
}
$oMail->SmtpClose();
}
if (count($aEmailResponseTo) > 0) {
$sMessage = templatereplace($thissurvey['email_admin_responses'], $aReplacementVars);
$sSubject = templatereplace($thissurvey['email_admin_responses_subj'], $aReplacementVars);
//.........这里部分代码省略.........