<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML lang="it">
<HEAD>
<TITLE>bbs</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<!--Semplice BBS system con database MySQL, output validato W3C HTML 4.01
e accessibile.
Il nome della pagina dev'essere bbs.php. Diversamente, sostituire le occorrenze di bbs.php con il nuovo nome.
Genera la seguente tabella (basta copiare il codice
nel campo testo di database in PHPMyAdmin):
..........................................................
CREATE TABLE bbsMessage
(
ID INT NOT NULL AUTO_INCREMENT,
Title VARCHAR(64),
Poster VARCHAR(64),
Created DATETIME,
Parent INT,
Body BLOB,
PRIMARY KEY(ID)
);
..........................................................
Codice PHP: -->
<?
/******************************************************
BBS v1.0
Code: PHP 3
Author: Leon Atkinson <leon.atkinson@clearink.com>
Simple BBS system using MySQL.
..........::.....................::............
Il codice è stato modificato in modo da avere un output
validato W3C e conforme alle
WCAG 1.0
rellero@webaccessibile.spadamar.com
*******************************************************/
/******************************************************
set database
*******************************************************/
mysql_connect("localhost", "username_databse", "password_database");
$Database = "nome_database";
function showMessages($parentID)
{
global $Database;
$dateToUse = Date("U");
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE Parent=$parentID ";
$Query = $Query . "ORDER BY Created desc ";
$result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
while($RowCount < $numRows)
{
$messageID = mysql_result($result,$RowCount,"ID");
$messageTitle = mysql_result($result,$RowCount,"Title");
$messageCreated = mysql_result($result,$RowCount,"Created");
$messageParent = mysql_result($result,$RowCount,"Parent");
printf("<UL><LI>($messageCreated) <A HREF="bbs.php?messageID=$messageID">$messageTitle</A>n");
showMessages($messageID);
$RowCount++;
echo "</LI></UL>n";
}
}
function postForm($parentID, $useTitle)
{
printf("<FORM ACTION="bbs.php" METHOD="post">n");
printf("<INPUT TYPE="hidden" NAME="inputParent" VALUE="$parentID">");
printf("<INPUT TYPE="hidden" NAME="ACTION" VALUE="POST">");
printf("<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5" summary="Tabella per inserire i post">n");
printf("<TR><TD><LABEL FOR="/argomento"><B>Argomento</B></LABEL></TD>");
printf("<TD><INPUT TYPE="text" NAME="inputTitle" SIZE="35" VALUE="/argomento..." id="/argomento"></TD></TR>n");
printf("<TR><TD><LABEL FOR="nome"><B>Nome</B></label></TD>");
printf("<TD><INPUT TYPE="text" NAME="inputPoster" SIZE="35" id="nome" VALUE="Nome..."></TD></TR>n");
printf("<TR><TD><LABEL FOR="descrizione"><b>Messaggio</b></label></td>");
printf("<td><TEXTAREA NAME="inputBody" COLS="45" ROWS="5" id="descrizione">Messaggio...</TEXTAREA></TD></TR>n");
printf("<TR><TD COLSPAN="2"><CENTER><INPUT TYPE="submit" VALUE="Invia"></CENTER></TD></TR>n");
printf("</TABLE>n");
printf("</FORM>n");
}
if($ACTION != "")
{
if($ACTION == "POST")
{
$inputTitle = ereg_replace("'", "''", $inputTitle);
$inputBody = ereg_replace("'", "''", $inputBody);
$Query = "INSERT INTO bbsMessage ";
$Query .= "VALUES(0, '$inputTitle', ";
$Query .= "'$inputPoster', ";
$Query .= "now(), $inputParent, ";
$Query .= "'$inputBody')";
$result = mysql($Database,$Query);
}
}
if($messageID > 0)
{
$Query = "SELECT * FROM bbsMessage ";
$Query = $Query . "WHERE ID=$messageID ";
$result = mysql($Database,$Query);
$numRows = mysql_NumRows($result);
$RowCount = 0;
if($RowCount < $numRows)
{
$messageID = mysql_result($result,$RowCount,"ID");
$messageTitle = mysql_result($result,$RowCount,"Title");
$messagePoster = mysql_result($result,$RowCount,"Poster");
$messageCreated = mysql_result($result,$RowCount,"Created");
$messageParent = mysql_result($result,$RowCount,"Parent");
$messageBody = mysql_result($result,$RowCount,"Body");
printf("<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5" summary="Tabella contenente i messaggi">n");
printf("<TR><TD><B>Argomento</B></TD><TD>$messageTitle</TD></TR>n");
printf("<TR><TD><B>Nome</B></TD><TD>$messagePoster</TD></TR>n");
printf("<TR><TD><B>Postato il</B></TD><TD>$messageCreated</TD></TR>n");
printf("<TR><TD COLSPAN="2">$messageBody</TD></TR>n");
printf("</TABLE>n");
postForm($messageID, "RE: $messageTitle");
}
echo "<A HREF="bbs.php">Annunci</A><BR>";
}
else
{
printf("<H4>Annunci</H4>n");
//echo "<UL>n";
showMessages(0);
//echo "</UL>n";
postForm(0, "");
}
?>
</p>
<p> </p>
<p>script di Leon Atkinson modificato in WCAG compliant</p>
</BODY>
</HTML>