1
|
<?php
|
2
|
class DB {
|
3
|
// (A) CONNECT TO DATABASE
|
4
|
public $error = "";
|
5
|
private $pdo = null;
|
6
|
private $stmt = null;
|
7
|
function __construct () {
|
8
|
ini_set('memory_limit', '1024M');
|
9
|
try {
|
10
|
$this->pdo = new PDO(
|
11
|
"pgsql:host=".DB_HOST.";dbname=".DB_NAME,
|
12
|
DB_USER, DB_PASSWORD, [
|
13
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
14
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
|
15
|
]
|
16
|
);
|
17
|
} catch (Exception $ex) { die($ex->getMessage()); }
|
18
|
}
|
19
|
|
20
|
// (B) CLOSE CONNECTION
|
21
|
function __destruct(){
|
22
|
if ($this->stmt!==null) { $this->stmt = null; }
|
23
|
if ($this->pdo!==null) { $this->pdo = null; }
|
24
|
}
|
25
|
|
26
|
// (C) RUN A SELECT QUERY
|
27
|
function select($sql, $params){
|
28
|
$result = false;
|
29
|
try {
|
30
|
$this->stmt = $this->pdo->prepare($sql);
|
31
|
if (array_key_exists("lemma", $params)) {
|
32
|
$this->stmt->bindParam(':lemma',$params['lemma'], PDO::PARAM_STR);
|
33
|
}
|
34
|
if (array_key_exists("word", $params)) {
|
35
|
$this->stmt->bindParam(':word',$params['word'], PDO::PARAM_STR);
|
36
|
}
|
37
|
if (array_key_exists("position1", $params)) {
|
38
|
$this->stmt->bindParam(':position1',$params['position1'], PDO::PARAM_INT);
|
39
|
}
|
40
|
if (array_key_exists("position2", $params)) {
|
41
|
$this->stmt->bindParam(':position2',$params['position2'], PDO::PARAM_INT);
|
42
|
}
|
43
|
if (array_key_exists("positiondetail", $params)) {
|
44
|
$this->stmt->bindParam(':positiondetail',$params['positiondetail'], PDO::PARAM_INT);
|
45
|
}
|
46
|
if (array_key_exists("tag", $params)) {
|
47
|
$this->stmt->bindParam(':tag',$params['tag'], PDO::PARAM_STR);
|
48
|
}
|
49
|
if (array_key_exists("tag", $params)) {
|
50
|
$this->stmt->bindParam(':tag',$params['tag'], PDO::PARAM_STR);
|
51
|
}
|
52
|
if (array_key_exists("description2", $params)) {
|
53
|
$this->stmt->bindParam(':description2',$params['description2']);
|
54
|
}
|
55
|
if (array_key_exists("manuscript", $params)) {
|
56
|
for ($x = 0; $x < count($params["manuscript"]); $x += 1) {
|
57
|
$this->stmt->bindParam(':manuscript'.$x,$params["manuscript"][$x], PDO::PARAM_INT);
|
58
|
}
|
59
|
}
|
60
|
$this->stmt->execute();
|
61
|
$result = $this->stmt->fetchAll();
|
62
|
return $result;
|
63
|
} catch (Exception $ex) {
|
64
|
$this->error = $ex->getMessage();
|
65
|
return false;
|
66
|
}
|
67
|
}
|
68
|
|
69
|
function getUser($username) {
|
70
|
$this->stmt = $this->pdo->prepare('SELECT id, username, password, role FROM users WHERE username = :username');
|
71
|
$this->stmt->bindParam(':username', $username);
|
72
|
$this->stmt->execute();
|
73
|
return $this->stmt->fetchAll();
|
74
|
}
|
75
|
|
76
|
function createUser($userDetails) {
|
77
|
$this->stmt = $this->pdo->prepare('INSERT INTO users (username, password, role) VALUES (:username, :password, :role)');
|
78
|
$password = password_hash($userDetails['password'], PASSWORD_DEFAULT);
|
79
|
$this->stmt->bindParam(':username', $userDetails['username']);
|
80
|
$this->stmt->bindParam(':password',$password);
|
81
|
$this->stmt->bindParam(':role',$userDetails['role']);
|
82
|
$this->stmt->execute();
|
83
|
return $this->stmt->fetchAll();
|
84
|
}
|
85
|
|
86
|
function createChangeRequest($request) {
|
87
|
$this->stmt = $this->pdo->prepare('INSERT INTO changes (wordform_id, message) VALUES (:wordform_id, :message)');
|
88
|
$this->stmt->bindParam(':wordform_id', $request['wordform_id']);
|
89
|
$this->stmt->bindParam(':message',$request['message']);
|
90
|
$this->stmt->execute();
|
91
|
return $this->stmt->fetchAll();
|
92
|
}
|
93
|
|
94
|
function removeChangeRequest($requestId) {
|
95
|
$this->stmt = $this->pdo->prepare('DELETE FROM changes WHERE id = :requestId');
|
96
|
$this->stmt->bindParam(':requestId', $requestId);
|
97
|
$this->stmt->execute();
|
98
|
return $this->stmt->fetchAll();
|
99
|
}
|
100
|
|
101
|
function getChangeRequests() {
|
102
|
$this->stmt = $this->pdo->prepare('SELECT c.id as changeId, c.message, w.id as wordformId, w.word, l.lemma FROM changes as c left join dd_wordform as w on c.wordform_id = w.id left join dd_lemma as l on w.lemma_id = l.id');
|
103
|
$this->stmt->execute();
|
104
|
return $this->stmt->fetchAll();
|
105
|
}
|
106
|
|
107
|
function updateUserRole($userId, $role) {
|
108
|
$this->stmt = $this->pdo->prepare("UPDATE users SET role = :role WHERE id = :userId");
|
109
|
$this->stmt->bindParam(':role', $role);
|
110
|
$this->stmt->bindParam(':userId',$userId);
|
111
|
$this->stmt->execute();
|
112
|
return $this->stmt->fetchAll();
|
113
|
}
|
114
|
|
115
|
function deleteUser($userId) {
|
116
|
$this->stmt = $this->pdo->prepare("DELETE from users WHERE id = :userId");
|
117
|
$this->stmt->bindParam(':userId',$userId);
|
118
|
$this->stmt->execute();
|
119
|
return $this->stmt->fetchAll();
|
120
|
}
|
121
|
|
122
|
function update(){
|
123
|
$query = "SELECT id FROM dd_lemma
|
124
|
WHERE lemma = :lemma;";
|
125
|
$this->stmt = $this->pdo->prepare($query);
|
126
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
127
|
$this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
|
128
|
}
|
129
|
$this->stmt->execute();
|
130
|
$lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
131
|
|
132
|
$query = "SELECT id FROM dd_tag
|
133
|
WHERE tag = :tag;";
|
134
|
$this->stmt = $this->pdo->prepare($query);
|
135
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
136
|
$this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
|
137
|
}
|
138
|
$this->stmt->execute();
|
139
|
$tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
140
|
|
141
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
142
|
if($lemma == null){
|
143
|
$query = "SELECT MAX(id) FROM dd_lemma;";
|
144
|
$this->stmt = $this->pdo->prepare($query);
|
145
|
$this->stmt->execute();
|
146
|
$result = $this->stmt->fetchAll();
|
147
|
$result[0]["max"]+=1;
|
148
|
|
149
|
$query = "INSERT INTO dd_lemma ( id, ";
|
150
|
$values = "VALUES (" . $result[0]["max"] . ", ";
|
151
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
152
|
$query .= " lemma, ";
|
153
|
$values .= " :lemma, ";
|
154
|
}
|
155
|
if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
|
156
|
$query .= " pos ) ";
|
157
|
$values .= " :pos ); ";
|
158
|
}
|
159
|
|
160
|
$query .= $values;
|
161
|
$this->stmt = $this->pdo->prepare($query);
|
162
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
163
|
$this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
|
164
|
}
|
165
|
if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
|
166
|
$this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
|
167
|
}
|
168
|
$this->stmt->execute();
|
169
|
|
170
|
$query = "SELECT id FROM dd_lemma
|
171
|
WHERE lemma = :lemma;";
|
172
|
$this->stmt = $this->pdo->prepare($query);
|
173
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
174
|
$this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
|
175
|
}
|
176
|
$this->stmt->execute();
|
177
|
$lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
178
|
}
|
179
|
|
180
|
$query = "UPDATE dd_lemma
|
181
|
SET ";
|
182
|
|
183
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
184
|
$query .= " lemma = :lemma , ";
|
185
|
}
|
186
|
if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
|
187
|
$query .= " pos = :pos ";
|
188
|
}
|
189
|
|
190
|
$query .= "WHERE ";
|
191
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
192
|
$query .= " id = :lemma_id ;";
|
193
|
}
|
194
|
|
195
|
|
196
|
$this->stmt = $this->pdo->prepare($query);
|
197
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
198
|
$this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
|
199
|
}
|
200
|
if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
|
201
|
$this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
|
202
|
}
|
203
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
204
|
$this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
|
205
|
}
|
206
|
$this->stmt->execute();
|
207
|
|
208
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
209
|
if($tag == null){
|
210
|
$query = "SELECT MAX(id) FROM dd_tag;";
|
211
|
$this->stmt = $this->pdo->prepare($query);
|
212
|
$this->stmt->execute();
|
213
|
$result = $this->stmt->fetchAll();
|
214
|
$result[0]["max"]+=1;
|
215
|
|
216
|
|
217
|
$query = "INSERT INTO dd_tag (id, ";
|
218
|
$values = "VALUES (" . $result[0]["max"] . ", ";
|
219
|
|
220
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
221
|
$query .= " tag ) ";
|
222
|
$values .= " :tag ); ";
|
223
|
}
|
224
|
|
225
|
$query .= $values;
|
226
|
$this->stmt = $this->pdo->prepare($query);
|
227
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
228
|
$this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
|
229
|
}
|
230
|
$this->stmt->execute();
|
231
|
|
232
|
$query = "SELECT id FROM dd_tag
|
233
|
WHERE tag = :tag;";
|
234
|
$this->stmt = $this->pdo->prepare($query);
|
235
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
236
|
$this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
|
237
|
}
|
238
|
$this->stmt->execute();
|
239
|
$tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
240
|
}
|
241
|
|
242
|
$query = "UPDATE dd_tag
|
243
|
SET ";
|
244
|
|
245
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
246
|
$query .= " tag = :tag ";
|
247
|
}
|
248
|
|
249
|
$query .= "WHERE ";
|
250
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
251
|
$query .= " id = :tag_id ;";
|
252
|
}
|
253
|
|
254
|
|
255
|
$this->stmt = $this->pdo->prepare($query);
|
256
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
257
|
$this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
|
258
|
}
|
259
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
260
|
$this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
|
261
|
}
|
262
|
$this->stmt->execute();
|
263
|
|
264
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
265
|
$query = "UPDATE dd_wordform
|
266
|
SET ";
|
267
|
|
268
|
|
269
|
if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
|
270
|
$query .= " context = :context, ";
|
271
|
}
|
272
|
$query .= " date = CURRENT_DATE,";
|
273
|
|
274
|
if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
|
275
|
$query .= " description = :description, ";
|
276
|
}
|
277
|
if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
|
278
|
$query .= " description2 = :description2, ";
|
279
|
}
|
280
|
if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
|
281
|
$query .= " description3 = :description3, ";
|
282
|
}
|
283
|
if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
|
284
|
$query .= " ending = :ending, ";
|
285
|
}
|
286
|
if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
|
287
|
$query .= " finished = :finished, ";
|
288
|
}
|
289
|
if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
|
290
|
$query .= " namedentity = :namedentity, ";
|
291
|
}
|
292
|
if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
|
293
|
$query .= " position1 = :position1, ";
|
294
|
}
|
295
|
if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
|
296
|
$query .= " position2 = :position2, ";
|
297
|
}
|
298
|
if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
|
299
|
$query .= " positiondetail = :positiondetail ,";
|
300
|
}
|
301
|
if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
|
302
|
$query .= " prefix = :prefix, ";
|
303
|
}
|
304
|
if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
|
305
|
$query .= " suffix = :suffix, ";
|
306
|
}
|
307
|
if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
|
308
|
$query .= " word = :word, ";
|
309
|
}
|
310
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
311
|
$query .= " lemma_id = :lemma_id, ";
|
312
|
}
|
313
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
314
|
$query .= " tag_id = :tag_id ";
|
315
|
}
|
316
|
|
317
|
$query .= " WHERE ";
|
318
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
319
|
$query .= " id = :id ;";
|
320
|
}
|
321
|
|
322
|
$this->stmt = $this->pdo->prepare($query);
|
323
|
|
324
|
if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
|
325
|
$this->stmt->bindParam(':context', $_POST['context'], PDO::PARAM_STR);
|
326
|
}
|
327
|
if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
|
328
|
$this->stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);
|
329
|
}
|
330
|
if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
|
331
|
$this->stmt->bindParam(':description2', $_POST['description2'], PDO::PARAM_STR);
|
332
|
}
|
333
|
if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
|
334
|
$this->stmt->bindParam(':description3', $_POST['description3'], PDO::PARAM_STR);
|
335
|
}
|
336
|
if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
|
337
|
$this->stmt->bindParam(':ending', $_POST['ending'], PDO::PARAM_STR);
|
338
|
}
|
339
|
if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
|
340
|
$this->stmt->bindParam(':finished', $_POST['finished']);
|
341
|
}
|
342
|
if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
|
343
|
$this->stmt->bindParam(':namedentity', $_POST['namedentity'], PDO::PARAM_INT);
|
344
|
}
|
345
|
if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
|
346
|
$this->stmt->bindParam(':position1', $_POST['position1'], PDO::PARAM_STR);
|
347
|
}
|
348
|
if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
|
349
|
$this->stmt->bindParam(':position2', $_POST['position2'], PDO::PARAM_STR);
|
350
|
}
|
351
|
if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
|
352
|
$this->stmt->bindParam(':positiondetail', $_POST['positiondetail'], PDO::PARAM_STR);
|
353
|
}
|
354
|
if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
|
355
|
$this->stmt->bindParam(':prefix', $_POST['prefix'], PDO::PARAM_STR);
|
356
|
}
|
357
|
if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
|
358
|
$this->stmt->bindParam(':suffix', $_POST['suffix'], PDO::PARAM_STR);
|
359
|
}
|
360
|
if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
|
361
|
$this->stmt->bindParam(':word', $_POST['word'], PDO::PARAM_STR);
|
362
|
}
|
363
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
364
|
$this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
|
365
|
}
|
366
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
367
|
$this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
|
368
|
}
|
369
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
370
|
$this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
|
371
|
}
|
372
|
|
373
|
$this->stmt->execute();
|
374
|
|
375
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
376
|
|
377
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
378
|
$query = "SELECT * FROM dd_manuscript WHERE ";
|
379
|
$query .= " wordform_id = :wordform_id ;";
|
380
|
}
|
381
|
|
382
|
$this->stmt = $this->pdo->prepare($query);
|
383
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
384
|
$this->stmt->bindParam(':wordform_id', $_POST['id']);
|
385
|
}
|
386
|
$this->stmt->execute();
|
387
|
$result = $this->stmt->fetchAll();
|
388
|
|
389
|
$to_insert = [];
|
390
|
$to_delete = [];
|
391
|
$contained = [];
|
392
|
$found = false;
|
393
|
$integerIDs = [];
|
394
|
|
395
|
foreach ($result as $res) {
|
396
|
$integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
|
397
|
foreach ($integerIDs as $new_value){
|
398
|
if($new_value == $res['manuscript']){
|
399
|
$found = true;
|
400
|
array_push($contained, $new_value);
|
401
|
}
|
402
|
}
|
403
|
if($found == false){
|
404
|
array_push($to_delete, $res);
|
405
|
}
|
406
|
$found = false;
|
407
|
}
|
408
|
$to_insert = array_diff($integerIDs, $contained);
|
409
|
|
410
|
foreach ($to_delete as $id_to_delete){
|
411
|
$query = "DELETE FROM dd_manuscript WHERE ";
|
412
|
$query .= "manuscript = " . $id_to_delete['manuscript'] . " AND ";
|
413
|
$query .= " wordform_id = :wordform_id ;";
|
414
|
|
415
|
|
416
|
$this->stmt = $this->pdo->prepare($query);
|
417
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
418
|
$this->stmt->bindParam(':wordform_id', $_POST['id'], PDO::PARAM_INT);
|
419
|
}
|
420
|
//
|
421
|
$this->stmt->execute();
|
422
|
var_dump($query);
|
423
|
}
|
424
|
|
425
|
foreach ($to_insert as $id_to_insert){
|
426
|
$query = "INSERT INTO dd_manuscript VALUES ( ";
|
427
|
$query .= " :wordform_id , ";
|
428
|
$query .= " " . $id_to_insert . " ); ";
|
429
|
|
430
|
$this->stmt = $this->pdo->prepare($query);
|
431
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
432
|
$this->stmt->bindParam(':wordform_id', $_POST['id'], PDO::PARAM_INT);
|
433
|
}
|
434
|
$this->stmt->execute();
|
435
|
}
|
436
|
}
|
437
|
|
438
|
function insert(){
|
439
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
440
|
$query = "SELECT id FROM dd_lemma
|
441
|
WHERE lemma = :lemma;";
|
442
|
$this->stmt = $this->pdo->prepare($query);
|
443
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
444
|
$this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
|
445
|
}
|
446
|
$this->stmt->execute();
|
447
|
$lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
448
|
|
449
|
if($lemma == null){
|
450
|
$query = "SELECT MAX(id) FROM dd_lemma;";
|
451
|
$this->stmt = $this->pdo->prepare($query);
|
452
|
$this->stmt->execute();
|
453
|
$result = $this->stmt->fetchAll();
|
454
|
$result[0]["max"]+=1;
|
455
|
|
456
|
$query = "INSERT INTO dd_lemma ( id, ";
|
457
|
$values = "VALUES (" . $result[0]["max"] . ", ";
|
458
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
459
|
$query .= " lemma, ";
|
460
|
$values .= " :lemma, ";
|
461
|
}
|
462
|
if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
|
463
|
$query .= " pos ) ";
|
464
|
$values .= " :pos ); ";
|
465
|
}
|
466
|
|
467
|
$query .= $values;
|
468
|
$this->stmt = $this->pdo->prepare($query);
|
469
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
470
|
$this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
|
471
|
}
|
472
|
if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
|
473
|
$this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
|
474
|
}
|
475
|
$this->stmt->execute();
|
476
|
}
|
477
|
|
478
|
|
479
|
|
480
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
481
|
$query = "SELECT id FROM dd_tag
|
482
|
WHERE tag = :tag;";
|
483
|
$this->stmt = $this->pdo->prepare($query);
|
484
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
485
|
$this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
|
486
|
}
|
487
|
$this->stmt->execute();
|
488
|
$tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
489
|
|
490
|
if($tag == null){
|
491
|
$query = "SELECT MAX(id) FROM dd_tag;";
|
492
|
$this->stmt = $this->pdo->prepare($query);
|
493
|
$this->stmt->execute();
|
494
|
$result = $this->stmt->fetchAll();
|
495
|
$result[0]["max"]+=1;
|
496
|
|
497
|
|
498
|
$query = "INSERT INTO dd_tag (id, ";
|
499
|
$values = "VALUES (" . $result[0]["max"] . ", ";
|
500
|
|
501
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
502
|
$query .= " tag ) ";
|
503
|
$values .= " :tag ); ";
|
504
|
}
|
505
|
|
506
|
$query .= $values;
|
507
|
$this->stmt = $this->pdo->prepare($query);
|
508
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
509
|
$this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
|
510
|
}
|
511
|
$this->stmt->execute();
|
512
|
}
|
513
|
|
514
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
515
|
$query = "SELECT MAX(id) FROM dd_wordform;";
|
516
|
$this->stmt = $this->pdo->prepare($query);
|
517
|
$this->stmt->execute();
|
518
|
$result = $this->stmt->fetchAll();
|
519
|
$result[0]["max"]+=1;
|
520
|
|
521
|
$query = "SELECT id FROM dd_lemma
|
522
|
WHERE lemma = :lemma;";
|
523
|
$this->stmt = $this->pdo->prepare($query);
|
524
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
525
|
$this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
|
526
|
}
|
527
|
$this->stmt->execute();
|
528
|
$lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
529
|
|
530
|
$query = "SELECT id FROM dd_tag
|
531
|
WHERE tag = :tag;";
|
532
|
$this->stmt = $this->pdo->prepare($query);
|
533
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
534
|
$this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
|
535
|
}
|
536
|
$this->stmt->execute();
|
537
|
$tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
538
|
|
539
|
$query = "INSERT INTO dd_wordform ( id, ";
|
540
|
$values = "VALUES (" . $result[0]["max"] . ", ";
|
541
|
|
542
|
if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
|
543
|
$query .= " context, ";
|
544
|
$values .= " :context, ";
|
545
|
}
|
546
|
$query .= " date, ";
|
547
|
$values .= " CURRENT_DATE, ";
|
548
|
|
549
|
if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
|
550
|
$query .= " description, ";
|
551
|
$values .= " :description, ";
|
552
|
}
|
553
|
if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
|
554
|
$query .= " description2, ";
|
555
|
$values .= " :description2, ";
|
556
|
}
|
557
|
if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
|
558
|
$query .= " description3, ";
|
559
|
$values .= " :description3, ";
|
560
|
}
|
561
|
if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
|
562
|
$query .= " ending, ";
|
563
|
$values .= " :ending, ";
|
564
|
}
|
565
|
if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
|
566
|
$query .= " finished, ";
|
567
|
$values .= " :finished, ";
|
568
|
}
|
569
|
if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
|
570
|
$query .= " namedentity, ";
|
571
|
$values .= " :namedentity, ";
|
572
|
}
|
573
|
if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
|
574
|
$query .= " position1, ";
|
575
|
$values .= " :position1, ";
|
576
|
}
|
577
|
if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
|
578
|
$query .= " position2, ";
|
579
|
$values .= " :position2, ";
|
580
|
}
|
581
|
if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
|
582
|
$query .= " positiondetail, ";
|
583
|
$values .= " :positiondetail, ";
|
584
|
}
|
585
|
if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
|
586
|
$query .= " prefix, ";
|
587
|
$values .= " :prefix, ";
|
588
|
}
|
589
|
if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
|
590
|
$query .= " suffix, ";
|
591
|
$values .= " :suffix, ";
|
592
|
}
|
593
|
if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
|
594
|
$query .= " word, ";
|
595
|
$values .= " :word, ";
|
596
|
}
|
597
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
598
|
$query .= " lemma_id, ";
|
599
|
$values .= " :lemma_id, ";
|
600
|
}
|
601
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
602
|
$query .= " tag_id ) ";
|
603
|
$values .= " :tag_id ); ";
|
604
|
}
|
605
|
|
606
|
$query .= $values;
|
607
|
$this->stmt = $this->pdo->prepare($query);
|
608
|
|
609
|
if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
|
610
|
$this->stmt->bindParam(':context', $_POST['context'], PDO::PARAM_STR);
|
611
|
}
|
612
|
if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
|
613
|
$this->stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);
|
614
|
}
|
615
|
if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
|
616
|
$this->stmt->bindParam(':description2', $_POST['description2'], PDO::PARAM_STR);
|
617
|
}
|
618
|
if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
|
619
|
$this->stmt->bindParam(':description3', $_POST['description3'], PDO::PARAM_STR);
|
620
|
}
|
621
|
if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
|
622
|
$this->stmt->bindParam(':ending', $_POST['ending'], PDO::PARAM_STR);
|
623
|
}
|
624
|
if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
|
625
|
$this->stmt->bindParam(':finished', $_POST['finished']);
|
626
|
}
|
627
|
if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
|
628
|
$this->stmt->bindParam(':namedentity', $_POST['namedentity'], PDO::PARAM_INT);
|
629
|
}
|
630
|
if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
|
631
|
$this->stmt->bindParam(':position1', $_POST['position1'], PDO::PARAM_STR);
|
632
|
}
|
633
|
if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
|
634
|
$this->stmt->bindParam(':position2', $_POST['position2'], PDO::PARAM_STR);
|
635
|
}
|
636
|
if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
|
637
|
$this->stmt->bindParam(':positiondetail', $_POST['positiondetail'], PDO::PARAM_STR);
|
638
|
}
|
639
|
if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
|
640
|
$this->stmt->bindParam(':prefix', $_POST['prefix'], PDO::PARAM_STR);
|
641
|
}
|
642
|
if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
|
643
|
$this->stmt->bindParam(':suffix', $_POST['suffix'], PDO::PARAM_STR);
|
644
|
}
|
645
|
if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
|
646
|
$this->stmt->bindParam(':word', $_POST['word'], PDO::PARAM_STR);
|
647
|
}
|
648
|
if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
|
649
|
$this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
|
650
|
}
|
651
|
if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
|
652
|
$this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
|
653
|
}
|
654
|
|
655
|
$this->stmt->execute();
|
656
|
|
657
|
|
658
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
659
|
|
660
|
$to_insert = array_map('intval', explode(',', $_POST['manuscript']));
|
661
|
foreach ($to_insert as $id_to_insert){
|
662
|
$query = "INSERT INTO dd_manuscript VALUES ( ";
|
663
|
$query .= " :wordform_id , ";
|
664
|
$query .= " " . $id_to_insert . " ); ";
|
665
|
|
666
|
$this->stmt = $this->pdo->prepare($query);
|
667
|
$this->stmt->bindParam(':wordform_id', $result[0]["max"], PDO::PARAM_INT);
|
668
|
$this->stmt->execute();
|
669
|
}
|
670
|
}
|
671
|
|
672
|
|
673
|
function remove(){
|
674
|
$query = "SELECT lemma_id FROM dd_wordform
|
675
|
WHERE id = :id;";
|
676
|
$this->stmt = $this->pdo->prepare($query);
|
677
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
678
|
$this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_STR);
|
679
|
}
|
680
|
$this->stmt->execute();
|
681
|
$lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
682
|
|
683
|
$query = "SELECT tag_id FROM dd_wordform
|
684
|
WHERE id = :id;";
|
685
|
$this->stmt = $this->pdo->prepare($query);
|
686
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
687
|
$this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_STR);
|
688
|
}
|
689
|
$this->stmt->execute();
|
690
|
$tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
691
|
|
692
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
693
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
694
|
$query = "DELETE FROM dd_manuscript WHERE";
|
695
|
$query .= " wordform_id = :wordform_id ;";
|
696
|
$this->stmt = $this->pdo->prepare($query);
|
697
|
$this->stmt->bindParam(':wordform_id', $_POST['id'], PDO::PARAM_INT);
|
698
|
$this->stmt->execute();
|
699
|
}
|
700
|
|
701
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
702
|
if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
|
703
|
$query = "DELETE FROM dd_wordform WHERE";
|
704
|
$query .= " id = :id ;";
|
705
|
$this->stmt = $this->pdo->prepare($query);
|
706
|
$this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
|
707
|
$this->stmt->execute();
|
708
|
}
|
709
|
|
710
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
711
|
$query = "SELECT id FROM dd_wordform WHERE lemma_id = :lemma_id;";
|
712
|
$this->stmt = $this->pdo->prepare($query);
|
713
|
$this->stmt->bindParam(':lemma_id', $lemma["lemma_id"], PDO::PARAM_INT);
|
714
|
$this->stmt->execute();
|
715
|
$result = $this->stmt->fetchAll();
|
716
|
if(sizeof($result)==0){
|
717
|
$query = "DELETE FROM dd_lemma WHERE";
|
718
|
$query .= " id = :lemma_id ;";
|
719
|
$this->stmt = $this->pdo->prepare($query);
|
720
|
$this->stmt->bindParam(':lemma_id', $lemma["lemma_id"], PDO::PARAM_INT);
|
721
|
$this->stmt->execute();
|
722
|
}
|
723
|
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
724
|
$query = "SELECT id FROM dd_wordform WHERE tag_id = :tag_id;";
|
725
|
$this->stmt = $this->pdo->prepare($query);
|
726
|
$this->stmt->bindParam(':tag_id', $tag["tag_id"], PDO::PARAM_INT);
|
727
|
$this->stmt->execute();
|
728
|
$result = $this->stmt->fetchAll();
|
729
|
if(sizeof($result)==0){
|
730
|
$query = "DELETE FROM dd_tag WHERE";
|
731
|
$query .= " id = :tag_id ;";
|
732
|
$this->stmt = $this->pdo->prepare($query);
|
733
|
$this->stmt->bindParam(':tag_id', $tag["tag_id"], PDO::PARAM_INT);
|
734
|
$this->stmt->execute();
|
735
|
}else{
|
736
|
echo "fail";
|
737
|
}
|
738
|
}
|
739
|
|
740
|
}
|
741
|
|
742
|
// (D) DATABASE SETTINGS - CHANGE TO YOUR OWN!
|
743
|
define('DB_HOST', 'localhost');
|
744
|
define('DB_NAME', 'dalimil2');
|
745
|
define('DB_CHARSET', 'utf8');
|
746
|
define('DB_USER', 'postgres');
|
747
|
define('DB_PASSWORD', 'a');
|