forked from SimonT-STHS/STHS-DynamicWebsite-Production
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI.php
951 lines (918 loc) · 211 KB
/
API.php
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
<?php
require_once "STHSSetting.php";
$EmptyReturn = (string)"<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"><head><title>API</title></head><body><h1><div style=\"text-align:center\"><a href=\"https://sths.simont.info/WebAPI.php\">STHS API Documentation</a></h1></div></body></html>";
$Query = (string) "";
$QueryBoxscore = (string) "";
$CareerStatQuery = (boolean)False;
$CareerStatQueryWithLiveDB = (boolean)False;
$Playoff = (boolean)False;
$PlayoffString = (string)"False";
$Year = (integer)0;
$MaximumResult = (integer)0;
$TypeQuery = (string)""; /* In PlayerInfo Section */
$Retire = (string )"'False'"; /* To Show Retire Player or Not */
$Expansion = (boolean)FALSE; /* In PlayerInfo Section */
$AvailableForTrade = (boolean)FALSE; /* In PlayerInfo Section */
$Team = (integer)-1; /* -1 All Team */
$Type = (integer)0; /* In PlayerInfo Section: 0 = All, 1 = Pro, 2 = Farm // In Transaction Section: 0 = Other, 1 = Trade, 2 = Injury, 3 = Waiver, 4 = SendToPro, 5 = SendToFarm, 6 = Suspension, 7 = RosterLineError, 8 = Information, 9 = Players, 10 = Team, 11 = OptionChange */
$FreeAgentYear = (integer)-1; /* In PlayerInfo Section / -1 = No Input */
$TypeQuery = "Number > 0"; /* In PlayerInfo Section */
$TeamQuery = "Team >= 0"; /* In PlayerInfo Section */
$MinimumGP = (integer)1; /* Player and Goalies Stat */
$Injury = (boolean)FALSE; /* Players and Goaler Roster */
$Conference = (integer)0; /* In Standing Section */
$Division = (integer)0; /* In Standing Section */
$PlayerUniqueID = (integer)-1; /* In PlayerStat***History Section */
$GameNumber = (integer)0; /* In Boxscore Section */
$ReturnOnlyTeamData = (boolean)FALSE; /* In TeamStatProHistoryAllSeasonMerge & TeamStatFarmHistoryAllSeasonMerge Section */
/* Possible Variable */
if(isset($_GET['Playoff'])){$Playoff=True;$PlayoffString="True";}
if(isset($_POST['Playoff'])){$Playoff=True;$PlayoffString="True";}
if(isset($_GET['Year'])){$Year = filter_var($_GET['Year'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['Year'])){$Year = filter_var($_POST['Year'], FILTER_SANITIZE_NUMBER_INT);}
if($Year == null){$Year = 0;}
if($Year > 10000){$Year = 0;}
if(isset($_GET['Max'])){$MaximumResult = filter_var($_GET['Max'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['Max'])){$MaximumResult = filter_var($_POST['Max'], FILTER_SANITIZE_NUMBER_INT);}
if($MaximumResult == null){$MaximumResult = 0;}
if($MaximumResult > 10000){$MaximumResult = 0;}
if(isset($_GET['Team'])){$Team = filter_var($_GET['Team'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['Team'])){$Team = filter_var($_POST['Team'], FILTER_SANITIZE_NUMBER_INT);}
if($Team == null){$Team = -1;}
if($Team > 100){$Team = -1;}
if(isset($_GET['Type'])){$Type = filter_var($_GET['Type'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['Type'])){$Type = filter_var($_POST['Type'], FILTER_SANITIZE_NUMBER_INT);}
if($Type == null){$Type = 0;}
if($Type > 20){$Type = 0;}
if(isset($_GET['Retire'])){$Retire = "'True'";}
if(isset($_POST['Retire'])){$Retire = "'True'";}
if(isset($_GET['FreeAgentYear'])){$FreeAgentYear = filter_var($_GET['FreeAgentYear'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['FreeAgentYear'])){$FreeAgentYear = filter_var($_POST['FreeAgentYear'], FILTER_SANITIZE_NUMBER_INT);}
if($FreeAgentYear == null){$FreeAgentYear = -1;}
if($FreeAgentYear > 100){$FreeAgentYear = -1;}
if(isset($_GET['Expansion'])){$Expansion = TRUE;}
if(isset($_POST['Expansion'])){$Expansion = TRUE;}
if(isset($_GET['AvailableForTrade'])){$AvailableForTrade = TRUE;}
if(isset($_POST['AvailableForTrade'])){$AvailableForTrade = TRUE;}
if(isset($_GET['Injury'])){$Injury = TRUE;}
if(isset($_POST['Injury'])){$Injury = TRUE;}
if(isset($_GET['MinGP'])){$MinimumGP = filter_var($_GET['MinGP'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['MinGP'])){$MinimumGP = filter_var($_POST['MinGP'], FILTER_SANITIZE_NUMBER_INT);}
if($MinimumGP == null){$MinimumGP = 1;}
if($MinimumGP > 1000){$MinimumGP = 1;}
if(isset($_GET['Conference'])){$Conference= filter_var($_GET['Conference'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['Conference'])){$Conference = filter_var($_POST['Conference'], FILTER_SANITIZE_NUMBER_INT);}
if($Conference == null){$Conference = 0;}
if($Conference > 2){$Conference = 0;}
if(isset($_GET['Division'])){$Division= filter_var($_GET['Division'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['Division'])){$Division = filter_var($_POST['Division'], FILTER_SANITIZE_NUMBER_INT);}
if($Division == null){$Division = 0;}
if($Division > 6){$Division = 0;}
if(isset($_GET['ReturnOnlyTeamData'])){$ReturnOnlyTeamData = TRUE;}
if(isset($_POST['ReturnOnlyTeamData'])){$ReturnOnlyTeamData = TRUE;}
if(isset($_GET['UniqueID'])){$PlayerUniqueID = filter_var($_GET['UniqueID'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['UniqueID'])){$PlayerUniqueID = filter_var($_POST['UniqueID'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_GET['GameNumber'])){$GameNumber = filter_var($_GET['GameNumber'], FILTER_SANITIZE_NUMBER_INT);}
if(isset($_POST['GameNumber'])){$GameNumber = filter_var($_POST['GameNumber'], FILTER_SANITIZE_NUMBER_INT);}
If (file_exists($DatabaseFile) == false){
Goto ReturnEmpty;
}{
if(isset($_GET['CoachesPro']) OR isset($_POST['CoachesPro'])){
/* CoachesPro */
$Query = "SELECT CoachInfo.*, TeamProInfo.Name as TeamProName, TeamFarmInfo.Name As TeamFarmName, TeamProInfo.CoachID as ProCoachTeamID, TeamFarmInfo.CoachID as FarmCoachTeamID, TeamProInfo.TeamThemeID As TeamThemeID FROM (CoachInfo LEFT JOIN TeamFarmInfo ON CoachInfo.Team = TeamFarmInfo.Number) LEFT JOIN TeamProInfo ON CoachInfo.Team = TeamProInfo.Number WHERE TEAM <> 0 ORDER BY CoachInfo.Name";
}elseif(isset($_GET['CoachesFarm']) OR isset($_POST['CoachesFarm'])){
/* CoachesFarm */
$Query = "SELECT CoachInfo.*, TeamProInfo.Name as TeamProName, TeamFarmInfo.Name As TeamFarmName, TeamProInfo.CoachID as ProCoachTeamID, TeamFarmInfo.CoachID as FarmCoachTeamID, TeamFarmInfo.TeamThemeID As TeamThemeID FROM (CoachInfo LEFT JOIN TeamFarmInfo ON CoachInfo.Team = TeamFarmInfo.Number) LEFT JOIN TeamProInfo ON CoachInfo.Team = TeamProInfo.Number WHERE TEAM <> 0 ORDER BY CoachInfo.Name";
}elseif(isset($_GET['CoachesAvailable']) OR isset($_POST['CoachesAvailable'])){
/* CoachesAvailable */
$Query = "SELECT CoachInfo.*, TeamProInfo.Name as TeamProName, TeamFarmInfo.Name As TeamFarmName, TeamProInfo.CoachID as ProCoachTeamID, TeamFarmInfo.CoachID as FarmCoachTeamID FROM (CoachInfo LEFT JOIN TeamFarmInfo ON CoachInfo.Team = TeamFarmInfo.Number) LEFT JOIN TeamProInfo ON CoachInfo.Team = TeamProInfo.Number WHERE TEAM = 0 ORDER BY CoachInfo.Name";
}elseif(isset($_GET['FinancePro']) OR isset($_POST['FinancePro'])){
/* FinancePro*/
$Query = "SELECT TeamProFinance.*, TempTable.EstimatedSeasonExpense AS FarmEstimatedSeasonExpense, TempTable.HomeGP AS HomeGP, TeamProInfo.TeamThemeID FROM TeamProFinance INNER JOIN (SELECT TeamFarmFinance.Number, TeamFarmFinance.EstimatedSeasonExpense,TeamProStat.HomeGP FROM TeamProStat INNER JOIN TeamFarmFinance ON TeamProStat.Number = TeamFarmFinance.Number) AS TempTable ON TeamProFinance.Number = TempTable.Number LEFT JOIN TeamProInfo ON TeamProFinance.Number = TeamProInfo.Number ORDER by TeamProFinance.Name";
}elseif(isset($_GET['FinanceFarm']) OR isset($_POST['FinanceFarm'])){
/* FinanceFarm */
$Query = "SELECT TeamFarmFinance.*, TeamFarmStat.HomeGP, TeamFarmInfo.TeamThemeID FROM (TeamFarmFinance LEFT JOIN TeamFarmStat ON TeamFarmFinance.Number = TeamFarmStat.Number) LEFT JOIN TeamFarmInfo ON TeamFarmFinance.Number = TeamFarmInfo.Number ORDER BY TeamFarmFinance.Name;";
}elseif(isset($_GET['Prospect']) OR isset($_POST['Prospect'])){
/* Prospect */
$Query = "SELECT Prospects.*, TeamProInfo.Name As TeamName, TeamProInfo.TeamThemeID FROM Prospects LEFT JOIN TeamProInfo ON Prospects.TeamNumber = TeamProInfo.Number";
if($Team > 0){$Query = $Query . " WHERE TeamNumber = " . $Team; }
$Query = $Query . " ORDER BY Name ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['SchedulePro']) OR isset($_POST['SchedulePro'])){
/* SchedulePro */
If ($Team == -1){
$Query = "SELECT * FROM SchedulePro ORDER BY GameNumber";
}else{
$Query = "SELECT * FROM SchedulePro WHERE (VisitorTeam = " . $Team . " OR HomeTeam = " . $Team . ") ORDER BY GameNumber";
}
}elseif(isset($_GET['ScheduleFarm']) OR isset($_POST['ScheduleFarm'])){
/* ScheduleFarm */
If ($Team == -1){
$Query = "SELECT * FROM ScheduleFarm ORDER BY GameNumber";
}else{
$Query = "SELECT * FROM ScheduleFarm WHERE (VisitorTeam = " . $Team . " OR HomeTeam = " . $Team . ") ORDER BY GameNumber";
}
}elseif(isset($_GET['StandingPro']) OR isset($_POST['StandingPro'])){
/* StandingPro */
If ($Conference == 1 OR $Conference == 2){
/* Conference */
$Query = "SELECT TeamProStat.*, TeamProInfo.Conference, TeamProInfo.Division, TeamProInfo.ConferenceNumber, TeamProInfo.DivisionNumber, TeamProInfo.TeamThemeID, RankingOrder.Type FROM (TeamProStat INNER JOIN TeamProInfo ON TeamProStat.Number = TeamProInfo.Number) INNER JOIN RankingOrder ON TeamProStat.Number = RankingOrder.TeamProNumber WHERE (((RankingOrder.Type)=" . $Conference . ")) ORDER BY RankingOrder.TeamOrder";
}elseif ($Division == 1 OR $Division == 2 OR $Division == 3 OR $Division == 4 OR $Division == 5 OR $Division == 6){
/* Division */
$Query = "SELECT TeamProStat.*, TeamProInfo.Conference, TeamProInfo.Division, TeamProInfo.ConferenceNumber, TeamProInfo.DivisionNumber, TeamProInfo.TeamThemeID, RankingOrder.Type FROM (TeamProStat INNER JOIN TeamProInfo ON TeamProStat.Number = TeamProInfo.Number) INNER JOIN RankingOrder ON TeamProStat.Number = RankingOrder.TeamProNumber WHERE (((TeamProInfo.DivisionNumber)=" . $Division . ") AND ((RankingOrder.Type)=0)) ORDER BY RankingOrder.TeamOrder";
}elseif($Conference > 0 OR $Division > 0){
/* Return Empty */
}else{
/* Overall */
$Query = "SELECT TeamProStat.*, TeamProInfo.Conference, TeamProInfo.Division, TeamProInfo.ConferenceNumber, TeamProInfo.DivisionNumber,TeamProInfo.TeamThemeID, RankingOrder.Type FROM (TeamProStat INNER JOIN TeamProInfo ON TeamProStat.Number = TeamProInfo.Number) INNER JOIN RankingOrder ON TeamProStat.Number = RankingOrder.TeamProNumber WHERE (((RankingOrder.Type)=0)) ORDER BY RankingOrder.TeamOrder";
}
}elseif(isset($_GET['StandingFarm']) OR isset($_POST['StandingFarm'])){
/* StandingFarm */
If ($Conference == 1 OR $Conference == 2){
/* Conference */
$Query = "SELECT TeamFarmStat.*, TeamFarmInfo.Conference, TeamFarmInfo.Division, TeamFarmInfo.ConferenceNumber, TeamFarmInfo.DivisionNumber, TeamFarmInfo.TeamThemeID, RankingOrder.Type FROM (TeamFarmStat INNER JOIN TeamFarmInfo ON TeamFarmStat.Number = TeamFarmInfo.Number) INNER JOIN RankingOrder ON TeamFarmStat.Number = RankingOrder.TeamFarmNumber WHERE (((RankingOrder.Type)=" . $Conference . ")) ORDER BY RankingOrder.TeamOrder";
}elseif ($Division == 1 OR $Division == 2 OR $Division == 3 OR $Division == 4 OR $Division == 5 OR $Division == 6){
/* Division */
$Query = "SELECT TeamFarmStat.*, TeamFarmInfo.Conference, TeamFarmInfo.Division, TeamFarmInfo.ConferenceNumber, TeamFarmInfo.DivisionNumber, TeamFarmInfo.TeamThemeID, RankingOrder.Type FROM (TeamFarmStat INNER JOIN TeamFarmInfo ON TeamFarmStat.Number = TeamFarmInfo.Number) INNER JOIN RankingOrder ON TeamFarmStat.Number = RankingOrder.TeamFarmNumber WHERE (((TeamFarmInfo.DivisionNumber)=" . $Division . ") AND ((RankingOrder.Type)=0)) ORDER BY RankingOrder.TeamOrder";
}elseif($Conference > 0 OR $Division > 0){
/* Return Empty */
}else{
/* Overall */
$Query = "SELECT TeamFarmStat.*, TeamFarmInfo.Conference, TeamFarmInfo.Division, TeamFarmInfo.ConferenceNumber, TeamFarmInfo.DivisionNumber, TeamFarmInfo.TeamThemeID, RankingOrder.Type FROM (TeamFarmStat INNER JOIN TeamFarmInfo ON TeamFarmStat.Number = TeamFarmInfo.Number) INNER JOIN RankingOrder ON TeamFarmStat.Number = RankingOrder.TeamFarmNumber WHERE (((RankingOrder.Type)=0)) ORDER BY RankingOrder.TeamOrder";
}
}elseif(isset($_GET['PlayoffPro']) OR isset($_POST['PlayoffPro'])){
/* PlayoffPro */
$Query = "SELECT PlayoffPro.*, TeamInfoHome.Conference as ConferenceName, TeamInfoHome.Division as DivisionName, TeamInfoHome.Name as HomeTeamName, TeamInfoVisitor.Name as VisitorTeamName, TeamInfoHome.TeamThemeID as HomeThemID, TeamInfoVisitor.TeamThemeID as VisitorThemID FROM (PlayoffPro INNER JOIN TeamProInfo AS TeamInfoHome ON PlayoffPro.HomeTeam = TeamInfoHome.Number) LEFT JOIN TeamProInfo AS TeamInfoVisitor ON PlayoffPro.VisitorTeam = TeamInfoVisitor.Number";
}elseif(isset($_GET['PlayoffFarm']) OR isset($_POST['PlayoffFarm'])){
/* PlayoffFarm */
$Query = "SELECT PlayoffFarm.*, TeamInfoHome.Conference as ConferenceName, TeamInfoHome.Division as DivisionName, TeamInfoHome.Name as HomeTeamName, TeamInfoVisitor.Name as VisitorTeamName, TeamInfoHome.TeamThemeID as HomeThemID, TeamInfoVisitor.TeamThemeID as VisitorThemID FROM (PlayoffFarm INNER JOIN TeamFarmInfo AS TeamInfoHome ON PlayoffFarm.HomeTeam = TeamInfoHome.Number) LEFT JOIN TeamFarmInfo AS TeamInfoVisitor ON PlayoffFarm.VisitorTeam = TeamInfoVisitor.Number";
}elseif(isset($_GET['TodayGame']) OR isset($_POST['TodayGame'])){
/* TodayGame */
$Query = "SELECT TodayGame.*, substr(TodayGame.GameNumber,1,3) AS Type FROM TodayGame ORDER BY TYPE DESC, GameNumber";
}elseif(isset($_GET['TodayGamePro']) OR isset($_POST['TodayGamePro'])){
/* TodayGamePro */
$Query = "SELECT TodayGame.* FROM TodayGame WHERE TodayGame.GameNumber Like 'Pro%'";
}elseif(isset($_GET['TodayGameFarm']) OR isset($_POST['TodayGameFarm'])){
/* TodayGameFarm*/
$Query = "SELECT TodayGame.* FROM TodayGame WHERE TodayGame.GameNumber Like 'Farm%'";
}elseif(isset($_GET['TeamStatPro']) OR isset($_POST['TeamStatPro'])){
/* TeamStatPro */
If ($Team == -1){
$Query = "SELECT MainTable.* FROM (SELECT TeamProStat.Number as Number, TeamProStat.Name as Name, TeamProStat.Name as OrderName, TeamProStat.TeamThemeID as TeamThemeID, TeamProStat.GP AS GP, TeamProStat.W AS W, TeamProStat.L AS L, TeamProStat.T AS T, TeamProStat.OTW AS OTW, TeamProStat.OTL AS OTL, TeamProStat.SOW AS SOW, TeamProStat.SOL AS SOL, TeamProStat.Points AS Points, TeamProStat.GF AS GF, TeamProStat.GA AS GA, TeamProStat.HomeGP AS HomeGP, TeamProStat.HomeW AS HomeW, TeamProStat.HomeL AS HomeL, TeamProStat.HomeT AS HomeT, TeamProStat.HomeOTW AS HomeOTW, TeamProStat.HomeOTL AS HomeOTL, TeamProStat.HomeSOW AS HomeSOW, TeamProStat.HomeSOL AS HomeSOL, TeamProStat.HomeGF AS HomeGF, TeamProStat.HomeGA AS HomeGA, TeamProStat.PPAttemp AS PPAttemp, TeamProStat.PPGoal AS PPGoal, TeamProStat.PKAttemp AS PKAttemp, TeamProStat.PKGoalGA AS PKGoalGA, TeamProStat.PKGoalGF AS PKGoalGF, TeamProStat.ShotsFor AS ShotsFor, TeamProStat.ShotsAga AS ShotsAga, TeamProStat.ShotsBlock AS ShotsBlock, TeamProStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStat.Shutouts AS Shutouts, TeamProStat.TotalGoal AS TotalGoal, TeamProStat.TotalAssist AS TotalAssist, TeamProStat.TotalPoint AS TotalPoint, TeamProStat.Pim AS Pim, TeamProStat.Hits AS Hits, TeamProStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStat.EmptyNetGoal AS EmptyNetGoal FROM TeamProStat UNION ALL SELECT 105 as Number, '<strong>Average</strong>' as Name,'ZZZZZZZZZZZZZ' as OrderName, '0' As TeamThemeID, Round(AVG(TeamProStat.GP),2) AS GP, Round(AVG(TeamProStat.W),2) AS W, Round(AVG(TeamProStat.L),2) AS L, Round(AVG(TeamProStat.T),2) AS T, Round(AVG(TeamProStat.OTW),2) AS OTW, Round(AVG(TeamProStat.OTL),2) AS OTL, Round(AVG(TeamProStat.SOW),2) AS SOW, Round(AVG(TeamProStat.SOL),2) AS SOL, Round(AVG(TeamProStat.Points),2) AS Points, Round(AVG(TeamProStat.GF),2) AS GF, Round(AVG(TeamProStat.GA),2) AS GA, Round(AVG(TeamProStat.HomeGP),2) AS HomeGP, Round(AVG(TeamProStat.HomeW),2) AS HomeW, Round(AVG(TeamProStat.HomeL),2) AS HomeL, Round(AVG(TeamProStat.HomeT),2) AS HomeT, Round(AVG(TeamProStat.HomeOTW),2) AS HomeOTW, Round(AVG(TeamProStat.HomeOTL),2) AS HomeOTL, Round(AVG(TeamProStat.HomeSOW),2) AS HomeSOW, Round(AVG(TeamProStat.HomeSOL),2) AS HomeSOL, Round(AVG(TeamProStat.HomeGF),2) AS HomeGF, Round(AVG(TeamProStat.HomeGA),2) AS HomeGA, Round(AVG(TeamProStat.PPAttemp),2) AS PPAttemp, Round(AVG(TeamProStat.PPGoal),2) AS PPGoal, Round(AVG(TeamProStat.PKAttemp),2) AS PKAttemp, Round(AVG(TeamProStat.PKGoalGA),2) AS PKGoalGA, Round(AVG(TeamProStat.PKGoalGF),2) AS PKGoalGF, Round(AVG(TeamProStat.ShotsFor),2) AS ShotsFor, Round(AVG(TeamProStat.ShotsAga),2) AS ShotsAga, Round(AVG(TeamProStat.ShotsBlock),2) AS ShotsBlock, Round(AVG(TeamProStat.ShotsPerPeriod1),2) AS ShotsPerPeriod1, Round(AVG(TeamProStat.ShotsPerPeriod2),2) AS ShotsPerPeriod2, Round(AVG(TeamProStat.ShotsPerPeriod3),2) AS ShotsPerPeriod3, Round(AVG(TeamProStat.ShotsPerPeriod4),2) AS ShotsPerPeriod4, Round(AVG(TeamProStat.GoalsPerPeriod1),2) AS GoalsPerPeriod1, Round(AVG(TeamProStat.GoalsPerPeriod2),2) AS GoalsPerPeriod2, Round(AVG(TeamProStat.GoalsPerPeriod3),2) AS GoalsPerPeriod3, Round(AVG(TeamProStat.GoalsPerPeriod4),2) AS GoalsPerPeriod4, Round(AVG(TeamProStat.PuckTimeInZoneDF),2) AS PuckTimeInZoneDF, Round(AVG(TeamProStat.PuckTimeInZoneOF),2) AS PuckTimeInZoneOF, Round(AVG(TeamProStat.PuckTimeInZoneNT),2) AS PuckTimeInZoneNT, Round(AVG(TeamProStat.PuckTimeControlinZoneDF),2) AS PuckTimeControlinZoneDF, Round(AVG(TeamProStat.PuckTimeControlinZoneOF),2) AS PuckTimeControlinZoneOF, Round(AVG(TeamProStat.PuckTimeControlinZoneNT),2) AS PuckTimeControlinZoneNT, Round(AVG(TeamProStat.Shutouts),2) AS Shutouts, Round(AVG(TeamProStat.TotalGoal),2) AS TotalGoal, Round(AVG(TeamProStat.TotalAssist),2) AS TotalAssist, Round(AVG(TeamProStat.TotalPoint),2) AS TotalPoint, Round(AVG(TeamProStat.Pim),2) AS Pim, Round(AVG(TeamProStat.Hits),2) AS Hits, Round(AVG(TeamProStat.FaceOffWonDefensifZone),2) AS FaceOffWonDefensifZone, Round(AVG(TeamProStat.FaceOffTotalDefensifZone),2) AS FaceOffTotalDefensifZone, Round(AVG(TeamProStat.FaceOffWonOffensifZone),2) AS FaceOffWonOffensifZone, Round(AVG(TeamProStat.FaceOffTotalOffensifZone),2) AS FaceOffTotalOffensifZone, Round(AVG(TeamProStat.FaceOffWonNeutralZone),2) AS FaceOffWonNeutralZone, Round(AVG(TeamProStat.FaceOffTotalNeutralZone),2) AS FaceOffTotalNeutralZone, Round(AVG(TeamProStat.EmptyNetGoal),2) AS EmptyNetGoal FROM TeamProStat) AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}else{
$Query = "SELECT MainTable.* FROM (SELECT TeamProStatVS.TeamVSName AS Name, TeamProStatVS.TeamVSNumber AS Number, TeamProStatVS.TeamVSNumberThemeID as TeamThemeID, TeamProStatVS.GP, TeamProStatVS.W, TeamProStatVS.L, TeamProStatVS.T, TeamProStatVS.OTW, TeamProStatVS.OTL, TeamProStatVS.SOW, TeamProStatVS.SOL, TeamProStatVS.Points, TeamProStatVS.GF, TeamProStatVS.GA, TeamProStatVS.HomeGP, TeamProStatVS.HomeW, TeamProStatVS.HomeL, TeamProStatVS.HomeT, TeamProStatVS.HomeOTW, TeamProStatVS.HomeOTL, TeamProStatVS.HomeSOW, TeamProStatVS.HomeSOL, TeamProStatVS.HomeGF, TeamProStatVS.HomeGA, TeamProStatVS.PPAttemp, TeamProStatVS.PPGoal, TeamProStatVS.PKAttemp, TeamProStatVS.PKGoalGA, TeamProStatVS.PKGoalGF, TeamProStatVS.ShotsFor, TeamProStatVS.ShotsAga, TeamProStatVS.ShotsBlock, TeamProStatVS.ShotsPerPeriod1, TeamProStatVS.ShotsPerPeriod2, TeamProStatVS.ShotsPerPeriod3, TeamProStatVS.ShotsPerPeriod4, TeamProStatVS.GoalsPerPeriod1, TeamProStatVS.GoalsPerPeriod2, TeamProStatVS.GoalsPerPeriod3, TeamProStatVS.GoalsPerPeriod4, TeamProStatVS.PuckTimeInZoneDF, TeamProStatVS.PuckTimeInZoneOF, TeamProStatVS.PuckTimeInZoneNT, TeamProStatVS.PuckTimeControlinZoneDF, TeamProStatVS.PuckTimeControlinZoneOF, TeamProStatVS.PuckTimeControlinZoneNT, TeamProStatVS.Shutouts, TeamProStatVS.TotalGoal, TeamProStatVS.TotalAssist, TeamProStatVS.TotalPoint, TeamProStatVS.Pim, TeamProStatVS.Hits, TeamProStatVS.FaceOffWonDefensifZone, TeamProStatVS.FaceOffTotalDefensifZone, TeamProStatVS.FaceOffWonOffensifZone, TeamProStatVS.FaceOffTotalOffensifZone, TeamProStatVS.FaceOffWonNeutralZone, TeamProStatVS.FaceOffTotalNeutralZone, TeamProStatVS.EmptyNetGoal FROM TeamProStatVS WHERE GP > 0 AND TeamNumber = " . $Team . " UNION ALL SELECT 'Total' as Name, '104' as Number, '0' as TeamThemeID, TeamProStat.GP, TeamProStat.W, TeamProStat.L, TeamProStat.T, TeamProStat.OTW, TeamProStat.OTL, TeamProStat.SOW, TeamProStat.SOL, TeamProStat.Points, TeamProStat.GF, TeamProStat.GA, TeamProStat.HomeGP, TeamProStat.HomeW, TeamProStat.HomeL, TeamProStat.HomeT, TeamProStat.HomeOTW, TeamProStat.HomeOTL, TeamProStat.HomeSOW, TeamProStat.HomeSOL, TeamProStat.HomeGF, TeamProStat.HomeGA, TeamProStat.PPAttemp, TeamProStat.PPGoal, TeamProStat.PKAttemp, TeamProStat.PKGoalGA, TeamProStat.PKGoalGF, TeamProStat.ShotsFor, TeamProStat.ShotsAga, TeamProStat.ShotsBlock, TeamProStat.ShotsPerPeriod1, TeamProStat.ShotsPerPeriod2, TeamProStat.ShotsPerPeriod3, TeamProStat.ShotsPerPeriod4, TeamProStat.GoalsPerPeriod1, TeamProStat.GoalsPerPeriod2, TeamProStat.GoalsPerPeriod3, TeamProStat.GoalsPerPeriod4, TeamProStat.PuckTimeInZoneDF, TeamProStat.PuckTimeInZoneOF, TeamProStat.PuckTimeInZoneNT, TeamProStat.PuckTimeControlinZoneDF, TeamProStat.PuckTimeControlinZoneOF, TeamProStat.PuckTimeControlinZoneNT, TeamProStat.Shutouts, TeamProStat.TotalGoal, TeamProStat.TotalAssist, TeamProStat.TotalPoint, TeamProStat.Pim, TeamProStat.Hits, TeamProStat.FaceOffWonDefensifZone, TeamProStat.FaceOffTotalDefensifZone, TeamProStat.FaceOffWonOffensifZone, TeamProStat.FaceOffTotalOffensifZone, TeamProStat.FaceOffWonNeutralZone, TeamProStat.FaceOffTotalNeutralZone, TeamProStat.EmptyNetGoal FROM TeamProStat WHERE Number = " . $Team . ") AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}
}elseif(isset($_GET['TeamStatFarm']) OR isset($_POST['TeamStateFarm'])){
/* TeamStatFarm */
If ($Team == -1){
$Query = "SELECT MainTable.* FROM (SELECT TeamFarmStat.Number as Number, TeamFarmStat.Name as Name, TeamFarmStat.Name as OrderName, TeamFarmStat.TeamThemeID as TeamThemeID, TeamFarmStat.GP AS GP, TeamFarmStat.W AS W, TeamFarmStat.L AS L, TeamFarmStat.T AS T, TeamFarmStat.OTW AS OTW, TeamFarmStat.OTL AS OTL, TeamFarmStat.SOW AS SOW, TeamFarmStat.SOL AS SOL, TeamFarmStat.Points AS Points, TeamFarmStat.GF AS GF, TeamFarmStat.GA AS GA, TeamFarmStat.HomeGP AS HomeGP, TeamFarmStat.HomeW AS HomeW, TeamFarmStat.HomeL AS HomeL, TeamFarmStat.HomeT AS HomeT, TeamFarmStat.HomeOTW AS HomeOTW, TeamFarmStat.HomeOTL AS HomeOTL, TeamFarmStat.HomeSOW AS HomeSOW, TeamFarmStat.HomeSOL AS HomeSOL, TeamFarmStat.HomeGF AS HomeGF, TeamFarmStat.HomeGA AS HomeGA, TeamFarmStat.PPAttemp AS PPAttemp, TeamFarmStat.PPGoal AS PPGoal, TeamFarmStat.PKAttemp AS PKAttemp, TeamFarmStat.PKGoalGA AS PKGoalGA, TeamFarmStat.PKGoalGF AS PKGoalGF, TeamFarmStat.ShotsFor AS ShotsFor, TeamFarmStat.ShotsAga AS ShotsAga, TeamFarmStat.ShotsBlock AS ShotsBlock, TeamFarmStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStat.Shutouts AS Shutouts, TeamFarmStat.TotalGoal AS TotalGoal, TeamFarmStat.TotalAssist AS TotalAssist, TeamFarmStat.TotalPoint AS TotalPoint, TeamFarmStat.Pim AS Pim, TeamFarmStat.Hits AS Hits, TeamFarmStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStat.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStat UNION ALL SELECT 105 as Number, '<strong>Average</strong>' as Name,'ZZZZZZZZZZZZZ' as OrderName, '0' As TeamThemeID, Round(AVG(TeamFarmStat.GP),2) AS GP, Round(AVG(TeamFarmStat.W),2) AS W, Round(AVG(TeamFarmStat.L),2) AS L, Round(AVG(TeamFarmStat.T),2) AS T, Round(AVG(TeamFarmStat.OTW),2) AS OTW, Round(AVG(TeamFarmStat.OTL),2) AS OTL, Round(AVG(TeamFarmStat.SOW),2) AS SOW, Round(AVG(TeamFarmStat.SOL),2) AS SOL, Round(AVG(TeamFarmStat.Points),2) AS Points, Round(AVG(TeamFarmStat.GF),2) AS GF, Round(AVG(TeamFarmStat.GA),2) AS GA, Round(AVG(TeamFarmStat.HomeGP),2) AS HomeGP, Round(AVG(TeamFarmStat.HomeW),2) AS HomeW, Round(AVG(TeamFarmStat.HomeL),2) AS HomeL, Round(AVG(TeamFarmStat.HomeT),2) AS HomeT, Round(AVG(TeamFarmStat.HomeOTW),2) AS HomeOTW, Round(AVG(TeamFarmStat.HomeOTL),2) AS HomeOTL, Round(AVG(TeamFarmStat.HomeSOW),2) AS HomeSOW, Round(AVG(TeamFarmStat.HomeSOL),2) AS HomeSOL, Round(AVG(TeamFarmStat.HomeGF),2) AS HomeGF, Round(AVG(TeamFarmStat.HomeGA),2) AS HomeGA, Round(AVG(TeamFarmStat.PPAttemp),2) AS PPAttemp, Round(AVG(TeamFarmStat.PPGoal),2) AS PPGoal, Round(AVG(TeamFarmStat.PKAttemp),2) AS PKAttemp, Round(AVG(TeamFarmStat.PKGoalGA),2) AS PKGoalGA, Round(AVG(TeamFarmStat.PKGoalGF),2) AS PKGoalGF, Round(AVG(TeamFarmStat.ShotsFor),2) AS ShotsFor, Round(AVG(TeamFarmStat.ShotsAga),2) AS ShotsAga, Round(AVG(TeamFarmStat.ShotsBlock),2) AS ShotsBlock, Round(AVG(TeamFarmStat.ShotsPerPeriod1),2) AS ShotsPerPeriod1, Round(AVG(TeamFarmStat.ShotsPerPeriod2),2) AS ShotsPerPeriod2, Round(AVG(TeamFarmStat.ShotsPerPeriod3),2) AS ShotsPerPeriod3, Round(AVG(TeamFarmStat.ShotsPerPeriod4),2) AS ShotsPerPeriod4, Round(AVG(TeamFarmStat.GoalsPerPeriod1),2) AS GoalsPerPeriod1, Round(AVG(TeamFarmStat.GoalsPerPeriod2),2) AS GoalsPerPeriod2, Round(AVG(TeamFarmStat.GoalsPerPeriod3),2) AS GoalsPerPeriod3, Round(AVG(TeamFarmStat.GoalsPerPeriod4),2) AS GoalsPerPeriod4, Round(AVG(TeamFarmStat.PuckTimeInZoneDF),2) AS PuckTimeInZoneDF, Round(AVG(TeamFarmStat.PuckTimeInZoneOF),2) AS PuckTimeInZoneOF, Round(AVG(TeamFarmStat.PuckTimeInZoneNT),2) AS PuckTimeInZoneNT, Round(AVG(TeamFarmStat.PuckTimeControlinZoneDF),2) AS PuckTimeControlinZoneDF, Round(AVG(TeamFarmStat.PuckTimeControlinZoneOF),2) AS PuckTimeControlinZoneOF, Round(AVG(TeamFarmStat.PuckTimeControlinZoneNT),2) AS PuckTimeControlinZoneNT, Round(AVG(TeamFarmStat.Shutouts),2) AS Shutouts, Round(AVG(TeamFarmStat.TotalGoal),2) AS TotalGoal, Round(AVG(TeamFarmStat.TotalAssist),2) AS TotalAssist, Round(AVG(TeamFarmStat.TotalPoint),2) AS TotalPoint, Round(AVG(TeamFarmStat.Pim),2) AS Pim, Round(AVG(TeamFarmStat.Hits),2) AS Hits, Round(AVG(TeamFarmStat.FaceOffWonDefensifZone),2) AS FaceOffWonDefensifZone, Round(AVG(TeamFarmStat.FaceOffTotalDefensifZone),2) AS FaceOffTotalDefensifZone, Round(AVG(TeamFarmStat.FaceOffWonOffensifZone),2) AS FaceOffWonOffensifZone, Round(AVG(TeamFarmStat.FaceOffTotalOffensifZone),2) AS FaceOffTotalOffensifZone, Round(AVG(TeamFarmStat.FaceOffWonNeutralZone),2) AS FaceOffWonNeutralZone, Round(AVG(TeamFarmStat.FaceOffTotalNeutralZone),2) AS FaceOffTotalNeutralZone, Round(AVG(TeamFarmStat.EmptyNetGoal),2) AS EmptyNetGoal FROM TeamFarmStat) AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}else{
$Query = "SELECT MainTable.* FROM (SELECT TeamFarmStatVS.TeamVSName AS Name, TeamFarmStatVS.TeamVSNumber AS Number, TeamFarmStatVS.TeamVSNumberThemeID as TeamThemeID, TeamFarmStatVS.GP, TeamFarmStatVS.W, TeamFarmStatVS.L, TeamFarmStatVS.T, TeamFarmStatVS.OTW, TeamFarmStatVS.OTL, TeamFarmStatVS.SOW, TeamFarmStatVS.SOL, TeamFarmStatVS.Points, TeamFarmStatVS.GF, TeamFarmStatVS.GA, TeamFarmStatVS.HomeGP, TeamFarmStatVS.HomeW, TeamFarmStatVS.HomeL, TeamFarmStatVS.HomeT, TeamFarmStatVS.HomeOTW, TeamFarmStatVS.HomeOTL, TeamFarmStatVS.HomeSOW, TeamFarmStatVS.HomeSOL, TeamFarmStatVS.HomeGF, TeamFarmStatVS.HomeGA, TeamFarmStatVS.PPAttemp, TeamFarmStatVS.PPGoal, TeamFarmStatVS.PKAttemp, TeamFarmStatVS.PKGoalGA, TeamFarmStatVS.PKGoalGF, TeamFarmStatVS.ShotsFor, TeamFarmStatVS.ShotsAga, TeamFarmStatVS.ShotsBlock, TeamFarmStatVS.ShotsPerPeriod1, TeamFarmStatVS.ShotsPerPeriod2, TeamFarmStatVS.ShotsPerPeriod3, TeamFarmStatVS.ShotsPerPeriod4, TeamFarmStatVS.GoalsPerPeriod1, TeamFarmStatVS.GoalsPerPeriod2, TeamFarmStatVS.GoalsPerPeriod3, TeamFarmStatVS.GoalsPerPeriod4, TeamFarmStatVS.PuckTimeInZoneDF, TeamFarmStatVS.PuckTimeInZoneOF, TeamFarmStatVS.PuckTimeInZoneNT, TeamFarmStatVS.PuckTimeControlinZoneDF, TeamFarmStatVS.PuckTimeControlinZoneOF, TeamFarmStatVS.PuckTimeControlinZoneNT, TeamFarmStatVS.Shutouts, TeamFarmStatVS.TotalGoal, TeamFarmStatVS.TotalAssist, TeamFarmStatVS.TotalPoint, TeamFarmStatVS.Pim, TeamFarmStatVS.Hits, TeamFarmStatVS.FaceOffWonDefensifZone, TeamFarmStatVS.FaceOffTotalDefensifZone, TeamFarmStatVS.FaceOffWonOffensifZone, TeamFarmStatVS.FaceOffTotalOffensifZone, TeamFarmStatVS.FaceOffWonNeutralZone, TeamFarmStatVS.FaceOffTotalNeutralZone, TeamFarmStatVS.EmptyNetGoal FROM TeamFarmStatVS WHERE GP > 0 AND TeamNumber = " . $Team . " UNION ALL SELECT 'Total' as Name, '104' as Number, '0' as TeamThemeID, TeamFarmStat.GP, TeamFarmStat.W, TeamFarmStat.L, TeamFarmStat.T, TeamFarmStat.OTW, TeamFarmStat.OTL, TeamFarmStat.SOW, TeamFarmStat.SOL, TeamFarmStat.Points, TeamFarmStat.GF, TeamFarmStat.GA, TeamFarmStat.HomeGP, TeamFarmStat.HomeW, TeamFarmStat.HomeL, TeamFarmStat.HomeT, TeamFarmStat.HomeOTW, TeamFarmStat.HomeOTL, TeamFarmStat.HomeSOW, TeamFarmStat.HomeSOL, TeamFarmStat.HomeGF, TeamFarmStat.HomeGA, TeamFarmStat.PPAttemp, TeamFarmStat.PPGoal, TeamFarmStat.PKAttemp, TeamFarmStat.PKGoalGA, TeamFarmStat.PKGoalGF, TeamFarmStat.ShotsFor, TeamFarmStat.ShotsAga, TeamFarmStat.ShotsBlock, TeamFarmStat.ShotsPerPeriod1, TeamFarmStat.ShotsPerPeriod2, TeamFarmStat.ShotsPerPeriod3, TeamFarmStat.ShotsPerPeriod4, TeamFarmStat.GoalsPerPeriod1, TeamFarmStat.GoalsPerPeriod2, TeamFarmStat.GoalsPerPeriod3, TeamFarmStat.GoalsPerPeriod4, TeamFarmStat.PuckTimeInZoneDF, TeamFarmStat.PuckTimeInZoneOF, TeamFarmStat.PuckTimeInZoneNT, TeamFarmStat.PuckTimeControlinZoneDF, TeamFarmStat.PuckTimeControlinZoneOF, TeamFarmStat.PuckTimeControlinZoneNT, TeamFarmStat.Shutouts, TeamFarmStat.TotalGoal, TeamFarmStat.TotalAssist, TeamFarmStat.TotalPoint, TeamFarmStat.Pim, TeamFarmStat.Hits, TeamFarmStat.FaceOffWonDefensifZone, TeamFarmStat.FaceOffTotalDefensifZone, TeamFarmStat.FaceOffWonOffensifZone, TeamFarmStat.FaceOffTotalOffensifZone, TeamFarmStat.FaceOffWonNeutralZone, TeamFarmStat.FaceOffTotalNeutralZone, TeamFarmStat.EmptyNetGoal FROM TeamFarmStat WHERE Number = " . $Team . ") AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}
}elseif(isset($_GET['PlayerInfo']) OR isset($_POST['PlayerInfo'])){
/* PlayerInfo */
/* FreeAgent has priority over Expansion who has priority over Available for Trade */
If ($Team >= 0){
$TeamQuery = "Team = " . $Team;
}else{
$TeamQuery = "Team >= 0"; /* Default Place Order Where everything will return */
}
if($Type == 1){
$TypeQuery = "Status1 >= 2";
}elseif($Type == 2){
$TypeQuery = "Status1 <= 1";
}else{
$TypeQuery = "Number > 0"; /* Default Place Order Where everything will return */
}
$Query = "SELECT MainTable.* FROM (SELECT PlayerInfo.Number, PlayerInfo.Name, PlayerInfo.Team, PlayerInfo.TeamName, PlayerInfo.ProTeamName, PlayerInfo.TeamThemeID, PlayerInfo.Age, PlayerInfo.AgeDate, PlayerInfo.Country, PlayerInfo.Weight, PlayerInfo.Height, PlayerInfo.Contract, PlayerInfo.Rookie, PlayerInfo.NoTrade, PlayerInfo.CanPlayPro, PlayerInfo.CanPlayFarm, PlayerInfo.ForceWaiver, PlayerInfo.WaiverPossible, PlayerInfo.ExcludeSalaryCap, PlayerInfo.ProSalaryinFarm, PlayerInfo.SalaryAverage, PlayerInfo.Salary1, PlayerInfo.Salary2, PlayerInfo.Salary3, PlayerInfo.Salary4, PlayerInfo.Salary5, PlayerInfo.Salary6, PlayerInfo.Salary7, PlayerInfo.Salary8, PlayerInfo.Salary9, PlayerInfo.Salary10, PlayerInfo.SalaryCap1, PlayerInfo.SalaryCap2, PlayerInfo.SalaryCap3, PlayerInfo.SalaryCap4, PlayerInfo.SalaryCap5, PlayerInfo.SalaryCap6, PlayerInfo.SalaryCap7, PlayerInfo.SalaryCap8, PlayerInfo.SalaryCap9, PlayerInfo.SalaryCap10, PlayerInfo.NoTrade1, PlayerInfo.NoTrade2, PlayerInfo.NoTrade3, PlayerInfo.NoTrade4, PlayerInfo.NoTrade5, PlayerInfo.NoTrade6, PlayerInfo.NoTrade7, PlayerInfo.NoTrade8, PlayerInfo.NoTrade9, PlayerInfo.NoTrade10, PlayerInfo.SalaryRemaining, PlayerInfo.SalaryCap, PlayerInfo.SalaryCapRemaining, PlayerInfo.Condition, PlayerInfo.ConditionDecimal,PlayerInfo.Status1, PlayerInfo.URLLink, PlayerInfo.NHLID, PlayerInfo.PProtected, PlayerInfo.AvailableForTrade,PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, 'False' AS PosG, PlayerInfo.AcquiredType as AcquiredType, PlayerInfo.LastTradeDate as LastTradeDate, PlayerInfo.ContractSignatureDate As ContractSignatureDate, PlayerInfo.ForceUFA As ForceUFA, PlayerInfo.EmergencyRecall As EmergencyRecall, PlayerInfo.Retire as Retire FROM PlayerInfo WHERE " . $TeamQuery . " AND Retire = " . $Retire . " AND " . $TypeQuery . " UNION ALL SELECT GoalerInfo.Number, GoalerInfo.Name, GoalerInfo.Team, GoalerInfo.TeamName, GoalerInfo.ProTeamName, GoalerInfo.TeamThemeID, GoalerInfo.Age, GoalerInfo.AgeDate, GoalerInfo.Country, GoalerInfo.Weight, GoalerInfo.Height, GoalerInfo.Contract, GoalerInfo.Rookie, GoalerInfo.NoTrade, GoalerInfo.CanPlayPro, GoalerInfo.CanPlayFarm, GoalerInfo.ForceWaiver, GoalerInfo.WaiverPossible, GoalerInfo.ExcludeSalaryCap, GoalerInfo.ProSalaryinFarm, GoalerInfo.SalaryAverage, GoalerInfo.Salary1, GoalerInfo.Salary2, GoalerInfo.Salary3, GoalerInfo.Salary4, GoalerInfo.Salary5, GoalerInfo.Salary6, GoalerInfo.Salary7, GoalerInfo.Salary8, GoalerInfo.Salary9, GoalerInfo.Salary10, GoalerInfo.SalaryCap1, GoalerInfo.SalaryCap2, GoalerInfo.SalaryCap3, GoalerInfo.SalaryCap4, GoalerInfo.SalaryCap5, GoalerInfo.SalaryCap6, GoalerInfo.SalaryCap7, GoalerInfo.SalaryCap8, GoalerInfo.SalaryCap9, GoalerInfo.SalaryCap10, GoalerInfo.NoTrade1, GoalerInfo.NoTrade2, GoalerInfo.NoTrade3, GoalerInfo.NoTrade4, GoalerInfo.NoTrade5, GoalerInfo.NoTrade6, GoalerInfo.NoTrade7, GoalerInfo.NoTrade8, GoalerInfo.NoTrade9, GoalerInfo.NoTrade10, GoalerInfo.SalaryRemaining, GoalerInfo.SalaryCap, GoalerInfo.SalaryCapRemaining, GoalerInfo.Condition, GoalerInfo.ConditionDecimal, GoalerInfo.Status1, GoalerInfo.URLLink, GoalerInfo.NHLID, GoalerInfo.PProtected, GoalerInfo.AvailableForTrade,'False' AS PosC, 'False' AS PosLW, 'False' AS PosRW, 'False' AS PosD, 'True' AS PosG, GoalerInfo.AcquiredType as AcquiredType, GoalerInfo.LastTradeDate as LastTradeDate, GoalerInfo.ContractSignatureDate As ContractSignatureDate, GoalerInfo.ForceUFA As ForceUFA, GoalerInfo.EmergencyRecall As EmergencyRecall, GoalerInfo.Retire as Retire FROM GoalerInfo WHERE " . $TeamQuery . " AND Retire = " . $Retire . " AND " . $TypeQuery . ") AS MainTable";
If ($FreeAgentYear >= 0){
$Query = $Query . " WHERE MainTable.Contract = " . $FreeAgentYear; /* Free Agent Query */
If ($FreeAgentYear == 1){ /* OverWrite to add a Left Join to NextYearFreeAgent */
$Query = "SELECT MainTable.* FROM (SELECT PlayerInfo.Number, PlayerInfo.Name, PlayerInfo.Team, PlayerInfo.TeamName, PlayerInfo.ProTeamName, PlayerInfo.TeamThemeID, PlayerInfo.Age, PlayerInfo.AgeDate, PlayerInfo.Country, PlayerInfo.Weight, PlayerInfo.Height, PlayerInfo.Contract, PlayerInfo.Rookie, PlayerInfo.NoTrade, PlayerInfo.CanPlayPro, PlayerInfo.CanPlayFarm, PlayerInfo.ForceWaiver, PlayerInfo.WaiverPossible, PlayerInfo.ExcludeSalaryCap, PlayerInfo.ProSalaryinFarm, PlayerInfo.SalaryAverage, PlayerInfo.Salary1, PlayerInfo.Salary2, PlayerInfo.Salary3, PlayerInfo.Salary4, PlayerInfo.Salary5, PlayerInfo.Salary6, PlayerInfo.Salary7, PlayerInfo.Salary8, PlayerInfo.Salary9, PlayerInfo.Salary10, PlayerInfo.SalaryCap1, PlayerInfo.SalaryCap2, PlayerInfo.SalaryCap3, PlayerInfo.SalaryCap4, PlayerInfo.SalaryCap5, PlayerInfo.SalaryCap6, PlayerInfo.SalaryCap7, PlayerInfo.SalaryCap8, PlayerInfo.SalaryCap9, PlayerInfo.SalaryCap10, PlayerInfo.NoTrade1, PlayerInfo.NoTrade2, PlayerInfo.NoTrade3, PlayerInfo.NoTrade4, PlayerInfo.NoTrade5, PlayerInfo.NoTrade6, PlayerInfo.NoTrade7, PlayerInfo.NoTrade8, PlayerInfo.NoTrade9, PlayerInfo.NoTrade10, PlayerInfo.SalaryRemaining, PlayerInfo.SalaryCap, PlayerInfo.SalaryCapRemaining, PlayerInfo.Condition, PlayerInfo.ConditionDecimal,PlayerInfo.Status1, PlayerInfo.URLLink, PlayerInfo.NHLID, PlayerInfo.AvailableForTrade,PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, 'False' AS PosG, PlayerInfo.Retire as Retire, NextYearFreeAgent.PlayerType AS NextYearFreeAgentPlayerType, NextYearFreeAgent.Contract as NextYearFreeAgentContract, NextYearFreeAgent.Salary as NextYearFreeAgentSalary FROM PlayerInfo LEFT JOIN NextYearFreeAgent ON PlayerInfo.Number = NextYearFreeAgent.Number WHERE PlayerInfo." . $TeamQuery . " AND Retire = " . $Retire . " AND PlayerInfo." . $TypeQuery . " AND NextYearFreeAgentContract IS NULL UNION ALL SELECT GoalerInfo.Number, GoalerInfo.Name, GoalerInfo.Team, GoalerInfo.TeamName, GoalerInfo.ProTeamName, GoalerInfo.TeamThemeID, GoalerInfo.Age, GoalerInfo.AgeDate, GoalerInfo.Country, GoalerInfo.Weight, GoalerInfo.Height, GoalerInfo.Contract, GoalerInfo.Rookie, GoalerInfo.NoTrade, GoalerInfo.CanPlayPro, GoalerInfo.CanPlayFarm, GoalerInfo.ForceWaiver, GoalerInfo.WaiverPossible, GoalerInfo.ExcludeSalaryCap, GoalerInfo.ProSalaryinFarm, GoalerInfo.SalaryAverage, GoalerInfo.Salary1, GoalerInfo.Salary2, GoalerInfo.Salary3, GoalerInfo.Salary4, GoalerInfo.Salary5, GoalerInfo.Salary6, GoalerInfo.Salary7, GoalerInfo.Salary8, GoalerInfo.Salary9, GoalerInfo.Salary10, GoalerInfo.SalaryCap1, GoalerInfo.SalaryCap2, GoalerInfo.SalaryCap3, GoalerInfo.SalaryCap4, GoalerInfo.SalaryCap5, GoalerInfo.SalaryCap6, GoalerInfo.SalaryCap7, GoalerInfo.SalaryCap8, GoalerInfo.SalaryCap9, GoalerInfo.SalaryCap10, GoalerInfo.NoTrade1, GoalerInfo.NoTrade2, GoalerInfo.NoTrade3, GoalerInfo.NoTrade4, GoalerInfo.NoTrade5, GoalerInfo.NoTrade6, GoalerInfo.NoTrade7, GoalerInfo.NoTrade8, GoalerInfo.NoTrade9, GoalerInfo.NoTrade10, GoalerInfo.SalaryRemaining, GoalerInfo.SalaryCap, GoalerInfo.SalaryCapRemaining, GoalerInfo.Condition, GoalerInfo.ConditionDecimal, GoalerInfo.Status1, GoalerInfo.URLLink, GoalerInfo.NHLID, GoalerInfo.AvailableForTrade,'False' AS PosC, 'False' AS PosLW, 'False' AS PosRW, 'False' AS PosD, 'True' AS PosG, GoalerInfo.Retire as Retire, NextYearFreeAgent.PlayerType AS NextYearFreeAgentPlayerType, NextYearFreeAgent.Contract as NextYearFreeAgentContract, NextYearFreeAgent.Salary as NextYearFreeAgentSalary FROM GoalerInfo LEFT JOIN NextYearFreeAgent ON GoalerInfo.Number = NextYearFreeAgent.Number WHERE GoalerInfo." . $TeamQuery . " AND Retire = " . $Retire . " AND GoalerInfo." . $TypeQuery . " AND NextYearFreeAgentContract IS NULL) AS MainTable WHERE MainTable.Contract = " . $FreeAgentYear;
}
}elseif($AvailableForTrade == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " WHERE MainTable.Team > 0";}
$Query = $Query . " AND MainTable.AvailableForTrade = 'True'";
}elseif($Expansion == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " WHERE MainTable.Team > 0";}
$Query = $Query . " AND MainTable.PProtected = 'False'";
}
$Query = $Query . " ORDER BY MainTable.Name ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['PlayerRoster']) OR isset($_POST['PlayerRoster'])){
/* PlayerRoster */
If ($FreeAgentYear == 1){
$Query = "SELECT PlayerInfo.*, NextYearFreeAgent.PlayerType AS NextYearFreeAgentPlayerType, NextYearFreeAgent.Contract as NextYearFreeAgentContract, NextYearFreeAgent.Salary as NextYearFreeAgentSalary FROM PlayerInfo LEFT JOIN NextYearFreeAgent ON PlayerInfo.Number = NextYearFreeAgent.Number WHERE Retire = 'False' AND NextYearFreeAgentContract IS NULL";
}else{
$Query = "SELECT * FROM PlayerInfo WHERE Retire = " . $Retire;
}
if ($PlayerUniqueID > -1){
$Query = $Query . " AND PlayerInfo.UniqueID = " . $PlayerUniqueID ;
}elseif($Team > 0 And $Retire == "'False'"){
$Query = $Query . " AND PlayerInfo.Team = " . $Team;
}else{
if($Type == 1 Or $Type == 2){$Query = $Query . " AND PlayerInfo.Number > 0";}
}
if($Type == 1){
$Query = $Query . " AND PlayerInfo.Status1 >= 2";
}elseif($Type == 2){
$Query = $Query . " AND PlayerInfo.Status1 <= 1";
}
If ($Retire == "'False'"){
If ($FreeAgentYear >= 0){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND PlayerInfo.Team > 0";}
$Query = $Query . " AND PlayerInfo.Contract = " . $FreeAgentYear; /* Free Agent Query */
}elseif($AvailableForTrade == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND PlayerInfo.Team > 0";}
$Query = $Query . " AND PlayerInfo.AvailableForTrade = 'True'";
}elseif($Injury == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND PlayerInfo.Team > 0";}
$Query = $Query . " AND (PlayerInfo.Condition < '95' OR PlayerInfo.Suspension > '1')";
}elseif($Expansion == TRUE){
$Query = $Query . " AND PlayerInfo.PProtected = 'False'";
}
}
$Query = $Query . " ORDER BY Overall";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['GoalerRoster']) OR isset($_POST['GoalerRoster'])){
/* GoalerRoster */
If ($FreeAgentYear == 1){
$Query = "SELECT GoalerInfo.*, NextYearFreeAgent.PlayerType AS NextYearFreeAgentPlayerType, NextYearFreeAgent.Contract as NextYearFreeAgentContract, NextYearFreeAgent.Salary as NextYearFreeAgentSalary FROM GoalerInfo LEFT JOIN NextYearFreeAgent ON GoalerInfo.Number = NextYearFreeAgent.Number WHERE Retire = 'False' AND NextYearFreeAgentContract IS NULL";
}else{
$Query = "SELECT * FROM GoalerInfo WHERE Retire = " . $Retire;
}
if ($PlayerUniqueID > -1){
$Query = $Query . " AND GoalerInfo.UniqueID = " . $PlayerUniqueID;
}elseif($Team > 0 And $Retire == "'False'"){
$Query = $Query . " AND GoalerInfo.Team = " . $Team;
}else{
if($Type == 1 Or $Type == 2 ){$Query = $Query . " AND GoalerInfo.Number > 0";}
}
if($Type == 1){
$Query = $Query . " AND GoalerInfo.Status1 >= 2";
}elseif($Type == 2){
$Query = $Query . " AND GoalerInfo.Status1 <= 1";
}
If ($Retire == "'False'"){
If ($FreeAgentYear >= 0){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND GoalerInfo.Team > 0";}
$Query = $Query . " AND GoalerInfo.Contract = " . $FreeAgentYear; /* Free Agent Query */
}elseif($Expansion == TRUE){
$Query = $Query . " AND GoalerInfo.PProtected = 'False'";
}elseif($AvailableForTrade == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND GoalerInfo.Team > 0";}
$Query = $Query . " AND GoalerInfo.AvailableForTrade = 'True'";
}elseif($Injury == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND GoalerInfo.Team > 0";}
$Query = $Query . " AND (GoalerInfo.Condition < '95' OR GoalerInfo.Suspension > '1')";
}
}
$Query = $Query . " ORDER BY Overall";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['PlayerStatPro']) OR isset($_POST['PlayerStatPro'])){
/* PlayerStatPro */
$Query = "SELECT PlayerProStat.*, PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, PlayerInfo.TeamName, PlayerInfo.TeamThemeID, ROUND((CAST(PlayerProStat.G AS REAL) / (PlayerProStat.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStat.SecondPlay AS REAL) / 60 / (PlayerProStat.GP)),2) AS AMG,ROUND((CAST(PlayerProStat.FaceOffWon AS REAL) / (PlayerProStat.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStat.P AS REAL) / (PlayerProStat.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfo INNER JOIN PlayerProStat ON PlayerInfo.Number = PlayerProStat.Number WHERE PlayerInfo.Retire = 'False' AND PlayerProStat.GP >= " . $MinimumGP;
if($PlayerUniqueID > -1){$Query = $Query . " AND PlayerInfo.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND PlayerInfo.Team = " . $Team;}
$Query = $Query . " ORDER BY PlayerProStat.P DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['PlayerStatFarm']) OR isset($_POST['PlayerStatFarm'])){
/* PlayerStatFarm */
$Query = "SELECT PlayerFarmStat.*, PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, PlayerInfo.TeamName, PlayerInfo.TeamThemeID, ROUND((CAST(PlayerFarmStat.G AS REAL) / (PlayerFarmStat.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStat.SecondPlay AS REAL) / 60 / (PlayerFarmStat.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStat.FaceOffWon AS REAL) / (PlayerFarmStat.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStat.P AS REAL) / (PlayerFarmStat.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfo INNER JOIN PlayerFarmStat ON PlayerInfo.Number = PlayerFarmStat.Number WHERE PlayerInfo.Retire = 'False' AND PlayerFarmStat.GP >= " . $MinimumGP;
if($PlayerUniqueID > -1){$Query = $Query . " AND PlayerInfo.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND PlayerInfo.Team = " . $Team;}
$Query = $Query . " ORDER BY PlayerFarmStat.P DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['GoalerStatPro']) OR isset($_POST['GoalerStatPro'])){
/* GoalerStatPro */
$Query = "SELECT GoalerInfo.TeamName, GoalerInfo.TeamThemeID, GoalerProStat.*, ROUND((CAST(GoalerProStat.GA AS REAL) / (GoalerProStat.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerProStat.SA - GoalerProStat.GA AS REAL) / (GoalerProStat.SA)),3) AS PCT, ROUND((CAST(GoalerProStat.PenalityShotsShots - GoalerProStat.PenalityShotsGoals AS REAL) / (GoalerProStat.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfo INNER JOIN GoalerProStat ON GoalerInfo.Number = GoalerProStat.Number WHERE GoalerInfo.Retire = 'False' AND GoalerProStat.GP >= " . $MinimumGP;
if($PlayerUniqueID > -1){$Query = $Query . " AND GoalerInfo.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND GoalerInfo.Team = " . $Team;}
$Query = $Query . " ORDER BY GoalerProStat.W DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['GoalerStatFarm']) OR isset($_POST['GoalerStatFarm'])){
/* GoalerStatFarm */
$Query = "SELECT GoalerInfo.TeamName, GoalerInfo.TeamThemeID, GoalerFarmStat.*, ROUND((CAST(GoalerFarmStat.GA AS REAL) / (GoalerFarmStat.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerFarmStat.SA - GoalerFarmStat.GA AS REAL) / (GoalerFarmStat.SA)),3) AS PCT, ROUND((CAST(GoalerFarmStat.PenalityShotsShots - GoalerFarmStat.PenalityShotsGoals AS REAL) / (GoalerFarmStat.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfo INNER JOIN GoalerFarmStat ON GoalerInfo.Number = GoalerFarmStat.Number WHERE GoalerInfo.Retire = 'False' AND GoalerFarmStat.GP >= " . $MinimumGP;
if($PlayerUniqueID > -1){$Query = $Query . " AND GoalerInfo.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND GoalerInfo.Team = " . $Team;}
$Query = $Query . " ORDER BY GoalerFarmStat.W DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['EntryDraftProjection']) OR isset($_POST['EntryDraftProjection'])){
/* EntryDraftProjection */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted from LeagueGeneral";
$LeagueGeneralEntryDraftProjection = $dbTemp->querySingle($QueryTemp,true);
if ($LeagueGeneralEntryDraftProjection['PlayOffStarted'] == "False"){
$Query = "SELECT MainTable.*, DraftPick.*, TeamProInfo.Name AS CurrentTeam, TeamProInfo.TeamThemeID As CurrentTeamThemeID FROM ((SELECT TeamProInfo.Number, TeamProInfo.Name AS OriginalTeam, TeamProInfo.TeamThemeID As OriginalTeamThemeID, RankingOrder.TeamOrder FROM TeamProInfo LEFT JOIN RankingOrder ON TeamProInfo.Number = RankingOrder.TeamProNumber WHERE RankingOrder.Type=0 ORDER BY TeamOrder DESC) AS MainTable LEFT JOIN DraftPick ON MainTable.Number = DraftPick.FromTeam) INNER JOIN TeamProInfo ON DraftPick.TeamNumber = TeamProInfo.Number WHERE DraftPick.Year = " . ($LeagueGeneralEntryDraftProjection['LeagueYearOutput'] + 1) . " ORDER BY DraftPick.Round, MainTable.TeamOrder DESC";
}else{
$Query = "SELECT MainTable.*, DraftPick.*, TeamProInfo.Name AS CurrentTeam, TeamProInfo.TeamThemeID As CurrentTeamThemeID FROM ((SELECT TeamProInfo.Number, TeamProInfo.Name AS OriginalTeam, TeamProInfo.TeamThemeID As OriginalTeamThemeID, TeamProInfo.PlayoffEliminated, TeamProInfo.DidNotMakePlayoff, RankingOrder.TeamOrder FROM TeamProInfo LEFT JOIN RankingOrder ON TeamProInfo.Number = RankingOrder.TeamProNumber WHERE RankingOrder.Type=0) AS MainTable LEFT JOIN DraftPick ON MainTable.Number = DraftPick.FromTeam) INNER JOIN TeamProInfo ON DraftPick.TeamNumber = TeamProInfo.Number WHERE DraftPick.Year = " . ($LeagueGeneralEntryDraftProjection['LeagueYearOutput'] + 1) . " ORDER BY DraftPick.Round, MainTable.DidNotMakePlayoff DESC, MainTable.PlayoffEliminated DESC,MainTable.TeamOrder DESC";
}
}elseif(isset($_GET['Waiver']) OR isset($_POST['Waiver'])){
/* Waiver */
$Query = "SELECT Waiver.*, TeamProInfo.Name As FromTeamName, TeamProInfo_ToTeam.Name AS ToTeamName, TeamProInfo.TeamThemeID as FromTeamThemeID, TeamProInfo_ToTeam.TeamThemeID as ToTeamThemeID FROM (Waiver LEFT JOIN TeamProInfo ON Waiver.FromTeam = TeamProInfo.Number) LEFT JOIN TeamProInfo AS TeamProInfo_ToTeam ON Waiver.ToTeam = TeamProInfo_ToTeam.Number ORDER BY Waiver.Player";
}elseif(isset($_GET['WaiverOrder']) OR isset($_POST['WaiverOrder'])){
/* Waiver Order */
$Query = "SELECT WaiverOrder.*, TeamProInfo.Name FROM WaiverOrder LEFT JOIN TeamProInfo ON WaiverOrder.TeamProNumber = TeamProInfo.Number ORDER BY WaiverOrder.Number";
}elseif(isset($_GET['PowerRankingPro']) OR isset($_POST['PowerRankingPro'])){
/* PowerRankingPro */
$Query = "SELECT PowerRankingPro.*, TeamProInfo.Name, TeamProInfo.TeamThemeID FROM PowerRankingPro LEFT JOIN TeamProInfo ON PowerRankingPro.Teams = TeamProInfo.Number ORDER BY PowerRankingPro.TodayRanking;";
}elseif(isset($_GET['PowerRankingFarm']) OR isset($_POST['PowerRankingFarm'])){
/* PowerRankingFarm */
$Query = "SELECT PowerRankingFarm.*, TeamFarmInfo.Name, TeamFarmInfo.TeamThemeID FROM PowerRankingFarm LEFT JOIN TeamFarmInfo ON PowerRankingFarm.Teams = TeamFarmInfo.Number ORDER BY PowerRankingFarm.TodayRanking;";
}elseif(isset($_GET['Transaction']) OR isset($_POST['Transaction'])){
/* Transaction */
if ($Type == 0){
$Query = "SELECT LeagueLog.* FROM LeagueLog ORDER BY LeagueLog.Number DESC";
}else{
$Query = "SELECT LeagueLog.* FROM LeagueLog WHERE TransactionType = " . $Type . " ORDER BY LeagueLog.Number DESC";
}
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['TradeHistory']) OR isset($_POST['TradeHistory'])){
/* TradeHistory */
$Query = "SELECT LeagueLog.* FROM LeagueLog WHERE LeagueLog.TransactionType = 1 ORDER BY LeagueLog.Number DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['TradeLogHistory']) OR isset($_POST['TradeLogHistory'])){
/* TradeLogHistory */
$Query = "SELECT TradeLog.* FROM TradeLog ORDER BY TradeLog.Number ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif((isset($_GET['TeamTransaction']) OR isset($_POST['TeamTransaction'])) AND $Team != 0){
/* TeamTransaction */
$Query = "SELECT TeamLog.*, '' AS Color FROM TeamLog WHERE TeamLog.TeamNumber = " . $Team . " ORDER BY TeamLog.Number DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
}elseif(isset($_GET['DraftPick']) OR isset($_POST['DraftPick'])){
/* DraftPick */
$Query = "SELECT * FROM DraftPick";
if($Team > 0){$Query = $Query . " WHERE TeamNumber = " . $Team; }
$Query = $Query . " ORDER By Year, Round";
}elseif(isset($_GET['TeamProLines']) OR isset($_POST['TeamProLines'])){
/* TeamProLines */
$Query = "SELECT * FROM TeamProLines WHERE";
if($Team > 0){$Query = $Query . " TeamNumber = " . $Team . " AND";}
$Query = $Query . " Day = 1 ORDER BY TeamNumber";
}elseif(isset($_GET['TeamFarmLines']) OR isset($_POST['TeamFarmLines'])){
/* TeamFarmLines */
$Query = "SELECT * FROM TeamFarmLines WHERE";
if($Team > 0){$Query = $Query . " TeamNumber = " . $Team . " AND";}
$Query = $Query . " Day = 1 ORDER BY TeamNumber";
}elseif((isset($_GET['BoxscorePro']) OR isset($_POST['BoxscorePro'])) AND $GameNumber > 0){
/* BoxscorePro */
$dbBoxscore = new SQLite3($DatabaseFile);
$QueryBoxscore = "Select OutputGameJSONToSQLiteDatabase from LeagueOutputOption";
$BoxscoreLeagueOutputOption = $dbBoxscore->querySingle($QueryBoxscore,true);
$QueryBoxscore= "Select LeagueYear from LeagueGeneral";
$BoxscoreLeagueGeneral = $dbBoxscore->querySingle($QueryBoxscore,true);
$Year = $BoxscoreLeagueGeneral['LeagueYear'];
If ($BoxscoreLeagueOutputOption['OutputGameJSONToSQLiteDatabase'] == "True"){
$GameDatabaseFile = str_replace("@-@",$Year."-".floor($GameNumber/200),$GameJSONDatabaseFile);
If (file_exists($GameDatabaseFile) == False){
echo $EmptyReturn;
}else{
$Gamedb = new SQLite3($GameDatabaseFile);
$QueryBoxscore = "Select * from GameResult WHERE Number = '" . $GameNumber . "' AND Pro = 'True'";
$GameResult = $Gamedb ->querySingle($QueryBoxscore,true);
If ($GameResult != Null){
$GameJSON = gzdecode(base64_decode($GameResult['JSON']));
header('Content-type: application/json');
echo $GameJSON;
}else{
echo $EmptyReturn;
}
}
}else{
echo $EmptyReturn;
}
}elseif((isset($_GET['BoxscoreFarm']) OR isset($_POST['BoxscoreFarm'])) AND $GameNumber > 0){
/* BoxscoreFarm */
$dbBoxscore = new SQLite3($DatabaseFile);
$QueryBoxscore = "Select OutputGameJSONToSQLiteDatabase from LeagueOutputOption";
$BoxscoreLeagueOutputOption = $dbBoxscore->querySingle($QueryBoxscore,true);
$QueryBoxscore= "Select LeagueYear from LeagueGeneral";
$BoxscoreLeagueGeneral = $dbBoxscore->querySingle($QueryBoxscore,true);
$Year = $BoxscoreLeagueGeneral['LeagueYear'];
If ($BoxscoreLeagueOutputOption['OutputGameJSONToSQLiteDatabase'] == "True"){
$GameDatabaseFile = str_replace("@-@",$Year."-".floor($GameNumber/200),$GameJSONDatabaseFile);
If (file_exists($GameDatabaseFile) == False){
echo $EmptyReturn;
}else{
$Gamedb = new SQLite3($GameDatabaseFile);
$QueryBoxscore = "Select * from GameResult WHERE Number = '" . $GameNumber . "' AND Pro = 'False'";
$GameResult = $Gamedb ->querySingle($QueryBoxscore,true);
If ($GameResult != Null){
$GameJSON = gzdecode(base64_decode($GameResult['JSON']));
header('Content-type: application/json');
echo $GameJSON;
}else{
echo $EmptyReturn;
}
}
}else{
echo $EmptyReturn;
}
}elseif(isset($_GET['MetaContent']) OR isset($_POST['MetaContent'])){
$QueryBoxscore = "@@"; //Required so code at the end doesn't run.
header('Content-type: application/json');
echo json_encode($MetaContent);
/* --------------------------------------- HISTORY --------------------------------------- */
}elseif((isset($_GET['PlayerInfoHistory']) OR isset($_POST['PlayerInfoHistory'])) AND $Year != 0){
/* PlayerInfoHistory */
If ($Team >= 0){
$TeamQuery = "Team = " . $Team;
}else{
$TeamQuery = "Team >= 0"; /* Default Place Order Where everything will return */
}
if($Type == 1){
$TypeQuery = "Status1 >= 2";
}elseif($Type == 2){
$TypeQuery = "Status1 <= 1";
}else{
$TypeQuery = "Number > 0"; /* Default Place Order Where everything will return */
}
$Query = "SELECT MainTable.* FROM (SELECT PlayerInfoHistory.Number, PlayerInfoHistory.Name, PlayerInfoHistory.Team, PlayerInfoHistory.TeamName, PlayerInfoHistory.ProTeamName, '0' As TeamThemeID, PlayerInfoHistory.Age, PlayerInfoHistory.AgeDate, PlayerInfoHistory.Country, PlayerInfoHistory.Weight, PlayerInfoHistory.Height, PlayerInfoHistory.Contract, PlayerInfoHistory.Rookie, PlayerInfoHistory.NoTrade, PlayerInfoHistory.CanPlayPro, PlayerInfoHistory.CanPlayFarm, PlayerInfoHistory.ForceWaiver, PlayerInfoHistory.ExcludeSalaryCap, PlayerInfoHistory.ProSalaryinFarm, PlayerInfoHistory.SalaryAverage, PlayerInfoHistory.Salary1, PlayerInfoHistory.Salary2, PlayerInfoHistory.Salary3, PlayerInfoHistory.Salary4, PlayerInfoHistory.Salary5, PlayerInfoHistory.Salary6, PlayerInfoHistory.Salary7, PlayerInfoHistory.Salary8, PlayerInfoHistory.Salary9, PlayerInfoHistory.Salary10, PlayerInfoHistory.SalaryRemaining, PlayerInfoHistory.SalaryCap, PlayerInfoHistory.SalaryCapRemaining, PlayerInfoHistory.Condition, PlayerInfoHistory.ConditionDecimal,PlayerInfoHistory.Status1, PlayerInfoHistory.URLLink, PlayerInfoHistory.NHLID, PlayerInfoHistory.PProtected, PlayerInfoHistory.AvailableForTrade,PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, 'False' AS PosG, PlayerInfoHistory.Retire as Retire FROM PlayerInfoHistory WHERE Year = " . $Year . " And Playoff = '" . $PlayoffString. "' AND " . $TeamQuery . " AND Retire = " . $Retire . " AND " . $TypeQuery . " UNION ALL SELECT GoalerInfoHistory.Number, GoalerInfoHistory.Name, GoalerInfoHistory.Team, GoalerInfoHistory.TeamName, GoalerInfoHistory.ProTeamName, '0' As TeamThemeID, GoalerInfoHistory.Age, GoalerInfoHistory.AgeDate, GoalerInfoHistory.Country, GoalerInfoHistory.Weight, GoalerInfoHistory.Height, GoalerInfoHistory.Contract, GoalerInfoHistory.Rookie, GoalerInfoHistory.NoTrade, GoalerInfoHistory.CanPlayPro, GoalerInfoHistory.CanPlayFarm, GoalerInfoHistory.ForceWaiver, GoalerInfoHistory.ExcludeSalaryCap, GoalerInfoHistory.ProSalaryinFarm, GoalerInfoHistory.SalaryAverage, GoalerInfoHistory.Salary1, GoalerInfoHistory.Salary2, GoalerInfoHistory.Salary3, GoalerInfoHistory.Salary4, GoalerInfoHistory.Salary5, GoalerInfoHistory.Salary6, GoalerInfoHistory.Salary7, GoalerInfoHistory.Salary8, GoalerInfoHistory.Salary9, GoalerInfoHistory.Salary10, GoalerInfoHistory.SalaryRemaining, GoalerInfoHistory.SalaryCap, GoalerInfoHistory.SalaryCapRemaining, GoalerInfoHistory.Condition, GoalerInfoHistory.ConditionDecimal, GoalerInfoHistory.Status1, GoalerInfoHistory.URLLink, GoalerInfoHistory.NHLID, GoalerInfoHistory.PProtected, GoalerInfoHistory.AvailableForTrade,'False' AS PosC, 'False' AS PosLW, 'False' AS PosRW, 'False' AS PosD, 'True' AS PosG, GoalerInfoHistory.Retire as Retire FROM GoalerInfoHistory WHERE Year = " . $Year . " And Playoff = '" . $PlayoffString. "' AND " . $TeamQuery . " AND Retire = " . $Retire . " AND " . $TypeQuery . ") AS MainTable";
If ($AvailableForTrade == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " WHERE MainTable.Team > 0";}
$Query = $Query . " AND MainTable.AvailableForTrade = 'True'";
}
$Query = $Query . " ORDER BY MainTable.Name ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif((isset($_GET['PlayerRosterHistory']) OR isset($_POST['PlayerRosterHistory'])) AND $Year != 0){
/* PlayerRosterHistory */
$Query = "SELECT *, '0' As TeamThemeID FROM PlayerInfoHistory WHERE Retire = " . $Retire . " AND Year = " . $Year . " And Playoff = '" . $PlayoffString. "'";
if ($PlayerUniqueID > -1){
$Query = $Query . " AND PlayerInfoHistory.UniqueID = " . $PlayerUniqueID ;
}elseif($Team > 0 And $Retire == "'False'"){
$Query = $Query . " AND PlayerInfoHistory.Team = " . $Team;
}else{
if($Type == 1 Or $Type == 2){$Query = $Query . " AND PlayerInfoHistory.Number > 0";}
}
if($Type == 1){
$Query = $Query . " AND PlayerInfoHistory.Status1 >= 2";
}elseif($Type == 2){
$Query = $Query . " AND PlayerInfoHistory.Status1 <= 1";
}
If ($Retire == "'False'"){
if($AvailableForTrade == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND PlayerInfoHistory.Team > 0";}
$Query = $Query . " AND PlayerInfoHistory.AvailableForTrade = 'True'";
}elseif($Injury == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND PlayerInfoHistory.Team > 0";}
$Query = $Query . " AND (PlayerInfoHistory.Condition < '95' OR PlayerInfoHistory.Suspension > '1')";
}
}
$Query = $Query . " ORDER BY Overall";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif((isset($_GET['GoalerRosterHistory']) OR isset($_POST['GoalerRosterHistory'])) AND $Year != 0){
/* GoalerRosterHistory */
$Query = "SELECT *, '0' As TeamThemeID FROM GoalerInfoHistory WHERE Retire = " . $Retire . " AND Year = " . $Year . " And Playoff = '" . $PlayoffString. "'";
if ($PlayerUniqueID > -1){
$Query = $Query . " AND GoalerInfoHistory.UniqueID = " . $PlayerUniqueID;
}elseif($Team > 0 And $Retire == "'False'"){
$Query = $Query . " AND GoalerInfoHistory .Team = " . $Team;
}else{
if($Type == 1 Or $Type == 2 ){$Query = $Query . " AND GoalerInfoHistory .Number > 0";}
}
if($Type == 1){
$Query = $Query . " AND GoalerInfoHistory .Status1 >= 2";
}elseif($Type == 2){
$Query = $Query . " AND GoalerInfoHistory .Status1 <= 1";
}
If ($Retire == "'False'"){
if($AvailableForTrade == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND GoalerInfoHistory .Team > 0";}
$Query = $Query . " AND GoalerInfoHistory .AvailableForTrade = 'True'";
}elseif($Injury == TRUE){
if($Type == 0 AND $Team == -1){$Query = $Query . " AND GoalerInfo.Team > 0";}
$Query = $Query . " AND (GoalerInfoHistory .Condition < '95' OR GoalerInfoHistory .Suspension > '1')";
}
}
$Query = $Query . " ORDER BY Overall";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif((isset($_GET['StandingProHistory']) OR isset($_POST['StandingProHistory'])) AND $Year != 0){
/* StandingProHistory */
If ($Conference == 1 OR $Conference == 2){
/* Conference */
$Query = "SELECT TeamProStatHistory.*, TeamProInfoHistory.Conference, TeamProInfoHistory.Division, RankingOrder.Type FROM (TeamProStatHistory INNER JOIN TeamProInfoHistory ON TeamProStatHistory.Number = TeamProInfoHistory.Number) INNER JOIN RankingOrder ON TeamProStatHistory.Number = RankingOrder.TeamProNumber WHERE ((RankingOrder.Type)=" . $Conference . ") AND TeamProStatHistory.Year = " . $Year . " And TeamProStatHistory.Playoff = '" . $PlayoffString . "' AND TeamProInfoHistory.Year = " . $Year . " And TeamProInfoHistory.Playoff = '" . $PlayoffString . "' AND RankingOrder.Year = " . $Year . " And RankingOrder.Playoff = '" . $PlayoffString . "' ORDER BY RankingOrder.TeamOrder";
}elseif ($Division == 1 OR $Division == 2 OR $Division == 3 OR $Division == 4 OR $Division == 5 OR $Division == 6){
/* Division */
$dbStanding = new SQLite3($CareerStatDatabaseFile);
$QueryStanding = "Select Name, ProDivisionName" . $Division ." AS Division FROM LeagueGeneral WHERE Year = " . $Year . " And Playoff = '" . $PlayoffString . "'";
$StandingLeagueGeneral = $dbStanding->querySingle($QueryStanding,true);
$Query = "SELECT TeamProStatHistory.*, TeamProInfoHistory.Conference, TeamProInfoHistory.Division, RankingOrder.Type FROM (TeamProStatHistory INNER JOIN TeamProInfoHistory ON TeamProStatHistory.Number = TeamProInfoHistory.Number) INNER JOIN RankingOrder ON TeamProStatHistory.Number = RankingOrder.TeamProNumber WHERE (((TeamProInfoHistory.Division)=\"" . $StandingLeagueGeneral['Division'] . "\") AND ((RankingOrder.Type)=0)) AND TeamProStatHistory.Year = " . $Year . " And TeamProStatHistory.Playoff = '" . $PlayoffString . "' AND TeamProInfoHistory.Year = " . $Year . " And TeamProInfoHistory.Playoff = '" . $PlayoffString . "' AND RankingOrder.Year = " . $Year . " And RankingOrder.Playoff = '" . $PlayoffString . "' ORDER BY RankingOrder.TeamOrder";
}elseif($Conference > 0 OR $Division > 0){
/* Return Empty */
}else{
/* Overall */
$Query = "SELECT TeamProStatHistory.*, RankingOrder.TeamOrder FROM TeamProStatHistory INNER JOIN RankingOrder ON TeamProStatHistory.Number = RankingOrder.TeamProNumber WHERE (((RankingOrder.Type)=0)) AND TeamProStatHistory.Year = " . $Year . " And TeamProStatHistory.Playoff = '" . $PlayoffString . "' AND RankingOrder.Year = " . $Year . " And RankingOrder.Playoff = '" . $PlayoffString . "' ORDER BY RankingOrder.TeamOrder";
}
$CareerStatQuery = True;
}elseif((isset($_GET['StandingFarmHistory']) OR isset($_POST['StandingFarmHistory'])) AND $Year != 0){
/* StandingFarmHistory*/
If ($Conference == 1 OR $Conference == 2){
/* Conference */
$Query = "SELECT TeamFarmStatHistory.*, TeamFarmInfoHistory.Conference, TeamFarmInfoHistory.Division, RankingOrder.Type FROM (TeamFarmStatHistory INNER JOIN TeamFarmInfoHistory ON TeamFarmStatHistory.Number = TeamFarmInfoHistory.Number) INNER JOIN RankingOrder ON TeamFarmStatHistory.Number = RankingOrder.TeamFarmNumber WHERE ((RankingOrder.Type)=" . $Conference . ") AND TeamFarmStatHistory.Year = " . $Year . " And TeamFarmStatHistory.Playoff = '" . $PlayoffString . "' AND TeamFarmInfoHistory.Year = " . $Year . " And TeamFarmInfoHistory.Playoff = '" . $PlayoffString . "' AND RankingOrder.Year = " . $Year . " And RankingOrder.Playoff = '" . $PlayoffString . "' ORDER BY RankingOrder.TeamOrder";
}elseif ($Division == 1 OR $Division == 2 OR $Division == 3 OR $Division == 4 OR $Division == 5 OR $Division == 6){
/* Division */
$dbStanding = new SQLite3($CareerStatDatabaseFile);
$QueryStanding = "Select Name, FarmDivisionName" . $Division ." AS Division FROM LeagueGeneral WHERE Year = " . $Year . " And Playoff = '" . $PlayoffString . "'";
$StandingLeagueGeneral = $dbStanding->querySingle($QueryStanding,true);
$Query = "SELECT TeamFarmStatHistory.*, TeamFarmInfoHistory.Conference, TeamFarmInfoHistory.Division, RankingOrder.Type FROM (TeamFarmStatHistory INNER JOIN TeamFarmInfoHistory ON TeamFarmStatHistory.Number = TeamFarmInfoHistory.Number) INNER JOIN RankingOrder ON TeamFarmStatHistory.Number = RankingOrder.TeamFarmNumber WHERE (((TeamFarmInfoHistory.Division)=\"" . $StandingLeagueGeneral['Division'] . "\") AND ((RankingOrder.Type)=0)) AND TeamFarmStatHistory.Year = " . $Year . " And TeamFarmStatHistory.Playoff = '" . $PlayoffString . "' AND TeamFarmInfoHistory.Year = " . $Year . " And TeamFarmInfoHistory.Playoff = '" . $PlayoffString . "' AND RankingOrder.Year = " . $Year . " And RankingOrder.Playoff = '" . $PlayoffString . "' ORDER BY RankingOrder.TeamOrder";
}elseif($Conference > 0 OR $Division > 0){
/* Return Empty */
}else{
/* Overall */
$Query = "SELECT TeamFarmStatHistory.*, RankingOrder.TeamOrder FROM TeamFarmStatHistory INNER JOIN RankingOrder ON TeamFarmStatHistory.Number = RankingOrder.TeamFarmNumber WHERE (((RankingOrder.Type)=0)) AND TeamFarmStatHistory.Year = " . $Year . " And TeamFarmStatHistory.Playoff = '" . $PlayoffString . "' AND RankingOrder.Year = " . $Year . " And RankingOrder.Playoff = '" . $PlayoffString . "' ORDER BY RankingOrder.TeamOrder";
}
$CareerStatQuery = True;
}elseif((isset($_GET['FinanceProHistory']) OR isset($_POST['FinanceProHistory'])) AND $Year != 0){
/* FinanceProHistory */
$Query = "SELECT TeamProFinanceHistory.*, TempTable.EstimatedSeasonExpense AS FarmEstimatedSeasonExpense, TempTable.HomeGP AS HomeGP, 0 As TeamThemeID FROM TeamProFinanceHistory INNER JOIN (SELECT TeamFarmFinanceHistory.Number, TeamFarmFinanceHistory.Year, TeamFarmFinanceHistory.Playoff, TeamFarmFinanceHistory.EstimatedSeasonExpense,TeamProStatHistory.HomeGP FROM TeamProStatHistory INNER JOIN TeamFarmFinanceHistory ON TeamProStatHistory.Number = TeamFarmFinanceHistory.Number AND TeamProStatHistory.Year = " . $Year . " AND TeamFarmFinanceHistory.Year = " . $Year . " AND TeamProStatHistory.Playoff = '" . $PlayoffString. "' AND TeamFarmFinanceHistory.Playoff = '" . $PlayoffString. "') AS TempTable ON TeamProFinanceHistory.Number = TempTable.Number AND TeamProFinanceHistory.Year = " . $Year . " AND TempTable.Year = " . $Year . " AND TeamProFinanceHistory.Playoff = '" . $PlayoffString. "' AND TempTable.Playoff = '" . $PlayoffString. "' LEFT JOIN TeamProInfoHistory ON TeamProFinanceHistory.Number = TeamProInfoHistory.Number AND TeamProFinanceHistory.Year = '" . $Year . "' AND TeamProInfoHistory.Year = " . $Year . " AND TeamProFinanceHistory.Playoff = '" . $PlayoffString. "' AND TeamProInfoHistory.Playoff = '" . $PlayoffString. "' AND TeamProFinanceHistory.Year = " . $Year . " AND TeamProFinanceHistory.Playoff = '" . $PlayoffString. "' ORDER by TeamProFinanceHistory.Name";
$CareerStatQuery = True;
}elseif((isset($_GET['FinanceFarmHistory']) OR isset($_POST['FinanceFarmHistory'])) AND $Year != 0){
/* FinanceFarmHistory */
$Query = "SELECT TeamFarmFinanceHistory.*, TeamFarmStatHistory.HomeGP, 0 AS TeamThemeID FROM (TeamFarmFinanceHistory LEFT JOIN TeamFarmStatHistory ON TeamFarmFinanceHistory.Number = TeamFarmStatHistory.Number AND TeamFarmFinanceHistory.Year = " . $Year . " AND TeamFarmStatHistory.Year = " . $Year . " AND TeamFarmFinanceHistory.Playoff = '" . $PlayoffString. "' = " . $Year . " AND TeamFarmStatHistory.Playoff = '" . $PlayoffString. "') LEFT JOIN TeamFarmInfoHistory ON TeamFarmFinanceHistory.Number = TeamFarmInfoHistory.Number AND TeamFarmFinanceHistory.Year = " . $Year . " AND TeamFarmInfoHistory.Year = " . $Year . " AND TeamFarmFinanceHistory.Playoff = '" . $PlayoffString. "' AND TeamFarmInfoHistory.Playoff = '" . $PlayoffString. "' WHERE TeamFarmFinanceHistory.Year = " . $Year . " AND TeamFarmFinanceHistory.Playoff = '" . $PlayoffString. "' ORDER BY TeamFarmFinanceHistory.Name";
$CareerStatQuery = True;
}elseif((isset($_GET['ProspectHistory']) OR isset($_POST['ProspectHistory'])) AND $Year != 0){
/* ProspectHistory */
$Query = "SELECT 0 As TeamThemeID, Prospects.*, TeamProInfoHistory.Name As TeamName FROM Prospects LEFT JOIN TeamProInfoHistory ON Prospects.TeamNumber = TeamProInfoHistory.Number WHERE Prospects.Year = " . $Year . " And Prospects.Playoff = '" . $PlayoffString. "' AND TeamProInfoHistory.Year = " . $Year . " And TeamProInfoHistory.Playoff = '" . $PlayoffString. "'";
if($Team > 0){$Query = $Query . " AND TeamNumber = " . $Team;}
$Query = $Query . " ORDER BY NAME ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif((isset($_GET['DraftPickHistory']) OR isset($_POST['DraftPickHistory'])) AND $Year != 0){
/* DraftPickHistory */
$Query = "SELECT * FROM DraftPick WHERE Year = " . $Year . " And Playoff = '" . $PlayoffString. "' AND Year = " . $Year . " And Playoff = '" . $PlayoffString. "'";
if($Team > 0){$Query = $Query . " AND TeamNumber = " . $Team;}
$Query = $Query . " ORDER By Year, Round";
$CareerStatQuery = True;
}elseif((isset($_GET['ScheduleProHistory']) OR isset($_POST['ScheduleProHistory'])) AND $Year != 0){
/* ScheduleProHistory */
If ($Team == -1){
$Query = "SELECT 0 As VisitorTeamThemeID, 0 As HomeTeamThemeID, * FROM SchedulePro WHERE Year = " . $Year . " And Playoff = '" . $PlayoffString. "' ORDER BY GameNumber";
}else{
$Query = "SELECT 0 As VisitorTeamThemeID, 0 As HomeTeamThemeID, * FROM SchedulePro WHERE (VisitorTeam = " . $Team . " OR HomeTeam = " . $Team . ") AND Year = " . $Year . " And Playoff = '" . $PlayoffString. "' ORDER BY GameNumber";
}
$CareerStatQuery = True;
}elseif((isset($_GET['ScheduleFarmHistory']) OR isset($_POST['ScheduleFarmHistory'])) AND $Year != 0){
/* ScheduleFarmHistory */
If ($Team == -1){
$Query = "SELECT 0 As VisitorTeamThemeID, 0 As HomeTeamThemeID, * FROM ScheduleFarm WHERE Year = " . $Year . " And Playoff = '" . $PlayoffString. "' ORDER BY GameNumber";
}else{
$Query = "SELECT 0 As VisitorTeamThemeID, 0 As HomeTeamThemeID, * FROM ScheduleFarm WHERE (VisitorTeam = " . $Team . " OR HomeTeam = " . $Team . ") AND Year = " . $Year . " And Playoff = '" . $PlayoffString. "' ORDER BY GameNumber";
}
$CareerStatQuery = True;
}elseif((isset($_GET['TeamStatProHistory']) OR isset($_POST['TeamStatProHistory'])) AND $Year != 0){
/* TeamStatProHistory */
If ($Team == -1){
$Query = "SELECT MainTable.* FROM (SELECT TeamProStat.Number as Number, TeamProStat.Name as Name, TeamProStat.Name as OrderName, TeamProStat.TeamThemeID as TeamThemeID, TeamProStat.GP AS GP, TeamProStat.W AS W, TeamProStat.L AS L, TeamProStat.T AS T, TeamProStat.OTW AS OTW, TeamProStat.OTL AS OTL, TeamProStat.SOW AS SOW, TeamProStat.SOL AS SOL, TeamProStat.Points AS Points, TeamProStat.GF AS GF, TeamProStat.GA AS GA, TeamProStat.HomeGP AS HomeGP, TeamProStat.HomeW AS HomeW, TeamProStat.HomeL AS HomeL, TeamProStat.HomeT AS HomeT, TeamProStat.HomeOTW AS HomeOTW, TeamProStat.HomeOTL AS HomeOTL, TeamProStat.HomeSOW AS HomeSOW, TeamProStat.HomeSOL AS HomeSOL, TeamProStat.HomeGF AS HomeGF, TeamProStat.HomeGA AS HomeGA, TeamProStat.PPAttemp AS PPAttemp, TeamProStat.PPGoal AS PPGoal, TeamProStat.PKAttemp AS PKAttemp, TeamProStat.PKGoalGA AS PKGoalGA, TeamProStat.PKGoalGF AS PKGoalGF, TeamProStat.ShotsFor AS ShotsFor, TeamProStat.ShotsAga AS ShotsAga, TeamProStat.ShotsBlock AS ShotsBlock, TeamProStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStat.Shutouts AS Shutouts, TeamProStat.TotalGoal AS TotalGoal, TeamProStat.TotalAssist AS TotalAssist, TeamProStat.TotalPoint AS TotalPoint, TeamProStat.Pim AS Pim, TeamProStat.Hits AS Hits, TeamProStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStat.EmptyNetGoal AS EmptyNetGoal FROM TeamProStat UNION ALL SELECT 105 as Number, '<strong>Average</strong>' as Name,'ZZZZZZZZZZZZZ' as OrderName, '0' As TeamThemeID, Round(AVG(TeamProStat.GP),2) AS GP, Round(AVG(TeamProStat.W),2) AS W, Round(AVG(TeamProStat.L),2) AS L, Round(AVG(TeamProStat.T),2) AS T, Round(AVG(TeamProStat.OTW),2) AS OTW, Round(AVG(TeamProStat.OTL),2) AS OTL, Round(AVG(TeamProStat.SOW),2) AS SOW, Round(AVG(TeamProStat.SOL),2) AS SOL, Round(AVG(TeamProStat.Points),2) AS Points, Round(AVG(TeamProStat.GF),2) AS GF, Round(AVG(TeamProStat.GA),2) AS GA, Round(AVG(TeamProStat.HomeGP),2) AS HomeGP, Round(AVG(TeamProStat.HomeW),2) AS HomeW, Round(AVG(TeamProStat.HomeL),2) AS HomeL, Round(AVG(TeamProStat.HomeT),2) AS HomeT, Round(AVG(TeamProStat.HomeOTW),2) AS HomeOTW, Round(AVG(TeamProStat.HomeOTL),2) AS HomeOTL, Round(AVG(TeamProStat.HomeSOW),2) AS HomeSOW, Round(AVG(TeamProStat.HomeSOL),2) AS HomeSOL, Round(AVG(TeamProStat.HomeGF),2) AS HomeGF, Round(AVG(TeamProStat.HomeGA),2) AS HomeGA, Round(AVG(TeamProStat.PPAttemp),2) AS PPAttemp, Round(AVG(TeamProStat.PPGoal),2) AS PPGoal, Round(AVG(TeamProStat.PKAttemp),2) AS PKAttemp, Round(AVG(TeamProStat.PKGoalGA),2) AS PKGoalGA, Round(AVG(TeamProStat.PKGoalGF),2) AS PKGoalGF, Round(AVG(TeamProStat.ShotsFor),2) AS ShotsFor, Round(AVG(TeamProStat.ShotsAga),2) AS ShotsAga, Round(AVG(TeamProStat.ShotsBlock),2) AS ShotsBlock, Round(AVG(TeamProStat.ShotsPerPeriod1),2) AS ShotsPerPeriod1, Round(AVG(TeamProStat.ShotsPerPeriod2),2) AS ShotsPerPeriod2, Round(AVG(TeamProStat.ShotsPerPeriod3),2) AS ShotsPerPeriod3, Round(AVG(TeamProStat.ShotsPerPeriod4),2) AS ShotsPerPeriod4, Round(AVG(TeamProStat.GoalsPerPeriod1),2) AS GoalsPerPeriod1, Round(AVG(TeamProStat.GoalsPerPeriod2),2) AS GoalsPerPeriod2, Round(AVG(TeamProStat.GoalsPerPeriod3),2) AS GoalsPerPeriod3, Round(AVG(TeamProStat.GoalsPerPeriod4),2) AS GoalsPerPeriod4, Round(AVG(TeamProStat.PuckTimeInZoneDF),2) AS PuckTimeInZoneDF, Round(AVG(TeamProStat.PuckTimeInZoneOF),2) AS PuckTimeInZoneOF, Round(AVG(TeamProStat.PuckTimeInZoneNT),2) AS PuckTimeInZoneNT, Round(AVG(TeamProStat.PuckTimeControlinZoneDF),2) AS PuckTimeControlinZoneDF, Round(AVG(TeamProStat.PuckTimeControlinZoneOF),2) AS PuckTimeControlinZoneOF, Round(AVG(TeamProStat.PuckTimeControlinZoneNT),2) AS PuckTimeControlinZoneNT, Round(AVG(TeamProStat.Shutouts),2) AS Shutouts, Round(AVG(TeamProStat.TotalGoal),2) AS TotalGoal, Round(AVG(TeamProStat.TotalAssist),2) AS TotalAssist, Round(AVG(TeamProStat.TotalPoint),2) AS TotalPoint, Round(AVG(TeamProStat.Pim),2) AS Pim, Round(AVG(TeamProStat.Hits),2) AS Hits, Round(AVG(TeamProStat.FaceOffWonDefensifZone),2) AS FaceOffWonDefensifZone, Round(AVG(TeamProStat.FaceOffTotalDefensifZone),2) AS FaceOffTotalDefensifZone, Round(AVG(TeamProStat.FaceOffWonOffensifZone),2) AS FaceOffWonOffensifZone, Round(AVG(TeamProStat.FaceOffTotalOffensifZone),2) AS FaceOffTotalOffensifZone, Round(AVG(TeamProStat.FaceOffWonNeutralZone),2) AS FaceOffWonNeutralZone, Round(AVG(TeamProStat.FaceOffTotalNeutralZone),2) AS FaceOffTotalNeutralZone, Round(AVG(TeamProStat.EmptyNetGoal),2) AS EmptyNetGoal FROM TeamProStat) AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}else{
$Query = "SELECT MainTable.* FROM (SELECT TeamProStatVS.TeamVSName AS Name, TeamProStatVS.TeamVSNumber AS Number, TeamProStatVS.TeamVSNumberThemeID as TeamThemeID, TeamProStatVS.GP, TeamProStatVS.W, TeamProStatVS.L, TeamProStatVS.T, TeamProStatVS.OTW, TeamProStatVS.OTL, TeamProStatVS.SOW, TeamProStatVS.SOL, TeamProStatVS.Points, TeamProStatVS.GF, TeamProStatVS.GA, TeamProStatVS.HomeGP, TeamProStatVS.HomeW, TeamProStatVS.HomeL, TeamProStatVS.HomeT, TeamProStatVS.HomeOTW, TeamProStatVS.HomeOTL, TeamProStatVS.HomeSOW, TeamProStatVS.HomeSOL, TeamProStatVS.HomeGF, TeamProStatVS.HomeGA, TeamProStatVS.PPAttemp, TeamProStatVS.PPGoal, TeamProStatVS.PKAttemp, TeamProStatVS.PKGoalGA, TeamProStatVS.PKGoalGF, TeamProStatVS.ShotsFor, TeamProStatVS.ShotsAga, TeamProStatVS.ShotsBlock, TeamProStatVS.ShotsPerPeriod1, TeamProStatVS.ShotsPerPeriod2, TeamProStatVS.ShotsPerPeriod3, TeamProStatVS.ShotsPerPeriod4, TeamProStatVS.GoalsPerPeriod1, TeamProStatVS.GoalsPerPeriod2, TeamProStatVS.GoalsPerPeriod3, TeamProStatVS.GoalsPerPeriod4, TeamProStatVS.PuckTimeInZoneDF, TeamProStatVS.PuckTimeInZoneOF, TeamProStatVS.PuckTimeInZoneNT, TeamProStatVS.PuckTimeControlinZoneDF, TeamProStatVS.PuckTimeControlinZoneOF, TeamProStatVS.PuckTimeControlinZoneNT, TeamProStatVS.Shutouts, TeamProStatVS.TotalGoal, TeamProStatVS.TotalAssist, TeamProStatVS.TotalPoint, TeamProStatVS.Pim, TeamProStatVS.Hits, TeamProStatVS.FaceOffWonDefensifZone, TeamProStatVS.FaceOffTotalDefensifZone, TeamProStatVS.FaceOffWonOffensifZone, TeamProStatVS.FaceOffTotalOffensifZone, TeamProStatVS.FaceOffWonNeutralZone, TeamProStatVS.FaceOffTotalNeutralZone, TeamProStatVS.EmptyNetGoal FROM TeamProStatVS WHERE GP > 0 AND TeamNumber = " . $Team . " UNION ALL SELECT 'Total' as Name, '104' as Number, '0' as TeamThemeID, TeamProStat.GP, TeamProStat.W, TeamProStat.L, TeamProStat.T, TeamProStat.OTW, TeamProStat.OTL, TeamProStat.SOW, TeamProStat.SOL, TeamProStat.Points, TeamProStat.GF, TeamProStat.GA, TeamProStat.HomeGP, TeamProStat.HomeW, TeamProStat.HomeL, TeamProStat.HomeT, TeamProStat.HomeOTW, TeamProStat.HomeOTL, TeamProStat.HomeSOW, TeamProStat.HomeSOL, TeamProStat.HomeGF, TeamProStat.HomeGA, TeamProStat.PPAttemp, TeamProStat.PPGoal, TeamProStat.PKAttemp, TeamProStat.PKGoalGA, TeamProStat.PKGoalGF, TeamProStat.ShotsFor, TeamProStat.ShotsAga, TeamProStat.ShotsBlock, TeamProStat.ShotsPerPeriod1, TeamProStat.ShotsPerPeriod2, TeamProStat.ShotsPerPeriod3, TeamProStat.ShotsPerPeriod4, TeamProStat.GoalsPerPeriod1, TeamProStat.GoalsPerPeriod2, TeamProStat.GoalsPerPeriod3, TeamProStat.GoalsPerPeriod4, TeamProStat.PuckTimeInZoneDF, TeamProStat.PuckTimeInZoneOF, TeamProStat.PuckTimeInZoneNT, TeamProStat.PuckTimeControlinZoneDF, TeamProStat.PuckTimeControlinZoneOF, TeamProStat.PuckTimeControlinZoneNT, TeamProStat.Shutouts, TeamProStat.TotalGoal, TeamProStat.TotalAssist, TeamProStat.TotalPoint, TeamProStat.Pim, TeamProStat.Hits, TeamProStat.FaceOffWonDefensifZone, TeamProStat.FaceOffTotalDefensifZone, TeamProStat.FaceOffWonOffensifZone, TeamProStat.FaceOffTotalOffensifZone, TeamProStat.FaceOffWonNeutralZone, TeamProStat.FaceOffTotalNeutralZone, TeamProStat.EmptyNetGoal FROM TeamProStat WHERE Number = " . $Team . ") AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}
$CareerStatQuery = True;
}elseif((isset($_GET['TeamStatFarmHistory']) OR isset($_POST['TeamStateFarmHistory'])) AND $Year != 0){
/* TeamStatFarmHistory */
If ($Team == -1){
$Query = "SELECT MainTable.* FROM (SELECT TeamFarmStat.Number as Number, TeamFarmStat.Name as Name, TeamFarmStat.Name as OrderName, TeamFarmStat.TeamThemeID as TeamThemeID, TeamFarmStat.GP AS GP, TeamFarmStat.W AS W, TeamFarmStat.L AS L, TeamFarmStat.T AS T, TeamFarmStat.OTW AS OTW, TeamFarmStat.OTL AS OTL, TeamFarmStat.SOW AS SOW, TeamFarmStat.SOL AS SOL, TeamFarmStat.Points AS Points, TeamFarmStat.GF AS GF, TeamFarmStat.GA AS GA, TeamFarmStat.HomeGP AS HomeGP, TeamFarmStat.HomeW AS HomeW, TeamFarmStat.HomeL AS HomeL, TeamFarmStat.HomeT AS HomeT, TeamFarmStat.HomeOTW AS HomeOTW, TeamFarmStat.HomeOTL AS HomeOTL, TeamFarmStat.HomeSOW AS HomeSOW, TeamFarmStat.HomeSOL AS HomeSOL, TeamFarmStat.HomeGF AS HomeGF, TeamFarmStat.HomeGA AS HomeGA, TeamFarmStat.PPAttemp AS PPAttemp, TeamFarmStat.PPGoal AS PPGoal, TeamFarmStat.PKAttemp AS PKAttemp, TeamFarmStat.PKGoalGA AS PKGoalGA, TeamFarmStat.PKGoalGF AS PKGoalGF, TeamFarmStat.ShotsFor AS ShotsFor, TeamFarmStat.ShotsAga AS ShotsAga, TeamFarmStat.ShotsBlock AS ShotsBlock, TeamFarmStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStat.Shutouts AS Shutouts, TeamFarmStat.TotalGoal AS TotalGoal, TeamFarmStat.TotalAssist AS TotalAssist, TeamFarmStat.TotalPoint AS TotalPoint, TeamFarmStat.Pim AS Pim, TeamFarmStat.Hits AS Hits, TeamFarmStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStat.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStat UNION ALL SELECT 105 as Number, '<strong>Average</strong>' as Name,'ZZZZZZZZZZZZZ' as OrderName, '0' As TeamThemeID, Round(AVG(TeamFarmStat.GP),2) AS GP, Round(AVG(TeamFarmStat.W),2) AS W, Round(AVG(TeamFarmStat.L),2) AS L, Round(AVG(TeamFarmStat.T),2) AS T, Round(AVG(TeamFarmStat.OTW),2) AS OTW, Round(AVG(TeamFarmStat.OTL),2) AS OTL, Round(AVG(TeamFarmStat.SOW),2) AS SOW, Round(AVG(TeamFarmStat.SOL),2) AS SOL, Round(AVG(TeamFarmStat.Points),2) AS Points, Round(AVG(TeamFarmStat.GF),2) AS GF, Round(AVG(TeamFarmStat.GA),2) AS GA, Round(AVG(TeamFarmStat.HomeGP),2) AS HomeGP, Round(AVG(TeamFarmStat.HomeW),2) AS HomeW, Round(AVG(TeamFarmStat.HomeL),2) AS HomeL, Round(AVG(TeamFarmStat.HomeT),2) AS HomeT, Round(AVG(TeamFarmStat.HomeOTW),2) AS HomeOTW, Round(AVG(TeamFarmStat.HomeOTL),2) AS HomeOTL, Round(AVG(TeamFarmStat.HomeSOW),2) AS HomeSOW, Round(AVG(TeamFarmStat.HomeSOL),2) AS HomeSOL, Round(AVG(TeamFarmStat.HomeGF),2) AS HomeGF, Round(AVG(TeamFarmStat.HomeGA),2) AS HomeGA, Round(AVG(TeamFarmStat.PPAttemp),2) AS PPAttemp, Round(AVG(TeamFarmStat.PPGoal),2) AS PPGoal, Round(AVG(TeamFarmStat.PKAttemp),2) AS PKAttemp, Round(AVG(TeamFarmStat.PKGoalGA),2) AS PKGoalGA, Round(AVG(TeamFarmStat.PKGoalGF),2) AS PKGoalGF, Round(AVG(TeamFarmStat.ShotsFor),2) AS ShotsFor, Round(AVG(TeamFarmStat.ShotsAga),2) AS ShotsAga, Round(AVG(TeamFarmStat.ShotsBlock),2) AS ShotsBlock, Round(AVG(TeamFarmStat.ShotsPerPeriod1),2) AS ShotsPerPeriod1, Round(AVG(TeamFarmStat.ShotsPerPeriod2),2) AS ShotsPerPeriod2, Round(AVG(TeamFarmStat.ShotsPerPeriod3),2) AS ShotsPerPeriod3, Round(AVG(TeamFarmStat.ShotsPerPeriod4),2) AS ShotsPerPeriod4, Round(AVG(TeamFarmStat.GoalsPerPeriod1),2) AS GoalsPerPeriod1, Round(AVG(TeamFarmStat.GoalsPerPeriod2),2) AS GoalsPerPeriod2, Round(AVG(TeamFarmStat.GoalsPerPeriod3),2) AS GoalsPerPeriod3, Round(AVG(TeamFarmStat.GoalsPerPeriod4),2) AS GoalsPerPeriod4, Round(AVG(TeamFarmStat.PuckTimeInZoneDF),2) AS PuckTimeInZoneDF, Round(AVG(TeamFarmStat.PuckTimeInZoneOF),2) AS PuckTimeInZoneOF, Round(AVG(TeamFarmStat.PuckTimeInZoneNT),2) AS PuckTimeInZoneNT, Round(AVG(TeamFarmStat.PuckTimeControlinZoneDF),2) AS PuckTimeControlinZoneDF, Round(AVG(TeamFarmStat.PuckTimeControlinZoneOF),2) AS PuckTimeControlinZoneOF, Round(AVG(TeamFarmStat.PuckTimeControlinZoneNT),2) AS PuckTimeControlinZoneNT, Round(AVG(TeamFarmStat.Shutouts),2) AS Shutouts, Round(AVG(TeamFarmStat.TotalGoal),2) AS TotalGoal, Round(AVG(TeamFarmStat.TotalAssist),2) AS TotalAssist, Round(AVG(TeamFarmStat.TotalPoint),2) AS TotalPoint, Round(AVG(TeamFarmStat.Pim),2) AS Pim, Round(AVG(TeamFarmStat.Hits),2) AS Hits, Round(AVG(TeamFarmStat.FaceOffWonDefensifZone),2) AS FaceOffWonDefensifZone, Round(AVG(TeamFarmStat.FaceOffTotalDefensifZone),2) AS FaceOffTotalDefensifZone, Round(AVG(TeamFarmStat.FaceOffWonOffensifZone),2) AS FaceOffWonOffensifZone, Round(AVG(TeamFarmStat.FaceOffTotalOffensifZone),2) AS FaceOffTotalOffensifZone, Round(AVG(TeamFarmStat.FaceOffWonNeutralZone),2) AS FaceOffWonNeutralZone, Round(AVG(TeamFarmStat.FaceOffTotalNeutralZone),2) AS FaceOffTotalNeutralZone, Round(AVG(TeamFarmStat.EmptyNetGoal),2) AS EmptyNetGoal FROM TeamFarmStat) AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}else{
$Query = "SELECT MainTable.* FROM (SELECT TeamFarmStatVS.TeamVSName AS Name, TeamFarmStatVS.TeamVSNumber AS Number, TeamFarmStatVS.TeamVSNumberThemeID as TeamThemeID, TeamFarmStatVS.GP, TeamFarmStatVS.W, TeamFarmStatVS.L, TeamFarmStatVS.T, TeamFarmStatVS.OTW, TeamFarmStatVS.OTL, TeamFarmStatVS.SOW, TeamFarmStatVS.SOL, TeamFarmStatVS.Points, TeamFarmStatVS.GF, TeamFarmStatVS.GA, TeamFarmStatVS.HomeGP, TeamFarmStatVS.HomeW, TeamFarmStatVS.HomeL, TeamFarmStatVS.HomeT, TeamFarmStatVS.HomeOTW, TeamFarmStatVS.HomeOTL, TeamFarmStatVS.HomeSOW, TeamFarmStatVS.HomeSOL, TeamFarmStatVS.HomeGF, TeamFarmStatVS.HomeGA, TeamFarmStatVS.PPAttemp, TeamFarmStatVS.PPGoal, TeamFarmStatVS.PKAttemp, TeamFarmStatVS.PKGoalGA, TeamFarmStatVS.PKGoalGF, TeamFarmStatVS.ShotsFor, TeamFarmStatVS.ShotsAga, TeamFarmStatVS.ShotsBlock, TeamFarmStatVS.ShotsPerPeriod1, TeamFarmStatVS.ShotsPerPeriod2, TeamFarmStatVS.ShotsPerPeriod3, TeamFarmStatVS.ShotsPerPeriod4, TeamFarmStatVS.GoalsPerPeriod1, TeamFarmStatVS.GoalsPerPeriod2, TeamFarmStatVS.GoalsPerPeriod3, TeamFarmStatVS.GoalsPerPeriod4, TeamFarmStatVS.PuckTimeInZoneDF, TeamFarmStatVS.PuckTimeInZoneOF, TeamFarmStatVS.PuckTimeInZoneNT, TeamFarmStatVS.PuckTimeControlinZoneDF, TeamFarmStatVS.PuckTimeControlinZoneOF, TeamFarmStatVS.PuckTimeControlinZoneNT, TeamFarmStatVS.Shutouts, TeamFarmStatVS.TotalGoal, TeamFarmStatVS.TotalAssist, TeamFarmStatVS.TotalPoint, TeamFarmStatVS.Pim, TeamFarmStatVS.Hits, TeamFarmStatVS.FaceOffWonDefensifZone, TeamFarmStatVS.FaceOffTotalDefensifZone, TeamFarmStatVS.FaceOffWonOffensifZone, TeamFarmStatVS.FaceOffTotalOffensifZone, TeamFarmStatVS.FaceOffWonNeutralZone, TeamFarmStatVS.FaceOffTotalNeutralZone, TeamFarmStatVS.EmptyNetGoal FROM TeamFarmStatVS WHERE GP > 0 AND TeamNumber = " . $Team . " UNION ALL SELECT 'Total' as Name, '104' as Number, '0' as TeamThemeID, TeamFarmStat.GP, TeamFarmStat.W, TeamFarmStat.L, TeamFarmStat.T, TeamFarmStat.OTW, TeamFarmStat.OTL, TeamFarmStat.SOW, TeamFarmStat.SOL, TeamFarmStat.Points, TeamFarmStat.GF, TeamFarmStat.GA, TeamFarmStat.HomeGP, TeamFarmStat.HomeW, TeamFarmStat.HomeL, TeamFarmStat.HomeT, TeamFarmStat.HomeOTW, TeamFarmStat.HomeOTL, TeamFarmStat.HomeSOW, TeamFarmStat.HomeSOL, TeamFarmStat.HomeGF, TeamFarmStat.HomeGA, TeamFarmStat.PPAttemp, TeamFarmStat.PPGoal, TeamFarmStat.PKAttemp, TeamFarmStat.PKGoalGA, TeamFarmStat.PKGoalGF, TeamFarmStat.ShotsFor, TeamFarmStat.ShotsAga, TeamFarmStat.ShotsBlock, TeamFarmStat.ShotsPerPeriod1, TeamFarmStat.ShotsPerPeriod2, TeamFarmStat.ShotsPerPeriod3, TeamFarmStat.ShotsPerPeriod4, TeamFarmStat.GoalsPerPeriod1, TeamFarmStat.GoalsPerPeriod2, TeamFarmStat.GoalsPerPeriod3, TeamFarmStat.GoalsPerPeriod4, TeamFarmStat.PuckTimeInZoneDF, TeamFarmStat.PuckTimeInZoneOF, TeamFarmStat.PuckTimeInZoneNT, TeamFarmStat.PuckTimeControlinZoneDF, TeamFarmStat.PuckTimeControlinZoneOF, TeamFarmStat.PuckTimeControlinZoneNT, TeamFarmStat.Shutouts, TeamFarmStat.TotalGoal, TeamFarmStat.TotalAssist, TeamFarmStat.TotalPoint, TeamFarmStat.Pim, TeamFarmStat.Hits, TeamFarmStat.FaceOffWonDefensifZone, TeamFarmStat.FaceOffTotalDefensifZone, TeamFarmStat.FaceOffWonOffensifZone, TeamFarmStat.FaceOffTotalOffensifZone, TeamFarmStat.FaceOffWonNeutralZone, TeamFarmStat.FaceOffTotalNeutralZone, TeamFarmStat.EmptyNetGoal FROM TeamFarmStat WHERE Number = " . $Team . ") AS MainTable ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, Name ASC";
}
$CareerStatQuery = True;
}elseif(isset($_GET['TeamStatProHistoryAllSeasonMerge']) OR isset($_POST['TeamStatProHistoryAllSeasonMerge'])){
/* TeamStatProHistoryAllSeasonMerge */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonMerge = $dbTemp->querySingle($QueryTemp,true);
$Query = "SELECT MainTable.Number AS Number, MainTable.Name AS Name, MainTable.Name AS OrderName, '0' AS TeamThemeID, Sum(MainTable.GP) AS GP, Sum(MainTable.W) AS W, Sum(MainTable.L) AS L, Sum(MainTable.T) AS T, Sum(MainTable.OTW) AS OTW, Sum(MainTable.OTL) AS OTL, Sum(MainTable.SOW) AS SOW, Sum(MainTable.SOL) AS SOL, Sum(MainTable.Points) AS Points, Sum(MainTable.GF) AS GF, Sum(MainTable.GA) AS GA, Sum(MainTable.HomeGP) AS HomeGP, Sum(MainTable.HomeW) AS HomeW, Sum(MainTable.HomeL) AS HomeL, Sum(MainTable.HomeT) AS HomeT, Sum(MainTable.HomeOTW) AS HomeOTW, Sum(MainTable.HomeOTL) AS HomeOTL, Sum(MainTable.HomeSOW) AS HomeSOW, Sum(MainTable.HomeSOL) AS HomeSOL, Sum(MainTable.HomeGF) AS HomeGF, Sum(MainTable.HomeGA) AS HomeGA, Sum(MainTable.PPAttemp) AS PPAttemp, Sum(MainTable.PPGoal) AS PPGoal, Sum(MainTable.PKAttemp) AS PKAttemp, Sum(MainTable.PKGoalGA) AS PKGoalGA, Sum(MainTable.PKGoalGF) AS PKGoalGF, Sum(MainTable.ShotsFor) AS ShotsFor, Sum(MainTable.ShotsAga) AS ShotsAga, Sum(MainTable.ShotsBlock) AS ShotsBlock, Sum(MainTable.ShotsPerPeriod1) AS ShotsPerPeriod1, Sum(MainTable.ShotsPerPeriod2) AS ShotsPerPeriod2, Sum(MainTable.ShotsPerPeriod3) AS ShotsPerPeriod3, Sum(MainTable.ShotsPerPeriod4) AS ShotsPerPeriod4, Sum(MainTable.GoalsPerPeriod1) AS GoalsPerPeriod1, Sum(MainTable.GoalsPerPeriod2) AS GoalsPerPeriod2, Sum(MainTable.GoalsPerPeriod3) AS GoalsPerPeriod3, Sum(MainTable.GoalsPerPeriod4) AS GoalsPerPeriod4, Sum(MainTable.PuckTimeInZoneDF) AS PuckTimeInZoneDF, Sum(MainTable.PuckTimeInZoneOF) AS PuckTimeInZoneOF, Sum(MainTable.PuckTimeInZoneNT) AS PuckTimeInZoneNT, Sum(MainTable.PuckTimeControlinZoneDF) AS PuckTimeControlinZoneDF, Sum(MainTable.PuckTimeControlinZoneOF) AS PuckTimeControlinZoneOF, Sum(MainTable.PuckTimeControlinZoneNT) AS PuckTimeControlinZoneNT, Sum(MainTable.Shutouts) AS Shutouts, Sum(MainTable.TotalGoal) AS TotalGoal, Sum(MainTable.TotalAssist) AS TotalAssist, Sum(MainTable.TotalPoint) AS TotalPoint, Sum(MainTable.Pim) AS Pim, Sum(MainTable.Hits) AS Hits, Sum(MainTable.FaceOffWonDefensifZone) AS FaceOffWonDefensifZone, Sum(MainTable.FaceOffTotalDefensifZone) AS FaceOffTotalDefensifZone, Sum(MainTable.FaceOffWonOffensifZone) AS FaceOffWonOffensifZone, Sum(MainTable.FaceOffTotalOffensifZone) AS FaceOffTotalOffensifZone, Sum(MainTable.FaceOffWonNeutralZone) AS FaceOffWonNeutralZone, Sum(MainTable.FaceOffTotalNeutralZone) AS FaceOffTotalNeutralZone, Sum(MainTable.EmptyNetGoal) AS EmptyNetGoal, Count(MainTable.Year) as CountYear";
if($Team > 0 AND $ReturnOnlyTeamData == False){
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, TeamProStatVS.TeamVSName AS Name, TeamProStatVS.TeamVSNumber AS Number, TeamProStatVS.TeamVSNumberThemeID as TeamThemeID, TeamProStatVS.GP, TeamProStatVS.W, TeamProStatVS.L, TeamProStatVS.T, TeamProStatVS.OTW, TeamProStatVS.OTL, TeamProStatVS.SOW, TeamProStatVS.SOL, TeamProStatVS.Points, TeamProStatVS.GF, TeamProStatVS.GA, TeamProStatVS.HomeGP, TeamProStatVS.HomeW, TeamProStatVS.HomeL, TeamProStatVS.HomeT, TeamProStatVS.HomeOTW, TeamProStatVS.HomeOTL, TeamProStatVS.HomeSOW, TeamProStatVS.HomeSOL, TeamProStatVS.HomeGF, TeamProStatVS.HomeGA, TeamProStatVS.PPAttemp, TeamProStatVS.PPGoal, TeamProStatVS.PKAttemp, TeamProStatVS.PKGoalGA, TeamProStatVS.PKGoalGF, TeamProStatVS.ShotsFor, TeamProStatVS.ShotsAga, TeamProStatVS.ShotsBlock, TeamProStatVS.ShotsPerPeriod1, TeamProStatVS.ShotsPerPeriod2, TeamProStatVS.ShotsPerPeriod3, TeamProStatVS.ShotsPerPeriod4, TeamProStatVS.GoalsPerPeriod1, TeamProStatVS.GoalsPerPeriod2, TeamProStatVS.GoalsPerPeriod3, TeamProStatVS.GoalsPerPeriod4, TeamProStatVS.PuckTimeInZoneDF, TeamProStatVS.PuckTimeInZoneOF, TeamProStatVS.PuckTimeInZoneNT, TeamProStatVS.PuckTimeControlinZoneDF, TeamProStatVS.PuckTimeControlinZoneOF, TeamProStatVS.PuckTimeControlinZoneNT, TeamProStatVS.Shutouts, TeamProStatVS.TotalGoal, TeamProStatVS.TotalAssist, TeamProStatVS.TotalPoint, TeamProStatVS.Pim, TeamProStatVS.Hits, TeamProStatVS.FaceOffWonDefensifZone, TeamProStatVS.FaceOffTotalDefensifZone, TeamProStatVS.FaceOffWonOffensifZone, TeamProStatVS.FaceOffTotalOffensifZone, TeamProStatVS.FaceOffWonNeutralZone, TeamProStatVS.FaceOffTotalNeutralZone, TeamProStatVS.EmptyNetGoal FROM TeamProStatVS WHERE GP > 0 AND NUMBER < 103 AND TeamNumber = " . $Team . " UNION ALL SELECT TeamProStatVSHistory.Year AS Year, TeamProStatVSHistory.TeamVSName AS Name, TeamProStatVSHistory.TeamVSNumber AS Number, '0' As TeamThemeID, TeamProStatVSHistory.GP, TeamProStatVSHistory.W, TeamProStatVSHistory.L, TeamProStatVSHistory.T, TeamProStatVSHistory.OTW, TeamProStatVSHistory.OTL, TeamProStatVSHistory.SOW, TeamProStatVSHistory.SOL, TeamProStatVSHistory.Points, TeamProStatVSHistory.GF, TeamProStatVSHistory.GA, TeamProStatVSHistory.HomeGP, TeamProStatVSHistory.HomeW, TeamProStatVSHistory.HomeL, TeamProStatVSHistory.HomeT, TeamProStatVSHistory.HomeOTW, TeamProStatVSHistory.HomeOTL, TeamProStatVSHistory.HomeSOW, TeamProStatVSHistory.HomeSOL, TeamProStatVSHistory.HomeGF, TeamProStatVSHistory.HomeGA, TeamProStatVSHistory.PPAttemp, TeamProStatVSHistory.PPGoal, TeamProStatVSHistory.PKAttemp, TeamProStatVSHistory.PKGoalGA, TeamProStatVSHistory.PKGoalGF, TeamProStatVSHistory.ShotsFor, TeamProStatVSHistory.ShotsAga, TeamProStatVSHistory.ShotsBlock, TeamProStatVSHistory.ShotsPerPeriod1, TeamProStatVSHistory.ShotsPerPeriod2, TeamProStatVSHistory.ShotsPerPeriod3, TeamProStatVSHistory.ShotsPerPeriod4, TeamProStatVSHistory.GoalsPerPeriod1, TeamProStatVSHistory.GoalsPerPeriod2, TeamProStatVSHistory.GoalsPerPeriod3, TeamProStatVSHistory.GoalsPerPeriod4, TeamProStatVSHistory.PuckTimeInZoneDF, TeamProStatVSHistory.PuckTimeInZoneOF, TeamProStatVSHistory.PuckTimeInZoneNT, TeamProStatVSHistory.PuckTimeControlinZoneDF, TeamProStatVSHistory.PuckTimeControlinZoneOF, TeamProStatVSHistory.PuckTimeControlinZoneNT, TeamProStatVSHistory.Shutouts, TeamProStatVSHistory.TotalGoal, TeamProStatVSHistory.TotalAssist, TeamProStatVSHistory.TotalPoint, TeamProStatVSHistory.Pim, TeamProStatVSHistory.Hits, TeamProStatVSHistory.FaceOffWonDefensifZone, TeamProStatVSHistory.FaceOffTotalDefensifZone, TeamProStatVSHistory.FaceOffWonOffensifZone, TeamProStatVSHistory.FaceOffTotalOffensifZone, TeamProStatVSHistory.FaceOffWonNeutralZone, TeamProStatVSHistory.FaceOffTotalNeutralZone, TeamProStatVSHistory.EmptyNetGoal FROM TeamProStatVSHistory WHERE GP > 0 AND NUMBER < 103 AND TeamNumber = " . $Team . " And Playoff = '" . $PlayoffString. "' ) AS MainTable GROUP BY Number ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, MainTable.Name ASC";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT TeamProStatVSHistory.Year AS Year, TeamProStatVSHistory.TeamVSName AS Name, TeamProStatVSHistory.TeamVSNumber AS Number, '0' As TeamThemeID, TeamProStatVSHistory.GP, TeamProStatVSHistory.W, TeamProStatVSHistory.L, TeamProStatVSHistory.T, TeamProStatVSHistory.OTW, TeamProStatVSHistory.OTL, TeamProStatVSHistory.SOW, TeamProStatVSHistory.SOL, TeamProStatVSHistory.Points, TeamProStatVSHistory.GF, TeamProStatVSHistory.GA, TeamProStatVSHistory.HomeGP, TeamProStatVSHistory.HomeW, TeamProStatVSHistory.HomeL, TeamProStatVSHistory.HomeT, TeamProStatVSHistory.HomeOTW, TeamProStatVSHistory.HomeOTL, TeamProStatVSHistory.HomeSOW, TeamProStatVSHistory.HomeSOL, TeamProStatVSHistory.HomeGF, TeamProStatVSHistory.HomeGA, TeamProStatVSHistory.PPAttemp, TeamProStatVSHistory.PPGoal, TeamProStatVSHistory.PKAttemp, TeamProStatVSHistory.PKGoalGA, TeamProStatVSHistory.PKGoalGF, TeamProStatVSHistory.ShotsFor, TeamProStatVSHistory.ShotsAga, TeamProStatVSHistory.ShotsBlock, TeamProStatVSHistory.ShotsPerPeriod1, TeamProStatVSHistory.ShotsPerPeriod2, TeamProStatVSHistory.ShotsPerPeriod3, TeamProStatVSHistory.ShotsPerPeriod4, TeamProStatVSHistory.GoalsPerPeriod1, TeamProStatVSHistory.GoalsPerPeriod2, TeamProStatVSHistory.GoalsPerPeriod3, TeamProStatVSHistory.GoalsPerPeriod4, TeamProStatVSHistory.PuckTimeInZoneDF, TeamProStatVSHistory.PuckTimeInZoneOF, TeamProStatVSHistory.PuckTimeInZoneNT, TeamProStatVSHistory.PuckTimeControlinZoneDF, TeamProStatVSHistory.PuckTimeControlinZoneOF, TeamProStatVSHistory.PuckTimeControlinZoneNT, TeamProStatVSHistory.Shutouts, TeamProStatVSHistory.TotalGoal, TeamProStatVSHistory.TotalAssist, TeamProStatVSHistory.TotalPoint, TeamProStatVSHistory.Pim, TeamProStatVSHistory.Hits, TeamProStatVSHistory.FaceOffWonDefensifZone, TeamProStatVSHistory.FaceOffTotalDefensifZone, TeamProStatVSHistory.FaceOffWonOffensifZone, TeamProStatVSHistory.FaceOffTotalOffensifZone, TeamProStatVSHistory.FaceOffWonNeutralZone, TeamProStatVSHistory.FaceOffTotalNeutralZone, TeamProStatVSHistory.EmptyNetGoal FROM TeamProStatVSHistory WHERE GP > 0 AND NUMBER < 103 AND TeamNumber = " . $Team . " And Playoff = '" . $PlayoffString. "' ) AS MainTable GROUP BY Number ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, MainTable.Name ASC";
}
}else{
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, TeamProStat.Number as Number, TeamProStat.UniqueID as UniqueID, TeamProStat.Name as Name, TeamProStat.Name as OrderName, TeamProStat.TeamThemeID as TeamThemeID, TeamProStat.GP AS GP, TeamProStat.W AS W, TeamProStat.L AS L, TeamProStat.T AS T, TeamProStat.OTW AS OTW, TeamProStat.OTL AS OTL, TeamProStat.SOW AS SOW, TeamProStat.SOL AS SOL, TeamProStat.Points AS Points, TeamProStat.GF AS GF, TeamProStat.GA AS GA, TeamProStat.HomeGP AS HomeGP, TeamProStat.HomeW AS HomeW, TeamProStat.HomeL AS HomeL, TeamProStat.HomeT AS HomeT, TeamProStat.HomeOTW AS HomeOTW, TeamProStat.HomeOTL AS HomeOTL, TeamProStat.HomeSOW AS HomeSOW, TeamProStat.HomeSOL AS HomeSOL, TeamProStat.HomeGF AS HomeGF, TeamProStat.HomeGA AS HomeGA, TeamProStat.PPAttemp AS PPAttemp, TeamProStat.PPGoal AS PPGoal, TeamProStat.PKAttemp AS PKAttemp, TeamProStat.PKGoalGA AS PKGoalGA, TeamProStat.PKGoalGF AS PKGoalGF, TeamProStat.ShotsFor AS ShotsFor, TeamProStat.ShotsAga AS ShotsAga, TeamProStat.ShotsBlock AS ShotsBlock, TeamProStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStat.Shutouts AS Shutouts, TeamProStat.TotalGoal AS TotalGoal, TeamProStat.TotalAssist AS TotalAssist, TeamProStat.TotalPoint AS TotalPoint, TeamProStat.Pim AS Pim, TeamProStat.Hits AS Hits, TeamProStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStat.EmptyNetGoal AS EmptyNetGoal FROM TeamProStat UNION ALL SELECT TeamProStatHistory.Year as Year, TeamProStatHistory.Number as Number, TeamProStatHistory.UniqueID as UniqueID, TeamProStatHistory.Name as Name, TeamProStatHistory.Name as OrderName,'0' As TeamThemeID, TeamProStatHistory.GP AS GP, TeamProStatHistory.W AS W, TeamProStatHistory.L AS L, TeamProStatHistory.T AS T, TeamProStatHistory.OTW AS OTW, TeamProStatHistory.OTL AS OTL, TeamProStatHistory.SOW AS SOW, TeamProStatHistory.SOL AS SOL, TeamProStatHistory.Points AS Points, TeamProStatHistory.GF AS GF, TeamProStatHistory.GA AS GA, TeamProStatHistory.HomeGP AS HomeGP, TeamProStatHistory.HomeW AS HomeW, TeamProStatHistory.HomeL AS HomeL, TeamProStatHistory.HomeT AS HomeT, TeamProStatHistory.HomeOTW AS HomeOTW, TeamProStatHistory.HomeOTL AS HomeOTL, TeamProStatHistory.HomeSOW AS HomeSOW, TeamProStatHistory.HomeSOL AS HomeSOL, TeamProStatHistory.HomeGF AS HomeGF, TeamProStatHistory.HomeGA AS HomeGA, TeamProStatHistory.PPAttemp AS PPAttemp, TeamProStatHistory.PPGoal AS PPGoal, TeamProStatHistory.PKAttemp AS PKAttemp, TeamProStatHistory.PKGoalGA AS PKGoalGA, TeamProStatHistory.PKGoalGF AS PKGoalGF, TeamProStatHistory.ShotsFor AS ShotsFor, TeamProStatHistory.ShotsAga AS ShotsAga, TeamProStatHistory.ShotsBlock AS ShotsBlock, TeamProStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStatHistory.Shutouts AS Shutouts, TeamProStatHistory.TotalGoal AS TotalGoal, TeamProStatHistory.TotalAssist AS TotalAssist, TeamProStatHistory.TotalPoint AS TotalPoint, TeamProStatHistory.Pim AS Pim, TeamProStatHistory.Hits AS Hits, TeamProStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamProStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT TeamProStatHistory.Year as Year, TeamProStatHistory.Number as Number, TeamProStatHistory.UniqueID as UniqueID, TeamProStatHistory.Name as Name, TeamProStatHistory.Name as OrderName,'0' As TeamThemeID, TeamProStatHistory.GP AS GP, TeamProStatHistory.W AS W, TeamProStatHistory.L AS L, TeamProStatHistory.T AS T, TeamProStatHistory.OTW AS OTW, TeamProStatHistory.OTL AS OTL, TeamProStatHistory.SOW AS SOW, TeamProStatHistory.SOL AS SOL, TeamProStatHistory.Points AS Points, TeamProStatHistory.GF AS GF, TeamProStatHistory.GA AS GA, TeamProStatHistory.HomeGP AS HomeGP, TeamProStatHistory.HomeW AS HomeW, TeamProStatHistory.HomeL AS HomeL, TeamProStatHistory.HomeT AS HomeT, TeamProStatHistory.HomeOTW AS HomeOTW, TeamProStatHistory.HomeOTL AS HomeOTL, TeamProStatHistory.HomeSOW AS HomeSOW, TeamProStatHistory.HomeSOL AS HomeSOL, TeamProStatHistory.HomeGF AS HomeGF, TeamProStatHistory.HomeGA AS HomeGA, TeamProStatHistory.PPAttemp AS PPAttemp, TeamProStatHistory.PPGoal AS PPGoal, TeamProStatHistory.PKAttemp AS PKAttemp, TeamProStatHistory.PKGoalGA AS PKGoalGA, TeamProStatHistory.PKGoalGF AS PKGoalGF, TeamProStatHistory.ShotsFor AS ShotsFor, TeamProStatHistory.ShotsAga AS ShotsAga, TeamProStatHistory.ShotsBlock AS ShotsBlock, TeamProStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStatHistory.Shutouts AS Shutouts, TeamProStatHistory.TotalGoal AS TotalGoal, TeamProStatHistory.TotalAssist AS TotalAssist, TeamProStatHistory.TotalPoint AS TotalPoint, TeamProStatHistory.Pim AS Pim, TeamProStatHistory.Hits AS Hits, TeamProStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamProStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}
if($Team > 0 AND $ReturnOnlyTeamData == True){
$Query = $Query . " WHERE UniqueID = " . $Team . " ORDER BY MainTable.Name ASC";
}else{
$Query = $Query . " GROUP BY UniqueID ORDER BY MainTable.Name ASC";
}
}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['TeamStatFarmHistoryAllSeasonMerge']) OR isset($_POST['TeamStatFarmHistoryAllSeasonMerge'])){
/* TeamStatFarmHistoryAllSeasonMerge */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonMerge = $dbTemp->querySingle($QueryTemp,true);
$Query = "SELECT MainTable.Number AS Number, MainTable.Name AS Name, MainTable.Name AS OrderName, '0' AS TeamThemeID, Sum(MainTable.GP) AS GP, Sum(MainTable.W) AS W, Sum(MainTable.L) AS L, Sum(MainTable.T) AS T, Sum(MainTable.OTW) AS OTW, Sum(MainTable.OTL) AS OTL, Sum(MainTable.SOW) AS SOW, Sum(MainTable.SOL) AS SOL, Sum(MainTable.Points) AS Points, Sum(MainTable.GF) AS GF, Sum(MainTable.GA) AS GA, Sum(MainTable.HomeGP) AS HomeGP, Sum(MainTable.HomeW) AS HomeW, Sum(MainTable.HomeL) AS HomeL, Sum(MainTable.HomeT) AS HomeT, Sum(MainTable.HomeOTW) AS HomeOTW, Sum(MainTable.HomeOTL) AS HomeOTL, Sum(MainTable.HomeSOW) AS HomeSOW, Sum(MainTable.HomeSOL) AS HomeSOL, Sum(MainTable.HomeGF) AS HomeGF, Sum(MainTable.HomeGA) AS HomeGA, Sum(MainTable.PPAttemp) AS PPAttemp, Sum(MainTable.PPGoal) AS PPGoal, Sum(MainTable.PKAttemp) AS PKAttemp, Sum(MainTable.PKGoalGA) AS PKGoalGA, Sum(MainTable.PKGoalGF) AS PKGoalGF, Sum(MainTable.ShotsFor) AS ShotsFor, Sum(MainTable.ShotsAga) AS ShotsAga, Sum(MainTable.ShotsBlock) AS ShotsBlock, Sum(MainTable.ShotsPerPeriod1) AS ShotsPerPeriod1, Sum(MainTable.ShotsPerPeriod2) AS ShotsPerPeriod2, Sum(MainTable.ShotsPerPeriod3) AS ShotsPerPeriod3, Sum(MainTable.ShotsPerPeriod4) AS ShotsPerPeriod4, Sum(MainTable.GoalsPerPeriod1) AS GoalsPerPeriod1, Sum(MainTable.GoalsPerPeriod2) AS GoalsPerPeriod2, Sum(MainTable.GoalsPerPeriod3) AS GoalsPerPeriod3, Sum(MainTable.GoalsPerPeriod4) AS GoalsPerPeriod4, Sum(MainTable.PuckTimeInZoneDF) AS PuckTimeInZoneDF, Sum(MainTable.PuckTimeInZoneOF) AS PuckTimeInZoneOF, Sum(MainTable.PuckTimeInZoneNT) AS PuckTimeInZoneNT, Sum(MainTable.PuckTimeControlinZoneDF) AS PuckTimeControlinZoneDF, Sum(MainTable.PuckTimeControlinZoneOF) AS PuckTimeControlinZoneOF, Sum(MainTable.PuckTimeControlinZoneNT) AS PuckTimeControlinZoneNT, Sum(MainTable.Shutouts) AS Shutouts, Sum(MainTable.TotalGoal) AS TotalGoal, Sum(MainTable.TotalAssist) AS TotalAssist, Sum(MainTable.TotalPoint) AS TotalPoint, Sum(MainTable.Pim) AS Pim, Sum(MainTable.Hits) AS Hits, Sum(MainTable.FaceOffWonDefensifZone) AS FaceOffWonDefensifZone, Sum(MainTable.FaceOffTotalDefensifZone) AS FaceOffTotalDefensifZone, Sum(MainTable.FaceOffWonOffensifZone) AS FaceOffWonOffensifZone, Sum(MainTable.FaceOffTotalOffensifZone) AS FaceOffTotalOffensifZone, Sum(MainTable.FaceOffWonNeutralZone) AS FaceOffWonNeutralZone, Sum(MainTable.FaceOffTotalNeutralZone) AS FaceOffTotalNeutralZone, Sum(MainTable.EmptyNetGoal) AS EmptyNetGoal, Count(MainTable.Year) as CountYear";
if($Team > 0 AND $ReturnOnlyTeamData == False){
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, TeamFarmStatVS.TeamVSName AS Name, TeamFarmStatVS.TeamVSNumber AS Number, TeamFarmStatVS.TeamVSNumberThemeID as TeamThemeID, TeamFarmStatVS.GP, TeamFarmStatVS.W, TeamFarmStatVS.L, TeamFarmStatVS.T, TeamFarmStatVS.OTW, TeamFarmStatVS.OTL, TeamFarmStatVS.SOW, TeamFarmStatVS.SOL, TeamFarmStatVS.Points, TeamFarmStatVS.GF, TeamFarmStatVS.GA, TeamFarmStatVS.HomeGP, TeamFarmStatVS.HomeW, TeamFarmStatVS.HomeL, TeamFarmStatVS.HomeT, TeamFarmStatVS.HomeOTW, TeamFarmStatVS.HomeOTL, TeamFarmStatVS.HomeSOW, TeamFarmStatVS.HomeSOL, TeamFarmStatVS.HomeGF, TeamFarmStatVS.HomeGA, TeamFarmStatVS.PPAttemp, TeamFarmStatVS.PPGoal, TeamFarmStatVS.PKAttemp, TeamFarmStatVS.PKGoalGA, TeamFarmStatVS.PKGoalGF, TeamFarmStatVS.ShotsFor, TeamFarmStatVS.ShotsAga, TeamFarmStatVS.ShotsBlock, TeamFarmStatVS.ShotsPerPeriod1, TeamFarmStatVS.ShotsPerPeriod2, TeamFarmStatVS.ShotsPerPeriod3, TeamFarmStatVS.ShotsPerPeriod4, TeamFarmStatVS.GoalsPerPeriod1, TeamFarmStatVS.GoalsPerPeriod2, TeamFarmStatVS.GoalsPerPeriod3, TeamFarmStatVS.GoalsPerPeriod4, TeamFarmStatVS.PuckTimeInZoneDF, TeamFarmStatVS.PuckTimeInZoneOF, TeamFarmStatVS.PuckTimeInZoneNT, TeamFarmStatVS.PuckTimeControlinZoneDF, TeamFarmStatVS.PuckTimeControlinZoneOF, TeamFarmStatVS.PuckTimeControlinZoneNT, TeamFarmStatVS.Shutouts, TeamFarmStatVS.TotalGoal, TeamFarmStatVS.TotalAssist, TeamFarmStatVS.TotalPoint, TeamFarmStatVS.Pim, TeamFarmStatVS.Hits, TeamFarmStatVS.FaceOffWonDefensifZone, TeamFarmStatVS.FaceOffTotalDefensifZone, TeamFarmStatVS.FaceOffWonOffensifZone, TeamFarmStatVS.FaceOffTotalOffensifZone, TeamFarmStatVS.FaceOffWonNeutralZone, TeamFarmStatVS.FaceOffTotalNeutralZone, TeamFarmStatVS.EmptyNetGoal FROM TeamFarmStatVS WHERE GP > 0 AND NUMBER < 103 AND TeamNumber = " . $Team . " UNION ALL SELECT TeamFarmStatVSHistory.Year AS Year, TeamFarmStatVSHistory.TeamVSName AS Name, TeamFarmStatVSHistory.TeamVSNumber AS Number, '0' As TeamThemeID, TeamFarmStatVSHistory.GP, TeamFarmStatVSHistory.W, TeamFarmStatVSHistory.L, TeamFarmStatVSHistory.T, TeamFarmStatVSHistory.OTW, TeamFarmStatVSHistory.OTL, TeamFarmStatVSHistory.SOW, TeamFarmStatVSHistory.SOL, TeamFarmStatVSHistory.Points, TeamFarmStatVSHistory.GF, TeamFarmStatVSHistory.GA, TeamFarmStatVSHistory.HomeGP, TeamFarmStatVSHistory.HomeW, TeamFarmStatVSHistory.HomeL, TeamFarmStatVSHistory.HomeT, TeamFarmStatVSHistory.HomeOTW, TeamFarmStatVSHistory.HomeOTL, TeamFarmStatVSHistory.HomeSOW, TeamFarmStatVSHistory.HomeSOL, TeamFarmStatVSHistory.HomeGF, TeamFarmStatVSHistory.HomeGA, TeamFarmStatVSHistory.PPAttemp, TeamFarmStatVSHistory.PPGoal, TeamFarmStatVSHistory.PKAttemp, TeamFarmStatVSHistory.PKGoalGA, TeamFarmStatVSHistory.PKGoalGF, TeamFarmStatVSHistory.ShotsFor, TeamFarmStatVSHistory.ShotsAga, TeamFarmStatVSHistory.ShotsBlock, TeamFarmStatVSHistory.ShotsPerPeriod1, TeamFarmStatVSHistory.ShotsPerPeriod2, TeamFarmStatVSHistory.ShotsPerPeriod3, TeamFarmStatVSHistory.ShotsPerPeriod4, TeamFarmStatVSHistory.GoalsPerPeriod1, TeamFarmStatVSHistory.GoalsPerPeriod2, TeamFarmStatVSHistory.GoalsPerPeriod3, TeamFarmStatVSHistory.GoalsPerPeriod4, TeamFarmStatVSHistory.PuckTimeInZoneDF, TeamFarmStatVSHistory.PuckTimeInZoneOF, TeamFarmStatVSHistory.PuckTimeInZoneNT, TeamFarmStatVSHistory.PuckTimeControlinZoneDF, TeamFarmStatVSHistory.PuckTimeControlinZoneOF, TeamFarmStatVSHistory.PuckTimeControlinZoneNT, TeamFarmStatVSHistory.Shutouts, TeamFarmStatVSHistory.TotalGoal, TeamFarmStatVSHistory.TotalAssist, TeamFarmStatVSHistory.TotalPoint, TeamFarmStatVSHistory.Pim, TeamFarmStatVSHistory.Hits, TeamFarmStatVSHistory.FaceOffWonDefensifZone, TeamFarmStatVSHistory.FaceOffTotalDefensifZone, TeamFarmStatVSHistory.FaceOffWonOffensifZone, TeamFarmStatVSHistory.FaceOffTotalOffensifZone, TeamFarmStatVSHistory.FaceOffWonNeutralZone, TeamFarmStatVSHistory.FaceOffTotalNeutralZone, TeamFarmStatVSHistory.EmptyNetGoal FROM TeamFarmStatVSHistory WHERE GP > 0 AND NUMBER < 103 AND TeamNumber = " . $Team . " And Playoff = '" . $PlayoffString. "' ) AS MainTable GROUP BY Number ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, MainTable.Name ASC";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT TeamFarmStatVSHistory.Year AS Year, TeamFarmStatVSHistory.TeamVSName AS Name, TeamFarmStatVSHistory.TeamVSNumber AS Number, '0' As TeamThemeID, TeamFarmStatVSHistory.GP, TeamFarmStatVSHistory.W, TeamFarmStatVSHistory.L, TeamFarmStatVSHistory.T, TeamFarmStatVSHistory.OTW, TeamFarmStatVSHistory.OTL, TeamFarmStatVSHistory.SOW, TeamFarmStatVSHistory.SOL, TeamFarmStatVSHistory.Points, TeamFarmStatVSHistory.GF, TeamFarmStatVSHistory.GA, TeamFarmStatVSHistory.HomeGP, TeamFarmStatVSHistory.HomeW, TeamFarmStatVSHistory.HomeL, TeamFarmStatVSHistory.HomeT, TeamFarmStatVSHistory.HomeOTW, TeamFarmStatVSHistory.HomeOTL, TeamFarmStatVSHistory.HomeSOW, TeamFarmStatVSHistory.HomeSOL, TeamFarmStatVSHistory.HomeGF, TeamFarmStatVSHistory.HomeGA, TeamFarmStatVSHistory.PPAttemp, TeamFarmStatVSHistory.PPGoal, TeamFarmStatVSHistory.PKAttemp, TeamFarmStatVSHistory.PKGoalGA, TeamFarmStatVSHistory.PKGoalGF, TeamFarmStatVSHistory.ShotsFor, TeamFarmStatVSHistory.ShotsAga, TeamFarmStatVSHistory.ShotsBlock, TeamFarmStatVSHistory.ShotsPerPeriod1, TeamFarmStatVSHistory.ShotsPerPeriod2, TeamFarmStatVSHistory.ShotsPerPeriod3, TeamFarmStatVSHistory.ShotsPerPeriod4, TeamFarmStatVSHistory.GoalsPerPeriod1, TeamFarmStatVSHistory.GoalsPerPeriod2, TeamFarmStatVSHistory.GoalsPerPeriod3, TeamFarmStatVSHistory.GoalsPerPeriod4, TeamFarmStatVSHistory.PuckTimeInZoneDF, TeamFarmStatVSHistory.PuckTimeInZoneOF, TeamFarmStatVSHistory.PuckTimeInZoneNT, TeamFarmStatVSHistory.PuckTimeControlinZoneDF, TeamFarmStatVSHistory.PuckTimeControlinZoneOF, TeamFarmStatVSHistory.PuckTimeControlinZoneNT, TeamFarmStatVSHistory.Shutouts, TeamFarmStatVSHistory.TotalGoal, TeamFarmStatVSHistory.TotalAssist, TeamFarmStatVSHistory.TotalPoint, TeamFarmStatVSHistory.Pim, TeamFarmStatVSHistory.Hits, TeamFarmStatVSHistory.FaceOffWonDefensifZone, TeamFarmStatVSHistory.FaceOffTotalDefensifZone, TeamFarmStatVSHistory.FaceOffWonOffensifZone, TeamFarmStatVSHistory.FaceOffTotalOffensifZone, TeamFarmStatVSHistory.FaceOffWonNeutralZone, TeamFarmStatVSHistory.FaceOffTotalNeutralZone, TeamFarmStatVSHistory.EmptyNetGoal FROM TeamFarmStatVSHistory WHERE GP > 0 AND NUMBER < 103 AND TeamNumber = " . $Team . " And Playoff = '" . $PlayoffString. "' ) AS MainTable GROUP BY Number ORDER BY CASE WHEN Number > 100 THEN 2 ELSE 1 END, MainTable.Name ASC";
}
}else{
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, TeamFarmStat.Number as Number, TeamFarmStat.UniqueID as UniqueID, TeamFarmStat.Name as Name, TeamFarmStat.Name as OrderName, TeamFarmStat.TeamThemeID as TeamThemeID, TeamFarmStat.GP AS GP, TeamFarmStat.W AS W, TeamFarmStat.L AS L, TeamFarmStat.T AS T, TeamFarmStat.OTW AS OTW, TeamFarmStat.OTL AS OTL, TeamFarmStat.SOW AS SOW, TeamFarmStat.SOL AS SOL, TeamFarmStat.Points AS Points, TeamFarmStat.GF AS GF, TeamFarmStat.GA AS GA, TeamFarmStat.HomeGP AS HomeGP, TeamFarmStat.HomeW AS HomeW, TeamFarmStat.HomeL AS HomeL, TeamFarmStat.HomeT AS HomeT, TeamFarmStat.HomeOTW AS HomeOTW, TeamFarmStat.HomeOTL AS HomeOTL, TeamFarmStat.HomeSOW AS HomeSOW, TeamFarmStat.HomeSOL AS HomeSOL, TeamFarmStat.HomeGF AS HomeGF, TeamFarmStat.HomeGA AS HomeGA, TeamFarmStat.PPAttemp AS PPAttemp, TeamFarmStat.PPGoal AS PPGoal, TeamFarmStat.PKAttemp AS PKAttemp, TeamFarmStat.PKGoalGA AS PKGoalGA, TeamFarmStat.PKGoalGF AS PKGoalGF, TeamFarmStat.ShotsFor AS ShotsFor, TeamFarmStat.ShotsAga AS ShotsAga, TeamFarmStat.ShotsBlock AS ShotsBlock, TeamFarmStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStat.Shutouts AS Shutouts, TeamFarmStat.TotalGoal AS TotalGoal, TeamFarmStat.TotalAssist AS TotalAssist, TeamFarmStat.TotalPoint AS TotalPoint, TeamFarmStat.Pim AS Pim, TeamFarmStat.Hits AS Hits, TeamFarmStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStat.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStat UNION ALL SELECT TeamFarmStatHistory.Year as Year, TeamFarmStatHistory.Number as Number, TeamFarmStatHistory.UniqueID as UniqueID, TeamFarmStatHistory.Name as Name, TeamFarmStatHistory.Name as OrderName,'0' As TeamThemeID, TeamFarmStatHistory.GP AS GP, TeamFarmStatHistory.W AS W, TeamFarmStatHistory.L AS L, TeamFarmStatHistory.T AS T, TeamFarmStatHistory.OTW AS OTW, TeamFarmStatHistory.OTL AS OTL, TeamFarmStatHistory.SOW AS SOW, TeamFarmStatHistory.SOL AS SOL, TeamFarmStatHistory.Points AS Points, TeamFarmStatHistory.GF AS GF, TeamFarmStatHistory.GA AS GA, TeamFarmStatHistory.HomeGP AS HomeGP, TeamFarmStatHistory.HomeW AS HomeW, TeamFarmStatHistory.HomeL AS HomeL, TeamFarmStatHistory.HomeT AS HomeT, TeamFarmStatHistory.HomeOTW AS HomeOTW, TeamFarmStatHistory.HomeOTL AS HomeOTL, TeamFarmStatHistory.HomeSOW AS HomeSOW, TeamFarmStatHistory.HomeSOL AS HomeSOL, TeamFarmStatHistory.HomeGF AS HomeGF, TeamFarmStatHistory.HomeGA AS HomeGA, TeamFarmStatHistory.PPAttemp AS PPAttemp, TeamFarmStatHistory.PPGoal AS PPGoal, TeamFarmStatHistory.PKAttemp AS PKAttemp, TeamFarmStatHistory.PKGoalGA AS PKGoalGA, TeamFarmStatHistory.PKGoalGF AS PKGoalGF, TeamFarmStatHistory.ShotsFor AS ShotsFor, TeamFarmStatHistory.ShotsAga AS ShotsAga, TeamFarmStatHistory.ShotsBlock AS ShotsBlock, TeamFarmStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStatHistory.Shutouts AS Shutouts, TeamFarmStatHistory.TotalGoal AS TotalGoal, TeamFarmStatHistory.TotalAssist AS TotalAssist, TeamFarmStatHistory.TotalPoint AS TotalPoint, TeamFarmStatHistory.Pim AS Pim, TeamFarmStatHistory.Hits AS Hits, TeamFarmStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT TeamFarmStatHistory.Year as Year, TeamFarmStatHistory.Number as Number, TeamFarmStatHistory.UniqueID as UniqueID, TeamFarmStatHistory.Name as Name, TeamFarmStatHistory.Name as OrderName,'0' As TeamThemeID, TeamFarmStatHistory.GP AS GP, TeamFarmStatHistory.W AS W, TeamFarmStatHistory.L AS L, TeamFarmStatHistory.T AS T, TeamFarmStatHistory.OTW AS OTW, TeamFarmStatHistory.OTL AS OTL, TeamFarmStatHistory.SOW AS SOW, TeamFarmStatHistory.SOL AS SOL, TeamFarmStatHistory.Points AS Points, TeamFarmStatHistory.GF AS GF, TeamFarmStatHistory.GA AS GA, TeamFarmStatHistory.HomeGP AS HomeGP, TeamFarmStatHistory.HomeW AS HomeW, TeamFarmStatHistory.HomeL AS HomeL, TeamFarmStatHistory.HomeT AS HomeT, TeamFarmStatHistory.HomeOTW AS HomeOTW, TeamFarmStatHistory.HomeOTL AS HomeOTL, TeamFarmStatHistory.HomeSOW AS HomeSOW, TeamFarmStatHistory.HomeSOL AS HomeSOL, TeamFarmStatHistory.HomeGF AS HomeGF, TeamFarmStatHistory.HomeGA AS HomeGA, TeamFarmStatHistory.PPAttemp AS PPAttemp, TeamFarmStatHistory.PPGoal AS PPGoal, TeamFarmStatHistory.PKAttemp AS PKAttemp, TeamFarmStatHistory.PKGoalGA AS PKGoalGA, TeamFarmStatHistory.PKGoalGF AS PKGoalGF, TeamFarmStatHistory.ShotsFor AS ShotsFor, TeamFarmStatHistory.ShotsAga AS ShotsAga, TeamFarmStatHistory.ShotsBlock AS ShotsBlock, TeamFarmStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStatHistory.Shutouts AS Shutouts, TeamFarmStatHistory.TotalGoal AS TotalGoal, TeamFarmStatHistory.TotalAssist AS TotalAssist, TeamFarmStatHistory.TotalPoint AS TotalPoint, TeamFarmStatHistory.Pim AS Pim, TeamFarmStatHistory.Hits AS Hits, TeamFarmStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}
if($Team > 0 AND $ReturnOnlyTeamData == True){
$Query = $Query . " WHERE UniqueID = " . $Team . " ORDER BY MainTable.Name ASC";
}else{
$Query = $Query . " GROUP BY UniqueID ORDER BY MainTable.Name ASC";
}
}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['TeamStatProHistoryAllSeasonPerYear']) OR isset($_POST['TeamStatProHistoryAllSeasonPerYear'])){
/* TeamStatProHistoryAllSeasonPerYear */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonPerYear = $dbTemp->querySingle($QueryTemp,true);
$Query = "Select MainTable.*";
if($LeagueGeneralAllSeasonPerYear['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonPerYear['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = "Select MainTable.* FROM (SELECT '". $LeagueGeneralAllSeasonPerYear['LeagueYearOutput'] . "' as Year, TeamProStat.Number as Number, TeamProStat.UniqueID as UniqueID, TeamProStat.Name as Name, TeamProStat.Name as OrderName, TeamProStat.TeamThemeID as TeamThemeID, TeamProStat.GP AS GP, TeamProStat.W AS W, TeamProStat.L AS L, TeamProStat.T AS T, TeamProStat.OTW AS OTW, TeamProStat.OTL AS OTL, TeamProStat.SOW AS SOW, TeamProStat.SOL AS SOL, TeamProStat.Points AS Points, TeamProStat.GF AS GF, TeamProStat.GA AS GA, TeamProStat.HomeGP AS HomeGP, TeamProStat.HomeW AS HomeW, TeamProStat.HomeL AS HomeL, TeamProStat.HomeT AS HomeT, TeamProStat.HomeOTW AS HomeOTW, TeamProStat.HomeOTL AS HomeOTL, TeamProStat.HomeSOW AS HomeSOW, TeamProStat.HomeSOL AS HomeSOL, TeamProStat.HomeGF AS HomeGF, TeamProStat.HomeGA AS HomeGA, TeamProStat.PPAttemp AS PPAttemp, TeamProStat.PPGoal AS PPGoal, TeamProStat.PKAttemp AS PKAttemp, TeamProStat.PKGoalGA AS PKGoalGA, TeamProStat.PKGoalGF AS PKGoalGF, TeamProStat.ShotsFor AS ShotsFor, TeamProStat.ShotsAga AS ShotsAga, TeamProStat.ShotsBlock AS ShotsBlock, TeamProStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStat.Shutouts AS Shutouts, TeamProStat.TotalGoal AS TotalGoal, TeamProStat.TotalAssist AS TotalAssist, TeamProStat.TotalPoint AS TotalPoint, TeamProStat.Pim AS Pim, TeamProStat.Hits AS Hits, TeamProStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStat.EmptyNetGoal AS EmptyNetGoal FROM TeamProStat UNION ALL SELECT TeamProStatHistory.Year as Year, TeamProStatHistory.Number as Number, TeamProStatHistory.UniqueID as UniqueID, TeamProStatHistory.Name as Name, TeamProStatHistory.Name as OrderName,'0' As TeamThemeID, TeamProStatHistory.GP AS GP, TeamProStatHistory.W AS W, TeamProStatHistory.L AS L, TeamProStatHistory.T AS T, TeamProStatHistory.OTW AS OTW, TeamProStatHistory.OTL AS OTL, TeamProStatHistory.SOW AS SOW, TeamProStatHistory.SOL AS SOL, TeamProStatHistory.Points AS Points, TeamProStatHistory.GF AS GF, TeamProStatHistory.GA AS GA, TeamProStatHistory.HomeGP AS HomeGP, TeamProStatHistory.HomeW AS HomeW, TeamProStatHistory.HomeL AS HomeL, TeamProStatHistory.HomeT AS HomeT, TeamProStatHistory.HomeOTW AS HomeOTW, TeamProStatHistory.HomeOTL AS HomeOTL, TeamProStatHistory.HomeSOW AS HomeSOW, TeamProStatHistory.HomeSOL AS HomeSOL, TeamProStatHistory.HomeGF AS HomeGF, TeamProStatHistory.HomeGA AS HomeGA, TeamProStatHistory.PPAttemp AS PPAttemp, TeamProStatHistory.PPGoal AS PPGoal, TeamProStatHistory.PKAttemp AS PKAttemp, TeamProStatHistory.PKGoalGA AS PKGoalGA, TeamProStatHistory.PKGoalGF AS PKGoalGF, TeamProStatHistory.ShotsFor AS ShotsFor, TeamProStatHistory.ShotsAga AS ShotsAga, TeamProStatHistory.ShotsBlock AS ShotsBlock, TeamProStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStatHistory.Shutouts AS Shutouts, TeamProStatHistory.TotalGoal AS TotalGoal, TeamProStatHistory.TotalAssist AS TotalAssist, TeamProStatHistory.TotalPoint AS TotalPoint, TeamProStatHistory.Pim AS Pim, TeamProStatHistory.Hits AS Hits, TeamProStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamProStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = "Select MainTable.* FROM (SELECT TeamProStatHistory.Year as Year, TeamProStatHistory.Number as Number, TeamProStatHistory.UniqueID as UniqueID, TeamProStatHistory.Name as Name, TeamProStatHistory.Name as OrderName,'0' As TeamThemeID, TeamProStatHistory.GP AS GP, TeamProStatHistory.W AS W, TeamProStatHistory.L AS L, TeamProStatHistory.T AS T, TeamProStatHistory.OTW AS OTW, TeamProStatHistory.OTL AS OTL, TeamProStatHistory.SOW AS SOW, TeamProStatHistory.SOL AS SOL, TeamProStatHistory.Points AS Points, TeamProStatHistory.GF AS GF, TeamProStatHistory.GA AS GA, TeamProStatHistory.HomeGP AS HomeGP, TeamProStatHistory.HomeW AS HomeW, TeamProStatHistory.HomeL AS HomeL, TeamProStatHistory.HomeT AS HomeT, TeamProStatHistory.HomeOTW AS HomeOTW, TeamProStatHistory.HomeOTL AS HomeOTL, TeamProStatHistory.HomeSOW AS HomeSOW, TeamProStatHistory.HomeSOL AS HomeSOL, TeamProStatHistory.HomeGF AS HomeGF, TeamProStatHistory.HomeGA AS HomeGA, TeamProStatHistory.PPAttemp AS PPAttemp, TeamProStatHistory.PPGoal AS PPGoal, TeamProStatHistory.PKAttemp AS PKAttemp, TeamProStatHistory.PKGoalGA AS PKGoalGA, TeamProStatHistory.PKGoalGF AS PKGoalGF, TeamProStatHistory.ShotsFor AS ShotsFor, TeamProStatHistory.ShotsAga AS ShotsAga, TeamProStatHistory.ShotsBlock AS ShotsBlock, TeamProStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamProStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamProStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamProStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamProStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamProStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamProStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamProStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamProStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamProStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamProStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamProStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamProStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamProStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamProStatHistory.Shutouts AS Shutouts, TeamProStatHistory.TotalGoal AS TotalGoal, TeamProStatHistory.TotalAssist AS TotalAssist, TeamProStatHistory.TotalPoint AS TotalPoint, TeamProStatHistory.Pim AS Pim, TeamProStatHistory.Hits AS Hits, TeamProStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamProStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamProStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamProStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamProStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamProStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamProStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamProStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}
if($Team > 0){$Query = $Query . " WHERE MainTable.Number = " . $Team;}
$Query = $Query . " ORDER BY MainTable.Year, MainTable.Name";
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['TeamStatFarmHistoryAllSeasonPerYear']) OR isset($_POST['TeamStatFarmHistoryAllSeasonPerYear'])){
/* TeamStatFarmHistoryAllSeasonPerYear */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonPerYear = $dbTemp->querySingle($QueryTemp,true);
if($LeagueGeneralAllSeasonPerYear['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonPerYear['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = "Select MainTable.* FROM (SELECT '". $LeagueGeneralAllSeasonPerYear['LeagueYearOutput'] . "' as Year, TeamFarmStat.Number as Number, TeamFarmStat.UniqueID as UniqueID, TeamFarmStat.Name as Name, TeamFarmStat.Name as OrderName, TeamFarmStat.TeamThemeID as TeamThemeID, TeamFarmStat.GP AS GP, TeamFarmStat.W AS W, TeamFarmStat.L AS L, TeamFarmStat.T AS T, TeamFarmStat.OTW AS OTW, TeamFarmStat.OTL AS OTL, TeamFarmStat.SOW AS SOW, TeamFarmStat.SOL AS SOL, TeamFarmStat.Points AS Points, TeamFarmStat.GF AS GF, TeamFarmStat.GA AS GA, TeamFarmStat.HomeGP AS HomeGP, TeamFarmStat.HomeW AS HomeW, TeamFarmStat.HomeL AS HomeL, TeamFarmStat.HomeT AS HomeT, TeamFarmStat.HomeOTW AS HomeOTW, TeamFarmStat.HomeOTL AS HomeOTL, TeamFarmStat.HomeSOW AS HomeSOW, TeamFarmStat.HomeSOL AS HomeSOL, TeamFarmStat.HomeGF AS HomeGF, TeamFarmStat.HomeGA AS HomeGA, TeamFarmStat.PPAttemp AS PPAttemp, TeamFarmStat.PPGoal AS PPGoal, TeamFarmStat.PKAttemp AS PKAttemp, TeamFarmStat.PKGoalGA AS PKGoalGA, TeamFarmStat.PKGoalGF AS PKGoalGF, TeamFarmStat.ShotsFor AS ShotsFor, TeamFarmStat.ShotsAga AS ShotsAga, TeamFarmStat.ShotsBlock AS ShotsBlock, TeamFarmStat.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStat.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStat.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStat.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStat.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStat.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStat.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStat.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStat.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStat.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStat.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStat.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStat.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStat.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStat.Shutouts AS Shutouts, TeamFarmStat.TotalGoal AS TotalGoal, TeamFarmStat.TotalAssist AS TotalAssist, TeamFarmStat.TotalPoint AS TotalPoint, TeamFarmStat.Pim AS Pim, TeamFarmStat.Hits AS Hits, TeamFarmStat.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStat.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStat.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStat.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStat.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStat.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStat.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStat UNION ALL SELECT TeamFarmStatHistory.Year as Year, TeamFarmStatHistory.Number as Number, TeamFarmStatHistory.UniqueID as UniqueID, TeamFarmStatHistory.Name as Name, TeamFarmStatHistory.Name as OrderName,'0' As TeamThemeID, TeamFarmStatHistory.GP AS GP, TeamFarmStatHistory.W AS W, TeamFarmStatHistory.L AS L, TeamFarmStatHistory.T AS T, TeamFarmStatHistory.OTW AS OTW, TeamFarmStatHistory.OTL AS OTL, TeamFarmStatHistory.SOW AS SOW, TeamFarmStatHistory.SOL AS SOL, TeamFarmStatHistory.Points AS Points, TeamFarmStatHistory.GF AS GF, TeamFarmStatHistory.GA AS GA, TeamFarmStatHistory.HomeGP AS HomeGP, TeamFarmStatHistory.HomeW AS HomeW, TeamFarmStatHistory.HomeL AS HomeL, TeamFarmStatHistory.HomeT AS HomeT, TeamFarmStatHistory.HomeOTW AS HomeOTW, TeamFarmStatHistory.HomeOTL AS HomeOTL, TeamFarmStatHistory.HomeSOW AS HomeSOW, TeamFarmStatHistory.HomeSOL AS HomeSOL, TeamFarmStatHistory.HomeGF AS HomeGF, TeamFarmStatHistory.HomeGA AS HomeGA, TeamFarmStatHistory.PPAttemp AS PPAttemp, TeamFarmStatHistory.PPGoal AS PPGoal, TeamFarmStatHistory.PKAttemp AS PKAttemp, TeamFarmStatHistory.PKGoalGA AS PKGoalGA, TeamFarmStatHistory.PKGoalGF AS PKGoalGF, TeamFarmStatHistory.ShotsFor AS ShotsFor, TeamFarmStatHistory.ShotsAga AS ShotsAga, TeamFarmStatHistory.ShotsBlock AS ShotsBlock, TeamFarmStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStatHistory.Shutouts AS Shutouts, TeamFarmStatHistory.TotalGoal AS TotalGoal, TeamFarmStatHistory.TotalAssist AS TotalAssist, TeamFarmStatHistory.TotalPoint AS TotalPoint, TeamFarmStatHistory.Pim AS Pim, TeamFarmStatHistory.Hits AS Hits, TeamFarmStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = "Select MainTable.* FROM (SELECT TeamFarmStatHistory.Year as Year, TeamFarmStatHistory.Number as Number, TeamFarmStatHistory.UniqueID as UniqueID, TeamFarmStatHistory.Name as Name, TeamFarmStatHistory.Name as OrderName,'0' As TeamThemeID, TeamFarmStatHistory.GP AS GP, TeamFarmStatHistory.W AS W, TeamFarmStatHistory.L AS L, TeamFarmStatHistory.T AS T, TeamFarmStatHistory.OTW AS OTW, TeamFarmStatHistory.OTL AS OTL, TeamFarmStatHistory.SOW AS SOW, TeamFarmStatHistory.SOL AS SOL, TeamFarmStatHistory.Points AS Points, TeamFarmStatHistory.GF AS GF, TeamFarmStatHistory.GA AS GA, TeamFarmStatHistory.HomeGP AS HomeGP, TeamFarmStatHistory.HomeW AS HomeW, TeamFarmStatHistory.HomeL AS HomeL, TeamFarmStatHistory.HomeT AS HomeT, TeamFarmStatHistory.HomeOTW AS HomeOTW, TeamFarmStatHistory.HomeOTL AS HomeOTL, TeamFarmStatHistory.HomeSOW AS HomeSOW, TeamFarmStatHistory.HomeSOL AS HomeSOL, TeamFarmStatHistory.HomeGF AS HomeGF, TeamFarmStatHistory.HomeGA AS HomeGA, TeamFarmStatHistory.PPAttemp AS PPAttemp, TeamFarmStatHistory.PPGoal AS PPGoal, TeamFarmStatHistory.PKAttemp AS PKAttemp, TeamFarmStatHistory.PKGoalGA AS PKGoalGA, TeamFarmStatHistory.PKGoalGF AS PKGoalGF, TeamFarmStatHistory.ShotsFor AS ShotsFor, TeamFarmStatHistory.ShotsAga AS ShotsAga, TeamFarmStatHistory.ShotsBlock AS ShotsBlock, TeamFarmStatHistory.ShotsPerPeriod1 AS ShotsPerPeriod1, TeamFarmStatHistory.ShotsPerPeriod2 AS ShotsPerPeriod2, TeamFarmStatHistory.ShotsPerPeriod3 AS ShotsPerPeriod3, TeamFarmStatHistory.ShotsPerPeriod4 AS ShotsPerPeriod4, TeamFarmStatHistory.GoalsPerPeriod1 AS GoalsPerPeriod1, TeamFarmStatHistory.GoalsPerPeriod2 AS GoalsPerPeriod2, TeamFarmStatHistory.GoalsPerPeriod3 AS GoalsPerPeriod3, TeamFarmStatHistory.GoalsPerPeriod4 AS GoalsPerPeriod4, TeamFarmStatHistory.PuckTimeInZoneDF AS PuckTimeInZoneDF, TeamFarmStatHistory.PuckTimeInZoneOF AS PuckTimeInZoneOF, TeamFarmStatHistory.PuckTimeInZoneNT AS PuckTimeInZoneNT, TeamFarmStatHistory.PuckTimeControlinZoneDF AS PuckTimeControlinZoneDF, TeamFarmStatHistory.PuckTimeControlinZoneOF AS PuckTimeControlinZoneOF, TeamFarmStatHistory.PuckTimeControlinZoneNT AS PuckTimeControlinZoneNT, TeamFarmStatHistory.Shutouts AS Shutouts, TeamFarmStatHistory.TotalGoal AS TotalGoal, TeamFarmStatHistory.TotalAssist AS TotalAssist, TeamFarmStatHistory.TotalPoint AS TotalPoint, TeamFarmStatHistory.Pim AS Pim, TeamFarmStatHistory.Hits AS Hits, TeamFarmStatHistory.FaceOffWonDefensifZone AS FaceOffWonDefensifZone, TeamFarmStatHistory.FaceOffTotalDefensifZone AS FaceOffTotalDefensifZone, TeamFarmStatHistory.FaceOffWonOffensifZone AS FaceOffWonOffensifZone, TeamFarmStatHistory.FaceOffTotalOffensifZone AS FaceOffTotalOffensifZone, TeamFarmStatHistory.FaceOffWonNeutralZone AS FaceOffWonNeutralZone, TeamFarmStatHistory.FaceOffTotalNeutralZone AS FaceOffTotalNeutralZone, TeamFarmStatHistory.EmptyNetGoal AS EmptyNetGoal FROM TeamFarmStatHistory WHERE Playoff = '" . $PlayoffString. "' ) AS MainTable";
}
if($Team > 0){$Query = $Query . " WHERE MainTable.Number = " . $Team;}
$Query = $Query . " ORDER BY MainTable.Year, MainTable.Name";
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif((isset($_GET['PlayerStatProHistory']) OR isset($_POST['PlayerStatProHistory'])) AND $Year != 0){
/* PlayerStatProHistory */
$Query = "SELECT PlayerProStatHistory.*, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.ProTeamName AS TeamName, '0' As TeamThemeID, ROUND((CAST(PlayerProStatHistory.G AS REAL) / (PlayerProStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStatHistory.SecondPlay AS REAL) / 60 / (PlayerProStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerProStatHistory.FaceOffWon AS REAL) / (PlayerProStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStatHistory.P AS REAL) / (PlayerProStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerProStatHistory ON PlayerInfoHistory.Number = PlayerProStatHistory.Number WHERE PlayerInfoHistory.Retire = 'False' AND PlayerProStatHistory.GP >= " . $MinimumGP . " AND PlayerInfoHistory.Year = " . $Year . " AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "' AND PlayerProStatHistory.Year = " . $Year . " AND PlayerProStatHistory.Playoff = '" . $PlayoffString. "'";
if($PlayerUniqueID > -1){$Query = $Query . " AND PlayerInfoHistory.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND PlayerInfoHistory.Team = " . $Team;}
$Query = $Query . " ORDER BY PlayerProStatHistory.P DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif((isset($_GET['PlayerStatFarmHistory']) OR isset($_POST['PlayerStatFarmHistory'])) AND $Year != 0){
/* PlayerStatFarmHistory */
$Query = "SELECT PlayerFarmStatHistory.*, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.TeamName AS TeamName, '0' As TeamThemeID, ROUND((CAST(PlayerFarmStatHistory.G AS REAL) / (PlayerFarmStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStatHistory.SecondPlay AS REAL) / 60 / (PlayerFarmStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStatHistory.FaceOffWon AS REAL) / (PlayerFarmStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStatHistory.P AS REAL) / (PlayerFarmStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerFarmStatHistory ON PlayerInfoHistory.Number = PlayerFarmStatHistory.Number WHERE PlayerInfoHistory.Retire = 'False' AND PlayerFarmStatHistory.GP >= " . $MinimumGP . " AND PlayerInfoHistory.Year = " . $Year . " AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "' AND PlayerFarmStatHistory.Year = " . $Year . " AND PlayerFarmStatHistory.Playoff = '" . $PlayoffString. "'";
if($PlayerUniqueID > -1){$Query = $Query . " AND PlayerInfoHistory.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND PlayerInfoHistory.Team = " . $Team;}
$Query = $Query . " ORDER BY PlayerFarmStatHistory.P DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif(isset($_GET['PlayerStatProHistoryAllSeasonMerge']) OR isset($_POST['PlayerStatProHistoryAllSeasonMerge'])){
/* PlayerStatProHistoryAllSeasonMerge */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonMerge = $dbTemp->querySingle($QueryTemp,true);
$Query = "SELECT MainTable.Number, MainTable.UniqueID, '0' As TeamThemeID, MainTable.Name, MainTable.Team, MainTable.TeamName, Sum(MainTable.GP) AS GP, Sum(MainTable.Shots) AS Shots, Sum(MainTable.G) AS G, Sum(MainTable.A) AS A, Sum(MainTable.P) AS P, Sum(MainTable.PlusMinus) AS PlusMinus, Sum(MainTable.Pim) AS Pim, Sum(MainTable.Pim5) AS Pim5, Sum(MainTable.ShotsBlock) AS ShotsBlock, Sum(MainTable.OwnShotsBlock) AS OwnShotsBlock, Sum(MainTable.OwnShotsMissGoal) AS OwnShotsMissGoal, Sum(MainTable.Hits) AS Hits, Sum(MainTable.HitsTook) AS HitsTook, Sum(MainTable.GW) AS GW, Sum(MainTable.GT) AS GT, Sum(MainTable.FaceOffWon) AS FaceOffWon, Sum(MainTable.FaceOffTotal) AS FaceOffTotal, Sum(MainTable.PenalityShotsScore) AS PenalityShotsScore, Sum(MainTable.PenalityShotsTotal) AS PenalityShotsTotal, Sum(MainTable.EmptyNetGoal) AS EmptyNetGoal, Sum(MainTable.SecondPlay) AS SecondPlay, Sum(MainTable.HatTrick) AS HatTrick, Sum(MainTable.PPG) AS PPG, Sum(MainTable.PPA) AS PPA, Sum(MainTable.PPP) AS PPP, Sum(MainTable.PPShots) AS PPShots, Sum(MainTable.PPSecondPlay) AS PPSecondPlay, Sum(MainTable.PKG) AS PKG, Sum(MainTable.PKA) AS PKA, Sum(MainTable.PKP) AS PKP, Sum(MainTable.PKShots) AS PKShots, Sum(MainTable.PKSecondPlay) AS PKSecondPlay, Sum(MainTable.GiveAway) AS GiveAway, Sum(MainTable.TakeAway) AS TakeAway, Sum(MainTable.PuckPossesionTime) AS PuckPossesionTime, Sum(MainTable.FightW) AS FightW, Sum(MainTable.FightL) AS FightL, Sum(MainTable.FightT) AS FightT, Sum(MainTable.Star1) AS Star1, Sum(MainTable.Star2) AS Star2, Sum(MainTable.Star3) AS Star3, ROUND((CAST(Sum(MainTable.G) AS REAL) / (Sum(MainTable.Shots)))*100,2) AS ShotsPCT, ROUND((CAST(Sum(MainTable.SecondPlay) AS REAL) / 60 / (Sum(MainTable.GP))),2) AS AMG,ROUND((CAST(Sum(MainTable.FaceOffWon) AS REAL) / (Sum(MainTable.FaceOffTotal)))*100,2) as FaceoffPCT,ROUND((CAST(Sum(MainTable.P) AS REAL) / (Sum(MainTable.SecondPlay)) * 60 * 20),2) AS P20, Count(MainTable.Year) as CountYear";
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, PlayerProStat.Number, PlayerProStat.UniqueID, '0' As TeamThemeID, PlayerProStat.Name, PlayerProStat.GP, PlayerProStat.Shots, PlayerProStat.G, PlayerProStat.A, PlayerProStat.P, PlayerProStat.PlusMinus, PlayerProStat.Pim, PlayerProStat.Pim5, PlayerProStat.ShotsBlock, PlayerProStat.OwnShotsBlock, PlayerProStat.OwnShotsMissGoal, PlayerProStat.Hits, PlayerProStat.HitsTook, PlayerProStat.GW, PlayerProStat.GT, PlayerProStat.FaceOffWon, PlayerProStat.FaceOffTotal, PlayerProStat.PenalityShotsScore, PlayerProStat.PenalityShotsTotal, PlayerProStat.EmptyNetGoal, PlayerProStat.SecondPlay, PlayerProStat.HatTrick, PlayerProStat.PPG, PlayerProStat.PPA, PlayerProStat.PPP, PlayerProStat.PPShots, PlayerProStat.PPSecondPlay, PlayerProStat.PKG, PlayerProStat.PKA, PlayerProStat.PKP, PlayerProStat.PKShots, PlayerProStat.PKSecondPlay, PlayerProStat.GiveAway, PlayerProStat.TakeAway, PlayerProStat.PuckPossesionTime, PlayerProStat.FightW, PlayerProStat.FightL, PlayerProStat.FightT, PlayerProStat.Star1, PlayerProStat.Star2, PlayerProStat.Star3, PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, PlayerInfo.Team, PlayerInfo.TeamName, PlayerInfo.Rookie, ROUND((CAST(PlayerProStat.G AS REAL) / (PlayerProStat.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStat.SecondPlay AS REAL) / 60 / (PlayerProStat.GP)),2) AS AMG,ROUND((CAST(PlayerProStat.FaceOffWon AS REAL) / (PlayerProStat.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStat.P AS REAL) / (PlayerProStat.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfo INNER JOIN PlayerProStat ON PlayerInfo.Number = PlayerProStat.Number WHERE PlayerProStat.GP > 0) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT PlayerProStatHistory.Year, PlayerProStatHistory.Number, PlayerProStatHistory.UniqueID, '0' As TeamThemeID, PlayerProStatHistory.Name, PlayerProStatHistory.GP, PlayerProStatHistory.Shots, PlayerProStatHistory.G, PlayerProStatHistory.A, PlayerProStatHistory.P, PlayerProStatHistory.PlusMinus, PlayerProStatHistory.Pim, PlayerProStatHistory.Pim5, PlayerProStatHistory.ShotsBlock, PlayerProStatHistory.OwnShotsBlock, PlayerProStatHistory.OwnShotsMissGoal, PlayerProStatHistory.Hits, PlayerProStatHistory.HitsTook, PlayerProStatHistory.GW, PlayerProStatHistory.GT, PlayerProStatHistory.FaceOffWon, PlayerProStatHistory.FaceOffTotal, PlayerProStatHistory.PenalityShotsScore, PlayerProStatHistory.PenalityShotsTotal, PlayerProStatHistory.EmptyNetGoal, PlayerProStatHistory.SecondPlay, PlayerProStatHistory.HatTrick, PlayerProStatHistory.PPG, PlayerProStatHistory.PPA, PlayerProStatHistory.PPP, PlayerProStatHistory.PPShots, PlayerProStatHistory.PPSecondPlay, PlayerProStatHistory.PKG, PlayerProStatHistory.PKA, PlayerProStatHistory.PKP, PlayerProStatHistory.PKShots, PlayerProStatHistory.PKSecondPlay, PlayerProStatHistory.GiveAway, PlayerProStatHistory.TakeAway, PlayerProStatHistory.PuckPossesionTime, PlayerProStatHistory.FightW, PlayerProStatHistory.FightL, PlayerProStatHistory.FightT, PlayerProStatHistory.Star1, PlayerProStatHistory.Star2, PlayerProStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.ProTeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerProStatHistory.G AS REAL) / (PlayerProStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStatHistory.SecondPlay AS REAL) / 60 / (PlayerProStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerProStatHistory.FaceOffWon AS REAL) / (PlayerProStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStatHistory.P AS REAL) / (PlayerProStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerProStatHistory ON PlayerInfoHistory.Number = PlayerProStatHistory.Number AND PlayerInfoHistory.Year = PlayerProStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerProStatHistory.Playoff WHERE PlayerProStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT PlayerProStatHistory.Year, PlayerProStatHistory.Number, PlayerProStatHistory.UniqueID, '0' As TeamThemeID, PlayerProStatHistory.Name, PlayerProStatHistory.GP, PlayerProStatHistory.Shots, PlayerProStatHistory.G, PlayerProStatHistory.A, PlayerProStatHistory.P, PlayerProStatHistory.PlusMinus, PlayerProStatHistory.Pim, PlayerProStatHistory.Pim5, PlayerProStatHistory.ShotsBlock, PlayerProStatHistory.OwnShotsBlock, PlayerProStatHistory.OwnShotsMissGoal, PlayerProStatHistory.Hits, PlayerProStatHistory.HitsTook, PlayerProStatHistory.GW, PlayerProStatHistory.GT, PlayerProStatHistory.FaceOffWon, PlayerProStatHistory.FaceOffTotal, PlayerProStatHistory.PenalityShotsScore, PlayerProStatHistory.PenalityShotsTotal, PlayerProStatHistory.EmptyNetGoal, PlayerProStatHistory.SecondPlay, PlayerProStatHistory.HatTrick, PlayerProStatHistory.PPG, PlayerProStatHistory.PPA, PlayerProStatHistory.PPP, PlayerProStatHistory.PPShots, PlayerProStatHistory.PPSecondPlay, PlayerProStatHistory.PKG, PlayerProStatHistory.PKA, PlayerProStatHistory.PKP, PlayerProStatHistory.PKShots, PlayerProStatHistory.PKSecondPlay, PlayerProStatHistory.GiveAway, PlayerProStatHistory.TakeAway, PlayerProStatHistory.PuckPossesionTime, PlayerProStatHistory.FightW, PlayerProStatHistory.FightL, PlayerProStatHistory.FightT, PlayerProStatHistory.Star1, PlayerProStatHistory.Star2, PlayerProStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.ProTeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerProStatHistory.G AS REAL) / (PlayerProStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStatHistory.SecondPlay AS REAL) / 60 / (PlayerProStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerProStatHistory.FaceOffWon AS REAL) / (PlayerProStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStatHistory.P AS REAL) / (PlayerProStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerProStatHistory ON PlayerInfoHistory.Number = PlayerProStatHistory.Number AND PlayerInfoHistory.Year = PlayerProStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerProStatHistory.Playoff WHERE PlayerProStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " GROUP BY UniqueID ORDER BY Sum(MainTable.P) DESC, Sum(MainTable.GP)";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['PlayerStatFarmHistoryAllSeasonMerge']) OR isset($_POST['PlayerStatFarmHistoryAllSeasonMerge'])){
/* PlayerStatFarmHistoryAllSeasonMerge */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonMerge = $dbTemp->querySingle($QueryTemp,true);
$Query = "SELECT MainTable.Number, MainTable.UniqueID, '0' As TeamThemeID, MainTable.Name, MainTable.Team, MainTable.TeamName, Sum(MainTable.GP) AS GP, Sum(MainTable.Shots) AS Shots, Sum(MainTable.G) AS G, Sum(MainTable.A) AS A, Sum(MainTable.P) AS P, Sum(MainTable.PlusMinus) AS PlusMinus, Sum(MainTable.Pim) AS Pim, Sum(MainTable.Pim5) AS Pim5, Sum(MainTable.ShotsBlock) AS ShotsBlock, Sum(MainTable.OwnShotsBlock) AS OwnShotsBlock, Sum(MainTable.OwnShotsMissGoal) AS OwnShotsMissGoal, Sum(MainTable.Hits) AS Hits, Sum(MainTable.HitsTook) AS HitsTook, Sum(MainTable.GW) AS GW, Sum(MainTable.GT) AS GT, Sum(MainTable.FaceOffWon) AS FaceOffWon, Sum(MainTable.FaceOffTotal) AS FaceOffTotal, Sum(MainTable.PenalityShotsScore) AS PenalityShotsScore, Sum(MainTable.PenalityShotsTotal) AS PenalityShotsTotal, Sum(MainTable.EmptyNetGoal) AS EmptyNetGoal, Sum(MainTable.SecondPlay) AS SecondPlay, Sum(MainTable.HatTrick) AS HatTrick, Sum(MainTable.PPG) AS PPG, Sum(MainTable.PPA) AS PPA, Sum(MainTable.PPP) AS PPP, Sum(MainTable.PPShots) AS PPShots, Sum(MainTable.PPSecondPlay) AS PPSecondPlay, Sum(MainTable.PKG) AS PKG, Sum(MainTable.PKA) AS PKA, Sum(MainTable.PKP) AS PKP, Sum(MainTable.PKShots) AS PKShots, Sum(MainTable.PKSecondPlay) AS PKSecondPlay, Sum(MainTable.GiveAway) AS GiveAway, Sum(MainTable.TakeAway) AS TakeAway, Sum(MainTable.PuckPossesionTime) AS PuckPossesionTime, Sum(MainTable.FightW) AS FightW, Sum(MainTable.FightL) AS FightL, Sum(MainTable.FightT) AS FightT, Sum(MainTable.Star1) AS Star1, Sum(MainTable.Star2) AS Star2, Sum(MainTable.Star3) AS Star3, ROUND((CAST(Sum(MainTable.G) AS REAL) / (Sum(MainTable.Shots)))*100,2) AS ShotsPCT, ROUND((CAST(Sum(MainTable.SecondPlay) AS REAL) / 60 / (Sum(MainTable.GP))),2) AS AMG,ROUND((CAST(Sum(MainTable.FaceOffWon) AS REAL) / (Sum(MainTable.FaceOffTotal)))*100,2) as FaceoffPCT,ROUND((CAST(Sum(MainTable.P) AS REAL) / (Sum(MainTable.SecondPlay)) * 60 * 20),2) AS P20, Count(MainTable.Year) as CountYear";
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, PlayerFarmStat.Number, PlayerFarmStat.UniqueID, '0' As TeamThemeID, PlayerFarmStat.Name, PlayerFarmStat.GP, PlayerFarmStat.Shots, PlayerFarmStat.G, PlayerFarmStat.A, PlayerFarmStat.P, PlayerFarmStat.PlusMinus, PlayerFarmStat.Pim, PlayerFarmStat.Pim5, PlayerFarmStat.ShotsBlock, PlayerFarmStat.OwnShotsBlock, PlayerFarmStat.OwnShotsMissGoal, PlayerFarmStat.Hits, PlayerFarmStat.HitsTook, PlayerFarmStat.GW, PlayerFarmStat.GT, PlayerFarmStat.FaceOffWon, PlayerFarmStat.FaceOffTotal, PlayerFarmStat.PenalityShotsScore, PlayerFarmStat.PenalityShotsTotal, PlayerFarmStat.EmptyNetGoal, PlayerFarmStat.SecondPlay, PlayerFarmStat.HatTrick, PlayerFarmStat.PPG, PlayerFarmStat.PPA, PlayerFarmStat.PPP, PlayerFarmStat.PPShots, PlayerFarmStat.PPSecondPlay, PlayerFarmStat.PKG, PlayerFarmStat.PKA, PlayerFarmStat.PKP, PlayerFarmStat.PKShots, PlayerFarmStat.PKSecondPlay, PlayerFarmStat.GiveAway, PlayerFarmStat.TakeAway, PlayerFarmStat.PuckPossesionTime, PlayerFarmStat.FightW, PlayerFarmStat.FightL, PlayerFarmStat.FightT, PlayerFarmStat.Star1, PlayerFarmStat.Star2, PlayerFarmStat.Star3, PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, PlayerInfo.Team, PlayerInfo.TeamName, PlayerInfo.Rookie, ROUND((CAST(PlayerFarmStat.G AS REAL) / (PlayerFarmStat.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStat.SecondPlay AS REAL) / 60 / (PlayerFarmStat.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStat.FaceOffWon AS REAL) / (PlayerFarmStat.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStat.P AS REAL) / (PlayerFarmStat.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfo INNER JOIN PlayerFarmStat ON PlayerInfo.Number = PlayerFarmStat.Number WHERE PlayerFarmStat.GP > 0) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT PlayerFarmStatHistory.Year, PlayerFarmStatHistory.Number, PlayerFarmStatHistory.UniqueID, '0' As TeamThemeID, PlayerFarmStatHistory.Name, PlayerFarmStatHistory.GP, PlayerFarmStatHistory.Shots, PlayerFarmStatHistory.G, PlayerFarmStatHistory.A, PlayerFarmStatHistory.P, PlayerFarmStatHistory.PlusMinus, PlayerFarmStatHistory.Pim, PlayerFarmStatHistory.Pim5, PlayerFarmStatHistory.ShotsBlock, PlayerFarmStatHistory.OwnShotsBlock, PlayerFarmStatHistory.OwnShotsMissGoal, PlayerFarmStatHistory.Hits, PlayerFarmStatHistory.HitsTook, PlayerFarmStatHistory.GW, PlayerFarmStatHistory.GT, PlayerFarmStatHistory.FaceOffWon, PlayerFarmStatHistory.FaceOffTotal, PlayerFarmStatHistory.PenalityShotsScore, PlayerFarmStatHistory.PenalityShotsTotal, PlayerFarmStatHistory.EmptyNetGoal, PlayerFarmStatHistory.SecondPlay, PlayerFarmStatHistory.HatTrick, PlayerFarmStatHistory.PPG, PlayerFarmStatHistory.PPA, PlayerFarmStatHistory.PPP, PlayerFarmStatHistory.PPShots, PlayerFarmStatHistory.PPSecondPlay, PlayerFarmStatHistory.PKG, PlayerFarmStatHistory.PKA, PlayerFarmStatHistory.PKP, PlayerFarmStatHistory.PKShots, PlayerFarmStatHistory.PKSecondPlay, PlayerFarmStatHistory.GiveAway, PlayerFarmStatHistory.TakeAway, PlayerFarmStatHistory.PuckPossesionTime, PlayerFarmStatHistory.FightW, PlayerFarmStatHistory.FightL, PlayerFarmStatHistory.FightT, PlayerFarmStatHistory.Star1, PlayerFarmStatHistory.Star2, PlayerFarmStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.TeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerFarmStatHistory.G AS REAL) / (PlayerFarmStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStatHistory.SecondPlay AS REAL) / 60 / (PlayerFarmStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStatHistory.FaceOffWon AS REAL) / (PlayerFarmStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStatHistory.P AS REAL) / (PlayerFarmStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerFarmStatHistory ON PlayerInfoHistory.Number = PlayerFarmStatHistory.Number AND PlayerInfoHistory.Year = PlayerFarmStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerFarmStatHistory.Playoff WHERE PlayerFarmStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT PlayerFarmStatHistory.Year, PlayerFarmStatHistory.Number, PlayerFarmStatHistory.UniqueID, '0' As TeamThemeID, PlayerFarmStatHistory.Name, PlayerFarmStatHistory.GP, PlayerFarmStatHistory.Shots, PlayerFarmStatHistory.G, PlayerFarmStatHistory.A, PlayerFarmStatHistory.P, PlayerFarmStatHistory.PlusMinus, PlayerFarmStatHistory.Pim, PlayerFarmStatHistory.Pim5, PlayerFarmStatHistory.ShotsBlock, PlayerFarmStatHistory.OwnShotsBlock, PlayerFarmStatHistory.OwnShotsMissGoal, PlayerFarmStatHistory.Hits, PlayerFarmStatHistory.HitsTook, PlayerFarmStatHistory.GW, PlayerFarmStatHistory.GT, PlayerFarmStatHistory.FaceOffWon, PlayerFarmStatHistory.FaceOffTotal, PlayerFarmStatHistory.PenalityShotsScore, PlayerFarmStatHistory.PenalityShotsTotal, PlayerFarmStatHistory.EmptyNetGoal, PlayerFarmStatHistory.SecondPlay, PlayerFarmStatHistory.HatTrick, PlayerFarmStatHistory.PPG, PlayerFarmStatHistory.PPA, PlayerFarmStatHistory.PPP, PlayerFarmStatHistory.PPShots, PlayerFarmStatHistory.PPSecondPlay, PlayerFarmStatHistory.PKG, PlayerFarmStatHistory.PKA, PlayerFarmStatHistory.PKP, PlayerFarmStatHistory.PKShots, PlayerFarmStatHistory.PKSecondPlay, PlayerFarmStatHistory.GiveAway, PlayerFarmStatHistory.TakeAway, PlayerFarmStatHistory.PuckPossesionTime, PlayerFarmStatHistory.FightW, PlayerFarmStatHistory.FightL, PlayerFarmStatHistory.FightT, PlayerFarmStatHistory.Star1, PlayerFarmStatHistory.Star2, PlayerFarmStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.TeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerFarmStatHistory.G AS REAL) / (PlayerFarmStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStatHistory.SecondPlay AS REAL) / 60 / (PlayerFarmStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStatHistory.FaceOffWon AS REAL) / (PlayerFarmStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStatHistory.P AS REAL) / (PlayerFarmStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerFarmStatHistory ON PlayerInfoHistory.Number = PlayerFarmStatHistory.Number AND PlayerInfoHistory.Year = PlayerFarmStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerFarmStatHistory.Playoff WHERE PlayerFarmStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " GROUP BY UniqueID ORDER BY Sum(MainTable.P) DESC, Sum(MainTable.GP)";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['PlayerStatProHistoryAllSeasonPerYear']) OR isset($_POST['PlayerStatProHistoryAllSeasonPerYear'])){
/* PlayerStatProHistoryAllSeasonPerYear */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonPerYear = $dbTemp->querySingle($QueryTemp,true);
$Query = "Select MainTable.*";
if($LeagueGeneralAllSeasonPerYear['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonPerYear['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonPerYear['LeagueYearOutput'] . "' as Year, PlayerProStat.Number, PlayerProStat.UniqueID, '0' As TeamThemeID, PlayerProStat.Name, PlayerProStat.GP, PlayerProStat.Shots, PlayerProStat.G, PlayerProStat.A, PlayerProStat.P, PlayerProStat.PlusMinus, PlayerProStat.Pim, PlayerProStat.Pim5, PlayerProStat.ShotsBlock, PlayerProStat.OwnShotsBlock, PlayerProStat.OwnShotsMissGoal, PlayerProStat.Hits, PlayerProStat.HitsTook, PlayerProStat.GW, PlayerProStat.GT, PlayerProStat.FaceOffWon, PlayerProStat.FaceOffTotal, PlayerProStat.PenalityShotsScore, PlayerProStat.PenalityShotsTotal, PlayerProStat.EmptyNetGoal, PlayerProStat.SecondPlay, PlayerProStat.HatTrick, PlayerProStat.PPG, PlayerProStat.PPA, PlayerProStat.PPP, PlayerProStat.PPShots, PlayerProStat.PPSecondPlay, PlayerProStat.PKG, PlayerProStat.PKA, PlayerProStat.PKP, PlayerProStat.PKShots, PlayerProStat.PKSecondPlay, PlayerProStat.GiveAway, PlayerProStat.TakeAway, PlayerProStat.PuckPossesionTime, PlayerProStat.FightW, PlayerProStat.FightL, PlayerProStat.FightT, PlayerProStat.Star1, PlayerProStat.Star2, PlayerProStat.Star3, PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, PlayerInfo.Team, PlayerInfo.TeamName, PlayerInfo.Rookie, ROUND((CAST(PlayerProStat.G AS REAL) / (PlayerProStat.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStat.SecondPlay AS REAL) / 60 / (PlayerProStat.GP)),2) AS AMG,ROUND((CAST(PlayerProStat.FaceOffWon AS REAL) / (PlayerProStat.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStat.P AS REAL) / (PlayerProStat.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfo INNER JOIN PlayerProStat ON PlayerInfo.Number = PlayerProStat.Number WHERE PlayerProStat.GP > 0) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT PlayerProStatHistory.Year, PlayerProStatHistory.Number, PlayerProStatHistory.UniqueID, '0' As TeamThemeID, PlayerProStatHistory.Name, PlayerProStatHistory.GP, PlayerProStatHistory.Shots, PlayerProStatHistory.G, PlayerProStatHistory.A, PlayerProStatHistory.P, PlayerProStatHistory.PlusMinus, PlayerProStatHistory.Pim, PlayerProStatHistory.Pim5, PlayerProStatHistory.ShotsBlock, PlayerProStatHistory.OwnShotsBlock, PlayerProStatHistory.OwnShotsMissGoal, PlayerProStatHistory.Hits, PlayerProStatHistory.HitsTook, PlayerProStatHistory.GW, PlayerProStatHistory.GT, PlayerProStatHistory.FaceOffWon, PlayerProStatHistory.FaceOffTotal, PlayerProStatHistory.PenalityShotsScore, PlayerProStatHistory.PenalityShotsTotal, PlayerProStatHistory.EmptyNetGoal, PlayerProStatHistory.SecondPlay, PlayerProStatHistory.HatTrick, PlayerProStatHistory.PPG, PlayerProStatHistory.PPA, PlayerProStatHistory.PPP, PlayerProStatHistory.PPShots, PlayerProStatHistory.PPSecondPlay, PlayerProStatHistory.PKG, PlayerProStatHistory.PKA, PlayerProStatHistory.PKP, PlayerProStatHistory.PKShots, PlayerProStatHistory.PKSecondPlay, PlayerProStatHistory.GiveAway, PlayerProStatHistory.TakeAway, PlayerProStatHistory.PuckPossesionTime, PlayerProStatHistory.FightW, PlayerProStatHistory.FightL, PlayerProStatHistory.FightT, PlayerProStatHistory.Star1, PlayerProStatHistory.Star2, PlayerProStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.ProTeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerProStatHistory.G AS REAL) / (PlayerProStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStatHistory.SecondPlay AS REAL) / 60 / (PlayerProStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerProStatHistory.FaceOffWon AS REAL) / (PlayerProStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStatHistory.P AS REAL) / (PlayerProStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerProStatHistory ON PlayerInfoHistory.Number = PlayerProStatHistory.Number AND PlayerInfoHistory.Year = PlayerProStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerProStatHistory.Playoff WHERE PlayerProStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT PlayerProStatHistory.Year, PlayerProStatHistory.Number, PlayerProStatHistory.UniqueID, '0' As TeamThemeID, PlayerProStatHistory.Name, PlayerProStatHistory.GP, PlayerProStatHistory.Shots, PlayerProStatHistory.G, PlayerProStatHistory.A, PlayerProStatHistory.P, PlayerProStatHistory.PlusMinus, PlayerProStatHistory.Pim, PlayerProStatHistory.Pim5, PlayerProStatHistory.ShotsBlock, PlayerProStatHistory.OwnShotsBlock, PlayerProStatHistory.OwnShotsMissGoal, PlayerProStatHistory.Hits, PlayerProStatHistory.HitsTook, PlayerProStatHistory.GW, PlayerProStatHistory.GT, PlayerProStatHistory.FaceOffWon, PlayerProStatHistory.FaceOffTotal, PlayerProStatHistory.PenalityShotsScore, PlayerProStatHistory.PenalityShotsTotal, PlayerProStatHistory.EmptyNetGoal, PlayerProStatHistory.SecondPlay, PlayerProStatHistory.HatTrick, PlayerProStatHistory.PPG, PlayerProStatHistory.PPA, PlayerProStatHistory.PPP, PlayerProStatHistory.PPShots, PlayerProStatHistory.PPSecondPlay, PlayerProStatHistory.PKG, PlayerProStatHistory.PKA, PlayerProStatHistory.PKP, PlayerProStatHistory.PKShots, PlayerProStatHistory.PKSecondPlay, PlayerProStatHistory.GiveAway, PlayerProStatHistory.TakeAway, PlayerProStatHistory.PuckPossesionTime, PlayerProStatHistory.FightW, PlayerProStatHistory.FightL, PlayerProStatHistory.FightT, PlayerProStatHistory.Star1, PlayerProStatHistory.Star2, PlayerProStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.ProTeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerProStatHistory.G AS REAL) / (PlayerProStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerProStatHistory.SecondPlay AS REAL) / 60 / (PlayerProStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerProStatHistory.FaceOffWon AS REAL) / (PlayerProStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerProStatHistory.P AS REAL) / (PlayerProStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerProStatHistory ON PlayerInfoHistory.Number = PlayerProStatHistory.Number AND PlayerInfoHistory.Year = PlayerProStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerProStatHistory.Playoff WHERE PlayerProStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " ORDER BY MainTable.Year ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['PlayerStatFarmHistoryAllSeasonPerYear']) OR isset($_POST['PlayerStatFarmHistoryAllSeasonPerYear'])){
/* PlayerStatFarmHistoryAllSeasonPerYear */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonPerYear = $dbTemp->querySingle($QueryTemp,true);
$Query = "Select MainTable.*";
if($LeagueGeneralAllSeasonPerYear['PlayOffStarted'] == $PlayoffString & $LeagueGeneralAllSeasonPerYear['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM (Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonPerYear['LeagueYearOutput'] . "' as Year, PlayerFarmStat.Number, PlayerFarmStat.UniqueID, '0' As TeamThemeID, PlayerFarmStat.Name, PlayerFarmStat.GP, PlayerFarmStat.Shots, PlayerFarmStat.G, PlayerFarmStat.A, PlayerFarmStat.P, PlayerFarmStat.PlusMinus, PlayerFarmStat.Pim, PlayerFarmStat.Pim5, PlayerFarmStat.ShotsBlock, PlayerFarmStat.OwnShotsBlock, PlayerFarmStat.OwnShotsMissGoal, PlayerFarmStat.Hits, PlayerFarmStat.HitsTook, PlayerFarmStat.GW, PlayerFarmStat.GT, PlayerFarmStat.FaceOffWon, PlayerFarmStat.FaceOffTotal, PlayerFarmStat.PenalityShotsScore, PlayerFarmStat.PenalityShotsTotal, PlayerFarmStat.EmptyNetGoal, PlayerFarmStat.SecondPlay, PlayerFarmStat.HatTrick, PlayerFarmStat.PPG, PlayerFarmStat.PPA, PlayerFarmStat.PPP, PlayerFarmStat.PPShots, PlayerFarmStat.PPSecondPlay, PlayerFarmStat.PKG, PlayerFarmStat.PKA, PlayerFarmStat.PKP, PlayerFarmStat.PKShots, PlayerFarmStat.PKSecondPlay, PlayerFarmStat.GiveAway, PlayerFarmStat.TakeAway, PlayerFarmStat.PuckPossesionTime, PlayerFarmStat.FightW, PlayerFarmStat.FightL, PlayerFarmStat.FightT, PlayerFarmStat.Star1, PlayerFarmStat.Star2, PlayerFarmStat.Star3, PlayerInfo.PosC, PlayerInfo.PosLW, PlayerInfo.PosRW, PlayerInfo.PosD, PlayerInfo.Team, PlayerInfo.TeamName, PlayerInfo.Rookie, ROUND((CAST(PlayerFarmStat.G AS REAL) / (PlayerFarmStat.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStat.SecondPlay AS REAL) / 60 / (PlayerFarmStat.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStat.FaceOffWon AS REAL) / (PlayerFarmStat.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStat.P AS REAL) / (PlayerFarmStat.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfo INNER JOIN PlayerFarmStat ON PlayerInfo.Number = PlayerFarmStat.Number WHERE PlayerFarmStat.GP > 0) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT PlayerFarmStatHistory.Year, PlayerFarmStatHistory.Number, PlayerFarmStatHistory.UniqueID, '0' As TeamThemeID, PlayerFarmStatHistory.Name, PlayerFarmStatHistory.GP, PlayerFarmStatHistory.Shots, PlayerFarmStatHistory.G, PlayerFarmStatHistory.A, PlayerFarmStatHistory.P, PlayerFarmStatHistory.PlusMinus, PlayerFarmStatHistory.Pim, PlayerFarmStatHistory.Pim5, PlayerFarmStatHistory.ShotsBlock, PlayerFarmStatHistory.OwnShotsBlock, PlayerFarmStatHistory.OwnShotsMissGoal, PlayerFarmStatHistory.Hits, PlayerFarmStatHistory.HitsTook, PlayerFarmStatHistory.GW, PlayerFarmStatHistory.GT, PlayerFarmStatHistory.FaceOffWon, PlayerFarmStatHistory.FaceOffTotal, PlayerFarmStatHistory.PenalityShotsScore, PlayerFarmStatHistory.PenalityShotsTotal, PlayerFarmStatHistory.EmptyNetGoal, PlayerFarmStatHistory.SecondPlay, PlayerFarmStatHistory.HatTrick, PlayerFarmStatHistory.PPG, PlayerFarmStatHistory.PPA, PlayerFarmStatHistory.PPP, PlayerFarmStatHistory.PPShots, PlayerFarmStatHistory.PPSecondPlay, PlayerFarmStatHistory.PKG, PlayerFarmStatHistory.PKA, PlayerFarmStatHistory.PKP, PlayerFarmStatHistory.PKShots, PlayerFarmStatHistory.PKSecondPlay, PlayerFarmStatHistory.GiveAway, PlayerFarmStatHistory.TakeAway, PlayerFarmStatHistory.PuckPossesionTime, PlayerFarmStatHistory.FightW, PlayerFarmStatHistory.FightL, PlayerFarmStatHistory.FightT, PlayerFarmStatHistory.Star1, PlayerFarmStatHistory.Star2, PlayerFarmStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.TeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerFarmStatHistory.G AS REAL) / (PlayerFarmStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStatHistory.SecondPlay AS REAL) / 60 / (PlayerFarmStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStatHistory.FaceOffWon AS REAL) / (PlayerFarmStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStatHistory.P AS REAL) / (PlayerFarmStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerFarmStatHistory ON PlayerInfoHistory.Number = PlayerFarmStatHistory.Number AND PlayerInfoHistory.Year = PlayerFarmStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerFarmStatHistory.Playoff WHERE PlayerFarmStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT PlayerFarmStatHistory.Year, PlayerFarmStatHistory.Number, PlayerFarmStatHistory.UniqueID, '0' As TeamThemeID, PlayerFarmStatHistory.Name, PlayerFarmStatHistory.GP, PlayerFarmStatHistory.Shots, PlayerFarmStatHistory.G, PlayerFarmStatHistory.A, PlayerFarmStatHistory.P, PlayerFarmStatHistory.PlusMinus, PlayerFarmStatHistory.Pim, PlayerFarmStatHistory.Pim5, PlayerFarmStatHistory.ShotsBlock, PlayerFarmStatHistory.OwnShotsBlock, PlayerFarmStatHistory.OwnShotsMissGoal, PlayerFarmStatHistory.Hits, PlayerFarmStatHistory.HitsTook, PlayerFarmStatHistory.GW, PlayerFarmStatHistory.GT, PlayerFarmStatHistory.FaceOffWon, PlayerFarmStatHistory.FaceOffTotal, PlayerFarmStatHistory.PenalityShotsScore, PlayerFarmStatHistory.PenalityShotsTotal, PlayerFarmStatHistory.EmptyNetGoal, PlayerFarmStatHistory.SecondPlay, PlayerFarmStatHistory.HatTrick, PlayerFarmStatHistory.PPG, PlayerFarmStatHistory.PPA, PlayerFarmStatHistory.PPP, PlayerFarmStatHistory.PPShots, PlayerFarmStatHistory.PPSecondPlay, PlayerFarmStatHistory.PKG, PlayerFarmStatHistory.PKA, PlayerFarmStatHistory.PKP, PlayerFarmStatHistory.PKShots, PlayerFarmStatHistory.PKSecondPlay, PlayerFarmStatHistory.GiveAway, PlayerFarmStatHistory.TakeAway, PlayerFarmStatHistory.PuckPossesionTime, PlayerFarmStatHistory.FightW, PlayerFarmStatHistory.FightL, PlayerFarmStatHistory.FightT, PlayerFarmStatHistory.Star1, PlayerFarmStatHistory.Star2, PlayerFarmStatHistory.Star3, PlayerInfoHistory.PosC, PlayerInfoHistory.PosLW, PlayerInfoHistory.PosRW, PlayerInfoHistory.PosD, PlayerInfoHistory.Team, PlayerInfoHistory.TeamName AS TeamName, PlayerInfoHistory.Rookie, ROUND((CAST(PlayerFarmStatHistory.G AS REAL) / (PlayerFarmStatHistory.Shots))*100,2) AS ShotsPCT, ROUND((CAST(PlayerFarmStatHistory.SecondPlay AS REAL) / 60 / (PlayerFarmStatHistory.GP)),2) AS AMG,ROUND((CAST(PlayerFarmStatHistory.FaceOffWon AS REAL) / (PlayerFarmStatHistory.FaceOffTotal))*100,2) as FaceoffPCT,ROUND((CAST(PlayerFarmStatHistory.P AS REAL) / (PlayerFarmStatHistory.SecondPlay) * 60 * 20),2) AS P20 FROM PlayerInfoHistory INNER JOIN PlayerFarmStatHistory ON PlayerInfoHistory.Number = PlayerFarmStatHistory.Number AND PlayerInfoHistory.Year = PlayerFarmStatHistory.Year AND PlayerInfoHistory.Playoff = PlayerFarmStatHistory.Playoff WHERE PlayerFarmStatHistory.GP > 0 AND PlayerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " ORDER BY MainTable.Year ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif((isset($_GET['GoalerStatProHistory']) OR isset($_POST['GoalerStatProHistory'])) AND $Year != 0){
/* GoalerStatProHistory */
$Query = "SELECT GoalerInfoHistory.ProTeamName AS TeamName, '0' As TeamThemeID, GoalerProStatHistory.*, ROUND((CAST(GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerProStatHistory.SA - GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerProStatHistory.PenalityShotsShots - GoalerProStatHistory.PenalityShotsGoals AS REAL) / (GoalerProStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerProStatHistory ON GoalerInfoHistory.Number = GoalerProStatHistory.Number WHERE GoalerInfoHistory.Retire = 'False' AND GoalerProStatHistory.GP >= " . $MinimumGP . " AND GoalerInfoHistory.Year = " . $Year . " AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "' AND GoalerProStatHistory.Year = " . $Year . " AND GoalerProStatHistory.Playoff = '" . $PlayoffString. "'";
if($PlayerUniqueID > -1){$Query = $Query . " AND GoalerInfoHistory.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND GoalerInfoHistory.Team = " . $Team;}
$Query = $Query . " ORDER BY GoalerProStatHistory.W DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif((isset($_GET['GoalerStatFarmHistory']) OR isset($_POST['GoalerStatFarmHistory'])) AND $Year != 0){
/* GoalerStatFarmHistory */
$Query = "SELECT GoalerInfoHistory.TeamName AS TeamName, '0' As TeamThemeID, GoalerFarmStatHistory.*, ROUND((CAST(GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerFarmStatHistory.SA - GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerFarmStatHistory.PenalityShotsShots - GoalerFarmStatHistory.PenalityShotsGoals AS REAL) / (GoalerFarmStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerFarmStatHistory ON GoalerInfoHistory.Number = GoalerFarmStatHistory.Number WHERE GoalerInfoHistory.Retire = 'False' AND GoalerFarmStatHistory.GP >= " . $MinimumGP . " AND GoalerInfoHistory.Year = " . $Year . " AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "' AND GoalerFarmStatHistory.Year = " . $Year . " AND GoalerFarmStatHistory.Playoff = '" . $PlayoffString. "'";
if($PlayerUniqueID > -1){$Query = $Query . " AND GoalerInfoHistory.UniqueID = " . $PlayerUniqueID;}
if($Team > 0){$Query = $Query . " AND GoalerInfoHistory.Team = " . $Team;}
$Query = $Query . " ORDER BY GoalerFarmStatHistory.W DESC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
}elseif(isset($_GET['GoalerStatProHistoryAllSeasonMerge']) OR isset($_POST['GoalerStatProHistoryAllSeasonMerge'])){
/* GoalerStatProHistoryAllSeasonMerge */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonMerge = $dbTemp->querySingle($QueryTemp,true);
$Query = "SELECT MainTable.Number, MainTable.UniqueID, '0' As TeamThemeID, MainTable.Name, MainTable.Team, MainTable.TeamName, Sum(MainTable.GP) AS GP, Sum(MainTable.SecondPlay) AS SecondPlay, Sum(MainTable.W) AS W, Sum(MainTable.L) AS L, Sum(MainTable.OTL) AS OTL, Sum(MainTable.Shootout) AS Shootout, Sum(MainTable.GA) AS GA, Sum(MainTable.SA) AS SA, Sum(MainTable.SARebound) AS SARebound, Sum(MainTable.Pim) AS Pim, Sum(MainTable.A) AS A, Sum(MainTable.PenalityShotsShots) AS PenalityShotsShots, Sum(MainTable.PenalityShotsGoals) AS PenalityShotsGoals, Sum(MainTable.StartGoaler) AS StartGoaler, Sum(MainTable.BackupGoaler) AS BackupGoaler, Sum(MainTable.EmptyNetGoal) AS EmptyNetGoal, Sum(MainTable.Star1) AS Star1, Sum(MainTable.Star2) AS Star2, Sum(MainTable.Star3) AS Star3, ROUND((CAST(Sum(MainTable.GA) AS REAL) / (Sum(MainTable.SecondPlay) / 60))*60, 3) AS GAA, ROUND((CAST(Sum(MainTable.SA) - Sum(MainTable.GA) AS REAL) / (Sum(MainTable.SA))), 3) AS PCT, ROUND((CAST(Sum(MainTable.PenalityShotsShots) - Sum(MainTable.PenalityShotsGoals) AS REAL) / (Sum(MainTable.PenalityShotsShots))), 3) AS PenalityShotsPCT, Count(MainTable.Year) as CountYear";
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM ( Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, GoalerInfo.TeamName, GoalerInfo.Team, GoalerInfo.Rookie, '0' As TeamThemeID, GoalerProStat.Number, GoalerProStat.UniqueID, GoalerProStat.Name, GoalerProStat.GP, GoalerProStat.SecondPlay, GoalerProStat.W, GoalerProStat.L, GoalerProStat.OTL, GoalerProStat.Shootout, GoalerProStat.GA, GoalerProStat.SA, GoalerProStat.SARebound, GoalerProStat.Pim, GoalerProStat.A, GoalerProStat.PenalityShotsShots, GoalerProStat.PenalityShotsGoals, GoalerProStat.StartGoaler, GoalerProStat.BackupGoaler, GoalerProStat.EmptyNetGoal, GoalerProStat.Star1, GoalerProStat.Star2, GoalerProStat.Star3, ROUND((CAST(GoalerProStat.GA AS REAL) / (GoalerProStat.SecondPlay / 60))*60, 3) AS GAA, ROUND((CAST(GoalerProStat.SA - GoalerProStat.GA AS REAL) / (GoalerProStat.SA)), 3) AS PCT, ROUND((CAST(GoalerProStat.PenalityShotsShots - GoalerProStat.PenalityShotsGoals AS REAL) / (GoalerProStat.PenalityShotsShots)), 3) AS PenalityShotsPCT FROM GoalerInfo INNER JOIN GoalerProStat ON GoalerInfo.Number = GoalerProStat.Number WHERE GoalerProStat.GP > 0 ) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT GoalerProStatHistory.Year, GoalerInfoHistory.ProTeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerProStatHistory.Number, GoalerProStatHistory.UniqueID, GoalerProStatHistory.Name, GoalerProStatHistory.GP, GoalerProStatHistory.SecondPlay, GoalerProStatHistory.W, GoalerProStatHistory.L, GoalerProStatHistory.OTL, GoalerProStatHistory.Shootout, GoalerProStatHistory.GA, GoalerProStatHistory.SA, GoalerProStatHistory.SARebound, GoalerProStatHistory.Pim, GoalerProStatHistory.A, GoalerProStatHistory.PenalityShotsShots, GoalerProStatHistory.PenalityShotsGoals, GoalerProStatHistory.StartGoaler, GoalerProStatHistory.BackupGoaler, GoalerProStatHistory.EmptyNetGoal, GoalerProStatHistory.Star1, GoalerProStatHistory.Star2, GoalerProStatHistory.Star3, ROUND((CAST(GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerProStatHistory.SA - GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerProStatHistory.PenalityShotsShots - GoalerProStatHistory.PenalityShotsGoals AS REAL) / (GoalerProStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerProStatHistory ON GoalerInfoHistory.Number = GoalerProStatHistory.Number AND GoalerInfoHistory.Year = GoalerProStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerProStatHistory.Playoff WHERE GoalerProStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT GoalerProStatHistory.Year, GoalerInfoHistory.ProTeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerProStatHistory.Number, GoalerProStatHistory.UniqueID, GoalerProStatHistory.Name, GoalerProStatHistory.GP, GoalerProStatHistory.SecondPlay, GoalerProStatHistory.W, GoalerProStatHistory.L, GoalerProStatHistory.OTL, GoalerProStatHistory.Shootout, GoalerProStatHistory.GA, GoalerProStatHistory.SA, GoalerProStatHistory.SARebound, GoalerProStatHistory.Pim, GoalerProStatHistory.A, GoalerProStatHistory.PenalityShotsShots, GoalerProStatHistory.PenalityShotsGoals, GoalerProStatHistory.StartGoaler, GoalerProStatHistory.BackupGoaler, GoalerProStatHistory.EmptyNetGoal, GoalerProStatHistory.Star1, GoalerProStatHistory.Star2, GoalerProStatHistory.Star3, ROUND((CAST(GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerProStatHistory.SA - GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerProStatHistory.PenalityShotsShots - GoalerProStatHistory.PenalityShotsGoals AS REAL) / (GoalerProStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerProStatHistory ON GoalerInfoHistory.Number = GoalerProStatHistory.Number AND GoalerInfoHistory.Year = GoalerProStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerProStatHistory.Playoff WHERE GoalerProStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " GROUP BY UniqueID ORDER BY Sum(MainTable.W) DESC, Sum(MainTable.GP)";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['GoalerStatFarmHistoryAllSeasonMerge']) OR isset($_POST['GoalerStatFarmHistoryAllSeasonMerge'])){
/* GoalerStatFarmHistoryAllSeasonMerge */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonMerge = $dbTemp->querySingle($QueryTemp,true);
$Query = "SELECT MainTable.Number, MainTable.UniqueID, '0' As TeamThemeID, MainTable.Name, MainTable.Team, MainTable.TeamName, Sum(MainTable.GP) AS GP, Sum(MainTable.SecondPlay) AS SecondPlay, Sum(MainTable.W) AS W, Sum(MainTable.L) AS L, Sum(MainTable.OTL) AS OTL, Sum(MainTable.Shootout) AS Shootout, Sum(MainTable.GA) AS GA, Sum(MainTable.SA) AS SA, Sum(MainTable.SARebound) AS SARebound, Sum(MainTable.Pim) AS Pim, Sum(MainTable.A) AS A, Sum(MainTable.PenalityShotsShots) AS PenalityShotsShots, Sum(MainTable.PenalityShotsGoals) AS PenalityShotsGoals, Sum(MainTable.StartGoaler) AS StartGoaler, Sum(MainTable.BackupGoaler) AS BackupGoaler, Sum(MainTable.EmptyNetGoal) AS EmptyNetGoal, Sum(MainTable.Star1) AS Star1, Sum(MainTable.Star2) AS Star2, Sum(MainTable.Star3) AS Star3, ROUND((CAST(Sum(MainTable.GA) AS REAL) / (Sum(MainTable.SecondPlay) / 60))*60, 3) AS GAA, ROUND((CAST(Sum(MainTable.SA) - Sum(MainTable.GA) AS REAL) / (Sum(MainTable.SA))), 3) AS PCT, ROUND((CAST(Sum(MainTable.PenalityShotsShots) - Sum(MainTable.PenalityShotsGoals) AS REAL) / (Sum(MainTable.PenalityShotsShots))), 3) AS PenalityShotsPCT, Count(MainTable.Year) as CountYear";
if($LeagueGeneralAllSeasonMerge['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonMerge['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM ( Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonMerge['LeagueYearOutput'] . "' as Year, GoalerInfo.TeamName, GoalerInfo.Team, GoalerInfo.Rookie, '0' As TeamThemeID, GoalerFarmStat.Number, GoalerFarmStat.UniqueID, GoalerFarmStat.Name, GoalerFarmStat.GP, GoalerFarmStat.SecondPlay, GoalerFarmStat.W, GoalerFarmStat.L, GoalerFarmStat.OTL, GoalerFarmStat.Shootout, GoalerFarmStat.GA, GoalerFarmStat.SA, GoalerFarmStat.SARebound, GoalerFarmStat.Pim, GoalerFarmStat.A, GoalerFarmStat.PenalityShotsShots, GoalerFarmStat.PenalityShotsGoals, GoalerFarmStat.StartGoaler, GoalerFarmStat.BackupGoaler, GoalerFarmStat.EmptyNetGoal, GoalerFarmStat.Star1, GoalerFarmStat.Star2, GoalerFarmStat.Star3, ROUND((CAST(GoalerFarmStat.GA AS REAL) / (GoalerFarmStat.SecondPlay / 60))*60, 3) AS GAA, ROUND((CAST(GoalerFarmStat.SA - GoalerFarmStat.GA AS REAL) / (GoalerFarmStat.SA)), 3) AS PCT, ROUND((CAST(GoalerFarmStat.PenalityShotsShots - GoalerFarmStat.PenalityShotsGoals AS REAL) / (GoalerFarmStat.PenalityShotsShots)), 3) AS PenalityShotsPCT FROM GoalerInfo INNER JOIN GoalerFarmStat ON GoalerInfo.Number = GoalerFarmStat.Number WHERE GoalerFarmStat.GP > 0 ) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT GoalerFarmStatHistory.Year, GoalerInfoHistory.TeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerFarmStatHistory.Number, GoalerFarmStatHistory.UniqueID, GoalerFarmStatHistory.Name, GoalerFarmStatHistory.GP, GoalerFarmStatHistory.SecondPlay, GoalerFarmStatHistory.W, GoalerFarmStatHistory.L, GoalerFarmStatHistory.OTL, GoalerFarmStatHistory.Shootout, GoalerFarmStatHistory.GA, GoalerFarmStatHistory.SA, GoalerFarmStatHistory.SARebound, GoalerFarmStatHistory.Pim, GoalerFarmStatHistory.A, GoalerFarmStatHistory.PenalityShotsShots, GoalerFarmStatHistory.PenalityShotsGoals, GoalerFarmStatHistory.StartGoaler, GoalerFarmStatHistory.BackupGoaler, GoalerFarmStatHistory.EmptyNetGoal, GoalerFarmStatHistory.Star1, GoalerFarmStatHistory.Star2, GoalerFarmStatHistory.Star3, ROUND((CAST(GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerFarmStatHistory.SA - GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerFarmStatHistory.PenalityShotsShots - GoalerFarmStatHistory.PenalityShotsGoals AS REAL) / (GoalerFarmStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerFarmStatHistory ON GoalerInfoHistory.Number = GoalerFarmStatHistory.Number AND GoalerInfoHistory.Year = GoalerFarmStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerFarmStatHistory.Playoff WHERE GoalerFarmStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT GoalerFarmStatHistory.Year, GoalerInfoHistory.TeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerFarmStatHistory.Number, GoalerFarmStatHistory.UniqueID, GoalerFarmStatHistory.Name, GoalerFarmStatHistory.GP, GoalerFarmStatHistory.SecondPlay, GoalerFarmStatHistory.W, GoalerFarmStatHistory.L, GoalerFarmStatHistory.OTL, GoalerFarmStatHistory.Shootout, GoalerFarmStatHistory.GA, GoalerFarmStatHistory.SA, GoalerFarmStatHistory.SARebound, GoalerFarmStatHistory.Pim, GoalerFarmStatHistory.A, GoalerFarmStatHistory.PenalityShotsShots, GoalerFarmStatHistory.PenalityShotsGoals, GoalerFarmStatHistory.StartGoaler, GoalerFarmStatHistory.BackupGoaler, GoalerFarmStatHistory.EmptyNetGoal, GoalerFarmStatHistory.Star1, GoalerFarmStatHistory.Star2, GoalerFarmStatHistory.Star3, ROUND((CAST(GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerFarmStatHistory.SA - GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerFarmStatHistory.PenalityShotsShots - GoalerFarmStatHistory.PenalityShotsGoals AS REAL) / (GoalerFarmStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerFarmStatHistory ON GoalerInfoHistory.Number = GoalerFarmStatHistory.Number AND GoalerInfoHistory.Year = GoalerFarmStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerFarmStatHistory.Playoff WHERE GoalerFarmStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " GROUP BY UniqueID ORDER BY Sum(MainTable.W) DESC, Sum(MainTable.GP)";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['GoalerStatProHistoryAllSeasonPerYear']) OR isset($_POST['GoalerStatProHistoryAllSeasonPerYear'])){
/* GoalerStatProHistoryAllSeasonPerYear */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonPerYear = $dbTemp->querySingle($QueryTemp,true);
$Query = "Select MainTable.*";
if($LeagueGeneralAllSeasonPerYear['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonPerYear['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM ( Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonPerYear ['LeagueYearOutput'] . "' as Year, GoalerInfo.TeamName, GoalerInfo.Team, GoalerInfo.Rookie, '0' As TeamThemeID, GoalerProStat.Number, GoalerProStat.UniqueID, GoalerProStat.Name, GoalerProStat.GP, GoalerProStat.SecondPlay, GoalerProStat.W, GoalerProStat.L, GoalerProStat.OTL, GoalerProStat.Shootout, GoalerProStat.GA, GoalerProStat.SA, GoalerProStat.SARebound, GoalerProStat.Pim, GoalerProStat.A, GoalerProStat.PenalityShotsShots, GoalerProStat.PenalityShotsGoals, GoalerProStat.StartGoaler, GoalerProStat.BackupGoaler, GoalerProStat.EmptyNetGoal, GoalerProStat.Star1, GoalerProStat.Star2, GoalerProStat.Star3, ROUND((CAST(GoalerProStat.GA AS REAL) / (GoalerProStat.SecondPlay / 60))*60, 3) AS GAA, ROUND((CAST(GoalerProStat.SA - GoalerProStat.GA AS REAL) / (GoalerProStat.SA)), 3) AS PCT, ROUND((CAST(GoalerProStat.PenalityShotsShots - GoalerProStat.PenalityShotsGoals AS REAL) / (GoalerProStat.PenalityShotsShots)), 3) AS PenalityShotsPCT FROM GoalerInfo INNER JOIN GoalerProStat ON GoalerInfo.Number = GoalerProStat.Number WHERE GoalerProStat.GP > 0 ) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT GoalerProStatHistory.Year, GoalerInfoHistory.ProTeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerProStatHistory.Number, GoalerProStatHistory.UniqueID, GoalerProStatHistory.Name, GoalerProStatHistory.GP, GoalerProStatHistory.SecondPlay, GoalerProStatHistory.W, GoalerProStatHistory.L, GoalerProStatHistory.OTL, GoalerProStatHistory.Shootout, GoalerProStatHistory.GA, GoalerProStatHistory.SA, GoalerProStatHistory.SARebound, GoalerProStatHistory.Pim, GoalerProStatHistory.A, GoalerProStatHistory.PenalityShotsShots, GoalerProStatHistory.PenalityShotsGoals, GoalerProStatHistory.StartGoaler, GoalerProStatHistory.BackupGoaler, GoalerProStatHistory.EmptyNetGoal, GoalerProStatHistory.Star1, GoalerProStatHistory.Star2, GoalerProStatHistory.Star3, ROUND((CAST(GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerProStatHistory.SA - GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerProStatHistory.PenalityShotsShots - GoalerProStatHistory.PenalityShotsGoals AS REAL) / (GoalerProStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerProStatHistory ON GoalerInfoHistory.Number = GoalerProStatHistory.Number AND GoalerInfoHistory.Year = GoalerProStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerProStatHistory.Playoff WHERE GoalerProStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT GoalerProStatHistory.Year, GoalerInfoHistory.ProTeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerProStatHistory.Number, GoalerProStatHistory.UniqueID, GoalerProStatHistory.Name, GoalerProStatHistory.GP, GoalerProStatHistory.SecondPlay, GoalerProStatHistory.W, GoalerProStatHistory.L, GoalerProStatHistory.OTL, GoalerProStatHistory.Shootout, GoalerProStatHistory.GA, GoalerProStatHistory.SA, GoalerProStatHistory.SARebound, GoalerProStatHistory.Pim, GoalerProStatHistory.A, GoalerProStatHistory.PenalityShotsShots, GoalerProStatHistory.PenalityShotsGoals, GoalerProStatHistory.StartGoaler, GoalerProStatHistory.BackupGoaler, GoalerProStatHistory.EmptyNetGoal, GoalerProStatHistory.Star1, GoalerProStatHistory.Star2, GoalerProStatHistory.Star3, ROUND((CAST(GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerProStatHistory.SA - GoalerProStatHistory.GA AS REAL) / (GoalerProStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerProStatHistory.PenalityShotsShots - GoalerProStatHistory.PenalityShotsGoals AS REAL) / (GoalerProStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerProStatHistory ON GoalerInfoHistory.Number = GoalerProStatHistory.Number AND GoalerInfoHistory.Year = GoalerProStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerProStatHistory.Playoff WHERE GoalerProStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " ORDER BY MainTable.Year ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif(isset($_GET['GoalerStatFarmHistoryAllSeasonPerYear']) OR isset($_POST['GoalerStatFarmHistoryAllSeasonPerYear'])){
/* GoalerStatFarmHistoryAllSeasonPerYear */
$dbTemp = new SQLite3($DatabaseFile);
$QueryTemp = "Select LeagueYearOutput, PlayOffStarted, PreSeasonSchedule from LeagueGeneral";
$LeagueGeneralAllSeasonPerYear = $dbTemp->querySingle($QueryTemp,true);
$Query = "Select MainTable.*";
if($LeagueGeneralAllSeasonPerYear['PlayOffStarted'] == $PlayoffString AND $LeagueGeneralAllSeasonPerYear['PreSeasonSchedule'] == "False"){
/* Regular Query */
$Query = $Query . " FROM ( Select MainLive.* FROM (SELECT '". $LeagueGeneralAllSeasonPerYear ['LeagueYearOutput'] . "' as Year, GoalerInfo.TeamName, GoalerInfo.Team, GoalerInfo.Rookie, '0' As TeamThemeID, GoalerFarmStat.Number, GoalerFarmStat.UniqueID, GoalerFarmStat.Name, GoalerFarmStat.GP, GoalerFarmStat.SecondPlay, GoalerFarmStat.W, GoalerFarmStat.L, GoalerFarmStat.OTL, GoalerFarmStat.Shootout, GoalerFarmStat.GA, GoalerFarmStat.SA, GoalerFarmStat.SARebound, GoalerFarmStat.Pim, GoalerFarmStat.A, GoalerFarmStat.PenalityShotsShots, GoalerFarmStat.PenalityShotsGoals, GoalerFarmStat.StartGoaler, GoalerFarmStat.BackupGoaler, GoalerFarmStat.EmptyNetGoal, GoalerFarmStat.Star1, GoalerFarmStat.Star2, GoalerFarmStat.Star3, ROUND((CAST(GoalerFarmStat.GA AS REAL) / (GoalerFarmStat.SecondPlay / 60))*60, 3) AS GAA, ROUND((CAST(GoalerFarmStat.SA - GoalerFarmStat.GA AS REAL) / (GoalerFarmStat.SA)), 3) AS PCT, ROUND((CAST(GoalerFarmStat.PenalityShotsShots - GoalerFarmStat.PenalityShotsGoals AS REAL) / (GoalerFarmStat.PenalityShotsShots)), 3) AS PenalityShotsPCT FROM GoalerInfo INNER JOIN GoalerFarmStat ON GoalerInfo.Number = GoalerFarmStat.Number WHERE GoalerFarmStat.GP > 0 ) AS MainLive UNION ALL Select MainHistory.* FROM (SELECT GoalerFarmStatHistory.Year, GoalerInfoHistory.TeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerFarmStatHistory.Number, GoalerFarmStatHistory.UniqueID, GoalerFarmStatHistory.Name, GoalerFarmStatHistory.GP, GoalerFarmStatHistory.SecondPlay, GoalerFarmStatHistory.W, GoalerFarmStatHistory.L, GoalerFarmStatHistory.OTL, GoalerFarmStatHistory.Shootout, GoalerFarmStatHistory.GA, GoalerFarmStatHistory.SA, GoalerFarmStatHistory.SARebound, GoalerFarmStatHistory.Pim, GoalerFarmStatHistory.A, GoalerFarmStatHistory.PenalityShotsShots, GoalerFarmStatHistory.PenalityShotsGoals, GoalerFarmStatHistory.StartGoaler, GoalerFarmStatHistory.BackupGoaler, GoalerFarmStatHistory.EmptyNetGoal, GoalerFarmStatHistory.Star1, GoalerFarmStatHistory.Star2, GoalerFarmStatHistory.Star3, ROUND((CAST(GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerFarmStatHistory.SA - GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerFarmStatHistory.PenalityShotsShots - GoalerFarmStatHistory.PenalityShotsGoals AS REAL) / (GoalerFarmStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerFarmStatHistory ON GoalerInfoHistory.Number = GoalerFarmStatHistory.Number AND GoalerInfoHistory.Year = GoalerFarmStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerFarmStatHistory.Playoff WHERE GoalerFarmStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainHistory) AS MainTable";
}else{
/* Requesting Playoff While in Season or Requesting Season while in Playoff or In Pre-Season Mode - Do not fetch data from live database */
$Query = $Query . " FROM (SELECT GoalerFarmStatHistory.Year, GoalerInfoHistory.TeamName AS TeamName, GoalerInfoHistory.Team, GoalerInfoHistory.Rookie, '0' As TeamThemeID, GoalerFarmStatHistory.Number, GoalerFarmStatHistory.UniqueID, GoalerFarmStatHistory.Name, GoalerFarmStatHistory.GP, GoalerFarmStatHistory.SecondPlay, GoalerFarmStatHistory.W, GoalerFarmStatHistory.L, GoalerFarmStatHistory.OTL, GoalerFarmStatHistory.Shootout, GoalerFarmStatHistory.GA, GoalerFarmStatHistory.SA, GoalerFarmStatHistory.SARebound, GoalerFarmStatHistory.Pim, GoalerFarmStatHistory.A, GoalerFarmStatHistory.PenalityShotsShots, GoalerFarmStatHistory.PenalityShotsGoals, GoalerFarmStatHistory.StartGoaler, GoalerFarmStatHistory.BackupGoaler, GoalerFarmStatHistory.EmptyNetGoal, GoalerFarmStatHistory.Star1, GoalerFarmStatHistory.Star2, GoalerFarmStatHistory.Star3, ROUND((CAST(GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SecondPlay / 60))*60,3) AS GAA, ROUND((CAST(GoalerFarmStatHistory.SA - GoalerFarmStatHistory.GA AS REAL) / (GoalerFarmStatHistory.SA)),3) AS PCT, ROUND((CAST(GoalerFarmStatHistory.PenalityShotsShots - GoalerFarmStatHistory.PenalityShotsGoals AS REAL) / (GoalerFarmStatHistory.PenalityShotsShots)),3) AS PenalityShotsPCT FROM GoalerInfoHistory INNER JOIN GoalerFarmStatHistory ON GoalerInfoHistory.Number = GoalerFarmStatHistory.Number AND GoalerInfoHistory.Year = GoalerFarmStatHistory.Year AND GoalerInfoHistory.Playoff = GoalerFarmStatHistory.Playoff WHERE GoalerFarmStatHistory.GP > 0 AND GoalerInfoHistory.Playoff = '" . $PlayoffString. "') AS MainTable";
}
if ($PlayerUniqueID > -1){$Query = $Query . " WHERE MainTable.UniqueID = " . $PlayerUniqueID;}
elseif($Team > 0){$Query = $Query . " WHERE MainTable.Team = " . $Team;}
$Query = $Query . " ORDER BY MainTable.Year ASC";
If ($MaximumResult > 0){$Query = $Query . " LIMIT " . $MaximumResult;}
$CareerStatQuery = True;
$CareerStatQueryWithLiveDB = True;
}elseif((isset($_GET['CoachesHistory']) OR isset($_POST['CoachesHistory'])) AND $Year != 0){
/* CoachesHistory */
$Query = "SELECT CoachInfo.*, TeamProInfoHistory.Name as TeamProName, TeamFarmInfoHistory.Name As TeamFarmName, TeamProInfoHistory.CoachID as ProCoachTeamID, TeamFarmInfoHistory.CoachID as FarmCoachTeamID, 0 AS TeamThemeID FROM (CoachInfo LEFT JOIN TeamFarmInfoHistory ON CoachInfo.Team = TeamFarmInfoHistory.Number) LEFT JOIN TeamProInfoHistory ON CoachInfo.Team = TeamProInfoHistory.Number WHERE TEAM <> 0 AND CoachInfo.Year = " . $Year . " AND CoachInfo.Playoff = '" . $PlayoffString. "' AND TeamProInfoHistory.Year = " . $Year . " AND TeamProInfoHistory.Playoff = '" . $PlayoffString. "' AND TeamFarmInfoHistory.Year = " . $Year . " AND TeamFarmInfoHistory.Playoff = '" . $PlayoffString. "' ORDER BY CoachInfo.Name";
$CareerStatQuery = True;
}elseif(isset($_GET['CupWinner']) OR isset($_POST['CupWinner'])){
/* CupWinner */
$Query = "Select MainTable.*, TeamProInfoHistory.Name as ProTeam , TeamFarmInfoHistory.Name as FarmTeam FROM (SELECT Year,Playoff, PlayOffWinnerPro, PlayOffWinnerFarm From LeagueGeneral Where Playoff = 'True' ORDER BY Year DESC) as MainTable LEFT JOIN TeamFarmInfoHistory ON (MainTable.PlayOffWinnerFarm = TeamFarmInfoHistory.Number) AND (MainTable.Year = TeamFarmInfoHistory.Year) AND (MainTable.Playoff = TeamFarmInfoHistory.Playoff) LEFT JOIN TeamProInfoHistory ON (MainTable.PlayOffWinnerPro = TeamProInfoHistory.Number) AND (MainTable.Year = TeamProInfoHistory.Year) AND (MainTable.Playoff = TeamProInfoHistory.Playoff)";
$CareerStatQuery = True;
}
/* Actual Query Run */
if($QueryBoxscore != ""){
// Do Nothing. Result already send by Boxscore section
}elseif ($Query != ""){
If ($CareerStatQuery == False){
$db = new SQLite3($DatabaseFile);
$DBReturn = $db->query($Query);
/* Special Edit When Free Agent Year is request */
If ($FreeAgentYear >= 0){
$Query = "Select FreeAgentUseDateInsteadofDay, FreeAgentRealDate from LeagueOutputOption";
$LeagueOutputOption = $db->querySingle($Query,true);
$Query = "Select RFAAge, UFAAge from LeagueGeneral";
$LeagueGeneral = $db->querySingle($Query,true);
}
}else{
$db = new SQLite3($CareerStatDatabaseFile);
//Confirm Valid Data Found
$CareerDBFormatV2CheckCheck = $db->querySingle("SELECT Count(name) AS CountName FROM sqlite_master WHERE type='table' AND name='LeagueGeneral'",true);
If ($CareerDBFormatV2CheckCheck['CountName'] == 1){
If ($CareerStatQueryWithLiveDB == True){$db->query("ATTACH DATABASE '".realpath($DatabaseFile)."' AS CurrentDB");}
$DBReturn = $db->query($Query);
}else{
Goto ReturnEmpty;
}
}
$Result = array();
if (empty($DBReturn) == false){while ($Row = $DBReturn ->fetchArray(SQLITE3_ASSOC)) {
/* Special Edit When Free Agent Year is request */
If ($FreeAgentYear >= 0){
If ($FreeAgentYear == 1 and $Row['NextYearFreeAgentPlayerType'] != Null){
if ($Row['PosG']== "True"){
if ($Row['NextYearFreeAgentPlayerType']=="False"){$Row['NextYearFreeAgentPlayerType'] = "AlreadyResign";}else{$Row['NextYearFreeAgentPlayerType'] = "";}
}else{
if ($Row['NextYearFreeAgentPlayerType']=="True"){$Row['NextYearFreeAgentPlayerType'] = "AlreadyResign";}else{$Row['NextYearFreeAgentPlayerType'] = "";}
}
}elseif ($LeagueOutputOption['FreeAgentUseDateInsteadofDay'] == "True" AND $FreeAgentYear == 1){
$age = date_diff(date_create($Row['AgeDate']), date_create($LeagueOutputOption['FreeAgentRealDate']))->y;
if ($age >= $LeagueGeneral['UFAAge']){$Row['NextYearFreeAgentPlayerType'] = "UFA";}elseif($age >= $LeagueGeneral['RFAAge']){$Row['NextYearFreeAgentPlayerType'] = "RFA";}else{$Row['NextYearFreeAgentPlayerType'] = "ELC";}
}else{
if ($Row['Age'] >= $LeagueGeneral['UFAAge']){$Row['NextYearFreeAgentPlayerType'] = "UFA";}elseif($Row['Age'] >= $LeagueGeneral['RFAAge']){$Row['NextYearFreeAgentPlayerType'] = "RFA";}else{$Row['NextYearFreeAgentPlayerType'] = "ELC";}
}
}
$Result[] = $Row;
}}
header('Content-type: application/json');
echo json_encode($Result);
}else{
ReturnEmpty:
echo $EmptyReturn;
}
}
?>