| 32 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
| 56 |
bgadell |
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 |
|
| 32 |
- |
9 |
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
|
|
|
10 |
|
| 196 |
- |
11 |
use strict;
|
| 32 |
- |
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 (3) || die;
|
|
|
20 |
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
| 196 |
- |
21 |
my $RCAUTH_cookie = CGI::Cookie->new (-name=>'RCAUTH', -value=>"$cookie_string", -expires=>"+30m");
|
| 32 |
- |
22 |
|
|
|
23 |
my $pageTitle = "Volunteer Hours Summary";
|
|
|
24 |
our $DBTABLE = 'v_volhours';
|
|
|
25 |
my %COLUMNS = (
|
|
|
26 |
# colname => [qw(DisplayName N type status)], status -> static | default | <blank>
|
| 196 |
- |
27 |
RCid => [qw(RCid 15 number )],
|
|
|
28 |
derby_name => [qw(DerbyName 25 select static )],
|
|
|
29 |
full_name => [qw(FullName 27 select )],
|
|
|
30 |
dept => [qw(Department 30 select static )],
|
|
|
31 |
hours => [qw(Hours 40 number static )]
|
| 32 |
- |
32 |
);
|
|
|
33 |
|
|
|
34 |
# Set any custom "where" DB filters here...
|
|
|
35 |
my @whereClause;
|
| 196 |
- |
36 |
# Users should only be able to see the hours report for the departments in which they're a manager
|
| 32 |
- |
37 |
if ($LVL < 5) {
|
| 196 |
- |
38 |
my $string = "dept in (".join ",", map { '"'.$_.'"' } grep { $ORCUSER->{department}->{$_} >= 3 } keys %{$ORCUSER->{department}};
|
| 32 |
- |
39 |
$string .= ")";
|
|
|
40 |
push @whereClause, $string;
|
|
|
41 |
}
|
|
|
42 |
push @whereClause, "dept != 'PER'";
|
|
|
43 |
|
|
|
44 |
# If we need to modify line item values, create a subroutine named "modify_$columnname"
|
|
|
45 |
# It will receive a hashref to the object lineitem
|
|
|
46 |
|
|
|
47 |
sub modify_derby_name {
|
|
|
48 |
my $li = shift;
|
| 56 |
bgadell |
49 |
return $h->a ({ href=>"view_user.pl?RCid=".getRCid ($li->{derby_name}) }, $li->{derby_name});
|
| 32 |
- |
50 |
}
|
|
|
51 |
|
|
|
52 |
my $DEPTS = getDepartments ();
|
|
|
53 |
sub modify_dept {
|
|
|
54 |
my $hr = shift;
|
|
|
55 |
return $DEPTS->{$hr->{dept}};
|
|
|
56 |
}
|
|
|
57 |
|
| 196 |
- |
58 |
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
|
|
|
59 |
# It will receive two fields, the field name and the current filter value (if any)
|
|
|
60 |
|
| 32 |
- |
61 |
sub filter_dept {
|
|
|
62 |
my $colName = shift;
|
| 196 |
- |
63 |
my $filter = shift;
|
| 32 |
- |
64 |
|
| 196 |
- |
65 |
if (defined $filter) {
|
|
|
66 |
if ($filter eq "-blank-") {
|
|
|
67 |
return "($colName = '' or isNull($colName) = 1)";
|
| 32 |
- |
68 |
}
|
| 196 |
- |
69 |
return "$colName = \"$filter\"";
|
| 32 |
- |
70 |
} else {
|
| 230 |
- |
71 |
my $tmpFormValue = getFilterValue ($colName);
|
| 196 |
- |
72 |
my $categories = join "", map { $tmpFormValue eq $_ ? $h->option ({ value=>$_, selected=>[] }, $DEPTS->{$_}) : $h->option ({ value=>$_ }, $DEPTS->{$_}) } grep { $LVL > 4 or $ORCUSER->{department}->{$_} >= 3 } sort keys %{$DEPTS};
|
|
|
73 |
my $Options = "<OPTION></OPTION>".$categories;
|
|
|
74 |
|
|
|
75 |
$Options =~ s/>($tmpFormValue)/ selected>$1/;
|
| 222 |
- |
76 |
my $autoload = param ("autoload") // 1;
|
|
|
77 |
my $onChange = $autoload ? "onChange='page.value = 1; submit();'" : "";
|
| 196 |
- |
78 |
return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
|
| 32 |
- |
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
| 196 |
- |
82 |
# Uncomment and update if we want to enable clicking on a row to open a new page.
|
|
|
83 |
#
|
|
|
84 |
#sub addRowClick {
|
|
|
85 |
# my $t = shift;
|
|
|
86 |
# return "location.href='view_thing.pl?field=$t->{field}&choice=View'";
|
|
|
87 |
#}
|
| 32 |
- |
88 |
|
| 196 |
- |
89 |
# Call the function to print the table view page (with available options)
|
|
|
90 |
printTablePage ({ Title => $pageTitle,
|
|
|
91 |
Table => $DBTABLE,
|
|
|
92 |
Columns => \%COLUMNS,
|
|
|
93 |
RCAuth => $RCAUTH_cookie,
|
|
|
94 |
Where => join(" and ", @whereClause),
|
|
|
95 |
DisplayYearSelect => 1,
|
|
|
96 |
});
|