Subversion Repositories VORC

Rev

Rev 55 | Rev 195 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 55 Rev 56
Line 1... Line 1...
1
#!/usr/bin/perl
1
#!/usr/bin/perl
Line -... Line 2...
-
 
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";
2
 
8
 
3
use strict;
9
use strict;
4
use cPanelUserConfig;
10
use cPanelUserConfig;
5
use WebDB;
11
use WebDB;
6
use HTML::Tiny;
12
use HTML::Tiny;
7
use RollerCon;
13
use RollerCon;
8
use CGI qw/param header start_html url/;
14
use CGI qw/param header start_html url/;
Line 9... Line 15...
9
my $h = HTML::Tiny->new( mode => 'html' );
15
my $h = HTML::Tiny->new( mode => 'html' );
Line 10... Line 16...
10
 
16
 
11
my %F;
17
my %F;
12
 
18
 
13
my $cookie_string = authenticate (5) || die;
19
my $cookie_string = authenticate (RollerCon::USER) || die;
14
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
20
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
15
my $user = getUser ($EML);
21
my $user = getUser ($EML);
Line 50... Line 56...
50
sub fieldOrder {
56
sub fieldOrder {
51
	$FIELDS{$a}->[1] <=> $FIELDS{$b}->[1];
57
	$FIELDS{$a}->[1] <=> $FIELDS{$b}->[1];
52
}
58
}
Line 53... Line 59...
53
 
59
 
-
 
60
sub saveForm {
-
 
61
  error ("ERROR: Only SysAdmins can change shifts.") unless $LVL >= RollerCon::ADMIN;
54
sub saveForm {
62
  
Line 55... Line 63...
55
  my $FTS = shift;
63
  my $FTS = shift;
56
  
64
  
57
  my $dbh = WebDB::connect ();
65
  my $dbh = WebDB::connect ();
Line 99... Line 107...
99
	$dbh->disconnect ();	 # stored into database successfully.
107
	$dbh->disconnect ();	 # stored into database successfully.
100
	return $FTS->{id};
108
	return $FTS->{id};
101
}
109
}
Line 102... Line 110...
102
 
110
 
-
 
111
sub delete_item {
-
 
112
  error ("ERROR: Only SysAdmins can delete shifts.") unless $LVL >= RollerCon::ADMIN;
103
sub delete_item {
113
  
104
  my $X = shift;
114
  my $X = shift;
105
  my $dbh = WebDB::connect ();
115
  my $dbh = WebDB::connect ();
106
  $dbh->do ("delete from $DBTable where $primary = ?", undef, $X->{$primary});
116
  $dbh->do ("delete from $DBTable where $primary = ?", undef, $X->{$primary});
107
  $dbh->disconnect ();
117
  $dbh->disconnect ();
Line 171... Line 181...
171
sub display_form  {
181
sub display_form  {
172
  my $R = shift;
182
  my $R = shift;
173
  my $view = shift // "";
183
  my $view = shift // "";
174
	my $actionbutton;
184
	my $actionbutton;
Line -... Line 185...
-
 
185
  
-
 
186
  $view = "View" unless $LVL >= RollerCon::ADMIN;
175
  
187
  
176
  if ($view eq "POSTSAVE" and $R->{$primary} eq "NEW") {
188
  if ($view eq "POSTSAVE" and $R->{$primary} eq "NEW") {
177
      print &formField ("Cancel", "Back", "POSTSAVE");
189
      print &formField ("Cancel", "Back", "POSTSAVE");
178
      return;
190
      return;
Line 188... Line 200...
188
	  $dbh->disconnect ();
200
	  $dbh->disconnect ();
Line 189... Line 201...
189
	  
201
	  
190
	  # did we find a record?
202
	  # did we find a record?
Line -... Line 203...
-
 
203
	  error ("Cannot find a database entry for '$R->{$primary}'") unless defined $F{$DBFields[0]};
-
 
204
    
-
 
205
    # If the DB returns a null value, HTML::Tiny doesn't like it, so make sure nulls are converted to empty strings.
-
 
206
    map { $F{$_} = "" unless $F{$_} } @DBFields;
191
	  error ("Cannot find a database entry for '$R->{$primary}'") unless defined $F{$DBFields[0]};
207
	  
192
    
208
    ## Check to make sure the user can actually see the shift
193
    if ($user->{dept}->{$F{dept}} < 3 and $LVL < 5) {
209
    if ($user->{department}->{$F{dept}} < RollerCon::USER and $LVL < RollerCon::ADMIN) {
Line 194... Line 210...
194
  	  error ("You're not a $DepartmentNames->{$F{dept}} Manager!");
210
  	  error ("You're not a volunteer in the $DepartmentNames->{$F{dept}} department!");
195
    }
211
    }
196
    
212
    
Line 218... Line 234...
218
      $actionbutton .= formField ("Cancel");
234
      $actionbutton .= formField ("Cancel");
219
    } else {
235
    } else {
220
      # We're just looking at it...
236
      # We're just looking at it...
221
      print $h->p ("Viewing Shift: $R->{$primary}...");
237
      print $h->p ("Viewing Shift: $R->{$primary}...");
222
      $F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
238
      $F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
-
 
239
            
-
 
240
      use DateTime;
-
 
241
      my $now = DateTime->now (time_zone => 'America/Los_Angeles');
-
 
242
 
-
 
243
     	my ($yyyy, $mm, $dd) = split /\-/, $F{date};
-
 
244
    	my $cutoff = DateTime->new(
-
 
245
            year => $yyyy,
-
 
246
            month => $mm,
-
 
247
            day => $dd,
-
 
248
            hour => 5,
-
 
249
            minute => 0,
-
 
250
            second => 0,
-
 
251
            time_zone => 'America/Los_Angeles'
-
 
252
      );
-
 
253
            
-
 
254
     	if (!$F{assignee_id}) {
-
 
255
     	  $F{assignee_id} = "OPEN";
-
 
256
     		if (signUpEligible ($ORCUSER, \%F, "vol") and $now < $cutoff) {
-
 
257
     			# SIGN UP
-
 
258
     			$F{assignee_id} .= " | <A HREF='#' onClick=\"event.stopPropagation(); window.open('make_shift_change.pl?change=add&RCid=$RCid&id=$R->{$primary}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[SIGN UP]</a>";
-
 
259
     		}
-
 
260
     		if ($user->{department}->{$F{dept}} >= RollerCon::LEAD or $LVL >= RollerCon::ADMIN) {
-
 
261
     			# ADD USER
-
 
262
     			$F{assignee_id} .= " | <A HREF='#' onClick=\"event.stopPropagation(); window.open('make_shift_change.pl?change=lookup&RCid=$RCid&id=$R->{$primary}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[ADD USER]</a>";
-
 
263
     		}
-
 
264
     	} elsif (($F{assignee_id} == $RCid and $F{type} ne "selected" and $now < $cutoff) or $user->{department}->{$F{dept}} >= RollerCon::LEAD or $LVL >= RollerCon::ADMIN) {
-
 
265
     	  my $temp = $h->a ({ href=>"/schedule/view_user.pl?RCid=$F{assignee_id}" }, getUserDerbyName ($F{assignee_id}));
-
 
266
     		# DROP
-
 
267
     		$temp .= " | <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=$F{assignee_id}&id=$R->{$primary}','Confirm Shift Change','resizable,height=260,width=370'); return false; }\">[DROP]</a>";
-
 
268
     		if ($user->{department}->{$F{dept}} >= RollerCon::LEAD or $LVL >= RollerCon::ADMIN) {
-
 
269
     		  # NO SHOW
-
 
270
     		  $temp .= " | <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=$F{assignee_id}&id=$R->{$primary}','Confirm Shift Change','resizable,height=260,width=370'); return false; }\">[NO SHOW]</a>";
-
 
271
     		}
-
 
272
     		$F{assignee_id} = $temp;
-
 
273
     	} else {
-
 
274
     	  $F{assignee_id} = "FILLED";
-
 
275
     	}
-
 
276
 
223
      $F{dept} = $DepartmentNames->{$F{dept}};
277
      $F{dept} = $DepartmentNames->{$F{dept}};
224
      if ($F{assignee_id}) {
-
 
225
        my $temp;
-
 
226
        $temp = getUserDerbyName ($F{assignee_id});
-
 
227
        $temp .= "&nbsp;".$h->a ({ onClick=>"if (confirm('Really? You want to drop this person from the shift?')==true) { window.open('make_shift_change.pl?change=del&RCid=$F{assignee_id}&id=$R->{$primary}','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "[DROP]");
-
 
228
        $F{assignee_id} = $temp;
-
 
229
      } else {
-
 
230
        $F{assignee_id} = $h->a ({ onClick=>"window.open('make_shift_change.pl?change=lookup&id=$R->{$primary}','Confirm Shift Change','resizable,height=260,width=370'); return false;" }, "[ADD USER]");
-
 
231
      }
-
 
232
      $F{doubletime} = $F{doubletime} ? "TRUE" : "FALSE";
278
      $F{doubletime} = $F{doubletime} ? "TRUE" : "FALSE";
Line 233... Line 279...
233
      
279
      
234
      $actionbutton = formField ("choice", "Update");
280
      $actionbutton = formField ("choice", "Update") unless $F{dept} eq "Coaching" or $LVL < RollerCon::ADMIN;
235
      if ($view eq "POSTSAVE" or $choice eq "View") {
281
      if ($view eq "POSTSAVE" or $choice eq "View") {
236
        $actionbutton .= formField ("Cancel", "Back", "POSTSAVE");
282
        $actionbutton .= formField ("Cancel", "Back", "POSTSAVE");
237
      } else {
283
      } else {
238
        $actionbutton .= formField ("Cancel", "Back");
284
        $actionbutton .= formField ("Cancel", "Back");
239
      }
285
      }
240
    }
286
    }
-
 
287
  } else {
-
 
288
    error ("No Shift ID provided.") unless $LVL >= RollerCon::ADMIN;
241
  } else {
289
    
Line 242... Line 290...
242
    print $h->p ("Adding a new Shift...");
290
    print $h->p ("Adding a new Shift...");
243
 
291
 
244
    foreach (@DBFields) {
292
    foreach (@DBFields) {
Line 267... Line 315...
267
  print $h->close ("form");
315
  print $h->close ("form");
Line 268... Line 316...
268
 
316
 
Line 269... Line 317...
269
}
317
}
-
 
318
 
-
 
319
sub process_form  {
270
 
320
  error ("ERROR: Only SysAdmins can change shifts.") unless $LVL >= RollerCon::ADMIN;
271
sub process_form  {
321
  
272
  my %FORM;  
322
  my %FORM;
273
  foreach (keys %FIELDS) {
323
  foreach (keys %FIELDS) {
274
  	if ($fieldType{$_} =~ /^text/) {
324
  	if ($fieldType{$_} =~ /^text/) {
275
  		$FORM{$_} = WebDB::trim param ($_) // "";
325
  		$FORM{$_} = WebDB::trim param ($_) // "";
Line 315... Line 365...
315
	my $type = $fieldType{$name} // "button";
365
	my $type = $fieldType{$name} // "button";
Line 316... Line 366...
316
  
366
  
317
  if ($type eq "button") {
367
  if ($type eq "button") {
318
		if ($name eq "Cancel") {
368
		if ($name eq "Cancel") {
319
		  if ($context eq "POSTSAVE") {
369
		  if ($context eq "POSTSAVE") {
320
		    return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"window.location.href = \"manage_shifts.pl\"; return false;" });
370
		    return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"window.location.href = \"shifts.pl\"; return false;" });
321
		  } else {
371
		  } else {
322
		    return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"history.back(); return false;" });
372
		    return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"history.back(); return false;" });
323
		  }
373
		  }
324
		} else {
374
		} else {