Subversion Repositories VORC

Rev

Rev 222 | Go to most recent revision | Details | 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
 
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
  } else {
103
    my @options = ();
104
    my $tmpFormValue = param ("filter-".$colName);
105
 
106
    push @options, "-blank-" unless $LVL < 4;
107
    push @options, ($LVL < 4 and $ORCUSER->{department}->{VCI} < 2) ? grep { $ORCUSER->{department}->{$_} >= 2 } sort keys %{$ORCUSER->{department}} : sort keys %{$DepartmentNames};
108
 
109
    @options = map { $tmpFormValue eq $_ ?
110
                       ( $h->option ({ selected=>[], value=>$_ }, $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) ) :
111
                       ( $h->option ({ value=>$_ },               $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) )  } @options;
112
 
113
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
114
 
115
    return param ("autoload") ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
116
  }
117
}
118
 
119
our $filtered_by_access = "";
120
sub filter_access {
121
  my $colName = shift;
122
  my $filter = shift // "";
123
 
124
  if ($filter ne "")  {
125
    $filtered_by_access = $filter;
126
    return $filter eq "-1" ? "$colName = $filter" : "($colName = $filter or department like '%$filter%')";
127
  } else {
128
    my @options = (-1, 0, 1, 2, 3, 4, 5);
129
    my $tmpFormValue = param ("filter-".$colName);
130
 
131
    @options = map { $tmpFormValue eq $_ ?
132
                       ( $h->option ({ selected=>[], value=>$_ }, $ROLE->{$_}) ) :
133
                       ( $h->option ({ value=>$_ },               $ROLE->{$_}) )  } @options;
134
 
135
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
136
 
137
    return param ("autoload") ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
138
  }
139
}
140
 
141
sub filter_MVPid {
142
  my $colName = shift;
143
  my $filter = shift // "";
144
 
145
  if ($filter)  {
146
    return $filter =~ /^R-/ ? "$colName = '$filter'" : $filter eq "pass" ? "isnull($colName) = 0" : "isnull($colName) = 1";
147
  } else {
148
    my @options = ("", "pass", "no pass");
149
    my $tmpFormValue = param ("filter-".$colName);
150
 
151
    @options = map { $tmpFormValue eq $_ ?
152
                       ( $h->option ({ selected=>[] }, $_) ) :
153
                       ( $h->option (                  $_) )  } @options;
154
 
155
    return param ("autoload") ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
156
  }
157
}
158
 
159
sub filter_emt_verified {
160
  my $colName = shift;
161
  my $filter = shift // "";
162
 
163
  if ($filter ne "")  {
164
    return join " and ", "department like '%EMT%'", $filter eq "True" ? "$colName = 1" : "$colName = 0";
165
  } else {
166
    my @options = ("", "True", "False");
167
    my $tmpFormValue = param ("filter-".$colName);
168
 
169
    @options = map { $tmpFormValue eq $_ ?
170
                       ( $h->option ({ selected=>[] }, $_) ) :
171
                       ( $h->option (                  $_) )  } @options;
172
 
173
    return param ("autoload") ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
174
  }
175
}
176
 
177
# Uncomment and update if we want to enable clicking on a row to open a new page.
178
#
179
sub addRowClick {
180
  my $t = shift;
181
 
182
  return "location.href='view_user.pl?RCid=$t->{RCid}'";
183
}
184
 
185
# Call the function to print the table view page (with available options)
186
printTablePage ({ Title   => $pageTitle,
187
                  Table   => $DBTABLE,
188
                  Columns => \%COLUMNS,
189
                  RCAuth  => $RCAUTH_cookie,
190
                  Where   => $defaultWhere,
191
                  DisplayYearSelect => 0,
192
                 });
193