2121use Models \Clause ;
2222use Models \Module ;
2323use Models \View ;
24+ use Doctrine \SqlFormatter \SqlFormatter ;
2425
2526include_once __DIR__ .'/../../core.php ' ;
2627
7172if ($ options != '' && $ options != 'menu ' && $ options != 'custom ' ) {
7273 $ module_query = Util \Query::getQuery (Module::find ($ id_record ));
7374
74- $ beautiful_query = nl2br (htmlentities ((string ) $ module_query ));
75- $ beautiful_query = str_replace (' ' , ' ' , $ beautiful_query );
75+ // Utilizzo di SqlFormatter per formattare e colorare la query
76+ $ sqlFormatter = new SqlFormatter ();
77+ $ beautiful_query = $ sqlFormatter ->highlight ($ module_query );
78+
79+ // Salva la query originale (senza formattazione HTML) per il copia-incolla
80+ $ original_query = (string ) $ module_query ;
7681
7782 echo '
7883 <div class="row">
7984 <div class="col-md-12">
80- <p><strong> ' .tr ('Query risultante ' ).':</strong></p>
81- <div class="well"> ' .$ beautiful_query .'</div>
85+ <p><strong> ' .tr ('Query risultante ' ).':</strong>
86+ <button type="button" class="btn btn-sm btn-info" id="copy-query-btn" title=" ' .tr ('Copia query ' ).'">
87+ <i class="fa fa-copy"></i>
88+ </button>
89+ </p>
90+ <div class="sql-formatted well"> ' .$ beautiful_query .'</div>
91+ <textarea id="query-to-copy" style="position: absolute; left: -9999px;"> ' .$ original_query .'</textarea>
8292
8393 <div class="row">
8494 <div class="col-md-12 text-right">
129139
130140 </div>
131141</div> ' ;
132-
133- echo '
134- <script>
135- function testQuery(){
136- $("#main_loading").fadeIn();
137-
138- $.ajax({
139- url: " ' .base_path ().'/actions.php?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&op=test",
140- cache: false,
141- type: "post",
142- processData: false,
143- contentType: false,
144- dataType : "html",
145- success: function(data) {
146- $("#main_loading").fadeOut();
147-
148- if (data == "ok"){
149- swal(" ' .tr ('Query funzionante ' ).'", " ' .tr ('La query attuale funziona correttamente! ' ).'", "success");
150- } else {
151- swal(" ' .tr ('Errore ' ).'", data, "error");
152- }
153- }
154- })
155- }
156- </script> ' ;
157142}
143+
144+ // Traduzioni per JavaScript
145+ echo '<script>
146+ if (typeof globals.translations === "undefined") {
147+ globals.translations = {};
148+ }
149+ globals.translations.copied = " ' .tr ('Copiato! ' ).'";
150+ globals.translations.query_copied = " ' .tr ('La query è stata copiata negli appunti ' ).'";
151+ globals.translations.working_query = " ' .tr ('Query funzionante ' ).'";
152+ globals.translations.query_works_correctly = " ' .tr ('La query attuale funziona correttamente! ' ).'";
153+ globals.translations.error = " ' .tr ('Errore ' ).'";
154+ </script>
155+ <link rel="stylesheet" href=" ' .base_path ().'/modules/viste/css/main.css">
156+ <script src=" ' .base_path ().'/modules/viste/js/main.js"></script>
157+ ' ;
0 commit comments