Subversion Repositories VORC

Rev

Rev 196 | Rev 229 | 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
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
10
 
196 - 11
use strict;
56 bgadell 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::LEAD) || die;
20
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
196 - 21
our $RCAUTH_cookie = CGI::Cookie->new (-name=>'RCAUTH', -value=>"$cookie_string", -expires=>"+30m");
56 bgadell 22
 
23
my $pageTitle = "User Report";
58 bgadell 24
our $DBTABLE = 'v_official';
56 bgadell 25
my %COLUMNS = (
26
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
196 - 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 )],
134 - 33
  phone        => [qw(Phone       35    text                )],
196 - 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         )]
56 bgadell 40
);
41
 
196 - 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
 
56 bgadell 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
 
134 - 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
 
196 - 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
 
56 bgadell 87
sub filter_department {
88
  my $colName = shift;
89
  my $filter = shift // "";
90
 
196 - 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
 
56 bgadell 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
 
196 - 109
    @options = map { $tmpFormValue eq $_ ?
56 bgadell 110
                       ( $h->option ({ selected=>[], value=>$_ }, $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) ) :
111
                       ( $h->option ({ value=>$_ },               $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) )  } @options;
112
 
196 - 113
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
114
 
222 - 115
    my $autoload = param ("autoload") // 1;
116
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
56 bgadell 117
  }
118
}
119
 
120
our $filtered_by_access = "";
121
sub filter_access {
122
  my $colName = shift;
123
  my $filter = shift // "";
124
 
196 - 125
  if ($filter ne "")  {
126
    $filtered_by_access = $filter;
127
    return $filter eq "-1" ? "$colName = $filter" : "($colName = $filter or department like '%$filter%')";
128
  } else {
129
    my @options = (-1, 0, 1, 2, 3, 4, 5);
130
    my $tmpFormValue = param ("filter-".$colName);
56 bgadell 131
 
196 - 132
    @options = map { $tmpFormValue eq $_ ?
56 bgadell 133
                       ( $h->option ({ selected=>[], value=>$_ }, $ROLE->{$_}) ) :
134
                       ( $h->option ({ value=>$_ },               $ROLE->{$_}) )  } @options;
135
 
196 - 136
    unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";
137
 
222 - 138
    my $autoload = param ("autoload") // 1;
139
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
56 bgadell 140
  }
141
}
142
 
58 bgadell 143
sub filter_MVPid {
144
  my $colName = shift;
145
  my $filter = shift // "";
146
 
196 - 147
  if ($filter)  {
148
    return $filter =~ /^R-/ ? "$colName = '$filter'" : $filter eq "pass" ? "isnull($colName) = 0" : "isnull($colName) = 1";
149
  } else {
58 bgadell 150
    my @options = ("", "pass", "no pass");
196 - 151
    my $tmpFormValue = param ("filter-".$colName);
58 bgadell 152
 
196 - 153
    @options = map { $tmpFormValue eq $_ ?
58 bgadell 154
                       ( $h->option ({ selected=>[] }, $_) ) :
155
                       ( $h->option (                  $_) )  } @options;
156
 
222 - 157
    my $autoload = param ("autoload") // 1;
158
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
58 bgadell 159
  }
160
}
161
 
134 - 162
sub filter_emt_verified {
163
  my $colName = shift;
164
  my $filter = shift // "";
165
 
196 - 166
  if ($filter ne "")  {
167
    return join " and ", "department like '%EMT%'", $filter eq "True" ? "$colName = 1" : "$colName = 0";
168
  } else {
134 - 169
    my @options = ("", "True", "False");
196 - 170
    my $tmpFormValue = param ("filter-".$colName);
134 - 171
 
196 - 172
    @options = map { $tmpFormValue eq $_ ?
134 - 173
                       ( $h->option ({ selected=>[] }, $_) ) :
174
                       ( $h->option (                  $_) )  } @options;
175
 
222 - 176
    my $autoload = param ("autoload") // 1;
177
    return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);
134 - 178
  }
179
}
180
 
196 - 181
# Uncomment and update if we want to enable clicking on a row to open a new page.
182
#
183
sub addRowClick {
184
  my $t = shift;
56 bgadell 185
 
196 - 186
  return "location.href='view_user.pl?RCid=$t->{RCid}'";
56 bgadell 187
}
188
 
196 - 189
# Call the function to print the table view page (with available options)
190
printTablePage ({ Title   => $pageTitle,
191
                  Table   => $DBTABLE,
192
                  Columns => \%COLUMNS,
193
                  RCAuth  => $RCAUTH_cookie,
194
                  Where   => $defaultWhere,
195
                  DisplayYearSelect => 0,
196
                 });
56 bgadell 197