| 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 |
|
| 98 |
bgadell |
36 |
my $WARNING = getUser ($RCid) ? "" : $h->p ({ class => "error" }, "User [$RCid] Not Found!");
|
| 7 |
- |
37 |
|
| 98 |
bgadell |
38 |
if ($change eq "lookup" or $WARNING) {
|
| 112 |
- |
39 |
if (($department eq "CLA" and convertDepartments($user->{department})->{MVP} < 2 and $LVL < 5) and (convertDepartments($user->{department})->{$department} < 2 and $LVL < 5 and convertDepartments($user->{department})->{VCI} < 2)) {
|
|
|
40 |
# if (convertDepartments($user->{department})->{$department} < 2 and $LVL < 5 and convertDepartments($user->{department})->{VCI} < 2) {
|
| 7 |
- |
41 |
print $h->div ({ class=>"error" }, "You're not allowed to change other people's schedules.");
|
|
|
42 |
print $h->close ("body"), $h->close ("html");
|
| 98 |
bgadell |
43 |
exit;
|
| 7 |
- |
44 |
}
|
|
|
45 |
|
| 98 |
bgadell |
46 |
my $options = fetchDerbyNameWithRCid ({ DATALIST=>1 }, $department);
|
| 112 |
- |
47 |
|
| 98 |
bgadell |
48 |
print $WARNING, $h->form ({ action=>url }, [
|
| 7 |
- |
49 |
$h->input ({ type=>"hidden", name=>"change", value=>"add" }),
|
|
|
50 |
$h->input ({ type=>"hidden", name=>"id", value=>$id }),
|
|
|
51 |
$h->input ({ type=>"hidden", name=>"role", value=>$role }),
|
| 35 |
- |
52 |
$department eq "CLA" ? $h->p ("Add User to Class ($id):") : $h->p ("Add User to Shift ($id):"),
|
| 99 |
bgadell |
53 |
$h->input ({ name => "RCid-picker", id=>"pickname", list => "eligibleusers" }).$h->tag ("datalist", { id => "eligibleusers" }, [$options]),
|
| 98 |
bgadell |
54 |
$h->input ({ type=>"hidden", name=>"RCid", id=>"pickname-hidden" }),
|
|
|
55 |
$h->input ({ type=>"submit", value=>"Save", onClick=>"if (isInt(document.getElementById('pickname').value)) { return false } else { return isInt(document.getElementById('pickname-hidden').value) };" }),
|
| 7 |
- |
56 |
$h->button ({ onClick=>"window.close();" }, "Cancel")
|
|
|
57 |
]);
|
| 98 |
bgadell |
58 |
print<<JAVASCRIPT;
|
|
|
59 |
<SCRIPT language="JavaScript">
|
|
|
60 |
<!--
|
|
|
61 |
function isInt(value) {
|
|
|
62 |
if (value == '') { return false; }
|
|
|
63 |
return !isNaN(value) && (function(x) { return (x | 0) === x; })(parseFloat(value))
|
|
|
64 |
}
|
|
|
65 |
document.querySelector('input[list]').addEventListener('input', function(e) {
|
|
|
66 |
var input = e.target,
|
|
|
67 |
list = input.getAttribute('list'),
|
|
|
68 |
options = document.querySelectorAll('#' + list + ' option'),
|
|
|
69 |
hiddenInput = document.getElementById(input.getAttribute('id') + '-hidden'),
|
|
|
70 |
inputValue = input.value;
|
| 7 |
- |
71 |
|
| 98 |
bgadell |
72 |
hiddenInput.value = inputValue;
|
|
|
73 |
|
|
|
74 |
for(var i = 0; i < options.length; i++) {
|
|
|
75 |
var option = options[i];
|
|
|
76 |
|
|
|
77 |
if(option.innerText === inputValue) {
|
|
|
78 |
hiddenInput.value = option.getAttribute('data-value');
|
|
|
79 |
break;
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
});
|
|
|
83 |
//-->
|
|
|
84 |
</SCRIPT>
|
|
|
85 |
JAVASCRIPT
|
|
|
86 |
|
|
|
87 |
|
| 7 |
- |
88 |
} else {
|
|
|
89 |
print $h->p ("Making a shift change...");
|
|
|
90 |
|
|
|
91 |
if ($noshow eq "true") {
|
|
|
92 |
logit ($RCid, "NO SHOW: $id");
|
|
|
93 |
logit ($user->{RCid}, "Logged a No Show for ($RCid): $id");
|
|
|
94 |
print $h->p ("Logged a No Show and removing the official from the shift...");
|
|
|
95 |
} elsif ($RCid eq $user->{RCid}) {
|
|
|
96 |
print $h->p ("So, <b>$user->{derby_name}</b>, you'd like to <b>$change</b> a shift: <b>$id</b>...");
|
|
|
97 |
} else {
|
|
|
98 |
my $target = getUserDerbyName ($RCid);
|
|
|
99 |
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>...");
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
my $change_err = changeShift($change, $id, $role, $RCid);
|
|
|
104 |
my $closer;
|
|
|
105 |
if ($change_err) {
|
|
|
106 |
print $change_err;
|
| 200 |
- |
107 |
if ($change_err =~ /conflict|class is already full/ and (convertDepartments($user->{department})->{VCI} > 2 or $LVL > 4 or convertDepartments($user->{department})->{OFF} > 1 or convertDepartments($user->{department})->{MVP} > 2)) {
|
| 46 |
- |
108 |
print $h->form ({ action=>url }, [
|
|
|
109 |
$h->input ({ type=>"hidden", name=>"change", value=>"override" }),
|
|
|
110 |
$h->input ({ type=>"hidden", name=>"id", value=>$id }),
|
|
|
111 |
$h->input ({ type=>"hidden", name=>"role", value=>$role }),
|
|
|
112 |
$h->input ({ type=>"hidden", name=>"RCid", value=>$RCid }),
|
|
|
113 |
$h->input ({ type=>"submit", value=>"OVERRIDE", onClick=>"if (confirm('Are you sure you want to override the conflict?')==true) { return true } else { return false }" }),
|
|
|
114 |
]);
|
|
|
115 |
}
|
| 7 |
- |
116 |
print $h->br, $h->button ({ onClick=>"window.close();" }, "Close");
|
|
|
117 |
} else {
|
|
|
118 |
print "<br>This window will close automatically in 3 seconds.";
|
|
|
119 |
$closer = 'setTimeout(() => { window.close(); }, 3000);';
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
print<<tail;
|
|
|
123 |
<SCRIPT language="JavaScript">
|
|
|
124 |
<!--
|
|
|
125 |
function reloadParent() {
|
| 54 |
bgadell |
126 |
if (window.opener.location.href.split("/").slice(-1) == "manage_shift.pl") {
|
|
|
127 |
window.opener.location.href = window.opener.location.href + "?id=" + window.opener.document.Req.id.value + "&choice=View";
|
|
|
128 |
} else {
|
|
|
129 |
window.opener.location.reload();
|
|
|
130 |
}
|
| 7 |
- |
131 |
$closer
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
reloadParent();
|
|
|
135 |
//-->
|
|
|
136 |
</SCRIPT>
|
|
|
137 |
tail
|
|
|
138 |
print $h->close ("body"), $h->close ("html");
|
| 112 |
- |
139 |
}
|