Subversion Repositories ORC

Rev

Rev 8 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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