-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge.php
307 lines (272 loc) · 14.9 KB
/
challenge.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
ob_start();
session_start();
require 'connect_db.php';
if(!empty($_SESSION['id'])){
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<title>Challenge</title>
<style>
/* Set height of the grid so .sidenav can be 100% (adjust if needed) */
.row.content {
height: 1000px
}
/* Set gray background color and 100% height */
.sidenav {
background-color: #f1f1f1;
height: 100%;
}
/* Set black background color, white text and some padding */
footer {
background-color: #555;
color: white;
padding: 15px;
}
/* On small screens, set height to 'auto' for sidenav and grid */
@media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {
height: auto;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="trangchu.php">Assignment</a>
</div>
<ul class="nav navbar-nav navbar-right">
<?php
if (!empty($_SESSION['username'])) {
?>
<li style="color:white; margin-top: 5px">
<h4>Xin chào <?= $_SESSION['username'] ?></h4>
</li>
<li><a href='logout.php'><span class='glyphicon glyphicon-user'></span> Đăng xuất</a></li>
<?php
} else {
echo '<li><a href="register.php"><span class="glyphicon glyphicon-user"></span> Đăng ký</a></li>
<li><a href="index.php"><span class="glyphicon glyphicon-log-in"></span> Đăng nhập</a></li>';
}
?>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row content">
<div class="col-sm-3 sidenav" style="width:20%">
<h4>Danh Mục</h4>
<div class="list-group">
<a href="trangchu.php" class="list-group-item ">Giới Thiệu</a>
<?php if (!empty($_SESSION['id'])) { ?>
<?php if ($_SESSION['role'] == 0) { ?>
<a href="quanlysinhvien.php" class="list-group-item ">Quản lý sinh viên</a>
<?php } ?>
<a href="thongtincanhan.php" class="list-group-item">Thông tin cá nhân</a>
<a href="danhsachnguoidung.php" class="list-group-item">Danh sách người dùng</a>
<?php
if (isset($_SESSION['role']) && $_SESSION['role'] == 0) {
echo '<a href="giaobai.php" class="list-group-item">Giao bài</a>';
} else {
echo '<a href="nopbai.php" class="list-group-item">Nộp bài</a>';
}
?>
<a href="challenge.php" class="list-group-item active">Challenge</a>
<?php } ?>
</div><br>
</div>
<div class="row" >
<div class="col-sm-9" >
<?php
if (isset($_SESSION['role']) && $_SESSION['role'] == 0) {
?>
<div class="container" style="width: 800px;">
<center>
<h1>Challenge</h1>
</center>
<br>
<form action="" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>Tên challenge:</label><br>
<input type="text" class="form-control" placeholder="Nhập tên challenge" name="input_tenchallenge" required>
</div>
<div class="form-group">
<label>Gợi ý:</label><br>
<input type="text" class="form-control" placeholder="Nhập gợi ý" name="input_goiy" required>
</div>
<div class="form-group">
<label>Chọn file challenge để upload:</label>
<input type="file" name="input_filechallenge" required>
</div>
<div class="form-group">
<input type="submit" class="btn btn-success" name="click_submit_file" value="Tạo">
</div>
</form>
</div>
<?php
function stripVN($str)
{
$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
$str = preg_replace("/(đ)/", 'd', $str);
$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
$str = preg_replace("/(Đ)/", 'D', $str);
return $str;
}
if (isset($_POST['click_submit_file'])) {
if (!empty($_POST['input_tenchallenge']) && !empty($_POST['input_goiy'])) {
// var_dump($_FILES['input_filebaitap']);
//lấy tên file
$ten_filechallenge = $_FILES['input_filechallenge']['name'];
$ten_filechallenge = stripVN($ten_filechallenge);
$ten_filechallenge = trim(preg_replace("/\s+/", " ", $ten_filechallenge));
// var_dump($ten_filechallenge);
$ex = strtolower(pathinfo($ten_filechallenge, PATHINFO_EXTENSION));
if ($ex == 'txt') {
if (file_exists('./challenge/' . $ten_filechallenge)) {
echo '<script>alert("File đã tồn tại")</script>';
} else {
move_uploaded_file($_FILES['input_filechallenge']['tmp_name'], './challenge/' . $ten_filechallenge);
//luu dia chi file vao database
$conn = mysqli_connect('localhost', 'root', '', 'assignment');
$ten_challenge = mysqli_real_escape_string($conn, $_POST['input_tenchallenge']);
$ten_filechallenge = mysqli_real_escape_string($conn, $ten_filechallenge);
$goiy = mysqli_real_escape_string($conn, $_POST['input_goiy']);
$sql = "INSERT INTO challenge VALUES (null, '$ten_challenge', '$ten_filechallenge', '$goiy', " . $_SESSION['id'] . ", '')";
mysqli_query($conn, $sql);
echo '<script>alert("Upload challenge thành công")</script>';
mysqli_close($conn);
}
} else {
echo '<script>alert("Chỉ được phép upload file định dạng .txt")</script>';
}
} else {
echo '<script>alert("Không được để trống tên challenge và gợi ý")</script>';
}
}
?>
<hr>
<div class="container" style="width: 800px;">
<h3>Danh sách challenge</h3>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Tên challenge</th>
<th>Người tạo challenge</th>
<th style="text-align: center; width: 25%;">Số người hoàn thành</th>
</tr>
</thead>
<?php
$sql = 'SELECT challenge.id_challenge, challenge.ten_challenge, challenge.ten_filechallenge, challenge.id_giaovien, challenge.id_hocsinh, user.hoten FROM challenge INNER JOIN user ON challenge.id_giaovien = user.id';
$result = GetData($sql);
while ($row = mysqli_fetch_assoc($result)) {
?>
<tbody>
<td><?= $row['id_challenge'] ?></td>
<td><?= $row['ten_challenge'] ?></td>
<td><?= $row['hoten'] ?></td>
<td style="text-align: center;">
<?php
$str = $row['id_hocsinh'];
if ($str == '') {
echo 0;
} else {
$arr = explode(',', $str);
echo count($arr) - 1;
}
?>
</td>
</tbody>
<?php
}
?>
</table>
</div>
<?php
} else {
?>
<div class="container" style="width: 800px;">
<center>
<h1>Danh sách challenge</h1>
</center>
<br>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Tên challenge</th>
<th>Người tạo challenge</th>
<th style="text-align: center; width: 20px;">Trạng thái</th>
<th style="text-align: center; width: 70px;">Chi tiết</th>
</tr>
</thead>
<?php
$sql = 'SELECT challenge.id_challenge, challenge.ten_challenge, challenge.ten_filechallenge, challenge.goiy, challenge.id_giaovien, challenge.id_hocsinh, user.hoten FROM challenge INNER JOIN user ON challenge.id_giaovien = user.id';
$result = GetData($sql);
while ($row = mysqli_fetch_assoc($result)) {
?>
<tbody>
<td><?= $row['id_challenge'] ?></td>
<td><?= $row['ten_challenge'] ?></td>
<td><?= $row['hoten'] ?></td>
<td>
<?php
//xử lý kiểm tra học sinh đã nộp bài tập này hay chưa
$hocsinhhoanthanh = $row['id_hocsinh'];
$hocsinhhoanthanh = explode(',', $hocsinhhoanthanh);
if (isset($_SESSION['id']) && in_array($_SESSION['id'], $hocsinhhoanthanh)) {
echo '<button type="button" class="btn btn-success">Hoàn thành</button>';
} else {
echo '<button type="button" class="btn btn-danger">Chưa làm</button>';
}
?>
</td>
<td style="text-align: center;"><a href="giaichallenge.php?id_challenge=<?= $row['id_challenge'] ?>">Giải</a></td>
</tbody>
<?php
}
?>
</table>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>
<?php
?>
</div>
</div>
</body>
</html>
<?php
}else{
header("Location: trangchu.php");
}
?>