-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
121 lines (115 loc) · 5.51 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php include "includes/head.php"; ?>
<?php
$error = 0;
$row = [];
$table = "admins";
if(isset($_GET['id']) && !empty($_GET['id'])){
$id = trim($_GET['id']);
$getData = $conn->prepare("SELECT * FROM `${table}` WHERE id = ?");
$getData->execute([$id]);
if($getData->rowCount() > 0){
$row = $getData->fetch(PDO::FETCH_OBJ);
}
}
else{
$error = 1;
}
if($error == 1 && empty($row)){
echo '<h3>Access Forbidden</h3>';
}
else{
if(isset($_POST['submit'])){
$firstname = ($_POST['firstname']);
$lastname = ($_POST['lastname']);
$email = ($_POST['email']);
$support_email = ($_POST['support_email']);
$password = (empty($_POST['password']) ? password_hash($_POST['password'], PASSWORD_DEFAULT) : $row->password);
$phone = ($_POST['phone']);
$role = ($_POST['role']);
$editData = $conn->prepare("UPDATE `${table}` SET firstname=?, lastname=?, email=?, support_email=?, password=?, phone=?, role=? WHERE id=?");
$editData->execute([
$firstname, $lastname, $email, $support_email, $password, $phone, $role, $id
]);
if($editData->rowCount() > 0){
echo "<div class='alert alert-success'>Updated.</div>";
}
if($editData->rowCount() == 0){
echo "<div class='alert alert-danger'>Failed.</div>";
}
}
if(isset($_GET['delete'])){
$id = $_GET['id'];
$delete = $_GET['delete'];
if($id != '' && $delete == 'yes'){
$deleteData = $conn->prepare("DELETE FROM `${table}` WHERE id = ?");
$deleteData->execute([
$id
]);
if($deleteData->rowCount() > 0){
echo "<div class='alert alert-success'>Deleted.</div>";
echo "<script>
setTimeout(() => {
window.location.assign('admins.php')
}, 1000)
</script>";
}
if($deleteData->rowCount() == 0){
echo "<div class='alert alert-danger'>Failed.</div>";
}
}
}
}
?>
<!-- Start info box -->
<div class="row mt-5" style="margin: 0 auto;display:flex; justify-content:center; align-items:center;">
<div class="col-lg-4 col-md-6">
<div class="widget">
<div class="widget-content" style="padding:10px;">
<h3>Edit Admin</h3><hr>
<form method="POST">
<div class="form-group">
<label>Firstname</label>
<input value="<?php echo $row->firstname; ?>" type="text" name="firstname" class="form-control"/>
</div>
<div class="form-group">
<label>Lastname</label>
<input value="<?php echo $row->lastname; ?>" type="text" name="lastname" class="form-control"/>
</div>
<div class="form-group">
<label>Username</label>
<input value="<?php echo $row->username; ?>" readonly type="text" required name="username" class="form-control"/>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control"/>
</div>
<div class="form-group">
<label>Email</label>
<input value="<?php echo $row->email; ?>" type="email" name="email" class="form-control"/>
</div>
<div class="form-group">
<label>Phone No.</label>
<input value="<?php echo $row->phone; ?>" type="text" name="phone" class="form-control"/>
</div>
<div class="form-group">
<label>Role</label>
<select name="role" class="form-control">
<option <?php if($row->role == "admin"){ echo 'selected'; } ?> value="admin">admin</option>
<option <?php if($row->role == "moderator"){ echo 'selected'; } ?> value="moderator">moderator</option>
</select>
</div>
<div class="form-group">
<label>Support Email</label>
<input value="<?php echo $row->support_email; ?>" type="email" name="support_email" class="form-control"/>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-md btn-success">Edit </button>
<a href="admin?id=<?php echo $id; ?>&delete=yes" class="ml-4 btn btn-md btn-danger">Delete</a>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- End of info box -->
<?php include "includes/foot.php"; ?>