-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-blackListUsers.php
More file actions
100 lines (95 loc) · 2.72 KB
/
Copy pathadmin-blackListUsers.php
File metadata and controls
100 lines (95 loc) · 2.72 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
<?php
require_once "user.php";
CheckIfAdminLoggedIn();
function toggleBlocklist(){
require 'db.php';
try{
$db->beginTransaction();
$db->query('LOCK TABLES users WRITE');
// Update blacklist value
$sql = 'UPDATE users set blacklisted=:blacklisted where id=:id';
$sth = $db->prepare ($sql);
// Was the user before blacklisted
if(intval($_POST['old'])==0)
$sth->bindValue (':blacklisted', 1);
else
$sth->bindValue (':blacklisted', 0);
$sth->bindValue (':id', $_POST['userID']);
$affected_rows = $sth->execute();
if($affected_rows != 1){
// Should only change for one user at the time
$db->rollBack();
$db->query('UNLOCK TABLES');
throw new Exception('Unable to update information');
}
}catch (Exception $e){
$db->rollBack();
$db->query('UNLOCK TABLES');
throw new Exception('Unable to update information, Email duplicate');
}
$db->commit();
echo "<t1>Users blacklisting changed</t1></br>";
}
function findUser(){
require 'db.php';
if (isset ($_POST['search'])) {
try{
$sql = 'select * from users where email=:search OR id=:search OR name=:search';
$sth = $db->prepare($sql);
$sth->bindValue(':search', $_POST['search']);
$sth->execute();
$sth->setFetchMode(PDO::FETCH_ASSOC);
while($row = $sth->fetch()){
echo "<div id=user>";
echo "<t2>Name: ".$row['name']."</t2></br>";
if(intval($row['blacklisted'])==0)
echo "NOT blacklisted</br>";
else
echo "Blacklisted!!</br>";
echo "<t2>".$row['email']."</t2></br>";
echo "<t3>Address: ".$row['streetAddress']."</t3></br>";
echo "<t3>".$row['postCode']."</t3></br>";
echo "<t3>".$row['country']."</t3></br>";
echo'<form method="post" action="admin-blackListUsers.php">';
echo "<input type=\"hidden\" name=\"userID\" value=".$row['id']."/>";
echo "<input type=\"hidden\" name=\"old\" value=".$row['blacklisted']."/>";
echo '<input type="submit" value="Blacklist/Unblacklist"/>';
echo "</div>";
}
}catch(Exception $e){
echo $e->getMessage();
}
}
}
?>
<?php
include 'Geeksforsaletop.php';
?>
<div id="content">
<?php include 'admin-buttons.php'; ?>
<?php
require 'db.php';
if (isset ($_POST['userID'])) {
try{
toggleBlocklist();
}catch(Exception $e){
echo $e->getMessage();
}
}
if (isset ($_POST['search'])) {
try {
findUser();
}catch (Exception $e){
echo $e->getMessage();
echo "Something went wrong. Codemonkeys on it";
}
}
?>
<t2> Search for a user using email,name or ID</t2>
<form class="form-wrapper cf" method="post" action="admin-blackListUsers.php">
<input type="text" name="search" placeholder="Search here after email,ID">
<button type="submit">Search</button>
</form>
</div>
</BODY>
</HTML>