Subversion Repositories ORC

Rev

Rev 8 | Rev 16 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 - 1
#!/usr/bin/perl
2
 
3
use strict;
8 - 4
use cPanelUserConfig;
7 - 5
use RollerCon;
6
use CGI;
7
use CGI::Cookie;
8
use DBI;
9
use HTML::Tiny;
10
my $h = HTML::Tiny->new( mode => 'html' );
11
use WebDB;
12
my $dbh = WebDB->connect ();
13
 
14
my $cookie_string = authenticate(2) || die;
15
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
16
my $user = getUser ($EML);
17
$user->{department} = convertDepartments ($user->{department});
18
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
19
my $DEPT = getDepartments ();
20
 
21
my $targetRCid = param ("RCid") // "";
22
my $targetDept = param ("department") // "";
23
my $confirmed = param ("confirmed") // 0;
24
 
25
print CGI::header(-cookie=>$RCAUTH_cookie);
26
 
27
printRCHeader("");
28
 
29
# Are they a lead for the Department in question?
30
printError ("You're not authorized to activate users in that department.") unless $user->{department}->{$targetDept} > 1 or $LVL > 4;
31
 
32
# Does the user exist in the DB?
33
my $targetuser = getUser ($targetRCid);
34
printError ("That user doesn't exist.") unless $targetuser->{RCid} eq $targetRCid;
35
 
36
# Is the user in a pending state for the Department in question?
37
$targetuser->{department} = convertDepartments ($targetuser->{department});
38
printError ("That user can't be activated for this department.") unless exists $targetuser->{department}->{$targetDept} and $targetuser->{department}->{$targetDept} eq "0";
39
 
40
# Has the form been re-submitted with a confirmation?
41
if ($confirmed eq "YES") {
42
  print $h->p ("Very well.  Activating $targetuser->{derby_name} (RCid: $targetRCid)...");
43
  ACTIVATE ($targetuser, $targetDept, $user);
44
  print $h->p ("Done.  Now emailing the user to let them know...");
45
#  sendEmail ($targetuser);
46
  print $h->p ("Done.  You can close this window now (if it doesn't close automatically). Nothing else is going to happen here.");
47
 	print<<tail;
48
	<SCRIPT language="JavaScript">
49
	<!--
50
			function sleep(milliseconds) {
51
			  var start = new Date().getTime();
52
			  for (var i = 0; i < 1e7; i++) {
53
			    if ((new Date().getTime() - start) > milliseconds){
54
			      break;
55
			    }
56
			  }
57
			}
58
 
59
			function reloadParent() {
60
	      window.opener.document.Req.submit();
61
	      sleep(5000);
62
	      //window.close();
63
			}
64
 
65
			reloadParent();
66
	//-->
67
	</SCRIPT>
68
tail
69
  print $h->close ("body"), $h->close ("html");
70
 
71
} else {
72
  print $h->p ("Do you really want to activate $targetuser->{derby_name} (RCid: $targetRCid) to work in the $DEPT->{$targetDept} Department?");
73
  print $h->form ({ action=>url, method=>"POST" }, [
74
    $h->input ({ type=>"hidden", name=>"RCid", value=>$targetRCid }),
75
    $h->input ({ type=>"hidden", name=>"department", value=>$targetDept }),
76
    $h->input ({ type=>"submit", name=>"confirmed", value=>"YES" }), "&nbsp;",
77
    $h->button ({ onClick=>"window.close();" }, "Cancel")
78
  ]);
79
  print $h->close ("body"), $h->close ("html");
80
}
81
 
82
sub ACTIVATE {
83
  my $U = shift;
84
  my $D = shift;
85
  my $OU = shift;
86
 
87
  $U->{department}->{$D} = 1;
88
  $U->{department} = convertDepartments ($U->{department});
89
  $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);
90
  logit ($OU->{RCid}, "Activated $U->{derby_name} ($U->{RCid}) to work in $DEPT->{$D} Department");
91
  logit ($U->{RCid}, "Activated to work in $DEPT->{$D} Department");
92
}
93
 
94
sub printError {
95
  my $message = shift // "";
96
  print $h->div ({ class=>"error" }, "ERROR! ".$message);
97
  $h->button ({ onClick=>"window.close();" }, "Close");
98
  print $h->close ("body"), $h->close ("html");
99
  die;
100
}
101
 
102
sub sendEmail {
103
	use RCMailer;
104
	my $data = shift;
105
 
106
	my $email = $data->{email};
107
	my $subject = 'RollerCon Volunteer Schedule Manager - Added to $DEPT->{$targetDept} Department';
108
	my $body = "Greetings,
109
 
110
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:
111
 
112
		Derby Name: $data->{derby_name}
113
		Real Name: 	$data->{real_name}
114
		Email Address: $data->{email}
115
		Phone: $data->{phone}
116
 
117
Has been activated!
118
 
119
You are now able to log in to view and sign up for shifts!  YAAAAAYYYY!!!!!  (Imagine Kermit the Frog doing muppet hands here.)
120
 
12 - 121
https://volunteers.rollercon.com/schedule/
7 - 122
 
123
Please note that you are limited to signing up to a limnited 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?
124
 
125
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.
126
 
127
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.
128
 
129
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).
130
 
131
-RollerCon Management
132
";
133
 
134
	# send the message
135
	EmailUser($email, $subject, $body);
136
}