/var/www/hkosl.com/onegolf/webadmin/scores_modifyform.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
<?php
    
require_once('check_login.php');

    
$event_id = (int)$_GET["event_id"];

    
$event get_event($event_id);
    
$scores_info get_scores($event_id);

    
$sql99        "SELECT * FROM sys_cms_login WHERE cmsloginid=?";
    
$parameters99 = array((int)$scores_info[0]{'lastupby'});
    
$row99        bind_pdo($sql99$parameters99"selectone");
?>
<!DOCTYPE html>
<html>
<head>
    <?php require_once('html_head.php'); ?>

    <script type="text/javascript">
        function isInt(value) {
            return !isNaN(value) &&
                    parseInt(Number(value)) == value &&
                    !isNaN(parseInt(value, 10));
        }

        function ajax_update_scores(scores_id, scores, hole) {

            if(!isInt(scores_id)){
                alert("Scores id should be a positive number.");
                return;
            }

            if(scores!=""){
                if(!isInt(scores)){
                    alert("Scores should be a positive number.");
                    return;
                }
            }else{
                return;
            }

            if(!isInt(hole)){
                alert("Hole should be a positive number.");
                return;
            }

            var xmlhttp;

            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                    //console.log(xmlhttp.responseText);
                    var result = $.trim(xmlhttp.responseText);

                    if (result != "1") {
                        alert("Cannot update scores! Please refresh page and try again.");
                    }
                }
            }
            xmlhttp.open("POST", "ajax.php?for=update_scores", true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send("id=" + scores_id + "&scores=" + scores+ "&hole=" + hole);
        }

        function ajax_update_sort(event_id, player_id, sort) {

            if(!isInt(event_id)){
                alert("Event id should be a positive number.");
                return;
            }

            if(!isInt(player_id)){
                alert("Player id should be a positive number.");
                return;
            }

            if(sort!=""){
                if(!isInt(sort)){
                    alert("Sort should be a positive number.");
                    return;
                }
            }else{
                return;
            }

            var xmlhttp;

            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                    console.log(xmlhttp.responseText);
                    var result = $.trim(xmlhttp.responseText);

                    if (result != "1") {
                        alert("Cannot update sorting! Please refresh page and try again.");
                    }
                }
            }
            xmlhttp.open("POST", "ajax.php?for=update_sort", true);
            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send("event_id=" + event_id + "&player_id=" + player_id+ "&sort=" + sort);
        }

        $(function () {
            $("#date").datepicker({dateFormat: "yy-mm-dd"});

            $(".hole_score").on("keyup", function () {
                var scores = $(this).val();
                var max_par = $(this).attr("max");

                if(!isInt(scores) && scores != ""){
                    $(this).css("background-color", "red");
                    alert("Please enter a number for records");
                }else{
                    if(parseInt(scores) > parseInt(max_par)){
                        $(this).css("background-color", "red");
                    }else{
                        $(this).css("background-color", "#fff");

                        //update scores
                        var event_id = "<?=(int)$event_id?>";
                        var hole_string = $(this).parent().attr("id");
                        var hole = hole_string.replace(/hole_/, "");
                        var scores_id = this.id;

                        ajax_update_scores(scores_id, scores, hole);
                    }
                }
            });

            $(".sort").on("keyup", function () {
                var sort = $(this).val();
                var player_id = this.id;
                var event_id = <?=$event_id?>;

                ajax_update_sort(event_id, player_id, sort);
            });
        });
    </script>
</head>
<body>

<form action="scores_modify.php" method="post" name="modifyform" enctype="multipart/form-data">
    <input type="hidden" name="event_id" value="<?= $event_id?>">
    <table width="2100" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td height="70" align="right" valign="middle" class="icontxt">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="50" align="center" style="font-size: 12px;">
                            <input type="image" alt="submit" src="images/iconSave.png" width="32" height="32" border="0"><br>

                                &nbsp;Save&nbsp;&nbsp;</div></td>
                        <td width="50" align="center">
                            <a href="event_index.php"><img src="images/iconCancel.png" alt="Cancel" width="32" height="32" border="0"><br>
                                &nbsp;Cancel&nbsp;&nbsp;</a></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <span style="float:left;" class="pagetitletxt">
                    &nbsp;&nbsp;<b><img src="images/iconList.jpg" width="48" height="48" align="absmiddle"/>
                        Scores </b></span><span style="float:right;" class="msg">Last
                    Update: <?= $row99{'cmsusername'} . '&nbsp;&nbsp;&nbsp;' $scores_info[0]{'lastupdate'}; ?></span>
            </td>
        </tr>
        <tr>
            <td align="left" valign="middle"><!-- Content -->
                <table border="0" cellpadding="0" cellspacing="0" style="margin-left: 10px;">

                    <tr>
                        <td height="25" align="left" valign="middle" class="msg"><?php if (!empty($_GET["msg"])) echo $msg?></td>
                    </tr>

                    <tr>
                        <td width="120" align="right" valign="top" class='content'>Event Name</td>
                        <td class='content' valign="top">:&nbsp;</td>
                        <td class='content'>
                            <a href="event_modifyform.php?id=<?=$event_id?>" target="_blank" style="text-decoration: underline;">
                                <?= $event["name"?>
                            </a>
                            <br><br>
                        </td>
                    </tr>

                    <tr>
                        <td width="120" align="right" valign="top" class='content required'>Scores</td>
                        <td class='content' valign="top">:&nbsp;</td>
                        <td class='content'>
                            <table id="scores_table" style="border-collapse: collapse;">
                                <tr>
                                    <td>Hole</td>
                                    <?php
                                        
for ($i 1$i <= 18$i++) {
                                            if(
$i==10){
                                                echo 
"<td>Out Par</td>";
                                            }

                                            echo 
"<td>".$i."</td>";

                                            if(
$i==18){
                                                echo 
"<td>In Par</td>";
                                                echo 
"<td>Total Par(Gross)</td>";
                                                echo 
"<td>Total Par(Net)</td>";
                                                echo 
"<td>Net</td>";
                                            }
                                        }
                                    
?>
                                </tr>

                                <tr>
                                    <td>Par (Male)</td>
                                    <?php
                                        $out 
0;
                                        
$in 0;
                                        
$gross_total 0;
                                        
$net_total 0;

                                        for (
$i 1$i <= 18$i++) {

                                            if(
$i<=9){
                                                
$out+=$event["hole_".$i."_par_M"];
                                            }

                                            if(
$i>9){
                                                
$in+=$event["hole_".$i."_par_M"];
                                            }

                                            
$gross_total+=$event["hole_".$i."_par_M"];

                                            if(
$event["hole_".$i."_count"] == 1){
                                                
$net_total+=$event["hole_".$i."_par_M"];
                                            }

                                            if(
$i==10){
                                                echo 
"<td>".$out."</td>";
                                            }

                                            
$max_par get_max_par($event_id$event["hole_".$i."_par_M"]);
                                            echo 
"<td>".$event["hole_".$i."_par_M"]." (Max: ".$max_par.")</td>";

                                            if(
$i==18){
                                                echo 
"<td>".$in."</td>";
                                                echo 
"<td>".$gross_total."</td>";
                                                echo 
"<td>".$net_total."</td>";
                                                echo 
"<td></td>";
                                            }
                                        }

                                        
$male_total_par $gross_total;
                                    
?>
                                </tr>

                                <tr>
                                    <td>Par (Female)</td>
                                    <?php
                                        $out 
0;
                                        
$in 0;
                                        
$gross_total 0;
                                        
$net_total 0;

                                        for (
$i 1$i <= 18$i++) {

                                            if(
$i<=9){
                                                
$out+=$event["hole_".$i."_par_F"];
                                            }

                                            if(
$i>9){
                                                
$in+=$event["hole_".$i."_par_F"];
                                            }

                                            
$gross_total+=$event["hole_".$i."_par_F"];

                                            if(
$event["hole_".$i."_count"] == 1){
                                                
$net_total+=$event["hole_".$i."_par_F"];
                                            }

                                            if(
$i==10){
                                                echo 
"<td>".$out."</td>";
                                            }

                                            
$max_par get_max_par($event_id$event["hole_".$i."_par_F"]);
                                            echo 
"<td>".$event["hole_".$i."_par_F"]." (Max: ".$max_par.")</td>";

                                            if(
$i==18){
                                                echo 
"<td>".$in."</td>";
                                                echo 
"<td>".$gross_total."</td>";
                                                echo 
"<td>".$net_total."</td>";
                                                echo 
"<td></td>";
                                            }
                                        }

                                        
$female_total_par $gross_total;
                                    
?>
                                </tr>

                                <tr>
                                    <td>Count</td>
                                    <?php
                                        
for ($i 1$i <= 18$i++) {
                                            if(
$i==10){
                                                echo 
"<td></td>";
                                            }
                                            echo 
"<td>".($event["hole_".$i."_count"]==1?'Yes':'No')."</td>";

                                            if(
$i==18){
                                                echo 
"<td></td>";
                                                echo 
"<td></td>";
                                                echo 
"<td></td>";
                                                echo 
"<td></td>";
                                            }
                                        }
                                    
?>
                                </tr>

                                <tr>
                                    <td colspan="24">Players</td>
                                </tr>

                                <?php
                                    $sql 
"select * from event_player where event_id = ? order by sort ASC";
                                    
$parameters = array($event_id);
                                    
$players_id_array bind_pdo($sql$parameters"selectall");

                                    
/*$players_list = $event["players_id"];
                                    $players_id_array = explode(",", $players_list);*/

                                    
$gross_array = array();
                                    
$net_array = array();
                                    
$net_array = array();
                                    
$net_M_array = array();
                                    
$net_F_array = array();

                                    
//$num = 1;
                                    
foreach($players_id_array as $row){
                                        
$score get_scores($event_id$row["player_id"]);
                                        
$player get_player($row["player_id"]);
                                        if(
$player["deleted"] == 1)
                                            continue;

                                        echo 
"<tr><td><input type='text' name='sort' class='sort' id='".$row["player_id"]."' value='".$row["sort"]."' style='width:25px;'>&nbsp;&nbsp;<a href='player_modifyform.php?id=".$row["player_id"]."' target='_blank' style='text-decoration: underline;'>".$player["name"]." (".$player["gender"].")</a></td>";

                                        
$num++;

                                        
$out 0;
                                        
$in 0;
                                        
$gross_total 0;
                                        
$net_total 0;

                                        for (
$i 1$i <= 18$i++) {

                                            if(
$i<=9){
                                                
$out+=(int)$score["hole_".$i];
                                            }

                                            if(
$i>9){
                                                
$in+=(int)$score["hole_".$i];
                                            }

                                            
$gross_total+=(int)$score["hole_".$i];

                                            if(
$event["hole_".$i."_count"] == 1){
                                                
$net_total+=$score["hole_".$i];
                                            }

                                            if(
$i==10){
                                                echo 
"<td>".$out."</td>";
                                            }

                                            
$max_par get_max_par($event_id$event["hole_".$i."_par_".$player["gender"]]);
                                            
//echo "<td><input type='text' name='player_".$row["player_id"]."_hole_".$i."' value='".$score["hole_".$i]."' min='1' max='".$max_par."' id='".$score["id"]."' class='hole_score' style='width:60px;'></td>";
                                            
echo "<td id='hole_".$i."'><input type='text' name='scores[".$score["id"]."][".$i."]' value='".$score["hole_".$i]."' min='1' max='".$max_par."' id='".$score["id"]."' class='hole_score' style='width:60px;'></td>";

                                            if(
$i==18){
                                                echo 
"<td>".$in."</td>";
                                                echo 
"<td>".$gross_total."</td>";
                                                echo 
"<td>".$net_total."</td>";
                                                
//=(W13*1.5-70)*0.8
                                                
if($player["gender"] == "M"){
                                                    
$net_total = ($net_total*1.5-$male_total_par)*0.8;
                                                }else{
                                                    
$net_total = ($net_total*1.5-$female_total_par)*0.8;
                                                }

                                                if(
$net_total 0){
                                                    
$net_total 0;
                                                }
                                                echo 
"<td>".round($net_total1)."</td>";
                                            }
                                        }

                                        
$gross_array[$row["player_id"]] = $gross_total;
                                        
//$net_array[$row["player_id"]] = $net_total;
                                        
$net_array[$row["player_id"]] = $net_total;

                                        if(
$player["gender"] == "M"){
                                            
$net_M_array[$row["player_id"]] = $net_total;
                                        }else{
                                            
$net_F_array[$row["player_id"]] = $net_total;
                                        }

                                    }
                                
?>


                            </table>
                            <br><br>
                            <?php if(!isset($_GET["show_result"])){ ?>
                                <button type="button" onclick="window.location.href='scores_modifyform.php?event_id=<?=$event_id?>&show_result=1'">Show Result</button>
                                <br><br>
                            <?php ?>
                        </td>
                    </tr>

                    <tr style="<?php echo (isset($_GET["show_result"]) && $_GET["show_result"] == "display: table-row":"display: none;"); ?>">
                        <td width="120" align="right" valign="top" class='content winner'>Winner</td>
                        <td class='content winner' valign="top">:</td>
                        <td class='content winner' style="font-weight: bold; font-size: 16px;">
                            <?php
                                asort
($gross_array);
                                
asort($net_array);
                                
asort($net_M_array);
                                
asort($net_F_array);

                                
//remove gross winner in net array
                                
$gross_first_player_id 0;
                                foreach(
$gross_array as $player_id => $row){
                                    
$gross_first_player_id $player_id;
                                    break;
                                }

                                foreach(
$net_array as $player_id => $row){
                                    if(
$player_id == $gross_first_player_id){
                                        unset(
$net_array[$player_id]);
                                    }
                                }

                                foreach(
$net_M_array as $player_id => $row){
                                    if(
$player_id == $gross_first_player_id){
                                        unset(
$net_M_array[$player_id]);
                                    }
                                }

                                foreach(
$net_F_array as $player_id => $row){
                                    if(
$player_id == $gross_first_player_id){
                                        unset(
$net_F_array[$player_id]);
                                    }
                                }

                                
$array1 = array("Gross"=>$gross_array"Net (All)"=>$net_array"Net (Male)"=>$net_M_array"Net (Female)"=>$net_F_array);
                                
$array2 = array("1st""2nd""3rd");

                                foreach(
$array1 as $key1 => $row1){

                                    echo 
$key1.": ";
                                    
$count 0;
                                    foreach(
$row1 as $player_id => $row2){
                                        if(
$key1 == "Gross"){
                                            if(
$count <= 0){
                                                
$player get_player($player_id);
                                                echo 
$array2[$count]." ".$player["name"]." (Par: ".$row2.") ";
                                            }
                                        }else{
                                            if(
$count <= 2){
                                                
$player get_player($player_id);
                                                echo 
$array2[$count]." ".$player["name"]." (Par: ".$row2.")";
                                            }

                                            if(
$count <= 1){
                                                echo 
", ";
                                            }
                                        }

                                        
$count++;
                                    }
                                    echo 
"<br><br>";
                                }
                            
?>

                        </td>
                    </tr>

                    <tr>
                        <td width="120" align="right" valign="top" class='content'></td>
                        <td class='content' valign="top"></td>
                        <td class='content red'>
                            <br> * Required Field <br> * Remark: The scores records will update automatically when a score changes (depends on network status). Click "Save" to save records.<br><br>
                        </td>
                    </tr>

                </table>
            </td>
        </tr>
    </table>
</form>
</body>
</html>