Subversion Repositories VORC

Rev

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

Rev Author Line No. Line
56 bgadell 1
#!/usr/bin/perl
2
 
3
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
4
my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
5
close STDERR;
6
open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
7
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
8
 
9
use strict;
10
use cPanelUserConfig;
11
use RollerCon;
93 bgadell 12
use tableViewer qw/inArray/;
56 bgadell 13
use CGI qw/param cookie header start_html url/;
14
use Email::Valid;
15
use WebDB;
16
use HTML::Tiny;
17
our $h = HTML::Tiny->new( mode => 'html' );
18
 
19
my ($FORM, $cookie_string, $ERRMSG);
20
my @ERRORS;
21
my $dbh = getRCDBH;
22
my $depts = getDepartments (); # HashRef of the department TLAs -> Display Names...
23
my $deptDesc = getDepartmentDescriptions ();
24
my $deptLink = getDepartmentLinks ();
25
my $AccessLevel = getAccessLevels;
26
my @tshirtOptions = ("", "MS", "MM", "ML", "MXL", "M2X", "M3X");
86 bgadell 27
my @AUTODEPTS = map { $_->[0] } @{$dbh->selectall_arrayref ("select TLA from department where autoapprove = true")};
93 bgadell 28
my @FIELDS = qw/ derby_name email real_name phone password access department tshirt pronouns timeformat /;
29
my @PRIVFIELDS = qw/ email access /;
30
$ORCUSER->{department} = ref $ORCUSER->{department} eq "HASH" ? $ORCUSER->{department} : convertDepartments($ORCUSER->{department});
56 bgadell 31
 
93 bgadell 32
 
56 bgadell 33
# The page's form might be submitted as a POST or a GET (or both?)
34
#  The initial _view_ likely comes as a GET request (making it easier to embed in an HREF as a URL)
35
#  Unpack any values sent in the GET and add them to the FORM hash
36
$FORM->{'SUB'} = param ('submit') // '';
37
$FORM->{'RCid'} = param ('RCid') // '';
38
$FORM->{referer} = param ("referer") // "";
39
if ($FORM->{'SUB'} eq '') {
88 bgadell 40
  if ($ENV{'REQUEST_URI'}) {
41
    my ($g, $keep) = split /\?/, $ENV{'REQUEST_URI'};
42
    if ($keep) {
43
      foreach (split /&/, $keep) {
44
        my ($k, $v) = split /=/;
45
        $k =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
46
        $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
47
        $k eq "submit" ? $FORM->{'SUB'} = $v : $FORM->{$k} = $v;
48
      }
49
    }
50
  }
56 bgadell 51
}
52
 
53
# Keep track of the original referrer for the 'back' link/button
54
my $goback;
55
if ($FORM->{referer}) {
88 bgadell 56
  $goback = $FORM->{referer};
56 bgadell 57
} else {
88 bgadell 58
  $goback = $ENV{HTTP_REFERER};
56 bgadell 59
}
60
 
61
 
62
if ($FORM->{'SUB'} eq "Save") {
88 bgadell 63
  process_form ($FORM);
56 bgadell 64
} elsif ($FORM->{'SUB'} eq "New User") {
65
  display_form ("New", "New User"); # blank form
66
} elsif ($FORM->{'RCid'}) {
67
  display_form ($FORM->{'RCid'}, $FORM->{'SUB'});
68
} else {
88 bgadell 69
  $cookie_string = authenticate (1);
70
  my ($EM, $PWD, $AL) = split /&/, $cookie_string;
71
  display_form (getUser ($EM)->{'RCid'}, "View");
56 bgadell 72
}
73
 
74
 
75
sub process_form {
76
  my $F = shift // "";
77
  push @ERRORS, "Tried to save an empty form." and return unless $F;
78
 
88 bgadell 79
  $F->{email}       = lc WebDB::trim param ('email')   // '';
80
  $F->{password}    = WebDB::trim param ('password')   // '';
81
  $F->{derby_name}  = WebDB::trim param ('derby_name') // '';
82
  $F->{real_name}   = WebDB::trim param ('real_name')  // '';
83
  $F->{pronouns}    = WebDB::trim param ('pronouns')   // '';
84
  $F->{tshirt}      = WebDB::trim param ('tshirt')     // '';
85
  $F->{phone}       = WebDB::trim param ('phone')      // '';
86
  $F->{timeformat}  = WebDB::trim param ('timeformat') // '24hr';
87
  $F->{RCid}        = param ('RCid')       // '';
88
  $F->{access}      = param ('access')     // 0;
89
  $F->{department}  = join ":", map { "$_-".param ("DEPT-".$_) } map { s/^DEPT-//; $_ } grep { param ($_) ne "" } grep { /^DEPT-/ } param ;
56 bgadell 90
 
91
  if ($F->{RCid} eq "New") {
92
  # Saving a new User...
93
    # But first let's do some error checking...0
88 bgadell 94
    if (!$F->{password})   { push @ERRORS, "Blank Password!"; }
95
    if (!$F->{real_name})  { push @ERRORS, "Blank Full Name!"; }
96
    if (!$F->{derby_name}) { $F->{derby_name} = $F->{real_name}; } # If they leave derby_name blank, use their real_name
97
    if (checkDupes ('derby_name', $F->{derby_name})) { push @ERRORS, "Derby Name already in use. Pick a different one."; $F->{derby_name} = ""; }
98
    if (!$F->{email})      { push @ERRORS, "Blank Email (User-ID)!"; } else {
99
      $F->{email} =~ s/\s+//g; # make sure people aren't accidentally including spaces
100
      $F->{email} = lc $F->{email}; # sometimes people capitalize their email addresses and that's annoying...
101
      if (! Email::Valid->address (-address => $F->{email}, -mxcheck => 1, -tldcheck => 1)) { push @ERRORS, "Mal-formatted (or fake) Email Address!"; $F->{email} = ""; }
102
    }
103
    if (checkDupes ('email', $F->{email})) { push @ERRORS, "Email Address already in use. Pick a different one."; $F->{email} = ""; }
56 bgadell 104
 
88 bgadell 105
    if (scalar @ERRORS) {
106
      $ERRMSG = join $h->br, @ERRORS;
107
      display_form ("New", "New User", $ERRMSG, $F);
108
    } else {
109
      # We have a correctly formatted email address with a mail host record, go ahead and add the user
110
 
111
      # Check to see if any of the departments they've requested are set to autoapprove.
112
      $F->{department} = convertDepartments $F->{department};
113
      map { $F->{department}->{$_} = inArray ($_, \@AUTODEPTS) } keys %{$F->{department}};
114
      $F->{department} = convertDepartments $F->{department};
115
 
93 bgadell 116
      $dbh->do ("insert into official (email,  password,       derby_name,       real_name,       pronouns,       tshirt,       phone,       timeformat,       access, department, added, activation) values (?, password(?), ?, ?, ?, ?, ?, ?, ?, ?, CONVERT_TZ(now(), 'America/Chicago', 'America/Los_Angeles'), md5(rand()))", undef,
117
                                  $F->{email}, $F->{password}, $F->{derby_name}, $F->{real_name}, $F->{pronouns}, $F->{tshirt}, $F->{phone}, $F->{timeformat}, 0,      $F->{department})
118
        or display_form ("New", "New User", "ERROR: DB: ".$dbh->errstr, $F);
56 bgadell 119
 
94 bgadell 120
      ($F->{RCid}, $F->{activation}) = $dbh->selectrow_array ("select RCid, activation from official where email = ?", undef, $F->{email});
93 bgadell 121
 
88 bgadell 122
      $dbh->do ("replace into RCid_ticket_link select official.RCid, v_ticket.id from official join v_ticket on official.email = v_ticket.email and official.real_name = v_ticket.full_name where official.RCid = ?", undef, $F->{RCid});
123
      logit ($F->{RCid}, "New User Registration");
124
      sendNewUserEMail ("New User", $F);
93 bgadell 125
      $cookie_string = authenticate (RollerCon::USER);
88 bgadell 126
    }
127
  } else {
93 bgadell 128
  # Save changes to an existing user.
129
    $cookie_string = authenticate (RollerCon::USER);
88 bgadell 130
    my ($EM, $PWD, $AL) = split /&/, $cookie_string;
131
 
132
    my $OG = getUser ($F->{RCid});
93 bgadell 133
 
88 bgadell 134
    if ($F->{derby_name} ne $OG->{derby_name} and checkDupes ('derby_name', $F->{derby_name})) { push @ERRORS, "Derby Name already in use. Pick a different one."; $F->{derby_name} = ""; }
135
    if ($F->{email} ne $OG->{email} and checkDupes ('email', $F->{email})) { push @ERRORS, "Email Address already in use. Pick a different one."; $F->{email} = ""; }
136
    if (!$F->{real_name})  { push @ERRORS, "Blank Full Name!"; }
93 bgadell 137
 
88 bgadell 138
    if (scalar @ERRORS) {
139
      $ERRMSG = join $h->br, @ERRORS;
140
      display_form ($F->{RCid}, "Edit", $ERRMSG, $F);
141
    }
142
 
93 bgadell 143
 
144
 
145
    if ($ORCUSER->{RCid} == $F->{RCid} or $AL >= RollerCon::SYSADMIN) {
146
    # They're editing their own record (or a sysadmin).
56 bgadell 147
 
93 bgadell 148
      my $DBDepts = $OG->{department};
149
      if ($F->{department} ne $DBDepts and $AL < RollerCon::SYSADMIN) {
88 bgadell 150
        # They're trying to change one of their own departments.
151
        my $FORMDepts = convertDepartments $F->{department};
152
        $DBDepts =   convertDepartments $DBDepts;
56 bgadell 153
        # the only change to a dept should be a request to be added, some depts are auto-approved.
88 bgadell 154
        map { $FORMDepts->{$_} = inArray ($_, \@AUTODEPTS) } keys %{$FORMDepts};
56 bgadell 155
        # or they can retract their request
88 bgadell 156
        map { do { delete $DBDepts->{$_} } if $DBDepts->{$_} == 0 and !defined $FORMDepts->{$_} } keys %{$DBDepts};
157
        # otherwise, keep the same depts as are in the DB (or have been auto-approved...)
158
        map { $FORMDepts->{$_} = max ($DBDepts->{$_}, $FORMDepts->{$_}) } keys %{$DBDepts};
159
        $F->{department} = convertDepartments $FORMDepts;
160
      }
56 bgadell 161
 
93 bgadell 162
      foreach my $field (@FIELDS) {
103 bgadell 163
        if ($F->{$field} eq $OG->{$field} or $F->{$field} == $OG->{$field} or ($field eq "password" and !$F->{$field})) {
93 bgadell 164
          # No changes to this field, move on...
165
          next;
166
        }
167
 
168
        if ($AL < RollerCon::SYSADMIN and inArray ($field, \@PRIVFIELDS)) {
169
          push @ERRORS, "ERROR: Only SysAdmins are allowed to change the $field field";
170
          logit ($F->{RCid}, "SECURITY: Only SysAdmins are allowed to change the $field field");
171
          next;
172
        }
173
 
174
        # warn "Changing $field: $F->{$field}";
175
        if (my $err = changeUser ($F->{RCid}, $field, $F->{$field})) {
176
          push @ERRORS, $err;
177
          logit ($F->{RCid}, "DB ERROR: Updating User Details: $err");
178
        }
88 bgadell 179
      }
56 bgadell 180
 
93 bgadell 181
 
88 bgadell 182
    } else {
93 bgadell 183
      push @ERRORS, "Attempting to update someone else's record, and you don't have permission to do that.";
184
      logit ($ORCUSER->{RCid}, "FAIL: You don't have access to update other people's user record");
88 bgadell 185
    }
186
  }
187
  $F->{password} = "*******";
188
  $F->{buttons}   = $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{RCid} }).$h->input ({ type=>"submit", name=>"submit", value=>"Edit" });
189
  $F->{department} = convertDepartments ($F->{department});
190
  $dbh->do ("replace into RCid_ticket_link select official.RCid, v_ticket.id from official join v_ticket on official.email = v_ticket.email and official.real_name = v_ticket.full_name where official.RCid = ?", undef, $F->{RCid});
56 bgadell 191
 
93 bgadell 192
  if (scalar @ERRORS) {
193
    $ERRMSG = join $h->br, @ERRORS;
194
  }
195
 
196
  display_form ($F->{RCid}, "View", $ERRMSG);
56 bgadell 197
}
198
 
199
sub display_form {
200
  my $RCID = shift // "";
201
  my $view = shift; # // "New User";
202
  my $errors = shift // "";
203
  my $F = shift; # // "";
204
 
205
  if ($view eq 'Edit') {
93 bgadell 206
    $cookie_string = authenticate (RollerCon::USER);
88 bgadell 207
    my ($EM, $PWD, $AL) = split /&/, $cookie_string;
208
    $F = getUser ($RCID);
209
 
93 bgadell 210
    if (canView ($ORCUSER, $F)) {
88 bgadell 211
      # Editing your own record OR you're a lead/higher
93 bgadell 212
      if (lc $EM eq lc $F->{email} or $ORCUSER->{access} < $F->{access}) {
88 bgadell 213
        # If you're editing your own record, or someone who has higher access than you, make access level read-only
214
        $F->{access}      = $h->input ({ type=>"hidden", name=>"access", value=>$F->{access} }).$AccessLevel->{$F->{access}};
215
      } else {
93 bgadell 216
        $F->{access}      = $h->select ({ name=>"access" }, [map { $F->{access} == $_ ? $h->option ({ value=>$_, selected=>[] }, $AccessLevel->{$_}) : $h->option ({ value=>$_ }, $AccessLevel->{$_}) } (-1..$ORCUSER->{access})]);
88 bgadell 217
      }
93 bgadell 218
      if ($ORCUSER->{access} >= RollerCon::MANAGER) {
219
        #this would be the place to test for other types of managers that can update the MVP Pass setting
58 bgadell 220
        if ($F->{MVPid}) {
221
          $F->{MVPid} .= "->link to change...<-";
222
        }
88 bgadell 223
      } else {
224
      }
93 bgadell 225
      if ($AL == RollerCon::SYSADMIN) {
88 bgadell 226
        $F->{email}      = $h->input ({ type=>"text", name=>"email", value=>$F->{email} });
227
      } else {
228
        $F->{email}      = $F->{email}.$h->input ({ type=>"hidden", name=>"email", value=>$F->{email} });
229
      }
93 bgadell 230
      if ($ORCUSER->{RCid} eq $F->{RCid} or $ORCUSER->{access} >= RollerCon::SYSADMIN) {
88 bgadell 231
        $F->{password}   = $h->input ({ type=>"password", name=>"password" });
232
        $F->{derby_name} = $h->input ({ type=>"text", name=>"derby_name", value=>$F->{derby_name} });
233
        $F->{real_name}  = $h->input ({ type=>"text", name=>"real_name", value=>$F->{real_name} });
234
        $F->{pronouns}   = $h->input ({ type=>"text", name=>"pronouns", value=>$F->{pronouns} });
235
        $F->{tshirt}     = $h->select ({ name=>"tshirt" }, [map { $F->{tshirt} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @tshirtOptions] );
236
        $F->{phone}      = $h->input ({ type=>"text", name=>"phone", value=>$F->{phone} });
237
        $F->{timeformat} = $h->select ({ name=>"timeformat" }, [map { $F->{timeformat} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } qw(24hr ampm)] );
238
      } else {
239
        $F->{password}   = '*******';
240
      }
241
      $F->{RCid}       = $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{RCid} })."$F->{RCid}&nbsp;";
242
      $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" });
243
 
244
      $F->{department} = convertDepartments ($F->{department});
245
      foreach my $k (keys %{$depts}) {
246
        next if $k eq "CMP";
93 bgadell 247
        if ($ORCUSER->{access} > 4) {
88 bgadell 248
          # SysAdmin can change anyone's department level
249
          $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) ]);
93 bgadell 250
        } elsif ($ORCUSER->{department}->{$k} > 1 and $ORCUSER->{department}->{$k} > $F->{department}->{$k}) {
88 bgadell 251
          # Department Leads and above can change someone's level within the dept (up to their own level -1)
93 bgadell 252
          $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..$ORCUSER->{department}->{$k}-1) ]);
88 bgadell 253
        } else {
254
          # Or it's your own record, you can still submit a request to be added to the dept.
255
          if (!defined $F->{department}->{$k}) {
86 bgadell 256
            $F->{department}->{$k} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$k", value=>0 }), $h->span ({ class=>"slider round" })]) unless !inArray ($k, \@AUTODEPTS);
56 bgadell 257
          } elsif ($F->{department}->{$k} == 0) {
88 bgadell 258
            $F->{department}->{$k} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$k", value=>0, checked=>[] }), $h->span ({ class=>"slider round" })]);
56 bgadell 259
          }
88 bgadell 260
        }
261
      }
262
    } else {
263
      $ERRMSG = "Attempting to update someone else's record, and you don't have permission to do that.";
264
    }
56 bgadell 265
 
266
  } elsif ($view eq 'New User') {
93 bgadell 267
    $errors .= $h->br."NOTE: You will not be able to login until your account has been activated. Watch your email for further instructions.";
88 bgadell 268
    # Skip authentication
269
    $F->{email}      = $h->input ({ type=>"text", name=>"email", value=>$F->{email} });
270
    $F->{password}   = $h->input ({ type=>"password", name=>"password" });
271
    $F->{derby_name} = $h->input ({ type=>"text", name=>"derby_name", value=>$F->{derby_name} });
272
    $F->{real_name}  = $h->input ({ type=>"text", name=>"real_name", value=>$F->{real_name} });
273
    $F->{pronouns}   = $h->input ({ type=>"text", name=>"pronouns", value=>$F->{pronouns} });
274
    $F->{tshirt}     = $h->select ({ name=>"tshirt" }, [map { $F->{tshirt} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @tshirtOptions] );
275
    $F->{phone}      = $h->input ({ type=>"text", name=>"phone", value=>$F->{phone} });
276
    $F->{timeformat} = $h->select ({ name=>"timeformat" }, [map { $F->{timeformat} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } qw(24hr ampm)] );
277
    $F->{RCid}         = $h->input ({ type=>"hidden", name=>"RCid", value=>"New" })."TBD&nbsp;";
278
    $F->{access}      = $h->input ({ type=>"hidden", name=>"access", value=>0 })."0";
56 bgadell 279
 
280
    $F->{department} = convertDepartments ($F->{department});
88 bgadell 281
    foreach (sort keys %{$depts}) {
282
      next if $_ eq "CMP";
283
      next unless inArray($_, \@AUTODEPTS);
284
      if (defined param ("DEPT-$_")) {
285
        $F->{department}->{$_} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$_", value=>0, checked=>[] }), $h->span ({ class=>"slider round" })]);
286
      } else {
287
        $F->{department}->{$_} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$_", value=>0 }), $h->span ({ class=>"slider round" })]);
288
      }
289
    }
290
    $F->{buttons}   = $h->input ({ type=>"submit", name=>"submit", value=>"Save" })." ".$h->input ({ type=>"reset", value=>"Reset" })." ".$h->input ({ type=>"submit", name=>"submit", value=>"Cancel" });
291
    $cookie_string = '';
56 bgadell 292
  } elsif ($view eq 'View' or $view eq 'Cancel' or !$view) {
88 bgadell 293
    $cookie_string = authenticate (1);
294
    my ($EM, $PWD, $AL) = split /&/, $cookie_string;
56 bgadell 295
 
88 bgadell 296
    if (!$view) {
56 bgadell 297
      $F->{'RCid'} = getUser ($EM)->{'RCid'};
88 bgadell 298
    }
56 bgadell 299
 
88 bgadell 300
    # Check to make sure they're only looking up their own ID unless they're a lead or higher
301
    my  $targetuser = getUser ($RCID);
56 bgadell 302
 
93 bgadell 303
    if (canView ($ORCUSER, $targetuser)) {
88 bgadell 304
      $F = $targetuser;
305
      $F->{department} = convertDepartments ($F->{department});
56 bgadell 306
      $F->{access} = $AccessLevel->{$F->{access}};
88 bgadell 307
      $F->{'password'} = "*******";
308
      $F->{buttons}   = $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{'RCid'} }).$h->input ({ type=>"submit", name=>"submit", value=>"Edit" });
71 bgadell 309
 
93 bgadell 310
      if ($ORCUSER->{access} > 2 or ($ORCUSER->{department} and $ORCUSER->{department}->{MVP} >= 2)) {
58 bgadell 311
        if($F->{MVPid}) {
312
          $F->{MVPid} .= '&nbsp;&nbsp;' . $h->button ({ onClick=>"window.open('update_mvp_ticket.pl?change=Delete&RCid=$F->{RCid}&MVPid=$F->{MVPid}','Change MVP Ticket','resizable,height=260,width=370'); return false;" }, "Delete Match");
313
        } else {
314
          $F->{MVPid} .= $h->button ({ onClick=>"window.open('update_mvp_ticket.pl?change=lookup&RCid=$F->{RCid}','Change MVP Ticket','resizable,height=260,width=370'); return false;" }, "Manual Match");
315
          my $possible_matches = $dbh->selectall_arrayref ("select id, full_name from v_ticket where isnull(RCid) = true and email = (select email from official where RCid = ?) union
316
            select id, full_name from v_ticket where isnull(RCid) = true and full_name = (select real_name from official where RCid = ?) union
317
            select id, full_name from v_ticket where isnull(RCid) = true and derby_name = (select derby_name from official where RCid = ?)", undef, $F->{RCid}, $F->{RCid}, $F->{RCid});
318
 
319
          foreach my $match (@$possible_matches) {
320
            my ($MVPid, $fullname) = @$match;
71 bgadell 321
 
58 bgadell 322
            $F->{MVPid} .= $h->div ({ class => "hint" }, ["Possible Match: @$match", '&nbsp;&nbsp;', $h->button ({ onClick=>"window.open('update_mvp_ticket.pl?change=add&RCid=$F->{RCid}&MVPid=$MVPid','Change MVP Ticket','resizable,height=260,width=370'); return false;" }, "Accept Match")]);
323
          }
324
        }
325
      }
88 bgadell 326
    } else {
93 bgadell 327
      logit ($ORCUSER->{RCid}, "SECURITY: $ORCUSER->{derby_name} attempted to view another user's ($RCID) info");
88 bgadell 328
      $errors = "Unauthorized attempt to view another user.  This has been logged.";
93 bgadell 329
      $RCID = "";
88 bgadell 330
      $F->{email}      = "&nbsp;";
331
      $F->{password}   = "&nbsp;";
332
      $F->{derby_name} = "&nbsp;";
333
      $F->{real_name}  = "&nbsp;";
334
      $F->{pronouns}   = "&nbsp;";
335
      $F->{tshirt}     = "&nbsp;";
336
      $F->{phone}      = "&nbsp;";
337
      $F->{timeformat} = "&nbsp;";
338
      $F->{RCid}       = "&nbsp;";
339
      $F->{access}     = "&nbsp;";
340
      $F->{MVPid}      = "&nbsp;";
341
      $F->{buttons}    = "&nbsp;";
56 bgadell 342
    }
343
 
93 bgadell 344
  }
56 bgadell 345
 
346
  #---------------START THE HTML--------------------
347
 
348
  my $RCAUTH_cookie = cookie (-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
349
 
350
  print header (-cookie=>$RCAUTH_cookie);
351
 
352
  #foreach (keys %ENV) {
93 bgadell 353
  # warn "$_: $ENV{$_}\n<br>";
56 bgadell 354
  #}
355
 
356
  if ($errors) {
88 bgadell 357
    $errors = $h->div ({ class=>"error" }, $errors);
56 bgadell 358
  } else {
88 bgadell 359
    $errors = "";
56 bgadell 360
  }
361
 
58 bgadell 362
   my @printDepartments = ( $h->div ({ class=>"index", style=>"display: unset;" }, $h->p ({ class=>"heading" }, "Volunteer Department Access:")) );
56 bgadell 363
  push @printDepartments, $h->div ({ class=>"rTableRowSpan" },[ $h->div ({ style=>"rTableCellr" }, $h->div ({ class=>"hint" }, "Here is where you're signed up to volunteer at RollerCon:")) ]);
364
  foreach (sort grep { !/^PER$/ } keys %{$F->{department}}) {
365
    push @printDepartments, $h->div ({ class=>"rTableRow" }, [
366
      $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" },
367
        [ $h->span ({ class=>"tooltip-wrap" }, [$h->img ({src=>"/images/qm.png", width=>"18", height=>"18"}), $h->div ({ class=>"tooltip-content" }, $h->div ({class=>"bold"}, $depts->{$_}).$deptDesc->{$_} . (exists $deptLink->{$_} ? $h->a ({ href=>$deptLink->{$_}, target=>"_new"}, " [More Info]") : "") )]), $depts->{$_}.":" ],
368
        $F->{department}->{$_} =~ /^\d$/ ? $AccessLevel->{$F->{department}->{$_}} : $F->{department}->{$_}),
369
    ]);
370
  }
371
 
372
  printRCHeader ("User Manager");
373
 
374
  print $errors;
375
  print $h->form ({ action=>url, method=>'POST', name=>'Req' },[
376
    $h->input ({ type=>"hidden", name=>"referer", value=>$goback }),
377
    $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "User Details:"),
378
      $h->div ({ class=>"rTable", style=>"min-width: 0%;" },[
379
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "User-ID / Email Address: ", $F->{email}) ]),
380
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Password: ",                $F->{password}) ]),
381
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Derby Name: ",              $F->{derby_name}) ]),
58 bgadell 382
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Full Name: ",               $F->{real_name}) ]),
56 bgadell 383
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Pronouns: ",                $F->{pronouns}) ]),
384
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "TShirt Size: ",             $F->{tshirt}) ]),
385
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Phone: ",                   $F->{phone}) ]),
386
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Time Format: ",       $F->{timeformat}) ]),
387
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Database ID: ",             $F->{RCid}) ]),
388
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "User Added: ",              $F->{added}) ]),
389
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Last Login: ",              $F->{last_login}) ]),
390
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "vORC Access Level: ",       $F->{access}) ]),
58 bgadell 391
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "MVP Pass: ",                $F->{MVPid}) ]),
56 bgadell 392
        @printDepartments,
393
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCell" }, "&nbsp;") ]),
394
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr" }, $h->a ({ href=>$goback }, "[go back]"), $F->{buttons}) ])
395
      ])
396
    ])
93 bgadell 397
  ]);
56 bgadell 398
  print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Schedule:"), getSchedule ($RCID, "all")]) unless $RCID !~ /^\d+$/;
399
  print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Recent Activity:"), getLog ($RCID)]) unless $RCID !~ /^\d+$/;
400
  print $h->close ('html');
93 bgadell 401
  exit;
56 bgadell 402
}
403
 
404
 
405
sub checkDupes {
406
  my $field = shift;
407
  my $nametocheck = shift;
408
  my $han = $dbh->prepare("select RCid from official where $field = ?");
409
  $han->execute($nametocheck);
410
  my ($rcid) = $han->fetchrow();
411
  return $rcid;
412
}
413
 
414
sub getLog {
415
  my $RCID = shift;
416
 
417
  my @activity_log;
418
  my $alog = $dbh->prepare("select timestamp, event from v_log where RCid = ? limit 10");
419
  $alog->execute($RCID);
420
  while (my @logs = $alog->fetchrow_array) {
88 bgadell 421
    push @activity_log, $h->li ({ class=>"shaded" }, join " ", @logs);
56 bgadell 422
  }
423
 
424
  return $h->ul ([@activity_log]).$h->h5 ($h->a ({ href=>"log.pl?filter-RCid=".$RCID }, "[Entire log history]"));
425
}
426
 
427
sub getDepartmentDescriptions {
88 bgadell 428
  my %HASH;
429
  my $sth = $dbh->prepare("select TLA, description from department");
430
  $sth->execute();
431
  while (my ($tla, $name) = $sth->fetchrow) {
432
    $HASH{$tla} = $name;
56 bgadell 433
  }
434
  return \%HASH;
435
}
436
 
437
sub getDepartmentLinks {
88 bgadell 438
  my %HASH;
439
  my $sth = $dbh->prepare("select TLA, link from department where link <> ''");
440
  $sth->execute();
441
  while (my ($tla, $name) = $sth->fetchrow) {
442
    $HASH{$tla} = $name;
56 bgadell 443
  }
444
  return \%HASH;
445
}
93 bgadell 446
 
447
sub changeUser {
448
  my ($uid, $field, $newvalue) = @_;
449
 
450
  return "ERROR: Bad (or missing) RCid: [$uid]" unless $uid =~ /^\d+$/;
451
  return "ERROR: Bad (or missing) field name: [$field]" unless $field;
452
#  return "ERROR: Bad (or missing) new value: [$newvalue]" unless $newvalue;
453
  return "ERROR: Can't change someone's RCid" if $field eq "RCid";
454
 
455
  if ($field eq "password") {
456
    return unless $newvalue;
457
    $dbh->do ("update official set password = password(?) where RCid = ?", undef, $newvalue, $uid) or return "ERROR: ".$dbh->errstr;
458
  } else {
459
    $dbh->do ("update official set $field = ? where RCid = ?", undef, $newvalue, $uid) or return "ERROR: ".$dbh->errstr;
460
  }
461
 
462
  $newvalue = '********' if $field eq "password";
463
  if ($ORCUSER->{RCid} eq $uid) {
464
    logit ($uid, "Updated Profile: $field -> $newvalue");
465
  } else {
466
    logit ($ORCUSER->{RCid}, "Updated User [$uid]: $field -> $newvalue");
467
    logit ($uid, "$ORCUSER->{derby_name} updated your profile: $field -> $newvalue");
468
  }
469
 
470
  return;
471
}