| 58 |
bgadell |
1 |
#!/usr/bin/perl
|
|
|
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";
|
|
|
8 |
|
|
|
9 |
use strict;
|
|
|
10 |
use cPanelUserConfig;
|
|
|
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(3) || 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 $MVPid = param ('MVPid');
|
|
|
30 |
|
|
|
31 |
print start_html (-title => "vORC Update MVP Ticket Match", -style => {'src' => "/style.css"}), $h->open ("body");
|
|
|
32 |
|
|
|
33 |
if ($change eq "lookup") {
|
|
|
34 |
|
|
|
35 |
print $h->form ({ action=>url }, [
|
|
|
36 |
$h->input ({ type=>"hidden", name=>"change", value=>"add" }),
|
|
|
37 |
$h->input ({ type=>"hidden", name=>"RCid", value=>$RCid }),
|
|
|
38 |
$h->p ("Match ticket to User ($RCid):"),
|
|
|
39 |
$h->input ({ type=>"text", name=>"MVPid", id=>"pickticket" }),
|
|
|
40 |
$h->input ({ type=>"submit", value=>"Save", onClick=>"if (document.getElementById('pickticket').value === '') { return false; }" }),
|
|
|
41 |
$h->button ({ onClick=>"window.close();" }, "Cancel")
|
|
|
42 |
]);
|
|
|
43 |
|
|
|
44 |
} else {
|
|
|
45 |
print $h->p ("Making an MVP Ticket change...");
|
|
|
46 |
|
|
|
47 |
my $target = getUserDerbyName ($RCid);
|
|
|
48 |
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>...");
|
|
|
49 |
|
|
|
50 |
my $change_err = changeTicket($change, $RCid, $MVPid);
|
|
|
51 |
my $closer;
|
|
|
52 |
if ($change_err) {
|
|
|
53 |
print $change_err;
|
|
|
54 |
if ($change_err =~ /^WARNING/) {
|
|
|
55 |
print $h->form ({ action=>url }, [
|
|
|
56 |
$h->input ({ type=>"hidden", name=>"change", value=>"override" }),
|
|
|
57 |
$h->input ({ type=>"hidden", name=>"MVPid", value=>$MVPid }),
|
|
|
58 |
$h->input ({ type=>"hidden", name=>"RCid", value=>$RCid }),
|
|
|
59 |
$h->input ({ type=>"submit", value=>"OVERRIDE", onClick=>"if (confirm('Are you sure you want to override the warning?')==true) { return true } else { return false }" }),
|
|
|
60 |
]);
|
|
|
61 |
}
|
|
|
62 |
print $h->br, $h->button ({ onClick=>"window.close();" }, "Close");
|
|
|
63 |
} else {
|
|
|
64 |
print "<br>This window will close automatically in 3 seconds.";
|
|
|
65 |
$closer = 'setTimeout(() => { window.close(); }, 3000);';
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
print<<tail;
|
|
|
69 |
<SCRIPT language="JavaScript">
|
|
|
70 |
<!--
|
|
|
71 |
function reloadParent() {
|
|
|
72 |
window.opener.location.reload();
|
|
|
73 |
$closer
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
reloadParent();
|
|
|
77 |
//-->
|
|
|
78 |
</SCRIPT>
|
|
|
79 |
tail
|
|
|
80 |
}
|
|
|
81 |
print $h->close ("body"), $h->close ("html");
|
|
|
82 |
|
|
|
83 |
sub changeTicket {
|
|
|
84 |
my $change = shift // "";
|
|
|
85 |
my $rcid = shift // "";
|
|
|
86 |
my $mvpid = shift // "";
|
|
|
87 |
return "ERROR: Missing Details to make the change" unless $change and $rcid and $mvpid;
|
|
|
88 |
|
|
|
89 |
my $dbh = getRCDBH;
|
|
|
90 |
my $sth;
|
|
|
91 |
|
|
|
92 |
if ($change eq "Delete" or $change eq "override") {
|
|
|
93 |
if ($change ne "override") {
|
|
|
94 |
my ($badidea) = $dbh->selectrow_array ("select id from v_ticket where RCid = ? and email = vorc_email and full_name = vorc_full_name", undef, $rcid);
|
|
|
95 |
return "WARNING: This user's email and full name match the MVP ticket. (It will likely re-match.)" if $badidea;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
$sth = $dbh->prepare ("delete from RCid_ticket_link where RCid = ? and MVPid = ?");
|
|
|
99 |
|
|
|
100 |
} else {
|
|
|
101 |
my ($taken) = $dbh->selectrow_array ("select RCid from RCid_ticket_link where MVPid = ? or RCid = ?", undef, $mvpid, $rcid);
|
|
|
102 |
return "ERROR ($taken): Either that user or that ticket is already matched." if $taken;
|
|
|
103 |
|
|
|
104 |
my ($exists) = $dbh->selectrow_array ("select id from ticket where id = ?", undef, $mvpid);
|
|
|
105 |
return "ERROR: That MVP Ticket doesn't seem to exist ($mvpid)." unless $exists;
|
|
|
106 |
|
|
|
107 |
$sth = $dbh->prepare ("insert into RCid_ticket_link (RCid, MVPid) values (?, ?)");
|
|
|
108 |
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
if ($sth->execute ($rcid, $mvpid)) {
|
|
|
112 |
logit ($user->{RCid}, "Updated MVP Ticket: $rcid $change $mvpid");
|
|
|
113 |
logit ($rcid, "MVP Ticket Change: $user->{derby_name} $change");
|
|
|
114 |
print "SUCCESS!";
|
|
|
115 |
return;
|
|
|
116 |
} else {
|
|
|
117 |
return "ERROR: Something failed. Maybe this will help:". $sth->errstr();
|
|
|
118 |
}
|
|
|
119 |
}
|