-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.php
More file actions
237 lines (211 loc) · 9.76 KB
/
Copy pathweb.php
File metadata and controls
237 lines (211 loc) · 9.76 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>KoReader Sync</title>
<style>
* { box-sizing:border-box; margin:0; padding:0 }
body { font:14px system-ui,sans-serif; background:#f5f5f5; color:#222; min-height:100vh }
header { background:#2c3e50; color:#fff; padding:12px 16px; display:flex; justify-content:space-between; align-items:center }
header h1 { font-size:1.1rem; font-weight:600 }
header .user { font-size:.85rem; opacity:.85; display:flex; gap:8px; align-items:center }
header .user button { background:none; border:1px solid rgba(255,255,255,.3); color:#fff; padding:4px 12px; border-radius:4px; cursor:pointer; font-size:.8rem }
header .user button:hover { background:rgba(255,255,255,.1) }
main { max-width:860px; margin:0 auto; padding:16px }
.card { background:#fff; border-radius:8px; box-shadow:0 1px 3px rgba(0,0,0,.08); padding:20px; margin-bottom:16px }
.card h2 { font-size:1rem; margin-bottom:14px; color:#2c3e50 }
input { display:block; width:100%; padding:10px 12px; margin-bottom:10px; border:1px solid #ddd; border-radius:6px; font-size:.95rem; font-family:inherit }
input:focus { outline:none; border-color:#3498db; box-shadow:0 0 0 2px rgba(52,152,219,.15) }
.meta-edit input { padding:6px 8px; margin-bottom:6px; font-size:.8rem }
.btn { display:inline-block; padding:10px 20px; border:none; border-radius:6px; font-size:.9rem; font-weight:600; cursor:pointer; font-family:inherit }
.btn-primary { background:#3498db; color:#fff }
.btn-primary:hover { background:#2980b9 }
.btn-green { background:#27ae60; color:#fff }
.btn-green:hover { background:#219a52 }
.btn-group { display:flex; gap:8px }
.error { background:#fdecea; color:#c0392b; padding:10px 14px; border-radius:6px; margin-bottom:12px; font-size:.85rem }
table { width:100%; border-collapse:collapse }
th, td { text-align:left; padding:10px 12px; border-bottom:1px solid #eee; font-size:.85rem; vertical-align:middle }
th { color:#888; font-weight:500; text-transform:uppercase; font-size:.75rem; letter-spacing:.5px }
tr:hover td { background:#f8f9fa }
tr.edit-row td { background:#f0f7ff; padding:6px 12px }
.progress-bar { width:80px; height:6px; background:#e9ecef; border-radius:3px; overflow:hidden; display:inline-block; vertical-align:middle; margin-right:6px }
.progress-bar-fill { height:100%; background:#27ae60; border-radius:3px }
.progress-cell { white-space:nowrap }
.hash { font-family:monospace; font-size:.8rem; color:#888 }
.hash-full { display:none }
.hash:hover .hash-short { display:none }
.hash:hover .hash-full { display:inline }
.actions { white-space:nowrap }
.actions button { background:none; border:none; cursor:pointer; font-size:.85rem; padding:4px 6px; border-radius:4px }
.edit-btn { color:#3498db }
.edit-btn:hover { background:#eaf2fb }
.del-btn { color:#c0392b }
.del-btn:hover { background:#fdecea }
.empty { text-align:center; color:#888; padding:40px 0; font-size:.9rem }
</style>
</head>
<body>
<header>
<h1>KoReader Sync</h1>
<?php if ($loggedIn): ?>
<span class="user"><?= htmlspecialchars($username) ?> <button onclick="logout()">Uitloggen</button></span>
<?php endif; ?>
</header>
<main>
<?php if ($error): ?>
<div class="error"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<?php if (!$loggedIn): ?>
<div class="card">
<h2>Inloggen</h2>
<p style="color:#666;font-size:.8rem;margin-bottom:12px">Gebruik hetzelfde account als op je ereader om je leesvoortgang te zien.</p>
<form id="loginForm" onsubmit="handleLogin(event)">
<input type="text" id="loginUser" placeholder="Gebruikersnaam" required autocomplete="username">
<input type="password" id="loginPass" placeholder="Wachtwoord" required autocomplete="current-password">
<div class="btn-group">
<button type="submit" class="btn btn-primary">Inloggen</button>
<?php if ($registrationEnabled): ?>
<button type="button" class="btn btn-green" onclick="handleRegister(event)">Registreren</button>
<?php endif; ?>
</div>
</form>
</div>
<?php else: ?>
<div class="card">
<h2>Leesvoortgang</h2>
<?php if (empty($documents)): ?>
<div class="empty">
Geen leesvoortgang voor <strong><?= htmlspecialchars($username) ?></strong>.<br><br>
<span style="font-size:.8rem;color:#999">Controleer of je ereader hetzelfde account gebruikt.<br>
Custom sync server: <code><?= htmlspecialchars($_SERVER['HTTP_HOST'] ?? 'jouw-server') ?></code></span>
</div>
<?php else: ?>
<table>
<thead>
<tr>
<th>Document</th>
<th>Voortgang</th>
<th>Apparaat</th>
<th>Laatst bijgewerkt</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($documents as $doc):
$meta = json_decode($doc['metadata'] ?? '{}', true) ?: [];
$title = $meta['title'] ?? '';
$file = $meta['filename'] ?? '';
$authors = $meta['authors'] ?? '';
$hash = $doc['document'];
$label = $title ?: ($file ?: null);
$sub = $title && $file ? $file : null;
$pct = round((float) $doc['percentage'] * 100, 1);
$ts = date('d-m-Y H:i', (int) $doc['updated_at']);
$rid = 'd' . substr($hash, 0, 16);
?>
<tr id="<?= $rid ?>">
<td>
<?php if ($label): ?>
<strong><?= htmlspecialchars($label) ?></strong>
<?php if ($sub): ?><br><span class="hash"><?= htmlspecialchars($sub) ?></span><?php endif; ?>
<?php if ($authors): ?><br><span class="hash"><?= htmlspecialchars($authors) ?></span><?php endif; ?>
<?php else: ?>
<span class="hash">
<span class="hash-short"><?= htmlspecialchars(substr($hash, 0, 8)) ?>…</span>
<span class="hash-full"><?= htmlspecialchars($hash) ?></span>
</span>
<?php endif; ?>
</td>
<td class="progress-cell">
<div class="progress-bar"><div class="progress-bar-fill" style="width:<?= $pct ?>%"></div></div>
<?= $pct ?>%
</td>
<td><?= htmlspecialchars($doc['device']) ?></td>
<td><?= $ts ?></td>
<td class="actions">
<button class="edit-btn" onclick="editMeta('<?= htmlspecialchars($hash, ENT_QUOTES) ?>', this)" title="Bewerk metadata">✎</button>
<button class="del-btn" onclick="del('<?= htmlspecialchars($hash, ENT_QUOTES) ?>', this)" title="Verwijderen">×</button>
</td>
</tr>
<tr class="edit-row" id="<?= $rid ?>e" style="display:none">
<td colspan="5">
<div style="display:flex;gap:8px;align-items:flex-end">
<div style="flex:1" class="meta-edit">
<input id="<?= $rid ?>_title" placeholder="Titel" value="<?= htmlspecialchars($title) ?>" style="margin-bottom:4px">
<input id="<?= $rid ?>_file" placeholder="Bestandsnaam" value="<?= htmlspecialchars($file) ?>" style="margin-bottom:4px">
<input id="<?= $rid ?>_authors" placeholder="Auteur(s)" value="<?= htmlspecialchars($authors) ?>">
</div>
<div style="margin-bottom:2px">
<button class="btn btn-primary" style="padding:6px 14px;font-size:.8rem;margin-right:4px" onclick="saveMeta('<?= htmlspecialchars($hash, ENT_QUOTES) ?>', '<?= $rid ?>')">Opslaan</button>
<button class="btn" style="padding:6px 14px;font-size:.8rem;background:#eee" onclick="cancelEdit('<?= $rid ?>')">Annuleren</button>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<?php endif; ?>
</main>
<script>
async function post(url, body) {
const r = await fetch(url, {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)});
return r.json();
}
async function handleLogin(e) {
e.preventDefault();
const u = document.getElementById('loginUser').value.trim();
const p = document.getElementById('loginPass').value.trim();
const r = await post('/?a=login', {username:u, password:p});
if (r.ok) location.reload();
else alert(r.error || 'Inloggen mislukt');
}
async function handleRegister(e) {
const u = document.getElementById('loginUser').value.trim();
const p = document.getElementById('loginPass').value.trim();
if (!u || !p) { alert('Vul gebruikersnaam en wachtwoord in'); return; }
const r = await post('/?a=register', {username:u, password:p});
if (r.ok) location.reload();
else alert(r.error || 'Registratie mislukt');
}
async function logout() {
await post('/?a=logout', {});
location.reload();
}
async function del(docHash, btn) {
if (!confirm('Deze leesvoortgang verwijderen?')) return;
btn.disabled = true;
const r = await post('/?a=delete', {document: docHash});
if (r.ok) {
const id = 'd' + docHash.substring(0, 16);
btn.closest('tr').remove();
document.getElementById(id + 'e')?.remove();
} else {
btn.disabled = false;
alert('Verwijderen mislukt');
}
}
function editMeta(docHash, btn) {
const id = 'd' + docHash.substring(0, 16);
document.getElementById(id).style.display = 'none';
document.getElementById(id + 'e').style.display = '';
}
function cancelEdit(rowId) {
document.getElementById(rowId).style.display = '';
document.getElementById(rowId + 'e').style.display = 'none';
}
async function saveMeta(docHash, rowId) {
const title = document.getElementById(rowId + '_title').value.trim();
const filename = document.getElementById(rowId + '_file').value.trim();
const authors = document.getElementById(rowId + '_authors').value.trim();
const r = await post('/?a=editmeta', {document: docHash, title, filename, authors});
if (r.ok) location.reload();
else alert(r.error || 'Opslaan mislukt');
}
</script>
</body>
</html>