-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
150 lines (141 loc) · 5.81 KB
/
Copy pathadmin.php
File metadata and controls
150 lines (141 loc) · 5.81 KB
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
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Panel Administratora</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous" />
<script defer src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" />
</head>
<body>
<?php
include 'chklgn.php';
if (!isset($logedin)) {
exit();
}
?>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="admin.php">Panel Administratora</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="logout.php">Wyloguj</a>
</li>
<li class="nav-item">
<a class="nav-link" href="index.php">Strona Główna</a>
</li>
</ul>
<form class="d-flex" action="admin.php" method="GET">
<?php
$szukane = "";
if (isset($_GET['q'])) {
$szukane = $_GET['q'];
}
?>
<input class="form-control me-2" type="search" name="q" value="<?php echo $szukane; ?>" placeholder="Wyszukaj" />
<button class="btn btn-outline-success" type="submit">
Szukaj
</button>
</form>
</div>
</div>
</nav>
<div class="container">
<form action="create.php" style="margin-top: 20px;">
<button type="submit" class="btn btn-dark">Utwórz nowy post</button>
</form>
<?php
if (isset($_GET['q'])) {
$szukane = $_GET['q'];
$liczba = mysqli_query($conn, "SELECT COUNT(id) AS liczba FROM post WHERE title LIKE '%$szukane%' OR tags LIKE '%$szukane%' ORDER BY id DESC");
} else {
$liczba = mysqli_query($conn, "SELECT COUNT(id) AS liczba FROM post ORDER BY id DESC");
}
$liczba = mysqli_fetch_assoc($liczba);
$liczba = $liczba['liczba'];
$mostCommon = mysqli_query($conn, "SELECT creator, COUNT(creator) AS num FROM post GROUP BY creator ORDER BY num DESC LIMIT 1");
$mostCommon = mysqli_fetch_assoc($mostCommon);
$mostCreator = $mostCommon['creator'];
$sql = "SELECT login FROM users WHERE ID=$mostCreator";
$mostCreator = mysqli_query($conn, $sql);
$mostCreator = mysqli_fetch_assoc($mostCreator);
$mostCreator = $mostCreator['login'];
$mostNum = $mostCommon['num'];
?>
<h4 style="margin-top: 10px;">Liczba postów: <?php echo $liczba; ?></h4>
<h4 style="margin-top: 10px;">Najbardziej aktywny autor: <?php echo $mostCreator . " (" . $mostNum . ")"; ?></h4>
<table class="table table-dark table-striped mt-4 table-hover">
<thead>
<tr>
<th scope="col" class="status">Status</th>
<th scope="col" class="title">Tytuł</th>
<th scope="col" class="slug">Slogan</th>
<th scope="col" class="content">Zawartosć</th>
<th scope="col" class="category">Kategoria</th>
<th scope="col" class="tags">Tagi</th>
<th scope="col" class="actions">Akcje</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_GET['q'])) {
$szukane = $_GET['q'];
$posts = mysqli_query($conn, "SELECT * FROM post WHERE title LIKE '%$szukane%' OR tags LIKE '%$szukane%' ORDER BY id DESC");
} else {
$posts = mysqli_query($conn, "SELECT * FROM post ORDER BY id DESC");
}
while ($row = mysqli_fetch_assoc($posts)) {
$id = $row['id'];
$status = $row['status'];
if ($status == 0) {
$status = "SZKIC";
} else if ($status == 1) {
$status = "OPUBLIKOWANY";
}
$title = $row['title'];
$slug = $row['slug'];
$content = $row['content'];
if (strlen($content) > 100) {
$content = substr($content, 0, 100);
$content = $content . "[..]";
}
$category = $row['category'];
$categories = mysqli_query($conn, "SELECT nazwa FROM categories WHERE id='$category'");
$categories = mysqli_fetch_assoc($categories);
$category = $categories['nazwa'];
$tags = $row['tags'];
//$creator = $row['creator'];
//$data = $row['data'];
echo "
<tr>
<td class='status'>$status</td>
<td class='title'>$title</td>
<td class='slug'>$slug</td>
<td class='content'>$content</td>
<td class='category'>$category</td>
<td class='tags'>$tags</td>
<td class='actions' style='white-space: nowrap; width: 1%'>
<a class='btn btn-success' href='edit.php?id=$id' role='button'
><i class='bi bi-pencil'></i
></a>
<a class='btn btn-primary' href='view.php?p=$id' role='button'
><i class='bi bi-search'></i
></a>
<a class='btn btn-danger' href='delete.php?id=$id' role='button'
><i class='bi bi-x-lg'></i
></a>
</td>
</tr>
";
}
?>
</tbody>
</table>
</div>
</body>
</html>