Subversion Repositories VORC

Rev

Rev 199 | Rev 222 | 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
use DateTime;
18
my $now = DateTime->now (time_zone => 'America/Los_Angeles');
19
our $h = HTML::Tiny->new( mode => 'html' );
20
 
196 - 21
my $cookie_string = authenticate(1) || die;
22
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
23
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
24
my $RCid = $ORCUSER->{RCid};
56 bgadell 25
 
196 - 26
if (!$ORCUSER->{MVPid} and $LVL < RollerCon::ADMIN and $ORCUSER->{department}->{MVP} < RollerCon::USER and $ORCUSER->{department}->{COA} < RollerCon::USER) {
27
  print header(-cookie=>$RCAUTH_cookie);
28
  printRCHeader("Unauthorized Page");
29
  print $h->div ({ class=>"error" }, "No Access");
30
  print $h->div ("Your user account is not registered to sign up for MVP Classes, so you can't see this page.  It's possible that your access is still being reviewed.  Please be patient.");
31
  print $h->a ({ href=>"/schedule/" }, "[Go Home]");
32
  print $h->close ("html");
33
  exit;
56 bgadell 34
}
35
 
36
my $pageTitle = "MVP Classes";
208 - 37
our $DBTABLE = 'v_class_new';
56 bgadell 38
my %COLUMNS = (
39
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
196 - 40
  name        => [qw(Class         5    text     static )],
41
  date        => [qw(Date         10    date              )],
42
  dayofweek   => [qw(Day          15    select    default )],
43
  start_time  => [qw(StartTime    20    text      )],
44
  end_time    => [qw(EndTime      25    text       )],
45
  time        => [qw(Time         30    text      default )],
46
  location    => [qw(Track        35    select    default )],
47
  level       => [qw(Level        37    select    default )],
208 - 48
  coach       => [qw(Coach        40    select    default )],
49
  assistant   => [qw(Assistant    41    select     )]
56 bgadell 50
);
51
 
52
if ($LVL >= RollerCon::ADMIN) {
53
  $COLUMNS{id}       = [qw(Admin         1    none        default )];
196 - 54
  $COLUMNS{available}= [qw(SignUp       45    text       )]
56 bgadell 55
}
56
 
196 - 57
if ($LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::VOLUNTEER or $ORCUSER->{department}->{COA} >= RollerCon::USER) {
58
  $COLUMNS{note}       = [qw(Notes         60    text         )],
59
  $COLUMNS{capacity}   = [qw(Capacity      65    number        default )],
60
  $COLUMNS{count}      = [qw(Count         70    number      default )],
61
  $COLUMNS{stars}      = [qw(Stars         75    number      default )],
62
  $COLUMNS{responses}  = [qw(Responses     80    number      default )],
56 bgadell 63
}
64
 
196 - 65
if ($ORCUSER->{MVPid} and $LVL < RollerCon::ADMIN) {
66
  $COLUMNS{available}= [qw(SignUp       45    text       static)]
56 bgadell 67
}
68
 
69
# Set any custom "where" DB filters here...
70
my @whereClause;
71
 
72
# If we need to modify line item values, create a subroutine named "modify_$columnname"
73
#    It will receive a hashref to the object lineitem
74
 
75
my $dbh = getRCDBH;
76
 
77
sub modify_id {
78
  my $hr = shift;
79
  my $clicky = $hr->{count} ? "event.stopPropagation(); if (confirm('WARNING!\\nYou are modifying a class that someone has signed up for.')==true) {return true;} else {return false;}" : "return true;";
80
  my $extrawarning = $hr->{count} ? "\\nWARNING! It appears someone is signed up for it." : "";
81
  return join "&nbsp;", #$hr->{id},
82
         $h->a ({ href=>"view_class.pl?id=$hr->{id}&choice=Update", onClick=>$clicky }, "[Edit]"),
83
         $h->a ({ href=>"view_class.pl?id=$hr->{id}&choice=Copy" }, "[Copy]"),
84
         $h->a ({ href=>"view_class.pl?id=$hr->{id}&choice=Delete", onClick=>"event.stopPropagation(); if (confirm('Are you sure you want to DELETE this class?$extrawarning')==true) {return true;} else {return false;}" }, "[Delete]")
85
  ;
86
};
87
 
88
sub modify_available {
196 - 89
  my $t = shift;
90
 
91
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
92
  my $cutoff = DateTime->new(
56 bgadell 93
        year => $yyyy,
94
        month => $mm,
95
        day => $dd,
96
        hour => 5,
97
        minute => 0,
98
        second => 0,
99
        time_zone => 'America/Los_Angeles'
100
  );
101
 
102
  return "CLOSED" unless $now < $cutoff;
103
 
196 - 104
  my $classkey = join '|', $t->{date}, $t->{start_time}, $t->{location};
105
 
208 - 106
  ($t->{signedup}) = $dbh->selectrow_array ("select role from v_class_signup_new where RCid = ? and id = ?", undef, $RCid, $t->{id} );
196 - 107
  my $droplink = $h->a ({ onClick=>"if (confirm('Really? You want to drop this class?')==true) { window.open('make_shift_change.pl?change=del&RCid=$RCid&id=$t->{id}&role=$t->{signedup}','Confirm Change','resizable,height=260,width=370'); return false; }" }, "[DROP]");
108
  if (!$t->{available}) {
109
    my $full = "FULL";
110
    $full .= " | ".$droplink unless !$t->{signedup};
111
    return $full;
56 bgadell 112
  }
113
 
196 - 114
  $t->{available} .= " Open";
56 bgadell 115
  $t->{available} .= " | ".$droplink unless !$t->{signedup};
85 bgadell 116
  if (findConflict ($ORCUSER->{RCid}, $t->{id}, "class")) {
87 bgadell 117
    $t->{available} .= " | *schedule conflict*" unless $t->{signedup};
85 bgadell 118
  } elsif (signUpEligible ($ORCUSER, $t, "class")) {
196 - 119
    # SIGN UP
120
    $t->{available} .= " | ".$h->a ({ onClick=>"event.stopPropagation(); window.open('make_shift_change.pl?change=add&RCid=$RCid&id=$classkey','Confirm Class Change','resizable,height=260,width=370'); return false;" }, "[SIGN UP]");
121
  }
122
  if ($LVL > 4 or $ORCUSER->{department}->{VCI} >= 2) {
123
    # ADD USER
124
    $t->{available} ? $t->{available} .= " | " : {};
125
    $t->{available} .= $h->a ({ onClick=>"event.stopPropagation(); window.open('make_shift_change.pl?change=lookup&RCid=$RCid&id=$classkey','Confirm Class Change','resizable,height=260,width=370'); return false;" }, "[ADD USER]");
126
  }
127
 
128
  return $t->{available};
56 bgadell 129
}
130
 
131
sub filter_available {
132
  my $colName = shift;
196 - 133
  my $filter = shift;
134
 
135
  if (defined $filter)  {
136
    if ($filter eq "Full") {
137
      return "$colName = 0";
138
    }
139
    return "$colName > 0";
140
  } else {
141
    my $thing = "filter-${colName}";
142
    my $Options = "<OPTION></OPTION>"."<OPTION>Available</OPTION>"."<OPTION>Full</OPTION>";
143
 
144
    my $tmpfilter = param ("filter-$colName");
145
    $Options =~ s/>($tmpfilter)/ selected>$1/;
146
    return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
147
  }
56 bgadell 148
}
149
 
150
sub modify_time {
151
  my $t = shift;
152
  return convertTime $t->{time};
153
}
154
 
155
sub modify_start_time {
156
  my $t = shift;
157
  return convertTime $t->{start_time};
158
}
159
 
160
sub modify_end_time {
161
  my $t = shift;
162
  return convertTime $t->{end_time};
163
}
164
 
112 - 165
sub modify_stars {
166
  my $t = shift;
196 - 167
  if ($t->{coach} eq $ORCUSER->{derby_name} or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::MANAGER) {
112 - 168
    $t->{stars} = $t->{stars};
169
  } else {
170
    $t->{stars} = '&nbsp;';
171
  }
172
}
56 bgadell 173
 
112 - 174
sub modify_responses {
175
  my $t = shift;
196 - 176
  if ($t->{coachRCid} == $ORCUSER->{RCid} or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::MANAGER) {
112 - 177
    $t->{responses} = $t->{responses} // '0';
178
  } else {
179
    $t->{responses} = '&nbsp;';
180
  }
181
}
182
 
196 - 183
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
184
#    It will receive two fields, the field name and the current filter value (if any)
112 - 185
 
196 - 186
# Uncomment and update if we want to enable clicking on a row to open a new page.
187
#
188
sub addRowClick {
189
  my $t = shift;
56 bgadell 190
 
196 - 191
  if ($LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::VOLUNTEER or $ORCUSER->{department}->{COA} >= RollerCon::VOLUNTEER) {
192
    return "location.href='view_class.pl?id=$t->{id}&choice=View'";
56 bgadell 193
  } else {
196 - 194
    return "";
56 bgadell 195
  }
196
}
197
 
196 - 198
# Call the function to print the table view page (with available options)
56 bgadell 199
 
196 - 200
printTablePage ({ Title   => $pageTitle,
201
                  Table   => $DBTABLE,
202
                  Columns => \%COLUMNS,
203
                  RCAuth  => $RCAUTH_cookie,
204
                  DisplayYearSelect => 1,
199 - 205
                  ShowMyShifts       => 1,
196 - 206
                  PersonalTimeButton => 1,
207
                 });