Subversion Repositories PEEPS

Rev

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

Rev Author Line No. Line
2 - 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 CGI qw/param cookie header start_html url/;
13
use HTML::Tiny;
14
use tableViewer;
15
use PEEPS;
16
our $h = HTML::Tiny->new( mode => 'html' );
4 - 17
$ENV{HTTPS} = 'ON' if $ENV{SERVER_NAME} =~ /^peeps/;
2 - 18
 
19
my $cookie_string = authenticate () || die;
20
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
21
my $PEEPSAUTH_cookie = CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string",-expires=>"+30m");
22
 
23
my $pageTitle = "PEEPS - Organizations";
37 - 24
our $DBTABLE = 'v_organization';
2 - 25
my %COLUMNS = (
26
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
27
  id                 => [qw(ID               5    number              )],
28
  league_name        => [qw(LeagueName      10    text        default )],
29
  business_name      => [qw(BusinessName    15    text                )],
30
  city               => [qw(City            20    text        default )],
31
  state_province     => [qw(StateProvince   25    select      default )],
32
  country            => [qw(Country         30    select      default )],
33
  url                => [qw(Website         35    text                )],
34
  type               => [qw(Type            40    select      default )],
35
  status             => [qw(Status          45    select      default )],
36
  legal_entity_type  => [qw(LegalEntity     50    select       )],
37
  tax_id             => [qw(TaxID           55    text         )],
38
  date_established   => [qw(Established     60    date        default )],
39 - 39
  policy_id          => [qw(Policy          65    number      default )],
40
  policy_name        => [qw(PolicyName      70    text        default )],
41
  start              => [qw(PolicyStart     75    date        default )],
42
  end                => [qw(PolicyEnd       80    date        default )],
2 - 43
);
44
 
45
# Set any custom "where" DB filters here...
46
my @whereClause;
47
 
25 - 48
my $newleaguebutton;
16 - 49
if ($ORCUSER->{SYSADMIN}) {
31 - 50
  $COLUMNS{alcohol_liability_eligible} = ["AL Eligible",   64,    "select"];
16 - 51
  $COLUMNS{visible} = [qw(Visible   65    select)];
25 - 52
  $newleaguebutton = 1;
16 - 53
} else {
54
  push @whereClause, "visible = 1";
55
}
56
 
57
 
2 - 58
# If we need to modify line item values, create a subroutine named "modify_$columnname"
59
#    It will receive a hashref to the object lineitem
60
 
61
sub modify_url {
62
  my $thing = shift;
63
  return $h->a ({ href => $thing->{url}, target => "_blank", onClick=>"event.stopPropagation();" }, $thing->{url});
64
}
65
 
16 - 66
sub modify_visible {
67
  my $thing = shift;
68
  return $thing->{visible} ? "True" : "False";
69
}
70
 
31 - 71
sub modify_alcohol_liability_eligible {
72
  my $thing = shift;
73
  return $thing->{alcohol_liability_eligible} ? "True" : "False";
74
}
75
 
2 - 76
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
77
#    It will receive two fields, the field name and the current filter value (if any)
78
 
16 - 79
sub filter_visible {
80
  my $colName = shift;
81
  my $filter = shift;
82
 
83
  if (defined $filter)  {
84
    if ($filter eq "True") {
85
      return "$colName = 1";
86
    } elsif ($filter eq "False") {
87
      return "$colName = 0";
88
    }
89
  } else {
90
    my $Options = $h->option ("", "True", "False");
91
 
92
    my $tmpfilter = getFilterValue ($colName);
93
 
94
    $Options =~ s/>($tmpfilter)/ selected>$1/;
95
    return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
96
  }
97
}
98
 
31 - 99
sub filter_alcohol_liability_eligible {
100
  my $colName = shift;
101
  my $filter = shift;
102
 
103
  if (defined $filter)  {
104
    if ($filter eq "True") {
105
      return "$colName = 1";
106
    } elsif ($filter eq "False") {
107
      return "$colName = 0";
108
    }
109
  } else {
110
    my $Options = $h->option ("", "True", "False");
111
 
112
    my $tmpfilter = getFilterValue ($colName);
113
 
114
    $Options =~ s/>($tmpfilter)/ selected>$1/;
115
    return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
116
  }
117
}
118
 
2 - 119
# Uncomment and update if we want to enable clicking on a row to open a new page.
120
#
121
sub addRowClick {
122
  my $t = shift;
123
  return "location.href='view_league?id=$t->{id}'";
124
}
125
 
126
# Call the function to print the table view page (with available options)
127
printTablePage ({ Title     => $pageTitle,
128
#                  Prefs     => $prefscookie,
129
                  Table     => $DBTABLE,
130
                  Columns   => \%COLUMNS,
131
                  PEEPSAuth => $PEEPSAUTH_cookie,
132
                  Where     => join (" and ", @whereClause),
25 - 133
                  HeaderButton       => $newleaguebutton ? { field  => "id",
134
                                          button => $h->input ({ type=>"button", value=>"Add", onClick=>"event.stopPropagation(); window.location.href='view_league.pl';" }) } : undef
2 - 135
               });
136
 
5 - 137