/**
 * Add answers to selected question.
 * @param $testlog_id (int) testlog ID.
 * @param $question_id (int) question ID.
 * @param $question_type (int) type of question.
 * @param $num_answers (int) number of alternative answers to display.
 * @param $firsttest (int) ID of first test testuser_id.
 * @param $testdata (array) array of test data.
 * @return boolean TRUE in case of success, FALSE otherwise.
 */
function F_addQuestionAnswers($testlog_id, $question_id, $question_type, $num_answers, $firsttest, $testdata)
{
    require_once '../config/tce_config.php';
    global $db, $l;
    if ($question_type == 3) {
        // free text question
        return true;
    }
    $randorder = F_getBoolean($testdata['test_random_answers_order']);
    // for each question
    if (F_getBoolean($testdata['test_random_questions_select']) or F_getBoolean($testdata['test_random_answers_select']) or $firsttest == 0) {
        $answers_ids = array();
        // array used to store answers IDs
        switch ($question_type) {
            case 1:
                // MCSA
                // select first right answer
                $answers_ids += F_selectAnswers($question_id, 1, false, 1, 0, $randorder);
                // select remaining answers
                $answers_ids += F_selectAnswers($question_id, 0, false, $num_answers - 1, 1, $randorder);
                break;
            case 2:
                // MCMA
                // select answers
                $answers_ids += F_selectAnswers($question_id, '', false, $num_answers, 0, $randorder);
                break;
            case 4:
                // ORDERING
                // select answers
                $randorder = true;
                $answers_ids += F_selectAnswers($question_id, '', true, 0, 0, $randorder);
                break;
        }
        // randomizes the order of the answers
        if ($randorder) {
            shuffle($answers_ids);
        } else {
            ksort($answers_ids);
        }
        // add answers
        F_addLogAnswers($testlog_id, $answers_ids);
    } else {
        // same answers for all test-takers
        // --------------------------------
        $sql = 'SELECT logansw_answer_id
			FROM ' . K_TABLE_LOG_ANSWER . ', ' . K_TABLE_TESTS_LOGS . '
			WHERE logansw_testlog_id=testlog_id
				AND testlog_testuser_id=' . $firsttest . '
				AND testlog_question_id=' . $question_id . '';
        if ($randorder) {
            $sql .= ' ORDER BY RAND()';
        } else {
            $sql .= ' ORDER BY logansw_order';
        }
        if ($r = F_db_query($sql, $db)) {
            $answers_ids = array();
            while ($m = F_db_fetch_array($r)) {
                $answers_ids[] = $m['logansw_answer_id'];
            }
            F_addLogAnswers($testlog_id, $answers_ids);
        } else {
            F_display_db_error(false);
            return false;
        }
    }
    return true;
}
예제 #2
0
         // MCSA
         // select first right answer
         $answers_ids += F_selectAnswers($q['id'], 1, false, 1, 0, $randorder, $test_answers_order_mode);
         // select remaining answers
         $answers_ids += F_selectAnswers($q['id'], 0, false, $q['answers'] - 1, 1, $randorder, $test_answers_order_mode);
         break;
     case 2:
         // MCMA
         // select answers
         $answers_ids += F_selectAnswers($q['id'], '', false, $q['answers'], 0, $randorder, $test_answers_order_mode);
         break;
     case 4:
         // ORDERING
         // select answers
         $randorder = true;
         $answers_ids += F_selectAnswers($q['id'], '', true, 0, 0, $randorder, $test_answers_order_mode);
         break;
 }
 // randomizes the order of the answers
 if ($randorder) {
     shuffle($answers_ids);
 } else {
     ksort($answers_ids);
 }
 // print answers
 // add answers
 $answ_id = 0;
 // display multiple answers
 while (list($key, $answer_id) = each($answers_ids)) {
     ++$answ_id;
     // add answer ID to QR-Code data
예제 #3
0
         // MCSA
         // select first right answer
         $answers_ids += F_selectAnswers($q['id'], 1, false, 1, 0, $randorder);
         // select remaining answers
         $answers_ids += F_selectAnswers($q['id'], 0, false, $q['answers'] - 1, 1, $randorder);
         break;
     case 2:
         // MCMA
         // select answers
         $answers_ids += F_selectAnswers($q['id'], '', false, $q['answers'], 0, $randorder);
         break;
     case 4:
         // ORDERING
         // select answers
         $randorder = true;
         $answers_ids += F_selectAnswers($q['id'], '', true, 0, 0, $randorder);
         break;
 }
 // randomizes the order of the answers
 if ($randorder) {
     shuffle($answers_ids);
 } else {
     ksort($answers_ids);
 }
 // print answers
 // add answers
 $answ_id = 0;
 // display multiple answers
 while (list($key, $answer_id) = each($answers_ids)) {
     ++$answ_id;
     // add answer ID to QR-Code data