Subversion Repositories VORC

Rev

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