Subversion Repositories VORC

Rev

Rev 252 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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) };
252 - 42
  } elsif ($type eq "seminar") {
43
    push @emails, map { @{$_} } @{ $dbh->selectall_arrayref ("select email from v_seminar_signup_new join official on v_seminar_signup_new.RCid = official.RCid where id = ?", undef, $ID) };
168 - 44
	} elsif ($type eq "game") {
45
	  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) };
46
	}
47
	$dbh->disconnect ();
48
 
49
	use RCMailer;
50
	foreach (@emails) {
51
	  EmailUser ($_, $subject, $body);
52
	  sleep (1);
53
	}
54
  print "SENT!";
55
	return;
56
}
57
 
58
 
59
print header (),
60
			start_html (-title => $pageTitle, -style => {'src' => "/style.css"} );
61
 
62
print $h->div ({ class => "accent pageheader" }, [
63
  $h->h1 ($pageTitle),
64
  $h->div ({ class=>"sp0" }, [
65
    $h->div ({ class=>"spLeft" }, [
66
    ]),
67
    $h->div ({ class=>"spRight" }, [
68
      $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
69
    ]),
70
  ]),
71
]);
72
 
73
my $SEND = "";
74
if (param ("choice") eq "Send Email") {
75
  $SEND = 1;
76
}
77
 
78
print $h->open ("form", { action => url (), name=>"Req", method=>"POST" });
79
 
80
my $type    = chooseType ();
81
my $ID      = chooseID   ($type);
82
printDetails ($type, $ID) unless (!$type or !$ID);
83
my $subject = setSubject ();
84
my $body    = setBody ();
85
my $choice = param ("choice") // "";
86
 
87
print $h->br, $h->br;
88
if ($SEND) {
89
  emailUsers ($type, $ID, $subject, $body);
90
} else {
91
  print $h->input ({ type=>"button", value => "Cancel" , onClick=>"history.back(); return false;" });
92
  print " ";
93
  print $h->input ({ type=>"submit", name=>"choice", value => "Send Email" });
94
}
95
 
96
print $h->close ("form");
97
print $h->close ("html");
98
 
99
sub chooseType {
100
  my $type = param ("type") // "";
252 - 101
  $type = "" unless ($type eq "class" or $type eq "seminar" or $type eq "game");
168 - 102
 
252 - 103
  for ("class", "seminar", "game") {
168 - 104
    my %PROPS = (
105
      type     => "radio",
106
      id       => $_,
107
      name     => "type",
108
      value    => $_,
109
      onChange => "Req.ID.value=''; submit();"
110
    );
111
    $PROPS{checked} = [] if $type eq $_;
112
    $PROPS{disabled} = [] if $SEND;
113
 
114
    print $h->input (\%PROPS);
115
    print $h->label ({for=>$_}, ucfirst $_);
116
    print $h->br;
117
  }
118
  print $h->br;
119
 
120
  return $type;
121
}
122
 
123
sub chooseID {
124
  my $type = shift // "";
125
  my $ID = param ("ID") // "";
126
  $ID = "" unless $ID =~ /^\d+$/;
127
 
128
  if (!$type) {
252 - 129
    print $h->div ("Please select Class, Seminar, or Game.");
168 - 130
    print $h->input ({type=>"hidden", name=>"ID"});
131
    print $h->br;
132
    return "";
133
  } else {
252 - 134
    my $table = $type eq "class" ? "v_class_new" : $type eq "seminar" ? "v_seminar_new" : "v_games";
135
    my $field = ($type eq "class" or $type eq "seminar") ? "name" : "teams";
168 - 136
    my $dbh = WebDB::connect ();
137
    #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") };
138
    my %things = map { $_->[0] => $_->[1] } @{ $dbh->selectall_arrayref ("select distinct id, $field from $table where year(date) = year(now())") };
139
  	$dbh->disconnect ();
140
  	if ($SEND) {
141
  	  print $h->div([ucfirst $type.": ", $things{$ID}]);
142
  	} else {
143
      print $h->div([ucfirst $type.": ", $h->select ({ name=>"ID", onChange=>"submit();" }, [ $h->option (),
144
        map { $ID eq $_ ? $h->option ({ value=>$_, selected=>[] }, $things{$_}) : $h->option ({ value=>$_ }, $things{$_}) } sort { $things{$a} cmp $things{$b} } keys %things
145
      ])]);
146
    }
147
  }
148
  print $h->br;
149
  return $ID;
150
}
151
 
152
sub printDetails {
153
  my $type = shift // "";
154
  my $ID   = shift // "";
155
 
252 - 156
  error ("No Class, Semianr, or Game Selected") unless $type and $ID;
168 - 157
 
158
  my $dbh = WebDB::connect ();
159
 
160
  my $user_count;
161
  if ($type eq "class") {
208 - 162
    print map { $_.$h->br } $dbh->selectrow_array ("select id, name, coach, date, dayofweek, time, location from v_class_new where id = ?", undef, $ID);
163
    ($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 - 164
    print $user_count." Users".$h->br;
252 - 165
  } elsif ($type eq "seminar") {
166
    print map { $_.$h->br } $dbh->selectrow_array ("select id, name, coach, date, dayofweek, time, location from v_seminar_new where id = ?", undef, $ID);
167
    ($user_count) = $dbh->selectrow_array ("select count(email) from v_seminar_signup_new join official on v_seminar_signup_new.RCid = official.RCid where id = ?", undef, $ID);
168
    print $user_count." Users".$h->br;
168 - 169
  } elsif ($type eq "game") {
170
    print map { $_.$h->br } $dbh->selectrow_array ("select id, teams, date, dayofweek, time, track, gtype from v_games where id = ?", undef, $ID);
171
    ($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);
172
    print $user_count." Users".$h->br;
173
  } else {
174
    error ("Unknown Type: ".$type);
175
  }
176
 
177
	$dbh->disconnect ();
178
  print $h->br;
179
}
180
 
181
sub setSubject {
182
  my $subject = param ("subject") // "";
183
 
184
  if ($SEND) {
185
    print "Subject: ", $h->input ({ type=>"text", name=>"subject", value=>"$subject", size=>30, readonly=>[] });
186
  } else {
187
    print "Subject: ", $h->input ({ type=>"text", name=>"subject", value=>"$subject", size=>30 });
188
  }
189
  print $h->br;
190
 
191
  print $h->br;
192
  return $subject;
193
}
194
 
195
sub setBody {
196
  my $body = param ("body") // "";
197
 
198
  if ($SEND) {
199
    print $h->tag ("textarea", { name=>"body", value=>"$body", cols => 45, rows => 10, readonly=>[] }, $body);
200
  } else {
201
    print $h->tag ("textarea", { name=>"body", value=>"$body", cols => 45, rows => 10 }, $body);
202
  }
203
 
204
  return $body;
205
}
206
 
207
 
208
sub error {
209
	my $msg = shift;
210
	print $h->p ({ class=>"error" }, "Error: $msg");
211
  print $h->close("html");
212
	exit (0);
213
}