feat(ui): 重新设计判题结果页与提交页

- 判题结果页引入友好错误解释面板,按 verdict 类型给出提示与改进建议
- 新增 dedup_runtimeinfo() 函数将重复 RE 测试点折叠为区间汇总
- 区分管理员/源浏览者与普通用户视图,原始错误默认折叠
- 错误模式匹配扩展至 28 条,覆盖 glibc/Java/Python/Go 等常见运行时异常
- 提交页改用卡片式布局,编辑器工具栏与测试运行区交互优化
- 中英文语言文件补充相关文案与快捷操作标签
- 切换 LLM 点评 API 至 newapi.klarkxy.xyz,模型改为 minimax-m3
- 新增 .codegraph/.gitignore 忽略本地调试数据
This commit is contained in:
2026-07-08 20:56:17 +08:00
parent c4e0f104b4
commit 6c462655b9
7 changed files with 1236 additions and 419 deletions

5
web/.codegraph/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
# CodeGraph data files — local to each machine, not for committing.
# Ignore everything in .codegraph/ except this file itself, so transient
# files (the database, daemon.pid, sockets, logs) never show up in git.
*
!.gitignore

View File

@@ -147,9 +147,9 @@ static $OJ_MENU_NEWS=true;
/* LLM AI Review - AI错误点评功能 */
static $OJ_LLM_ENABLED=true; // 总开关设为true开启AI点评
static $OJ_LLM_API_URL="https://api.minimaxi.com/anthropic/v1/messages"; // API地址MiniMax Anthropic兼容格式
static $OJ_LLM_API_KEY="sk-cp-w571CJpA_6WP5P6b_xGVbjOqXOGBWTQsiNY9xxAPambouIhD7ic3GHIoWce0ON_Y7Q0rVLzBWtgwwS8cQVUxS1guBxYkPJoJ33q0jEcx0Qei60bx5La4fB4"; // 填入你的MiniMax API Key
static $OJ_LLM_MODEL="MiniMax-M3"; // 模型名称,如 MiniMax-M3 / MiniMax-M2.7 / MiniMax-M2.5 / MiniMax-M2.5-highspeed
static $OJ_LLM_API_URL="https://newapi.klarkxy.xyz/v1/messages"; // API地址MiniMax Anthropic兼容格式
static $OJ_LLM_API_KEY="sk-2qWDjt8NJ5gwuAq1WWpaVsdIZ0qlImKDjtGpByYm3RvHV2NP"; // 填入你的MiniMax API Key
static $OJ_LLM_MODEL="minimax-m3"; // 模型名称,如 MiniMax-M3 / MiniMax-M2.7 / MiniMax-M2.5 / MiniMax-M2.5-highspeed
static $OJ_LLM_MAX_TOKENS=65536; // 最大输出token数
static $OJ_LLM_TIMEOUT=60; // 请求超时LLM响应较慢建议60秒
static $OJ_LLM_SYSTEM_PROMPT=""; // 自定义系统prompt留空使用内置默认

View File

@@ -358,7 +358,39 @@
$MSG_YOURS="你的程序输出";
$MSG_FILENAME="文件名";
$MSG_SIZE="大小";
// reinfo.php 友好提示
$MSG_RUNTIME_GENERIC_ERROR="程序运行时发生了未明确的错误。建议:检查边界条件、空输入、特殊值处理。";
$MSG_FORBIDDEN_SYSCALL="使用了系统禁止的操作系统调用,看看是否越权访问了文件或进程等资源。";
$MSG_HINT_TLE="程序运行超过了题目设定的时间限制 (TLE)。常见原因:算法复杂度过高(如 O() n 10、死循环、I/O 效率低(建议用 scanf/printf 或更快 I/O";
$MSG_HINT_MLE="程序使用的内存超过了题目设定的限制 (MLE)。常见原因:数组开得过大、递归过深未释放、全局变量占用空间过多。";
$MSG_HINT_OLE="输出内容超过了限制 (OLE)。常见原因:死循环输出、忘记换行、调试信息未删除。";
$MSG_RAW_ERROR="查看原始错误信息";
$MSG_RESULT_BANNER="判题结果";
$MSG_QUICK_ACTIONS="快捷操作";
$MSG_RESUBMIT="重新提交";
$MSG_VIEW_SOURCE="查看我的代码";
$MSG_VIEW_PROBLEM="查看题目";
$MSG_DOWNLOAD_DATA="下载测试数据";
$MSG_FRIENDLY_EXPLAIN="错误解释";
$MSG_DEDUP_HINT="已折叠 %d 个相同测试点";
$MSG_AI_REVIEW_DESC="基于你的代码和判题结果分析";
$MSG_DEDUP_GROUP="%s: %s ( %d 个测试点)";
// 新增 RE 模式(覆盖 glibc / Java / Python / Go
$MSG_STACK_SMASHING_DETECTED="栈保护触发stack smashing detected通常是数组越界写入了栈上的数据。检查字符数组、循环写入是否越界。";
$MSG_TERMINATE_CALLED="C++ 抛出未捕获的异常terminate called after throwing an instance of...)。检查代码中的 throw 语句是否有对应的 try/catch";
$MSG_NULL_POINTER_EXCEPTION="空指针异常NullPointerException。某处对未初始化的对象调用了方法或访问了字段。";
$MSG_NUMBER_FORMAT_EXCEPTION="数字格式异常NumberFormatException。把非数字字符串转换成数字时出错检查输入解析逻辑。";
$MSG_CLASS_CAST_EXCEPTION="类型转换异常ClassCastException。把对象强制转换为不兼容的类型。";
$MSG_NEGATIVE_ARRAY_SIZE_EXCEPTION="数组长度为负数NegativeArraySizeException。检查计算数组长度时是否出现负值。";
$MSG_PYTHON_TRACEBACK="Python 抛出异常,下方是调用栈,从下往上读就是异常发生的位置。";
$MSG_PYTHON_RECURSION_ERROR="递归层数过多RecursionError。递归深度超过了默认限制1000考虑改为迭代或手动加深递归限制。";
$MSG_PYTHON_INDENTATION_ERROR="缩进错误IndentationError。Python 用缩进表示代码块,请检查空格/Tab 是否混用。";
$MSG_PYTHON_ZERO_DIVISION="除以零错误ZeroDivisionError";
$MSG_PYTHON_NAME_ERROR="使用了未定义的变量或函数NameError。检查拼写、是否忘记 import。";
$MSG_GO_PANIC="Go 运行时报错panic通常是越界访问、nil 指针或类型断言失败。";
$MSG_ABORTED_CORE_DUMPED="程序被 abort() 终止Aborted通常源于 assert 失败或 std::terminate。";
// template/../ceinfo.php
$MSG_ERROR_EXPLAIN="辅助解释";

View File

@@ -357,6 +357,39 @@
$MSG_INVALID_CONVERSION="The implicit type conversion is invalid, try to use explicit coercion such as (int *)malloc(....)";
$MSG_NO_RETURN_TYPE_IN_MAIN="In the C++ standard, the main function must have a return value.";
$MSG_NOT_DECLARED_IN_SCOPE="The variable has not been declared, check for spelling errors!";
// reinfo.php friendly hints
$MSG_RUNTIME_GENERIC_ERROR="An unspecified runtime error occurred. Check boundary conditions, empty inputs, and edge cases.";
$MSG_FORBIDDEN_SYSCALL="A forbidden system call was used. Check if you tried to access files, network, or processes directly.";
$MSG_HINT_TLE="Time Limit Exceeded (TLE). Common causes: high algorithm complexity (e.g. O(n²) when n ≤ 10⁵), infinite loops, slow I/O. Use scanf/printf or faster I/O.";
$MSG_HINT_MLE="Memory Limit Exceeded (MLE). Common causes: oversized arrays, deep recursion, unreleased memory.";
$MSG_HINT_OLE="Output Limit Exceeded (OLE). Common causes: infinite output loops, missing newlines, leftover debug prints.";
$MSG_RAW_ERROR="View raw error information";
$MSG_RESULT_BANNER="Verdict";
$MSG_QUICK_ACTIONS="Quick actions";
$MSG_RESUBMIT="Resubmit";
$MSG_VIEW_SOURCE="View my code";
$MSG_VIEW_PROBLEM="View problem";
$MSG_DOWNLOAD_DATA="Download test data";
$MSG_FRIENDLY_EXPLAIN="Error explanation";
$MSG_DEDUP_HINT="Collapsed %d duplicate test cases";
$MSG_AI_REVIEW_DESC="Analyzing your code and verdict";
$MSG_DEDUP_GROUP="%s: %s (in %d test cases)";
// Additional RE patterns
$MSG_STACK_SMASHING_DETECTED="Stack smashing detected. Usually means an out-of-bounds write into a stack buffer. Check char arrays and loop write bounds.";
$MSG_TERMINATE_CALLED="C++ exception was thrown but not caught (terminate called after throwing). Check that all throw statements are wrapped in try/catch.";
$MSG_NULL_POINTER_EXCEPTION="NullPointerException. A method or field was called on an uninitialized object.";
$MSG_NUMBER_FORMAT_EXCEPTION="NumberFormatException. Failed to parse a non-numeric string as a number. Check your input parsing.";
$MSG_CLASS_CAST_EXCEPTION="ClassCastException. Tried to cast an object to an incompatible type.";
$MSG_NEGATIVE_ARRAY_SIZE_EXCEPTION="NegativeArraySizeException. The array size computed to a negative value.";
$MSG_PYTHON_TRACEBACK="Python raised an exception. The traceback below shows the call stack — read from bottom to top to find the origin.";
$MSG_PYTHON_RECURSION_ERROR="RecursionError: maximum recursion depth exceeded. Consider converting to iteration or raising the limit.";
$MSG_PYTHON_INDENTATION_ERROR="IndentationError. Python uses indentation for code blocks. Check for mixed tabs/spaces.";
$MSG_PYTHON_ZERO_DIVISION="ZeroDivisionError.";
$MSG_PYTHON_NAME_ERROR="NameError. Used an undefined name (variable or function). Check spelling and imports.";
$MSG_GO_PANIC="Go panic — usually out-of-bounds access, nil pointer, or failed type assertion.";
$MSG_ABORTED_CORE_DUMPED="Aborted. Usually caused by a failed assert or std::terminate.";
$MSG_MAIN_MUST_RETURN_INT="In the standard C language, the return value type of the main function must be int, and the use of void in teaching materials and VC is a non-standard usage.";
$MSG_PRINTF_NOT_DECLARED_IN_SCOPE="The printf function is called without a declaration, and check whether the <stdio.h> or <cstdio> header file is imported.";
$MSG_IGNOREING_RETURN_VALUE="Warning: Ignore the return value of the function, it may be that the function is used incorrectly or the return value is not considered abnormal.";

View File

@@ -24,9 +24,10 @@ if(!isset($_GET['sid'])){
function is_valid($str2){
global $_SESSION,$OJ_NAME,$OJ_FRIENDLY_LEVEL;
if(isset($_SESSION[$OJ_NAME.'_'.'source_browser'])) return true;
return true; // 如果希望能让任何人都查看对比和RE,放开行首注释,并设定$OJ_SHOW_DIFF=true; if you fail to view diff , try remove the // at beginning of this line.
if($OJ_FRIENDLY_LEVEL>3) return true;
// 如果希望能让任何人都查看对比和RE,放开行首注释,并设定$OJ_SHOW_DIFF=true;
// return true;
$n = strlen($str2);
$str = str_split($str2);
$m = 1;
@@ -65,39 +66,190 @@ if(!empty($spj)&&$spj[0][0]==2 && $OJ_HIDE_RIGHT_ANSWER && !isset($_SESSION[$OJ_
$view_errors = "<h1>$MSG_MARK:$mark</h1><br>";
$ok = false;
}
/**
* 把 N 个相同测试点的 RE 折叠为 "1.in~5.in: Aborted (共 5 个测试点)"
*/
function dedup_runtimeinfo($text, &$dedup_count) {
$lines = explode("\n", $text);
$buckets = array(); // reason => [testcase, ...]
$other = array();
foreach ($lines as $line) {
$line = trim($line);
if ($line === "") continue;
// 形如 "data/1001/1.in:Aborted" 或 "1.in: Segmentation fault"
if (preg_match('/^(?:data\/\d+\/)?([^\s:]+(?:[.:][^\s:]+)*?):\s*(.+)$/', $line, $m)) {
$tc = $m[1];
$reason = trim($m[2]);
$buckets[$reason][] = $tc;
} else {
$other[] = $line;
}
}
$out = array();
foreach ($other as $o) $out[] = $o;
foreach ($buckets as $reason => $tcs) {
$count = count($tcs);
if ($count == 1) {
$out[] = $tcs[0] . ": " . $reason;
} else {
$first = $tcs[0];
$last = $tcs[$count - 1];
$range = ($first === $last) ? $first : ($first . "~" . $last);
$out[] = $range . ": " . $reason . " (共 " . $count . " 个测试点)";
$dedup_count += ($count - 1);
}
}
return implode("\n", $out);
}
$view_reinfo = "";
$view_reinfo_raw = ""; // 原始(管理员/有权限者看)
$view_reinfo_summary = ""; // 折叠后(普通用户看)
$view_reinfo_dedup_count = 0; // 折叠掉的测试点数
$verdict_color_class = "blue"; // semantic ui color: green/red/orange/yellow/grey
$result_icon = "info circle";
$verdict_tip = "";
$verdict_hints = array();
if($ok){
if($row['user_id']!=$_SESSION[$OJ_NAME.'_'.'user_id']){
$view_mail_link= "<a href='mail.php?to_user=".htmlentities($row['user_id'],ENT_QUOTES,"UTF-8")."&title=$MSG_SUBMIT $id'>Mail the auther</a>";
}
$sql = "SELECT `error` FROM `runtimeinfo` WHERE `solution_id`=?";
$result = pdo_query($sql,$id);
if(isset($result[0])){
$row = $result[0];
$view_reinfo = str_replace("\n\r","\n",$row['error']);
// $view_reinfo=htmlentities($view_reinfo,ENT_QUOTES,"UTF-8");
$rt = pdo_query($sql,$id);
$raw_error = "";
if(isset($rt[0])){
$raw_error = str_replace("\n\r","\n",$rt[0]['error']);
}
if(strpos($row['error'],"judge/")!==false&&!isset($_SESSION[$OJ_NAME."_administrator"])) $view_reinfo = "潜在的数组或指针越界,请检查代码。";
else if(strpos($row['error'],"php")!==false) $view_reinfo = "error2";
else if(strpos($row['error'],"PASS")!==false) $view_reinfo = "error3";
else if($OJ_SHOW_DIFF && $row && ($ok||$isRE) && ($OJ_TEST_RUN||is_valid($row['error'])||$ok)){
$view_reinfo = str_replace("\n\r","\n",$row['error']);
$view_reinfo = htmlspecialchars_decode($view_reinfo,ENT_QUOTES);
// $view_reinfo = htmlentities($view_reinfo,ENT_QUOTES,"UTF-8");
// $view_reinfo = "```\n" . $view_reinfo. "```\n";
$view_reinfo .="<br>$MSG_MARK:$mark";
// === 阶段 1基于 solution.result 给"主解释"(永远非空)===
$result_code = intval($row['result']);
$is_admin_session = isset($_SESSION[$OJ_NAME."_administrator"]);
$is_source_browser = isset($_SESSION[$OJ_NAME.'_'.'source_browser']);
// 颜色 + 图标
switch ($result_code) {
case 4: $verdict_color_class = "green"; $result_icon = "check circle"; break;
case 5: // PE
case 6: $verdict_color_class = "red"; $result_icon = "times circle"; break;
case 7: // TLE
case 8: // MLE
case 9: $verdict_color_class = "yellow";$result_icon = "hourglass end"; break;
case 10: $verdict_color_class = "red"; $result_icon = "bug"; break;
case 11: $verdict_color_class = "grey"; $result_icon = "code"; break;
case 13: $verdict_color_class = "blue"; $result_icon = "play circle"; break;
default: $verdict_color_class = "blue"; $result_icon = "info circle";
}
else{
$view_errors = $MSG_WARNING_ACCESS_DENIED;
//$view_reinfo = "出于数据保密原因,当前错误提示不可查看,如果希望能让任何人都查看对比和运行错误,请管理员配置\$OJ_SHOW_DIFF=true;<br>然后编辑本文件开放18行首注释令is_valid总是返回true。 <br>\n Sorry , not available (RE:".$isRE.",OJ_SHOW_DIFF:".$OJ_SHOW_DIFF.",TR:".$OJ_TEST_RUN.",valid:".is_valid($row['error']).")";
// 友好提示
switch ($result_code) {
case 4: // AC
$verdict_tip = "本次提交通过了所有测试点";
$verdict_hints[] = "注意时间/内存是否接近限制,考虑是否有更优的算法";
$verdict_hints[] = "可以继续挑战更高难度或查看其他人的标程";
break;
case 5: // PE
$verdict_tip = "输出与预期基本一致但格式不符Presentation Error";
$verdict_hints[] = "对照样例:每行末尾是否多/少换行";
$verdict_hints[] = "检查空格、大小写、标点符号";
$verdict_hints[] = "PE 通常是细微的格式问题,请逐字符对比";
break;
case 6: // WA
$verdict_tip = "输出与预期不符Wrong Answer";
$verdict_hints[] = "对照样例手动模拟程序执行过程";
$verdict_hints[] = "检查边界条件n=0、n=1、极值、空输入";
$verdict_hints[] = "注意 long long 溢出、int 范围";
break;
case 7: // TLE
$verdict_tip = $MSG_HINT_TLE;
$verdict_hints[] = "检查是否有死循环(循环变量未更新)";
$verdict_hints[] = "优化算法复杂度(如 O(n²) → O(n log n)";
$verdict_hints[] = "递归层数过深?改为迭代或加深栈";
break;
case 8: // MLE
$verdict_tip = $MSG_HINT_MLE;
$verdict_hints[] = "大数组开在函数内(栈)?改为全局或 new";
$verdict_hints[] = "Java: 减小内存使用或调整 JVM 参数";
$verdict_hints[] = "递归太深未释放,考虑显式清理";
break;
case 9: // OLE
$verdict_tip = $MSG_HINT_OLE;
$verdict_hints[] = "是否有死循环输出";
$verdict_hints[] = "调试用的 print/cout 是否忘记删除";
break;
case 10: // RE
$verdict_tip = "程序运行中发生错误Runtime Error";
$verdict_hints[] = "数组下标是否越界i<n 还是 i<=n";
$verdict_hints[] = "除以零、空指针、栈溢出";
$verdict_hints[] = "递归爆栈:转迭代或加尾递归";
break;
case 11: // CE
$verdict_tip = "编译错误Compile Error。请查看编译信息页。";
break;
case 13: // TR (test run)
$verdict_tip = "测试运行完成Test Run";
$verdict_hints[] = "你输入的测试数据已与程序输出对比";
break;
default:
$verdict_tip = "正在评判,请稍候刷新";
}
// === 阶段 2syscall vs 真正越界 的区分 ===
if ($result_code === 10) {
if (preg_match('/Forbidden system call.*CALLID:(\d+)/', $raw_error, $m)) {
$callid = $m[1];
$verdict_hints[] = sprintf("系统调用 ID=%d 被判题器禁止,常见于直接操作文件/网络/进程", $callid);
}
// Java / Python / Go 的细化提示
if (preg_match('/java\.lang\.(\w+Exception|\w+Error)/', $raw_error, $m2)) {
$verdict_hints[] = "Java 异常类型:" . $m2[1];
} elseif (preg_match('/Traceback \(most recent call last\)/', $raw_error)) {
$verdict_hints[] = "Python 抛出异常,下方 traceback 从下往上读就是异常源头";
} elseif (preg_match('/panic:.*?(index out of range|invalid memory address|nil pointer)/i', $raw_error)) {
$verdict_hints[] = "Go 运行时报错:通常是越界访问或 nil 指针";
}
}
// === 阶段 3原始错误处理syscall 提示 vs 占位符修复)===
$view_reinfo_raw = $raw_error;
if (trim($raw_error) === "") {
// TLE/MLE/OLE 时 runtimeinfo 通常为空
$view_reinfo_summary = "";
} else {
// 含 "PASS" 不再显示 "error3" 占位
// 含 "php" 不再显示 "error2" 占位(用 generic 提示)
if (strpos($raw_error, "php") !== false) {
$view_reinfo_summary = $MSG_RUNTIME_GENERIC_ERROR;
$view_reinfo_raw = $raw_error; // 管理员仍能看
}
// 含 "judge/" 区分:是否是 syscall 错误
elseif (strpos($raw_error, "judge/") !== false
&& strpos($raw_error, "CALLID") === false
&& strpos($raw_error, "Forbidden system call") === false) {
$view_reinfo_summary = "潜在的数组或指针越界,请检查代码。";
}
// 默认:原文 + 去重
else {
$view_reinfo_summary = $raw_error;
// 多测试点去重:按 "infile: error" 模式分组
$view_reinfo_summary = dedup_runtimeinfo($view_reinfo_summary, $view_reinfo_dedup_count);
}
}
$view_reinfo = $view_reinfo_summary;
// 管理员或 source_browser 永远看完整原文
$show_raw = $is_admin_session || $is_source_browser;
if ($show_raw) {
$view_reinfo = $view_reinfo_raw;
} else {
$view_reinfo = $view_reinfo_summary;
}
}
// 不是本人的提交,且不是 source_browser
else{
if($spj[0][0]!=2) $view_errors = $MSG_WARNING_ACCESS_DENIED;
require("template/".$OJ_TEMPLATE."/error.php");

View File

@@ -7,207 +7,239 @@
.single-subtask {
box-shadow: none !important;
}
.single-subtask > .title {
display: none;
}
.single-subtask > .content {
padding: 0 !important;
}
.accordion > .content > .accordion {
margin-top: 0;
margin-bottom: 0;
}
.accordion > .content > .accordion > .content {
margin-top: 0;
margin-bottom: 14px;
}
.accordion > .content > .accordion > .content > :last-child {
margin-bottom: -10px !important;
}
/* === reinfo 友好化样式 === */
#result-banner {
margin-bottom: 18px;
border-left: 5px solid;
}
#result-banner.green { border-left-color: #21ba45; }
#result-banner.red { border-left-color: #db2828; }
#result-banner.yellow{ border-left-color: #fbbd08; }
#result-banner.blue { border-left-color: #2185d0; }
#result-banner.grey { border-left-color: #767676; }
#result-banner h2.ui.header {
margin: 0;
}
#result-banner .verdict-stats {
margin-top: 6px;
font-size: 0.95em;
color: rgba(0,0,0,0.6);
}
#result-banner .verdict-stats .stat {
margin-right: 16px;
}
#result-banner .verdict-stats i.icon {
margin-right: 4px;
}
#friendly-explain {
margin-bottom: 18px;
}
#friendly-explain .verdict-tip {
font-size: 1.05em;
margin-bottom: 12px;
padding: 8px 12px;
background: rgba(33,150,243,0.08);
border-radius: 6px;
border-left: 3px solid #2185d0;
}
#friendly-explain .verdict-hints {
margin: 0;
padding-left: 22px;
}
#friendly-explain .verdict-hints li {
margin-bottom: 6px;
line-height: 1.5;
}
#raw-info-accordion {
margin-bottom: 18px;
}
#raw-info-accordion > .content {
padding: 8px 14px;
}
#raw-info-accordion pre#errtxt {
margin: 0;
padding: 12px;
background: #f7f7f9;
border-radius: 4px;
font-family: 'Fira Mono', 'Cascadia Code', Consolas, monospace;
font-size: 0.9em;
white-space: pre-wrap;
word-break: break-all;
}
#raw-info-accordion .title .dedup-label {
margin-left: 8px;
}
#raw-info-accordion .empty-notice {
color: #999;
font-style: italic;
}
.quick-actions {
text-align: center;
margin-top: 24px;
margin-bottom: 12px;
}
.quick-actions .ui.buttons {
box-shadow: none;
}
/* AI 点评区 */
#llm-section {
margin-top: 20px;
margin-bottom: 18px;
}
#llm-section .ui.header {
margin-top: 0;
}
#llm-review-result {
word-break: break-word;
}
/* 错误解释列表(由 JS explain() 填充) */
#errexp-list {
list-style: disc;
padding-left: 22px;
margin: 0;
}
#errexp-list li {
margin-bottom: 6px;
line-height: 1.5;
}
#errexp-list li code {
background: rgba(0,0,0,0.05);
padding: 1px 4px;
border-radius: 3px;
font-size: 0.9em;
}
</style>
<div class="padding">
<div style="margin-top: 0px; margin-bottom: 14px; " v-if="content != null && content !== ''">
<p class="transition visible">
<strong ><?php echo "$MSG_ERROR_INFO";?> </strong>
</p>
<div class="ui existing segment">
<div v-if="escape" style="margin-top: 0; margin-bottom: 0; " id="errtxt">
<pre><?php
echo $view_reinfo
?></pre>
<h2></h2>
</div>
</div>
</div>
<?php
// 兼容老变量:$row 是 solution 行reinfo.php 已查询过)
$verdict_name = isset($judge_result[$row['result']]) ? $judge_result[$row['result']] : (isset($MSG_UNKNOWN) ? $MSG_UNKNOWN : 'Unknown');
$verdict_lang = isset($language_name[$lang]) ? $language_name[$lang] : '?';
$verdict_memory = isset($row['memory']) ? intval($row['memory']) : 0;
$verdict_time = isset($row['time']) ? intval($row['time']) : 0;
$verdict_mark = isset($mark) ? $mark : (isset($row['pass_rate']) ? round($row['pass_rate']*100, 1) : 0);
?>
<div style="margin-top: 0px; margin-bottom: 14px; " v-if="content != null && content !== ''">
<p class="transition visible">
<strong ><?php echo "$MSG_INFO_EXPLAINATION";?></strong>
</p>
<div class="ui existing segment">
<pre v-if="escape" style="margin-top: 0; margin-bottom: 0; "><code><div id='errexp'></div></code></pre>
</div>
</div>
</div>
<script>
var pats=new Array();
var exps=new Array();
pats[0]=/A Not allowed system call/;
exps[0]="<?php echo $MSG_A_NOT_ALLOWED_SYSTEM_CALL ?>";
pats[1]=/Segmentation fault/;
exps[1]="<?php echo $MSG_SEGMETATION_FAULT ?>";
pats[2]=/Floating point exception/;
exps[2]="<?php echo $MSG_FLOATING_POINT_EXCEPTION ?>";
pats[3]=/buffer overflow detected/;
exps[3]="<?php echo $MSG_BUFFER_OVERFLOW_DETECTED ?>";
pats[4]=/Killed/;
exps[4]="<?php echo $MSG_PROCESS_KILLED ?>";
pats[5]=/Alarm clock/;
exps[5]="<?php echo $MSG_ALARM_CLOCK ?>";
pats[6]=/CALLID:20/;
exps[6]="<?php echo $MSG_CALLID_20 ?>";
pats[7]=/ArrayIndexOutOfBoundsException/;
exps[7]="<?php echo $MSG_ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION ?>";
pats[8]=/StringIndexOutOfBoundsException/;
exps[8]="<?php echo $MSG_STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION ?>";
pats[9]=/Binary files/;
exps[9]="<?php echo $MSG_WRONG_OUTPUT_TYPE_EXCEPTION ?>";
pats[10]=/non-zero return/;
exps[10]="<?php echo $MSG_NON_ZERO_RETURN ?>";
function explain(){
var errmsg = $("#errtxt").text();
var expmsg = "";
for(var i=0; i<pats.length; i++){
var pat = pats[i];
var exp = exps[i];
var ret = pat.exec(errmsg);
if(ret){
expmsg += ret+" : "+exp+"<br><hr />";
}
}
document.getElementById("errexp").innerHTML=expmsg;
}
explain();
</script>
<?php if(isset($OJ_MARKDOWN)&&$OJ_MARKDOWN){ ?>
<script>
$(document).ready(function(){
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#8521d022",
"height": "30px"
});
$("#errtxt table tr:even td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#2185d022",
"height": "30px"
});
$("#errtxt table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#2185d088",
"text-align": "center"
});
<?php
if(isset($OJ_DOWNLOAD)&&$OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?>
let down=$($("#errtxt").find("h2")[0]);
let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php
}else{
?>
$("#errtxt").find("h2").each(function(){
let down=$(this);
let filename=down.text();
console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
});
<?php
}
}
?>
$("th").each(function(){
let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
});
</script>
<?php } ?>
<?php if(isset($OJ_LLM_ENABLED) && $OJ_LLM_ENABLED){ ?>
<div style="margin-top: 20px; margin-bottom: 14px; ">
<div class="ui styled fluid accordion" id="llm-review-accordion">
<div class="title" style="font-size: 1.1em; font-weight: bold; ">
<i class="dropdown icon"></i> 🤖 AI 点评
</div>
<!-- 1. 顶部判题结果横幅 -->
<div class="ui segment <?php echo isset($verdict_color_class) ? $verdict_color_class : 'blue'; ?>" id="result-banner">
<h2 class="ui header">
<i class="<?php echo isset($result_icon) ? $result_icon : 'info circle' ?> icon" style="color: inherit;"></i>
<div class="content">
<div id="llm-review-area">
<button class="ui labeled icon blue button" id="llm-review-btn" onclick="fetchLLMReview()">
<i class="magic icon"></i> 获取 AI 点评
</button>
<div id="llm-review-loading" style="display:none; margin-top: 15px; ">
<div class="ui active centered inline text loader">AI 正在分析你的代码,请稍候...</div>
</div>
<div id="llm-review-result" style="display:none; margin-top: 15px; ">
<div class="ui existing segment" id="llm-review-content"></div>
</div>
<div id="llm-review-error" style="display:none; margin-top: 15px; ">
<div class="ui negative message">
<p id="llm-review-error-msg"></p>
</div>
</div>
<?php echo htmlspecialchars($verdict_name, ENT_QUOTES, 'UTF-8') ?>
<div class="verdict-stats">
<span class="stat"><i class="chart bar icon"></i><?php echo $MSG_MARK ?>: <?php echo $verdict_mark ?>%</span>
<span class="stat"><i class="microchip icon"></i><?php echo $verdict_memory ?> KB</span>
<span class="stat"><i class="clock icon"></i><?php echo $verdict_time ?> ms</span>
<span class="stat"><i class="code icon"></i><?php echo htmlspecialchars($verdict_lang, ENT_QUOTES, 'UTF-8') ?></span>
</div>
</div>
</h2>
</div>
<!-- 2. 友好解释区(永远非空) -->
<div class="ui message" id="friendly-explain">
<div class="header">
<i class="lightbulb outline icon"></i>
<?php echo isset($MSG_FRIENDLY_EXPLAIN) ? $MSG_FRIENDLY_EXPLAIN : '错误解释'; ?>
</div>
<div class="verdict-tip">
<i class="info circle icon"></i>
<?php echo isset($verdict_tip) ? htmlspecialchars($verdict_tip, ENT_QUOTES, 'UTF-8') : ''; ?>
</div>
<?php if (!empty($verdict_hints) && is_array($verdict_hints)): ?>
<ul class="verdict-hints">
<?php foreach ($verdict_hints as $h): ?>
<li><?php echo htmlspecialchars($h, ENT_QUOTES, 'UTF-8'); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<!-- JS explain() 也会把 pats[] 匹配到的具体错误模式追加在这里 -->
<ul id="errexp-list"></ul>
</div>
<!-- 3. 原始错误折叠(默认收起) -->
<div class="ui styled accordion" id="raw-info-accordion">
<div class="title">
<i class="dropdown icon"></i>
<?php echo isset($MSG_RAW_ERROR) ? $MSG_RAW_ERROR : '查看原始错误信息'; ?>
<?php if (!empty($view_reinfo_dedup_count)): ?>
<span class="ui tiny teal label dedup-label">
<?php echo sprintf(isset($MSG_DEDUP_HINT) ? $MSG_DEDUP_HINT : '已折叠 %d 个相同测试点', intval($view_reinfo_dedup_count)); ?>
</span>
<?php endif; ?>
<?php if (trim($view_reinfo) === ''): ?>
<span class="dedup-label empty-notice">(无)</span>
<?php endif; ?>
</div>
<div class="content">
<?php if (trim($view_reinfo) === ''): ?>
<p class="empty-notice">当前判题结果没有原始错误信息(如 TLE/MLE 通常不会写 runtimeinfo。</p>
<?php else: ?>
<pre id="errtxt"><?php
// 普通用户:折叠后;管理员/源浏览者:原文
if (isset($is_admin_session) && $is_admin_session) {
echo htmlspecialchars($view_reinfo_raw, ENT_QUOTES, 'UTF-8');
} elseif (isset($is_source_browser) && $is_source_browser) {
echo htmlspecialchars($view_reinfo_raw, ENT_QUOTES, 'UTF-8');
} else {
echo htmlspecialchars($view_reinfo, ENT_QUOTES, 'UTF-8');
}
?></pre>
<?php endif; ?>
</div>
</div>
<script>
$(document).ready(function(){
$('#llm-review-accordion').accordion();
});
<!-- 4. AI 点评区(直接显示按钮,不再折叠) -->
<?php if (isset($OJ_LLM_ENABLED) && $OJ_LLM_ENABLED) { ?>
<div class="ui raised segment" id="llm-section">
<h3 class="ui header">
<i class="magic icon"></i>
<div class="content">
AI 智能点评
<div class="sub header"><?php echo isset($MSG_AI_REVIEW_DESC) ? $MSG_AI_REVIEW_DESC : '基于你的代码和判题结果分析'; ?></div>
</div>
</h3>
<button class="ui labeled icon primary button" id="llm-review-btn" onclick="fetchLLMReview()">
<i class="magic icon"></i> 获取 AI 点评
</button>
<div id="llm-review-loading" class="ui active inline text loader" style="display:none; margin-left: 1em;">
AI 正在分析你的代码,请稍候...
</div>
<div id="llm-review-result" style="display:none; margin-top: 15px;">
<div class="ui existing segment" id="llm-review-content"></div>
</div>
<div id="llm-review-error" style="display:none; margin-top: 15px;">
<div class="ui negative message">
<p id="llm-review-error-msg"></p>
</div>
</div>
</div>
<script>
function fetchLLMReview(){
var btn = $('#llm-review-btn');
btn.prop('disabled', true).addClass('loading');
@@ -221,12 +253,11 @@
var reader = null;
var decoder = new TextDecoder();
// 解析 SSE 事件
var sseBuffer = "";
function processSSE(text) {
sseBuffer += text;
var lines = sseBuffer.split('\n');
sseBuffer = lines.pop(); // 保留未完成的行
sseBuffer = lines.pop();
var currentEvent = "";
for (var i = 0; i < lines.length; i++) {
@@ -260,7 +291,6 @@
btn.removeClass('loading').hide();
document.getElementById('llm-review-loading').style.display = 'none';
resultDiv.style.display = 'block';
// 渲染 Markdown
if (fullText && typeof HustOJVditor !== 'undefined' && HustOJVditor.renderMarkdownBlocks) {
HustOJVditor.renderMarkdownBlocks('#llm-review-content', { useTextContent: true });
}
@@ -317,4 +347,244 @@
</script>
<?php } ?>
<!-- 5. 快捷操作区 -->
<div class="quick-actions">
<div class="ui horizontal divider">
<?php echo isset($MSG_QUICK_ACTIONS) ? $MSG_QUICK_ACTIONS : '快捷操作'; ?>
</div>
<div class="ui buttons">
<a class="ui blue button" href="submitpage.php?id=<?php echo intval($row['problem_id']) ?>">
<i class="edit icon"></i> <?php echo isset($MSG_RESUBMIT) ? $MSG_RESUBMIT : '重新提交'; ?>
</a>
<a class="ui button" href="showsource.php?id=<?php echo intval($id) ?>">
<i class="code icon"></i> <?php echo isset($MSG_VIEW_SOURCE) ? $MSG_VIEW_SOURCE : '查看我的代码'; ?>
</a>
<a class="ui button" href="problem.php?id=<?php echo intval($row['problem_id']) ?>">
<i class="info circle icon"></i> <?php echo isset($MSG_VIEW_PROBLEM) ? $MSG_VIEW_PROBLEM : '查看题目'; ?>
</a>
<?php if (isset($OJ_DOWNLOAD) && $OJ_DOWNLOAD && ($isRE || $row['result']==6)) { ?>
<a class="ui orange button" href="download.php?sid=<?php echo intval($id) ?>">
<i class="download icon"></i> <?php echo isset($MSG_DOWNLOAD_DATA) ? $MSG_DOWNLOAD_DATA : '下载测试数据'; ?>
</a>
<?php } ?>
</div>
</div>
</div>
<!-- 错误模式 → 解释pats[]/exps[],共 28 条) -->
<script>
var pats = new Array();
var exps = new Array();
var patsSeen = {}; // 防止"段错误"和"stack smashing"双重提示
// === 原有 11 条 ===
pats[0]=/A Not allowed system call.* /;
exps[0]="<?php echo $MSG_A_NOT_ALLOWED_SYSTEM_CALL ?>";
pats[1]=/Segmentation fault/;
exps[1]="<?php echo $MSG_SEGMETATION_FAULT ?>";
pats[2]=/Floating point exception/;
exps[2]="<?php echo $MSG_FLOATING_POINT_EXCEPTION ?>";
pats[3]=/buffer overflow detected/;
exps[3]="<?php echo $MSG_BUFFER_OVERFLOW_DETECTED ?>";
pats[4]=/Killed/;
exps[4]="<?php echo $MSG_PROCESS_KILLED ?>";
pats[5]=/Alarm clock/;
exps[5]="<?php echo $MSG_ALARM_CLOCK ?>";
pats[6]=/CALLID:20/;
exps[6]="<?php echo $MSG_CALLID_20 ?>";
pats[7]=/ArrayIndexOutOfBoundsException/;
exps[7]="<?php echo $MSG_ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION ?>";
pats[8]=/StringIndexOutOfBoundsException/;
exps[8]="<?php echo $MSG_STRING_INDEX_OUT_OF_BOUNDS_EXCEPTION ?>";
pats[9]=/Binary files/;
exps[9]="<?php echo $MSG_WRONG_OUTPUT_TYPE_EXCEPTION ?>";
pats[10]=/non-zero return/;
exps[10]="<?php echo $MSG_NON_ZERO_RETURN ?>";
// === 新增 17 条(覆盖 glibc / Java / Python / Go ===
pats[11]=/stack smashing detected/;
exps[11]="<?php echo $MSG_STACK_SMASHING_DETECTED ?>";
// 同时标 pats[3] 已被覆盖(避免重复)
pats[12]=/terminate called after throwing/;
exps[12]="<?php echo $MSG_TERMINATE_CALLED ?>";
pats[13]=/NullPointerException/;
exps[13]="<?php echo $MSG_NULL_POINTER_EXCEPTION ?>";
pats[14]=/NumberFormatException/;
exps[14]="<?php echo $MSG_NUMBER_FORMAT_EXCEPTION ?>";
pats[15]=/ClassCastException/;
exps[15]="<?php echo $MSG_CLASS_CAST_EXCEPTION ?>";
pats[16]=/NegativeArraySizeException/;
exps[16]="<?php echo $MSG_NEGATIVE_ARRAY_SIZE_EXCEPTION ?>";
pats[17]=/Traceback \(most recent call last\)/;
exps[17]="<?php echo $MSG_PYTHON_TRACEBACK ?>";
pats[18]=/RecursionError/;
exps[18]="<?php echo $MSG_PYTHON_RECURSION_ERROR ?>";
pats[19]=/IndentationError/;
exps[19]="<?php echo $MSG_PYTHON_INDENTATION_ERROR ?>";
pats[20]=/ZeroDivisionError/;
exps[20]="<?php echo $MSG_PYTHON_ZERO_DIVISION ?>";
pats[21]=/NameError:/;
exps[21]="<?php echo $MSG_PYTHON_NAME_ERROR ?>";
pats[22]=/panic:.*runtime error/;
exps[22]="<?php echo $MSG_GO_PANIC ?>";
pats[23]=/Aborted \(core dumped\)/;
exps[23]="<?php echo $MSG_ABORTED_CORE_DUMPED ?>";
pats[24]=/CALLID:(\d+)/;
exps[24]="使用了非法的系统调用syscall请检查是否访问了文件、网络、进程等受限资源。";
pats[25]=/StackOverflowError/;
exps[25]="<?php echo $MSG_STACK_OVERFLOW_ERROR ?? '栈溢出StackOverflowError。通常是递归层数过深或局部大数组占用过多栈空间。' ?>";
pats[26]=/class not found|Could not find or load main class/;
exps[26]="Java 类未找到。检查 public class 名称是否与文件名一致,是否有 package 声明。";
pats[27]=/no test data/;
exps[27]="没有找到测试数据,请联系管理员检查题目数据。";
/**
* 把匹配到的错误模式追加到 <ul id="errexp-list">
* 同一类错误(内存类/异常类/系统调用类)只显示一次
*/
function explain(){
var errmsg = $("#errtxt").text();
if (!errmsg || errmsg.trim() === '') return;
// 同族分组
var familyMap = {
'mem': [1, 3, 11, 25], // 段错误 / 缓冲溢出 / stack smashing / 栈溢出
'sysc': [0, 6, 24], // 系统调用
'time': [4, 5], // 时间/Killed
'arith':[2, 20], // 除零
'jexc': [7, 8, 13, 14, 15, 16, 25], // Java 异常
'pyexc':[17, 18, 19, 20, 21], // Python
'goexc':[22], // Go
};
var shownFamilies = {};
var shown = {};
var items = [];
for (var i = 0; i < pats.length; i++) {
if (!pats[i] || shown[i]) continue;
var ret = pats[i].exec(errmsg);
if (!ret) continue;
// 检查是否已被同族其它规则覆盖
var family = null;
for (var f in familyMap) {
if (familyMap[f].indexOf(i) >= 0) { family = f; break; }
}
if (family && shownFamilies[family]) continue;
if (family) shownFamilies[family] = true;
shown[i] = true;
items.push("<li><code>" + ret[0] + "</code> &rarr; " + exps[i] + "</li>");
}
if (items.length > 0) {
$("#errexp-list").html(items.join(""));
} else {
$("#errexp-list").html("<li class='empty-notice'>未匹配到具体错误模式,请参考原始错误信息或 AI 点评。</li>");
}
}
explain();
</script>
<?php if(isset($OJ_MARKDOWN) && $OJ_MARKDOWN){ ?>
<script>
$(document).ready(function(){
// 初始化折叠面板
$('#raw-info-accordion').accordion();
// 管理员/superuser 默认展开原始错误
<?php if (isset($is_admin_session) && $is_admin_session) { ?>
$('#raw-info-accordion').accordion('open', 0);
<?php } elseif (isset($is_source_browser) && $is_source_browser) { ?>
$('#raw-info-accordion').accordion('open', 0);
<?php } ?>
HustOJVditor.renderMarkdownBlocks('#errtxt', {
getSource: function (element) {
var pre = element.querySelector ? element.querySelector('pre') : null;
return pre ? pre.textContent : element.textContent || '';
}
}).then(function () {
for(let i=1;i<10;i++){
$(".language-input"+i).parent().before("<div><?php echo $MSG_Input?>"+i+":</div>");
$(".language-output"+i).parent().before("<div><?php echo $MSG_Output?>"+i+":</div>");
}
$("#errtxt table").addClass("ui mini-table cell striped");
$("#errtxt table tr:odd td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#8521d022",
"height": "30px"
});
$("#errtxt table tr:even td").css({
"border": "1px solid grey",
"text-align": "center",
"width": "200px",
"background-color": "#2185d022",
"height": "30px"
});
$("#errtxt table th").css({
"border": "1px solid grey",
"width": "200px",
"height": "30px",
"background-color": "#2185d088",
"text-align": "center"
});
<?php
if(isset($OJ_DOWNLOAD) && $OJ_DOWNLOAD){
if(isset($OJ_DL_1ST_WA_ONLY) && $OJ_DL_1ST_WA_ONLY){
?>
let down=$($("#errtxt").find("h2")[0]);
let filename=down.text();
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
<?php
}else{
?>
$("#errtxt").find("h2").each(function(){
let down=$(this);
let filename=down.text();
console.log(filename);
down.html("<a href='download.php?sid=<?php echo $id?>&name=" + filename+ "'>" + filename+ "</a>");
});
<?php
}
}
?>
$("th").each(function(){
let html=$(this).html();
html=html.replace("Expected","<?php echo $MSG_EXPECTED ?>");
html=html.replace("Yours","<?php echo $MSG_YOURS ?>");
html=html.replace("filename","<?php echo $MSG_FILENAME ?>");
html=html.replace("size","<?php echo $MSG_SIZE ?>");
html=html.replace("result","<?php echo $MSG_RESULT ?>");
html=html.replace("memory","<?php echo $MSG_MEMORY?>");
html=html.replace("time","<?php echo $MSG_TIME ?>");
$(this).html(html);
});
}).catch(function (error) {
console.error('Failed to render reinfo markdown.', error);
});
});
</script>
<?php } else { ?>
<script>
// OJ_MARKDOWN 未开启时也要初始化折叠
$(document).ready(function(){
$('#raw-info-accordion').accordion();
<?php if (isset($is_admin_session) && $is_admin_session) { ?>
$('#raw-info-accordion').accordion('open', 0);
<?php } elseif (isset($is_source_browser) && $is_source_browser) { ?>
$('#raw-info-accordion').accordion('open', 0);
<?php } ?>
});
</script>
<?php } ?>
<?php include("template/$OJ_TEMPLATE/footer.php");?>

View File

@@ -1,24 +1,143 @@
<?php $show_title="$MSG_SUBMIT - $OJ_NAME"; ?>
<?php include("template/$OJ_TEMPLATE/header.php");?>
<style>
#frmSolution {
width: 100%;
text-align: left;
<style>
.submit-wrapper {
max-width: 1200px;
margin: 20px auto;
padding: 0 16px;
}
.submit-card {
background: rgba(255,255,255,0.85);
border-radius: 12px;
padding: 24px;
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
border: 1px solid rgba(255,255,255,0.5);
backdrop-filter: blur(10px);
}
.submit-header {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
padding-bottom: 16px;
margin-bottom: 20px;
border-bottom: 1px solid rgba(0,0,0,0.08);
}
.submit-title {
margin: 0;
font-size: 1.5em;
font-weight: 600;
color: #333;
}
.submit-title .problem-id {
color: #2185d0;
font-weight: 700;
}
.submit-toolbar {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 16px;
}
.submit-toolbar .field-group {
display: flex;
align-items: center;
gap: 8px;
}
.submit-toolbar .field-group > label {
margin: 0;
font-weight: 600;
color: #555;
white-space: nowrap;
}
.submit-toolbar select,
.submit-toolbar input[type="text"] {
font-size: 1em;
padding: 6px 10px;
border-radius: 6px;
border: 1px solid #d4d4d5;
background: #fff;
outline: none;
transition: border-color 0.15s;
}
.submit-toolbar select:focus,
.submit-toolbar input[type="text"]:focus {
border-color: #2185d0;
}
.submit-toolbar img#vcode {
border-radius: 4px;
cursor: pointer;
height: 32px;
vertical-align: middle;
}
.editor-card {
background: #fff;
border-radius: 8px;
border: 1px solid #d4d4d5;
overflow: hidden;
margin-bottom: 16px;
}
.editor-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background: #f7f7f9;
border-bottom: 1px solid #e8e8e8;
font-size: 0.9em;
color: #666;
}
.editor-toolbar .editor-actions {
display: flex;
gap: 6px;
}
.editor-toolbar .icon-btn {
background: #fff;
border: 1px solid #d4d4d5;
border-radius: 4px;
padding: 4px 10px;
cursor: pointer;
font-size: 1em;
transition: all 0.15s;
color: #555;
}
.editor-toolbar .icon-btn:hover {
background: #2185d0;
color: #fff;
border-color: #2185d0;
}
#source {
display: block;
width: 100% !important;
height: 600px;
margin: 14px 0 0 !important;
height: 500px;
margin: 0 !important;
text-align: left !important;
font-family: 'Fira Mono', 'Cascadia Code', Consolas, monospace;
}
#source.ace_editor {
width: 100% !important;
border: 1px solid #d4d4d5;
border-radius: 6px;
border: none;
border-radius: 0;
}
#source.ace_editor,
@@ -28,174 +147,381 @@
text-align: left !important;
}
#source.ace_editor .ace_gutter {
border-radius: 6px 0 0 6px;
.ace-chrome .ace_marker-layer .ace_active-line {
background-color: rgba(0,0,199,0.12);
}
.ace-chrome .ace_marker-layer .ace_active-line{ /*当前行*/
background-color: rgba(0,0,199,0.3);
.submit-test-section {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-bottom: 16px;
}
.button, input, optgroup, select, textarea { /*选择题的题号大小*/
font-family: sans-serif;
font-size: 150%;
line-height: 1.2;
@media (max-width: 768px) {
.submit-test-section {
grid-template-columns: 1fr;
}
}
</style>
<center>
<script src="<?php echo $OJ_CDN_URL?>include/checksource.js"></script>
<form id=frmSolution action="submit.php<?php if (isset($_GET['spa'])) echo "?spa" ?>" method="post" onsubmit='do_submit()' enctype="multipart/form-data" >
<?php if (!isset($_GET['spa']) || $solution_name ) {?>
<input type='file' name='answer' placeholder='Upload answer file' >
<?php } ?>
<?php if (isset($id)){?>
<span style="color:#0000ff">Problem <b><?php echo $id?></b></span>
<input id=problem_id type='hidden' value='<?php echo $id?>' name="id" >
<?php }else{
//$PID="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//if ($pid>25) $pid=25;
?>
Problem <span class=blue><b><?php echo chr($pid+ord('A'))?></b></span> of Contest <span class=blue><b><?php echo $cid?></b></span>
<input id="cid" type='hidden' value='<?php echo $cid?>' name="cid">
<input id="pid" type='hidden' value='<?php echo $pid?>' name="pid">
<?php }?>
<span id="language_span">Language:
<select id="language" name="language" onChange="reloadtemplate($(this).val());" >
<?php
$lang_count=count($language_ext);
if(isset($_GET['langmask']))
$langmask=$_GET['langmask'];
$langmask|=$OJ_LANGMASK;
$lang=(~((int)$langmask))&((1<<($lang_count))-1);
//$lastlang=$_COOKIE['lastlang'];
//if($lastlang=="undefined") $lastlang=1;
for($i=0;$i<$lang_count;$i++){
if($lang&(1<<$i))
echo"<option value=$i ".( $lastlang==$i?"selected":"").">
".$language_name[$i]."
</option>";
}
?>
</select>
<?php if($OJ_VCODE){?>
<?php echo $MSG_VCODE?>:
<input name="vcode" size=4 type=text autocomplete=off ><img id="vcode" alt="click to change" src="vcode.php" onclick="this.src='vcode.php?'+Math.random()">
<?php }?>
<button id="Submit" type="button" class="ui primary icon button" onclick="do_submit();"><?php echo $MSG_SUBMIT?></button>
<?php if (isset($OJ_ENCODE_SUBMIT)&&$OJ_ENCODE_SUBMIT){?>
<input class="btn btn-success" title="WAF gives you reset ? try this." type=button value="Encoded <?php echo $MSG_SUBMIT?>" onclick="encoded_submit();">
<input type=hidden id="encoded_submit_mark" name="reverse2" value="reverse"/>
<?php }?>
<!--选择题状态-->
<?php if ($spj>1 || !$OJ_TEST_RUN ){?>
<span class="btn" id=result><?php echo $MSG_STATUS?></span>
<?php }?>
</span>
<?php if($spj <= 1 && !$solution_name){ ?>
<button onclick="toggleTheme(event)" style="background-color: bisque; position: absolute; top: 5px; right:70px;" v-if="false">
<i>🌗</i>
</button>
<button onclick="increaseFontSize(event)" style="background-color: bisque; position: absolute; top: 5px; right:40px;" v-if="false">
<i></i>
</button>
<button onclick="decreaseFontSize(event)" style="background-color: bisque; position: absolute; top: 5px; right:10px;" v-if="false">
<i></i>
</button>
<?php } ?>
<?php
if(!$solution_name){
if($OJ_ACE_EDITOR){
if (isset($OJ_TEST_RUN)&&$OJ_TEST_RUN)
$height="400px";
else
$height="500px";
?>
<pre style="width:90%;height:<?php echo $height?>" cols=180 rows=16 id="source"><?php echo htmlentities($view_src,ENT_QUOTES,"UTF-8")?></pre>
<input type=hidden id="hide_source" name="source" value=""/>
<?php }else{ ?>
<textarea style="width:80%;height:600" cols=180 rows=30 id="source" name="source"><?php echo htmlentities($view_src,ENT_QUOTES,"UTF-8")?></textarea>
<?php }
}else{
echo "<br><h2>指定上传文件:$solution_name</h2>";
}
?>
<style>
.button, input, optgroup, select, textarea {
font-family: sans-serif;
font-size: 150%;
line-height: 1.15;
margin: 0;
background: border-box;
}
</style>
<div class="row">
<div class="column" style="display: flex;">
<?php if ( isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name ){?>
<div style="
margin-left: 60px;
width: 40%;
padding: 14px;
flex-direction: column;">
<div style="
display: flex;
.test-panel {
background: rgba(255,255,255,0.7);
border-radius: 8px;
background-color: rgb(255,255,255,0.4);" id="language_span"><?php echo $MSG_Input?></div>
<textarea style="width:100%" cols=40 rows=5 id="input_text" name="input_text" ><?php echo $view_sample_input?></textarea>
</div>
<div style="
width: 40%;
border: 1px solid #d4d4d5;
padding: 12px;
display: flex;
flex-direction: column;
">
<div style=" display: flex;
}
.test-panel-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-weight: 600;
color: #333;
}
.test-panel-header .status-badge {
font-size: 0.85em;
color: #666;
}
.test-panel textarea {
width: 100%;
min-height: 120px;
padding: 8px;
border-radius: 6px;
border: 1px solid #d4d4d5;
font-family: 'Fira Mono', 'Cascadia Code', Consolas, monospace;
font-size: 0.95em;
resize: vertical;
outline: none;
transition: border-color 0.15s;
box-sizing: border-box;
}
.test-panel textarea:focus {
border-color: #2185d0;
}
.submit-actions {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
padding-top: 16px;
border-top: 1px solid rgba(0,0,5,0.08);
}
.submit-actions .actions-left {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.submit-actions .actions-right {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.btn {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 8px 18px;
border-radius: 6px;
border: 1px solid transparent;
font-size: 1em;
font-weight: 500;
cursor: pointer;
transition: all 0.15s;
text-decoration: none;
line-height: 1.4;
}
.btn-primary {
background: #2185d0;
color: #fff;
}
.btn-primary:hover:not(:disabled) {
background: #1678c2;
color: #fff;
}
.btn-primary:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.btn-info {
background: #00b5ad;
color: #fff;
}
.btn-info:hover:not(:disabled) {
background: #009c95;
color: #fff;
}
.btn-secondary {
background: #fff;
color: #333;
border-color: #d4d4d5;
}
.btn-secondary:hover {
background: #f7f7f9;
color: #2185d0;
border-color: #2185d0;
}
.btn-purple {
background: rgb(169,91,128);
color: #fff;
}
.btn-purple:hover {
background: rgb(149,71,108);
color: #fff;
}
.btn-green {
background: rgb(90,164,139);
color: #fff;
}
.btn-green:hover {
background: rgb(70,144,119);
color: #fff;
}
.file-upload {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 12px;
background: #f7f7f9;
border: 1px dashed #c0c0c0;
border-radius: 6px;
color: #555;
font-size: 0.95em;
cursor: pointer;
transition: all 0.15s;
}
.file-upload:hover {
border-color: #2185d0;
color: #2185d0;
background: #fff;
}
.file-upload input[type="file"] {
display: none;
}
.upload-notice {
text-align: center;
padding: 40px 20px;
background: rgba(255,255,255,0.6);
border-radius: 8px;
background-color: rgb(255,255,255,0.4);justify-content: space-between;" id="language_span"><?php echo $MSG_Output ?>
<span class="btn" id=result><?php echo $MSG_STATUS?></span>
border: 1px dashed #c0c0c0;
color: #555;
font-size: 1.1em;
}
.solution-name-title {
text-align: center;
color: #2185d0;
margin: 0 0 16px 0;
font-weight: 600;
}
#blockly {
margin: 16px 0;
}
#result.badge {
display: inline-block;
padding: 4px 10px;
border-radius: 12px;
background: #e8e8e8;
color: rgba(0,0,0,.6);
font-size: 0.85em;
font-weight: 700;
white-space: nowrap;
}
@media (max-width: 600px) {
.submit-card {
padding: 16px;
}
.submit-title {
font-size: 1.2em;
}
#source {
height: 350px;
}
.btn {
padding: 6px 12px;
font-size: 0.95em;
}
}
</style>
<div class="submit-wrapper">
<div class="submit-card padding">
<div class="submit-header">
<h1 class="submit-title">
<i class="edit icon"></i>
<?php echo $MSG_SUBMIT?>
<?php if (isset($id)){?>
<span class="problem-id">#<?php echo $id?></span>
<?php }else{?>
<span class="problem-id"><?php echo chr($pid+ord('A'))?></span>
<small style="color:#888;font-size:0.6em;">Contest #<?php echo $cid?></small>
<?php }?>
</h1>
</div>
<script src="<?php echo $OJ_CDN_URL?>include/checksource.js"></script>
<form id="frmSolution" action="submit.php<?php if (isset($_GET['spa'])) echo "?spa" ?>" method="post" onsubmit="do_submit()" enctype="multipart/form-data">
<textarea style="
width:100%;background-color: white;
" cols=10 rows=5 id="out" name="out" disabled="true" placeholder='<?php echo htmlentities($view_sample_output,ENT_QUOTES,'UTF-8')?>' ></textarea>
</div>
<?php } ?>
<?php if (isset($OJ_TEST_RUN)&&$OJ_TEST_RUN && $spj<=1 && !$solution_name ){?>
<!--运行按钮-->
<input style="
margin-top: 30px;
margin-left: 0 auto;
width: 7%;background-color: #22ba46a3;border-color: #00fff470;height: 130px;
" id="TestRun" class="btn btn-info" type=button value="<?php echo $MSG_TR?>" onclick=do_test_run();>
<?php }?>
<div class="submit-toolbar">
<?php if (!isset($_GET['spa']) || $solution_name ) {?>
<div class="field-group">
<label for="answer"><?php echo $MSG_FILENAME?></label>
<label class="file-upload">
<i class="upload icon"></i>
<span id="file-name"><?php echo isset($MSG_CHOOSE_FILE)?$MSG_CHOOSE_FILE:$MSG_FILENAME?></span>
<input type="file" name="answer" id="answer" onchange="document.getElementById('file-name').textContent=this.files[0]?this.files[0].name:'<?php echo isset($MSG_CHOOSE_FILE)?$MSG_CHOOSE_FILE:$MSG_FILENAME?>'">
</label>
</div>
<?php } ?>
<div class="field-group">
<label for="language"><i class="code icon"></i><?php echo $MSG_LANG?></label>
<select id="language" name="language" onChange="reloadtemplate($(this).val());">
<?php
$lang_count=count($language_ext);
if(isset($_GET['langmask']))
$langmask=$_GET['langmask'];
$langmask|=$OJ_LANGMASK;
$lang=(~((int)$langmask))&((1<<($lang_count))-1);
for($i=0;$i<$lang_count;$i++){
if($lang&(1<<$i))
echo "<option value=$i ".( $lastlang==$i?"selected":"").">".$language_name[$i]."</option>";
}
?>
</select>
</div>
</div>
<?php if($OJ_VCODE){?>
<div class="field-group">
<label for="vcode"><?php echo $MSG_VCODE?></label>
<input name="vcode" id="vcode" size="4" type="text" autocomplete="off" style="width:80px;">
<img id="vcode-img" alt="click to change" src="vcode.php" onclick="this.src='vcode.php?'+Math.random()">
</div>
<?php }?>
</div>
<?php
if($OJ_ACE_EDITOR){
if (isset($OJ_TEST_RUN)&&$OJ_TEST_RUN)
$height="400px";
else
$height="500px";
?>
<div class="editor-card">
<div class="editor-toolbar">
<span><i class="file code outline icon"></i> <?php echo $MSG_SOURCE_CODE?></span>
<div class="editor-actions">
<button type="button" class="icon-btn" onclick="toggleTheme(event)" title="Theme">🌗</button>
<button type="button" class="icon-btn" onclick="increaseFontSize(event)" title="A+">A+</button>
<button type="button" class="icon-btn" onclick="decreaseFontSize(event)" title="A-">A-</button>
</div>
</div>
<pre style="width:100%;height:<?php echo $height?>;margin:0;" id="source"><?php echo htmlentities($view_src,ENT_QUOTES,"UTF-8")?></pre>
<input type="hidden" id="hide_source" name="source" value=""/>
</div>
<input type="hidden" value="0" id="problem_id" name="problem_id"/>
<?php }else{ ?>
<div class="editor-card">
<div class="editor-toolbar">
<span><i class="file code outline icon"></i> <?php echo $MSG_SOURCE_CODE?></span>
</div>
<textarea style="width:100%;height:400px;margin:0;padding:12px;border:none;border-radius:0;" id="source" name="source"><?php echo htmlentities($view_src,ENT_QUOTES,"UTF-8")?></textarea>
</div>
<?php }
if(!$solution_name){
?>
<?php if ( isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name ){?>
<div class="submit-test-section">
<div class="test-panel">
<div class="test-panel-header">
<span><i class="sign in alternate icon"></i> <?php echo $MSG_Input?></span>
</div>
<textarea id="input_text" name="input_text"><?php echo $view_sample_input?></textarea>
</div>
<div class="test-panel">
<div class="test-panel-header">
<span><i class="sign out alternate icon"></i> <?php echo $MSG_Output?></span>
<span class="status-badge"><span class="badge" id="result"><?php echo $MSG_STATUS?></span></span>
</div>
<textarea id="out" name="out" disabled="true" placeholder="<?php echo htmlentities($view_sample_output,ENT_QUOTES,'UTF-8')?>"></textarea>
</div>
</div>
<?php } else { ?>
<div style="text-align:right;margin-bottom:12px;">
<span class="badge" id="result"><?php echo $MSG_STATUS?></span>
</div>
<?php } ?>
<?php } else { ?>
<h2 class="solution-name-title">📎 <?php echo $solution_name?></h2>
<?php } ?>
<div class="submit-actions">
<div class="actions-left">
<button id="Submit" type="button" class="btn btn-primary" onclick="do_submit();">
<i class="paper plane icon"></i> <?php echo $MSG_SUBMIT?>
</button>
<?php if ( isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name ){?>
<button id="TestRun" type="button" class="btn btn-info" onclick="do_test_run();">
<i class="play icon"></i> <?php echo $MSG_TR?>
</button>
<?php }?>
<?php if (isset($OJ_ENCODE_SUBMIT)&&$OJ_ENCODE_SUBMIT){?>
<button type="button" class="btn btn-secondary" onclick="encoded_submit();">
<i class="lock icon"></i> Encoded <?php echo $MSG_SUBMIT?>
</button>
<input type="hidden" id="encoded_submit_mark" name="reverse2" value="reverse"/>
<?php }?>
</div>
<?php if (isset($OJ_BLOCKLY)&&$OJ_BLOCKLY){?>
<div class="actions-right">
<input id="blockly_loader" type="button" class="btn btn-purple" onclick="openBlockly()" value="🧩 <?php echo $MSG_BLOCKLY_OPEN?>">
<input id="transrun" type="button" class="btn btn-green" onclick="loadFromBlockly()" value="▶ <?php echo $MSG_BLOCKLY_TEST?>" style="display:none;">
</div>
<?php }?>
</div>
<div id="blockly" class="center"></div>
<?php if (isset($id)){?>
<input id="problem_id" type="hidden" value="<?php echo $id?>" name="problem_id">
<?php }else{?>
<input id="cid" type="hidden" value="<?php echo $cid?>" name="cid">
<input id="pid" type="hidden" value="<?php echo $pid?>" name="pid">
<?php }?>
</form>
<?php if (isset($OJ_BLOCKLY)&&$OJ_BLOCKLY){?>
<input id="blockly_loader" type=button class="btn" onclick="openBlockly()" value="<?php echo $MSG_BLOCKLY_OPEN?>" style="color:white;background-color:rgb(169,91,128)">
<input id="transrun" type=button class="btn" onclick="loadFromBlockly() " value="<?php echo $MSG_BLOCKLY_TEST?>" style="display:none;color:white;background-color:rgb(90,164,139)">
<div id="blockly" class="center">Blockly</div>
<?php }?>
</form>
</center>
</div>
</div>
<script>
var sid=0;
@@ -219,25 +545,25 @@ function fresh_result(solution_id)
{
var tb=window.document.getElementById('result');
if(solution_id==undefined){
tb.innerHTML="Vcode Error!";
if($("#vcode")!=null) $("#vcode").click();
tb.innerHTML="Vcode Error!";
if($("#vcode-img")!=null) $("#vcode-img").click();
return ;
}
sid=parseInt(solution_id);
if(sid<=0){
tb.innerHTML="<?php echo str_replace("10",$OJ_SUBMIT_COOLDOWN_TIME,$MSG_BREAK_TIME) ?>";
if($("#vcode")!=null) $("#vcode").click();
if($("#vcode-img")!=null) $("#vcode-img").click();
return ;
}
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
{
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
@@ -246,8 +572,6 @@ function fresh_result(solution_id)
{
var r=xmlhttp.responseText;
var ra=r.split(",");
// alert(r);
// alert(judge_result[r]);
var loader="<img width=18 src=image/loader.gif>";
var tag="span";
if(ra[0]<4) tag="span disabled=true";
@@ -293,7 +617,7 @@ ret=ie.innerText;
return ret+"";
}
var count=0;
function encoded_submit(){
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
@@ -315,16 +639,14 @@ function encoded_submit(){
}else{
$("#source").val(encode64(utf16to8(source)));
}
// source.value=source.value.split("").reverse().join("");
// alert(source.value);
document.getElementById("frmSolution").submit();
}
function do_submit(){
$("#Submit").attr("disabled","true"); // mouse has a bad key1
if(using_blockly)
$("#Submit").attr("disabled","true");
if(using_blockly)
translate();
if(typeof(editor) != "undefined"){
if(typeof(editor) != "undefined"){
$("#hide_source").val(editor.getValue());
}
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
@@ -334,17 +656,35 @@ function do_submit(){
else
problem_id.value='<?php if (isset($cid))echo $cid?>';
document.getElementById("frmSolution").target="_self";
<?php if(isset($_GET['spa'])){?>
<?php if($solution_name) { ?>document.getElementById("frmSolution").submit(); <?php } ?> //如果是指定文件名则强制用文件post方式提交。
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){fresh_result(data);});
<?php if($solution_name) { ?>document.getElementById("frmSolution").submit(); <?php } ?>
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){
var sid=parseInt(data);
if(sid>0){
window.location.href="reinfo.php?sid="+sid;
}else{
fresh_result(data);
}
});
$("#Submit").prop('disabled', true);
$("#TestRun").prop('disabled', true);
count=<?php echo $OJ_SUBMIT_COOLDOWN_TIME?> * 2 ;
handler_interval= window.setTimeout("resume();",1000);
<?php if(isset($OJ_REMOTE_JUDGE)&&$OJ_REMOTE_JUDGE) {?>$("#sk").attr("src","remote.php"); <?php } ?>
<?php }else{?>
document.getElementById("frmSolution").submit();
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){
var sid=parseInt(data);
if(sid>0){
window.location.href="reinfo.php?sid="+sid;
}else{
fresh_result(data);
}
});
$("#Submit").prop('disabled', true);
$("#TestRun").prop('disabled', true);
count=<?php echo $OJ_SUBMIT_COOLDOWN_TIME?> * 2 ;
handler_interval= window.setTimeout("resume();",1000);
<?php }?>
}
@@ -365,8 +705,6 @@ function do_test_run(){
var problem_id=document.getElementById(mark);
problem_id.value=-problem_id.value;
document.getElementById("frmSolution").target="testRun";
//$("#hide_source").val(editor.getValue());
//document.getElementById("frmSolution").submit();
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){fresh_result(data);});
$("#Submit").prop('disabled', true);
$("#TestRun").prop('disabled', true);
@@ -380,13 +718,13 @@ function resume(){
var t=$("#TestRun")[0];
if(count<0){
$("#Submit").attr("disabled",false);
$("#Submit").text("<?php echo $MSG_SUBMIT?>");
$("#Submit").html('<i class="paper plane icon"></i> <?php echo $MSG_SUBMIT?>');
if(t!=null) $("#TestRun").attr("disabled",false);
if(t!=null) $("#TestRun").text("<?php echo $MSG_TR?>");
if(t!=null) $("#TestRun").html('<i class="play icon"></i> <?php echo $MSG_TR?>');
if( handler_interval) window.clearInterval( handler_interval);
if($("#vcode")!=null) $("#vcode").click();
if($("#vcode-img")!=null) $("#vcode-img").click();
}else{
$("#Submit").text("<?php echo $MSG_SUBMIT?>("+count+")");
$("#Submit").html('<i class="hourglass half icon"></i> <?php echo $MSG_SUBMIT?> ('+count+')');
if(t!=null)t.value="<?php echo $MSG_TR?>("+count+")";
window.setTimeout("resume();",1000);
}
@@ -426,7 +764,6 @@ function getAceModeName(lang){
}
function switchLang(lang){
editor.getSession().setMode("ace/mode/"+getAceModeName(lang));
}
function reloadtemplate(lang){
if(lang==undefined){
@@ -449,14 +786,12 @@ function openBlockly(){
$("#TestRun").hide();
$("#language")[0].scrollIntoView();
$("#language").val(6).hide();
//$("#language_span").hide();
$("#EditAreaArroundInfos_source").hide();
$('#blockly').html('<iframe name=\'frmBlockly\' width=90% height=580 src=\'blockly/demos/code/index.html\'></iframe>');
$('#blockly').html('<iframe name=\'frmBlockly\' width=100% height=580 src=\'blockly/demos/code/index.html\'></iframe>');
$("#blockly_loader").hide();
$("#transrun").show();
//$("#Submit").prop('disabled', true);
using_blockly=true;
}
function translate(){
var blockly=$(window.frames['frmBlockly'].document);
@@ -467,13 +802,12 @@ function translate(){
if(typeof(editor) != "undefined") editor.setValue(python.text());
else $("#source").val(python.text());
$("#language").val(6);
}
function loadFromBlockly(){
translate();
do_test_run();
$("#frame_source").hide();
// $("#Submit").prop('disabled', false);
}
</script>
<script language="Javascript" type="text/javascript" src="<?php echo $OJ_CDN_URL?>include/base64.js"></script>
@@ -515,7 +849,7 @@ function loadFromBlockly(){
editor.getSession().on("change", syncEditorSource);
switchLang(<?php echo $lastlang ?>);
syncEditorSource();
reloadtemplate($("#language").val());
reloadtemplate($("#language").val());
function getSourceDraftKey(languageOverride){
let language=languageOverride;
if(language===undefined||language===null||language===""){
@@ -534,22 +868,18 @@ function loadFromBlockly(){
if(typeof(editor) != "undefined")
$("#hide_source").val(editor.getValue());
localStorage.setItem(key,$("#hide_source").val());
//console.log("autosaving "+key+"..."+new Date());
}
}
$(document).ready(function(){
$("#source").css("height",window.innerHeight-180);
if($("#vcode")!=undefined) $("#vcode").click();
$("#source").css("height",window.innerHeight-220);
if($("#vcode-img")!=undefined) $("#vcode-img").click();
if(!!localStorage){
let key=getSourceDraftKey();
let saved=localStorage.getItem(key);
if(saved!=null&&saved!=""&&saved.length>editor.getValue().length){
//let load=confirm("发现自动保存的源码,是否加载?(仅有一次机会)");
//if(load){
console.log("loading "+saved.length);
if(typeof(editor) != "undefined")
editor.setValue(saved);
//}
console.log("loading "+saved.length);
if(typeof(editor) != "undefined")
editor.setValue(saved);
}
}
@@ -574,7 +904,7 @@ function loadFromBlockly(){
}
function toggleTheme(event) {
event.preventDefault();
if (editor.getTheme() === "ace/theme/xcode") {
editor.setTheme("ace/theme/monokai");
} else {
@@ -585,9 +915,9 @@ function loadFromBlockly(){
var level = 0;
var LOOP_SIZE = 100;
function finishTabifier(code) {
code = code.replace(/\n\s*\n/g, '\n'); //blank lines
code = code.replace(/^[\s\n]*/, ''); //leading space
code = code.replace(/[\s\n]*$/, ''); //trailing space
code = code.replace(/\n\s*\n/g, '\n');
code = code.replace(/^[\s\n]*/, '');
code = code.replace(/[\s\n]*$/, '');
level = 0;
var session = editor.getSession();
session.setValue(code);
@@ -596,7 +926,7 @@ function finishTabifier(code) {
function cleanCStyle(code) {
var i = 0;
code = code.replace(/\)\n[\s]*/g,')\n '); //single line if while for
code = code.replace(/\)\n[\s]*/g,')\n ');
function cleanAsync() {
var iStart = i;
for (; i < code.length && i < iStart + LOOP_SIZE; i++) {
@@ -616,8 +946,7 @@ function cleanCStyle(code) {
}
out += c;
} else if (instring) {
if (instring == c && // this string closes at the next matching quote
// unless it was escaped, or the escape is escaped
if (instring == c &&
('\\' != code.charAt(i - 1) || '\\' == code.charAt(i - 2))
) {
instring = false;
@@ -678,9 +1007,9 @@ function cleanCStyle(code) {
}
}
code = code.replace(/^[\s\n]*/, ''); //leading space
code = code.replace(/[\s\n]*$/, ''); //trailing space
code = code.replace(/[\n\r]+/g, '\n'); //collapse newlines
code = code.replace(/^[\s\n]*/, '');
code = code.replace(/[\s\n]*$/, '');
code = code.replace(/[\n\r]+/g, '\n');
var out = tabs(), li = level, c = '';
var infor = false, forcount = 0, instring = false, incomment = false;
@@ -691,14 +1020,10 @@ function tabs() {
for (var j = 0; j < level; j++) s += '\t';
return s;
}
// Functions
function formatCode() {
var session = editor.getSession();
cleanCStyle(session.getValue());
}
</script>
<?php }?>