| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/onegolf/webadmin/ |
Upload File : |
<?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>
Save </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>
Cancel </a></td>
<td> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<span style="float:left;" class="pagetitletxt">
<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'} . ' ' . $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">: </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">: </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;'> <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_total, 1)."</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"] == 1 ? "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>