-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletegoal.php
139 lines (125 loc) · 3.95 KB
/
deletegoal.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
<html>
<head>
<title>Delete Goal</title>
</head>
<body onload="showDates(document.getElementById('location').value)">
<?php
if(isset($_POST['submit'])){
$data_missing = array();
foreach($_POST as $key => $value) {
if($value == "") {
$data_missing[] = $key;
}
$$key = $value;
}
// $date, $location, $min, $sec, $period // are set now
if ($sec < 10) {
$sec = '0'.$sec;
}
$goal_time = $min.':'.$sec;
if(empty($data_missing)){
require_once('../../mysqli_connect.php');
// Check primary keys for if this row already exists
if(mysqli_fetch_array(mysqli_query($dbc, 'SELECT date, location, goal_time
FROM goal
WHERE date = "'.$date.'" AND location = "'.$location.'" AND goal_time = "'.$goal_time.'" AND goal_period = "'.$period.'"'))['date'] == $date) {
// Goal exists
$query = 'DELETE FROM goal WHERE date = "'.$date.'" AND location = "'.$location.'" AND goal_time = "'.$goal_time.'" AND goal_period = "'.$period.'"';
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_execute($stmt);
echo 'Goal Removed';
} else {
// Goal does not exist
// Do nothing
echo 'Goal does not exist.';
}
} else {
echo 'You need to enter the following data<br />';
foreach($data_missing as $missing){
echo "$missing<br />";
}
}
}
?>
<form action="" method="post">
<b>Delete a Goal</b><br>
Location:<br>
<select name="location" id="location" onchange="showDates(this.value)">
<?php
require_once('../../mysqli_connect.php');
$query = "SELECT location
FROM game";
$response = mysqli_query($dbc, $query);
if($response) {
$locations = array();
while($row = mysqli_fetch_array($response)) {
$locations[] = $row['location'];
}
foreach (array_unique($locations) as $i => $location) {
echo "<option>" . $location . "</option>";
}
} ?>
</select><br>
Date:<br>
<select name="date" id="date">
</select><br>
<script>
var dates = {};
<?php
require_once('../../mysqli_connect.php');
$dates = array();
foreach (array_unique($locations) as $i => $location) {
$query = "SELECT date
FROM game
WHERE location = '$location'";
$response = mysqli_query($dbc, $query);
if($response) {
$dates[$location] = array();
while($row = mysqli_fetch_array($response)) {
$dates[$location][] = $row['date'];
}
}
}
foreach ($dates as $location => $datesArray) {
echo 'dates["'.$location.'"] = [];
';
foreach ($datesArray as $i => $date) {
echo 'dates["'.$location.'"].push("'.$date.'");';
}
}
?>
function showDates(location) {
var newDates = dates[location];
var options = newDates.map(function (date) {
var option = document.createElement("option");
option.setAttribute("value", date);
option.innerHTML = date;
return option;
});
select = document.getElementById("date");
select.innerHTML = "";
for (option of options) {
select.appendChild(option);
}
}
</script>
Period:<br>
<select name="period">
<option>1</option>
<option>2</option>
<option>3</option>
</select><br>
Minutes:<br>
<select name="min">
<?php for ($i = 0; $i <= 19; $i++) {
echo '<option>'.$i.'</option>'; } ?>
</select><br>
Seconds:<br>
<select name="sec">
<?php for ($i = 0; $i <= 59; $i++) {
echo '<option>'.$i.'</option>'; } ?>
</select><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>