]>
Commit | Line | Data |
---|---|---|
180b8ec1 VP |
1 | <?php |
2 | $conn = NULL; | |
3 | ||
c06c1713 BM |
4 | require_once "../inc/common.php"; |
5 | require_once "../inc/header.php"; | |
180b8ec1 VP |
6 | do_log($_POST); |
7 | ||
8 | ||
9 | ||
10 | ||
11 | ?> | |
6210ec48 | 12 | <h4>Panel Accounts</h4> |
180b8ec1 VP |
13 | |
14 | <?php | |
15 | ||
16 | if (isset($_POST)) | |
17 | { | |
18 | $p = $_POST; | |
19 | if (isset($p['delete_user']) && current_user_can(PERMISSION_MANAGE_USERS)) | |
20 | { | |
21 | $info = []; | |
22 | foreach ($p['userch'] as $id) | |
23 | { | |
24 | $user = new PanelUser(NULL, $id); | |
25 | $us = unreal_get_current_user(); | |
26 | $deleted = delete_user($id, $info); | |
27 | if ($us->id == $user->id) // if it's the current user | |
28 | { | |
29 | session_destroy(); | |
ce25dde2 | 30 | header("Location: " . get_config("base_url") . "plugins/sql_db/login.php"); |
180b8ec1 VP |
31 | die(); |
32 | } | |
33 | $msg = ($deleted = 1) ? "Message::Success" : "Message::Fail"; | |
34 | } | |
35 | $msg($info); | |
36 | unset($info); | |
37 | } | |
38 | ||
39 | if (isset($p['do_add_user']) && current_user_can(PERMISSION_MANAGE_USERS)) | |
40 | { | |
41 | $user = []; | |
42 | $user['user_name'] = $p['user_add']; | |
43 | $user['user_pass'] = $p['password']; | |
44 | $user['fname'] = $p['add_first_name']; | |
45 | $user['lname'] = $p['add_last_name']; | |
9a674833 | 46 | $user['user_email'] = $p['user_email']; |
180b8ec1 VP |
47 | $user['user_bio'] = $p['user_bio']; |
48 | $user['err'] = ""; | |
49 | if (!create_new_user($user)) | |
50 | { | |
51 | Message::Fail("Failed to create user: " . $user['user_name'] . " " . $user['err']); | |
52 | } | |
53 | else if (($usr_obj = new PanelUser($user['user_name'])) && isset($usr_obj->id)) | |
54 | { | |
6f0e7ce4 | 55 | $usr_obj->add_meta("role", $p['user_role']); |
180b8ec1 VP |
56 | Message::Success("Successfully created user \"" . $user['user_name'] . "\""); |
57 | } | |
58 | else | |
59 | { | |
60 | Message::Fail("Failed to create user \"" . $user['user_name'] . "\""); | |
61 | } | |
62 | } | |
63 | } | |
180b8ec1 VP |
64 | $userlist = []; |
65 | Hook::run(HOOKTYPE_GET_USER_LIST, $userlist); | |
66 | ||
67 | ?> | |
180b8ec1 VP |
68 | Click on a username to view more information. |
69 | <br><br> | |
70 | <div id="Users"> | |
71 | <div class="row"> | |
72 | <?php if (current_user_can(PERMISSION_MANAGE_USERS)) { ?> | |
73 | <div class="col-sm-3"> | |
74 | <form method="post"> | |
75 | <div class="btn btn-primary" data-toggle="modal" data-target="#myModal">Add New User</div> | |
76 | <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">Delete selected</button> | |
77 | </div> | |
78 | <?php } ?> | |
79 | </div> | |
80 | <br> | |
81 | </table> | |
82 | <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> | |
83 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
84 | <div class="modal-content"> | |
85 | <div class="modal-header"> | |
86 | <h5 class="modal-title" id="myModalLabel">Add new Admin Panel user</h5> | |
87 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
88 | <span aria-hidden="true">×</span></button> | |
89 | </div> | |
90 | <div class="modal-body"> | |
91 | <div class="input-group mb-3"> | |
92 | <label for="name_add" name="user_add" id="user_add">Username | |
d0bec005 | 93 | <input name="user_add" id="user_add" class="form-control curvy" type="text"></label> |
180b8ec1 VP |
94 | </div> |
95 | <div class="input-group mb-3"> | |
96 | <label for="password" id="user_add">Password | |
d0bec005 | 97 | <input name="password" id="password" class="form-control curvy" type="password"></label> |
180b8ec1 | 98 | </div> |
6f0e7ce4 VP |
99 | <div class="input-group mb-3"> |
100 | <label for="user_role" id="user_add">Role | |
101 | <select name="user_role" class="custom-select form-control" id="user_role" style="width:170%"> | |
102 | <?php | |
103 | foreach(get_panel_user_roles_list() as $s => $l) | |
104 | echo "<option value=\"$s\">$s</option>"; | |
105 | ?> | |
106 | </select> | |
107 | </div> | |
9a674833 VP |
108 | <div class="input-group mb-3"> |
109 | <label for="user_email" id="user_add">Email | |
d0bec005 | 110 | <input name="user_email" id="user_email" class="form-control curvy" type="text"></label> |
9a674833 | 111 | </div> |
180b8ec1 VP |
112 | <div class="input-group mb-3"> |
113 | <label for="add_first_name" id="user_add">First Name | |
d0bec005 | 114 | <input name="add_first_name" id="add_first_name" class="form-control curvy" type="text"></label> |
9a674833 VP |
115 | </div> |
116 | <div class="input-group mb-3"> | |
180b8ec1 | 117 | <label for="password" id="user_add">Last Name |
d0bec005 | 118 | <input name="add_last_name" id="add_last_name" class="form-control curvy" type="text"></label> |
180b8ec1 VP |
119 | </div> |
120 | <div class="input-group mb-3"> | |
121 | <label for="password" id="user_add">Info /Bio | |
d0bec005 | 122 | <textarea name="user_bio" class="form-control curvy" aria-label="With textarea"></textarea></label> |
180b8ec1 VP |
123 | </div> |
124 | </div> | |
125 | ||
126 | <div class="modal-footer"> | |
127 | <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | |
128 | <button type="submit" name="do_add_user" class="btn btn-danger">Add User</button> | |
129 | ||
130 | </div> | |
131 | </div> | |
132 | </div> | |
133 | </div> | |
134 | </div> | |
135 | ||
136 | </form> | |
137 | <table class="container-xxl table table-sm table-responsive caption-top table-striped"> | |
138 | <thead class="table-primary"> | |
139 | <form method="post"> | |
140 | <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th> | |
141 | <th scope="col">Username</th> | |
6f0e7ce4 | 142 | <th scope="col">Role</th> |
180b8ec1 VP |
143 | <th scope="col">First Name</th> |
144 | <th scope="col">Last Name</th> | |
9a674833 | 145 | <th scope="col">Email</th> |
180b8ec1 VP |
146 | <th scope="col">Created</th> |
147 | <th scope="col">Bio</th> | |
148 | <th scope="col">Last login</th> | |
149 | ||
150 | </thead> | |
151 | <tbody> | |
152 | <?php | |
153 | foreach($userlist as $user) | |
154 | { | |
155 | ||
156 | echo "<td scope=\"col\"><input type=\"checkbox\" value='" .$user->id . "' name=\"userch[]\"></td>"; | |
ea90b321 | 157 | echo "<td scope=\"col\"><a href=\"".get_config("base_url")."settings/user-edit.php?id=$user->id\">$user->username</a></td>"; |
6f0e7ce4 | 158 | echo "<td scope=\"col\"><code>".((isset($user->user_meta['role'])) ? $user->user_meta['role'] : "")."</code></td>"; |
180b8ec1 VP |
159 | echo "<td scope=\"col\">".$user->first_name."</td>"; |
160 | echo "<td scope=\"col\">".$user->last_name."</td>"; | |
9a674833 | 161 | echo "<td scope=\"col\"><a href=\"mailto:$user->email\">$user->email</a></td>"; |
2d62c85d | 162 | echo "<td scope=\"col\"><code>".$user->created."</code></td>"; |
180b8ec1 | 163 | echo "<td scope=\"col\">".$user->bio."</td>"; |
2d62c85d VP |
164 | $last = (isset($user->user_meta['last_login'])) ? "<code>".$user->user_meta['last_login'] . "</code> <span class=\"badge rounded-pill badge-dark\">".how_long_ago($user->user_meta['last_login'])."</span>" : "none"; |
165 | echo "<td scope=\"col\">$last</td>"; | |
e9996356 | 166 | echo "</tr>\n"; |
180b8ec1 | 167 | } |
e9996356 VP |
168 | ?></tbody></table> |
169 | <?php if (current_user_can(PERMISSION_MANAGE_USERS)) { ?> | |
170 | <p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2"> | |
180b8ec1 VP |
171 | Delete selected |
172 | </button></p> | |
e9996356 | 173 | <?php } ?> |
180b8ec1 VP |
174 | <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> |
175 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
176 | <div class="modal-content"> | |
177 | <div class="modal-header"> | |
178 | <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5> | |
179 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
180 | <span aria-hidden="true">×</span> | |
181 | </button> | |
182 | </div> | |
183 | <div class="modal-body"> | |
184 | Are you sure you want to do this?<br> | |
185 | This cannot be undone. | |
186 | </div> | |
187 | <div class="modal-footer"> | |
188 | <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | |
189 | <button type="submit" action="post" name="delete_user" class="btn btn-danger">Delete</button> | |
190 | ||
191 | </div> | |
192 | </div> | |
193 | </div> | |
194 | </div></form></div></div><br></div> | |
195 | <?php | |
c06c1713 | 196 | require_once '../inc/footer.php'; ?> |