-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
105 lines (98 loc) · 2.52 KB
/
admin.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
<?php
session_start();
if (empty($_SESSION['user_id'])) {
header('Location:./login.php');
exit;
}
require_once(realpath(dirname(__FILE__)) . '/lib/db.php');
require_once(realpath(dirname(__FILE__)) . '/lib/user.php');
require_once(realpath(dirname(__FILE__)) . '/lib/order.php');
$connection = create_db_connection();
?>
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') : ?>
<?php
if (isset($_POST['status']) && $_POST['id']) {
try {
update_order($connection, $_POST['id'], $_POST['status']);
header('Location:./admin.php');
exit;
} catch (PDOException $e) {
exit("Error: " . $e->getMessage());
}
}
?>
<?php else : ?>
<?php
if (empty($_SESSION['is_admin'])) {
header('Location:./login.php');
exit;
}
try {
$user = get_user($connection, $_SESSION['user_id']);
if (!$user) {
header('Location:./logout.php');
exit;
}
} catch (PDOException $e) {
header('Location:./logout.php');
exit;
}
$orders = get_all_orders($connection)
?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Админ панель</title>
<link rel="stylesheet" href="./static/css/style.css">
</head>
<body>
<?php include("blocks/header.php"); ?>
<main class="orders">
<div class="orders__container">
<h2>Все заявления</h2>
<form action="admin.php" method="POST">
<table>
<thead>
<tr>
<th>№</th>
<th>Номер машины</th>
<th>Описание</th>
<th>Статус</th>
<th>ФИО</th>
</tr>
</thead>
<tbody>
<?php
if (empty($orders)) {
return;
}
foreach ($orders as $item) {
echo "<tr>";
echo "<td>" . $item['id'] . "</td>";
echo "<td>" . $item['car_number'] . "</td>";
echo " <td>" . $item['description'] . "</td>";
if ($item['status'] === '0') {
echo "<td><select onchange='this.form.submit()' name='status'>
<option value='0'>Новый</option>
<option value='1'>Подтвержденный</option>
<option value='2'>Отклоненный</option>
</select></td>";
echo '<input type="text" hidden name="id" value="' . $item['id'] . '">';
} elseif ($item['status'] === '1') {
echo "<td>Подтверждено</td>";
} elseif ($item['status'] === '2') {
echo "<td>Отклонено</td>";
}
echo " <td>" . $item['fio'] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
</form>
</div>
</main>
</body>
</html>
<?php endif; ?>