]>
Commit | Line | Data |
---|---|---|
a5eae6b7 MR |
1 | <?php |
2 | /* $Id$ */ | |
3 | require_once 'config.inc.php'; | |
4 | require_once 'user_validate.php'; | |
5 | require_once 'helper.php'; | |
6 | ||
7 | valid_user(); | |
8 | ||
9 | if (! defined($_SESSION['__ROOT__']) && empty($_SESSION['__ROOT__'])) { | |
10 | if (session_id()) | |
11 | session_destroy(); | |
12 | header('Location: ' . WEB_ROOT . 'error.html'); | |
13 | exit; | |
14 | } | |
15 | ||
16 | if (! has_admin_role()) { | |
17 | if (session_id()) | |
18 | session_destroy(); | |
19 | header('Location: ' . WEB_ROOT . 'error.html'); | |
20 | exit; | |
21 | } | |
22 | ||
23 | require_once 'persistens.php'; | |
24 | ||
25 | include TOP_FOLDER.'/include/header.inc.php'; | |
26 | include TOP_FOLDER.'/include/menu.inc.php'; | |
27 | $self =$_SERVER['PHP_SELF']; | |
28 | $db = Persistens::getInstance(DBDRIVER); | |
29 | ||
30 | if (count($_POST) > 0 && isset($_POST['action'])) { | |
31 | ||
32 | $action = strtolower($_POST['action']); | |
33 | switch ($action) { | |
34 | case 'delete': | |
35 | $error = ''; | |
36 | if (isset($_POST['uid']) && ! empty($_POST['uid'])) { | |
37 | foreach ($_POST['uid'] as $uid) { | |
38 | $result = $db->deleteUser($uid); | |
39 | if ($result !== TRUE) { | |
40 | $error .= "$result<br/>"; | |
41 | } | |
42 | } | |
43 | } | |
44 | else | |
45 | $error = 'No user selected for deletion'; | |
46 | if ($error == '') | |
47 | $result = "Users was succesfully delete"; | |
48 | else | |
49 | $result = $error; | |
50 | break; | |
51 | case 'reset password': | |
52 | $res = ''; | |
53 | $error = ''; | |
54 | if (isset($_POST['uid']) && ! empty($_POST['uid'])) { | |
55 | foreach ($_POST['uid'] as $uid) { | |
56 | $pwd = substr(md5($_POST['uid'] . microtime()), 0, 8); | |
57 | $result = $db->changePassword($uid, sha1($pwd)); | |
58 | if ($result !== TRUE) | |
59 | $res .= $_POST['uid'] .": No change<br/>"; | |
60 | else | |
61 | $res .= $uid .": $pwd<br/>"; | |
62 | } | |
63 | } | |
64 | else | |
65 | $error = 'No user selected for resetting password'; | |
66 | if ($error == '') | |
67 | $result = $res; | |
68 | else | |
69 | $result = $error; | |
70 | break; | |
71 | default: | |
72 | $result = "$action: Unknown action"; | |
73 | break; | |
74 | } | |
75 | $pageView .= <<<__EOF | |
76 | <p style="text-align: center"> | |
77 | $result | |
78 | </p> | |
79 | __EOF; | |
80 | } | |
81 | else { | |
82 | $pageView = <<<__EOF | |
83 | <form action="$self" method="post" id="form"> | |
84 | <p> | |
85 | <table class="config"> | |
86 | <tr> | |
87 | <td colspan="3" style="text-align: center; | |
88 | font-weight: bold;font-size: 2.0em;"> | |
89 | Manage users | |
90 | </td> | |
91 | </tr> | |
92 | <tr> | |
93 | <th>Username</th><th>Role</th><th> </th> | |
94 | </tr> | |
95 | __EOF; | |
96 | $users = $db->getAllUsers(); | |
97 | foreach ($users as $user) { | |
98 | if (strtoupper($user['uid']) == 'ADMIN') { | |
99 | $pageView .= "<tr><td>{$user['uid']}</td><td>{$user['userrole']}</td> | |
100 | <td> </td> | |
101 | </tr>"; | |
102 | } | |
103 | else { | |
104 | $pageView .= "<tr><td>{$user['uid']}</td><td>{$user['userrole']}</td> | |
105 | <td style=\"text-align: center\"><input type=\"checkbox\" name=\"uid[]\" | |
106 | value=\"{$user['uid']}\"/></td></tr>"; | |
107 | } | |
108 | } | |
109 | $pageView .= '<tr><td class="config" colspan="3" style="text-align: center"> | |
110 | <input type="submit" name="action" value="Delete"/> | |
111 | <input type="button" value="New user" | |
112 | onclick="document.location.href=\'newuser.php\'" /> | |
113 | <input type="submit" name="action" value="Reset password" /> | |
114 | </td></tr></table></p></form>'; | |
115 | } | |
116 | ||
117 | print "<div id=\"ui\">$pageView</div>"; | |
118 | ||
119 | include TOP_FOLDER.'/include/footer.inc.php'; | |
120 | ||
121 | ?> |