'all'), $atts));
ob_start();
anacxmlviewer_generatabella($id);
$anacxmlshortcode = ob_get_clean();
return $anacxmlshortcode;
} );
add_shortcode('wpgov-xmlviewer', function($atts) {
extract(shortcode_atts(array('id' => 'all'), $atts));
ob_start();
anacxmlviewer_generatabella($id);
$anacxmlshortcode = ob_get_clean();
return $anacxmlshortcode;
} );
add_filter('user_can_richedit', function($default) {
global $post;
if ('anac-xml-view' == get_post_type($post)) {
add_filter('quicktags_settings', 'anacxmlviewer_47010');
wp_deregister_script('postbox');
remove_action('media_buttons', 'media_buttons');
return false;
}
return $default;
});
function anacxmlviewer_47010($qtInit) {
$qtInit['buttons'] = 'fullscreen';
return $qtInit;
}
add_action('add_meta_boxes', function() {
add_meta_box('anacxmlviewer_info', ' ', 'anacxmlviewer_metabox_callback', 'anac-xml-view', 'side', 'high');
});
function anacxmlviewer_metabox_callback ($post, $metabox) {
global $post;
echo '
Puoi visualizzare la tabella con
[anac-xml id="' . $post->ID . '"]
';
}
function add_anacxmlviewer_table_box() {
add_meta_box('anacxmlviewer_table', 'Anteprima tabella', 'anacxmlviewer_table_callback', 'anac-xml-view', 'normal', 'default');
}
function anacxmlviewer_table_callback($post, $metabox) {
anacxmlviewer_generatabella($post->ID);
}
function anacxmlviewer_generatabella($id) {
remove_filter('the_content', 'wpautop');
if (get_post_field('post_content', $id) == null) {
return;
}
$time_start = microtime(true);
//$xml_file = $_SERVER['DOCUMENT_ROOT'] . parse_url(stripslashes(get_post_field('post_content', $id)), PHP_URL_PATH);
if ( substr( get_post_field('post_content', $id), 0, 4 ) === "http" ) {
$gare_xml = new SimpleXMLElement( get_post_field('post_content', $id), LIBXML_NOCDATA, true);
} else {
$gare_xml = new SimpleXMLElement(stripslashes(get_post_field('post_content', $id)));
}
echo '';
echo '
' . $gare_xml->metadata->entePubblicatore . 'Aggiornato al ' . date("d.m.Y", strtotime($gare_xml->metadata->dataUltimoAggiornamentoDataset)) . '
URL originale: ' . $gare_xml->metadata->urlFile . '
|
Bandi di gara - '.$gare_xml->metadata->annoRiferimento.'
|
| CIG |
Oggetto |
Importo aggiudicazione |
Importo somme liquidate |
Data inizio Data fine |
';
$tot_agg = 0.00;
$tot_liq = 0.00;
$tot_lotti = 0;
foreach ($gare_xml->xpath('//lotto') as $lotto) {
$tot_agg += (double)$lotto->importoAggiudicazione;
$tot_liq += (double)$lotto->importoSommeLiquidate;
$tot_lotti++;
if ($a == '') {
$a = ' class="alternate"';
} else {
$a = '';
}
if ( $lotto->tempiCompletamento->dataInizio ) {
$dataInizio = date("d/m/Y", strtotime($lotto->tempiCompletamento->dataInizio));
} else { $dataInizio = 'N.D.'; }
if ( $lotto->tempiCompletamento->dataUltimazione ) {
$dataUltimazione = date("d/m/Y", strtotime($lotto->tempiCompletamento->dataUltimazione));
} else { $dataUltimazione = 'N.D.'; }
echo '
|
' . $lotto->oggetto . ' |
' . number_format((double)$lotto->importoAggiudicazione, 2, ',', '.') . ' |
' . number_format((double)$lotto->importoSommeLiquidate, 2, ',', '.') . ' |
' . $dataInizio . ' ' . $dataUltimazione . ' |
| ' . $lotto->sceltaContraente . ' Partecipanti: ';
foreach ($lotto->partecipanti->partecipante as $partecipante) {
echo $partecipante->ragioneSociale . ' (' . $partecipante->codiceFiscale . ') ';
}
echo 'Aggiudicatari: ';
foreach ($lotto->aggiudicatari->aggiudicatario as $aggiudicatario) {
echo $aggiudicatario->ragioneSociale . ' (' . $aggiudicatario->codiceFiscale . ') ';
}
echo ' |
';
}
echo '
| Totali |
Numero Lotti: '. number_format((double)$tot_lotti, 0, ',', '.') . ' |
'. number_format((double)$tot_agg, 2, ',', '.') . ' |
'. number_format((double)$tot_liq, 2, ',', '.') . ' |
|
Tabella generata in ' . number_format( microtime(true) - $time_start, 3) . ' secondi
|
';
echo 'Scarica in
';
echo ' |
';
echo '
';
echo '
';
?>
query_vars['post_type']) && $wp->query_vars['post_type'] == 'anac-xml-view') {
if (have_posts()) {
add_filter('the_content', 'anacxmlviewer_template_filter');
} else {
$wp_query->is_404 = true;
}
}
}
function anacxmlviewer_template_filter($content) {
global $wp_query;
ob_start();
anacxmlviewer_generatabella($wp_query->post->ID);
$anacxmlshortcode = ob_get_clean();
return $anacxmlshortcode;
}
?>