Subversion Repositories VORC

Rev

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

Rev Author Line No. Line
7 - 1
#!/usr/bin/perl
2
 
56 bgadell 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
 
7 - 9
use strict;
8 - 10
use cPanelUserConfig;
7 - 11
use RollerCon;
50 bgadell 12
use CGI qw/param cookie header start_html url/;
7 - 13
use CGI::Cookie;
14
use DBI;
15
use HTML::Tiny;
16
my $h = HTML::Tiny->new( mode => 'html' );
17
use WebDB;
153 - 18
my $dbh = WebDB::connect ();
7 - 19
 
20
my $cookie_string = authenticate(2) || die;
21
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
22
my $user = getUser ($EML);
23
$user->{department} = convertDepartments ($user->{department});
24
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
25
my $DEPT = getDepartments ();
26
 
27
my $targetRCid = param ("RCid") // "";
28
my $targetDept = param ("department") // "";
29
my $confirmed = param ("confirmed") // 0;
30
 
31
print CGI::header(-cookie=>$RCAUTH_cookie);
32
 
33
printRCHeader("");
34
 
35
# Are they a lead for the Department in question?
36
printError ("You're not authorized to activate users in that department.") unless $user->{department}->{$targetDept} > 1 or $LVL > 4;
37
 
38
# Does the user exist in the DB?
39
my $targetuser = getUser ($targetRCid);
40
printError ("That user doesn't exist.") unless $targetuser->{RCid} eq $targetRCid;
41
 
42
# Is the user in a pending state for the Department in question?
43
$targetuser->{department} = convertDepartments ($targetuser->{department});
44
printError ("That user can't be activated for this department.") unless exists $targetuser->{department}->{$targetDept} and $targetuser->{department}->{$targetDept} eq "0";
45
 
46
# Has the form been re-submitted with a confirmation?
47
if ($confirmed eq "YES") {
48
  print $h->p ("Very well.  Activating $targetuser->{derby_name} (RCid: $targetRCid)...");
49
  ACTIVATE ($targetuser, $targetDept, $user);
50
  print $h->p ("Done.  Now emailing the user to let them know...");
16 - 51
  sendEmail ($targetuser);
7 - 52
  print $h->p ("Done.  You can close this window now (if it doesn't close automatically). Nothing else is going to happen here.");
53
 	print<<tail;
54
	<SCRIPT language="JavaScript">
55
	<!--
56
			function sleep(milliseconds) {
57
			  var start = new Date().getTime();
58
			  for (var i = 0; i < 1e7; i++) {
59
			    if ((new Date().getTime() - start) > milliseconds){
60
			      break;
61
			    }
62
			  }
63
			}
64
 
65
			function reloadParent() {
66
	      window.opener.document.Req.submit();
67
	      sleep(5000);
29 - 68
	      window.close();
7 - 69
			}
70
 
71
			reloadParent();
72
	//-->
73
	</SCRIPT>
74
tail
75
  print $h->close ("body"), $h->close ("html");
76
 
77
} else {
78
  print $h->p ("Do you really want to activate $targetuser->{derby_name} (RCid: $targetRCid) to work in the $DEPT->{$targetDept} Department?");
50 bgadell 79
  print $h->form ({ action=>url(), method=>"POST" }, [
7 - 80
    $h->input ({ type=>"hidden", name=>"RCid", value=>$targetRCid }),
81
    $h->input ({ type=>"hidden", name=>"department", value=>$targetDept }),
82
    $h->input ({ type=>"submit", name=>"confirmed", value=>"YES" }), "&nbsp;",
83
    $h->button ({ onClick=>"window.close();" }, "Cancel")
84
  ]);
85
  print $h->close ("body"), $h->close ("html");
86
}
87
 
88
sub ACTIVATE {
89
  my $U = shift;
90
  my $D = shift;
91
  my $OU = shift;
92
 
93
  $U->{department}->{$D} = 1;
94
  $U->{department} = convertDepartments ($U->{department});
65 bgadell 95
  $dbh->do ("update official set department = ? where RCid = ?", undef, $U->{department}, $U->{RCid}) or printError ("Something 'bad' happened when saving to the database.".$dbh->errstr);
7 - 96
  logit ($OU->{RCid}, "Activated $U->{derby_name} ($U->{RCid}) to work in $DEPT->{$D} Department");
97
  logit ($U->{RCid}, "Activated to work in $DEPT->{$D} Department");
98
}
99
 
100
sub printError {
101
  my $message = shift // "";
102
  print $h->div ({ class=>"error" }, "ERROR! ".$message);
103
  $h->button ({ onClick=>"window.close();" }, "Close");
104
  print $h->close ("body"), $h->close ("html");
105
  die;
106
}
107
 
108
sub sendEmail {
109
	use RCMailer;
110
	my $data = shift;
111
 
112
	my $email = $data->{email};
29 - 113
	my $subject = "RollerCon Volunteer Schedule Manager - Added to $DEPT->{$targetDept} Department";
7 - 114
	my $body = "Greetings,
115
 
116
This should hopefully not be the first automated message you've received from us.  Your account to volunteer in the $DEPT->{$targetDept} Department at RollerCon with the following information:
117
 
118
		Derby Name: $data->{derby_name}
119
		Real Name: 	$data->{real_name}
120
		Email Address: $data->{email}
121
		Phone: $data->{phone}
122
 
123
Has been activated!
124
 
125
You are now able to log in to view and sign up for shifts!  YAAAAAYYYY!!!!!  (Imagine Kermit the Frog doing muppet hands here.)
126
 
12 - 127
https://volunteers.rollercon.com/schedule/
7 - 128
 
61 bgadell 129
Please note that you are limited to signing up to a limited number of shifts per day.  (Meaning, once you sign up for X shifts, you'll have to wait until tomorrow to sign up for more.)  Please understand, while you are a nice, concientious, and good-looking person yourself, who knows how to share, there are others out there that will hogger up all of the shifts.  As time goes by and we get closer to the event, we may lift the limit.  Who knows?
7 - 130
 
131
If you've already signed up for your daily limit of shifts, and another shift REALLY strikes your fancy, try dropping one of your shifts.  That should allow you to pick up a different one.
132
 
133
We'll be adding shifts over time, again to throttle how fast some people (not you, mind you) gobble up the shifts.  Check back, maybe even daily.
134
 
16 - 135
If you're new to using vORC, you may want to read this:
136
 
137
https://volunteers.rollercon.com/info.html
138
 
7 - 139
If you didn't make this request, well, you're still the only one who received this email, and you now have an active account.  You should probably let us know that someone is messing with you, or just sign up for shifts (if you're actually coming to RollerCon, that is).
140
 
141
-RollerCon Management
142
";
143
 
144
	# send the message
145
	EmailUser($email, $subject, $body);
146
}