Subversion Repositories VORC

Rev

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