/** * Load edit email template screen. * @param mixed $iSurveyId * @return */ function index($iSurveyId) { $clang = $this->getController()->lang; $iSurveyId = sanitize_int($iSurveyId); $this->getController()->_css_admin_includes(Yii::app()->getConfig('adminstyleurl') . "superfish.css"); Yii::app()->loadHelper('admin.htmleditor'); Yii::app()->loadHelper('surveytranslator'); Yii::app()->session['FileManagerContext'] = "edit:assessments:{$iSurveyId}"; if (isset($iSurveyId) && getEmailFormat($iSurveyId) == 'html') { $ishtml = true; } else { $ishtml = false; } $grplangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages; $baselang = Survey::model()->findByPk($iSurveyId)->language; array_unshift($grplangs, $baselang); $sEditScript = PrepareEditorScript(false, $this->getController()); $aData['attrib'] = array(); $aData['bplangs'] = array(); $aData['defaulttexts'] = array(); if ($ishtml) { $sEscapeMode = 'html'; } else { $sEscapeMode = 'unescaped'; } foreach ($grplangs as $key => $grouplang) { $aData['bplangs'][$key] = new limesurvey_lang($grouplang); $aData['attrib'][$key] = Surveys_languagesettings::model()->find('surveyls_survey_id = :ssid AND surveyls_language = :ls', array(':ssid' => $iSurveyId, ':ls' => $grouplang)); $aData['defaulttexts'][$key] = templateDefaultTexts($aData['bplangs'][$key], $sEscapeMode); } $aData['surveyid'] = $iSurveyId; $aData['ishtml'] = $ishtml; $aData['grplangs'] = $grplangs; $this->_renderWrappedTemplate('emailtemplates', array('output' => $sEditScript, 'emailtemplates_view'), $aData); }
/** * Defines the customs validation rule lsdefault * * @param mixed $attribute * @param mixed $params */ public function lsdefault($attribute, $params) { $oLanguageTranslator = new Limesurvey_lang($this->surveyls_language); $aDefaultTexts = templateDefaultTexts($oLanguageTranslator, 'unescaped'); $aDefaultTextData = array('surveyls_email_invite_subj' => $aDefaultTexts['invitation_subject'], 'surveyls_email_invite' => $aDefaultTexts['invitation'], 'surveyls_email_remind_subj' => $aDefaultTexts['reminder_subject'], 'surveyls_email_remind' => $aDefaultTexts['reminder'], 'surveyls_email_confirm_subj' => $aDefaultTexts['confirmation_subject'], 'surveyls_email_confirm' => $aDefaultTexts['confirmation'], 'surveyls_email_register_subj' => $aDefaultTexts['registration_subject'], 'surveyls_email_register' => $aDefaultTexts['registration'], 'email_admin_notification_subj' => $aDefaultTexts['admin_notification_subject'], 'email_admin_notification' => $aDefaultTexts['admin_notification'], 'email_admin_responses_subj' => $aDefaultTexts['admin_detailed_notification_subject'], 'email_admin_responses' => $aDefaultTexts['admin_detailed_notification']); if (getEmailFormat($this->surveyls_survey_id) == "html") { $aDefaultTextData['admin_detailed_notification'] = $aDefaultTexts['admin_detailed_notification_css'] . $aDefaultTexts['admin_detailed_notification']; } if (empty($this->{$attribute})) { $this->{$attribute} = $aDefaultTextData[$attribute]; } }
/** * Load edit email template screen. * @param mixed $iSurveyId * @return */ function index($iSurveyId) { $iSurveyId = sanitize_int($iSurveyId); Yii::app()->loadHelper('admin.htmleditor'); Yii::app()->loadHelper('surveytranslator'); Yii::app()->session['FileManagerContext'] = "edit:emailsettings:{$iSurveyId}"; initKcfinder(); if (isset($iSurveyId) && getEmailFormat($iSurveyId) == 'html') { $ishtml = true; } else { $ishtml = false; } $grplangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages; $baselang = Survey::model()->findByPk($iSurveyId)->language; array_unshift($grplangs, $baselang); $sEditScript = PrepareEditorScript(false, $this->getController()); $aData['attrib'] = array(); $aData['bplangs'] = array(); $aData['defaulttexts'] = array(); if ($ishtml) { $sEscapeMode = 'html'; } else { $sEscapeMode = 'unescaped'; } foreach ($grplangs as $key => $grouplang) { $aData['bplangs'][$key] = $grouplang; $aData['attrib'][$key] = SurveyLanguageSetting::model()->find('surveyls_survey_id = :ssid AND surveyls_language = :ls', array(':ssid' => $iSurveyId, ':ls' => $grouplang)); $aData['attrib'][$key]['attachments'] = unserialize($aData['attrib'][$key]['attachments']); $aData['defaulttexts'][$key] = templateDefaultTexts($aData['bplangs'][$key], $sEscapeMode); } $aData['sidemenu']['state'] = false; $surveyinfo = Survey::model()->findByPk($iSurveyId)->surveyinfo; $aData['title_bar']['title'] = $surveyinfo['surveyls_title'] . "(" . gT("ID") . ":" . $iSurveyId . ")"; $aData['surveybar']['savebutton']['form'] = 'frmeditgroup'; $aData['surveybar']['saveandclosebutton']['form'] = 'frmeditgroup'; if (!Permission::model()->hasSurveyPermission($iSurveyId, 'surveycontent', 'update')) { unset($aData['surveybar']['savebutton']); unset($aData['surveybar']['saveandclosebutton']); } $aData['surveybar']['closebutton']['url'] = 'admin/survey/sa/view/surveyid/' . $iSurveyId; // Close button $aData['surveyid'] = $iSurveyId; $aData['ishtml'] = $ishtml; $aData['grplangs'] = $grplangs; $this->_renderWrappedTemplate('emailtemplates', array('output' => $sEditScript, 'emailtemplates_view'), $aData); }
function getEditor($fieldtype, $fieldname, $fieldtext, $surveyID = null, $gID = null, $qID = null, $action = null) { global $defaulthtmleditormode; if (isset($_SESSION['htmleditormode']) && $_SESSION['htmleditormode'] == 'none') { return ''; } if (!isset($_SESSION['htmleditormode']) || $_SESSION['htmleditormode'] != 'inline' && $_SESSION['htmleditormode'] != 'popup') { $htmleditormode = $defaulthtmleditormode; } else { $htmleditormode = $_SESSION['htmleditormode']; } if (($fieldtype == 'email-inv' || $fieldtype == 'email-reg' || $fieldtype == 'email-conf' || $fieldtype == 'email-rem') && getEmailFormat($surveyID) != 'html') { return ''; } if ($htmleditormode == 'popup' || $fieldtype == 'editanswer' || $fieldtype == 'addanswer' || $fieldtype == 'editlabel' || $fieldtype == 'addlabel') { return getPopupEditor($fieldtype, $fieldname, $fieldtext, $surveyID, $gID, $qID, $action); } elseif ($htmleditormode == 'inline') { return getInlineEditor($fieldtype, $fieldname, $fieldtext, $surveyID, $gID, $qID, $action); } else { return ''; } }
function getEditor($fieldtype, $fieldname, $fieldtext, $surveyID = null, $gID = null, $qID = null, $action = null) { global $defaulthtmleditormode; //error_log("TIBO fieldtype=$fieldtype,fieldname=$fieldname,fieldtext=$fieldtext,surveyID=$surveyID,gID=$gID,qID=$qID,action=$action"); if (isset($_SESSION['htmleditormode']) && $_SESSION['htmleditormode'] == 'none') { return ''; } if (!isset($_SESSION['htmleditormode']) || $_SESSION['htmleditormode'] != 'inline' && $_SESSION['htmleditormode'] != 'popup') { $htmleditormode = $defaulthtmleditormode; } else { $htmleditormode = $_SESSION['htmleditormode']; } if (($fieldtype == 'email-inv' || $fieldtype == 'email-reg' || $fieldtype == 'email-conf' || $fieldtype == 'email-rem') && getEmailFormat($surveyID) != 'html') { return ''; } if ($htmleditormode == 'popup' || ($fieldtype == 'editanswer' || $fieldtype == 'addanswer' || $fieldtype == 'editlabel' || $fieldtype == 'addlabel') && preg_match("/^translate/", $action) == 0) { return getPopupEditor($fieldtype, $fieldname, $fieldtext, $surveyID, $gID, $qID, $action); } elseif ($htmleditormode == 'inline') { return getInlineEditor($fieldtype, $fieldname, $fieldtext, $surveyID, $gID, $qID, $action); } else { return ''; } }
/** * Load edit email template screen. * @param mixed $iSurveyId * @return */ function index($iSurveyId) { $iSurveyId = sanitize_int($iSurveyId); App()->getClientScript()->registerPackage('jquery-superfish'); Yii::app()->loadHelper('admin.htmleditor'); Yii::app()->loadHelper('surveytranslator'); Yii::app()->session['FileManagerContext'] = "edit:emailsettings:{$iSurveyId}"; initKcfinder(); if (isset($iSurveyId) && getEmailFormat($iSurveyId) == 'html') { $ishtml = true; } else { $ishtml = false; } $grplangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages; $baselang = Survey::model()->findByPk($iSurveyId)->language; array_unshift($grplangs, $baselang); $sEditScript = PrepareEditorScript(false, $this->getController()); $aData['attrib'] = array(); $aData['bplangs'] = array(); $aData['defaulttexts'] = array(); if ($ishtml) { $sEscapeMode = 'html'; } else { $sEscapeMode = 'unescaped'; } foreach ($grplangs as $key => $grouplang) { $aData['bplangs'][$key] = $grouplang; $aData['attrib'][$key] = SurveyLanguageSetting::model()->find('surveyls_survey_id = :ssid AND surveyls_language = :ls', array(':ssid' => $iSurveyId, ':ls' => $grouplang)); $aData['attrib'][$key]['attachments'] = unserialize($aData['attrib'][$key]['attachments']); $aData['defaulttexts'][$key] = templateDefaultTexts($aData['bplangs'][$key], $sEscapeMode); } $aData['surveyid'] = $iSurveyId; $aData['ishtml'] = $ishtml; $aData['grplangs'] = $grplangs; $this->_renderWrappedTemplate('emailtemplates', array('output' => $sEditScript, 'emailtemplates_view'), $aData); }
/** * 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) { $surveyid = Yii::app()->getConfig('surveyID'); if (isset($_SESSION['survey_' . $surveyid]['s_lang'])) { $thissurvey = getSurveyInfo($surveyid, $_SESSION['survey_' . $surveyid]['s_lang']); } else { $thissurvey = getSurveyInfo($surveyid); } $clienttoken = $_SESSION['survey_' . $surveyid]['token']; $sitename = Yii::app()->getConfig("sitename"); $emailcharset = Yii::app()->getConfig("emailcharset"); // Shift the date due to global timeadjust setting $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust")); // check how many uses the token has left $token = Token::model($surveyid)->findByAttributes(array('token' => $clienttoken)); if ($quotaexit == true) { $token->completed = 'Q'; $token->usesleft--; } else { if ($token->usesleft <= 1) { // Finish the token if (isTokenCompletedDatestamped($thissurvey)) { $token->completed = $today; } else { $token->completed = 'Y'; } if (isset($token->participant_id)) { $slquery = SurveyLink::model()->find('participant_id = :pid AND survey_id = :sid AND token_id = :tid', array(':pid' => $token->participant_id, ':sid' => $surveyid, ':tid' => $token->tid)); if ($slquery) { if (isTokenCompletedDatestamped($thissurvey)) { $slquery->date_completed = $today; } else { // Update the survey_links table if necessary, to protect anonymity, use the date_created field date $slquery->date_completed = $slquery->date_created; } $slquery->save(); } } } $token->usesleft--; } $token->save(); if ($quotaexit == false) { if ($token && trim(strip_tags($thissurvey['email_confirm'])) != "" && $thissurvey['sendconfirmation'] == "Y") { // if($token->completed == "Y" || $token->completed == $today) // { $from = "{$thissurvey['adminname']} <{$thissurvey['adminemail']}>"; $subject = $thissurvey['email_confirm_subj']; $aReplacementVars = array(); $aReplacementVars["ADMINNAME"] = $thissurvey['admin']; $aReplacementVars["ADMINEMAIL"] = $thissurvey['adminemail']; $aReplacementVars['ADMINEMAIL'] = $thissurvey['adminemail']; //Fill with token info, because user can have his information with anonimity control $aReplacementVars["FIRSTNAME"] = $token->firstname; $aReplacementVars["LASTNAME"] = $token->lastname; $aReplacementVars["TOKEN"] = $token->token; // added survey url in replacement vars $surveylink = Yii::app()->createAbsoluteUrl("/survey/index/sid/{$surveyid}", array('lang' => $_SESSION['survey_' . $surveyid]['s_lang'], 'token' => $token->token)); $aReplacementVars['SURVEYURL'] = $surveylink; $attrfieldnames = getAttributeFieldNames($surveyid); foreach ($attrfieldnames as $attr_name) { $aReplacementVars[strtoupper($attr_name)] = $token->{$attr_name}; } $dateformatdatat = getDateFormatData($thissurvey['surveyls_dateformat']); $numberformatdatat = getRadixPointData($thissurvey['surveyls_numberformat']); $redata = array('thissurvey' => $thissurvey); $subject = templatereplace($subject, $aReplacementVars, $redata, '', false, null, array(), true); $subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset); if (getEmailFormat($surveyid) == 'html') { $ishtml = true; } else { $ishtml = false; } $message = $thissurvey['email_confirm']; //$message=ReplaceFields($message, $fieldsarray, true); $message = templatereplace($message, $aReplacementVars, $redata, '', false, null, array(), true); if (!$ishtml) { $message = strip_tags(breakToNewline(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 $sToAddress = validateEmailAddresses($token->email); if ($sToAddress) { $aAttachments = unserialize($thissurvey['attachments']); $aRelevantAttachments = array(); /* * Iterate through attachments and check them for relevance. */ if (isset($aAttachments['confirmation'])) { foreach ($aAttachments['confirmation'] as $aAttachment) { $relevance = $aAttachment['relevance']; // If the attachment is relevant it will be added to the mail. if (LimeExpressionManager::ProcessRelevance($relevance) && file_exists($aAttachment['url'])) { $aRelevantAttachments[] = $aAttachment['url']; } } } SendEmailMessage($message, $subject, $sToAddress, $from, $sitename, $ishtml, null, $aRelevantAttachments); } // } else { // Leave it to send optional confirmation at closed token // } } } }
} } // Add base language too $sqlstring .= "and surveyls_language <> '" . GetBaseLanguageFromSurveyID($surveyid) . "' "; $usquery = "Delete from " . db_table_name('surveys_languagesettings') . " where surveyls_survey_id={$postsid} " . $sqlstring; $usresult = $connect->Execute($usquery) or safe_die("Error deleting obsolete surveysettings<br />" . $usquery . "<br /><br /><strong>" . $connect->ErrorMsg()); // Checked foreach (GetAdditionalLanguagesFromSurveyID($surveyid) as $langname) { if ($langname) { $usquery = "select * from " . db_table_name('surveys_languagesettings') . " where surveyls_survey_id={$postsid} and surveyls_language='" . $langname . "'"; $usresult = $connect->Execute($usquery) or safe_die("Error deleting obsolete surveysettings<br />" . $usquery . "<br /><br /><strong>" . $connect->ErrorMsg()); // Checked if ($usresult->RecordCount() == 0) { $bplang = new limesurvey_lang($langname); $aDefaultTexts = aTemplateDefaultTexts($bplang, 'unescaped'); if (getEmailFormat($surveyid) == "html") { $ishtml = true; $aDefaultTexts['admin_detailed_notification'] = $aDefaultTexts['admin_detailed_notification_css'] . $aDefaultTexts['admin_detailed_notification']; } else { $ishtml = false; } $languagedetails = getLanguageDetails($langname); $usquery = "INSERT INTO " . db_table_name('surveys_languagesettings') . " (surveyls_survey_id, surveyls_language, surveyls_title, " . " surveyls_email_invite_subj, surveyls_email_invite, " . " surveyls_email_remind_subj, surveyls_email_remind, " . " surveyls_email_confirm_subj, surveyls_email_confirm, " . " surveyls_email_register_subj, surveyls_email_register, " . " email_admin_notification_subj, email_admin_notification, " . " email_admin_responses_subj, email_admin_responses, " . " surveyls_dateformat) " . " VALUES ({$postsid}, '" . $langname . "', ''," . db_quoteall($aDefaultTexts['invitation_subject']) . "," . db_quoteall($aDefaultTexts['invitation']) . "," . db_quoteall($aDefaultTexts['reminder_subject']) . "," . db_quoteall($aDefaultTexts['reminder']) . "," . db_quoteall($aDefaultTexts['confirmation_subject']) . "," . db_quoteall($aDefaultTexts['confirmation']) . "," . db_quoteall($aDefaultTexts['registration_subject']) . "," . db_quoteall($aDefaultTexts['registration']) . "," . db_quoteall($aDefaultTexts['admin_notification_subject']) . "," . db_quoteall($aDefaultTexts['admin_notification']) . "," . db_quoteall($aDefaultTexts['admin_detailed_notification_subject']) . "," . db_quoteall($aDefaultTexts['admin_detailed_notification']) . "," . $languagedetails['dateformat'] . ")"; unset($bplang); $usresult = $connect->Execute($usquery) or safe_die("Error deleting obsolete surveysettings<br />" . $usquery . "<br /><br />" . $connect->ErrorMsg()); // Checked } } } if ($usresult) { $surveyselect = getsurveylist();
/** * * Enter description here... * @param $surveyid * @param $type * @param $maxLsrcEmails * @return unknown_type */ function emailSender($surveyid, $type, $maxLsrcEmails = '') { global $publicurl, $maxemails; global $connect, $sitename; global $dbprefix; $surveyid = sanitize_int($surveyid); include "lsrc.config.php"; // wenn maxmails ber den lsrc gegeben wird das nutzen, ansonsten die default werte aus der config.php if ($maxLsrcEmails != '') { $maxemails = $maxLsrcEmails; } switch ($type) { case "custom": break; case "invite": $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", START invite "); if (isset($surveyid) && getEmailFormat($surveyid) == 'html') { $ishtml = true; } else { $ishtml = false; } //$tokenoutput .= ("Sending Invitations"); //if (isset($tokenid)) {$tokenoutput .= " (".("Sending to Token ID").": {$tokenid})";} //$tokenoutput .= "\n"; $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", {$surveyid}, {$type}"); // Texte für Mails aus der Datenbank holen und in die POST Dinger schreiben. Nicht schön aber praktikabel $sql = "SELECT surveyls_language, surveyls_email_invite_subj, surveyls_email_invite " . "FROM {$dbprefix}surveys_languagesettings " . "WHERE surveyls_survey_id = " . $surveyid . " "; //GET SURVEY DETAILS $thissurvey = getSurveyInfo($surveyid); // $connect->SetFetchMode(ADODB_FETCH_ASSOC); // $sqlResult=$connect->Execute($sql); $sqlResult = db_execute_assoc($sql); $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite "); while ($languageRow = $sqlResult->FetchRow()) { $_POST['message_' . $languageRow['surveyls_language']] = $languageRow['surveyls_email_invite']; $_POST['subject_' . $languageRow['surveyls_language']] = $languageRow['surveyls_email_invite_subj']; } // if (isset($_POST['bypassbademails']) && $_POST['bypassbademails'] == 'Y') // { // $SQLemailstatuscondition = " AND emailstatus = 'OK'"; // } // else // { // $SQLemailstatuscondition = ""; // } $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite "); $ctquery = "SELECT * FROM " . db_table_name("tokens_{$surveyid}") . " WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND emailstatus = 'OK' "; if (isset($tokenid)) { $ctquery .= " AND tid='{$tokenid}'"; } //$tokenoutput .= "<!-- ctquery: $ctquery -->\n"; $ctresult = $connect->Execute($ctquery); $ctcount = $ctresult->RecordCount(); $ctfieldcount = $ctresult->FieldCount(); $emquery = "SELECT * "; //if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";} $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite "); $emquery .= " FROM " . db_table_name("tokens_{$surveyid}") . " WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND emailstatus = 'OK' "; if (isset($tokenid)) { $emquery .= " and tid='{$tokenid}'"; } //$tokenoutput .= "\n\n<!-- emquery: $emquery -->\n\n"; $emresult = db_select_limit_assoc($emquery, $maxemails); $emcount = $emresult->RecordCount(); //$tokenoutput .= "<table width='500px' align='center' >\n" ////."\t<tr>\n" //."\t\t<td><font size='1'>\n"; $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselanguage = GetBaseLanguageFromSurveyID($surveyid); array_unshift($surveylangs, $baselanguage); $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite "); foreach ($surveylangs as $language) { $_POST['message_' . $language] = auto_unescape($_POST['message_' . $language]); $_POST['subject_' . $language] = auto_unescape($_POST['subject_' . $language]); if ($ishtml) { $_POST['message_' . $language] = html_entity_decode($_POST['message_' . $language], ENT_QUOTES, $emailcharset); } } $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite "); if ($emcount > 0) { $mailsSend = 0; while ($emrow = $emresult->FetchRow()) { $c = 1; 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']; while (isset($emrow["attribute_{$c}"])) { $fieldsarray["{ATTRIBUTE_{$c}}"] = $emrow["attribute_{$c}"]; $fieldsarray["{TOKEN:ATTRIBUTE_{$c}}"] = $emrow["attribute_{$c}"]; ++$c; } $fieldsarray["{ADMINNAME}"] = $thissurvey['adminname']; $fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail']; $fieldsarray["{SURVEYNAME}"] = $thissurvey['name']; $fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description']; $fieldsarray["{EXPIRY}"] = $thissurvey["expiry"]; $emrow['language'] = trim($emrow['language']); if ($emrow['language'] == '') { $emrow['language'] = $baselanguage; } //if language is not give use default $found = array_search($emrow['language'], $surveylangs); if ($found == false) { $emrow['language'] = $baselanguage; } $from = $thissurvey['adminemail']; 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}"] = "<a href='{$publicurl}/{$surveyid}/lang-" . trim($emrow['language']) . "/tk-{$emrow['token']}'>" . htmlspecialchars("{$publicurl}/{$surveyid}/lang-" . trim($emrow['language']) . "/tk-{$emrow['token']}") . "</a>"; } else { $fieldsarray["{SURVEYURL}"] = "<a href='{$publicurl}/index.php?lang=" . trim($emrow['language']) . "&sid={$surveyid}&token={$emrow['token']}'>" . htmlspecialchars("{$publicurl}/index.php?lang=" . trim($emrow['language']) . "&sid={$surveyid}&token={$emrow['token']}") . "</a>"; } } $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite "); $modsubject = Replacefields($_POST['subject_' . $emrow['language']], $fieldsarray); $modmessage = Replacefields($_POST['message_' . $emrow['language']], $fieldsarray); if (SendEmailMessage($modmessage, $modsubject, $to, $from, $sitename, $ishtml, getBounceEmail($surveyid))) { // Put date into sent //$timeadjust = 0; $today = date("Y-m-d H:i"); $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite Today:" . $today); $udequery = "UPDATE " . db_table_name("tokens_{$surveyid}") . "\n" . "SET sent='{$today}' WHERE tid={$emrow['tid']}"; // $uderesult = $connect->Execute($udequery); $mailsSend++; //$tokenoutput .= "[".("Invitation sent to:")."{$emrow['firstname']} {$emrow['lastname']} ($to)]\n"; } else { //$tokenoutput .= ReplaceFields(("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."", $fieldsarray); if ($n == 1) { $failedAddresses .= "," . $to; } else { $failedAddresses = $to; $n = 1; } } } $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", invite "); if ($ctcount > $emcount) { $lefttosend = $ctcount - $maxemails; } else { $lefttosend = 0; } } else { return "No Mails to send"; } if ($maxemails > 0 && $maxemails != '') { $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; } 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"; $this->debugLsrc("Executing SQL: " . $remSQL); $remResult = db_execute_assoc($remSQL); $remRow = $remResult->FetchRow(); /* Get the reminder count from the row, if we have a row. If * we don't have a row then we set reminderCount to 0 to prevent * queries down below from bombing out. */ $reminderCount = $remRow['remindercount']; if (empty($reminderCount)) { $this->debugLsrc("There are no reminders to send."); $reminderCount = 0; } $this->debugLsrc("wir sind in " . __FUNCTION__ . " Line " . __LINE__ . ", remind " . $remRow['tid'] . "; " . $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 < " . $reminderCount . " " . "ORDER BY tid asc LIMIT 1"; $this->debugLsrc("Executing SQL: " . $sendOnlySQL); if ($sendOnlyResult->RecordCount() > 0) { $sendOnlyRow = $sendOnlyResult->FetchRow(); $starttokenid = $sendOnlyRow['tid']; $this->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); $this->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 . " "; $this->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 .= ("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]); } $SQLemailstatuscondition = " AND emailstatus = 'OK'"; 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 .= "<!-- ctquery: $ctquery -->\n"; $ctresult = $connect->Execute($ctquery) or $this->debugLsrc("Database error!\n" . $connect->ErrorMsg()); $ctcount = $ctresult->RecordCount(); $ctfieldcount = $ctresult->FieldCount(); $emquery = "SELECT * "; //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(); if ($emcount > 0) { while ($emrow = $emresult->FetchRow()) { $c = 1; 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']; while (isset($emrow["attribute_{$c}"])) { $fieldsarray["{ATTRIBUTE_{$c}}"] = $emrow["attribute_{$c}"]; $fieldsarray["{TOKEN:ATTRIBUTE_{$c}}"] = $emrow["attribute_{$c}"]; ++$c; } $fieldsarray["{ADMINNAME}"] = $thissurvey['adminname']; $fieldsarray["{ADMINEMAIL}"] = $thissurvey['adminemail']; $fieldsarray["{SURVEYNAME}"] = $thissurvey['name']; $fieldsarray["{SURVEYDESCRIPTION}"] = $thissurvey['description']; $fieldsarray["{EXPIRY}"] = $thissurvey["expiry"]; $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 = $thissurvey['adminemail']; 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}"] = "<a href='{$publicurl}/{$surveyid}/lang-" . trim($emrow['language']) . "/tk-{$emrow['token']}'>" . htmlspecialchars("{$publicurl}/{$surveyid}/lang-" . trim($emrow['language']) . "/tk-{$emrow['token']}") . "</a>"; } else { $fieldsarray["{SURVEYURL}"] = "<a href='{$publicurl}/index.php?lang=" . trim($emrow['language']) . "&sid={$surveyid}&token={$emrow['token']}'>" . htmlspecialchars("{$publicurl}/index.php?lang=" . trim($emrow['language']) . "&sid={$surveyid}&token={$emrow['token']}") . "</a>"; $_POST['message_' . $emrow['language']] = html_entity_decode($_POST['message_' . $emrow['language']], ENT_QUOTES, $emailcharset); } } $msgsubject = Replacefields($_POST['subject_' . $emrow['language']], $fieldsarray); $sendmessage = Replacefields($_POST['message_' . $emrow['language']], $fieldsarray); if (SendEmailMessage($sendmessage, $msgsubject, $to, $from, $sitename, $ishtml, getBounceEmail($surveyid))) { // Put date into remindersent $today = date("Y-m-d H:i"); $udequery = "UPDATE " . db_table_name("tokens_{$surveyid}") . "\n" . "SET remindersent='{$today}',remindercount = remindercount+1 WHERE tid={$emrow['tid']}"; // $uderesult = $connect->Execute($udequery) or $this->debugLsrc("Could not update tokens{$udequery}" . $connect->ErrorMsg()); //orig: $tokenoutput .= "\t\t\t({$emrow['tid']})[".("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']}]\n"; //$tokenoutput .= "\t\t\t({$emrow['tid']}) [".("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']} ($to)]\n"; $mailsSend++; } else { //$tokenoutput .= ReplaceFields(("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; } else { $lefttosend = 0; } } else { 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; } }
/** * Handle email action */ function email($iSurveyId, $tokenids = null) { $clang = $this->getController()->lang; $iSurveyId = sanitize_int($iSurveyId); if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update')) { Yii::app()->session['flashmessage'] = $clang->gT("You do not have sufficient rights to access this page."); $this->getController()->redirect(array("/admin/survey/sa/view/surveyid/{$iSurveyId}")); } // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}'); if (!$bTokenExists) { self::_newtokentable($iSurveyId); } $aTokenIds = $tokenids; if (empty($tokenids)) { $aTokenIds = Yii::app()->request->getPost('tokenids', false); } if (!empty($aTokenIds)) { $aTokenIds = explode('|', $aTokenIds); $aTokenIds = array_filter($aTokenIds); $aTokenIds = array_map('sanitize_int', $aTokenIds); } $aTokenIds = array_unique(array_filter((array) $aTokenIds)); $sSubAction = Yii::app()->request->getParam('action'); $sSubAction = !in_array($sSubAction, array('email', 'remind')) ? 'email' : $sSubAction; $bEmail = $sSubAction == 'email'; Yii::app()->loadHelper('surveytranslator'); Yii::app()->loadHelper('/admin/htmleditor'); Yii::app()->loadHelper('replacements'); $token = Token::model($iSurveyId)->find(); $aExampleRow = isset($token) ? $token->attributes : array(); $aSurveyLangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages; $sBaseLanguage = Survey::model()->findByPk($iSurveyId)->language; array_unshift($aSurveyLangs, $sBaseLanguage); $aTokenFields = getTokenFieldsAndNames($iSurveyId, true); $iAttributes = 0; $bHtml = getEmailFormat($iSurveyId) == 'html'; $timeadjust = Yii::app()->getConfig("timeadjust"); $aData['thissurvey'] = getSurveyInfo($iSurveyId); foreach ($aSurveyLangs as $sSurveyLanguage) { $aData['thissurvey'][$sSurveyLanguage] = getSurveyInfo($iSurveyId, $sSurveyLanguage); } $aData['surveyid'] = $iSurveyId; $aData['sSubAction'] = $sSubAction; $aData['bEmail'] = $bEmail; $aData['aSurveyLangs'] = $aData['surveylangs'] = $aSurveyLangs; $aData['baselang'] = $sBaseLanguage; $aData['tokenfields'] = array_keys($aTokenFields); $aData['nrofattributes'] = $iAttributes; $aData['examplerow'] = $aExampleRow; $aData['tokenids'] = $aTokenIds; $aData['ishtml'] = $bHtml; $iMaxEmails = Yii::app()->getConfig('maxemails'); if (Yii::app()->request->getPost('bypassbademails') == 'Y') { $SQLemailstatuscondition = "emailstatus = 'OK'"; } else { $SQLemailstatuscondition = "emailstatus <> 'OptOut'"; } if (!Yii::app()->request->getPost('ok')) { if (empty($aData['tokenids'])) { $aTokens = TokenDynamic::model($iSurveyId)->findUninvitedIDs($aTokenIds, 0, $bEmail, $SQLemailstatuscondition); foreach ($aTokens as $aToken) { $aData['tokenids'][] = $aToken; } } $this->_renderWrappedTemplate('token', array('tokenbar', $sSubAction), $aData); } else { $SQLremindercountcondition = ""; $SQLreminderdelaycondition = ""; if (!$bEmail) { if (Yii::app()->request->getPost('maxremindercount') && Yii::app()->request->getPost('maxremindercount') != '' && intval(Yii::app()->request->getPost('maxremindercount')) != 0) { $SQLremindercountcondition = "remindercount < " . intval(Yii::app()->request->getPost('maxremindercount')); } if (Yii::app()->request->getPost('minreminderdelay') && Yii::app()->request->getPost('minreminderdelay') != '' && intval(Yii::app()->request->getPost('minreminderdelay')) != 0) { // Yii::app()->request->getPost('minreminderdelay') in days (86400 seconds per day) $compareddate = dateShift(date("Y-m-d H:i:s", time() - 86400 * intval(Yii::app()->request->getPost('minreminderdelay'))), "Y-m-d H:i", $timeadjust); $SQLreminderdelaycondition = " ( " . " (remindersent = 'N' AND sent < '" . $compareddate . "') " . " OR " . " (remindersent < '" . $compareddate . "'))"; } } $ctresult = TokenDynamic::model($iSurveyId)->findUninvitedIDs($aTokenIds, 0, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); $ctcount = count($ctresult); $emresult = TokenDynamic::model($iSurveyId)->findUninvited($aTokenIds, $iMaxEmails, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); $emcount = count($emresult); foreach ($aSurveyLangs as $language) { // See #08683 : this allow use of {TOKEN:ANYTHING}, directly replaced by {ANYTHING} $sSubject[$language] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", Yii::app()->request->getPost('subject_' . $language)); $sMessage[$language] = preg_replace("/{TOKEN:([A-Z0-9_]+)}/", "{" . "\$1" . "}", Yii::app()->request->getPost('message_' . $language)); if ($bHtml) { $sMessage[$language] = html_entity_decode($sMessage[$language], ENT_QUOTES, Yii::app()->getConfig("emailcharset")); } } $attributes = array_keys(getTokenFieldsAndNames($iSurveyId, true)); $tokenoutput = ""; if ($emcount > 0) { foreach ($emresult as $emrow) { $to = $fieldsarray = 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) { $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" * 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'); if ($event->get('send', true) == false) { // This is some ancient global used for error reporting instead of a return value from the actual mail function.. $maildebug = $event->get('error', $maildebug); $success = $event->get('error') == null; } else { $success = SendEmailMessage($modmessage, $modsubject, $to, $from, Yii::app()->getConfig("sitename"), $bHtml, getBounceEmail($iSurveyId), $aRelevantAttachments, $customheaders); } if ($success) { // Put date into sent $token = Token::model($iSurveyId)->findByPk($emrow['tid']); if ($bEmail) { $tokenoutput .= $clang->gT("Invitation sent to:"); $token->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:"); $token->remindersent = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust")); $token->remindercount++; } $token->save(); //Update central participant survey_links if (!empty($emrow['participant_id'])) { $slquery = SurveyLink::model()->find('participant_id = :pid AND survey_id = :sid AND token_id = :tid', array(':pid' => $emrow['participant_id'], ':sid' => $iSurveyId, ':tid' => $emrow['tid'])); if (!is_null($slquery)) { $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'; } else { $aData['tokenoutput'] .= "<strong class='result success text-success'>" . gT("All emails were sent.") . "<strong>"; } $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); } } }
/** * RPC Routine to send reminder for participants in a survey * Returns array of results of sending * * @access public * @param string $sSessionKey Auth credentials * @param int $iSurveyID ID of the survey that participants belong * @param int $iMinDaysBetween Optional parameter days from last reminder * @param int $iMaxReminders Optional parameter Maximum reminders count * @return array Result of the action */ public function remind_participants($sSessionKey, $iSurveyID, $iMinDaysBetween = null, $iMaxReminders = null) { Yii::app()->loadHelper('admin/token'); if (!$this->_checkSessionKey($sSessionKey)) { return array('status' => 'Invalid session key'); } $oSurvey = Survey::model()->findByPk($iSurveyID); if (!isset($oSurvey)) { return array('status' => 'Error: Invalid survey ID'); } if (Permission::model()->hasSurveyPermission($iSurveyID, 'tokens', 'update')) { $timeadjust = Yii::app()->getConfig("timeadjust"); if (!tableExists("{{tokens_{$iSurveyID}}}")) { return array('status' => 'Error: No token table'); } if (getEmailFormat($iSurveyID) == 'html') { $bHtml = true; } else { $bHtml = false; } $SQLemailstatuscondition = "emailstatus = 'OK'"; $SQLremindercountcondition = ''; $SQLreminderdelaycondition = ''; $iMaxEmails = (int) Yii::app()->getConfig("maxemails"); if (!is_null($iMinDaysBetween)) { $compareddate = dateShift(date("Y-m-d H:i:s", time() - 86400 * $iMinDaysBetween), "Y-m-d H:i", $timeadjust); $SQLreminderdelaycondition = " ((remindersent = 'N' AND sent < '" . $compareddate . "') OR (remindersent < '" . $compareddate . "'))"; } if (!is_null($iMaxReminders)) { $SQLremindercountcondition = "remindercount < " . $iMaxReminders; } $oTokens = TokenDynamic::model($iSurveyID); $aAllTokens = $oTokens->findUninvitedIDs(false, 0, false, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); $iAllTokensCount = count($aAllTokens); unset($aAllTokens); // save some memory before the next query $aResultTokens = $oTokens->findUninvited(false, $iMaxEmails, false, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); if (empty($aResultTokens)) { return array('status' => 'Error: No candidate tokens'); } $aResult = emailTokens($iSurveyID, $aResultTokens, 'remind'); $iLeft = $iAllTokensCount - count($aResultTokens); $aResult['status'] = $iLeft . " left to send"; return $aResult; } else { return array('status' => 'No permission'); } }
/** * 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); $utquery = "UPDATE {$dbprefix}tokens_{$surveyid}\n"; if ($quotaexit == true) { $utquery .= "SET completed='Q'\n"; } elseif (bIsTokenCompletedDatestamped($thissurvey)) { $utquery .= "SET completed='{$today}'\n"; } else { $utquery .= "SET completed='Y'\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']); $fieldsarray["{EXPIRY}"] = convertDateTimeFormat($thissurvey["expiry"], 'Y-m-d H:i:s', $dateformatdatat['phpdate']); $subject = Replacefields($subject, $fieldsarray); if ($thissurvey['private'] == "N") { // Survey is not anonymous, we can translate insertAns placeholder $subject = insertansReplace($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); if ($thissurvey['private'] == "N") { // Survey is not anonymous, we can translate insertAns placeholder $message = insertansReplace($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($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 :-) } } } }
/** * Handle email action */ function email($iSurveyId, $tokenids = null) { /* Check permissions */ if (!hasSurveyPermission($iSurveyId, 'tokens', 'read')) { die("You do not have permission to view this page"); // TODO Replace } $aTokenIds = $tokenids; if (empty($tokenids)) { $aTokenIds = Yii::app()->request->getPost('tokenids', false); } if (!empty($aTokenIds)) { $aTokenIds = explode('|', $aTokenIds); $aTokenIds = array_filter($aTokenIds); $aTokenIds = array_map('sanitize_int', $aTokenIds); } $aTokenIds = array_unique(array_filter((array) $aTokenIds)); // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}'); if (!$bTokenExists) { self::_newtokentable($iSurveyId); } $clang = $this->getController()->lang; $iSurveyId = sanitize_int($iSurveyId); if (!hasSurveyPermission($iSurveyId, 'tokens', 'update')) { die("no permissions"); // TODO Replace } $sSubAction = Yii::app()->request->getParam('action'); $sSubAction = !in_array($sSubAction, array('email', 'remind')) ? 'email' : $sSubAction; $bEmail = $sSubAction == 'email'; Yii::app()->loadHelper('surveytranslator'); Yii::app()->loadHelper('/admin/htmleditor'); Yii::app()->loadHelper('replacements'); $query = Tokens_dynamic::model($iSurveyId)->find(); $aExampleRow = empty($query) ? array() : $query->attributes; $aSurveyLangs = Survey::model()->findByPk($iSurveyId)->additionalLanguages; $sBaseLanguage = Survey::model()->findByPk($iSurveyId)->language; array_unshift($aSurveyLangs, $sBaseLanguage); $aTokenFields = getTokenFieldsAndNames($iSurveyId, true); $iAttributes = 0; $bHtml = getEmailFormat($iSurveyId) == 'html'; $timeadjust = Yii::app()->getConfig("timeadjust"); $aData['thissurvey'] = getSurveyInfo($iSurveyId); $aData['surveyid'] = $iSurveyId; $aData['sSubAction'] = $sSubAction; $aData['bEmail'] = $bEmail; $aData['aSurveyLangs'] = $aData['surveylangs'] = $aSurveyLangs; $aData['baselang'] = $sBaseLanguage; $aData['tokenfields'] = $aTokenFields; $aData['nrofattributes'] = $iAttributes; $aData['examplerow'] = $aExampleRow; $aData['tokenids'] = $aTokenIds; $aData['ishtml'] = $bHtml; $iMaxEmails = Yii::app()->getConfig('maxemails'); if (Yii::app()->request->getPost('bypassbademails') == 'Y') { $SQLemailstatuscondition = "emailstatus = 'OK'"; } else { $SQLemailstatuscondition = "emailstatus <> 'OptOut'"; } if (!Yii::app()->request->getPost('ok')) { if (empty($aData['tokenids'])) { $aTokens = Tokens_dynamic::model($iSurveyId)->findUninvited($aTokenIds, 0, $bEmail, $SQLemailstatuscondition); foreach ($aTokens as $aToken) { $aData['tokenids'][] = $aToken['tid']; } } $this->_renderWrappedTemplate('token', array('tokenbar', $sSubAction), $aData); } else { $SQLremindercountcondition = ""; $SQLreminderdelaycondition = ""; if (!$bEmail) { if (Yii::app()->request->getPost('maxremindercount') && Yii::app()->request->getPost('maxremindercount') != '' && intval(Yii::app()->request->getPost('maxremindercount')) != 0) { $SQLremindercountcondition = "remindercount < " . intval(Yii::app()->request->getPost('maxremindercount')); } if (Yii::app()->request->getPost('minreminderdelay') && Yii::app()->request->getPost('minreminderdelay') != '' && intval(Yii::app()->request->getPost('minreminderdelay')) != 0) { // Yii::app()->request->getPost('minreminderdelay') in days (86400 seconds per day) $compareddate = dateShift(date("Y-m-d H:i:s", time() - 86400 * intval(Yii::app()->request->getPost('minreminderdelay'))), "Y-m-d H:i", $timeadjust); $SQLreminderdelaycondition = " ( " . " (remindersent = 'N' AND sent < '" . $compareddate . "') " . " OR " . " (remindersent < '" . $compareddate . "'))"; } } $ctresult = Tokens_dynamic::model($iSurveyId)->findUninvited($aTokenIds, 0, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); $ctcount = count($ctresult); $emresult = Tokens_dynamic::model($iSurveyId)->findUninvited($aTokenIds, $iMaxEmails, $bEmail, $SQLemailstatuscondition, $SQLremindercountcondition, $SQLreminderdelaycondition); $emcount = count($emresult); foreach ($aSurveyLangs as $language) { $_POST['message_' . $language] = autoUnescape(Yii::app()->request->getPost('message_' . $language)); $_POST['subject_' . $language] = autoUnescape(Yii::app()->request->getPost('subject_' . $language)); if ($bHtml) { $_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); } } }
/** * 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; }
/** * register::index() * Process register form data and take appropriate action * @return */ function actionIndex($iSurveyID = null) { Yii::app()->loadHelper('database'); Yii::app()->loadHelper('replacements'); $sLanguage = Yii::app()->request->getParam('lang', ''); if ($iSurveyID == null) { $iSurveyID = Yii::app()->request->getPost('sid'); } if (!$iSurveyID) { $this->redirect(Yii::app()->baseUrl); } if ($sLanguage == "") { $sBaseLanguage = Survey::model()->findByPk($iSurveyID)->language; } else { $sBaseLanguage = $sLanguage; } Yii::import('application.libraries.Limesurvey_lang'); Yii::app()->lang = new Limesurvey_lang($sBaseLanguage); $clang = Yii::app()->lang; $thissurvey = getSurveyInfo($iSurveyID, $sBaseLanguage); $register_errormsg = ""; // Check the security question's answer if (function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $thissurvey['usecaptcha'])) { if (!isset($_POST['loadsecurity']) || !isset($_SESSION['survey_' . $iSurveyID]['secanswer']) || Yii::app()->request->getPost('loadsecurity') != $_SESSION['survey_' . $iSurveyID]['secanswer']) { $register_errormsg .= $clang->gT("The answer to the security question is incorrect.") . "<br />\n"; } } //Check that the email is a valid style address if (!validateEmailAddress(Yii::app()->request->getPost('register_email'))) { $register_errormsg .= $clang->gT("The email you used is not valid. Please try again."); } // Check for additional fields $attributeinsertdata = array(); foreach (GetParticipantAttributes($iSurveyID) as $field => $data) { if (empty($data['show_register']) || $data['show_register'] != 'Y') { continue; } $value = sanitize_xss_string(Yii::app()->request->getPost('register_' . $field)); if (trim($value) == '' && $data['mandatory'] == 'Y') { $register_errormsg .= sprintf($clang->gT("%s cannot be left empty"), $thissurvey['attributecaptions'][$field]); } $attributeinsertdata[$field] = $value; } if ($register_errormsg != "") { $_SESSION['survey_' . $iSurveyID]['register_errormsg'] = $register_errormsg; $this->redirect($this->createUrl("survey/index/sid/{$iSurveyID}", array('lang' => $sBaseLanguage))); } //Check if this email already exists in token database $oToken = TokenDynamic::model($iSurveyID)->find('email=:email', array(':email' => Yii::app()->request->getPost('register_email'))); if ($oToken) { $register_errormsg = $clang->gT("The email you used has already been registered."); $_SESSION['survey_' . $iSurveyID]['register_errormsg'] = $register_errormsg; $this->redirect($this->createUrl("survey/index/sid/{$iSurveyID}", array('lang' => $sBaseLanguage))); //include "index.php"; //exit; } $mayinsert = false; // 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(); }
$fieldsarray["{SID}"]=$fieldsarray["{SURVEYID}"]=$surveyid; $fieldsarray["{SURVEYNAME}"]=$thissurvey["surveyls_title"]; foreach ($attributes as $attributefield=>$attributedescription) { $fieldsarray['{'.strtoupper($attributefield).'}']=$emrow[$attributefield]; } $emrow['language']=trim($emrow['language']); if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give 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) { $fieldsarray["{OPTOUTURL}"]="$publicurl/optout.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}"; if ( $modrewrite ) { $fieldsarray["{SURVEYURL}"]="$publicurl/$surveyid/lang-".trim($emrow['language'])."/tk-{$emrow['token']}"; }
/** * register::index() * Process register form data and take appropriate action * @return */ function actionIndex($surveyid = null) { Yii::app()->loadHelper('database'); Yii::app()->loadHelper('replacements'); $postlang = Yii::app()->request->getPost('lang'); if ($surveyid == null) { $surveyid = Yii::app()->request->getPost('sid'); } if (!$surveyid) { Yii::app()->request->redirect(Yii::app()->baseUrl); } // Get passed language from form, so that we dont loose this! if (!isset($postlang) || $postlang == "" || !$postlang) { $baselang = Survey::model()->findByPk($surveyid)->language; Yii::import('application.libraries.Limesurvey_lang'); Yii::app()->lang = new Limesurvey_lang($baselang); $clang = Yii::app()->lang; } else { Yii::import('application.libraries.Limesurvey_lang'); Yii::app()->lang = new Limesurvey_lang($postlang); $clang = Yii::app()->lang; $baselang = $postlang; } $thissurvey = getSurveyInfo($surveyid, $baselang); $register_errormsg = ""; // Check the security question's answer if (function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $thissurvey['usecaptcha'])) { if (!isset($_POST['loadsecurity']) || !isset($_SESSION['survey_' . $surveyid]['secanswer']) || Yii::app()->request->getPost('loadsecurity') != $_SESSION['survey_' . $surveyid]['secanswer']) { $register_errormsg .= $clang->gT("The answer to the security question is incorrect.") . "<br />\n"; } } //Check that the email is a valid style address if (!validateEmailAddress(Yii::app()->request->getPost('register_email'))) { $register_errormsg .= $clang->gT("The email you used is not valid. Please try again."); } // Check for additional fields $attributeinsertdata = array(); foreach (GetParticipantAttributes($surveyid) as $field => $data) { if (empty($data['show_register']) || $data['show_register'] != 'Y') { continue; } $value = sanitize_xss_string(Yii::app()->request->getPost('register_' . $field)); if (trim($value) == '' && $data['mandatory'] == 'Y') { $register_errormsg .= sprintf($clang->gT("%s cannot be left empty"), $thissurvey['attributecaptions'][$field]); } $attributeinsertdata[$field] = $value; } if ($register_errormsg != "") { $_SESSION['survey_' . $surveyid]['register_errormsg'] = $register_errormsg; Yii::app()->request->redirect(Yii::app()->createUrl('survey/index/sid/' . $surveyid)); } //Check if this email already exists in token database $query = "SELECT email FROM {{tokens_{$surveyid}}}\n" . "WHERE email = '" . sanitize_email(Yii::app()->request->getPost('register_email')) . "'"; $usrow = Yii::app()->db->createCommand($query)->queryRow(); if ($usrow) { $register_errormsg = $clang->gT("The email you used has already been registered."); $_SESSION['survey_' . $surveyid]['register_errormsg'] = $register_errormsg; Yii::app()->request->redirect(Yii::app()->createUrl('survey/index/sid/' . $surveyid)); //include "index.php"; //exit; } $mayinsert = false; // Get the survey settings for token length //$this->load->model("surveys_model"); $tlresult = Survey::model()->findAllByAttributes(array("sid" => $surveyid)); if (isset($tlresult[0])) { $tlrow = $tlresult[0]; } else { $tlrow = $tlresult; } $tokenlength = $tlrow['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); $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(); }
/** * 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; global $surveyid; global $clienttoken; $clang = Yii::app()->lang; $sitename = Yii::app()->getConfig("sitename"); $emailcharset = Yii::app()->getConfig("emailcharset"); // Shift the date due to global timeadjust setting $today = dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust")); // check how many uses the token has left $usesquery = "SELECT usesleft, participant_id, tid FROM {{tokens_{$surveyid}}} WHERE token='" . $clienttoken . "'"; $usesresult = dbExecuteAssoc($usesquery); $usesrow = $usesresult->read(); if (isset($usesrow)) { $usesleft = $usesrow['usesleft']; $participant_id = $usesrow['participant_id']; $token_id = $usesrow['tid']; } $utquery = "UPDATE {{tokens_{$surveyid}}}\n"; if ($quotaexit == true) { $utquery .= "SET completed='Q', usesleft=usesleft-1\n"; } elseif (isTokenCompletedDatestamped($thissurvey)) { if (isset($usesleft) && $usesleft <= 1) { $utquery .= "SET usesleft=usesleft-1, completed='{$today}'\n"; if (!empty($participant_id)) { //Update the survey_links table if necessary $slquery = Survey_links::model()->find('participant_id = "' . $participant_id . '" AND survey_id = ' . $surveyid . ' AND token_id = ' . $token_id); $slquery->date_completed = $today; $slquery->save(); } } else { $utquery .= "SET usesleft=usesleft-1\n"; } } else { if (isset($usesleft) && $usesleft <= 1) { $utquery .= "SET usesleft=usesleft-1, completed='Y'\n"; if (!empty($participant_id)) { //Update the survey_links table if necessary, to protect anonymity, use the date_created field date $slquery = Survey_links::model()->find('participant_id = "' . $participant_id . '" AND survey_id = ' . $surveyid . ' AND token_id = ' . $token_id); $slquery->date_completed = $slquery->date_created; $slquery->save(); } } else { $utquery .= "SET usesleft=usesleft-1\n"; } } $utquery .= "WHERE token='" . $clienttoken . "'"; $utresult = dbExecuteAssoc($utquery) or safeDie("Couldn't update tokens table!<br />\n{$utquery}<br />\n"); //Checked if ($quotaexit == false) { // TLR change to put date into sent and completed $cnfquery = "SELECT * FROM {{tokens_{$surveyid}}} WHERE token='" . $clienttoken . "' AND completed!='N' AND completed!=''"; $cnfresult = dbExecuteAssoc($cnfquery); //Checked $cnfrow = $cnfresult->read(); 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); $subject = html_entity_decode($subject, ENT_QUOTES, $emailcharset); if (getEmailFormat($surveyid) == 'html') { $ishtml = true; } else { $ishtml = false; } if (trim(strip_tags($thissurvey['email_confirm'])) != "" && $thissurvey['sendconfirmation'] == "Y") { $message = $thissurvey['email_confirm']; $message = ReplaceFields($message, $fieldsarray, true); if (!$ishtml) { $message = strip_tags(breakToNewline(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 (validateEmailAddress($cnfrow['email'])) { SendEmailMessage($message, $subject, $to, $from, $sitename, $ishtml); } } else { //There is nothing in the message or "Send confirmation emails" is set to "No" , so don't send a confirmation email //This section only here as placeholder to indicate new feature :-) } } } }
function getEditor($fieldtype, $fieldname, $fieldtext, $surveyID = null, $gID = null, $qID = null, $action = null) { initKcfinder(); //error_log("TIBO fieldtype=$fieldtype,fieldname=$fieldname,fieldtext=$fieldtext,surveyID=$surveyID,gID=$gID,qID=$qID,action=$action"); $session =& Yii::app()->session; if ($session['htmleditormode'] && $session['htmleditormode'] == 'none') { return ''; } if (!$session['htmleditormode'] || $session['htmleditormode'] != 'inline' && $session['htmleditormode'] != 'popup') { $htmleditormode = Yii::app()->getConfig('defaulthtmleditormode'); } else { $htmleditormode = $session['htmleditormode']; } if ($surveyID && getEmailFormat($surveyID) != 'html' && substr($fieldtype, 0, 6) === "email-") { return ''; } if ($htmleditormode == 'popup' || ($fieldtype == 'editanswer' || $fieldtype == 'addanswer' || $fieldtype == 'editlabel' || $fieldtype == 'addlabel') && preg_match("/^translate/", $action) == 0) { return getPopupEditor($fieldtype, $fieldname, $fieldtext, $surveyID, $gID, $qID, $action); } elseif ($htmleditormode == 'inline') { return getInlineEditor($fieldtype, $fieldname, $fieldtext, $surveyID, $gID, $qID, $action); } else { return ''; } }
public function beforeSurveyPage() { $oEvent = $this->event; $iSurveyId = $oEvent->get('surveyId'); self::__init(); $bUse=$this->get('bUse', 'Survey', $iSurveyId); if(is_null($bUse)) $bUse=$this->bUse; if(!$bUse) return; $sToken= Yii::app()->request->getParam('token'); if($iSurveyId && !$sToken)// Test invalid token ? { // Get the survey model $oSurvey=Survey::model()->find("sid=:sid",array(':sid'=>$iSurveyId)); if($oSurvey && $oSurvey->active=="Y" && $oSurvey->allowregister=="Y" && tableExists("tokens_{$iSurveyId}")) { // Fill parameters $bShowTokenForm=$this->get('bShowTokenForm', 'Survey', $iSurveyId); if(is_null($bShowTokenForm)) $bShowTokenForm=$this->bShowTokenForm; $bShowTokenForm=$this->get('use', 'Survey', $iSurveyId); if(is_null($bShowTokenForm)) $bShowTokenForm=$this->bUse; Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicurl')."plugins/replaceRegister/css/register.css"); // We can go $sLanguage = Yii::app()->request->getParam('lang',''); if ($sLanguage=="" ) { $sLanguage = Survey::model()->findByPk($iSurveyId)->language; } $aSurveyInfo=getSurveyInfo($iSurveyId,$sLanguage); $sAction= Yii::app()->request->getParam('action','view') ; $sHtmlRegistererror=""; $sHtmlRegistermessage1=gT("You must be registered to complete this survey");; $sHtmlRegistermessage2=gT("You may register for this survey if you wish to take part.")."<br />\n".gT("Enter your details below, and an email containing the link to participate in this survey will be sent immediately."); $sHtmlRegisterform=""; $sHtml=""; $bShowForm=true; $bValidMail=false; $bTokenCreate=true; $aExtraParams=array(); $aRegisterError=array(); $sR_email= Yii::app()->request->getPost('register_email'); $sR_firstname= sanitize_xss_string(Yii::app()->request->getPost('register_firstname',"")); $sR_lastname= sanitize_xss_string(Yii::app()->request->getPost('register_lastname',"")); $sR_lastname= sanitize_xss_string(Yii::app()->request->getPost('register_lastname',"")); $aR_attribute=array(); $aR_attributeGet=array(); $aExtraParams=array(); $aMail=array(); foreach ($aSurveyInfo['attributedescriptions'] as $field => $aAttribute) { if (!empty($aAttribute['show_register']) && $aAttribute['show_register'] == 'Y') { $aR_attribute[$field]= sanitize_xss_string(Yii::app()->request->getPost('register_'.$field),"");// Need to be filtered ? } elseif($aAttribute['description']==sanitize_paranoid_string($aAttribute['description']) && trim(Yii::app()->request->getQuery($aAttribute['description'],"")) ) { $aR_attributeGet[$field]= sanitize_xss_string(trim(Yii::app()->request->getQuery($aAttribute['description'],"")));// Allow prefill with URL (TODO: add an option) $aExtraParams[$aAttribute['description']]=sanitize_xss_string(trim(Yii::app()->request->getParam($aAttribute['description'],""))); } } if($sAction=='register' && !is_null($sR_email) && Yii::app()->request->getPost('changelang')!='changelang') { $bShowForm=false; // captcha $sLoadsecurity=Yii::app()->request->getPost('loadsecurity'); $sSecAnswer=(isset($_SESSION['survey_'.$iSurveyId]['secanswer']))?$_SESSION['survey_'.$iSurveyId]['secanswer']:""; $bShowForm=false; $bNoError=true; // Copy paste RegisterController if($sR_email) { //Check that the email is a valid style addressattribute_2 if (!validateEmailAddress($sR_email)) { $aRegisterError[]= gT("The email you used is not valid. Please try again."); } } else { $aRegisterError[]= gT("The email you used is not valid. Please try again.");// Empty email } // Fill and validate mandatory extra attribute foreach ($aSurveyInfo['attributedescriptions'] as $field => $aAttribute) { if (!empty($aAttribute['show_register']) && $aAttribute['show_register'] == 'Y' && $aAttribute['mandatory'] == 'Y' && ($aR_attribute[$field]=="" || is_null($aR_attribute[$field])) ) { $aRegisterError[]= sprintf(gT("%s cannot be left empty").".", $aSurveyInfo['attributecaptions'][$field]); } } // Check the security question's answer : at end because the security question is the last one if (function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen',$aSurveyInfo['usecaptcha']) ) { if (!$sLoadsecurity || !$sSecAnswer || $sLoadsecurity != $sSecAnswer) { $aRegisterError[]= gT("The answer to the security question is incorrect."); } } if(count($aRegisterError)==0) { //Check if this email already exists in token database $oToken=TokenDynamic::model($iSurveyId)->find('email=:email',array(':email'=>$sR_email)); if ($oToken) { if($oToken->usesleft<1 && $aSurveyInfo['alloweditaftercompletion']!='Y') { $aRegisterError="The e-mail address you have entered is already registered an the questionnaire has been completed."; } elseif(strtolower(substr(trim($oToken->emailstatus),0,6))==="optout")// And global blacklisting ? { $aRegisterError="This email address is already registered but someone ask to don't receive new email again."; } elseif(!$oToken->emailstatus && $oToken->emailstatus!="OK") { $aRegisterError="This email address is already registered but the email adress was bounced."; } else { $iTokenId=$oToken->tid; $aMail['subject']=$aSurveyInfo['email_register_subj']; $aMail['message']=$aSurveyInfo['email_register']; $aMail['information']="The address you have entered is already registered. An email has been sent to this address with a link that gives you access to the survey."; // Did we update the token ? Setting ? } } else { $oToken= Token::create($iSurveyId); $oToken->firstname = $sR_firstname; $oToken->lastname = $sR_lastname; $oToken->email = $sR_email; $oToken->emailstatus = 'OK'; $oToken->language = $sLanguage; $oToken->setAttributes($aR_attribute); $oToken->setAttributes($aR_attributeGet);// Need an option if ($aSurveyInfo['startdate']) { $oToken->validfrom = $aSurveyInfo['startdate']; } if ($aSurveyInfo['expires']) { $oToken->validuntil = $aSurveyInfo['expires']; } $oToken->save(); $iTokenId=$oToken->tid; TokenDynamic::model($iSurveyId)->createToken($iTokenId);// Review if really create a token $aMail['subject']=$aSurveyInfo['email_register_subj']; $aMail['message']=$aSurveyInfo['email_register']; $aMail['information']=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."); } } } if($aMail && $oToken) { $aReplacementFields=array(); $aReplacementFields["{ADMINNAME}"]=$aSurveyInfo['adminname']; $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(); 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(); } if($bShowForm || count($aRegisterError)) { // Language ? if(count($aRegisterError)==1){ $sHtmlRegistererror="<p class='error error-register'><strong>{$aRegisterError[0]}</strong></p>"; }elseif(count($aRegisterError)>1){ $sHtmlRegistererror="<ul class='error error-register error-list'>"; foreach ($aRegisterError as $sRegisterError) $sHtmlRegistererror.="<li><strong>{$sRegisterError}</strong></li>"; $sHtmlRegistererror.="</ul>"; } $aExtraParams['action']='register'; $aExtraParams['lang']=$sLanguage; $sHtmlRegisterform = CHtml::form(Yii::app()->createUrl("/survey/index/sid/{$iSurveyId}",$aExtraParams), 'post'); $sHtmlRegisterform.="<table class='register'><tbody>\n"; $sHtmlRegisterform.= "<tr><th><label for='register_firstname'>".gT("First name") . "</label></th><td>".CHtml::textField('register_firstname',htmlentities($sR_firstname, ENT_QUOTES, 'UTF-8'),array('class'=>'text'))."</td></tr>\n"; $sHtmlRegisterform.= "<tr><th><label for='register_lastname'>".gT("Last name") . "</label></th><td>".CHtml::textField('register_lastname',htmlentities($sR_lastname, ENT_QUOTES, 'UTF-8'),array('class'=>'text'))."</td></tr>\n"; $sHtmlRegisterform.= "<tr class='mandatory'><th><label for='register_email'>".gT("Email address") . "</label></th><td>".CHtml::textField('register_email',htmlentities($sR_email, ENT_QUOTES, 'UTF-8'),array('class'=>'text'))."</td></tr>\n"; // Extra attribute foreach ($aSurveyInfo['attributedescriptions'] as $field => $aAttribute) { if (!empty($aAttribute['show_register']) && $aAttribute['show_register'] == 'Y') { $sHtmlRegisterform.= "<tr".($aAttribute['mandatory'] == 'Y' ? " class='mandatory'" : '')."><th><label for='register_{$field}'>".$aSurveyInfo['attributecaptions'][$field].($aAttribute['mandatory'] == 'Y' ? ' *' : '')."</label></th><td>".CHtml::textField('register_'.$field,htmlentities($aR_attribute[$field], ENT_QUOTES, 'UTF-8'),array('class'=>'text'))."</td></tr>\n"; } } if (function_exists("ImageCreate") && isCaptchaEnabled('registrationscreen', $aSurveyInfo['usecaptcha'])) $sHtmlRegisterform.= "<tr><th><label for='loadsecurity'>" . gT("Security question") . "</label></th><td><img src='".Yii::app()->getController()->createUrl("/verification/image/sid/{$iSurveyId}")."' alt='' /><input type='text' size='5' maxlength='3' name='loadsecurity' id='loadsecurity' value='' /></td></tr>\n"; $sHtmlRegisterform.= "<tr><td></td><td>".CHtml::submitButton(gT("Continue"))."</td></tr>"; $sHtmlRegisterform.= "</tbody></table>\n"; $sHtmlRegisterform.= makeLanguageChangerSurvey($sLanguage);// Need to be inside the form $sHtmlRegisterform.= CHtml::endForm(); } $sTemplatePath=$aData['templatedir'] = getTemplatePath($aSurveyInfo['template']); ob_start(function($buffer, $phase) { App()->getClientScript()->render($buffer); App()->getClientScript()->reset(); return $buffer; }); ob_implicit_flush(false); sendCacheHeaders(); doHeader(); // Get the register.pstpl file content, but remplace default by own string $sHtmlRegister=file_get_contents($sTemplatePath.'/register.pstpl'); $sHtmlRegister= str_replace("{REGISTERERROR}",$sHtmlRegistererror,$sHtmlRegister); $sHtmlRegister= str_replace("{REGISTERMESSAGE1}",$sHtmlRegistermessage1,$sHtmlRegister); $sHtmlRegister= str_replace("{REGISTERMESSAGE2}",$sHtmlRegistermessage2,$sHtmlRegister); $sHtmlRegister= str_replace("{REGISTERFORM}",$sHtmlRegisterform,$sHtmlRegister); $aData['thissurvey'] = $aSurveyInfo; echo templatereplace(file_get_contents($sTemplatePath.'/startpage.pstpl'),array(), $aData); echo templatereplace(file_get_contents($sTemplatePath.'/survey.pstpl'),array(), $aData); echo templatereplace($sHtmlRegister); echo templatereplace(file_get_contents($sTemplatePath.'/endpage.pstpl'),array(), $aData); doFooter(); ob_flush(); App()->end(); } } }
/** * Sends email to tokens - invitation and reminders * * @param mixed $iSurveyID * @param array $aResultTokens * @param string $sType type of notification invite|register|remind * @return array of results */ function emailTokens($iSurveyID, $aResultTokens, $sType) { Yii::app()->loadHelper('common'); $oSurvey = Survey::model()->findByPk($iSurveyID); if (getEmailFormat($iSurveyID) == 'html') { $bHtml = true; } else { $bHtml = false; } $attributes = array_keys(getTokenFieldsAndNames($iSurveyID)); $oSurveyLocale = SurveyLanguageSetting::model()->findAllByAttributes(array('surveyls_survey_id' => $iSurveyID)); $oTokens = Token::model($iSurveyID); $aSurveyLangs = $oSurvey->additionalLanguages; array_unshift($aSurveyLangs, $oSurvey->language); //Convert result to associative array to minimize SurveyLocale access attempts foreach ($oSurveyLocale as $rows) { $oTempObject = array(); foreach ($rows as $k => $v) { $oTempObject[$k] = $v; } $aSurveyLocaleData[$rows['surveyls_language']] = $oTempObject; } foreach ($aResultTokens as $aTokenRow) { //Select language $aTokenRow['language'] = trim($aTokenRow['language']); $found = array_search($aTokenRow['language'], $aSurveyLangs); if ($aTokenRow['language'] == '' || $found == false) { $aTokenRow['language'] = $oSurvey['language']; } $sTokenLanguage = $aTokenRow['language']; //Build recipient $to = array(); $aEmailaddresses = explode(';', $aTokenRow['email']); foreach ($aEmailaddresses as $sEmailaddress) { $to[] = $aTokenRow['firstname'] . " " . $aTokenRow['lastname'] . " <{$sEmailaddress}>"; } //Populate attributes $fieldsarray["{SURVEYNAME}"] = $aSurveyLocaleData[$sTokenLanguage]['surveyls_title']; if ($fieldsarray["{SURVEYNAME}"] == '') { $fieldsarray["{SURVEYNAME}"] = $aSurveyLocaleData[$oSurvey['language']]['surveyls_title']; } $fieldsarray["{SURVEYDESCRIPTION}"] = $aSurveyLocaleData[$sTokenLanguage]['surveyls_description']; if ($fieldsarray["{SURVEYDESCRIPTION}"] == '') { $fieldsarray["{SURVEYDESCRIPTION}"] = $aSurveyLocaleData[$oSurvey['language']]['surveyls_description']; } $fieldsarray["{ADMINNAME}"] = $oSurvey['admin']; $fieldsarray["{ADMINEMAIL}"] = $oSurvey['adminemail']; $from = $fieldsarray["{ADMINNAME}"] . ' <' . $fieldsarray["{ADMINEMAIL}"] . '>'; if ($from == '') { $from = Yii::app()->getConfig('siteadminemail'); } foreach ($attributes as $attributefield) { $fieldsarray['{' . strtoupper($attributefield) . '}'] = $aTokenRow[$attributefield]; $fieldsarray['{TOKEN:' . strtoupper($attributefield) . '}'] = $aTokenRow[$attributefield]; } //create urls $fieldsarray["{OPTOUTURL}"] = Yii::app()->getController()->createAbsoluteUrl("/optout/tokens/langcode/" . trim($aTokenRow['language']) . "/surveyid/{$iSurveyID}/token/{$aTokenRow['token']}"); $fieldsarray["{OPTINURL}"] = Yii::app()->getController()->createAbsoluteUrl("/optin/tokens/langcode/" . trim($aTokenRow['language']) . "/surveyid/{$iSurveyID}/token/{$aTokenRow['token']}"); $fieldsarray["{SURVEYURL}"] = Yii::app()->getController()->createAbsoluteUrl("/survey/index/sid/{$iSurveyID}/token/{$aTokenRow['token']}/lang/" . trim($aTokenRow['language']) . "/"); if ($bHtml) { foreach (array('OPTOUT', 'OPTIN', 'SURVEY') as $key) { $url = $fieldsarray["{{$key}URL}"]; $fieldsarray["{{$key}URL}"] = "<a href='{$url}'>" . htmlspecialchars($url) . '</a>'; if ($key == 'SURVEY') { $barebone_link = $url; } } } //mail headers $customheaders = array('1' => "X-surveyid: " . $iSurveyID, '2' => "X-tokenid: " . $fieldsarray["{TOKEN}"]); global $maildebug; //choose appriopriate email message if ($sType == 'invite') { $sSubject = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_invite_subj']; $sMessage = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_invite']; } else { if ($sType == 'register') { $sSubject = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_register_subj']; $sMessage = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_register']; } else { $sSubject = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_remind_subj']; $sMessage = $aSurveyLocaleData[$sTokenLanguage]['surveyls_email_remind']; } } $modsubject = Replacefields($sSubject, $fieldsarray); $modmessage = Replacefields($sMessage, $fieldsarray); if (isset($barebone_link)) { $modsubject = str_replace("@@SURVEYURL@@", $barebone_link, $modsubject); $modmessage = str_replace("@@SURVEYURL@@", $barebone_link, $modmessage); } if (isset($aTokenRow['validfrom']) && trim($aTokenRow['validfrom']) != '' && convertDateTimeFormat($aTokenRow['validfrom'], 'Y-m-d H:i:s', 'U') * 1 > date('U') * 1) { $aResult[$aTokenRow['tid']] = array('name' => $fieldsarray["{FIRSTNAME}"] . " " . $fieldsarray["{LASTNAME}"], 'email' => $fieldsarray["{EMAIL}"], 'status' => 'fail', 'error' => 'Token not valid yet'); } elseif (isset($aTokenRow['validuntil']) && trim($aTokenRow['validuntil']) != '' && convertDateTimeFormat($aTokenRow['validuntil'], 'Y-m-d H:i:s', 'U') * 1 < date('U') * 1) { $aResult[$aTokenRow['tid']] = array('name' => $fieldsarray["{FIRSTNAME}"] . " " . $fieldsarray["{LASTNAME}"], 'email' => $fieldsarray["{EMAIL}"], 'status' => 'fail', 'error' => 'Token not valid anymore'); } else { if (SendEmailMessage($modmessage, $modsubject, $to, $from, Yii::app()->getConfig("sitename"), $bHtml, getBounceEmail($iSurveyID), null, $customheaders)) { $aResult[$aTokenRow['tid']] = array('name' => $fieldsarray["{FIRSTNAME}"] . " " . $fieldsarray["{LASTNAME}"], 'email' => $fieldsarray["{EMAIL}"], 'status' => 'OK'); if ($sType == 'invite' || $sType == 'register') { $oTokens->updateByPk($aTokenRow['tid'], array('sent' => dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust")))); } if ($sType == 'remind') { $iRCount = $oTokens->findByPk($aTokenRow['tid'])->remindercount + 1; $oTokens->updateByPk($aTokenRow['tid'], array('remindersent' => dateShift(date("Y-m-d H:i:s"), "Y-m-d H:i", Yii::app()->getConfig("timeadjust")))); $oTokens->updateByPk($aTokenRow['tid'], array('remindercount' => $iRCount)); } } else { $aResult[$aTokenRow['tid']] = array('name' => $fieldsarray["{FIRSTNAME}"] . " " . $fieldsarray["{LASTNAME}"], 'email' => $fieldsarray["{EMAIL}"], 'status' => 'fail', 'error' => $maildebug); } } unset($fieldsarray); } return $aResult; }
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz * All rights reserved. * License: GNU/GPL License v2 or later, see LICENSE.php * LimeSurvey is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. * * $Id: * */ include_once "login_check.php"; //Login Check dies also if the script is started directly $js_admin_includes[] = 'scripts/emailtemplates.js'; if (isset($surveyid) && getEmailFormat($surveyid) == 'html') { $ishtml = true; } else { $ishtml = false; } $grplangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselang = GetBaseLanguageFromSurveyID($surveyid); array_unshift($grplangs, $baselang); $sHTMLOutput = PrepareEditorScript(); // Inject necessary strings for Javascript functions $sHTMLOutput .= "<script type='text/javascript'>\n var sReplaceTextConfirmation='" . $clang->gT("This will replace the existing text. Continue?", "js") . "'\n </script>\n"; $sHTMLOutput .= "<div class='header ui-widget-header'>\n" . $clang->gT("Edit email templates") . "</div>\n" . "<form class='form30newtabs' id='emailtemplates' action='{$scriptname}' method='post'>\n" . "<div id='tabs'><ul>"; $surveyinfo = getSurveyInfo($surveyid); foreach ($grplangs as $grouplang) { $sHTMLOutput .= "<li><a href='#tab-{$grouplang}'>" . getLanguageNameFromCode($grouplang, false); if ($grouplang == GetBaseLanguageFromSurveyID($surveyid)) {