-
Notifications
You must be signed in to change notification settings - Fork 0
/
team.php
265 lines (249 loc) · 12.5 KB
/
team.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
// Include the init file
include "functions/init.php";
// Redirect if not logged in
if (!logged_in()) {
header("Location:login");
}
// Include the functions file
include "functions/pages/team.php";
if($role != 0) {
redirect($url);
die();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="shortcut icon" href="<?= $url ?>/assets/images/logo.png" type="image/png">
<title>Team | Campfire</title>
<?php include 'includes/styles.php'; ?>
</head>
<body>
<div class="page">
<div class="page-main">
<?php include "includes/header.php" ?>
<div class="my-3 my-md-5">
<div class="container">
<div class="page-header">
<h1 class="page-title">
<i class="fe fe-users mr-2"></i> Team Members
</h1>
</div>
<div class="row">
<div class="col-lg-4">
<div class="card">
<div class="card-header">
<h4 class="card-title"><i class="fe fe-plus mr-2"></i> Add Member</h4>
</div>
<div class="card-body pt-1">
<form method="post">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>First Name</label>
<input type="text"
class="form-control" name="first_name" value="" required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label>Last Name</label>
<input type="text"
class="form-control" name="last_name" value="" required>
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label>Email address</label>
<input type="email"
class="form-control" name="email" value="" required>
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label>Password</label>
<input type="password"
class="form-control" name="password" value="" required>
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label>Role</label>
<select class="form-control mb-2" name="role"
required>
<option value="1">Administrator</option>
<option value="2">Editor</option>
</select>
</div>
</div>
</div>
<button type="submit" class="btn bg-camp w-100" name="create"
value="1"
onclick="$(this).addClass('disabled').addClass('btn-loading');">
Create user
</button>
</form>
</div>
</div>
</div>
<div class="col-lg-8">
<?php
if (isset($error)) {
echo '<div class="alert alert-danger">' . $error . '</div>';
} elseif (isset($success)) {
echo '<div class="alert alert-success">' . $success . '</div>';
}
?>
<?php
$sql = "SELECT id, first_name, last_name, CONCAT(first_name, ' ', last_name) name, email, role, owner FROM users ORDER BY owner DESC, first_name ASC, last_name ASC";
$result = $conn->query($sql);
?>
<div class="card">
<div class="card-header">
<h4 class="card-title">Active Members (<?= $result->num_rows ?>)</h4>
</div>
<div class="card-body pt-1">
<div class="row">
<?php
while ($row = $result->fetch_assoc()) { ?>
<div class="col-12">
<div class="card mb-3">
<div class="card-body">
<div class="d-flex justify-content-between">
<div class="d-flex">
<img class="avatar avatar-lg mr-4"
src="<?= 'https://www.gravatar.com/avatar/' . md5($row["email"]) . '?d=mp' ?>" alt="">
<div>
<p class="mb-0">
<span class="font-weight-bold mb-0"><?= $row["name"] ?></span>
<?= $row['id'] == $user_id ? '(You)' : '' ?>
</p>
<p class="mb-0">
<?php
if($row['role'] == 0 && $row['owner'] == 1) {
echo '<span class="badge badge-warning text-dark"><i class="fe fe-star mr-1"></i> Owner</span>';
} elseif($row['role'] == 0) {
echo '<span class="badge badge-success">Administrator</span>';
} elseif($row['role'] == 1) {
echo '<span class="badge badge-secondary">Editor</span>';
}
?>
</p>
</div>
</div>
<div>
<a href="#" class="btn btn-secondary btn-sm mr-1" data-toggle="modal" data-target="#editUserModal-<?= $row["id"] ?>">
<i class="fe fe-edit-2 mr-1"></i>
Edit
</a>
<?php if ($row['owner'] != 1 || $row['id'] != $user_id) { ?>
<a href="#" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#deleteUserModal-<?= $row["id"] ?>">
<i class="fe fe-trash mr-1"></i>
Delete
</a>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="editUserModal-<?= $row["id"] ?>">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit user</h5>
<button type="button" class="close" data-dismiss="modal">
</button>
</div>
<div class="modal-body">
<form method="post">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label for="editFirstName">First Name</label>
<input type="text" class="form-control"
name="first_name" id="editFirstName" value="<?= $row['first_name'] ?>"
required>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="editLastName">Last Name</label>
<input type="text" class="form-control"
name="last_name" id="editLastName" value="<?= $row['last_name'] ?>"
required>
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label for="editEmail">Email address</label>
<input type="email" class="form-control"
name="email" id="editEmail" value="<?= $row['email'] ?>"
required>
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label for="editPassword">Password</label>
<input type="password" class="form-control"
name="password" id="editPassword">
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label for="editRole">Role</label>
<select class="form-control mb-2" name="role" id="editRole" required>
<option value="0" <?= $row['role'] == 0 ? 'selected' : '' ?>>Administrator</option>
<option value="1" <?= $row['role'] == 1 ? 'selected' : '' ?>>Editor</option>
</select>
</div>
</div>
</div>
<input type="hidden" name="user_id" value="<?= $row['id'] ?>">
<button type="submit" class="btn bg-camp w-100" name="editUser"
value="1"
onclick="$(this).addClass('disabled').addClass('btn-loading');">
Save changes
</button>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="deleteUserModal-<?= $row["id"] ?>">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete user</h5>
<button type="button" class="close" data-dismiss="modal">
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this user? They will lose all access to Campfire and won't be able to contribute.</p>
<form method="post">
<input type="hidden" name="user_id" value="<?= $row['id'] ?>">
<button type="submit" class="btn bg-camp w-100" name="deleteUser" value="1" onclick="$(this).addClass('disabled').addClass('btn-loading');">
Confirm
</button>
</form>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include "includes/footer.php" ?>
</div>
</body>
</html>