tip:选中题目查看选项
EOF; $query = new QueryQuestion(); try { DbUtil::query("select * from question", $query); } catch (Exception $e) { error_res("系统出现严重异常,请联系管理员", "/"); return; } 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("问题不能为空!", "/admin/Question.php"); } else if (empty($_POST["answer"])) { error_res("答案内容不能为空!", "/admin/Question.php"); } else if (!is_array($_POST["answer"])) { error_res("非法答案参数", "/admin/Question.php"); } else if (count($_POST["answer"]) != $answer_count) { error_res("答案数量不等于4个!", "/admin/Question.php"); } else if (count(array_unique($_POST["answer"])) != $answer_count) { error_res("答案不能重复!", "/admin/Question.php"); } else if (empty($_POST["right_answer"])) { error_res("没有正确答案!", "/admin/Question.php"); } else { try { DbUtil::insert("insert into question (question_title) values (?)", 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 (?,?,?)", null, "isi", $id, $answer, array_search($answer, $_POST["answer"]) + 1 == (int)($_POST["right_answer"])); } } }, "s", $_POST["question"]); info_res("保存成功", "/admin/Question.php"); } catch (Exception $e) { error($e); error_res("保存异常,请稍后再试或者联系管理员!", "/admin/Question.php"); } } } else if (isset($_GET["action"]) && $_GET["action"] == "list") { if (empty($_GET["question_id"])) { error_res("没有指定问题id,无法查看详情信息!", "/admin/Question.php"); } else if (!is_numeric($_GET["question_id"])) { error_res("问题id不合法", "/admin/Question.php"); } else { $query_result = new QueryAnswer(); try { DbUtil::query("select * from answer where question_id=?", $query_result, array($_GET["question_id"])); } catch (Exception $e) { error_res("系统出现严重异常,请联系管理员", "/"); return; } if (empty($query_result->getAnswerArray())) { error_res("问题id不合法", "/admin/Question.php"); } else { echo '
'; foreach ($query_result->getAnswerArray() as $item) { if ($item instanceof Answer) { $answer = $item->getAnswer(); $is_true = $item->getIsTrue() == 1 ? "checked" : ""; echo <<
EOF; } else { error("类型不匹配"); error_res("操作异常,请联系管理员", "/admin/Question.php"); } } echo '
返回
'; } } } else if (isset($_GET["action"]) && $_GET["action"] == "delete") { if (empty($_GET["question_id"])) { error_res("缺少问题id", "/admin/Question.php"); } else if (!is_numeric($_GET["question_id"])) { error_res("非法参数id", "/admin/Question.php"); } else { try { DbUtil::delete("DELETE q,a FROM question as q,answer as a WHERE q.question_id=a.question_id and q.question_id=?", null, "i", (int)$_GET["question_id"]); info_res("问题删除成功", "/admin/Question.php"); } catch (Exception $e) { error($e); error_res("操作异常,请联系管理员", "/admin/Question.php"); } } } else { error("非法操作!"); \error_res("非法操作!", "/admin/Question.php"); }