This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogs.php
110 lines (98 loc) · 2.69 KB
/
logs.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
<?php
include 'includes/header.php';
require 'includes/config.php';
?>
<body>
<?php
if($_SESSION['status'] == "admin")
{
?>
<div class="container">
<?php
$page='logs';
include 'includes/navbar.php';
include 'includes/file-nav.php';
?>
<div class="sub-page-main">
<div class="display-menu">
<!-- Or delete just the button if no buttons on the page -->
<form method='POST'>
<button class="btn-display-menu" type='submit' name="deleteOldLogs"><i class="fas fa-trash-alt"></i> Delete logs older than 7 days</button>
</form>
</div>
<div class="scroll">
<div class="main">
<?php
$sqlGetData = "SELECT * FROM Logs ORDER BY date DESC";
$resultsData = mysqli_query($conn, $sqlGetData);
if(isset($_POST['deleteOldLogs']))
{
$sqlGetCountOfOldLogs = "SELECT * FROM Logs WHERE DATE(date) < DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
$resultsGetCountOfOldLogs = mysqli_query($conn, $sqlGetCountOfOldLogs);
$removedOldLogsCount = mysqli_num_rows($resultsGetCountOfOldLogs);
$sqlDeleteOldLogs = "DELETE FROM Logs WHERE DATE(date) < DATE_SUB(CURDATE(), INTERVAL 7 DAY)";
if(mysqli_query($conn, $sqlDeleteOldLogs))
{
echo $removedOldLogsCount." old logs were removed!<br>";
}
else
{
echo "ERROR".mysqli_error($conn);
}
}
echo "<form method='POST'>";
echo "<table>";
echo "<tr>"; //nick, status, suspension, last connected
echo "<th>Log text</th>";
echo "<th>User</th>";
echo "<th>Ip</th>";
echo "<th>Date</th>";
echo "<th>Delete</th>";
echo "</tr>";
while($row = mysqli_fetch_assoc($resultsData))
{
echo "<tr>";
echo "<td>".$row['text']."</td>";
if(strlen($row['user']) != 0)
{
echo "<td>".$row['user']."</td>";
}
else
{
echo "<td><i>UNKNOWN</i></td>";
}
echo "<td>".$row['ip']."</td>";
echo "<td>".$row['date']."</td>";
echo "<td><button class='butonas' name='delete".$row['id']."'>X</button></td>";
echo "</tr>";
if(isset($_POST['delete'.$row['id']]))
{
$rowId = $row['id'];
$sqlDeleteCurrentLog = "DELETE FROM Logs WHERE id='$rowId'";
if(mysqli_query($conn, $sqlDeleteCurrentLog))
{
echo "You have succesfully removed a log!<br>";
echo '<meta http-equiv="refresh" content="0;" />';
}
else
{
echo "KLAIDA!<br>".mysqli_error($conn);;
}
}
}
echo "</table>";
echo "</form>"; ?>
</div>
</div>
<?php
}
else
{
echo '<meta http-equiv="refresh" content="0; url=./errorAuthorization.shtml" />';
echo "You are not authorised to view this page!<br>";
}
?>
</div>
</div>
</body>
</html>