diff --git a/web/app/controllers/contest_manage.php b/web/app/controllers/contest_manage.php index d4ae16a..015d11d 100644 --- a/web/app/controllers/contest_manage.php +++ b/web/app/controllers/contest_manage.php @@ -256,82 +256,36 @@ function(res) { EOD); $add_problem_form->runAtServer(); } elseif ($cur_tab == 'managers') { - if (isset($_POST['submit-remove_manager']) && $_POST['submit-remove_manager'] == 'remove_manager') { - $username = $_POST['username']; - $user = UOJUser::query($username); + $managers_form = newAddDelCmdForm( + 'managers', + 'validateUserAndStoreByUsername', + function ($type, $username, &$vdata) { + $user = $vdata['user'][$username]; - if (!$user) { - dieWithAlert('用户不存在。'); - } - - if (!UOJContest::cur()->userCanManage($user)) { - dieWithAlert('用户不是这场比赛的管理员。'); - } - - DB::delete([ - "delete from contests_permissions", - "where", [ - "contest_id" => $contest['id'], - "username" => $user['username'], - ] - ]); - dieWithAlert('移除成功!'); - } - - $add_manager_form = new UOJForm('add_manager'); - $add_manager_form->addInput( - 'username', + if ($type == '+') { + DB::insert([ + "insert into contests_permissions", + "(contest_id, username)", + "values", DB::tuple([ + UOJContest::info('id'), $user['username'] + ]) + ]); + } else if ($type == '-') { + DB::delete([ + "delete from contests_permissions", + "where", [ + "contest_id" => UOJContest::info('id'), + "username" => $user['username'] + ] + ]); + } + }, + null, [ - 'label' => '用户名', - 'validator_php' => function ($username, &$vdata) { - $user = UOJUser::query($username); - - if (!$user) { - return '用户不存在'; - } - - if (UOJContest::cur()->userCanManage($user)) { - return '用户已经是这场比赛的管理员'; - } - - $vdata['username'] = $username; - - return ''; - }, + 'help' => '命令格式:命令一行一个,+mike 表示把 mike 加入管理者,-mike 表示把 mike 从管理者中移除。', ] ); - $add_manager_form->handle = function (&$vdata) { - DB::insert([ - "insert into contests_permissions", - DB::bracketed_fields(["contest_id", "username"]), - "values", - DB::tuple([UOJContest::info('id'), $vdata['username']]) - ]); - - dieWithJsonData(['status' => 'success', 'message' => '已将用户名为 ' . $vdata['username'] . ' 的用户设置为本场比赛的管理者。']); - }; - $add_manager_form->config['submit_button']['text'] = '添加'; - $add_manager_form->config['submit_button']['class'] = 'btn btn-secondary mt-3'; - $add_manager_form->setAjaxSubmit(<<runAtServer(); + $managers_form->runAtServer(); } elseif ($cur_tab == 'others') { $rule_form = new UOJForm('basic_rule'); $rule_form->addSelect('basic_rule', [ @@ -531,81 +485,34 @@ EOD);
-
- -
-
-
- - 用户名 - 操作 - - EOD, - function ($row) { - $user = UOJUser::query($row['username']); +
+ + 用户名 + + EOD, + function ($row) { + $user = UOJUser::query($row['username']); - echo HTML::tag_begin('tr'); - echo HTML::tag('td', [], UOJUser::getLink($user)); - echo HTML::tag('td', [], [ - HTML::tag('form', [ - 'method' => 'POST', - 'target' => '_self', - 'class' => 'd-inline-block', - 'onsubmit' => "return confirm('你确定要将 {$user['username']} 从比赛管理员列表中移除吗?');", - ], [ - HTML::hiddenToken(), - HTML::empty_tag('input', [ - 'type' => 'hidden', - 'name' => 'username', - 'value' => $user['username'], - ]), - HTML::tag('button', [ - 'type' => 'submit', - 'class' => 'btn btn-link text-danger text-decoration-none p-0', - 'name' => 'submit-remove_manager', - 'value' => 'remove_manager', - ], '移除'), - ]), - ]); - echo HTML::tag_end('tr'); - }, - [ - 'echo_full' => true, - 'div_classes' => ['table-responsive'], - 'table_classes' => ['table'], - ] - ); - ?> -
-
- -
-
- printHTML(); ?> -
-
-
注意事项
-
    -
  • 添加管理者前请确认用户名是否正确以免带来不必要的麻烦。
  • -
  • 比赛管理者如果报名了比赛仍可以正常参赛,但不报名比赛也可以查看并管理本场比赛。
  • -
-
-
-
+ echo HTML::tag_begin('tr'); + echo HTML::tag('td', [], UOJUser::getLink($user)); + echo HTML::tag_end('tr'); + }, + [ + 'echo_full' => true, + 'div_classes' => ['table-responsive'], + 'table_classes' => ['table'], + ] + ); + ?> + + printHTML() ?>
diff --git a/web/app/controllers/problem_permissions_manage.php b/web/app/controllers/problem_permissions_manage.php index 3451be2..0c8bde3 100644 --- a/web/app/controllers/problem_permissions_manage.php +++ b/web/app/controllers/problem_permissions_manage.php @@ -46,7 +46,11 @@ $managers_form = newAddDelCmdForm( ] ]); } - } + }, + null, + [ + 'help' => '命令格式:命令一行一个,+mike 表示把 mike 加入管理者,-mike 表示把 mike 从管理者中移除。', + ] ); $managers_form->runAtServer(); diff --git a/web/app/libs/uoj-form-lib.php b/web/app/libs/uoj-form-lib.php index ddde655..333f4c9 100644 --- a/web/app/libs/uoj-form-lib.php +++ b/web/app/libs/uoj-form-lib.php @@ -1,13 +1,13 @@ ;window.location = window.location.origin + window.location.pathname + (window.location.search.length ? window.location.search + "&" : "?") + "_refresh_" + (+new Date()) + "=" + (+new Date()) + window.location.hash;'); -function newAddDelCmdForm($form_name, $validate, $handle, $final = null) { +function newAddDelCmdForm($form_name, $validate, $handle, $final = null, $cfg = []) { $form = new UOJForm($form_name); $form->addTextArea("{$form_name}_cmds", [ 'label' => '命令', 'input_class' => 'form-control font-monospace', 'validator_php' => function ($str, &$vdata) use ($validate) { - $cmds = array(); + $cmds = []; foreach (explode("\n", $str) as $line_id => $raw_line) { $line = trim($raw_line); if ($line == '') { @@ -26,8 +26,8 @@ function newAddDelCmdForm($form_name, $validate, $handle, $final = null) { $vdata['cmds'] = $cmds; return ''; }, - ]); - if (!isset($final)) { + ] + $cfg); + if (!isset($final) || !$final) { $form->handle = function (&$vdata) use ($handle) { foreach ($vdata['cmds'] as $cmd) { $handle($cmd['type'], $cmd['obj'], $vdata);