-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedituser-modify.php
280 lines (257 loc) · 11.3 KB
/
edituser-modify.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?PHP
session_start();
if (!(isset($_SESSION['SESS_MEMBER_ID']) && $_SESSION['SESS_MEMBER_ID'] != '')) {
header("Location: login.php");
}
if ($_SESSION['SESS_MEMBER_ROLE'] != "admin") {
header("Location: index.php");
}
//Include database connection details
require_once ('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if (!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if (get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$rowSelected = $_POST['row'];
// If nothing was selected.
if (empty($rowSelected)) {
echo("You didn't select anything.");
session_write_close();
header("location: edituser.php");
exit();
}
//Create SELECT query
$qry = "";
$qry = $qry . "SELECT * FROM members WHERE member_id = " . $rowSelected[0];
$qry = $qry . ";";
$result = @mysql_query($qry);
$memberid = $rowSelected[0];
if ($result) {
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$ein = $row['ein'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$login = $row['login'];
$passwd = $row['passwd'];
$role = $row['role'];
$email = $row['email'];
$myagency = $row['agency'];
$myagcyaddr = $row['agcyaddr'];
}
}
} else {
die("Query failed");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Form</title>
<link href="form.css" rel="stylesheet" type="text/css" />
<script>
function toggleview(id1, id2, txt1) {
var parnt = document.getElementById(id1);
var child = document.getElementById(id2);
var field = document.getElementById(id2 + "id");
var matchtxt = txt1;
if (parnt.options[parnt.selectedIndex].text == matchtxt) {
child.className = "itemshown";
} else {
child.className = "itemhidden";
field.value = parnt.options[parnt.selectedIndex].text;
}
}
function setvisible(id1) {
var obj1 = document.getElementById(id1);
if (obj1.className == "itemhidden") {
obj1.className = "itemshown";
}
}
function validateForm() {
var vform = document.forms["edituserform"];
var x = vform["first"].value;
if (x == null || x == "") {
alert("Please enter the employee's first name");
return false;
}
var x = vform["last"].value;
if (x == null || x == "") {
alert("Please enter the employee's last name");
return false;
}
var x = vform["login"].value;
if (x == null || x == "") {
alert("Please enter a valid username");
return false;
}
var x = vform["ein"].value;
if (x == null || x == "") {
alert("EIN must be filled out");
return false;
}
var x = vform["agencyinputid"].value;
if (x == null || x == "") {
alert("Please select an agency");
return false;
}
var x = vform["agencyaddressinputid"].value;
if (x == null || x == "") {
alert("Please select an agency address");
return false;
}
}
</script>
</head>
<body>
<?php
if (isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) > 0) {
echo '<ul class="err">';
foreach ($_SESSION['ERRMSG_ARR'] as $msg) {
echo '<li>', $msg, '</li>';
}
echo '</ul>';
unset($_SESSION['ERRMSG_ARR']);
}
?>
<header class="body">
<h1>Forms Central - Modify User</h1>
</header>
<section class="body">
<form id="edituserform" method="post" action="edituser-exec.php" onsubmit="return validateForm()" >
<?php
printf("<input name=\"memberid\" type=\"hidden\" class=\"hidden\" id=\"memberid\" value=\"%s\" />\n",$memberid);
printf("<label>First Name </label>\n");
printf("<input name=\"first\" type=\"text\" class=\"textfield\" id=\"first\" value=\"%s\" />\n",$firstname);
printf("<label>Last Name </label>\n");
printf("<input name=\"last\" type=\"text\" class=\"textfield\" id=\"last\" value=\"%s\" />\n",$lastname);
printf("<label>Username</label>\n");
printf("<input name=\"login\" type=\"text\" class=\"textfield\" id=\"login\" value=\"%s\"/>\n",$login);
printf("<label>EIN</label>\n");
printf("<input name=\"ein\" type=\"text\" class=\"textfield\" id=\"ein\" value=\"%s\"/>\n",$ein);
printf("<label>Agency</label>\n");
printf("<select id=\"agencyselect\" onchange=\"javascript:toggleview('agencyselect', 'agencyinput', 'My agency is not listed')\">\n");
?>
<option> Select one of the following</option>
<option value="My agency is not listed">My agency is not listed</option>
<?php
//Include database connection details
require_once ('config.php');
$option1text='';
$option2text='';
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if (!$db) {
die("Unable to select database");
}
$qry = "SELECT DISTINCT agency FROM members;";
$result = mysql_query($qry);
if ($result) {
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$agency = $row['agency'];
if ( $agency == $myagency )
{
$option1text .= " <option value=\"" . $agency . "\" selected>" . $agency . " </option>\n";
} else {
$option1text .= " <option value=\"" . $agency . "\">" . $agency . " </option>\n";
}
}
}
} else {
die("Query failed");
}
$qry = "SELECT DISTINCT agcyaddr FROM members;";
$result = mysql_query($qry);
if ($result) {
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$agcyaddr = $row['agcyaddr'];
if ( $agcyaddr == $myagcyaddr ) {
$option2text .= " <option value=\"" . $agcyaddr . "\" selected>" . $agcyaddr . " </option>\n";
} else {
$option2text .= " <option value=\"" . $agcyaddr . "\">" . $agcyaddr . " </option>\n";
}
}
}
@mysql_free_result($result);
print $option1text;
} else {
die("Query failed");
}
?>
</select>
<div id="agencyinput" class="itemhidden">
<label>Agency Name</label>
<?php
printf("<input name=\"agencyinput\" id=\"agencyinputid\" value=\"%s\">\n",$myagency);
?>
</div>
<label>Agency Address</label>
<select id="agencyaddress" onchange="javascript:toggleview('agencyaddress', 'agencyaddressinput', 'My address is not listed')">
<option> Select one of the following</option>
<option value="My address is not listed">My address is not listed</option>
<?php
print $option2text;
?>
</select>
<div id="agencyaddressinput" class="itemhidden">
<label>Work Address</label>
<?php
printf("<input name=\"agencyaddressinput\" id=\"agencyaddressinputid\" value=\"%s\">\n",$myagcyaddr);
?>
</div>
<label>User Role</label>
<?php
if ($role == "user") {
printf("<input type=\"radio\" name=\"role\" value=\"user\" checked=\"checked\">Form User - Can only fill out/submit forms<br>\n");
printf("<input type=\"radio\" name=\"role\" value=\"admin\">Admin - Can also create and edit form users<br>\n");
} else {
printf("<input type=\"radio\" name=\"role\" value=\"user\" >Form User - Can only fill out/submit forms<br>\n");
printf("<input type=\"radio\" name=\"role\" value=\"admin\" checked=\"checked\">Admin - Can also create and edit form users<br>\n");
}
?>
<label>Password</label>
<input name="password" type="password" class="textfield" id="password" />
<label>Confirm Password </label>
<input name="cpassword" type="password" class="textfield" id="cpassword" />
<label alt="Employee's email address">Email Address</label>
<?php
printf("<input name=\"email\" type=\"text\" type=\"email\" class=\"textfield\" id=\"email\" value=\"%s\"/>\n",$email);
?>
<input id="submit" type="submit" name="Submit" value="Change User" />
</form>
<form method="post" action="admin.php">
<input id="submit" name="submit" type="submit" value="Back">
</form>
<form method="post" action="logout.php">
<input id="submit" name="submit" type="submit" value="Logout">
</form>
</section>
</body>
</html>