| 2 |
- |
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 PEEPS;
|
|
|
11 |
use CGI qw/param header start_html url/;
|
|
|
12 |
use CGI::Cookie;
|
|
|
13 |
our $h = HTML::Tiny->new( mode => 'html' );
|
|
|
14 |
my $dbh = getRCDBH ();
|
|
|
15 |
|
|
|
16 |
my $cookie_string = authenticate (1) || die;
|
|
|
17 |
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
|
|
18 |
my $user = $ORCUSER;
|
|
|
19 |
my @ERRORS;
|
|
|
20 |
#my $activated = $ORCUSER->{access};
|
|
|
21 |
|
|
|
22 |
print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
|
|
|
23 |
|
|
|
24 |
#foreach (sort keys %ENV) {
|
|
|
25 |
# print "$_: $ENV{$_}\n<br>";
|
|
|
26 |
#}
|
|
|
27 |
|
|
|
28 |
use DateTime;
|
|
|
29 |
my $dt = DateTime->today;
|
|
|
30 |
$dt =~ s/T00\:00\:00$//;
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
#for my $key (sort keys %{$user}) {
|
|
|
34 |
# print "$key: $user->{$key}<br>";
|
|
|
35 |
#}
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
my $league_id = WebDB::trim param ("league_id") // printError ("League ID not set.");
|
|
|
39 |
my $person_id = WebDB::trim param ("person_id") // printError ("Person ID not set.");
|
|
|
40 |
|
|
|
41 |
# Does the league exist?
|
|
|
42 |
my $league_name = getLeagueName ($league_id);
|
|
|
43 |
printError ("League not found ($league_id).") unless $league_name;
|
|
|
44 |
|
|
|
45 |
# Is the current user a League (or WFTDA) Admin?
|
|
|
46 |
my ($isALeagueAdmin) = $dbh->selectrow_array ("select 1 from role where role = ? and member_org_id = ? and person_id = ?", undef, "League Admin", $league_id, $user->{person_id});
|
|
|
47 |
my ($isAWFTDAAdmin) = $dbh->selectrow_array ("select 1 from role where role = ? and member_org_id = ? and person_id = ?", undef, "System Admin", 4276, $user->{person_id});
|
|
|
48 |
printError ("Not a League Admin for $league_name") unless ($isALeagueAdmin or $isAWFTDAAdmin);
|
|
|
49 |
|
|
|
50 |
# Does the person exist...
|
|
|
51 |
my $target_person = getUser ($person_id);
|
|
|
52 |
|
|
|
53 |
# ...within the leauge?
|
|
|
54 |
my @roles = @{ $dbh->selectall_arrayref ("select id, role from role where person_id = ? and member_org_id = ? order by role", undef, $person_id, $league_id) };
|
|
|
55 |
my %rolename = map { $_->[0] => $_->[1] } @roles;
|
|
|
56 |
|
|
|
57 |
printError ("Person ID not found, or they don't exist within your League") unless scalar @roles;
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
if (my $RoleID = WebDB::trim scalar param ("Delete")) {
|
|
|
62 |
printError ("Improperly formatted RoleID [$_]") unless $RoleID =~ /^\d+$/;
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
if (scalar @roles == 1) {
|
|
|
66 |
my $confirmed = WebDB::trim scalar param ("Confirmed") // "";
|
|
|
67 |
if (!$confirmed) {
|
|
|
68 |
# confirm removing the user from the org first...
|
|
|
69 |
|
|
|
70 |
printRCHeader ("User Role Manager");
|
|
|
71 |
print $h->h2 ("Deleting role from user...");
|
|
|
72 |
print $h->open ("form", { action=>url, method=>'POST', name=>'UserRoleForm', id=>'UserForm' });
|
|
|
73 |
print $h->input ({ type=>"hidden", name=>"person_id", value=>$person_id}),
|
|
|
74 |
$h->input ({ type=>"hidden", name=>"league_id", value=>$league_id}),
|
|
|
75 |
$h->input ({ type=>"hidden", name=>"Delete", value=>$RoleID});
|
|
|
76 |
print $h->div ("Removing this role will remove this person from your Organization.".$h->br."Are you sure you want to do that?");
|
|
|
77 |
print $h->div ([$h->input ({type=>"submit", name=>"Confirmed", value=>"Yes"}), ' ', $h->input ({type=>"submit", name=>"Confirmed", value=>"Cancel"})]);
|
|
|
78 |
print $h->close ("form", "body", "html");
|
|
|
79 |
exit;
|
|
|
80 |
} elsif ($confirmed eq "Yes") {
|
|
|
81 |
# delete the role
|
|
|
82 |
$dbh->do ("delete from role where member_org_id = ? and person_id = ? and id = ?", undef, $league_id, $person_id, $RoleID);
|
|
|
83 |
$dbh->do ("replace into full_person select * from v_person where id = ? and league_id = ?", undef, $person_id, $league_id);
|
|
|
84 |
logit ($person_id, "Removed from the '$rolename{$RoleID}' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
85 |
logit ($user->{person_id}, "Removed user ".$target_person->{derby_name}." [ID:$person_id] from the '$rolename{$RoleID}' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
86 |
orglogit ($user->{person_id}, $league_id, "Removed user ".$target_person->{derby_name}." [ID:$person_id] from the '$rolename{$RoleID}' role [ID:$RoleID] and league");
|
|
|
87 |
#warn "Removing RoleID: $RoleID";
|
|
|
88 |
}
|
|
|
89 |
# They didn't confirm the delete, don't do anything
|
|
|
90 |
} else {
|
|
|
91 |
$dbh->do ("delete from role where member_org_id = ? and person_id = ? and id = ?", undef, $league_id, $person_id, $RoleID);
|
|
|
92 |
$dbh->do ("replace into full_person select * from v_person where id = ? and league_id = ?", undef, $person_id, $league_id);
|
|
|
93 |
logit ($person_id, "Removed from the '$rolename{$RoleID}' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
94 |
logit ($user->{person_id}, "Removed user ".$target_person->{derby_name}." [ID:$person_id] from the '$rolename{$RoleID}' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
95 |
orglogit ($user->{person_id}, $league_id, "Removed user ".$target_person->{derby_name}." [ID:$person_id] from the '$rolename{$RoleID}' role [ID:$RoleID]");
|
|
|
96 |
#warn "Removing RoleID: $RoleID";
|
|
|
97 |
}
|
|
|
98 |
@roles = @{ $dbh->selectall_arrayref ("select id, role from role where person_id = ? and member_org_id = ? order by role", undef, $person_id, $league_id) };
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
if (WebDB::trim scalar param ("savenewrole") eq "Save") {
|
|
|
103 |
my $NewRole = WebDB::trim scalar param ("newrole");
|
|
|
104 |
# We should check to make sure the new role is acceptable...
|
|
|
105 |
|
|
|
106 |
my ($RoleID) = $dbh->selectrow_array ("select id from role where person_id = ? and member_org_id = ? and role = ?", undef, $person_id, $league_id, "Pending");
|
|
|
107 |
if ($RoleID) {
|
|
|
108 |
$dbh->do ("update role set role = ? where member_org_id = ? and person_id = ? and id = ?", undef, $NewRole, $league_id, $person_id, $RoleID);
|
|
|
109 |
$dbh->do ("replace into full_person select * from v_person where id = ? and league_id = ?", undef, $person_id, $league_id);
|
|
|
110 |
logit ($person_id, "Updated to the '$NewRole' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
111 |
logit ($user->{person_id}, "Updated user ".$target_person->{derby_name}." [ID:$person_id] to the '$NewRole' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
112 |
orglogit ($user->{person_id}, $league_id, "Added user ".$target_person->{derby_name}." [ID:$person_id] to the league and '$NewRole' role [ID:$RoleID]");
|
|
|
113 |
# Maybe send an email to the user that they've been added to the league...
|
|
|
114 |
} else {
|
|
|
115 |
$dbh->do ("insert into role (member_org_id, person_id, role) values (?, ?, ?)", undef, $league_id, $person_id, $NewRole);
|
|
|
116 |
$RoleID = $dbh->last_insert_id ();
|
|
|
117 |
$dbh->do ("replace into full_person select * from v_person where id = ? and league_id = ?", undef, $person_id, $league_id);
|
|
|
118 |
logit ($person_id, "Added to the '$NewRole' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
119 |
logit ($user->{person_id}, "Added user ".$target_person->{derby_name}." [ID:$person_id] to the '$NewRole' role [ID:$RoleID] for ".getLeagueName ($league_id)." [ID:$league_id]");
|
|
|
120 |
orglogit ($user->{person_id}, $league_id, "Added user ".$target_person->{derby_name}." [ID:$person_id] to the '$NewRole' role [ID:$RoleID]");
|
|
|
121 |
}
|
|
|
122 |
@roles = @{ $dbh->selectall_arrayref ("select id, role from role where person_id = ? and member_org_id = ? order by role", undef, $person_id, $league_id) };
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
printRCHeader ("User Role Manager");
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
print $h->h2 ("Roles for $target_person->{derby_name} in $league_name:");
|
|
|
130 |
print $h->open ("form", { action=>url, method=>'POST', name=>'UserRoleForm', id=>'UserForm' });
|
|
|
131 |
print $h->input ({ type=>"hidden", name=>"person_id", value=>$person_id}),
|
|
|
132 |
$h->input ({ type=>"hidden", name=>"league_id", value=>$league_id});
|
|
|
133 |
|
|
|
134 |
my @leagueroles = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, "Role".' '.$h->input ({type=>"submit", name=>"Add", value=>"Add"}), "Change" ) ]));
|
|
|
135 |
foreach (@roles) {
|
|
|
136 |
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
push @leagueroles, map { $h->div ({ class=>"rTableRow shaded" },
|
|
|
140 |
[ $h->div ({ class=>"rTableCellr".($_->[1] eq "Pending" ? " highlighted" : ""), style=>"font-size: smaller;".($_->[1] eq "Pending" ? " font-style: italic;" : "") },
|
|
|
141 |
$_->[1], [ $h->input ({type=>"submit", name=>"Delete", value=>"Delete", onClick=>"this.value=$_->[0]"}) ] ) ]) } @roles; # Change button -> , $h->input ({type=>"submit", name=>"Change", value=>"Change", onClick=>"this.value=$_->[0]"})
|
|
|
142 |
|
|
|
143 |
if (WebDB::trim scalar param ("Add")) {
|
|
|
144 |
use tableViewer qw(notInArray);
|
|
|
145 |
my @allowed_roles = grep { notInArray ($_, [map { $_->[1] } @roles]) } map { $_->[0] } @{ $dbh->selectall_arrayref ("select distinct role from role order by role") };
|
|
|
146 |
push @leagueroles, $h->div ({ class=>"rTableRow shaded" },
|
|
|
147 |
[ $h->div ({ class=>"rTableCellr"}, $h->select ({name=>"newrole"}, [ map { $h->option ($_) } @allowed_roles ]), $h->input ({type=>"submit", name=>"savenewrole", value=>"Save"}).' '.$h->button ("Cancel")) ]);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
print $h->ul ([@leagueroles]);
|
|
|
151 |
|
|
|
152 |
print $h->ul ($h->input ({type=>"button", onClick=>"window.location.href='view_user?person_id=$person_id'", value=>"Back"}));
|
|
|
153 |
|
|
|
154 |
print $h->close ("form");
|
|
|
155 |
|
|
|
156 |
sub printError {
|
|
|
157 |
my $message = shift // "Unknown Error";
|
|
|
158 |
|
|
|
159 |
printRCHeader("Manage Role");
|
|
|
160 |
print $h->close ("table");
|
|
|
161 |
print $h->h2 ("Error:");
|
|
|
162 |
print $h->div ({ style=>"max-width:450px;" }, $message, " ");
|
|
|
163 |
print $h->button ({onclick => "window.location.href='/';"}, "Home");
|
|
|
164 |
print $h->close ("BODY", "HTML");
|
|
|
165 |
logit ($user->{id}, "ERROR (Manage Role) ".$message);
|
|
|
166 |
exit;
|
|
|
167 |
}
|
|
|
168 |
|