commenti.php
Codice PHP:
<?php
/*Header*/
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
[...]
/*Connessione al database*/
include 'database.php';
if(count($_POST) > 0)
{
$user = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$date_db = time();
$nickname = htmlentities($_POST['nickname']);
$commento = htmlentities($_POST['commento']);
if(!empty($nickname) || !empty($commento))
{
//controlliamo se i campi cotengono testo
if (empty($nickname))
{
$status = "[b]Inserisci il tuo Nickname![/b]";
(isset($commento)) ? $commento_text = $commento : $commento_text = "";
}
if (empty($commento)) $status = "[b]Inserisci il tuo Commento![/b] (max 250 caratteri)";
}
else
{
$db_commenti_sec = "INSERT INTO commenti_". $sec ." (filename_code_extension, nickname, commento, userIP, date, agent) ";
$db_commenti_sec.= "VALUES ('". $sourceID ."', '". $nickname ."', '". $commento ."', '". $user ."', '". $date_db ."', '". $agent ."')";
//salviamo il nickname e il commento nel database
$write = mysql_query ($db_commenti_sec) or die (mysql_error());
if ($write === FALSE) $status = "Errore nel salvataggio del commento. Riprova.";
else $status = "Il commento è stato inserito correttamente";
}
}
/*estraiamo le informazioni sulla foto */
$array_photo = $array_sec[$sourceID];
$upload_date = explode('-', $array_photo['filename']);
$upload_date = $upload_date[0];
$array_photo['date'] = formatdate($upload_date);
/*info sull'immagine */
$headers = array();
$headers['filename'] = 'Nome file immagine:';
$headers['title'] = 'Titolo:';
$headers['nickname'] = 'Inserita da:';
$headers['date'] = 'Caricata:';
$info_immagine = array();
foreach($array_photo as $key => $value)
{
$info_immagine[$key] = "<tr id='info_". $key ."'><td>". $headers[$key] .'</td><td>'. $value .'</td></tr>';
}
$output_immagine = '<table>'. $info_immagine['title'] . $info_immagine['nickname'] . $info_immagine['date'] .'</table>';
/* Selezioniamo nickname, commento e date dal Database */
$query = "SELECT nickname, commento, date FROM commenti_". $sec ." WHERE filename_code_extension = '" . $sourceID ."'";
$risultato = mysql_query($query, $conn_host) or die (mysql_error()); ;
if (mysql_num_rows($risultato) == 0)
{
$output_commenti = "<h4>Non è ancora stato lasciato alcun commento per questa immagine... Lascia tu il primo!</h4>";
}
else
{
$array_comments = array();
while ($riga = mysql_fetch_array($risultato, MYSQL_ASSOC))
{
$array_comments[] = $riga;
}
/* mostriamo i commenti */
$output_commenti = '<div id="elenco_commenti">';
foreach($array_comments as $key => $comment)
{
$output_commenti.= '<div id="comment_'. $key .'">';
$output_commenti.= '<hr>Nickname: [b]'. $comment["nickname"] .'[/b]
Commento:
'. $comment["commento"] .'</p> Caricato il: '. formatdate($comment["date"]) . '
';
$output_commenti.= '</div>';
}
$output_commenti.= '</div>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Commenti | FantaPic - <?php echo $subname .' - '. $secname; ?></title>
<script type="text/javascript" src="../../_script/less.js"></script>
<script type="text/javascript" src="../../_script/local.js"></script>
<body onload="activeCount('nickname','commento')">
<div id="wrap" class="<?php echo $sec; ?>">
<div id="intro">
<span>[img]<?php echo 'miniature/'. $sourceID .'.jpeg'; ?>[/img]</span>
<?php
echo $output_immagine;
?>
</div>
<div id="comment_section">
<form name="commenta" id="commenta" method="post" action="../commenti_.php">
<input class="field" type="hidden" name="sourceID" id="sourceID" value="<?php echo $array_photo['filename']; ?>">
<input class="field" type="hidden" name="section" id="section" value="<?php echo $sec; ?>">
<input class="field" type="hidden" name="subcategory" id="subcategory" value="<?php echo $sub; ?>">
<label>
Nickname
<input class="field" type="text" id="nickname" name="nickname" maxlength="20" value="<?php if (empty($_COOKIE['nickname'])){echo "";} elseif(!empty($_COOKIE['nickname'])){echo $_COOKIE['nickname'];}?>">
</label>
<label>
<textarea class="field" name="commento" cols="40" rows="3" id="commento" onload="{if(this.value=='')this.innerHTML='Inserisci un commento...'; this.style.color='#8F8F8F';}" onfocus="{this.innerHTML='';this.style.color='#000';}" onblur="{if(this.value=='')this.innerHTML='Inserisci un commento...'; this.style.color='#8F8F8F';}" value=""></textarea>
</label>
<button type="submit" id="invia" name="invia">Invia</button>
</form>
<?php
echo $output_commenti;
?>
</div>
</div>
</body>
</html>
commenti_.php
Codice PHP:
<?php
$sourceID = $_POST['sourceID'];
$sec = $_POST['section'];
$sub = $_POST['subcategory'];
$url = "http://websitehosting.altervista.org/sito/pages/" . $sec . "/" . $sub . ".php?commenti=" . $sourceID;
$user = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$date_db = time();
$nickname = htmlentities($_POST['nickname']);
$commento = htmlentities($_POST['commento']);
/*Connessione al database*/
include 'database.php';
if(empty($nickname) || empty($commento))
{
//controlliamo se i campi cotengono testo
if (empty($nickname))
{
$status = "[b]Inserisci il tuo Nickname![/b]";
(isset($commento)) ? $commento_text = $commento : $commento_text = "";
}
if (empty($commento)) $status = "[b]Inserisci il tuo Commento![/b] (max 250 caratteri)";
}
else
{
$db_commenti_sec = "INSERT INTO commenti_". $sec ." (filename_code_extension, nickname, commento, userIP, date, agent) ";
$db_commenti_sec.= "VALUES ('". $sourceID ."', '". $nickname ."', '" . $commento ."', '". $user ."', ". $date_db .", '". $agent ."')";
//salviamo il nickname e il commento nel database
$write = mysql_query ($db_commenti_sec) or die (mysql_error());
if ($write === FALSE) $status = "Errore nel salvataggio del commento. Riprova.";
else
{
$colore_tabella='#ffffff';
$bordo_tabella='#000000';
$status = "<table align='center' width='256' cellpadding='2' cellspacing='0' bordercolor='$bordo_tabella' bgcolor='$colore_tabella' style='border:2px solid;'>";
$status .="<tr><td><div><p align='center'>Commento Inviato Correttamente</p></div></td></tr></table>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Commenti | FantaPic</title>
<meta http-equiv="refresh" content='2; url=<?php echo $url ; ?>'>
</head>
<body>
<h2 id="status"><?php echo $status ; ?></h2>
</body>
</html>
Come rendere un tuttuno questi due files?