PluginProbe
ANAC XML Bandi di Gara / 7.7.3
ANAC XML Bandi di Gara v7.7.3
7.8 trunk 0.1 1.0.0.1 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.1.1 1.1.2 2.0 2.0.1 2.0.2 2.0.3 2.1 2.2 2.3 2.3.1 3 3.0.1 3.1 3.1.1 3.1.2 3.1.3 All 57 releases
avcp / valid_page.php

valid_page.php in ANAC XML Bandi di Gara 7.7.3, at valid_page.php

419 lines 25.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function avcp_v_dataset_load() {
4 // Handle XML generation and log reset with nonce checks
5 if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
6 if ( isset( $_POST['avcp_xmlgen_nonce'] ) && wp_verify_nonce( $_POST['avcp_xmlgen_nonce'], 'avcp_xmlgen_action' ) ) {
7 $terms = get_terms( 'annirif', array('hide_empty' => 0) );
8 foreach ( $terms as $term ) {
9 if ( isset( $_POST['XMLGEN_' . $term->name] ) ) {
10 creafilexml( $term->name );
11 echo '<div class="notice notice-success is-dismissible"><p>';
12 printf( esc_html__( 'Il seguente file .xml è generato: %s', 'avcp' ), '<b>' . esc_html( $term->name ) . '</b>' );
13 echo "</p></div>";
14 break;
15 }
16 }
17 }
18 if ( isset( $_POST['avcp_reset_log_nonce'] ) && wp_verify_nonce( $_POST['avcp_reset_log_nonce'], 'avcp_reset_log_action' ) && isset( $_POST['AVCP-RESET-LOG'] ) ) {
19 delete_option( 'anac_log' );
20 echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Log eliminati', 'avcp' ) . '</p></div>';
21 }
22 }
23
24 $basexmlurl = avcp_get_basexmlurl();
25 ?>
26 <style>
27 /* Table header improvements */
28 table.widefat thead th {
29 background: #f3f4f5;
30 color: #23282d;
31 font-weight: 600;
32 text-align: left;
33 border-bottom: 2px solid #ccd0d4;
34 padding: 10px 8px;
35 }
36 table.widefat td {
37 padding: 8px;
38 vertical-align: top;
39 }
40 /* Responsive table */
41 @media (max-width: 900px) {
42 table.widefat, table.widefat thead, table.widefat tbody, table.widefat th, table.widefat td, table.widefat tr {
43 display: block;
44 }
45 table.widefat thead {
46 display: none;
47 }
48 table.widefat tr {
49 margin-bottom: 15px;
50 }
51 table.widefat td {
52 border: none;
53 position: relative;
54 padding-left: 50%;
55 }
56 table.widefat td:before {
57 position: absolute;
58 left: 10px;
59 width: 45%;
60 white-space: nowrap;
61 font-weight: bold;
62 }
63 table.widefat td:nth-of-type(1):before { content: "<?php esc_html_e('Anno', 'avcp'); ?>"; }
64 table.widefat td:nth-of-type(2):before { content: "<?php esc_html_e('Validazione XSD', 'avcp'); ?>"; }
65 table.widefat td:nth-of-type(3):before { content: "<?php esc_html_e('Versione XSD', 'avcp'); ?>"; }
66 table.widefat td:nth-of-type(4):before { content: "<?php esc_html_e('Validazione software', 'avcp'); ?>"; }
67 table.widefat td:nth-of-type(5):before { content: "<?php esc_html_e('Data generazione', 'avcp'); ?>"; }
68 table.widefat td:nth-of-type(6):before { content: "<?php esc_html_e('Azione', 'avcp'); ?>"; }
69 }
70 /* Log styling */
71 .avcp-log-list {
72 background: #fff;
73 border: 1px solid #ccd0d4;
74 padding: 10px;
75 max-height: 200px;
76 overflow-y: auto;
77 font-family: monospace;
78 font-size: 13px;
79 margin: 0;
80 white-space: pre-line;
81 }
82 </style>
83 <div class="wrap">
84 <h1><?php esc_html_e( 'Validazione', 'avcp' ); ?></h1>
85 <div class="notice notice-info" style="padding:20px;">
86 <?php esc_html_e( 'Nota: il controllo tecnico non attesta la correttezza dei dati.', 'avcp' ); ?><br>
87 <?php esc_html_e( 'Puoi controllare online i dataset con un', 'avcp' ); ?>
88 <a href="https://anac.softcare.it/Validator" target="_blank" rel="noopener"><?php esc_html_e( 'validatore esterno', 'avcp' ); ?></a>
89 <br><br>
90 <?php esc_html_e( "L'archivio dei documenti XML generati è disponibile qui:", 'avcp' ); ?>
91 <a href="<?php echo esc_url( $basexmlurl ); ?>" target="_blank" rel="noopener"><?php echo esc_html( $basexmlurl ); ?></a>
92 <br><br>
93 <strong><?php esc_html_e( 'Risorse utili:', 'avcp' ); ?></strong><br>
94 📖 <a href="<?php echo esc_url( 'https://github.com/WPGov/avcp/wiki' ); ?>" target="_blank" rel="noopener"><?php esc_html_e( 'Documentazione e Wiki', 'avcp' ); ?></a> |
95 💻 <a href="<?php echo esc_url( 'https://github.com/WPGov/avcp' ); ?>" target="_blank" rel="noopener"><?php esc_html_e( 'Repository GitHub', 'avcp' ); ?></a>
96 </div>
97
98 <div id="poststuff">
99 <div id="post-body" class="metabox-holder columns-2">
100 <div id="post-body-content">
101 <div class="meta-box-sortables">
102 <div class="inside">
103 <?php
104 // Check for posts without year (annirif) and collect them
105 $offending_posts = array();
106 $post_ids = get_posts( array(
107 'post_type' => 'avcp',
108 'posts_per_page' => -1,
109 'fields' => 'ids',
110 'post_status' => 'any',
111 ) );
112 if ( ! empty( $post_ids ) ) {
113 foreach ( $post_ids as $post_id ) {
114 if ( !has_term( '', 'annirif', $post_id ) ) {
115 $offending_posts[] = $post_id;
116 }
117 }
118 }
119 if ( count( $offending_posts ) > 0 ) {
120 $message = sprintf( esc_html__( 'Ci sono %d gare registrate senza anno di riferimento da correggere!', 'avcp' ), number_format_i18n( count( $offending_posts ) ) );
121 echo '<div class="notice notice-error"><p><strong>' . esc_html( $message ) . '</strong></p>';
122 echo '<ul style="margin:8px 0 12px 18px;">';
123 foreach ( $offending_posts as $id ) {
124 $title_esc = esc_html( get_the_title( $id ) );
125 if ( !$title_esc ) {
126 $title_esc = esc_html__( '(Nessun titolo)', 'avcp' );
127 }
128 echo '<li><a href="' . get_edit_post_link( $id ) . '">' . $title_esc . '</a></li>';
129 }
130 echo '</ul></div>';
131 }
132
133 // Check for 'ditte' terms missing 'avcp_codice_fiscale' term meta and collect them $offending_ditte = array();
134 $ditte_terms = get_terms( array(
135 'taxonomy' => 'ditte',
136 'hide_empty' => false,
137 ) );
138 if ( ! is_wp_error( $ditte_terms ) && ! empty( $ditte_terms ) ) {
139 foreach ( $ditte_terms as $dterm ) {
140 $codice = get_term_meta( $dterm->term_id, 'avcp_codice_fiscale', true );
141 if ( empty( $codice ) ) {
142 $offending_ditte[] = $dterm->term_id;
143 }
144 }
145 }
146 if ( count( $offending_ditte) > 0 ) {
147 $msg2 = sprintf( esc_html__( 'Ci sono %d ditte senza codice fiscale da correggere!', 'avcp' ), number_format_i18n( count( $offending_ditte) ) );
148 echo '<div class="notice notice-error"><p><strong>' . esc_html( $msg2 ) . '</strong></p>';
149 echo '<ul style="margin:8px 0 12px 18px;">';
150 foreach ( $offending_ditte as $id ) {
151 $name_esc = esc_html( get_term( $id )->name );
152 if ( !$name_esc ) {
153 $name_esc = esc_html__( '(Nessun nome)', 'avcp' );
154 }
155 $link_esc = esc_url( get_edit_term_link( $id, 'ditte' ) );
156 echo '<li><a href="' . $link_esc . '">' . $name_esc . '</a></li>';
157 }
158 echo '</ul></div>';
159 }
160 $terms = get_terms( 'annirif', array('hide_empty' => 0) );
161 ?>
162 <form method="post" style="overflow-x: auto;">
163 <?php wp_nonce_field( 'avcp_xmlgen_action', 'avcp_xmlgen_nonce' ); ?>
164 <table class="widefat striped">
165 <thead>
166 <tr>
167 <th><?php esc_html_e( 'Anno', 'avcp' ); ?></th>
168 <th><?php esc_html_e( 'Validazione XSD', 'avcp' ); ?> <span class="dashicons dashicons-info" title="<?php esc_attr_e( 'Verifica che il file xml sia tecnicamente corretto alle specifiche XSD', 'avcp' ); ?>"></span></th>
169 <th><?php esc_html_e( 'Versione XSD', 'avcp' ); ?></th>
170 <th><?php esc_html_e( 'Validazione software', 'avcp' ); ?> <span class="dashicons dashicons-info" title="<?php esc_attr_e( 'Verifiche aggiuntive del plugin WordPress per il controllo di alcuni campi, come ad esempio le date', 'avcp' ); ?>"></span></th>
171 <th><?php esc_html_e( 'Data generazione', 'avcp' ); ?></th>
172 <th><?php esc_html_e( 'Azione', 'avcp' ); ?></th>
173 </tr>
174 </thead>
175 <tbody>
176 <?php
177 foreach ( $terms as $term ) {
178 $file_exists = file_exists( avcp_get_basexmlpath( $term->name ) );
179 if ( ! $file_exists && $term->name < date('Y') - 2 ) {
180 continue;
181 }
182 echo '<tr>';
183 echo '<td>' . esc_html( $term->name ) . ' <a href="' . esc_url( avcp_get_basexmlurl( $term->name ) ) . '" target="_blank" title="' . esc_attr( $term->name ) . '"><span class="dashicons dashicons-external"></span></a></td>';
184
185 // XSD version
186 if ( $term->name >= 2021 ) {
187 $xsd_dir = '1_3';
188 $xsd_ver = 'v 1.3';
189 } elseif ( $term->name >= 2019 ) {
190 $xsd_dir = '1_1';
191 $xsd_ver = 'v 1.1';
192 } else {
193 $xsd_dir = '1_0';
194 $xsd_ver = 'v 1.0';
195 }
196
197 // XSD validation
198 echo '<td>';
199 $errors = false;
200 if ( $file_exists ) {
201 $xml = new DOMDocument();
202 $xml->load( avcp_get_basexmlpath( $term->name ) );
203 if ( $xml->schemaValidate( ABSPATH . '/wp-content/plugins/avcp/includes/XSD/' . $xsd_dir . '/datasetAppaltiL190.xsd' ) ) {
204 echo '<span class="dashicons dashicons-yes" title="' . esc_attr__( 'Corretto', 'avcp' ) . '"></span>';
205 } else {
206 echo '<span class="dashicons dashicons-dismiss" title="' . esc_attr__( 'Trovati errori', 'avcp' ) . '"></span>';
207 $errors = libxml_get_errors();
208 }
209 }
210 echo '</td>';
211
212 echo '<td>' . esc_html( $xsd_ver ) . '</td>';
213
214 // Software validation
215 echo '<td>';
216 if ( $file_exists ) {
217 $args = array(
218 'post_type' => 'avcp',
219 'tax_query' => array(
220 array(
221 'taxonomy' => 'annirif',
222 'field' => 'name',
223 'terms' => $term->name,
224 ),
225 ),
226 'posts_per_page' => -1,
227 );
228 $query = new WP_Query( $args );
229 $error = false;
230 if ( $query->have_posts() ) {
231 foreach ( $query->posts as $post ) {
232 $datainizio = get_post_meta( $post->ID, 'avcp_data_inizio', true );
233 $datafine = get_post_meta( $post->ID, 'avcp_data_fine', true );
234 if ( empty( $datainizio ) || empty( $datafine ) ) {
235 $error = true;
236 echo '<span class="notice-error" style="background-color:red;color:white;padding:2px;">' . esc_html__( 'Errore campo data', 'avcp' ) . '</span><br><a href="' . esc_url( get_edit_post_link( $post->ID ) ) . '">' . esc_html( get_the_title( $post->ID ) ) . '</a><hr>';
237 }
238 if ( strlen( get_the_title( $post->ID ) ) >= 250 ) {
239 $error = true;
240 echo '<span class="notice-error" style="background-color:red;color:white;padding:2px;">' . esc_html__( 'Titolo oltre 250 caratteri', 'avcp' ) . '</span><br><a href="' . esc_url( get_edit_post_link( $post->ID ) ) . '">' . esc_html( get_the_title( $post->ID ) ) . '</a><hr>';
241 }
242 }
243 }
244 if ( ! $error ) {
245 echo '<span class="dashicons dashicons-yes"></span>';
246 }
247 }
248 echo '</td>';
249
250 // Generation date
251 echo '<td>' . ( $file_exists && filemtime( avcp_get_basexmlpath( $term->name ) ) ? esc_html( date( "d/m/Y H:i", filemtime( avcp_get_basexmlpath( $term->name ) ) ) ) : '-' ) . '</td>';
252
253 // Action
254 echo '<td>';
255 if ( $term->name >= date('Y') - 2 ) {
256 echo '<input type="submit" class="button button-primary" name="XMLGEN_' . esc_attr( $term->name ) . '" value="' . esc_attr__( 'Genera', 'avcp' ) . '" />';
257 }
258 echo '</td>';
259 echo '</tr>';
260
261 // XSD errors
262 if ( $errors ) {
263 echo '<tr><td colspan="6">';
264 foreach ( $errors as $err ) {
265 print esc_html( libxml_display_error( $err ) );
266 }
267 libxml_clear_errors();
268 echo '</td></tr>';
269 }
270 }
271 ?>
272 </tbody>
273 </table>
274 </form>
275 </div>
276 </div>
277 </div>
278 <!-- Sidebar -->
279 <div id="postbox-container-1" class="postbox-container">
280 <div class="meta-box-sortables">
281 <div class="postbox">
282 <h2><span><?php esc_html_e( 'Stato server', 'avcp' ); ?></span></h2>
283 <div class="inside">
284 <p>
285 <?php
286 $dir = avcp_get_basexmlpath();
287 $file = $dir . '/index.php';
288 $system_ok = true;
289 if ( is_dir( $dir ) ) {
290 echo esc_html__( 'Presenza cartella /avcp', 'avcp' ) . '<span style="color:green;font-weight:bold;">: OK</span>';
291 } else {
292 echo esc_html__( 'Presenza cartella /avcp', 'avcp' ) . '<span style="color:red;font-weight:bold;">: NON TROVATA</span>';
293 $system_ok = false;
294 }
295 echo '<br/>';
296 if ( is_writable( $dir ) ) {
297 echo esc_html__( 'Permessi scrittura cartella /avcp', 'avcp' ) . '<span style="color:green;font-weight:bold;">: OK</span>';
298 } else {
299 echo esc_html__( 'Permessi scrittura cartella /avcp', 'avcp' ) . '<span style="color:red;font-weight:bold;">: NON CORRISPONDENTI</span>';
300 $system_ok = false;
301 }
302 echo '<br/>';
303 if ( file_exists( $file ) ) {
304 echo esc_html__( 'Presenza index.php /avcp', 'avcp' ) . '<span style="color:green;font-weight:bold;">: OK</span>';
305 } else {
306 echo esc_html__( 'Presenza index.php /avcp', 'avcp' ) . '<span style="color:red;font-weight:bold;">: NON TROVATO</span>';
307 $system_ok = false;
308 }
309 echo '<br/>';
310
311 $urlcheck = get_site_url() . '/avcp/index.php';
312 $agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; pt-pt) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27";
313 if ( is_callable( 'curl_init' ) ) {
314 $ch = curl_init();
315 curl_setopt( $ch, CURLOPT_URL, $urlcheck );
316 curl_setopt( $ch, CURLOPT_USERAGENT, $agent );
317 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
318 curl_setopt( $ch, CURLOPT_VERBOSE, false );
319 curl_setopt( $ch, CURLOPT_TIMEOUT, 5 );
320 curl_exec( $ch );
321 $httpcode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
322 curl_close( $ch );
323 if ( $httpcode == 200 ) {
324 echo esc_html__( 'Test Accesso pubblico /avcp', 'avcp' ) . '<span style="color:green;font-weight:bold;">: OK [200]</span>';
325 } elseif ( $httpcode == 500 ) {
326 echo esc_html__( 'Test Accesso pubblico /avcp', 'avcp' ) . '<span style="color:red;font-weight:bold;">: ERRORE 500 ISE</span>';
327 $headers = @get_headers( $urlcheck );
328 echo ' - ' . esc_html( @$headers[0] );
329 $system_ok = false;
330 } else {
331 echo esc_html__( 'Test Accesso pubblico /avcp', 'avcp' ) . '<span style="color:red;font-weight:bold;">: ERRORE ' . esc_html( $httpcode ) . '</span>';
332 $headers = @get_headers( $urlcheck );
333 echo ' - ' . esc_html( @$headers[0] );
334 $system_ok = false;
335 }
336 } else {
337 echo esc_html__( 'Test Accesso pubblico /avcp', 'avcp' ) . '<span style="color:red;font-weight:bold;">: CURL_INIT MANCANTE</span>';
338 $system_ok = false;
339 }
340 if ( $system_ok ) {
341 echo '<hr><center>' . esc_html__( 'Nessun problema trovato.', 'avcp' ) . '</center>';
342 } else {
343 echo '<div class="notice notice-error"><p>' . esc_html__( 'Sono stati trovati alcuni problemi critici. Affinchè AVCP funzioni correttamente è necessario risolvere al più presto questi problemi.', 'avcp' ) . '</p></div>';
344 }
345 ?>
346 </p>
347 </div>
348 </div>
349 </div>
350 <div class="meta-box-sortables">
351 <div class="postbox">
352 <h2>
353 <form method="post" style="display:inline;">
354 <?php wp_nonce_field( 'avcp_reset_log_action', 'avcp_reset_log_nonce' ); ?>
355 <input type="submit" class="button button-primary" name="AVCP-RESET-LOG" value="<?php esc_attr_e( 'Pulisci', 'avcp' ); ?>" style="float:right;" />
356 </form>
357 <?php esc_html_e( 'Log', 'avcp' ); ?>
358 </h2>
359 <div class="inside">
360 <?php
361 $log = get_option( 'anac_log' );
362 if ( ! empty( $log ) ) {
363 // Show log as HTML, allowing only safe tags (b, strong, em, a, br)
364 $allowed_tags = array(
365 'b' => array(),
366 'strong' => array(),
367 'em' => array(),
368 'a' => array(
369 'href' => array(),
370 'title' => array(),
371 'target' => array(),
372 'rel' => array(),
373 ),
374 'br' => array(),
375 );
376 echo '<div class="avcp-log-list">' . wp_kses( $log, $allowed_tags ) . '</div>';
377 } else {
378 echo '<div class="avcp-log-list">' . esc_html__( 'Nessun log presente.', 'avcp' ) . '</div>';
379 }
380 ?>
381 </div>
382 </div>
383 </div>
384 </div>
385 <!-- #postbox-container-1 .postbox-container -->
386 </div>
387 <!-- #post-body .metabox-holder .columns-2 -->
388 <br class="clear">
389 </div>
390 <!-- #poststuff -->
391 </div>
392 <?php
393 }
394
395 function libxml_display_error( $error ) {
396 $return = "\n";
397 switch ( $error->level ) {
398 case LIBXML_ERR_WARNING:
399 $return .= "Warning $error->code: ";
400 break;
401 case LIBXML_ERR_ERROR:
402 $return .= "Error $error->code: ";
403 break;
404 case LIBXML_ERR_FATAL:
405 $return .= "Fatal Error $error->code: ";
406 break;
407 }
408 $return .= trim( $error->message );
409 if ( $error->file ) {
410 $return .= " in $error->file";
411 }
412 $return .= " on line $error->line";
413 return $return;
414 }
415
416 // Enable user error handling
417 libxml_use_internal_errors( true );
418 ?>
419