Subversion Repositories ORC

Rev

Rev 16 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/perl

use strict;
use cPanelUserConfig;
use RollerCon;
use CGI;
use CGI::Cookie;
use DBI;
use HTML::Tiny;
my $h = HTML::Tiny->new( mode => 'html' );
use WebDB;
my $dbh = WebDB->connect ();

my $cookie_string = authenticate(2) || die;
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $user = getUser ($EML);
$user->{department} = convertDepartments ($user->{department});
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
my $DEPT = getDepartments ();

my $targetRCid = param ("RCid") // "";
my $targetDept = param ("department") // "";
my $confirmed = param ("confirmed") // 0;

print CGI::header(-cookie=>$RCAUTH_cookie);

printRCHeader("");

# Are they a lead for the Department in question?
printError ("You're not authorized to activate users in that department.") unless $user->{department}->{$targetDept} > 1 or $LVL > 4;

# Does the user exist in the DB?
my $targetuser = getUser ($targetRCid);
printError ("That user doesn't exist.") unless $targetuser->{RCid} eq $targetRCid;

# Is the user in a pending state for the Department in question?
$targetuser->{department} = convertDepartments ($targetuser->{department});
printError ("That user can't be activated for this department.") unless exists $targetuser->{department}->{$targetDept} and $targetuser->{department}->{$targetDept} eq "0";

# Has the form been re-submitted with a confirmation?
if ($confirmed eq "YES") {
  print $h->p ("Very well.  Activating $targetuser->{derby_name} (RCid: $targetRCid)...");
  ACTIVATE ($targetuser, $targetDept, $user);
  print $h->p ("Done.  Now emailing the user to let them know...");
  sendEmail ($targetuser);
  print $h->p ("Done.  You can close this window now (if it doesn't close automatically). Nothing else is going to happen here.");
        print<<tail;
        <SCRIPT language="JavaScript">
        <!-- 
                        function sleep(milliseconds) {
                          var start = new Date().getTime();
                          for (var i = 0; i < 1e7; i++) {
                            if ((new Date().getTime() - start) > milliseconds){
                              break;
                            }
                          }
                        }
         
                        function reloadParent() {
              window.opener.document.Req.submit();
              sleep(5000);                      
              window.close();
                        }
                        
                        reloadParent();
        //-->
        </SCRIPT>
tail
  print $h->close ("body"), $h->close ("html");

} else {
  print $h->p ("Do you really want to activate $targetuser->{derby_name} (RCid: $targetRCid) to work in the $DEPT->{$targetDept} Department?");
  print $h->form ({ action=>url, method=>"POST" }, [
    $h->input ({ type=>"hidden", name=>"RCid", value=>$targetRCid }),
    $h->input ({ type=>"hidden", name=>"department", value=>$targetDept }),
    $h->input ({ type=>"submit", name=>"confirmed", value=>"YES" }), "&nbsp;",
    $h->button ({ onClick=>"window.close();" }, "Cancel")
  ]);
  print $h->close ("body"), $h->close ("html");
}

sub ACTIVATE {
  my $U = shift;
  my $D = shift;
  my $OU = shift;
  
  $U->{department}->{$D} = 1;
  $U->{department} = convertDepartments ($U->{department});
  $dbh->do ("update official set access = 1, department = ? where RCid = ?", undef, $U->{department}, $U->{RCid}) or printError ("Something 'bad' happened when saving to the database.".$dbh->errstr);
  logit ($OU->{RCid}, "Activated $U->{derby_name} ($U->{RCid}) to work in $DEPT->{$D} Department");
  logit ($U->{RCid}, "Activated to work in $DEPT->{$D} Department");
}

sub printError {
  my $message = shift // "";
  print $h->div ({ class=>"error" }, "ERROR! ".$message);
  $h->button ({ onClick=>"window.close();" }, "Close");
  print $h->close ("body"), $h->close ("html");
  die;
}

sub sendEmail {
        use RCMailer;
        my $data = shift;

        my $email = $data->{email};
        my $subject = "RollerCon Volunteer Schedule Manager - Added to $DEPT->{$targetDept} Department";
        my $body = "Greetings,

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:

                Derby Name: $data->{derby_name} 
                Real Name:      $data->{real_name}
                Email Address: $data->{email}
                Phone: $data->{phone}

Has been activated!

You are now able to log in to view and sign up for shifts!  YAAAAAYYYY!!!!!  (Imagine Kermit the Frog doing muppet hands here.)

https://volunteers.rollercon.com/schedule/

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?

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.

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.

If you're new to using vORC, you may want to read this:

https://volunteers.rollercon.com/info.html

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).

-RollerCon Management
";

        # send the message
        EmailUser($email, $subject, $body);
}