Subversion Repositories VORC

Rev

Rev 230 | 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 )],
244 - 37
  hours        => [qw(VolHours    46    number      default )],
38
  emt_verified => [qw(EMTVerified 47    select       )],
219 - 39
  added        => [qw(Added       50    date         )],
40
  last_login   => [qw(LastLogin   55    date         )]
41
);
42
 
43
my $defaultWhere;
44
if ($LVL < 4 and $ORCUSER->{department}->{VCI} < 2) {
45
  $defaultWhere = join " or ", map { 'department like "%'.$_.'%"' } grep { $ORCUSER->{department}->{$_} >= 2 } keys %{$ORCUSER->{department}};
46
  $defaultWhere = "($defaultWhere)";
47
}
48
 
49
my $ROLE = getAccessLevels;
50
my $DepartmentNames = getDepartments ();
51
 
52
# If we need to modify line item values, create a subroutine named "modify_$columnname"
53
#    It will receive a hashref to the object lineitem
54
# You can also create specific "filter_column" subroutines...
55
 
56
sub modify_department {
57
  my $li = shift // "";
58
  if ($li->{"department"}) {
59
    my $Ds = convertDepartments $li->{"department"};
60
    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};
61
  } else {
62
    return "";
63
  }
64
}
65
 
66
sub modify_access {
67
  my $li = shift // "";
68
  my @levels = ($li->{"access"});
69
 
70
  if ($li->{"department"}) {
71
    push @levels, values %{convertDepartments $li->{"department"}};
72
  }
73
 
74
  return $ROLE->{ max @levels };
75
}
76
 
77
sub modify_emt_verified {
78
  my $li = shift // "";
79
 
80
  return "" unless exists convertDepartments($li->{"department"})->{EMT};
81
 
82
  return $li->{"emt_verified"} ? "True" : "False";
83
}
84
 
85
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
86
#    It will receive two fields, the field name and the current filter value (if any)
87
 
88
sub filter_department {
89
  my $colName = shift;
90
  my $filter = shift // "";
91
 
92
  if ($filter)  {
93
    if ($filter eq "-blank-") {
94
      return "($colName = '' or isNull($colName) = 1)";
95
    }
96
 
222 - 97
#    no strict;
98
#    if ($filtered_by_access ne "") {
99
#      return "$colName like \"%$filter-$filtered_by_access%\"";
100
#    } else {
101
#      return "$colName like \"%$filter%\"";
102
#    }
103
    return "department like '%$filter-2%' or department like '%$filter-3%' or department like '%$filter-4%'";
219 - 104
  } else {
105
    my @options = ();
230 - 106
    my $tmpFormValue = getFilterValue ($colName);
219 - 107
 
108
    push @options, "-blank-" unless $LVL < 4;
109
    push @options, ($LVL < 4 and $ORCUSER->{department}->{VCI} < 2) ? grep { $ORCUSER->{department}->{$_} >= 2 } sort keys %{$ORCUSER->{department}} : sort keys %{$DepartmentNames};
110
 
111
    @options = map { $tmpFormValue eq $_ ?
112
                       ( $h->option ({ selected=>[], value=>$_ }, $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) ) :
113
                       ( $h->option ({ value=>$_ },               $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) )  } @options;
114
 
115
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
116
 
222 - 117
    my $autoload = param ("autoload") // 1;
118
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 119
  }
120
}
121
 
122
our $filtered_by_access = "";
123
sub filter_access {
124
  my $colName = shift;
125
  my $filter = shift // "";
126
 
127
  if ($filter ne "")  {
128
    $filtered_by_access = $filter;
129
    return $filter eq "-1" ? "$colName = $filter" : "($colName = $filter or department like '%$filter%')";
130
  } else {
131
    my @options = (-1, 0, 1, 2, 3, 4, 5);
230 - 132
    my $tmpFormValue = getFilterValue ($colName);
219 - 133
 
134
    @options = map { $tmpFormValue eq $_ ?
135
                       ( $h->option ({ selected=>[], value=>$_ }, $ROLE->{$_}) ) :
136
                       ( $h->option ({ value=>$_ },               $ROLE->{$_}) )  } @options;
137
 
138
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
139
 
222 - 140
    my $autoload = param ("autoload") // 1;
141
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 142
  }
143
}
144
 
145
sub filter_MVPid {
146
  my $colName = shift;
147
  my $filter = shift // "";
148
 
149
  if ($filter)  {
150
    return $filter =~ /^R-/ ? "$colName = '$filter'" : $filter eq "pass" ? "isnull($colName) = 0" : "isnull($colName) = 1";
151
  } else {
152
    my @options = ("", "pass", "no pass");
230 - 153
    my $tmpFormValue = getFilterValue ($colName);
219 - 154
 
155
    @options = map { $tmpFormValue eq $_ ?
156
                       ( $h->option ({ selected=>[] }, $_) ) :
157
                       ( $h->option (                  $_) )  } @options;
158
 
222 - 159
    my $autoload = param ("autoload") // 1;
160
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 161
  }
162
}
163
 
164
sub filter_emt_verified {
165
  my $colName = shift;
166
  my $filter = shift // "";
167
 
168
  if ($filter ne "")  {
169
    return join " and ", "department like '%EMT%'", $filter eq "True" ? "$colName = 1" : "$colName = 0";
170
  } else {
171
    my @options = ("", "True", "False");
230 - 172
    my $tmpFormValue = getFilterValue ($colName);
219 - 173
 
174
    @options = map { $tmpFormValue eq $_ ?
175
                       ( $h->option ({ selected=>[] }, $_) ) :
176
                       ( $h->option (                  $_) )  } @options;
177
 
222 - 178
    my $autoload = param ("autoload") // 1;
179
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
219 - 180
  }
181
}
182
 
183
# Uncomment and update if we want to enable clicking on a row to open a new page.
184
#
185
sub addRowClick {
186
  my $t = shift;
187
 
188
  return "location.href='view_user.pl?RCid=$t->{RCid}'";
189
}
190
 
191
# Call the function to print the table view page (with available options)
192
printTablePage ({ Title   => $pageTitle,
193
                  Table   => $DBTABLE,
194
                  Columns => \%COLUMNS,
195
                  RCAuth  => $RCAUTH_cookie,
196
                  Where   => $defaultWhere,
197
                  DisplayYearSelect => 0,
198
                 });
199