Codice PHP:
<?php
class Estrapola{
public $IDATTIVITA;
public $percorso_foto;
public $row;
public $ultimoCommento;
public $stampa;
private $db;
private $select_db;
private $eseguo;
private $eseguoUltimoCommento;
private $query;
private $queryUltimoCommento;
private $close;
function __construct(){
$this->db_host="localhost";
$this->db_user="user";
$this->db_password="pw";
$this->db_name="database";
}
function connetti(){
$this->db = mysql_connect($this->db_host, $this->db_user, $this->db_password) or die ("Errore nella connessione al database numero: ".mysql_errno()." Descrizione: ".mysql_error());
$this->select_db = mysql_select_db($this->db_name, $this->db) or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
}
function disconnetti(){
$this->close=mysql_close($this->db);
}
function estraiRecord($IDATTIVITA) {
$this->query="SELECT AT.IDATTIVITA, AT.NomeAttivita, AT.DescrizioneAttivita, AT.IndirizzoAttivita, AT.TelefonoAttivita, AT.LatitudineAttivita, AT.LongitudineAttivita, AT.ComeArrivare, AT.VotoCriterio1, AT.VotoCriterio2, AT.VotoCriterio3, AT.VotoCriterio4, AT.EMangiare, AT.EBere, AT.EFumare, AT.EDisabili, AT.EParcheggio, AT.ECani, AT.ECondizionata, AT.ECarte, AT.EWireless, AT.EHostess, AT.ELap, AT.EStrip, AT.EVip, AT.EConferenze, AT.EPiscina, AT.ETennis, AT.EFrigobar, AT.ECassaforte, AT.ETennis, AT.EPalestra, AT.ESpiaggia, AT.EGuardaroba, AT.Foto1, AT.Foto2, AT.Foto3, PR.BConsentita, PR.MailPrenotazione, PR.ReferentePrenotazione, CI.NomeCitta, TIAT.TipoAttivita, TIAT.NomeCriterio1, TIAT.NomeCriterio2, TIAT.NomeCriterio3, TIAT.NomeCriterio4 FROM tblATTIVITA AS AT, tblCITTA AS CI, tblTIPOATTIVITA AS TIAT, tblPRENOTA AS PR WHERE AT.IDCITTA = CI.IDCITTA AND AT.idTIPOATTIVITA=TIAT.idTIPOATTIVITA AND PR.IDATTIVITA = AT.IDATTIVITA AND AT.IDATTIVITA=".$this->IDATTIVITA;
$this->eseguo = mysql_query($this->query,$this->db) or die ("Errore nella query numero: ".mysql_errno()." Descrizione: ".mysql_error());
$this->row = mysql_fetch_array($this->eseguo);
return $this->row;
}
function elaboraRecord($row){
// SETTO I PERCORSI DEI CRITERI
$this->row['PercorsoCriterio1'] = strtolower($this->row[NomeCriterio1])."/".strtolower(substr($this->row[NomeCriterio1],0,1))."_".$this->row[VotoCriterio1].".gif";
$this->row['PercorsoCriterio2'] = strtolower($this->row[NomeCriterio2])."/".strtolower(substr($this->row[NomeCriterio2],0,1))."_".$this->row[VotoCriterio2].".gif";
$this->row['PercorsoCriterio3'] = strtolower($this->row[NomeCriterio3])."/".strtolower(substr($this->row[NomeCriterio3],0,1))."_".$this->row[VotoCriterio3].".gif";
$this->row['PercorsoCriterio4'] = strtolower($this->row[NomeCriterio4])."/".strtolower(substr($this->row[NomeCriterio4],0,1))."_".$this->row[VotoCriterio4].".gif";
//COSTRIUSCO IL PERCORSO DELLE FOTO
//PRIMA
if($this->row['Foto1']){
$this->row['Foto1']=$this->percorso_foto."/".$this->row['Foto1'];
}else{
$this->row['Foto1']=$this->percorso_foto."/no_foto.jpg";
}
//SECONDA
if($this->row['Foto2']){
$this->row['Foto2']=$this->percorso_foto."/".$this->row['Foto2'];
}else{
$this->row['Foto2']=$this->percorso_foto."/no_foto_2.jpg";
}
//TERZA
if($this->row['Foto3']){
$this->row['Foto3']=$this->percorso_foto."/".$this->row['Foto3'];
}else{
$this->row['Foto3']=$this->percorso_foto."/no_foto.jpg";
}
//COSTRUISCO IL NOME DELLA CITTA' PER CHIAMARE LA FOTO
$this->row[NomeCittaFoto]= strtolower($this->row[NomeCitta]);
//ESEGUO IL PARSING DEI DATI SENSIBILI
$this->row['NomeAttivita']= htmlentities($this->row[NomeAttivita]);
$this->row['DescrizioneAttivita']= htmlentities($this->row[DescrizioneAttivita]);
$this->row['ComeArrivare']= htmlentities($this->row[ComeArrivare]);
return $this->row;
}
// FUNZIONE ESTRAPOLA I COMMENTI (SE PRESENTI)
function estrapolaUltimoCommento($IDATTIVITA,$stampa){
$this->queryUltimoCommento="SELECT idUTENTE, Nick, WebSite, Email, TitoloCommento, Commento, DataCommento, Bpubblicato FROM tblCOMMENTI WHERE idATTIVITA=".$this->IDATTIVITA." ORDER BY DataCommento DESC";
$this->eseguoUltimoCommento = mysql_query($this->queryUltimoCommento,$this->db) or die ("Errore nella query Ultimo Commento: ".mysql_errno()." Descrizione: ".mysql_error());
//SE STAMPO E' 1 STAMPO I COMMENTO
if($this->stampa==1){
while($this->ultimoCommento = $this->elaboraUltimoCommento(mysql_fetch_array($this->eseguoUltimoCommento))){
echo"
<p class=\"commenti_ajax\">
<img src=\"img/avatar.gif\" class=\"avatar\" />
<span class=\"titolo_commenti\">".$this->ultimoCommento[TitoloCommento]."</span>
<span class=\"corpo_commenti\">".$this->ultimoCommento[Commento]."</span>
<span class=\"coda_commenti\">Rilasciato da $ultimoCommento[Link] il [i]$ultimoCommento[GiornoCommento] alle ore $ultimoCommento[OraCommento][/i]</span>
</p>
";
}
}
//ALTRIMENTO ESEGUO LA FUNZIONE NORMALMENTE
else {
$this->ultimoCommento = mysql_fetch_array($this->eseguoUltimoCommento);
$this->ultimoCommento['numero']= mysql_num_rows($this->eseguoUltimoCommento);
}
if(!$this->ultimoCommento){
$this->ultimoCommento['numero']="0";
return $this->ultimoCommento;
} else {
return $this->ultimoCommento;
}
}
// FUNZIONE CHE ELABORA I RISULTATI DEI COMMENTI
function elaboraUltimoCommento($ultimoCommento){
$this->ultimoCommento['TitoloCommento'] = htmlentities($this->ultimoCommento['TitoloCommento']);
$this->ultimoCommento['Commento'] = htmlentities($this->ultimoCommento['Commento']);
$this->ultimoCommento['Commento'] = str_replace("€","€",$this->ultimoCommento['Commento']);
$this->ultimoCommento['GiornoCommento'] = date("d/m/Y",$this->ultimoCommento['DataCommento']);
$this->ultimoCommento['OraCommento'] = date("G.i",$this->ultimoCommento['DataCommento']);
if(!$this->ultimoCommento['Nick']){
$this->ultimoCommento['Nick']= "Anonimo";
}
if(!$this->ultimoCommento['WebSite']){
$this->ultimoCommento['Link']= "<a href=\"#\">".$this->ultimoCommento['Nick']."</a>";
} else{
$this->ultimoCommento['Link']= "<a href=\"".$this->ultimoCommento['WebSite']."\" target=\"_blank\">".$this->ultimoCommento['Nick']."</a>";
}
if(!$this->ultimoCommento['Mail']){
$this->ultimoCommento['WebSite']= "#";
}
return $this->ultimoCommento;
}
}
?>