Subversion Repositories VORC

Rev

Rev 275 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
275 - 48
if ($LVL >= RollerCon::SYSADMIN) {
49
  $COLUMNS{full_name} = [qw(FullName  75  text)];
50
}
51
 
7 - 52
my @whereClause;
196 - 53
# Users should only see shifts within their own departments (except VCI sees all)
54
if ($LVL < 5 and $ORCUSER->{VCI} < 2) {
56 bgadell 55
  my $string = "dept in (".join ",", map { '"'.$_.'"' } grep { $ORCUSER->{department}->{$_} >= 1 } keys %{$ORCUSER->{department}};
7 - 56
  $string .= ")";
57
  push @whereClause, $string;
2 - 58
}
56 bgadell 59
push @whereClause, "dept != 'PER'";
2 - 60
 
7 - 61
# If we need to modify line item values, create a subroutine named "modify_$columnname"
62
#    It will receive a hashref to the object lineitem
63
 
29 - 64
sub modify_doubletime {
65
  my $thing = shift;
66
  return $thing->{doubletime} ? "True" : "False";
67
}
68
 
56 bgadell 69
sub modify_id {
70
  my $hr = shift;
71
  return $hr->{id} unless $LVL >= RollerCon::ADMIN;
83 bgadell 72
  if ($hr->{dept} eq "COA" and $hr->{location} =~ /MVP/) {
301 - 73
    return $h->a ({ href=>"view_class.pl?id=".getClassID ($hr->{id}) }, "[View Class]");
252 - 74
  } elsif ($hr->{dept} eq "COA" and $hr->{role} eq "Seminar Coach") {
301 - 75
    return $h->a ({ href=>"view_seminar.pl?id=".getSeminarID ($hr->{id}) }, "[View Seminar]");
56 bgadell 76
  } else {
77
    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;";
78
    my $extrawarning = $hr->{RCid} ? "\\nWARNING! It appears someone is signed up for it." : "";
79
    return join "&nbsp;", #$hr->{id},
80
           $h->a ({ href=>"view_shift.pl?id=$hr->{id}&choice=Update", onClick=>$clicky }, "[Edit]"),
81
           $h->a ({ href=>"view_shift.pl?id=$hr->{id}&choice=Copy" }, "[Copy]"),
82
           $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]")
83
    ;
84
  }
85
};
86
 
87
my $DEPTS = getDepartments;
88
sub modify_dept {
89
  my $hr = shift;
69 bgadell 90
  $hr->{orig_dept} = $hr->{dept};
56 bgadell 91
  $hr->{dept} = $DEPTS->{$hr->{dept}};
92
}
93
 
94
sub filter_dept {
95
  my $colName = shift;
196 - 96
  my $filter = shift;
97
 
98
  if (defined $filter)  {
99
    if ($filter eq "-blank-") {
100
      return "($colName = '' or isNull($colName) = 1)";
101
    }
102
    return "$colName = \"$filter\"";
103
  } else {
230 - 104
    my $tmpFormValue = getFilterValue ($colName);
196 - 105
    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};
106
    my $Options = "<OPTION></OPTION>".$categories;
107
 
108
    $Options =~ s/>($tmpFormValue)/ selected>$1/;
222 - 109
 
110
    my $autoload = param ("autoload") // 1;
111
    my $onChange = $autoload ? "onChange='page.value = 1; submit();'" : "";
196 - 112
    return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
113
  }
56 bgadell 114
}
115
 
7 - 116
sub modify_derby_name {
56 bgadell 117
  my $t = shift;
69 bgadell 118
  my $dept = $t->{orig_dept} // $t->{dept};
56 bgadell 119
 
120
  if ($t->{derby_name}) {
196 - 121
    if ($ORCUSER->{department}->{$dept} >= RollerCon::LEAD or $LVL >= RollerCon::ADMIN) {
56 bgadell 122
      $t->{derby_name} = $h->a ({ href=>"/schedule/view_user.pl?RCid=$t->{RCid}" }, $t->{derby_name});
123
    } else {
122 - 124
      $t->{derby_name} = "FILLED" unless getUser($t->{RCid})->{showme};
56 bgadell 125
      return $t->{derby_name};
126
    }
7 - 127
  }
128
 
196 - 129
  if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
130
    # Don't let anyone change the assignee for an Hours Request.
131
    return $t->{derby_name};
132
  }
133
 
77 bgadell 134
  if ($dept eq "COA" and $t->{location} =~ /MVP/) {
301 - 135
    return $LVL >= RollerCon::ADMIN ? $t->{derby_name} . " | " . $h->a ({ href=>"view_class.pl?id=".getClassID ($t->{id}) }, "[View Class]") : $t->{derby_name};
252 - 136
  } elsif ($dept eq "COA" and $t->{role} eq "Seminar Coach") {
301 - 137
    return $LVL >= RollerCon::ADMIN ? $t->{derby_name} . " | " . $h->a ({ href=>"view_seminar.pl?id=".getSeminarID ($t->{id}) }, "[View Seminar]") : $t->{derby_name};
56 bgadell 138
  }
139
 
196 - 140
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
141
  my $cutoff = DateTime->new(
7 - 142
        year => $yyyy,
143
        month => $mm,
144
        day => $dd,
145
        hour => 5,
146
        minute => 0,
147
        second => 0,
148
        time_zone => 'America/Los_Angeles'
149
  );
56 bgadell 150
 
196 - 151
  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))) {
152
    # DROP
153
    $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>";
154
    if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
155
      # NO SHOW
156
      $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>";
157
    }
158
  } elsif (!$t->{derby_name}) {
159
    if (findConflict ($ORCUSER->{RCid}, $t->{id})) {
100 bgadell 160
      $t->{derby_name} .= "*schedule conflict*";
196 - 161
    } elsif ($dept eq "EMT" and !$ORCUSER->{emt_verified}) {
162
      $t->{derby_name} .= "*needs verification*";
100 bgadell 163
    } elsif (signUpEligible ($ORCUSER, $t, "vol") and $now < $cutoff) {
196 - 164
      # SIGN UP
165
      $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>";
166
    }
167
    if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
168
      # ADD USER
169
      $t->{derby_name} ? $t->{derby_name} .= " | " : {};
170
      $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>";
171
    }
172
  }
173
  return $t->{derby_name};
7 - 174
}
175
 
56 bgadell 176
sub modify_time {
177
  my $t = shift;
178
  return convertTime $t->{time};
7 - 179
}
180
 
56 bgadell 181
sub modify_start_time {
182
  my $t = shift;
183
  return convertTime $t->{start_time};
7 - 184
}
185
 
56 bgadell 186
sub modify_end_time {
50 bgadell 187
  my $t = shift;
56 bgadell 188
  return convertTime $t->{end_time};
50 bgadell 189
}
7 - 190
 
196 - 191
sub modify_volhours {
192
  my $t = shift;
193
  if ($t->{type} eq "request") {
194
    return "<i>TBD</i>";
7 - 195
  } else {
196 - 196
    return $t->{volhours};
7 - 197
  }
198
}
2 - 199
 
196 - 200
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
201
#    It will receive two fields, the field name and the current filter value (if any)
2 - 202
 
196 - 203
# Uncomment and update if we want to enable clicking on a row to open a new page.
204
#
205
sub addRowClick {
206
  my $t = shift;
7 - 207
 
196 - 208
  if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
209
    return "location.href='missing_hours.pl?id=$t->{id}'";
7 - 210
  } else {
196 - 211
    return "location.href='view_shift.pl?id=$t->{id}'";
7 - 212
  }
213
}
2 - 214
 
196 - 215
# Call the function to print the table view page (with available options)
216
printTablePage ({ Title   => $pageTitle,
217
                  Table   => $DBTABLE,
218
                  Columns => \%COLUMNS,
219
                  Where   => join (" and ", @whereClause),
220
                  RCAuth  => $RCAUTH_cookie,
221
                  DisplayYearSelect => 1,
222
                  ShowMyShifts  => 1,
223
                  HighlightShifts => 1,
224
                  PersonalTimeButton => 1,
222 - 225
                  HeaderButton => { field  => "id",
226
                                    button => $h->input ({ type=>"button", value=>"Add", onClick=>"event.stopPropagation(); window.location.href='view_shift.pl'" }) }
196 - 227
                 });