<?php
setlocale(LC_ALL, array(
    'it_IT.UTF-8',
    'it_IT@euro',
    'it_IT',
    'italian'
));
// Free PHP File Directory Listing Script - Version 1.4 - HalGatewood.com
// Edited for AVCP/ANAC XML compatiblity by MARCO MILESI - WPGOV - wpgov.it

?>
<!DOCTYPE html>
<html>

<head>
    <title>ANAC XML</title>
<?php 
$urlcompleto = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url         = substr_replace($urlcompleto, "", -5); 
?>
    <style>
        body { font-family: 'Open Sans', sans-serif; padding: 0; margin: 0; background: #f5f5f5 url('<?php echo $url; ?>wp-content/plugins/avcp/includes/bandieraitaliana.png') no-repeat center; }
        .wrap { width: 515px; margin: 4em auto 1em auto; background: white; padding: 25px; border: solid 1px #ECE9E9; -moz-border-radius: 10px; -webkit-border-radius: 10px; }
        h1 { margin: 0 0 5px 0; font-size:120%; font-weight:normal; color: #666; }
        h2 { margin: 0; font-size: 1.2em; }
        a { color: #399ae5; text-decoration: none; } a:hover { color: #206ba4; text-decoration: underline; }
        .note { padding:  0 5px 25px 0; font-size:80%; color: #666; line-height: 18px; }
        .media_block { clear: both;  min-height: 50px; padding: 10px 15px; border-top: solid 1px #ECE9E9; }
        .media_block_filebox { float:left; width: 44%; min-height: 50px; padding: 20px 15px; border-top: solid 1px #ECE9E9; }
        .media_block_date { margin-top: 4px; font-size: 70%; color: #666; }
        .jpg, .jpeg, .gif, .png { background-position: -50px 0 !important; }
        .pdf { background-position: -100px 0 !important; }
        .txt, .rtf { background-position: -150px 0 !important; }
        .xls, .xlsx { background-position: -200px 0 !important; }
        .ppt, .pptx { background-position: -250px 0 !important; }
        .doc, .docx { background-position: -300px 0 !important; }
        .zip, .rar, .tar, .gzip { background-position: -350px 0 !important; }
        .swf { background-position: -400px 0 !important; }
        .fla { background-position: -450px 0 !important; }
        .mp3 { background-position: -500px 0 !important; }
        .wav { background-position: -550px 0 !important; }
        .mp4 { background-position: -600px 0 !important; }
        .mov, .aiff, .m2v, .avi, .pict, .qif { background-position: -650px 0 !important; }
        .wmv, .avi, .mpg { background-position: -700px 0 !important; }
        .flv, .f2v { background-position: -750px 0 !important; }
        .psd { background-position: -800px 0 !important; }
        .ai { background-position: -850px 0 !important; }
        .html, .xhtml, .dhtml, .php, .asp, .css, .js, .inc { background-position: -900px 0 !important; }
        .dir { background-position: -950px 0 !important; }
        div.clear {
            clear:both;
        }
    </style>
</head>
<body>
    <div class="wrap">
        <div style="float:right;"><small><a href="<?php echo $url; ?>" title="Torna al sito">Torna al Sito</a></small></div>
        <h1><strong>ANAC</strong> XML</h1>
<?php

function cleanTitle($title)
{
    $title = str_replace("-", " ", $title);
    $title = str_replace("_", " ", $title);
    return ucwords($title);
}

function getFileExt($filename)
{
    return substr(strrchr($filename, '.'), 1);
}

function format_size($file)
{
    $bytes = filesize($file);
    if ($bytes < 1024)
        return '<strong>' . $bytes . '</strong> byte';
    elseif ($bytes < 1048576)
        return '<strong>' . round($bytes / 1024, 2) . '</strong> KB';
    elseif ($bytes < 1073741824)
        return '<strong>' . round($bytes / 1048576, 2) . '</strong> MB';
    elseif ($bytes < 1099511627776)
        return '<strong>' . round($bytes / 1073741824, 2) . '</strong> GB';
    else
        return '<strong>' . round($bytes / 1099511627776, 2) . '</strong> TB';
}

// GET FILES AND PUT INTO AN ARRAY
$files = array();
$handle = opendir(dirname(__FILE__));
while (false !== ($file = readdir($handle)))  
    if (!is_dir($file) && getFileExt($file) == "xml") 
        $files[] = $file;
closedir($handle);
natcasesort($files);

foreach ($files as $file) 
{
    echo "<div class=\"media_block_filebox\">";
    echo "    <a href=\"$file\"><img style=\"float: left;\" src=\"" . $url . "wp-content/plugins/avcp/includes/xmlicon.png\"></a>";
    echo "        <div class=\"media_block_file\"><h2><a href=\"$file\">" . basename($file, ".xml") ."</a></h2></div>\n";
    echo "        <div class=\"media_block_date\">" . format_size($file) . "<br>" . ucwords(strftime("%d %B %Y", filemtime($file))) . "</div>\n";
    echo "</div>";
}
echo "<div class='clear'></div>"; 
?>
    </div>
    <center>
    <a href="https://wpgov.it"  target="_blank" title="WP Gov"><small>powered by</small><br><img src="<?php echo $url; ?>wp-content/plugins/avcp/includes/wpgov_icon.png"></a><br>

    <small style="display: none;">Software pubblicazione bandi di gara e generazione dataset ANAC/AVCP realizzato da <a href="http://www.marcomilesi.ml" target="_blank">Marco Milesi</a></small>

    </center>
</body>
</html>