Subversion Repositories VORC

Rev

Rev 54 | Rev 98 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 - 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
 
7 - 9
use strict;
8 - 10
use cPanelUserConfig;
7 - 11
use RollerCon;
12
use tableViewer;
13
use CGI qw/param cookie header start_html url/;
14
use HTML::Tiny;
15
my $h = HTML::Tiny->new( mode => 'html' );
16
 
17
my $cookie_string = authenticate(1) || die;
18
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
19
my $user = getUser($EML);
20
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
21
 
22
print header (-cookie=>$RCAUTH_cookie);
23
 
24
#foreach (sort keys %ENV) {
25
#	print "$_: $ENV{$_}\n<br>";
26
#}
27
my $change = param ('change');
28
my $RCid   = param ('RCid') // $user->{RCid};
29
my $id     = param ('id');
30
my $role   = param ('role') // "";
31
my $noshow = param ('noshow');
35 - 32
my $department = ($id =~ /^\d+$/) ? getShiftDepartment ($role ? $id."-".$role : $id) : "CLA";
7 - 33
 
34
print start_html (-title => "vORC Make Shift Change", -style => {'src' => "/style.css"}), $h->open ("body");
35
 
36
 
37
if ($change eq "lookup") {
35 - 38
	if (convertDepartments($user->{department})->{$department} < 2 and $LVL < 5 and convertDepartments($user->{department})->{VCI} < 2) {
7 - 39
    print $h->div ({ class=>"error" }, "You're not allowed to change other people's schedules.");
40
    print $h->close ("body"), $h->close ("html");
41
	  die;
42
	}
43
 
44
	my $options = fetchDerbyNameWithRCid ($department);
45
 
46
  print $h->form ({ action=>url }, [
47
    $h->input ({ type=>"hidden", name=>"change", value=>"add" }),
48
    $h->input ({ type=>"hidden", name=>"id", value=>$id }),
49
    $h->input ({ type=>"hidden", name=>"role", value=>$role }),
35 - 50
    $department eq "CLA" ? $h->p ("Add User to Class ($id):") : $h->p ("Add User to Shift ($id):"),
7 - 51
    $h->select ({ name=>"RCid", id=>"pickname" }, [ $h->option, $options ]),
52
    $h->input ({ type=>"submit", value=>"Save", onClick=>"if (document.getElementById('pickname').selectedIndex === 0) { return false; }" }),
53
    $h->button ({ onClick=>"window.close();" }, "Cancel")
54
  ]);
55
 
56
} else {
57
	print $h->p ("Making a shift change...");
58
 
59
  if ($noshow eq "true") {
60
    logit ($RCid, "NO SHOW: $id");
61
    logit ($user->{RCid}, "Logged a No Show for ($RCid): $id");
62
    print $h->p ("Logged a No Show and removing the official from the shift...");
63
  } elsif ($RCid eq $user->{RCid}) {
64
    print $h->p ("So, <b>$user->{derby_name}</b>, you'd like to <b>$change</b> a shift: <b>$id</b>...");
65
  } else {
66
    my $target = getUserDerbyName ($RCid);
67
    print $h->p ("So, <b>$user->{derby_name}</b>, you'd like to <b>$change</b> a shift for <b>$target</b>: <b>$id</b>...");
68
  }
69
 
70
 
71
	my $change_err = changeShift($change, $id, $role, $RCid);
72
	my $closer;
73
	if ($change_err) {
74
	  print $change_err;
46 - 75
	  if ($change_err =~ /conflict/ and (convertDepartments($user->{department})->{VCI} > 2 or $LVL > 4)) {
76
		  print $h->form ({ action=>url }, [
77
		    $h->input ({ type=>"hidden", name=>"change", value=>"override" }),
78
    		$h->input ({ type=>"hidden", name=>"id", value=>$id }),
79
    		$h->input ({ type=>"hidden", name=>"role", value=>$role }),
80
    		$h->input ({ type=>"hidden", name=>"RCid", value=>$RCid }),
81
    		$h->input ({ type=>"submit", value=>"OVERRIDE", onClick=>"if (confirm('Are you sure you want to override the conflict?')==true) { return true } else { return false }" }),
82
		  ]);
83
	  }
7 - 84
	  print $h->br, $h->button ({ onClick=>"window.close();" }, "Close");
85
	} else {
86
	  print "<br>This window will close automatically in 3 seconds.";
87
 	  $closer = 'setTimeout(() => { window.close(); }, 3000);';
88
	}
89
 
90
	print<<tail;
91
	<SCRIPT language="JavaScript">
92
	<!--
93
			function reloadParent() {
54 bgadell 94
			  if (window.opener.location.href.split("/").slice(-1) == "manage_shift.pl") {
95
			    window.opener.location.href = window.opener.location.href + "?id=" + window.opener.document.Req.id.value + "&choice=View";
96
			  } else {
97
	        window.opener.location.reload();
98
	      }
7 - 99
	      $closer
100
			}
101
 
102
			reloadParent();
103
	//-->
104
	</SCRIPT>
105
tail
106
  print $h->close ("body"), $h->close ("html");
2 - 107
}