-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_match.php
157 lines (134 loc) · 6.11 KB
/
create_match.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
<?php
include 'session_handler.php';
include 'config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Match</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap" rel="stylesheet">
<link rel="icon" href="./media/scorecard.com.png" type="image/png">
<link rel="stylesheet" href="css/create_match.css">
</head>
<body>
<h2>Add New Match</h2>
<form id="createMatchForm" method="POST" action="match_scorecard.php">
<label for="date">Date:</label>
<input type="date" id="date" name="date" required max="<?php echo date('Y-m-d'); ?>"><br>
<label for="team1">Home Team:</label>
<select id="team1" name="team1" onchange="updateVenue(); updateTossWonBy();" required>
<option value="">Select Team</option>
<!-- Populate team options dynamically -->
<?php
$sql = "SELECT short_name, team_name FROM teams";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['short_name'] . "'>" . $row['team_name'] . "</option>";
}
}
?>
</select><br>
<label for="team2">Visiting Team:</label>
<select id="team2" name="team2" onchange="updateVenue(); updateTossWonBy();" required>
<option value="">Select Team</option>
<!-- Populate team options dynamically -->
<?php
// Use the same query result to populate team options
if ($result->num_rows > 0) {
$result->data_seek(0); // Reset pointer to start of result set
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['short_name'] . "'>" . $row['team_name'] . "</option>";
}
}
?>
</select><br>
<label for="venue">Venue:</label>
<input type="text" id="venue" name="venue" readonly>
<br>
<label for="toss_won_by">Toss Won By:</label>
<select id="toss_won_by" name="toss_won_by" required>
<option value="">Select Team</option>
<!-- Options will be dynamically filled based on home and away team selection -->
</select><br>
<label for="decided_to">Decided To:</label>
<select id="decided_to" name="decided_to" required>
<option value="">Select</option>
<option value="bat">Bat</option>
<option value="bowl">Bowl</option>
</select><br>
<input type="submit" value="Create Match">
</form>
<p><a href="view_matches.php">See All Matches</a> | <a href="admin_dashboard.php">Go To Dashboard</a></p>
<p><a href="logout.php">Logout</a></p>
<script>
function updateVenue() {
var team1 = document.getElementById("team1").value;
var team2 = document.getElementById("team2").value;
if (team1 === team2 && team1 !== "" && team2 !== "") {
alert("Please select different teams.");
document.getElementById("team2").value = "";
return;
}
var venueOptions = {
"MI": "Wankhede Stadium",
"CSK": "MA Chidambaram Stadium",
"RCB": "M Chinnaswamy Stadium",
"RR": "Sawai Mansingh Stadium",
"SRH": "Rajiv Gandhi International Cricket Stadium",
"KKR": "Eden Gardens",
"DC": "Arun Jaitley Stadium",
"PKS": "Punjab Cricket Association Stadium",
"GG": "Narendra Modi Stadium",
"LSG": "Bharat Ratna Shri Atal Bihari Vajpayee Ekana Cricket Stadium"
};
var venueDropdown = document.getElementById("venue");
venueDropdown.innerHTML = "";
venueDropdown.innerHTML += "<option value=''>Select Venue</option>";
if (venueOptions[team1] && venueOptions[team2]) {
venueDropdown.innerHTML += "<option value='" + venueOptions[team1] + "'>" + venueOptions[team1] + "</option>";
venueDropdown.value = venueOptions[team1]; // Auto-select venue based on home team
}
}
function updateTossWonBy() {
var team1 = document.getElementById("team1").value;
var team2 = document.getElementById("team2").value;
var tossWonByDropdown = document.getElementById("toss_won_by");
tossWonByDropdown.innerHTML = ""; // Clear existing options
// Create and append the default option
var defaultOption = document.createElement("option");
defaultOption.text = "Select Team";
tossWonByDropdown.add(defaultOption);
// Add options for team1 and team2 if they are selected
if (team1 && team2) {
var team1Option = document.createElement("option");
team1Option.value = team1;
team1Option.text = team1;
tossWonByDropdown.add(team1Option);
var team2Option = document.createElement("option");
team2Option.value = team2;
team2Option.text = team2;
tossWonByDropdown.add(team2Option);
}
}
document.addEventListener("DOMContentLoaded", function () {
updateVenue();
updateTossWonBy();
});
document.getElementById("createMatchForm").addEventListener("submit", function (event) {
if (!confirm("Are you sure you want to create this match?")) {
event.preventDefault(); // Prevent form submission if user cancels
}
});
</script>
<script>
function confirmLogout() {
return confirm("Are you sure you want to log out?");
}
</script>
</body>
</html>