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