-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_users.php
More file actions
170 lines (161 loc) · 8.03 KB
/
edit_users.php
File metadata and controls
170 lines (161 loc) · 8.03 KB
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
<?php
include_once 'connection/checkUser.php';
include_once 'database/User.php';
include_once 'parts/header.php';
$err = '';
$success = '';
//Check if post back
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$err = User::testEdit();
}
if (($_SERVER["REQUEST_METHOD"] == "POST") && empty($err)) {
// Parse the $_POST['submit*id*'] to get the *id* only
$userId = explode("submit", key(array_intersect_key($_POST, array_flip(preg_grep('/^submit/', array_keys($_POST))))))[1];
User::updateUser($_POST["username".$userId], $_POST["name".$userId], $_POST["auth".$userId]);
debug($_SESSION);
if($_POST["username".$userId] == $_SESSION["user"]) {
$_SESSION["name"] = $_POST["name".$userId];
$_SESSION["auth"] = $_POST["auth".$userId];
}
$success = "Done!";
}
?>
<body>
<div id="wrapper">
<?php include_once 'parts/nav.php'; ?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Edit Users</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="panel panel-default">
<div class="panel-heading">
Information
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<form role="form" method="POST"
action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>>
<?php if (!empty($err)) { ?>
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<?php echo $err ?>
</div>
<?php } ?>
<?php if (!empty($success)) { ?>
<div class="alert alert-success" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<?php echo $success ?>
</div>
<?php } ?>
<label>Select Username:</label>
<?php
$results = User::getUsers();
$html = "<option value='' disabled selected style='display:none;'>Select user</option>";
foreach ($results as $key => $value) {
if(isset($_POST['form_select'])) {
if ($_POST['form_select'] == $key) {
$html .= "<option name='$value[username]' value='$key' selected>$value[username]</option>";
} else {
$html .= "<option name='$value[username]' value='$key'>$value[username]</option>";
}
} else {
$html .= "<option name='$value[username]' value='$key'>$value[username]</option>";
}
}
echo "<select class='form-control' name='form_select' onchange='showDiv(this);'>$html</select>";
?>
<br>
<?php
foreach ($results as $key => $value) {
?>
<div id="selection<?php echo $key ?>" style="display: none;">
<input class="form-control" name="username<?php echo $key; ?>" type="hidden"
value="<?php echo $value["username"]; ?>">
<div class="form-group">
<label>Name:</label>
<input class="form-control" name="name<?php echo $key; ?>" type="text"
value="<?php echo $value["name"]; ?>">
</div>
<div class="form-group">
<label>New password:</label>
<input class="form-control" name="newpass<?php echo $key; ?>"
type="password">
</div>
<div class="form-group">
<label>Confirm password:</label>
<input class="form-control" name="confirmpass<?php echo $key; ?>"
type="password">
</div>
<div class="form-group">
<label>Authorization:</label>
<select class="form-control" name="auth<?php echo $key ?>">
<option value="1" <?php if ($value["auth"] == 1) echo "selected"; ?>>
Admin
</option>
<option value="2" <?php if ($value["auth"] == 2) echo "selected"; ?>>
Dr.
</option>
<option value="3" <?php if ($value["auth"] == 3) echo "selected"; ?>>
Nurse
</option>
<option value="4" <?php if ($value["auth"] == 4) echo "selected"; ?>>
Research
</option>
</select>
</div>
<input type=submit class="btn btn-default" value='Save'
name="submit<?php echo $key; ?>">
</div>
<?php
}
?>
</form>
</div>
</div>
<!-- /.row (nested) -->
</div>
<!-- /.panel-body -->
</div>
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<script type="text/javascript">
function showDiv(elem) {
var all_elem = getElementsStartsWithId('selection');
for (var i = 0, length = all_elem.length; i < length; i++) {
document.getElementById('selection' + i).style.display = "none";
}
document.getElementById('selection' + elem.value).style.display = "block";
}
function getElementsStartsWithId(id) {
var children = document.body.getElementsByTagName('*');
var elements = [], child;
for (var i = 0, length = children.length; i < length; i++) {
child = children[i];
if (child.id.substr(0, id.length) == id)
elements.push(child);
}
return elements;
}
</script>
<?php
/*if (isset($_POST['form_select'])) {
echo "<script>";
echo "showDiv(".$_POST['form_select'].")";
echo "</script>";
}*/
?>
<?php
include_once 'parts/bottom.php';
include_once 'parts/footer.php';
?>