]>
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 | { | |
55 | Message::Success("Successfully created user \"" . $user['user_name'] . "\""); | |
56 | } | |
57 | else | |
58 | { | |
59 | Message::Fail("Failed to create user \"" . $user['user_name'] . "\""); | |
60 | } | |
61 | } | |
62 | } | |
180b8ec1 VP |
63 | $userlist = []; |
64 | Hook::run(HOOKTYPE_GET_USER_LIST, $userlist); | |
65 | ||
66 | ?> | |
180b8ec1 VP |
67 | Click on a username to view more information. |
68 | <br><br> | |
69 | <div id="Users"> | |
70 | <div class="row"> | |
71 | <?php if (current_user_can(PERMISSION_MANAGE_USERS)) { ?> | |
72 | <div class="col-sm-3"> | |
73 | <form method="post"> | |
74 | <div class="btn btn-primary" data-toggle="modal" data-target="#myModal">Add New User</div> | |
75 | <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">Delete selected</button> | |
76 | </div> | |
77 | <?php } ?> | |
78 | </div> | |
79 | <br> | |
80 | </table> | |
81 | <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> | |
82 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
83 | <div class="modal-content"> | |
84 | <div class="modal-header"> | |
85 | <h5 class="modal-title" id="myModalLabel">Add new Admin Panel user</h5> | |
86 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
87 | <span aria-hidden="true">×</span></button> | |
88 | </div> | |
89 | <div class="modal-body"> | |
90 | <div class="input-group mb-3"> | |
91 | <label for="name_add" name="user_add" id="user_add">Username | |
92 | <input style="width: 170%;" name="user_add" id="user_add" class="form-control curvy" type="text"></label> | |
93 | </div> | |
94 | <div class="input-group mb-3"> | |
95 | <label for="password" id="user_add">Password | |
96 | <input style="width: 170%;" name="password" id="password" class="form-control curvy" type="password"></label> | |
97 | </div> | |
9a674833 VP |
98 | <div class="input-group mb-3"> |
99 | <label for="user_email" id="user_add">Email | |
100 | <input style="width: 170%;" name="user_email" id="user_email" class="form-control curvy" type="text"></label> | |
101 | </div> | |
180b8ec1 VP |
102 | <div class="input-group mb-3"> |
103 | <label for="add_first_name" id="user_add">First Name | |
104 | <input style="width: 170%;" name="add_first_name" id="add_first_name" class="form-control curvy" type="text"></label> | |
9a674833 VP |
105 | </div> |
106 | <div class="input-group mb-3"> | |
180b8ec1 VP |
107 | <label for="password" id="user_add">Last Name |
108 | <input style="width: 170%;" name="add_last_name" id="add_last_name" class="form-control curvy" type="text"></label> | |
109 | </div> | |
110 | <div class="input-group mb-3"> | |
111 | <label for="password" id="user_add">Info /Bio | |
112 | <textarea style="width: 170%;" name="user_bio" class="form-control curvy" aria-label="With textarea"></textarea></label> | |
113 | </div> | |
114 | </div> | |
115 | ||
116 | <div class="modal-footer"> | |
117 | <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | |
118 | <button type="submit" name="do_add_user" class="btn btn-danger">Add User</button> | |
119 | ||
120 | </div> | |
121 | </div> | |
122 | </div> | |
123 | </div> | |
124 | </div> | |
125 | ||
126 | </form> | |
127 | <table class="container-xxl table table-sm table-responsive caption-top table-striped"> | |
128 | <thead class="table-primary"> | |
129 | <form method="post"> | |
130 | <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th> | |
131 | <th scope="col">Username</th> | |
132 | <th scope="col">First Name</th> | |
133 | <th scope="col">Last Name</th> | |
9a674833 | 134 | <th scope="col">Email</th> |
180b8ec1 VP |
135 | <th scope="col">Created</th> |
136 | <th scope="col">Bio</th> | |
137 | <th scope="col">Last login</th> | |
138 | ||
139 | </thead> | |
140 | <tbody> | |
141 | <?php | |
142 | foreach($userlist as $user) | |
143 | { | |
144 | ||
145 | echo "<td scope=\"col\"><input type=\"checkbox\" value='" .$user->id . "' name=\"userch[]\"></td>"; | |
ea90b321 | 146 | echo "<td scope=\"col\"><a href=\"".get_config("base_url")."settings/user-edit.php?id=$user->id\">$user->username</a></td>"; |
180b8ec1 VP |
147 | echo "<td scope=\"col\">".$user->first_name."</td>"; |
148 | echo "<td scope=\"col\">".$user->last_name."</td>"; | |
9a674833 | 149 | echo "<td scope=\"col\"><a href=\"mailto:$user->email\">$user->email</a></td>"; |
2d62c85d | 150 | echo "<td scope=\"col\"><code>".$user->created."</code></td>"; |
180b8ec1 | 151 | echo "<td scope=\"col\">".$user->bio."</td>"; |
2d62c85d VP |
152 | $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"; |
153 | echo "<td scope=\"col\">$last</td>"; | |
e9996356 | 154 | echo "</tr>\n"; |
180b8ec1 | 155 | } |
e9996356 VP |
156 | ?></tbody></table> |
157 | <?php if (current_user_can(PERMISSION_MANAGE_USERS)) { ?> | |
158 | <p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2"> | |
180b8ec1 VP |
159 | Delete selected |
160 | </button></p> | |
e9996356 | 161 | <?php } ?> |
180b8ec1 VP |
162 | <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true"> |
163 | <div class="modal-dialog modal-dialog-centered" role="document"> | |
164 | <div class="modal-content"> | |
165 | <div class="modal-header"> | |
166 | <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5> | |
167 | <button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
168 | <span aria-hidden="true">×</span> | |
169 | </button> | |
170 | </div> | |
171 | <div class="modal-body"> | |
172 | Are you sure you want to do this?<br> | |
173 | This cannot be undone. | |
174 | </div> | |
175 | <div class="modal-footer"> | |
176 | <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> | |
177 | <button type="submit" action="post" name="delete_user" class="btn btn-danger">Delete</button> | |
178 | ||
179 | </div> | |
180 | </div> | |
181 | </div> | |
182 | </div></form></div></div><br></div> | |
183 | <?php | |
c06c1713 | 184 | require_once '../inc/footer.php'; ?> |