/** * Created by PhpStorm. * User: Bogdan * Date: 23/07/2015 * Time: 17:17 */ if (!empty($_POST['documentID'])) { /* Protezione input da codice eseguibile */ $idDocumento = safeInput($_POST['documentID']); /* Controllo se id è lungo 10 caratteri ed è composto solo di lettere e numeri */ if (30 == strlen($idDocumento) && preg_match("/^[a-zA-Z0-9]+\$/", $idDocumento)) { main($idDocumento); } } else { sayBadInput("Errore! Il parametro documentID è vuoto!"); } /* MAIN - TUTTE LE AZIONI SI SVOLGONO QUI */ function main($idDocumento) { } /** RICHIESTA IN SQL PER CERCARE IL DOCUMENTO */ function build_sql_request_document($idDocumento) { $requestToSQL = "SELECT titolo,imgLocation FROM Documents WHERE idDocumento='" . $idDocumento . "'"; return $requestToSQL; } /** IMMAGINE/PDF DOCUMENTO */ function build_HTML($documento) { $risposta = '<img alt="' . $documento->titolo . '" id="imgDoc" src="' . $documento->imgLocation . '">';
<?php /** * Created by PhpStorm. * User: Bogdan * Date: 26/07/2015 * Time: 22:42 */ if (!empty($_POST['userID'])) { $idUtente = safeInput($_POST['userID']); //Controllo se id è lungo 10 caratteri ed è composto solo di lettere e numeri if (10 == strlen($idUtente) && preg_match("/^[a-zA-Z0-9]+\$/", $idUtente)) { main_allDocuments($idUtente); } } else { sayBadInput("Errore! Il parametro userID è vuoto!"); } /** MAIN - TUTTE LE AZIONI SI SVOLGONO QUI */ function main_allDocuments($idUtente) { include_once root_dir_php . 'class/Document.php'; $sqlRequest = build_sql_request_allDocuments($idUtente); $rispostaDB = ricercaDB($sqlRequest); if (isset($rispostaDB)) { $vettDocumenti = parse_sql_allDocuments($rispostaDB); $rispostaHTML = build_HTML($vettDocumenti); //Costruisco la risposta in HTML } else { $rispostaHTML = sayNotFound("Ricerca non ha prodotto risultati"); } echo $rispostaHTML;
if (10 == strlen($idUtente) && preg_match("/^[a-zA-Z0-9]+\$/", $idUtente)) { echo getElencoDocumenti($idUtente); } } } else { if ($tipoRichiesta === "user") { $idUtente = $GLOBALS['ID_User']; if (!empty($idUtente)) { $idUtente = safeInput($idUtente); //Controllo se id è lungo 10 caratteri ed è composto solo di lettere e numeri if (10 == strlen($idUtente) && preg_match("/^[a-zA-Z0-9]+\$/", $idUtente)) { echo getDocente($idUtente); } } } else { echo sayBadInput(); } } } } } } /** Funzione di test richiesta da codice maligno per prevenire * codice javascript eseguibile */ function safeInput($data) { //$data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data;
coursePeriod [500 caratteri] coursePlan [50000 caratteri] additionalInfo [50000 caratteri] upload - pdfDoc : idDocument */ include 'common.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $tipoDati = $_POST['dataType']; if (!empty($tipoDati)) { $tipoDati = SafeInput($tipoDati); if (preg_match('/^[a-zA-Z]*$/', $tipoDati)) { } else { sayBadInput("Input errato! Variabile datatype contiene caratteri non validi"); } } else { sayBadInput("Input errato! Variabile dataType è vuota."); } } /** INIZIO DEBUG */ function crea_utente() { $user = new User(); $user->idUtente = generateRandomString(30); $user->nome = generateRandomString(6); $user->cognome = generateRandomString(6); return $user; } function crea_documento() { $utente = crea_utente(); $corso = crea_corso();
*/ include 'common.php'; /** CONTROLLO INPUT */ if ($_SERVER['REQUEST_METHOD'] == "POST") { $tipoDati = $_POST['dataType']; if (!empty($tipoDati)) { $tipoDati = safeInput($tipoDati); if (preg_match('/^[a-zA-Z]*$/', $tipoDati)) { /* Richiesta di ricerca */ if ($tipoDati === "search") { include 'download/download_search.php'; } else { if ($tipoDati === "document") { include 'download/download_document.php'; } else { if ($tipoDati === "allDocuments") { include 'download/download_allDocuments.php'; } else { if ($tipoDati === "user") { include 'download/download_user.php'; } else { echo sayBadInput("Errore! datatype non ammesso!"); } } } } } else { sayBadInput("Input errato! Variabile datatype contiene caratteri non validi"); } } }