Beispiel #1
0
function print_list($result)
{
    $num = pg_num_rows($result);
    if ($num == 0) {
        print "まだ診断を行っていません。<br>\n";
    } else {
        print "<table>\n";
        print "<tr><th>診断名</th><th>回答</th><th>結果</th></tr>\n";
        for ($i = 0; $i < $num; $i++) {
            $row = pg_fetch_assoc($result, $i);
            $ans = getAnswer($row['answer']);
            print "<tr><td>{$row['content']}</td><td>{$row['choice']}</td><td>{$ans}</td></tr>\n";
        }
        print "</table>\n";
    }
}
Beispiel #2
0
function getAnswers($phraseID, $drill)
{
    include 'config.php';
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
    mysql_select_db($dbname);
    $qBlanks = getBlanks($phraseID, 'fill_in_the_blank');
    $blankCounter = 1;
    for ($i = 0; $i < $qBlanks; $i++) {
        if ($drill == "adj" || $drill == "wordBox") {
            $answers[] = getAdjAnswer($phraseID, $blankCounter);
        } elseif ($drill == "fib") {
            $answers[] = getAnswer(getAnswerID($phraseID, $blankCounter));
        }
        $blankCounter++;
    }
    return $answers;
}
Beispiel #3
0
include "setting.php";
if (!isset($_SESSION['id']) || !isset($_SESSION['ipaddress'])) {
    gotoindex();
}
check_login();
if (!isset($_GET['id']) || !isset($_GET['ans'])) {
    exit(0);
}
include "header.php";
$q_id = $_GET['id'];
$ans = $_GET['ans'];
$m_id = $_SESSION['id'];
if (update_answer($m_id, $q_id, $ans) != false) {
    $answer = get_answer($ans);
    $q = pg_fetch_assoc($answer, 0);
    $ans = getAnswer($q['answer']);
    update_log($m_id, $q['answer']);
    print "結果は{$ans}です。";
}
include "footer.php";
function get_answer($id)
{
    $db = new mydb();
    $query = "select * from choices where id = \$1";
    $result = $db->query($query, array($id), "getans");
    return $result;
}
function update_answer($m_id, $q_id, $answer)
{
    $db = new mydb();
    $query = "insert into answer (m_id, q_id, answer) values(\$1, \$2, \$3)";
<?php

$result = $_POST;
//var_dump($result);
$answer = array();
$score = 0;
$filename = 'gen_knowledge.json';
$data = json_decode(file_get_contents($filename));
$answer = getAnswer($data);
$score = getScore($answer, $result);
echo "Your Score is {$score}";
function getAnswer($data)
{
    $contents = $data->contents;
    //var_dump($contents);
    $index = 0;
    foreach ($contents as $value) {
        $answer[$index++] = $value->answer;
    }
    return $answer;
}
function getScore($answer, $result)
{
    $index = 0;
    $score = 0;
    //var_dump($answer);
    //var_dump($result);
    foreach ($result as $key => $value) {
        switch ($key) {
            case 'q1':
                $index = 0;
            $questionSQL2 = "SELECT * FROM navigation_tab JOIN question_type ON navigation_tab.nav_tab_id = question_type.nav_tab_id WHERE parent_id = '{$new_parent}' AND navigation_tab.status = 3 AND template_id = '20' ORDER BY usort ASC";
            $questionSET2 = mysql_query($questionSQL2);
            while ($questionROW2 = mysql_fetch_assoc($questionSET2)) {
                $question_id = $questionROW2['nav_tab_id'];
                $question_type = $questionROW2['question_type'];
                if ($question_type == '1') {
                    $value = getAnswer($question_id, $session_id, 2);
                    $csvline = $csvline . $sep2 . $value;
                }
                if ($question_type == '4') {
                    $mySQL = "SELECT * FROM navigation_tab WHERE parent_id = '{$question_id}' ORDER BY usort ASC";
                    $recSET = mysql_query($mySQL);
                    while ($recROW = mysql_fetch_assoc($recSET)) {
                        $i_count++;
                        $question_id2 = $recROW['nav_tab_id'];
                        $value = getAnswer($question_id2, $session_id, 2);
                        $csvline = $csvline . $sep2 . $value;
                    }
                }
            }
        }
    }
    $row_count = $row_count + 1;
    $csvline = $csvline . $sep1 . $end;
    fwrite($handle, $csvline);
}
?>


<div align="center">
&nbsp;<p>&nbsp;</p>
Beispiel #6
0
 $quiz = $quiz . "</td>";
 //  is this answer correct?
 $correct = $row["ok"];
 if ($correct && $marked) {
     $nrcorrect++;
 }
 $explanation = $row["Explanation"];
 if ($marked && $explanation != '') {
     $extra = $correct ? "style=\"font-weight:bold;color:#006600;\"" : "style=\"font-weight:bold;color:#990000;\"";
 }
 $quiz = $quiz . "<td valign=middle> <div {$extra} id=\"A{$answer}\">";
 $quiz = $quiz . $row["Answer"];
 if ($marked) {
     $extra = $correct ? "style=\"font-weight:bold;color:#000000;\"" : "style=\"font-weight:bold;color:#000000;\"";
     $temp = $correct ? "Correct: " : "Incorrect: ";
     $temp2 = getAnswer($i);
     $allanswers = $allanswers . $temp2;
     //mysql_query("insert into tblember_user_results VALUES('', 1, '$temp2', '$correct');") or die (mysql_error());
     // add an explanation
     if ($explanation != '') {
         $quiz = $quiz . "</td></tr><tr><td></td><td><span {$extra}>" . $temp . $explanation . "</span></td>";
     }
 }
 $quiz = $quiz . "</div></td>";
 $quiz = $quiz . "</tr>";
 if ($i == 3) {
     $quiz = $quiz . "</table><br>";
     $i = 0;
     $questionnr++;
 } else {
     $i++;
Beispiel #7
0
    if (empty($secondVariable) && $operationType == '/') {
        return "Ошибка! На ноль делить нельзя!";
    } elseif (empty((int) $secondVariable) && $operationType == '%') {
        return "Остаток от деления работает только с целыми числами. Приведение {$secondVariable} к целому числу возвращает 0. На 0 делить нельзя!";
    } else {
        return eval('return ' . $firstVariable . $operationType . '(' . $secondVariable . ')' . ';');
    }
}
if (isset($_POST['firstVariableSelectForm']) && isset($_POST['secondVariableSelectForm'])) {
    $answerSelectForm = getAnswer($_POST['firstVariableSelectForm'], $_POST['secondVariableSelectForm'], $_POST['operationTypeSelect']);
} else {
    $_POST['firstVariableSelectForm'] = "";
    $_POST['secondVariableSelectForm'] = "";
}
if (isset($_POST['firstVariableButtonForm']) && isset($_POST['secondVariableButtonForm'])) {
    $answerButtonForm = getAnswer($_POST['firstVariableButtonForm'], $_POST['secondVariableButtonForm'], $_POST['operationTypeButton']);
} else {
    $_POST['firstVariableButtonForm'] = "";
    $_POST['secondVariableButtonForm'] = "";
}
?>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Задание 4</title>
  </head>
  <body>
    <?php 
echo "<h3>2. Калькулятор с выбором операций через SELECT</h3>";
Beispiel #8
0
 if ($action == '7') {
     $_SESSION['puzzleID'] = 7;
     $challenge = getChallenge($_SESSION['puzzleID']);
     include 'view/d1gg3r/Message2.php';
 } else {
     if ($action == 'unlocked') {
         $unlocked = getUnlocked($_SESSION['id']);
         include 'view/unlockedSplash.php';
     } else {
         if ($action == 'puzzles') {
             include 'view/puzzleSplash.php';
         } else {
             if ($action == 'check_solution') {
                 $text = filter_input(INPUT_GET, 'answer');
                 $answer = strtolower($text);
                 $value = getAnswer($_SESSION['puzzleID']);
                 if ($answer == $value[0]) {
                     updateUnlocked($_SESSION['id'], $_SESSION['puzzleID']);
                     $answer_error = 'New content unlocked';
                     include 'view/puzzleSplash.php';
                 } else {
                     $answer_error = 'Incorrect answer. Please try again.';
                     include 'view/puzzleSplash.php';
                 }
             } else {
                 if ($action == 'show_info') {
                     $info = $_POST['information'];
                     switch ($info) {
                         case 1:
                             include 'view/Unlocked files/1.php';
                             break;