ID = 0;
$this->Nome = "";
$this->Descrizione = "";
$this->Foto = "";
$this->IDTipo = 0;
$this->NomeTipo = "";
$this->Email = "";
$this->Telefono = "";
$this->Indirizzo = "";
$this->IDComune = "";
$this->IDProvincia = "";
$this->IDNazione = "";
$this->Registrato = 0;
$this->Attivo = 0;
$this->Latitudine = 0;
$this->Longitudine = 0;
$this->TipoNome = 0;
$this->TipoIsLuogo = 0;
$this->TipoIsArtista = 0;
$this->TipoCreaEvento = 0;
$this->TipoCreaConcerto = 0;
$this->Genere = "";
$this->IDGenere = 0;
$this->SottoGenere = "";
if (is_numeric($id))
{
if ($id > 0)
{
$query = "SELECT e.*, te.Nome NomeTipo, te.IsLuogo, te.IsArtista, te.CreaEvento, te.CreaConcerto, gm.Nome Genere from realta e INNER JOIN tipo_realta te ON e.IDTipo = te.ID LEFT OUTER JOIN genere_musicale gm ON e.IDGenere = gm.ID WHERE e.ID = " . $id;
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
$row = mysql_fetch_assoc($res);
$this->ID = $row["ID"];
$this->Nome = $row["Nome"];
$this->Descrizione = $row["Descrizione"];
$this->Foto = $row["Foto"];
$this->IDTipo = $row["IDTipo"];
$this->NomeTipo = $row["NomeTipo"];
$this->Email = $row["Email"];
$this->Telefono = $row["Telefono"];
$this->Indirizzo = $row["Indirizzo"];
$this->IDComune = $row["IDComune"];
$this->IDProvincia = $row["IDProvincia"];
$this->IDNazione = $row["IDNazione"];
$this->Registrato = $row["Registrato"];
$this->Attivo = $row["Attivo"];
$this->Latitudine = $row["Latitudine"];
$this->Longitudine = $row["Longitudine"];
$this->TipoIsLuogo = $row["IsLuogo"];
$this->TipoIsArtista = $row["IsArtista"];
$this->TipoCreaEvento = $row["CreaEvento"];
$this->TipoCreaConcerto = $row["CreaConcerto"];
$this->Genere = $row["Genere"];
$this->IDGenere = $row["IDGenere"];
$this->SottoGenere = $row["SottoGenere"];
}
}
}
}
function getNomeRealta($db, $id)
{
$query = "SELECT Nome FROM tipo_realta WHERE ID = " . $id;
return $db->getSingleValue($query);
}
function newRealta($db, $tiporealta, $nome, $provincia, $nazione, $utente)
{
$ok = true;
if ($provincia != "")
{
$query = "SELECT * FROM realta WHERE UPPER(Nome) = '" . strtoupper(pulisci($nome)) . "' AND IDProvincia = '" . $provincia . "' AND Attivo = 1";
}
else
{
$query = "SELECT * FROM realta WHERE UPPER(Nome) = '" . strtoupper(pulisci($nome)) . "' AND IDNazione = '" . $nazione . "' AND Attivo = 1";
}
$res0 = $db->getRecordset($query);
$num_row0 = mysql_num_rows($res0);
if ($num_row0 > 0)
{
$row0 = mysql_fetch_assoc($res0);
$IDRealta = $row0["ID"];
if ($row0["Registrato"] == 1)
{
$query = "";
$query .= "SELECT u.Email FROM utente u INNER JOIN utente_realta ue ON u.ID = ue.IDUtente AND ue.Attivo = 1 AND ue.IDRealta = " . $IDRealta . " WHERE u.Attivo = 1 ";
$query .= "UNION ALL ";
if ($provincia != "")
{
$query .= "SELECT u.Email FROM utente u INNER JOIN utente_zona uz ON u.ID = uz.IDUtente INNER JOIN zona_provincia zp ON uz.IDZona = zp.IDZona WHERE u.Attivo = 1 AND zp.IDProvincia = '" . $provincia . "' ";
}
else
{
$query .= "SELECT u.Email FROM utente u INNER JOIN utente_zona uz ON u.ID = uz.IDUtente INNER JOIN zona_nazione zn ON uz.IDZona = zn.IDZona WHERE u.Attivo = 1 AND zn.IDNazione = '" . $nazione . "' ";
}
$query .= "UNION ALL ";
$query .= "SELECT u.Email FROM utente u WHERE u.Attivo = 1 AND u.IDTipo = 99 ";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
$testoMail = "Un utente ha cercato di gestire la Realtà " . strtoupper(pulisci($nome)) . " gestita/controllata da te.
Controlla nella tua Area Utente se accettare la sua richiesta.";
while($row = mysql_fetch_assoc($res))
{
sendMail("", $row["Email"], "LiveUs.it -> Gestione Realtà musicale", $testoMail);
}
}
$query = "SELECT count(*) FROM utente_realta WHERE IDUtente = " . $utente->ID . " AND IDRealta = " . $IDRealta;
$giaRichiesto = $db->getSingleValue($query);
if ($giaRichiesto == 0)
{
$query = "INSERT INTO utente_realta (IDUtente, IDRealta, Attivo) VALUES (" . $utente->ID . ", " . $IDRealta . ", 0)";
$db->exec($query);
}
$ok = false;
}
else
{
$query = "UPDATE realta SET Registrato = 1, Update_ID = " . $_SESSION["UtenteID"] . ", Update_DataOra = Now() WHERE ID = " . $IDRealta;
$db->exec($query);
$query = "INSERT INTO utente_realta (IDUtente, IDRealta, Attivo) VALUES (" . $utente->ID . ", " . $IDRealta . ", 1)";
$db->exec($query);
array_push($_SESSION["UtenteRealta"], $IDRealta);
array_push($_SESSION["UtenteNomeRealta"], pulisci($nome));
//array_push($utente->UtenteRealta, $IDRealta);
//array_push($utente->UtentNomeeRealta, pulisci($nome));
}
}
else
{
$query = "SELECT MAX(ID) FROM realta";
$IDRealta = $db->getSingleValue($query) + 1;
$query = "INSERT INTO realta (ID, Nome, IDProvincia, IDNazione, IDTipo, Registrato, Attivo, Insert_ID, Insert_DataOra) VALUES (" . $IDRealta . ", '" . pulisci($nome) . "', '" . $provincia . "', '" . $nazione . "', " . $tiporealta . ", 1, 1, " . $_SESSION["UtenteID"] . ", Now())";
$db->exec($query);
$query = "INSERT INTO utente_realta (IDUtente, IDRealta, Attivo) VALUES (" . $utente->ID . ", " . $IDRealta . ", 1)";
$db->exec($query);
array_push($_SESSION["UtenteRealta"], $IDRealta);
array_push($_SESSION["UtenteNomeRealta"], pulisci($nome));
//array_push($utente->UtenteRealta, $IDRealta);
//array_push($utente->UtentNomeeRealta, pulisci($nome));
}
$this->Nome = $nome;
$this->IDProvincia = $provincia;
return $ok;
}
function uploadFoto($db, $foto)
{
saveImage($db, "realta", 200, 200, $foto, $this->ID, $this->Foto, "", "tb_", false);
saveImage($db, "realta", 800, 800, $foto, $this->ID, $this->Foto, "", "", true);
}
function modRealtaData($db, $ID, $Descrizione, $Email, $Telefono, $Indirizzo, $IDComune, $IDProvincia, $IDNazione, $Nome, $IDTipo, $IDGenere, $SottoGenere)
{
if ($IDComune != "" || $IDProvincia || "")
{
$IDNazione = "I";
if ($IDComune != "")
{
$query = "SELECT Provincia FROM comuni WHERE CodCom = '" . $IDComune . "'";
$IDProvincia = $db->getSingleValue($query);
}
}
$queryAdmin = "";
if ($Nome != "")
{
$queryAdmin = ", Nome = '" . formatSQL($Nome) . "', IDTipo = " . $IDTipo;
}
$query = "UPDATE realta
SET Update_ID = " . $_SESSION["UtenteID"] . ", ";
if ($Descrizione != "")
{
$query .= " Descrizione = '" . formatSQL($Descrizione) . "', ";
}
if ($Email != "")
{
$query .= " Email = '" . formatSQL($Email) . "', ";
}
if ($Telefono != "")
{
$query .= " Telefono = '" . formatSQL($Telefono) . "', ";
}
if ($Indirizzo != "")
{
$query .= " Indirizzo = '" . formatSQL($Indirizzo) . "', ";
}
if ($IDComune != "")
{
$query .= " IDComune = '" . $IDComune . "', ";
}
if ($IDProvincia != "")
{
$query .= " IDProvincia = '" . $IDProvincia . "', ";
}
if ($IDNazione != "")
{
$query .= " IDNazione = '" . $IDNazione . "',";
}
if ($IDGenere != "")
{
$query .= " IDGenere = " . $IDGenere . ", ";
}
if ($SottoGenere != "")
{
$query .= " SottoGenere = '" . formatSQL($SottoGenere) . "', ";
}
$query .= " Update_DataOra = Now() " . $queryAdmin . "
WHERE ID = " . $ID;
//$db->exec("INSERT INTO debug_query (Query) VALUES ('" . formatSQL($query) . "')");
$db->exec($query);
$this->Descrizione = formatTXT($Descrizione);
$this->Email = formatTXT($Email);
$this->Telefono = formatTXT($Telefono);
$this->Indirizzo = formatTXT($Indirizzo);
$this->IDComune = $IDComune;
$this->IDProvincia = $IDProvincia;
$this->IDNazione = $IDNazione;
$this->Genere = $this->getGenere($db);
$this->IDGenere = $IDGenere;
$this->SottoGenere = formatTXT($SottoGenere);
if ($Nome != "")
{
$this->Nome = formatTXT($Nome);
$this->IDTipo = $IDTipo;
}
}
function getComune($db)
{
$ritorno = "";
if ($this->IDComune != "")
{
$query = "SELECT Comune FROM comuni WHERE CodCom = '" . $this->IDComune . "'";
$ritorno = $db->getSingleValue($query);
}
return $ritorno;
}
function getProvincia($db)
{
$ritorno = "";
if ($this->IDProvincia != "")
{
$query = "SELECT Nome FROM provincia WHERE Sigla = '" . $this->IDProvincia . "'";
$ritorno = $db->getSingleValue($query);
}
return $ritorno;
}
function getNazione($db)
{
$ritorno = "";
if ($this->IDNazione != "")
{
$query = "SELECT Nome FROM nazione WHERE Sigla = '" . $this->IDNazione . "'";
$ritorno = $db->getSingleValue($query);
}
return $ritorno;
}
function getGenere($db)
{
$ritorno = "";
if ($this->IDGenere != 0)
{
$query = "SELECT Nome FROM genere_musicale WHERE ID = " . $this->IDGenere;
$ritorno = $db->getSingleValue($query);
}
return $ritorno;
}
function getIndirizzoCompleto($db)
{
$ritorno = "";
if ($this->Indirizzo != "")
{
$ritorno .= $this->Indirizzo;
}
if ($this->IDComune != "")
{
if ($ritorno != "")
{
$ritorno .= ", ";
}
$ritorno .= $this->getComune($db);
}
if ($this->IDProvincia != "")
{
if ($ritorno != "")
{
$ritorno .= ", ";
}
$ritorno .= $this->IDProvincia;
}
if ($this->IDNazione != "")
{
if ($ritorno != "")
{
$ritorno .= ", ";
}
$ritorno .= $this->getNazione($db);
}
return $ritorno;
}
function segnalaRealta($db, $tiporealta, $nome, $provincia, $nazione, $comune, $IDGenere)
{
$ritorno = "";
if ($provincia != "")
{
$query = "SELECT * FROM realta WHERE UPPER(Nome) = '" . strtoupper(pulisci($nome)) . "' AND IDProvincia = '" . $provincia . "' AND Attivo = 1";
}
else
{
$query = "SELECT * FROM realta WHERE UPPER(Nome) = '" . strtoupper(pulisci($nome)) . "' AND IDNazione = '" . $nazione . "' AND Attivo = 1";
}
$res0 = $db->getRecordset($query);
$num_row0 = mysql_num_rows($res0);
if ($num_row0 > 0)
{
$IDRealta = $res0["ID"];
$ritorno = "Realta' musicale gia' presente!";
}
else
{
$query = "SELECT MAX(ID) FROM realta";
$IDRealta = $db->getSingleValue($query) + 1;
$query = "INSERT INTO realta (ID, Nome, IDComune, IDProvincia, IDNazione, IDTipo, Registrato, Attivo, Insert_ID, Insert_DataOra, IDGenere) VALUES (" . $IDRealta . ", '" . pulisci($nome) . "', '" . strtoupper($comune) . "', '" . strtoupper($provincia) . "', '" . strtoupper($nazione) . "', " . $tiporealta . ", 0, 1, " . $_SESSION["UtenteID"] . ", Now(), " . $IDGenere . ")";
$db->exec($query);
$ritorno = "Realtà musicale inserita!";
}
return $ritorno;
}
function getConcerti($db, $passatiFuturi, $order, $attivo)
{
$concerti = array();
$queryPassatiFuturi = "";
switch($passatiFuturi)
{
case "PASSATI":
$queryPassatiFuturi = " AND Date(c.DataOra) < Curdate() ";
break;
case "FUTURI":
$queryPassatiFuturi = " AND Date(c.DataOra) >= Curdate() ";
break;
}
$queryOrder = "";
if ($order != "")
{
$queryOrder = $order;
}
$query = "";
$query .= "SELECT c.*, e.Nome NomeLuogo, e.IDProvincia, tr.IsLuogo, tr.IsArtista from concerto c INNER JOIN realta_concerto ec ON c.ID = ec.IDConcerto INNER JOIN realta e ON e.ID = c.IDLuogo INNER JOIN tipo_realta tr ON e.IDTipo = tr.ID WHERE ec.IDRealta = " . $this->ID . " AND c.Attivo >= " . $attivo . " " . $queryPassatiFuturi;
if ($this->TipoIsLuogo == 1)
{
$query .= "UNION ALL ";
$query .= "SELECT c.*, e.Nome NomeLuogo, e.IDProvincia, tr.IsLuogo, tr.IsArtista from concerto c INNER JOIN realta e ON e.ID = c.IDLuogo INNER JOIN tipo_realta tr ON e.IDTipo = tr.ID WHERE c.IDLuogo = " . $this->ID . " AND c.Attivo = " . $attivo . " " . $queryPassatiFuturi;
}
$query .= "ORDER BY DataOra " . $queryOrder;
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($concerti, $row);
}
}
return $concerti;
}
function getIDConcerti($db)
{
$concerti = array();
$query = "";
$query .= "SELECT c.ID from concerto c INNER JOIN realta_concerto ec ON c.ID = ec.IDConcerto WHERE ec.IDRealta = " . $this->ID . " ";
if ($this->TipoIsLuogo == 1)
{
$query .= "UNION ALL ";
$query .= "SELECT c.ID from concerto c WHERE c.IDLuogo = " . $this->ID . " ";
}
$query .= "ORDER BY DataOra DESC";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($concerti, $row["ID"]);
}
}
return $concerti;
}
function attiva($db, $attivo)
{
if (is_numeric($attivo))
{
$query = "UPDATE realta SET Attivo = " . (($attivo + 1) % 2) . ", Update_ID = " . $_SESSION["UtenteID"] . ", Update_DataOra = Now() WHERE ID = " . $this->ID;
$db->exec($query);
}
}
function getLinks($db, $IDLink)
{
$links = array();
$queryWhere = "";
if ($IDLink > 0)
{
$queryWhere = " AND rl.IDLink = " . $IDLink;
}
$query = "";
$query .= "SELECT rl.IDLink, rl.Nome, rl.Link, tl.Nome NomeLink, tl.Icona, rl.Attivo FROM realta_link rl INNER JOIN tipo_link tl ON rl.IDLink = tl.ID WHERE tl.Attivo = 1 AND rl.IDRealta = " . $this->ID . $queryWhere . " ORDER BY tl.Nome, rl.Nome";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($links, $row);
}
}
return $links;
}
function addLink($db, $IDLink, $Nome, $Link)
{
$query = "SELECT count(*) FROM realta_link WHERE IDRealta = " . $this->ID . " AND IDLink = " . $IDLink;
$num = $db->getSingleValue($query);
if (substr($Link, 0, 7) != "http://")
{
$Link = "http://" . $Link;
}
if ($num == 0)
{
$query = "INSERT INTO realta_link (IDRealta, IDLink, Nome, Link, Attivo) VALUES (" . $this->ID . ", " . $IDLink . ", '" . formatSQL($Nome) . "', '" . formatSQL($Link) . "', 1)";
}
else
{
$query = "UPDATE realta_link
SET Nome = '" . formatSQL($Nome) . "',
Link = '" . formatSQL($Link) . "',
Attivo = 1
WHERE IDRealta = " . $this->ID . " AND IDLink = " . $IDLink;
}
$db->exec($query);
$query = "UPDATE realta SET Update_ID = " . $_SESSION["UtenteID"] . ", Update_DataOra = Now() WHERE ID = " . $this->ID;
$db->exec($query);
}
function attivaLink($db, $IDLink, $attivo)
{
if (is_numeric($attivo))
{
$query = "UPDATE realta_link SET Attivo = " . (($attivo + 1) % 2) . " WHERE IDRealta = " . $this->ID . " AND IDLink = " . $IDLink;
$db->exec($query);
}
}
function getArticoliInterviste($db)
{
$articoli = array();
$query = "SELECT a.* FROM articolo a INNER JOIN realta_articolo ra ON a.ID = ra.IDArticolo WHERE a.IDTipo = 3 AND ra.IDRealta = " . $this->ID . " AND a.Attivo = 1 ORDER BY a.DataPubblicazione DESC";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($articoli, $row);
}
}
return $articoli;
}
function getArticoliConcerti($db)
{
$articoli = array();
$query = "SELECT a.* FROM articolo a INNER JOIN realta_concerto ra ON a.IDConcerto = ra.IDConcerto WHERE a.Moderato = 1 AND a.IDTipo = 1 AND ra.IDRealta = " . $this->ID . " ORDER BY a.DataPubblicazione DESC";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($articoli, $row);
}
}
return $articoli;
}
}
?>