Subversion Repositories ORC

Rev

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

Rev 13 Rev 19
Line 330... Line 330...
330
  }
330
  }
331
}
331
}
Line 332... Line 332...
332
 
332
 
333
sub getSetting {
333
sub getSetting {
334
	my $k = shift;
334
	my $k = shift;
335
	my $sth = $dbh->prepare("select setting.value from setting where setting.key = ?");
335
	my ($value) = $dbh->selectrow_array ("select setting.value from setting where setting.key = ?", undef, $k);
336
	$sth->execute($k);
-
 
337
	return $sth->fetchrow_hashref()->{value};
336
  return $value;
Line 338... Line 337...
338
}
337
}
339
 
338
 
Line 540... Line 539...
540
}
539
}
Line 541... Line 540...
541
 
540
 
542
sub signUpCount {
541
sub signUpCount {
543
	my $action = shift;
542
	my $action = shift;
544
	my $id = shift;
543
	my $id = shift;
Line 545... Line 544...
545
	my $gtype = shift // "";
544
	my $dept = shift // "";
546
	
545
	
547
	if ($id eq $ORCUSER->{RCid}) {
546
	if ($id eq $ORCUSER->{RCid}) {
548
		if ($action eq 'add') {
547
		if ($action eq 'add') {
549
			if (signUpCount ('get', $id)) {
548
			if (signUpCount ('get', $id, $dept)) {
550
				$dbh->do("update sign_up_count set sign_ups = sign_ups + 1 where date = curdate() and RCid = ?", undef, $id);
549
				$dbh->do("update sign_up_count set sign_ups = sign_ups + 1 where date = curdate() and RCid = ? and department = ?", undef, $id, $dept);
551
			} else {
550
			} else {
552
				$dbh->do("replace into sign_up_count values (curdate(), ?, 1)", undef, $id);
551
				$dbh->do("replace into sign_up_count (date, RCid, department, sign_ups) values (curdate(), ?, ?, 1)", undef, $id, $dept);
553
			}
552
			}
554
		} elsif ($action eq 'del') {
553
		} elsif ($action eq 'del') {
555
			if (signUpCount ('get', $id)) {
554
			if (signUpCount ('get', $id, $dept)) {
556
				$dbh->do("update sign_up_count set sign_ups = sign_ups - 1 where date = curdate() and RCid = ?", undef, $id);
555
				$dbh->do("update sign_up_count set sign_ups = sign_ups - 1 where date = curdate() and RCid = ? and department = ?", undef, $id, $dept);
557
			}
556
			}
Line 558... Line 557...
558
		}
557
		}
Line 559... Line 558...
559
	}
558
	}
560
	
559
	
Line 561... Line 560...
561
	my ($R) = $dbh->selectrow_array ("select sign_ups from sign_up_count where RCid = ? and date = curdate()", undef, $id);
560
	my ($R) = $dbh->selectrow_array ("select sign_ups from sign_up_count where RCid = ? and department = ? and date = curdate()", undef, $id, $dept);
562
 
561
 
563
	return $R ? $R : '0';
562
	return $R ? $R : '0';
564
}
563
}
-
 
564
 
-
 
565
sub signUpEligible {
-
 
566
	my $user = shift;
-
 
567
	my $t = shift;
-
 
568
	my $shifttype = shift // "game";
-
 
569
	my $dept = $t->{dept} // "";
Line 565... Line 570...
565
 
570
	
Line 566... Line 571...
566
sub signUpEligible {
571
	my $limit = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY_".$dept);
567
	my $user = shift;
572
	$limit = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY") unless defined $limit;
568
	my $t = shift;
573
	
Line 569... Line 574...
569
	my $shifttype = shift // "game";
574
	my $limitkey = $dept ? "sign_ups_today_".$dept : "sign_ups_today";
570
	
575
	
571
	if (findConflict ($user->{RCid}, $t->{id}, $shifttype)) { return 0; }
576
	if (findConflict ($user->{RCid}, $t->{id}, $shifttype)) { return 0; }
572
 
577
 
573
	if (!exists $user->{sign_ups_today}) {
578
	if (!exists $user->{$limitkey}) {
574
		$user->{sign_ups_today} = signUpCount('get', $user->{RCid});
579
		$user->{$limitkey} = signUpCount('get', $user->{RCid}, $dept);
575
	}
580
	}
576
	
581
	
577
	if ($shifttype eq "game") {
582
	if ($shifttype eq "game") {
578
    if ($t->{gtype} !~ /^selected/ and $t->{gtype} ne "short track" and $user->{sign_ups_today} < getSetting("MAX_SHIFT_SIGNUP_PER_DAY")) {
583
    if ($t->{gtype} !~ /^selected/ and $t->{gtype} ne "short track" and $user->{$limitkey} < $limit) {
579
			return 1;
584
			return 1;
580
		} else {
585
		} else {
581
			return 0;
586
			return 0;
582
		}
587
		}
583
	} else {
588
	} else {
584
	  if ($user->{department}->{$t->{dept}} < 1) { return 0; }
589
	  if ($user->{department}->{$t->{dept}} < 1) { return 0; }