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