Subversion Repositories ORC

Rev

Rev 29 | Rev 35 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 - 1
#!/usr/bin/perl
2
 
3
use strict;
8 - 4
use cPanelUserConfig;
7 - 5
use RollerCon;
6
use CGI qw/param cookie header start_html url/;
7
use Email::Valid;
8
use WebDB;
9
use HTML::Tiny;
10
our $h = HTML::Tiny->new( mode => 'html' );
11
 
12
my ($FORM, $cookie_string, $ERRMSG);
13
my @ERRORS;
14
my $dbh = WebDB->connect ();
15
my $depts = getDepartments (); # HashRef of the department TLAs -> Display Names...
16
my $AccessLevel = getAccessLevels;
17
my @tshirtOptions = ("", "MS", "MM", "ML", "MXL", "M2X", "M3X");
18
 
19
# The page's form might be submitted as a POST or a GET (or both?)
20
#  The initial _view_ likely comes as a GET request (making it easier to embed in an HREF as a URL)
21
#  Unpack any values sent in the GET and add them to the FORM hash
22
$FORM->{'SUB'} = param ('submit') // '';
23
$FORM->{'RCid'} = param ('RCid') // '';
24
$FORM->{referer} = param ("referer") // "";
25
if ($FORM->{'SUB'} eq '') {
26
	if ($ENV{'REQUEST_URI'}) {
27
		my ($g, $keep) = split /\?/, $ENV{'REQUEST_URI'};
28
		if ($keep) {
29
			foreach (split /&/, $keep) {
30
				my ($k, $v) = split /=/;
31
				$k =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
32
				$v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
33
				$k eq "submit" ? $FORM->{'SUB'} = $v : $FORM->{$k} = $v;
34
			}
35
		}
36
	}
37
}
38
 
39
# Keep track of the original referrer for the 'back' link/button
40
my $goback;
41
if ($FORM->{referer}) {
42
	$goback = $FORM->{referer};
43
} else {
44
	$goback = $ENV{HTTP_REFERER};
45
}
46
 
47
 
48
if ($FORM->{'SUB'} eq "Save") {
49
	process_form ($FORM);
50
} elsif ($FORM->{'SUB'} eq "New User") {
51
  display_form ("New", "New User"); # blank form
52
} elsif ($FORM->{'RCid'}) {
53
  display_form ($FORM->{'RCid'}, $FORM->{'SUB'});
54
} else {
55
 	$cookie_string = authenticate (1);
56
 	my ($EM, $PWD, $AL) = split /&/, $cookie_string;
57
 	display_form (getUser ($EM)->{'RCid'}, "View");
58
}
59
 
60
 
61
sub process_form {
62
  my $F = shift // "";
63
  push @ERRORS, "Tried to save an empty form." and return unless $F;
64
 
29 - 65
	$F->{email}       = lc WebDB::trim param ('email')   // '';
7 - 66
	$F->{password}    = WebDB::trim param ('password')   // '';
67
	$F->{derby_name}  = WebDB::trim param ('derby_name') // '';
68
	$F->{real_name}   = WebDB::trim param ('real_name')  // '';
69
	$F->{pronouns}    = WebDB::trim param ('pronouns')   // '';
70
	$F->{tshirt}      = WebDB::trim param ('tshirt')   // '';
71
	$F->{phone}       = WebDB::trim param ('phone')      // '';
72
#	$F->{level}       = param ('level')      // '';
73
#	$F->{type}        = param ('type')       // '';
74
	$F->{RCid}        = param ('RCid')       // '';
75
	$F->{access}      = param ('access')     // 0;
76
#	$F->{clinic_pass} = defined param ('clinic_pass') ? 1 : 0;
8 - 77
	$F->{department}  = join ":", map { "$_-".param ("DEPT-".$_) } map { s/^DEPT-//; $_ } grep { param ($_) ne "" } grep { /^DEPT-/ } param ;
7 - 78
 
79
  if ($F->{RCid} eq "New") {
80
  # Saving a new User...
81
    # But first let's do some error checking...0
82
		if (!$F->{password})   { push @ERRORS, "Blank Password!"; }
83
		if (!$F->{real_name})  { push @ERRORS, "Blank Real Name!"; }
84
		if (!$F->{derby_name}) { $F->{derby_name} = $F->{real_name}; } # If they leave derby_name blank, use their real_name
85
		if (checkDupes ('derby_name', $F->{derby_name})) { push @ERRORS, "Derby Name already in use. Pick a different one."; $F->{derby_name} = ""; }
86
#		if (!$F->{level})      { $F->{level} = "B"; } # People keep leaving level blank.  Default 'em if they do.
87
#		if (!$F->{type})       { $F->{type} = "official"; } # and now they left the other drop-down blank!!!
88
		if (!$F->{email})      { push @ERRORS, "Blank Email (User-ID)!"; } else {
89
			$F->{email} =~ s/\s+//g; # make sure people aren't accidentally including spaces
90
			$F->{email} = lc $F->{email}; # sometimes people capitalize their email addresses and that's annoying...
91
			if (! Email::Valid->address (-address => $F->{email}, -mxcheck => 1, -tldcheck => 1)) { push @ERRORS, "Mal-formatted (or fake) Email Address!"; $F->{email} = ""; }
92
		}
93
		if (checkDupes ('email', $F->{email})) { push @ERRORS, "Email Address already in use. Pick a different one."; $F->{email} = ""; }
8 - 94
    if (!$F->{department}) { push @ERRORS, "You need to request at least one Department!"; }
95
 
7 - 96
		if (scalar @ERRORS) {
97
			$ERRMSG = join $h->br, @ERRORS;
98
			display_form ("New", "New User", $ERRMSG);
99
			return;
100
		} else {
101
			# We have a correctly formatted email address with a mail host record, go ahead and add the user
102
#			my $sth = $dbh->prepare ("insert into official (email, password, derby_name, real_name, phone, level, type, access, department, clinic_pass) values (?, password(?), ?, ?, ?, ?, ?, ?, ?, ?)");
25 - 103
			my $sth = $dbh->prepare ("insert into official (email, password, derby_name, real_name, pronouns, tshirt, phone, access, department, added) values (?, password(?), ?, ?, ?, ?, ?, ?, ?, CONVERT_TZ(now(), 'America/Chicago', 'America/Los_Angeles'))");
7 - 104
 
105
#			$sth->execute ($F->{email}, $F->{password}, $F->{derby_name}, $F->{real_name}, $F->{phone}, $F->{level}, $F->{type}, 0, $F->{department}, 0);
106
			$sth->execute ($F->{email}, $F->{password}, $F->{derby_name}, $F->{real_name}, $F->{pronouns}, $F->{tshirt}, $F->{phone}, 0, $F->{department});
107
 
108
			$sth = $dbh->prepare ("select RCid from official where email = ?");
109
			$sth->execute ($F->{email});
110
			($F->{RCid}) = $sth->fetchrow_array;
111
			logit ($F->{RCid}, "New User Registration");
112
			sendEMail ("New User", $F);
113
			$cookie_string = authenticate (1);
114
		}
115
	} else {
116
		$cookie_string = authenticate (1);
117
		my ($EM, $PWD, $AL) = split /&/, $cookie_string;
118
		if (lc $EM eq lc $F->{email} and $AL < 5) { # They're editing their own record (and not a sysadmin).
119
 
120
			# Don't let users change their own clinic_pass setting...
121
#		  $F->{clinic_pass} = getUser($EM)->{clinic_pass};
122
			my $DBDepts = getUser($EM)->{department};
123
		  if ($F->{department} ne $DBDepts) {
124
		  	# They're trying to change one of their own departments.
125
		  	my $FORMDepts = convertDepartments $F->{department};
126
		  	$DBDepts =   convertDepartments $DBDepts;
127
		  	map { $FORMDepts->{$_} = 0 } keys %{$FORMDepts};  # the only change to a dept should be a request to be added
128
				map { do { delete $DBDepts->{$_} } if $DBDepts->{$_} == 0 and !defined $FORMDepts->{$_} } keys %{$DBDepts};  # or they can retract their request
129
		  	map { $FORMDepts->{$_} = $DBDepts->{$_} } keys %{$DBDepts};  # otherwise, keep the same depts as are in the DB
130
		  	$F->{department} = convertDepartments $FORMDepts;
131
		  }
132
 
133
      if ($F->{password}) { # They've possibly included an updated password.
134
#    		my $sth = $dbh->prepare("replace into official (RCid, email, password, derby_name, real_name, phone, level, type, access, department, clinic_pass) values (?, ?, password(?), ?, ?, ?, ?, ?, ?, ?, ?)");
135
#    		$sth->execute ($F->{RCid}, $EM, $F->{password}, $F->{derby_name}, $F->{real_name}, $F->{phone}, $F->{level}, $F->{type}, $F->{access}, $F->{department}, $F->{clinic_pass})
136
    		my $sth = $dbh->prepare("replace into official (RCid, email, password, derby_name, real_name, pronouns, tshirt, phone, access, department, added, last_login) values (?, ?, password(?), ?, ?, ?, ?, ?, ?, ?, ?, ?)");
29 - 137
    		$sth->execute ($F->{RCid}, lc $EM, $F->{password}, $F->{derby_name}, $F->{real_name}, $F->{pronouns}, $F->{tshirt}, $F->{phone}, $F->{access}, $F->{department}, getUser($EM)->{added}, getUser($EM)->{last_login})
7 - 138
    			or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
139
    	} else { # No password was included, just keep the existing one.
140
#    		my $sth = $dbh->prepare("replace into official (RCid, email, password, derby_name, real_name, phone, level, type, access, department, clinic_pass) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
141
#    		$sth->execute($F->{RCid}, $EM, $PWD, $F->{derby_name}, $F->{real_name}, $F->{phone}, $F->{level}, $F->{type}, $F->{access}, $F->{department}, $F->{clinic_pass})
142
    		my $sth = $dbh->prepare("replace into official (RCid, email, password, derby_name, real_name, pronouns, tshirt, phone, access, department, added, last_login) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
29 - 143
    		$sth->execute($F->{RCid}, lc $EM, $PWD, $F->{derby_name}, $F->{real_name}, $F->{pronouns}, $F->{tshirt}, $F->{phone}, $F->{access}, $F->{department}, getUser($EM)->{added}, getUser($EM)->{last_login})
7 - 144
    			or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
145
    	}
146
 
147
			if ($ERRMSG) {
148
				logit ($F->{RCid}, "DB ERROR: Updating Self Details: $ERRMSG");
149
			} else {
150
				logit ($F->{RCid}, "Updated User Details");
151
			}
152
		} elsif ($AL > 1) { # A lead or higher is updating someone else's record
16 - 153
 
154
		  use List::Util qw/sum/;
155
		  if (sum (values %{ convertDepartments ($F->{department}) }) > 0 and $F->{access} == 0) {
156
		    # activating a user for the first time...
157
		    $F->{access} = 1;
158
		    sendEMail ("Activate", $F);
159
		  }
160
 
7 - 161
			if ($FORM->{password}) {
162
#				my $sth = $dbh->prepare ("replace into official (RCid, email, password, derby_name, real_name, phone, level, type, access, department, clinic_pass) values (?, ?, password(?), ?, ?, ?, ?, ?, ?, ?, ?)");
163
#				$sth->execute ($F->{RCid}, $F->{email}, $F->{password}, $F->{derby_name}, $F->{real_name}, $F->{phone}, $F->{level}, $F->{type}, $F->{access}, $F->{department}, $F->{clinic_pass})
164
				my $sth = $dbh->prepare ("replace into official (RCid, email, password, derby_name, real_name, pronouns, tshirt, phone, access, department, added, last_login) values (?, ?, password(?), ?, ?, ?, ?, ?, ?, ?, ?, ?)");
165
				$sth->execute ($F->{RCid}, $F->{email}, $F->{password}, $F->{derby_name}, $F->{real_name}, $F->{pronouns}, $F->{tshirt}, $F->{phone}, $F->{access}, $F->{department}, getUser($F->{email})->{added}, getUser($F->{email})->{last_login})
166
					or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
167
			} else {
168
#				my $sth = $dbh->prepare ("update official set email = ?, derby_name = ?, real_name = ?, phone = ?, level = ?, type = ?, access = ?, department = ?, clinic_pass = ? where RCid = ?");
169
#				$sth->execute ($F->{email}, $F->{derby_name}, $F->{real_name}, $F->{phone}, $F->{level}, $F->{type}, $F->{access}, $F->{department}, $F->{clinic_pass}, $F->{RCid})
170
				my $sth = $dbh->prepare ("update official set email = ?, derby_name = ?, real_name = ?, pronouns = ?, tshirt = ?, phone = ?, access = ?, department = ? where RCid = ?");
171
				$sth->execute ($F->{email}, $F->{derby_name}, $F->{real_name}, $F->{pronouns}, $F->{tshirt}, $F->{phone}, $F->{access}, $F->{department}, $F->{RCid})
172
					or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
173
			}
174
			if ($ERRMSG) {
175
				logit ($F->{RCid}, "DB ERROR: Updating Someone Else: $ERRMSG");
176
			} else {
177
				logit ($F->{RCid}, "Updated User Details (by ".getUser($EM)->{derby_name}.")");
178
				logit (getUser($EM)->{RCid}, "Updated User Details: ".$F->{derby_name}." (".$F->{RCid}.")");
179
			}
180
		} else {
181
			$ERRMSG = "Attempting to update someone else's record, and you don't have permission to do that.";
29 - 182
			logit ($F->{RCid}, "FAIL: ($EM) doesn't have access to update ($F->{email})'s record");
7 - 183
		}
184
	}
185
	$F->{password} = "*******";
186
	$F->{buttons}		= $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{RCid} }).$h->input ({ type=>"submit", name=>"submit", value=>"Edit" });
187
#	my $checked = $F->{clinic_pass} ? "checked" : "";
188
#	$F->{clinic_pass}	= "<INPUT type='checkbox' name='clinic_pass' $checked disabled readonly>";
189
	$F->{department} = convertDepartments ($F->{department});
190
 
191
	display_form ($F->{RCid}, "View");
192
}
193
 
194
sub display_form {
195
  my $RCID = shift // "";
196
  my $view = shift; # // "New User";
197
  my $errors = shift // "";
198
  my $F;
199
 
200
  if ($view eq 'Edit') {
201
  	$cookie_string = authenticate (1);
202
  	my ($EM, $PWD, $AL) = split /&/, $cookie_string;
203
  	$F = getUser ($RCID);
204
  	my $currentuser = getUser ($EM);
205
#  	$currentuser->{department} = convertDepartments ($currentuser->{department});
206
 
207
#  	if (lc $EM eq lc $F->{email} or $AL > 1) {
208
  	if (canView ($currentuser, $F)) {
209
  	  # Editing your own record OR you're a lead/higher
210
  		if (lc $EM eq lc $F->{email} or $currentuser->{access} < $F->{access}) {
211
  		  # If you're editing your own record, or someone who has higher access than you, make access level read-only
212
  			$F->{access}			= $h->input ({ type=>"hidden", name=>"access", value=>$F->{access} }).$AccessLevel->{$F->{access}};
213
  		} else {
214
  			$F->{access}			= $h->select ({ name=>"access" }, [map { $F->{access} == $_ ? $h->option ({ value=>$_, selected=>[] }, $AccessLevel->{$_}) : $h->option ({ value=>$_ }, $AccessLevel->{$_}) } (-1..$currentuser->{access})]);
215
  		}
216
#  		my $checked = $F->{clinic_pass} ? "checked" : "";
217
#  		if ($currentuser->{access} > 2) {
218
#  			$F->{clinic_pass} = "<INPUT type='checkbox' name='clinic_pass' value=$F->{clinic_pass} $checked>";
219
#  		} else {
220
#  			$F->{clinic_pass} = "<INPUT type='checkbox' name='clinic_pass' $checked disabled readonly>";
221
#  		}
222
#  		$F->{email}      = $h->input ({ type=>"text", name=>"email", value=>$F->{email}, readonly=>[] });
223
  		$F->{email}      = $F->{email}.$h->input ({ type=>"hidden", name=>"email", value=>$F->{email} });
224
  		if ($currentuser->{RCid} eq $F->{RCid} or $currentuser->{access} > 4) {
225
  			$F->{password}   = $h->input ({ type=>"password", name=>"password" });
226
  			$F->{derby_name} = $h->input ({ type=>"text", name=>"derby_name", value=>$F->{derby_name} });
227
  			$F->{real_name}  = $h->input ({ type=>"text", name=>"real_name", value=>$F->{real_name} });
228
  			$F->{pronouns}   = $h->input ({ type=>"text", name=>"pronouns", value=>$F->{pronouns} });
229
  			$F->{tshirt}     = $h->select ({ name=>"tshirt" }, [map { $F->{tshirt} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @tshirtOptions] );
230
  			$F->{phone}      = $h->input ({ type=>"text", name=>"phone", value=>$F->{phone} });
231
  		} else {
232
  			$F->{password}   = '*******';
233
  		}
234
#  		$F->{level}      = "<SELECT NAME=level>".selectOptions ($F->{level}, [qw(AA A B C)])."</SELECT>";
235
#  		$F->{type}       = "<SELECT NAME=type>".selectOptions ($F->{type}, [qw(official nso referee)])."</SELECT>";
236
  		$F->{RCid}       = $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{RCid} })."$F->{RCid}&nbsp;";
237
  		$F->{buttons}		 = join " ", $h->input ({ type=>"submit", name=>"submit", value=>"Save" }), $h->input ({ type=>"reset", value=>"Reset" }), $h->input ({ type=>"submit", name=>"submit", value=>"Cancel" });
238
 
239
    	$F->{department} = convertDepartments ($F->{department});
240
    	$currentuser->{department} = convertDepartments ($currentuser->{department});
241
    	foreach my $k (keys %{$depts}) {
29 - 242
    	  next if $k eq "CMP";
7 - 243
    	  if ($currentuser->{access} > 4) {
244
    	    # SysAdmin can change anyone's department level
245
    	    $F->{department}->{$k} = $h->select ({ name=>"DEPT-".$k }, [ $h->option ({ value=>"" }, ""), map { $_ eq $F->{department}->{$k} ? $h->option ({ value=>$_, selected=>[] }, $AccessLevel->{$_}) : $h->option ({ value=>$_ }, $AccessLevel->{$_}) } (0..4) ]);
246
    	  } elsif ($currentuser->{department}->{$k} > 1 and $currentuser->{department}->{$k} > $F->{department}->{$k}) {
247
    	    # Department Leads and above can change someone's level within the dept (up to their own level -1)
248
    	    $F->{department}->{$k} = $h->select ({ name=>"DEPT-".$k }, [ $h->option ({ value=>"" }, ""), map { $_ eq $F->{department}->{$k} ? $h->option ({ value=>$_, selected=>[] }, $AccessLevel->{$_}) : $h->option ({ value=>$_ }, $AccessLevel->{$_}) } (0..$currentuser->{department}->{$k}-1) ]);
249
    	  } else {
250
    	    # Or it's your own record, you can still submit a request to be added to the dept.
251
    	    if (!defined $F->{department}->{$k}) {
252
            $F->{department}->{$k} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$k", value=>0 }), $h->span ({ class=>"slider round" })]);
253
          } elsif ($F->{department}->{$k} == 0) {
254
            $F->{department}->{$k} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$k", value=>0, checked=>[] }), $h->span ({ class=>"slider round" })]);
255
          }
256
    	  }
257
    	}
258
  	} else {
259
  		$ERRMSG = "Attempting to update someone else's record, and you don't have permission to do that.";
260
  	}
261
 
262
  } elsif ($view eq 'New User') {
31 - 263
    $errors .= $h->br."NOTE: You will not be able to login until your account has been reviewed and approved. Watch your email for notification.";
7 - 264
  	# Skip authentication
265
 		$F->{email}      = $h->input ({ type=>"text", name=>"email", value=>$F->{email} });
266
 		$F->{password}   = $h->input ({ type=>"password", name=>"password" });
267
 		$F->{derby_name} = $h->input ({ type=>"text", name=>"derby_name", value=>$F->{derby_name} });
268
 		$F->{real_name}  = $h->input ({ type=>"text", name=>"real_name", value=>$F->{real_name} });
269
		$F->{pronouns}   = $h->input ({ type=>"text", name=>"pronouns", value=>$F->{pronouns} });
270
		$F->{tshirt}     = $h->select ({ name=>"tshirt" }, [map { $F->{tshirt} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @tshirtOptions] );
271
 		$F->{phone}      = $h->input ({ type=>"text", name=>"phone", value=>$F->{phone} });
272
#  	$F->{level}      = "<SELECT NAME=level>".selectOptions ($F->{level}, ["", qw(AA A B C)])."</SELECT>";
273
#  	$F->{type}       = "<SELECT NAME=type>".selectOptions ($F->{type}, ["", qw(official nso referee)])."</SELECT>";
274
 		$F->{RCid}         = $h->input ({ type=>"hidden", name=>"RCid", value=>"New" })."TBD&nbsp;";
275
  	$F->{access}			= $h->input ({ type=>"hidden", name=>"access", value=>0 })."0";
276
#  	$F->{clinic_pass}	= "<INPUT type='checkbox' name='clinic_pass' disabled readonly>";
277
  	foreach (keys %{$depts}) {
29 - 278
  	  next if $_ eq "CMP";
7 - 279
  	  if (defined param ("DEPT-$_")) {
280
  	    $F->{department}->{$_} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$_", value=>0, checked=>[] }), $h->span ({ class=>"slider round" })]);
281
  	  } else {
282
  	    $F->{department}->{$_} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$_", value=>0 }), $h->span ({ class=>"slider round" })]);
283
  	  }
284
  	}
285
  	$F->{buttons}		= $h->input ({ type=>"submit", name=>"submit", value=>"Save" })." ".$h->input ({ type=>"reset", value=>"Reset" })." ".$h->input ({ type=>"submit", name=>"submit", value=>"Cancel" });
286
  	$cookie_string = '';
287
  } elsif ($view eq 'View' or $view eq 'Cancel' or !$view) {
288
  	$cookie_string = authenticate (1);
289
  	my ($EM, $PWD, $AL) = split /&/, $cookie_string;
290
 
291
  	if (!$view) {
292
      $F->{'RCid'} = getUser ($EM)->{'RCid'};
293
  	}
294
 
295
  	# Check to make sure they're only looking up their own ID unless they're a lead or higher
296
  	my $currentuser = getUser ($EM);
297
    my	$targetuser = getUser ($RCID);
298
 
299
  	if (canView ($currentuser, $targetuser)) {
300
    	$F = $targetuser;
301
    	$F->{department} = convertDepartments ($F->{department});
302
      $F->{access} = $AccessLevel->{$F->{access}};
303
    	$F->{'password'} = "*******";
304
      $F->{buttons}		= $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{'RCid'} }).$h->input ({ type=>"submit", name=>"submit", value=>"Edit" });
305
#    	my $checked = $F->{clinic_pass} ? "checked" : "";
306
#    	$F->{clinic_pass}	= "<INPUT type='checkbox' name='clinic_pass' value=$F->{clinic_pass} $checked disabled readonly>";
307
  	} else {
308
  	  logit ($currentuser->{RCid}, "SECURITY: $currentuser->{derby_name} attempted to view another user's ($RCID) info");
309
  	  $errors = "Unauthorized attempt to view another user.  This has been logged.";
310
    	$F->{email}      = "&nbsp;";
311
    	$F->{password}   = "&nbsp;";
312
    	$F->{derby_name} = "&nbsp;";
313
    	$F->{real_name}  = "&nbsp;";
314
    	$F->{pronouns}      = "&nbsp;";
315
    	$F->{tshirt}      = "&nbsp;";
316
    	$F->{phone}      = "&nbsp;";
317
#    	$F->{level}      = "&nbsp;";
318
#    	$F->{type}       = "&nbsp;";
319
    	$F->{RCid}       = "&nbsp;";
320
    	$F->{access}			= "&nbsp;";
321
#    	$F->{clinic_pass}	= "&nbsp;";
322
    	$F->{buttons}		 = "&nbsp;";
323
    }
324
 
325
#  	if (lc $EM eq lc $F->{email} or $AL > 1) {
326
#      $F->{buttons}		= $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{'RCid'} }).$h->input ({ type=>"submit", name=>"submit", value=>"Edit" });
327
#  	} else {
328
#  		$F->{buttons} = "";
329
#  	}
330
  } #else {
331
  #	$cookie_string = authenticate(1);
332
  #	$FORM->{email}      = "&nbsp;";
333
  #	$FORM->{password}   = "&nbsp;";
334
  #	$FORM->{derby_name} = "&nbsp;";
335
  #	$FORM->{real_name}  = "&nbsp;";
336
  #	$FORM->{phone}      = "&nbsp;";
337
  #	$FORM->{level}      = "&nbsp;";
338
  #	$FORM->{type}       = "&nbsp;";
339
  #	$FORM->{RCid}         = "&nbsp;";
340
  #	$FORM->{access}			= "&nbsp;";
341
  #	$FORM->{clinic_pass}	= "&nbsp;";
342
  #	$FORM->{buttons}		= "&nbsp;";
343
  #}
344
 
345
  #---------------START THE HTML--------------------
346
 
347
  my $RCAUTH_cookie = cookie (-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
348
 
349
  print header (-cookie=>$RCAUTH_cookie);
350
 
351
  #foreach (keys %ENV) {
352
  #	print "$_: $ENV{$_}\n<br>";
353
  #}
354
 
355
  if ($errors) {
356
  	$errors = $h->div ({ class=>"error" }, $errors);
357
  } else {
358
  	$errors = "";
359
  }
360
 
8 - 361
  my @printDepartments = ( $h->div ({ class=>"index", style=>"display: unset;" }, $h->p ({ class=>"heading" }, "Department Access:")) );
7 - 362
  foreach (sort grep { !/^PER$/ } keys %{$F->{department}}) {
363
    push @printDepartments, $h->div ({ class=>"rTableRow" }, [
8 - 364
      $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, $depts->{$_}.":", $F->{department}->{$_} =~ /^\d$/ ? $AccessLevel->{$F->{department}->{$_}} : $F->{department}->{$_}),
7 - 365
    ]);
366
  }
367
 
368
  printRCHeader ("User Manager");
369
 
370
  print $errors;
371
  print $h->form ({ action=>url, method=>'POST', name=>'Req' },[
372
    $h->input ({ type=>"hidden", name=>"referer", value=>$goback }),
8 - 373
    $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "User Details:"),
374
      $h->div ({ class=>"rTable", style=>"min-width: 0%;" },[
375
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "User-ID / Email Address: ", $F->{email}) ]),
376
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Password: ",                $F->{password}) ]),
377
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Derby Name: ",              $F->{derby_name}) ]),
378
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Real Name: ",               $F->{real_name}) ]),
379
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Pronouns: ",                $F->{pronouns}) ]),
380
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "TShirt Size: ",             $F->{tshirt}) ]),
381
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Phone: ",                   $F->{phone}) ]),
382
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Database ID: ",             $F->{RCid}) ]),
383
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "User Added: ",              $F->{added}) ]),
384
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Last Login: ",              $F->{last_login}) ]),
385
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "vORC Access Level: ",       $F->{access}) ]),
386
        @printDepartments,
387
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCell" }, "&nbsp;") ]),
388
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr" }, $h->a ({ href=>$goback }, "[go back]"), $F->{buttons}) ])
389
      ])
390
    ])
391
  ]); #  print $h->close('form');
392
  print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Schedule:"), getSchedule ($RCID)]) unless $RCID !~ /^\d+$/;
393
  print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Recent Activity:"), getLog ($RCID)]) unless $RCID !~ /^\d+$/;
7 - 394
  print $h->close ('html');
395
}
396
 
397
#sub selectOptions {
398
#	my $selectedOption = shift;
399
#	my $options = shift;
400
#	return join " ", map { $selectedOption eq $_ ?
401
#	                        $h->option ({ value=>$_, selected=>[] }, $_) :
402
#													$h->option ({ value=>$_ }, $_)
403
#						 					} @$options;
404
#}
405
 
406
sub sendEMail {
407
	my $context = shift;
408
	my $data = shift;
409
	use RCMailer;
410
 
411
	my $email = $data->{email};
29 - 412
	my $subject = 'RollerCon Volunteer Schedule Manager - New User';
16 - 413
	my $body;
414
	if ($context eq "New User") {
29 - 415
    $subject .= " Request";
16 - 416
	  $body = "Greetings,
7 - 417
 
20 - 418
It appears as though you've registered a new account to Volunteer at RollerCon with the following information:
7 - 419
 
420
		Derby Name: $data->{derby_name}
421
		Real Name: 	$data->{real_name}
422
		Pronouns: 	$data->{pronouns}
423
		TShirt Size: $data->{tshirt}
424
		Email Address: $data->{email}
425
		Phone: $data->{phone}
426
 
427
Please be patient while our Admins are reviewing your account request.  Each user is manually approved to help ensure robots, spiders, and shift hoggers don't get in.
428
 
429
YOU WILL NOT BE ABLE TO LOG IN UNTIL YOU RECEIVE ANOTHER EMAIL STATING YOUR ACCOUNT REQUEST HAS BEEN APPROVED!
430
 
431
Once approved, you'll be able to log in and view the schedule and sign up for shifts.  Please be considerate of others and don't hogger all of the shifts.  If you do, we will find you and randomly drop your shifts.
432
 
16 - 433
If you're new to using vORC, you may want to read this:
434
 
435
https://volunteers.rollercon.com/info.html
436
 
7 - 437
If you didn't make this request, well, you're still the only one who received this email, and you now have an account request.  You should probably let us know that someone is messing with you.
438
 
16 - 439
-RollerCon Management
7 - 440
";
16 - 441
  } elsif ($context eq "Activate") {
29 - 442
    $subject .= " Activated!";
16 - 443
    my $tempDepartments = convertDepartments ($data->{department});
444
    my $printableDepartments = join "\n", map { $depts->{$_}.": ".$AccessLevel->{$tempDepartments->{$_}} } sort keys %{$tempDepartments};
445
    $body = "Greetings again,
446
 
447
You have been approved to volunteer at RollerCon in the following departments:
448
 
449
$printableDepartments
450
 
451
You may log into vORC and begin signing up for shifts.  Please be considerate of others and don't hogger all of the shifts.  If you do, we will find you and randomly drop your shifts.
452
 
453
https://volunteers.rollercon.com/schedule/
454
 
455
Please note that you are limited to signing up to a limnited number of shifts per day.  (Meaning, once you sign up for X shifts, you'll have to wait until tomorrow to sign up for more.)  Please understand, while you are a nice, concientious, and good-looking person yourself, who knows how to share, there are others out there that will hogger up all of the shifts.  As time goes by and we get closer to the event, we may lift the limit.  Who knows?
456
 
457
If you've already signed up for your daily limit of shifts, and another shift REALLY strikes your fancy, try dropping one of your shifts.  That should allow you to pick up a different one.
458
 
459
We'll be adding shifts over time, again to throttle how fast some people (not you, mind you) gobble up the shifts.  Check back, maybe even daily.
460
 
461
If you're new to using vORC, you may want to read this:
462
 
463
https://volunteers.rollercon.com/info.html
464
 
465
If you didn't make this request, well, you're still the only one who received this email, and you now have an active account.  You should probably let us know that someone is messing with you.
466
 
467
-RollerCon Management
468
";
469
  } else {
470
    return;
471
  }
7 - 472
	# send the message
473
	EmailUser ($email, $subject, $body);
474
 
475
}
476
 
477
sub checkDupes {
478
  my $field = shift;
479
  my $nametocheck = shift;
480
  my $han = $dbh->prepare("select RCid from official where $field = ?");
481
  $han->execute($nametocheck);
482
  my ($rcid) = $han->fetchrow();
483
  return $rcid;
484
}
485
 
486
sub canView {
487
	my $A = shift // "";
488
	my $B = shift // "";
489
	# Is A a lead or higher of one of B's Depts? (or they're looking at themselves)
490
	# parameters should be a Hashref to the users' details
491
 
492
	return 1 if $A->{access} > 4 or $A->{RCid} == $B->{RCid}; # viewer and target are the same person or it's a SysAdmin.
493
 
494
	my $ADept = convertDepartments $A->{department};
495
	my $BDept = convertDepartments $B->{department};
496
 
497
	foreach (keys %{$BDept}) {
498
		if ($ADept->{$_} > 1) { # A is a Lead or higher of one of B's departments
499
			return 1;
500
		}
501
	}
502
 
503
	return 0;
504
}
505
 
506
sub getLog {
507
  my $RCID = shift;
508
 
509
  my @activity_log;
510
  my $alog = $dbh->prepare("select timestamp, event from v_log where RCid = ? limit 10");
511
  $alog->execute($RCID);
512
  while (my @logs = $alog->fetchrow_array) {
513
  	push @activity_log, $h->li ({ class=>"shaded" }, join " ", @logs);
514
  }
515
 
516
  return $h->ul ([@activity_log]).$h->h5 ($h->a ({ href=>"log.pl?filter-RCid=".$RCID }, "[Entire log history]"));
17 - 517
}