Subversion Repositories VORC

Rev

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

Rev 190 Rev 200
Line 46... Line 46...
46
  );
46
  );
47
  return \%AccessLevels;
47
  return \%AccessLevels;
48
}
48
}
Line 49... Line 49...
49
 
49
 
50
sub authDB {
50
sub authDB {
51
	my $src = shift;
51
  my $src = shift;
52
	my $id = shift;
52
  my $id = shift;
53
	my $pass = shift;
53
  my $pass = shift;
54
	my $level = shift;
54
  my $level = shift;
55
	my $activationcode = shift // "";
55
  my $activationcode = shift // "";
56
	my ($result, $encpass);
56
  my ($result, $encpass);
57
	
57
  
58
	my $sth = $dbh->prepare("select * from official where email = ?");
58
  my $sth = $dbh->prepare("select * from official where email = ?");
59
	$sth->execute($id);
59
  $sth->execute($id);
60
	my $RCDBIDHASH = $sth->fetchrow_hashref();
60
  my $RCDBIDHASH = $sth->fetchrow_hashref();
61
	
61
  
62
	if ($src eq "form") {
62
  if ($src eq "form") {
63
		my $pwdhan = $dbh->prepare("select password(?)");
63
    my $pwdhan = $dbh->prepare("select password(?)");
64
		$pwdhan->execute($pass);
64
    $pwdhan->execute($pass);
65
		($encpass) = $pwdhan->fetchrow();
65
    ($encpass) = $pwdhan->fetchrow();
66
	} else {
66
  } else {
67
		$encpass = $pass;		
67
    $encpass = $pass;   
68
	}
68
  }
69
	
69
  
70
	my $tempDepartments = convertDepartments ($RCDBIDHASH->{department});
70
  my $tempDepartments = convertDepartments ($RCDBIDHASH->{department});
71
	my $MAXACCESS = scalar keys %{ $tempDepartments } ? max ($RCDBIDHASH->{'access'}, values %{ $tempDepartments } ) : $RCDBIDHASH->{'access'};
71
  my $MAXACCESS = scalar keys %{ $tempDepartments } ? max ($RCDBIDHASH->{'access'}, values %{ $tempDepartments } ) : $RCDBIDHASH->{'access'};
72
	
72
  
73
	if (!$RCDBIDHASH->{'RCid'}) {
73
  if (!$RCDBIDHASH->{'RCid'}) {
74
		$result->{ERRMSG} = "Email Address not found!";
74
    $result->{ERRMSG} = "Email Address not found!";
75
		$result->{cookie_string} = '';
75
    $result->{cookie_string} = '';
76
		$result->{RCid} = '';
76
    $result->{RCid} = '';
77
		logit(0, "Account not found: $id");
77
    logit(0, "Account not found: $id");
78
		$result->{authenticated} = 'false';
78
    $result->{authenticated} = 'false';
79
		return $result;
79
    return $result;
80
	} elsif ($RCDBIDHASH->{'password'} ne $encpass) {
80
  } elsif ($RCDBIDHASH->{'password'} ne $encpass) {
81
		$result->{ERRMSG} = "Incorrect Password!";
81
    $result->{ERRMSG} = "Incorrect Password!";
82
		$result->{cookie_string} = '';
82
    $result->{cookie_string} = '';
83
		$result->{RCid} = $RCDBIDHASH->{'RCid'};
83
    $result->{RCid} = $RCDBIDHASH->{'RCid'};
84
		logit($RCDBIDHASH->{'RCid'}, "Incorrect Password");
84
    logit($RCDBIDHASH->{'RCid'}, "Incorrect Password");
85
		$result->{authenticated} = 'false';
85
    $result->{authenticated} = 'false';
86
		return $result;
86
    return $result;
87
  } elsif ($RCDBIDHASH->{'activation'} ne "active") {
87
  } elsif ($RCDBIDHASH->{'activation'} ne "active") {
88
    # It's an inactive account...
88
    # It's an inactive account...
89
    if ($activationcode eq "resend") {
89
    if ($activationcode eq "resend") {
90
      # warn "Resending activation code...";
90
      # warn "Resending activation code...";
91
      sendNewUserEMail ("New User", $RCDBIDHASH);
91
      sendNewUserEMail ("New User", $RCDBIDHASH);
92
      $result->{ERRMSG} = "Activation code resent. Please check your email.";
92
      $result->{ERRMSG} = "Activation code resent. Please check your email.";
93
  		$result->{cookie_string} = "${id}&${encpass}&0";
93
      $result->{cookie_string} = "${id}&${encpass}&0";
94
  		$result->{RCid} = $RCDBIDHASH->{'RCid'};
94
      $result->{RCid} = $RCDBIDHASH->{'RCid'};
95
  		logit($RCDBIDHASH->{'RCid'}, "Activation code resent.");
95
      logit($RCDBIDHASH->{'RCid'}, "Activation code resent.");
96
  		$result->{authenticated} = 'inactive';
96
      $result->{authenticated} = 'inactive';
97
  		return $result;        
97
      return $result;        
98
    } elsif ($activationcode) {
98
    } elsif ($activationcode) {
99
      # They sent an activation code
99
      # They sent an activation code
100
      if ($activationcode eq $RCDBIDHASH->{'activation'}) {
100
      if ($activationcode eq $RCDBIDHASH->{'activation'}) {
101
        # ...and it was good.
101
        # ...and it was good.
Line 106... Line 106...
106
        $RCDBIDHASH->{'activation'} = "active";
106
        $RCDBIDHASH->{'activation'} = "active";
107
        $MAXACCESS = max ($MAXACCESS, 1);
107
        $MAXACCESS = max ($MAXACCESS, 1);
108
      } else {
108
      } else {
109
        # ...but it wasn't good.
109
        # ...but it wasn't good.
110
        $result->{ERRMSG} = "Activation failed, invalid code submitted.";
110
        $result->{ERRMSG} = "Activation failed, invalid code submitted.";
111
    		$result->{cookie_string} = "${id}&${encpass}&0";;
111
        $result->{cookie_string} = "${id}&${encpass}&0";;
112
    		$result->{RCid} = $RCDBIDHASH->{'RCid'};
112
        $result->{RCid} = $RCDBIDHASH->{'RCid'};
113
        logit($RCDBIDHASH->{'RCid'}, "Activation failed, invalid code submitted.");
113
        logit($RCDBIDHASH->{'RCid'}, "Activation failed, invalid code submitted.");
114
    		$result->{authenticated} = 'inactive';
114
        $result->{authenticated} = 'inactive';
115
  	  	return $result;
115
        return $result;
116
      }
116
      }
117
    } else {
117
    } else {
118
      # No activation code was submitted.
118
      # No activation code was submitted.
119
  		$result->{ERRMSG} = "Inactive account! Please check your email for activation link/code." unless $result->{ERRMSG};
119
      $result->{ERRMSG} = "Inactive account! Please check your email for activation link/code." unless $result->{ERRMSG};
120
  		$result->{cookie_string} = "${id}&${encpass}&0";
120
      $result->{cookie_string} = "${id}&${encpass}&0";
121
  		$result->{RCid} = $RCDBIDHASH->{'RCid'};
121
      $result->{RCid} = $RCDBIDHASH->{'RCid'};
122
  		logit($RCDBIDHASH->{'RCid'}, "Login attempted without activation code.");
122
      logit($RCDBIDHASH->{'RCid'}, "Login attempted without activation code.");
123
  		$result->{authenticated} = 'inactive';
123
      $result->{authenticated} = 'inactive';
124
  		return $result;      
124
      return $result;      
125
    }
125
    }
126
	}
126
  }
127
	
127
  
128
	if ($MAXACCESS < $level) {
128
  if ($MAXACCESS < $level) {
129
	  if (getSetting ("MAINTENANCE")) {
129
    if (getSetting ("MAINTENANCE")) {
130
	    $result->{ERRMSG} = "MAINTENANCE MODE: Logins are temporarily disabled.";
130
      $result->{ERRMSG} = "MAINTENANCE MODE: Logins are temporarily disabled.";
131
	  } else {
131
    } else {
132
		  $result->{ERRMSG} = "Your account either needs to be activated, or doesn't have access to this page!";
132
      $result->{ERRMSG} = "Your account either needs to be activated, or doesn't have access to this page!";
133
  		logit($RCDBIDHASH->{'RCid'}, "Insufficient Privileges");
133
      logit($RCDBIDHASH->{'RCid'}, "Insufficient Privileges");
134
		}
134
    }
135
		$result->{cookie_string} = "${id}&${encpass}&$RCDBIDHASH->{'access'}";
135
    $result->{cookie_string} = "${id}&${encpass}&$RCDBIDHASH->{'access'}";
136
		$result->{RCid} = $RCDBIDHASH->{'RCid'};
136
    $result->{RCid} = $RCDBIDHASH->{'RCid'};
137
		$result->{authenticated} = 'false';
137
    $result->{authenticated} = 'false';
138
	} else {
138
  } else {
139
		$result->{ERRMSG} = '';
139
    $result->{ERRMSG} = '';
140
		$RCDBIDHASH->{department} = convertDepartments ($RCDBIDHASH->{department});
140
    $RCDBIDHASH->{department} = convertDepartments ($RCDBIDHASH->{department});
141
		$RCDBIDHASH->{'access'} = max ($RCDBIDHASH->{'access'}, values %{$RCDBIDHASH->{department}});
141
    $RCDBIDHASH->{'access'} = max ($RCDBIDHASH->{'access'}, values %{$RCDBIDHASH->{department}});
142
		$result->{cookie_string} = "${id}&${encpass}&$RCDBIDHASH->{'access'}";
142
    $result->{cookie_string} = "${id}&${encpass}&$RCDBIDHASH->{'access'}";
143
		$result->{RCid} = $RCDBIDHASH->{'RCid'};
143
    $result->{RCid} = $RCDBIDHASH->{'RCid'};
144
		logit($RCDBIDHASH->{'RCid'}, "Logged In") if $src eq "form";
144
    logit($RCDBIDHASH->{'RCid'}, "Logged In") if $src eq "form";
145
		$dbh->do ("update official set last_login = now() where RCid = ?", undef, $RCDBIDHASH->{'RCid'}) if $src eq "form";
145
    $dbh->do ("update official set last_login = now() where RCid = ?", undef, $RCDBIDHASH->{'RCid'}) if $src eq "form";
146
		$result->{authenticated} = 'true';
146
    $result->{authenticated} = 'true';
147
		
147
    
148
		$ORCUSER = $RCDBIDHASH;
148
    $ORCUSER = $RCDBIDHASH;
149
		$ORCUSER->{MVPid} = getUser($ORCUSER->{RCid})->{MVPid};
149
    $ORCUSER->{MVPid} = getUser($ORCUSER->{RCid})->{MVPid};
150
		$ORCUSER->{emt_verified} = getUser($ORCUSER->{RCid})->{emt_verified};
150
    $ORCUSER->{emt_verified} = getUser($ORCUSER->{RCid})->{emt_verified};
151
	}
151
  }
152
	return $result;
152
  return $result;
153
}
153
}
Line 154... Line 154...
154
 
154
 
155
sub max {
155
sub max {
156
    my ($max, $next, @vars) = @_;
156
    my ($max, $next, @vars) = @_;
157
    return $max if not $next;
157
    return $max if not $next;
158
    return max( $max > $next ? $max : $next, @vars );
158
    return max( $max > $next ? $max : $next, @vars );
Line 159... Line 159...
159
}
159
}
160
 
160
 
161
sub inQueue {
161
sub inQueue {
162
	my $item = shift;
162
  my $item = shift;
163
	my $array = shift;
163
  my $array = shift;
164
	my $position = 1;
164
  my $position = 1;
165
	foreach (@{$array})	{
165
  foreach (@{$array}) {
166
	  if ($item eq $_) {
166
    if ($item eq $_) {
167
		  return $position;
167
      return $position;
168
		} else {
168
    } else {
169
		  $position++;
169
      $position++;
170
		}
170
    }
171
	}
171
  }
Line 172... Line 172...
172
	return 0;
172
  return 0;
173
}
173
}
174
 
174
 
175
 
175
 
176
sub authenticate {									# Verifies the user has logged in or puts up a log in screen
176
sub authenticate {                  # Verifies the user has logged in or puts up a log in screen
177
	my $MAINTMODE = getSetting ("MAINTENANCE");
177
  my $MAINTMODE = getSetting ("MAINTENANCE");
178
	my $MINLEVEL = $MAINTMODE ? $MAINTMODE : shift // 1;
178
  my $MINLEVEL = $MAINTMODE ? $MAINTMODE : shift // 1;
179
	
179
  
180
	my ($ERRMSG, $authenticated, %FORM);
180
  my ($ERRMSG, $authenticated, %FORM);
181
	my $sth = $dbh->prepare("select * from official where email = '?'");
181
  my $sth = $dbh->prepare("select * from official where email = '?'");
182
	
182
  
183
	my $query = new CGI;
183
  my $query = new CGI;
184
# Check to see if the user has already logged in (there should be cookies with their authentication)?
184
# Check to see if the user has already logged in (there should be cookies with their authentication)?
185
	my $RCAUTH = $query->cookie('RCAUTH');
185
  my $RCAUTH = $query->cookie('RCAUTH');
186
 	my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
186
  my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
187
	$FORM{'ID'} = WebDB::trim $query->param('userid') || '';
187
  $FORM{'ID'} = WebDB::trim $query->param('userid') || '';
188
	$FORM{'PASS'} = WebDB::trim $query->param('pass') || '';
188
  $FORM{'PASS'} = WebDB::trim $query->param('pass') || '';
189
	$FORM{'SUB'} = $query->param('login') || '';
189
  $FORM{'SUB'} = $query->param('login') || '';
190
	$FORM{'activate'} = WebDB::trim $query->param('activate') // '';
190
  $FORM{'activate'} = WebDB::trim $query->param('activate') // '';
191
	
191
  
192
	if ($RCAUTH) {
192
  if ($RCAUTH) {
193
		# We have an authenication cookie.  Double-check it
193
    # We have an authenication cookie.  Double-check it
194
		my ($RCID, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
194
    my ($RCID, $RCPASS, $RCLVL) = split /&/, $RCAUTH;
195
		$authenticated = authDB('cookie', $RCID, $RCPASS, $MINLEVEL, $FORM{'activate'});
195
    $authenticated = authDB('cookie', $RCID, $RCPASS, $MINLEVEL, $FORM{'activate'});
196
	} elsif ($FORM{'SUB'}) {
196
  } elsif ($FORM{'SUB'}) {
197
		# a log in form was submited
197
    # a log in form was submited
198
		if ($FORM{'SUB'} eq "Submit") {
198
    if ($FORM{'SUB'} eq "Submit") {
199
			$authenticated = authDB('form', $FORM{'ID'}, $FORM{'PASS'}, $MINLEVEL, $FORM{'activate'});
199
      $authenticated = authDB('form', $FORM{'ID'}, $FORM{'PASS'}, $MINLEVEL, $FORM{'activate'});
200
		} elsif ($FORM{'SUB'} eq "New User") {
200
    } elsif ($FORM{'SUB'} eq "New User") {
201
			# Print the new user form and exit
201
      # Print the new user form and exit
202
		}
202
    }
203
	} else {
203
  } else {
204
		$authenticated->{authenticated} = 'false';
204
    $authenticated->{authenticated} = 'false';
205
	}
205
  }
Line 206... Line 206...
206
	
206
  
207
	if ($authenticated->{authenticated} eq 'true') {
207
  if ($authenticated->{authenticated} eq 'true') {
Line 214... Line 214...
214
      $ENV{'QUERY_STRING'} = "LOGOUT";
214
      $ENV{'QUERY_STRING'} = "LOGOUT";
215
      $authenticated->{ERRMSG} = "Maximum session time exceeded.<br>";
215
      $authenticated->{ERRMSG} = "Maximum session time exceeded.<br>";
216
    }
216
    }
Line 217... Line 217...
217
    
217
    
218
    my $qdbh = WebDB::connect ("session");
218
    my $qdbh = WebDB::connect ("session");
219
	  if ($ENV{'QUERY_STRING'} eq "LOGOUT") {
219
    if ($ENV{'QUERY_STRING'} eq "LOGOUT") {
220
      # warn "logging $ORCUSER->{derby_name} out...";
220
      # warn "logging $ORCUSER->{derby_name} out...";
221
      $authenticated->{ERRMSG} .= "Logged Out.<br>";
221
      $authenticated->{ERRMSG} .= "Logged Out.<br>";
222
      $authenticated->{cookie_string} = "";
222
      $authenticated->{cookie_string} = "";
223
      $authenticated->{authenticated} = 'false';
223
      $authenticated->{authenticated} = 'false';
224
      $ENV{REQUEST_URI} =~ s/LOGOUT//;
224
      $ENV{REQUEST_URI} =~ s/LOGOUT//;
225
      logit ($ORCUSER->{RCid}, "Logged Out");
225
      logit ($ORCUSER->{RCid}, "Logged Out");
226
      $dbh->do ("update official set last_active = ? where RCid = ?", undef, undef, $ORCUSER->{RCid});
226
      $dbh->do ("update official set last_active = ? where RCid = ?", undef, undef, $ORCUSER->{RCid});
227
			$qdbh->do ("delete from session where sessionid = ?", undef, $sessionid);
227
      $qdbh->do ("delete from session where sessionid = ?", undef, $sessionid);
228
      $ORCUSER = "";
228
      $ORCUSER = "";
229
    } else {
229
    } else {
230
  		$dbh->do ("update official set last_active = now() where RCid = ?", undef, $ORCUSER->{RCid});
230
      $dbh->do ("update official set last_active = now() where RCid = ?", undef, $ORCUSER->{RCid});
231
      $qdbh->do ("replace into session (RCid, sessionid, timestamp, email) values (?, ?, now(), ?)", undef, $ORCUSER->{RCid}, $sessionid, $ORCUSER->{email});
231
      $qdbh->do ("replace into session (RCid, sessionid, timestamp, email) values (?, ?, now(), ?)", undef, $ORCUSER->{RCid}, $sessionid, $ORCUSER->{email});
232
      $qdbh->do ("delete from queue where queueid = ?", undef, $RCqueueID) if $RCqueueID;
232
      $qdbh->do ("delete from queue where queueid = ?", undef, $RCqueueID) if $RCqueueID;
233
  		return $authenticated->{cookie_string};
233
      return $authenticated->{cookie_string};
234
  	}
234
    }
235
    $qdbh->disconnect;
235
    $qdbh->disconnect;
236
	}
236
  }
237
	
237
  
238
	
238
  
Line 239... Line 239...
239
# If we get here, the user has failed authentication; throw up the log-in screen and die.
239
# If we get here, the user has failed authentication; throw up the log-in screen and die.
Line 240... Line 240...
240
 
240
 
241
	my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>$authenticated->{cookie_string},-expires=>"+30m");
241
  my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>$authenticated->{cookie_string},-expires=>"+30m");
242
  
242
  
243
  if ($authenticated->{ERRMSG}) {
243
  if ($authenticated->{ERRMSG}) {
244
  	$authenticated->{ERRMSG} = "<TR><TD colspan=2 align=center><font color=red><b>".$authenticated->{ERRMSG}."</b></font>&nbsp</TD></TR>";
244
    $authenticated->{ERRMSG} = "<TR><TD colspan=2 align=center><font color=red><b>".$authenticated->{ERRMSG}."</b></font>&nbsp</TD></TR>";
245
  	# Log the failed access attempt
245
    # Log the failed access attempt
246
  } else {
246
  } else {
Line 247... Line 247...
247
  	$authenticated->{ERRMSG} = "";
247
    $authenticated->{ERRMSG} = "";
248
  	# Since there was no ERRMSG, no need to log anything.
248
    # Since there was no ERRMSG, no need to log anything.
249
  }
249
  }
250
  
250
  
251
  if ($RCqueueID) {
251
  if ($RCqueueID) {
252
   	my $RCQUEUE_cookie = CGI::Cookie->new(-name=>'RCQUEUEID',-value=>"",-expires=>"+0m");
252
    my $RCQUEUE_cookie = CGI::Cookie->new(-name=>'RCQUEUEID',-value=>"",-expires=>"+0m");
253
 	  print header(-cookie=>[$RCAUTH_cookie,$RCQUEUE_cookie]);
253
    print header(-cookie=>[$RCAUTH_cookie,$RCQUEUE_cookie]);
254
  } else {
254
  } else {
255
 	  print header(-cookie=>$RCAUTH_cookie);
255
    print header(-cookie=>$RCAUTH_cookie);
256
 	}
256
  }
257
 	
257
  
258
	printRCHeader("Please Sign In");
258
  printRCHeader("Please Sign In");
259
	print<<authpage;
259
  print<<authpage;
260
	<form action="$ENV{REQUEST_URI}" method=POST name=Req id=Req>
260
  <form action="$ENV{REQUEST_URI}" method=POST name=Req id=Req>
261
	<input type=hidden name=RCqueueID value=$RCqueueID>
261
  <input type=hidden name=RCqueueID value=$RCqueueID>
262
		<TR><TD colspan=2 align=center><b><font size=+2>Please Sign In</font>
262
    <TR><TD colspan=2 align=center><b><font size=+2>Please Sign In</font>
263
		<TABLE>
263
    <TABLE>
Line 264... Line 264...
264
		</TD></TR>
264
    </TD></TR>
265
		<TR><TD colspan=2>&nbsp</TD></TR>
265
    <TR><TD colspan=2>&nbsp</TD></TR>
266
		$authenticated->{ERRMSG}
266
    $authenticated->{ERRMSG}
267
authpage
267
authpage
268
  
268
  
269
  if ($ENV{'QUERY_STRING'} eq "LOGOUT") {
269
  if ($ENV{'QUERY_STRING'} eq "LOGOUT") {
Line 270... Line 270...
270
    print "<TR><TD colspan=2>&nbsp</TD></TR>";
270
    print "<TR><TD colspan=2>&nbsp</TD></TR>";
271
    print "<TR><TD colspan=2><button onClick=\"location.href='';\">Log In</button></TD></TR>";
271
    print "<TR><TD colspan=2><button onClick=\"location.href='';\">Log In</button></TD></TR>";
272
    print "</TABLE></BODY></HTML>";
272
    print "</TABLE></BODY></HTML>";
273
    exit;
273
    exit;
274
  }
274
  }
275
  
275
  
276
  if ($authenticated->{authenticated} eq "inactive") {
276
  if ($authenticated->{authenticated} eq "inactive") {
Line 284... Line 284...
284
      <TR><TD colspan=2 align=center><A HREF='' onClick="location.href='?LOGOUT';">[Log Out]</A></TD></TR>
284
      <TR><TD colspan=2 align=center><A HREF='' onClick="location.href='?LOGOUT';">[Log Out]</A></TD></TR>
285
      </TABLE></FORM>
285
      </TABLE></FORM>
286
activationpage
286
activationpage
Line 287... Line 287...
287
    
287
    
288
  } else {
288
  } else {
289
 
289
    
290
    print<<authpage2;
290
    print<<authpage2;
291
  		<TR>
291
      <TR>
292
  			<TD align=right><B>Email Address:</TD><TD><INPUT type=text id=login name=userid></TD>
292
        <TD align=right><B>Email Address:</TD><TD><INPUT type=text id=login name=userid></TD>
293
  		</TR>
293
      </TR>
294
  		<TR>
294
      <TR>
295
  			<TD align=right><B>Password:</TD><TD><INPUT type=password name=pass></TD>
295
        <TD align=right><B>Password:</TD><TD><INPUT type=password name=pass></TD>
296
  		</TR>
296
      </TR>
297
  		<TR><TD></TD><TD><input type=hidden name=activate id=activate value=$FORM{'activate'}><INPUT type=submit name=login value=Submit></TD></TR>
297
      <TR><TD></TD><TD><input type=hidden name=activate id=activate value=$FORM{'activate'}><INPUT type=submit name=login value=Submit></TD></TR>
298
  		<TR><TD colspan=2 align=center>&nbsp;</TD></TR>
298
      <TR><TD colspan=2 align=center>&nbsp;</TD></TR>
299
  		<TR><TD colspan=2 align=center><A HREF="/schedule/view_user.pl?submit=New%20User">[register as a new user]</A></TD></TR>
299
      <TR><TD colspan=2 align=center><A HREF="/schedule/view_user.pl?submit=New%20User">[register as a new user]</A></TD></TR>
300
  		<TR><TD colspan=2 align=center><A HREF="/schedule/password_reset.pl">[reset your password]</A></TD></TR>
300
      <TR><TD colspan=2 align=center><A HREF="/schedule/password_reset.pl">[reset your password]</A></TD></TR>
301
  	</TABLE>
301
    </TABLE>
302
  	</FORM>
302
    </FORM>
303
 
303
    
304
  	<SCRIPT language="JavaScript">
304
    <SCRIPT language="JavaScript">
305
  	<!--
305
    <!--
306
  	document.getElementById("login").focus();
306
    document.getElementById("login").focus();
307
  	
307
    
308
  	function Login () {
308
    function Login () {
309
  		document.getElementById('Req').action = "$ENV{SCRIPT_NAME}";
309
      document.getElementById('Req').action = "$ENV{SCRIPT_NAME}";
310
  		document.getElementById('Req').submit.click();
310
      document.getElementById('Req').submit.click();
311
  		return true;
311
      return true;
312
  	}
312
    }
313
 
313
    
314
  	//-->
314
    //-->
315
  	</SCRIPT>
315
    </SCRIPT>
316
 
316
    
317
authpage2
317
authpage2
318
  }
318
  }
319
 
319
  
320
#foreach (keys %ENV) {
320
#foreach (keys %ENV) {
321
#	print "$_: $ENV{$_}<br>";
321
# print "$_: $ENV{$_}<br>";
322
#}
322
#}
323
#	&JScript;
323
# &JScript;
324
	exit;
324
  exit;
Line 325... Line 325...
325
}
325
}
326
 
326
 
Line 327... Line 327...
327
sub checkQueue {
327
sub checkQueue {
328
  my $max_users = shift;
328
  my $max_users = shift;
329
  
329
  
330
  return unless $max_users =~ /^\d+$/;
330
  return unless $max_users =~ /^\d+$/;
331
	
331
  
332
	return if $ENV{'QUERY_STRING'} eq "SKIPQUEUE";
332
  return if $ENV{'QUERY_STRING'} eq "SKIPQUEUE";
333
	
333
  
334
	my $RCAUTH = CGI::cookie('RCAUTH') // "";
334
  my $RCAUTH = CGI::cookie('RCAUTH') // "";
335
		
335
    
336
	my $qdbh = WebDB::connect ("session");
336
  my $qdbh = WebDB::connect ("session");
337
	
337
  
338
	if ($RCAUTH) {
338
  if ($RCAUTH) {
339
	  # If the user is already logged in, bypass the queue check.
339
    # If the user is already logged in, bypass the queue check.
340
   	my ($email, $RCPASS, $RCLVL) = split /&/, $RCAUTH;    
340
    my ($email, $RCPASS, $RCLVL) = split /&/, $RCAUTH;    
341
   	my ($active) = $qdbh->selectrow_array ("select count(*) from session where email = ? and timestampdiff(minute, timestamp, now()) < 30", undef, $email);
341
    my ($active) = $qdbh->selectrow_array ("select count(*) from session where email = ? and timestampdiff(minute, timestamp, now()) < 30", undef, $email);
342
    return if $active;
342
    return if $active;
343
	}
343
  }
344
	
344
  
345
 	my ($active_users) = $qdbh->selectrow_array ("select count(*) from session where timestampdiff(minute, timestamp, now()) < 30");
345
  my ($active_users) = $qdbh->selectrow_array ("select count(*) from session where timestampdiff(minute, timestamp, now()) < 30");
346
	my ($current_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where timestampdiff(minute, last_seen, now()) < 7 and (timestamp <> last_seen or timestampdiff(second, last_seen, now()) <= 60) limit 1");
346
  my ($current_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where timestampdiff(minute, last_seen, now()) < 7 and (timestamp <> last_seen or timestampdiff(second, last_seen, now()) <= 60) limit 1");
347
	my @queued_users;
347
  my @queued_users;
348
  push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where timestampdiff(minute, last_seen, now()) < 7 and (timestamp <> last_seen or timestampdiff(second, last_seen, now()) <= 60) order by timestamp") };
348
  push @queued_users, map { @{$_} } @{ $qdbh->selectall_arrayref ("select queueid from queue where timestampdiff(minute, last_seen, now()) < 7 and (timestamp <> last_seen or timestampdiff(second, last_seen, now()) <= 60) order by timestamp") };
349
 
349
  
350
 	my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
350
  my $RCqueueID = CGI::cookie('RCQUEUEID') // WebDB::trim CGI::param('RCqueueID') // "";
351
  $RCqueueID = "" unless inQueue ($RCqueueID, \@queued_users);
351
  $RCqueueID = "" unless inQueue ($RCqueueID, \@queued_users);
352
 	
352
  
353
 	my $your_wait = 0;
353
  my $your_wait = 0;
354
  if ($active_users >= $max_users) {
354
  if ($active_users >= $max_users) {
355
    # We are at max users. People have to wait.
355
    # We are at max users. People have to wait.
356
    if (!$RCqueueID) {
356
    if (!$RCqueueID) {
357
   	  use Digest::MD5 qw/md5_hex/;
357
      use Digest::MD5 qw/md5_hex/;
358
   	  $RCqueueID = time () ."-". md5_hex (rand ());
358
      $RCqueueID = time () ."-". md5_hex (rand ());
359
   	  push @queued_users, $RCqueueID;
359
      push @queued_users, $RCqueueID;
360
   	  $qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
360
      $qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
361
    } else {
361
    } else {
362
    	($your_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where queueid = ?", undef, $RCqueueID);
362
      ($your_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where queueid = ?", undef, $RCqueueID);
363
      $qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
363
      $qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
364
    }
364
    }
Line 365... Line 365...
365
 		
365
    
366
    printQueuePage ($RCqueueID, "(".inQueue ($RCqueueID, \@queued_users)." of ".scalar @queued_users." users)", $current_wait - $your_wait);
366
    printQueuePage ($RCqueueID, "(".inQueue ($RCqueueID, \@queued_users)." of ".scalar @queued_users." users)", $current_wait - $your_wait);
367
    exit;
367
    exit;
368
    
368
    
369
  } elsif (scalar @queued_users) {
369
  } elsif (scalar @queued_users) {
370
    # There are users in queue...
370
    # There are users in queue...
371
    if (!$RCqueueID) {
371
    if (!$RCqueueID) {
372
      # If you're not already in queue, get in line.
372
      # If you're not already in queue, get in line.
373
   	  use Digest::MD5 qw/md5_hex/;
373
      use Digest::MD5 qw/md5_hex/;
374
   	  $RCqueueID = time () ."-". md5_hex (rand ());
374
      $RCqueueID = time () ."-". md5_hex (rand ());
375
   	  push @queued_users, $RCqueueID;
375
      push @queued_users, $RCqueueID;
376
   	  $qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
376
      $qdbh->do ("replace into queue (queueid, timestamp, last_seen) values (?, now(), now())", undef, $RCqueueID);
377
    } else {
377
    } else {
378
    	($your_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where queueid = ?", undef, $RCqueueID);
378
      ($your_wait) = $qdbh->selectrow_array ("select timestampdiff(minute, timestamp, now()) from queue where queueid = ?", undef, $RCqueueID);
379
      $qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
379
      $qdbh->do ("update queue set last_seen = now() where queueid = ?", undef, $RCqueueID);
380
    }
380
    }
381
 	  
381
    
382
   	my $queue_position = inQueue ($RCqueueID, \@queued_users);
382
    my $queue_position = inQueue ($RCqueueID, \@queued_users);
383
    if ($queue_position > ($max_users - $active_users)) {
383
    if ($queue_position > ($max_users - $active_users)) {
384
      # If you're not at the head of the line, continue to wait.
384
      # If you're not at the head of the line, continue to wait.
385
      printQueuePage ($RCqueueID, "($queue_position of ".scalar @queued_users." users)", $current_wait - $your_wait);
385
      printQueuePage ($RCqueueID, "($queue_position of ".scalar @queued_users." users)", $current_wait - $your_wait);
386
      exit;
386
      exit;
387
    }
387
    }
Line 388... Line 388...
388
  }
388
  }
389
 
389
  
Line 399... Line 399...
399
  printRCHeader("is Busy");
399
  printRCHeader("is Busy");
400
  print<<busy;
400
  print<<busy;
401
    <P><b><font size=+2>Sorry, we are full right now.</font></P>
401
    <P><b><font size=+2>Sorry, we are full right now.</font></P>
402
    <P>You are in queue $queue_position.</P>
402
    <P>You are in queue $queue_position.</P>
403
    <div><ul>
403
    <div><ul>
404
	<li>Current wait time is about $wait_time minute(s).</li>
404
  <li>Current wait time is about $wait_time minute(s).</li>
405
    <li>This page will refresh every 30 seconds.</li>
405
    <li>This page will refresh every 30 seconds.</li>
406
    <li>When it's your turn to log in, you'll see the username/password boxes.</li>
406
    <li>When it's your turn to log in, you'll see the username/password boxes.</li>
407
    <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>
407
    <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>
408
    <li>Please LOG OUT of VORC when you are done so that others can log in.</li>
408
    <li>Please LOG OUT of VORC when you are done so that others can log in.</li>
409
    </ul></div>
409
    </ul></div>
410
    </BODY>
410
    </BODY>
411
    <SCRIPT language="JavaScript">
411
    <SCRIPT language="JavaScript">
412
   	<!--
412
    <!--
413
    // Refresh the page after a delay
413
    // Refresh the page after a delay
414
      setTimeout(function(){
414
      setTimeout(function(){
415
        location.replace(location.href);
415
        location.replace(location.href);
416
      }, 30000); // 30000 milliseconds = 30 seconds
416
      }, 30000); // 30000 milliseconds = 30 seconds
417
    //-->
417
    //-->
Line 420... Line 420...
420
busy
420
busy
421
  return;
421
  return;
422
}
422
}
Line 423... Line 423...
423
 
423
 
424
sub canView {
424
sub canView {
425
	my $A = shift // "";
425
  my $A = shift // "";
426
	my $B = shift // "";
426
  my $B = shift // "";
427
	# Is A a lead or higher of one of B's Depts? (or they're looking at themselves)
427
  # Is A a lead or higher of one of B's Depts? (or they're looking at themselves)
428
	# parameters should be a Hashref to the users' details
428
  # parameters should be a Hashref to the users' details
429
	
429
  
430
	return 1 if $A->{access} > 4 or $A->{RCid} == $B->{RCid}; # viewer and target are the same person or it's a SysAdmin.
430
  return 1 if $A->{access} > 4 or $A->{RCid} == $B->{RCid}; # viewer and target are the same person or it's a SysAdmin.
431
 
431
  
432
	my $ADept = ref $A->{department} eq "HASH" ? $A->{department} : convertDepartments($A->{department});
432
  my $ADept = ref $A->{department} eq "HASH" ? $A->{department} : convertDepartments($A->{department});
433
	my $BDept = ref $B->{department} eq "HASH" ? $B->{department} : convertDepartments($B->{department});
433
  my $BDept = ref $B->{department} eq "HASH" ? $B->{department} : convertDepartments($B->{department});
434
	
434
  
435
	foreach (keys %{$BDept}) {
435
  foreach (keys %{$BDept}) {
436
		if ($ADept->{$_} > 1) { # A is a Lead or higher of one of B's departments
436
    if ($ADept->{$_} > 1) { # A is a Lead or higher of one of B's departments
437
			return 1;
437
      return 1;
438
		}
438
    }
439
	}
439
  }
440
	
440
  
441
	if ($ADept->{MVP} >= RollerCon::LEAD and $B->{MVPid}) {
441
  if ($ADept->{MVP} >= RollerCon::LEAD and $B->{MVPid}) {
442
	  # MVP Volunteers can see user details for people with MVP Passes
442
    # MVP Volunteers can see user details for people with MVP Passes
443
	  return 1;
443
    return 1;
444
	}
444
  }
445
	
445
  
446
	return 0;
446
  return 0;
Line 447... Line 447...
447
}
447
}
448
 
448
 
449
sub getShiftDepartment {
449
sub getShiftDepartment {
Line 495... Line 495...
495
sub getDepartments {
495
sub getDepartments {
496
  my $RCid = shift // "";
496
  my $RCid = shift // "";
497
  # If we get an RCid, return the list of departments and levels for that user.
497
  # If we get an RCid, return the list of departments and levels for that user.
498
  #   Otherwise (no parameter), return the list of departments with their display names.
498
  #   Otherwise (no parameter), return the list of departments with their display names.
Line 499... Line 499...
499
  
499
  
500
	if ($RCid) {
500
  if ($RCid) {
501
  	my $sth = $dbh->prepare("select department from official where RCid = ?");
501
    my $sth = $dbh->prepare("select department from official where RCid = ?");
502
  	$sth->execute($RCid);
502
    $sth->execute($RCid);
503
  	my ($dlist) = $sth->fetchrow;
503
    my ($dlist) = $sth->fetchrow;
504
  	return convertDepartments ($dlist);
504
    return convertDepartments ($dlist);
505
	} else {
505
  } else {
506
  	my %HASH;
506
    my %HASH;
507
  	my $sth = $dbh->prepare("select TLA, name from department");
507
    my $sth = $dbh->prepare("select TLA, name from department");
508
  	$sth->execute();
508
    $sth->execute();
509
  	while (my ($tla, $name) = $sth->fetchrow) {
509
    while (my ($tla, $name) = $sth->fetchrow) {
510
  	  $HASH{$tla} = $name;
510
      $HASH{$tla} = $name;
511
    }
511
    }
512
    return \%HASH;
512
    return \%HASH;
Line 513... Line 513...
513
  }
513
  }
Line 514... Line 514...
514
  
514
  
515
}
515
}
516
 
516
 
517
sub convertDepartments {
517
sub convertDepartments {
518
  # For the department membership, converts the DB string back and forth to a hashref...
518
  # For the department membership, converts the DB string back and forth to a hashref...
519
  my $input = shift // "";
519
  my $input = shift // "";
520
  my $output;
520
  my $output;
521
 
521
  
522
  if (ref $input eq "HASH") {
522
  if (ref $input eq "HASH") {
523
    $output = join ":", map { $_."-".$input->{$_} } sort keys %{$input};
523
    $output = join ":", map { $_."-".$input->{$_} } sort keys %{$input};
524
  } else {
524
  } else {
525
  	foreach (split /:/, $input) {
525
    foreach (split /:/, $input) {
526
  	  my ($tla, $level) = split /-/;
526
      my ($tla, $level) = split /-/;
527
  	  $output->{$tla} = $level;
527
      $output->{$tla} = $level;
Line 528... Line 528...
528
    }
528
    }
Line 539... Line 539...
539
    return join " - ", map { convertTime ($_) } split / - /, $time;
539
    return join " - ", map { convertTime ($_) } split / - /, $time;
540
  }
540
  }
Line 541... Line 541...
541
  
541
  
542
  $time =~ s/^(\d{1,2}:\d{2}):\d{2}$/$1/;
542
  $time =~ s/^(\d{1,2}:\d{2}):\d{2}$/$1/;
543
  $time =~ s/^0//;
543
  $time =~ s/^0//;
544
 
544
  
545
  if ($ORCUSER->{timeformat} eq "24hr") {
545
  if ($ORCUSER->{timeformat} eq "24hr") {
546
    if ($time =~ /^\d{1,2}:\d{2}$/) { return $time; }    
546
    if ($time =~ /^\d{1,2}:\d{2}$/) { return $time; }    
547
  } else {
547
  } else {
548
    my ($hr, $min) = split /:/, $time;
548
    my ($hr, $min) = split /:/, $time;
Line 563... Line 563...
563
  my $output = shift // "";
563
  my $output = shift // "";
564
  my $year = 1900 + (localtime)[5];
564
  my $year = 1900 + (localtime)[5];
Line 565... Line 565...
565
    
565
    
566
  my @whereclause;
566
  my @whereclause;
567
  if ($filter eq "all") {
567
  if ($filter eq "all") {
568
  	push @whereclause, "year(date) >= year(now())";  	
568
    push @whereclause, "year(date) >= year(now())";   
569
  } else {
569
  } else {
570
  	push @whereclause, "date >= date(now())";
570
    push @whereclause, "date >= date(now())";
571
  }
571
  }
572
#  if ($RCid ne $ORCUSER->{RCid}) {
572
#  if ($RCid ne $ORCUSER->{RCid}) {
573
#    push @whereclause, "dept != 'PER'";
573
#    push @whereclause, "dept != 'PER'";
Line 574... Line 574...
574
#  }
574
#  }
575
  
575
  
576
  use DateTime;
576
  use DateTime;
577
  my $dt = DateTime->today (time_zone => 'America/Los_Angeles');
577
  my $dt = DateTime->today (time_zone => 'America/Los_Angeles');
578
  $dt =~ s/T00\:00\:00$//;
578
  $dt =~ s/T00\:00\:00$//;
Line 579... Line 579...
579
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
579
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
580
 
580
  
Line 581... Line 581...
581
  
581
  
Line 591... Line 591...
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};
596
	  my $cutoff = DateTime->new(
596
    my $cutoff = DateTime->new(
597
        year => $yyyy,
597
        year => $yyyy,
598
        month => $mm,
598
        month => $mm,
599
        day => $dd,
599
        day => $dd,
600
        hour => 5,
600
        hour => 5,
601
        minute => 0,
601
        minute => 0,
602
        second => 0,
602
        second => 0,
603
        time_zone => 'America/Los_Angeles'
603
        time_zone => 'America/Los_Angeles'
604
    );
604
    );
Line 605... Line 605...
605
    
605
    
606
    
606
    
607
  	if (!$s->{teams} or $s->{dept} eq "CLA") {
607
    if (!$s->{teams} or $s->{dept} eq "CLA") {
608
  	  # it's a time-based shift
608
      # it's a time-based shift
609
  	  if ($s->{dept} eq "PER") {
609
      if ($s->{dept} eq "PER") {
610
        if ($RCid eq $ORCUSER->{RCid}) {
610
        if ($RCid eq $ORCUSER->{RCid}) {
611
          # DROP
611
          # DROP
612
  	      $s->{buttons} = $h->button ({ onClick=>"event.stopPropagation(); if (confirm('Really? You want to delete this personal time?')==true) { location.href='personal_time.pl?choice=Delete&id=$s->{id}'; return false; }" }, "DEL")."&nbsp;".$h->button ({ onClick=>"event.stopPropagation(); location.href='personal_time.pl?choice=Update&id=$s->{id}'" }, "EDIT");
612
          $s->{buttons} = $h->button ({ onClick=>"event.stopPropagation(); if (confirm('Really? You want to delete this personal time?')==true) { location.href='personal_time.pl?choice=Delete&id=$s->{id}'; return false; }" }, "DEL")."&nbsp;".$h->button ({ onClick=>"event.stopPropagation(); location.href='personal_time.pl?choice=Update&id=$s->{id}'" }, "EDIT");
613
  	    } else {
613
        } else {
614
  	      $s->{location} = "";
614
          $s->{location} = "";
615
  	      $s->{role} = "";
615
          $s->{role} = "";
616
  	    }
616
        }
617
      } elsif (($RCid == $ORCUSER->{RCid} and $s->{signup} !~ /^selected/ and $now < $cutoff) or ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5)) {
617
      } elsif (($RCid == $ORCUSER->{RCid} and $s->{signup} !~ /^selected/ and $now < $cutoff) or ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5)) {
618
        # DROP
618
        # DROP
619
        my ($shiftORclass, $linkargs) = ("shift", "");
619
        my ($shiftORclass, $linkargs) = ("shift", "");
620
        if ($s->{dept} eq "CLA") {
620
        if ($s->{dept} eq "CLA") {
621
          $shiftORclass = "class";
621
          $shiftORclass = "class";
622
          $linkargs = "&role=$s->{role}";
622
          $linkargs = "&role=$s->{role}";
623
          $s->{role} = $s->{teams};
623
          $s->{role} = $s->{teams};
624
          $s->{teams} = "";
624
          $s->{teams} = "";
625
        }
625
        }
626
	   		$s->{buttons} = $h->button ({ onClick=>"if (confirm('Really? You want to drop this $shiftORclass?')==true) { window.open('make_shift_change.pl?change=del&RCid=$RCid&id=$s->{id}$linkargs','Confirm Class Change','resizable,height=260,width=370'); return false; }" }, "DROP");
626
        $s->{buttons} = $h->button ({ onClick=>"if (confirm('Really? You want to drop this $shiftORclass?')==true) { window.open('make_shift_change.pl?change=del&RCid=$RCid&id=$s->{id}$linkargs','Confirm Class Change','resizable,height=260,width=370'); return false; }" }, "DROP");
627
	   		if ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5) {
627
        if ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5) {
628
   		    # NO SHOW
628
          # NO SHOW
Line 629... Line 629...
629
 	  	    $s->{buttons} .= "&nbsp;".$h->button ({ onClick=>"if (confirm('Really? They were a no show?')==true) { window.open('make_shift_change.pl?noshow=true&change=del&RCid=$RCid&id=$s->{id}$linkargs','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "NO SHOW");
629
          $s->{buttons} .= "&nbsp;".$h->button ({ onClick=>"if (confirm('Really? They were a no show?')==true) { window.open('make_shift_change.pl?noshow=true&change=del&RCid=$RCid&id=$s->{id}$linkargs','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "NO SHOW");
630
 		    }
630
        }
631
        
631
        
632
  		}
632
      }
633
#  		$hours += $s->{volhours} unless $s->{dept} eq "PER" or $s->{dept} eq "CLA";
633
#     $hours += $s->{volhours} unless $s->{dept} eq "PER" or $s->{dept} eq "CLA";
634
 
634
      
635
    } elsif (($RCid == $ORCUSER->{RCid} and $s->{signup} !~ /^selected/ and $now < $cutoff) or ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5)) {
635
    } elsif (($RCid == $ORCUSER->{RCid} and $s->{signup} !~ /^selected/ and $now < $cutoff) or ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5)) {
636
      # it's a game shift
636
      # it's a game shift
637
      #DROP
637
      #DROP
638
  		$s->{buttons} = $h->button ({ onClick=>"if (confirm('Really? You want to drop this shift?')==true) { window.open('make_shift_change.pl?change=del&RCid=$RCid&id=$s->{id}&role=$s->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "DROP");
638
      $s->{buttons} = $h->button ({ onClick=>"if (confirm('Really? You want to drop this shift?')==true) { window.open('make_shift_change.pl?change=del&RCid=$RCid&id=$s->{id}&role=$s->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "DROP");
639
   		if ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5) {
639
      if ($ORCUSER->{department}->{$s->{dept}} >= 2 or $ORCUSER->{access} >= 5) {
640
 		    # NO SHOW
640
        # NO SHOW
641
        $s->{buttons} .= "&nbsp;".$h->button ({ onClick=>"if (confirm('Really? They were a no show?')==true) { window.open('make_shift_change.pl?noshow=true&change=del&RCid=$RCid&id=$s->{id}&role=$s->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "NO SHOW");
641
        $s->{buttons} .= "&nbsp;".$h->button ({ onClick=>"if (confirm('Really? They were a no show?')==true) { window.open('make_shift_change.pl?noshow=true&change=del&RCid=$RCid&id=$s->{id}&role=$s->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "NO SHOW");
642
      }
642
      }
643
#      $hours += $s->{volhours};
643
#      $hours += $s->{volhours};
644
  	}
644
    }
645
  	$s->{role} =~ s/\-\d+$//;
645
    $s->{role} =~ s/\-\d+$//;
646
  	
646
    
647
#  	push @shifts, $h->li ({ class=> $s->{date} eq $dt ? "nowrap highlighted" : "nowrap shaded" }, join '&nbsp;&nbsp;', $s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams}, $s->{buttons});
647
#   push @shifts, $h->li ({ class=> $s->{date} eq $dt ? "nowrap highlighted" : "nowrap shaded" }, join '&nbsp;&nbsp;', $s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams}, $s->{buttons});
648
#  	push @shifts, $h->li ({ class=> $s->{date} eq $dt ? "highlighted" : "shaded" }, join '&nbsp;&nbsp;', $s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams}, $s->{buttons});
648
#   push @shifts, $h->li ({ class=> $s->{date} eq $dt ? "highlighted" : "shaded" }, join '&nbsp;&nbsp;', $s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams}, $s->{buttons});
649
    $s->{time} = convertTime $s->{time};
649
    $s->{time} = convertTime $s->{time};
650
    if ($s->{dept} eq "PER") {
650
    if ($s->{dept} eq "PER") {
651
  	  push @shifts, $h->li ({ onClick => "location.replace('personal_time.pl?id=$s->{id}');", class=> $s->{date} eq $dt ? "highlighted" : "shaded" }, $h->div ({ class=>"lisp0" }, [ $h->div ({ class=>"liLeft" }, join '&nbsp;&nbsp;', ($s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, $s->{dept} eq "CLA" ? "MVP Class:" : getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams})), $h->div ({ class=>"liRight" }, $s->{buttons}) ]));
651
      push @shifts, $h->li ({ onClick => "location.replace('personal_time.pl?id=$s->{id}');", class=> $s->{date} eq $dt ? "highlighted" : "shaded" }, $h->div ({ class=>"lisp0" }, [ $h->div ({ class=>"liLeft" }, join '&nbsp;&nbsp;', ($s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, $s->{dept} eq "CLA" ? "MVP Class:" : getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams})), $h->div ({ class=>"liRight" }, $s->{buttons}) ]));
652
    } else {
652
    } else {
653
  	  push @shifts, $h->li ({ class=> $s->{date} eq $dt ? "highlighted" : "shaded" }, $h->div ({ class=>"lisp0" }, [ $h->div ({ class=>"liLeft" }, join '&nbsp;&nbsp;', ($s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, $s->{dept} eq "CLA" ? "MVP Class:" : getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams})), $h->div ({ class=>"liRight" }, $s->{buttons}) ]));
653
      push @shifts, $h->li ({ class=> $s->{date} eq $dt ? "highlighted" : "shaded" }, $h->div ({ class=>"lisp0" }, [ $h->div ({ class=>"liLeft" }, join '&nbsp;&nbsp;', ($s->{date}, $s->{dayofweek}, $s->{time}, $s->{location}, $s->{dept} eq "CLA" ? "MVP Class:" : getDepartments()->{$s->{dept}}, $s->{role}, $s->{teams})), $h->div ({ class=>"liRight" }, $s->{buttons}) ]));
654
  	}
654
    }
655
    $hours += $s->{volhours} unless $s->{dept} eq "PER" or $s->{dept} eq "CLA";
655
    $hours += $s->{volhours} unless $s->{dept} eq "PER" or $s->{dept} eq "CLA";
656
  }
656
  }
657
 
657
  
Line 658... Line 658...
658
  if ($output eq "hours") {
658
  if ($output eq "hours") {
Line 671... Line 671...
671
  ($derbyname) = $dbh->selectrow_array ("select RCid from official where derby_name = ?", undef, $derbyname);
671
  ($derbyname) = $dbh->selectrow_array ("select RCid from official where derby_name = ?", undef, $derbyname);
672
  return $derbyname;
672
  return $derbyname;
673
}
673
}
Line 674... Line 674...
674
 
674
 
675
sub getSetting {
675
sub getSetting {
676
	my $k = shift;
676
  my $k = shift;
677
	
677
  
678
	my ($value) = $dbh->selectrow_array ("select setting.value from setting where setting.key = ?", undef, $k);
678
  my ($value) = $dbh->selectrow_array ("select setting.value from setting where setting.key = ?", undef, $k);
679
  return defined $value ? $value : undef;
679
  return defined $value ? $value : undef;
Line 680... Line 680...
680
}
680
}
681
 
681
 
682
sub getUser {
682
sub getUser {
683
	my $ID = shift;
683
  my $ID = shift;
684
	
684
  
685
	my $sth;
685
  my $sth;
686
	if ($ID =~ /^\d+$/) {
686
  if ($ID =~ /^\d+$/) {
687
	  $sth = $dbh->prepare("select * from v_official where RCid = ?");
687
    $sth = $dbh->prepare("select * from v_official where RCid = ?");
688
	} else {
688
  } else {
689
	  $sth = $dbh->prepare("select * from v_official where email = ?");
689
    $sth = $dbh->prepare("select * from v_official where email = ?");
690
  }
690
  }
691
	$sth->execute($ID);
691
  $sth->execute($ID);
692
	
692
  
693
	my $user = $sth->fetchrow_hashref;
693
  my $user = $sth->fetchrow_hashref;
694
	map { $user->{$_} = "" unless $user->{$_} } keys %{$user};
694
  map { $user->{$_} = "" unless $user->{$_} } keys %{$user};
Line 695... Line 695...
695
	return $user->{RCid} ? $user : "";
695
  return $user->{RCid} ? $user : "";
696
}
696
}
697
 
697
 
698
sub getUserEmail {
698
sub getUserEmail {
699
	my $RCid = shift;
699
  my $RCid = shift;
700
	my $sth = $dbh->prepare("select email from official where RCid = ?");
700
  my $sth = $dbh->prepare("select email from official where RCid = ?");
701
	$sth->execute($RCid);
701
  $sth->execute($RCid);
Line 702... Line 702...
702
	my ($email) = $sth->fetchrow_array();
702
  my ($email) = $sth->fetchrow_array();
703
	return $email;
703
  return $email;
704
}
704
}
705
 
705
 
706
sub getUserDerbyName {
706
sub getUserDerbyName {
707
	my $RCid = shift;
707
  my $RCid = shift;
708
	my $sth = $dbh->prepare("select derby_name from official where RCid = ?");
708
  my $sth = $dbh->prepare("select derby_name from official where RCid = ?");
Line 709... Line 709...
709
	$sth->execute($RCid);
709
  $sth->execute($RCid);
710
	my ($dname) = $sth->fetchrow_array();
710
  my ($dname) = $sth->fetchrow_array();
711
	return $dname;
711
  return $dname;
712
}
712
}
713
 
713
 
714
sub getYears {
714
sub getYears {
715
	my $sth = $dbh->prepare("select distinct year from (select distinct year(date) as year from shift union select distinct year(date) as year from game union select distinct year(date) as year from class union select year(now()) as year) years order by year");
715
  my $sth = $dbh->prepare("select distinct year from (select distinct year(date) as year from shift union select distinct year(date) as year from game union select distinct year(date) as year from class union select year(now()) as year) years order by year");
716
#	my $sth = $dbh->prepare("select distinct year(date) from v_shift_admin_view");
716
# my $sth = $dbh->prepare("select distinct year(date) from v_shift_admin_view");
Line 717... Line 717...
717
	$sth->execute();
717
  $sth->execute();
718
	my @years;
718
  my @years;
719
	while (my ($y) =$sth->fetchrow_array()) { push @years, $y; }
719
  while (my ($y) =$sth->fetchrow_array()) { push @years, $y; }
720
	return \@years;
720
  return \@years;
721
}
721
}
Line 722... Line 722...
722
 
722
 
723
sub printRCHeader {
723
sub printRCHeader {
724
	my $PAGE_TITLE = shift;
724
  my $PAGE_TITLE = shift;
725
#	use CGI qw/start_html/;
725
# use CGI qw/start_html/;
726
	use HTML::Tiny;
726
  use HTML::Tiny;
727
  my $h = HTML::Tiny->new( mode => 'html' );
727
  my $h = HTML::Tiny->new( mode => 'html' );
728
  
728
  
Line 729... Line 729...
729
#  my $logout = $h->a ({ href=>"index.pl", onClick=>"document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';return true;" }, "[Log Out]");
729
#  my $logout = $h->a ({ href=>"index.pl", onClick=>"document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';return true;" }, "[Log Out]");
Line -... Line 730...
-
 
730
  my $referrer = param ("referrer") ? param ("referrer") : $ENV{HTTP_REFERER};
-
 
731
  my $logout = (!$referrer or $referrer eq url) ? "" : $h->button ({ onClick=>"window.location.href='$referrer';" }, "Back")."&nbsp;";
-
 
732
  $logout .= url =~ /\/(index.pl)?$/ ? "" : $h->button ({ onClick=>"window.location.href='/schedule/';" }, "Home")."&nbsp;";
-
 
733
#  $logout .= $h->button ({ onClick=>"document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/'; location.href='/';" }, "Log Out");
-
 
734
  $logout .= $h->button ({ onClick=>"location.href='?LOGOUT';" }, "Log Out");
-
 
735
  my $loggedinas = $ORCUSER ? "Currently logged in as: ".$h->a ({ href=>"/schedule/view_user.pl?submit=View&RCid=$ORCUSER->{RCid}" }, $ORCUSER->{derby_name}).$h->br.$logout : "";
-
 
736
  
-
 
737
#  print start_html (-title=>"vORC - $PAGE_TITLE", -style => {'src' => "/style.css"} );
-
 
738
  
-
 
739
  my $ANALYTICS = <<MATOMO;
-
 
740
  var _mtm = window._mtm = window._mtm || [];
-
 
741
  _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
-
 
742
  (function() {
-
 
743
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
-
 
744
    g.async=true; g.src='https://analytics.whump.org/js/container_to4NCtvM.js'; s.parentNode.insertBefore(g,s);
-
 
745
  })();
-
 
746
MATOMO
-
 
747
  
730
  my $referrer = param ("referrer") ? param ("referrer") : $ENV{HTTP_REFERER};
748
  print $h->open ("html");
731
  my $logout = (!$referrer or $referrer eq url) ? "" : $h->button ({ onClick=>"window.location.href='$referrer';" }, "Back")."&nbsp;";
749
  print $h->head ([$h->title ("vORC - $PAGE_TITLE"),
732
  $logout .= url =~ /\/(index.pl)?$/ ? "" : $h->button ({ onClick=>"window.location.href='/schedule/';" }, "Home")."&nbsp;";
750
                   $h->link  ({ rel  => "stylesheet",
733
#  $logout .= $h->button ({ onClick=>"document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/'; location.href='/';" }, "Log Out");
751
                                type => "text/css",
734
  $logout .= $h->button ({ onClick=>"location.href='?LOGOUT';" }, "Log Out");
752
                                href => "/style.css" }),
735
	my $loggedinas = $ORCUSER ? "Currently logged in as: ".$h->a ({ href=>"/schedule/view_user.pl?submit=View&RCid=$ORCUSER->{RCid}" }, $ORCUSER->{derby_name}).$h->br.$logout : "";
753
                   $h->script ($ANALYTICS)
736
  
754
                  ]);
737
  print start_html (-title=>"vORC - $PAGE_TITLE", -style => {'src' => "/style.css"} );
755
  print $h->open ("body");
738
  
756
#  print $h->img ({referrerpolicy=>"no-referrer-when-downgrade", src=>"https://analytics.whump.org/matomo.php?idsite=2&amp;rec=1", style=>"border:0", alt=>""});
739
#<html><head><title>Officials' RollerCon Schedule Manager - $PAGE_TITLE</title>
757
#<html><head><title>Officials' RollerCon Schedule Manager - $PAGE_TITLE</title>
740
#<link rel="stylesheet" type="text/css" href="/style.css">
758
#<link rel="stylesheet" type="text/css" href="/style.css">
741
#</head>
759
#</head>
742
#<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">
760
#<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">
743
	print $h->div ({ class=>"sp0" }, [ $h->div ({ class=>"spLeft" },  $h->a ({ href=>"/schedule/" }, $h->img ({ src=>"/logo.jpg", width=>"75", height=>"75" }))),
761
  print $h->div ({ class=>"sp0" }, [ $h->div ({ class=>"spLeft" },  $h->a ({ href=>"/schedule/" }, $h->img ({ src=>"/logo.jpg", width=>"75", height=>"75" }))),
744
	                                   $h->div ({ class=>"spRight" }, [ $h->h1 (["vORC $PAGE_TITLE", $h->br]),
762
                                     $h->div ({ class=>"spRight" }, [ $h->h1 (["vORC $PAGE_TITLE", $h->br]),
745
	                                   $loggedinas, 
763
                                     $loggedinas, 
Line 746... Line 764...
746
	                                   ])
764
                                     ])
747
	                                 ]);
765
                                   ]);
Line 748... Line 766...
748
#print<<rcheader;
766
#print<<rcheader;
749
#  <TABLE>
767
#  <TABLE>
750
#	<TR class="nostripe">
768
# <TR class="nostripe">
751
#		<TD align=right><img SRC="/logo.jpg"></TD>
769
#   <TD align=right><img SRC="/logo.jpg"></TD>
752
#		<TD align=center valign=middle><b><font size=+3>Officials' RollerCon<br>Schedule Manager<br>$PAGE_TITLE</FONT></b>
770
#   <TD align=center valign=middle><b><font size=+3>Officials' RollerCon<br>Schedule Manager<br>$PAGE_TITLE</FONT></b>
753
#	<p align=right><font size=-2>$loggedinas <a href='index.pl' onClick="document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';return true;">[Log Out]</a></font></TD>
771
# <p align=right><font size=-2>$loggedinas <a href='index.pl' onClick="document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';return true;">[Log Out]</a></font></TD>
754
#	</TR>
772
# </TR>
755
 
773
 
756
#rcheader
774
#rcheader
757
}
775
}
758
 
776
 
759
sub changeShift {
777
sub changeShift {
760
	my ($change, $shift_id, $role, $user_id) = @_;
778
  my ($change, $shift_id, $role, $user_id) = @_;
761
  if ($shift_id =~ /(am|pm)/) {
779
  if ($shift_id =~ /(am|pm)/) {
762
    my ($td, $st, $tl) = split /\|/, $shift_id;
780
    my ($td, $st, $tl) = split /\|/, $shift_id;
763
    my ($hr, $min, $ampm) = split /:|\s/, $st;
781
    my ($hr, $min, $ampm) = split /:|\s/, $st;
764
    if ($ampm eq "pm") { $hr += 12; }
782
    if ($ampm eq "pm") { $hr += 12; }
765
    elsif ($ampm eq "am" and $hr == 12) { $hr = "00" }
783
    elsif ($ampm eq "am" and $hr == 12) { $hr = "00" }
766
 
784
    
767
    $st = $hr.":".$min;
785
    $st = $hr.":".$min;
768
    $shift_id = join "|", ($td, $st, $tl);
786
    $shift_id = join "|", ($td, $st, $tl);
769
  }
787
  }
-
 
788
#warn join " - ", $change, $shift_id, $role, $user_id;
770
#warn join " - ", $change, $shift_id, $role, $user_id;
789
  my $leadership_change = 0;
-
 
790
# my $department = getShiftDepartment ($role ? $shift_id."-".$role : $shift_id);
771
	my $leadership_change = 0;
791
  my $department;
-
 
792
  if ($shift_id =~ /^\d+$/) {
-
 
793
    $department = getShiftDepartment ($role ? $shift_id."-".$role : $shift_id);
772
#	my $department = getShiftDepartment ($role ? $shift_id."-".$role : $shift_id);
794
  } else {
773
	my $department;
795
    $department = "CLA";
774
	if ($shift_id =~ /^\d+$/) {
796
    if ($change eq "del") {
775
		$department = getShiftDepartment ($role ? $shift_id."-".$role : $shift_id);
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);
776
	} else {
798
    } else {
777
		$department = "CLA";
799
      if ($change eq "override") {
778
		if ($change eq "del") {
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";
779
		  ($shift_id, $role) = $dbh->selectrow_array ("select id, role from v_class_signup where date = ? and start_time = ? and location = ?", undef, split /\|/, $shift_id);
801
      } else {
780
		} 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);
781
		  ($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);
803
      }
782
		}
804
    }
783
    $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 
784
	}
806
  }
785
#	my $game_based = $role ? "game" : "shift";
807
# my $game_based = $role ? "game" : "shift";
786
	my $game_based = $role =~ /^CLA-/ ? "class" : $role ? "game" : "shift";
808
  my $game_based = $role =~ /^CLA-/ ? "class" : $role ? "game" : "shift";
787
	my $sth;
809
  my $sth;
788
	
810
  
789
	if ($change eq "add" or $change eq "override") {
811
  if ($change eq "add" or $change eq "override") {
790
  	my $taken;
812
    my $taken;
791
		if ($department eq "CLA") {
813
    if ($department eq "CLA") {
792
  	  ($taken) = $shift_id ? 0 : 1;
814
      ($taken) = $shift_id ? 0 : 1;
793
  	} elsif ($game_based eq "game") {
815
    } elsif ($game_based eq "game") {
794
  	  ($taken) = $dbh->selectrow_array ("select count(*) from assignment where Gid = ? and role = ?", undef, $shift_id, $role);
816
      ($taken) = $dbh->selectrow_array ("select count(*) from assignment where Gid = ? and role = ?", undef, $shift_id, $role);
795
  	} else {
817
    } else {
796
  	  ($taken) = $dbh->selectrow_array ('select count(*) from shift where id = ? and (isnull(assignee_id) = 0 or assignee_id <> "")', undef, $shift_id);
818
      ($taken) = $dbh->selectrow_array ('select count(*) from shift where id = ? and (isnull(assignee_id) = 0 or assignee_id <> "")', undef, $shift_id);
797
  	}
819
    }
798
  	if ($taken) {
820
    if ($taken) {
799
  	    return ($department eq "CLA") ? "<br>Denied! This class is already full ($shift_id).<br>\n" : "<br>Denied! This shift is already taken ($shift_id).<br>\n";
821
      return ($department eq "CLA") ? "<br>Denied! This class is already full ($shift_id).<br>\n" : "<br>Denied! This shift is already taken ($shift_id).<br>\n";
800
  	}
822
    }
801
  }
823
  }
802
	
824
  
803
	if (lc ($user_id) ne lc ($ORCUSER->{RCid})) { # they're changing someone else's schedule...
825
  if (lc ($user_id) ne lc ($ORCUSER->{RCid})) { # they're changing someone else's schedule...
804
	  if (($department eq "CLA" and $ORCUSER->{department}->{MVP} >= 2) or $ORCUSER->{department}->{$department} >= 2 or $ORCUSER->{access} >= 5 or $ORCUSER->{department}->{VCI} >= 2) {
826
    if (($department eq "CLA" and $ORCUSER->{department}->{MVP} >= 2) or $ORCUSER->{department}->{$department} >= 2 or $ORCUSER->{access} >= 5 or $ORCUSER->{department}->{VCI} >= 2) {
805
	    # the user making the change is either a lead in the dept, a sysadmin, or a VCI lead
827
      # the user making the change is either a lead in the dept, a sysadmin, or a VCI lead
Line 806... Line 828...
806
	    logit ($ORCUSER->{RCid}, "$ORCUSER->{derby_name} changed someone else's schedule. ($change, $shift_id, $role, $user_id)");
828
      logit ($ORCUSER->{RCid}, "$ORCUSER->{derby_name} changed someone else's schedule. ($change, $shift_id, $role, $user_id)");
807
	    logit ($user_id, "Schedule was changed by $ORCUSER->{derby_name}. ($change, $shift_id, $role, $user_id)");
829
      logit ($user_id, "Schedule was changed by $ORCUSER->{derby_name}. ($change, $shift_id, $role, $user_id)");
808
	    $leadership_change = 1;
830
      $leadership_change = 1;
809
	  } else {
831
    } else {
Line 823... Line 845...
823
    }
845
    }
824
  }
846
  }
Line 825... Line 847...
825
  
847
  
826
  my $conflict = findConflict ($user_id, $shift_id, $game_based);
848
  my $conflict = findConflict ($user_id, $shift_id, $game_based);
827
  if ($change eq "add" and $conflict) {
849
  if ($change eq "add" and $conflict) {
828
		return "<br>Denied! There is a conflict ($conflict) with that shift's time!<br>\n";
850
    return "<br>Denied! There is a conflict ($conflict) with that shift's time!<br>\n";
Line 829... Line 851...
829
  }
851
  }
830
  
852
  
831
  my $game_type;
853
  my $game_type;
832
  if ($department ne "CLA") {
854
  if ($department ne "CLA") {
833
   	($game_type) = $dbh->selectrow_array ("select type from ".$game_based." where id = ?", undef, $shift_id);
855
    ($game_type) = $dbh->selectrow_array ("select type from ".$game_based." where id = ?", undef, $shift_id);
834
   	
856
    
835
   	if ($game_type =~ /^selected/ and !$leadership_change) {
857
    if ($game_type =~ /^selected/ and !$leadership_change) {
836
   	  return "<br>Denied! Only leadership can make changes to 'selected staffing' shifts!<br>\n" unless $department eq "CMP";
858
      return "<br>Denied! Only leadership can make changes to 'selected staffing' shifts!<br>\n" unless $department eq "CMP";
837
   	}
859
    }
838
   	
860
    
839
   	if ($change eq "add" and $game_type eq "lead" and convertDepartments(getUser($user_id)->{department})->{$department} < 2 and $ORCUSER->{access} < 3) {
861
    if ($change eq "add" and $game_type eq "lead" and convertDepartments(getUser($user_id)->{department})->{$department} < 2 and $ORCUSER->{access} < 3) {
840
   	  return "<br>Denied! Shift reserved for leadership staff!<br>\n";
862
      return "<br>Denied! Shift reserved for leadership staff!<br>\n";
841
   	}
863
    }
842
  } else {
864
  } else {
Line 843... Line 865...
843
    $game_type = "class";
865
    $game_type = "class";
844
  }
866
  }
845
  
867
  
846
 
868
  
847
# 	my $MAXSHIFTS = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY");
869
#   my $MAXSHIFTS = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY");
848
	my $MAXSHIFTS = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY_".$department);
870
  my $MAXSHIFTS = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY_".$department);
849
	$MAXSHIFTS = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY") unless defined $MAXSHIFTS;
871
  $MAXSHIFTS = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY") unless defined $MAXSHIFTS;
850
	if ($game_type eq "lead" and $department eq "OFF") { $MAXSHIFTS = 99; }
872
  if ($game_type eq "lead" and $department eq "OFF") { $MAXSHIFTS = 99; }
851
 
873
  
852
  my $daily_count;
874
  my $daily_count;
853
  if ($department eq "CLA") {
875
  if ($department eq "CLA") {
854
    # MVP Class Sign-up
876
    # MVP Class Sign-up
855
    $MAXSHIFTS = getSetting ("MAX_CLASS_SIGNUP");
877
    $MAXSHIFTS = getSetting ("MAX_CLASS_SIGNUP");
856
	  ($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 where RCid = ? and year(date) = year(now())", undef, $user_id);
857
#	  ($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);
858
   	if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {	  
880
    if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {    
859
	    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";
860
	  }
882
    }
861
  } else {
883
  } else {
862
   	$daily_count = signUpCount ('get', $user_id, $department);
884
    $daily_count = signUpCount ('get', $user_id, $department);
863
   	if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {
885
    if ($change eq "add" and $daily_count >= $MAXSHIFTS and !$leadership_change) {
864
   		return "<br>Denied! You may only sign up for $MAXSHIFTS $game_type shifts in one day!<br>\n";
886
      return "<br>Denied! You may only sign up for $MAXSHIFTS $game_type shifts in one day!<br>\n";
865
   	}
887
    }
866
   	if ($change eq "add" and $game_based eq "game" and ($department eq "OFF" or $department eq "ANN") and $game_type eq "full length" and !$leadership_change) {
888
    if ($change eq "add" and $game_based eq "game" and ($department eq "OFF" or $department eq "ANN") and $game_type eq "full length" and !$leadership_change) {
867
    	my $dept_table = $department eq 'OFF' ? "v_shift_officiating" : "v_shift_announcer";
889
      my $dept_table = $department eq 'OFF' ? "v_shift_officiating" : "v_shift_announcer";
868
    	my ($full_length_count) = $dbh->selectrow_array ("select count(*) from $dept_table where RCid = ? and gtype = 'full length' and year(date) = year(now())", undef, $user_id);
890
      my ($full_length_count) = $dbh->selectrow_array ("select count(*) from $dept_table where RCid = ? and gtype = 'full length' and year(date) = year(now())", undef, $user_id);
869
  		my $full_length_max = getSetting("MAX_FULL_LENGTH_SIGNUP_".$department);
891
      my $full_length_max = getSetting("MAX_FULL_LENGTH_SIGNUP_".$department);
870
  		if ($full_length_count >= $full_length_max) {
892
      if ($full_length_count >= $full_length_max) {
871
  		  my $errormsg = "<br>Denied! You may only sign up to ".($department eq 'OFF' ? "officiate" : "announce")." $full_length_max $game_type game(s) (total)!<br>\n";
893
        my $errormsg = "<br>Denied! You may only sign up to ".($department eq 'OFF' ? "officiate" : "announce")." $full_length_max $game_type game(s) (total)!<br>\n";
872
  			return $errormsg;
894
        return $errormsg;
Line 873... Line 895...
873
  		}  
895
      }  
874
    }
896
    }
875
  }
897
  }
876
  
898
  
877
 	my @DBARGS;
899
  my @DBARGS;
878
  if ($game_based eq "game" or $game_based eq "class") {
900
  if ($game_based eq "game" or $game_based eq "class") {
879
  	if ($change eq "add" or $change eq "override") {
901
    if ($change eq "add" or $change eq "override") {
880
  		$sth = $dbh->prepare("insert into assignment (Gid, role, RCid) values (?, ?, ?)");
902
      $sth = $dbh->prepare("insert into assignment (Gid, role, RCid) values (?, ?, ?)");
881
  	} elsif ($change eq "del") {
903
    } elsif ($change eq "del") {
882
  		$sth = $dbh->prepare("delete from assignment where Gid = ? and role = ? and RCid= ?");
904
      $sth = $dbh->prepare("delete from assignment where Gid = ? and role = ? and RCid= ?");
883
  	}
905
    }
884
  	@DBARGS = ($shift_id, $role, $user_id);
906
    @DBARGS = ($shift_id, $role, $user_id);
885
  } else {
907
  } else {
886
  	if ($change eq "add" or $change eq "override") {
908
    if ($change eq "add" or $change eq "override") {
887
  		$sth = $dbh->prepare("update shift set assignee_id = ? where id = ? and isnull(assignee_id) = 1");
909
      $sth = $dbh->prepare("update shift set assignee_id = ? where id = ? and isnull(assignee_id) = 1");
888
  		@DBARGS = ($user_id, $shift_id);
910
      @DBARGS = ($user_id, $shift_id);
889
  	} elsif ($change eq "del") {
911
    } elsif ($change eq "del") {
Line 890... Line 912...
890
  		$sth = $dbh->prepare("update shift set assignee_id = null where id = ?");
912
      $sth = $dbh->prepare("update shift set assignee_id = null where id = ?");
891
  		@DBARGS = ($shift_id);
913
      @DBARGS = ($shift_id);
892
  	}
914
    }
893
  }
915
  }
Line 894... Line 916...
894
  
916
  
895
  my $wb_act_code;
917
  my $wb_act_code;
896
  if ($change eq "del" and $department eq "CLA") {
918
  if ($change eq "del" and $department eq "CLA") {
897
    ($wb_act_code) = $dbh->selectrow_array ("select wb_ticket_act from assignment where Gid = ? and RCid = ? and role like ?", undef, $DBARGS[0], $DBARGS[2], 'CLA-%');
919
    ($wb_act_code) = $dbh->selectrow_array ("select wb_ticket_act from assignment where Gid = ? and RCid = ? and role like ?", undef, $DBARGS[0], $DBARGS[2], 'CLA-%');
898
  }
920
  }
899
  
921
  
900
  print "<br>attempting to make DB changes...<br>";
922
  print "<br>attempting to make DB changes...<br>";
901
  if ($sth->execute (@DBARGS)) {
923
  if ($sth->execute (@DBARGS)) {
902
  	$daily_count = signUpCount ($change, $user_id, $department) unless $leadership_change;
924
    $daily_count = signUpCount ($change, $user_id, $department) unless $leadership_change;
903
  	logit ($user_id, "Shift ".ucfirst($change).": $shift_id -> $role");
925
    logit ($user_id, "Shift ".ucfirst($change).": $shift_id -> $role");
904
  	logit ($ORCUSER->{RCid}, "OVERRIDE: Shift ".ucfirst($change).": $shift_id -> $role") if $change eq "override";
926
    logit ($ORCUSER->{RCid}, "OVERRIDE: Shift ".ucfirst($change).": $shift_id -> $role") if $change eq "override";
905
  	if ($department eq "CLA") {
927
    if ($department eq "CLA") {
906
  	  print "Success!...<br>You've signed up for $daily_count class(es) (you're currently allowed to sign up for $MAXSHIFTS).<br>\n";
928
      print "Success!...<br>You've signed up for $daily_count class(es) (you're currently allowed to sign up for $MAXSHIFTS).<br>\n";
907
 	    updateWRSTBND ($change, $wb_act_code, $DBARGS[0], $DBARGS[2]);
929
      updateWRSTBND ($change, $wb_act_code, $DBARGS[0], $DBARGS[2]);
908
  	} else {
930
    } else {
909
  	  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";
931
      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";
910
  	}
932
    }
911
  	return;
933
    return;
912
  } else {
934
  } else {
913
  	if ($department eq "CLA") {
935
    if ($department eq "CLA") {
Line 923... Line 945...
923
  use REST::Client;
945
  use REST::Client;
924
  use JSON;
946
  use JSON;
925
  my $headers = { Authorization => '601037851507c624' };
947
  my $headers = { Authorization => '601037851507c624' };
926
  my $client = REST::Client->new();
948
  my $client = REST::Client->new();
927
  $client->setHost('https://core.wrstbnd.io');
949
  $client->setHost('https://core.wrstbnd.io');
928
 
950
  
929
  my ($accountid) = $dbh->selectrow_array ("select wrstbnd_accountid from RCid_ticket_link left join ticket on MVPid = id where RCid = ? and year = year(now())", undef, $user_id);
951
  my ($accountid) = $dbh->selectrow_array ("select wrstbnd_accountid from RCid_ticket_link left join ticket on MVPid = id where RCid = ? and year = year(now())", undef, $user_id);
Line 930... Line 952...
930
  
952
  
931
  if ($change eq "add" or $change eq "override") {
953
  if ($change eq "add" or $change eq "override") {
932
    my ($classid) = $dbh->selectrow_array ("select wrstbnd_id from class where id = ?", undef, $shift_id);
954
    my ($classid) = $dbh->selectrow_array ("select wrstbnd_id from class where id = ?", undef, $shift_id);
933
 
955
    
934
    my $body = {
956
    my $body = {
935
      "eventId"      => "event_Y5567UWwS5",
957
      "eventId"      => "event_Y5567UWwS5",
936
      "activeStatus" => "active",
958
      "activeStatus" => "active",
937
      "ticketTypeId" => $classid
959
      "ticketTypeId" => $classid
938
    };
960
    };
939
    my $json_body = encode_json $body;
961
    my $json_body = encode_json $body;
940
 
962
    
941
    $client->POST(
963
    $client->POST(
942
      '/rest/core/v1/ticket', 
964
      '/rest/core/v1/ticket', 
943
      $json_body,
965
      $json_body,
944
      $headers
966
      $headers
945
    );
967
    );
946
    my $response = from_json($client->responseContent());
968
    my $response = from_json($client->responseContent());
947
 
969
    
Line 948... Line 970...
948
    my $activationCode = $response->{activationCode};
970
    my $activationCode = $response->{activationCode};
949
    
971
    
950
#    my @add_response = `/bin/curl --location --request POST 'https://core.wrstbnd.io/rest/core/v1/assign' --header 'Authorization: 601037851507c624' --form accountid=$accountid --form ticketactcode=$activationCode --output /dev/null --silent --write-out '%{http_code}\n'`;
972
#    my @add_response = `/bin/curl --location --request POST 'https://core.wrstbnd.io/rest/core/v1/assign' --header 'Authorization: 601037851507c624' --form accountid=$accountid --form ticketactcode=$activationCode --output /dev/null --silent --write-out '%{http_code}\n'`;
Line 960... Line 982...
960
  }
982
  }
Line 961... Line 983...
961
  
983
  
Line 962... Line 984...
962
}
984
}
963
 
985
 
964
sub modShiftTime {
986
sub modShiftTime {
965
	my ($shift_id, $user_id, $diff) = @_;
987
  my ($shift_id, $user_id, $diff) = @_;
966
	my $ORCUSER = getUser (1);
988
  my $ORCUSER = getUser (1);
967
	
989
  
968
	use Scalar::Util qw(looks_like_number);
990
  use Scalar::Util qw(looks_like_number);
969
	if (!looks_like_number ($diff)) {
991
  if (!looks_like_number ($diff)) {
970
	  print "<br>ERROR! The time adjustment ($diff) doesn't look like a number.<br>\n";
992
    print "<br>ERROR! The time adjustment ($diff) doesn't look like a number.<br>\n";
971
  	return;		
993
    return;   
972
	}
994
  }
973
	
995
  
974
  my ($validate_assignee) = $dbh->selectrow_array ("select count(*) from v_shift where id = ? and RCid = ?", undef, $shift_id, $user_id);
996
  my ($validate_assignee) = $dbh->selectrow_array ("select count(*) from v_shift where id = ? and RCid = ?", undef, $shift_id, $user_id);
975
 	if (!$validate_assignee) {
997
  if (!$validate_assignee) {
976
	  print "<br>ERROR! This shift is assigned to someone else.<br>\n";
998
    print "<br>ERROR! This shift is assigned to someone else.<br>\n";
Line 977... Line 999...
977
  	return;
999
    return;
978
 	}
1000
  }
979
 
1001
 
980
	my $department = getShiftDepartment ($shift_id);
1002
  my $department = getShiftDepartment ($shift_id);
981
  if (convertDepartments ($ORCUSER->{department})->{$department} < 2 and $ORCUSER->{access} < 5) {
1003
  if (convertDepartments ($ORCUSER->{department})->{$department} < 2 and $ORCUSER->{access} < 5) {
982
	  print "<br>ERROR! You're not authorized to modify this shift's time.<br>\n";
1004
    print "<br>ERROR! You're not authorized to modify this shift's time.<br>\n";
983
	  logit ($ORCUSER->{RCid}, "Unauthorized attempt to modify shift time. ($department, $shift_id)");
1005
    logit ($ORCUSER->{RCid}, "Unauthorized attempt to modify shift time. ($department, $shift_id)");
984
  	return;
1006
    return;
985
 	}
1007
  }
986
   	
1008
    
987
  my $rows_changed;
1009
  my $rows_changed;
988
  print "<br>attempting to make DB changes...<br>";
1010
  print "<br>attempting to make DB changes...<br>";
989
  if ($diff == 0) {
1011
  if ($diff == 0) {
990
	  $rows_changed = $dbh->do ("update shift set mod_time = null where id = ? and assignee_id = ?", undef, $shift_id, $user_id);	  	
1012
    $rows_changed = $dbh->do ("update shift set mod_time = null where id = ? and assignee_id = ?", undef, $shift_id, $user_id);     
Line 991... Line 1013...
991
  } else {
1013
  } else {
992
	  $rows_changed = $dbh->do ("update shift set mod_time = ? where id = ? and assignee_id = ?", undef, $diff, $shift_id, $user_id);	
1014
    $rows_changed = $dbh->do ("update shift set mod_time = ? where id = ? and assignee_id = ?", undef, $diff, $shift_id, $user_id); 
993
  }
1015
  }
994
  
1016
  
995
  
1017
  
996
  if (!$rows_changed or $dbh->errstr) {
1018
  if (!$rows_changed or $dbh->errstr) {
997
  	print "ERROR: Nothing got updated".$dbh->errstr;
1019
    print "ERROR: Nothing got updated".$dbh->errstr;
998
  	logit (0, "ERROR modifying a shift time ($diff, $shift_id, $user_id):".$dbh->errstr);
1020
    logit (0, "ERROR modifying a shift time ($diff, $shift_id, $user_id):".$dbh->errstr);
999
  } else {
1021
  } else {
1000
  	print "SUCCESS: Shift $shift_id succesfully modified by $diff hour(s)";
1022
    print "SUCCESS: Shift $shift_id succesfully modified by $diff hour(s)";
Line 1001... Line 1023...
1001
  	logit ($ORCUSER->{RCid}, "SUCCESS: Shift $shift_id succesfully modified by $diff hour(s)");
1023
    logit ($ORCUSER->{RCid}, "SUCCESS: Shift $shift_id succesfully modified by $diff hour(s)");
1002
  	
1024
    
1003
  }
1025
  }
1004
  return;
1026
  return;
1005
}
1027
}
1006
 
1028
 
1007
sub signUpCount {
1029
sub signUpCount {
1008
	my $action = shift;
1030
  my $action = shift;
1009
	my $id = shift;
1031
  my $id = shift;
1010
	my $dept = shift // "";
1032
  my $dept = shift // "";
1011
	
1033
  
1012
	if ($id eq $ORCUSER->{RCid}) {
1034
  if ($id eq $ORCUSER->{RCid}) {
1013
		if ($action eq 'add') {
1035
    if ($action eq 'add') {
1014
			if (signUpCount ('get', $id, $dept)) {
1036
      if (signUpCount ('get', $id, $dept)) {
1015
				$dbh->do("update sign_up_count set sign_ups = sign_ups + 1 where date = curdate() and RCid = ? and department = ?", undef, $id, $dept);
1037
        $dbh->do("update sign_up_count set sign_ups = sign_ups + 1 where date = curdate() and RCid = ? and department = ?", undef, $id, $dept);
1016
			} else {
1038
      } else {
1017
				$dbh->do("replace into sign_up_count (date, RCid, department, sign_ups) values (curdate(), ?, ?, 1)", undef, $id, $dept);
1039
        $dbh->do("replace into sign_up_count (date, RCid, department, sign_ups) values (curdate(), ?, ?, 1)", undef, $id, $dept);
1018
			}
1040
      }
1019
		} elsif ($action eq 'del') {
1041
    } elsif ($action eq 'del') {
1020
			if (signUpCount ('get', $id, $dept)) {
1042
      if (signUpCount ('get', $id, $dept)) {
1021
				$dbh->do("update sign_up_count set sign_ups = sign_ups - 1 where date = curdate() and RCid = ? and department = ?", undef, $id, $dept);
1043
        $dbh->do("update sign_up_count set sign_ups = sign_ups - 1 where date = curdate() and RCid = ? and department = ?", undef, $id, $dept);
1022
			}
1044
      }
1023
		}
1045
    }
Line 1024... Line 1046...
1024
	}
1046
  }
1025
	
1047
  
1026
	my ($R) = $dbh->selectrow_array ("select sign_ups from sign_up_count where RCid = ? and department = ? and date = curdate()", undef, $id, $dept);
1048
  my ($R) = $dbh->selectrow_array ("select sign_ups from sign_up_count where RCid = ? and department = ? and date = curdate()", undef, $id, $dept);
1027
 
1049
  
1028
	return $R ? $R : '0';
1050
  return $R ? $R : '0';
1029
}
1051
}
1030
 
1052
 
1031
sub signUpEligible {
1053
sub signUpEligible {
1032
	my $user = shift;
1054
  my $user = shift;
1033
	my $t = shift;
1055
  my $t = shift;
1034
	my $shifttype = shift // "game";
1056
  my $shifttype = shift // "game";
1035
	my $dept = $t->{dept} // "";
1057
  my $dept = $t->{dept} // "";
1036
  my $DEPTHASH = getDepartments ();
1058
  my $DEPTHASH = getDepartments ();
1037
  if ($dept and !exists $DEPTHASH->{$dept}) {
1059
  if ($dept and !exists $DEPTHASH->{$dept}) {
1038
    my %reverso = reverse %{$DEPTHASH};
1060
    my %reverso = reverse %{$DEPTHASH};
1039
    $dept = $reverso{$dept};
1061
    $dept = $reverso{$dept};
1040
  }
1062
  }
1041
	
1063
  
1042
	my $limit = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY_".$dept);
1064
  my $limit = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY_".$dept);
1043
	$limit = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY") unless defined $limit;
1065
  $limit = getSetting ("MAX_SHIFT_SIGNUP_PER_DAY") unless defined $limit;
1044
	
1066
  
1045
	if (lc $t->{type} eq "lead" and $dept eq "OFF") { $limit = 99; }
1067
  if (lc $t->{type} eq "lead" and $dept eq "OFF") { $limit = 99; }
1046
	
1068
  
1047
	return 0 unless $limit > 0;
1069
  return 0 unless $limit > 0;
1048
	
1070
  
1049
	my $limitkey = $dept ? "sign_ups_today_".$dept : "sign_ups_today";
1071
  my $limitkey = $dept ? "sign_ups_today_".$dept : "sign_ups_today";
1050
	
1072
  
1051
	if ($shifttype eq "class") {
1073
  if ($shifttype eq "class") {
1052
		($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 where date = ? and location = ? and start_time = ?", undef, $t->{date}, $t->{location}, $t->{start_time});
1053
		$t->{dept} = "CLA";
1075
    $t->{dept} = "CLA";
1054
		$dept = "CLA";
1076
    $dept = "CLA";
1055
		$t->{type} = "open";
1077
    $t->{type} = "open";
1056
	}
1078
  }
1057
  
1079
  
1058
	if (findConflict ($user->{RCid}, $t->{id}, $shifttype)) { return 0; }
1080
  if (findConflict ($user->{RCid}, $t->{id}, $shifttype)) { return 0; }
1059
  
1081
  
1060
	if (!exists $user->{$limitkey}) {
1082
  if (!exists $user->{$limitkey}) {
1061
		$user->{$limitkey} = signUpCount('get', $user->{RCid}, $dept);
1083
    $user->{$limitkey} = signUpCount('get', $user->{RCid}, $dept);
1062
	}
1084
  }
1063
	
1085
  
1064
	if ($shifttype eq "game") {
1086
  if ($shifttype eq "game") {
1065
#    if ($t->{gtype} !~ /^selected/ and $t->{gtype} ne "short track" and $user->{$limitkey} < $limit) {
1087
#    if ($t->{gtype} !~ /^selected/ and $t->{gtype} ne "short track" and $user->{$limitkey} < $limit) {
1066
		if ($t->{gtype} eq "full length" and ($dept eq "OFF" or $dept eq "ANN")) {
1088
    if ($t->{gtype} eq "full length" and ($dept eq "OFF" or $dept eq "ANN")) {
1067
		  my $table = $dept eq "OFF" ? "v_shift_officiating" : "v_shift_announcer";
1089
      my $table = $dept eq "OFF" ? "v_shift_officiating" : "v_shift_announcer";
1068
			my ($full_length_count) = $dbh->selectrow_array ("select count(*) from $table where RCid = ? and gtype = 'full length' and year(date) = year(now())", undef, $user->{RCid});
1090
      my ($full_length_count) = $dbh->selectrow_array ("select count(*) from $table where RCid = ? and gtype = 'full length' and year(date) = year(now())", undef, $user->{RCid});
1069
			if ($full_length_count >= getSetting ("MAX_FULL_LENGTH_SIGNUP_".$dept)) {
1091
      if ($full_length_count >= getSetting ("MAX_FULL_LENGTH_SIGNUP_".$dept)) {
1070
				return 0;
1092
        return 0;
1071
			}
1093
      }
1072
		}
1094
    }
1073
    if (lc $t->{signup} ne "selected" and $user->{$limitkey} < $limit) {
1095
    if (lc $t->{signup} ne "selected" and $user->{$limitkey} < $limit) {
1074
			return 1;
1096
      return 1;
1075
		} else {
1097
    } else {
1076
			return 0;
1098
      return 0;
1077
		}
1099
    }
1078
	} else {
1100
  } else {
1079
    if ($dept eq "CLA") {
1101
    if ($dept eq "CLA") {
1080
      # MVP Class Sign-up
1102
      # MVP Class Sign-up
1081
			return 0 unless $user->{MVPid};
1103
      return 0 unless $user->{MVPid};
1082
      my $class_limit = getSetting ("MAX_CLASS_SIGNUP");
1104
      my $class_limit = getSetting ("MAX_CLASS_SIGNUP");
1083
			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 where RCid = ? and year(date) = year(now())", undef, $user->{RCid});
1084
			return 0 unless $class_count < $class_limit;
1106
      return 0 unless $class_count < $class_limit;
1085
    } else {
1107
    } else {
1086
	    if ($user->{department}->{$dept} < 1) { return 0; }
1108
      if ($user->{department}->{$dept} < 1) { return 0; }
1087
	  }
1109
    }
1088
	  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; }
1089
	  if (lc $t->{type} eq "manager" and $user->{department}->{$dept} < 3) { return 0; }
1111
    if (lc $t->{type} eq "manager" and $user->{department}->{$dept} < 3) { return 0; }
1090
	  if ($dept eq "EMT" and $user->{emt_verified} == 0) { return 0; }
1112
    if ($dept eq "EMT" and $user->{emt_verified} == 0) { return 0; }
Line 1091... Line 1113...
1091
    if (lc $t->{type} !~ /^selected/ and $user->{$limitkey} < $limit) {
1113
    if (lc $t->{type} !~ /^selected/ and $user->{$limitkey} < $limit) {
1092
			return 1;
1114
      return 1;
1093
		} else {
1115
    } else {
Line 1104... Line 1126...
1104
  
1126
  
1105
  if ($type eq "game") {
1127
  if ($type eq "game") {
1106
  # Are they already signed up for this game? (It's faster to check the two views one at a time...)
1128
  # Are they already signed up for this game? (It's faster to check the two views one at a time...)
1107
#    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where substring_index(id, '-', 1) = ? and RCid = ?", undef, $gid, $rcid);
1129
#    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where substring_index(id, '-', 1) = ? and RCid = ?", undef, $gid, $rcid);
1108
    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where id = ? and RCid = ?", undef, $gid, $rcid);
1130
    ($conflicts) = $dbh->selectrow_array ("select count(*) from v_shift_officiating where id = ? and RCid = ?", undef, $gid, $rcid);
1109
  	if ($conflicts) { return "OFF-".$gid; } # no need to keep looking...
1131
    if ($conflicts) { return "OFF-".$gid; } # no need to keep looking...
1110
    ($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);
1111
  	if ($conflicts) { return "ANN-".$gid; } # no need to keep looking...
1133
    if ($conflicts) { return "ANN-".$gid; } # no need to keep looking...
1112
  	
1134
    
1113
    ($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);    
1114
  } elsif ($type eq "class")  {
1136
  } elsif ($type eq "class")  {
1115
    ($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 where id = ? and RCid = ?", undef, $gid, $rcid);
1116
  	if ($conflicts) { return "CLA:".$gid; } # no need to keep looking...
1138
    if ($conflicts) { return "CLA:".$gid; } # no need to keep looking...
1117
  	
1139
    
Line 1118... Line 1140...
1118
    ($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 where id = ?", undef, $gid);
1119
    
1141
    
1120
  } elsif ($type eq "personal")  {
1142
  } elsif ($type eq "personal")  {
Line 1138... Line 1160...
1138
    
1160
    
1139
  return $conflicts;
1161
  return $conflicts;
Line 1140... Line 1162...
1140
}
1162
}
1141
 
1163
 
1142
sub changeLeadShift {
1164
sub changeLeadShift {
1143
	my ($change, $lshift, $user_id) = @_;
1165
  my ($change, $lshift, $user_id) = @_;
1144
	my $ERRMSG;
1166
  my $ERRMSG;
1145
 
1167
  
1146
	my $sth = $dbh->prepare("update lead_shift set assignee_id = ? where id = ?");
1168
  my $sth = $dbh->prepare("update lead_shift set assignee_id = ? where id = ?");
1147
	
1169
  
1148
	print "<br>attempting to make DB changes...<br>";
1170
  print "<br>attempting to make DB changes...<br>";
1149
	if ($change eq "add") {
1171
  if ($change eq "add") {
1150
		$sth->execute($user_id, $lshift)
1172
    $sth->execute($user_id, $lshift)
1151
    	or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
1173
      or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
1152
	} elsif ($change eq "del") {
1174
  } elsif ($change eq "del") {
1153
		$sth->execute('', $lshift)
1175
    $sth->execute('', $lshift)
1154
    	or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
1176
      or $ERRMSG = "ERROR: Can't execute SQL statement: ".$sth->errstr()."\n";
1155
	}
1177
  }
1156
	if ($ERRMSG) {
1178
  if ($ERRMSG) {
1157
		print $ERRMSG;
1179
    print $ERRMSG;
1158
	} else {
1180
  } else {
1159
		logit($user_id, "Lead Shift ".ucfirst($change).": $lshift");
1181
    logit($user_id, "Lead Shift ".ucfirst($change).": $lshift");
1160
  	print "Success.<br>";
1182
    print "Success.<br>";
Line 1161... Line 1183...
1161
  }
1183
  }
1162
}
1184
}
1163
 
1185
 
1164
sub logit {
1186
sub logit {
1165
	my $RCid = shift;
1187
  my $RCid = shift;
1166
	my $msg = shift;
1188
  my $msg = shift;
Line 1167... Line 1189...
1167
	my $sth = $dbh->prepare("insert into log (RCid, event) values (?, ?)");
1189
  my $sth = $dbh->prepare("insert into log (RCid, event) values (?, ?)");
1168
	$sth->execute($RCid, $msg);
1190
  $sth->execute($RCid, $msg);
1169
}
1191
}
1170
 
1192
 
1171
sub sendNewUserEMail {
1193
sub sendNewUserEMail {
1172
	my $context = shift;
1194
  my $context = shift;
1173
	my $data = shift;
1195
  my $data = shift;
1174
	use RCMailer;
1196
  use RCMailer;
1175
  use HTML::Tiny;
1197
  use HTML::Tiny;
1176
  my $h = HTML::Tiny->new( mode => 'html' );
1198
  my $h = HTML::Tiny->new( mode => 'html' );
1177
  my $depts = getDepartments (); # HashRef of the department TLAs -> Display Names...
1199
  my $depts = getDepartments (); # HashRef of the department TLAs -> Display Names...
1178
  my $AccessLevel = getAccessLevels;
1200
  my $AccessLevel = getAccessLevels;
1179
 
1201
  
1180
	my $email = $data->{email};
1202
  my $email = $data->{email};
1181
	my $subject = 'RollerCon VORC - New User';
1203
  my $subject = 'RollerCon VORC - New User';
1182
	my $body;
1204
  my $body;
1183
	if ($context eq "New User") {
1205
  if ($context eq "New User") {
1184
    $subject .= " Request";
1206
    $subject .= " Request";
1185
    my $activationlink = url ()."?activate=".$data->{activation};
1207
    my $activationlink = url ()."?activate=".$data->{activation};
1186
	  $body = $h->p ("Greetings,");
1208
    $body = $h->p ("Greetings,");
1187
	  $body .= $h->p ("It appears as though you've registered a new account in RollerCon's VORC system with the following information:");
1209
    $body .= $h->p ("It appears as though you've registered a new account in RollerCon's VORC system with the following information:");
1188
	  $body .= $h->table ([
1210
    $body .= $h->table ([
1189
	    $h->tr ([$h->td ("&nbsp;&nbsp;", "Derby Name:",    $data->{derby_name})]),
1211
      $h->tr ([$h->td ("&nbsp;&nbsp;", "Derby Name:",    $data->{derby_name})]),
1190
	    $h->tr ([$h->td ("&nbsp;&nbsp;", "Full Name:",     $data->{real_name})]),
1212
      $h->tr ([$h->td ("&nbsp;&nbsp;", "Full Name:",     $data->{real_name})]),
1191
	    $h->tr ([$h->td ("&nbsp;&nbsp;", "Pronouns:",      $data->{pronouns})]),
1213
      $h->tr ([$h->td ("&nbsp;&nbsp;", "Pronouns:",      $data->{pronouns})]),
1192
	    $h->tr ([$h->td ("&nbsp;&nbsp;", "TShirt Size:",   $data->{tshirt})]),
1214
      $h->tr ([$h->td ("&nbsp;&nbsp;", "TShirt Size:",   $data->{tshirt})]),
1193
	    $h->tr ([$h->td ("&nbsp;&nbsp;", "Email Address:", $data->{email})]),
1215
      $h->tr ([$h->td ("&nbsp;&nbsp;", "Email Address:", $data->{email})]),
1194
	    $h->tr ([$h->td ("&nbsp;&nbsp;", "Phone:",         $data->{phone})])
1216
      $h->tr ([$h->td ("&nbsp;&nbsp;", "Phone:",         $data->{phone})])
1195
	  ]);
1217
    ]);
1196
    $body .= $h->p ("To validate that you've entered a real (and correct) email address (and that you're not a spam-bot), please click the following link:",
1218
    $body .= $h->p ("To validate that you've entered a real (and correct) email address (and that you're not a spam-bot), please click the following link:",
Line 1232... Line 1254...
1232
-RollerCon Management
1254
-RollerCon Management
1233
";
1255
";
1234
  } else {
1256
  } else {
1235
    return;
1257
    return;
1236
  }
1258
  }
1237
	# send the message
1259
  # send the message
1238
	EmailUser ($email, $subject, $body);
1260
  EmailUser ($email, $subject, $body);
1239
 
1261
  
1240
}
1262
}
Line 1241... Line 1263...
1241
 
1263
 
1242
sub validate_emt {
1264
sub validate_emt {
1243
  my $target = shift // "";
1265
  my $target = shift // "";