forked from ewic/php_timeclock
/
manage_users.php
223 lines (193 loc) · 7.86 KB
/
manage_users.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
ob_start(); // Output buffering - allows header rewrites to happen at anytime before flushing the buffer
session_start();
require_once("incdir.php.inc");
require_once("config.php");
include_php_dir("includes",$debug);
mysql_init();
handle_ajax();
document_header();
echo include_javascript_dir("js",$debug);
echo include_stylesheet_dir("stylesheets",$debug);
check_validated();
//If a new user was submitted!
if (isset($_POST['newuser-submit'])) {
$userinfo = array(
"username" => $_POST['username'],
"fname" => $_POST['fname'],
"lname" => $_POST['lname'],
"emplid" => $_POST['emplid'],
"password" => $_POST['password'],
"email" => $_POST['email'],
"phone" => $_POST['phone'],
"address" => $_POST['address'],
"pwconfirm" => $_POST['pwconfirm'],
);
adduser($userinfo);
}
if(!check_app_admin())
header( 'Location: index.php' );
open_page("Not User Management");
draw_page();
close_page();
ob_end_flush(); // Flush the buffer out to client
document_footer(); mysql_end();
//The actual page.
function draw_page() {
?>
<div class="container">
<?php open_panel("userlist","User List",false); ?>
<div class="row">
<div class="col-md-10">
<?php draw_user_list(); ?>
</div>
<div class="col-md-2 side_box">
<button class="btn btn-default btn-sm col-md-12" onClick="toggleinactive()">Show Inactives</button>
<button class="btn btn-default btn-sm col-md-6" data-toggle="modal" data-target="#adduser">Add User</button>
<button class="btn btn-default btn-sm col-md-6" data-toggle="modal" data-target="#bulkadd">Bulk Add</button>
</div>
<div class="col-md-2 side_box">
<button class="btn btn-default btn-sm col-md-12" onClick="toggleinactive()">Show Inactives</button>
<button class="btn btn-default btn-sm col-md-6" data-toggle="modal" data-target="#adduser">Add User</button>
<button class="btn btn-default btn-sm col-md-6" data-toggle="modal" data-target="#bulkadd">Bulk Add</button>
</div>
</div>
<?php close_panel(); ?>
</div>
<?php
draw_adduser_form();
draw_bulkadd_form();
}
function draw_user_list() {
$users = get_users();
?>
<table class="userlist table table-condensed table-bordered">
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Username</th>
</tr>
<?php
while ($row = $users->fetch_array()) {
$row['role'] = get_role($row['user_id']);
echo '<tr class="userlist ';
echo 'userlist-'.$row['role'];
if ($row['inactive'])
echo ' userlist-inactive';
echo '" onclick="openEdit('.$row['user_id'].')">';
echo '<td style="cursor:pointer;">'.$row['lname']."</td>";
echo '<td style="cursor:pointer;">'.$row['fname']."</td>";
echo '<td style="cursor:pointer;">'.$row['username']."</td>";
echo '</tr>';
}
?>
</table>
<?php
}
function draw_adduser_form() { ?>
<!-- adduser modal -->
<div class="modal fade" id="adduser" tabindex="-1" role="dialog" aria-labelledby="adduserLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form role="form" method="post" action="manage_users.php">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="adduserLabel">Add User</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="adduser-username">Username</label>
<input type="text" id="adduser-username" name="username" class= "form-control" placeholder="Enter username">
</div>
<div class="form-group">
<label for="adduser-fname">First Name</label>
<input type="text" id="adduser-fname" name="fname" class="form-control" placeholder="Enter first name">
</div>
<div class="form-group">
<label for="adduser-lname">Last Name</label>
<input type="text" id="adduser-lname" name="lname" class="form-control" placeholder="Enter last name">
</div>
<div class="form-group">
<label for="adduser-emplid">URI ID Number</label>
<input type="text" id="adduser-emplid" name="emplid" class="form-control" placeholder="Enter URI ID Number">
</div>
<div class="form-group">
<label for="adduser-email">eMail</label>
<input type="text" id="adduser-email" name="email" class="form-control" placeholder="Enter eMail" autocomplete="off">
</div>
<div class="form-group">
<label for="adduser-phone">Phone</label>
<input type="text" id="adduser-phone" name="phone" class="form-control" placeholder="Enter Phone" autocomplete="off">
</div>
<div class="form-group">
<label for="adduser-address">Address</label>
<input type="text" id="adduser-address" name="address" class="form-control" placeholder="Enter Address" autocomplete="off">
</div>
<div class="form-group">
<label for="adduser-password">Password</label>
<input type="password" id="adduser-password" name="password" class="form-control" autocomplete="off" placeholder="Enter password">
</div>
<div class="form-group">
<label for="adduser-pwconfirm">Confirm Password<span id="pwconfirm-message" style="color:red; display:none"></span></label>
<input type="password" id="adduser-pwconfirm" name="pwconfirm" class="form-control" placeholder="Enter password again">
</div>
</div>
<div class="modal-footer">
<input type='hidden' name='newuser-submit' value='true'>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-primary" value="Add User" name="submit">
</div>
</form>
</div>
</div>
</div><!-- close modal -->
<?php }
function draw_bulkadd_form() { ?>
<!-- adduser modal -->
<div class="modal fade" id="bulkadd" tabindex="-1" role="dialog" aria-labelledby="bulkaddLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form role="form" method="post" action="manage_users.php">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="bulkaddLabel">Add Users</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<input type='hidden' name='bulkadd-submit' value='true'>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-primary" value="Add Users" name="submit">
</div>
</form>
</div>
</div>
</div><!-- close modal -->
<?php }
function draw_newpass_success($newpass) {
?>
<div class="notice">
Successfully reset password. New password is "<?php echo $newpass ?>".
</div>
<?php
}
?>
<!-- JS to show inactive users if a button is clicked -->
<script type="text/javascript">
function toggleinactive() {
var inactives = document.getElementsByClassName("userlist-inactive");
for(var i=0; i<inactives.length; i++) {
if( inactives[i].style.display=="table-row")
inactives[i].style.display="none";
else
inactives[i].style.display="table-row";
}
}
</script>
<!-- also, don't forget password mismatch js -->
<!-- popup javascript -->
<script type="text/javascript">
function openEdit(id) {
window.open('edit_user.php?user_id='+id,'_blank','height=540,width=680,menubar=no,status=no,titlebar=no,toolbar=no');
}
</script>