本文整理汇总了PHP中LimeExpressionManager::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP LimeExpressionManager::singleton方法的具体用法?PHP LimeExpressionManager::singleton怎么用?PHP LimeExpressionManager::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LimeExpressionManager
的用法示例。
在下文中一共展示了LimeExpressionManager::singleton方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createFullQuestionIndexByGroup
protected function createFullQuestionIndexByGroup($LEMsessid)
{
echo "\n\n<!-- PRESENT THE INDEX -->\n";
echo CHtml::openTag('div', array('id' => 'index'));
echo CHtml::openTag('div', array('class' => 'container'));
echo CHtml::tag('h2', array(), gT("Question index"));
echo CHtml::openTag('ol');
foreach ($_SESSION[$LEMsessid]['grouplist'] as $key => $group) {
// echo '<script>';
// echo 'var session = '. json_encode(LimeExpressionManager::singleton()->_ValidateGroup($key)) . ';';
// echo 'console.log(session);';
// echo '</script>';
// Better to use tracevar /
if (LimeExpressionManager::GroupIsRelevant($group['gid'])) {
$group['step'] = $key + 1;
$stepInfo = LimeExpressionManager::singleton()->_ValidateGroup($key);
$classes = implode(' ', array('row', $stepInfo['anyUnanswered'] ? 'missing' : '', $_SESSION[$LEMsessid]['step'] == $group['step'] ? 'current' : ''));
$sButtonSubmit = CHtml::htmlButton(gT('Go to this group'), array('type' => 'submit', 'value' => $group['step'], 'name' => 'move', 'class' => 'jshide'));
echo CHtml::tag('li', array('data-gid' => $group['gid'], 'title' => $group['description'], 'class' => $classes), $group['group_name'] . $sButtonSubmit);
}
}
echo CHtml::closeTag('ol');
echo CHtml::closeTag('div');
echo CHtml::closeTag('div');
App()->getClientScript()->registerScript('manageIndex', "manageIndex()\n", CClientScript::POS_END);
}
示例2: actiontokens
function actiontokens($surveyid, $token, $langcode = '')
{
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('sanitize');
$sLanguageCode = $langcode;
$iSurveyID = $surveyid;
$sToken = $token;
$sToken = sanitize_token($sToken);
if (!$iSurveyID) {
$this->redirect(array('/'));
}
$iSurveyID = (int) $iSurveyID;
//Check that there is a SID
// Get passed language from form, so that we dont loose this!
if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode) {
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
} else {
$sBaseLanguage = sanitize_languagecode($sLanguageCode);
}
Yii::app()->setLanguage($sBaseLanguage);
$aSurveyInfo = getSurveyInfo($iSurveyID, $sBaseLanguage);
if ($aSurveyInfo == false || !tableExists("{{tokens_{$iSurveyID}}}")) {
throw new CHttpException(404, "This survey does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect.");
} else {
LimeExpressionManager::singleton()->loadTokenInformation($iSurveyID, $token, false);
$oToken = Token::model($iSurveyID)->findByAttributes(array('token' => $token));
if (!isset($oToken)) {
$sMessage = gT('You are not a participant in this survey.');
} else {
if ($oToken->emailstatus == 'OptOut') {
$oToken->emailstatus = 'OK';
$oToken->save();
$sMessage = gT('You have been successfully added back to this survey.');
} elseif ($oToken->emailstatus == 'OK') {
$sMessage = gT('You are already a part of this survey.');
} else {
$sMessage = gT('You have been already removed from this survey.');
}
}
}
//PRINT COMPLETED PAGE
if (!$aSurveyInfo['templatedir']) {
$sTemplate = getTemplatePath(Yii::app()->getConfig("defaulttemplate"));
} else {
$sTemplate = getTemplatePath($aSurveyInfo['templatedir']);
}
$this->_renderHtml($sMessage, $sTemplate, $aSurveyInfo);
}
示例3: email
//.........这里部分代码省略.........
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"
* send w If true limesurvey will send the email. Setting this to false will cause limesurvey to assume the mail has been sent by the plugin.
* error w If set and "send" is true, log the error as failed email attempt.
* token r Raw token data.
*/
$event = new PluginEvent('beforeTokenEmail');
$event->set('type', $sTemplate);
$event->set('subject', $modsubject);
$event->set('to', $to);
$event->set('body', $modmessage);
$event->set('from', $from);
$event->set('bounce', getBounceEmail($iSurveyId));
$event->set('token', $emrow);
App()->getPluginManager()->dispatchEvent($event);
$modsubject = $event->get('subject');
$modmessage = $event->get('body');
$to = $event->get('to');
$from = $event->get('from');
示例4: getHtmlExpression
/**
* Get the complete HTML from a string
* @param string $sExpression : the string to parse
* @param array $aReplacement : optionnal array of replacemement
* @param string $sDebugSource : optionnal debug source (for templatereplace)
* @uses ExpressionValidate::$iSurveyId
* @uses ExpressionValidate::$sLang
*
* @author Denis Chenu
* @version 1.0
*/
private function getHtmlExpression($sExpression, $aReplacement = array(), $sDebugSource = __CLASS__)
{
$LEM = LimeExpressionManager::singleton();
$LEM::SetDirtyFlag();
// Not sure it's needed
$LEM::SetPreviewMode('logic');
$aReData = array();
if ($this->iSurveyId) {
$LEM::StartSurvey($this->iSurveyId, 'survey', array('hyperlinkSyntaxHighlighting' => true));
// replace QCODE
$aReData['thissurvey'] = getSurveyInfo($this->iSurveyId, $this->sLang);
}
// TODO : Find error in class name, style etc ....
// need: templatereplace without any filter and find if there are error but $bHaveError=$LEM->em->HasErrors() is Private
$oFilter = new CHtmlPurifier();
templatereplace($oFilter->purify(viewHelper::filterScript($sExpression)), $aReplacement, $aReData, $sDebugSource, false, null, array(), true);
return $LEM::GetLastPrettyPrintExpression();
}
示例5: getLEMsurveyId
/**
* Returns the survey ID of the EM singleton
*/
public static function getLEMsurveyId()
{
$LEM =& LimeExpressionManager::singleton();
return $LEM->sid;
}
示例6: actionparticipants
function actionparticipants()
{
$iSurveyID = Yii::app()->request->getQuery('surveyid');
$sLanguageCode = Yii::app()->request->getQuery('langcode');
$sToken = sanitize_token(Yii::app()->request->getQuery('token'));
Yii::app()->loadHelper('database');
Yii::app()->loadHelper('sanitize');
if (!$iSurveyID) {
$this->redirect(array('/'));
}
$iSurveyID = (int) $iSurveyID;
//Make sure it's an integer (protect from SQL injects)
//Check that there is a SID
// Get passed language from form, so that we dont lose this!
if (!isset($sLanguageCode) || $sLanguageCode == "" || !$sLanguageCode) {
$sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language;
} else {
$sBaseLanguage = sanitize_languagecode($sLanguageCode);
}
Yii::app()->setLanguage($sBaseLanguage);
$aSurveyInfo = getSurveyInfo($iSurveyID, $sBaseLanguage);
if ($aSurveyInfo == false || !tableExists("{{tokens_{$iSurveyID}}}")) {
throw new CHttpException(404, "The survey in which you are trying to participate does not seem to exist. It may have been deleted or the link you were given is outdated or incorrect.");
} else {
LimeExpressionManager::singleton()->loadTokenInformation($iSurveyID, $sToken, false);
$oToken = Token::model($iSurveyID)->findByAttributes(array('token' => $sToken));
if (!isset($oToken)) {
$sMessage = gT('You are not a participant in this survey.');
} else {
if (substr($oToken->emailstatus, 0, strlen('OptOut')) !== 'OptOut') {
$oToken->emailstatus = 'OptOut';
$oToken->save();
$sMessage = gT('You have been successfully removed from this survey.');
} else {
$sMessage = gT('You have been already removed from this survey.');
}
if (!empty($oToken->participant_id)) {
//Participant also exists in central db
$oParticipant = Participant::model()->findByPk($oToken->participant_id);
if ($oParticipant->blacklisted == "Y") {
$sMessage .= "<br />";
$sMessage .= gT("You have already been removed from the central participants list for this site");
} else {
$oParticipant->blacklisted = 'Y';
$oParticipant->save();
$sMessage .= "<br />";
$sMessage .= gT("You have been removed from the central participants list for this site");
}
}
}
}
//PRINT COMPLETED PAGE
if (!$aSurveyInfo['templatedir']) {
$sTemplate = getTemplatePath(Yii::app()->getConfig("defaulttemplate"));
} else {
$sTemplate = getTemplatePath($aSurveyInfo['templatedir']);
}
$this->_renderHtml($sMessage, $sTemplate, $aSurveyInfo);
}
示例7: oldTestEvaluator
//.........这里部分代码省略.........
NULL~five ! three
NULL~(5 + 7) = 8
NULL~&& four
NULL~min(
NULL~max three, four, five)
NULL~three four
NULL~max(three,four,five) six
NULL~WELCOME='Good morning'
NULL~TOKEN:FIRSTNAME='Tom'
NULL~NUMBEROFQUESTIONS+=3
NULL~NUMBEROFQUESTIONS*=4
NULL~NUMBEROFQUESTIONS/=5
NULL~NUMBEROFQUESTIONS-=6
NULL~'Tom'='tired'
NULL~max()
NULL~convert_value( 10, 1, '0,5,10,15,20', '0,5,10,15')
100~convert_value( 10, 1, '0,5,10,15,20', '0,50,100,150,200')
NULL~convert_value( 10, 0, '0,5,10,15,20', '0,50,100,150,200')
100~convert_value( 8, 0, '0,5,10,15,20', '0,50,100,150,200')
100~convert_value( 12, 0, '0,5,10,15,20', '0,50,100,150,200')
0~convert_value( 0, 0, '0,5,10,15,20', '0,50,100,150,200')
0~convert_value( -10000, 0, '0,5,10,15,20', '0,50,100,150,200')
NULL~convert_value( -10000, 1, '0,5,10,15,20', '0,50,100,150,200')
200~convert_value( 20, 0, '0,5,10,15,20', '0,50,100,150,200')
200~convert_value( 20, 1, '0,5,10,15,20', '0,50,100,150,200')
200~convert_value( 30, 0, '0,5,10,15,20', '0,50,100,150,200')
NULL~convert_value( 30, 1, '0,5,10,15,20', '0,50,100,150,200')
EOD;
$atests = explode("\n", $tests);
$atests[] = "1\n2\n3~BREAKS";
$atests[] = "1<br />\n2<br />\n3~nl2br(BREAKS)";
$atests[] = "hi<br />\nthere<br />\nhow<br />\nare<br />\nyou?~nl2br('hi\\nthere\\nhow\\nare\\nyou?')";
$atests[] = "hi<br />\nthere,<br />\nuser!~nl2br(implode('\\n','hi','there,','user!'))";
$LEM =& LimeExpressionManager::singleton();
$em = new ExpressionManager();
$LEM->setTempVars($vars);
//$LEMsessid = 'survey_' . Yii::app()->getConfig('surveyID');
$LEMsessid = 'survey_12345';
// manually set relevance status
$_SESSION[$LEMsessid]['relevanceStatus'] = array();
foreach ($vars as $var) {
if (isset($var['qseq'])) {
$_SESSION[$LEMsessid]['relevanceStatus'][$var['qseq']] = 1;
}
}
$allJsVarnamesUsed = array();
$body = '';
$body .= '<table border="1"><tr><th>Expression</th><th>PHP Result</th><th>Expected</th><th>JavaScript Result</th><th>VarNames</th><th>JavaScript Eqn</th></tr>';
$i = 0;
$javaScript = array();
foreach ($atests as $test) {
++$i;
$values = explode("~", $test);
$expectedResult = array_shift($values);
$expr = implode("~", $values);
$resultStatus = 'ok';
$em->groupSeq = 2;
$em->questionSeq = 3;
$status = $em->RDP_Evaluate($expr);
if ($status) {
$allJsVarnamesUsed = array_merge($allJsVarnamesUsed, $em->GetJsVarsUsed());
}
$result = $em->GetResult();
$valToShow = $result;
// htmlspecialchars($result,ENT_QUOTES,'UTF-8',false);
$expectedToShow = $expectedResult;
示例8: UnitTestEvaluator
//.........这里部分代码省略.........
NULL~*
NULL~three +
NULL~four * / seven
NULL~(five - three
NULL~five + three)
NULL~seven + = four
NULL~>
NULL~five > > three
NULL~seven > = four
NULL~seven >=
NULL~three &&
NULL~three ||
NULL~three +
NULL~three >=
NULL~three +=
NULL~three !
NULL~three *
NULL~five ! three
NULL~(5 + 7) = 8
NULL~&& four
NULL~min(
NULL~max three, four, five)
NULL~three four
NULL~max(three,four,five) six
NULL~WELCOME='Good morning'
NULL~TOKEN:FIRSTNAME='Tom'
NULL~NUMBEROFQUESTIONS+=3
NULL~NUMBEROFQUESTIONS*=4
NULL~NUMBEROFQUESTIONS/=5
NULL~NUMBEROFQUESTIONS-=6
NULL~'Tom'='tired'
NULL~max()
EOD;
$LEM =& LimeExpressionManager::singleton();
$em = new ExpressionManager();
$LEM->setTempVars($vars);
// manually set relevance status
$_SESSION['relevanceStatus'] = array();
foreach ($vars as $var) {
if (isset($var['qseq'])) {
$_SESSION['relevanceStatus'][$var['qseq']] = 1;
}
}
$allJsVarnamesUsed = array();
$body = '';
$body .= '<table border="1"><tr><th>Expression</th><th>PHP Result</th><th>Expected</th><th>JavaScript Result</th><th>VarNames</th><th>JavaScript Eqn</th></tr>';
$i = 0;
$javaScript = array();
foreach (explode("\n", $tests) as $test) {
++$i;
$values = explode("~", $test);
$expectedResult = array_shift($values);
$expr = implode("~", $values);
$resultStatus = 'ok';
$em->groupSeq = 2;
$em->questionSeq = 3;
$status = $em->RDP_Evaluate($expr);
if ($status) {
$allJsVarnamesUsed = array_merge($allJsVarnamesUsed, $em->GetJsVarsUsed());
}
$result = $em->GetResult();
$valToShow = $result;
// htmlspecialchars($result,ENT_QUOTES,'UTF-8',false);
$expectedToShow = $expectedResult;
// htmlspecialchars($expectedResult,ENT_QUOTES,'UTF-8',false);
$body .= "<tr>";
示例9: ShowSurveyLogicFile
/**
* Create HTML view of the survey, showing everything that uses EM
* @param <type> $sid
* @param <type> $gid
* @param <type> $qid
*/
public static function ShowSurveyLogicFile($sid, $gid = NULL, $qid = NULL, $LEMdebugLevel = 0, $assessments = false)
{
// Title
// Welcome
// G1, name, relevance, text
// *Q1, name [type], relevance [validation], text, help, default, help_msg
// SQ1, name [scale], relevance [validation], text
// A1, code, assessment_value, text
// End Message
global $rooturl;
$LEM =& LimeExpressionManager::singleton();
$allErrors = array();
$warnings = 0;
$surveyOptions = array('assessments' => $assessments, 'hyperlinkSyntaxHighlighting' => true, 'rooturl' => $rooturl);
$varNamesUsed = array();
// keeps track of whether variables have been declared
if (!is_null($qid)) {
$surveyMode = 'question';
LimeExpressionManager::StartSurvey($sid, 'question', $surveyOptions, false, $LEMdebugLevel);
$qseq = LimeExpressionManager::GetQuestionSeq($qid);
$moveResult = LimeExpressionManager::JumpTo($qseq + 1, true, false, true);
} else {
if (!is_null($gid)) {
$surveyMode = 'group';
LimeExpressionManager::StartSurvey($sid, 'group', $surveyOptions, false, $LEMdebugLevel);
$gseq = LimeExpressionManager::GetGroupSeq($gid);
$moveResult = LimeExpressionManager::JumpTo($gseq + 1, true, false, true);
} else {
$surveyMode = 'survey';
LimeExpressionManager::StartSurvey($sid, 'survey', $surveyOptions, false, $LEMdebugLevel);
$moveResult = LimeExpressionManager::NavigateForwards();
}
}
$qtypes = getqtypelist('', 'array');
if (is_null($moveResult) || is_null($LEM->currentQset) || count($LEM->currentQset) == 0) {
return array('errors' => 1, 'html' => $LEM->gT('Invalid question - probably missing sub-questions or language-specific settings for language ') . $_SESSION['LEMlang']);
}
$surveyname = templatereplace('{SURVEYNAME}');
$out = '<H3>' . $LEM->gT('Logic File for Survey # ') . '[' . $LEM->sid . "]: {$surveyname}</H3>\n";
$out .= "<table border='1'>";
if (is_null($gid) && is_null($qid)) {
$description = templatereplace('{SURVEYDESCRIPTION}');
$errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
if ($description != '') {
$out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("Description:") . "</td><td colspan=2>" . $description . "</td></tr>";
}
$welcome = templatereplace('{WELCOME}');
$errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
if ($welcome != '') {
$out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("Welcome:") . "</td><td colspan=2>" . $welcome . "</td></tr>";
}
$endmsg = templatereplace('{ENDTEXT}');
$errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
if ($endmsg != '') {
$out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("End message:") . "</td><td colspan=2>" . $endmsg . "</td></tr>";
}
$_linkreplace = templatereplace('{URL}');
$errClass = $LEM->em->HasErrors() ? 'LEMerror' : '';
if ($_linkreplace != '') {
$out .= "<tr class='LEMgroup {$errClass}'><td colspan=2>" . $LEM->gT("End URL") . ":</td><td colspan=2>" . $_linkreplace . "</td></tr>";
}
}
$out .= "<tr><th>#</th><th>" . $LEM->gT('Name [ID]') . "</th><th>" . $LEM->gT('Relevance [Validation] (Default)') . "</th><th>" . $LEM->gT('Text [Help] (Tip)') . "</th></tr>\n";
$_gseq = -1;
foreach ($LEM->currentQset as $q) {
$gseq = $q['info']['gseq'];
$gid = $q['info']['gid'];
$qid = $q['info']['qid'];
$qseq = $q['info']['qseq'];
$errorCount = 0;
//////
// SHOW GROUP-LEVEL INFO
//////
if ($gseq != $_gseq) {
$LEM->ParseResultCache = array();
// reset for each group so get proper color coding?
$_gseq = $gseq;
$ginfo = $LEM->gseq2info[$gseq];
$grelevance = '{' . ($ginfo['grelevance'] == '' ? 1 : $ginfo['grelevance']) . '}';
$gtext = trim($ginfo['description']) == '' ? ' ' : $ginfo['description'];
$groupRow = "<tr class='LEMgroup'>" . "<td>G-{$gseq}</td>" . "<td><b>" . $ginfo['group_name'] . "</b><br/>[<a target='_blank' href='{$rooturl}/admin/admin.php?action=orderquestions&sid={$sid}&gid={$gid}'>GID " . $gid . "</a>]</td>" . "<td>" . $grelevance . "</td>" . "<td>" . $gtext . "</td>" . "</tr>\n";
$LEM->ProcessString($groupRow, $qid, NULL, false, 1, 1, false, false);
$out .= $LEM->GetLastPrettyPrintExpression();
if ($LEM->em->HasErrors()) {
++$errorCount;
}
}
//////
// SHOW QUESTION-LEVEL INFO
//////
$mandatory = $q['info']['mandatory'] == 'Y' ? "<span style='color:red'>*</span>" : '';
$type = $q['info']['type'];
$typedesc = $qtypes[$type]['description'];
$sgqas = explode('|', $q['sgqa']);
//.........这里部分代码省略.........
示例10: 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('survey', $iSurveyId);
$event->set('type', 'register');
$event->set('model', '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);
App()->getPluginManager()->dispatchEvent($event);
$aMail['subject'] = $event->get('subject');
$aMail['message'] = $event->get('body');
$sTo = $event->get('to');
$sFrom = $event->get('from');
$sBounce = $event->get('bounce');
$aRelevantAttachments = array();
if (isset($aSurveyInfo['attachments'])) {
$aAttachments = unserialize($aSurveyInfo['attachments']);
if (!empty($aAttachments)) {
if (isset($aAttachments['registration'])) {
LimeExpressionManager::singleton()->loadTokenInformation($aSurveyInfo['sid'], $sToken);
foreach ($aAttachments['registration'] as $aAttachment) {
if (LimeExpressionManager::singleton()->ProcessRelevance($aAttachment['relevance'])) {
$aRelevantAttachments[] = $aAttachment['url'];
}
}
}
}
}
if ($event->get('send', true) == false) {
$this->sMessage = $event->get('message', $this->sMailMessage);
// event can send is own message
if ($event->get('error') == null) {
$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, $aRelevantAttachments)) {
// 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;
}