✨ feat: 添加管理员操作功能以支持重判和删除提交
This commit is contained in:
131
web/admin/status_action.php
Normal file
131
web/admin/status_action.php
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
require_once("../include/db_info.inc.php");
|
||||||
|
require_once("../include/my_func.inc.php");
|
||||||
|
|
||||||
|
if (!(isset($_SESSION[$OJ_NAME.'_'.'administrator']))) {
|
||||||
|
header("Location: ../loginpage.php");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
header("Location: ../status.php");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once("../include/check_post_key.php");
|
||||||
|
|
||||||
|
function status_action_can_delete($result) {
|
||||||
|
return $result >= 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);
|
||||||
|
?>
|
||||||
@@ -81,6 +81,42 @@ function formatTimeLength($length) {
|
|||||||
return $result;
|
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");
|
require_once("./include/my_func.inc.php");
|
||||||
|
|
||||||
if (isset($OJ_LANG)) {
|
if (isset($OJ_LANG)) {
|
||||||
@@ -90,6 +126,18 @@ if (isset($OJ_LANG)) {
|
|||||||
require_once("./include/const.inc.php");
|
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 = "";
|
$str2 = "";
|
||||||
$lock = false;
|
$lock = false;
|
||||||
$lock_time = date("Y-m-d H:i:s",time());
|
$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'])) {
|
if (isset($_SESSION[$OJ_NAME.'_'.'administrator'])) {
|
||||||
$view_status[$i][8] = substr($row['in_date'],5)."[".$used."]";
|
$view_status[$i][8] = substr($row['in_date'],5)."[".$used."]";
|
||||||
$view_status[$i][9] = $row['judger'];
|
$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
|
else
|
||||||
$view_status[$i][8]= $row['in_date'];
|
$view_status[$i][8]= $row['in_date'];
|
||||||
|
|||||||
@@ -91,6 +91,7 @@
|
|||||||
echo "<th class='desktop-only item'>";
|
echo "<th class='desktop-only item'>";
|
||||||
echo $MSG_JUDGER;
|
echo $MSG_JUDGER;
|
||||||
echo "</th>";
|
echo "</th>";
|
||||||
|
echo "<th class='desktop-only item'>操作</th>";
|
||||||
} ?>
|
} ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -93,6 +93,7 @@
|
|||||||
echo "<th class='desktop-only item'>";
|
echo "<th class='desktop-only item'>";
|
||||||
echo $MSG_JUDGER;
|
echo $MSG_JUDGER;
|
||||||
echo "</th>";
|
echo "</th>";
|
||||||
|
echo "<th class='desktop-only item'>操作</th>";
|
||||||
} ?>
|
} ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
Reference in New Issue
Block a user