-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscorecard.php
133 lines (127 loc) · 3.71 KB
/
scorecard.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
<?php
$send_back = true; //bool to determine if user should be redirected back to 'Create Game'
//Check if players have been submitted, else set send back to true;
if(isset($_POST['players'])){
$players = $_POST['players'];
foreach($players as $key=>$name){
$name = trim($name); //remove excess whitespace
//Check at least one valid name has been submitted
if(strlen($name) > 0){
$send_back = false;
}else{
//remove non-players
unset($players[$key]);
}
}
}
//send back if no players have been submitted
if($send_back){
header('Location:index.php?msg='.urlencode('You must specify at least 1 player before continuing'));
die('Not enough players');
}
//reset array index
$players = array_values($players);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Bowling Scorecard</title>
<link rel='stylesheet' type="text/css" href='resources/css/scorecard.css' />
<link rel='stylesheet' type="text/css" href='resources/css/common.css' />
<script type='text/javascript' src='resources/js/jquery-1.11.0.min.js' ></script>
<script type='text/javascript' src='resources/js/scorecard.js' ></script>
<script type='text/javascript' src='resources/js/class.player.js' ></script>
</head>
<body>
<div id='scoresheet-container'>
<table>
<thead>
<tr>
<th>No.</th>
<th>Player</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
<th>9</th>
<th>10</th>
</tr>
</thead>
<tbody>
<?php
//run through submitted players to build scorecard
foreach($players as $key => $name){
$name = trim($name); //remove extra white space
createPlayerScorecard($key, $name);
}
?>
</tr>
</tbody>
</table>
</div>
<div id='controls'>
<div id='button-container' class='button-container'>
<div id='btn0' class='marRight'>0</div>
<div id='btn1' class='marRight'>1</div>
<div id='btn2' >2</div>
<div id='btn3' class='marRight marTop'>3</div>
<div id='btn4' class='marRight marTop'>4</div>
<div id='btn5' class='marTop'>5</div>
<div id='btn6' class='marRight marTop'>6</div>
<div id='btn7' class='marRight marTop'>7</div>
<div id='btn8' class='marTop'>8</div>
<div id='btn9' class='marRight marTop'>9</div>
<div id='btn10' class='marRight marTop'>X</div>
</div>
<div id='newGame' class='hidden button-container'>
<p>Start New<br />Game</p>
</div>
</div>
<script type='text/javascript'>
<?php
foreach($players as $key=>$name){ //create JavaScript Player objects
echo "players[$key] = new Player($key, '$name');\n";
}
?>
</script>
</body>
</html>
<?php
//Builds the HTML for a player in the scorecard
function createPlayerScorecard($key, $name){
$no = $key + 1; //Set readable player number
if($key == 0){ //if first player set css class
$cssTR = " class='current_player'";
}else{
$cssTR = '';
}
echo "<tr id='pRow$key'$cssTR>
<td class='player_no'>$no</td>
<td class='player_name'>$name</td>";
//create the 9 standard frames
for($f=0; $f<=8; $f++){
echo "<td class='frame";
//set CSS class for first frame
if($f == 0 && $key == 0){
echo " current_frame";
}
echo "' id='p$key-f$f'>
<div class='frame'></div>
<div class='shot shot1'></div>
<div class='shot shot0'></div>
</td>";
}
//create the final frame
echo "<td class='frame' id='p$key-f9'>
<div class='frame final_frame'></div>
<div class='shot shot2'></div>
<div class='shot shot1'></div>
<div class='shot shot0'></div>
</td>
</tr>";
}
?>