-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreEditor.php
176 lines (152 loc) · 4.19 KB
/
scoreEditor.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
<?php
include ('config.php');
include ('init.php');
include ('include.php');
$eventId = $_GET['eventId'];
$eventShooterId = $_GET['eventShooterId'];
//get key:value (id:targetsBroken) from POST and UPDATE
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$keys = array_keys($_POST);
foreach ($keys as $value){
$query = 'UPDATE shootereventstationscore
SET targetsBroken =' . $_POST[$value] . '
WHERE id=' . $value;
$query = str_replace('\'NULL\'','NULL',$query);
dbquery($query);
}
$url = 'Location:eventShooterEditor.php?eventId=' . $eventId;
header($url);
exit;
}
//get quantity of stations from event
$query = 'SELECT stations
FROM shootevent
WHERE id='. $eventId;
$result = dbquery($query);
$row = mysqli_fetch_assoc($result);
$stations = $row['stations'];
$i = 1;
//add rows for scores
//eventShooterId and eventId must be unique so repeated values are rejected
while ($i <= $stations){
//get individual station id
$query = 'SELECT id
FROM eventstation
WHERE shootEventid=' . $eventId . '
AND stationNumber=' . $i;
$result = dbquery($query);
$row = mysqli_fetch_assoc($result);
//insert individual station id with event shooter id into scores table
$query = 'INSERT INTO shootereventstationscore (`id`,`eventShooterId`,`eventStationId`) VALUES (NULL,\'' . $eventShooterId . '\',\'' . $row['id'] . '\')';
dbqueryl($query);
$i++;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Score Editor</title>
<?php
include 'header.php';
?>
<style>
td{
padding: 1px 5px;
text-align:center;
}
</style>
</head>
<body>
<h1>Score Editor</h1>
<?php
//put if event exists statement here
//editing scores for NAME in the EVENTTYPE of the SHOOTNAME registered shoot
echo '<h2> Editing ';
//get Shooter Name
$query = 'SELECT shooter.firstName, shooter.lastName
FROM shooter
JOIN eventshooter
ON shooter.id=eventshooter.shooterId
WHERE eventshooter.id=' . $eventShooterId;
$result = dbquery($query);
$row = mysqli_fetch_array($result);
echo $row['firstName'] . ' ' . $row['lastName'];
echo ' in the ';
//get Event Name
$query = 'SELECT eventType
FROM shootevent
WHERE id='. $eventId;
$result = dbquery($query);
$row = mysqli_fetch_assoc($result);
echo $row['eventType'];
echo ' Event of the ';
//Get Shooter Name
$query = 'SELECT registeredshoot.shootName
FROM registeredshoot
JOIN shootevent
ON registeredshoot.id=shootevent.shootId
WHERE shootevent.id = ' . $eventId;
$result = dbquery($query);
$row = mysqli_fetch_array($result);
echo $row['shootName'];
echo ' Registered Shoot</h2>';
?>
<?php
echo '<table border=\'1\'><thead>';
$j = 1;
while ($j <= $stations){
echo '<td>' . $j . '</td>';
$j++; }
echo '<td>Total</td></thead>';
$query = 'SELECT id,targetsBroken
FROM shootereventstationscore
WHERE eventShooterId =' . $eventShooterId;
$result = dbquery($query);
$m = 1;
echo '<tr><form method=\'post\' action=\'scoreEditor.php?eventId=' . $eventId . '&eventShooterId=' . $eventShooterId . '\' >';
while ($row = mysqli_fetch_array($result)){
echo '<td><input type=\'text\' size=\'1\' class=\'station' . $m . '\' name=\'' . $row['id'] . '\' value=\'' . $row['targetsBroken'] . '\'';
//set first station to autofocus
if ($m == 1){
echo 'autofocus=\'autofocus\'';
}
echo '></td>';
$m++;
}
echo '<td id=\'totalScore\'></td>';
echo '<td><input type=\'submit\' value=\'Save Scores\' id=\'saveScores\' ></td></form></tr>';
echo '</table>';
?>
</body>
<?php
include 'footer.php';
?>
<script>
//total score on the fly
function calculateScore () {
var score = parseInt(0);
$('input[type="text"]').each(function(k,v){
var val = $(v).val();
score += parseInt(val);
});
$('#totalScore').html(score);
};
$( document ).ready(function() {
//check score on page load
calculateScore();
//check score after data entered
$('input[type="text"]').change(function(){
calculateScore();
});
//setting empty values to NULL rather than zero
//will then check for empty values in eventShooterEditor
$('#saveScores').click(function(){
$('input[type="text"]').each(function(){
if ($(this).val() == ''){
$(this).val('NULL');
}
});
});
});
</script>
</html>