From 0c7297afd73f287f6e41b7370ebe10212b20853e Mon Sep 17 00:00:00 2001 From: klarkxy <278370456@qq.com> Date: Sun, 5 Apr 2026 13:55:10 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=B7=BB=E5=8A=A0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E6=93=8D=E4=BD=9C=E5=8A=9F=E8=83=BD=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=87=8D=E5=88=A4=E5=92=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/admin/status_action.php | 131 +++++++++++++++++++++++++++ web/status.php | 58 ++++++++++++ web/template/syzoj/conteststatus.php | 1 + web/template/syzoj/status.php | 1 + 4 files changed, 191 insertions(+) create mode 100644 web/admin/status_action.php diff --git a/web/admin/status_action.php b/web/admin/status_action.php new file mode 100644 index 0000000..76d09b7 --- /dev/null +++ b/web/admin/status_action.php @@ -0,0 +1,131 @@ += 4 && !in_array($result, array(12, 15, 16, 17), true); +} + +function status_action_get_return_url() { + $default_url = "../status.php"; + if (!isset($_POST['return_url'])) { + return $default_url; + } + + $return_url = trim($_POST['return_url']); + if ($return_url === "") { + return $default_url; + } + + $parts = parse_url($return_url); + if ($parts === false || !isset($parts['path']) || basename($parts['path']) !== 'status.php') { + return $default_url; + } + + $safe_url = $parts['path']; + if (isset($parts['query']) && $parts['query'] !== "") { + $safe_url .= "?".$parts['query']; + } + return $safe_url; +} + +function status_action_redirect($return_url) { + header("Location: ".$return_url); + exit(0); +} + +$return_url = status_action_get_return_url(); +$sid = isset($_POST['sid']) ? intval($_POST['sid']) : 0; +$action = isset($_POST['action']) ? $_POST['action'] : ""; + +if ($sid <= 0 || ($action !== 'rejudge' && $action !== 'delete')) { + status_action_redirect($return_url); +} + +$solution = pdo_query("SELECT `solution_id`,`problem_id`,`user_id`,`contest_id`,`result` FROM `solution` WHERE `solution_id`=? LIMIT 1", $sid); +if (empty($solution)) { + status_action_redirect($return_url); +} + +$row = $solution[0]; +$problem_id = intval($row['problem_id']); +$contest_id = intval($row['contest_id']); +$user_id = $row['user_id']; +$result = intval($row['result']); + +if ($action === 'rejudge') { + pdo_query("DELETE FROM `sim` WHERE `s_id`=?", $sid); + pdo_query("UPDATE `solution` SET `result`=1,`pass_rate`=0 WHERE `solution_id`=? AND `problem_id`>0", $sid); + + if ($OJ_REDIS && class_exists('Redis')) { + $redis_class = 'Redis'; + $redis = new $redis_class(); + $redis->connect($OJ_REDISSERVER, $OJ_REDISPORT); + if (isset($OJ_REDISAUTH)) { + $redis->auth($OJ_REDISAUTH); + } + $redis->lpush($OJ_REDISQNAME, $sid); + $redis->close(); + } + + if (isset($OJ_UDP) && $OJ_UDP) { + trigger_judge($sid); + } + + status_action_redirect($return_url); +} + +if (!status_action_can_delete($result)) { + status_action_redirect($return_url); +} + +pdo_query("DELETE FROM `sim` WHERE `s_id`=? OR `sim_s_id`=?", $sid, $sid); +pdo_query("DELETE FROM `source_code` WHERE `solution_id`=?", $sid); +pdo_query("DELETE FROM `source_code_user` WHERE `solution_id`=?", $sid); +pdo_query("DELETE FROM `runtimeinfo` WHERE `solution_id`=?", $sid); +pdo_query("DELETE FROM `compileinfo` WHERE `solution_id`=?", $sid); +pdo_query("DELETE FROM `custominput` WHERE `solution_id`=?", $sid); +pdo_query("DELETE FROM `solution` WHERE `solution_id`=? LIMIT 1", $sid); + +if ($problem_id > 0) { + pdo_query( + "UPDATE `problem` SET `accepted`=(SELECT count(1) FROM `solution` WHERE `problem_id`=? AND `result`=4), `submit`=(SELECT count(1) FROM `solution` WHERE `problem_id`=?) WHERE `problem_id`=?", + $problem_id, + $problem_id, + $problem_id + ); +} + +if ($contest_id > 0 && $problem_id > 0) { + pdo_query( + "UPDATE `contest_problem` SET `c_accepted`=(SELECT count(1) FROM `solution` WHERE `problem_id`=? AND `contest_id`=? AND `result`=4), `c_submit`=(SELECT count(1) FROM `solution` WHERE `problem_id`=? AND `contest_id`=?) WHERE `problem_id`=? AND `contest_id`=?", + $problem_id, + $contest_id, + $problem_id, + $contest_id, + $problem_id, + $contest_id + ); +} + +pdo_query( + "UPDATE `users` SET `solved`=(SELECT count(DISTINCT `problem_id`) FROM `solution` WHERE `user_id`=? AND `result`=4), `submit`=(SELECT count(*) FROM `solution` WHERE `user_id`=? AND `problem_id`>0) WHERE `user_id`=?", + $user_id, + $user_id, + $user_id +); + +status_action_redirect($return_url); +?> \ No newline at end of file diff --git a/web/status.php b/web/status.php index b326363..03b7b71 100644 --- a/web/status.php +++ b/web/status.php @@ -81,6 +81,42 @@ function formatTimeLength($length) { return $result; } +function status_admin_can_delete($result) { + return $result >= 4 && !in_array($result, array(12, 15, 16, 17), true); +} + +function build_status_admin_actions($solution_id, $postkey, $return_url, $can_delete, $rejudge_text, $delete_text) { + $solution_id = intval($solution_id); + $postkey = htmlspecialchars($postkey, ENT_QUOTES, 'UTF-8'); + $return_url = htmlspecialchars($return_url, ENT_QUOTES, 'UTF-8'); + $rejudge_text = htmlspecialchars($rejudge_text, ENT_QUOTES, 'UTF-8'); + $delete_text = htmlspecialchars($delete_text, ENT_QUOTES, 'UTF-8'); + $rejudge_confirm = htmlspecialchars("确认重判提交 #".$solution_id." 吗?", ENT_QUOTES, 'UTF-8'); + $delete_confirm = htmlspecialchars("确认删除提交 #".$solution_id." 吗?此操作不可恢复。", ENT_QUOTES, 'UTF-8'); + $html = "
"; + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= "
"; + if ($can_delete) { + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= "
"; + } + else { + $html .= "".$delete_text.""; + } + $html .= "
"; + return $html; +} + require_once("./include/my_func.inc.php"); if (isset($OJ_LANG)) { @@ -90,6 +126,18 @@ if (isset($OJ_LANG)) { require_once("./include/const.inc.php"); +$status_admin_actions_enabled = isset($_SESSION[$OJ_NAME.'_'.'administrator']) && $OJ_TEMPLATE=="syzoj"; +$status_admin_postkey = ""; +$status_admin_return_url = "/status.php"; +if ($status_admin_actions_enabled && isset($_SESSION[$OJ_NAME.'_'.'user_id'])) { + $status_admin_postkey = strtoupper(substr(md5($_SESSION[$OJ_NAME.'_'.'user_id'].rand(0,9999999)),0,10)); + $_SESSION[$OJ_NAME.'_'.'postkey'] = $status_admin_postkey; + if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI']!="") { + $status_admin_return_url = $_SERVER['REQUEST_URI']; + } +} + + $str2 = ""; $lock = false; $lock_time = date("Y-m-d H:i:s",time()); @@ -541,6 +589,16 @@ for ($i=0; $i<$rows_cnt; $i++) { if (isset($_SESSION[$OJ_NAME.'_'.'administrator'])) { $view_status[$i][8] = substr($row['in_date'],5)."[".$used."]"; $view_status[$i][9] = $row['judger']; + if ($status_admin_actions_enabled) { + $view_status[$i][10] = build_status_admin_actions( + $row['solution_id'], + $status_admin_postkey, + $status_admin_return_url, + status_admin_can_delete(intval($row['result'])), + $MSG_REJUDGE, + $MSG_DELETE + ); + } } else $view_status[$i][8]= $row['in_date']; diff --git a/web/template/syzoj/conteststatus.php b/web/template/syzoj/conteststatus.php index 787b987..f26381d 100644 --- a/web/template/syzoj/conteststatus.php +++ b/web/template/syzoj/conteststatus.php @@ -91,6 +91,7 @@ echo ""; echo $MSG_JUDGER; echo ""; + echo "操作"; } ?> diff --git a/web/template/syzoj/status.php b/web/template/syzoj/status.php index b53d0d9..31d43bf 100644 --- a/web/template/syzoj/status.php +++ b/web/template/syzoj/status.php @@ -93,6 +93,7 @@ echo ""; echo $MSG_JUDGER; echo ""; + echo "操作"; } ?>