From 21e67e6fb59eeb7aa3dfba117c9da1cc17f047a0 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 18 Oct 2022 14:47:03 +0800 Subject: [PATCH] refactor(web/problem/manage/data): bootstrap5 --- web/app/controllers/problem_data_manage.php | 591 +++++++++++--------- web/css/uoj-bs5.css | 4 + 2 files changed, 335 insertions(+), 260 deletions(-) diff --git a/web/app/controllers/problem_data_manage.php b/web/app/controllers/problem_data_manage.php index 229aa3f..7f6c0b4 100644 --- a/web/app/controllers/problem_data_manage.php +++ b/web/app/controllers/problem_data_manage.php @@ -3,6 +3,7 @@ redirectToLogin(); } + requireLib('bootstrap5'); requirePHPLib('form'); requirePHPLib('judger'); requirePHPLib('data'); @@ -20,7 +21,8 @@ $data_dir = "/var/uoj_data/${problem['id']}"; function echoFileNotFound($file_name) { - echo '

', htmlspecialchars($file_name), ' ', '文件未找到', '

'; + echo '
', htmlspecialchars($file_name), '
'; + echo '
', '文件未找到', '
'; } function echoFilePre($file_name) { global $data_dir; @@ -34,8 +36,9 @@ } finfo_close($finfo); - echo '

', htmlspecialchars($file_name), ' ', $mimetype, '

'; - echo "
\n";
+		echo '
', htmlspecialchars($file_name), '
'; + echo '
', $mimetype, '
'; + echo '
', "\n";
 
 		$output_limit = 1000;
 		if (strStartWith($mimetype, 'text/')) {
@@ -77,7 +80,7 @@
 
 	//添加配置文件
 	if ($_POST['problem_settings_file_submit']=='submit') {
-		if ($_POST['use_builtin_checker'] and $_POST['n_tests'] and $_POST['input_pre'] and $_POST['input_suf'] and $_POST['output_pre'] and $_POST['output_suf'] and $_POST['time_limit'] and $_POST['memory_limit']) {
+		if ($_POST['use_builtin_checker'] and $_POST['n_tests']) {
 			$set_filename="/var/uoj_data/upload/{$problem['id']}/problem.conf";
 			$has_legacy=false;
 			if (file_exists($set_filename)) {
@@ -100,20 +103,28 @@
 			} else {
 				fwrite($setfile, "n_sample_tests 0\n");
 			}
-			fwrite($setfile, "input_pre ".$_POST['input_pre']."\n");
-			fwrite($setfile, "input_suf ".$_POST['input_suf']."\n");
-			fwrite($setfile, "output_pre ".$_POST['output_pre']."\n");
-			fwrite($setfile, "output_suf ".$_POST['output_suf']."\n");
-			fwrite($setfile, "time_limit ".$_POST['time_limit']."\n");
-			fwrite($setfile, "memory_limit ".$_POST['memory_limit']."\n");
+			if (isset($_POST['input_pre'])) {
+				fwrite($setfile, "input_pre ".$_POST['input_pre']."\n");
+			}
+			if (isset($_POST['input_suf'])) {
+				fwrite($setfile, "input_suf ".$_POST['input_suf']."\n");
+			}
+			if (isset($_POST['output_pre'])) {
+				fwrite($setfile, "output_pre ".$_POST['output_pre']."\n");
+			}
+			if (isset($_POST['output_suf'])) {
+				fwrite($setfile, "output_suf ".$_POST['output_suf']."\n");
+			}
+			fwrite($setfile, "time_limit ".($_POST['time_limit'] ?: 1)."\n");
+			fwrite($setfile, "memory_limit ".($_POST['memory_limit'] ?: 256)."\n");
 			fclose($setfile);
 			if (!$has_legacy) {
-				echo "";
+				echo "";
 			} else {
-				echo "";
+				echo "";
 			}
 		} else {
-			$errmsg = "添加配置文件失败,请检查是否所有输入框都已填写!";
+			$errmsg = "添加配置文件失败,请检查是否所有必填输入框都已填写!";
 			becomeMsgPage('
' . $errmsg . '
返回'); } } @@ -121,27 +132,13 @@ $info_form = new UOJForm('info'); $http_host = HTML::escape(UOJContext::httpHost()); - $info_form->appendHTML(<< - - -EOD - ); $attachment_url = HTML::url("/download.php?type=attachment&id={$problem['id']}"); $info_form->appendHTML(<< @@ -153,7 +150,7 @@ EOD @@ -164,7 +161,7 @@ EOD @@ -176,7 +173,7 @@ EOD
-
+		
 $esc_submission_requirement
 
@@ -189,7 +186,7 @@ EOD
-
+		
 $esc_extra_config
 
@@ -253,9 +250,11 @@ EOD $this->setDisplayer('problem.conf', function($self) { global $info_form; $info_form->printHTML(); - echo '
'; - echo ''; + echo '
'; + + echo '
'; + echo ''; echo ''; echo ''; echo ''; @@ -272,7 +271,7 @@ EOD } elseif ($info['status'] == 'danger') { echo ''; echo ''; - echo ''; + echo ''; echo ''; } } @@ -322,9 +321,10 @@ EOD } } + $problem_conf = getUOJConf("$data_dir/problem.conf"); + function getDataDisplayer() { - global $data_dir; - global $problem; + global $data_dir, $problem, $problem_conf; $allow_files = array_flip(array_filter(scandir($data_dir), function($x) { return $x !== '.' && $x !== '..'; @@ -346,11 +346,13 @@ EOD }; }; - $problem_conf = getUOJConf("$data_dir/problem.conf"); if ($problem_conf === -1) { return (new DataDisplayer())->setDisplayer('problem.conf', function() { global $info_form; $info_form->printHTML(); + + echo '
'; + echoFileNotFound('problem.conf'); }); } @@ -358,7 +360,10 @@ EOD return (new DataDisplayer())->setDisplayer('problem.conf', function() { global $info_form; $info_form->printHTML(); - echo '

problem.conf 格式有误

'; + + echo '
'; + + echo '
problem.conf 文件格式有误
'; echoFilePre('problem.conf'); }); } @@ -435,7 +440,7 @@ EOD if (!isset($problem_conf['interaction_mode'])) { if (isset($problem_conf['use_builtin_checker'])) { $data_disp->addDisplayer('checker', function($self) { - echo '

use builtin checker : ', $self->problem_conf['use_builtin_checker']['val'], '

'; + echo '
use builtin checker : ', $self->problem_conf['use_builtin_checker']['val'], '
'; }); } else { $data_disp->addDisplayer('checker', $getDisplaySrcFunc('chk')); @@ -469,7 +474,6 @@ EOD $hackable_form->handle = function() { global $problem; $problem['hackable'] = !$problem['hackable']; - //$problem['hackable'] = 0; $ret = dataSyncProblemData($problem); if ($ret) { becomeMsgPage('
' . $ret . '
返回'); @@ -478,8 +482,8 @@ EOD $hackable = $problem['hackable'] ? 1 : 0; DB::query("update problems set hackable = $hackable where id = ${problem['id']}"); }; - $hackable_form->submit_button_config['class_str'] = 'btn btn-warning btn-block'; - $hackable_form->submit_button_config['text'] = $problem['hackable'] ? '禁止使用hack' : '允许使用hack'; + $hackable_form->submit_button_config['class_str'] = 'btn btn-warning d-block w-100'; + $hackable_form->submit_button_config['text'] = $problem['hackable'] ? '禁用 Hack 功能' : '启用 Hack 功能'; $hackable_form->submit_button_config['smart_confirm'] = ''; $data_form = new UOJForm('data'); @@ -491,7 +495,7 @@ EOD becomeMsgPage('
' . $ret . '
返回'); } }; - $data_form->submit_button_config['class_str'] = 'btn btn-danger btn-block'; + $data_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; $data_form->submit_button_config['text'] = '检验配置并同步数据'; $data_form->submit_button_config['smart_confirm'] = ''; @@ -500,7 +504,7 @@ EOD global $problem; dataClearProblemData($problem); }; - $clear_data_form->submit_button_config['class_str'] = 'btn btn-danger btn-block'; + $clear_data_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; $clear_data_form->submit_button_config['text'] = '清空题目数据'; $clear_data_form->submit_button_config['smart_confirm'] = ''; @@ -510,7 +514,7 @@ EOD rejudgeProblem($problem); }; $rejudge_form->succ_href = "/submissions?problem_id={$problem['id']}"; - $rejudge_form->submit_button_config['class_str'] = 'btn btn-danger btn-block'; + $rejudge_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; $rejudge_form->submit_button_config['text'] = '重测该题'; $rejudge_form->submit_button_config['smart_confirm'] = ''; @@ -520,7 +524,7 @@ EOD rejudgeProblemGe97($problem); }; $rejudgege97_form->succ_href = "/submissions?problem_id={$problem['id']}"; - $rejudgege97_form->submit_button_config['class_str'] = 'btn btn-danger btn-block'; + $rejudgege97_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; $rejudgege97_form->submit_button_config['text'] = '重测 >=97 的程序'; $rejudgege97_form->submit_button_config['smart_confirm'] = ''; @@ -560,7 +564,7 @@ EOD $esc_config = DB::escape(json_encode($config)); DB::query("update problems set extra_config = '$esc_config' where id = '{$problem['id']}'"); }; - $view_type_form->submit_button_config['class_str'] = 'btn btn-warning btn-block top-buffer-sm'; + $view_type_form->submit_button_config['class_str'] = 'btn btn-warning d-block w-100 mt-2'; $solution_view_type_form = new UOJForm('solution_view_type'); $solution_view_type_form->addVSelect('view_solution_type', @@ -587,7 +591,7 @@ EOD $esc_config = DB::escape(json_encode($config)); DB::query("update problems set extra_config = '$esc_config' where id = '{$problem['id']}'"); }; - $solution_view_type_form->submit_button_config['class_str'] = 'btn btn-warning btn-block top-buffer-sm'; + $solution_view_type_form->submit_button_config['class_str'] = 'btn btn-warning d-block w-100 mt-2'; $difficulty_form = new UOJForm('difficulty'); $difficulty_form->addVInput('difficulty', 'text', '难度系数', $problem_extra_config['difficulty'], @@ -605,7 +609,7 @@ EOD $esc_config = DB::escape(json_encode($config)); DB::query("update problems set extra_config = '$esc_config' where id = '{$problem['id']}'"); }; - $difficulty_form->submit_button_config['class_str'] = 'btn btn-warning btn-block top-buffer-sm'; + $difficulty_form->submit_button_config['class_str'] = 'btn btn-warning d-block w-100 mt-2'; if ($problem['hackable']) { $test_std_form = new UOJForm('test_std'); @@ -614,7 +618,7 @@ EOD $user_std = queryUser('std'); if (!$user_std) { - becomeMsgPage('请建立"std"账号。'); + becomeMsgPage('请建立 std 账号。'); } $requirement = json_decode($problem['submission_requirement'], true); @@ -655,7 +659,7 @@ EOD DB::insert("insert into submissions (problem_id, submit_time, submitter, content, language, tot_size, status, result, is_hidden) values ({$problem['id']}, now(), '{$user_std['username']}', '$esc_content', '$esc_language', $tot_size, '{$result['status']}', '$result_json', $is_hidden)"); }; $test_std_form->succ_href = "/submissions?problem_id={$problem['id']}"; - $test_std_form->submit_button_config['class_str'] = 'btn btn-danger btn-block'; + $test_std_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100'; $test_std_form->submit_button_config['text'] = '检验数据正确性'; $test_std_form->runAtServer(); } @@ -670,224 +674,291 @@ EOD $rejudgege97_form->runAtServer(); $info_form->runAtServer(); ?> - + -

# : 管理

-
-
-
-
- -
-
- displayFile('problem.conf'); ?> -
- -
-
-
-
- - hack功能已启用 - - hack功能已禁止 - - printHTML() ?> -
-
- - printHTML() ?> - -
-
- - -
-
- - -
-
- printHTML(); ?> -
-
- printHTML(); ?> -
-
- printHTML(); ?> -
-
- printHTML(); ?> -
+

+ #. 管理 +

-
- -
-
- -
+ -
- - -
+
+
+
- + + + + +
+ + + + + diff --git a/web/css/uoj-bs5.css b/web/css/uoj-bs5.css index 3af5ad7..3039ad4 100644 --- a/web/css/uoj-bs5.css +++ b/web/css/uoj-bs5.css @@ -8,6 +8,10 @@ pre { tab-size: 4; } +.uoj-pre { + padding: 1em; +} + .uoj-username, .uoj-score { font-weight: 800;
problem.conf
key
', htmlspecialchars($key), '', htmlspecialchars($info['val']), ' ', '', htmlspecialchars($info['val']), ' ', '