-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyRoster.java
1341 lines (1333 loc) · 63.2 KB
/
MyRoster.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyRoster extends HttpServlet
{
private ConnectionPool pool;
private ServletContext context;
private static String servletName="MyRoster";
public void init()
{
context = getServletContext();
synchronized(context)
{
pool=(ConnectionPool)context.getAttribute("pool");
if(pool==null)
{
String driverClassName = context.getInitParameter("driverClassName");
String url = context.getInitParameter("url");
String userName = context.getInitParameter("username");
String password = context.getInitParameter("password");
try
{
pool=new ConnectionPool(driverClassName,url,userName,password);
}
catch(Exception error)
{
Routines.writeToLog(servletName,"Unable to create connection pool : " + error,false,context);
}
context.setAttribute("pool",pool);
}
}
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
{
doGet(request,response);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
{
response.setContentType("text/html");
PrintWriter webPageOutput=null;
try
{
webPageOutput=response.getWriter();
}
catch(IOException error)
{
Routines.writeToLog(servletName,"Error getting writer : " + error,false,context);
}
HttpSession session=request.getSession();
session.setAttribute("redirect",request.getRequestURL() + "?" + request.getQueryString());
Connection database=null;
try
{
database=pool.getConnection(servletName);
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to connect to database : " + error,false,context);
}
if(Routines.loginCheck(false,request,response,database,context))
{
return;
}
Routines.WriteHTMLHead("My Roster",//title
true,//showMenu
9,//menuHighLight
false,//seasonsMenu
false,//weeksMenu
false,//scores
false,//standings
false,//gameCenter
false,//schedules
false,//previews
false,//teamCenter
false,//draft
database,//database
request,//request
response,//response
webPageOutput,//webPageOutput
context);//context
webPageOutput.println("<CENTER>");
webPageOutput.println("<IMG SRC=\"../Images/MyRoster.jpg\"" +
" WIDTH='386' HEIGHT='79' ALT='My Roster'>");
webPageOutput.println(Routines.spaceLines(1));
String submitAction = request.getParameter("submitAction");
int league=Routines.safeParseInt((String)session.getAttribute("league"));
int teamNumber=Routines.safeParseInt((String)session.getAttribute("team"));
int setNumber=Routines.safeParseInt(request.getParameter("set"));
String currentPositionDescription="";
int positionNumbers[]=null;
String anchorDescriptions[]=null;
String positionSubDescriptions[]=null;
int numOfPositions=0;
try
{
Statement sql=database.createStatement();
ResultSet queryResults;
queryResults=sql.executeQuery("SELECT COUNT(PositionNumber) " +
"FROM positions " +
"WHERE Type!=3 " +
"AND RealPosition=1 " +
"GROUP BY RealPosition");
if(queryResults.first())
{
numOfPositions=queryResults.getInt(1);
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to get positions(1) : " + error,false,context);
}
positionNumbers=new int[numOfPositions];
anchorDescriptions=new String[numOfPositions];
positionSubDescriptions=new String[numOfPositions];
try
{
Statement sql=database.createStatement();
ResultSet queryResults;
queryResults=sql.executeQuery("SELECT PositionNumber,PositionCode,PositionName " +
"FROM positions " +
"WHERE Type!=3 " +
"AND ChartOnly=0 " +
"ORDER BY PositionNumber ASC");
int currentPosition=0;
while(queryResults.next())
{
positionNumbers[currentPosition]=queryResults.getInt(1);
anchorDescriptions[currentPosition]=queryResults.getString(2);
positionSubDescriptions[currentPosition]=queryResults.getString(3);
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to get positions(2) : " + error,false,context);
}
String positionDescriptions[]={"QuarterBacks",
"RunningBacks",
"Tight Ends",
"Wide Receivers",
"Offensive Linemen",
"Offensive Linemen",
"Offensive Linemen",
"Offensive Linemen",
"Offensive Linemen",
"Offensive Linemen",
"Defensive Linemen",
"Defensive Linemen",
"Defensive Linemen",
"LineBackers",
"LineBackers",
"LineBackers",
"Defensive Backs",
"Defensive Backs",
"Defensive Backs",
"Kickers"};
int bestInjuredPunter=0;
int bestInjuredPunterInjury=0;
int bestInjuredPunterSkills=0;
String bestInjuredPunterName="";
int bestHealthyPunter=0;
int bestHealthyPunterSkills=0;
String bestHealthyPunterName="";
boolean doctorTrainer=false;
int[] drTrPositionNumber={10,11};
String[] drTrText={"Doctor","Trainer"};
int numOfPlaces[]={0,0};
String[] surNames={"",""};
String[] forNames={"",""};
boolean multiDRTR[]={false,false};
boolean updated=false;
for(int currentPosition=0;currentPosition<drTrPositionNumber.length;currentPosition++)
{
try
{
Statement sql=database.createStatement();
ResultSet queryResult;
queryResult=sql.executeQuery("SELECT Skill1,Injury,Surname,Forname " +
"FROM players " +
"WHERE TeamNumber=" + teamNumber + " " +
"AND PositionNumber=" + drTrPositionNumber[currentPosition]);
int tempNumOfPlaces=0;
int numOfDRTR=0;
while(queryResult.next())
{
numOfDRTR++;
int skill1=queryResult.getInt(1)/10;
int injury=queryResult.getInt(2);
surNames[currentPosition]=queryResult.getString(3);
forNames[currentPosition]=queryResult.getString(4);
if(injury==0)
{
tempNumOfPlaces=+skill1;
}
}
if(tempNumOfPlaces>0)
{
numOfPlaces[currentPosition]=tempNumOfPlaces;
if(numOfDRTR>1)
{
multiDRTR[currentPosition]=true;
}
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to access " + drTrText[currentPosition] + " details : " + error,false,context);
}
}
try
{
Statement sql=database.createStatement();
ResultSet queryResult;
queryResult=sql.executeQuery("SELECT Sum(Doctors),Sum(Trainers) " +
"FROM players " +
"WHERE TeamNumber=" + teamNumber);
if(queryResult.first())
{
int doctorVisits=queryResult.getInt(1);
int trainerVisits=queryResult.getInt(2);
numOfPlaces[0]-=doctorVisits;
numOfPlaces[1]-=trainerVisits;
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to retrieve player injury/doctor usage : " + error,false,context);
}
try
{
Statement sql = database.createStatement();
ResultSet queryResponse;
if(setNumber==0)
{
queryResponse=sql.executeQuery("SELECT SetNumber " +
"FROM defaultsets " +
"WHERE SetName='Normal'");
if(queryResponse.first())
{
setNumber=queryResponse.getInt(1);
}
else
{
Routines.writeToLog(servletName,"No normal set found (TeamNumber=" +
teamNumber +
")",false,context);
}
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to retrieve sets : " + error,false,context);
}
if ("Send to Doctors".equals(submitAction)||
"Send to Trainers".equals(submitAction)||
"Move Up".equals(submitAction)||
"Move Down".equals(submitAction)||
"Waive".equals(submitAction))
{
int updateValues[]={0,0,0};
updateValues=updateEntry(submitAction,
numOfPlaces[0],
numOfPlaces[1],
teamNumber,
setNumber,
request,
database);
if(updateValues[2]==1)
{
updated=true;
numOfPlaces[0]=updateValues[0];
numOfPlaces[1]=updateValues[1];
}
}
webPageOutput.println("<FORM ACTION=\"http://" +
request.getServerName() +
":" +
request.getServerPort() +
request.getContextPath() +
"/servlet/MyRoster\" METHOD=\"POST\">");
webPageOutput.println("<CENTER>");
if(numOfPlaces[0]!=0)
{
webPageOutput.println("<IMG SRC=\"../Images/MadDoc.gif\"" +
" WIDTH='80' HEIGHT='110' ALT='Doctor'>");
}
webPageOutput.println("<IMG SRC=\"../Images/CoachRoster.gif\"" +
" WIDTH='60' HEIGHT='100' ALT='Coach'>");
if(numOfPlaces[0]!=0)
{
webPageOutput.println("<IMG SRC=\"../Images/ScoldingCoach.gif\"" +
" WIDTH='95' HEIGHT='90' ALT='Trainer'>");
}
webPageOutput.println("</CENTER>");
Routines.myTableStart(false,webPageOutput);
Routines.myTableHeader((String)session.getAttribute("teamName"),1,webPageOutput);
Routines.tableEnd(webPageOutput);
if((String)session.getAttribute("message")!=null)
{
Routines.tableStart(false,webPageOutput);
Routines.tableHeader("Messages",0,webPageOutput);
Routines.tableDataStart(true,false,true,true,false,0,0,"scoresrow",webPageOutput);
Routines.messageCheck(false,request,webPageOutput);
Routines.tableDataEnd(true,false,true,webPageOutput);
doctorTrainer=true;
}
for(int currentPosition=0;currentPosition<drTrPositionNumber.length;currentPosition++)
{
if(numOfPlaces[currentPosition]>0)
{
if(!doctorTrainer)
{
Routines.tableStart(false,webPageOutput);
Routines.tableHeader("Messages",0,webPageOutput);
doctorTrainer=true;
}
Routines.tableDataStart(true,false,true,true,false,0,0,"scoresrow",webPageOutput);
if(multiDRTR[currentPosition]==true)
{
webPageOutput.println("Your " + drTrText[currentPosition] + "s can work on " + numOfPlaces[currentPosition] + " more players this week.");
}
else
{
webPageOutput.println(drTrText[currentPosition] + " " + forNames[currentPosition] + " " + surNames[currentPosition] + " can work on " + numOfPlaces[currentPosition] + " more players this week.");
}
Routines.tableDataEnd(true,false,true,webPageOutput);
}
}
if(doctorTrainer)
{
Routines.tableEnd(webPageOutput);
webPageOutput.println(Routines.spaceLines(1));
}
webPageOutput.println(Routines.spaceLines(1));
Routines.tableStart(false,webPageOutput);
Routines.tableHeader("Sets",0,webPageOutput);
Routines.tableDataStart(true,true,true,true,false,0,0,"scoresrow",webPageOutput);
try
{
Statement sql=database.createStatement();
ResultSet queryResult;
queryResult=sql.executeQuery("SELECT SetNumber,SetName " +
"FROM defaultsets " +
"ORDER BY SetNumber ASC");
webPageOutput.println("<SELECT NAME=\"set\">");
int tempSetNumber=0;
String tempSetName="";
String selected="";
while(queryResult.next())
{
tempSetNumber=queryResult.getInt(1);
tempSetName=queryResult.getString(2);
if(tempSetNumber==setNumber)
{
selected="SELECTED ";
}
else
{
selected="";
}
webPageOutput.println(" " +
"<OPTION " +
selected +
"VALUE=\"" +
tempSetNumber +
"\">" +
"Your '" +
tempSetName +
"' set of players");
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to retrieve sets : " + error,false,context);
}
webPageOutput.println("</SELECT>");
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" NAME=\"action\" VALUE=\"Change\">");
Routines.tableDataEnd(true,false,true,webPageOutput);
Routines.tableHeader("Actions",0,webPageOutput);
Routines.tableDataStart(true,true,true,true,false,0,0,"scoresrow",webPageOutput);
if(numOfPlaces[0]!=0)
{
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Send to Doctors\" NAME=\"submitAction\">");
}
if(numOfPlaces[0]!=0)
{
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Send to Trainers\" NAME=\"submitAction\">");
}
// webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Waive\" NAME=\"submitAction\">");
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Move Up\" NAME=\"submitAction\">");
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Move Down\" NAME=\"submitAction\">");
Routines.tableDataEnd(true,false,true,webPageOutput);
Routines.tableHeader("Quick Links",0,webPageOutput);
Routines.tableDataStart(true,true,false,true,false,0,0,"scoresrow",webPageOutput);
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#QB\">QuarterBacks</A>");
webPageOutput.println("<B>·</B>");
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#RB\">RunningBacks</A>");
webPageOutput.println("<B>·</B>");
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#TE\">Tight Ends</A>");
webPageOutput.println("<B>·</B>");
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#WR\">Wide Receivers</A>");
webPageOutput.println("<B>·</B>");
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#OL\">Offensive Linemen</A>");
webPageOutput.println(Routines.spaceLines(1));
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#DL\">Defensive Linemen</A>");
webPageOutput.println("<B>·</B>");
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#LB\">Linebackers</A>");
webPageOutput.println("<B>·</B>");
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#DB\">Defensive Backs</A>");
webPageOutput.println("<B>·</B>");
webPageOutput.println("<A CLASS=\"opt\" HREF=\"#K\">Kickers</A>");
Routines.tableDataEnd(false,false,true,webPageOutput);
webPageOutput.println("</CENTER>");
Routines.tableEnd(webPageOutput);
webPageOutput.println(Routines.spaceLines(1));
webPageOutput.println("<DIV CLASS=\"SLTables2\"><TABLE WIDTH=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"1\" BORDER=\"0\">");
webPageOutput.println("<TBODY>");
int selectedPlayers[]=new int[100];
int numOfSelectedPlayers=0;
if(!updated)
{
for(int currentPlayer=0;currentPlayer<selectedPlayers.length;currentPlayer++)
{
int playerID=0;
playerID=Routines.safeParseInt(request.getParameter("selectPlayer" + currentPlayer));
if(playerID!=0)
{
selectedPlayers[numOfSelectedPlayers]=playerID;
numOfSelectedPlayers++;
}
}
}
int currentPlayer=0;
for(int currentPosition=0;currentPosition<positionNumbers.length;currentPosition++)
{
try
{
Statement sql = database.createStatement();
ResultSet queryResponse;
queryResponse = sql.executeQuery("SELECT players.PlayerNumber,PositionDisplayCode,Surname,Forname,Experience,Skill1,Skill2,Skill3,Skill4,Skill5,Skill6,Skill7,Injury,Form " +
"FROM players,depthcharts,positions " +
"WHERE players.TeamNumber = " +
teamNumber + " " +
"AND players.PlayerNumber=depthcharts.PlayerNumber " +
"AND players.TeamNumber=depthcharts.teamNumber " +
"AND SetNumber=" + setNumber + " " +
"AND depthcharts.PositionNumber = positions.PositionNumber " +
"AND depthcharts.PositionNumber = " + positionNumbers[currentPosition] +
" " +
"ORDER BY depth ASC");
if(!currentPositionDescription.equals(positionDescriptions[currentPosition]))
{
webPageOutput.println("<TR ALIGN=\"left\" CLASS=\"bg0\">");
if("Kickers".equals(positionDescriptions[currentPosition]))
{
webPageOutput.println("<TD CLASS=\"home\" COLSPAN=\"11\">");
}
else
{
webPageOutput.println("<TD CLASS=\"home\" COLSPAN=\"12\">");
}
webPageOutput.println("<A NAME=\"" + anchorDescriptions[currentPosition] + "\"></A>");
webPageOutput.println("<FONT CLASS=\"home\">");
webPageOutput.println(positionDescriptions[currentPosition]);
webPageOutput.println("</FONT>");
webPageOutput.println("</TD>");
webPageOutput.println("</TR>");
currentPositionDescription=positionDescriptions[currentPosition];
Routines.skillsTitleLine(positionDescriptions[currentPosition],currentPosition,false,webPageOutput);
}
if(!positionDescriptions[currentPosition].equals(positionSubDescriptions[currentPosition]))
{
webPageOutput.println("<TR CLASS=\"bg1\">");
webPageOutput.println("<TD ALIGN=\"LEFT\" COLSPAN=\"12\"><FONT CLASS=\"opt2\"><B>" + positionSubDescriptions[currentPosition] + "</B></FONT></TD>");
webPageOutput.println("</TR>");
}
while(queryResponse.next())
{
int playerID=queryResponse.getInt(1);
String positionCode=queryResponse.getString(2);
String surname=queryResponse.getString(3);
String forname=queryResponse.getString(4);
int experience=queryResponse.getInt(5);
int skill1=queryResponse.getInt(6);
int skill2=queryResponse.getInt(7);
int skill3=queryResponse.getInt(8);
int skill4=queryResponse.getInt(9);
int skill5=queryResponse.getInt(10);
int skill6=queryResponse.getInt(11);
int skill7=queryResponse.getInt(12);
int injury=queryResponse.getInt(13);
int form=queryResponse.getInt(14);
String colourOpen = new String("");
String colourClose = new String("");
colourOpen = Routines.colourOpen(injury);
colourClose = Routines.colourClose(injury);
boolean selected=false;
for(int currentSelect=0;currentSelect<numOfSelectedPlayers;currentSelect++)
{
if(selectedPlayers[currentSelect]==playerID)
{
selected=true;
}
}
webPageOutput.println("<TR CLASS=\"bg2\">");
webPageOutput.println("<TD><FONT CLASS=\"opt2\">");
webPageOutput.print("<INPUT TYPE=\"CHECKBOX\" NAME=\"selectPlayer" + currentPlayer + "\" VALUE=\"" + playerID + "\"");
if(selected)
{
webPageOutput.print(" CHECKED");
}
webPageOutput.println(">");
webPageOutput.println("</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"LEFT\"><FONT CLASS=\"opt2\">" + colourOpen);
String fullName = forname + " " + surname;
Routines.WriteHTMLLink(request,
response,
webPageOutput,
"wfafl",
"action=viewMyRosterEntry&playerNumber=" +
playerID +
"&positionName=" +
positionDescriptions[currentPosition] +
"&positionNumber=" +
currentPosition,
fullName,
null,
true);
if (positionDescriptions[currentPosition].equals("Offensive Linemen") ||
positionDescriptions[currentPosition].equals("Defensive Linemen"))
{
webPageOutput.println("(" + positionCode + ")");
}
webPageOutput.println(colourClose + "</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
experience +
colourClose +
"</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill1) +
colourClose +
"</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill2) +
colourClose +
"</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill3) +
colourClose +
"</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill4) +
colourClose +
"</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill5) +
colourClose +
"</FONT></TD>");
if(positionDescriptions[currentPosition].equals("Kickers"))
{
int punterSkills=(skill6*10)+skill7;
if(injury==0)
{
if(punterSkills>=bestHealthyPunterSkills)
{
bestHealthyPunter=playerID;
bestHealthyPunterSkills=punterSkills;
bestHealthyPunterName=forname + " " + surname;
}
}
else
{
if(bestInjuredPunterInjury==0||
injury<bestInjuredPunterInjury)
{
bestInjuredPunter=playerID;
bestInjuredPunterSkills=punterSkills;
bestInjuredPunterName=forname + " " + surname;
}
}
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
skill6 +
skill7 +
colourClose +
"</FONT></TD>");
}
else
{
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill6) +
colourClose +
"</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill7) +
colourClose +
"</FONT></TD>");
}
if(injury!=0)
{
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
injury +
colourClose +
"</FONT></TD>");
}
else
{
webPageOutput.println("<TD></TD>");
}
String formString="";
if(form<5)
{
formString="-";
}
if(form>5)
{
formString="+";
}
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
formString +
colourClose +
"</FONT></TD>");
webPageOutput.println("</TR>");
currentPlayer++;
}
if(!queryResponse.first())
{
webPageOutput.println("<TR CLASS=\"bg2\">");
if("Kickers".equals(positionDescriptions[currentPosition]))
{
webPageOutput.println("<TD ALIGN=\"LEFT\" COLSPAN=\"11\"><FONT CLASS=\"opt2\">");
}
else
{
webPageOutput.println("<TD ALIGN=\"LEFT\" COLSPAN=\"12\"><FONT CLASS=\"opt2\">");
}
webPageOutput.println("None");
webPageOutput.println("</FONT></TD></TR>");
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to access player details : " + error,false,context);
}
}
webPageOutput.println("<TR CLASS=\"bg1\">");
webPageOutput.println("<TD ALIGN=\"LEFT\" COLSPAN=\"11\"><FONT CLASS=\"opt2\">");
String bestPunter="";
if(bestHealthyPunter==0)
{
bestPunter=bestInjuredPunterName;
}
else
{
bestPunter=bestHealthyPunterName;
}
webPageOutput.println("Your punter is automatically set and will be " + bestPunter);
webPageOutput.println("</FONT></TD></TR>");
webPageOutput.println("</TBODY></TABLE></DIV>");
try
{
webPageOutput.println("<DIV CLASS=\"SLTables2\"><TABLE WIDTH=\"70%\" CELLPADDING=\"2\" CELLSPACING=\"1\" BORDER=\"0\">");
webPageOutput.println("<TBODY>");
Statement sql=database.createStatement();
ResultSet queryResponse;
queryResponse = sql.executeQuery("SELECT PlayerNumber,positions.PositionDisplayCode,Surname,Forname,Experience,Skill1,Injury " +
"FROM players,positions " +
"WHERE TeamNumber = " +
teamNumber +
" AND Staff=1 " +
"AND players.PositionNumber = positions.PositionNumber " +
"ORDER BY PlayerNumber ASC");
webPageOutput.println("<TR ALIGN=\"left\" CLASS=\"bg0\">");
webPageOutput.println("<TD CLASS=\"home\" COLSPAN=\"7\">");
webPageOutput.println("<FONT CLASS=\"home\">");
webPageOutput.println("Staff");
webPageOutput.println("</FONT>");
webPageOutput.println("</TD>");
webPageOutput.println("</TR>");
webPageOutput.println("<TR CLASS=\"bg1\">");
webPageOutput.println("<TD ALIGN=\"LEFT\"><FONT CLASS=\"opt2\">Sel</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"LEFT\"><FONT CLASS=\"opt2\">Name</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">Experience</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">Rating</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">Injury</FONT></TD>");
while(queryResponse.next())
{
int playerID=queryResponse.getInt(1);
String positionCode=queryResponse.getString(2);
String surname=queryResponse.getString(3);
String forname=queryResponse.getString(4);
int experience=queryResponse.getInt(5);
int skill1=queryResponse.getInt(6)/10;
int injury=queryResponse.getInt(7);
String colourOpen = new String("");
String colourClose = new String("");
colourOpen = Routines.colourOpen(injury);
colourClose = Routines.colourClose(injury);
webPageOutput.println("<TR CLASS=\"bg2\">");
webPageOutput.println("<TD><FONT CLASS=\"opt2\">");
webPageOutput.println("<INPUT TYPE=\"CHECKBOX\" NAME=\"selectPlayer" + currentPlayer + "\" VALUE=\"" + playerID + "\">");
webPageOutput.println("</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"LEFT\"><FONT CLASS=\"opt2\">" + colourOpen);
String fullName = forname + " " + surname;
Routines.WriteHTMLLink(request,
response,
webPageOutput,
"wfafl",
"action=viewMyRosterEntry&playerNumber=" +
playerID,
fullName,
null,
true);
webPageOutput.println("(" + positionCode + ")");
webPageOutput.println(colourClose + "</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
experience +
colourClose +
"</FONT></TD>");
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
Routines.skillsDescription(skill1) +
colourClose +
"</FONT></TD>");
if(injury!=0)
{
webPageOutput.println("<TD ALIGN=\"RIGHT\"><FONT CLASS=\"opt2\">" +
colourOpen +
injury +
colourClose +
"</FONT></TD>");
}
else
{
webPageOutput.println("<TD></TD>");
}
webPageOutput.println("</TR>");
currentPlayer++;
}
if(!queryResponse.first())
{
webPageOutput.println("<TR CLASS=\"bg2\">");
webPageOutput.println("<TD ALIGN=\"LEFT\" COLSPAN=\"7\"><FONT CLASS=\"opt2\">");
webPageOutput.println("None");
webPageOutput.println("</FONT></TD></TR>");
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to access staff details : " + error,false,context);
}
webPageOutput.println("</TBODY></TABLE></DIV>");
webPageOutput.println("<CENTER>");
webPageOutput.println(Routines.spaceLines(1));
Routines.tableStart(false,webPageOutput);
Routines.tableHeader("Actions",0,webPageOutput);
Routines.tableDataStart(true,true,true,true,false,0,0,"scoresrow",webPageOutput);
if(numOfPlaces[0]!=0)
{
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Send to Doctors\" NAME=\"submitAction\">");
}
if(numOfPlaces[1]!=0)
{
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Send to Trainers\" NAME=\"submitAction\">");
}
// webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Waive\" NAME=\"submitAction\">");
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Move Up\" NAME=\"submitAction\">");
webPageOutput.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Move Down\" NAME=\"submitAction\">");
Routines.tableDataEnd(true,false,true,webPageOutput);
Routines.tableEnd(webPageOutput);
webPageOutput.println("</CENTER>");
webPageOutput.println("<INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"" + "viewMyRoster" + "\">");
webPageOutput.println("<INPUT TYPE=\"hidden\" NAME=\"league\" VALUE=\"" + league + "\">");
webPageOutput.println("<INPUT TYPE=\"hidden\" NAME=\"team\" VALUE=\"" + teamNumber + "\">");
webPageOutput.println("<INPUT TYPE=\"hidden\" NAME=\"jsessionid\" VALUE=\"" + session.getId() + "\">");
webPageOutput.println("</FORM>");
pool.returnConnection(database);
Routines.WriteHTMLTail(request,response,webPageOutput);
}
private synchronized int[] updateEntry(String submitAction,
int doctors,
int trainers,
int teamNumber,
int setNumber,
HttpServletRequest request,
Connection database)
{
int returnValues[]={doctors,trainers,0};
HttpSession session=request.getSession();
int selectedPlayers[]=new int[100];
int currentSelectedPlayer=0;
int numOfSelectedPlayers=0;
int maxDepth=0;
String message="";
int positionNumbers[]={19,20,17,18,
14,13,12,15,16,29,
23,24,30,
25,26,31,
27,28,32,
2};
String positionDescriptions[]={"QuarterBack",
"RunningBack",
"Tight End",
"Wide Receiver",
"Offensive Lineman",
"Offensive Lineman",
"Offensive Lineman",
"Offensive Lineman",
"Offensive Lineman",
"Offensive Lineman",
"Defensive Lineman",
"Defensive Lineman",
"Defensive Lineman",
"LineBacker",
"LineBacker",
"LineBacker",
"Defensive Back",
"Defensive Back",
"Defensive Back",
"Kickers"};
boolean allowUp[]={false,false,false,false,
false,true,true,true,true,true,
false,true,true,
false,true,true,
false,true,true,
false};
boolean allowDown[]={false,false,false,false,
true,true,true,true,true,false,
true,true,false,
true,true,false,
true,true,false,
false};
boolean upDown[]={false,false,false,false,
false,false,false,false,false,false,
false,false,false,
false,false,false,
false,false,false,
false};
boolean moveUp=false;
for(int currentPlayer=0;currentPlayer<selectedPlayers.length;currentPlayer++)
{
int playerID=0;
playerID=Routines.safeParseInt(request.getParameter("selectPlayer" + currentPlayer));
if(playerID!=0)
{
selectedPlayers[currentSelectedPlayer]=playerID;
currentSelectedPlayer++;
numOfSelectedPlayers++;
}
}
String actionText[]={"Send to Doctors","Send to Trainers"};
int numOfPlaces[]={doctors,trainers};
String messageText[]={"doctors","trainers"};
String selectText[]={"Injury,Doctors","Form,Trainers"};
String updateText[]={"Injury=(Injury-1),Doctors=1","Form=(Form+5),Trainers=1"};
for(int currentAction=0;currentAction<actionText.length;currentAction++)
{
if(actionText[currentAction].equals(submitAction))
{
if(numOfSelectedPlayers>numOfPlaces[currentAction])
{
session.setAttribute("message","You can only send " + numOfPlaces[currentAction] + " players to the " + messageText[currentAction]);
return returnValues;
}
for(int currentPlayer=0;currentPlayer<numOfSelectedPlayers;currentPlayer++)
{
if(selectedPlayers[currentPlayer]!=0)
{
try
{
Statement sql=database.createStatement();
ResultSet queryResult;
queryResult=sql.executeQuery("SELECT " + selectText[currentAction] + ",Forname,Surname,positions.PositionDisplayCode " +
"FROM players,positions " +
"WHERE PlayerNumber=" + selectedPlayers[currentPlayer] + " " +
"AND players.PositionNumber=positions.PositionNumber");
if(queryResult.first())
{
int skillToModify=queryResult.getInt(1);
int beenModified=queryResult.getInt(2);
String forName=queryResult.getString(3);
String surName=queryResult.getString(4);
String positionCode=queryResult.getString(5);
if(beenModified==1)
{
session.setAttribute("message",forName + " " + surName + "(" + positionCode + ") has been to the " + messageText[currentAction] + " already this week, only one session per week is allowed");
return returnValues;
}
if(currentAction==0&&skillToModify==0)
{
session.setAttribute("message",forName + " " + surName + "(" + positionCode + ") is not injured and cannot be sent to the Doctors");
return returnValues;
}
if(currentAction==1&&skillToModify==9)
{
session.setAttribute("message",forName + " " + surName + "(" + positionCode + ") is already on top form and cannot be sent to the Trainers");
return returnValues;
}
}
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to access player details : " + error,false,context);
}
}
}
}
}
for(int currentAction=0;currentAction<actionText.length;currentAction++)
{
if(actionText[currentAction].equals(submitAction))
{
for(int currentPlayer=0;currentPlayer<numOfSelectedPlayers;currentPlayer++)
{
if(selectedPlayers[currentPlayer]!=0)
{
try
{
Statement sql=database.createStatement();
ResultSet queryResult;
queryResult=sql.executeQuery("UPDATE players " +
"SET " + updateText[currentAction] + " " +
"WHERE PlayerNumber=" + selectedPlayers[currentPlayer]);
returnValues[currentAction]--;
}
catch(SQLException error)
{
Routines.writeToLog(servletName,"Unable to update player details : " + error,false,context);
}
}
}
}
}
if("Waive".equals(submitAction))
{
for(int currentPlayer=0;currentPlayer<selectedPlayers.length;currentPlayer++)
{
if(selectedPlayers[currentPlayer]!=0)
{
Routines.writeToLog(servletName,"Waiving " + selectedPlayers[currentPlayer],false,context);
}
}
}
boolean movePlayers=false;
if("Move Up".equals(submitAction))
{
upDown=allowUp;
movePlayers=true;
moveUp=true;
}
if("Move Down".equals(submitAction))
{
upDown=allowDown;
movePlayers=true;
moveUp=false;
}
if(movePlayers)
{
for(int currentPlayer=0;currentPlayer<selectedPlayers.length;currentPlayer++)
{
if(selectedPlayers[currentPlayer]!=0)
{
try
{
Statement sql1=database.createStatement();
Statement sql2=database.createStatement();
ResultSet queryResult1;
ResultSet queryResult2;
queryResult1=sql1.executeQuery("SELECT Forname,Surname,positions.PositionDisplayCode,depth,depthcharts.PositionNumber " +
"FROM players,depthcharts,positions " +
"WHERE players.PlayerNumber=" + selectedPlayers[currentPlayer] + " " +
"AND players.PlayerNumber=depthcharts.PlayerNumber " +
"AND players.TeamNumber=" + teamNumber + " " +
"AND SetNumber=" + setNumber + " " +
"AND players.PositionNumber=positions.PositionNumber");
if(queryResult1.first())
{
int positionIndex=0;
String forName=queryResult1.getString(1);