Subversion Repositories VORC

Rev

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

Rev 201 Rev 208
Line 10... Line 10...
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), @_ };
Line 13... Line 13...
13
$SIG{__DIE__}  = sub { die  sprintf("[%s] ", scalar localtime), @_ };
13
$SIG{__DIE__}  = sub { die  sprintf("[%s] ", scalar localtime), @_ };
Line 14... Line 14...
14
 
14
 
Line 15... Line 15...
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);
15
our @EXPORT = qw( $ORCUSER $SYSTEM_EMAIL getRCDBH getAccessLevels authDB max authenticate canView getShiftRef getShiftDepartment getClassID getDepartments convertDepartments convertTime getSchedule getRCid getSetting getUser getUserEmail getUserDerbyName getYears printRCHeader changeShift modShiftTime signUpCount signUpEligible findConflict changeLeadShift sendNewUserEMail logit validate_emt);
16
 
16
 
Line 585... Line 585...
585
  my $where = scalar @whereclause ? "where ".join " and ", @whereclause : "";
585
  my $where = scalar @whereclause ? "where ".join " and ", @whereclause : "";
586
  my @shifts;
586
  my @shifts;
587
  my $sth = $dbh->prepare("select * from (select id, date, dayofweek, track as location, time, role, teams, signup, 'OFF' as dept, volhours from v_shift_officiating where RCid = ? union
587
  my $sth = $dbh->prepare("select * from (select id, date, dayofweek, track as location, time, role, teams, signup, 'OFF' as dept, volhours from v_shift_officiating where RCid = ? union
588
                                          select id, date, dayofweek, track as location, time, role, teams, signup, 'ANN' as dept, volhours from v_shift_announcer where RCid = ? union
588
                                          select id, date, dayofweek, track as location, time, role, teams, signup, 'ANN' as dept, volhours from v_shift_announcer where RCid = ? union
589
                                          select id, date, dayofweek, location, time, role, '' as teams, type as signup, dept, volhours from v_shift where RCid = ? union
589
                                          select id, date, dayofweek, location, time, role, '' as teams, type as signup, dept, volhours from v_shift where RCid = ? union
590
                                          select id, date, dayofweek, location, time, role, name as teams, 'mvpclass' as signup, 'CLA' as dept, 0 as volhours from v_class_signup where RCid = ?) temp
590
                                          select id, date, dayofweek, location, time, role, name as teams, 'mvpclass' as signup, 'CLA' as dept, 0 as volhours from v_class_signup_new where RCid = ?) temp
591
                           $where order by date, time");
591
                           $where order by date, time");
592
  $sth->execute($RCid, $RCid, $RCid, $RCid);
592
  $sth->execute($RCid, $RCid, $RCid, $RCid);
593
  my $hours = 0;
593
  my $hours = 0;
594
  while (my $s = $sth->fetchrow_hashref) {
594
  while (my $s = $sth->fetchrow_hashref) {
595
    my ($yyyy, $mm, $dd) = split /\-/, $s->{date};
595
    my ($yyyy, $mm, $dd) = split /\-/, $s->{date};
Line 792... Line 792...
792
  if ($shift_id =~ /^\d+$/) {
792
  if ($shift_id =~ /^\d+$/) {
793
    $department = getShiftDepartment ($role ? $shift_id."-".$role : $shift_id);
793
    $department = getShiftDepartment ($role ? $shift_id."-".$role : $shift_id);
794
  } else {
794
  } else {
795
    $department = "CLA";
795
    $department = "CLA";
796
    if ($change eq "del") {
796
    if ($change eq "del") {
797
      ($shift_id, $role) = $dbh->selectrow_array ("select id, role from v_class_signup where date = ? and start_time = ? and location = ?", undef, split /\|/, $shift_id);
797
      ($shift_id, $role) = $dbh->selectrow_array ("select id, role from v_class_signup_new where date = ? and start_time = ? and location = ?", undef, split /\|/, $shift_id);
798
    } else {
798
    } else {
799
      if ($change eq "override") {
799
      if ($change eq "override") {
800
        ($shift_id, $role) = $dbh->selectrow_array ("select id, concat('CLA-', max(cast(substring_index(role, '-', -1) as UNSIGNED)) +1) as role from v_class_signup where date = ? and start_time = ? and location = ?", undef, split /\|/, $shift_id) unless $change ne "override";
800
        ($shift_id, $role) = $dbh->selectrow_array ("select id, concat('CLA-', max(cast(substring_index(role, '-', -1) as UNSIGNED)) +1) as role from v_class_signup_new where date = ? and start_time = ? and location = ?", undef, split /\|/, $shift_id) unless $change ne "override";
801
      } else {
801
      } else {
802
        ($shift_id, $role) = $dbh->selectrow_array ("select id, concat('CLA-', max(cast(substring_index(role, '-', -1) as UNSIGNED)) +1) as role, count(role), capacity from v_class_signup where date = ? and start_time = ? and location = ? having capacity > count(role)", undef, split /\|/, $shift_id);
802
        ($shift_id, $role) = $dbh->selectrow_array ("select id, concat('CLA-', max(cast(substring_index(role, '-', -1) as UNSIGNED)) +1) as role, count(role), capacity from v_class_signup_new where date = ? and start_time = ? and location = ? having capacity > count(role)", undef, split /\|/, $shift_id);
803
      }
803
      }
804
    }
804
    }
805
    $role = "CLA-1" unless $role; # If no one has signed up for the class yet, the SQL above doesn't retrieve the first available 
805
    $role = "CLA-1" unless $role; # If no one has signed up for the class yet, the SQL above doesn't retrieve the first available 
806
  }
806
  }
807
# my $game_based = $role ? "game" : "shift";
807
# my $game_based = $role ? "game" : "shift";
Line 873... Line 873...
873
  
873
  
874
  my $daily_count;
874
  my $daily_count;
875
  if ($department eq "CLA") {
875
  if ($department eq "CLA") {
876
    # MVP Class Sign-up
876
    # MVP Class Sign-up
877
    $MAXSHIFTS = getSetting ("MAX_CLASS_SIGNUP");
877
    $MAXSHIFTS = getSetting ("MAX_CLASS_SIGNUP");
878
    ($daily_count) = $dbh->selectrow_array ("select count(*) from v_class_signup where RCid = ? and year(date) = year(now())", undef, $user_id);
878
    ($daily_count) = $dbh->selectrow_array ("select count(*) from v_class_signup_new where RCid = ? and year(date) = year(now())", undef, $user_id);
879
#   ($daily_count) = $dbh->selectrow_array ("select count(*) from v_shift where RCid = ? and dept = 'CLA'", undef, $user_id);
879
#   ($daily_count) = $dbh->selectrow_array ("select count(*) from v_shift where RCid = ? and dept = 'CLA'", undef, $user_id);
880
    if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {    
880
    if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {    
881
      return "<br>Denied! You may only sign up for $MAXSHIFTS Classes!<br>\n";
881
      return "<br>Denied! You may only sign up for $MAXSHIFTS Classes!<br>\n";
882
    }
882
    }
Line 1069... Line 1069...
1069
  return 0 unless $limit > 0;
1069
  return 0 unless $limit > 0;
Line 1070... Line 1070...
1070
  
1070
  
Line 1071... Line 1071...
1071
  my $limitkey = $dept ? "sign_ups_today_".$dept : "sign_ups_today";
1071
  my $limitkey = $dept ? "sign_ups_today_".$dept : "sign_ups_today";
1072
  
1072
  
1073
  if ($shifttype eq "class") {
1073
  if ($shifttype eq "class") {
1074
    ($t->{id}) = $dbh->selectrow_array ("select id from v_class where date = ? and location = ? and start_time = ?", undef, $t->{date}, $t->{location}, $t->{start_time});
1074
    ($t->{id}) = $dbh->selectrow_array ("select id from v_class_new where date = ? and location = ? and start_time = ?", undef, $t->{date}, $t->{location}, $t->{start_time});
1075
    $t->{dept} = "CLA";
1075
    $t->{dept} = "CLA";
1076
    $dept = "CLA";
1076
    $dept = "CLA";
Line 1100... Line 1100...
1100
  } else {
1100
  } else {
1101
    if ($dept eq "CLA") {
1101
    if ($dept eq "CLA") {
1102
      # MVP Class Sign-up
1102
      # MVP Class Sign-up
1103
      return 0 unless $user->{MVPid};
1103
      return 0 unless $user->{MVPid};
1104
      my $class_limit = getSetting ("MAX_CLASS_SIGNUP");
1104
      my $class_limit = getSetting ("MAX_CLASS_SIGNUP");
1105
      my ($class_count) = $dbh->selectrow_array ("select count(*) from v_class_signup where RCid = ? and year(date) = year(now())", undef, $user->{RCid});
1105
      my ($class_count) = $dbh->selectrow_array ("select count(*) from v_class_signup_new where RCid = ? and year(date) = year(now())", undef, $user->{RCid});
1106
      return 0 unless $class_count < $class_limit;
1106
      return 0 unless $class_count < $class_limit;
1107
    } else {
1107
    } else {
1108
      if ($user->{department}->{$dept} < 1) { return 0; }
1108
      if ($user->{department}->{$dept} < 1) { return 0; }
1109
    }
1109
    }
1110
    if (lc $t->{type} eq "lead" and $user->{department}->{$dept} < 2) { return 0; }
1110
    if (lc $t->{type} eq "lead" and $user->{department}->{$dept} < 2) { return 0; }
Line 1132... Line 1132...
1132
    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_announcer where id = ? and RCid = ?", undef, $gid, $rcid);
1132
    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_announcer where id = ? and RCid = ?", undef, $gid, $rcid);
1133
    if ($conflicts) { return "ANN-".$gid; } # no need to keep looking...
1133
    if ($conflicts) { return "ANN-".$gid; } # no need to keep looking...
Line 1134... Line 1134...
1134
    
1134
    
1135
    ($date, $start, $end) = $dbh->selectrow_array ("select distinct date, time, end_time from game where id = ?", undef, $gid);    
1135
    ($date, $start, $end) = $dbh->selectrow_array ("select distinct date, time, end_time from game where id = ?", undef, $gid);    
1136
  } elsif ($type eq "class")  {
1136
  } elsif ($type eq "class")  {
1137
    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_class_signup where id = ? and RCid = ?", undef, $gid, $rcid);
1137
    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_class_signup_new where id = ? and RCid = ?", undef, $gid, $rcid);
Line 1138... Line 1138...
1138
    if ($conflicts) { return "CLA:".$gid; } # no need to keep looking...
1138
    if ($conflicts) { return "CLA:".$gid; } # no need to keep looking...
Line 1139... Line 1139...
1139
    
1139
    
1140
    ($date, $start, $end) = $dbh->selectrow_array ("select distinct date, start_time, end_time from v_class where id = ?", undef, $gid);
1140
    ($date, $start, $end) = $dbh->selectrow_array ("select distinct date, start_time, end_time from v_class_new where id = ?", undef, $gid);
1141
    
1141
    
1142
  } elsif ($type eq "personal")  {
1142
  } elsif ($type eq "personal")  {
Line 1149... Line 1149...
1149
#  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 = ?");
1149
#  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 = ?");
1150
#  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 = ?");
1150
#  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 = ?");
Line 1151... Line 1151...
1151
  
1151
  
1152
  ($conflicts) = $dbh->selectrow_array ("select * from (
1152
  ($conflicts) = $dbh->selectrow_array ("select * from (
1153
    select concat(dept, '-', id) as conflict from v_shift          where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
1153
    select concat(dept, '-', id) as conflict from v_shift          where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
1154
    select concat('CLA:', id) as conflict from v_class_signup      where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
1154
    select concat('CLA:', id) as conflict from v_class_signup_new  where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
1155
    select concat('ANN-', id) as conflict from v_shift_announcer   where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
1155
    select concat('ANN-', id) as conflict from v_shift_announcer   where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? union
1156
    select concat('OFF-', id) as conflict from v_shift_officiating where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? ) alltables
1156
    select concat('OFF-', id) as conflict from v_shift_officiating where date = ? and ((start_time <= ? and end_time > ?) or (start_time > ? and start_time < ?)) and RCid = ? ) alltables
1157
    where conflict <> ?",
1157
    where conflict <> ?",
1158
    undef, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, "PER-".$existing
1158
    undef, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, $date, $start, $start, $start, $end, $rcid, "PER-".$existing