php8
[web.mtrack] / admin / user.php
1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3 include '../../inc/common.php';
4
5 /* Note: individual user editing is carried out in web/user.php */
6
7 MTrackACL::requireAnyRights('User', 'modify');
8
9 mtrack_head("Administration - Users");
10
11 ?>
12 <h1>Users</h1>
13 <?php
14   echo "<form method='get' action=\"{$ABSWEB}admin/user.php\">";
15   $find = htmlentities(trim($_GET['find']), ENT_QUOTES, 'utf-8');
16 ?>
17 <p>To find an user, enter their name, userid or email address in the box
18 below and click search; matches will be shown in the list below.
19 </p>
20 <input type="text" name="find" value="<?php echo $find ?>">
21 <button type="submit">Find User</button>
22 </form>
23 <p>
24 Select a user below to edit them, or click the "Add" button to create
25 a new user.
26 </p>
27
28 <?php
29
30 $limit = 15;
31 $offset = isset($_GET['off']) ? (int)$_GET['off'] : 0;
32
33 if (strlen($find)) {
34   $sql =
35     "select distinct i.userid, fullname, email, active from userinfo i left join useraliases a on i.userid = a.userid where i.userid like '%$find%' or fullname like '%$find%' or email like '%$find%' or a.alias like '%$find%' order by active desc, i.userid limit $limit offset $offset";
36 } else {
37   $sql = "select userid, fullname, email, active from userinfo order by case active when 1 then 0 else 1 end, userid limit $limit offset $offset";
38 }
39
40 echo "<table>\n";
41 foreach (MTrackDB::q($sql) as $row) {
42
43   $uid = $row[0];
44   $name = htmlentities($row[1], ENT_QUOTES, 'utf-8');
45   $email = htmlentities($row[2], ENT_QUOTES, 'utf-8');
46   $class = $row[3] == '1' ? 'activeuser' : 'inactiveuser';
47
48   echo "<tr class='$class'>",
49     "<td>" . mtrack_username($uid, array('edit' => 1)) . "</td>" .
50     "<td>$name</td>",
51     "<td>$email</td>",
52     "</tr>\n";
53
54 }
55 echo "</table><br>";
56 if ($offset > 0) {
57   echo "<a href=\"{$ABSWEB}admin/user.php?off=" . ($offset - $limit) . "\">Previous</a> ";
58 }
59 echo "<a href=\"{$ABSWEB}admin/user.php?off=" . ($offset + $limit) . "\">Next</a>";
60 echo "<br><br>";
61
62 echo "<h2>Add User</h2>";
63 echo "<form method='get' action=\"{$ABSWEB}user.php\">";
64 ?>
65 <input type="hidden" name="edit" value="1">
66 <p>
67 To create a new user, enter the userid (typically the "short" login name) that
68 you want to use in the box below, and click "Create".
69 </p>
70 <input type="text" name="user" value="">
71 <button type="submit">Create User</button>
72 </form>
73 <?php
74
75 mtrack_foot();
76