-
Notifications
You must be signed in to change notification settings - Fork 0
/
pva-seminarka.php
179 lines (161 loc) · 7.63 KB
/
pva-seminarka.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
177
178
179
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css"
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
<title>My Played Games</title>
</head>
<body>
<div class="container" style="margin-bottom: 4rem;">
<h1 class="text-center my-5">My Played Games</h1>
<div class="row">
<div class="col-6">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Add Game
</button>
</div>
<div class="col-6">
<form action="pva-search.php" style="max-width: 400px; margin-left: auto; margin-right: 0;"
class="input-group mb-3" method="post">
<input type="text" class="form-control" placeholder="Search" name="searchInput">
<input type="submit" class="btn btn-primary" name="submit">
</form>
</div>
</div>
<div class="row">
<div class="row row-cols-1 row-cols-md-3 g-4">
<?php
$database = 'herni_databaze.db';
try {
$pdo = new PDO("sqlite:$database");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->query("SELECT jmeno,popis FROM hra");
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
echo '<div class="col">
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">'.$row['jmeno'].'</h5>
<p class="card-text">'.$row['popis'].'</p>
</div>
<div class="card-footer">
<div class="d-flex justify-content-between">
<form action="pva-delete.php" method="post">
<input type="hidden" name="itemId" value="'.$row['jmeno'].'">
<button type="submit" class="btn btn-danger btn-sm">Remove</button>
</form>
<button type="submit" class="btn btn-outline-primary btn-sm" data-bs-toggle="modal" data-bs-target="#updateModal" data-bs-whatever="' . $row['jmeno'] . '">Edit</button>
</div>
</div>
</div>
</div>';
}
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous">
</script>
</body>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Add game</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form name="message-form" action="pva-send.php" class="input-group" method="post">
<input type="text" class="form-control" placeholder="Jméno" name="nameInput"></input>
<input type="text" class="form-control" placeholder="Popis" name="descInput"></input>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="send-message-btn">Confirm</button>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var sendMessageButton = document.getElementById('send-message-btn');
sendMessageButton.addEventListener('click', function() {
var form = document.forms['message-form'];
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'pva-send.php');
xhr.onload = function() {
if (xhr.status === 200) {
// success
form.reset();
location.reload();
} else {
// fail
console.error('Request failed. Status:', xhr.status);
}
};
xhr.send(formData);
});
});
</script>
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="updateModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="updateModalLabel">Update game</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form name="update-form" class="input-group" method="post">
<input type="text" class="form-control" placeholder="Jméno" disabled id="labelNameInput"
name="labelNameInput"></input>
<input type="hidden" id="editNameInput" name="editNameInput"></input>
<input type="text" class="form-control" placeholder="Popis" id="editDescInput"
name="editDescInput"></input>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="update-message-btn">Confirm</button>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var updateMessageButton = document.getElementById('update-message-btn');
updateMessageButton.addEventListener('click', function() {
var form = document.forms['update-form'];
var formData = new FormData(form);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'pva-update.php');
xhr.onload = function() {
if (xhr.status === 200) {
// success
form.reset();
location.reload();
} else {
// fail
console.error('Request failed. Status:', xhr.status);
}
};
xhr.send(formData);
});
var sendMessageButtons = document.querySelectorAll('[data-bs-toggle="modal"]');
sendMessageButtons.forEach(function(button) {
button.addEventListener('click', function() {
const recipient = button.getAttribute('data-bs-whatever');
document.getElementById('labelNameInput').value = recipient;
document.getElementById('editNameInput').value = recipient;
});
});
});
</script>
</html>