Subversion Repositories VORC

Rev

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