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

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

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

    
$sql99        "SELECT * FROM sys_cms_login WHERE cmsloginid=?";
    
$parameters99 = array((int)$scores_info{'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 () {
            $("#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).attr("name");
                        var hole = hole_string.replace(/hole_/, "");
                        var scores_id = this.id;

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

        });
    </script>
</head>
<body>

<form action="scores_modify2.php" method="post" name="modifyform" enctype="multipart/form-data">
    <input type="hidden" name="event_id" value="<?= $event_id?>">
    <input type="hidden" name="player_id" value="<?= $player_id?>">
    <table width="1000" 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="scores_index.php?event_id=<?=$event_id?>"><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{'lastupdate'}; ?></span>
            </td>
        </tr>

        <tr>
            <td height="25" align="left" valign="middle" class="msg" style="padding-left: 10px;"><?php if (!empty($_GET["msg"])) echo $msg?></td>
        </tr>

        <tr>
            <td align="left" valign="middle"><!-- Content -->
                <table border="0" cellpadding="0" cellspacing="0">

                    <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">
                                <?php
                                    $score  
get_scores($event_id$player_id);
                                    
$player get_player($player_id);
                                    
$hole_array = array(array(1,9), array(10,18));
                                    
$male_total_par 0;
                                    
$female_total_par 0;

                                    
$player_out         0;
                                    
$player_in          0;
                                    
$player_gross_total 0;
                                    
$player_net_total   0;

                                    
$male_out         0;
                                    
$male_in          0;
                                    
$male_gross_total 0;
                                    
$male_net_total   0;

                                    
$female_out         0;
                                    
$female_in          0;
                                    
$female_gross_total 0;
                                    
$female_net_total   0;


                                    foreach(
$hole_array as $hole) {

                                        
?>
                                        <tr>
                                            <td>Hole</td>
                                            <?php
                                                
for ($i $hole[0]; $i <= $hole[1]; $i++) {

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

                                                    if (
$i == 9) {
                                                        echo 
"<td>Out Par</td>";
                                                    }

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

                                        <?php if($player["gender"] == "M") { ?>
                                        <tr>
                                            <td>Par (Male)</td>
                                            <?php
                                                
for ($i $hole[0]; $i <= $hole[1]; $i++) {

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

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

                                                    
$male_gross_total += $event["hole_" $i "_par_M"];

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

                                                    
$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 == 9) {
                                                        echo 
"<td>" $male_out "</td>";
                                                    }

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

                                                
$male_total_par $male_gross_total;
                                            
?>
                                        </tr>
                                        <?php ?>

                                        <?php if($player["gender"] == "F") { ?>
                                        <tr>
                                            <td>Par (Female)</td>
                                            <?php
                                                
for ($i $hole[0]; $i <= $hole[1]; $i++) {

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

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

                                                    
$female_gross_total += $event["hole_" $i "_par_F"];

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


                                                    
$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 == 9) {
                                                        echo 
"<td>" $female_out "</td>";
                                                    }


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

                                                
$female_total_par $female_gross_total;
                                            
?>
                                        </tr>
                                            <?php ?>

                                        <tr>
                                            <td>Count</td>
                                            <?php
                                                
for ($i $hole[0]; $i <= $hole[1]; $i++) {

                                                    echo 
"<td>" . ($event["hole_" $i "_count"] == 'Yes' 'No') . "</td>";

                                                    if (
$i == 9) {
                                                        echo 
"<td></td>";
                                                    }

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

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

                                        <?php
                                        
echo "<tr><td><a href='player_modifyform.php?id=" $row["player_id"] . "' target='_blank' style='text-decoration: underline;'>" $player["name"] . " (" $player["gender"] . ")</a></td>";



                                        for (
$i $hole[0]; $i <= $hole[1]; $i++) {

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

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

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

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


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

                                            if (
$i == 9) {
                                                echo 
"<td>" $player_out "</td>";
                                            }

                                            if (
$i == 18) {
                                                echo 
"<td>" $player_in "</td>";

                                            }
                                        }

                                        echo 
"<tr><td colspan='11' style='border: none; height: 15px;'></td></tr>";
                                    }
                                
?>
                            </table>

                            <table id="scores_table2">
                                <?php if($player["gender"] == "M") { ?>
                                <tr>
                                    <td>Male: Total Par(Gross)</td>
                                    <td>Male: Total Par(Net)</td>
                                    <!--<td colspan="9" style='border: none; height: 15px;'></td>-->
                                </tr>

                                <tr>
                                    <?php
                                        
echo "<td>" $male_gross_total "</td>";
                                        echo 
"<td>" $male_net_total "</td>";
                                    
?>
                                </tr>
                                <?php ?>

                                <?php if($player["gender"] == "F") { ?>
                                <tr>
                                    <td>Female: Total Par(Gross)</td>
                                    <td>Female: Total Par(Net)</td>
                                </tr>

                                <tr>
                                    <?php
                                        
echo "<td>" $female_gross_total "</td>";
                                        echo 
"<td>" $female_net_total "</td>";
                                    
?>
                                </tr>

                                <?php  ?>
                                <tr>
                                    <td>Player: Total Par(Gross)</td>
                                    <td>Player: Total Par(Net)</td>
                                    <td>Player: Net</td>
                                </tr>

                                <tr>
                                    <?php
                                        
echo "<td>" $player_gross_total "</td>";
                                        echo 
"<td>" $player_net_total "</td>";
                                        if (
$player["gender"] == "M") {
                                            
$player_net_total = ($player_net_total 1.5 $male_total_par) * 0.8;
                                        } else {
                                            
$player_net_total = ($player_net_total 1.5 $female_total_par) * 0.8;
                                        }

                                        if (
$player_net_total 0) {
                                            
$player_net_total 0;
                                        }
                                        echo 
"<td>" round($player_net_total1) . "</td>";
                                    
?>
                                </tr>
                            </table>
                            <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>