| 168 |
- |
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 WebDB;
|
|
|
12 |
use HTML::Tiny;
|
|
|
13 |
use RollerCon;
|
|
|
14 |
use CGI qw/param header start_html url/;
|
|
|
15 |
my $h = HTML::Tiny->new( mode => 'html' );
|
|
|
16 |
|
|
|
17 |
my %F;
|
|
|
18 |
|
|
|
19 |
my $cookie_string = authenticate (RollerCon::ADMIN) || die;
|
|
|
20 |
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
|
|
21 |
my $user = getUser ($EML);
|
|
|
22 |
$user->{department} = convertDepartments $user->{department};
|
|
|
23 |
my $DepartmentNames = getDepartments ();
|
|
|
24 |
my $username = $user->{derby_name};
|
|
|
25 |
my $RCid = $user->{RCid};
|
|
|
26 |
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
|
|
|
27 |
my $YEAR = 1900 + (localtime)[5];
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
my $pageTitle = "Email Users";
|
|
|
31 |
my $homeURL = "/schedule/";
|
|
|
32 |
|
|
|
33 |
sub emailUsers {
|
|
|
34 |
error ("ERROR: Only SysAdmins can change games.") unless $LVL >= RollerCon::ADMIN;
|
|
|
35 |
|
|
|
36 |
my ($type, $ID, $subject, $body) = @_;
|
|
|
37 |
|
|
|
38 |
my @emails;
|
|
|
39 |
my $dbh = WebDB::connect ();
|
|
|
40 |
if ($type eq "class") {
|
| 208 |
- |
41 |
push @emails, map { @{$_} } @{ $dbh->selectall_arrayref ("select email from v_class_signup_new join official on v_class_signup_new.RCid = official.RCid where id = ?", undef, $ID) };
|
| 168 |
- |
42 |
} elsif ($type eq "game") {
|
|
|
43 |
push @emails, map { @{$_} } @{ $dbh->selectall_arrayref ("select email from v_shift_officiating where id = ? and isnull(email) = 0 union select email from v_shift_announcer where id = ? and isnull(email) = 0", undef, $ID, $ID) };
|
|
|
44 |
}
|
|
|
45 |
$dbh->disconnect ();
|
|
|
46 |
|
|
|
47 |
use RCMailer;
|
|
|
48 |
foreach (@emails) {
|
|
|
49 |
EmailUser ($_, $subject, $body);
|
|
|
50 |
sleep (1);
|
|
|
51 |
}
|
|
|
52 |
print "SENT!";
|
|
|
53 |
return;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
print header (),
|
|
|
58 |
start_html (-title => $pageTitle, -style => {'src' => "/style.css"} );
|
|
|
59 |
|
|
|
60 |
print $h->div ({ class => "accent pageheader" }, [
|
|
|
61 |
$h->h1 ($pageTitle),
|
|
|
62 |
$h->div ({ class=>"sp0" }, [
|
|
|
63 |
$h->div ({ class=>"spLeft" }, [
|
|
|
64 |
]),
|
|
|
65 |
$h->div ({ class=>"spRight" }, [
|
|
|
66 |
$h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
|
|
|
67 |
]),
|
|
|
68 |
]),
|
|
|
69 |
]);
|
|
|
70 |
|
|
|
71 |
my $SEND = "";
|
|
|
72 |
if (param ("choice") eq "Send Email") {
|
|
|
73 |
$SEND = 1;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
print $h->open ("form", { action => url (), name=>"Req", method=>"POST" });
|
|
|
77 |
|
|
|
78 |
my $type = chooseType ();
|
|
|
79 |
my $ID = chooseID ($type);
|
|
|
80 |
printDetails ($type, $ID) unless (!$type or !$ID);
|
|
|
81 |
my $subject = setSubject ();
|
|
|
82 |
my $body = setBody ();
|
|
|
83 |
my $choice = param ("choice") // "";
|
|
|
84 |
|
|
|
85 |
print $h->br, $h->br;
|
|
|
86 |
if ($SEND) {
|
|
|
87 |
emailUsers ($type, $ID, $subject, $body);
|
|
|
88 |
} else {
|
|
|
89 |
print $h->input ({ type=>"button", value => "Cancel" , onClick=>"history.back(); return false;" });
|
|
|
90 |
print " ";
|
|
|
91 |
print $h->input ({ type=>"submit", name=>"choice", value => "Send Email" });
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
print $h->close ("form");
|
|
|
95 |
print $h->close ("html");
|
|
|
96 |
|
|
|
97 |
sub chooseType {
|
|
|
98 |
my $type = param ("type") // "";
|
|
|
99 |
$type = "" unless ($type eq "class" or $type eq "game");
|
|
|
100 |
|
|
|
101 |
for ("class", "game") {
|
|
|
102 |
my %PROPS = (
|
|
|
103 |
type => "radio",
|
|
|
104 |
id => $_,
|
|
|
105 |
name => "type",
|
|
|
106 |
value => $_,
|
|
|
107 |
onChange => "Req.ID.value=''; submit();"
|
|
|
108 |
);
|
|
|
109 |
$PROPS{checked} = [] if $type eq $_;
|
|
|
110 |
$PROPS{disabled} = [] if $SEND;
|
|
|
111 |
|
|
|
112 |
print $h->input (\%PROPS);
|
|
|
113 |
print $h->label ({for=>$_}, ucfirst $_);
|
|
|
114 |
print $h->br;
|
|
|
115 |
}
|
|
|
116 |
print $h->br;
|
|
|
117 |
|
|
|
118 |
return $type;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
sub chooseID {
|
|
|
122 |
my $type = shift // "";
|
|
|
123 |
my $ID = param ("ID") // "";
|
|
|
124 |
$ID = "" unless $ID =~ /^\d+$/;
|
|
|
125 |
|
|
|
126 |
if (!$type) {
|
|
|
127 |
print $h->div ("Please select either Class or Game.");
|
|
|
128 |
print $h->input ({type=>"hidden", name=>"ID"});
|
|
|
129 |
print $h->br;
|
|
|
130 |
return "";
|
|
|
131 |
} else {
|
| 208 |
- |
132 |
my $table = $type eq "class" ? "v_class_new" : "v_games";
|
| 168 |
- |
133 |
my $field = $type eq "class" ? "name" : "teams";
|
|
|
134 |
my $dbh = WebDB::connect ();
|
|
|
135 |
#push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where timestampdiff(minute, last_seen, now()) < 7 and (timestamp <> last_seen or timestampdiff(second, last_seen, now()) <= 60) order by timestamp") };
|
|
|
136 |
my %things = map { $_->[0] => $_->[1] } @{ $dbh->selectall_arrayref ("select distinct id, $field from $table where year(date) = year(now())") };
|
|
|
137 |
$dbh->disconnect ();
|
|
|
138 |
if ($SEND) {
|
|
|
139 |
print $h->div([ucfirst $type.": ", $things{$ID}]);
|
|
|
140 |
} else {
|
|
|
141 |
print $h->div([ucfirst $type.": ", $h->select ({ name=>"ID", onChange=>"submit();" }, [ $h->option (),
|
|
|
142 |
map { $ID eq $_ ? $h->option ({ value=>$_, selected=>[] }, $things{$_}) : $h->option ({ value=>$_ }, $things{$_}) } sort { $things{$a} cmp $things{$b} } keys %things
|
|
|
143 |
])]);
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
print $h->br;
|
|
|
147 |
return $ID;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
sub printDetails {
|
|
|
151 |
my $type = shift // "";
|
|
|
152 |
my $ID = shift // "";
|
|
|
153 |
|
|
|
154 |
error ("No Class or Game Selected") unless $type and $ID;
|
|
|
155 |
|
|
|
156 |
my $dbh = WebDB::connect ();
|
|
|
157 |
|
|
|
158 |
my $user_count;
|
|
|
159 |
if ($type eq "class") {
|
| 208 |
- |
160 |
print map { $_.$h->br } $dbh->selectrow_array ("select id, name, coach, date, dayofweek, time, location from v_class_new where id = ?", undef, $ID);
|
|
|
161 |
($user_count) = $dbh->selectrow_array ("select count(email) from v_class_signup_new join official on v_class_signup_new.RCid = official.RCid where id = ?", undef, $ID);
|
| 168 |
- |
162 |
print $user_count." Users".$h->br;
|
|
|
163 |
} elsif ($type eq "game") {
|
|
|
164 |
print map { $_.$h->br } $dbh->selectrow_array ("select id, teams, date, dayofweek, time, track, gtype from v_games where id = ?", undef, $ID);
|
|
|
165 |
($user_count) = $dbh->selectrow_array ("select count(*) from (select email from v_shift_officiating where id = ? and isnull(email) = 0 union select email from v_shift_announcer where id = ? and isnull(email) = 0) temptable", undef, $ID, $ID);
|
|
|
166 |
print $user_count." Users".$h->br;
|
|
|
167 |
} else {
|
|
|
168 |
error ("Unknown Type: ".$type);
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
$dbh->disconnect ();
|
|
|
172 |
print $h->br;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
sub setSubject {
|
|
|
176 |
my $subject = param ("subject") // "";
|
|
|
177 |
|
|
|
178 |
if ($SEND) {
|
|
|
179 |
print "Subject: ", $h->input ({ type=>"text", name=>"subject", value=>"$subject", size=>30, readonly=>[] });
|
|
|
180 |
} else {
|
|
|
181 |
print "Subject: ", $h->input ({ type=>"text", name=>"subject", value=>"$subject", size=>30 });
|
|
|
182 |
}
|
|
|
183 |
print $h->br;
|
|
|
184 |
|
|
|
185 |
print $h->br;
|
|
|
186 |
return $subject;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
sub setBody {
|
|
|
190 |
my $body = param ("body") // "";
|
|
|
191 |
|
|
|
192 |
if ($SEND) {
|
|
|
193 |
print $h->tag ("textarea", { name=>"body", value=>"$body", cols => 45, rows => 10, readonly=>[] }, $body);
|
|
|
194 |
} else {
|
|
|
195 |
print $h->tag ("textarea", { name=>"body", value=>"$body", cols => 45, rows => 10 }, $body);
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
return $body;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
sub error {
|
|
|
203 |
my $msg = shift;
|
|
|
204 |
print $h->p ({ class=>"error" }, "Error: $msg");
|
|
|
205 |
print $h->close("html");
|
|
|
206 |
exit (0);
|
|
|
207 |
}
|