<?php 
/* ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); */ 

include_once("../../include/config.php");
include_once($Root."/include/funzioni.php");
include_once($Root."/include/connessione.php");

// Controllo di accesso
include($Root."/sessioni/controlla_permesso_segnalazioni_anonime.php");

$id_ente_anonimo = $enti_stat[$_SERVER["HTTP_HOST"]];

$utente = Utente::selezionaAnonimo($id_ente_anonimo, "00000000000000000000");
$_SESSION["ID_UTENTE"] = $utente->id;

$ente = Ente::seleziona("id", $id_ente_anonimo);

$msg = "";
$id_elemento = "";
$errore = "";
$recaptcha_error = "";

if (isset($_REQUEST["form_inserisci"]) && $_REQUEST["form_inserisci"] == "true") {

    // =============================================
    // VALIDAZIONE PROTEZIONI ANTI-BOT
    // =============================================
    
    $errore_validazione = false;
    
    // csrf_token
    if (!isset($_POST["csrf_token"]) || $_POST["csrf_token"] !== $_SESSION['csrf_token']) {
        $errore = "si";
        $recaptcha_error = "Token di sicurezza non valido. Ricarica la pagina e riprova.";
        $errore_validazione = true;
    }
    
    // honeypot
    if (!$errore_validazione && !empty($_POST["honeypot"])) {
        $errore = "si";
        $recaptcha_error = "Bot rilevato. Se sei umano, ricarica la pagina e riprova.";
        $errore_validazione = true;
    }
    
    // tempo
    if (!$errore_validazione) {
        $tempo_compilazione = time() - $_SESSION['form_start_time'];
        $tempo_minimo = 5;
        
        if ($tempo_compilazione < $tempo_minimo) {
            $errore = "si";
            $recaptcha_error = "Compilazione troppo rapida. Prenditi il tempo necessario per compilare il form.";
            $errore_validazione = true;
        }
    }
    
    // matematico
    if (!$errore_validazione) {
        if (!isset($_POST["captcha"]) || $_POST["captcha"] != $_SESSION['captcha_result']) {
            $errore = "si";
            $recaptcha_error = "Risultato del calcolo matematico errato. Riprova.";
            $errore_validazione = true;
        }
    }
    
    // js_enabled
    if (!$errore_validazione) {
        if (!isset($_POST['js_enabled']) || $_POST['js_enabled'] != '1') {
            $errore = "si";
            $recaptcha_error = "Il tuo browser non supporta JavaScript o è disabilitato.";
            $errore_validazione = true;
        }
    }
    
    // HTTP_USER_AGENT
    if (!$errore_validazione) {
        $user_agent = $_SERVER['HTTP_USER_AGENT'];
        if (empty($user_agent) || strlen($user_agent) < 10) {
            $errore = "si";
            $recaptcha_error = "User agent non valido.";
            $errore_validazione = true;
        }
    }
    

    if ($errore != "si") {

        $_REQUEST["status"] = "inviato";

        $_REQUEST = array_map('recursiveTrim', $_REQUEST);

        if (!isset($Config["segnalazione"]["nome_classe"]) || !class_exists($Config["segnalazione"]["nome_classe"])) {
            throw new Exception("Classe non valida o non trovata: " . $Config["segnalazione"]["nome_classe"]);
        }

        $elemento = new $Config["segnalazione"]["nome_classe"]($_REQUEST);
        $id_elemento = $elemento->inserisciAnonima();

        // Inserimento allegati se presenti
        foreach ($_FILES["allegati"]["name"] as $key => $value) {
            if ($_REQUEST["desc_doc"][$key] == "") $_REQUEST["desc_doc"][$key] = "Documento allegato";
            $allegato = new $Config["allegato"]["nome_classe"]();
            $allegato->inserisci($_REQUEST["desc_doc"][$key], $id_elemento, "segnalazione", $key);
        }

        $segnalazione_temp = Segnalazione::seleziona("id", $id_elemento);
        $codice = $segnalazione_temp->codice;

        // Notifica via mail ai responsabili
        if ($segnalazione_temp->status == "inviato") {
            $dati_mail = array();
            $dati_mail["oggetto"] = "Whistleblowing - Nuova segnalazione inviata";
            $dati_mail["testo"]   = "Gentile Responsabile, una nuova segnalazione anonima è stata inviata al portale " . $_SERVER['HTTP_HOST'] . ".\n\nPer prenderne visione sarà necessario eseguire il login, utilizzando i propri parametri di accesso.\n\nCordiali saluti\n";
            $dati_mail["intestazioni"] = "From: " . $Mittente . " <" . $Casella_postale . "> \nX-Mailer: PHP/" . phpversion();

            $configurazione = Configurazione::selezionaDaIdEnteCodice($_SESSION["ID_ENTE"], "invia-notifiche");
            if ($configurazione->valore == "s") {
                $responsabili = Utente::selezionaEmailResponsabili();
                foreach ($responsabili as $key => $email_responsabile) {
                    $dati_mail["destinatario"] = $email_responsabile;
                    Utente::inviaMail($dati_mail);
                }
            }
        }

        $msg = $Config["segnalazione"]["msg_inviata_anonima"] . '<div align="center"><span class="codice-segnalazione">' . $codice . '</span></div>';
        

        $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
        
       
        $_SESSION['form_start_time'] = time();
    }
}

// CSRF 
if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}

// tempo di inizio
if (!isset($_SESSION['form_start_time']) || !isset($_REQUEST["form_inserisci"])) {
    $_SESSION['form_start_time'] = time();
}

// mat
$_SESSION['captcha_num1'] = rand(1, 9);
$_SESSION['captcha_num2'] = rand(1, 9);
$_SESSION['captcha_result'] = $_SESSION['captcha_num1'] + $_SESSION['captcha_num2'];

echo "<script>console.log('Captcha: " . $_SESSION['captcha_num1'] . " + " . $_SESSION['captcha_num2'] . " = " . $_SESSION['captcha_result'] . "');</script>";

include($Root . "/layout/top-app.php");
?>

<script type="text/javascript">


document.addEventListener('DOMContentLoaded', function() {
    // JavaScript
    var jsField = document.getElementById('js_enabled');
    if (jsField) {
        jsField.value = '1';
    }
    
    // csrf_token
    var csrfField = document.getElementById('csrf_token');
    if (csrfField && csrfField.value == '') {
        alert('Errore: Token di sicurezza mancante. Ricarica la pagina.');
    }
});

function setNomeFile(nomeFile, i) {
    document.getElementById('nomeDelFile[' + i + ']').value = nomeFile;
}

$(function() {
    var addDiv = $('#addinput');
    var i = $('#addinput p').size() + 1;

    $('#addNew').live('click', function() {
        $('<p class="uploadallegati">'
            + '<span id="errore_formato[' + i + ']" class="form-error" style="display:none"></span>'
            + '<input type="text" id="nomeDelFile[' + i + ']" name="nomeDelFile[' + i + ']" value="" readonly="readonly">'
            + '<input type="file" id="allegati[' + i + ']" name="allegati[' + i + ']" value="" onchange="setNomeFile(this.value,' + i + ')" />'
            + '<button class="btn-form">Scegli file</button>'
            + '<style>input[type="file"]{opacity:0;position:absolute;width:100px;height:40px;}</style>'
            + '<input type="text" id="desc_doc" name="desc_doc[' + i + ']" value="" placeholder="Descrizione allegato" />'
            + '<input type="button" id="remNew" value="Elimina">'
            + '</p>').appendTo(addDiv);
        i++;
        return false;
    });

    $('#remNew').live('click', function() {
        if (i > 1) {
            $(this).parents('p').remove();
            i--;
            document.getElementById('errore_formato[' + i + ']').style.display = 'none';
        }
        return false;
    });
});

function controlloData(data) {
    if (data.length != 10) return false;
    var data_temp = data.split("/");
    if (data_temp.length != 3) return false;
    var giorno = data_temp[0], mese = data_temp[1], anno = data_temp[2];
    var today = new Date();
    var dd = today.getDate(), mm = today.getMonth() + 1, yyyy = today.getFullYear();
    if (dd < 10) dd = '0' + dd;
    if (mm < 10) mm = '0' + mm;
    var data_corrente = yyyy + '-' + mm + '-' + dd;
    var data_ricevuta = anno + '-' + mese + '-' + giorno;
    if (data_ricevuta > data_corrente) return false;
    if (isNaN(giorno) || giorno > 31) return false;
    if (isNaN(mese) || mese > 12) return false;
    if (isNaN(anno) || anno.length != 4) return false;
    return true;
}

function controlloPeriodo(data_inizio, data_fine) {
    if (data_inizio.length != 10 || data_fine.length != 10) return false;
    if (data_inizio > data_fine) return false;
    return true;
}

function controllaCampi(status) {
    var errore = 'no';

    // =============================================
    // VERIFICHE ANTI-BOT JAVASCRIPT
    // =============================================
    
    // javaScript abilitato
    document.getElementById('js_enabled').value = '1';
    
    // matematico
    var captcha_value = document.getElementById('captcha').value;
    if (captcha_value == '') {
        document.getElementById("errore_captcha").innerHTML = 'Completa il calcolo matematico!';
        errore = 'si';
    } else {
        document.getElementById("errore_captcha").innerHTML = '';
    }

    // honeypot vuoto
    var honeypot = document.getElementById('honeypot').value;
    if (honeypot != '') {
        document.getElementById("errore_honeypot").innerHTML = 'Bot rilevato!';
        errore = 'si';
    } else {
        document.getElementById("errore_honeypot").innerHTML = '';
    }

    //csrf_token
    if (document.getElementById('csrf_token').value == '') {
        document.getElementById("errore_csrf").innerHTML = 'Token di sicurezza mancante! Ricarica la pagina.';
        errore = 'si';
    } else {
        document.getElementById("errore_csrf").innerHTML = '';
    }

    // =============================================
    // CONTROLLO FORMATO ALLEGATI
    // =============================================
    
    var formati_consentiti = [".jpg", ".pdf", ".doc", ".rtf", ".xls", ".mov", ".avi", ".mp4", "docx", "xlsx", ".odt", "jpeg"];
    var errore_formato = 0;
    for (var h = 1; h <= 100; h++) {
        if (document.getElementById('nomeDelFile[' + h + ']') != null) {
            var ext = document.getElementById('nomeDelFile[' + h + ']').value.toLowerCase().substr(-4);
            if (ext == '') {
                document.getElementById('errore_formato[' + h + ']').innerHTML = 'campo obbligatorio!';
                document.getElementById('errore_formato[' + h + ']').style.display = 'block';
                errore_formato++;
            } else if (formati_consentiti.indexOf(ext) != -1) {
                document.getElementById('errore_formato[' + h + ']').style.display = 'none';
            } else {
                document.getElementById('errore_formato[' + h + ']').innerHTML = 'tipo file non consentito!';
                document.getElementById('errore_formato[' + h + ']').style.display = 'block';
                errore_formato++;
            }
        }
    }
    if (errore_formato != 0) errore = 'si';

    document.getElementById("status").innerHTML = '<input type="hidden" name="status" id="status_val" value="' + status + '">';

    // =============================================
    // CONTROLLO DATA/PERIODO
    // =============================================
    
    if (document.getElementById("tipo_periodo_data").checked == true) {
        if (document.form1.data_inizio_singola.value == '') {
            document.getElementById("errore_data_inizio_singola").innerHTML = 'campo obbligatorio!';
            errore = 'si';
        } else {
            if (!controlloData(document.form1.data_inizio_singola.value)) {
                document.getElementById("errore_data_inizio_singola").innerHTML = 'data successiva ad oggi!';
                errore = 'si';
            } else {
                document.getElementById("errore_data_inizio_singola").innerHTML = '';
            }
        }
    } else if (document.getElementById("tipo_periodo_periodo").checked == true) {
        if (document.form1.data_inizio.value == '') {
            document.getElementById("errore_data_inizio").innerHTML = 'campo obbligatorio!';
            errore = 'si';
        } else {
            if (!controlloData(document.form1.data_inizio.value)) {
                document.getElementById("errore_data_inizio").innerHTML = 'data inizio successiva ad oggi!';
                errore = 'si';
            } else {
                document.getElementById("errore_data_inizio").innerHTML = '';
            }
        }
        if (document.form1.data_fine.value == '') {
            document.getElementById("errore_data_fine").innerHTML = 'campo obbligatorio!';
            errore = 'si';
        } else {
            if (!controlloData(document.form1.data_fine.value)) {
                document.getElementById("errore_data_fine").innerHTML = 'data fine successiva ad oggi!';
                errore = 'si';
            } else {
                document.getElementById("errore_data_fine").innerHTML = '';
            }
        }
        if (document.form1.data_inizio.value != '' && document.form1.data_fine.value != '') {
            if (!controlloPeriodo(document.form1.data_inizio.value, document.form1.data_fine.value)) {
                document.getElementById("errore_data_inizio").innerHTML = 'data inizio successiva alla data fine!';
                document.getElementById("errore_data_fine").innerHTML = 'data inizio successiva alla data fine!';
                errore = 'si';
            }
        }
    }

    // =============================================
    // CONTROLLO LUOGO
    // =============================================
    
    if (document.form1.luogo.value == '') {
        document.getElementById("errore_luogo").innerHTML = 'campo obbligatorio!';
        errore = 'si';
    } else {
        document.getElementById("errore_luogo").innerHTML = '';
        if (document.form1.luogo.value == 'ufficio') {
            if (document.form1.indirizzo_ufficio.value == '') {
                document.getElementById("errore_indirizzo_ufficio").innerHTML = 'campo obbligatorio!';
                errore = 'si';
            }
        } else if (document.form1.luogo.value == 'esterno') {
            if (document.form1.indirizzo_esterno.value == '') {
                document.getElementById("errore_indirizzo_esterno").innerHTML = 'campo obbligatorio!';
                errore = 'si';
            }
        }
    }

    // =============================================
    // CONTROLLO AZIONI
    // =============================================
    
    if (document.form1.azioni.value == '') {
        document.getElementById("errore_azioni").innerHTML = 'campo obbligatorio!';
        errore = 'si';
    } else if (document.form1.azioni.value == 'altro') {
        document.getElementById("errore_azioni").innerHTML = '';
        if (document.form1.azioni_altro.value == '') {
            document.getElementById("errore_azioni_altro").innerHTML = 'campo obbligatorio!';
            errore = 'si';
        }
    } else {
        document.getElementById("errore_azioni").innerHTML = '';
        document.getElementById("errore_azioni_altro").innerHTML = '';
    }

    // =============================================
    // CONTROLLO OGGETTO
    // =============================================
    
    if (document.form1.oggetto.value == '') {
        document.getElementById("errore_oggetto").innerHTML = 'campo obbligatorio!';
        errore = 'si';
    } else {
        document.getElementById("errore_oggetto").innerHTML = '';
    }

    // =============================================
    // CONTROLLO DESCRIZIONE
    // =============================================
    
    if (document.form1.descrizione.value == '') {
        document.getElementById("errore_descrizione").innerHTML = 'campo obbligatorio!';
        errore = 'si';
    } else {
        document.getElementById("errore_descrizione").innerHTML = '';
    }

    // =============================================
    // CONTROLLO AUTORE
    // =============================================
    
    if (document.form1.autore.value == '') {
        document.getElementById("errore_autore").innerHTML = 'campo obbligatorio!';
        errore = 'si';
    } else {
        document.getElementById("errore_autore").innerHTML = '';
    }

    // =============================================
    // RISULTATO FINALE
    // =============================================
    
    if (errore == 'si') {
        document.getElementById("errore").innerHTML = '<div style="color:red;font-weight:bold;padding:10px;border:1px solid red;background:#ffeeee;">Errore nell\'inserimento dei dati. Controlla i campi evidenziati in rosso.</div>';
    } else {
        document.form1.submit();
    }
}

function controllaSalva() {
    controllaCampi(document.form1.salva.value);
}

function controllaInvia() {
    controllaCampi(document.form1.invia.value);
}

function limitText(limitField, limitCount, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } else {
        limitCount.value = limitNum - limitField.value.length;
    }
}

// =============================================
// FUNZIONI DI MOSTRA/NASCONDI
// =============================================

function mostraPeriodo(id) {
    if (id == 'data' || id == null) {
        document.getElementById('data_inizio').style.display = 'block';
        document.getElementById('data_fine').style.display = 'none';
    } else if (id == 'periodo') {
        document.getElementById('data_inizio').style.display = 'none';
        document.getElementById('data_fine').style.display = 'block';
    }
}

function mostraLuogo(id) {
    if (id == 'ufficio') {
        document.getElementById('ufficio').style.display = 'block';
        document.getElementById('esterno').style.display = 'none';
    } else if (id == 'esterno') {
        document.getElementById('ufficio').style.display = 'none';
        document.getElementById('esterno').style.display = 'block';
    } else {
        document.getElementById('ufficio').style.display = 'none';
        document.getElementById('esterno').style.display = 'none';
    }
}

function mostraAzioni(id) {
    if (id == 'altro') {
        document.getElementById('azioni_altro').style.display = 'block';
    } else {
        document.getElementById('azioni_altro').style.display = 'none';
    }
}

function setMsg(msg) {
    if (msg != "") {
        document.getElementById('system-message-container').innerHTML = '<div class="alert alert-success"><a class="close" data-dismiss="alert">&#215;</a><p class="alert-message">' + msg + '</p></div>';
    }
}

setMsg('<?php echo addslashes($msg); ?>');
</script>

<script src="/calendario/Test/mootools-core.js" type="text/javascript"></script>
<script src="/calendario/Test/mootools-more.js" type="text/javascript"></script>
<script src="/calendario/Source/Locale.it-IT.DatePicker.js" type="text/javascript"></script>
<script src="/calendario/Source/Picker.js" type="text/javascript"></script>
<script src="/calendario/Source/Picker.Attach.js" type="text/javascript"></script>
<script src="/calendario/Source/Picker.Date.js" type="text/javascript"></script>
<link href="/calendario/Source/datepicker.css" rel="stylesheet" type="text/css" media="screen" />

<script>
window.addEvent('domready', function() {
    new Picker.Date('data_inizio_singola');
    new Picker.Date('data_inizio_periodo');
    new Picker.Date('data_fine_periodo');
});
</script>

<div id="top-bar">
<div class="padd">
<?php include("top.php"); ?>
</div>
</div>

<div id="content">
<div class="padd">

    <h1 class="separator"><?php echo $Config["segnalazione"]["inserisci_anonima"]; ?></h1>

    <?php if ($msg == "") { ?>

        <p>
        Il segnalante &egrave; consapevole delle responsabilit&agrave; e delle conseguenze civili e penali previste in caso di
        dichiarazioni mendaci e/o formazione o uso di atti falsi, anche ai sensi e per gli effetti dell'art. 76 del d.P.R. 445/2000.
        </p>

        <?php if ($recaptcha_error != "") { ?>
            <div class="form-error" style="color:red;font-weight:bold;padding:10px;border:1px solid red;background:#ffeeee;margin-bottom:10px;">
                <?php echo htmlspecialchars($recaptcha_error); ?>
            </div>
        <?php } ?>

        <?php if ($id_elemento == "") { ?>

            <div id="errore"></div>

            <form action="inserisci.php" method="post" enctype="multipart/form-data" name="form1" title="<?php echo htmlspecialchars($Config["segnalazione"]["inserisci"]); ?>">
                <input name="form_inserisci" type="hidden" id="form_inserisci" value="true">
                <input type="hidden" name="codice" id="codice" value="<?php echo $_SESSION["CODICE_ENTE"]; ?>">
                
                
                <!-- Token -->
                <input type="hidden" name="csrf_token" id="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
                <div id="errore_csrf" class="form-error" style="color:red;font-weight:bold;"></div>
                
                <!-- Honeypot -->
                <div style="display:none;">
                    <label for="honeypot">Non compilare questo campo se sei umano</label>
                    <input type="text" name="honeypot" id="honeypot" value="">
                    <div id="errore_honeypot" class="form-error" style="color:red;font-weight:bold;"></div>
                </div>
                
                <!-- JavaScript enabled -->
                <input type="hidden" name="js_enabled" id="js_enabled" value="0">
        
                
                <div>
                    <label for="tipo_periodo">Data/Periodo in cui si &egrave; verificato il fatto</label>
                    <?php if ($_REQUEST["tipo_periodo"] == "") $_REQUEST["tipo_periodo"] = "data"; ?>
                    <div class="form-dx">
                        Data <input type="radio" name="tipo_periodo" id="tipo_periodo_data" value="data" <?php if ($_REQUEST["tipo_periodo"] == "data") echo " checked=\"checked\""; ?> onchange="javascript:mostraPeriodo(this.value);" />
                        Periodo <input type="radio" name="tipo_periodo" id="tipo_periodo_periodo" value="periodo" <?php if ($_REQUEST["tipo_periodo"] == "periodo") echo " checked=\"checked\""; ?> onchange="javascript:mostraPeriodo(this.value);" />
                    </div>
                    <div class="both"></div>
                </div>

                <span id="data_inizio" style="display:block">
                    <div>
                        <label for="data_inizio_singola">Data *</label><div id="errore_data_inizio_singola" class="form-error" style="color:red;font-weight:bold;"></div>
                        <input type="text" id="data_inizio_singola" name="data_inizio_singola" value="<?php echo htmlspecialchars($_REQUEST["data_inizio_singola"]); ?>" maxlength="10" />
                        <div class="both"></div>
                    </div>
                </span>

                <span id="data_fine" style="display:none">
                    <div>
                        <label for="data_inizio">Data inizio *</label><div id="errore_data_inizio" class="form-error" style="color:red;font-weight:bold;"></div>
                        <input type="text" id="data_inizio_periodo" name="data_inizio" value="<?php echo htmlspecialchars($_REQUEST["data_inizio"]); ?>" maxlength="10" />
                        <div class="both"></div>
                    </div>
                    <div>
                        <label for="data_fine">Data fine *</label><div id="errore_data_fine" class="form-error" style="color:red;font-weight:bold;"></div>
                        <input type="text" id="data_fine_periodo" name="data_fine" value="<?php echo htmlspecialchars($_REQUEST["data_fine"]); ?>" maxlength="10" />
                        <div class="both"></div>
                    </div>
                </span>

                <div>
                    <label for="luogo">Luogo fisico in cui si &egrave; verificato il fatto *</label><div id="errore_luogo" class="form-error" style="color:red;font-weight:bold;"></div>
                    <select name="luogo" id="luogo" onchange="javascript:mostraLuogo(this.value);">
                        <option value="">-- Seleziona opzione --</option>
                        <option value="ufficio" <?php if ($_REQUEST["luogo"] == "ufficio") echo "selected=\"selected\""; ?>>In ufficio</option>
                        <option value="esterno" <?php if ($_REQUEST["luogo"] == "esterno") echo "selected=\"selected\""; ?>>All'esterno dell'ufficio</option>
                    </select>
                    <div class="both"></div>
                </div>

                <span id="ufficio" style="display:none">
                    <div>
                        <label for="indirizzo_ufficio">Denominazione e indirizzo della struttura *:</label><div id="errore_indirizzo_ufficio" class="form-error" style="color:red;font-weight:bold;"></div>
                        <input type="text" id="indirizzo_ufficio" name="indirizzo_ufficio" value="<?php echo htmlspecialchars(stripslashes($_REQUEST["indirizzo_ufficio"])); ?>" maxlength="255" />
                        <div class="both"></div>
                    </div>
                </span>

                <span id="esterno" style="display:none">
                    <div>
                        <label for="indirizzo_esterno">Luogo ed indirizzo *</label><div id="errore_indirizzo_esterno" class="form-error" style="color:red;font-weight:bold;"></div>
                        <input type="text" id="indirizzo_esterno" name="indirizzo_esterno" value="<?php echo htmlspecialchars(stripslashes($_REQUEST["indirizzo_esterno"])); ?>" maxlength="255" />
                        <div class="both"></div>
                    </div>
                </span>

                <div>
                    <label for="azioni">Ritengo che le azioni od omissioni commesse o tentate siano *</label><div id="errore_azioni" class="form-error" style="color:red;font-weight:bold;"></div>
                    <select name="azioni" id="azioni" onchange="javascript:mostraAzioni(this.value);">
                        <option value="">-- Seleziona opzione --</option>
                        <option value="penali" <?php if ($_REQUEST["azioni"] == "penali") echo "selected=\"selected\""; ?>>Penalmente rilevanti</option>
                        <option value="disciplinari" <?php if ($_REQUEST["azioni"] == "disciplinari") echo "selected=\"selected\""; ?>>Poste in essere in violazione dei Codici di comportamento o di altre disposizioni sanzionabili in via disciplinare</option>
                        <option value="patrimoniali" <?php if ($_REQUEST["azioni"] == "patrimoniali") echo "selected=\"selected\""; ?>>Suscettibili di arrecare un pregiudizio patrimoniale all'amministrazione di appartenenza o di altro Ente Pubblico</option>
                        <option value="immagine" <?php if ($_REQUEST["azioni"] == "immagine") echo "selected=\"selected\""; ?>>Suscettibili di arrecare un pregiudizio all'immagine dell'amministrazione</option>
                        <option value="altro" <?php if ($_REQUEST["azioni"] == "altro") echo "selected=\"selected\""; ?>>Altro</option>
                    </select>
                    <div class="both"></div>
                </div>

                <span id="azioni_altro" style="display:none">
                    <div>
                        <label for="azioni_altro">Specificare altro *</label><div id="errore_azioni_altro" class="form-error" style="color:red;font-weight:bold;"></div>
                        <input type="text" id="azioni_altro" name="azioni_altro" value="<?php echo htmlspecialchars(stripslashes($_REQUEST["azioni_altro"])); ?>" maxlength="255" />
                        <div class="both"></div>
                    </div>
                </span>

                <div>
                    <label for="oggetto">Oggetto *</label><div id="errore_oggetto" class="form-error" style="color:red;font-weight:bold;"></div>
                    <textarea name="oggetto" cols="50" rows="5" id="oggetto" onKeyDown="javascript:limitText(this.form.oggetto, this.form.countdown, 100);" onKeyUp="javascript:limitText(this.form.oggetto, this.form.countdown, 100);"><?php echo htmlspecialchars(stripslashes($_REQUEST["oggetto"])); ?></textarea>
                    <div class="both"></div>
                </div>

                <div>
                    <label for="countdown">Numero caratteri rimanenti per l'oggetto</label>
                    <input readonly type="text" name="countdown" size="3" value="100">
                    <div class="both"></div>
                </div>

                <div>
                    <label for="descrizione">Descrizione *</label><div id="errore_descrizione" class="form-error" style="color:red;font-weight:bold;"></div>
                    <textarea cols="50" id="descrizione" name="descrizione" rows="10"><?php echo htmlspecialchars($_REQUEST["descrizione"]); ?></textarea>
                    <div class="both"></div>
                </div>

                <div>
                    <label for="autore">Autore/i del fatto *</label><div id="errore_autore" class="form-error" style="color:red;font-weight:bold;"></div>
                    <textarea cols="50" id="autore" name="autore" rows="5"><?php echo htmlspecialchars($_REQUEST["autore"]); ?></textarea>
                    <div class="both"></div>
                </div>

                <div>
                    <label for="soggetti">Altri eventuali soggetti a conoscenza del fatto e/o in grado di riferire sul medesimo</label><div id="errore_soggetti" class="form-error" style="color:red;font-weight:bold;"></div>
                    <textarea cols="50" id="soggetti" name="soggetti" rows="5"><?php echo htmlspecialchars($_REQUEST["soggetti"]); ?></textarea>
                    <div class="both"></div>
                </div>

                <div>
                    <label for="allegato">
                        Allega documenti<br />
                        (<strong>jpg</strong>, <strong>jpeg</strong>, <strong>pdf</strong>, <strong>doc</strong>, <strong>rtf</strong>, <strong>xls</strong>, <strong>mov</strong>, <strong>avi</strong>, <strong>mp4</strong>, <strong>docx</strong>, <strong>xlsx</strong>, <strong>odt</strong>)
                    </label>
                    <div id="addinput" class="form-dx">
                        <input type="button" id="addNew" value="Aggiungi allegato" />
                    </div>
                    <div class="both"></div>
                </div>

				                <!--  Mat -->
                <div style="margin-bottom:15px;padding:10px;background:#f5f5f5;border-radius:5px;">
                    <label for="captcha" style="font-weight:bold;">Quanto fa <?php echo $_SESSION['captcha_num1']; ?> + <?php echo $_SESSION['captcha_num2']; ?>? *</label>
                    <div id="errore_captcha" class="form-error" style="color:red;font-weight:bold;"></div>
                    <input type="text" id="captcha" name="captcha" value="" maxlength="2" style="width:60px;padding:5px;border:1px solid #ccc;border-radius:3px;" autocomplete="off" />
                    <span style="font-size:12px;color:#666;margin-left:10px;">Inserisci il risultato del calcolo</span>
                    <div class="both"></div>
                </div>

                <div id="status"></div>

                <div class="btn-box">
                    <input type="button" name="invia" id="invia" value="invia" onclick="controllaInvia();" class="btn-form">
                    <a href="inserisci.php" title="Annulla" class="btn-form">Annulla</a>
                </div>

            </form>

			 <p class="attenzione" >N.B. I campi contrassegnati con * sono OBBLIGATORI!</p>


        <?php } else { ?>

            <h2><?php echo $msg; ?></h2>

        <?php } ?>

    <?php } else { ?>

        <h2><?php echo $msg; ?></h2>

    <?php } ?>

<div class="both"></div>
</div>
</div>
<?php include($Root . "/layout/bottom-app.php"); ?>