<?php
/***************************************************************************
____ _ _ ____ _ _ _ _ _ _
| _ \| | | | _ \| |_ ___ ___ | |___| || | | | | |
| |_) | |_| | |_) | __/ _ \ / _ \| / __| || |_| | | |
| __/| _ | __/| || (_) | (_) | \__ \__ _| |_| |
|_| |_| |_|_| \__\___/ \___/|_|___/ |_| \___/
guestbook.php - A Guestbook :o)
-------------------
begin : Thu Apr 18 2002
copyright : (C) 2002 PHPtools4U.com - Mathieu LESNIAK
email : support@phptools4u.com
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/****************************************************************************
* SQL Structure
CREATE TABLE `guestbook` (
`id` int(11) NOT NULL auto_increment,
`nom` varchar(30) default NULL,
`email` varchar(50) default NULL,
`date` int(11) default NULL,
`message` blob,
PRIMARY KEY (`id`)
) TYPE=MyISAM COMMENT='Guestbook table'
****************************************************************************/
function guestbook() {
Global $HTTP_POST_VARS, $HTTP_GET_VARS, $PHP_SELF;
Global $DOCUMENT_ROOT;
### Parameters
$path_2_mysql = $_SERVER['DOCUMENT_ROOT'].'/lib/mysql.inc.php';
$nb_message = 10;
$font = '<FONT face="Verdana, Arial, Helvetica" size="1" color="#000000">';
### Img for the form button, if null, show a submit button with $button_txt caption
$button_src = '/images/poster.gif';
$button_txt = 'Poster';
### End of parameters
require_once($path_2_mysql);
$DBGBook = new DB();
$error = 0;
$output = '';
$show = isset($HTTP_GET_VARS['show']) ? $HTTP_GET_VARS['show'] : '';
$start = isset($HTTP_GET_VARS['start']) ? $HTTP_GET_VARS['start'] : 0;
$insert = isset($HTTP_POST_VARS['insert']) ? $HTTP_POST_VARS['insert'] : '';
$nom = isset($HTTP_POST_VARS['nom']) ? $HTTP_POST_VARS['nom'] : '';
$email = isset($HTTP_POST_VARS['email']) ? $HTTP_POST_VARS['email'] : '';
$message = isset($HTTP_POST_VARS['message']) ? $HTTP_POST_VARS['message'] : '';
if ($insert == 1) {
$error = !strlen(trim($nom)) || !strlen(trim($message));
if ($error == 0) {
$nom = (!get_magic_quotes_gpc()) ? addslashes($nom) : $nom;
$email = (!get_magic_quotes_gpc()) ? addslashes($email) : $email;
$message = (!get_magic_quotes_gpc()) ? addslashes($message) : $message;
$DBGBook->query("INSERT INTO guestbook VALUES ('','$nom','$email','".time()."','$message')");
$show = 1;
}
}
if ($show != '' && $error != 1) {
$DBGBook->query("SELECT COUNT(*) FROM guestbook");
list($total_enreg) = $DBGBook->next_record();
$DBGBook->query("SELECT nom, email, message, date FROM guestbook ORDER BY date DESC LIMIT $start,$nb_message");
if ($DBGBook->num_rows()) {
$output = '<TABLE border="0">'."\n";
while (list($nom, $email, $message, $date) = $DBGBook->next_record()) {
$email = (strlen($email)) ? '('.htmlentities_iso($email).')' : '';
$date = date("d-m-Y à H:i:s",$date);
$output .= '<TR>'."\n";
$output .= ' <TD colspan="2">'.$font.'<B>Posté le </B>'.$date.'<B> par </B>'.htmlentities_iso($nom).' '.$email.'</FONT></TD>'."\n";
$output .= '</TR>'."\n";
$output .= '<TR>'."\n";
$output .= ' <TD colspan="2">'.$font.nl2br(htmlentities_iso($message)).'</FONT></TD>'."\n";
$output .= '</TR>'."\n";
}
$output .= '<TR>'."\n";
if ($start > 0) {
$output .= '<TD width="50%">'.$font.'<A href="'.$PHP_SELF.'?show=1&start='.($start-$nb_message).'">Page précédente</A></FONT></TD>';
}
else {
$output .= '<TD width="50%"> </TD>';
}
if (($start + $nb_message) < $total_enreg) {
$output .= '<TD width="50%" align="right">'.$font.'<A href="'.$PHP_SELF.'?show=1&start='.($start+$nb_message).'">Page suivante</A></FONT></TD>';
}
else {
$output .= '<TD width="50%"> </TD>';
}
$output .= '</TR>'."\n";
$output .= '</TABLE>'."\n";
}
else {
$output .= $font.'Pas de message pour le moment.</FONT>';
}
$output .= '<BR><BR><A href="'.$PHP_SELF.'">Ajouter un message</A>';
}
else {
if ($error) {
$output .= '<CENTER><B>'.$font.'Votre saisie comporte des erreurs</FONT></B></CENTER>';
}
if ($button_src != '') {
$button = '<INPUT type="image" src="'.$button_src.'" class="imgbtn" >';
}
else {
$button = '<INPUT type="submit" value="'.$button_txt.'">';
}
$output .= '<style type="text/css">
<!--
.imgbtn { border-top : 0px; border-bottom : 0px; border-left : 0px; border-right : 0px; }
//-->
</style>';
$output .= '<FORM action="'.$PHP_SELF.'" method="POST" name="guestbook">'."\n";
$output .= '<TABLE border="0">'."\n";
$output .= '<TR>'."\n";
$output .= ' <TD>'.$font.'Votre nom : </FONT></TD>'."\n";
$output .= ' <TD><INPUT type="text" name="nom" maxlength="30" value="'.stripslashes($nom).'"></TD>'."\n";
$output .= '</TR>';
$output .= '<TR>';
$output .= ' <TD>'.$font.'Votre adresse mail : </FONT></TD>'."\n";
$output .= ' <TD>'.$font.'<INPUT type="text" name="email" maxlength="50" value="'.stripslashes($email).'"> (facultatif)</FONT></TD>'."\n";
$output .= '</TR>'."\n";
$output .= '<TR>'."\n";
$output .= ' <TD valign="top">'.$font.'Votre message : </FONT></TD>'."\n";
$output .= ' <TD><TEXTAREA name="message" cols="30" rows="5">'.stripslashes($message).'</TEXTAREA></TD>'."\n";
$output .= '</TR>'."\n";
$output .= '<TR>'."\n";
$output .= ' <TD colspan="2" align="right">'.$button.'</TD>'."\n";
$output .= '</TR>'."\n";
$output .= '<TR>'."\n";
$output .= ' <TD colspan="2" align="right">'.$font.'<A href="'.$PHP_SELF.'?show=1">Voir les messages</A></TD>'."\n";
$output .= '</TR>'."\n";
$output .= '</TABLE>'."\n";
$output .= '<INPUT type="hidden" name="insert" value="1">'."\n";
$output .= '</FORM>';
}
$DBGBook->close();
return $output;
}
?>