Skip to content

Commit

Permalink
problem disabling functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Belikhun committed Feb 27, 2020
1 parent 7983911 commit ad05c23
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 325 deletions.
3 changes: 2 additions & 1 deletion api/code.txt
Expand Up @@ -25,6 +25,7 @@
22 file submit disabled
23 view log disabled
24 register disabled
25 problem disabled

// 3x: permission
31 access denied
Expand All @@ -37,7 +38,7 @@
44 file not found
45 file exist

// 10x: info
// 10x: info IGNORED
101 not in contest mode
102 modified nothing
103 contest not started
Expand Down
2 changes: 2 additions & 0 deletions api/contest/problems/add.php
Expand Up @@ -36,6 +36,7 @@
$attachment = isset($_FILES["attm"]) ? $_FILES["attm"] : null;
$description = reqForm("desc");
$test = isset($_POST["test"]) ? json_decode($_POST["test"], true) : Array();
$disabled = withType(getForm("disabled"), "boolean", false);

$code = problemAdd($id, Array(
"name" => $name,
Expand All @@ -49,6 +50,7 @@
"accept" => $accept,
"description" => $description,
"test" => $test,
"disabled" => $disabled
), $image, $attachment);

switch ($code) {
Expand Down
6 changes: 6 additions & 0 deletions api/contest/problems/attachment.php
Expand Up @@ -25,6 +25,12 @@

require_once $_SERVER["DOCUMENT_ROOT"] ."/data/problems/problem.php";

if (!problemExist($id))
stop(45, "Không tìm thấy đề của id đã cho!", 404, Array( "id" => $id ));

if (problemDisabled($id) && $_SESSION["id"] !== "admin")
stop(25, "Đề $id đã bị tắt", 403, Array( "id" => $id ));

if (problemGetAttachment($id, !getQuery("embed", false)) === PROBLEM_OKAY)
writeLog("INFO", "Đã tải tệp đính kèm của bài \"". $_GET["id"] ."\"");
else
Expand Down
13 changes: 8 additions & 5 deletions api/contest/problems/edit.php
Expand Up @@ -24,19 +24,21 @@
require_once $_SERVER["DOCUMENT_ROOT"] ."/data/problems/problem.php";

$id = preg_replace("/[.\/\\\\]/m", "", reqForm("id"));
$problem = problemGet($id, true);

$name = getForm("name");
$description = getForm("desc");

$point = withType(reqForm("point"), "integer");
$point = withType(getForm("point"), "integer");
$time = withType(getForm("time"), "integer");
$memLimit = withType(getForm("memory"), "integer");
$inpType = getForm("inpType");
$outType = getForm("outType");
$accept = json_decode(getForm("acpt", Array()), true);
$test = json_decode(getForm("test", Array()), true);
$inpType = getForm("inpType", $problem["type"]["inp"]);
$outType = getForm("outType", $problem["type"]["out"]);
$accept = json_decode(getForm("acpt", "[]"), true) ?: null;
$test = json_decode(getForm("test", "[]"), true) ?: null;
$image = isset($_FILES["img"]) ? $_FILES["img"] : null;
$attachment = isset($_FILES["attm"]) ? $_FILES["attm"] : null;
$disabled = withType(getForm("disabled"), "boolean");

$code = problemEdit($id, Array(
"name" => $name,
Expand All @@ -50,6 +52,7 @@
),
"accept" => $accept,
"test" => $test,
"disabled" => $disabled
), $image, $attachment);

switch ($code) {
Expand Down
17 changes: 12 additions & 5 deletions api/contest/problems/get.php
Expand Up @@ -18,7 +18,17 @@
contest_timeRequire([CONTEST_STARTED], false);

require_once $_SERVER["DOCUMENT_ROOT"] ."/data/problems/problem.php";
$data = problemGet($id);
$data = problemGet($id, $_SESSION["id"] === "admin");

switch ($data) {
case PROBLEM_ERROR_IDREJECT:
stop(44, "Không tìm thấy để của id đã cho!", 404, Array( "id" => $id ));
break;

case PROBLEM_ERROR_DISABLED:
stop(25, "Đề $id đã bị tắt", 403, Array( "id" => $id ));
break;
}

if (isset($data["image"]))
$data["image"] = "/api/contest/problems/image?id=". $id;
Expand All @@ -42,7 +52,4 @@
"embed" => false
);

if ($data === PROBLEM_ERROR_IDREJECT)
stop(44, "Không tìm thấy để của id đã cho!", 404, Array( "id" => $id ));
else
stop(0, "Success!", 200, $data);
stop(0, "Success!", 200, $data);
2 changes: 1 addition & 1 deletion api/contest/problems/image.php
Expand Up @@ -32,7 +32,7 @@ function showImage(string $path) {

require_once $_SERVER["DOCUMENT_ROOT"] ."/data/problems/problem.php";

if (!problemExist($id))
if (!problemExist($id) || (problemDisabled($id) && $_SESSION["id"] !== "admin"))
showImage(PROBLEM_DIR ."/image.default");

if (isset($problemList[$id]["image"])) {
Expand Down
2 changes: 1 addition & 1 deletion api/contest/problems/list.php
Expand Up @@ -16,4 +16,4 @@
contest_timeRequire([CONTEST_STARTED], false);

require_once $_SERVER["DOCUMENT_ROOT"] ."/data/problems/problem.php";
stop(0, "Thành công!", 200, problemList());
stop(0, "Thành công!", 200, problemList($_SESSION["id"] === "admin"));
3 changes: 3 additions & 0 deletions api/contest/upload.php
Expand Up @@ -40,6 +40,9 @@
if (!problemExist($filename))
stop(44, "Không có đề cho bài này!", 404, Array( "file" => $filename ));

if (problemDisabled($filename) && $_SESSION["id"] !== "admin")
stop(25, "Đề $filename đã bị tắt", 403, Array( "id" => $filename ));

if (!problemCheckExtension($filename, $extension))
stop(43, "Không chấp nhận tệp!", 415);
} else
Expand Down
11 changes: 10 additions & 1 deletion assets/css/core.css
Expand Up @@ -1222,6 +1222,10 @@ body.guest #problemp.hide {
animation: problemsListShow 0.5s cubic-bezier(0.23, 1, 0.32, 1) 0s 1 normal forwards;
}

#problemp .problemsContainer .problemsList:empty {
height: 100%;
}

#problemp .problemsContainer .problemsList .item {
position: relative;
display: flex;
Expand Down Expand Up @@ -1289,6 +1293,10 @@ body.guest #problemp.hide {
border-radius: 4px;
}

#problemp .problemsContainer .problemsList .item[disabled="true"] {
background-color: rgba(243, 184, 205, 0.6);
}

#problemp .problemsContainer .problem {
position: absolute;
width: 100%;
Expand Down Expand Up @@ -1530,8 +1538,9 @@ body.guest #problemp.hide {
#problemp .problemsContainer .problem .attachment .embed {
width: 100%;
height: 0;
min-height: 80px;
max-height: calc(100vh - 160px);
padding: 10px 0 20px 0;
margin: 10px 0 20px 0;
transition: height 0.4s ease-in;
}

Expand Down
10 changes: 7 additions & 3 deletions assets/css/dark.css
Expand Up @@ -98,6 +98,10 @@ body.dark #problemp .problemsContainer .problemsList .item {
border-bottom-color: rgb(88, 88, 88);
}

body.dark #problemp .problemsContainer .problemsList .item[disabled="true"] {
background-color: rgba(117, 57, 78, 0.6);
}

body.dark #problemp .problemsContainer .problemsList .item:hover {
background-color: rgb(70, 70, 70);
}
Expand Down Expand Up @@ -343,15 +347,15 @@ body.dark .problemSettings .header div span::before {
color: rgba(190, 190, 190, 0.54);
}

body.dark .problemSettings .problemsContainer.problemsList li.item:hover {
body.dark .problemSettings .problemsContainer .problemsList li.item:hover {
background-color: rgba(36, 36, 36, 0.4);
}

body.dark .problemSettings .problemsContainer.problemsList li.item .title .id {
body.dark .problemSettings .problemsContainer .problemsList li.item .title .id {
color: rgb(160, 160, 160);
}

body.dark .problemSettings .problemsContainer.problemsList li.item .title .name {
body.dark .problemSettings .problemsContainer .problemsList li.item .title .name {
color: rgb(214, 214, 214);
}

Expand Down
2 changes: 1 addition & 1 deletion assets/css/default.css
Expand Up @@ -505,7 +505,7 @@ body.dark separator {
.popupContainer .popupWindow .body .customNode {
position: relative;
flex-shrink: 1;
margin: 10px 0;
margin: 10px 0;
width: 100%;
}

Expand Down
41 changes: 29 additions & 12 deletions assets/css/switch.css
Expand Up @@ -7,7 +7,7 @@
? |-----------------------------------------------------------------------------------------------|
*/

.ios-switch {
.iosSwitch {
display: inline-block;
position: relative;
cursor: pointer;
Expand All @@ -19,7 +19,7 @@
user-select: none;
}

.ios-switch .background {
.iosSwitch .background {
position: absolute;
top: 0;
left: 0;
Expand All @@ -33,13 +33,13 @@
}

/* Hide the browser's default checkbox */
.ios-switch input {
.iosSwitch input {
position: absolute;
opacity: 0;
cursor: pointer;
}

.ios-switch .circle {
.iosSwitch .circle {
position: absolute;
display: inline-block;
top: 0;
Expand All @@ -55,12 +55,12 @@
animation-fill-mode: forwards;
}

.ios-switch input:checked + .background {
.iosSwitch input:checked + .background {
background: #4cd864;
border-color: #4cd864;
}

.ios-switch input:checked ~ .circle {
.iosSwitch input:checked ~ .circle {
animation: swanmfw 0.3s cubic-bezier(0.48,-0.07, 0.49, 1.08);
animation-fill-mode: forwards;
}
Expand Down Expand Up @@ -94,7 +94,7 @@
}
}

.material-switch {
.materialSwitch {
display: inline-block;
position: relative;
cursor: pointer;
Expand All @@ -106,13 +106,13 @@
user-select: none;
}

.material-switch input {
.materialSwitch input {
position: absolute;
opacity: 0;
cursor: pointer;
}

.material-switch .track {
.materialSwitch .track {
position: absolute;
width: 40px;
height: 16px;
Expand All @@ -121,7 +121,7 @@
transition: color 0.2s ease-in-out;
}

.material-switch .track::after {
.materialSwitch .track::after {
content: "";
position: absolute;
background-color: #ffffff;
Expand All @@ -135,15 +135,32 @@
transition: all 0.2s ease-in-out;
}

.material-switch input:checked + .track {
.materialSwitch input:checked + .track {
background-color: rgba(26, 115, 232, 0.5);
}

.material-switch input:checked + .track::after {
.materialSwitch input:checked + .track::after {
left: 16px;
background-color: #4285f4;
}

.materialSwitch input:disabled + .track {
cursor: not-allowed;
background-color: rgb(146, 146, 146);
}

.materialSwitch input:disabled + .track::after {
background-color: rgb(116, 116, 116);
}

.materialSwitch input:checked:disabled + .track {
background-color: rgba(7, 68, 148, 0.5);
}

.materialSwitch input:checked:disabled + .track::after {
background-color: #1e53a8;
}

.sq-checkbox {
position: relative;
display: block;
Expand Down

0 comments on commit ad05c23

Please sign in to comment.