<? 
include ('logue.php'); 
include 'entetecommentaire.php';
?>

<?php
$nom = "news" ;
$pagecommentaire = $nom ;
?>
<html>
<head>
<title><?php echo $str_titre_page; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="StyleSheet" type="text/css" href="<?php echo $CSS_file; ?>">
</head>

<body bgcolor="<?php echo $background_couleur; ?>" text="white" link="white" vlink="white" alink="white" rightmargin=5 bottommargin=5 leftmargin=5 marginwidth=5 topmargin=5 marginheight=5>

<script language="JavaScript">
<!--
function verif_form()
	{
 	if (document.commentaire.auteur_form.value=="")
 		{
  		alert("<?php echo $str_erreur_nom; ?>");
  		document.commentaire.auteur_form.focus();
  		return false;
 		}
 	if (document.commentaire.texte_form.value=="")
 		{
  		alert("<?php echo $str_erreur_commentaire; ?>");
  		document.commentaire.texte_form.focus();
  		return false;
 		}
	 if (document.commentaire.email_form.value!="")
	 	{
		 if (document.commentaire.email_form.value.indexOf('@')==-1 || document.commentaire.email_form.value.indexOf('.')==-1)  
			{
			alert("<?php echo $str_erreur_email; ?>");
	  		document.commentaire.email_form.focus();
	  		return false;
			}
		}
	return true;
	}
//-->
</script>
<? include ('entete.php'); ?>



<table cellpadding="3" width="640" height="100%" cellspacing="0" border="0" bgcolor="<?php echo $cadre_couleur; ?>" align="left">
  <tr><td valign=top>
<table cellpadding="6" width="100%" height="100%" cellspacing="0" border="0" bgcolor="<?php echo $tableau_couleur; ?>"><tr><td valign=top>
<img src="images/dot.gif" align=absmiddle height=3 width=1><br>

<?php
//-------------------------------
// connexion à la base de données
//-------------------------------

$connection = mysql_connect($host, $user, $password);
$db         = mysql_select_db($database, $connection);

//---------------------
// ajout du commentaire
//---------------------
if ( $texte_form != '' ) {
if ( $action == 'ajouter' && !empty($nom) && !empty($login) && !empty($texte_form) )
	{
	$date = date('Y/m/d H:i');
	$sql  = db_mysql_Query('INSERT INTO '.$table.' (nom, auteur, texte, date) VALUES (\''.$nom.'\', \''.$idlogin.'\', \''.$texte_form.'\', \''.$date.'\')', $connection);
	echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("index.php");
-->
</script>';
	}}


//----------------------
// sélection des données
//----------------------

if ( !isset($debut) ) $debut = 0;
$sql = db_mysql_Query('SELECT auteur, texte, date FROM '.$table.' WHERE nom = \''.$nom.'\' ORDER BY id '.$ordre.' LIMIT '.$debut.', '.$nb_comment_par_page, $connection);
$nbResults = mysql_num_rows($sql);

$nbTotalComment = db_mysql_Query('SELECT COUNT(*) FROM '.$table.' WHERE nom = \''.$nom.'\'', $connection);
$nbTotalComment_enr = mysql_fetch_array($nbTotalComment);
$nbTotalComment = $nbTotalComment_enr[0];
$nbPages = ceil($nbTotalComment/$nb_comment_par_page);
$numPage = ( $debut/$nb_comment_par_page ) + 1;

?>

<table align="center" width="100%" cellpadding="2" cellspacing="0" border="0" bgcolor="<?php echo $cadre_formulaire_couleur; ?>" ><tr><td>
<table cellpadding="3" cellspacing="0" border="0" align="center" width="100%" bgcolor="<?php echo $formulaire_couleur; ?>">
<form action="news_ecrire.php" method="post" target="_parent" name="commentaire" onsubmit="return verif_form()">
  <tr>
    <td width="7%"><b>Pseudo : </b></td>
    <td width="93%"><b><? echo ("$_SESSION[login]")?></b></td>
    </tr>
  <tr>
    <td colspan="2"><strong>Commentaire : </strong></td>
    </tr>
  <tr>
    <td colspan="2"><textarea name="texte_form" cols=29 rows=5></textarea></td>
    </tr>
  <tr>
    <td height="25" colspan="2"><input type="hidden" name="nom" value="<?php echo htmlspecialchars($nom); ?>"><input type="hidden" name="action" value="ajouter"><input type="submit" value="<?php echo $str_ajouter; ?>"></td>
    </tr>
	</form>
</table>

<p align="center"><img src="<?php echo $separation_img; ?>" align=absmiddle></p>

</td></tr></table>
</td></tr></table>

</body>
</html>

<?php
mysql_close($connection);
?>