]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - settings/index.php
Rename "Panel Access" menu item to "Accounts"
[irc/unrealircd/unrealircd-webpanel.git] / settings / index.php
CommitLineData
180b8ec1
VP
1<?php
2$conn = NULL;
3
4require_once "../common.php";
5require_once "../header.php";
6do_log($_POST);
7
8
9
10
11?>
6210ec48 12<h4>Panel Accounts</h4>
180b8ec1
VP
13
14<?php
15
16if (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();
ea90b321 30 header("Location: " . get_config("base_url") . "plugins/sql_auth/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}
63
64$userlist = [];
65Hook::run(HOOKTYPE_GET_USER_LIST, $userlist);
66
67?>
180b8ec1
VP
68Click 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">&times;</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
93 <input style="width: 170%;" name="user_add" id="user_add" class="form-control curvy" type="text"></label>
94 </div>
95 <div class="input-group mb-3">
96 <label for="password" id="user_add">Password
97 <input style="width: 170%;" name="password" id="password" class="form-control curvy" type="password"></label>
98 </div>
9a674833
VP
99 <div class="input-group mb-3">
100 <label for="user_email" id="user_add">Email
101 <input style="width: 170%;" name="user_email" id="user_email" class="form-control curvy" type="text"></label>
102 </div>
180b8ec1
VP
103 <div class="input-group mb-3">
104 <label for="add_first_name" id="user_add">First Name
105 <input style="width: 170%;" name="add_first_name" id="add_first_name" class="form-control curvy" type="text"></label>
9a674833
VP
106 </div>
107 <div class="input-group mb-3">
180b8ec1
VP
108 <label for="password" id="user_add">Last Name
109 <input style="width: 170%;" name="add_last_name" id="add_last_name" class="form-control curvy" type="text"></label>
110 </div>
111 <div class="input-group mb-3">
112 <label for="password" id="user_add">Info /Bio
113 <textarea style="width: 170%;" name="user_bio" class="form-control curvy" aria-label="With textarea"></textarea></label>
114 </div>
115 </div>
116
117 <div class="modal-footer">
118 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
119 <button type="submit" name="do_add_user" class="btn btn-danger">Add User</button>
120
121 </div>
122 </div>
123 </div>
124 </div>
125 </div>
126
127</form>
128 <table class="container-xxl table table-sm table-responsive caption-top table-striped">
129 <thead class="table-primary">
130 <form method="post">
131 <th scope="col"><input type="checkbox" label='selectall' onClick="toggle_tkl(this)" /></th>
132 <th scope="col">Username</th>
133 <th scope="col">First Name</th>
134 <th scope="col">Last Name</th>
9a674833 135 <th scope="col">Email</th>
180b8ec1
VP
136 <th scope="col">Created</th>
137 <th scope="col">Bio</th>
138 <th scope="col">Last login</th>
139
140 </thead>
141 <tbody>
142 <?php
143 foreach($userlist as $user)
144 {
145
146 echo "<td scope=\"col\"><input type=\"checkbox\" value='" .$user->id . "' name=\"userch[]\"></td>";
ea90b321 147 echo "<td scope=\"col\"><a href=\"".get_config("base_url")."settings/user-edit.php?id=$user->id\">$user->username</a></td>";
180b8ec1
VP
148 echo "<td scope=\"col\">".$user->first_name."</td>";
149 echo "<td scope=\"col\">".$user->last_name."</td>";
9a674833 150 echo "<td scope=\"col\"><a href=\"mailto:$user->email\">$user->email</a></td>";
2d62c85d 151 echo "<td scope=\"col\"><code>".$user->created."</code></td>";
180b8ec1 152 echo "<td scope=\"col\">".$user->bio."</td>";
2d62c85d
VP
153 $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";
154 echo "<td scope=\"col\">$last</td>";
e9996356 155 echo "</tr>\n";
180b8ec1 156 }
e9996356
VP
157 ?></tbody></table>
158 <?php if (current_user_can(PERMISSION_MANAGE_USERS)) { ?>
159 <p><button type="button" class="btn btn-danger" data-toggle="modal" data-target="#myModal2">
180b8ec1
VP
160 Delete selected
161 </button></p>
e9996356 162 <?php } ?>
180b8ec1
VP
163 <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
164 <div class="modal-dialog modal-dialog-centered" role="document">
165 <div class="modal-content">
166 <div class="modal-header">
167 <h5 class="modal-title" id="myModalLabel">Confirm deletion</h5>
168 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
169 <span aria-hidden="true">&times;</span>
170 </button>
171 </div>
172 <div class="modal-body">
173 Are you sure you want to do this?<br>
174 This cannot be undone.
175 </div>
176 <div class="modal-footer">
177 <button id="CloseButton" type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
178 <button type="submit" action="post" name="delete_user" class="btn btn-danger">Delete</button>
179
180 </div>
181 </div>
182 </div>
183 </div></form></div></div><br></div>
184<?php
185require_once '../footer.php'; ?>