par
mauvais » 14 mai 2011, 13:57
Bonjour,
J'ai un problème concernant un envoi de form Post assez standard mais rien ne s'enregistre dans la db étrangement.
Je vous laisse une partie du code épuré de l'inutile pour que vous puissiez m'aider... enfin j'espère.
Il sagit tout simplement d'une page de news avec possibilité de laisser des commentaires si on est enregistré ou des les visualiser à tout moment à l'aide de <button>.
Rien d'extraordinaire mais je flanche complètement sur mon problème, c'est certainement tout con mais je n'arrive pas à trouver... voici les codes
La page principale
<?php
session_start();
function chargClass($class) { require 'lib/'.$class.'.class.php'; } spl_autoload_register('chargClass');
if(isset($_GET['deconnexion'])) { session_destroy(); header('Location:index.php'); }
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>PAGE PRINCPALE</title>
<link href="css/globalStyle.css" rel="stylesheet" type="text/css">
<link href="css/actuStyle.css" rel="stylesheet" type="text/css">
<script src="js/xmlhr.js" type="text/javascript"></script>
<script src="js/global.js" type="text/javascript"></script>
<script src="js/newsPage.js" type="text/javascript"></script>
</head>
<body>
<header>
<!-- LE FORM CI DESSOUS FAIT PARTIE DU HEADER MAIS L'ENSEMBLE DE CE DERNIER EST INUTILE ICI -->
</header>
<?php
try {
$bdd = BDD::OPENBDD();
$bdd->exec('SET NAMES utf8');
if(isset($_POST['connect'])) {
$member = new ConnectMember($bdd, $_POST['email'], $_POST['passwd'], $_SERVER["REMOTE_ADDR"]);
$member->validMember();
}
if(empty($_SESSION['email'])) {
?>
<div id="connectZone">
<div class="coRight">
<form method="post">
<br/><input type="submit" name="connect" value="" id="connexion" />
</div>
<div id="coLeft">
<label for="connect"><span class="legend">E-mail</span></label>
<br/><input type="text" name="email" id="connect" class="connectInput" value="<?php if(isset($_COOKIE['email'])) { echo htmlentities($_COOKIE['email']); } ?>" />
<br/><a href="register.php" title="inscription" style="font-size:0.8em">S'inscrire</a>
</div>
<div id="coCenter">
<label for="passwd"><span class="legend">Mot de passe</span></label>
<br/><input type="password" name="passwd" id="passwd" class="connectInput" />
<br/><a href="passFor.php" title="mot de passe oublié ?" class="alegend">Mot de passe oublié ?</a>
</form>
</div>
</div>
<?php
}
else {
?>
<div id="connectZoneB">
<div id="coAvatar">
<?php
echo '<img src="avatar_user/'.htmlentities($_SESSION['avatar']).'" alt="'.htmlentities($_SESSION['pseudo']).'" id="headAvatar" />';
?>
</div>
<div id="coProfil">
<?php
echo '<strong>'.htmlentities($_SESSION['pseudo']).'</strong>';
?>
<span id="blue"> connecté</span><br/>
<a href="profil_user.php" class="awhite" title="éditez votre profil">Editer mon profil</a>
<br/><a href="?deconnexion=1" title="se déconnecter" style="font-size:0.8em">déconnexion</a>
</div>
</div>
<?php
}
?>
</div>
</div>
<div>
<!-- LE CONTENU DE LA PAGE INUTILE POUR MON PROBLEME ET... -->
<?php
$actu = new BaseActu($bdd);
$actu->viewActu(5);
}
catch(Exception $e) { die ('blah blah blah'); }
?>
</div>
</div>
<foorter>
</footer>
</body></html>
Le js qui appel mes commentaires et mon formualire d'ajout
Code : Tout sélectionner
function openCom(idActu) {
var xhr = getXHR(), btnOn = document.getElementById('on' + idActu).style;
btnOn.display = 'none';
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
document.getElementById('barLoader' + idActu).style.display = 'none';
viewCom(xhr.responseText, idActu);
}
else if(xhr.readyState < 4) {
document.getElementById('barLoader' + idActu).style.display = 'inline';
}
};
xhr.open('POST', 'importPHP/commentList.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('openCom=' + idActu);
}
function viewCom(file, idActu) {
if(file != '') {
var comment = document.getElementById('num' + idActu), btnOff = document.getElementById('off' + idActu).style, actPage = document.getElementById('global').offsetHeight;
comment.innerHTML = file;
document.getElementById('global').style.height = actPage + comment.offsetHeight + 'px';
btnOff.display = 'inline';
}
else {
var btnOn = document.getElementById('on' + idActu).style;
btnOn.display = 'inline';
}
}
function closeCom(idActu) {
var comment = document.getElementById('num' + idActu), btnOn = document.getElementById('on' + idActu).style, btnOff = document.getElementById('off' + idActu).style, actPage = document.getElementById('global').offsetHeight;
document.getElementById('global').style.height = actPage - comment.offsetHeight + 'px';
comment.innerHTML = '';
btnOn.display = 'inline';
btnOff.display = 'none';
}
function openForm(idActu) {
var xhr = getXHR(), btnOn = document.getElementById('onForm' + idActu).style;
btnOn.display = 'none';
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && (xhr.status == 200 || xhr.satus == 0)) {
document.getElementById('barLoader' + idActu).style.display = 'none';
viewForm(xhr.responseText, idActu);
}
else if(xhr.readyState < 4) {
document.getElementById('barLoader' + idActu).style.display = 'inline';
}
};
xhr.open('POST', 'importPHP/commentForm.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'),
xhr.send('openForm=' + idActu);
}
function viewForm(file, idActu) {
var formul = document.getElementById('add' + idActu), actPage = document.getElementById('global').offsetHeight, btnOff = document.getElementById('offForm' + idActu).style, browser = navigator.appName;
formul.innerHTML = file;
if(browser=='Netscape') {
document.getElementById('global').style.height = (actPage + 132) + 'px';
}
else {
document.getElementById('global').style.height = (actPage + 150) + 'px';
}
btnOff.display = 'inline';
}
function closeForm(idActu) {
var formul = document.getElementById('add' + idActu), btnOn = document.getElementById('onForm' + idActu).style, btnOff = document.getElementById('offForm' + idActu).style, actPage = document.getElementById('global').offsetHeight, browser = navigator.appName;
if(browser=='Netscape') {
document.getElementById('global').style.height = (actPage - 132) + 'px';
}
else {
document.getElementById('global').style.height = (actPage - 150) + 'px';
}
formul.innerHTML = '';
btnOn.display = 'inline';
btnOff.display = 'none';
}
//---------------------------------------------------------------------
function visible(thingId, balId) {
var targetElement = document.getElementById(thingId + balId);
if (targetElement.style.display == 'none') {
targetElement.style.display = 'inline' ;
}
else {
targetElement.style.display = 'none' ;
}
}
//---------------------------------------------------------------------
function insertTag(startTag, endTag, textareaId, tagType) {
var field = document.getElementById(textareaId);
var scroll = field.scrollTop;
field.focus();
if (window.ActiveXObject) {
var textRange = document.selection.createRange(), currentSelection = textRange.text;
}
else {
var startSelection = field.value.substring(0, field.selectionStart), currentSelection = field.value.substring(field.selectionStart, field.selectionEnd), endSelection = field.value.substring(field.selectionEnd);
}
if (tagType) {
switch (tagType) {
case "lien":
endTag = "[/lien]";
if(currentSelection) {
if(currentSelection.indexOf("http://") == 0 || currentSelection.indexOf("www.") == 0) {
var label = prompt("Saisissez le texte du lien.") || "";
startTag = "[lien url=\"" + currentSelection + "\"]";
currentSelection = label;
}
else {
var URL = prompt("Saisissez l'URL de la sélection.");
startTag = "[lien url=\"" + URL + "\"]";
}
}
else {
var URL = prompt("Saisissez l'URL du lien.") || "", label = prompt("Quel est le libellé du lien ?") || "";
startTag = "[lien url=\"" + URL + "\"]";
currentSelection = label;
}
break;
case "image":
endTag = "";
if(currentSelection) {
if(currentSelection.indexOf("http://") == 0 || currentSelection.indexOf("www.") == 0) {
var label = "" || "";
startTag = "[img url=\"" + currentSelection + "\"]";
currentSelection = label;
}
else {
var URL = prompt("Saisissez l'URL de la sélection.");
startTag = "[img url=\"" + URL + "\"]";
}
}
else {
var URL = prompt("Saisissez l'URL du lien.") || "", label = "" || "";
startTag = "[img url=\"" + URL + "\"]";
currentSelection = label;
}
break;
}
}
if (window.ActiveXObject) {
textRange.text = startTag + currentSelection + endTag;
textRange.moveStart("character", -endTag.length - currentSelection.length);
textRange.moveEnd("character", -endTag.length);
textRange.select();
}
else {
field.value = startSelection + startTag + currentSelection + endTag + endSelection;
field.focus();
field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
}
field.scrollTop = scroll;
}
//---------------------------------------------------------------------
functi
La page d'appel xhr du formulaire en question
<?php
session_start();
function chargClass($class) { require '../lib/'.$class.'.class.php'; } spl_autoload_register('chargClass');
if(isset($_POST['openForm'])) {
if(empty($_SESSION['email'])) {
echo '
<p>
<span class="error">Vous devez vous identifier pour poster un commentaire.</span>
<br/>
<span class="greyB">Devenez membre de blah blah blah.</span>
<div>
<a href="#" onMouseOut="restoreImage()" onMouseOver="hoverImage(\'inscription\',\'\',\'i/btn/inscriptionB.png\',1)" title="s\'inscrire"><img src="i/btn/inscriptionA.png" name="inscription" alt="insciption" width="180" height="30" border="0"></a>
<p class="greyB">
Ou connectez-vous pour rédiger votre commentaire<br/>
</p>
</div>
</p>';
}
else {
try {
$bdd = BDD::OPENBDD();
$bdd->exec('SET NAMES utf8');
$viewForm = new BaseActu($bdd);
$viewForm->openFormComment(htmlentities($_POST['openForm']));
}
catch(Exception $e) { die(blah blah blah.'); }
}
}
?>
La page d'appel xhr des commentaires
<?php
session_start();
function chargClass($class) { require '../lib/'.$class.'.class.php'; } spl_autoload_register('chargClass');
if(isset($_POST['openCom']))
{
try {
$bdd = BDD::OPENBDD();
$bdd->exec('SET NAMES utf8');
$comment = new BaseActu($bdd);
$comment->viewComment($_POST['openCom']);
}
catch(Exception $e) { die ('blah blah blah'); }
}
?>
Ma class d'actu
<?php
class BaseActu
{
protected $bdd;
protected $val;
public function __construct($bdd) {
$this->bdd = $bdd;
}
public function viewActu($nbr) {
$pagination = new Pagination();
$pagination->controlPage($this->bdd, 'actu', $nbr);
$firstEntry = $pagination->getFirstEntry();
$messageByPage = $pagination->getMessageByPage();
$viewActuQuery = $this->bdd->query('SELECT id, title, picture, content, signature, avatar, nbr_comment, DATE_FORMAT(act_date, \'%d / %m / %Y à %Hh%S\') AS act_date FROM actu ORDER BY id DESC LIMIT '.$firstEntry.', '.$messageByPage.'');
foreach($viewActuQuery as $viewActuDone) {
echo '
<div class="actuGlobal">
<div class="actuWrite">
<img src="avatar_user/'.htmlentities($viewActuDone['avatar']).'" alt="'.htmlentities($viewActuDone['signature']).'" class="actuAvatar" />
</div>
<div class="actuTitle">
<strong>'.strtoupper(htmlentities($viewActuDone['title'])).'</strong>
<br/><span class="gris">posté par <strong>'.$viewActuDone['signature'].'</strong> le '.$viewActuDone['act_date'].'</span>
</div>
<div class="actuContent">';
if($viewActuDone['picture'] != 1)
{
echo '
<div class="actuImg">
<img src="image/'.htmlentities($viewActuDone['picture']).'" alt="'.htmlentities($viewActuDone['title']).'" width="70" height="70" />
</div>';
}
echo $viewActuDone['content'].'
</div>
<div class="actuFooter">
<div class="actuComment">
<span class="pink">'.htmlentities($viewActuDone['nbr_comment']).'</span> commentaires
<span id="on'.htmlentities($viewActuDone['id']).'" style="display:inline"><button id="'.htmlentities($viewActuDone['id']).'" onclick="openCom(this.id);">voir les commentaires</button></span>
<span id="off'.htmlentities($viewActuDone['id']).'" style="display:none"><button id="'.htmlentities($viewActuDone['id']).'" onclick="closeCom(this.id);">masquer les commentaires</button></span>
<span id="barLoader'.htmlentities($viewActuDone['id']).'" style="display:none"> <img src="i/loader/barLoader.gif" alt="chargement" width="120" height="8" /></span>
<span id="onForm'.htmlentities($viewActuDone['id']).'" style="display:inline"><button id="'.htmlentities($viewActuDone['id']).'" onclick="openForm(this.id);">poster un commentaire</button></span>
<span id="offForm'.htmlentities($viewActuDone['id']).'" style="display:none"><button id="'.htmlentities($viewActuDone['id']).'" onclick="closeForm(this.id);">poster un commentaire</button></span>
</div>
</div>
</div>
<div id="add'.htmlentities($viewActuDone['id']).'"></div>
<div id="num'.htmlentities($viewActuDone['id']).'"></div>
<br/>
';
}
$actualPage = $pagination->getActualPage();
$pageNumber = $pagination->getPageNumber();
$pagination->readPage('index', $actualPage, $pageNumber);
$this->val = $viewActuQuery->rowCount();
$viewActuQuery->closeCursor();
}
public function viewComment($id) {
$commentQuery = $this->bdd->query('SELECT id, pseudo, avatar, content, num_actu, DATE_FORMAT(com_date, \'%d/%m/%Y\') AS com_date FROM comment WHERE num_actu = \''.$id.'\' ORDER BY id DESC');
foreach($commentQuery as $commentDone) {
echo '
<br/>
<div class="commBorder">
<div class="commBack">
<div class="commAvatar">
<img src="avatar_user/'.$commentDone['avatar'].'" alt="'.htmlentities($commentDone['pseudo']).'" width="40" height="40" />
</div>
<div class="commContent">
<span class="gris">de <strong>'.htmlentities($commentDone['pseudo']).'</strong> le '.$commentDone['com_date'].'</span>
<p>
'.$commentDone['content'].'
</p>
</div>
</div>
</div>
';
}
}
public function openFormComment($id) {
echo '<div>';
if(isset($_POST['commentPost'])) {
if(empty($_POST['commentContent'])) {
echo 'mal';
}
else {
if(strlen($_POST['commentContent']) < 10 ||strlen($_POST['commentContent']) > 1000) {
echo 'pas bien';
}
else {
$nbrCommentQuery = $this->bdd->query('SELECT nbr_comment FROM actu WHERE id = \''.$id.'\'');
$nbrCommentDone = $nbrCommentQuery->fetch();
$check = new Check();
$check->checkContent($_POST['commentContent']);
$content = $check->getContent();
$this->addComment($id, $_POST['commentContent'], $nbrCommentDone['nbr_comment']);
}
}
}
echo '</div>';
echo '
<p>
<div style="text-align:left">
<form method="post">
<input type="button" value="" id="strong" onclick="insertTag(\'[b]\',\'[/b]\',\'textarea\');" />
<input type="button" value="" id="em" onclick="insertTag(\'[i]\', \'[/i]\', \'textarea\');" />
<input type="button" value="" id="underline" onclick="insertTag(\'[u]\', \'[/u]\', \'textarea\');"/>
<input type="button" value="" id="lien" onclick="insertTag(\'\',\'\',\'textarea\', \'lien\');" />
<input type="button" value="" id="image" onclick="insertTag(\'\',\'\',\'textarea\', \'image\');" />
<input type="button" value="" id="smiley" onclick="visible(\'viewSmiley\', '.$id.');return false" />
<div id="viewSmiley'.$id.'" style="display:none; text-align:left">
<img src="smiley/smile.png" alt="smile" onclick="insertTag(\':-)\', \'\', \'textarea\');" />
<img src="smiley/neutral.png" alt="neutral" onclick="insertTag(\':-|\', \'\', \'textarea\');" />
<img src="smiley/sad.png" alt="sad" onclick="insertTag(\':-(\', \'\', \'textarea\');" />
<img src="smiley/big_smile.png" alt="big smile" onclick="insertTag(\':-D\', \'\', \'textarea\');" />
<img src="smiley/yikes.png" alt="yikes" onclick="insertTag(\':-o\', \'\', \'textarea\');" />
<img src="smiley/wink.png" alt="wink" onclick="insertTag(\';-)\', \'\', \'textarea\');" />
<img src="smiley/hmm.png" alt="hmm" onclick="insertTag(\':-/\', \'\', \'textarea\');" />
<img src="smiley/tongue.png" alt="tongue" onclick="insertTag(\':-P\', \'\', \'textarea\');" />
<img src="smiley/lol.png" alt="lol" onclick="insertTag(\':lol\', \'\', \'textarea\');" />
<img src="smiley/mad.png" alt="mad" onclick="insertTag(\':mad\', \'\', \'textarea\');" />
<img src="smiley/roll.png" alt="roll" onclick="insertTag(\':roll\', \'\', \'textarea\');" />
<img src="smiley/cool.png" alt="cool" onclick="insertTag(\':cool\', \'\', \'textarea\');" />
</div>
<br/>
<textarea name="commentContent" id="textarea">';
if(isset($_POST['commentContent'])) {
echo htmlentities($_POST['commentContent']);
}
echo '</textarea><br/>
<input type="submit" name="commentPost" value="" id="postComment" />
</form>
</div>
</p>
';
}
public function addComment($id, $content, $nbr_comment) {
$comment_prepare = $this->bdd->prepare('INSERT INTO comment (pseudo, avatar, content, num_actu, com_date) VALUES (:pseudo, :avatar, :content, :num_actu, NOW())');
$comment_array = $comment_prepare->execute(array(
':pseudo' => $_SESSION['pseudo'],
':avatar' => $_SESSION['avatar'],
':content' => $content,
':num_actu' => $id
));
$nbr = $nbr_comment++;
$update_nbr_comment = $this->bdd->prepare('UPDATE actu SET nbr_comment = :nbr_comment WHERE id=:this_id');
$update_nbr_comment->execute(array(
':nbr_comment' => $nbr_comment,
':this_id' => $id
));
echo 'Votre commentaire a bien été ajouté.';
}
}
La classe Check (pas forcément utile mais bon)
<?php
class Check
{
private $content;
public function checkContent($content) {
$content = stripslashes($content);
$content = strip_tags($content);
$content = nl2br($content);
$content = preg_replace('#<script#', '', $content);
$content = preg_replace('#</script>#', '', $content);
$content = preg_replace('#mysql#', '', $content);
$content = preg_replace('#<?php#', '', $content);
$content = preg_replace('#\[b\](.+)\[/b\]#isU', '<strong>$1</strong>', $content);
$content = preg_replace('#\[i\](.+)\[/i\]#isU', '<em>$1</em>', $content);
$content = preg_replace('#\[u\](.+)\[/u\]#isU', '<u>$1</u>', $content);
$content = preg_replace('#\[lien url="(.+)"\](.+)\[/lien\]#isU', '<a href="$1" title="ouvrir la page" target="_blank">$2</a>', $content);
$content = preg_replace('#[a-z0-9._/-]+@[a-z0-9._/-]+#i', '<a href="mailto:$0" title="envoyer un e-mail">$0</a>', $content);
$content = preg_replace('#\[lien url="(.+)"\](.+)\[/lien\]#isU', '<a href="$1" title="ouvrir la page" target="_blank">$2</a>', $content);
$content = preg_replace('#\[img url="(.+)"\]#isU', '<img src="$1" alt="machin.com" width="80" height="80" />', $content);
$content = preg_replace('#:-\)#', '<img src="smiley/smile.png" width="15 height="15" />', $content);
$content = preg_replace('#:-\|#', '<img src="smiley/neutral.png" width="15 height="15" />', $content);
$content = preg_replace('#:-\(#', '<img src="smiley/sad.png" width="15 height="15" />', $content);
$content = preg_replace('#:-D#', '<img src="smiley/big_smile.png" width="15 height="15" />', $content);
$content = preg_replace('#:-o#', '<img src="smiley/yikes.png" width="15 height="15" />', $content);
$content = preg_replace('#;-\)#', '<img src="smiley/wink.png" width="15 height="15" />', $content);
$content = preg_replace('#:-\/#', '<img src="smiley/hmm.png" width="15 height="15" />', $content);
$content = preg_replace('#:-P#', '<img src="smiley/tongue.png" width="15 height="15" />', $content);
$content = preg_replace('#:lol#', '<img src="smiley/lol.png" width="15 height="15" />', $content);
$content = preg_replace('#:mad#', '<img src="smiley/mad.png" width="15 height="15" />', $content);
$content = preg_replace('#:roll#', '<img src="smiley/roll.png" width="15 height="15" />', $content);
$content = preg_replace('#:cool#', '<img src="smiley/cool.png" width="15 height="15" />', $content);
$this->content = $content;
}
public function getContent() {
return $this->content;
}
}
Inutile d'indiquer mes feuilles css ou le xmlhr.js qui n'a aucun problème et il y en a déjà pas mal là.
Si quelqu'un parmis vous pouvait m'aider, ce serait trop la fête pour moi... merci par avance.
Bonjour,
J'ai un problème concernant un envoi de form Post assez standard mais rien ne s'enregistre dans la db étrangement.
Je vous laisse une partie du code épuré de l'inutile pour que vous puissiez m'aider... enfin j'espère.
Il sagit tout simplement d'une page de news avec possibilité de laisser des commentaires si on est enregistré ou des les visualiser à tout moment à l'aide de <button>.
Rien d'extraordinaire mais je flanche complètement sur mon problème, c'est certainement tout con mais je n'arrive pas à trouver... voici les codes
[b]La page principale[/b]
[php]
<?php
session_start();
function chargClass($class) { require 'lib/'.$class.'.class.php'; } spl_autoload_register('chargClass');
if(isset($_GET['deconnexion'])) { session_destroy(); header('Location:index.php'); }
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>PAGE PRINCPALE</title>
<link href="css/globalStyle.css" rel="stylesheet" type="text/css">
<link href="css/actuStyle.css" rel="stylesheet" type="text/css">
<script src="js/xmlhr.js" type="text/javascript"></script>
<script src="js/global.js" type="text/javascript"></script>
<script src="js/newsPage.js" type="text/javascript"></script>
</head>
<body>
<header>
<!-- LE FORM CI DESSOUS FAIT PARTIE DU HEADER MAIS L'ENSEMBLE DE CE DERNIER EST INUTILE ICI -->
</header>
<?php
try {
$bdd = BDD::OPENBDD();
$bdd->exec('SET NAMES utf8');
if(isset($_POST['connect'])) {
$member = new ConnectMember($bdd, $_POST['email'], $_POST['passwd'], $_SERVER["REMOTE_ADDR"]);
$member->validMember();
}
if(empty($_SESSION['email'])) {
?>
<div id="connectZone">
<div class="coRight">
<form method="post">
<br/><input type="submit" name="connect" value="" id="connexion" />
</div>
<div id="coLeft">
<label for="connect"><span class="legend">E-mail</span></label>
<br/><input type="text" name="email" id="connect" class="connectInput" value="<?php if(isset($_COOKIE['email'])) { echo htmlentities($_COOKIE['email']); } ?>" />
<br/><a href="register.php" title="inscription" style="font-size:0.8em">S'inscrire</a>
</div>
<div id="coCenter">
<label for="passwd"><span class="legend">Mot de passe</span></label>
<br/><input type="password" name="passwd" id="passwd" class="connectInput" />
<br/><a href="passFor.php" title="mot de passe oublié ?" class="alegend">Mot de passe oublié ?</a>
</form>
</div>
</div>
<?php
}
else {
?>
<div id="connectZoneB">
<div id="coAvatar">
<?php
echo '<img src="avatar_user/'.htmlentities($_SESSION['avatar']).'" alt="'.htmlentities($_SESSION['pseudo']).'" id="headAvatar" />';
?>
</div>
<div id="coProfil">
<?php
echo '<strong>'.htmlentities($_SESSION['pseudo']).'</strong>';
?>
<span id="blue"> connecté</span><br/>
<a href="profil_user.php" class="awhite" title="éditez votre profil">Editer mon profil</a>
<br/><a href="?deconnexion=1" title="se déconnecter" style="font-size:0.8em">déconnexion</a>
</div>
</div>
<?php
}
?>
</div>
</div>
<div>
<!-- LE CONTENU DE LA PAGE INUTILE POUR MON PROBLEME ET... -->
<?php
$actu = new BaseActu($bdd);
$actu->viewActu(5);
}
catch(Exception $e) { die ('blah blah blah'); }
?>
</div>
</div>
<foorter>
</footer>
</body></html>
[/php]
[b]
Le js qui appel mes commentaires et mon formualire d'ajout[/b]
[code]
function openCom(idActu) {
var xhr = getXHR(), btnOn = document.getElementById('on' + idActu).style;
btnOn.display = 'none';
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
document.getElementById('barLoader' + idActu).style.display = 'none';
viewCom(xhr.responseText, idActu);
}
else if(xhr.readyState < 4) {
document.getElementById('barLoader' + idActu).style.display = 'inline';
}
};
xhr.open('POST', 'importPHP/commentList.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('openCom=' + idActu);
}
function viewCom(file, idActu) {
if(file != '') {
var comment = document.getElementById('num' + idActu), btnOff = document.getElementById('off' + idActu).style, actPage = document.getElementById('global').offsetHeight;
comment.innerHTML = file;
document.getElementById('global').style.height = actPage + comment.offsetHeight + 'px';
btnOff.display = 'inline';
}
else {
var btnOn = document.getElementById('on' + idActu).style;
btnOn.display = 'inline';
}
}
function closeCom(idActu) {
var comment = document.getElementById('num' + idActu), btnOn = document.getElementById('on' + idActu).style, btnOff = document.getElementById('off' + idActu).style, actPage = document.getElementById('global').offsetHeight;
document.getElementById('global').style.height = actPage - comment.offsetHeight + 'px';
comment.innerHTML = '';
btnOn.display = 'inline';
btnOff.display = 'none';
}
function openForm(idActu) {
var xhr = getXHR(), btnOn = document.getElementById('onForm' + idActu).style;
btnOn.display = 'none';
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && (xhr.status == 200 || xhr.satus == 0)) {
document.getElementById('barLoader' + idActu).style.display = 'none';
viewForm(xhr.responseText, idActu);
}
else if(xhr.readyState < 4) {
document.getElementById('barLoader' + idActu).style.display = 'inline';
}
};
xhr.open('POST', 'importPHP/commentForm.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'),
xhr.send('openForm=' + idActu);
}
function viewForm(file, idActu) {
var formul = document.getElementById('add' + idActu), actPage = document.getElementById('global').offsetHeight, btnOff = document.getElementById('offForm' + idActu).style, browser = navigator.appName;
formul.innerHTML = file;
if(browser=='Netscape') {
document.getElementById('global').style.height = (actPage + 132) + 'px';
}
else {
document.getElementById('global').style.height = (actPage + 150) + 'px';
}
btnOff.display = 'inline';
}
function closeForm(idActu) {
var formul = document.getElementById('add' + idActu), btnOn = document.getElementById('onForm' + idActu).style, btnOff = document.getElementById('offForm' + idActu).style, actPage = document.getElementById('global').offsetHeight, browser = navigator.appName;
if(browser=='Netscape') {
document.getElementById('global').style.height = (actPage - 132) + 'px';
}
else {
document.getElementById('global').style.height = (actPage - 150) + 'px';
}
formul.innerHTML = '';
btnOn.display = 'inline';
btnOff.display = 'none';
}
//---------------------------------------------------------------------
function visible(thingId, balId) {
var targetElement = document.getElementById(thingId + balId);
if (targetElement.style.display == 'none') {
targetElement.style.display = 'inline' ;
}
else {
targetElement.style.display = 'none' ;
}
}
//---------------------------------------------------------------------
function insertTag(startTag, endTag, textareaId, tagType) {
var field = document.getElementById(textareaId);
var scroll = field.scrollTop;
field.focus();
if (window.ActiveXObject) {
var textRange = document.selection.createRange(), currentSelection = textRange.text;
}
else {
var startSelection = field.value.substring(0, field.selectionStart), currentSelection = field.value.substring(field.selectionStart, field.selectionEnd), endSelection = field.value.substring(field.selectionEnd);
}
if (tagType) {
switch (tagType) {
case "lien":
endTag = "[/lien]";
if(currentSelection) {
if(currentSelection.indexOf("http://") == 0 || currentSelection.indexOf("www.") == 0) {
var label = prompt("Saisissez le texte du lien.") || "";
startTag = "[lien url=\"" + currentSelection + "\"]";
currentSelection = label;
}
else {
var URL = prompt("Saisissez l'URL de la sélection.");
startTag = "[lien url=\"" + URL + "\"]";
}
}
else {
var URL = prompt("Saisissez l'URL du lien.") || "", label = prompt("Quel est le libellé du lien ?") || "";
startTag = "[lien url=\"" + URL + "\"]";
currentSelection = label;
}
break;
case "image":
endTag = "";
if(currentSelection) {
if(currentSelection.indexOf("http://") == 0 || currentSelection.indexOf("www.") == 0) {
var label = "" || "";
startTag = "[img url=\"" + currentSelection + "\"]";
currentSelection = label;
}
else {
var URL = prompt("Saisissez l'URL de la sélection.");
startTag = "[img url=\"" + URL + "\"]";
}
}
else {
var URL = prompt("Saisissez l'URL du lien.") || "", label = "" || "";
startTag = "[img url=\"" + URL + "\"]";
currentSelection = label;
}
break;
}
}
if (window.ActiveXObject) {
textRange.text = startTag + currentSelection + endTag;
textRange.moveStart("character", -endTag.length - currentSelection.length);
textRange.moveEnd("character", -endTag.length);
textRange.select();
}
else {
field.value = startSelection + startTag + currentSelection + endTag + endSelection;
field.focus();
field.setSelectionRange(startSelection.length + startTag.length, startSelection.length + startTag.length + currentSelection.length);
}
field.scrollTop = scroll;
}
//---------------------------------------------------------------------
functi
[/code]
[b]La page d'appel xhr du formulaire en question[/b]
[php]
<?php
session_start();
function chargClass($class) { require '../lib/'.$class.'.class.php'; } spl_autoload_register('chargClass');
if(isset($_POST['openForm'])) {
if(empty($_SESSION['email'])) {
echo '
<p>
<span class="error">Vous devez vous identifier pour poster un commentaire.</span>
<br/>
<span class="greyB">Devenez membre de blah blah blah.</span>
<div>
<a href="#" onMouseOut="restoreImage()" onMouseOver="hoverImage(\'inscription\',\'\',\'i/btn/inscriptionB.png\',1)" title="s\'inscrire"><img src="i/btn/inscriptionA.png" name="inscription" alt="insciption" width="180" height="30" border="0"></a>
<p class="greyB">
Ou connectez-vous pour rédiger votre commentaire<br/>
</p>
</div>
</p>';
}
else {
try {
$bdd = BDD::OPENBDD();
$bdd->exec('SET NAMES utf8');
$viewForm = new BaseActu($bdd);
$viewForm->openFormComment(htmlentities($_POST['openForm']));
}
catch(Exception $e) { die(blah blah blah.'); }
}
}
?>
[/php]
[b]La page d'appel xhr des commentaires[/b]
[php]
<?php
session_start();
function chargClass($class) { require '../lib/'.$class.'.class.php'; } spl_autoload_register('chargClass');
if(isset($_POST['openCom']))
{
try {
$bdd = BDD::OPENBDD();
$bdd->exec('SET NAMES utf8');
$comment = new BaseActu($bdd);
$comment->viewComment($_POST['openCom']);
}
catch(Exception $e) { die ('blah blah blah'); }
}
?>
[/php]
[b]Ma class d'actu[/b]
[php]
<?php
class BaseActu
{
protected $bdd;
protected $val;
public function __construct($bdd) {
$this->bdd = $bdd;
}
public function viewActu($nbr) {
$pagination = new Pagination();
$pagination->controlPage($this->bdd, 'actu', $nbr);
$firstEntry = $pagination->getFirstEntry();
$messageByPage = $pagination->getMessageByPage();
$viewActuQuery = $this->bdd->query('SELECT id, title, picture, content, signature, avatar, nbr_comment, DATE_FORMAT(act_date, \'%d / %m / %Y à %Hh%S\') AS act_date FROM actu ORDER BY id DESC LIMIT '.$firstEntry.', '.$messageByPage.'');
foreach($viewActuQuery as $viewActuDone) {
echo '
<div class="actuGlobal">
<div class="actuWrite">
<img src="avatar_user/'.htmlentities($viewActuDone['avatar']).'" alt="'.htmlentities($viewActuDone['signature']).'" class="actuAvatar" />
</div>
<div class="actuTitle">
<strong>'.strtoupper(htmlentities($viewActuDone['title'])).'</strong>
<br/><span class="gris">posté par <strong>'.$viewActuDone['signature'].'</strong> le '.$viewActuDone['act_date'].'</span>
</div>
<div class="actuContent">';
if($viewActuDone['picture'] != 1)
{
echo '
<div class="actuImg">
<img src="image/'.htmlentities($viewActuDone['picture']).'" alt="'.htmlentities($viewActuDone['title']).'" width="70" height="70" />
</div>';
}
echo $viewActuDone['content'].'
</div>
<div class="actuFooter">
<div class="actuComment">
<span class="pink">'.htmlentities($viewActuDone['nbr_comment']).'</span> commentaires
<span id="on'.htmlentities($viewActuDone['id']).'" style="display:inline"><button id="'.htmlentities($viewActuDone['id']).'" onclick="openCom(this.id);">voir les commentaires</button></span>
<span id="off'.htmlentities($viewActuDone['id']).'" style="display:none"><button id="'.htmlentities($viewActuDone['id']).'" onclick="closeCom(this.id);">masquer les commentaires</button></span>
<span id="barLoader'.htmlentities($viewActuDone['id']).'" style="display:none"> <img src="i/loader/barLoader.gif" alt="chargement" width="120" height="8" /></span>
<span id="onForm'.htmlentities($viewActuDone['id']).'" style="display:inline"><button id="'.htmlentities($viewActuDone['id']).'" onclick="openForm(this.id);">poster un commentaire</button></span>
<span id="offForm'.htmlentities($viewActuDone['id']).'" style="display:none"><button id="'.htmlentities($viewActuDone['id']).'" onclick="closeForm(this.id);">poster un commentaire</button></span>
</div>
</div>
</div>
<div id="add'.htmlentities($viewActuDone['id']).'"></div>
<div id="num'.htmlentities($viewActuDone['id']).'"></div>
<br/>
';
}
$actualPage = $pagination->getActualPage();
$pageNumber = $pagination->getPageNumber();
$pagination->readPage('index', $actualPage, $pageNumber);
$this->val = $viewActuQuery->rowCount();
$viewActuQuery->closeCursor();
}
public function viewComment($id) {
$commentQuery = $this->bdd->query('SELECT id, pseudo, avatar, content, num_actu, DATE_FORMAT(com_date, \'%d/%m/%Y\') AS com_date FROM comment WHERE num_actu = \''.$id.'\' ORDER BY id DESC');
foreach($commentQuery as $commentDone) {
echo '
<br/>
<div class="commBorder">
<div class="commBack">
<div class="commAvatar">
<img src="avatar_user/'.$commentDone['avatar'].'" alt="'.htmlentities($commentDone['pseudo']).'" width="40" height="40" />
</div>
<div class="commContent">
<span class="gris">de <strong>'.htmlentities($commentDone['pseudo']).'</strong> le '.$commentDone['com_date'].'</span>
<p>
'.$commentDone['content'].'
</p>
</div>
</div>
</div>
';
}
}
public function openFormComment($id) {
echo '<div>';
if(isset($_POST['commentPost'])) {
if(empty($_POST['commentContent'])) {
echo 'mal';
}
else {
if(strlen($_POST['commentContent']) < 10 ||strlen($_POST['commentContent']) > 1000) {
echo 'pas bien';
}
else {
$nbrCommentQuery = $this->bdd->query('SELECT nbr_comment FROM actu WHERE id = \''.$id.'\'');
$nbrCommentDone = $nbrCommentQuery->fetch();
$check = new Check();
$check->checkContent($_POST['commentContent']);
$content = $check->getContent();
$this->addComment($id, $_POST['commentContent'], $nbrCommentDone['nbr_comment']);
}
}
}
echo '</div>';
echo '
<p>
<div style="text-align:left">
<form method="post">
<input type="button" value="" id="strong" onclick="insertTag(\'[b]\',\'[/b]\',\'textarea\');" />
<input type="button" value="" id="em" onclick="insertTag(\'[i]\', \'[/i]\', \'textarea\');" />
<input type="button" value="" id="underline" onclick="insertTag(\'[u]\', \'[/u]\', \'textarea\');"/>
<input type="button" value="" id="lien" onclick="insertTag(\'\',\'\',\'textarea\', \'lien\');" />
<input type="button" value="" id="image" onclick="insertTag(\'\',\'\',\'textarea\', \'image\');" />
<input type="button" value="" id="smiley" onclick="visible(\'viewSmiley\', '.$id.');return false" />
<div id="viewSmiley'.$id.'" style="display:none; text-align:left">
<img src="smiley/smile.png" alt="smile" onclick="insertTag(\':-)\', \'\', \'textarea\');" />
<img src="smiley/neutral.png" alt="neutral" onclick="insertTag(\':-|\', \'\', \'textarea\');" />
<img src="smiley/sad.png" alt="sad" onclick="insertTag(\':-(\', \'\', \'textarea\');" />
<img src="smiley/big_smile.png" alt="big smile" onclick="insertTag(\':-D\', \'\', \'textarea\');" />
<img src="smiley/yikes.png" alt="yikes" onclick="insertTag(\':-o\', \'\', \'textarea\');" />
<img src="smiley/wink.png" alt="wink" onclick="insertTag(\';-)\', \'\', \'textarea\');" />
<img src="smiley/hmm.png" alt="hmm" onclick="insertTag(\':-/\', \'\', \'textarea\');" />
<img src="smiley/tongue.png" alt="tongue" onclick="insertTag(\':-P\', \'\', \'textarea\');" />
<img src="smiley/lol.png" alt="lol" onclick="insertTag(\':lol\', \'\', \'textarea\');" />
<img src="smiley/mad.png" alt="mad" onclick="insertTag(\':mad\', \'\', \'textarea\');" />
<img src="smiley/roll.png" alt="roll" onclick="insertTag(\':roll\', \'\', \'textarea\');" />
<img src="smiley/cool.png" alt="cool" onclick="insertTag(\':cool\', \'\', \'textarea\');" />
</div>
<br/>
<textarea name="commentContent" id="textarea">';
if(isset($_POST['commentContent'])) {
echo htmlentities($_POST['commentContent']);
}
echo '</textarea><br/>
<input type="submit" name="commentPost" value="" id="postComment" />
</form>
</div>
</p>
';
}
public function addComment($id, $content, $nbr_comment) {
$comment_prepare = $this->bdd->prepare('INSERT INTO comment (pseudo, avatar, content, num_actu, com_date) VALUES (:pseudo, :avatar, :content, :num_actu, NOW())');
$comment_array = $comment_prepare->execute(array(
':pseudo' => $_SESSION['pseudo'],
':avatar' => $_SESSION['avatar'],
':content' => $content,
':num_actu' => $id
));
$nbr = $nbr_comment++;
$update_nbr_comment = $this->bdd->prepare('UPDATE actu SET nbr_comment = :nbr_comment WHERE id=:this_id');
$update_nbr_comment->execute(array(
':nbr_comment' => $nbr_comment,
':this_id' => $id
));
echo 'Votre commentaire a bien été ajouté.';
}
}
[/php]
[b]La classe Check (pas forcément utile mais bon)[/b]
[php]
<?php
class Check
{
private $content;
public function checkContent($content) {
$content = stripslashes($content);
$content = strip_tags($content);
$content = nl2br($content);
$content = preg_replace('#<script#', '', $content);
$content = preg_replace('#</script>#', '', $content);
$content = preg_replace('#mysql#', '', $content);
$content = preg_replace('#<?php#', '', $content);
$content = preg_replace('#\[b\](.+)\[/b\]#isU', '<strong>$1</strong>', $content);
$content = preg_replace('#\[i\](.+)\[/i\]#isU', '<em>$1</em>', $content);
$content = preg_replace('#\[u\](.+)\[/u\]#isU', '<u>$1</u>', $content);
$content = preg_replace('#\[lien url="(.+)"\](.+)\[/lien\]#isU', '<a href="$1" title="ouvrir la page" target="_blank">$2</a>', $content);
$content = preg_replace('#[a-z0-9._/-]+@[a-z0-9._/-]+#i', '<a href="mailto:$0" title="envoyer un e-mail">$0</a>', $content);
$content = preg_replace('#\[lien url="(.+)"\](.+)\[/lien\]#isU', '<a href="$1" title="ouvrir la page" target="_blank">$2</a>', $content);
$content = preg_replace('#\[img url="(.+)"\]#isU', '<img src="$1" alt="machin.com" width="80" height="80" />', $content);
$content = preg_replace('#:-\)#', '<img src="smiley/smile.png" width="15 height="15" />', $content);
$content = preg_replace('#:-\|#', '<img src="smiley/neutral.png" width="15 height="15" />', $content);
$content = preg_replace('#:-\(#', '<img src="smiley/sad.png" width="15 height="15" />', $content);
$content = preg_replace('#:-D#', '<img src="smiley/big_smile.png" width="15 height="15" />', $content);
$content = preg_replace('#:-o#', '<img src="smiley/yikes.png" width="15 height="15" />', $content);
$content = preg_replace('#;-\)#', '<img src="smiley/wink.png" width="15 height="15" />', $content);
$content = preg_replace('#:-\/#', '<img src="smiley/hmm.png" width="15 height="15" />', $content);
$content = preg_replace('#:-P#', '<img src="smiley/tongue.png" width="15 height="15" />', $content);
$content = preg_replace('#:lol#', '<img src="smiley/lol.png" width="15 height="15" />', $content);
$content = preg_replace('#:mad#', '<img src="smiley/mad.png" width="15 height="15" />', $content);
$content = preg_replace('#:roll#', '<img src="smiley/roll.png" width="15 height="15" />', $content);
$content = preg_replace('#:cool#', '<img src="smiley/cool.png" width="15 height="15" />', $content);
$this->content = $content;
}
public function getContent() {
return $this->content;
}
}
[/php]
Inutile d'indiquer mes feuilles css ou le xmlhr.js qui n'a aucun problème et il y en a déjà pas mal là. #-o
Si quelqu'un parmis vous pouvait m'aider, ce serait trop la fête pour moi... merci par avance.