| 2 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
| 56 |
bgadell |
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 |
|
| 2 |
- |
9 |
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
|
|
|
10 |
|
| 196 |
- |
11 |
use strict;
|
| 8 |
- |
12 |
use cPanelUserConfig;
|
| 229 |
- |
13 |
use CGI qw/param cookie header start_html url url_param/;
|
| 7 |
- |
14 |
use HTML::Tiny;
|
|
|
15 |
use tableViewer;
|
| 2 |
- |
16 |
use RollerCon;
|
|
|
17 |
use DateTime;
|
|
|
18 |
use DateTime::Duration;
|
| 7 |
- |
19 |
our $h = HTML::Tiny->new( mode => 'html' );
|
| 2 |
- |
20 |
|
| 56 |
bgadell |
21 |
my $cookie_string = authenticate (RollerCon::USER) || die;
|
| 7 |
- |
22 |
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
| 196 |
- |
23 |
my $RCAUTH_cookie = CGI::Cookie->new (-name=>'RCAUTH', -value=>"$cookie_string", -expires=>"+30m");
|
| 56 |
bgadell |
24 |
my $now = DateTime->now (time_zone => 'America/Los_Angeles');
|
| 2 |
- |
25 |
|
| 56 |
bgadell |
26 |
my $pageTitle = "Shift Management";
|
| 7 |
- |
27 |
our $DBTABLE = 'v_shift';
|
|
|
28 |
my %COLUMNS = (
|
|
|
29 |
# colname => [qw(DisplayName N type status)], status -> static | default | <blank>
|
| 196 |
- |
30 |
id => [qw(ID 5 number )],
|
|
|
31 |
dept => [qw(Department 10 select )],
|
|
|
32 |
date => [qw(Date 15 date default )],
|
| 56 |
bgadell |
33 |
dayofweek => [qw(Day 17 select )],
|
| 196 |
- |
34 |
time => [qw(Time 20 text default )],
|
|
|
35 |
start_time => [qw(Start 25 text )],
|
|
|
36 |
end_time => [qw(End 30 text )],
|
|
|
37 |
mod_time => [qw(ModTime 35 number )],
|
|
|
38 |
doubletime => [qw(DoubleTime 37 boolean )],
|
|
|
39 |
volhours => [qw(VolHours 40 number )],
|
|
|
40 |
role => [qw(Role 45 text default )],
|
|
|
41 |
type => [qw(Type 50 select default )],
|
|
|
42 |
location => [qw(Location 55 select default )],
|
|
|
43 |
note => [qw(Notes 60 text default )],
|
|
|
44 |
RCid => [qw(RCID 65 text )],
|
|
|
45 |
derby_name => [qw(Assignee 70 select default )],
|
| 7 |
- |
46 |
);
|
|
|
47 |
|
|
|
48 |
my @whereClause;
|
| 196 |
- |
49 |
# Users should only see shifts within their own departments (except VCI sees all)
|
|
|
50 |
if ($LVL < 5 and $ORCUSER->{VCI} < 2) {
|
| 56 |
bgadell |
51 |
my $string = "dept in (".join ",", map { '"'.$_.'"' } grep { $ORCUSER->{department}->{$_} >= 1 } keys %{$ORCUSER->{department}};
|
| 7 |
- |
52 |
$string .= ")";
|
|
|
53 |
push @whereClause, $string;
|
| 2 |
- |
54 |
}
|
| 56 |
bgadell |
55 |
push @whereClause, "dept != 'PER'";
|
| 2 |
- |
56 |
|
| 7 |
- |
57 |
# If we need to modify line item values, create a subroutine named "modify_$columnname"
|
|
|
58 |
# It will receive a hashref to the object lineitem
|
|
|
59 |
|
| 29 |
- |
60 |
sub modify_doubletime {
|
|
|
61 |
my $thing = shift;
|
|
|
62 |
return $thing->{doubletime} ? "True" : "False";
|
|
|
63 |
}
|
|
|
64 |
|
| 56 |
bgadell |
65 |
sub modify_id {
|
|
|
66 |
my $hr = shift;
|
|
|
67 |
return $hr->{id} unless $LVL >= RollerCon::ADMIN;
|
| 83 |
bgadell |
68 |
if ($hr->{dept} eq "COA" and $hr->{location} =~ /MVP/) {
|
| 56 |
bgadell |
69 |
return $h->a ({ href=>"view_class.pl?id=".getClassID ($hr->{id})."&choice=Update" }, "[Edit Class]");
|
| 252 |
- |
70 |
} elsif ($hr->{dept} eq "COA" and $hr->{role} eq "Seminar Coach") {
|
|
|
71 |
return $h->a ({ href=>"view_seminar.pl?id=".getSeminarID ($hr->{id})."&choice=Update" }, "[Edit Seminar]");
|
| 56 |
bgadell |
72 |
} else {
|
|
|
73 |
my $clicky = $hr->{RCid} ? "event.stopPropagation(); if (confirm('WARNING!\\nYou are modifying a shift that someone has signed up for.')==true) {return true;} else {return false;}" : "return true;";
|
|
|
74 |
my $extrawarning = $hr->{RCid} ? "\\nWARNING! It appears someone is signed up for it." : "";
|
|
|
75 |
return join " ", #$hr->{id},
|
|
|
76 |
$h->a ({ href=>"view_shift.pl?id=$hr->{id}&choice=Update", onClick=>$clicky }, "[Edit]"),
|
|
|
77 |
$h->a ({ href=>"view_shift.pl?id=$hr->{id}&choice=Copy" }, "[Copy]"),
|
|
|
78 |
$h->a ({ href=>"view_shift.pl?id=$hr->{id}&choice=Delete", onClick=>"event.stopPropagation(); if (confirm('Are you sure you want to DELETE this shift?$extrawarning')==true) {return true;} else {return false;}" }, "[Delete]")
|
|
|
79 |
;
|
|
|
80 |
}
|
|
|
81 |
};
|
|
|
82 |
|
|
|
83 |
my $DEPTS = getDepartments;
|
|
|
84 |
sub modify_dept {
|
|
|
85 |
my $hr = shift;
|
| 69 |
bgadell |
86 |
$hr->{orig_dept} = $hr->{dept};
|
| 56 |
bgadell |
87 |
$hr->{dept} = $DEPTS->{$hr->{dept}};
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
sub filter_dept {
|
|
|
91 |
my $colName = shift;
|
| 196 |
- |
92 |
my $filter = shift;
|
|
|
93 |
|
|
|
94 |
if (defined $filter) {
|
|
|
95 |
if ($filter eq "-blank-") {
|
|
|
96 |
return "($colName = '' or isNull($colName) = 1)";
|
|
|
97 |
}
|
|
|
98 |
return "$colName = \"$filter\"";
|
|
|
99 |
} else {
|
| 230 |
- |
100 |
my $tmpFormValue = getFilterValue ($colName);
|
| 196 |
- |
101 |
my $categories = join "", map { $tmpFormValue eq $_ ? $h->option ({ value=>$_, selected=>[] }, $DEPTS->{$_}) : $h->option ({ value=>$_ }, $DEPTS->{$_}) } grep { $LVL > 4 or exists $ORCUSER->{department}->{$_} } grep { !/^PER$/ } sort keys %{$DEPTS};
|
|
|
102 |
my $Options = "<OPTION></OPTION>".$categories;
|
|
|
103 |
|
|
|
104 |
$Options =~ s/>($tmpFormValue)/ selected>$1/;
|
| 222 |
- |
105 |
|
|
|
106 |
my $autoload = param ("autoload") // 1;
|
|
|
107 |
my $onChange = $autoload ? "onChange='page.value = 1; submit();'" : "";
|
| 196 |
- |
108 |
return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
|
|
|
109 |
}
|
| 56 |
bgadell |
110 |
}
|
|
|
111 |
|
| 7 |
- |
112 |
sub modify_derby_name {
|
| 56 |
bgadell |
113 |
my $t = shift;
|
| 69 |
bgadell |
114 |
my $dept = $t->{orig_dept} // $t->{dept};
|
| 56 |
bgadell |
115 |
|
|
|
116 |
if ($t->{derby_name}) {
|
| 196 |
- |
117 |
if ($ORCUSER->{department}->{$dept} >= RollerCon::LEAD or $LVL >= RollerCon::ADMIN) {
|
| 56 |
bgadell |
118 |
$t->{derby_name} = $h->a ({ href=>"/schedule/view_user.pl?RCid=$t->{RCid}" }, $t->{derby_name});
|
|
|
119 |
} else {
|
| 122 |
- |
120 |
$t->{derby_name} = "FILLED" unless getUser($t->{RCid})->{showme};
|
| 56 |
bgadell |
121 |
return $t->{derby_name};
|
|
|
122 |
}
|
| 7 |
- |
123 |
}
|
|
|
124 |
|
| 196 |
- |
125 |
if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
|
|
|
126 |
# Don't let anyone change the assignee for an Hours Request.
|
|
|
127 |
return $t->{derby_name};
|
|
|
128 |
}
|
|
|
129 |
|
| 77 |
bgadell |
130 |
if ($dept eq "COA" and $t->{location} =~ /MVP/) {
|
| 56 |
bgadell |
131 |
return $LVL >= RollerCon::ADMIN ? $t->{derby_name} . " | " . $h->a ({ href=>"view_class.pl?id=".getClassID ($t->{id})."&choice=Update" }, "[Edit Class]") : $t->{derby_name};
|
| 252 |
- |
132 |
} elsif ($dept eq "COA" and $t->{role} eq "Seminar Coach") {
|
|
|
133 |
return $LVL >= RollerCon::ADMIN ? $t->{derby_name} . " | " . $h->a ({ href=>"view_seminar.pl?id=".getSeminarID ($t->{id})."&choice=Update" }, "[Edit Seminar]") : $t->{derby_name};
|
| 56 |
bgadell |
134 |
}
|
|
|
135 |
|
| 196 |
- |
136 |
my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
|
|
|
137 |
my $cutoff = DateTime->new(
|
| 7 |
- |
138 |
year => $yyyy,
|
|
|
139 |
month => $mm,
|
|
|
140 |
day => $dd,
|
|
|
141 |
hour => 5,
|
|
|
142 |
minute => 0,
|
|
|
143 |
second => 0,
|
|
|
144 |
time_zone => 'America/Los_Angeles'
|
|
|
145 |
);
|
| 56 |
bgadell |
146 |
|
| 196 |
- |
147 |
if (($t->{RCid} == $ORCUSER->{RCid} and $t->{type} ne "selected" and $now < $cutoff) or ($t->{derby_name} and ($ORCUSER->{department}->{$dept} >= 2 or $LVL >= 5))) {
|
|
|
148 |
# DROP
|
|
|
149 |
$t->{derby_name} = "$t->{derby_name} <A HREF='#' onClick=\"event.stopPropagation(); if (confirm('Really? You want to drop this person from the shift?')==true) { window.open('make_shift_change.pl?change=del&RCid=$t->{RCid}&id=$t->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false; }\">[DROP]</a>";
|
|
|
150 |
if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
|
|
|
151 |
# NO SHOW
|
|
|
152 |
$t->{derby_name} .= " | <A HREF='#' onClick=\"event.stopPropagation(); if (confirm('Really? They were a no show?')==true) { window.open('make_shift_change.pl?noshow=true&change=del&RCid=$t->{RCid}&id=$t->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false; }\">[NO SHOW]</a>";
|
|
|
153 |
}
|
|
|
154 |
} elsif (!$t->{derby_name}) {
|
|
|
155 |
if (findConflict ($ORCUSER->{RCid}, $t->{id})) {
|
| 100 |
bgadell |
156 |
$t->{derby_name} .= "*schedule conflict*";
|
| 196 |
- |
157 |
} elsif ($dept eq "EMT" and !$ORCUSER->{emt_verified}) {
|
|
|
158 |
$t->{derby_name} .= "*needs verification*";
|
| 100 |
bgadell |
159 |
} elsif (signUpEligible ($ORCUSER, $t, "vol") and $now < $cutoff) {
|
| 196 |
- |
160 |
# SIGN UP
|
|
|
161 |
$t->{derby_name} = "<A HREF='#' onClick=\"event.stopPropagation(); window.open('make_shift_change.pl?change=add&RCid=$ORCUSER->{RCid}&id=$t->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[SIGN UP]</a>";
|
|
|
162 |
}
|
|
|
163 |
if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
|
|
|
164 |
# ADD USER
|
|
|
165 |
$t->{derby_name} ? $t->{derby_name} .= " | " : {};
|
|
|
166 |
$t->{derby_name} .= "<A HREF='#' onClick=\"event.stopPropagation(); window.open('make_shift_change.pl?change=lookup&RCid=$ORCUSER->{RCid}&id=$t->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[ADD USER]</a>";
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
return $t->{derby_name};
|
| 7 |
- |
170 |
}
|
|
|
171 |
|
| 56 |
bgadell |
172 |
sub modify_time {
|
|
|
173 |
my $t = shift;
|
|
|
174 |
return convertTime $t->{time};
|
| 7 |
- |
175 |
}
|
|
|
176 |
|
| 56 |
bgadell |
177 |
sub modify_start_time {
|
|
|
178 |
my $t = shift;
|
|
|
179 |
return convertTime $t->{start_time};
|
| 7 |
- |
180 |
}
|
|
|
181 |
|
| 56 |
bgadell |
182 |
sub modify_end_time {
|
| 50 |
bgadell |
183 |
my $t = shift;
|
| 56 |
bgadell |
184 |
return convertTime $t->{end_time};
|
| 50 |
bgadell |
185 |
}
|
| 7 |
- |
186 |
|
| 196 |
- |
187 |
sub modify_volhours {
|
|
|
188 |
my $t = shift;
|
|
|
189 |
if ($t->{type} eq "request") {
|
|
|
190 |
return "<i>TBD</i>";
|
| 7 |
- |
191 |
} else {
|
| 196 |
- |
192 |
return $t->{volhours};
|
| 7 |
- |
193 |
}
|
|
|
194 |
}
|
| 2 |
- |
195 |
|
| 196 |
- |
196 |
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
|
|
|
197 |
# It will receive two fields, the field name and the current filter value (if any)
|
| 2 |
- |
198 |
|
| 196 |
- |
199 |
# Uncomment and update if we want to enable clicking on a row to open a new page.
|
|
|
200 |
#
|
|
|
201 |
sub addRowClick {
|
|
|
202 |
my $t = shift;
|
| 7 |
- |
203 |
|
| 196 |
- |
204 |
if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
|
|
|
205 |
return "location.href='missing_hours.pl?id=$t->{id}'";
|
| 7 |
- |
206 |
} else {
|
| 196 |
- |
207 |
return "location.href='view_shift.pl?id=$t->{id}'";
|
| 7 |
- |
208 |
}
|
|
|
209 |
}
|
| 2 |
- |
210 |
|
| 196 |
- |
211 |
# Call the function to print the table view page (with available options)
|
|
|
212 |
printTablePage ({ Title => $pageTitle,
|
|
|
213 |
Table => $DBTABLE,
|
|
|
214 |
Columns => \%COLUMNS,
|
|
|
215 |
Where => join (" and ", @whereClause),
|
|
|
216 |
RCAuth => $RCAUTH_cookie,
|
|
|
217 |
DisplayYearSelect => 1,
|
|
|
218 |
ShowMyShifts => 1,
|
|
|
219 |
HighlightShifts => 1,
|
|
|
220 |
PersonalTimeButton => 1,
|
| 222 |
- |
221 |
HeaderButton => { field => "id",
|
|
|
222 |
button => $h->input ({ type=>"button", value=>"Add", onClick=>"event.stopPropagation(); window.location.href='view_shift.pl'" }) }
|
| 196 |
- |
223 |
});
|