-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.php
104 lines (100 loc) · 4.72 KB
/
edit.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>CardsQL| Edit cards</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="style.css" rel="stylesheet">
</head>
<body>
<?php require_once './header.html'?>
<?php
$pdo = new PDO('sqlite:cardsql.db');
if (isset($_POST['delete-card'])) {
$resultDelete = $pdo->query("delete from cards where id = {$_POST['id']};");
echo ($resultDelete) ? "Card deleted" : "Error deleting card";
}
else if (isset($_POST['edit-card'])) {
$editQuery = 'update cards set front=:front, back=:back, direction=:direction, scheduledDate=:date where id=:id';
// $editQuery = 'update cards set front=":front", back=":back", direction=:direction, scheduledDate=":date" where id=:id';
$statement = $pdo->prepare($editQuery);
$statement->bindValue(':front', $_POST['card-front'], PDO::PARAM_STR);
$statement->bindValue(':back', $_POST['card-back'], PDO::PARAM_STR);
$statement->bindValue(':direction', $_POST['card-direction'], PDO::PARAM_INT);
$statement->bindValue(':date', $_POST['card-new-date'], PDO::PARAM_STR);
$statement->bindValue(':id', $_POST['id'], PDO::PARAM_INT);
echo ($statement->execute()) ? "Card edited" : "Error editing card";
}
$sqlSelect = 'select id, front, back, direction, scheduledDate from cards;';
$resultSelect = $pdo->query($sqlSelect);
?>
<h2>Click on the row you want to edit</h2>
<table id="editable-cards-table">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Front</th>
<th scope="col" class="tooltip-creator">
<span>Card Direction</span>
<span class="tooltip-question-mark">?</span>
<div class="tooltip-container">
<p>Meaning of values:</p>
<ul>
<li>0 = disabled</li>
<li>1 = forward</li>
<li>2 = backward</li>
<li>3 = bi-directional</li>
</ul>
</div>
</th>
<th scope="col">Back</th>
<th scope="col">Scheduled Date</th>
</tr>
</thead>
<tbody>
<?php
while($row = $resultSelect->fetch(PDO::FETCH_ASSOC)) {
?>
<tr>
<th scope="row"><?=$row['id']?></th>
<td><?=$row['front']?></td>
<td><?=$row['direction'];?></td>
<td><?=$row['back']?></td>
<td><?=$row['scheduledDate']?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<dialog id="edit-card-dialog">
<form method="post">
<fieldset>
<legend></legend>
<input type="hidden" name="id">
<label><span>Front:</span>
<textarea name="card-front" id="" maxlength="255" spellcheck="true" rows="10" placeholder="Question. Example: What is CSS used for?" required autofocus></textarea>
</label>
<label><span>Card Direction:</span>
<select name="card-direction">
<option value="0">Disabled</option>
<option value="1">Forward</option>
<option value="2">Backward</option>
<option value="3">Bi-directional</option>
</select>
</label>
<label><span>Back:</span>
<textarea name="card-back" id="" maxlength="255" spellcheck="true" rows="10" placeholder="Answer. Example: Styling our HTML" required></textarea>
</label>
<label><span>Scheduled Date:</span>
<input name="card-new-date" type="date">
</label>
</fieldset>
<button type="button" class="dialog-cancel">Cancel</button>
<button type="submit" name="delete-card">Delete card</button>
<button type="submit" name="edit-card">Confirm changes</button>
</form>
</dialog>
<script src="./edit-logic.js"></script>
</body>
</html>