- 判题结果页引入友好错误解释面板,按 verdict 类型给出提示与改进建议 - 新增 dedup_runtimeinfo() 函数将重复 RE 测试点折叠为区间汇总 - 区分管理员/源浏览者与普通用户视图,原始错误默认折叠 - 错误模式匹配扩展至 28 条,覆盖 glibc/Java/Python/Go 等常见运行时异常 - 提交页改用卡片式布局,编辑器工具栏与测试运行区交互优化 - 中英文语言文件补充相关文案与快捷操作标签 - 切换 LLM 点评 API 至 newapi.klarkxy.xyz,模型改为 minimax-m3 - 新增 .codegraph/.gitignore 忽略本地调试数据
1033 lines
29 KiB
PHP
1033 lines
29 KiB
PHP
<?php $show_title="$MSG_SUBMIT - $OJ_NAME"; ?>
|
|
<?php include("template/$OJ_TEMPLATE/header.php");?>
|
|
|
|
<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: 500px;
|
|
margin: 0 !important;
|
|
text-align: left !important;
|
|
font-family: 'Fira Mono', 'Cascadia Code', Consolas, monospace;
|
|
}
|
|
|
|
#source.ace_editor {
|
|
width: 100% !important;
|
|
border: none;
|
|
border-radius: 0;
|
|
}
|
|
|
|
#source.ace_editor,
|
|
#source.ace_editor .ace_scroller,
|
|
#source.ace_editor .ace_content,
|
|
#source.ace_editor .ace_text-layer {
|
|
text-align: left !important;
|
|
}
|
|
|
|
.ace-chrome .ace_marker-layer .ace_active-line {
|
|
background-color: rgba(0,0,199,0.12);
|
|
}
|
|
|
|
.submit-test-section {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 16px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
.submit-test-section {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
|
|
.test-panel {
|
|
background: rgba(255,255,255,0.7);
|
|
border-radius: 8px;
|
|
border: 1px solid #d4d4d5;
|
|
padding: 12px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.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;
|
|
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">
|
|
|
|
<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>
|
|
|
|
<?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>
|
|
<?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>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
var sid=0;
|
|
var i=0;
|
|
var using_blockly=false;
|
|
var judge_result=[<?php
|
|
foreach($judge_result as $result){
|
|
echo "'$result',";
|
|
}
|
|
?>''];
|
|
function print_result(solution_id){
|
|
sid=solution_id;
|
|
$("#out").load("status-ajax.php?tr=1&solution_id="+solution_id);
|
|
}
|
|
function fancy(td){
|
|
$("body",parent.document).append("<div id='bannerFancy' style='position:absolute;top:0px;left:0px;width:100%;z-index:3' class='ui main container'></div><audio autoplay=\"autoplay\" preload=\"auto\" src=\"<?php echo $OJ_FANCY_MP3 ?>\"> </audio>");
|
|
window.setTimeout("$(\"#bannerFancy\",parent.document).html(\"<iframe border=0 src='fancy.php' width='100%' height='800px'></iframe>\");",500);
|
|
window.setTimeout("$(\"#bannerFancy\",parent.document).remove();",10000);
|
|
}
|
|
function fresh_result(solution_id)
|
|
{
|
|
var tb=window.document.getElementById('result');
|
|
if(solution_id==undefined){
|
|
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-img")!=null) $("#vcode-img").click();
|
|
return ;
|
|
}
|
|
|
|
var xmlhttp;
|
|
if (window.XMLHttpRequest)
|
|
{
|
|
xmlhttp=new XMLHttpRequest();
|
|
}
|
|
else
|
|
{
|
|
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
|
|
}
|
|
xmlhttp.onreadystatechange=function()
|
|
{
|
|
if (xmlhttp.readyState==4 && xmlhttp.status==200)
|
|
{
|
|
var r=xmlhttp.responseText;
|
|
var ra=r.split(",");
|
|
var loader="<img width=18 src=image/loader.gif>";
|
|
var tag="span";
|
|
if(ra[0]<4) tag="span disabled=true";
|
|
else tag="a";
|
|
{
|
|
if(ra[0]==11||ra[0]>15)
|
|
tb.innerHTML="<"+tag+" href='ceinfo.php?sid="+solution_id+"' class='badge badge-info' target=_blank>"+judge_result[ra[0]]+"</"+tag+">";
|
|
else
|
|
tb.innerHTML="<"+tag+" href='reinfo.php?sid="+solution_id+"' class='badge badge-info' target=_blank>"+judge_result[ra[0]]+"AC:"+ra[4]+"</"+tag+">";
|
|
}
|
|
if(ra[0]<4||ra[0]>15)
|
|
tb.innerHTML+=loader;
|
|
tb.innerHTML+="Memory:"+ra[1]+" ";
|
|
tb.innerHTML+="Time:"+ra[2]+"";
|
|
if(ra[0]<4||ra[0]>15)
|
|
window.setTimeout("fresh_result("+solution_id+")",2000);
|
|
else{
|
|
window.setTimeout("print_result("+solution_id+")",2000);
|
|
count=1;
|
|
}
|
|
<?php if ( $OJ_FANCY_RESULT ) {?>
|
|
if(ra[0]==4) fancy(tb);
|
|
<?php } ?>
|
|
}
|
|
}
|
|
xmlhttp.open("GET","status-ajax.php?solution_id="+solution_id,true);
|
|
xmlhttp.send();
|
|
}
|
|
function getSID(){
|
|
var ofrm1 = document.getElementById("testRun").document;
|
|
var ret="0";
|
|
if (ofrm1==undefined)
|
|
{
|
|
ofrm1 = document.getElementById("testRun").contentWindow.document;
|
|
var ff = ofrm1;
|
|
ret=ff.innerHTML;
|
|
}
|
|
else
|
|
{
|
|
var ie = document.frames["frame1"].document;
|
|
ret=ie.innerText;
|
|
}
|
|
return ret+"";
|
|
}
|
|
var count=0;
|
|
|
|
function encoded_submit(){
|
|
|
|
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
|
|
var problem_id=document.getElementById(mark);
|
|
|
|
if(typeof(editor) != "undefined")
|
|
$("#hide_source").val(editor.getValue());
|
|
if(mark=='problem_id')
|
|
problem_id.value='<?php if(isset($id)) echo $id?>';
|
|
else
|
|
problem_id.value='<?php if(isset($cid))echo $cid?>';
|
|
|
|
document.getElementById("frmSolution").target="_self";
|
|
document.getElementById("encoded_submit_mark").name="encoded_submit";
|
|
var source=$("#source").val();
|
|
if(typeof(editor) != "undefined") {
|
|
source=editor.getValue();
|
|
$("#hide_source").val(encode64(utf16to8(source)));
|
|
}else{
|
|
$("#source").val(encode64(utf16to8(source)));
|
|
}
|
|
document.getElementById("frmSolution").submit();
|
|
}
|
|
|
|
function do_submit(){
|
|
$("#Submit").attr("disabled","true");
|
|
if(using_blockly)
|
|
translate();
|
|
if(typeof(editor) != "undefined"){
|
|
$("#hide_source").val(editor.getValue());
|
|
}
|
|
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
|
|
var problem_id=document.getElementById(mark);
|
|
if(mark=='problem_id')
|
|
problem_id.value='<?php if (isset($id))echo $id?>';
|
|
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("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{?>
|
|
$.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 }?>
|
|
|
|
}
|
|
var handler_interval;
|
|
function do_test_run(){
|
|
if( handler_interval) window.clearInterval( handler_interval);
|
|
var loader="<img width=18 src=image/loader.gif>";
|
|
var tb=window.document.getElementById('result');
|
|
var source=$("#source").val();
|
|
if(typeof(editor) != "undefined") {
|
|
source=editor.getValue();
|
|
$("#hide_source").val(source);
|
|
}
|
|
if(source.length<10) return alert("too short!");
|
|
if(tb!=null)tb.innerHTML=loader;
|
|
|
|
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
|
|
var problem_id=document.getElementById(mark);
|
|
problem_id.value=-problem_id.value;
|
|
document.getElementById("frmSolution").target="testRun";
|
|
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){fresh_result(data);});
|
|
$("#Submit").prop('disabled', true);
|
|
$("#TestRun").prop('disabled', true);
|
|
problem_id.value=-problem_id.value;
|
|
count=<?php echo isset($OJ_SUBMIT_COOLDOWN_TIME)?$OJ_SUBMIT_COOLDOWN_TIME:5 ?> * 2 ;
|
|
handler_interval= window.setTimeout("resume();",1000);
|
|
}
|
|
function resume(){
|
|
count--;
|
|
var s=$("#Submit")[0];
|
|
var t=$("#TestRun")[0];
|
|
if(count<0){
|
|
$("#Submit").attr("disabled",false);
|
|
$("#Submit").html('<i class="paper plane icon"></i> <?php echo $MSG_SUBMIT?>');
|
|
if(t!=null) $("#TestRun").attr("disabled",false);
|
|
if(t!=null) $("#TestRun").html('<i class="play icon"></i> <?php echo $MSG_TR?>');
|
|
if( handler_interval) window.clearInterval( handler_interval);
|
|
if($("#vcode-img")!=null) $("#vcode-img").click();
|
|
}else{
|
|
$("#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);
|
|
}
|
|
}
|
|
var languageNames=<?php echo json_encode($language_name, JSON_UNESCAPED_UNICODE); ?>;
|
|
var aceModesByLanguageName={
|
|
"C":"c_cpp",
|
|
"C++":"c_cpp",
|
|
"Pascal":"pascal",
|
|
"Java":"java",
|
|
"Ruby":"ruby",
|
|
"Bash":"sh",
|
|
"Python":"python",
|
|
"PHP":"php",
|
|
"Perl":"perl",
|
|
"C#":"csharp",
|
|
"Obj-C":"objectivec",
|
|
"FreeBasic":"vbscript",
|
|
"Scheme":"scheme",
|
|
"Clang":"c_cpp",
|
|
"Clang++":"c_cpp",
|
|
"Lua":"lua",
|
|
"JavaScript":"javascript",
|
|
"Go":"golang",
|
|
"SQL":"sql",
|
|
"Fortran":"fortran",
|
|
"Matlab":"matlab",
|
|
"Cobol":"cobol",
|
|
"R":"r",
|
|
"Scratch3":"plain_text",
|
|
"UnknownLanguage":"plain_text"
|
|
};
|
|
function getAceModeName(lang){
|
|
var langIndex=parseInt(lang,10);
|
|
var languageName=languageNames[langIndex]||"";
|
|
return aceModesByLanguageName[languageName]||"plain_text";
|
|
}
|
|
function switchLang(lang){
|
|
editor.getSession().setMode("ace/mode/"+getAceModeName(lang));
|
|
}
|
|
function reloadtemplate(lang){
|
|
if(lang==undefined){
|
|
switchLang(1);
|
|
return;
|
|
}
|
|
console.log("reload:<?php echo $lastlang?> -->"+lang);
|
|
document.cookie="lastlang="+lang;
|
|
var url=window.location.href;
|
|
var i=url.indexOf("sid=");
|
|
if(lang!=<?php echo $lastlang?>)
|
|
autoSave(<?php echo $lastlang ?>);
|
|
switchLang(lang);
|
|
if(lang!=<?php echo $lastlang?>)
|
|
document.location.href=url;
|
|
}
|
|
|
|
function openBlockly(){
|
|
$("#source").hide();
|
|
$("#TestRun").hide();
|
|
$("#language")[0].scrollIntoView();
|
|
$("#language").val(6).hide();
|
|
$("#EditAreaArroundInfos_source").hide();
|
|
$('#blockly').html('<iframe name=\'frmBlockly\' width=100% height=580 src=\'blockly/demos/code/index.html\'></iframe>');
|
|
$("#blockly_loader").hide();
|
|
$("#transrun").show();
|
|
using_blockly=true;
|
|
|
|
}
|
|
function translate(){
|
|
var blockly=$(window.frames['frmBlockly'].document);
|
|
var tb=blockly.find('td[id=tab_python]');
|
|
var python=blockly.find('pre[id=content_python]');
|
|
tb.click();
|
|
blockly.find('td[id=tab_blocks]').click();
|
|
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();
|
|
}
|
|
</script>
|
|
<script language="Javascript" type="text/javascript" src="<?php echo $OJ_CDN_URL?>include/base64.js"></script>
|
|
<?php if (!empty($remote_oj)){
|
|
echo "<iframe src=remote.php height=0px width=0px ></iframe>";
|
|
}
|
|
?>
|
|
<?php if($OJ_ACE_EDITOR){ ?>
|
|
<script src="ace/ace.js"></script>
|
|
<script src="ace/ext-language_tools.js"></script>
|
|
<script>
|
|
ace.config.set("basePath", "ace");
|
|
|
|
var sourceElement = document.getElementById("source");
|
|
var hiddenSourceElement = document.getElementById("hide_source");
|
|
var initialSourceCode = sourceElement ? (sourceElement.textContent || sourceElement.innerText || "") : "";
|
|
var editor = ace.edit("source");
|
|
|
|
editor.setTheme("ace/theme/xcode");
|
|
editor.setShowPrintMargin(false);
|
|
editor.setBehavioursEnabled(true);
|
|
editor.session.setUseWrapMode(true);
|
|
editor.session.setTabSize(4);
|
|
editor.session.setUseSoftTabs(true);
|
|
editor.setOptions({
|
|
enableBasicAutocompletion: true,
|
|
enableSnippets: true,
|
|
enableLiveAutocompletion: true,
|
|
fontSize: "18px"
|
|
});
|
|
editor.setValue(initialSourceCode, -1);
|
|
|
|
function syncEditorSource(){
|
|
if(hiddenSourceElement){
|
|
hiddenSourceElement.value = editor.getValue();
|
|
}
|
|
}
|
|
|
|
editor.getSession().on("change", syncEditorSource);
|
|
switchLang(<?php echo $lastlang ?>);
|
|
syncEditorSource();
|
|
reloadtemplate($("#language").val());
|
|
function getSourceDraftKey(languageOverride){
|
|
let language=languageOverride;
|
|
if(language===undefined||language===null||language===""){
|
|
language=$("#language").val();
|
|
}
|
|
if(language===undefined||language===null||language===""){
|
|
language="<?php echo $lastlang ?>";
|
|
}
|
|
return "<?php echo $_SESSION[$OJ_NAME.'_user_id']?>source:"+location.href+":lang:"+language;
|
|
}
|
|
function autoSave(languageOverride){
|
|
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
|
|
var problem_id=$("#"+mark).val();
|
|
if(!!localStorage){
|
|
let key=getSourceDraftKey(languageOverride);
|
|
if(typeof(editor) != "undefined")
|
|
$("#hide_source").val(editor.getValue());
|
|
localStorage.setItem(key,$("#hide_source").val());
|
|
}
|
|
}
|
|
$(document).ready(function(){
|
|
$("#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){
|
|
console.log("loading "+saved.length);
|
|
if(typeof(editor) != "undefined")
|
|
editor.setValue(saved);
|
|
}
|
|
|
|
}
|
|
if(typeof(editor) != "undefined") editor.resize();
|
|
window.setInterval('autoSave();',5000);
|
|
$("body").dblclick(function(){
|
|
if (event.ctrlKey==1) formatCode();
|
|
}).attr("title","Ctrl+双击鼠标,自动整理缩进");
|
|
});
|
|
</script>
|
|
<script>
|
|
function increaseFontSize(event) {
|
|
event.preventDefault();
|
|
var currentSize = parseInt(editor.getFontSize());
|
|
editor.setFontSize(currentSize + 3);
|
|
}
|
|
|
|
function decreaseFontSize(event) {
|
|
event.preventDefault();
|
|
var currentSize = parseInt(editor.getFontSize());
|
|
editor.setFontSize(currentSize - 3);
|
|
}
|
|
function toggleTheme(event) {
|
|
event.preventDefault();
|
|
|
|
if (editor.getTheme() === "ace/theme/xcode") {
|
|
editor.setTheme("ace/theme/monokai");
|
|
} else {
|
|
editor.setTheme("ace/theme/xcode");
|
|
}
|
|
}
|
|
|
|
var level = 0;
|
|
var LOOP_SIZE = 100;
|
|
function finishTabifier(code) {
|
|
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);
|
|
return code;
|
|
}
|
|
|
|
function cleanCStyle(code) {
|
|
var i = 0;
|
|
code = code.replace(/\)\n[\s]*/g,')\n ');
|
|
function cleanAsync() {
|
|
var iStart = i;
|
|
for (; i < code.length && i < iStart + LOOP_SIZE; i++) {
|
|
c = code.charAt(i);
|
|
|
|
if (incomment) {
|
|
if ('//' == incomment && '\n' == c) {
|
|
incomment = false;
|
|
} else if ('/*' == incomment && '*/' == code.substr(i, 2)) {
|
|
incomment = false;
|
|
c = '*/\n';
|
|
i++;
|
|
}
|
|
if (!incomment) {
|
|
while (code.charAt(++i).match(/\s/)); ; i--;
|
|
c += tabs();
|
|
}
|
|
out += c;
|
|
} else if (instring) {
|
|
if (instring == c &&
|
|
('\\' != code.charAt(i - 1) || '\\' == code.charAt(i - 2))
|
|
) {
|
|
instring = false;
|
|
}
|
|
out += c;
|
|
} else if (infor && '(' == c) {
|
|
infor++;
|
|
out += c;
|
|
} else if (infor && ')' == c) {
|
|
infor--;
|
|
out += c;
|
|
} else if ('else' == code.substr(i, 4)) {
|
|
out = out.replace(/\s*$/, '') + ' e';
|
|
} else if (code.substr(i).match(/^for\s*\(/)) {
|
|
infor = 1;
|
|
out += 'for (';
|
|
while ('(' != code.charAt(++i)); ;
|
|
} else if ('//' == code.substr(i, 2)) {
|
|
incomment = '//';
|
|
out += '//';
|
|
i++;
|
|
} else if ('/*' == code.substr(i, 2)) {
|
|
incomment = '/*';
|
|
out += '\n' + tabs() + '/*';
|
|
i++;
|
|
} else if ('"' == c || "'" == c) {
|
|
if (instring && c == instring) {
|
|
instring = false;
|
|
} else {
|
|
instring = c;
|
|
}
|
|
out += c;
|
|
} else if ('{' == c) {
|
|
level++;
|
|
out = out.replace(/\s*$/, '') + ' {\n' + tabs();
|
|
while (code.charAt(++i).match(/\s/)); ; i--;
|
|
} else if ('}' == c) {
|
|
out = out.replace(/\s*$/, '');
|
|
level--;
|
|
out += '\n' + tabs() + '}\n' + tabs();
|
|
while (code.charAt(++i).match(/\s/)); ; i--;
|
|
} else if (';' == c && !infor) {
|
|
out += ';\n' + tabs();
|
|
while (code.charAt(++i).match(/\s/)); ; i--;
|
|
} else if ('\n' == c) {
|
|
out += '\n' + tabs();
|
|
} else {
|
|
out += c;
|
|
}
|
|
}
|
|
|
|
if (i < code.length) {
|
|
setTimeout(cleanAsync, 0);
|
|
} else {
|
|
level = li;
|
|
out = out.replace(/[\s\n]*$/, '');
|
|
finishTabifier(out);
|
|
}
|
|
}
|
|
|
|
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;
|
|
cleanAsync();
|
|
}
|
|
function tabs() {
|
|
var s = '';
|
|
for (var j = 0; j < level; j++) s += '\t';
|
|
return s;
|
|
}
|
|
function formatCode() {
|
|
var session = editor.getSession();
|
|
cleanCStyle(session.getValue());
|
|
}
|
|
</script>
|
|
<?php }?>
|
|
|
|
</body>
|
|
</html>
|
|
<?php //include("template/$OJ_TEMPLATE/footer.php");?>
|