-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshowsource.php
88 lines (80 loc) · 2.95 KB
/
showsource.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
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
$cache_time = 10;
$OJ_CACHE_SHARE = false;
require_once './include/cache_start.php';
require_once './include/db_info.inc.php';
require_once './include/setlang.php';
$view_title = "Source Code";
require_once "./include/const.inc.php";
if (!isset($_GET['id'])) {
$view_errors = "No such code!\n";
require "template/" . $OJ_TEMPLATE . "/error.php";
exit(0);
}
$ok = false;
$id = intval($_GET['id']);
$sql = "SELECT * FROM `solution` WHERE `solution_id`=?";
$result = pdo_query($sql, $id);
$row = $result[0];
$slanguage = $row['language'];
$sresult = $row['result'];
$stime = $row['time'];
$smemory = $row['memory'];
$sproblem_id = $row['problem_id'];
$view_user_id = $suser_id = $row['user_id'];
$contest_id = $row['contest_id'];
if (isset($OJ_EXAM_CONTEST_ID)) {
if ($contest_id < $OJ_EXAM_CONTEST_ID && (!isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || !isset($_SESSION[$OJ_NAME . '_' . 'source_browser']))) {
//2020.01.20修改逻辑 管理员与源代码审查者均有查看代码权限
header("Content-type: text/html; charset=utf-8");
echo $MSG_SOURCE_NOT_ALLOWED_FOR_EXAM;
exit();
}
}
if (isset($OJ_AUTO_SHARE) && $OJ_AUTO_SHARE && isset($_SESSION[$OJ_NAME . '_' . 'user_id'])) {
$sql = "SELECT 1 FROM solution where
result=4 and problem_id=$sproblem_id and user_id=?";
$rrs = pdo_query($sql, $_SESSION[$OJ_NAME . '_' . 'user_id']);
$ok = (count($rrs) > 0);
}
//check whether user has the right of view solutions of this problem
//echo "checking...";
if (isset($_SESSION[$OJ_NAME . '_' . 's' . $sproblem_id])) {
$ok = true;
// echo "Yes";
} else {
$sql = "select count(1) from privilege where user_id=? and rightstr=?";
$count = pdo_query($sql, $_SESSION[$OJ_NAME . '_' . 'user_id'], "s" . $sproblem_id);
if ($count && $count[0][0] > 0) {
$_SESSION[$OJ_NAME . '_' . 's' . $sproblem_id] = true;
$ok = true;
} else {
//echo "not right";
}
}
$view_source = "No source code available!";
if (isset($_SESSION[$OJ_NAME . '_' . 'user_id']) && $row && $row['user_id'] == $_SESSION[$OJ_NAME . '_' . 'user_id']) {
$ok = true;
}
if (isset($_SESSION[$OJ_NAME . '_' . 'administrator']) || isset($_SESSION[$OJ_NAME . '_' . 'source_browser'])) {
//2020.01.20修改逻辑 管理员与源代码审查者均有查看代码权限
$ok = true;
}
if (!$ok) {
$view_errors = "抱歉,您没有权限查看此信息!";
require "template/$OJ_TEMPLATE/error.php";
exit(0);
}
$sql = "SELECT `source` FROM `source_code_user` WHERE `solution_id`=?";
$result = pdo_query($sql, $id);
$row = $result[0];
if ($row) {
$view_source = $row['source'];
}
/////////////////////////Template
require "template/$OJ_TEMPLATE/showsource.php";
require "oj-footer.php";
/////////////////////////Common foot
if (file_exists('./include/cache_end.php')) {
require_once './include/cache_end.php';
}