Subversion Repositories VORC

Rev

Rev 138 | Rev 222 | Go to most recent revision | 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;
7 - 13
use CGI qw/param cookie header start_html url/;
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 "&nbsp;", #$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 {
98
    my $tmpFormValue = param ("filter-${colName}");
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/;
103
    my $onChange = param ("autoload") ? "onChange='page.value = 1; submit();'" : "";
104
    return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
105
  }
56 bgadell 106
}
107
 
7 - 108
sub modify_derby_name {
56 bgadell 109
  my $t = shift;
69 bgadell 110
  my $dept = $t->{orig_dept} // $t->{dept};
56 bgadell 111
 
112
  if ($t->{derby_name}) {
196 - 113
    if ($ORCUSER->{department}->{$dept} >= RollerCon::LEAD or $LVL >= RollerCon::ADMIN) {
56 bgadell 114
      $t->{derby_name} = $h->a ({ href=>"/schedule/view_user.pl?RCid=$t->{RCid}" }, $t->{derby_name});
115
    } else {
122 - 116
      $t->{derby_name} = "FILLED" unless getUser($t->{RCid})->{showme};
56 bgadell 117
      return $t->{derby_name};
118
    }
7 - 119
  }
120
 
196 - 121
  if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
122
    # Don't let anyone change the assignee for an Hours Request.
123
    return $t->{derby_name};
124
  }
125
 
77 bgadell 126
  if ($dept eq "COA" and $t->{location} =~ /MVP/) {
56 bgadell 127
    return $LVL >= RollerCon::ADMIN ? $t->{derby_name} . " | " . $h->a ({ href=>"view_class.pl?id=".getClassID ($t->{id})."&choice=Update" }, "[Edit Class]") : $t->{derby_name};
128
  }
129
 
196 - 130
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
131
  my $cutoff = DateTime->new(
7 - 132
        year => $yyyy,
133
        month => $mm,
134
        day => $dd,
135
        hour => 5,
136
        minute => 0,
137
        second => 0,
138
        time_zone => 'America/Los_Angeles'
139
  );
56 bgadell 140
 
196 - 141
  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))) {
142
    # DROP
143
    $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>";
144
    if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
145
      # NO SHOW
146
      $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>";
147
    }
148
  } elsif (!$t->{derby_name}) {
149
    if (findConflict ($ORCUSER->{RCid}, $t->{id})) {
100 bgadell 150
      $t->{derby_name} .= "*schedule conflict*";
196 - 151
    } elsif ($dept eq "EMT" and !$ORCUSER->{emt_verified}) {
152
      $t->{derby_name} .= "*needs verification*";
100 bgadell 153
    } elsif (signUpEligible ($ORCUSER, $t, "vol") and $now < $cutoff) {
196 - 154
      # SIGN UP
155
      $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>";
156
    }
157
    if ($ORCUSER->{department}->{$dept} >= 2 or $LVL > 4) {
158
      # ADD USER
159
      $t->{derby_name} ? $t->{derby_name} .= " | " : {};
160
      $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>";
161
    }
162
  }
163
  return $t->{derby_name};
7 - 164
}
165
 
56 bgadell 166
sub modify_time {
167
  my $t = shift;
168
  return convertTime $t->{time};
7 - 169
}
170
 
56 bgadell 171
sub modify_start_time {
172
  my $t = shift;
173
  return convertTime $t->{start_time};
7 - 174
}
175
 
56 bgadell 176
sub modify_end_time {
50 bgadell 177
  my $t = shift;
56 bgadell 178
  return convertTime $t->{end_time};
50 bgadell 179
}
7 - 180
 
196 - 181
sub modify_volhours {
182
  my $t = shift;
183
  if ($t->{type} eq "request") {
184
    return "<i>TBD</i>";
7 - 185
  } else {
196 - 186
    return $t->{volhours};
7 - 187
  }
188
}
2 - 189
 
196 - 190
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
191
#    It will receive two fields, the field name and the current filter value (if any)
2 - 192
 
196 - 193
# Uncomment and update if we want to enable clicking on a row to open a new page.
194
#
195
sub addRowClick {
196
  my $t = shift;
7 - 197
 
196 - 198
  if ($t->{type} eq "request" or $t->{type} eq "approved" or $t->{type} eq "denied") {
199
    return "location.href='missing_hours.pl?id=$t->{id}'";
7 - 200
  } else {
196 - 201
    return "location.href='view_shift.pl?id=$t->{id}'";
7 - 202
  }
203
}
2 - 204
 
196 - 205
# Call the function to print the table view page (with available options)
206
printTablePage ({ Title   => $pageTitle,
207
                  Table   => $DBTABLE,
208
                  Columns => \%COLUMNS,
209
                  Where   => join (" and ", @whereClause),
210
                  RCAuth  => $RCAUTH_cookie,
211
                  DisplayYearSelect => 1,
212
                  ShowMyShifts  => 1,
213
                  HighlightShifts => 1,
214
                  PersonalTimeButton => 1,
215
                 });