Esempio n. 1
0
function checkgroupfordisplay($gid)
{
    //This function checks all the questions in a group to see if they have
    //conditions, and if the do - to see if the conditions are met.
    //If none of the questions in the group are set to display, then
    //the function will return false, to indicate that the whole group
    //should not display at all.
    global $dbprefix, $connect;
    $countQuestionsInThisGroup = 0;
    $countConditionalQuestionsInThisGroup = 0;
    foreach ($_SESSION['fieldarray'] as $ia) {
        if ($ia[5] == $gid) {
            // Check if this question is hidden
            $qidattributes = getQuestionAttributes($ia[0]);
            if ($qidattributes !== false && $qidattributes['hidden'] == 0) {
                $countQuestionsInThisGroup++;
                if ($ia[7] == "Y") {
                    $countConditionalQuestionsInThisGroup++;
                    $QuestionsWithConditions[] = $ia;
                    //Create an array containing all the conditional questions
                }
            }
        }
    }
    if ($countQuestionsInThisGroup === 0) {
        return false;
    } elseif ($countQuestionsInThisGroup != $countConditionalQuestionsInThisGroup || !isset($QuestionsWithConditions)) {
        //One of the questions in this group is NOT conditional, therefore
        //the group MUST be displayed
        return true;
    } else {
        //All of the questions in this group are conditional. Now we must
        //check every question, to see if the condition for each has been met.
        //If 1 or more have their conditions met, then the group should
        //be displayed.
        foreach ($QuestionsWithConditions as $cc) {
            if (checkquestionfordisplay($cc[0], $gid) === true) {
                return true;
            }
        }
        //Since we made it this far, there mustn't have been any conditions met.
        //Therefore the group should not be displayed.
        return false;
    }
}
function checkUploadedFileValidity($move, $backok = null)
{
    global $connect, $thisstep, $clang;
    if (!isset($backok) || $backok != "Y") {
        global $dbprefix;
        $fieldmap = createFieldMap(returnglobal('sid'));
        if (isset($_POST['fieldnames']) && $_POST['fieldnames'] != "") {
            $fields = explode("|", $_POST['fieldnames']);
            foreach ($fields as $field) {
                if ($fieldmap[$field]['type'] == "|" && !strrpos($fieldmap[$field]['fieldname'], "_filecount")) {
                    $validation = array();
                    $query = "SELECT * FROM " . $dbprefix . "question_attributes WHERE qid = " . $fieldmap[$field]['qid'];
                    $result = db_execute_assoc($query);
                    while ($row = $result->FetchRow()) {
                        $validation[$row['attribute']] = $row['value'];
                    }
                    $filecount = 0;
                    $json = $_POST[$field];
                    // if name is blank, its basic, hence check
                    // else, its ajax, don't check, bypass it.
                    if ($json != "" && $json != "[]") {
                        $phparray = json_decode(stripslashes($json));
                        if ($phparray[0]->size != "") {
                            // ajax
                            $filecount = count($phparray);
                        } else {
                            // basic
                            for ($i = 1; $i <= $validation['max_num_of_files']; $i++) {
                                if (!isset($_FILES[$field . "_file_" . $i]) || $_FILES[$field . "_file_" . $i]['name'] == '') {
                                    continue;
                                }
                                $filecount++;
                                $file = $_FILES[$field . "_file_" . $i];
                                // File size validation
                                if ($file['size'] > $validation['max_filesize'] * 1000) {
                                    $filenotvalidated = array();
                                    $filenotvalidated[$field . "_file_" . $i] = sprintf($clang->gT("Sorry, the uploaded file (%s) is larger than the allowed filesize of %s KB."), $file['size'], $validation['max_filesize']);
                                    $append = true;
                                }
                                // File extension validation
                                $pathinfo = pathinfo(basename($file['name']));
                                $ext = $pathinfo['extension'];
                                $validExtensions = explode(",", $validation['allowed_filetypes']);
                                if (!in_array($ext, $validExtensions)) {
                                    if (isset($append) && $append) {
                                        $filenotvalidated[$field . "_file_" . $i] .= sprintf($clang->gT("Sorry, only %s extensions are allowed!"), $validation['allowed_filetypes']);
                                        unset($append);
                                    } else {
                                        $filenotvalidated = array();
                                        $filenotvalidated[$field . "_file_" . $i] .= sprintf($clang->gT("Sorry, only %s extensions are allowed!"), $validation['allowed_filetypes']);
                                    }
                                }
                            }
                        }
                    } else {
                        $filecount = 0;
                    }
                    if ($filecount < $validation['min_num_of_files'] && checkquestionfordisplay($fieldmap[$field]['qid'])) {
                        $filenotvalidated = array();
                        $filenotvalidated[$field] = $clang->gT("The minimum number of files has not been uploaded.");
                    }
                }
            }
        }
        if (isset($filenotvalidated)) {
            if (isset($move) && $move == "moveprev") {
                $_SESSION['step'] = $thisstep;
            }
            if (isset($move) && $move == "movenext") {
                $_SESSION['step'] = $thisstep;
            }
            return $filenotvalidated;
        }
    }
    if (!isset($filenotvalidated)) {
        return false;
    } else {
        return $filenotvalidated;
    }
}
$navigator = surveymover();
echo "\n\n<!-- PRESENT THE NAVIGATOR -->\n";
echo templatereplace(file_get_contents("{$thistpl}/navigator.pstpl"));
echo "\n";
if ($thissurvey['active'] != "Y") {
    echo "<p style='text-align:center' class='error'>" . $clang->gT("This survey is currently not active. You will not be able to save your responses.") . "</p>\n";
}
echo "\n";
if ($thissurvey['allowjumps'] == 'Y' && !$bIsGroupDescrPage) {
    echo "\n\n<!-- PRESENT THE INDEX -->\n";
    $iLastGrp = null;
    echo '<div id="index"><div class="container"><h2>' . $clang->gT("Question index") . '</h2>';
    for ($v = 0, $n = 0; $n != $_SESSION['maxstep']; ++$n) {
        $ia = $_SESSION['fieldarray'][$n];
        $qidattributes = getQuestionAttributes($ia[0], $ia[4]);
        if ($qidattributes['hidden'] == 1 || !checkquestionfordisplay($ia[0])) {
            continue;
        }
        $sText = FlattenText($ia[3]);
        $bAnsw = bCheckQuestionForAnswer($ia[1], $aFieldnamesInfoInv);
        if ($iLastGrp != $ia[5]) {
            $iLastGrp = $ia[5];
            foreach ($_SESSION['grouplist'] as $gl) {
                if ($gl[0] == $iLastGrp) {
                    echo '<h3>' . htmlspecialchars(strip_tags($gl[1]), ENT_QUOTES, 'UTF-8') . "</h3>";
                    break;
                }
            }
        }
        ++$v;
        $class = $n == $_SESSION['step'] - 1 ? 'current' : ($bAnsw ? 'answer' : 'missing');
Esempio n. 4
0
 $oldgid = 0;
 $oldqid = 0;
 foreach ($fnames as $fname) {
     $question = $fname['question'];
     if (isset($fname['gid']) && !empty($fname['gid'])) {
         //Check to see if gid is the same as before. if not show group name
         if ($oldgid !== $fname['gid']) {
             $oldgid = $fname['gid'];
             $printoutput .= "\t<tr class='printanswersgroupname'><td colspan='2'>{$fname['group_name']}</td></tr>\n";
             if (isset($_POST['printableexport'])) {
                 $pdf->intopdf(FlattenText($fname['group_name'], true));
                 $pdf->ln(2);
             }
         }
     }
     if (isset($fname['qid']) && !empty($fname['qid']) && ($printanswershonorsconditions == 1 && checkquestionfordisplay($fname['qid'], null)) || $printanswershonorsconditions != 1) {
         //Check to see if gid is the same as before. if not show group name
         if ($oldqid !== $fname['qid']) {
             $oldqid = $fname['qid'];
             if (isset($fname['subquestion']) || isset($fname['subquestion1']) || isset($fname['subquestion2'])) {
                 $printoutput .= "\t<tr class='printanswersquestion'><td>{$fname['question']}</td></tr>\n";
                 if (isset($_POST['printableexport'])) {
                     $pdf->intopdf(FlattenText($fname['question'], true));
                     $pdf->ln(2);
                 }
             }
         }
         if (isset($fname['subquestion'])) {
             $question = "{$fname['subquestion']}";
         }
         if (isset($fname['subquestion1'])) {
Esempio n. 5
0
} else {
    $currentquestion = $_SESSION['step'] - 1;
}
$ia = $_SESSION['fieldarray'][$currentquestion];
list($newgroup, $gid, $groupname, $groupdescription, $gl) = checkIfNewGroup($ia);
// MANAGE CONDITIONAL QUESTIONS AND HIDDEN QUESTIONS
$qidattributes = getQuestionAttributes($ia[0]);
if ($qidattributes === false) {
    $qidattributes['hidden'] == 1;
    //Workaround to skip the question if it was deleted while the survey is running in test mode
}
$conditionforthisquestion = $ia[7];
$questionsSkipped = 0;
while ($conditionforthisquestion == "Y" || $qidattributes['hidden'] == 1) {
    // this is a while, not an IF because if we skip the question we loop on the next question, see below
    if (checkquestionfordisplay($ia[0]) === true && $qidattributes['hidden'] == 0) {
        // question will be displayed
        // we set conditionforthisquestion to N here because it is used later to select style=display:'' for the question
        $conditionforthisquestion = "N";
    } else {
        $questionsSkipped++;
        if (returnglobal('move') == "movenext") {
            $currentquestion++;
            if (isset($_SESSION['fieldarray'][$currentquestion])) {
                $ia = $_SESSION['fieldarray'][$currentquestion];
            }
            if ($_SESSION['step'] >= $_SESSION['totalsteps']) {
                $move = "movesubmit";
                submitanswer();
                // complete this answer (submitdate)
                break;