feat: 添加管理员操作功能以支持重判和删除提交

This commit is contained in:
2026-04-05 13:55:10 +08:00
parent 489f11ce35
commit 0c7297afd7
4 changed files with 191 additions and 0 deletions

View File

@@ -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 = "<div style='display:flex;gap:6px;justify-content:center;flex-wrap:wrap'>";
$html .= "<form method='post' action='admin/status_action.php' style='margin:0' onsubmit=\"return confirm('".$rejudge_confirm."');\">";
$html .= "<input type='hidden' name='action' value='rejudge'>";
$html .= "<input type='hidden' name='sid' value='".$solution_id."'>";
$html .= "<input type='hidden' name='return_url' value='".$return_url."'>";
$html .= "<input type='hidden' name='postkey' value='".$postkey."'>";
$html .= "<button class='ui mini orange basic button' type='submit'>".$rejudge_text."</button>";
$html .= "</form>";
if ($can_delete) {
$html .= "<form method='post' action='admin/status_action.php' style='margin:0' onsubmit=\"return confirm('".$delete_confirm."');\">";
$html .= "<input type='hidden' name='action' value='delete'>";
$html .= "<input type='hidden' name='sid' value='".$solution_id."'>";
$html .= "<input type='hidden' name='return_url' value='".$return_url."'>";
$html .= "<input type='hidden' name='postkey' value='".$postkey."'>";
$html .= "<button class='ui mini red basic button' type='submit'>".$delete_text."</button>";
$html .= "</form>";
}
else {
$html .= "<span class='ui mini disabled button' title='仅可删除已结束评测的提交'>".$delete_text."</span>";
}
$html .= "</div>";
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'];