Subversion Repositories VORC

Rev

Details | Last modification | View Log | RSS feed

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