EOF;
$query = new QuestionQuery();
DbUtil::query("select * from question", $query);
if (empty($query->getQuestionArray())) {
warn_res_with_click("题库暂无题目,需要添加题目", <<getQuestionArray() as $item) {
if ($item instanceof Question) {
$id = $item->getQuestionId();
$title = $item->getQuestionTitle();
echo <<
$title?
X
EOF;
}
}
}
echo <<
EOF;
} else if (isset($_POST["action"]) && $_POST["action"] == "add") {
// 答案数
$answer_count = 4;
if (empty($_POST["question"])) {
error_res("问题不能为空!");
} else if (empty($_POST["answer"])) {
error_res("答案内容不能为空!");
} else if (!is_array($_POST["answer"])) {
error_res("非法答案参数");
} else if (count($_POST["answer"]) != $answer_count) {
error_res("答案数量不等于4个!");
} else if (count(array_unique($_POST["answer"])) != $answer_count) {
error_res("答案不能重复!");
} else if (empty($_POST["right_answer"])) {
error_res("没有正确答案!");
} else {
try {
DbUtil::insert_with_param("insert into question (question_title) values (?)", "s", new class() implements DoConn
{
public function before_close(mysqli $conn)
{
$id = mysqli_insert_id($conn);
foreach ($_POST["answer"] as $answer) {
DbUtil::insert("insert into answer (question_id, answer, is_true) values (?,?,?)", "isi", $id, $answer, array_search($answer, $_POST["answer"]) + 1 == (int)($_POST["right_answer"]));
}
}
}, $_POST["question"]);
info_res("保存成功");
} catch (Exception $e) {
error($e);
error_res("保存异常,请稍后再试或者联系管理员!");
}
}
} else if (isset($_GET["action"]) && $_GET["action"] == "list") {
if (empty($_GET["question_id"])) {
error_res("没有指定问题id,无法查看详情信息!");
} else if (!is_numeric($_GET["question_id"])) {
error_res("问题id不合法");
} else {
$query_result = new AnswerQuery();
DbUtil::query("select * from answer where question_id=?", $query_result, array($_GET["question_id"]));
if (empty($query_result->getAnswerArray())) {
error_res("问题id不合法");
} else {
echo '