| 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]");
|
|
|
70 |
} else {
|
|
|
71 |
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;";
|
|
|
72 |
my $extrawarning = $hr->{RCid} ? "\\nWARNING! It appears someone is signed up for it." : "";
|
|
|
73 |
return join " ", #$hr->{id},
|
|
|
74 |
$h->a ({ href=>"view_shift.pl?id=$hr->{id}&choice=Update", onClick=>$clicky }, "[Edit]"),
|
|
|
75 |
$h->a ({ href=>"view_shift.pl?id=$hr->{id}&choice=Copy" }, "[Copy]"),
|
|
|
76 |
$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]")
|
|
|
77 |
;
|
|
|
78 |
}
|
|
|
79 |
};
|
|
|
80 |
|
|
|
81 |
my $DEPTS = getDepartments;
|
|
|
82 |
sub modify_dept {
|
|
|
83 |
my $hr = shift;
|
| 69 |
bgadell |
84 |
$hr->{orig_dept} = $hr->{dept};
|
| 56 |
bgadell |
85 |
$hr->{dept} = $DEPTS->{$hr->{dept}};
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
sub filter_dept {
|
|
|
89 |
my $colName = shift;
|
| 196 |
- |
90 |
my $filter = shift;
|
|
|
91 |
|
|
|
92 |
if (defined $filter) {
|
|
|
93 |
if ($filter eq "-blank-") {
|
|
|
94 |
return "($colName = '' or isNull($colName) = 1)";
|
|
|
95 |
}
|
|
|
96 |
return "$colName = \"$filter\"";
|
|
|
97 |
} else {
|
| 230 |
- |
98 |
my $tmpFormValue = getFilterValue ($colName);
|
| 196 |
- |
99 |
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};
|
|
|
100 |
my $Options = "<OPTION></OPTION>".$categories;
|
|
|
101 |
|
|
|
102 |
$Options =~ s/>($tmpFormValue)/ selected>$1/;
|
| 222 |
- |
103 |
|
|
|
104 |
my $autoload = param ("autoload") // 1;
|
|
|
105 |
my $onChange = $autoload ? "onChange='page.value = 1; submit();'" : "";
|
| 196 |
- |
106 |
return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
|
|
|
107 |
}
|
| 56 |
bgadell |
108 |
}
|
|
|
109 |
|
| 7 |
- |
110 |
sub modify_derby_name {
|
| 56 |
bgadell |
111 |
my $t = shift;
|
| 69 |
bgadell |
112 |
my $dept = $t->{orig_dept} // $t->{dept};
|
| 56 |
bgadell |
113 |
|
|
|
114 |
if ($t->{derby_name}) {
|
| 196 |
- |
115 |
if ($ORCUSER->{department}->{$dept} >= RollerCon::LEAD or $LVL >= RollerCon::ADMIN) {
|
| 56 |
bgadell |
116 |
$t->{derby_name} = $h->a ({ href=>"/schedule/view_user.pl?RCid=$t->{RCid}" }, $t->{derby_name});
|
|
|
117 |
} else {
|
| 122 |
- |
118 |
$t->{derby_name} = "FILLED" unless getUser($t->{RCid})->{showme};
|
| 56 |
bgadell |
119 |
return $t->{derby_name};
|
|
|
120 |
}
|
| 7 |
- |
121 |
}
|
|
|
122 |
|
| 196 |
- |
123 |
if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
|
|
|
124 |
# Don't let anyone change the assignee for an Hours Request.
|
|
|
125 |
return $t->{derby_name};
|
|
|
126 |
}
|
|
|
127 |
|
| 77 |
bgadell |
128 |
if ($dept eq "COA" and $t->{location} =~ /MVP/) {
|
| 56 |
bgadell |
129 |
return $LVL >= RollerCon::ADMIN ? $t->{derby_name} . " | " . $h->a ({ href=>"view_class.pl?id=".getClassID ($t->{id})."&choice=Update" }, "[Edit Class]") : $t->{derby_name};
|
|
|
130 |
}
|
|
|
131 |
|
| 196 |
- |
132 |
my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
|
|
|
133 |
my $cutoff = DateTime->new(
|
| 7 |
- |
134 |
year => $yyyy,
|
|
|
135 |
month => $mm,
|
|
|
136 |
day => $dd,
|
|
|
137 |
hour => 5,
|
|
|
138 |
minute => 0,
|
|
|
139 |
second => 0,
|
|
|
140 |
time_zone => 'America/Los_Angeles'
|
|
|
141 |
);
|
| 56 |
bgadell |
142 |
|
| 196 |
- |
143 |
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))) {
|
|
|
144 |
# DROP
|
|
|
145 |
$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>";
|
|
|
146 |
if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
|
|
|
147 |
# NO SHOW
|
|
|
148 |
$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>";
|
|
|
149 |
}
|
|
|
150 |
} elsif (!$t->{derby_name}) {
|
|
|
151 |
if (findConflict ($ORCUSER->{RCid}, $t->{id})) {
|
| 100 |
bgadell |
152 |
$t->{derby_name} .= "*schedule conflict*";
|
| 196 |
- |
153 |
} elsif ($dept eq "EMT" and !$ORCUSER->{emt_verified}) {
|
|
|
154 |
$t->{derby_name} .= "*needs verification*";
|
| 100 |
bgadell |
155 |
} elsif (signUpEligible ($ORCUSER, $t, "vol") and $now < $cutoff) {
|
| 196 |
- |
156 |
# SIGN UP
|
|
|
157 |
$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>";
|
|
|
158 |
}
|
|
|
159 |
if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
|
|
|
160 |
# ADD USER
|
|
|
161 |
$t->{derby_name} ? $t->{derby_name} .= " | " : {};
|
|
|
162 |
$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>";
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
return $t->{derby_name};
|
| 7 |
- |
166 |
}
|
|
|
167 |
|
| 56 |
bgadell |
168 |
sub modify_time {
|
|
|
169 |
my $t = shift;
|
|
|
170 |
return convertTime $t->{time};
|
| 7 |
- |
171 |
}
|
|
|
172 |
|
| 56 |
bgadell |
173 |
sub modify_start_time {
|
|
|
174 |
my $t = shift;
|
|
|
175 |
return convertTime $t->{start_time};
|
| 7 |
- |
176 |
}
|
|
|
177 |
|
| 56 |
bgadell |
178 |
sub modify_end_time {
|
| 50 |
bgadell |
179 |
my $t = shift;
|
| 56 |
bgadell |
180 |
return convertTime $t->{end_time};
|
| 50 |
bgadell |
181 |
}
|
| 7 |
- |
182 |
|
| 196 |
- |
183 |
sub modify_volhours {
|
|
|
184 |
my $t = shift;
|
|
|
185 |
if ($t->{type} eq "request") {
|
|
|
186 |
return "<i>TBD</i>";
|
| 7 |
- |
187 |
} else {
|
| 196 |
- |
188 |
return $t->{volhours};
|
| 7 |
- |
189 |
}
|
|
|
190 |
}
|
| 2 |
- |
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)
|
| 2 |
- |
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;
|
| 7 |
- |
199 |
|
| 196 |
- |
200 |
if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
|
|
|
201 |
return "location.href='missing_hours.pl?id=$t->{id}'";
|
| 7 |
- |
202 |
} else {
|
| 196 |
- |
203 |
return "location.href='view_shift.pl?id=$t->{id}'";
|
| 7 |
- |
204 |
}
|
|
|
205 |
}
|
| 2 |
- |
206 |
|
| 196 |
- |
207 |
# Call the function to print the table view page (with available options)
|
|
|
208 |
printTablePage ({ Title => $pageTitle,
|
|
|
209 |
Table => $DBTABLE,
|
|
|
210 |
Columns => \%COLUMNS,
|
|
|
211 |
Where => join (" and ", @whereClause),
|
|
|
212 |
RCAuth => $RCAUTH_cookie,
|
|
|
213 |
DisplayYearSelect => 1,
|
|
|
214 |
ShowMyShifts => 1,
|
|
|
215 |
HighlightShifts => 1,
|
|
|
216 |
PersonalTimeButton => 1,
|
| 222 |
- |
217 |
HeaderButton => { field => "id",
|
|
|
218 |
button => $h->input ({ type=>"button", value=>"Add", onClick=>"event.stopPropagation(); window.location.href='view_shift.pl'" }) }
|
| 196 |
- |
219 |
});
|