801 lines
29 KiB
PHP
801 lines
29 KiB
PHP
<?php
|
||
if ($pr_flag) {
|
||
$show_title = "P$id - " . $row['title'] . " - $OJ_NAME";
|
||
} else {
|
||
$id = $row['problem_id'];
|
||
$show_title = "$MSG_PROBLEM " . $PID[$pid] . ": " . $row['title'] . " - $OJ_NAME";
|
||
}
|
||
?>
|
||
<?php include("template/$OJ_TEMPLATE/header.php"); ?>
|
||
<style>
|
||
.ace_cursor {
|
||
border-left-width: 1px !important;
|
||
color: #000 !important;
|
||
}
|
||
|
||
#languages-menu::-webkit-scrollbar,
|
||
#testcase-menu::-webkit-scrollbar {
|
||
width: 0px;
|
||
background: transparent;
|
||
}
|
||
|
||
div[class*=ace_br] {
|
||
border-radius: 0 !important;
|
||
}
|
||
|
||
.copy {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
min-width: 68px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
color: #2f4f7f;
|
||
background: rgba(255, 255, 255, 0.96);
|
||
padding: 6px 12px;
|
||
margin: 0;
|
||
border: 1px solid #c8d3e6;
|
||
border-radius: 999px;
|
||
cursor: pointer;
|
||
box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08);
|
||
}
|
||
|
||
.copy:hover {
|
||
background: #ffffff;
|
||
}
|
||
|
||
.sample-header {
|
||
display: flex !important;
|
||
align-items: center;
|
||
}
|
||
|
||
.sample-box {
|
||
position: relative;
|
||
border: 1px solid #cfd7e6 !important;
|
||
background: linear-gradient(180deg, #f9fbff 0%, #f3f7ff 100%) !important;
|
||
box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
|
||
}
|
||
|
||
.sample-copy {
|
||
position: absolute;
|
||
top: 12px;
|
||
right: 12px;
|
||
z-index: 2;
|
||
}
|
||
|
||
.sample-box pre {
|
||
margin: 0;
|
||
padding: 48px 18px 16px;
|
||
overflow: auto;
|
||
background: transparent;
|
||
}
|
||
|
||
.sample-box code {
|
||
display: block;
|
||
font-family: "Cascadia Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
|
||
font-size: 15px;
|
||
line-height: 1.7;
|
||
}
|
||
|
||
.hustoj-md-io-label {
|
||
margin: 12px 0 8px;
|
||
font-weight: 600;
|
||
color: #3d4d66;
|
||
}
|
||
|
||
</style>
|
||
<script src="<?php echo $OJ_CDN_URL . $path_fix . "template/$OJ_TEMPLATE/" ?>clipboard.min.js"></script>
|
||
<script src="include/vditor-adapter.js"></script>
|
||
|
||
<div class="padding ">
|
||
<div class="ui center aligned grid">
|
||
<div class="row">
|
||
<h1 class="ui header">
|
||
<?php
|
||
if ($pr_flag) {
|
||
echo "$id: " . $row['title'];
|
||
// <%= problem.title %><% if (problem.allowedEdit && !problem.is_public) { %><span class="ui tiny red label">未公开</span><% } %>";
|
||
//echo "<title>$MSG_PROBLEM".$row['problem_id']."--". $row['title']."</title>";
|
||
//echo "<center><h2><strong>$id: ".$row['title']."</strong></h2>";
|
||
} else {
|
||
$id = $row['problem_id'];
|
||
//echo "<title>$MSG_PROBLEM ".$PID[$pid].": ".$row['title']." </title>";
|
||
echo "$MSG_PROBLEM " . $PID[$pid] . ": " . $row['title'];
|
||
}
|
||
if ($row['defunct'] == "Y")
|
||
echo "<span class=\"p-label ui tiny red label\">$MSG_RESERVED</span>";
|
||
?>
|
||
</h1>
|
||
</div>
|
||
<div class="row" style="margin-top: -15px">
|
||
<span class="ui label"><?php echo $MSG_Memory_Limit ?>:<?php echo $row['memory_limit']; ?> MB</span>
|
||
<span class="ui label"><?php echo $MSG_Time_Limit ?>:<?php echo $row['time_limit']; ?> S</span>
|
||
<!-- <span class="ui label">标准输入输出</span> -->
|
||
</div>
|
||
<div class="row" style="margin-top: -23px">
|
||
<!-- <span class="ui label">题目类型:传统</span> -->
|
||
<span
|
||
class="ui label"><?php echo $MSG_JUDGE_STYLE ?>:<?php echo array($MSG_NJ, $MSG_SPJ, $MSG_RTJ)[$row['spj']]; ?>
|
||
</span>
|
||
<span class="ui label"><?php echo $MSG_Creator ?>:<span id='creator'></span></span>
|
||
</div>
|
||
<div class="row" style="margin-top: -23px">
|
||
<span class="ui label"><?php echo $MSG_SUBMIT ?>:<?php echo $row['submit']; ?></span>
|
||
<span class="ui label"><?php echo $MSG_SOVLED ?>:<?php echo $row['accepted']; ?></span>
|
||
</div>
|
||
</div>
|
||
<div class="ui grid">
|
||
<div class="row" id="submit-buttons">
|
||
<div class="column">
|
||
<div class="ui buttons">
|
||
|
||
<?php
|
||
if ($pr_flag) {
|
||
echo "<a id='submit' class=\"small ui primary button\" href=\"submitpage.php?id=$id\">$MSG_SUBMIT</a>";
|
||
echo "<a class=\"small ui positive button\" href=\"status.php?problem_id=$id\">$MSG_SUBMIT_RECORD</a>";
|
||
echo "<a class=\"small ui orange button\" href=\"problemstatus.php?id=$id\">$MSG_STATISTICS</a>";
|
||
if ($OJ_BBS)
|
||
echo "<a class=\"small ui red button\" href=\"discuss.php?pid=$id\">$MSG_BBS</a>";
|
||
} else {
|
||
echo "<a href=\"contest.php?cid=$cid\" class=\"ui orange button\">$MSG_RETURN_CONTEST</a>";
|
||
if ($contest_is_over)
|
||
echo "<a id='submit' class=\"small ui primary button\" href=\"submitpage.php?id=$id\">$MSG_SUBMIT</a>";
|
||
else
|
||
echo "<a id='submit' class=\"small ui primary button\" href=\"submitpage.php?cid=$cid&pid=$pid&langmask=$langmask\">$MSG_SUBMIT</a>";
|
||
echo "<a class=\"small ui positive button\" href=\"status.php?problem_id=$id\">$MSG_GLOBAL$MSG_SUBMIT_RECORD</a>";
|
||
echo "<a class=\"small ui orange button\" href=\"status.php?problem_id=$PID[$pid]&cid=$cid\">$MSG_THIS_CONTEST$MSG_SUBMIT_RECORD</a>";
|
||
|
||
}
|
||
if (!file_exists($OJ_DATA . "/" . $id . "/solution.name"))
|
||
echo "<a class='small ui primary button' href='#' onclick='transform()' role='button'>$MSG_SHOW_OFF</a>";
|
||
?>
|
||
|
||
</div>
|
||
|
||
<?php
|
||
if (isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_NAME . '_' . "p" . $row['problem_id']])) { //only the original editor can edit this problem
|
||
|
||
require_once("include/set_get_key.php");
|
||
?>
|
||
|
||
<div class="ui buttons right floated">
|
||
<a class="small ui button"
|
||
href="admin/problem_edit.php?id=<?php echo $id ?>&getkey=<?php echo $_SESSION[$OJ_NAME . '_' . 'getkey'] ?>"><?php echo $MSG_EDIT . $MSG_PROBLEM ?></a>
|
||
<a class="small ui button"
|
||
href='javascript:phpfm(<?php echo $row['problem_id']; ?>)'><?php echo $MSG_TEST_DATA ?></a>
|
||
</div>
|
||
<?php } ?>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
function trans_md($str)
|
||
{
|
||
$s = $str;
|
||
// $s = bbcode_to_html($s);
|
||
if (
|
||
strpos($s, "class='md") === false &&
|
||
strpos($s, "class=\"md") === false
|
||
) // 没找到,那就加上
|
||
$s = "<span class='md'>" . $s . "</span>";
|
||
// 删除代码块里的html字符防止引起混乱
|
||
$s = preg_replace_callback('/(```.*?```|`[^`]*`)/s', function ($matches) {
|
||
$ss = str_replace('<br />', '', $matches[0]);
|
||
return $ss;
|
||
}, $s);
|
||
// 特殊转义
|
||
$s = str_replace("<br />", "\n", $s);
|
||
// 把<pre></pre>中间的html字符转成原始字符
|
||
$s = preg_replace_callback('/<pre>(.*?)<\/pre>/s', function ($matches) {
|
||
$content = $matches[1];
|
||
$content = htmlspecialchars_decode($content, ENT_QUOTES);
|
||
$content = str_replace("<", "<", $content);
|
||
$content = str_replace(">", ">", $content);
|
||
$content = str_replace("&", "&", $content);
|
||
$content = str_replace(""", "\"", $content);
|
||
$content = str_replace("'", "'", $content);
|
||
return "<pre>" . $content . "</pre>";
|
||
}, $s);
|
||
return $s;
|
||
}
|
||
?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header"><?php echo $MSG_Description ?></h4>
|
||
<div id="description" class="ui bottom attached segment font-content">
|
||
<?php
|
||
// echo $row['description'];
|
||
echo trans_md($row['description']);
|
||
if (isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_NAME . '_' . "p" . $row['problem_id']])) {
|
||
// 管理员增加一个显示源数据
|
||
echo '<div class="ui accordion" style="margin-top: 15px;">
|
||
<div class="title">
|
||
<i class="dropdown icon"></i>
|
||
Markdown原文
|
||
</div>
|
||
<div class="content">
|
||
<pre style="overflow: auto; max-height: 300px; border: 1px solid #ddd; padding: 10px; background-color: #f5f5f5;">' .
|
||
$row['description'] .
|
||
'</pre>
|
||
</div>
|
||
</div>';
|
||
}
|
||
?>
|
||
<script>
|
||
$(document).ready(function() {
|
||
$('.ui.accordion').accordion();
|
||
});
|
||
</script>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php if ($row['input'] || isset($_GET['spa'])) { ?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header"><?php echo $MSG_Input ?></h4>
|
||
<div id='input' class="ui bottom attached segment font-content">
|
||
<?php
|
||
echo trans_md($row['input']);
|
||
?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
<?php if ($row['output'] || isset($_GET['spa'])) { ?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header"><?php echo $MSG_Output ?></h4>
|
||
<div id='output' class="ui bottom attached segment font-content">
|
||
<?php
|
||
echo trans_md($row['output']);
|
||
?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
|
||
<?php
|
||
function normalize_sample_text($text)
|
||
{
|
||
return str_replace(array("\r\n", "\r"), "\n", (string)$text);
|
||
}
|
||
|
||
function trim_sample_chunk($text)
|
||
{
|
||
return trim(normalize_sample_text($text), "\n");
|
||
}
|
||
|
||
function compact_sample_chunks($chunks)
|
||
{
|
||
$result = array();
|
||
foreach ($chunks as $chunk) {
|
||
$chunk = trim_sample_chunk($chunk);
|
||
if ($chunk !== '') {
|
||
$result[] = $chunk;
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
function split_sample_chunks_with_pattern($text, $pattern)
|
||
{
|
||
$chunks = preg_split($pattern, normalize_sample_text($text));
|
||
if ($chunks === false) {
|
||
return array();
|
||
}
|
||
return compact_sample_chunks($chunks);
|
||
}
|
||
|
||
function build_sample_pairs($input, $output)
|
||
{
|
||
$input = normalize_sample_text($input);
|
||
$output = normalize_sample_text($output);
|
||
if ($input === '' || $output === '') {
|
||
return array();
|
||
}
|
||
|
||
$patterns = array(
|
||
'/^\s*(?:sample|example|样例)\s*\d+\s*$/imu',
|
||
'/^\s*(?:[-=*_]{3,})\s*$/m',
|
||
"/\n\s*\n/"
|
||
);
|
||
|
||
foreach ($patterns as $pattern) {
|
||
$inputChunks = split_sample_chunks_with_pattern($input, $pattern);
|
||
$outputChunks = split_sample_chunks_with_pattern($output, $pattern);
|
||
|
||
if (count($inputChunks) > 1 && count($inputChunks) === count($outputChunks)) {
|
||
$pairs = array();
|
||
for ($index = 0; $index < count($inputChunks); $index++) {
|
||
$pairs[] = array(
|
||
'input' => $inputChunks[$index],
|
||
'output' => $outputChunks[$index]
|
||
);
|
||
}
|
||
return $pairs;
|
||
}
|
||
}
|
||
|
||
return array();
|
||
}
|
||
|
||
function format_sample_code($text)
|
||
{
|
||
return htmlspecialchars(trim_sample_chunk($text), ENT_NOQUOTES, 'UTF-8');
|
||
}
|
||
|
||
function format_sample_attr($text)
|
||
{
|
||
return htmlentities(trim_sample_chunk($text), ENT_QUOTES, 'UTF-8');
|
||
}
|
||
|
||
$sampleInputText = normalize_sample_text($row['sample_input']);
|
||
$sampleOutputText = normalize_sample_text($row['sample_output']);
|
||
$samplePairs = build_sample_pairs($sampleInputText, $sampleOutputText);
|
||
$showSampleIndex = count($samplePairs) > 1;
|
||
$singleSampleInput = trim_sample_chunk($sampleInputText);
|
||
$singleSampleOutput = trim_sample_chunk($sampleOutputText);
|
||
?>
|
||
<?php if ($showSampleIndex) { ?>
|
||
<?php foreach ($samplePairs as $sampleIndex => $samplePair) { ?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header sample-header"><?php echo $MSG_Sample_Input . ' ' . ($sampleIndex + 1); ?></h4>
|
||
<div class="ui bottom attached segment font-content sample-box">
|
||
<span class="copy sample-copy"
|
||
data-clipboard-text="<?php echo format_sample_attr($samplePair['input']); ?>"><?php echo $MSG_COPY; ?></span>
|
||
<pre
|
||
style="margin-top: 0; margin-bottom: 0; "><code class="lang-plain"><?php echo format_sample_code($samplePair['input']); ?></code></pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header sample-header"><?php echo $MSG_Sample_Output . ' ' . ($sampleIndex + 1); ?></h4>
|
||
<div class="ui bottom attached segment font-content sample-box">
|
||
<span class="copy sample-copy"
|
||
data-clipboard-text="<?php echo format_sample_attr($samplePair['output']); ?>"><?php echo $MSG_COPY; ?></span>
|
||
<pre
|
||
style="margin-top: 0; margin-bottom: 0; "><code class="lang-plain"><?php echo format_sample_code($samplePair['output']); ?></code></pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
<?php } else { ?>
|
||
<?php if ($singleSampleInput !== '' || isset($_GET['spa'])) { ?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header sample-header"><?php echo $MSG_Sample_Input ?></h4>
|
||
<div class="ui bottom attached segment font-content sample-box">
|
||
<span class="copy sample-copy"
|
||
data-clipboard-text="<?php echo format_sample_attr($singleSampleInput); ?>"><?php echo $MSG_COPY; ?></span>
|
||
<pre
|
||
style="margin-top: 0; margin-bottom: 0; "><code class="lang-plain"><?php echo format_sample_code($singleSampleInput); ?></code></pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
<?php if ($singleSampleOutput !== '' || isset($_GET['spa'])) { ?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header sample-header"><?php echo $MSG_Sample_Output ?></h4>
|
||
<div class="ui bottom attached segment font-content sample-box">
|
||
<span class="copy sample-copy"
|
||
data-clipboard-text="<?php echo format_sample_attr($singleSampleOutput); ?>"><?php echo $MSG_COPY; ?></span>
|
||
<pre
|
||
style="margin-top: 0; margin-bottom: 0; "><code class="lang-plain"><?php echo format_sample_code($singleSampleOutput); ?></code></pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
<?php } ?>
|
||
<?php if ($row['hint'] || isset($_GET['spa'])) { ?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui top attached block header"><?php echo $MSG_HINT ?></h4>
|
||
<div id='hint' class="ui bottom attached segment font-content hint">
|
||
<?php
|
||
echo trans_md($row['hint']);
|
||
?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
<?php
|
||
$color = array("blue", "teal", "orange", "pink", "olive", "red", "violet", "yellow", "green", "purple");
|
||
$tcolor = 0;
|
||
?>
|
||
<?php if ($row['source'] && !isset($_GET['cid'])) {
|
||
$cats = explode(" ", $row['source']);
|
||
?>
|
||
<div class="row">
|
||
<div class="column">
|
||
<h4 class="ui block header top attached" id="show_tag_title_div"
|
||
style="margin-bottom: 0; margin-left: -1px; margin-right: -1px; ">
|
||
<?php echo $MSG_SOURCE ?>
|
||
</h4>
|
||
<div class="ui bottom attached segment" id="show_tag_div">
|
||
|
||
<?php foreach ($cats as $cat) {
|
||
if (trim($cat) == "")
|
||
continue;
|
||
$label_theme = $color[$tcolor % count($color)];
|
||
$tcolor++;
|
||
?>
|
||
<a href="<?php
|
||
if (mb_ereg("^http", $cat)) // remote oj pop links
|
||
echo htmlentities($cat, ENT_QUOTES, 'utf-8') . '" target="_blank';
|
||
else
|
||
echo "problemset.php?search=" . urlencode(htmlentities($cat, ENT_QUOTES, 'utf-8'));
|
||
?>" class="ui medium <?php echo $label_theme; ?> label">
|
||
<?php echo htmlentities($cat, ENT_QUOTES, 'utf-8'); ?>
|
||
</a>
|
||
<?php } ?>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<?php } ?>
|
||
|
||
<div class="ui buttons">
|
||
|
||
<?php
|
||
if ($pr_flag) {
|
||
echo "<a id='submit' class=\"small ui primary button\" href=\"submitpage.php?id=$id\">$MSG_SUBMIT</a>";
|
||
echo "<a class=\"small ui positive button\" href=\"status.php?problem_id=$id\">$MSG_SUBMIT_RECORD</a>";
|
||
echo "<a class=\"small ui orange button\" href=\"problemstatus.php?id=$id\">$MSG_STATISTICS</a>";
|
||
if ($OJ_BBS)
|
||
echo "<a class=\"small ui red button\" href=\"discuss.php?pid=$id\">$MSG_BBS</a>";
|
||
} else {
|
||
echo "<a href=\"contest.php?cid=$cid\" class=\"ui orange button\">$MSG_RETURN_CONTEST</a>";
|
||
if ($contest_is_over)
|
||
echo "<a id='submit' class=\"small ui primary button\" href=\"submitpage.php?id=$id\">$MSG_SUBMIT</a>";
|
||
else
|
||
echo "<a id='submit' class=\"small ui primary button\" href=\"submitpage.php?cid=$cid&pid=$pid&langmask=$langmask\">$MSG_SUBMIT</a>";
|
||
echo "<a class=\"small ui positive button\" href=\"status.php?problem_id=$PID[$pid]&cid=$cid\">$MSG_SUBMIT_RECORD</a>";
|
||
}
|
||
if (!file_exists($OJ_DATA . "/" . $id . "/solution.name"))
|
||
echo "<a class='small ui primary button' href='#' onclick='transform()' role='button'>$MSG_SHOW_OFF</a>";
|
||
?>
|
||
|
||
</div>
|
||
</div>
|
||
<style>
|
||
#dragButton {
|
||
width: 10px;
|
||
height: 10%;
|
||
background-color: gray;
|
||
position: absolute;
|
||
top: 350px;
|
||
left: 0;
|
||
cursor: col-resize;
|
||
/* 显示可调整宽度的光标 */
|
||
}
|
||
</style>
|
||
<script type="text/javascript">
|
||
|
||
function transform() {
|
||
let height = document.body.clientHeight;
|
||
<?php if ($row['spj'] == 2) { ?>
|
||
let width = parseInt(document.body.clientWidth * 0.3);
|
||
let width2 = parseInt(document.body.clientWidth * 0.7);
|
||
<?php } else { ?>
|
||
let width = parseInt(document.body.clientWidth * 0.6);
|
||
let width2 = parseInt(document.body.clientWidth * 0.4);
|
||
<?php } ?>
|
||
let submitURL = $("#submit")[0].href;
|
||
<?php
|
||
if (isset($_GET['sid']))
|
||
echo "submitURL+='&sid=" . intval($_GET['sid']) . "';";
|
||
?>
|
||
console.log(width);
|
||
let main = $("#main");
|
||
let problem = main.html();
|
||
if (window.screen.width < 500) {
|
||
main.parent().append("<div id='submitPage' class='container' style='opacity:0.95;z-index:2;top:49px;'></div>");
|
||
$("#submitPage").html("<iframe id='ansFrame' src='" + submitURL + "&spa' width='100%' height='" + window.screen.height + "px' ></iframe>");
|
||
window.setTimeout('$("#ansFrame")[0].scrollIntoView()', 1000);
|
||
} else {
|
||
main.removeClass("container");
|
||
main.css("width", width2);
|
||
main.css("margin-left", "10px");
|
||
main.parent().append("<div id='submitPage' class='container' style='opacity:0.95;position:fixed;z-index:2;top:49px;right:-" + width2 + "px'></div>");
|
||
$("#submitPage").html("<iframe src='" + submitURL + "&spa' width='" + width + "px' height='" + height + "px' ></iframe>");
|
||
}
|
||
$("#submit").remove();
|
||
<?php if ($row['spj'] > 1) { ?>
|
||
window.setTimeout('$("iframe")[0].contentWindow.$("#TestRun").remove();', 1000);
|
||
<?php } ?>
|
||
|
||
// Add code to place drag button on the left side of the iframe
|
||
$("#submitPage").prepend("<div id='dragButton'></div>");
|
||
$(document).ready(function () {
|
||
let isDragging = false;
|
||
let startX = 0;
|
||
let initialWidth = 0;
|
||
|
||
|
||
function setIframeReadonly(readonly) {
|
||
const iframe = $("#submitPage").find('iframe')
|
||
if (readonly) {
|
||
iframe.css({
|
||
position: 'relative',
|
||
'z-index': -999
|
||
})
|
||
} else {
|
||
iframe.css({
|
||
position: 'static',
|
||
'z-index': 'unset'
|
||
})
|
||
}
|
||
}
|
||
|
||
|
||
// 鼠标按下时开始拖拽,颜色变为绿色
|
||
$("#dragButton").mousedown(function (event) {
|
||
if (event.target === this) { // Only allow dragging if the mouse button is clicked on the drag button itself
|
||
isDragging = true;
|
||
startX = event.pageX;
|
||
initialWidth = parseInt($("#main").css("width"));
|
||
$(this).css("background-color", "#a5ff00");
|
||
|
||
setIframeReadonly(true)
|
||
|
||
}
|
||
});
|
||
|
||
// 拖拽过程中更新宽度
|
||
$(document).mousemove(function (event) {
|
||
if (isDragging) {
|
||
let diffX = event.pageX - startX;
|
||
let newWidth = initialWidth + diffX;
|
||
$("#main").css("width", newWidth);
|
||
$("#submitPage").css("right", "-" + newWidth + "px");
|
||
$("#submitPage").find("iframe").attr("width", document.body.clientWidth - newWidth + "px");
|
||
}
|
||
});
|
||
|
||
// 鼠标释放时停止拖拽,恢复原始颜色
|
||
$(document).mouseup(function () {
|
||
if (isDragging) {
|
||
$("#dragButton").css("background-color", "gray");
|
||
}
|
||
isDragging = false;
|
||
|
||
setIframeReadonly(false)
|
||
|
||
});
|
||
|
||
// 鼠标移开页面或失焦时停止拖拽,恢复原始颜色
|
||
$(document).mouseleave(function () {
|
||
if (isDragging) {
|
||
$("#dragButton").css("background-color", "gray");
|
||
}
|
||
isDragging = false;
|
||
|
||
setIframeReadonly(false)
|
||
|
||
});
|
||
|
||
$(window).blur(function () {
|
||
if (isDragging) {
|
||
$("#dragButton").css("background-color", "gray");
|
||
}
|
||
isDragging = false;
|
||
setIframeReadonly(false)
|
||
|
||
});
|
||
|
||
});
|
||
|
||
}
|
||
|
||
function submit_code() {
|
||
if (!$('#submit_code input[name=answer]').val().trim() && !editor.getValue().trim()) return false;
|
||
$('#submit_code input[name=language]').val($('#languages-menu .item.active').data('value'));
|
||
lastSubmitted = editor.getValue();
|
||
$('#submit_code input[name=code]').val(editor.getValue());
|
||
return true;
|
||
}
|
||
|
||
// $('#languages-menu')[0].scrollTop = $('#languages-menu .active')[0].offsetTop - $('#languages-menu')[0].firstElementChild.offsetTop;
|
||
|
||
$(function () {
|
||
$('#languages-menu .item').click(function () {
|
||
$(this)
|
||
.addClass('active')
|
||
.closest('.ui.menu')
|
||
.find('.item')
|
||
.not($(this))
|
||
.removeClass('active')
|
||
;
|
||
editor.getSession().setMode("ace/mode/" + $(this).data('mode'));
|
||
});
|
||
});
|
||
</script>
|
||
|
||
|
||
<?php include("template/$OJ_TEMPLATE/footer.php"); ?>
|
||
|
||
<script>
|
||
function phpfm(pid) {
|
||
//alert(pid);
|
||
$.post("admin/phpfm.php", { 'frame': 3, 'pid': pid, 'pass': '' }, function (data, status) {
|
||
if (status == "success") {
|
||
document.location.href = "admin/phpfm.php?frame=3&pid=" + pid;
|
||
}
|
||
});
|
||
}
|
||
function getFrameSourceValue(frameWindow) {
|
||
if (frameWindow.editor && typeof frameWindow.editor.getValue === 'function') {
|
||
return frameWindow.editor.getValue();
|
||
}
|
||
return frameWindow.$("#source").text();
|
||
}
|
||
function setFrameSourceValue(frameWindow, value) {
|
||
if (frameWindow.editor && typeof frameWindow.editor.setValue === 'function') {
|
||
frameWindow.editor.setValue(value);
|
||
return;
|
||
}
|
||
frameWindow.$("#source").text(value);
|
||
}
|
||
function selectOne(num, answer) {
|
||
let frameWindow = $("iframe")[0].contentWindow;
|
||
let old = getFrameSourceValue(frameWindow);
|
||
let key = num + ".*";
|
||
console.log(key);
|
||
let rep = old.replace(new RegExp(key), num + " " + answer);
|
||
setFrameSourceValue(frameWindow, rep);
|
||
}
|
||
function selectMulti(num, answer) {
|
||
let frameWindow = $("iframe")[0].contentWindow;
|
||
let old = getFrameSourceValue(frameWindow);
|
||
let key = num + ".*";
|
||
console.log(key);
|
||
let rep = old.replace(new RegExp(key), num + " " + answer);
|
||
setFrameSourceValue(frameWindow, rep);
|
||
}
|
||
|
||
$(document).ready(function () {
|
||
$("#creator").load("problem-ajax.php?pid=<?php echo $id ?>");
|
||
|
||
function renderProblemMarkdown() {
|
||
<?php if (isset($OJ_MARKDOWN) && $OJ_MARKDOWN) { ?>
|
||
return HustOJVditor.renderMarkdownBlocks('.md');
|
||
<?php } ?>
|
||
return Promise.resolve([]);
|
||
}
|
||
|
||
function initializeProblemChoices() {
|
||
$('span[class=auto_select]').each(function () {
|
||
let i = 1;
|
||
let start = 0;
|
||
let next = 0;
|
||
let raw = $(this).html();
|
||
let options = ['A', 'B', 'C', 'D'];
|
||
console.log("scanning...");
|
||
while (start >= 0) {
|
||
start = raw.indexOf("\n" + i + ".", start);
|
||
if (start < 0) break;
|
||
let end = start;
|
||
let type = "radio"
|
||
for (let j = 0; j < 4; j++) {
|
||
let option = options[j];
|
||
end = raw.indexOf(option + ".", start);
|
||
next = raw.indexOf("\n" + (i + 1) + ".", start);
|
||
console.log("[" + raw.substring(start, end) + "]");
|
||
if (end < 0 || (end > next && next > 0)) {
|
||
console.log("i:" + i + " j:" + option + " end:" + end + " next:" + next);
|
||
end = start;
|
||
break;
|
||
}
|
||
if (j == 0 && raw.substring(start, end).indexOf("多选") > 0) type = "checkbox";
|
||
let disp = "<input type=\"" + type + "\" name=\"" + i + "\" value=\"" + option + "\" />" + option + ".";
|
||
raw = raw.substring(0, end - 1) + disp + raw.substring(end + 2);
|
||
start += disp.length;
|
||
}
|
||
start = end + 1;
|
||
i++;
|
||
}
|
||
$(this).html(raw);
|
||
});
|
||
|
||
$('span[class="md auto_select"]').each(function () {
|
||
let i = 1;
|
||
let options = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
|
||
$(this).find("ul").each(function () {
|
||
let type = "radio";
|
||
let ol = $(this).prev("ol");
|
||
if (ol != undefined && ol.attr("start") != undefined) i = ol.attr("start");
|
||
console.log("id[" + i + "]");
|
||
if ($(this).html().indexOf("多选") > 0 || (ol != undefined && ol.html() != undefined && ol.html().indexOf("multiselect") > 0)) type = "checkbox";
|
||
let j = 0;
|
||
$(this).find("li").each(function () {
|
||
let option = options[j];
|
||
let disp = "<input type=\"" + type + "\" name=\"" + i + "\" value=\"" + option + "\" />" + option + ".";
|
||
$(this).prepend(disp);
|
||
j++;
|
||
});
|
||
i++;
|
||
});
|
||
let html = $(this).html();
|
||
for (; i > 0; i--) {
|
||
console.log("searching..." + i);
|
||
html = html.replace("{{ input(" + i + ") }}", "<input type='text' size=5 name='" + i + "' placeholder='第" + i + "题' ><br>");
|
||
}
|
||
html = html.replaceAll("<", "<");
|
||
html = html.replaceAll(">", ">");
|
||
$(this).html(html);
|
||
});
|
||
|
||
$(".auto_select").find('input[type="text"]').change(function () {
|
||
selectOne($(this).attr("name"), $(this).val());
|
||
});
|
||
|
||
$('input[type="radio"]').click(function () {
|
||
if ($(this).is(':checked'))
|
||
selectOne($(this).attr("name"), $(this).val());
|
||
}).css("width", "24px").css("height", "21px");
|
||
$('input[type="checkbox"]').click(function () {
|
||
let num = $(this).attr("name");
|
||
let answer = "";
|
||
$("input[type=checkbox][name=" + num + "]").each(function () {
|
||
if ($(this).is(':checked'))
|
||
answer += $(this).val();
|
||
});
|
||
selectMulti(num, answer);
|
||
}).css("width", "24px").css("height", "21px");
|
||
<?php if ($row['spj'] > 1 || isset($_GET['sid']) || (isset($OJ_AUTO_SHOW_OFF) && $OJ_AUTO_SHOW_OFF)) { ?>
|
||
transform();
|
||
<?php } ?>
|
||
}
|
||
|
||
window.renderProblemMarkdown = renderProblemMarkdown;
|
||
|
||
renderProblemMarkdown().catch(function (error) {
|
||
console.error('Failed to render problem markdown.', error);
|
||
}).then(function () {
|
||
initializeProblemChoices();
|
||
});
|
||
|
||
});
|
||
</script>
|
||
|
||
|
||
<script>
|
||
$('.sample-copy').each(function () {
|
||
var button = $(this);
|
||
var defaultLabel = button.text();
|
||
var clipboard = new Clipboard(this);
|
||
|
||
clipboard.on('success', function (e) {
|
||
button.text("<?php echo $MSG_COPY . $MSG_SUCCESS; ?>!");
|
||
setTimeout(function () { button.text(defaultLabel); }, 1500);
|
||
console.log(e);
|
||
});
|
||
|
||
clipboard.on('error', function (e) {
|
||
button.text("<?php echo $MSG_COPY . $MSG_FAIL; ?>!");
|
||
setTimeout(function () { button.text(defaultLabel); }, 1500);
|
||
console.log(e);
|
||
});
|
||
});
|
||
|
||
</script>
|
||
<?php if (isset($OJ_MATHJAX) && $OJ_MATHJAX) { ?>
|
||
<!--以下为了加载公式的使用而既加入-->
|
||
<script>
|
||
MathJax = {
|
||
tex: { inlineMath: [['$', '$'], ['\\(', '\\)']] }
|
||
};
|
||
</script>
|
||
|
||
<script id="MathJax-script" async src="template/syzoj/tex-chtml.js"></script>
|
||
<style>
|
||
.jumbotron1 {
|
||
font-size: 18px;
|
||
}
|
||
</style>
|
||
|
||
<?php } ?>
|