Subversion Repositories VORC

Rev

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