Subversion Repositories VORC

Rev

Rev 103 | Rev 112 | 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} = ""; }
105 bgadell 135
    if (!$F->{derby_name}) { push @ERRORS, "Blank Derby Name!"; }
88 bgadell 136
    if ($F->{email} ne $OG->{email} and checkDupes ('email', $F->{email})) { push @ERRORS, "Email Address already in use. Pick a different one."; $F->{email} = ""; }
137
    if (!$F->{real_name})  { push @ERRORS, "Blank Full Name!"; }
93 bgadell 138
 
88 bgadell 139
    if (scalar @ERRORS) {
140
      $ERRMSG = join $h->br, @ERRORS;
141
      display_form ($F->{RCid}, "Edit", $ERRMSG, $F);
142
    }
143
 
93 bgadell 144
 
145
 
146
    if ($ORCUSER->{RCid} == $F->{RCid} or $AL >= RollerCon::SYSADMIN) {
147
    # They're editing their own record (or a sysadmin).
56 bgadell 148
 
93 bgadell 149
      my $DBDepts = $OG->{department};
150
      if ($F->{department} ne $DBDepts and $AL < RollerCon::SYSADMIN) {
88 bgadell 151
        # They're trying to change one of their own departments.
152
        my $FORMDepts = convertDepartments $F->{department};
153
        $DBDepts =   convertDepartments $DBDepts;
56 bgadell 154
        # the only change to a dept should be a request to be added, some depts are auto-approved.
88 bgadell 155
        map { $FORMDepts->{$_} = inArray ($_, \@AUTODEPTS) } keys %{$FORMDepts};
56 bgadell 156
        # or they can retract their request
88 bgadell 157
        map { do { delete $DBDepts->{$_} } if $DBDepts->{$_} == 0 and !defined $FORMDepts->{$_} } keys %{$DBDepts};
158
        # otherwise, keep the same depts as are in the DB (or have been auto-approved...)
159
        map { $FORMDepts->{$_} = max ($DBDepts->{$_}, $FORMDepts->{$_}) } keys %{$DBDepts};
160
        $F->{department} = convertDepartments $FORMDepts;
161
      }
56 bgadell 162
 
93 bgadell 163
      foreach my $field (@FIELDS) {
105 bgadell 164
        if ($F->{$field} eq $OG->{$field} or ($field eq "access" and $F->{$field} == $OG->{$field}) or ($field eq "password" and !$F->{$field})) {
93 bgadell 165
          # No changes to this field, move on...
166
          next;
167
        }
168
 
169
        if ($AL < RollerCon::SYSADMIN and inArray ($field, \@PRIVFIELDS)) {
170
          push @ERRORS, "ERROR: Only SysAdmins are allowed to change the $field field";
171
          logit ($F->{RCid}, "SECURITY: Only SysAdmins are allowed to change the $field field");
172
          next;
173
        }
174
 
175
        # warn "Changing $field: $F->{$field}";
176
        if (my $err = changeUser ($F->{RCid}, $field, $F->{$field})) {
177
          push @ERRORS, $err;
178
          logit ($F->{RCid}, "DB ERROR: Updating User Details: $err");
179
        }
88 bgadell 180
      }
56 bgadell 181
 
93 bgadell 182
 
88 bgadell 183
    } else {
93 bgadell 184
      push @ERRORS, "Attempting to update someone else's record, and you don't have permission to do that.";
185
      logit ($ORCUSER->{RCid}, "FAIL: You don't have access to update other people's user record");
88 bgadell 186
    }
187
  }
188
  $F->{password} = "*******";
189
  $F->{buttons}   = $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{RCid} }).$h->input ({ type=>"submit", name=>"submit", value=>"Edit" });
190
  $F->{department} = convertDepartments ($F->{department});
191
  $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 192
 
93 bgadell 193
  if (scalar @ERRORS) {
194
    $ERRMSG = join $h->br, @ERRORS;
195
  }
196
 
197
  display_form ($F->{RCid}, "View", $ERRMSG);
56 bgadell 198
}
199
 
200
sub display_form {
201
  my $RCID = shift // "";
202
  my $view = shift; # // "New User";
203
  my $errors = shift // "";
204
  my $F = shift; # // "";
205
 
206
  if ($view eq 'Edit') {
93 bgadell 207
    $cookie_string = authenticate (RollerCon::USER);
88 bgadell 208
    my ($EM, $PWD, $AL) = split /&/, $cookie_string;
209
    $F = getUser ($RCID);
210
 
93 bgadell 211
    if (canView ($ORCUSER, $F)) {
88 bgadell 212
      # Editing your own record OR you're a lead/higher
93 bgadell 213
      if (lc $EM eq lc $F->{email} or $ORCUSER->{access} < $F->{access}) {
88 bgadell 214
        # If you're editing your own record, or someone who has higher access than you, make access level read-only
215
        $F->{access}      = $h->input ({ type=>"hidden", name=>"access", value=>$F->{access} }).$AccessLevel->{$F->{access}};
216
      } else {
93 bgadell 217
        $F->{access}      = $h->select ({ name=>"access" }, [map { $F->{access} == $_ ? $h->option ({ value=>$_, selected=>[] }, $AccessLevel->{$_}) : $h->option ({ value=>$_ }, $AccessLevel->{$_}) } (-1..$ORCUSER->{access})]);
88 bgadell 218
      }
93 bgadell 219
      if ($ORCUSER->{access} >= RollerCon::MANAGER) {
220
        #this would be the place to test for other types of managers that can update the MVP Pass setting
58 bgadell 221
        if ($F->{MVPid}) {
222
          $F->{MVPid} .= "->link to change...<-";
223
        }
88 bgadell 224
      } else {
225
      }
93 bgadell 226
      if ($AL == RollerCon::SYSADMIN) {
88 bgadell 227
        $F->{email}      = $h->input ({ type=>"text", name=>"email", value=>$F->{email} });
228
      } else {
229
        $F->{email}      = $F->{email}.$h->input ({ type=>"hidden", name=>"email", value=>$F->{email} });
230
      }
93 bgadell 231
      if ($ORCUSER->{RCid} eq $F->{RCid} or $ORCUSER->{access} >= RollerCon::SYSADMIN) {
88 bgadell 232
        $F->{password}   = $h->input ({ type=>"password", name=>"password" });
233
        $F->{derby_name} = $h->input ({ type=>"text", name=>"derby_name", value=>$F->{derby_name} });
234
        $F->{real_name}  = $h->input ({ type=>"text", name=>"real_name", value=>$F->{real_name} });
235
        $F->{pronouns}   = $h->input ({ type=>"text", name=>"pronouns", value=>$F->{pronouns} });
236
        $F->{tshirt}     = $h->select ({ name=>"tshirt" }, [map { $F->{tshirt} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @tshirtOptions] );
237
        $F->{phone}      = $h->input ({ type=>"text", name=>"phone", value=>$F->{phone} });
238
        $F->{timeformat} = $h->select ({ name=>"timeformat" }, [map { $F->{timeformat} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } qw(24hr ampm)] );
239
      } else {
240
        $F->{password}   = '*******';
241
      }
242
      $F->{RCid}       = $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{RCid} })."$F->{RCid}&nbsp;";
243
      $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" });
244
 
245
      $F->{department} = convertDepartments ($F->{department});
246
      foreach my $k (keys %{$depts}) {
247
        next if $k eq "CMP";
93 bgadell 248
        if ($ORCUSER->{access} > 4) {
88 bgadell 249
          # SysAdmin can change anyone's department level
250
          $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 251
        } elsif ($ORCUSER->{department}->{$k} > 1 and $ORCUSER->{department}->{$k} > $F->{department}->{$k}) {
88 bgadell 252
          # Department Leads and above can change someone's level within the dept (up to their own level -1)
93 bgadell 253
          $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 254
        } else {
255
          # Or it's your own record, you can still submit a request to be added to the dept.
256
          if (!defined $F->{department}->{$k}) {
86 bgadell 257
            $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 258
          } elsif ($F->{department}->{$k} == 0) {
88 bgadell 259
            $F->{department}->{$k} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$k", value=>0, checked=>[] }), $h->span ({ class=>"slider round" })]);
56 bgadell 260
          }
88 bgadell 261
        }
262
      }
263
    } else {
264
      $ERRMSG = "Attempting to update someone else's record, and you don't have permission to do that.";
265
    }
56 bgadell 266
 
267
  } elsif ($view eq 'New User') {
93 bgadell 268
    $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 269
    # Skip authentication
270
    $F->{email}      = $h->input ({ type=>"text", name=>"email", value=>$F->{email} });
271
    $F->{password}   = $h->input ({ type=>"password", name=>"password" });
272
    $F->{derby_name} = $h->input ({ type=>"text", name=>"derby_name", value=>$F->{derby_name} });
273
    $F->{real_name}  = $h->input ({ type=>"text", name=>"real_name", value=>$F->{real_name} });
274
    $F->{pronouns}   = $h->input ({ type=>"text", name=>"pronouns", value=>$F->{pronouns} });
275
    $F->{tshirt}     = $h->select ({ name=>"tshirt" }, [map { $F->{tshirt} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @tshirtOptions] );
276
    $F->{phone}      = $h->input ({ type=>"text", name=>"phone", value=>$F->{phone} });
277
    $F->{timeformat} = $h->select ({ name=>"timeformat" }, [map { $F->{timeformat} eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } qw(24hr ampm)] );
278
    $F->{RCid}         = $h->input ({ type=>"hidden", name=>"RCid", value=>"New" })."TBD&nbsp;";
279
    $F->{access}      = $h->input ({ type=>"hidden", name=>"access", value=>0 })."0";
56 bgadell 280
 
281
    $F->{department} = convertDepartments ($F->{department});
88 bgadell 282
    foreach (sort keys %{$depts}) {
283
      next if $_ eq "CMP";
284
      next unless inArray($_, \@AUTODEPTS);
285
      if (defined param ("DEPT-$_")) {
286
        $F->{department}->{$_} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$_", value=>0, checked=>[] }), $h->span ({ class=>"slider round" })]);
287
      } else {
288
        $F->{department}->{$_} = $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>"DEPT-$_", value=>0 }), $h->span ({ class=>"slider round" })]);
289
      }
290
    }
291
    $F->{buttons}   = $h->input ({ type=>"submit", name=>"submit", value=>"Save" })." ".$h->input ({ type=>"reset", value=>"Reset" })." ".$h->input ({ type=>"submit", name=>"submit", value=>"Cancel" });
292
    $cookie_string = '';
56 bgadell 293
  } elsif ($view eq 'View' or $view eq 'Cancel' or !$view) {
88 bgadell 294
    $cookie_string = authenticate (1);
295
    my ($EM, $PWD, $AL) = split /&/, $cookie_string;
56 bgadell 296
 
88 bgadell 297
    if (!$view) {
56 bgadell 298
      $F->{'RCid'} = getUser ($EM)->{'RCid'};
88 bgadell 299
    }
56 bgadell 300
 
88 bgadell 301
    # Check to make sure they're only looking up their own ID unless they're a lead or higher
302
    my  $targetuser = getUser ($RCID);
56 bgadell 303
 
93 bgadell 304
    if (canView ($ORCUSER, $targetuser)) {
88 bgadell 305
      $F = $targetuser;
306
      $F->{department} = convertDepartments ($F->{department});
56 bgadell 307
      $F->{access} = $AccessLevel->{$F->{access}};
88 bgadell 308
      $F->{'password'} = "*******";
309
      $F->{buttons}   = $h->input ({ type=>"hidden", name=>"RCid", value=>$F->{'RCid'} }).$h->input ({ type=>"submit", name=>"submit", value=>"Edit" });
71 bgadell 310
 
93 bgadell 311
      if ($ORCUSER->{access} > 2 or ($ORCUSER->{department} and $ORCUSER->{department}->{MVP} >= 2)) {
58 bgadell 312
        if($F->{MVPid}) {
313
          $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");
314
        } else {
315
          $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");
316
          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
317
            select id, full_name from v_ticket where isnull(RCid) = true and full_name = (select real_name from official where RCid = ?) union
318
            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});
319
 
320
          foreach my $match (@$possible_matches) {
321
            my ($MVPid, $fullname) = @$match;
71 bgadell 322
 
58 bgadell 323
            $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")]);
324
          }
325
        }
326
      }
88 bgadell 327
    } else {
93 bgadell 328
      logit ($ORCUSER->{RCid}, "SECURITY: $ORCUSER->{derby_name} attempted to view another user's ($RCID) info");
88 bgadell 329
      $errors = "Unauthorized attempt to view another user.  This has been logged.";
93 bgadell 330
      $RCID = "";
88 bgadell 331
      $F->{email}      = "&nbsp;";
332
      $F->{password}   = "&nbsp;";
333
      $F->{derby_name} = "&nbsp;";
334
      $F->{real_name}  = "&nbsp;";
335
      $F->{pronouns}   = "&nbsp;";
336
      $F->{tshirt}     = "&nbsp;";
337
      $F->{phone}      = "&nbsp;";
338
      $F->{timeformat} = "&nbsp;";
339
      $F->{RCid}       = "&nbsp;";
340
      $F->{access}     = "&nbsp;";
341
      $F->{MVPid}      = "&nbsp;";
342
      $F->{buttons}    = "&nbsp;";
56 bgadell 343
    }
344
 
93 bgadell 345
  }
56 bgadell 346
 
347
  #---------------START THE HTML--------------------
348
 
349
  my $RCAUTH_cookie = cookie (-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
350
 
351
  print header (-cookie=>$RCAUTH_cookie);
352
 
353
  #foreach (keys %ENV) {
93 bgadell 354
  # warn "$_: $ENV{$_}\n<br>";
56 bgadell 355
  #}
356
 
357
  if ($errors) {
88 bgadell 358
    $errors = $h->div ({ class=>"error" }, $errors);
56 bgadell 359
  } else {
88 bgadell 360
    $errors = "";
56 bgadell 361
  }
362
 
58 bgadell 363
   my @printDepartments = ( $h->div ({ class=>"index", style=>"display: unset;" }, $h->p ({ class=>"heading" }, "Volunteer Department Access:")) );
56 bgadell 364
  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:")) ]);
365
  foreach (sort grep { !/^PER$/ } keys %{$F->{department}}) {
366
    push @printDepartments, $h->div ({ class=>"rTableRow" }, [
367
      $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" },
368
        [ $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->{$_}.":" ],
369
        $F->{department}->{$_} =~ /^\d$/ ? $AccessLevel->{$F->{department}->{$_}} : $F->{department}->{$_}),
370
    ]);
371
  }
372
 
373
  printRCHeader ("User Manager");
374
 
375
  print $errors;
376
  print $h->form ({ action=>url, method=>'POST', name=>'Req' },[
377
    $h->input ({ type=>"hidden", name=>"referer", value=>$goback }),
378
    $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "User Details:"),
379
      $h->div ({ class=>"rTable", style=>"min-width: 0%;" },[
380
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "User-ID / Email Address: ", $F->{email}) ]),
381
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Password: ",                $F->{password}) ]),
382
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Derby Name: ",              $F->{derby_name}) ]),
58 bgadell 383
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Full Name: ",               $F->{real_name}) ]),
56 bgadell 384
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Pronouns: ",                $F->{pronouns}) ]),
385
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "TShirt Size: ",             $F->{tshirt}) ]),
386
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Phone: ",                   $F->{phone}) ]),
387
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Time Format: ",       $F->{timeformat}) ]),
388
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Database ID: ",             $F->{RCid}) ]),
389
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "User Added: ",              $F->{added}) ]),
390
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "Last Login: ",              $F->{last_login}) ]),
391
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "vORC Access Level: ",       $F->{access}) ]),
58 bgadell 392
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, "MVP Pass: ",                $F->{MVPid}) ]),
56 bgadell 393
        @printDepartments,
394
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCell" }, "&nbsp;") ]),
395
        $h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableCellr" }, $h->a ({ href=>$goback }, "[go back]"), $F->{buttons}) ])
396
      ])
397
    ])
93 bgadell 398
  ]);
56 bgadell 399
  print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Schedule:"), getSchedule ($RCID, "all")]) unless $RCID !~ /^\d+$/;
400
  print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Recent Activity:"), getLog ($RCID)]) unless $RCID !~ /^\d+$/;
401
  print $h->close ('html');
93 bgadell 402
  exit;
56 bgadell 403
}
404
 
405
 
406
sub checkDupes {
407
  my $field = shift;
408
  my $nametocheck = shift;
409
  my $han = $dbh->prepare("select RCid from official where $field = ?");
410
  $han->execute($nametocheck);
411
  my ($rcid) = $han->fetchrow();
412
  return $rcid;
413
}
414
 
415
sub getLog {
416
  my $RCID = shift;
417
 
418
  my @activity_log;
419
  my $alog = $dbh->prepare("select timestamp, event from v_log where RCid = ? limit 10");
420
  $alog->execute($RCID);
421
  while (my @logs = $alog->fetchrow_array) {
88 bgadell 422
    push @activity_log, $h->li ({ class=>"shaded" }, join " ", @logs);
56 bgadell 423
  }
424
 
425
  return $h->ul ([@activity_log]).$h->h5 ($h->a ({ href=>"log.pl?filter-RCid=".$RCID }, "[Entire log history]"));
426
}
427
 
428
sub getDepartmentDescriptions {
88 bgadell 429
  my %HASH;
430
  my $sth = $dbh->prepare("select TLA, description from department");
431
  $sth->execute();
432
  while (my ($tla, $name) = $sth->fetchrow) {
433
    $HASH{$tla} = $name;
56 bgadell 434
  }
435
  return \%HASH;
436
}
437
 
438
sub getDepartmentLinks {
88 bgadell 439
  my %HASH;
440
  my $sth = $dbh->prepare("select TLA, link from department where link <> ''");
441
  $sth->execute();
442
  while (my ($tla, $name) = $sth->fetchrow) {
443
    $HASH{$tla} = $name;
56 bgadell 444
  }
445
  return \%HASH;
446
}
93 bgadell 447
 
448
sub changeUser {
449
  my ($uid, $field, $newvalue) = @_;
450
 
451
  return "ERROR: Bad (or missing) RCid: [$uid]" unless $uid =~ /^\d+$/;
452
  return "ERROR: Bad (or missing) field name: [$field]" unless $field;
453
#  return "ERROR: Bad (or missing) new value: [$newvalue]" unless $newvalue;
454
  return "ERROR: Can't change someone's RCid" if $field eq "RCid";
455
 
456
  if ($field eq "password") {
457
    return unless $newvalue;
458
    $dbh->do ("update official set password = password(?) where RCid = ?", undef, $newvalue, $uid) or return "ERROR: ".$dbh->errstr;
459
  } else {
460
    $dbh->do ("update official set $field = ? where RCid = ?", undef, $newvalue, $uid) or return "ERROR: ".$dbh->errstr;
461
  }
462
 
463
  $newvalue = '********' if $field eq "password";
464
  if ($ORCUSER->{RCid} eq $uid) {
465
    logit ($uid, "Updated Profile: $field -> $newvalue");
466
  } else {
467
    logit ($ORCUSER->{RCid}, "Updated User [$uid]: $field -> $newvalue");
468
    logit ($uid, "$ORCUSER->{derby_name} updated your profile: $field -> $newvalue");
469
  }
470
 
471
  return;
472
}