Skip to content

Commit

Permalink
Fixed issue #13630: EM send Notice about Undefined offset
Browse files Browse the repository at this point in the history
Dev: Pull request (#1180)
Dev: remove link on not valid variable (and qid is set here …)
Fixed issue : Only partial error shown in logic file
Dev: Previous system is totally broken , rewrite it
Dev: adding $this->RDP_errs inside $this->RDP_errs : remove this …
  • Loading branch information
Shnoulle committed Nov 25, 2018
1 parent eb60980 commit af310e8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -16,5 +16,5 @@
$config['dbversionnumber'] = 355;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '30068';
$config['assetsversionnumber'] = '30069';
return $config;
69 changes: 33 additions & 36 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -1294,42 +1294,41 @@ public function GetPrettyPrintString()
}
$stringParts = array();
$numTokens = count($tokens);
$globalErrs = array();
$bHaveError = false;

$globalErrs = array(); // Error not related to a token (bracket for example)
while ($errIndex < $errCount) {
if ($errs[$errIndex++][1][1] == 0) {
// General message, associated with position 0
$globalErrs[] = $errs[$errIndex - 1][0];
if (empty($errs[$errIndex][1])) {
$globalErrs[] = $errs[$errIndex][0];
$bHaveError = true;
} else {
--$errIndex;
break;
}
$errIndex++;
}

for ($i = 0; $i < $numTokens; ++$i) {
$token = $tokens[$i];
$messages = array();
$thisTokenHasError = false;
if ($i == 0 && count($globalErrs) > 0) {
$messages = array_merge($messages, $globalErrs);
$thisTokenHasError = true;
}
if ($errIndex < $errCount && $token[1] == $errs[$errIndex][1][1]) {
$messages[] = $errs[$errIndex][0];
$thisTokenHasError = true;
$errIndex = 0;
while ($errIndex < $errCount) {
if ($errs[$errIndex][1] == $token) { // Error related to this token
$messages[] = $errs[$errIndex][0];
$thisTokenHasError = true;
}
$errIndex++;
}
if ($thisTokenHasError) {
$stringParts[] = "<span title='".implode('; ', $messages)."' class='em-error'>";
$stringParts[] = "<span class='em-error'>";
$bHaveError = true;
}
switch ($token[2]) {
case 'DQ_STRING':
$stringParts[] = "<span title='".implode('; ', $messages)."' class='em-var-string'>\"";
$stringParts[] = "<span title='".CHtml::encode(implode('; ', $messages))."' class='em-var-string'>\"";
$stringParts[] = $token[0]; // htmlspecialchars($token[0],ENT_QUOTES,'UTF-8',false);
$stringParts[] = "\"</span>";
break;
case 'SQ_STRING':
$stringParts[] = "<span title='".implode('; ', $messages)."' class='em-var-string'>'";
$stringParts[] = "<span title='".CHtml::encode(implode('; ', $messages))."' class='em-var-string'>'";
$stringParts[] = $token[0]; // htmlspecialchars($token[0],ENT_QUOTES,'UTF-8',false);
$stringParts[] = "'</span>";
break;
Expand All @@ -1342,7 +1341,7 @@ public function GetPrettyPrintString()
$messages[] = $funcInfo[2];
$messages[] = $funcInfo[3];
}
$stringParts[] = "<span title='".preg_replace('/\'/', '"', implode('; ', $messages))."' class='em-function' >";
$stringParts[] = "<span title='".CHtml::encode(implode('; ', $messages))."' class='em-function' >";
$stringParts[] = $token[0];
$stringParts[] = "</span>";
} else {
Expand Down Expand Up @@ -1391,17 +1390,17 @@ public function GetPrettyPrintString()
$descriptor .= ': ';
}

$messages[] = $descriptor.htmlspecialchars($question, ENT_QUOTES, 'UTF-8', false);
$messages[] = $descriptor.$question;
if ($ansList != '') {
$messages[] = htmlspecialchars($ansList, ENT_QUOTES, 'UTF-8', false);
$messages[] = $ansList;
}
if ($code != '') {
if ($token[2] == 'SGQA' && preg_match('/^INSERTANS:/', $token[0])) {
$shown = $this->GetVarAttribute($token[0], 'shown', '');
$messages[] = 'value=['.htmlspecialchars($code, ENT_QUOTES, 'UTF-8', false).'] '
. htmlspecialchars($shown, ENT_QUOTES, 'UTF-8', false);
$messages[] = 'value=['.$code.'] '
. $shown;
} else {
$messages[] = 'value='.htmlspecialchars($code, ENT_QUOTES, 'UTF-8', false);
$messages[] = 'value='.$code;
}
}

Expand All @@ -1421,11 +1420,11 @@ public function GetPrettyPrintString()
$message = implode('; ', $messages);
$message = str_replace(array('{', '}'), array('{ ', ' }'), $message);

if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid) && $qid > 0) {
if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid) && $qid > 0 && $this->RDP_isValidVariable($token[0])) {
$editlink = Yii::app()->getController()->createUrl('admin/questions/sa/view/surveyid/'.$this->sid.'/gid/'.$gid.'/qid/'.$qid);
$stringParts[] = "<a title='{$message}' class='em-var {$class}' href='{$editlink}' >";
$stringParts[] = "<a title='".CHtml::encode($message)."' class='em-var {$class}' href='{$editlink}' >";
} else {
$stringParts[] = "<span title='".$message."' class='em-var {$class}' >";
$stringParts[] = "<span title='".CHtml::encode($message)."' class='em-var {$class}' >";
}
if ($this->sgqaNaming) {
$sgqa = substr($jsName, 4);
Expand All @@ -1437,7 +1436,7 @@ public function GetPrettyPrintString()
} else {
$stringParts[] = $displayName;
}
if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid) && $qid > 0) {
if ($this->hyperlinkSyntaxHighlighting && isset($gid) && isset($qid) && $qid > 0 && $this->RDP_isValidVariable($token[0])) {
$stringParts[] = "</a>";
} else {
$stringParts[] = "</span>";
Expand All @@ -1446,7 +1445,7 @@ public function GetPrettyPrintString()
break;
case 'ASSIGN':
$messages[] = self::gT('Assigning a new value to a variable.');
$stringParts[] = "<span title='".implode('; ', $messages)."' class='em-assign'>";
$stringParts[] = "<span title='".CHtml::encode(implode('; ', $messages))."' class='em-assign'>";
$stringParts[] = $token[0];
$stringParts[] = "</span>";
break;
Expand All @@ -1473,7 +1472,12 @@ public function GetPrettyPrintString()
}
$sClass = 'em-expression';
$sClass .= ($bHaveError) ? " em-haveerror" : "";
return "<span class='$sClass'>".implode('', $stringParts)."</span>";
$title = "";
if(!empty($globalErrs)) {
$sClass .= " em-error";
$title = " title='".CHtml::encode(implode('; ', $globalErrs))."'";
}
return "<span class='$sClass' $title >".implode('', $stringParts)."</span>";
}

/**
Expand Down Expand Up @@ -1667,7 +1671,6 @@ public function sProcessStringContainingExpressions($src, $questionNum = 0, $num
$this->groupSeq = $groupSeq;
$result = $src;
$prettyPrint = '';
$errors = array();

$prettyPrintIterationDone = false;
for ($i = 1; $i <= $numRecursionLevels; ++$i) {
Expand All @@ -1686,10 +1689,8 @@ public function sProcessStringContainingExpressions($src, $questionNum = 0, $num
$prettyPrint = $this->prettyPrintSource;
$prettyPrintIterationDone = true;
}
$errors = array_merge($errors, $this->RDP_errs);
}
$this->prettyPrintSource = $prettyPrint; // ensure that if doing recursive substition, can get original source to pretty print
$this->RDP_errs = $errors;
$result = str_replace(array('\{', '\}',), array('{', '}'), $result);
return $result;
}
Expand All @@ -1707,8 +1708,6 @@ public function sProcessStringContainingExpressionsHelper($src, $questionNum, $s
$stringParts = $this->asSplitStringOnExpressions($src);
$resolvedParts = array();
$prettyPrintParts = array();
$allErrors = array();

foreach ($stringParts as $stringPart) {
if ($stringPart[2] == 'STRING') {
$resolvedParts[] = $stringPart[0];
Expand All @@ -1725,7 +1724,6 @@ public function sProcessStringContainingExpressionsHelper($src, $questionNum, $s
} else {
$resolvedPart = '';
}
$allErrors[] = $this->GetErrors();
}
$onpageJsVarsUsed = $this->GetOnPageJsVarsUsed();
$jsVarsUsed = $this->GetJsVarsUsed();
Expand Down Expand Up @@ -1753,7 +1751,6 @@ public function sProcessStringContainingExpressionsHelper($src, $questionNum, $s
}
$result = implode('', $this->flatten_array($resolvedParts));
$this->prettyPrintSource = implode('', $this->flatten_array($prettyPrintParts));
$this->RDP_errs = $allErrors; // so that has all errors from this string
return $result; // recurse in case there are nested ones, avoiding infinite loops?
}

Expand Down
15 changes: 8 additions & 7 deletions assets/scripts/admin/expression.js
Expand Up @@ -3,11 +3,12 @@
*/
$(document).on('ready pjax:scriptcomplete', function(){
// Tooltip inside em-var
$(".em-expression").tooltip();
});


$(document).on('click','.em-expression a',function(e){
e.preventDefault();
window.open($(this).attr('href'));
$(".em-expression").tooltip({
placement : 'bottom',
template : '<div class="tooltip expression-tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
});
$(".em-expression *").tooltip({
placement : 'top',
template : '<div class="tooltip expression-tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
});
});
4 changes: 3 additions & 1 deletion assets/styles-public/expressionlogicfile.css
Expand Up @@ -18,8 +18,10 @@ background-color:white;
color:red;
font-weight:bold;
}

tr.LEMsubq td
{
background-color:lightyellow;
}
.expression-tooltip .tooltip-inner {
max-width: none;
}
1 change: 1 addition & 0 deletions assets/styles-public/expressions.css
Expand Up @@ -10,3 +10,4 @@
.em-var-error,a.em-var-error{color: #ff0000;font-weight:700} /* Maybe font-weight:400 */
.em-assign{color: #ff4500}
.em-error{border: 2px solid #ff0000}
.em-error .em-error{border: 1px solid #ff0000}

0 comments on commit af310e8

Please sign in to comment.