<?php

require '../Functions/mysql_fun.php';
require '../Functions/page_builder.php';
require '../Functions/urlLab.php';
session_start();
$absurl = urlbasesito();
if (empty($_SESSION['user'])) {
    header("Location: {$absurl}/error.php");
} else {
    $id = $_GET['id'];
    $id = mysql_escape_string($id);
    $conn = sql_conn();
    $query = "SELECT f.CodAuto, f.IdFonte, f.Nome, f.Descrizione, f.Time\n\t\t\tFROM Fonti f\n\t\t\tWHERE f.CodAuto='{$id}'";
    $req = mysql_query($query, $conn) or fail("Query fallita: " . mysql_error($conn));
    $row = mysql_fetch_row($req);
    if ($row[0] == $id) {
        $title = "Dettaglio Fonte - {$row['1']}";
        startpage_builder($title);
        echo <<<END

\t\t\t<div id="content">
\t\t\t\t<h2>Dettaglio - {$row['1']}</h2>
\t\t\t\t<dl class="widget">
END;
        $heads = array('', 'IdFonte:', 'Nome:', 'Descrizione:');
        for ($i = 1; $i < 4; $i++) {
            echo <<<END

\t\t\t\t\t<dt class="widget-title">{$heads[$i]}</dt>
END;
function endpage_builder()
{
    $absurl = urlbasesito();
    echo <<<END

\t\t\t<div id="push"></div>
\t\t</div>
END;
    if ($_SERVER['PHP_SELF'] != "{$absurl}/index.php" && !empty($_SESSION['user'])) {
        echo <<<END

\t\t<footer class="site-footer footer-color-pers" role="contentinfo">
\t\t\t<div class="site-info">
\t\t\t\t<p>Pragma</p>
\t\t\t</div>
\t\t</footer>
\t\t<p id="backTop" class="back-top">
\t\t\t<a rel="nofollow" class="back-top-a-color-pers" href="#top"></a>
\t\t</p>
\t\t<script type="text/javascript" src="{$absurl}/script.js"></script>
END;
    }
    echo <<<END

\t</body>
</html>
END;
}