stany.ferer 1 rok pred
rodič
commit
e9ebed7d7c

+ 17 - 8
core/class/document.class.php

@@ -287,12 +287,21 @@ class document
         $filePatch = file::download($_id, DIR_DATAS_DOCS);
         
         if (file_exists($filePatch) && is_readable($filePatch)) {
-
+    
             $file_info = new finfo(FILEINFO_MIME_TYPE);
             $mime_type = $file_info->file($filePatch);
-            header('Content-Type: ' . $mime_type);
-            header('Content-Length: ' . filesize($filePatch));
-            readfile($filePatch);
+    
+            // Vérification si le fichier est de type XML
+            if ($mime_type === 'application/xml' || $mime_type === 'text/xml') {
+                // Chargement du contenu XML
+                $xml_content = file_get_contents($filePatch);
+                xml::print($xml_content);
+            } else {
+                // Si ce n'est pas un fichier XML, comportement normal pour servir le fichier
+                header('Content-Type: ' . $mime_type);
+                header('Content-Length: ' . filesize($filePatch));
+                readfile($filePatch);
+            }
         } else {
             echo "Le fichier n'a pas été trouvé ou n'est pas lisible.";
         }
@@ -448,7 +457,7 @@ class document
                         <div><span class="fw-bold">'.$principal["name"].'</span> ('.core::convertBytes($principal["size"]).')</div>
                         Chargé le '.core::convertDate($principal["creer"]).' par '.$principal["user"].'
                         <div id="select-attach-'.$principal["id"].'" style="color:red;"></div>
-                    </div><button type="button" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $principal["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
+                    </div><button type="button" title="Voir le document" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $principal["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
                 </li>';
         foreach ($_attachs as $key => $attach) {
                 if($key != "principal"){
@@ -458,9 +467,9 @@ class document
                                     Chargé le '.core::convertDate($attach["creer"]).' par '.$attach["user"].'
                                     <div id="select-attach-'.$attach["id"].'"></div>
                                 </div><div class="btn-group">
-                                    <button type="button" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
-                                    <button type="button" class="btn btn btn-outline-primary" onclick="defaultAttachment(\''.$attach["id"].'\')" id="button-default-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-paperclip"]) . '</button>
-                                    <button type="button" class="btn btn-outline-danger" onclick="deleteAttachment(\''.$attach["id"].'\')" id="button-delete-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-trash"]) . '</button>
+                                    <button type="button" title="Voir le document" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
+                                    <button type="button" title="Document mis en avant" class="btn btn btn-outline-primary" onclick="defaultAttachment(\''.$attach["id"].'\')" id="button-default-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-star-fill"]) . '</button>
+                                    <button type="button" title="Supprimer ce document" class="btn btn-outline-danger" onclick="deleteAttachment(\''.$attach["id"].'\')" id="button-delete-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-trash"]) . '</button>
                                 </div>
                             </li>';
                 }          

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

@@ -0,0 +1,46 @@
+<?php
+
+class xml{
+    public static function print(string $_string){
+        // Utiliser DOMDocument pour rendre le XML lisible
+        $dom = new DOMDocument();
+        $dom->preserveWhiteSpace = false;
+        $dom->formatOutput = true;
+        $dom->loadXML($_string);
+
+        // Obtenir le XML formaté
+        $formatted_xml = htmlspecialchars($dom->saveXML());
+
+        // Affichage du XML formaté avec du style CSS pour colorer les éléments XML
+        header('Content-Type: text/html; charset=UTF-8');
+        echo "<html><head><title>Visualisation XML avec couleurs</title>";
+        // Ajouter du CSS pour colorer les éléments XML et gérer l'enroulement
+        echo "
+            <style>
+                pre {
+                    font-family: 'Courier New', Courier, monospace; 
+                    background-color: #f4f4f4; 
+                    padding: 15px; 
+                    border: 1px solid #ddd;
+                    white-space: pre-wrap;       /* Permet l'enroulement du texte */
+                    word-wrap: break-word;        /* Force l'enroulement sur les longs mots */
+                    overflow-wrap: break-word;    /* Gère les débordements du texte */
+                }
+                .tag { color: #007700; }      /* Couleur des balises */
+                .attribute { color: #0000ff; } /* Couleur des attributs */
+                .value { color: #dd0000; }     /* Couleur des valeurs d'attribut */
+            </style>
+        ";
+        echo "</head><body>";
+        echo "<h1>Visualisation du fichier XML avec code couleur</h1>";
+
+        // Remplacer les éléments pour les colorier avec du CSS
+        $formatted_xml = preg_replace('/(&lt;\/?)(\w+)(.*?&gt;)/', '<span class="tag">$1$2</span>$3', $formatted_xml);
+        $formatted_xml = preg_replace('/(\w+)="(.*?)"/', '<span class="attribute">$1</span>="<span class="value">$2</span>"', $formatted_xml);
+
+        // Afficher le XML formaté et coloré
+        echo "<pre>" . $formatted_xml . "</pre>";
+
+        echo "</body></html>";
+    }
+}

+ 4 - 3
core/views/pages/cms.document.php

@@ -165,7 +165,7 @@ if (isset($document["id"])) {
                     <div class="file-drop-area">
                         <span class="choose-file-button">Ajouter une pièce jointe</span>
                         <span class="file-message">ou drag & drop</span>
-                        <input id="attachement-document" class="import-excel" name="attachement-document" type="file" onchange="dargAndDropAttachment()" accept="image/jpeg,image/png,application/pdf">
+                        <input id="attachement-document" class="import-excel" name="attachement-document" type="file" onchange="dargAndDropAttachment()" accept="image/jpeg,image/png,application/pdf,text/xml,application/xml">
                     </div>
                 </div>
                 <br />
@@ -177,11 +177,12 @@ if (isset($document["id"])) {
                 <div class="file-drop-area" style="margin-top:22px;" id="file-document-import">
                     <span class="choose-file-button">Choisissez votre document</span>
                     <span class="file-message">ou drag & drop</span>
-                    <input id="document-import" class="import-excel" name="document-import" type="file" onchange="dargAndDrop()" accept="image/jpeg,image/png,application/pdf" required>
+                    <input id="document-import" class="import-excel" name="document-import" type="file" onchange="dargAndDrop()" accept="image/jpeg,image/png,application/pdf,text/xml,application/xml" required>
                 </div>
                 <br />
             <?php } else {
-                $heigh = (mime_content_type(file::download($files["principal"]["id"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
+                $getMime = mime_content_type(file::download($files["principal"]["id"], DIR_DATAS_DOCS));
+                $heigh = ($getMime == "application/pdf" OR $getMime == "text/xml" OR $getMime == "application/xml") ? "height:110vh;" : NULL;
                 echo '  <div style="margin-top:22px;">
                         <embed src="/document.php?id=' . $files["principal"]["id"] . '" style="width:100%; margin-top:10px;' . $heigh . '" /></embed>
                     </div><br />