فهرست منبع

Maj Documents & tags

stany.ferer 1 سال پیش
والد
کامیت
92dd9e8840

+ 8 - 3
conf.inc.php

@@ -25,7 +25,7 @@ define("DIR_BACKUP", DOCUMENT_DATAS . "backups/");
 
 define("DB_T_CONFIG", "config");
 define("DB_T_USER", "user");
-define("DB_T_USER_TYPE", "user_type");
+define("DB_T_USER_TAGS", "user_tags");
 define("DB_T_SALARIES", "salaries");
 define("DB_T_TEMP_SALARIES", "tmp_salaries");
 define("DB_T_ENTREE_SORTIE", "entree_sortie");
@@ -42,12 +42,17 @@ define("DB_T_HISTORIQUE_REF", "historiqueRef");
 define("DB_T_BANQUE_COMPTES", "banque_comptes");
 define("DB_T_BANQUE_LIGNES", "banque_lignes");
 define("DB_T_BANQUE_CSV", "banque_csv");
-define("DB_T_TYPE_ACCESS", "type_access");
 define("DB_T_ACCESS", "access");
 define("DB_T_DOCUMENTS", "documents");
-define("DB_T_TYPE_DOCUMENT", "type_document");
+define("DB_T_DOCUMENT_FILES", "documents_files");
+define("DB_T_DOCUMENT_TAGS", "documents_tags");
 define("DB_T_TAGS", "tags");
 
+define("DB_T_TYPE_TAGS", "type_tags");
+define("DB_T_TYPE_USER", "type_user");
+define("DB_T_TYPE_DOCUMENT", "type_document");
+define("DB_T_TYPE_ACCESS", "type_access");
+
 define("HOME_TYPE_USER", array(
     1 =>    [ // Administrateur
                 "home" => "rh-liste-salaries",

+ 6 - 6
core/class/access.class.php

@@ -63,12 +63,12 @@ class access
     {
         $return = array();
         db::query("SELECT "
-            . "" . DB_T_USER_TYPE . ".type, "
+            . "" . DB_T_TYPE_USER . ".type, "
             . "" . DB_T_ACCESS . ".label, "
             . "" . DB_T_ACCESS . ".show, "
             . "" . DB_T_ACCESS . ".add "
             . "FROM " . DB_T_ACCESS . " "
-            . "INNER JOIN " . DB_T_USER_TYPE . " ON " . DB_T_USER_TYPE . ".id = " . DB_T_TYPE_ACCESS . ".id_type "
+            . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_TYPE_USER . ".id = " . DB_T_TYPE_ACCESS . ".id_type "
             . "INNER JOIN " . DB_T_TYPE_ACCESS . " ON " . DB_T_ACCESS . ".id = " . DB_T_TYPE_ACCESS . ".id_access");
         try {
             $tmp = db::resultset();
@@ -103,9 +103,9 @@ class access
 
     public static function getTypesUsers(bool $_expect = FALSE)
     {
-        $except = ($_expect == FALSE) ? NULL : " WHERE " . DB_T_USER_TYPE . ".id != 1 AND " . DB_T_USER_TYPE . ".id != 2";
+        $except = ($_expect == FALSE) ? NULL : " WHERE " . DB_T_TYPE_USER . ".id != 1 AND " . DB_T_TYPE_USER . ".id != 2";
 
-        db::query("SELECT * FROM " . DB_T_USER_TYPE . $except);
+        db::query("SELECT * FROM " . DB_T_TYPE_USER . $except);
         try {
             $tmp = db::resultset();
             return $tmp;
@@ -122,10 +122,10 @@ class access
         db::query("SELECT "
             . "CONCAT(" . DB_T_ACCESS . ".label, '|', " . DB_T_ACCESS . ".show, " . DB_T_ACCESS . ".add) AS access, "
             . "" . DB_T_TYPE_ACCESS . ".id_type, "
-            . "" . DB_T_USER_TYPE . ".type "
+            . "" . DB_T_TYPE_USER . ".type "
             . "FROM " . DB_T_ACCESS . " "
             . "LEFT JOIN " . DB_T_TYPE_ACCESS . " ON " . DB_T_TYPE_ACCESS . ".id_access = " . DB_T_ACCESS . ".id "
-            . "LEFT JOIN " . DB_T_USER_TYPE . " ON " . DB_T_TYPE_ACCESS . ".id_type = " . DB_T_USER_TYPE . ".id "
+            . "LEFT JOIN " . DB_T_TYPE_USER . " ON " . DB_T_TYPE_ACCESS . ".id_type = " . DB_T_TYPE_USER . ".id "
         );
 
         try {

+ 178 - 62
core/class/document.class.php

@@ -16,8 +16,15 @@ class document
         return file::download($_id, DIR_DATAS_DOCS);
     }
 
-    static public function deleteFile(string $_id){
-        return file::delete($_id, DIR_DATAS_DOCS);
+    static public function deleteFile(float $_id){
+        foreach (self::getFiles($_id) as $file) {
+
+            db::query("DELETE FROM ". DB_T_DOCUMENT_FILES ." WHERE id_files = :id_files");
+            db::bind(':id_files', $file["id"]);
+            db::execute();
+
+            file::delete($file["id"], DIR_DATAS_DOCS);
+        }
     }
 
     static public function getTypes(){
@@ -27,15 +34,25 @@ class document
         return db::resultset();
     }
 
-    public static function delete(int $_id)
+    public static function delete(float $_id)
     {
-        $tmp = self::get($_id);
-
-        db::query("DELETE FROM " . DB_T_DOCUMENTS . " WHERE id = :id");
-        db::bind(':id', $_id);
-        db::execute();
+        try {
+            db::query("DELETE FROM ". DB_T_DOCUMENT_TAGS ." WHERE id_documents = :id_documents");
+            db::bind(':id_documents', $_id);
+            db::execute();
 
-        return self::deleteFile($tmp["id_file"]);
+            self::deleteFile($_id);
+            
+            db::query("DELETE FROM " . DB_T_DOCUMENTS . " WHERE id = :id");
+            db::bind(':id', $_id);
+            db::execute();
+            
+            alert::recSuccess("Le document vient d'être supprimé");
+            return TRUE;
+        } catch (Exception $ex) {
+            alert::recError("Erreur à la suppression du document");
+            return FALSE;
+        }
     }
 
     public static function lastAdd()
@@ -43,54 +60,111 @@ class document
         db::query("SELECT MAX(id) AS id FROM " . DB_T_DOCUMENTS);
         return db::single()["id"];
     }
+
+    private static function addFile(float $_idDocument, string $_idFile)
+    {
+        db::query("INSERT INTO " . DB_T_DOCUMENT_FILES . " (id_documents, id_files) VALUES (:id_documents, :id_files)");
+        db::bind(':id_documents', $_idDocument);
+        db::bind(':id_files', $_idFile);
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    private static function addTags(float $_idDocument, string $_tags = NULL, float $_type)
+    {
+        db::query("DELETE FROM " . DB_T_DOCUMENT_TAGS . " WHERE id_documents = :id_documents AND id_type_tags = :id_type_tags");
+        db::bind(':id_documents', $_idDocument);
+        db::bind(':id_type_tags', $_type);
+        db::execute();
+        
+        if($_tags != NULL){ 
+            $tags = explode(",", $_tags);
+
+            $sqlMaj = "";
+            foreach ($tags as $tag) {
+                $sqlMaj .= " (:id_documents, ".$tag.", :id_type_tags),";
+            }
+
+            $sqlMaj = substr($sqlMaj, 0, -1);
+
+            db::query("INSERT INTO " . DB_T_DOCUMENT_TAGS . " (id_documents, id_tags, id_type_tags) VALUES" . $sqlMaj);
+            db::bind(':id_documents', $_idDocument);
+            db::bind(':id_type_tags', $_type);
+            try {
+                db::execute();
+                return TRUE;
+            } catch (Exception $ex) {
+                return FALSE;
+            }
+        }
+    }
     
     public static function add()
     {   
-        /**
-        * 
-        * @var string $idFile
-        */
-
-        $file = core::getFiles("document-import"); 
-        $idFile = self::uploadFile($file); 
-
-        $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
-        $tagsSupplier = tags::textToId(core::getPost("tagsSupplier"), 2);
-
-        if($idFile != NULL){
-            db::query("INSERT INTO " . DB_T_DOCUMENTS . " (id_type, id_file, titre, date, deadline, description, tagsUser, tagsSupplier) VALUES (:id_type, :id_file, :titre, :date, :deadline, :description, :tagsUser, :tagsSupplier)");
-            db::bind(':id_type', core::getPost("id_type"));
-            db::bind(':id_file', $idFile);
-            db::bind(':titre', core::getPost("titre"));
-            db::bind(':date', core::getPost("date"));
-            db::bind(':deadline', core::getPost("deadline"));
-            db::bind(':description', core::getPost("description"));
-            db::bind(':tagsUser', $tagsUser);
-            db::bind(':tagsSupplier', $tagsSupplier);
+        db::query("INSERT INTO " . DB_T_DOCUMENTS . " (id_type, titre, date, deadline, description, id_user) VALUES (:id_type, :titre, :date, :deadline, :description, :id_user)");
+        db::bind(':id_type', core::getPost("id_type"));
+        db::bind(':titre', core::getPost("titre"));
+        db::bind(':date', core::getPost("date"));
+        db::bind(':deadline', core::getPost("deadline"));
+        db::bind(':description', core::getPost("description"));
+        db::bind(':id_user', session::getId());
+        
+        try {
+            db::execute();
+            $lastId = db::lastInsertId();
+        } catch (Exception $ex) {
+            alert::recError("Erreur à l'enregistrement de la fiche : " . core::getPost("titre"));
+            return FALSE;
+        }
+
+        try {
+            $file = core::getFiles("document-import"); 
+            $idFile = self::uploadFile($file);
+        } catch (Exception $ex) {
+            alert::recError("Erreur à l'enregistrement de la pièce jointe : " . $idFile);
+            return FALSE;
+        }
+
+        try {
+            self::addFile($lastId, $idFile);
+        } catch (Exception $ex) {
+            alert::recError("Erreur à l'enregistrement de la liaison : " . $idFile);
+            return FALSE;
+        }
+
+        try { 
+            $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
+            self::addTags($lastId, $tagsUser, 1);
+
+            $tagsSupplier = tags::textToId(core::getPost("tagsSupplier"), 2);
+            self::addTags($lastId, $tagsSupplier, 2);
             
-            try {
-                    db::execute();
-                    alert::recSuccess("Document enregistré avec succès");
-                    return TRUE;
-                } catch (Exception $ex) {
-                    file::delete($idFile, DIR_DATAS_DOCS);
-                    alert::recError("Erreur à l'enregistrement du document : " . core::getPost("titre"));
-                    return FALSE;
-                }
-        } else {
-            file::delete($idFile, DIR_DATAS_DOCS);
-            alert::recError("Erreur à l'enregistrement de la pièce jointe : " . $file["tmp_name"]);
+        } catch (Exception $ex) {
+            alert::recError("Erreur à l'enregistrement de la liaison : " . $idFile);
             return FALSE;
         }
+        
     }
 
     public static function update()
     {
-        $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
-        $tagsSupplier = tags::textToId(core::getPost("tagsSupplier"), 2);
+        try { 
+            $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
+            self::addTags(core::getPost("id"), $tagsUser, 1);
+
+            $tagsSupplier = tags::textToId(core::getPost("tagsSupplier"), 2); echo $tagsSupplier;
+            self::addTags(core::getPost("id"), $tagsSupplier, 2);
+        } catch (Exception $ex) {
+            alert::recError("Erreur à l'enregistrement de la liaison : " . core::getPost("id"));
+            return FALSE;
+        }
 
         if(core::ifPost("done") AND core::getPost("done") == TRUE){
-            $sql = "id_user_done = :id_user_done, date_done = CURRENT_TIMESTAMP, ";
+            $sql = ", id_user_done = :id_user_done, date_done = CURRENT_TIMESTAMP ";
         } else {
             $sql = "";
         }
@@ -100,10 +174,8 @@ class document
                 . "titre = :titre, "
                 . "date = :date, "
                 . "deadline = :deadline, "
-                . "description = :description, "
+                . "description = :description "
                 . $sql
-                . "tagsUser = :tagsUser, "
-                . "tagsSupplier = :tagsSupplier "
                 . "WHERE id = :id");
         
         db::bind(':id_type', core::getPost("id_type"));
@@ -111,8 +183,6 @@ class document
         db::bind(':date', core::getPost("date"));
         db::bind(':deadline', core::getPost("deadline"));
         db::bind(':description', core::getPost("description"));
-        db::bind(':tagsUser', $tagsUser);
-        db::bind(':tagsSupplier', $tagsSupplier);
         db::bind(':id', core::getPost("id"));
 
         if(core::ifPost("done") AND core::getPost("done") == TRUE){
@@ -124,7 +194,7 @@ class document
                 alert::recSuccess("Document mis à jour avec succès");
                 return TRUE;
             } catch (Exception $ex) {
-                alert::recError("Erreur de mise à jour du document");
+                alert::recError("Erreur de mise à jour du document : " . $ex);
                 return FALSE;
             }
     }
@@ -152,27 +222,73 @@ class document
         db::query("SELECT "
             . "" . DB_T_DOCUMENTS . ".id, "
             . "" . DB_T_DOCUMENTS . ".id_type, "
-            . "" . DB_T_DOCUMENTS . ".id_file, "
             . "" . DB_T_DOCUMENTS . ".titre, "
             . "" . DB_T_DOCUMENTS . ".date, "
             . "" . DB_T_DOCUMENTS . ".deadline, "
             . "" . DB_T_DOCUMENTS . ".description, "
-            . "" . DB_T_DOCUMENTS . ".tagsUser, "
-            . "" . DB_T_DOCUMENTS . ".tagsSupplier, "
             . "" . DB_T_DOCUMENTS . ".id_user_done, "
             . "" . DB_T_DOCUMENTS . ".date_done, "
-            . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS doneUser, "
-            . "" . DB_T_FILES . ".name, "
-            . "CONCAT(ROUND((" . DB_T_FILES . ".size / 1024 / 1024), 2), ' Mo') AS size "
+            . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS doneUser "
             . "FROM " . DB_T_DOCUMENTS . " "
-            . "INNER JOIN " . DB_T_FILES . " ON " . DB_T_FILES . ".id = " . DB_T_DOCUMENTS . ".id_file "
             . "LEFT JOIN " . DB_T_USER . " ON " . DB_T_USER . ".id = " . DB_T_DOCUMENTS . ".id_user_done "
             . "WHERE " . DB_T_DOCUMENTS . ".id = :id");
         db::bind(':id', $_id);
-        $row = db::single();
-        $row["tagsUser"] = tags::idToTtext($row["tagsUser"]);
-        $row["tagsSupplier"] = tags::idToTtext($row["tagsSupplier"]);
-        return $row;
+        $document = db::single();
+
+        $document["tagsSupplier"] = self::getTags($_id, 2);
+        $document["tagsUser"] = self::getTags($_id, 1);
+
+        $files = self::getFiles($_id);
+
+        return array("document" => $document, "files" => $files);
+    }
+
+    static public function getTags(float $_idDocument, float $_idTypeTags){
+        db::query("SELECT "
+            . "" . DB_T_TAGS . ".label "
+            . "FROM " . DB_T_DOCUMENT_TAGS . " "
+            . "INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags "
+            . "WHERE " . DB_T_DOCUMENT_TAGS . ".id_documents = :idDocument AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = :idTypeTags "
+            . "ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer");
+        db::bind(':idDocument', $_idDocument);
+        db::bind(':idTypeTags', $_idTypeTags);
+        $tmp = db::resultset();
+
+        if(isset($tmp[0])){
+            $return = NULL;
+            foreach ($tmp as $value) {
+                $return .= $value["label"].",";
+            }
+    
+            $return = substr($return, 0, -1);
+            return $return;
+        } else {
+            return NULL;
+        }
+        
+    }
+
+    static public function getFiles(float $_idDocument){
+        db::query("SELECT "
+            . "" . DB_T_FILES . ".id, "
+            . "" . DB_T_FILES . ".name, "
+            . "" . DB_T_FILES . ".size, "
+            . "" . DB_T_FILES . ".creer, "
+            . "" . DB_T_FILES . ".id_user, "
+            . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS user "
+            . "FROM " . DB_T_DOCUMENT_FILES . " "
+            . "INNER JOIN " . DB_T_FILES . " ON " . DB_T_FILES . ".id = " . DB_T_DOCUMENT_FILES . ".id_files "
+            . "INNER JOIN " . DB_T_USER . " ON " . DB_T_USER . ".id = " . DB_T_FILES . ".id_user "
+            . "WHERE " . DB_T_DOCUMENT_FILES . ".id_documents = :id "
+            . "ORDER BY " . DB_T_FILES . ".creer");
+        db::bind(':id', $_idDocument);
+        $tmp = db::resultset();
+
+        if(isset($tmp[0])){
+            return $tmp;
+        } else {
+            return NULL;
+        }
     }
 
 }

+ 2 - 12
core/class/json.class.php

@@ -192,7 +192,6 @@ class json extends db
 
     private static function create_document()
     {
-        $row = [];
         
         db::query("SELECT 
         " . DB_T_DOCUMENTS . ".id, 
@@ -200,23 +199,14 @@ class json extends db
         " . DB_T_DOCUMENTS . ".date, 
         " . DB_T_DOCUMENTS . ".deadline, 
         " . DB_T_DOCUMENTS . ".description, 
-        " . DB_T_DOCUMENTS . ".tagsUser, 
         IF(" . DB_T_DOCUMENTS . ".id_user_done IS NOT NULL, 'Traité', 'Non traité') AS done, 
-        " . DB_T_FILES . ".name, 
         " . DB_T_TYPE_DOCUMENT . ".label, 
-        CONCAT(ROUND((" . DB_T_FILES . ".size / 1024 / 1024), 2), ' Mo') AS size, 
         CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user'
         FROM " . DB_T_DOCUMENTS . " 
-        INNER JOIN " . DB_T_FILES . " ON " . DB_T_FILES . ".id = " . DB_T_DOCUMENTS . ".id_file 
         INNER JOIN " . DB_T_TYPE_DOCUMENT . " ON " . DB_T_TYPE_DOCUMENT . ".id = " . DB_T_DOCUMENTS . ".id_type
-        INNER JOIN " . DB_T_USER . " ON " . DB_T_FILES . ".id_user = " . DB_T_USER . ".id");
+        INNER JOIN " . DB_T_USER . " ON " . DB_T_DOCUMENTS . ".id_user = " . DB_T_USER . ".id");
 
-        $return =  db::resultset();
-
-        foreach ($return as $key => $docs) {
-            $row[$key] = $docs;
-            $row[$key]["tagsUser"] = tags::idToTtext($docs["tagsUser"]);
-        }
+        $row =  db::resultset();
 
         if (file_put_contents(DIR_DATAS_JSON . "documents.json", json_encode($row))) {
             return 1;

+ 2 - 26
core/class/tags.class.php

@@ -20,13 +20,10 @@ class tags
     }
 
     public static function cleanTags(){
-        db::query(" DELETE table_tags.*
-                    FROM ". DB_T_TAGS . " table_tags 
-                    LEFT JOIN ". DB_T_DOCUMENTS . " table_association ON table_association.tagsSupplier = table_tags.id 
-                    WHERE table_tags.id IS NULL AND table_tags.id_type != 1");
+        db::query("");
 
         try {
-            db::execute();
+            
             return TRUE;
         } catch (Exception $ex) {
             return FALSE;
@@ -95,27 +92,6 @@ class tags
         return $return;
     }
 
-    public static function idToTtext(string $_ids = NULL, float $_idTag = NULL) {
-        $return = NULL;  
-        if($_ids != NULL) {
-
-            $tmp = explode(",", $_ids);
-
-            $allTags = self::getAll($_idTag);
-
-            foreach ($allTags as $f) {
-                $find[$f["label"]] = $f["id"];
-            }
-
-            foreach ($tmp as $flag) { 
-                $return .= array_search($flag, $find).",";
-            }
-
-            $return = substr($return, 0, -1);
-        }
-        return $return;
-    }
-
     public static function findUsersTags(string $_tags = NULL){
 
         $tmp = explode(",", $_tags);

+ 72 - 25
core/class/user.class.php

@@ -18,22 +18,21 @@ class user {
                 . "" . DB_T_USER . ".actif, "
                 . "" . DB_T_USER . ".deleted, "
                 . "" . DB_T_USER . ".id_type, "
-                . "" . DB_T_USER . ".tags, "
-                . "" . DB_T_USER_TYPE . ".type "
+                . "" . DB_T_TYPE_USER . ".type "
                 . "FROM " . DB_T_USER . " "
-                . "INNER JOIN " . DB_T_USER_TYPE . " ON " . DB_T_USER . ".id_type = " . DB_T_USER_TYPE . ".id "
+                . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_USER . ".id_type = " . DB_T_TYPE_USER . ".id "
                 . "WHERE " . DB_T_USER . ".id = :id");
         db::bind(':id', $_id);
         $return = db::single();
-        $return["tags"] = tags::idToTtext($return["tags"]);
+        $return["tags"] = self::getTags($_id);
         return $return;
     }
 
     public static function getUsers() {
         // Récupération des données de l'excel au format Json
         db::query("SELECT "
-                . "" . DB_T_USER . ".id AS id, "
-                . "" . DB_T_USER . ".email ,"
+                . "" . DB_T_USER . ".id, "
+                . "" . DB_T_USER . ".email, "
                 . "" . DB_T_USER . ".prenom, "
                 . "" . DB_T_USER . ".nom, "
                 . "" . DB_T_USER . ".cree, "
@@ -41,16 +40,15 @@ class user {
                 . "" . DB_T_USER . ".googleAuthenticator, "
                 . "" . DB_T_USER . ".actif, "
                 . "" . DB_T_USER . ".id_type, "
-                . "" . DB_T_USER . ".tags, "
-                . "" . DB_T_USER_TYPE . ".type "
+                . "" . DB_T_TYPE_USER . ".type "
                 . "FROM " . DB_T_USER . " "
-                . "INNER JOIN " . DB_T_USER_TYPE . " ON " . DB_T_USER . ".id_type = " . DB_T_USER_TYPE . ".id "
+                . "INNER JOIN " . DB_T_TYPE_USER . " ON " . DB_T_USER . ".id_type = " . DB_T_TYPE_USER . ".id "
                 . "WHERE " . DB_T_USER . ".deleted = 0");
         $return =  db::resultset();
 
         foreach ($return as $key => $users) {
             $return[$key] = $users;
-            $return[$key]["tags"] = tags::idToTtext($users["tags"]);
+            $return[$key]["tags"] = self::getTags($users["id"]);
         }
 
         return $return;
@@ -134,9 +132,6 @@ class user {
     }
     
     public static function add_user(array $_input){
-
-        $tags = tags::textToId($_input["tags"], 1);
-        
         db::query("INSERT INTO " . DB_T_USER . " "
                 . "(email, password, googleAuthenticator, googleAuthenticatorSecret, prenom, nom, id_type, tags, actif) "
                 . "VALUES (:email, :password, :googleAuthenticator, :googleAuthenticatorSecret, :prenom, :nom, :id_type, :tags, :actif)");
@@ -147,11 +142,14 @@ class user {
         db::bind(':googleAuthenticator', $_input["googleAuthenticator"]);
         db::bind(':googleAuthenticatorSecret', googleAuthenticator::createSecret());
         db::bind(':id_type', $_input["id_type"]);
-        db::bind(':tags', $tags);
         db::bind(':actif', $_input["actif"]);
-        
+
         try {
             db::execute();
+
+            $tags = tags::textToId($_input["tags"], 1); 
+            self::addTags(db::lastInsertId(), $tags);
+
             alert::recSuccess("La création a bien été prise en compte");
         } catch (Exception $ex) {
             alert::recError("Erreur lors de la création de l'utilisateur");
@@ -193,23 +191,22 @@ class user {
             }
         }
 
-        $tags = tags::textToId($_input["tags"]); 
+        $tags = tags::textToId($_input["tags"], 1); 
+        self::addTags($_input["id"], $tags);
 
         db::query("UPDATE " . DB_T_USER . " SET 
-                                                    email = :email, 
-                                                    prenom = :prenom, 
-                                                    nom = :nom, 
-                                                    id_type = :id_type, 
-                                                    tags = :tags,
-                                                    googleAuthenticator = :googleAuthenticator, 
-                                                    actif = :actif
-                                                    WHERE id = :id");
+                    email = :email, 
+                    prenom = :prenom, 
+                    nom = :nom, 
+                    id_type = :id_type, 
+                    googleAuthenticator = :googleAuthenticator, 
+                    actif = :actif
+                    WHERE id = :id");
         db::bind(':email', $_input["email"]);
         db::bind(':prenom', $_input["prenom"]);
         db::bind(':nom', $_input["nom"]);
         db::bind(':googleAuthenticator', $_input["googleAuthenticator"]);
         db::bind(':id_type', $_input["id_type"]);
-        db::bind(':tags', $tags);
         db::bind(':actif', $_input["actif"]);
         db::bind(':id', $_input["id"]);
         
@@ -222,6 +219,56 @@ class user {
             exit();
         }
     }
+
+    static public function getTags(float $_idUser){
+        db::query("SELECT "
+            . "" . DB_T_TAGS . ".label "
+            . "FROM " . DB_T_USER_TAGS . " "
+            . "INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_USER_TAGS . ".id_tags "
+            . "WHERE " . DB_T_USER_TAGS . ".id_user = :id "
+            . "ORDER BY " . DB_T_USER_TAGS . ".creer");
+        db::bind(':id', $_idUser);
+        $tmp = db::resultset();
+
+        if(isset($tmp[0])){
+            $return = NULL;
+            foreach ($tmp as $value) {
+                $return .= $value["label"].",";
+            }
+    
+            $return = substr($return, 0, -1);
+            return $return;
+        } else {
+            return NULL;
+        }
+    }  
+
+    private static function addTags(float $_idUser, string $_tags = NULL)
+    {
+        db::query("DELETE FROM " . DB_T_USER_TAGS . " WHERE id_user = :id_user");
+        db::bind(':id_user', $_idUser);
+        db::execute();
+
+        if($_tags != NULL){ 
+            $tags = explode(",", $_tags);
+
+            $sqlMaj = "";
+            foreach ($tags as $tag) {
+                $sqlMaj .= " (:id_user, ".$tag."),";
+            }
+
+            $sqlMaj = substr($sqlMaj, 0, -1);
+
+            db::query("INSERT INTO " . DB_T_USER_TAGS . " (id_user, id_tags) VALUES" . $sqlMaj);
+            db::bind(':id_user', $_idUser);
+            try {
+                db::execute();
+                return TRUE;
+            } catch (Exception $ex) {
+                return FALSE;
+            }
+        }
+    }
     
     public static function deleteUser(int $_id){
         db::query("UPDATE " . DB_T_USER . " SET deleted = 1 WHERE id = :id");

+ 0 - 1
core/submit/cms.document-delete.php

@@ -3,7 +3,6 @@
 if(core::ifGet("id")) {
     document::delete(core::getGet("id"));
     json::create("documents");
-    alert::recSuccess("Le document vient d'être supprimé");
 
     historique::recRef("/document-" . core::getGet("id").".html");
     historique::add(array(

+ 13 - 9
core/views/pages/cms.document.php

@@ -9,7 +9,10 @@ if (core::getGet("id") == NULL) {
     $id_form = '<input type="hidden" name="id" value="add">';
     $submit = "Ajouter ce nouveau document";
 } else {
-    $document = document::get(core::getGet("id"));
+    $datas = document::get(core::getGet("id"));
+    $document = $datas["document"];
+    $files = $datas["files"];
+
     if (empty($document["id"])) {
         get::page("unknow");
         exit();
@@ -22,6 +25,7 @@ if (core::getGet("id") == NULL) {
 }
 
 $userTags = user::getUserById(session::getId())["tags"];
+
 ?>
 <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
     <h2 class="bd-title" id="content">
@@ -46,7 +50,7 @@ echo core::filAriane(array(
     )
 ));
 
-if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["tagsUser"]) == FALSE ){ 
+if(isset($document["id"])){ 
 ?>
     <div style="float:right; margin-top: -60px;">
         <a href="/submit.php?from=document-delete&id=<?php echo $document["id"] ?>" style="color: #dc3545; text-decoration:none;" onclick="return confirm('Voulez-vous supprimer ce document ?')"><button type="submit" class="btn btn-outline-danger btn-sm"><span data-feather="trash-2"></span> Supprimer</button></a>
@@ -135,16 +139,16 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
             <br />
             <?php } ?>
 
-            <?php if(isset($document["id_file"])) { ?>
+            <?php if(isset($files[0]["id"])) { ?>
                 <div class="form-group" style="opacity:0.5">
                     <label style="color:var(--bs-link-color)">Nom du fichier</label>
-                    <input type="text" class="form-control" style="border-color:var(--bs-link-color); color:var(--bs-link-color);" value="<?php echo $document["name"] ?>" readonly>
+                    <input type="text" class="form-control" style="border-color:var(--bs-link-color); color:var(--bs-link-color);" value="<?php echo $files[0]["name"] ?>" readonly>
                 </div>
                 <br />
 
                 <div class="form-group" style="opacity:0.5">
                     <label style="color:var(--bs-link-color)">Taille</label>
-                    <input type="text" class="form-control" style="border-color:var(--bs-link-color); color:var(--bs-link-color)" value="<?php echo $document["size"] ?>" readonly>
+                    <input type="text" class="form-control" style="border-color:var(--bs-link-color); color:var(--bs-link-color)" value="<?php echo $files[0]["size"] ?>" readonly>
                 </div>
                 <br />
             <?php } ?>
@@ -152,7 +156,7 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
         </div>
 
         <div class="col">
-        <?php if(empty($document["id_file"])) { ?>
+        <?php if(empty($files[0]["id"])) { ?>
             <div class="file-drop-area" style="margin-top:22px;">
                 <span class="choose-file-button">Choisissez votre document</span>
                 <span class="file-message">ou drag & drop</span>
@@ -160,12 +164,12 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
             </div>
             <br />
         <?php } else {
-            $heigh = (mime_content_type(file::download($document["id_file"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
+            $heigh = (mime_content_type(file::download($files[0]["id"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
             echo '  <div style="margin-top:22px;">
-                        <a href="/document.php?id='.$document["id_file"].'" target="_blank" style="right:0;">
+                        <a href="/document.php?id='.$files[0]["id"].'" target="_blank" style="right:0;">
                             <input class="btn btn-outline-secondary btn-sm" style="width: 100%; opacity:0.6;" value="Ouvrir le document">
                         </a>
-                        <embed src="/document.php?id='.$document["id_file"].'" style="width:100%; margin-top:10px;'.$heigh.'" /></embed>
+                        <embed src="/document.php?id='.$files[0]["id"].'" style="width:100%; margin-top:10px;'.$heigh.'" /></embed>
                     </div><br />
                     ';
         }

+ 1 - 2
core/views/pages/cms.documents.php

@@ -4,9 +4,8 @@
     $jsonTarget = "/json.php?file=documents";
     if(core::isDebug()){
         debug::log(debug::getBadge($jsonTarget, "OUVRIR LE JSON : ".$jsonTarget), "JSON chargé en arrière plan");
+        json::create("documents");
     } 
-
-    json::create("documents");
 ?>
 
 <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">

+ 3 - 1
maj/sql/maj.sql

@@ -1,3 +1,5 @@
 
 
-ALTER TABLE `documents` ADD `tagsSupplier` TEXT NULL AFTER `tagsUser`;
+ALTER TABLE `documents` ADD `tagsSupplier` TEXT NULL AFTER `tagsUser`;
+
+RENAME TABLE user_type TO type_user;