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
|
<?php
include "functions.php";
main_header( 'Edit User Listing' );
// are we an admin?
$query = mysql_query( "select admin from users where uid=$uid" );
list( $priv ) = mysql_fetch_row( $query );
if ( !$priv ) {
print '<p style="color:red;">You don\'t appear to be an admin.</p>';
main_footer();
exit;
}
if ( $submitted ) {
if ( $pass1 != $pass2 ) {
print '<p style="color:red;">Your password fields did not match.</p>';
} else {
// stuff that needs to be done for both
$team = team_name_num( $team );
if ( $admin ) $admin = '1'; else $admin = '0';
reset( $teams );
while ( $cur = each($teams) ) { // construct special teams value
if ( $$cur['value'] == 'r' || $$cur['value'] == 'l' ) $tms[] = $cur['key'];
if ( $$cur['value'] == 'l' ) $leads[] = $cur['key'];
}
if ( $tms ) {
$team = implode( ',', $tms );
} else {
$team = '';
}
// grant leaderships
if ( $leads ) {
while ( $cur = each($leads) ) {
mysql_query( "update teams set leader=$xuid where gid=".$cur['value'] );
}
}
// revoke leaderships
$oldleads = explode( ',', $oldleads );
if ($leads) reset( $leads );
while ( $ol = each($oldleads) ) {
$tmp = 1;
if ( $leads ) {
reset( $leads );
while ( $g = each($leads) ) {
if ( $g['value'] == $ol['value'] ) { $tmp = 0; break; }
}
}
if ( $tmp ) {
mysql_query( 'update teams set leader=0 where gid='.$ol['value'] );
}
}
if ( $xuid == 'new' ) {
// new user
mysql_query( "insert into users set username='$username',password='$pass1',admin=$admin,title='$title',email='$email',realname='$realname',location='$location',team='$team'" );
$xuid = mysql_insert_id();
print '<p style="color:red;">User added to database.</p>';
} else {
// change existing
$query = "update users set username='$username'";
if ( $pass1 ) $query .= ",password='$pass1'";
$query .= ",admin=$admin,title='$title',email='$email',realname='$realname',location='$location',team='$team' where uid=$xuid";
mysql_query( $query );
print '<p style="color:red;">User information updated.</p>';
}
}
}
if ( !$xuid ) {
?>
<p style="font-size:medium;font-weight:bold;">User Listing</p>
<ul>
<li> <a href="useredit.php?xuid=new">Create new user</a>
<?php
$result = mysql_query( "select uid,username from users order by username" );
while ( list($xuid,$dude) = mysql_fetch_row($result) ) {
?>
<li> <a href="useredit.php?xuid=<?=$xuid;?>"><?=$dude;?></a>
<?php
}
?>
</ul>
<?php
} else {
if ( $xuid != 'new' ) {
// otherwise, we'll just keep all values empty
$dude = mysql_query( "select * from users where uid=$xuid" );
$dude = mysql_fetch_array( $dude );
$xteams = explode( ",", $dude['team'] );
}
?>
<form action="useredit.php" method="post">
<table border=0 cellpadding=2 cellspacing=0>
<tr>
<td align="right"><b>Real Name:</b></td>
<td><input type="text" name="realname" maxlength=200 value="<?=$dude['realname'];?>"></td>
</tr>
<tr>
<td align="right"><b>Username:</b></td>
<td><input type="text" name="username" maxlength=10 value="<?=$dude['username'];?>"></td>
</tr>
<tr>
<td align="right"><b>Password:</b><br>(Type in a<br>password twice<br>to change.)</td>
<td><input type="password" name="pass1" maxlength=10><br><input type="password" name="pass2" maxlength=10></td>
</tr>
<tr>
<td align="right"><b>Title:</b></td>
<td><input type="text" name="title" maxlength=100 value="<?=$dude['title'];?>"></td>
</tr>
<tr>
<td align="right"><b>Email:</b></td>
<td><input type="input" name="email" value="<?=$dude['email'];?>" maxlength=200></td>
</tr>
<tr>
<td align="right"><b>Location:</b></td>
<td><input type="input" name="location" value="<?=$dude['location'];?>" maxlength=200></td>
</tr>
<tr>
<td align="right"><b>Admin:</b></td>
<td><input type="checkbox" name="admin"<?php if ( $dude['admin'] ) print ' checked'; ?>></td>
</tr>
<tr>
<td align="right" valign="top"><b>Team Memberships:</b></td>
<td>
<table border=0 cellpadding=1 cellspacing=0 bgcolor="black"><tr><td>
<table width=300 border=0 cellpadding=5 cellspacing=0 bgcolor="#bdbacc">
<tr>
<td> </td>
<td align="center"><b>Unaffiliated</b></td>
<td align="center"><b>Regular</b></td>
<td align="center"><b>Leader</b></td>
</tr>
<?php
// get team info
reset( $teams );
while ( $each = each($teams) ) {
if ( $each['key'] == 0 || $each['key'] == 1 ) continue; // skip 'none' and 'all'
$tm = 'u'; // set the default
if ( $xuid != 'new' ) {
// are they a simple member? ...
reset( $xteams );
while ( $cur = each($xteams) ) {
if ( $cur['value'] == $each['key'] ) $tm = 'r';
}
// are they the team LEADER?!?! :)
$ldr = mysql_query( 'select leader from teams where gid='.$each['key'] );
list( $ldr ) = mysql_fetch_row( $ldr );
if ( $ldr == $xuid ) { $tm = 'l'; $oldlead[] = $each['key']; }
}
?>
<tr>
<td><b><?=$each['value'];?></b></td>
<td align="center"><input type="radio" name="<?=$each['value'];?>" value="u"<?php if ($tm=='u') print ' checked'; ?>></td>
<td align="center"><input type="radio" name="<?=$each['value'];?>" value="r"<?php if ($tm=='r') print ' checked'; ?>></td>
<td align="center"><input type="radio" name="<?=$each['value'];?>" value="l"<?php if ($tm=='l') print ' checked'; ?>></td>
</tr>
<?php
}
?>
</table>
</td></tr></table>
</td>
</tr>
<tr>
<input type="hidden" name="submitted" value="1">
<input type="hidden" name="oldleads" value="<?php if ($oldlead) print implode( ',', $oldlead );?>">
<input type="hidden" name="xuid" value="<?=$xuid;?>">
<td align="center" colspan=2><input type="submit" value="Submit"></td>
<tr>
</table>
</form>
<?php
}
main_footer();
?>
|