186 lines
6.3 KiB
PHP
186 lines
6.3 KiB
PHP
<?php
|
|
/*************************************************************************************/
|
|
/* */
|
|
/* Thelia */
|
|
/* */
|
|
/* Copyright (c) Octolys Development */
|
|
/* email : thelia@octolys.fr */
|
|
/* web : http://www.octolys.fr */
|
|
/* */
|
|
/* 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. */
|
|
/* */
|
|
/* This program is distributed in the hope that it will be useful, */
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
/* GNU General Public License for more details. */
|
|
/* */
|
|
/* You should have received a copy of the GNU General Public License */
|
|
/* along with this program; if not, write to the Free Software */
|
|
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
/* */
|
|
/*************************************************************************************/
|
|
?>
|
|
<?php
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
|
|
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Variable.class.php");
|
|
|
|
|
|
class Commentaires extends PluginsClassiques{
|
|
|
|
var $id;
|
|
var $commentateur;
|
|
var $ville;
|
|
var $pays;
|
|
var $message;
|
|
var $ref;
|
|
var $titre;
|
|
var $date;
|
|
var $note;
|
|
var $ip;
|
|
var $valide;
|
|
|
|
var $table="commentaires";
|
|
var $bddvars = array("id", "commentateur", "ville", "pays", "message", "ref", "titre", "date", "note", "ip", "valide");
|
|
|
|
function Commentaires(){
|
|
$this->PluginsClassiques();
|
|
}
|
|
|
|
function charger($id, $lang=1){
|
|
|
|
return $this->getVars("select * from $this->table where id=\"$id\"");
|
|
|
|
}
|
|
|
|
|
|
function init(){
|
|
|
|
$cnx = new Cnx();
|
|
$query_commentaires = "CREATE TABLE `commentaires` (
|
|
`id` int(11) NOT NULL auto_increment,
|
|
`commentateur` text NOT NULL,
|
|
`ville` text NOT NULL,
|
|
`pays` text NOT NULL,
|
|
`message` text NOT NULL,
|
|
`ref` text NOT NULL,
|
|
`date` datetime NOT NULL,
|
|
`titre` text NOT NULL,
|
|
`note` int(1) NOT NULL,
|
|
`ip` varchar(15) NOT NULL default '000.000.000.000',
|
|
`valide` char(1) NOT NULL default '0',
|
|
PRIMARY KEY (`id`)
|
|
) AUTO_INCREMENT=1 ;";
|
|
$resul_commentaires = mysql_query($query_commentaires, $cnx->link);
|
|
|
|
}
|
|
|
|
function destroy(){
|
|
|
|
}
|
|
|
|
function boucle($texte, $args){
|
|
// récupération des arguments
|
|
$ref= lireTag($args, "ref");
|
|
$deb= lireTag($args, "deb", "int");
|
|
$num= lireTag($args, "num", "int");
|
|
$classement = lireTag($args, "classement");
|
|
|
|
if(!$deb) $deb = 0;
|
|
|
|
if($num>0)
|
|
$limit = "LIMIT $deb, $num";
|
|
else
|
|
$limit = "";
|
|
|
|
switch($classement)
|
|
{
|
|
case 'croissant':
|
|
$order = "ORDER BY date ASC";
|
|
break;
|
|
case 'decroissant':
|
|
$order = "ORDER BY date DESC";
|
|
break;
|
|
default:
|
|
$order = "ORDER BY date ASC";
|
|
break;
|
|
}
|
|
|
|
$search ="";
|
|
$res="";
|
|
|
|
// préparation de la requête
|
|
if($ref!="") $search.=" and ref=\"$ref\" and valide=\"1\"";
|
|
|
|
$commentaire = new Commentaires();
|
|
|
|
$query_commentaires = "select * from $commentaire->table where 1 $search $order $limit";
|
|
$resul_commentaires = mysql_query($query_commentaires, $commentaire->link);
|
|
$nbres = mysql_numrows($resul_commentaires);
|
|
if(!$nbres) return "";
|
|
|
|
while($row = mysql_fetch_object($resul_commentaires)){
|
|
$temp = str_replace("#COMMENTATEUR", $row->commentateur, $texte);
|
|
$temp = str_replace("#VILLE", $row->ville, $temp);
|
|
$temp = str_replace("#PAYS", $row->pays, $temp);
|
|
$temp = str_replace("#MESSAGE", $row->message, $temp);
|
|
$temp = str_replace("#DATE", substr($row->date, 0, 10), $temp);
|
|
$temp = str_replace("#HEURE", substr($row->date, 11), $temp);
|
|
$temp = str_replace("#TITRE", $row->titre, $temp);
|
|
$temp = str_replace("#NOTE", $row->note, $temp);
|
|
$temp = str_replace("#VALIDE", $row->valide, $temp);
|
|
$res .= $temp;
|
|
}
|
|
return $res;
|
|
|
|
}
|
|
|
|
function action($res){
|
|
|
|
if(isset($_POST['action']) && $_POST['action'] == "ajcommentaire"){
|
|
|
|
$commentaire = new Commentaires();
|
|
$commentaire->commentateur = strip_tags($_POST['commentaire_nom']);
|
|
$commentaire->ville = strip_tags($_POST['commentaire_ville']);
|
|
$commentaire->pays = strip_tags($_POST['commentaire_pays']);
|
|
$commentaire->message = strip_tags($_POST['commentaire_message']);
|
|
$commentaire->ref = strip_tags($_POST['commentaire_ref']);
|
|
$commentaire->titre = strip_tags($_POST["commentaire_titre"]);
|
|
$commentaire->date = date("Y-m-d H:i:s");
|
|
$commentaire->note = strip_tags($_POST["note"]);
|
|
$commentaire->ip = strip_tags($_SERVER['REMOTE_ADDR']);
|
|
$commentaire->valide = 0;
|
|
$commentaire->add();
|
|
|
|
$emailcontact = new Variable();
|
|
$emailcontact->charger("emailcontact");
|
|
|
|
$nomsite = new Variable();
|
|
$nomsite->charger("nomsite");
|
|
|
|
|
|
$mail = new Mail();
|
|
$mail->IsMail();
|
|
$mail->FromName = $nomsite->valeur;
|
|
$mail->From = $emailcontact->valeur;
|
|
$mail->Subject = "nouveau commentaire pour le produit : ".$commentaire->ref;
|
|
$mail->MsgHTML($commentaire->commentateur." : ".$commentaire->message);
|
|
$mail->AltBody = $commentaire->commentateur." : ".$commentaire->message;
|
|
$mail->AddAddress($emailcontact->valeur,$nomsite->valeur);
|
|
|
|
$mail->send();
|
|
|
|
$cache = new Cache();
|
|
$cache->vider("COMMENTAIRES", "%");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
?>
|