Subversion Repositories VORC

Rev

Rev 222 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
219 - 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
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
10
 
11
use strict;
12
use cPanelUserConfig;
13
use CGI qw/param cookie header start_html url/;
14
use HTML::Tiny;
15
use tableViewer;
16
use RollerCon;
17
our $h = HTML::Tiny->new( mode => 'html' );
18
 
19
my $cookie_string = authenticate (RollerCon::MANAGER) || die;
20
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
21
our $RCAUTH_cookie = CGI::Cookie->new (-name=>'RCAUTH', -value=>"$cookie_string", -expires=>"+30m");
22
 
23
my $pageTitle = "Leadership Report";
24
our $DBTABLE = 'v_leadership';
25
my %COLUMNS = (
26
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
27
  RCid         => [qw(ID           5    number       )],
28
  derby_name   => [qw(DerbyName   10    text        default )],
29
  email        => [qw(Email       15    text        default )],
30
  real_name    => [qw(FullName    20    text        default )],
31
  pronouns     => [qw(Pronouns    25    text        default )],
32
  tshirt       => [qw(TShirtSize  30    select      default )],
33
  phone        => [qw(Phone       35    text                )],
34
  access       => [qw(vOrcAccess  40    select              )],
35
  MVPid        => [qw(MVPPass     42    select              )],
36
  department   => [qw(Department  45    select      default )],
37
  emt_verified => [qw(EMTVerified 46    select       )],
38
  added        => [qw(Added       50    date         )],
39
  last_login   => [qw(LastLogin   55    date         )]
40
);
41
 
42
my $defaultWhere;
43
if ($LVL < 4 and $ORCUSER->{department}->{VCI} < 2) {
44
  $defaultWhere = join " or ", map { 'department like "%'.$_.'%"' } grep { $ORCUSER->{department}->{$_} >= 2 } keys %{$ORCUSER->{department}};
45
  $defaultWhere = "($defaultWhere)";
46
}
47
 
48
my $ROLE = getAccessLevels;
49
my $DepartmentNames = getDepartments ();
50
 
51
# If we need to modify line item values, create a subroutine named "modify_$columnname"
52
#    It will receive a hashref to the object lineitem
53
# You can also create specific "filter_column" subroutines...
54
 
55
sub modify_department {
56
  my $li = shift // "";
57
  if ($li->{"department"}) {
58
    my $Ds = convertDepartments $li->{"department"};
59
    return join $h->br, map { ($Ds->{$_} == 0 and ($ORCUSER->{department}->{$_} > 1 or $LVL > 4)) ? $h->a ({ onClick=>"event.stopPropagation(); window.open('activate_user.pl?RCid=$li->{RCid}&department=$_','Activating User','resizable,height=260,width=370');" }, "$DepartmentNames->{$_} - $ROLE->{$Ds->{$_}}") : "$DepartmentNames->{$_} - $ROLE->{$Ds->{$_}}" } sort keys %{$Ds};
60
  } else {
61
    return "";
62
  }
63
}
64
 
65
sub modify_access {
66
  my $li = shift // "";
67
  my @levels = ($li->{"access"});
68
 
69
  if ($li->{"department"}) {
70
    push @levels, values %{convertDepartments $li->{"department"}};
71
  }
72
 
73
  return $ROLE->{ max @levels };
74
}
75
 
76
sub modify_emt_verified {
77
  my $li = shift // "";
78
 
79
  return "" unless exists convertDepartments($li->{"department"})->{EMT};
80
 
81
  return $li->{"emt_verified"} ? "True" : "False";
82
}
83
 
84
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
85
#    It will receive two fields, the field name and the current filter value (if any)
86
 
87
sub filter_department {
88
  my $colName = shift;
89
  my $filter = shift // "";
90
 
91
  if ($filter)  {
92
    if ($filter eq "-blank-") {
93
      return "($colName = '' or isNull($colName) = 1)";
94
    }
95
 
222 - 96
#    no strict;
97
#    if ($filtered_by_access ne "") {
98
#      return "$colName like \"%$filter-$filtered_by_access%\"";
99
#    } else {
100
#      return "$colName like \"%$filter%\"";
101
#    }
102
    return "department like '%$filter-2%' or department like '%$filter-3%' or department like '%$filter-4%'";
219 - 103
  } else {
104
    my @options = ();
230 - 105
    my $tmpFormValue = getFilterValue ($colName);
219 - 106
 
107
    push @options, "-blank-" unless $LVL < 4;
108
    push @options, ($LVL < 4 and $ORCUSER->{department}->{VCI} < 2) ? grep { $ORCUSER->{department}->{$_} >= 2 } sort keys %{$ORCUSER->{department}} : sort keys %{$DepartmentNames};
109
 
110
    @options = map { $tmpFormValue eq $_ ?
111
                       ( $h->option ({ selected=>[], value=>$_ }, $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) ) :
112
                       ( $h->option ({ value=>$_ },               $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) )  } @options;
113
 
114
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
115
 
222 - 116
    my $autoload = param ("autoload") // 1;
117
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 118
  }
119
}
120
 
121
our $filtered_by_access = "";
122
sub filter_access {
123
  my $colName = shift;
124
  my $filter = shift // "";
125
 
126
  if ($filter ne "")  {
127
    $filtered_by_access = $filter;
128
    return $filter eq "-1" ? "$colName = $filter" : "($colName = $filter or department like '%$filter%')";
129
  } else {
130
    my @options = (-1, 0, 1, 2, 3, 4, 5);
230 - 131
    my $tmpFormValue = getFilterValue ($colName);
219 - 132
 
133
    @options = map { $tmpFormValue eq $_ ?
134
                       ( $h->option ({ selected=>[], value=>$_ }, $ROLE->{$_}) ) :
135
                       ( $h->option ({ value=>$_ },               $ROLE->{$_}) )  } @options;
136
 
137
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
138
 
222 - 139
    my $autoload = param ("autoload") // 1;
140
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 141
  }
142
}
143
 
144
sub filter_MVPid {
145
  my $colName = shift;
146
  my $filter = shift // "";
147
 
148
  if ($filter)  {
149
    return $filter =~ /^R-/ ? "$colName = '$filter'" : $filter eq "pass" ? "isnull($colName) = 0" : "isnull($colName) = 1";
150
  } else {
151
    my @options = ("", "pass", "no pass");
230 - 152
    my $tmpFormValue = getFilterValue ($colName);
219 - 153
 
154
    @options = map { $tmpFormValue eq $_ ?
155
                       ( $h->option ({ selected=>[] }, $_) ) :
156
                       ( $h->option (                  $_) )  } @options;
157
 
222 - 158
    my $autoload = param ("autoload") // 1;
159
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 160
  }
161
}
162
 
163
sub filter_emt_verified {
164
  my $colName = shift;
165
  my $filter = shift // "";
166
 
167
  if ($filter ne "")  {
168
    return join " and ", "department like '%EMT%'", $filter eq "True" ? "$colName = 1" : "$colName = 0";
169
  } else {
170
    my @options = ("", "True", "False");
230 - 171
    my $tmpFormValue = getFilterValue ($colName);
219 - 172
 
173
    @options = map { $tmpFormValue eq $_ ?
174
                       ( $h->option ({ selected=>[] }, $_) ) :
175
                       ( $h->option (                  $_) )  } @options;
176
 
222 - 177
    my $autoload = param ("autoload") // 1;
178
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 179
  }
180
}
181
 
182
# Uncomment and update if we want to enable clicking on a row to open a new page.
183
#
184
sub addRowClick {
185
  my $t = shift;
186
 
187
  return "location.href='view_user.pl?RCid=$t->{RCid}'";
188
}
189
 
190
# Call the function to print the table view page (with available options)
191
printTablePage ({ Title   => $pageTitle,
192
                  Table   => $DBTABLE,
193
                  Columns => \%COLUMNS,
194
                  RCAuth  => $RCAUTH_cookie,
195
                  Where   => $defaultWhere,
196
                  DisplayYearSelect => 0,
197
                 });
198