Rev 121 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/perl# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";close STDERR;open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";#warn "Redirecting errors to ${error_log_path}vorc_error.log";use strict;use cPanelUserConfig;use RollerCon;use tableViewer;use CGI qw/param cookie header start_html url/;use HTML::Tiny;my $h = HTML::Tiny->new( mode => 'html' );my $cookie_string = authenticate(1) || die;my ($EML, $PWD, $LVL) = split /&/, $cookie_string;my $user = getUser($EML);my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");print header (-cookie=>$RCAUTH_cookie);#foreach (sort keys %ENV) {# print "$_: $ENV{$_}\n<br>";#}my $change = param ('change');my $RCid = param ('RCid') // $user->{RCid};my $id = param ('id');my $role = param ('role') // "";my $noshow = param ('noshow');my $department = ($id =~ /^\d+$/) ? getShiftDepartment ($role ? $id."-".$role : $id) : "CLA";print start_html (-title => "vORC Make Shift Change", -style => {'src' => "/style.css"}), $h->open ("body");my $WARNING = getUser ($RCid) ? "" : $h->p ({ class => "error" }, "User [$RCid] Not Found!");if ($change eq "lookup" or $WARNING) {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)) {# if (convertDepartments($user->{department})->{$department} < 2 and $LVL < 5 and convertDepartments($user->{department})->{VCI} < 2) {print $h->div ({ class=>"error" }, "You're not allowed to change other people's schedules.");print $h->close ("body"), $h->close ("html");exit;}my $options = fetchDerbyNameWithRCid ({ DATALIST=>1 }, $department);print $WARNING, $h->form ({ action=>url }, [$h->input ({ type=>"hidden", name=>"change", value=>"add" }),$h->input ({ type=>"hidden", name=>"id", value=>$id }),$h->input ({ type=>"hidden", name=>"role", value=>$role }),$department eq "CLA" ? $h->p ("Add User to Class ($id):") : $h->p ("Add User to Shift ($id):"),$h->input ({ name => "RCid-picker", id=>"pickname", list => "eligibleusers" }).$h->tag ("datalist", { id => "eligibleusers" }, [$options]),$h->input ({ type=>"hidden", name=>"RCid", id=>"pickname-hidden" }),$h->input ({ type=>"submit", value=>"Save", onClick=>"if (isInt(document.getElementById('pickname').value)) { return false } else { return isInt(document.getElementById('pickname-hidden').value) };" }),$h->button ({ onClick=>"window.close();" }, "Cancel")]);print<<JAVASCRIPT;<SCRIPT language="JavaScript"><!--function isInt(value) {if (value == '') { return false; }return !isNaN(value) && (function(x) { return (x | 0) === x; })(parseFloat(value))}document.querySelector('input[list]').addEventListener('input', function(e) {var input = e.target,list = input.getAttribute('list'),options = document.querySelectorAll('#' + list + ' option'),hiddenInput = document.getElementById(input.getAttribute('id') + '-hidden'),inputValue = input.value;hiddenInput.value = inputValue;for(var i = 0; i < options.length; i++) {var option = options[i];if(option.innerText === inputValue) {hiddenInput.value = option.getAttribute('data-value');break;}}});//--></SCRIPT>JAVASCRIPT} else {print $h->p ("Making a shift change...");if ($noshow eq "true") {logit ($RCid, "NO SHOW: $id");logit ($user->{RCid}, "Logged a No Show for ($RCid): $id");print $h->p ("Logged a No Show and removing the official from the shift...");} elsif ($RCid eq $user->{RCid}) {print $h->p ("So, <b>$user->{derby_name}</b>, you'd like to <b>$change</b> a shift: <b>$id</b>...");} else {my $target = getUserDerbyName ($RCid);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>...");}my $change_err = changeShift($change, $id, $role, $RCid);my $closer;if ($change_err) {print $change_err;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)) {print $h->form ({ action=>url }, [$h->input ({ type=>"hidden", name=>"change", value=>"override" }),$h->input ({ type=>"hidden", name=>"id", value=>$id }),$h->input ({ type=>"hidden", name=>"role", value=>$role }),$h->input ({ type=>"hidden", name=>"RCid", value=>$RCid }),$h->input ({ type=>"submit", value=>"OVERRIDE", onClick=>"if (confirm('Are you sure you want to override the conflict?')==true) { return true } else { return false }" }),]);}print $h->br, $h->button ({ onClick=>"window.close();" }, "Close");} else {print "<br>This window will close automatically in 3 seconds.";$closer = 'setTimeout(() => { window.close(); }, 3000);';}print<<tail;<SCRIPT language="JavaScript"><!--function reloadParent() {if (window.opener.location.href.split("/").slice(-1) == "manage_shift.pl") {window.opener.location.href = window.opener.location.href + "?id=" + window.opener.document.Req.id.value + "&choice=View";} else {window.opener.location.reload();}$closer}reloadParent();//--></SCRIPT>tailprint $h->close ("body"), $h->close ("html");}