function doClick() { $script }
EOF; } function response_with_href($message, $class, $href) { reponse_with_click($message, $class, <<
tip:选中题目查看选项
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 '
'; 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("操作异常,请联系管理员"); } } echo '
'; } } } else if (isset($_GET["action"]) && $_GET["action"] == "delete") { if (empty($_GET["question_id"])) { error_res("缺少问题id"); } else if (!is_numeric($_GET["question_id"])) { error_res("非法参数id"); } 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=?", "i", (int)$_GET["question_id"]); info_res("问题删除成功"); } catch (Exception $e) { error($e); error_res("操作异常,请联系管理员"); } } } else { \error("非法操作!"); }