Subversion Repositories VORC

Rev

Rev 152 | Rev 154 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 152 Rev 153
Line 9... Line 9...
9
use DBI;
9
use DBI;
10
use WebDB;
10
use WebDB;
Line 11... Line 11...
11
 
11
 
12
$SIG{__WARN__} = sub { warn sprintf("[%s] ", scalar localtime), @_ };
12
$SIG{__WARN__} = sub { warn sprintf("[%s] ", scalar localtime), @_ };
13
$SIG{__DIE__}  = sub { die  sprintf("[%s] ", scalar localtime), @_ };
-
 
14
my $SESSIONS = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/vorc_sessions" : "/tmp/sessions";
-
 
15
my $SESSIONS_ACTIVE = $SESSIONS . "/active";
-
 
16
my $SESSIONS_QUEUE  = $SESSIONS . "/queue";
-
 
17
`/bin/mkdir $SESSIONS` unless -e $SESSIONS;
-
 
18
`/bin/mkdir $SESSIONS_ACTIVE` unless -e $SESSIONS_ACTIVE;
-
 
19
`/bin/mkdir $SESSIONS_QUEUE`  unless -e $SESSIONS_QUEUE;
-
 
20
`/usr/bin/find $SESSIONS_ACTIVE -mmin +30 -type f -delete`;
-
 
Line 21... Line 13...
21
`/usr/bin/find $SESSIONS_QUEUE -mmin +7 -type f -delete`;
13
$SIG{__DIE__}  = sub { die  sprintf("[%s] ", scalar localtime), @_ };
Line 22... Line 14...
22
 
14
 
Line 23... Line 15...
23
our @EXPORT = qw( $ORCUSER $SYSTEM_EMAIL getRCDBH getAccessLevels authDB max authenticate canView getShiftDepartment getClassID getDepartments convertDepartments convertTime getSchedule getRCid getSetting getUser getUserEmail getUserDerbyName getYears printRCHeader changeShift modShiftTime signUpCount signUpEligible findConflict changeLeadShift sendNewUserEMail logit validate_emt);
15
our @EXPORT = qw( $ORCUSER $SYSTEM_EMAIL getRCDBH getAccessLevels authDB max authenticate canView getShiftDepartment getClassID getDepartments convertDepartments convertTime getSchedule getRCid getSetting getUser getUserEmail getUserDerbyName getYears printRCHeader changeShift modShiftTime signUpCount signUpEligible findConflict changeLeadShift sendNewUserEMail logit validate_emt);
24
 
16
 
25
checkQueue (); # without a number here, the queue functionality is disabled / bypassed
17
checkQueue (); # without a number here, the queue functionality is disabled / bypassed
26
 
18
 
27
my $dbh = WebDB->connect ();
19
my $dbh = WebDB::connect ("vorc");
28
sub getRCDBH {
20
sub getRCDBH {
Line 224... Line 216...
224
    if ($session_length > getSetting ("MAX_SESSION_MINUTES")) {
216
    if ($session_length > getSetting ("MAX_SESSION_MINUTES")) {
225
      $ENV{'QUERY_STRING'} = "LOGOUT";
217
      $ENV{'QUERY_STRING'} = "LOGOUT";
226
      $authenticated->{ERRMSG} = "Maximum session time exceeded.<br>";
218
      $authenticated->{ERRMSG} = "Maximum session time exceeded.<br>";
227
    }
219
    }
Line -... Line 220...
-
 
220
    
228
    
221
    my $qdbh = WebDB::connect ("session");
229
	  if ($ENV{'QUERY_STRING'} eq "LOGOUT") {
222
	  if ($ENV{'QUERY_STRING'} eq "LOGOUT") {
230
      # warn "logging $ORCUSER->{derby_name} out...";
223
      # warn "logging $ORCUSER->{derby_name} out...";
231
      $authenticated->{ERRMSG} .= "Logged Out.<br>";
224
      $authenticated->{ERRMSG} .= "Logged Out.<br>";
232
      $authenticated->{cookie_string} = "";
225
      $authenticated->{cookie_string} = "";
233
      $authenticated->{authenticated} = 'false';
226
      $authenticated->{authenticated} = 'false';
234
      $ENV{REQUEST_URI} =~ s/LOGOUT//;
227
      $ENV{REQUEST_URI} =~ s/LOGOUT//;
235
      logit ($ORCUSER->{RCid}, "Logged Out");
228
      logit ($ORCUSER->{RCid}, "Logged Out");
236
      $dbh->do ("update official set last_active = ? where RCid = ?", undef, undef, $ORCUSER->{RCid});
229
      $dbh->do ("update official set last_active = ? where RCid = ?", undef, undef, $ORCUSER->{RCid});
-
 
230
#  		`/bin/rm $SESSIONS_ACTIVE/$sessionid`;
237
  		`/bin/rm $SESSIONS_ACTIVE/$sessionid`;
231
			$qdbh->do ("delete from session where sessionid = ?", undef, $sessionid);
238
      $ORCUSER = "";
232
      $ORCUSER = "";
239
    } else {
233
    } else {
240
  		$dbh->do ("update official set last_active = now() where RCid = ?", undef, $ORCUSER->{RCid});
234
  		$dbh->do ("update official set last_active = now() where RCid = ?", undef, $ORCUSER->{RCid});
-
 
235
#			`/bin/touch $SESSIONS_ACTIVE/$sessionid`;
241
			`/bin/touch $SESSIONS_ACTIVE/$sessionid`;
236
      $qdbh->do ("replace into session (RCid, sessionid, timestamp) values (?, ?, now())", undef, $ORCUSER->{RCid}, $sessionid);
-
 
237
#			`/bin/rm $SESSIONS_QUEUE/$RCqueueID` if ($RCqueueID and -e $SESSIONS_QUEUE."/".$RCqueueID);
242
			`/bin/rm $SESSIONS_QUEUE/$RCqueueID` if ($RCqueueID and -e $SESSIONS_QUEUE."/".$RCqueueID);
238
      $qdbh->do ("delete from queue where queueid = ?", undef, $RCqueueID) if $RCqueueID;
243
  		return $authenticated->{cookie_string};
239
  		return $authenticated->{cookie_string};
-
 
240
  	}
244
  	}
241
    $qdbh->disconnect;
Line 245... Line 242...
245
	}
242
	}
Line 341... Line 338...
341
	
338
	
Line 342... Line 339...
342
	return if $ENV{'QUERY_STRING'} eq "SKIPQUEUE";
339
	return if $ENV{'QUERY_STRING'} eq "SKIPQUEUE";
Line -... Line 340...
-
 
340
	
-
 
341
	my $RCAUTH = CGI::cookie('RCAUTH') // "";
343
	
342
	
344
	my $RCAUTH = CGI::cookie('RCAUTH') // "";
343
	my $qdbh = WebDB::connect ("session");
345
	
344
	
346
	if ($RCAUTH) {
345
	if ($RCAUTH) {
347
	  # If the user is already logged in, bypass the queue check.
346
	  # If the user is already logged in, bypass the queue check.
-
 
347
	  use Digest::MD5 qw/md5_hex/;
-
 
348
   	my ($RCID, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
Line 348... Line 349...
348
	  use Digest::MD5 qw/md5_hex/;
349
#    my $sessionid = md5_hex ($RCID);
-
 
350
    
349
   	my ($RCID, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
351
   	my ($active) = $qdbh->selectrow_array ("select count(*) from session where RCid = ? and last_active > (now() - interval 30 minute)", undef, $RCID);
Line 350... Line 352...
350
    my $sessionid = md5_hex ($RCID);
352
    
-
 
353
#    return if -e $SESSIONS_ACTIVE."/".$sessionid;
351
    
354
    return if $active;
-
 
355
	}
-
 
356
	
-
 
357
#  my $active_users = `/bin/ls -1 $SESSIONS_ACTIVE | /usr/bin/wc -l`; chomp $active_users;
352
    return if -e $SESSIONS_ACTIVE."/".$sessionid;
358
 	my ($active_users) = $qdbh->selectrow_array ("select count(*) from session where timestamp > (now() - interval 30 minute)");
Line 353... Line 359...
353
	}
359
#  my @queued_users = `/bin/ls -1 $SESSIONS_QUEUE`; foreach (@queued_users) { chomp; }
354
	
360
	my @queued_users;
355
  my $active_users = `/bin/ls -1 $SESSIONS_ACTIVE | /usr/bin/wc -l`; chomp $active_users;
361
  push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where timestamp > (now() - interval 7 minute) order by timestamp") };
356
  my @queued_users = `/bin/ls -1 $SESSIONS_QUEUE`; foreach (@queued_users) { chomp; }
362
 
357
 	my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
363
 	my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
358
 	
364
 	
359
  if ($active_users >= $max_users) {
365
  if ($active_users >= $max_users) {
360
    # We are at max users. People have to wait.
366
    # We are at max users. People have to wait.
361
    if (!$RCqueueID) {
-
 
-
 
367
    if (!$RCqueueID) {
362
   	  use Digest::MD5 qw/md5_hex/;
368
   	  use Digest::MD5 qw/md5_hex/;
363
   	  $RCqueueID = time () ."-". md5_hex (rand ());
369
   	  $RCqueueID = time () ."-". md5_hex (rand ());
Line 364... Line 370...
364
   	  push @queued_users, $RCqueueID;
370
   	  push @queued_users, $RCqueueID;
365
    }
371
    }
Line 374... Line 380...
374
      # If you're not already in queue, get in line.
380
      # If you're not already in queue, get in line.
375
   	  use Digest::MD5 qw/md5_hex/;
381
   	  use Digest::MD5 qw/md5_hex/;
376
   	  $RCqueueID = time () ."-". md5_hex (rand ());
382
   	  $RCqueueID = time () ."-". md5_hex (rand ());
377
   	  push @queued_users, $RCqueueID;
383
   	  push @queued_users, $RCqueueID;
378
    }
384
    }
379
 	  `/bin/touch $SESSIONS_QUEUE/$RCqueueID`;
385
 		$qdbh->do ("replace into queue (queueid, timestamp) values (?, now())", undef, $RCqueueID);   
Line 380... Line 386...
380
 	  
386
 	  
381
   	my $queue_position = inQueue ($RCqueueID, \@queued_users);
387
   	my $queue_position = inQueue ($RCqueueID, \@queued_users);
382
    if ($queue_position > ($max_users - $active_users)) {
388
    if ($queue_position > ($max_users - $active_users)) {
383
      # If you're not at the head of the line, continue to wait.
389
      # If you're not at the head of the line, continue to wait.
Line 397... Line 403...
397
  printRCHeader("is Busy");
403
  printRCHeader("is Busy");
398
  print<<busy;
404
  print<<busy;
399
    <P><b><font size=+2>Sorry, we are full right now.</font></P>
405
    <P><b><font size=+2>Sorry, we are full right now.</font></P>
400
    <P>You are in queue $queue_position.</P>
406
    <P>You are in queue $queue_position.</P>
401
    <div><ul>
407
    <div><ul>
402
    <li>This page will refresh every 15 seconds.</li>
408
    <li>This page will refresh every 30 seconds.</li>
403
    <li>When it's your turn to log in, you'll see the username/password boxes.</li>
409
    <li>When it's your turn to log in, you'll see the username/password boxes.</li>
404
    <li>If you don't log in within five [5] minutes, or if you leave this page, you will likely lose your place in line.</li>
410
    <li>If you don't log in within five [5] minutes, or if you leave this page, you will likely lose your place in line.</li>
405
    </ul></div>
411
    </ul></div>
406
    </BODY>
412
    </BODY>
407
    <SCRIPT language="JavaScript">
413
    <SCRIPT language="JavaScript">
408
   	<!--
414
   	<!--
409
    // Refresh the page after a delay of 5 seconds
415
    // Refresh the page after a delay
410
      setTimeout(function(){
416
      setTimeout(function(){
411
        location.replace(location.href);
417
        location.replace(location.href);
412
      }, 15000); // 15000 milliseconds = 15 seconds
418
      }, 30000); // 30000 milliseconds = 30 seconds
413
    //-->
419
    //-->
414
    </SCRIPT>
420
    </SCRIPT>
415
    </HTML>
421
    </HTML>
416
busy
422
busy
417
  return;
423
  return;
Line 558... Line 564...
558
  my $filter = shift // "";
564
  my $filter = shift // "";
559
  my $year = 1900 + (localtime)[5];
565
  my $year = 1900 + (localtime)[5];
Line 560... Line 566...
560
    
566
    
561
  my @whereclause;
567
  my @whereclause;
562
  if ($filter eq "all") {
568
  if ($filter eq "all") {
563
  	push @whereclause, "date >= '$year-01-01'";  	
569
  	push @whereclause, "year(date) >= year(now())";  	
564
  } else {
570
  } else {
565
  	push @whereclause, "date >= date(now())";
571
  	push @whereclause, "date >= date(now())";
566
  }
572
  }
567
#  if ($RCid ne $ORCUSER->{RCid}) {
573
#  if ($RCid ne $ORCUSER->{RCid}) {
Line 842... Line 848...
842
 
848
 
843
  my $daily_count;
849
  my $daily_count;
844
  if ($department eq "CLA") {
850
  if ($department eq "CLA") {
845
    # MVP Class Sign-up
851
    # MVP Class Sign-up
846
    $MAXSHIFTS = getSetting ("MAX_CLASS_SIGNUP");
852
    $MAXSHIFTS = getSetting ("MAX_CLASS_SIGNUP");
847
	  ($daily_count) = $dbh->selectrow_array ("select count(*) from v_class_signup where RCid = ?", undef, $user_id);
853
	  ($daily_count) = $dbh->selectrow_array ("select count(*) from v_class_signup where RCid = ? and year(date) = year(now())", undef, $user_id);
848
#	  ($daily_count) = $dbh->selectrow_array ("select count(*) from v_shift where RCid = ? and dept = 'CLA'", undef, $user_id);
854
#	  ($daily_count) = $dbh->selectrow_array ("select count(*) from v_shift where RCid = ? and dept = 'CLA'", undef, $user_id);
849
   	if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {	  
855
   	if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {	  
850
	    return "<br>Denied! You may only sign up for $MAXSHIFTS Classes!<br>\n";
856
	    return "<br>Denied! You may only sign up for $MAXSHIFTS Classes!<br>\n";
851
	  }
857
	  }