Rev 61 | Go to most recent revision | 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(3) || 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 $MVPid = param ('MVPid');print start_html (-title => "vORC Update MVP Ticket Match", -style => {'src' => "/style.css"}), $h->open ("body");if ($change eq "lookup") {print $h->form ({ action=>url }, [$h->input ({ type=>"hidden", name=>"change", value=>"add" }),$h->input ({ type=>"hidden", name=>"RCid", value=>$RCid }),$h->p ("Match ticket to User ($RCid):"),$h->input ({ type=>"text", name=>"MVPid", id=>"pickticket" }),$h->input ({ type=>"submit", value=>"Save", onClick=>"if (document.getElementById('pickticket').value === '') { return false; }" }),$h->button ({ onClick=>"window.close();" }, "Cancel")]);} else {print $h->p ("Making an MVP Ticket change...");my $target = getUserDerbyName ($RCid);print $h->p ("So, <b>$user->{derby_name}</b>, you'd like to <b>$change</b> an MVP Ticket for <b>$target</b>: <b>$RCid</b>...");my $change_err = changeTicket($change, $RCid, $MVPid);my $closer;if ($change_err) {print $change_err;if ($change_err =~ /^WARNING/) {print $h->form ({ action=>url }, [$h->input ({ type=>"hidden", name=>"change", value=>"override" }),$h->input ({ type=>"hidden", name=>"MVPid", value=>$MVPid }),$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 warning?')==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() {window.opener.location.reload();$closer}reloadParent();//--></SCRIPT>tail}print $h->close ("body"), $h->close ("html");sub changeTicket {my $change = shift // "";my $rcid = shift // "";my $mvpid = shift // "";return "ERROR: Missing Details to make the change" unless $change and $rcid and $mvpid;my $dbh = getRCDBH;my $sth;if ($change eq "Delete" or $change eq "override") {if ($change ne "override") {my ($badidea) = $dbh->selectrow_array ("select id from v_ticket where RCid = ? and email = vorc_email and full_name = vorc_full_name", undef, $rcid);return "WARNING: This user's email and full name match the MVP ticket. (It will likely re-match.)" if $badidea;}$sth = $dbh->prepare ("delete from RCid_ticket_link where RCid = ? and MVPid = ?");} else {my ($taken) = $dbh->selectrow_array ("select RCid from RCid_ticket_link where MVPid = ? or RCid = ?", undef, $mvpid, $rcid);return "ERROR ($taken): Either that user or that ticket is already matched." if $taken;my ($exists) = $dbh->selectrow_array ("select id from ticket where id = ?", undef, $mvpid);return "ERROR: That MVP Ticket doesn't seem to exist ($mvpid)." unless $exists;$sth = $dbh->prepare ("insert into RCid_ticket_link (RCid, MVPid) values (?, ?)");}if ($sth->execute ($rcid, $mvpid)) {logit ($user->{RCid}, "Updated MVP Ticket: $rcid $change $mvpid");logit ($rcid, "MVP Ticket Change: $user->{derby_name} $change");print "SUCCESS!";return;} else {return "ERROR: Something failed. Maybe this will help:". $sth->errstr();}}