-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit-user.php
273 lines (251 loc) · 7.59 KB
/
edit-user.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
<? include "db.php"; ?>
<?
if($loggedin)
{
if($isadmin && is_numeric($_GET["id"]))
{
$sid = $_GET["id"];
$isv = false;
}
else
{
$sid = $userid;
$isv = $isvalidated;
}
$result = mysql_query("SELECT * FROM USER_LIST WHERE USER_ID=$sid") or die("User query failed");
$l = mysql_fetch_array($result, MYSQL_ASSOC);
mysql_free_result($result);
}
else
forceLogin();
$done = false;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Edit Account</title>
<link rel="stylesheet" type="text/css" href="../shs.css">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<? include "inc-header.php" ?>
<h1>Edit Account</h1>
<?
if($_POST["btn"] == "Save")
{
$aun = stripslashes($_POST['un']);
$aaddr = stripslashes($_POST['addr']);
$acity = stripslashes($_POST['city']);
$azip = stripslashes($_POST['zip']);
$axfn = stripslashes($_POST['xfn']);
$axln = stripslashes($_POST['xln']);
$agr = stripslashes($_POST['gr']);
$atag = stripslashes($_POST['tag']);
$aemail = stripslashes($_POST['email']);
$asid = stripslashes($_POST['sid']);
$amailcap = stripslashes($_POST['mailcap']);
if(strlen($aemail) > 48)
print '<p>Sorry, your email address cannot exceed 48 characters in length.</p>';
else if (!ereg('^[-_.a-zA-Z0-9]+@[-_.a-zA-Z0-9]+\\.([-_.a-zA-Z0-9]{1,3})$', $aemail) && !$isadmin)
print '<p>The email address you entered appears to be invalid.</p>';
else if ($admin && !ereg('^([-_a-zA-Z0-9]{1,32})$', $aun))
print '<p>The username you entered was invalid. Valid usernames may contain letters, numbers, _, and -, and may be at most 32 characters long.</p>';
else
{
if($isadmin && is_numeric($agr))
{
if(!is_numeric($asid))
$asid = 'Null';
if(strlen($aun) < 1)
$aun = 'Null';
else
$aun = "'" . addslashes($aun) . "'";
if(!is_numeric($atag))
$atag = 'Null';
if(!is_numeric($amailcap))
$amailcap = 'Null';
$unameconflicts = mysql_query('SELECT COUNT(*) FROM USER_LIST WHERE USER_ID!=' . $sid . ' AND USER_UNAME=' . $aun);
$numconflicts = mysql_fetch_array($unameconflicts, MYSQL_ASSOC);
if($numconflicts['COUNT(*)'] > 0 && strlen($aun) > 0)
{
print '<p>That username was already taken.</p>';
}
else
{
mysql_query("UPDATE USER_LIST SET USER_SID=" . $asid . ",
USER_EMAIL='" . addslashes($aemail) . "',
USER_TEACHERTAG=" . $atag . ",
USER_UNAME=" . $aun . ",
USER_GR=" . $agr . ",
USER_ADDRESS='" . $aaddr . "',
USER_CITY='" . $acity . "',
USER_ZIP='" . $azip . "',
USER_MAILCAP=" . $amailcap . ",
USER_FN=CONCAT(UPPER(LEFT('" . $_POST["xfn"] . "',1)),SUBSTRING('" . $_POST["xfn"] . "' FROM 2)),
USER_LN=CONCAT(UPPER(LEFT('" . $_POST["xln"] . "',1)),SUBSTRING('" . $_POST["xln"] . "' FROM 2)),
USER_FULLNAME=CONCAT_WS(' ', USER_FN, USER_LN),
USER_FN_SOUNDEX=SOUNDEX(USER_FN),
USER_LN_SOUNDEX=SOUNDEX(USER_LN),
USER_FULLNAME_SOUNDEX=SOUNDEX(USER_FULLNAME)
WHERE USER_ID=$sid") or die("User update failed" . mysql_error());
$success = true;
}
}
else
{
mysql_query("UPDATE USER_LIST SET USER_EMAIL='" . addslashes($aemail) . "' WHERE USER_ID=$sid") or die("Update failed");
$success = true;
}
if($success)
print "<p>Your account has been successfully updated. <a href=\"./\">Home</a> <a href=\"directory/?id=$sid\">Your schedule</a></p>";
$done = true;
}
}
else
{
$aun = $l["USER_UNAME"];
$axfn = $l["USER_FN"];
$axln = $l["USER_LN"];
$aaddr = $l["USER_ADDRESS"];
$acity = $l["USER_CITY"];
$azip = $l["USER_ZIP"];
$agr = $l["USER_GR"];
$atag = $l["USER_TEACHERTAG"];
$aac = $l["USER_ACTIVATION"];
$aemail = $l["USER_EMAIL"];
$asid = $l["USER_SID"];
$aaim = $l["USER_AIM"];
$amailcap = $l["USER_MAILCAP"];
}
if(!$done)
{
?>
<form action="edit-user.php?id=<?= $sid ?>" name="mf" method="POST">
<table>
<? if($isadmin) { ?>
<tr>
<td>First Name</td>
<td><input type="text" maxlength="16" size="20" name="xfn" value="<?= htmlentities($axfn) ?>"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" maxlength="16" size="20" name="xln" value="<?= htmlentities($axln) ?>"></td>
</tr>
<tr>
<td style="vertical-align: top;">Address</td>
<td><input type="text" maxlength="48" size="35" name="addr" value="<?= htmlentities($aaddr) ?>">
<br><input type="text" maxlength="16" size="16" name="city" value="<?= htmlentities($acity) ?>">, CA <input type="text" maxlength="5" size="8" name="zip" value="<?= htmlentities($azip) ?>">
</td>
</tr>
<tr>
<td>Email Address</td>
<td><input type="text" maxlength="48" size="35" name="email" value="<?= htmlentities($aemail) ?>"></td>
</tr>
<tr>
<td>User Name</td>
<td><input type="text" maxlength="32" size="35" name="un" value="<?= htmlentities($aun) ?>"></td>
</tr>
<tr>
<td>Student ID#</td>
<td><input type="text" maxlength="6" size="8" name="sid" value="<?= $asid ?>"></td>
</tr>
<tr>
<td>Grade</td>
<td><select name="gr">
<?
for($i = C_SCHOOLYEAR - 4; $i <= C_SCHOOLYEAR + 4; $i++)
{
print '<option ';
if($agr == $i)
print 'selected ';
print 'value="' . $i . '">' . GradePrint($i) . '</option>';
}
?>
<option <? if($agr=='0') { print "selected"; } ?> value="0">Faculty</option>
<option <? if($agr=='1') { print "selected"; } ?> value="1">Parent</option>
</select></td>
</tr>
<tr>
<td>Teacher Tag</td>
<td>
<?
print "<select name=\"tag\">";
$result = mysql_query("SELECT * FROM TEACHER_LIST ORDER BY TEACHER_NAME") or die("User query failed");
print "<option value=\"\">Not applicable</option>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "<option ";
if($line["TEACHER_ID"] == $atag)
print " selected ";
print "value=\"" . $line["TEACHER_ID"] . "\">" . $line["TEACHER_NAME"] . "</option>";
}
mysql_free_result($result);
print "</select>";
?></td>
</tr>
<tr>
<td>Activation Code</td>
<td style="font-weight: bold"><? if(is_null($aac))
print '(Activated)';
else
print $aac; ?></td>
</tr>
<tr>
<td>AIM SN</td>
<td style="font-weight: bold">
<? if(is_null($aaim))
print 'None';
else
print "$aaim <a href=\"resetsn.php\">Reset</a>"; ?></td>
</tr>
<tr>
<td>Shmail Cap</td>
<td><input type="text" maxlength="4" size="6" name="mailcap" value="<?= htmlentities($amailcap) ?>"></td>
</tr>
<? } else { ?>
<tr>
<td>First Name</td>
<td><?= $axfn ?></td>
</tr>
<tr>
<td>Last Name</td>
<td><?= $axln ?></td>
</tr>
<tr>
<td style="vertical-align: top;">Address</td>
<td><?= htmlentities($aaddr) ?>
<br><?= htmlentities($acity) ?>, CA <?= htmlentities($azip) ?>
</td>
</tr>
<tr>
<td>Email Address</td>
<td><input type="text" size="35" name="email" value="<?= $aemail ?>"></td>
</tr>
<? if(IsStudent($agr)) { ?>
<tr>
<td>Grade</td>
<td style="font-weight: bold"><?= GradePrint($agr) ?><input type="hidden" name="gr" value="<?= $agr ?>"></td>
</tr>
<? } else { ?>
<tr>
<td>Level</td>
<td style="font-weight: bold"><?= GradePrint($agr) ?><input type="hidden" name="gr" value="<?= $agr ?>"></td>
</tr>
<? } ?>
<tr>
<td>AIM SN</td>
<td style="font-weight: bold">
<? if(is_null($aaim))
print 'None';
else
print "$aaim <a href=\"resetsn.php\">Reset</a>"; ?></td>
</tr>
<? } ?>
</table>
<p><input type="submit" name="btn" value="Save"></p>
</form>
<? } ?>
<? include 'inc-footer.php'; ?>
</body>
</html>