-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_users.php
169 lines (151 loc) · 4.57 KB
/
edit_users.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
<?php require_once("includes/initialize.php"); ?>
<?php
if(!$session->is_logged_in()) {
redirect_to("index.php");
}
$id = get_id();
$sql = "SELECT
u.id,
CONCAT(u.first_name, ' ', u.last_name) AS 'full_name',
u.mail,
u.privileges,
u.date,
u.activated,
(SELECT COUNT(*) FROM news n WHERE n.username = u.username) AS 'total_news',
(SELECT COUNT(*) FROM comments c WHERE c.username = u.username) AS 'total_comments'
FROM users u
ORDER BY u.id ASC";
$users = User::find_by_sql($sql);
if($id > 0) {
$users = User::find_by_id($id);
}
if(!$users) {
$session->message("User does not exist.");
redirect_to("edit_users.php");
} elseif(isset($_GET['id']) && empty($_GET['id'])) {
$session->message("User does not exist.");
redirect_to("edit_users.php");
}
if(isset($_POST['submit'])) {
if(User::update(post_array($_POST, $id))) {
$session->message("User successfully edited");
redirect_to("edit_users.php");
} else {
$session->message("There was an error that prevented the user from being edited.");
}
}
?>
<?php require_once("includes/header.php"); ?>
<div class="cAlign">
<div id="fullWidthSection">
<h4 align="center"><?php echo output_message($message); ?></h4>
<h2 align="center">Edit Users</h2>
<?php if(!isset($_GET['id'])) { ?>
<table id="users">
<tr>
<td>Name</td>
<td>E-mail</td>
<td>Privileges</td>
<td>Registred on</td>
<td>Activated</td>
<td>News posted</td>
<td>Comments posted</td>
<td> </td>
<td> </td>
</tr>
<?php
foreach($users as $user) {
echo "<tr>";
echo "<td>{$user['full_name']}</td>";
echo "<td><a href='mailto:" . $user['mail'] . "'>{$user['mail']}</a></td>";
echo "<td>{$user['privileges']}</td>";
echo "<td>" . date_for_news($user['date']) . "</td>";
if($user['activated'] == 1) {
echo "<td>Yes</td>";
} else {
echo "<td>No</td>";
}
echo "<td>{$user['total_news']}</td>";
echo "<td>{$user['total_comments']}</td>";
echo "<td><a href='edit_users.php?id={$user['id']}'>Edit</a></td>";
echo "<td><a href='delete_users.php?id={$user['id']}'>Delete</a></td>";
echo "</tr>";
}
?>
</table>
<br>
<h4><a href="admin.php">Back</a></h4>
<?php } else { ?>
<form action="edit_users.php?id=<?php echo $id; ?>" class="contact_form" method="post">
<ul>
<li>
<h2><?php echo $users['first_name']; ?></h2>
</li>
<li>
<label for="first_name">First name:</label>
<input type="text" name="first_name" id="first_name" value="<?php echo $users['first_name']; ?>">
</li>
<li>
<label for="last_name">Last name:</label>
<input type="text" name="last_name" id="last_name" value="<?php echo $users['last_name']; ?>">
</li>
<li>
<label for="mail">Mail:</label>
<input type="text" name="mail" id="mail" value="<?php echo $users['mail']; ?>">
</li>
<li>
<label for="privileges">Privileges:</label>
<select name="privileges">
<?php
switch($users['privileges']) {
case "admin":
echo "<option value='admin' selected>Administrator</option>";
echo "<option value='moderator'>Moderator</option>";
echo "<option value='user'>User</option>";
break;
case "moderator":
echo "<option value='admin'>Administrator</option>";
echo "<option value='moderator' selected>Moderator</option>";
echo "<option value='user'>User</option>";
break;
case "user";
echo "<option value='admin'>Administrator</option>";
echo "<option value='moderator'>Moderator</option>";
echo "<option value='user' selected>User</option>";
break;
}
?>
</select>
</li>
<li>
<label for="activated">Activated:</label>
<select name="activated">
<?php
switch($users['activated']) {
case "1":
echo "<option value='1' selected>Yes</option>";
echo "<option value='0'>No</option>";
break;
case "0":
echo "<option value='1'>Yes</option>";
echo "<option value='0' selected>No</option>";
break;
}
?>
</select>
</li>
<li>
<label for="date">Date of registration:</label>
<input type="text" name="date" id="date" value="<?php echo $users['date']; ?>">
</li>
<li>
<button type="submit" name="submit" class="submit">Edit User</button>
</li>
</ul>
<h4><a href='javascript:history.back();'>Back</a></h4>
</form>
<?php } ?>
</div>
<div class="cBoth"></div>
</div>
<?php require_once("includes/footer.php"); ?>