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