-
Notifications
You must be signed in to change notification settings - Fork 12
/
edit.php
75 lines (64 loc) · 3.16 KB
/
edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
//? |-----------------------------------------------------------------------------------------------|
//? | /api/contest/problems/edit.php |
//? | |
//? | Copyright (c) 2018-2020 Belikhun. All right reserved |
//? | Licensed under the MIT License. See LICENSE in the project root for license information. |
//? |-----------------------------------------------------------------------------------------------|
// SET PAGE TYPE
define("PAGE_TYPE", "API");
require_once $_SERVER["DOCUMENT_ROOT"] ."/lib/ratelimit.php";
require_once $_SERVER["DOCUMENT_ROOT"] ."/lib/belibrary.php";
require_once $_SERVER["DOCUMENT_ROOT"] ."/lib/logs.php";
if (!isLogedIn())
stop(11, "Bạn chưa đăng nhập.", 401);
checkToken();
if ($_SESSION["id"] !== "admin")
stop(31, "Access Denied!", 403);
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(getForm("point"), "integer");
$time = withType(getForm("time"), "integer");
$memLimit = withType(getForm("memory"), "integer");
$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,
"description" => $description,
"point" => $point,
"time" => $time,
"memory" => $memLimit,
"type" => Array(
"inp" => $inpType,
"out" => $outType
),
"accept" => $accept,
"test" => $test,
"disabled" => $disabled
), $image, $attachment);
switch ($code) {
case PROBLEM_OKAY:
writeLog("OKAY", "Đã chỉnh sửa đề \"$id\"");
stop(0, "Chỉnh sửa đề thành công!", 200, Array( "id" => $id ));
break;
case PROBLEM_ERROR_IDREJECT:
stop(45, "Không tìm thấy đề của id đã cho!", 404, Array( "id" => $id ));
break;
case PROBLEM_ERROR_FILEREJECT:
stop(43, "Không chấp nhận loại tệp!", 400, Array( "id" => $id, "allow" => IMAGE_ALLOW ));
break;
case PROBLEM_ERROR_FILETOOLARGE:
stop(42, "Tệp quá lớn!", 400, Array( "id" => $id, "image" => MAX_IMAGE_SIZE, "attachment" => MAX_ATTACHMENT_SIZE ));
break;
case PROBLEM_ERROR:
stop(-1, "Lỗi không rõ.", 500, Array( "id" => $id ));
break;
}