| 1 |
<?php |
| 2 |
add_action('admin_menu', 'avcp_valid_menu'); |
| 3 |
function avcp_valid_menu() |
| 4 |
{ |
| 5 |
add_submenu_page('edit.php?post_type=avcp', 'Validazione Dataset', 'Validazione Dataset', 'manage_options', 'avcp_v_dataset', 'avcp_v_dataset_load'); |
| 6 |
} |
| 7 |
|
| 8 |
function avcp_v_dataset_load() |
| 9 |
{ |
| 10 |
echo '<div class="wrap">'; |
| 11 |
screen_icon(); |
| 12 |
echo '<h2>Validazione Dataset XML</h2><em>Tramite questa pagina puoi verificare se i tuoi dataset xml generati presentano problemi di validazione secondo le specifiche di avcp. Ricorda che questo test non garantisce, e anzi <b>ignora</b>, la completezza o veridicita\' delle informazioni inserite, o di dati omessi.<br/>In particolare, controllare di avere impostato per ogni gara le relative ditte aggiudicatarie.</em>'; |
| 13 |
$terms = get_terms( 'annirif', array('hide_empty' => 0) ); |
| 14 |
foreach ( $terms as $term ) { |
| 15 |
$xml = new DOMDocument(); |
| 16 |
$xml->load(ABSPATH . '/avcp/' . $term->name. '.xml'); |
| 17 |
echo '<hr/><center><h3 style="margin-bottom: 0px;">Dataset Anno ' . $term->name . '</h3><small><a target="_blank" href="' . get_site_url() . '/avcp/' . $term->name. '.xml">' . get_site_url() . '/avcp/' . $term->name. '.xml</a></small></center>'; |
| 18 |
if (!$xml->schemaValidate(ABSPATH . '/wp-content/plugins/avcp/includes/datasetAppaltiL190.xsd')) { |
| 19 |
libxml_display_errors(); |
| 20 |
echo '<br/><center><font style="background-color:red;color:white;padding:2px;border-radius:3px;font-weight:bold;font-family:verdana;">Risolvere i problemi riportati qui sopra, poi procedere con la rigenerazione dei dataset .xml!</font></center>'; |
| 21 |
//check_aggiudicatari($term->name); |
| 22 |
} else { |
| 23 |
echo '<center><br/><font style="background-color:lime;padding:2px;border-radius:3px;font-weight:bold;font-family:verdana;">Validazione sintattica passata!</font></center>'; |
| 24 |
//check_aggiudicatari($term->name); |
| 25 |
} |
| 26 |
} |
| 27 |
echo '</div>'; |
| 28 |
} |
| 29 |
|
| 30 |
function libxml_display_error($error) |
| 31 |
{ |
| 32 |
$return = "<br/>\n"; |
| 33 |
switch ($error->level) { |
| 34 |
case LIBXML_ERR_WARNING: |
| 35 |
$return .= "<b>Warning $error->code</b>: "; |
| 36 |
break; |
| 37 |
case LIBXML_ERR_ERROR: |
| 38 |
$return .= "<b>Error $error->code</b>: "; |
| 39 |
break; |
| 40 |
case LIBXML_ERR_FATAL: |
| 41 |
$return .= "<b>Fatal Error $error->code</b>: "; |
| 42 |
break; |
| 43 |
} |
| 44 |
$return .= trim($error->message); |
| 45 |
if ($error->file) { |
| 46 |
$return .= " in <b>$error->file</b>"; |
| 47 |
} |
| 48 |
$return .= " on line <b>$error->line</b>\n"; |
| 49 |
|
| 50 |
return $return; |
| 51 |
} |
| 52 |
|
| 53 |
function libxml_display_errors() { |
| 54 |
$errors = libxml_get_errors(); |
| 55 |
foreach ($errors as $error) { |
| 56 |
print libxml_display_error($error); |
| 57 |
} |
| 58 |
libxml_clear_errors(); |
| 59 |
} |
| 60 |
// Enable user error handling |
| 61 |
libxml_use_internal_errors(true); |
| 62 |
|
| 63 |
function check_aggiudicatari($anno) { |
| 64 |
|
| 65 |
query_posts( array( 'post_type' => 'avcp', 'annirif' => $anno) ); global $post; |
| 66 |
$checkok = false; |
| 67 |
if ( have_posts() ) : while ( have_posts() ) : the_post(); |
| 68 |
$dittepartecipanti = get_the_terms( $post_id, 'ditte' ); |
| 69 |
$cats = get_post_meta($post_id,'avcp_aggiudicatari',true); |
| 70 |
if(is_array($dittepartecipanti)) { |
| 71 |
foreach ($dittepartecipanti as $term) { |
| 72 |
$cterm = get_term_by('name',$term->name,'ditte'); |
| 73 |
$cat_id = $cterm->term_id; //Prende l'id del termine |
| 74 |
$term_meta = get_option( "taxonomy_$cat_id" ); |
| 75 |
$checked = (in_array($cat_id,(array)$cats)? ' checked="checked"': ""); |
| 76 |
if ($checked) { |
| 77 |
$checkok = true; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
endwhile; else: |
| 82 |
$checkok = true; |
| 83 |
endif; |
| 84 |
if ($checkok == false) { |
| 85 |
echo '<center><font style="background-color:red;color:white;padding:2px;border-radius:3px;font-weight:bold;font-family:verdana;">AGGIUDICATARI MANCANTI</font></center>'; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
?> |