| Line 256... |
Line 256... |
| 256 |
sub getSchedule {
|
256 |
sub getSchedule {
|
| 257 |
my $RCid = shift // return "ERROR: No RCid provided to getSchedule";
|
257 |
my $RCid = shift // return "ERROR: No RCid provided to getSchedule";
|
| 258 |
my $filter = shift // "";
|
258 |
my $filter = shift // "";
|
| Line 259... |
Line 259... |
| 259 |
|
259 |
|
| - |
|
260 |
my @whereclause;
|
| - |
|
261 |
if ($filter eq "all") {
|
| - |
|
262 |
push @whereclause, "date >= '2022-01-01'";
|
| 260 |
my @whereclause;
|
263 |
} else {
|
| - |
|
264 |
push @whereclause, "date >= date(now())";
|
| 261 |
push @whereclause, "date >= date(now())" unless $filter eq "all";
|
265 |
}
|
| 262 |
# if ($RCid ne $ORCUSER->{RCid}) {
|
266 |
# if ($RCid ne $ORCUSER->{RCid}) {
|
| 263 |
# push @whereclause, "dept != 'PER'";
|
267 |
# push @whereclause, "dept != 'PER'";
|
| Line 264... |
Line 268... |
| 264 |
# }
|
268 |
# }
|
| Line 434... |
Line 438... |
| 434 |
($shift_id) = $dbh->selectrow_array ("select min(id) from v_shift where date = ? and start_time = ? and location = ? and isnull(RCid) = 1", undef, split /\|/, $shift_id);
|
438 |
($shift_id) = $dbh->selectrow_array ("select min(id) from v_shift where date = ? and start_time = ? and location = ? and isnull(RCid) = 1", undef, split /\|/, $shift_id);
|
| 435 |
}
|
439 |
}
|
| 436 |
my $game_based = $role ? "game" : "shift";
|
440 |
my $game_based = $role ? "game" : "shift";
|
| 437 |
my $sth;
|
441 |
my $sth;
|
| Line 438... |
Line 442... |
| 438 |
|
442 |
|
| 439 |
if ($change eq "add") {
|
443 |
if ($change eq "add" or $change eq "override") {
|
| 440 |
my $taken;
|
444 |
my $taken;
|
| 441 |
if ($game_based eq "game") {
|
445 |
if ($game_based eq "game") {
|
| 442 |
($taken) = $dbh->selectrow_array ("select count(*) from assignment where Gid = ? and role = ?", undef, $shift_id, $role);
|
446 |
($taken) = $dbh->selectrow_array ("select count(*) from assignment where Gid = ? and role = ?", undef, $shift_id, $role);
|
| 443 |
} elsif ($department eq "CLA") {
|
447 |
} elsif ($department eq "CLA") {
|
| Line 467... |
Line 471... |
| 467 |
|
471 |
|
| 468 |
if ($change eq "add" and convertDepartments(getUser($user_id)->{department})->{$department} < 1) {
|
472 |
if ($change eq "add" and convertDepartments(getUser($user_id)->{department})->{$department} < 1) {
|
| 469 |
return "<br>Denied! User ($user_id) is not a member of Department ($department)!<br>\n" unless $department eq "CMP";
|
473 |
return "<br>Denied! User ($user_id) is not a member of Department ($department)!<br>\n" unless $department eq "CMP";
|
| Line 470... |
Line 474... |
| 470 |
}
|
474 |
}
|
| - |
|
475 |
|
| 471 |
|
476 |
my $conflict = findConflict ($user_id, $shift_id, $game_based);
|
| 472 |
if ($change eq "add" and findConflict ($user_id, $shift_id, $game_based)) {
|
477 |
if ($change eq "add" and $conflict) {
|
| Line 473... |
Line 478... |
| 473 |
return "<br>Denied! There is a conflict with that shift's time!<br>\n";
|
478 |
return "<br>Denied! There is a conflict ($conflict) with that shift's time!<br>\n";
|
| 474 |
}
|
479 |
}
|
| 475 |
|
480 |
|
| Line 498... |
Line 503... |
| 498 |
} else {
|
503 |
} else {
|
| 499 |
$daily_count = signUpCount ('get', $user_id, $department);
|
504 |
$daily_count = signUpCount ('get', $user_id, $department);
|
| 500 |
if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {
|
505 |
if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {
|
| 501 |
return "<br>Denied! You may only sign up for $MAXSHIFTS $game_type shifts in one day!<br>\n";
|
506 |
return "<br>Denied! You may only sign up for $MAXSHIFTS $game_type shifts in one day!<br>\n";
|
| 502 |
}
|
507 |
}
|
| 503 |
if ($change eq "add" and $game_based eq "game" and $department eq "OFF" and $game_type eq "full length") {
|
508 |
# if ($change eq "add" and $game_based eq "game" and $department eq "OFF" and $game_type eq "full length") {
|
| 504 |
my ($full_length_count) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where RCid = ? and gtype = 'full length' and date > '2022-01-01'", undef, $user_id);
|
509 |
# my ($full_length_count) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where RCid = ? and gtype = 'full length' and date > '2022-01-01'", undef, $user_id);
|
| 505 |
if ($full_length_count >= 3) {
|
510 |
# if ($full_length_count >= 3) {
|
| 506 |
return "<br>Denied! You may only sign up to officiate 3 $game_type games (total)!<br>\n";
|
511 |
# return "<br>Denied! You may only sign up to officiate 3 $game_type games (total)!<br>\n";
|
| 507 |
}
|
512 |
# }
|
| 508 |
}
|
513 |
# }
|
| 509 |
}
|
514 |
}
|
| Line 510... |
Line 515... |
| 510 |
|
515 |
|
| 511 |
my @DBARGS;
|
516 |
my @DBARGS;
|
| 512 |
if ($game_based eq "game") {
|
517 |
if ($game_based eq "game") {
|
| 513 |
if ($change eq "add") {
|
518 |
if ($change eq "add" or $change eq "override") {
|
| 514 |
$sth = $dbh->prepare("insert into assignment (Gid, role, RCid) values (?, ?, ?)");
|
519 |
$sth = $dbh->prepare("insert into assignment (Gid, role, RCid) values (?, ?, ?)");
|
| 515 |
} elsif ($change eq "del") {
|
520 |
} elsif ($change eq "del") {
|
| 516 |
$sth = $dbh->prepare("delete from assignment where Gid = ? and role = ? and RCid= ?");
|
521 |
$sth = $dbh->prepare("delete from assignment where Gid = ? and role = ? and RCid= ?");
|
| 517 |
}
|
522 |
}
|
| 518 |
@DBARGS = ($shift_id, $role, $user_id);
|
523 |
@DBARGS = ($shift_id, $role, $user_id);
|
| 519 |
} else {
|
524 |
} else {
|
| 520 |
if ($change eq "add") {
|
525 |
if ($change eq "add" or $change eq "override") {
|
| 521 |
$sth = $dbh->prepare("update shift set assignee_id = ? where id = ? and isnull(assignee_id) = 1");
|
526 |
$sth = $dbh->prepare("update shift set assignee_id = ? where id = ? and isnull(assignee_id) = 1");
|
| 522 |
@DBARGS = ($user_id, $shift_id);
|
527 |
@DBARGS = ($user_id, $shift_id);
|
| 523 |
} elsif ($change eq "del") {
|
528 |
} elsif ($change eq "del") {
|
| 524 |
$sth = $dbh->prepare("update shift set assignee_id = null where id = ?");
|
529 |
$sth = $dbh->prepare("update shift set assignee_id = null where id = ?");
|
| Line 528... |
Line 533... |
| 528 |
|
533 |
|
| 529 |
print "<br>attempting to make DB changes...<br>";
|
534 |
print "<br>attempting to make DB changes...<br>";
|
| 530 |
if ($sth->execute (@DBARGS)) {
|
535 |
if ($sth->execute (@DBARGS)) {
|
| 531 |
$daily_count = signUpCount ($change, $user_id, $department) unless $leadership_change;
|
536 |
$daily_count = signUpCount ($change, $user_id, $department) unless $leadership_change;
|
| - |
|
537 |
logit ($user_id, "Shift ".ucfirst($change).": $shift_id -> $role");
|
| 532 |
logit ($user_id, "Shift ".ucfirst($change).": $shift_id -> $role");
|
538 |
logit ($ORCUSER->{RCid}, "OVERRIDE: Shift ".ucfirst($change).": $shift_id -> $role") if $change eq "override";
|
| 533 |
print "Success!...<br>You've signed up for $daily_count shifts today (you're currently allowed to sign up for $MAXSHIFTS per day).<br>\n";
|
539 |
print "Success!...<br>You've signed up for $daily_count shifts today (you're currently allowed to sign up for $MAXSHIFTS per day).<br>\n";
|
| 534 |
return;
|
540 |
return;
|
| 535 |
} else {
|
541 |
} else {
|
| 536 |
return "<br><b>You did not get the shift</b>, most likely because someone else took it while you were looking.<br>\nERROR: ", $sth->errstr();
|
542 |
return "<br><b>You did not get the shift</b>, most likely because someone else took it while you were looking.<br>\nERROR: ", $sth->errstr();
|
| Line 631... |
Line 637... |
| 631 |
$user->{$limitkey} = signUpCount('get', $user->{RCid}, $dept);
|
637 |
$user->{$limitkey} = signUpCount('get', $user->{RCid}, $dept);
|
| 632 |
}
|
638 |
}
|
| Line 633... |
Line 639... |
| 633 |
|
639 |
|
| 634 |
if ($shifttype eq "game") {
|
640 |
if ($shifttype eq "game") {
|
| 635 |
# if ($t->{gtype} !~ /^selected/ and $t->{gtype} ne "short track" and $user->{$limitkey} < $limit) {
|
641 |
# if ($t->{gtype} !~ /^selected/ and $t->{gtype} ne "short track" and $user->{$limitkey} < $limit) {
|
| 636 |
if ($t->{gtype} eq "full length" and $dept eq "OFF") {
|
642 |
# if ($t->{gtype} eq "full length" and $dept eq "OFF") {
|
| 637 |
my ($full_length_count) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where RCid = ? and gtype = 'full length' and date > '2022-01-01'", undef, $user->{RCid});
|
643 |
# my ($full_length_count) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where RCid = ? and gtype = 'full length' and date > '2022-01-01'", undef, $user->{RCid});
|
| 638 |
if ($full_length_count >= 3) {
|
644 |
# if ($full_length_count >= 3) {
|
| 639 |
return 0;
|
645 |
# return 0;
|
| 640 |
}
|
646 |
# }
|
| 641 |
}
|
647 |
# }
|
| 642 |
if ($t->{signup} ne "selected" and $user->{$limitkey} < $limit) {
|
648 |
if ($t->{signup} ne "selected" and $user->{$limitkey} < $limit) {
|
| 643 |
return 1;
|
649 |
return 1;
|
| 644 |
} else {
|
650 |
} else {
|
| 645 |
return 0;
|
651 |
return 0;
|
| Line 670... |
Line 676... |
| 670 |
|
676 |
|
| 671 |
if ($type eq "game") {
|
677 |
if ($type eq "game") {
|
| 672 |
# Are they already signed up for this game? (It's faster to check the two views one at a time...)
|
678 |
# Are they already signed up for this game? (It's faster to check the two views one at a time...)
|
| 673 |
# ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where substring_index(id, '-', 1) = ? and RCid = ?", undef, $gid, $rcid);
|
679 |
# ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where substring_index(id, '-', 1) = ? and RCid = ?", undef, $gid, $rcid);
|
| 674 |
($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where id = ? and RCid = ?", undef, $gid, $rcid);
|
680 |
($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where id = ? and RCid = ?", undef, $gid, $rcid);
|
| 675 |
if ($conflicts) { return 1; } # no need to keep looking...
|
681 |
if ($conflicts) { return "OFF-".$gid; } # no need to keep looking...
|
| 676 |
($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_announcer where id = ? and RCid = ?", undef, $gid, $rcid);
|
682 |
($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_announcer where id = ? and RCid = ?", undef, $gid, $rcid);
|
| Line 677... |
Line 683... |
| 677 |
if ($conflicts) { return 1; } # no need to keep looking...
|
683 |
if ($conflicts) { return "ANN-".$gid; } # no need to keep looking...
|
| 678 |
|
684 |
|
| 679 |
($date, $start, $end) = $dbh->selectrow_array ("select distinct date, time, end_time from game where id = ?", undef, $gid);
|
685 |
($date, $start, $end) = $dbh->selectrow_array ("select distinct date, time, end_time from game where id = ?", undef, $gid);
|
| 680 |
} elsif ($type eq "personal") {
|
686 |
} elsif ($type eq "personal") {
|
| Line 685... |
Line 691... |
| 685 |
|
691 |
|
| 686 |
# Are they signed up for any games that would conflict with this one?
|
692 |
# Are they signed up for any games that would conflict with this one?
|
| 687 |
# my $sth = $dbh->prepare("select count(*) from v_shift_admin_view where id in (select id from game where date = (select date from game where id = ?) and ((time <= (select time from game where id = ?) and end_time > (select time from game where id = ?)) or (time > (select time from game where id = ?) and time < (select end_time from game where id = ?)))) and RCid = ?");
|
693 |
# my $sth = $dbh->prepare("select count(*) from v_shift_admin_view where id in (select id from game where date = (select date from game where id = ?) and ((time <= (select time from game where id = ?) and end_time > (select time from game where id = ?)) or (time > (select time from game where id = ?) and time < (select end_time from game where id = ?)))) and RCid = ?");
|
| Line 688... |
Line 694... |
| 688 |
# my $sth = $dbh->prepare("select count(*) from v_shift_all where id in (select id from v_shift_all where date = (select date from v_shift_all where id = ?) and ((start_time <= (select start_time from v_shift_all where id = ?) and end_time > (select start_time from v_shift_all where id = ?)) or (start_time > (select start_time from v_shift_all where id = ?) and start_time < (select end_time from v_shift_all where id = ?)))) and RCid = ?");
|
694 |
# my $sth = $dbh->prepare("select count(*) from v_shift_all where id in (select id from v_shift_all where date = (select date from v_shift_all where id = ?) and ((start_time <= (select start_time from v_shift_all where id = ?) and end_time > (select start_time from v_shift_all where id = ?)) or (start_time > (select start_time from v_shift_all where id = ?) and start_time < (select end_time from v_shift_all where id = ?)))) and RCid = ?");
|
| 689 |
|
695 |
|
| 690 |
($conflicts) = $dbh->selectrow_array ("select count(*) from (
|
696 |
($conflicts) = $dbh->selectrow_array ("select * from (
|
| 691 |
select id from v_shift where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
|
697 |
select concat(dept, '-', id) from v_shift where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
|
| 692 |
select id from v_shift_announcer where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
|
698 |
select concat('ANN-', id) from v_shift_announcer where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
|
| 693 |
select id from v_shift_officiating where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? ) alltables",
|
699 |
select concat('OFF-', id) from v_shift_officiating where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? ) alltables",
|
| Line 694... |
Line 700... |
| 694 |
undef, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid
|
700 |
undef, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid
|
| 695 |
);
|
701 |
);
|