<html>
<head>
<title><?php $nom = $pagecommentaire; 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>
<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);



//----------------------
// 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;



//---------------------------
// affichage des commentaires
//---------------------------

function smiley($smiley, $image)
	{
	global $texte;
	$texte = ereg_replace($smiley, ' '.$image.' ', $texte);
	}

if ( $nbResults > 0 )
	{
	while ( $enr = mysql_fetch_array($sql) )
		{
		$auteur	= $enr[0];
		$texte	= $enr[1];
		$date	= $enr[2];

$sqllogin = "SELECT login FROM matgraph_users WHERE id='$auteur'";
$reqlogin = db_mysql_Query($sqllogin) or die('Erreur SQL !<br>'.$sqllogin.'<br>'.mysql_error());
$datalogin = mysql_fetch_array($reqlogin);
$loginfinal = $datalogin['login'] ;

$sqlmail = "SELECT mail FROM matgraph_users WHERE id='$auteur'";
$reqmail = db_mysql_Query($sqlmail) or die('Erreur SQL !<br>'.$sqlmail.'<br>'.mysql_error());
$datamail = mysql_fetch_array($reqmail);
$mailfinal = $datamail['mail'] ;

$sqlpermmail = "SELECT permmail FROM matgraph_users WHERE id='$auteur'";
$reqpermmail = db_mysql_Query($sqlpermmail) or die('Erreur SQL !<br>'.$sqlpermmail.'<br>'.mysql_error());
$datapermmail = mysql_fetch_array($reqpermmail);
$permmail = $datapermmail['permmail'] ;


		if (!$allow_HTML)  $texte = htmlspecialchars($texte);
		if ($wordwrap)     $texte = nl2br($texte);
		$texte = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" title=\"\\1://\\2\\3\" target=\"_blank\">[url]</a>", $texte);
		$texte = preg_replace('/([^ ]{'.$longueur_max_mot.'})/si','\\1 ',$texte);
		if ($smilies) { include('commentaires/config/smilies.inc.php'); }

		if ( $permmail == "NON" ) $auteur = '<b>'.htmlspecialchars($loginfinal).'</b>';
		elseif ( $permmail == "OUI" ) $auteur = '<a href="mailto:'.$mailfinal.'" title="'.$mailfinal.'"><u>'.htmlspecialchars($loginfinal).'</u></a>';

		$auteur_email = str_replace('{DATE}', affiche_date($date), str_replace('{AUTEUR}', $auteur, $str_nom_date));

		echo '<table align="center" width="100%" cellpadding="2" cellspacing="0" border="0" bgcolor="'.$cadre_formulaire_couleur.'"><tr><td>'."\n";
		echo '<table cellpadding="3" cellspacing="0" border="1" align="center" width="100%" bgcolor="'.$formulaire_couleur.'">'."\n";
		echo '<tr><td valign=top background="'.$background_img.'">'.$auteur_email.'</td></tr>'."\n";
		echo '<tr><td><a class="commentaire">'.$texte.'</a></td></tr>';
		echo '</table>'."\n";
		echo '</td></tr></table>'."\n";
		echo '<img src="images/dot.gif" align=absmiddle height=5 width=1><br>'."\n";
		}
	
	echo '<center><img src="images/dot.gif" width=1 height=10><br>';
	
	$j=1;

	if ( $nbPages>1 && $debut >= $nb_comment_par_page )
		{
		echo '<a href="'.$pagecommentaire.'.'.$php_extension.'?nom='.$nom.'&debut=0"><img src="'.$fleche_gauche_img.'" align="absmiddle" border=0 alt="'.$str_debut.'"><img src="'.$fleche_gauche_img.'" align="absmiddle" border=0 alt="'.$str_debut.'"></a> ';
		echo '<a href="'.$pagecommentaire.'.'.$php_extension.'?nom='.$nom.'&debut='.($debut-$nb_comment_par_page).'"><img src="'.$fleche_gauche_img.'" align="absmiddle" border=0 alt="'.$str_page_precedente.'"></a>&nbsp;&nbsp;';
		}

	$debut2 = $debut;
	
	while ( $j <= $nbPages)
		{
		$debut=$debut+$nb_comment_par_page;
		if ($j == '1') $debut = 0;
		if ($j != $numPage) echo '<a href="'.$pagecommentaire.'.'.$php_extension.'?nom='.$nom.'&debut='.$debut.'">';
		echo '['.$j.']';
		if ($j != $numPage) echo '</a>';
		echo '&nbsp;&nbsp;';
		$j++;
		}

	if ( $nbPages > 1 && $nbTotalComment > $debut && $nbPages != $numPage )
		{
		echo '<a href="'.$pagecommentaire.'.'.$php_extension.'?nom='.$nom.'&debut='.($debut2+$nb_comment_par_page).'"><img src="'.$fleche_droite_img.'" align="absmiddle" border=0 alt="'.$str_page_suivante.'"></a> ';
		echo '<a href="'.$pagecommentaire.'.'.$php_extension.'?nom='.$nom.'&debut='.(($nbPages*$nb_comment_par_page)-$nb_comment_par_page).'"><img src="'.$fleche_droite_img.'" align="absmiddle" border=0 alt="'.$str_fin.'"><img src="'.$fleche_droite_img.'" align="absmiddle" border=0 alt="'.$str_fin.'"></a>';
		}	
		
	echo '</center>';	
	}
else
	{
	echo '<center>'.$str_aucun_commentaire.'</center><br>'."\n";
	}
?>

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

</tr></table>

</body>
</html>

<?php
mysql_close($connection);
?>