commit cd67c936b45996e6b09aca59b49ba6dc7881b0ae
Author: Anděl Ondřej <ondrej.andel@marbes.cz>
Date:   Mon Apr 26 11:26:53 2021 +0200

    Feature #8727: Návrh změn záznamů - klient

diff --git a/application/changes.php b/application/changes.php
new file mode 100644
index 0000000..c4e54a3
--- /dev/null
+++ b/application/changes.php
@@ -0,0 +1,42 @@
+<!doctype html>
+<?php
+    session_start();
+?>
+<html >
+<head>
+    <meta charset="utf-8">
+    <title>Dalimilova kronika</title>
+
+    <!-- css -->
+    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
+    <link rel="stylesheet" href="view/style.css?<?php echo date('l jS \of F Y h:i:s A'); ?>">
+    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
+
+    <!-- jQuery library -->
+    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
+
+    <!-- JavaScript -->
+    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
+</head>
+<body>
+<div class="container-fluid">
+    <?php include "./view/header.html" ?>
+    <?php include "./view/menu.php" ?>
+
+    <div class="row app-content">
+        <div class="col-xs-12 col-sm-12 p-4 content d-flex">
+            <?php include "./view/changesContent.php" ?>
+        </div>
+    </div>
+    <?php include "./view/footer.html" ?>
+</div>
+
+<?php include "./view/modals/removeChangeModal.html" ?>
+</body>
+</html>
+
+<!-- hide settings, this is relevant only on search page -->
+<script>
+    document.getElementById("modalSettingsHref").style.display = "none";
+</script>
diff --git a/application/model/DB.php b/application/model/DB.php
index 1abf6f2..ced4fd9 100644
--- a/application/model/DB.php
+++ b/application/model/DB.php
@@ -118,56 +118,7 @@ class DB {
         return $this->stmt->fetchAll();
     }
 
-
-
-function update(){
-    $query = "SELECT id FROM dd_lemma
-              WHERE lemma = :lemma;";
-    $this->stmt = $this->pdo->prepare($query);
-        if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-            $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
-        }
-    $this->stmt->execute();
-    $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
-
-    $query = "SELECT id FROM dd_tag
-              WHERE tag = :tag;";
-    $this->stmt = $this->pdo->prepare($query);
-        if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-            $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
-        }
-    $this->stmt->execute();
-    $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
-
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-    if($lemma == null){
-        $query = "SELECT MAX(id) FROM dd_lemma;";
-        $this->stmt = $this->pdo->prepare($query);
-        $this->stmt->execute();
-        $result = $this->stmt->fetchAll();
-        $result[0]["max"]+=1;
-
-        $query = "INSERT INTO dd_lemma ( id, ";
-        $values = "VALUES (" . $result[0]["max"] . ", ";
-            if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-                $query .= " lemma, ";
-                $values .= " :lemma, ";
-            }
-            if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
-                $query .= " pos ) ";
-                $values .= " :pos ); ";
-            }
-
-        $query .= $values;
-        $this->stmt = $this->pdo->prepare($query);
-            if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-                $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
-            }
-            if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
-                $this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
-            }
-        $this->stmt->execute();
-
+    function update(){
         $query = "SELECT id FROM dd_lemma
                   WHERE lemma = :lemma;";
         $this->stmt = $this->pdo->prepare($query);
@@ -176,59 +127,6 @@ function update(){
             }
         $this->stmt->execute();
         $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
-    }
-
-    $query = "UPDATE dd_lemma
-                 SET ";
-
-    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-        $query .= " lemma = :lemma , ";
-    }
-    if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
-        $query .= " pos = :pos  ";
-    }
-
-    $query .= "WHERE ";
-    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-        $query .= " id = :lemma_id ;";
-    }
-
-
-    $this->stmt = $this->pdo->prepare($query);
-    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-        $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
-        $this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
-    }
-    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-        $this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
-    }
-    $this->stmt->execute();
-
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-    if($tag == null){
-     $query = "SELECT MAX(id) FROM dd_tag;";
-        $this->stmt = $this->pdo->prepare($query);
-        $this->stmt->execute();
-        $result = $this->stmt->fetchAll();
-        $result[0]["max"]+=1;
-
-
-        $query = "INSERT INTO dd_tag (id, ";
-        $values = "VALUES (" . $result[0]["max"] . ", ";
-
-            if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-                $query .= " tag ) ";
-                $values .= " :tag ); ";
-            }
-
-        $query .= $values;
-        $this->stmt = $this->pdo->prepare($query);
-            if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-                $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
-            }
-        $this->stmt->execute();
 
         $query = "SELECT id FROM dd_tag
                   WHERE tag = :tag;";
@@ -238,471 +136,572 @@ function update(){
             }
         $this->stmt->execute();
         $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
-    }
-
-    $query = "UPDATE dd_tag
-                 SET ";
-
-    if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-        $query .= " tag = :tag  ";
-    }
-
-    $query .= "WHERE ";
-    if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-        $query .= " id = :tag_id ;";
-    }
-
-
-    $this->stmt = $this->pdo->prepare($query);
-    if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-        $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-        $this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
-    }
-    $this->stmt->execute();
-
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-    $query = "UPDATE dd_wordform
-                SET ";
-
-
-    if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
-        $query .= " context = :context, ";
-    }
-        $query .= " date = CURRENT_DATE,";
-
-    if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
-        $query .= " description = :description, ";
-    }
-    if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
-        $query .= " description2 = :description2, ";
-    }
-    if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
-        $query .= " description3 = :description3, ";
-    }
-    if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
-        $query .= " ending = :ending, ";
-    }
-    if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
-        $query .= " finished = :finished, ";
-    }
-    if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
-        $query .= " namedentity = :namedentity, ";
-    }
-    if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
-        $query .= " position1 = :position1, ";
-    }
-    if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
-        $query .= " position2 = :position2, ";
-    }
-    if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
-        $query .= " positiondetail = :positiondetail ,";
-    }
-    if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
-        $query .= " prefix = :prefix, ";
-    }
-    if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
-        $query .= " suffix = :suffix, ";
-    }
-    if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
-        $query .= " word = :word, ";
-    }
-    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-        $query .= " lemma_id = :lemma_id, ";
-    }
-    if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-        $query .= " tag_id = :tag_id ";
-    }
 
-    $query .= " WHERE ";
-    if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
-        $query .= " id = :id ;";
-    }
-
-    $this->stmt = $this->pdo->prepare($query);
-
-    if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
-        $this->stmt->bindParam(':context', $_POST['context'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
-        $this->stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
-        $this->stmt->bindParam(':description2', $_POST['description2'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
-        $this->stmt->bindParam(':description3', $_POST['description3'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
-        $this->stmt->bindParam(':ending', $_POST['ending'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
-        $this->stmt->bindParam(':finished', $_POST['finished']);
-    }
-    if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
-        $this->stmt->bindParam(':namedentity', $_POST['namedentity'], PDO::PARAM_INT);
-    }
-    if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
-        $this->stmt->bindParam(':position1', $_POST['position1'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
-        $this->stmt->bindParam(':position2', $_POST['position2'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
-        $this->stmt->bindParam(':positiondetail', $_POST['positiondetail'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
-        $this->stmt->bindParam(':prefix', $_POST['prefix'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
-        $this->stmt->bindParam(':suffix', $_POST['suffix'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
-        $this->stmt->bindParam(':word', $_POST['word'], PDO::PARAM_STR);
-    }
-    if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-        $this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
-    }
-    if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-        $this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
-    }
-    if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
-        $this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
-    }
-
-    $this->stmt->execute();
+        // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+        if($lemma == null){
+            $query = "SELECT MAX(id) FROM dd_lemma;";
+            $this->stmt = $this->pdo->prepare($query);
+            $this->stmt->execute();
+            $result = $this->stmt->fetchAll();
+            $result[0]["max"]+=1;
 
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+            $query = "INSERT INTO dd_lemma ( id, ";
+            $values = "VALUES (" . $result[0]["max"] . ", ";
+                if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                    $query .= " lemma, ";
+                    $values .= " :lemma, ";
+                }
+                if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
+                    $query .= " pos ) ";
+                    $values .= " :pos ); ";
+                }
 
-    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
-        $query = "SELECT * FROM dd_manuscript WHERE ";
-        $query .= " wordform_id = :wordform_id ;";
-    }
+            $query .= $values;
+            $this->stmt = $this->pdo->prepare($query);
+                if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                    $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
+                    $this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
+                }
+            $this->stmt->execute();
 
-    $this->stmt = $this->pdo->prepare($query);
-    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
-        $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
-    }
-    $this->stmt->execute();
-    $result = $this->stmt->fetchAll();
+            $query = "SELECT id FROM dd_lemma
+                      WHERE lemma = :lemma;";
+            $this->stmt = $this->pdo->prepare($query);
+                if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                    $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
+                }
+            $this->stmt->execute();
+            $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
+        }
 
-    $to_insert = [];
-    $to_delete = [];
-    $contained = [];
-    $found = false;
-    $integerIDs = [];
+        $query = "UPDATE dd_lemma
+                     SET ";
 
-    foreach ($result as $res) {
-        $integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
-        foreach ($integerIDs as $new_value){
-            if($new_value == $res['manuscript']){
-                $found = true;
-                array_push($contained, $new_value);
-            }
+        if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+            $query .= " lemma = :lemma , ";
         }
-        if($found == false){
-            array_push($to_delete, $res);
+        if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
+            $query .= " pos = :pos  ";
         }
-        $found = false;
-    }
-    $to_insert = array_diff($integerIDs, $contained);
 
-    foreach ($to_delete as $id_to_delete){
-        $query = "DELETE FROM dd_manuscript WHERE ";
-        $query .= "manuscript = " . $id_to_delete['manuscript'] . " AND ";
-        $query .= " wordform_id = :wordform_id ;";
+        $query .= "WHERE ";
+        if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+            $query .= " id = :lemma_id ;";
+        }
 
 
         $this->stmt = $this->pdo->prepare($query);
-        if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
-            $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
+        if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+            $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
+        }
+        if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
+            $this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
+        }
+        if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+            $this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
         }
-        //
         $this->stmt->execute();
-        var_dump($query);
-    }
 
-    foreach ($to_insert as $id_to_insert){
-        $query = "INSERT INTO dd_manuscript VALUES ( ";
-        $query .= " :wordform_id , ";
-        $query .= " " . $id_to_insert . " ); ";
+        // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+        if($tag == null){
+         $query = "SELECT MAX(id) FROM dd_tag;";
+            $this->stmt = $this->pdo->prepare($query);
+            $this->stmt->execute();
+            $result = $this->stmt->fetchAll();
+            $result[0]["max"]+=1;
 
-        $this->stmt = $this->pdo->prepare($query);
-        if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
-            $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
-        }
-        $this->stmt->execute();
-    }
-}
 
-function insert(){
-// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-    $query = "SELECT id FROM dd_lemma
-              WHERE lemma = :lemma;";
-    $this->stmt = $this->pdo->prepare($query);
-        if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-            $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
-        }
-    $this->stmt->execute();
-    $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
+            $query = "INSERT INTO dd_tag (id, ";
+            $values = "VALUES (" . $result[0]["max"] . ", ";
 
-    if($lemma == null){
-        $query = "SELECT MAX(id) FROM dd_lemma;";
-        $this->stmt = $this->pdo->prepare($query);
-        $this->stmt->execute();
-        $result = $this->stmt->fetchAll();
-        $result[0]["max"]+=1;
+                if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                    $query .= " tag ) ";
+                    $values .= " :tag ); ";
+                }
 
-        $query = "INSERT INTO dd_lemma ( id, ";
-        $values = "VALUES (" . $result[0]["max"] . ", ";
-            if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-                $query .= " lemma, ";
-                $values .= " :lemma, ";
-            }
-            if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
-                $query .= " pos ) ";
-                $values .= " :pos ); ";
-            }
+            $query .= $values;
+            $this->stmt = $this->pdo->prepare($query);
+                if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                    $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+                }
+            $this->stmt->execute();
 
-        $query .= $values;
-        $this->stmt = $this->pdo->prepare($query);
-            if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-                $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
-            }
-            if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
-                $this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
-            }
-        $this->stmt->execute();
-    }
+            $query = "SELECT id FROM dd_tag
+                      WHERE tag = :tag;";
+            $this->stmt = $this->pdo->prepare($query);
+                if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                    $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+                }
+            $this->stmt->execute();
+            $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
+        }
 
+        $query = "UPDATE dd_tag
+                     SET ";
 
+        if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+            $query .= " tag = :tag  ";
+        }
 
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-    $query = "SELECT id FROM dd_tag
-              WHERE tag = :tag;";
-    $this->stmt = $this->pdo->prepare($query);
+        $query .= "WHERE ";
         if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-            $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+            $query .= " id = :tag_id ;";
         }
-    $this->stmt->execute();
-    $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
 
-    if($tag == null){
-     $query = "SELECT MAX(id) FROM dd_tag;";
+
         $this->stmt = $this->pdo->prepare($query);
+        if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+            $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+        }
+        if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+            $this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
+        }
         $this->stmt->execute();
-        $result = $this->stmt->fetchAll();
-        $result[0]["max"]+=1;
 
+        // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+        $query = "UPDATE dd_wordform
+                    SET ";
 
-        $query = "INSERT INTO dd_tag (id, ";
-        $values = "VALUES (" . $result[0]["max"] . ", ";
 
-            if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-                $query .= " tag ) ";
-                $values .= " :tag ); ";
-            }
-
-        $query .= $values;
-        $this->stmt = $this->pdo->prepare($query);
-            if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-                $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
-            }
-        $this->stmt->execute();
-    }
+        if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
+            $query .= " context = :context, ";
+        }
+            $query .= " date = CURRENT_DATE,";
 
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-    $query = "SELECT MAX(id) FROM dd_wordform;";
-    $this->stmt = $this->pdo->prepare($query);
-    $this->stmt->execute();
-    $result = $this->stmt->fetchAll();
-    $result[0]["max"]+=1;
-
-    $query = "SELECT id FROM dd_lemma
-              WHERE lemma = :lemma;";
-    $this->stmt = $this->pdo->prepare($query);
+        if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
+            $query .= " description = :description, ";
+        }
+        if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
+            $query .= " description2 = :description2, ";
+        }
+        if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
+            $query .= " description3 = :description3, ";
+        }
+        if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
+            $query .= " ending = :ending, ";
+        }
+        if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
+            $query .= " finished = :finished, ";
+        }
+        if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
+            $query .= " namedentity = :namedentity, ";
+        }
+        if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
+            $query .= " position1 = :position1, ";
+        }
+        if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
+            $query .= " position2 = :position2, ";
+        }
+        if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
+            $query .= " positiondetail = :positiondetail ,";
+        }
+        if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
+            $query .= " prefix = :prefix, ";
+        }
+        if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
+            $query .= " suffix = :suffix, ";
+        }
+        if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
+            $query .= " word = :word, ";
+        }
         if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-            $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
+            $query .= " lemma_id = :lemma_id, ";
         }
-    $this->stmt->execute();
-    $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
-
-    $query = "SELECT id FROM dd_tag
-              WHERE tag = :tag;";
-    $this->stmt = $this->pdo->prepare($query);
         if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-            $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+            $query .= " tag_id = :tag_id ";
         }
-    $this->stmt->execute();
-    $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
-
-    $query = "INSERT INTO dd_wordform ( id, ";
-    $values = "VALUES (" . $result[0]["max"] . ", ";
 
-     if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
-            $query .= " context, ";
-            $values .= " :context, ";
+        $query .= " WHERE ";
+        if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
+            $query .= " id = :id ;";
         }
-            $query .= " date, ";
-            $values .=  " CURRENT_DATE, ";
 
+        $this->stmt = $this->pdo->prepare($query);
+
+        if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
+            $this->stmt->bindParam(':context', $_POST['context'], PDO::PARAM_STR);
+        }
         if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
-            $query .= " description, ";
-            $values .= " :description, ";
+            $this->stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);
         }
         if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
-            $query .= " description2, ";
-            $values .= " :description2, ";
+            $this->stmt->bindParam(':description2', $_POST['description2'], PDO::PARAM_STR);
         }
         if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
-            $query .= " description3, ";
-            $values .= " :description3, ";
+            $this->stmt->bindParam(':description3', $_POST['description3'], PDO::PARAM_STR);
         }
         if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
-            $query .= " ending, ";
-            $values .= " :ending, ";
+            $this->stmt->bindParam(':ending', $_POST['ending'], PDO::PARAM_STR);
         }
         if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
-            $query .= " finished, ";
-            $values .= " :finished, ";
+            $this->stmt->bindParam(':finished', $_POST['finished']);
         }
         if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
-            $query .= " namedentity, ";
-            $values .= " :namedentity, ";
+            $this->stmt->bindParam(':namedentity', $_POST['namedentity'], PDO::PARAM_INT);
         }
         if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
-            $query .= " position1, ";
-            $values .= " :position1, ";
+            $this->stmt->bindParam(':position1', $_POST['position1'], PDO::PARAM_STR);
         }
         if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
-            $query .= " position2, ";
-            $values .= " :position2, ";
+            $this->stmt->bindParam(':position2', $_POST['position2'], PDO::PARAM_STR);
         }
         if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
-            $query .= " positiondetail, ";
-            $values .= " :positiondetail, ";
+            $this->stmt->bindParam(':positiondetail', $_POST['positiondetail'], PDO::PARAM_STR);
         }
         if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
-            $query .= " prefix, ";
-            $values .= " :prefix, ";
+            $this->stmt->bindParam(':prefix', $_POST['prefix'], PDO::PARAM_STR);
         }
         if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
-            $query .= " suffix, ";
-            $values .= " :suffix, ";
+            $this->stmt->bindParam(':suffix', $_POST['suffix'], PDO::PARAM_STR);
         }
         if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
-            $query .= " word, ";
-            $values .= " :word, ";
+            $this->stmt->bindParam(':word', $_POST['word'], PDO::PARAM_STR);
         }
         if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-            $query .= " lemma_id, ";
-            $values .= " :lemma_id, ";
+            $this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
         }
         if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-            $query .= " tag_id ) ";
-            $values .= " :tag_id ); ";
+            $this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
+        }
+        if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
+            $this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
+        }
+
+        $this->stmt->execute();
+
+        // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+
+        if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
+            $query = "SELECT * FROM dd_manuscript WHERE ";
+            $query .= " wordform_id = :wordform_id ;";
+        }
+
+        $this->stmt = $this->pdo->prepare($query);
+        if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
+            $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
+        }
+        $this->stmt->execute();
+        $result = $this->stmt->fetchAll();
+
+        $to_insert = [];
+        $to_delete = [];
+        $contained = [];
+        $found = false;
+        $integerIDs = [];
+
+        foreach ($result as $res) {
+            $integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
+            foreach ($integerIDs as $new_value){
+                if($new_value == $res['manuscript']){
+                    $found = true;
+                    array_push($contained, $new_value);
+                }
+            }
+            if($found == false){
+                array_push($to_delete, $res);
+            }
+            $found = false;
+        }
+        $to_insert = array_diff($integerIDs, $contained);
+
+        foreach ($to_delete as $id_to_delete){
+            $query = "DELETE FROM dd_manuscript WHERE ";
+            $query .= "manuscript = " . $id_to_delete['manuscript'] . " AND ";
+            $query .= " wordform_id = :wordform_id ;";
+
+
+            $this->stmt = $this->pdo->prepare($query);
+            if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
+                $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
+            }
+            //
+            $this->stmt->execute();
+            var_dump($query);
+        }
+
+        foreach ($to_insert as $id_to_insert){
+            $query = "INSERT INTO dd_manuscript VALUES ( ";
+            $query .= " :wordform_id , ";
+            $query .= " " . $id_to_insert . " ); ";
+
+            $this->stmt = $this->pdo->prepare($query);
+            if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
+                $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
+            }
+            $this->stmt->execute();
+        }
+    }
+
+    function insert(){
+      print_r($_POST);
+    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+        $query = "SELECT id FROM dd_lemma
+                  WHERE lemma = :lemma;";
+        $this->stmt = $this->pdo->prepare($query);
+            if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
+            }
+        $this->stmt->execute();
+        $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
+
+        if($lemma == null){
+            $query = "SELECT MAX(id) FROM dd_lemma;";
+            $this->stmt = $this->pdo->prepare($query);
+            $this->stmt->execute();
+            $result = $this->stmt->fetchAll();
+            $result[0]["max"]+=1;
+
+            $query = "INSERT INTO dd_lemma ( id, ";
+            $values = "VALUES (" . $result[0]["max"] . ", ";
+                if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                    $query .= " lemma, ";
+                    $values .= " :lemma, ";
+                }
+                if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
+                    $query .= " pos ) ";
+                    $values .= " :pos ); ";
+                }
+
+            $query .= $values;
+            $this->stmt = $this->pdo->prepare($query);
+                if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                    $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("pos", $_POST) && $_POST['pos'] != "") {
+                    $this->stmt->bindParam(':pos', $_POST['pos'], PDO::PARAM_INT);
+                }
+            $this->stmt->execute();
+        }
+
+
+
+        // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+        $query = "SELECT id FROM dd_tag
+                  WHERE tag = :tag;";
+        $this->stmt = $this->pdo->prepare($query);
+            if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+            }
+        $this->stmt->execute();
+        $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
+
+        if($tag == null){
+         $query = "SELECT MAX(id) FROM dd_tag;";
+            $this->stmt = $this->pdo->prepare($query);
+            $this->stmt->execute();
+            $result = $this->stmt->fetchAll();
+            $result[0]["max"]+=1;
+
+
+            $query = "INSERT INTO dd_tag (id, ";
+            $values = "VALUES (" . $result[0]["max"] . ", ";
+
+                if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                    $query .= " tag ) ";
+                    $values .= " :tag ); ";
+                }
+
+            $query .= $values;
+            $this->stmt = $this->pdo->prepare($query);
+                if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                    $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+                }
+            $this->stmt->execute();
         }
 
-        $query .= $values;
+        // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+        $query = "SELECT MAX(id) FROM dd_wordform;";
         $this->stmt = $this->pdo->prepare($query);
+        $this->stmt->execute();
+        $result = $this->stmt->fetchAll();
+        $result[0]["max"]+=1;
 
-            if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
-                $this->stmt->bindParam(':context', $_POST['context'], PDO::PARAM_STR);
+        $query = "SELECT id FROM dd_lemma
+                  WHERE lemma = :lemma;";
+        $this->stmt = $this->pdo->prepare($query);
+            if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                $this->stmt->bindParam(':lemma', $_POST['lemma'], PDO::PARAM_STR);
             }
+        $this->stmt->execute();
+        $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
+
+        $query = "SELECT id FROM dd_tag
+                  WHERE tag = :tag;";
+        $this->stmt = $this->pdo->prepare($query);
+            if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                $this->stmt->bindParam(':tag', $_POST['tag'], PDO::PARAM_STR);
+            }
+        $this->stmt->execute();
+        $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
+
+        $query = "INSERT INTO dd_wordform ( id, ";
+        $values = "VALUES (" . $result[0]["max"] . ", ";
+
+         if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
+                $query .= " context, ";
+                $values .= " :context, ";
+            }
+                $query .= " date, ";
+                $values .=  " CURRENT_DATE, ";
+
             if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
-                $this->stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);
+                $query .= " description, ";
+                $values .= " :description, ";
             }
             if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
-                $this->stmt->bindParam(':description2', $_POST['description2'], PDO::PARAM_STR);
+                $query .= " description2, ";
+                $values .= " :description2, ";
             }
             if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
-                $this->stmt->bindParam(':description3', $_POST['description3'], PDO::PARAM_STR);
+                $query .= " description3, ";
+                $values .= " :description3, ";
             }
             if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
-                $this->stmt->bindParam(':ending', $_POST['ending'], PDO::PARAM_STR);
+                $query .= " ending, ";
+                $values .= " :ending, ";
             }
             if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
-                $this->stmt->bindParam(':finished', $_POST['finished']);
+                $query .= " finished, ";
+                $values .= " :finished, ";
             }
             if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
-                $this->stmt->bindParam(':namedentity', $_POST['namedentity'], PDO::PARAM_INT);
+                $query .= " namedentity, ";
+                $values .= " :namedentity, ";
             }
             if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
-                $this->stmt->bindParam(':position1', $_POST['position1'], PDO::PARAM_STR);
+                $query .= " position1, ";
+                $values .= " :position1, ";
             }
             if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
-                $this->stmt->bindParam(':position2', $_POST['position2'], PDO::PARAM_STR);
+                $query .= " position2, ";
+                $values .= " :position2, ";
             }
             if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
-                $this->stmt->bindParam(':positiondetail', $_POST['positiondetail'], PDO::PARAM_STR);
+                $query .= " positiondetail, ";
+                $values .= " :positiondetail, ";
             }
             if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
-                $this->stmt->bindParam(':prefix', $_POST['prefix'], PDO::PARAM_STR);
+                $query .= " prefix, ";
+                $values .= " :prefix, ";
             }
             if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
-                $this->stmt->bindParam(':suffix', $_POST['suffix'], PDO::PARAM_STR);
+                $query .= " suffix, ";
+                $values .= " :suffix, ";
             }
             if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
-                $this->stmt->bindParam(':word', $_POST['word'], PDO::PARAM_STR);
+                $query .= " word, ";
+                $values .= " :word, ";
             }
             if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
-                $this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
+                $query .= " lemma_id, ";
+                $values .= " :lemma_id, ";
             }
             if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
-                $this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
+                $query .= " tag_id ) ";
+                $values .= " :tag_id ); ";
             }
 
-            $this->stmt->execute();
+            $query .= $values;
+            $this->stmt = $this->pdo->prepare($query);
 
+                if (array_key_exists("context", $_POST) && $_POST['context'] != "") {
+                    $this->stmt->bindParam(':context', $_POST['context'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("description", $_POST) && $_POST['description'] != "") {
+                    $this->stmt->bindParam(':description', $_POST['description'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("description2", $_POST) && $_POST['description2'] != "") {
+                    $this->stmt->bindParam(':description2', $_POST['description2'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("description3", $_POST) && $_POST['description3'] != "") {
+                    $this->stmt->bindParam(':description3', $_POST['description3'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("ending", $_POST) && $_POST['ending'] != "") {
+                    $this->stmt->bindParam(':ending', $_POST['ending'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("finished", $_POST) && $_POST['finished'] != "") {
+                    $this->stmt->bindParam(':finished', $_POST['finished']);
+                }
+                if (array_key_exists("namedentity", $_POST) && $_POST['namedentity'] != "") {
+                    $this->stmt->bindParam(':namedentity', $_POST['namedentity'], PDO::PARAM_INT);
+                }
+                if (array_key_exists("position1", $_POST) && $_POST['position1'] != "") {
+                    $this->stmt->bindParam(':position1', $_POST['position1'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("position2", $_POST) && $_POST['position2'] != "") {
+                    $this->stmt->bindParam(':position2', $_POST['position2'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("positiondetail", $_POST) && $_POST['positiondetail'] != "") {
+                    $this->stmt->bindParam(':positiondetail', $_POST['positiondetail'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("prefix", $_POST) && $_POST['prefix'] != "") {
+                    $this->stmt->bindParam(':prefix', $_POST['prefix'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("suffix", $_POST) && $_POST['suffix'] != "") {
+                    $this->stmt->bindParam(':suffix', $_POST['suffix'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("word", $_POST) && $_POST['word'] != "") {
+                    $this->stmt->bindParam(':word', $_POST['word'], PDO::PARAM_STR);
+                }
+                if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+                    $this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
+                }
+                if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+                    $this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
+                }
 
-// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+                $this->stmt->execute();
 
-    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
-        $query = "SELECT * FROM dd_manuscript WHERE ";
-        $query .= " wordform_id = :wordform_id ;";
 
-        $this->stmt = $this->pdo->prepare($query);
-            if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
-                $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
-            }
-            $this->stmt->execute();
-            $result = $this->stmt->fetchAll();
+    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
-            $to_insert = [];
-            $contained = [];
-            $found = false;
-            $integerIDs = [];
-
-            foreach ($result as $res) {
-                $integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
-                foreach ($integerIDs as $new_value){
-                    if($new_value == $res['manuscript']){
-                        $found = true;
-                        array_push($contained, $new_value);
-                    }
-                }
-                if($found == false){
-                    array_push($to_delete, $res);
-                }
-                $found = false;
-            }
-            $to_insert = array_diff($integerIDs, $contained);
-            foreach ($to_insert as $id_to_insert){
-                $query = "INSERT INTO dd_manuscript VALUES ( ";
-                $query .= " :wordform_id , ";
-                $query .= " " . $id_to_insert . " ); ";
+        if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
+            $query = "SELECT * FROM dd_manuscript WHERE ";
+            $query .= " wordform_id = :wordform_id ;";
 
-                $this->stmt = $this->pdo->prepare($query);
+            $this->stmt = $this->pdo->prepare($query);
                 if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
                     $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
                 }
                 $this->stmt->execute();
-            }
-    }
+                $result = $this->stmt->fetchAll();
+
+                $to_insert = [];
+                $contained = [];
+                $found = false;
+                $integerIDs = [];
+
+                foreach ($result as $res) {
+                    $integerIDs = array_map('intval', explode(',', $_POST['manuscript']));
+                    foreach ($integerIDs as $new_value){
+                        if($new_value == $res['manuscript']){
+                            $found = true;
+                            array_push($contained, $new_value);
+                        }
+                    }
+                    if($found == false){
+                        array_push($to_delete, $res);
+                    }
+                    $found = false;
+                }
+                $to_insert = array_diff($integerIDs, $contained);
+                foreach ($to_insert as $id_to_insert){
+                    $query = "INSERT INTO dd_manuscript VALUES ( ";
+                    $query .= " :wordform_id , ";
+                    $query .= " " . $id_to_insert . " ); ";
+
+                    $this->stmt = $this->pdo->prepare($query);
+                    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
+                        $this->stmt->bindParam(':wordform_id', $_POST['wordform_id'], PDO::PARAM_INT);
+                    }
+                    $this->stmt->execute();
+                }
+        }
 
 
-}
+    }
 
 
 }
diff --git a/application/search.php b/application/search.php
index f9b7535..f512b29 100644
--- a/application/search.php
+++ b/application/search.php
@@ -37,7 +37,13 @@
 <?php include "./view/modals/invalidLoginModal.html" ?>
 <?php include "./view/modals/detailModal.html" ?>
 <?php include "./view/modals/settingsModal.html" ?>
-<?php include "./view/modals/editModal.html" ?>
 <?php include "./view/modals/removeModal.html" ?>
+<?php
+if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true){
+    include "./view/modals/editModal.html";
+}else{
+    include "./view/modals/addChangeModal.html";
+}
+?>
 </body>
 </html>
diff --git a/application/view/changesContent.php b/application/view/changesContent.php
new file mode 100644
index 0000000..5cf288d
--- /dev/null
+++ b/application/view/changesContent.php
@@ -0,0 +1,70 @@
+<?php
+if (isset($_SESSION['role']) && $_SESSION['role'] == "admin") {
+    echo "<script>
+        //what to do when page renders
+        window.onload = function() {
+            fetchChanges();
+        };
+    </script>
+
+    <div class=\"search-results my-4\">
+        <table class=\"table table-striped\">
+            <thead>
+            <tr>
+                <th scope=\"col\">Lemma</th>
+                <th scope=\"col\">Slovní tvar</th>
+                <th scope=\"col\">Návrh změny</th>
+                <th scope=\"col\"></th>
+            </tr>
+            </thead>
+            <tbody id=\"search-table\">
+                <script>
+                    let changes;
+                    function fetchChanges () {
+                        // (A1) GET SEARCH TERM
+                        const formData = new FormData();
+
+                        // (A2) AJAX - USE HTTP:// NOT FILE:/
+                        let xhr = new XMLHttpRequest();
+                        xhr.open(\"POST\", \"./controller/GetChangeRequests.php\");
+                        xhr.onload = function(){
+                            let search = this.response;
+                            let parsedJSON = JSON.parse(search);
+                            changes = parsedJSON;
+                            renderChanges(parsedJSON);
+                        };
+                        xhr.send(formData);
+                    }
+
+
+                    function renderChanges(changesList) {
+                        let result = \"\";
+                        if(changesList !== null){
+                            changesList.forEach((item,id) => {
+                                result +=\" <tr>\";
+                                result += \" <td>\" + item.lemma + \" </td> \";
+                                result += \" <td>\" + item.word + \" </td> \";
+                                result += \" <td>\" + item.message + \" <td>\";
+                                result += \" <td class='action-td'> \" +
+                                    \" <button class='btn ml-1' title = 'Odstranit'  data-toggle = 'modal' data-target = '#remove-modal' data-pseudo-id = '\" + id + \"' ><i class='fa fa-trash' ></i ></button > \" +
+                                    \" </td>\";
+                                result += \" </tr> \";
+                            });
+                            document.getElementById(\"search-table\").innerHTML = result;                            
+                            document.getElementById(\"no-data-label\").style.display = \"none\";
+                        } else {
+                            document.getElementById(\"search-table\").innerHTML = result;   
+                            document.getElementById(\"no-data-label\").style.display = \"\";
+                        }
+                    }
+                </script>
+            </tbody>
+        </table>
+        
+        <h3 id=\"no-data-label\" class=\"mx-auto text-center font-italic\">Žádná data nebyla nalezena</h3>
+    </div>";
+} else {
+    echo "<h3 class=\"mx-auto text-center\">Pro navštívení stránky nemáte dostatečná oprávnění</h3>";
+}
+
+
diff --git a/application/view/menu.php b/application/view/menu.php
index 6e742a9..f5e078b 100644
--- a/application/view/menu.php
+++ b/application/view/menu.php
@@ -3,27 +3,35 @@
         <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'], '/index.php') ? 'active' : '');?>" href="index.php">Úvodní info</a>
         <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'],'/search.php') ? 'active' : '');?>" href="search.php">Vyhledávání</a>
         <a class="px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'],'/manual.php') ? 'active' : '');?>" href="manual.php">Manuál</a>
-        <!-- show login button when user logged out OR show logout button when user logged in - START -->
-        <?php
-            if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true){
-                echo "<a class=\" px-4 py-1 ";
-                echo (strstr($_SERVER['PHP_SELF'],'/login.php') ? 'active\"' : '\"');
-                echo "href=\"#\" onclick=\"logout()\">Odhlášení</a>";
-            }else{
-                echo "<a class=\" px-4 py-1 ";
-                echo (strstr($_SERVER['PHP_SELF'],'/login.php') ? 'active\"' : '\"');
-                echo "href=\"#\" data-toggle=\"modal\" data-target=\"#login-modal\">Přihlášení</a>";
-            }
-        ?>
-        <!-- show login button when user logged out OR show logout button when user logged in - END -->
         <?php
             if (isset($_SESSION['role']) && $_SESSION['role'] == "admin") {
                 echo "<a class=\" px-4 py-1 ";
-                echo (strstr($_SERVER['PHP_SELF'],'/users.php') ? 'active\"' : '\"');
+                echo (strstr($_SERVER['PHP_SELF'],'/users.php') ? 'active \"' : '\"');
                 echo "href=\"users.php\">Správa uživatelů</a>";
             }
         ?>
+        <?php
+        if (isset($_SESSION['role']) && $_SESSION['role'] == "admin") {
+            echo "<a class=\" px-4 py-1 ";
+            echo (strstr($_SERVER['PHP_SELF'],'/changes.php') ? 'active \"' : '\"');
+            echo "href=\"changes.php\">Správa změn</a>";
+        }
+        ?>
         <a class="my-auto px-4 py-1 <?php echo (strstr($_SERVER['PHP_SELF'],'/settings.php') ? 'active' : '');?>" href="#" data-toggle="modal" data-target="#settings-modal" id="modalSettingsHref">Nastavení</a>
+
+        <!-- show login button when user logged out OR show logout button when user logged in - START -->
+        <?php
+        if(isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] == true){
+            echo "<a class=\" px-4 py-1 ";
+            echo (strstr($_SERVER['PHP_SELF'],'/login.php') ? 'active\"' : '\"');
+            echo "href=\"#\" onclick=\"logout()\">Odhlášení</a>";
+        }else{
+            echo "<a class=\" px-4 py-1 ";
+            echo (strstr($_SERVER['PHP_SELF'],'/login.php') ? 'active\"' : '\"');
+            echo "href=\"#\" data-toggle=\"modal\" data-target=\"#login-modal\">Přihlášení</a>";
+        }
+        ?>
+        <!-- show login button when user logged out OR show logout button when user logged in - END -->
     </div>
 </div>
 
diff --git a/application/view/modals/addChangeModal.html b/application/view/modals/addChangeModal.html
new file mode 100644
index 0000000..3be3e21
--- /dev/null
+++ b/application/view/modals/addChangeModal.html
@@ -0,0 +1,66 @@
+<div id="edit-modal" class="modal fade" role="dialog">
+    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h4 class="modal-title">Navrhnout změny</h4>
+                <button type="button" class="close" data-dismiss="modal">&times;</button>
+            </div>
+            <div class="modal-body">
+                <div class="container">
+                    <div class="row my-1" id="password-wrapper">
+                        <div class="col-xs-12 col-sm-4">
+                            <label for="changeIdea">Návrh změn: <b class="required">*</b></label>
+                        </div>
+                        <div class="col-xs-12 col-sm-8">
+                            <textarea class="min-wdth" id="changeIdea"></textarea>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" id="submit-but" class="btn btn-default" data-dismiss="modal">Založit</button>
+                <button type="button" class="btn btn-default" data-dismiss="modal">Zavřít</button>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    $('#edit-modal').on('show.bs.modal', function (event) {
+        const button = $(event.relatedTarget);
+        const pseudo_id = button.data('pseudo-id');// Extract info from data-* attributes
+        const title = button.data('title');// Extract info from data-* attributes
+
+        let modal = $(this);
+
+        prefill(modal);
+        modal.find('#submit-but').click(() => createChange(modal, pseudo_id));
+
+        enableSubmit(modal);
+        modal.find("#changeIdea").change(() => enableSubmit(modal, true));
+    });
+
+    function enableSubmit(modal){
+        if(modal.find("#changeIdea")[0].value === ""){
+            modal.find("#submit-but").prop( "disabled", true );
+        } else {
+            modal.find("#submit-but").prop( "disabled", false );
+        }
+    }
+
+    function prefill(modal, data = null){
+        modal.find("#changeIdea").val("");
+    }
+
+
+    function createChange(modal, pseudo_id){
+        const formData = new FormData();
+        const changeIdea = modal.find("#changeIdea")[0].value;
+        formData.append("message", changeIdea);
+        formData.append("wordform_id", data[pseudo_id].id);
+
+        var xhr = new XMLHttpRequest();
+        xhr.open("POST", "./controller/CreateChangeRequestController.php");
+        xhr.send(formData);
+    }
+</script>
\ No newline at end of file
diff --git a/application/view/modals/removeChangeModal.html b/application/view/modals/removeChangeModal.html
new file mode 100644
index 0000000..ddb15a9
--- /dev/null
+++ b/application/view/modals/removeChangeModal.html
@@ -0,0 +1,47 @@
+<div id="remove-modal" class="modal fade" role="dialog">
+	<div class="modal-dialog modal-dialog-centered" role="document">
+		<div class="modal-content">
+			 <div class="modal-header">
+					<h4 class="modal-title">Potvrdit odstranění</h4>
+					<button type="button" class="close" data-dismiss="modal">&times;</button>
+			 </div>
+			 <div class="modal-body">
+				<div class="container">
+					<div class="row">
+                        <p id="mesBody"></p>
+                    </div>
+				</div>
+			 </div>
+			 <div class="modal-footer">
+                <button type="button" class="btn btn-default" data-dismiss="modal" onclick="removeChange(document.getElementById('idToRemoveInput').value)">Ano</button>
+                <button type="button" class="btn btn-default" data-dismiss="modal">Ne</button>
+				<input type="hidden" id="idToRemoveInput" />
+			</div>
+		</div>
+	</div>
+</div>
+
+<script>
+    $('#remove-modal').on('show.bs.modal', function (event){ //wait for modal to show 
+        const button = $(event.relatedTarget);
+        const pseudo_id = button.data('pseudo-id');//Extract info from data-* attributes
+
+        const data_obj = changes[pseudo_id];
+        let modal = $(this);
+		console.log(data_obj);
+		modal.find('#mesBody').text("Opravdu chcete odstranit návrh změny?");
+		modal.find('#idToRemoveInput').val(data_obj.changeid); //assign id to delete to hidden input
+    });
+
+	function removeChange(id){
+		const data = new FormData(); //to pass ids, which we want to delete from DB
+		data.append("requestId", ""+id); //id to delete from table dd_wordform
+
+		let xhr = new XMLHttpRequest();
+		xhr.open("POST", "./controller/RemoveChangeRequest.php");
+		xhr.send(data);
+		setTimeout(function(){
+			fetchChanges(); //reload data after item delete
+		}, 500);
+	}
+</script>
\ No newline at end of file
diff --git a/application/view/style.css b/application/view/style.css
index af46041..307c683 100644
--- a/application/view/style.css
+++ b/application/view/style.css
@@ -98,7 +98,7 @@ html, body, .container-fluid {
   width: 13%;
 }
 
-input, select {
+input, select, textarea {
   height: 90%;
   border-radius: 5px;
   border: 1px solid grey;
@@ -108,6 +108,11 @@ input, select {
   padding: 6px 12px;
 }
 
+textarea {
+  width: 100%;
+  resize: none;
+}
+
 .min-wdth {
   min-width: 200px;
 }
