Selaa lähdekoodia

Fixe Documents

stany.ferer 1 vuosi sitten
vanhempi
commit
e5a0b515f9

+ 11 - 4
core/class/document.class.php

@@ -54,10 +54,11 @@ class document
         $file = core::getFiles("document-import"); 
         $idFile = self::uploadFile($file); 
 
-        $tagsUser = tags::textToId(core::getPost("tagsUser"));
+        $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) VALUES (:id_type, :id_file, :titre, :date, :deadline, :description, :tagsUser)");
+            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"));
@@ -65,6 +66,7 @@ class document
             db::bind(':deadline', core::getPost("deadline"));
             db::bind(':description', core::getPost("description"));
             db::bind(':tagsUser', $tagsUser);
+            db::bind(':tagsSupplier', $tagsSupplier);
             
             try {
                     db::execute();
@@ -84,7 +86,8 @@ class document
 
     public static function update()
     {
-        $tagsUser = tags::textToId(core::getPost("tagsUser"));
+        $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
+        $tagsSupplier = tags::textToId(core::getPost("tagsSupplier"), 2);
 
         if(core::ifPost("done") AND core::getPost("done") == TRUE){
             $sql = "id_user_done = :id_user_done, date_done = CURRENT_TIMESTAMP, ";
@@ -99,7 +102,8 @@ class document
                 . "deadline = :deadline, "
                 . "description = :description, "
                 . $sql
-                . "tagsUser = :tagsUser "
+                . "tagsUser = :tagsUser, "
+                . "tagsSupplier = :tagsSupplier "
                 . "WHERE id = :id");
         
         db::bind(':id_type', core::getPost("id_type"));
@@ -108,6 +112,7 @@ class document
         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){
@@ -153,6 +158,7 @@ class document
             . "" . 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, "
@@ -165,6 +171,7 @@ class document
         db::bind(':id', $_id);
         $row = db::single();
         $row["tagsUser"] = tags::idToTtext($row["tagsUser"]);
+        $row["tagsSupplier"] = tags::idToTtext($row["tagsSupplier"]);
         return $row;
     }
 

+ 46 - 0
core/class/tags.class.php

@@ -19,6 +19,49 @@ class tags
         return db::resultset();
     }
 
+    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");
+
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    private static function insert(string $_tag, float $_idTag = 2) {
+        db::query("INSERT INTO " . DB_T_TAGS . " (id_type, label) VALUES (:id_type, :label)");
+        db::bind(':id_type', $_idTag);
+        db::bind(':label', $_tag);
+
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    static public function findAndCreate(string $_tags, float $_idTag = 2){
+        $find = [];
+        $tmp = explode(",", $_tags);
+        $allTags = self::getAll($_idTag);
+
+        foreach ($allTags as $tags) {
+            $find[] = $tags["label"];
+        }
+
+        $listCreate = array_udiff($tmp, $find, 'strcasecmp');
+
+        foreach ($listCreate as $insert) {
+            self::insert($insert, $_idTag);
+        }
+    }
+
     public static function getJquery(float $_idTag = NULL) {
         $tmp = "[";
         foreach (self::getAll($_idTag) as $tags) {
@@ -31,6 +74,9 @@ class tags
     public static function textToId(string $_tags = NULL, float $_idTag = NULL) {
         $return = NULL;
         if($_tags != NULL) {
+
+            ($_idTag != 1) ? self::findAndCreate($_tags) : NULL;
+
             $find = [];
             $tmp = explode(",", $_tags);
 

+ 1 - 1
core/class/user.class.php

@@ -135,7 +135,7 @@ class user {
     
     public static function add_user(array $_input){
 
-        $tags = tags::textToId($_input("tags"));
+        $tags = tags::textToId($_input["tags"], 1);
         
         db::query("INSERT INTO " . DB_T_USER . " "
                 . "(email, password, googleAuthenticator, googleAuthenticatorSecret, prenom, nom, id_type, tags, actif) "

+ 18 - 12
core/views/pages/cms.document.php

@@ -9,7 +9,7 @@ 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")); debug::log($document);
+    $document = document::get(core::getGet("id"));
     if (empty($document["id"])) {
         get::page("unknow");
         exit();
@@ -57,7 +57,7 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
 
 <link rel="stylesheet" href="css/dragAndDrop.css">
 
-<form method="post" action="/submit.php" enctype="multipart/form-data" onsubmit="loading()">
+<form id="form-document" method="post" action="/submit.php" enctype="multipart/form-data" onsubmit="return(false);">
 
     <div class="row">
         <div class="col">
@@ -89,6 +89,13 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
             </div>
             <br />
 
+            <?php $_tagsSupplier = (isset($document["tagsSupplier"])) ? $document["tagsSupplier"] : NULL; ?>
+            <div class="form-group">
+                <label>Tags associés</label>
+                <input type="text" value="<?php core::printFormValue($_tagsSupplier) ?>" name="tagsSupplier" id="tagsSupplier" />
+            </div>
+            <br />
+
             <?php $_date = (isset($document["date"])) ? $document["date"] : NULL; ?>
             <div class="form-group">
                 <label>Date associée à ce document</label>
@@ -110,14 +117,10 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
             </div>
             <br />
 
-            <?php $_assign_document = (isset($document["tagsUser"])) ? $document["tagsUser"] : NULL; ?>
+            <?php $_tagsUser = (isset($document["tagsUser"])) ? $document["tagsUser"] : NULL; ?>
             <div class="form-group">
                 <label>Attribution</label>
-                <input type="text" value="<?php
-                if (isset($document["tagsUser"])) {
-                    echo $document["tagsUser"];
-                }
-                ?>" name="tagsUser" id="tagsUser" />
+                <input type="text" value="<?php core::printFormValue($_tagsUser) ?>" name="tagsUser" id="tagsUser" />
             </div>
             <br />
 
@@ -168,19 +171,23 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
         }
         ?>
         </div>
-
     </div>
 
-    <input class="btn btn-primary btn-lg" style="width: 100%;" type="submit" value="<?php echo $submit ?>">
+    <input class="btn btn-primary btn-lg" style="width: 100%;" type="button" value="<?php echo $submit ?>" onclick="submit()">
     <br /><br />
 </form>
 
 <script>
+
     function dargAndDrop() {
         var fileName = $("#document-import").val().split('\\').pop();
         $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));
     }
 
+    function upperCase(input){
+        input.value = input.value.toUpperCase();
+    }
+
     $(document).ready(function () {
         $('#tagsUser').inputTags({
             autocomplete: {
@@ -192,8 +199,7 @@ if(isset($document["id"]) AND tags::compareUserDocument($userTags, $document["ta
 
         $('#tagsSupplier').inputTags({
             autocomplete: {
-                values: <?php echo tags::getJquery(2) ?>,
-                only: true
+                values: <?php echo tags::getJquery(2) ?>
             },
             max: 3
         });

+ 3 - 1
core/views/pages/cms.user.php

@@ -94,7 +94,7 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
     <br />
 
     <?php 
-        if(core::ifGet("id") == TRUE AND access::ifAccesss("add-user")) { ?>
+        if(access::ifAccesss("add-user")) { ?>
             <div class="form-group">
                 <label>Rôles aditionnels</label>
                 <input type="text" value="<?php
@@ -112,6 +112,8 @@ if(core::ifGet("add") AND access::ifAccesss("add-user")) {
         </div>
         <br />
     <?php 
+        } else {
+            echo '<input type="hidden" name="tags" value=">';
         }
     ?>
 

+ 2 - 0
maj/sql/maj.sql

@@ -1 +1,3 @@
 
+
+ALTER TABLE `documents` ADD `tagsSupplier` TEXT NULL AFTER `tagsUser`;