commit 53a9c7e2f2dff13d1a0a02509b95b69f6cdb6c86
Author: Milan Vacek <vacekm@students.zcu.cz>
Date:   Tue Apr 27 17:25:26 2021 +0200

    Enhancement #8640 Testování a oprava jednotlivých funkcionalit aplikace

diff --git a/application/index.php b/application/index.php
index eeb16cb..bfe6378 100644
--- a/application/index.php
+++ b/application/index.php
@@ -51,7 +51,6 @@ session_start();
         xhr.open("POST", "controller/LogoutController.php");
         xhr.onload = function(){
             let search = JSON.parse(this.response);
-            console.log(search);
         };
         xhr.send(data);
         return false;
diff --git a/application/model/DB.php b/application/model/DB.php
index 793950d..16329ed 100644
--- a/application/model/DB.php
+++ b/application/model/DB.php
@@ -61,6 +61,7 @@ class DB {
             }
             $this->stmt->execute();
             $result = $this->stmt->fetchAll();
+            //print_r($result);
             return $result;
         } catch (Exception $ex) {
             $this->error = $ex->getMessage();
@@ -357,14 +358,14 @@ function update(){
 
     // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 
-    if (array_key_exists("wordform_id", $_POST) && $_POST['wordform_id'] != "") {
+        if (array_key_exists("id", $_POST) && $_POST['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);
+        if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
+            $this->stmt->bindParam(':wordform_id', $_POST['id']);
     }
     $this->stmt->execute();
     $result = $this->stmt->fetchAll();
@@ -397,8 +398,8 @@ function update(){
 
 
         $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("id", $_POST) && $_POST['id'] != "") {
+                $this->stmt->bindParam(':wordform_id', $_POST['id'], PDO::PARAM_INT);
         }
         //
         $this->stmt->execute();
@@ -411,8 +412,8 @@ function update(){
         $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);
+            if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
+                $this->stmt->bindParam(':wordform_id', $_POST['id'], PDO::PARAM_INT);
         }
         $this->stmt->execute();
     }
@@ -640,53 +641,38 @@ function insert(){
 
 // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 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 = [];
-            $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);
+                $to_insert = array_map('intval', explode(',', $_POST['manuscript']));
             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->bindParam(':wordform_id', $result[0]["max"], PDO::PARAM_INT);
                 $this->stmt->execute();
             }
     }
 
 
-}
-
 function remove(){
+        $query = "SELECT lemma_id FROM dd_wordform
+                WHERE id = :id;";
+        $this->stmt = $this->pdo->prepare($query);
+        if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
+            $this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_STR);
+        }
+        $this->stmt->execute();
+        $lemma = $this->stmt->fetch(PDO::FETCH_ASSOC);
+
+        $query = "SELECT tag_id FROM dd_wordform
+                WHERE id = :id;";
+        $this->stmt = $this->pdo->prepare($query);
+        if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
+            $this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_STR);
+        }
+        $this->stmt->execute();
+        $tag = $this->stmt->fetch(PDO::FETCH_ASSOC);
+
     // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_manuscript |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
     if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
         $query = "DELETE FROM dd_manuscript WHERE";
@@ -696,32 +682,42 @@ function remove(){
         $this->stmt->execute();
     }
 
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+    if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
+        $query = "DELETE FROM dd_wordform WHERE";
+        $query .= " id = :id ;";
+        $this->stmt = $this->pdo->prepare($query);
+        $this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
+        $this->stmt->execute();
+    }
 
-        /*if (array_key_exists("lemma", $_POST) && $_POST['lemma'] != "") {
+    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_lemma |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+        $query = "SELECT id FROM dd_wordform WHERE lemma_id = :lemma_id;";
+        $this->stmt = $this->pdo->prepare($query);
+        $this->stmt->bindParam(':lemma_id', $lemma["lemma_id"], PDO::PARAM_INT);
+        $this->stmt->execute();
+        $result = $this->stmt->fetchAll();
+        if(sizeof($result)==0){
             $query = "DELETE FROM dd_lemma WHERE";
             $query .= " id = :lemma_id ;";
             $this->stmt = $this->pdo->prepare($query);
-            $this->stmt->bindParam(':lemma_id', $lemma["id"], PDO::PARAM_INT);
+            $this->stmt->bindParam(':lemma_id', $lemma["lemma_id"], PDO::PARAM_INT);
             $this->stmt->execute();
-        } TODO: fix lemma*/
+        }
     // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_tag |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-
-        /*if (array_key_exists("tag", $_POST) && $_POST['tag'] != "") {
+        $query = "SELECT id FROM dd_wordform WHERE tag_id = :tag_id;";
+        $this->stmt = $this->pdo->prepare($query);
+        $this->stmt->bindParam(':tag_id', $tag["tag_id"], PDO::PARAM_INT);
+        $this->stmt->execute();
+        $result = $this->stmt->fetchAll();
+        if(sizeof($result)==0){
             $query = "DELETE FROM dd_tag WHERE";
             $query .= " id = :tag_id ;";
             $this->stmt = $this->pdo->prepare($query);
-            $this->stmt->bindParam(':tag_id', $tag["id"], PDO::PARAM_INT);
-            $this->stmt->execute();
-        } TODO: fix tag */
-
-    // ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Tabulka dd_wordform |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-        if (array_key_exists("id", $_POST) && $_POST['id'] != "") {
-            $query = "DELETE FROM dd_wordform WHERE";
-            $query .= " id = :id ;";
-            $this->stmt = $this->pdo->prepare($query);
-            $this->stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
+            $this->stmt->bindParam(':tag_id', $tag["tag_id"], PDO::PARAM_INT);
             $this->stmt->execute();
+        }else{
+            echo "fail";
         }
 }
 
@@ -732,4 +728,4 @@ define('DB_HOST', 'localhost');
 define('DB_NAME', 'dalim2');
 define('DB_CHARSET', 'utf8');
 define('DB_USER', 'postgres');
-define('DB_PASSWORD', 'x');
\ No newline at end of file
+define('DB_PASSWORD', 'MVcesko98');
\ No newline at end of file
diff --git a/application/view/searchContent.php b/application/view/searchContent.php
index f4777d4..63ff409 100644
--- a/application/view/searchContent.php
+++ b/application/view/searchContent.php
@@ -560,6 +560,7 @@
                     xhr.open("POST", "./controller/TableController.php");
                     xhr.onload = function(){
                         let search = this.response;
+                        //console.log(search);
                         let parsedJSON = JSON.parse(search);
                         if(parsedJSON.count === 0){
                             document.getElementById("no-data-label").style.display = "";
@@ -633,7 +634,7 @@
 
                     var xhr = new XMLHttpRequest();
                     xhr.open("POST", "./controller/UpdateController.php");
-                    xhr.send(formData);//TODO VACI CHECK?
+                    xhr.send(formData);
                     setTimeout(function(){
                         location.reload();
                     }, 500);
