Skip to content
Permalink
Browse files

New feature #06624 : Allow to validate expression in email template

Dev: Adding a link in popup to show validation of email
Dev: TODO : same for quota is needed
Dev: Other can be interesting
Dev: Style can be reviewed, link must be reviewed : a button ?
Dev: Review it when using SettingsWidget
  • Loading branch information
Shnoulle committed Dec 27, 2014
1 parent 23ad464 commit 7f45e00e144121b1b00afdf52ac4d7364f8f821f
@@ -195,6 +195,7 @@ public function getActionClasses()
'emailtemplates' => 'emailtemplates',
'export' => 'export',
'expressions' => 'expressions',
'validate' => 'ExpressionValidate',
'globalsettings' => 'globalsettings',
'htmleditor_pop' => 'htmleditor_pop',
'limereplacementfields' => 'limereplacementfields',
@@ -0,0 +1,191 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* Offer some way to validate Expression in survey
*
* @copyright 2014 The LimeSurvey Project Team
* @license http://www.gnu.org/licenses/gpl-3.0.txt
* @todo : Add quota, add any expression
*/
class ExpressionValidate extends Survey_Common_Action {

public $layout = 'popup';

public function index()
{
throw new CHttpException(400);
}

/**
* Check the Expression in email
* @param $iSurveyId : the survey id : can be sid/surveyid url GET parameters
* @param $lang : the mail language
*
* @author Denis Chenu
* @version 1.0
*/
public function email($iSurveyId,$lang)
{
if(!Permission::model()->hasSurveyPermission($iSurveyId, 'surveysettings', 'update'))
throw new CHttpException(401,"401 Unauthorized");
$sType=Yii::app()->request->getQuery('type');
$sLang=$lang;
$LEM =LimeExpressionManager::singleton();

$LEM::SetDirtyFlag();// Not sure it's needed
$LEM::SetPreviewMode('logic');
$aSurveyInfo=getSurveyInfo($iSurveyId,$sLang);
$aSurveyOptions = array(
'hyperlinkSyntaxHighlighting'=>true,
);
$LEM::StartSurvey($iSurveyId, 'survey', $aSurveyOptions);// QCODE are replaced : see #9424 : to be moved only for after survey email after fixed
$aTypeAttributes=array(
'invitation'=>array(
'subject'=>array(
'attribute'=>'surveyls_email_invite_subj',
'title'=>gt('Invitation email subject'),
),
'message'=>array(
'attribute'=>'surveyls_email_invite',
'title'=>gt('Invitation email body'),
),
),
'reminder'=>array(
'subject'=>array(
'attribute'=>'surveyls_email_remind_subj',
'title'=>gt('Reminder email subject'),
),
'message'=>array(
'attribute'=>'surveyls_email_remind',
'title'=>gt('Reminder email body'),
),
),
'confirmation'=>array(
'subject'=>array(
'attribute'=>'surveyls_email_confirm_subj',
'title'=>gt('Confirmation email subject'),
),
'message'=>array(
'attribute'=>'surveyls_email_confirm',
'title'=>gt('Confirmation email body'),
),
),
'registration'=>array(
'subject'=>array(
'attribute'=>'surveyls_email_register_subj',
'title'=>gt('Registration email subject'),
),
'message'=>array(
'attribute'=>'surveyls_email_register',
'title'=>gt('Registration email body'),
),
),
'admin_notification'=>array(
'subject'=>array(
'attribute'=>'email_admin_notification_subj',
'title'=>gt('Basic admin notification subject'),
),
'message'=>array(
'attribute'=>'email_admin_notification',
'title'=>gt('Basic admin notification body'),
),
),
'admin_detailed_notification'=>array(
'subject'=>array(
'attribute'=>'email_admin_responses_subj',
'title'=>gt('Detailed admin notification subject'),
),
'message'=>array(
'attribute'=>'email_admin_responses',
'title'=>gt('Detailed admin notification body'),
),
),
);
// Replaced before email edit
$aReplacement=array(
'ADMINNAME'=> $aSurveyInfo['admin'],
'ADMINEMAIL'=> $aSurveyInfo['adminemail'],
);
// Not needed : templatereplace do the job : but this can/must be fixed for invitaton/reminder/registration (#9424)
$aReplacement["SURVEYNAME"] = gT("Name of the survey");
$aReplacement["SURVEYDESCRIPTION"] = gT("Description of the survey");
// Replaced when sending email with Survey
$aAttributes = getTokenFieldsAndNames($iSurveyId,true);
$aReplacement["TOKEN"] = gt("Token code for this participant");
$aReplacement["TOKEN:EMAIL"] = gt("Email from the token");
$aReplacement["TOKEN:FIRSTNAME"] = gt("First name from token");
$aReplacement["TOKEN:LASTNAME"] = gt("Last name from token");
$aReplacement["TOKEN:TOKEN"] = gt("Token code for this participant");
$aReplacement["TOKEN:LANGUAGE"] = gt("language of token");
foreach ($aAttributes as $sAttribute=>$aAttribute)
{
$aReplacement['TOKEN:'.strtoupper($sAttribute).'']=sprintf(gT("Token attribute: %s"), $aAttribute['description']);
}

switch ($sType)
{
case 'invitation' :
case 'reminder' :
case 'registration' :
// Replaced when sending email (registration too ?)
$aReplacement["EMAIL"] = gt("Email from the token");
$aReplacement["FIRSTNAME"] = gt("First name from token");
$aReplacement["LASTNAME"] = gt("Last name from token");
$aReplacement["LANGUAGE"] = gt("language of token");
$aReplacement["OPTOUTURL"] = gt("URL for a respondent to opt-out of this survey");
$aReplacement["OPTINURL"] = gt("URL for a respondent to opt-in to this survey");
$aReplacement["SURVEYURL"] = gt("URL of the survey");
foreach ($aAttributes as $sAttribute=>$aAttribute)
{
$aReplacement['' . strtoupper($sAttribute) . ''] = sprintf(gT("Token attribute: %s"), $aAttribute['description']);
}
break;
case 'confirmation' :
$aReplacement["EMAIL"] = gt("Email from the token");
$aReplacement["FIRSTNAME"] = gt("First name from token");
$aReplacement["LASTNAME"] = gt("Last name from token");
$aReplacement["SURVEYURL"] = gt("URL of the survey");
foreach ($aAttributes as $sAttribute=>$aAttribute)
{
$aReplacement['' . strtoupper($sAttribute) . ''] = sprintf(gT("Token attribute: %s"), $aAttribute['description']);
}
// $moveResult = LimeExpressionManager::NavigateForwards(); // Seems OK without, nut need $LEM::StartSurvey
break;
case 'admin_notification' :
case 'admin_detailed_notification' :
$aReplacement["RELOADURL"] = gT("Reload URL");
$aReplacement["VIEWRESPONSEURL"] = gT("View response URL");
$aReplacement["EDITRESPONSEURL"] = gT("Edit response URL");
$aReplacement["STATISTICSURL"] = gT("Statistics URL");
$aReplacement["ANSWERTABLE"] = gT("Answers from this response");
// $moveResult = LimeExpressionManager::NavigateForwards(); // Seems OK without, nut need $LEM::StartSurvey
break;
default:
throw new CHttpException(400,gt('Invalid type.'));
break;
}

$aData=array();
$aReData=array(
'thissurvey'=>getSurveyInfo($iSurveyId,$sLang),
);
//$oSurveyLanguage=SurveyLanguageSetting::model()->find("surveyls_survey_id=:sid and surveyls_language=:language",array(":sid"=>$iSurveyId,":language"=>$sLang));
$aExpressions=array();
foreach($aTypeAttributes[$sType] as $key=>$aAttribute)
{
$sAttribute=$aAttribute['attribute'];
// Email send do : templatereplace + ReplaceField to the Templatereplace done : we need 2 in one
// $LEM::ProcessString($oSurveyLanguage->$sAttribute,null,$aReplacement,false,1,1,false,false,true); // This way : ProcessString don't replace coreReplacements
templatereplace($aSurveyInfo[$sAttribute], $aReplacement,$aReData,'ExpressionValidate::email',false,null,array(),true);
$aExpressions[$key]=array(
'title'=>$aAttribute['title'],
'expression'=> $LEM::GetLastPrettyPrintExpression(),
);
}
$aData['aExpressions']=$aExpressions;
$this->getController()->layout=$this->layout;
$this->getController()->pageTitle=sprintf("Validate expression in email : %s",$sType);

$this->getController()->render("/admin/expressions/email", $aData);
}
}
@@ -52,7 +52,6 @@ public function runWithParams($params)
{
$sSubAction = $params['sa'];
}

// Check if the class has the method
$oClass = new ReflectionClass($this);
if (!$oClass->hasMethod($sSubAction))
@@ -87,7 +86,8 @@ public function runWithParams($params)

// Get the action classes from the admin controller as the urls necessarily do not equal the class names. Eg. survey -> surveyaction
$aActions = Yii::app()->getController()->getActionClasses();
if(empty($aActions[$this->getId()]) || strtolower($oMethod->getDeclaringClass()->name) != $aActions[$this->getId()] || !$oMethod->isPublic())

if(empty($aActions[$this->getId()]) || strtolower($oMethod->getDeclaringClass()->name) != strtolower($aActions[$this->getId()]) || !$oMethod->isPublic())
{
// Either action doesn't exist in our whitelist, or the method class doesn't equal the action class or the method isn't public
// So let us get the last possible default method, ie. index
@@ -1590,7 +1590,7 @@ public function GetPrettyPrintString()
$message = str_replace(array('{','}'), array('{ ', ' }'), $message);

$stringParts[] = "<span title='" . $message . "' class='em-var {$class}'";
if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid)) {
if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid) && $qid>0) {
$editlink = Yii::app()->getController()->createUrl('admin/survey/sa/view/surveyid/' . $this->sid . '/gid/' . $gid . '/qid/' . $qid);
$stringParts[] = " data-link='{$editlink}'";
}
@@ -1,6 +1,9 @@

<div id='<?php echo "tab-$grouplang-$tab"; ?>'>
<ul>
<li>
<?php echo CHtml::link(sprintf(gT("Validate expression in %s"),$details['title']),array('admin/validate','sa'=>'email','sid'=>$surveyid,'lang'=>$grouplang,'type'=>$tab),array('title'=>$details['title'],"target"=>"dialog")); ?>
</li>
<li>
<label for='email_<?php echo $tab; ?>_subj_<?php echo $grouplang; ?>'><?php echo $details['subject'] ?></label>
<?php echo CHtml::textField("email_{$tab}_subj_{$grouplang}",$esrow->$details['field']['subject'],array('size'=>80)); ?>
@@ -0,0 +1,8 @@
<?php
echo CHtml::tag('dl',array('class'=>"ui-widget ui-widget-content"),'',false);
foreach($aExpressions as $aExpression)
{
echo CHtml::tag('dt',array('class'=>"ui-widget-header"),$aExpression['title']);
echo CHtml::tag('dd',array('class'=>"ui-widget-content"),$aExpression['expression']);
}
echo CHtml::closeTag('dl');
@@ -18,7 +18,7 @@
* Need to be replaced by some polyfills see #8009
*/
hasFormValidation= typeof document.createElement( 'input' ).checkValidity == 'function';

linksInDialog();
$(document).ready(function(){
initializeAjaxProgress();
tableCellAdapters();
@@ -276,6 +276,7 @@ function doToolTip()
}
});
}
$(this).removeAttr('title');
}
});
$("a > img[alt]").data("hasqtip", true ).removeAttr('title');
@@ -376,8 +377,6 @@ function doToolTip()
});
}
});
/* Any other title take jquery ui tooltip */
$(document).tooltip();
}
// A function to encode any HTML for qtip
function htmlEncode(html){
@@ -724,6 +723,32 @@ function removeCSRFDivs()
});
}

function linksInDialog()
{
$(function () {
var iframe = $('<iframe id="dialog" allowfullscreen></iframe>');
var dialog = $("<div></div>").append(iframe).appendTo("body").dialog({
autoOpen: false,
modal: false,
resizable: true,
width: "60%",
height: $(window).height()*0.6,
close: function () {
iframe.attr("src", "");
}
});
$(document).on('click','a[target=dialog]',function(event){
event.preventDefault();
var src = $(this).attr("href");
var title = $(this).attr("title");
console.log(title);
iframe.attr({
src: src,
});
dialog.dialog("option", "title", title).dialog("open");
});
});
}
function initializeAjaxProgress()
{
$('#ajaxprogress').dialog({
@@ -2,7 +2,11 @@
* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GNU/GPL License v2 or later
*/
$(document).ready(function(){
// Open the link if there are data-link
$('[data-link]').on('click',function(){
window.open($(this).data('link'));
});
// Tooltip inside em-var
$(".em-expression").tooltip();
});

@@ -240,3 +240,6 @@ li input+label { display: inline;}
}

#quotalist form{display:inline;}

/* For the iframe in dialog */
iframe#dialog{display:block; width:100%!important; height:100%!important;margin:0;padding:0;border:0}
@@ -9,3 +9,4 @@
.em-var-error{color: #ff4500}
.em-var-error{color: #ff0000 /* orangered */}
.em-error{border: 2px solid #ff0000; /* red */;}
[data-link]{cursor:pointer}

0 comments on commit 7f45e00

Please sign in to comment.
You can’t perform that action at this time.