- Posts: 74
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
{if(LANG=="en","String in english","")} {if(LANG=="fr","Phrase en français","")}
// TMSW Validation -> EM
function mandatory_popup($ia, $notanswered=null)
{
//This sets the mandatory popup message to show if required
//Called from question.php, group.php or survey.php
if ($notanswered === null) {unset($notanswered);}
if (isset($notanswered) && is_array($notanswered)) //ADD WARNINGS TO QUESTIONS IF THEY WERE MANDATORY BUT NOT ANSWERED
{
global $mandatorypopup, $popup;
//POPUP WARNING
if (!isset($mandatorypopup) && ($ia[4] == 'T' || $ia[4] == 'S' || $ia[4] == 'U'))
{
$popup=gT("Please enter some text for the question(s) to continue.");
$mandatorypopup="Y";
}else
{
$popup=gT("Please answer the question(s) to continue.");
$mandatorypopup="Y";
}
return array($mandatorypopup, $popup);
}
else
{
return false;
}
}
//////////////////////////////////////////////
// DETECT ANY VIOLATIONS OF MANDATORY RULES //
//////////////////////////////////////////////
$qmandViolation = false; // assume there is no mandatory violation until discover otherwise
$mandatoryTip = '';
if ($qrel && !$qhidden && ($qInfo == 'Y'))
{
$mandatoryTip = "<strong><br /><span class='errormandatory'>".$LEM->gT('Please answer this question to continue.').'. ';
switch ($qInfo)
{
case 'M':
case 'P':
case '!': //List - dropdown
case 'L': //LIST drop-down/radio-button list
// If at least one checkbox is checked, we're OK
if (count($relevantSQs) > 0 && (count($relevantSQs) == count($unansweredSQs)))
{
$qmandViolation = true;
}
if (!($qInfo == '!' || $qInfo == 'L'))
{
$mandatoryTip .= $LEM->gT('Please check at least one item.');
}
if ($qInfo=='Y')
{
$qattr = isset($LEM->qattr[$qid]) ? $LEM->qattr[$qid] : array();
if (isset($qattr) && trim($qattr) != '') {
$othertext = trim($qattr);
}
else {
$othertext = $LEM->gT('Other:');
}
$mandatoryTip .= "<br />\n".sprintf($this->gT("If you choose '%s' please also specify your choice in the accompanying text field."),$othertext);
}
break;
case 'X': // Boilerplate can never be mandatory
case '*': // Equation is auto-computed, so can't violate mandatory rules
break;
case 'A':
case 'B':
case 'C':
case 'Q':
case 'K':
case 'E':
case 'F':
case 'J':
case 'H':
case ';':
case '1':
// In general, if any relevant questions aren't answered, then it violates the mandatory rule
if (count($unansweredSQs) > 0)
{
$qmandViolation = true; // TODO - what about 'other'?
}
$mandatoryTip .= $LEM->gT(' ').'.';
break;
case ':':
$qattr = isset($LEM->qattr[$qid]) ? $LEM->qattr[$qid] : array();
if (isset($qattr) && $qattr == 1)
{
// Need to check whether there is at least one checked box per row
foreach ($LEM->q2subqInfo[$qid] as $sq)
{
if (!isset($_SESSION[$LEM->sessid][$sq]) || $_SESSION[$LEM->sessid][$sq])
{
$rowCount=0;
$numUnanswered=0;
foreach ($sgqas as $s)
{
if (strpos($s, $sq."_") !== false) // Test complete subquestion code (#09493)
{
++$rowCount;
if (array_search($s,$unansweredSQs) !== false) {
++$numUnanswered;
}
}
}
if ($rowCount > 0 && $rowCount == $numUnanswered)
{
$qmandViolation = true;
}
}
}
$mandatoryTip .= $LEM->gT('Please check at least one box per row').'.';
}
else
{
if (count($unansweredSQs) > 0)
{
$qmandViolation = true; // TODO - what about 'other'?
}
$mandatoryTip .= $LEM->gT(' ').'.';
}
break;
case 'R':
if (count($unansweredSQs) > 0)
{
$qmandViolation = true; // TODO - what about 'other'?
}
$mandatoryTip .= $LEM->gT('Please rank all items').'.';
break;
case 'O': //LIST WITH COMMENT drop-down/radio-button list + textarea
$_count=0;
for ($i=0;$i<count($unansweredSQs);++$i)
{
if (preg_match("/comment$/",$unansweredSQs[$i])) {
continue;
}
++$_count;
}
if ($_count > 0)
{
$qmandViolation = true;
}
break;
default:
if (count($unansweredSQs) > 0)
{
$qmandViolation = true;
}
break;
}
$mandatoryTip .= "</span></strong>\n";
}
Thank you!{if(LANG=="en","String in english","")}
{if(LANG=="fr","Phrase en français","")}