to-ladder /functions/confirmwin.php

Language PHP Lines 859
MD5 Hash a29d92607e15cdae420d3f9ade9f0698 Estimated Cost $18,940 (why?)
Repository https://bitbucket.org/verax/to-ladder.git View Raw File View Project SPDX
  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
<?
function confirm_win(){
    global $dir, $file, $url, $out, $plyr;
    $tablehead=table_head("show","100%","","center");
    $tablefoot=table_foot("show");
    $bannerhead=table_head("show","488","80","center");
    $bannerfoot=table_foot("show");
    $out[body]=$out[body]."
    <center>
    $bannerhead
    $out[banner]
    $bannerfoot
    </center>
    <br>
    $tablehead
    <center>
    <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
    <tr class='altcolor'>
    <td width='100%' valign='top' align='center' colspan='6'>
    <strong>Unconfirmed Wins on your teams - Unconfirmed matches expire in 24 hours</strong><br>
    </td>
    </tr>
    <tr>
    <td width='15%' valign='center' align='center'>Confirm</td>
    <td width='15%' valign='center' align='center'>Losing Team</td>
    <td width='15%' valign='center' align='center'>Winning Team</td>
    <td width='15%' valign='center' align='center'>Ladder</td>
    <td width='15%' valign='center' align='center'>Reported By</td>
    <td width='25%' valign='center' align='center'>Reported Time</td>
    </tr>";
    $teamson=mysql_query("SELECT teamid,status FROM teammembers WHERE playerid='$plyr[id]'");
    while(list($teamid,$status)=mysql_fetch_row($teamson)){
        $unconfirmedwins=mysql_query("SELECT matchid,ladderid,loserid,loseralias,reportedby,reportedip,DATE_FORMAT(reporteddate, '%M %d, %l:%i %p') FROM matchdbval WHERE winnerid='$teamid' ORDER by reporteddate");
        while(list($matchid,$ladderid,$loserid,$loseralias,$reportedby,$reportedip,$reporteddate)=mysql_fetch_row($unconfirmedwins)){
            if($ladderid!="$lastladderid"){
                $ladinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$ladderid'");
                $linfo=mysql_fetch_array($ladinfo);
                $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
                $tinfo=mysql_fetch_array($teaminfo);
                $out[body]=$out[body]."
                <tr class='altcolor'>
                </tr>";
            }

            if($reportedby=="0"){
                $reporter[alias]="Unknown";
            }else{

                $reported=mysql_query("SELECT alias FROM users WHERE id='$reportedby'");
                $reporter=mysql_fetch_array($reported);
            }

            $out[body]=$out[body]."
            <tr>
            <td width='15%' valign='center' align='center' class='catfont'>[<a href='?action=confirmwin&matchid=$matchid'><b>Confirm</b></a>]</td>
            <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[teams]?teamid=$loserid'>$loseralias</a></b></td>
            <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[teams]?teamid=$teamid'>$tinfo[teamname]</a></b></td>
            <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[ladder]?ladderid=$ladderid'>$linfo[laddername]</a></b></td>
            <td width='15%' valign='center' align='center'><b><a href='$url[base]/$file[players]?playerid=$reportedby'>$reporter[alias]</a></b></td>
            <td width='25%' valign='center' align='center'><b>$reporteddate</b></td>
            </tr>";
            $foundwins=1;
        }

        $lastladderid="$ladderid";
    }

    if(!$foundwins){
        $out[body]=$out[body]."
        <tr>
        <td width='100%' valign='center' align='center' colspan='6'><b>There are no unconfirmed wins</b></td>
        </tr>";
    }

    $out[body]=$out[body]."</table>
    $tablefoot
    <br>";
    // UNCONFIRMED LOSSES
    $out[body]=$out[body]."
    $tablehead
    <center>
    <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
    <tr class='altcolor'>
    <td width='100%' valign='top' align='center' colspan='5'>
    <strong>Unconfirmed Losses on your teams - Unconfirmed matches expire in 24 hours</strong><br>
    </td>
    </tr>
    <tr>
    <td width='20%' valign='center' align='center'>Winning Team</td>
    <td width='20%' valign='center' align='center'>Losing Team</td>
    <td width='20%' valign='center' align='center'>Ladder</td>
    <td width='20%' valign='center' align='center'>Reported By</td>
    <td width='20%' valign='center' align='center'>Reported Time</td>
    </tr>";
    $lastladderid="";
    $teamsonb=mysql_query("SELECT teamid,status FROM teammembers WHERE playerid='$plyr[id]'");
    while(list($teamid,$status)=mysql_fetch_row($teamsonb)){
        $unconfirmedlosses=mysql_query("SELECT matchid,ladderid,winnerid,reportedby,reportedip,DATE_FORMAT(reporteddate, '%M %d, %l:%i %p') FROM matchdbval WHERE loserid='$teamid' ORDER by reporteddate");
        while(list($matchid,$ladderid,$winnerid,$reportedby,$reportedip,$reporteddate)=mysql_fetch_row($unconfirmedlosses)){
            if($ladderid!="$lastladderid"){
                $ladinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$ladderid'");
                $linfo=mysql_fetch_array($ladinfo);
                $teaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$teamid'");
                $tinfo=mysql_fetch_array($teaminfo);
                $out[body]=$out[body]."
                <tr class='altcolor'>
                </tr>";
            }

            $loserteaminfo=mysql_query("SELECT teamname FROM teams WHERE id='$winnerid'");
            $ltinfo=mysql_fetch_array($loserteaminfo);
            if($reportedby=="0"){
                $reporter[alias]="Unknown";
            }else{

                $reported=mysql_query("SELECT alias FROM users WHERE id='$reportedby'");
                $reporter=mysql_fetch_array($reported);
            }

            $out[body]=$out[body]."
            <tr>
            <td width='20%' valign='center' align='center'><a href='$url[base]/$file[teams]?teamid=$winnerid'><b>$ltinfo[teamname]</a></b></td>
            <td width='20%' valign='center' align='center'><a href='$url[base]/$file[teams]?teamid=$teamid'><b>$tinfo[teamname]</a></b></td>
            <td width='20%' valign='center' align='center'><a href='$url[base]/$file[ladder]?ladderid=$ladderid'><b>$linfo[laddername]</a></b></td>
            <td width='20%' valign='center' align='center'><a href='$url[base]/$file[players]?playerid=$reportedby'><b>$reporter[alias]</a></b></td>
            <td width='20%' valign='center' align='center'><b>$reporteddate</b></td>
            </tr>";
            $foundlosses=1;
        }

        $lastladderid="$ladderid";
    }

    if(!$foundlosses){
        $out[body]=$out[body]."
        <tr>
        <td width='100%' valign='center' align='center' colspan='5'><b>There are no unconfirmed losse</b>s</td>
        </tr>";
    }

    $out[body]=$out[body]."</table>
    $tablefoot";
    include("$dir[curtheme]");
}

function confirm_winb($matchid){
    global $dir, $file, $url, $out, $plyr;
    $matchinfo=mysql_query("SELECT *,DATE_FORMAT(reporteddate, '%M %d, %l:%i %p') FROM matchdbval WHERE matchid='$matchid'");
    $match=mysql_fetch_array($matchinfo);
    if(!$match[matchid]){
        include("$dir[func]/error.php");
        display_error("Unknown Match ID.<br>");
    }

    //CHECK IF CAN CONFIRM/REPORT
    if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$match[winnerid]' AND playerid='$plyr[id]' AND status <='4'")) < 1){
        include("$dir[func]/error.php");
        display_error("You are not allowed to report losses for this team.<br>");
    }

    $ladderinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$match[ladderid]'");
    $linfo=mysql_fetch_array($ladderinfo);
    if(!$linfo[laddername]){
        include("$dir[func]/error.php");
        display_error("Unknown ladder.<br>");
    }

    $winnerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$match[winnerid]'");
    $wtinfo=mysql_fetch_array($winnerinfo);
    if(!$wtinfo[teamname]){
        include("$dir[func]/error.php");
        display_error("Unable to find your team.<br>");
    }

    $tablehead=table_head("show","100%","","center");
    $tablefoot=table_foot("show");
    $bannerhead=table_head("show","488","80","center");
    $bannerfoot=table_foot("show");
    $out[body]=$out[body]."
    <center>
    $bannerhead
    $out[banner]
    $bannerfoot
    </center>
    <br>
    $tablehead
    <center>
    <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
    <tr class='altcolor'>
    <td width='100%' valign='top' align='center'>
    <strong>Confirm this win - $linfo[laddername]</strong><br>
    </td>
    </tr>
    <tr>
    <td width='100%' valign='center' align='center'>
    Winner: <a href='$url[base]/$file[teams]?teamid=$match[winnerid]'>$wtinfo[teamname]</a><br>
    Loser: <a href='$url[base]/$file[teams]?teamid=$match[loserid]'>$match[loseralias]</a><br>
    Winners Rank: $match[wrank]<br>
    Losers Rank: $match[lrank]<br>
    <br>
    Losers Comments:<br>$match[lcomment]<br>
    <br>
    Match was reported $match[15]</td>
    </tr>
    <form method='post'>
    <tr class='altcolor'>
    <td width='100%' valign='top' align='center'>
    <input type='hidden' name='matchid' value='$match[matchid]'>
    <input type='hidden' name='action' value='confirmwinc'>
    <input type='submit' name='' value='Confirm Win'>
    </td></form>
    </tr>
    </table>
    $tablefoot";
    include("$dir[curtheme]");
}

function confirm_winc($matchid){
    global $dir, $file, $url, $out, $plyr, $misc;
    $matchinfo=mysql_query("SELECT * FROM matchdbval WHERE matchid='$matchid'");
    $match=mysql_fetch_array($matchinfo);
    if(!$match[matchid]){
        include("$dir[func]/error.php");
        display_error("Unknown Match ID.<br>");
    }

    //CHECK IF CAN CONFIRM/REPORT
    if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$match[winnerid]' AND playerid='$plyr[id]' AND status <='4'")) < 1){
        include("$dir[func]/error.php");
        display_error("You are not allowed to report losses for this team.<br>");
    }

    $ladderinfo=mysql_query("SELECT laddername FROM ladders WHERE id='$match[ladderid]'");
    $linfo=mysql_fetch_array($ladderinfo);
    if(!$linfo[laddername]){
        include("$dir[func]/error.php");
        display_error("Unknown ladder.<br>");
    }

    $winnerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$match[winnerid]'");
    $wtinfo=mysql_fetch_array($winnerinfo);
    if(!$wtinfo[teamname]){
        include("$dir[func]/error.php");
        display_error("Unable to find your team.<br>");
    }

    $tablehead=table_head("show","100%","","center");
    $tablefoot=table_foot("show");
    $bannerhead=table_head("show","488","80","center");
    $bannerfoot=table_foot("show");
    $out[body]=$out[body]."
    <center>
    $bannerhead
    $out[banner]
    $bannerfoot
    </center>
    <br>
    $tablehead
    <center>
    <table width='100%' border='0' bordercolor='#ffffff' cellspacing='0' cellpadding='2'>
    <form method='post'>
    <tr class='altcolorc'>
    <td width='100%' align='center' border='0' bordercolor='#ffffff'>
    <strong>Confirm this win</strong><br>
    </td>
    </tr>
    <tr><td>
    <table width=80% align='center' class='altcolorc'>
    ";
    $altcolora="#000033";
    $altcolorb="#000020";
    $winnersmembers=mysql_query("SELECT playerid,status FROM teammembers WHERE teamid='$match[winnerid]' ORDER by status");
    while(list($playerid,$status)=mysql_fetch_row($winnersmembers)){
        $memberinfo=mysql_query("SELECT alias FROM users WHERE id='$playerid'");
        $minfo=mysql_fetch_array($memberinfo);
        if($altladrow=="$altcolora"){
            $altladrow="$altcolorb";
        }else{

            $altladrow="$altcolora";
        }

        $out[body]=$out[body]."
        <tr bgcolor='$altladrow'>
        <td width='50%' align='left'>
        <a href='$url[base]/$file[players]?playerid=$playerid' target='new'>
        $minfo[alias]</a></td>
        <td width='50%' valign='center' align='right'>";
        if($status < 6){
            $out[body]=$out[body]."Played in Match:
            <input type='checkbox' name='member[$playerid]' value='1'>
            <input type='hidden' name='kills[$playerid]' value='0' maxlength='2' size='5'>";
        }else{

            $status=member_status($status);
            $out[body]=$out[body]."$status";
        }

        $out[body]=$out[body]."
        </td>
        </tr>";
    }

    $out[body]=$out[body]."
    </table>";
    if($match[maps]){
        $out[body]=$out[body]."
        <tr><td>
        <table  width=80% align='center' class='altcolorc'>
        <tr class='altcolorc'>
        <td width='100%' valign='top' align='center' colspan='3'>
        <strong>Map Results</strong><br>
        </td>
        </tr>
        ";
        $mapsplayed=split(",",$match[maps]);
        while(list($mapnum,$mapid)=each($mapsplayed)){
            $mapnum=($mapnum+1);
            if($mapid){
                $mapplayedinfo=mysql_query("SELECT mapname FROM maps WHERE id='$mapid'");
                $mapinfo=mysql_fetch_array($mapplayedinfo);
                if($altladrow=="$altcolora"){
                    $altladrow="$altcolorb";
                }else{

                    $altladrow="$altcolora";
                }

                if(!$mapinfo[mapname]){
                    $mapinfo[mapname]="Unknown";
                }

                $out[body]=$out[body]."
                <tr bgcolor=$altladrow>
                <td width='33%' valign='center' align='left'>
                #$mapnum Map Played</td>
                <td width='33%' valign='center' align='center'>$mapinfo[mapname]</td>
                <td width='33%' valign='center' align='right'>Won: <input type='checkbox' name='map[$mapnum]' value='1'></td>
                </tr>
                ";
            }

        }

        $out[body]=$out[body]."
        </table></td></tr>
        ";
    }

    $out[body]=$out[body]."
    <tr class='altcolorc'>
    <td width='100%' valign='top' align='center'>
    <strong>Final Score</strong><br>
    </td>
    </tr>
    <tr>
    <td width='100%' valign='center' align='center'>
    <table width='100%' border='0'  cellspacing='0' cellpadding='0'>
    <tr>
    <td width='50%' valign='center' align='center'>$wtinfo[teamname] <input type='text' name='wfscore' value='' size='3' maxlength='3'>&nbsp;</td>
    <td width='50%' valign='center' align='center'>$match[loseralias] <input type='text' name='lfscore' value='' size='3' maxlength='3'> $ltinfo[teamname]</td>
    </tr>
    </table>";
    if($misc[winnercomment]=="yes"){
        $out[body]=$out[body]."</td>
        </tr>
        <tr class='altcolorc'>
        <td width='100%' valign='top' align='center'>
        <strong>Comment on this match</strong><br>
        </td>
        </tr>
        <tr>
        <td width='100%' valign='center' align='center'>
        <tr>
        <td width='100%' valign='center' align='center'>
        <input type='text' name='wcomment' maxlength='50' size='50'><br>
        <small>50 Characters Max</small>
        </td>
        </tr>";
    }

    $out[body]=$out[body]."
    <tr>
    <td width='100%' valign='top' align='center'>
    <BR>
    <input type='hidden' name='matchid' value='$match[matchid]'>
    <input type='hidden' name='action' value='confirmwind'>
    <input type='submit' name='' value='Confirm Win'>
    </td></form>
    </tr>
    </table>
    $tablefoot";
    include("$dir[curtheme]");
}

function confirm_wind($matchid,$member,$map,$wfscore,$lfscore,$wcomment,$kills){
    global $dir, $file, $url, $out, $plyr, $misc;
    if(!$matchid){
        include("$dir[func]/error.php");
        display_error("Invalid Match ID.<br>");
    }

    if((!$wfscore) || ($wfscore <= $lfscore)){
        include("$dir[func]/error.php");
        display_error("Invalid Final Score.<br>");
    }

    $matchinfo=mysql_query("SELECT * FROM matchdbval WHERE matchid='$matchid'");
    $match=mysql_fetch_array($matchinfo);
    if(!$match[matchid]){
        include("$dir[func]/error.php");
        display_error("Unknown Match ID.<br>");
    }

    //CHECK IF CAN CONFIRM/REPORT
    if (mysql_num_rows(mysql_query("SELECT status FROM teammembers WHERE teamid='$match[winnerid]' AND playerid='$plyr[id]' AND status <='4'")) < 1){
        include("$dir[func]/error.php");
        display_error("You are not allowed to report losses for this team.<br>");
    }

    $ladderinfo=mysql_query("SELECT * FROM ladders WHERE id='$match[ladderid]'");
    $linfo=mysql_fetch_array($ladderinfo);
    if(!$linfo[laddername]){
        include("$dir[func]/error.php");
        display_error("Unknown ladder.<br>");
    }

    $winnerinfo=mysql_query("SELECT teamname FROM teams WHERE id='$match[winnerid]'");
    $wtinfo=mysql_fetch_array($winnerinfo);
    if(!$wtinfo[teamname]){
        include("$dir[func]/error.php");
        display_error("Unable to find your team.<br>");
    }

    if(!$member){
        include("$dir[func]/error.php");
        display_error("You must select the members that played.<br>");
    }

    include("$dir[func]/checkdata.php");
    $wfscore=change_numbersonly($wfscore);
    if($lfscore==""){
        $lfscore=0;
    }else{

        $lfscore=change_numbersonly($lfscore);
    }

    if((!$wfscore) || (!$lfscore) && ($lfscore!="0")){
        include("$dir[func]/error.php");
        display_error("Invalid Final Score.<br>");
    }

    if($wcomment){
        $wcomment=wordwrap($wcomment,20," ",1);
        $wcomment=change_censor($wcomment);
        $wcomment=change_charecters($wcomment);
    }

    while(list($memberid,$played)=each($member)){
        if($played){
            $memberid=change_numbersonly($memberid);
            $kills[$memberid]=change_numbersonly($kills[$memberid]);
            $membersplayed=$membersplayed."$memberid|$kills[$memberid],";
            $totalkills=($totalkills + $kills[$memberid]);
        }

    }

    if($map){
        while(list($maporder,$wonmap)=each($map)){
            if($wonmap){
                $mapsplayed=$mapsplayed."$maporder,";
            }

        }

    }

    if(!$membersplayed){
        include("$dir[func]/error.php");
        display_error("You must select the members that played.<br>");
    }

    //CHECK FOR CHALLENGE OR IF OPEN PLAY IS ALLOWED
    $thechallenge=mysql_query("SELECT * FROM challenges WHERE challenger='$match[winnerid]' AND challenged='$match[loserid]' AND finalizedby > '0' OR challenger='$match[loserid]' AND challenged='$match[winnerid]' AND finalizedby > '0'");
    $chall=mysql_fetch_array($thechallenge);
    if($chall[challid]){
        if($misc[challranking] < 2){

        	if($match[winnerid]=="$chall[challenger]"){
            		$wtempnewrank="$chall[challengedrank]";
        	}else{

            		$wtempnewrank=0;
        	}
	}
	else if($misc[challranking] > 1){

		if($match[winnerid]=="$chall[challenger]"){
            		$wtempnewrank=($chall[challengedrank] / 2 - 0.5);
        	}else{

            		$wtempnewrank=0;
        	}

	}

	else{
		$wtempnewrank=0;
	}

    }else{

        if($linfo[openplay] < 1){
            include("$dir[func]/error.php");
            display_error("Open play is not allowed on this ladder.<br>All matches must be scheduled challenges.<br>");
        }

    }

    //CLEAN MATCH DB
    clean_matchdb($matchid);
    $tday=date("Y-m-d H:i:s");
    $ip=getenv("REMOTE_ADDR");
    //REPORT MATCH TO MATCH DATABASE
    mysql_query("INSERT INTO matchdb VALUES (
    '$match[matchid]',
    '$match[winnerid]',
    '$match[loserid]',
    '$wtinfo[teamname]',
    '$match[loseralias]',
    '$match[ladderid]',
    '$linfo[laddername]',
    '$match[wrank]',
    '$match[lrank]',
    '$wfscore',
    '$lfscore',
    '$membersplayed',
    '$match[losersmembers]',
    '$match[maps]',
    '$mapsplayed',
    '$wcomment',
    '$match[lcomment]',
    '$match[points]',
    '$totalkills|$match[skill]',
    '$match[reportedby]',
    '$match[reporteddate]',
    '$match[reportedip]',
    '$plyr[id]',
    '$tday',
    '$ip');");
    //UPDATE WINNER TEAM PLAYER SCORES
    $membersplayed=split(",",$membersplayed);
    while(list($num,$playerid)=each($membersplayed)){
        $playerid=split("\|",$playerid);
        if($playerid[0]){
            mysql_query("UPDATE users SET
            matcheswon=matcheswon+1,
            points=points+$match[points],
            skill=skill+$playerid[1]
            WHERE id='$playerid[0]'");
        }

    }

    //UPDATE LOSER TEAM PLAYER SCORES
    $losersmembers=split(",",$match[losersmembers]);
    while(list($num,$losersid)=each($losersmembers)){
        $losersid=split("\|",$losersid);
        if($losersid[0]){
            mysql_query("UPDATE users SET
            matcheslost=matcheslost+1,
            skill=skill+$losersid[1]
            WHERE id='$losersid[0]'");
        }

    }

    //GET WINNERS LADDER STATS
    $winnerladder=mysql_query("SELECT * FROM ladder_$match[ladderid] WHERE id='$match[winnerid]'");
    $wlinfo=mysql_fetch_array($winnerladder);
    //GET LOSERS LADDER STATS
    $loserladder=mysql_query("SELECT * FROM ladder_$match[ladderid] WHERE id='$match[loserid]'");
    $llinfo=mysql_fetch_array($loserladder);
    //GET TOTAL RANKERS
    $totalranked=mysql_query("SELECT COUNT(*) FROM ladder_$match[ladderid] WHERE rank > '0'");
    $totalranks=mysql_fetch_array($totalranked);
    $totalranks="$totalranks[0]";
    if(!$chall[challid]){

        //Winner moves half way up to losers position
        if($misc[ranking] < 2){
        	//UPDATE LADDER RANKS
        	//IF BOTH TEAMS ARE ALREADY RANKED
        	if(($match[wrank] > 0) && ($match[lrank] > 0)){
            		$wtempnewrank=($match[wrank] + $match[lrank]);
            		$wtempnewrank=($wtempnewrank / 2 - 0.5);
            		if($wtempnewrank > $totalranks){
                		$wtempnewrank="$totalranks";
            		}

        	}

        	else if($match[wrank] < 1){
            		$wtempnewrank=($totalranks + 1);
        	}else{
            		$wtempnewrank="";
        	}

        //Winner takes losers position
        }else if($misc[ranking] > 1){

 		//UPDATE LADDER RANKS
        	//IF BOTH TEAMS ARE ALREADY RANKED
        	if(($match[wrank] > 0) && ($match[lrank] > 0)){
            		$wtempnewrank=$match[lrank];         
        	}

        	else if($match[wrank] < 1){
            		$wtempnewrank=($totalranks + 1);
        	}else{
            		$wtempnewrank="";
        	}

	}else{
		$wtempnewrank="";
	}

    }

    $wtempnewrank=round($wtempnewrank);
    //IF RANK IS BETTER THAN CURRENT RANK UPDATE LADDER
    include("$dir[func]/rankadjust.php");
    if(($wtempnewrank) && ($wtempnewrank > 0)){
        if(($wtempnewrank < $wlinfo[rank]) || ($wlinfo[rank] < 1)){
            update_teamranks($match[ladderid],$match[winnerid],$wtempnewrank);
            $updatedrank="$wtempnewrank";
        }

    }

    //UPDATE WINNERS LADDER STATS
    if($updatedrank){
        $newlastrank="$wlinfo[rank]";
        if(($updatedrank < $wlinfo[bestrank]) || ($wlinfo[bestrank] < 1)){
            $newbestrank="$updatedrank";
        }else{

            $newbestrank="$wlinfo[bestrank]";
        }

    }else{

        $newlastrank="$wlinfo[lastrank]";
        $newbestrank="$wlinfo[bestrank]";
    }

    $newwins=($wlinfo[wins] + 1);
    $newgames=($newwins + $wlinfo[losses]);
    $newpercent=round($newwins / $newgames * 100);
    $newstreak=($wlinfo[streak] + 1);
    if($newstreak < 1){
        $newstreak="1";
    }

    if($newstreak > $wlinfo[beststreak]){
        $newbeststreak="$newstreak";
    }else{

        $newbeststreak="$wlinfo[beststreak]";
    }

    if($llinfo[rank] > 0){
        $newpoints=($totalranks - $llinfo[rank]);
        $newpoints=round($newpoints / 10);
    }

    if($newpoints < 10){
        $newpoints="10";
    }

    //CHANGED SKILL TO KILLS
    //$newskill=($wlinfo[skill] + $match[skill]);
    $newskill=($wlinfo[skill] + $totalkills);
    $newpoints=($newpoints + $wlinfo[points]);
    mysql_query("UPDATE ladder_$match[ladderid] SET
    lastmatch='$tday',
    lastplayed='$match[loserid]',
    statusdisplay='',
    lastrank='$newlastrank',
    bestrank='$newbestrank',
    wins='$newwins',
    games='$newgames',
    percent='$newpercent',
    streak='$newstreak',
    beststreak='$newbeststreak',
    points='$newpoints',
    skill='$newskill'
    WHERE id='$match[winnerid]'");
    //UPDATE LOSERS LADDER STATS
    $newlastrank="$llinfo[rank]";
    if(($llinfo[rank] < $llinfo[bestrank]) || ($llinfo[bestrank]=="0")){
        $newbestrank="$llinfo[rank]";
    }else{

        $newbestrank="$llinfo[bestrank]";
    }

    if($llinfo[rank] > $llinfo[worstrank]){
        $newworstrank="$llinfo[rank]";
    }else{

        $newworstrank="$llinfo[worstrank]";
    }

    $newlosses=($llinfo[losses] + 1);
    $newgames=($newlosses + $llinfo[wins]);
    $newpercent=round($llinfo[wins] / $newgames * 100);
    $newstreak=($llinfo[streak] - 1);
    if($newstreak > 0){
        $newstreak="-1";
    }

    if($newstreak < $llinfo[worststreak]){
        $newworststreak="$newstreak";
    }else{

        $newworststreak="$llinfo[worststreak]";
    }

    $newskill=($llinfo[skill] + $match[skill]);
    mysql_query("UPDATE ladder_$match[ladderid] SET
    lastmatch='$tday',
    lastplayed='$match[winnerid]',
    statusdisplay='',
    lastrank='$newlastrank',
    bestrank='$newbestrank',
    worstrank='$newworstrank',
    losses='$newlosses',
    games='$newgames',
    percent='$newpercent',
    streak='$newstreak',
    worststreak='$newworststreak',
    skill='$newskill'
    WHERE id='$match[loserid]'");
    //DELETE UNVALIDATED MATCH
    mysql_query("DELETE FROM matchdbval WHERE matchid='$matchid'");
    if($chall[challid]){
        //DELETE CHALLENGE
        mysql_query("DELETE FROM challenges WHERE challid='$chall[challid]'");
    }

    //CLEAN LADDER - INACTIVITY
    if($linfo[inactivedrop] > 0){
        //SECOND WARNING - DELETE TEAMS
        if($linfo[inactivedaysb] > 0){
            $dropdateb=date("Y-m-d H:i:s",time()-60*60*24*$linfo[inactivedaysb]);
            $inactivedropb=mysql_query("SELECT id FROM ladder_$match[ladderid] WHERE joindate < '$dropdateb' AND lastmatch < '$dropdateb'");
            while(list($dropidb)=mysql_fetch_row($inactivedropb)){
                // REMOVE ALL RECORDS OF TEAM FROM LADDER SYSTEM
                mysql_query("DELETE FROM teammembers WHERE teamid='$dropidb'");
                mysql_query("DELETE FROM teams WHERE id='$dropidb'");
                mysql_query("DELETE FROM ladder_$match[ladderid] WHERE id='$dropidb'");
                mysql_query("DELETE FROM challenges WHERE challenger='$dropidb'");
                mysql_query("DELETE FROM challenges WHERE challenged='$dropidb'");
                mysql_query("DELETE FROM teammembersinv WHERE teamid='$dropidb'");
            }

        }

        //FIRST DROP TO (admin set amount) RANKS
        if($linfo[inactivedaysa] > 0){
            $dropdatea=date("Y-m-d H:i:s",time()-60*60*24*$linfo[inactivedaysa]);
            $inactivedropa=mysql_query("SELECT id,rank FROM ladder_$match[ladderid] WHERE joindate < '$dropdatea' AND statusdate < '$dropdatea' AND lastmatch < '$dropdatea' AND rank > '0' ORDER by rank");
            while(list($dropida,$dropranka)=mysql_fetch_row($inactivedropa)){
                $teamsdropped++;
                if($teamsdropped < 25){
                    $droptoa=($dropranka + $linfo[inactivedrop]);
                    if($droptoa > $totalranks){
                        $droptoa="$totalranks";
                    }

                    mysql_query("UPDATE ladder_$match[ladderid] SET rank='$droptoa' WHERE id='$dropida'");
                    mysql_query("UPDATE ladder_$match[ladderid] SET status='69', statusdisplay='Dropped for Inactivity', statusdate='$tday' WHERE id='$dropida'");
                }

            }

        }

    }

    //CHECK FOR DUPLICATE RANKS AND ADJUST RANKS
    //RETURN (1) IF ADJUSTED
    $ranksadjusted=rank_checkadjust($match[ladderid]);
    $tablehead=table_head("show","100%","","center");
    $tablefoot=table_foot("show");
    $bannerhead=table_head("show","488","80","center");
    $bannerfoot=table_foot("show");
    $out[body]=$out[body]."
    <center>
    $bannerhead
    $out[banner]
    $bannerfoot
    </center>
    <br>
    $tablehead
    <table width='100%' border='0' bordercolor='#000000' cellspacing='0' cellpadding='2'>
    <tr class='altcolor'>
    <td width='100%' valign='top' align='center'>
    <strong>Your win has been recorded</strong><br>
    </td>
    </tr>
    <tr>
    <td width='100%' valign='center' align='left'>
    <br><ul>
    Ladder: <a href='$url[base]/$file[ladder]?ladderid=$match[ladderid]'>$linfo[laddername]</a><br>
    Winner: <a href='$url[base]/$file[teams]?teamid=$match[winnerid]'>$wtinfo[teamname]</a><br>
    Loser: <a href='$url[base]/$file[teams]?teamid=$match[loserid]'>$match[loseralias]</a>
    </ul></td>
    </tr>
    <tr class='altcolor'>
    <td width='100%' valign='top' align='center'>
    <strong><a href='$url[base]/$file[match]?matchid=$match[matchid]'>View the Match</a></strong><br>
    </td>
    </tr>
    </table>
    $tablefoot";
    include("$dir[curtheme]");
}

function clean_matchdb($matchid){
    $deletedate=date("Y-m-d H:i:s",time()-60*60*24*30);
    mysql_query("DELETE FROM matchdb WHERE reportdate < '$deletedate' OR matchid='$matchid'");
}

function member_status($status){
    if($status=="1"){ $status="Leader"; }

    if($status=="2"){ $status="Co-Leader"; }

    if($status=="3"){ $status="Captain"; }

    if($status=="4"){ $status="Co-Captain"; }

    if($status=="5"){ $status="Member"; }

    if($status=="6"){ $status="Training"; }

    if($status=="7"){ $status="Inactive"; }

    if($status=="8"){ $status="Suspended"; }

    return($status);
}

?>
Back to Top