0)
{
$this->ID = $_SESSION["UtenteID"];
$this->Login = $_SESSION["UtenteLogin"];
$this->Password = $_SESSION["UtentePassword"];
$this->Nome = $_SESSION["UtenteNome"];
$this->Cognome = $_SESSION["UtenteCognome"];
$this->Sesso = $_SESSION["UtenteSesso"];
$this->DataNascita = $_SESSION["UtenteDataNascita"];
$this->LuogoNascita = $_SESSION["UtenteLuogoNascita"];
$this->CodiceFiscale = $_SESSION["UtenteCodiceFiscale"];
$this->IDTipo = $_SESSION["UtenteIDTipo"];
$this->Foto = $_SESSION["UtenteFoto"];
$this->Descrizione = $_SESSION["UtenteDescrizione"];
$this->Email = $_SESSION["UtenteEmail"];
$this->Telefono = $_SESSION["UtenteTelefono"];
$this->Registrato = $_SESSION["UtenteRegistrato"];
$this->Attivo = $_SESSION["UtenteAttivo"];
$this->TipoNome = $_SESSION["TipoUtenteNome"];
$this->TipoCreaConcerto = $_SESSION["TipoUtenteCreaConcerto"];
$this->TipoCreaEvento = $_SESSION["TipoUtenteCreaEvento"];
$this->TipoIsModerato = $_SESSION["TipoUtenteIsModerato"];
$this->setRealta($db);
$this->setZona($db);
$this->MostraEmail = $_SESSION["MostraEmail"];
$this->ZonaAttiva = $_SESSION["ZonaAttiva"];
$this->setArticolo($db);
}
else
{
$this->ID = 0;
$this->Login = "";
$this->Password = "";
$this->Nome = "";
$this->Cognome = "";
$this->Sesso = "";
$this->DataNascita = "";
$this->LuogoNascita = "";
$this->CodiceFiscale = "";
$this->IDTipo = 0;
$this->Foto = "";
$this->Descrizione = "";
$this->Email = "";
$this->Telefono = "";
$this->Registrato = 0;
$this->Attivo = 0;
$this->TipoNome = 0;
$this->TipoCreaConcerto = 0;
$this->TipoCreaEvento = 0;
$this->TipoIsModerato = 0;
$this->UtenteRealta = array();
$this->UtenteNomeRealta = array();
$this->MostraEmail = 0;
$this->ZonaAttiva = 0;
$this->UtenteArticolo = array();
$this->UtenteNomeArticolo = array();
}
}
function setUtente($ID, $Login, $Password, $Nome, $Cognome, $Sesso, $DataNascita, $LuogoNascita, $CodiceFiscale, $IDTipo, $Foto, $Descrizione, $Email, $Telefono, $Registrato, $Attivo)
{
$this->ID = $ID;
$this->Login = $Login;
$this->Password = $Password;
$this->Nome = $Nome;
$this->Cognome = $Cognome;
$this->Sesso = $Sesso;
$this->DataNascita = $DataNascita;
$this->LuogoNascita = $LuogoNascita;
$this->CodiceFiscale = $CodiceFiscale;
$this->IDTipo = $IDTipo;
$this->Foto = $Foto;
$this->Descrizione = $Descrizione;
$this->Email = $Email;
$this->Telefono = $Telefono;
$this->Registrato = $Registrato;
$this->Attivo = $Attivo;
}
function getUtente($db, $id)
{
$query = "SELECT u.*, tu.Nome TipoUtenteNome, tu.CreaConcerto TipoUtenteCreaConcerto, tu.CreaEvento TipoUtenteCreaEvento, tu.IsModerato TipoUtenteIsModerato FROM utente u INNER JOIN tipo_utente tu ON u.IDTipo = tu.ID WHERE u.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->Login = $row['Login'];
$this->Password = $row['Password'];
$this->Nome = $row['Nome'];
$this->Cognome = $row['Cognome'];
$this->Sesso = $row['Sesso'];
$this->DataNascita = $row['DataNascita'];
$this->LuogoNascita = $row['LuogoNascita'];
$this->CodiceFiscale = $row['CodiceFiscale'];
$this->IDTipo = $row['IDTipo'];
$this->Foto = $row['Foto'];
$this->Descrizione = $row['Descrizione'];
$this->Email = $row['Email'];
$this->Telefono = $row['Telefono'];
$this->Registrato = $row['Registrato'];
$this->Attivo = $row['Attivo'];
$this->TipoNome = $row["TipoUtenteNome"];
$this->TipoCreaConcerto = $row["TipoUtenteCreaConcerto"];
$this->TipoCreaEvento = $row["TipoUtenteCreaEvento"];
$this->TipoIsModerato = $row["TipoUtenteIsModerato"];
$this->setRealta($db);
$this->MostraEmail = $row['MostraEmail'];
$this->ZonaAttiva = $row["ZonaAttiva"];
$this->setArticolo($db);
}
}
function setRealta($db)
{
$query = "SELECT ur.IDRealta, r.Nome FROM utente_realta ur INNER JOIN realta r ON ur.IDRealta = r.ID WHERE ur.Attivo = 1 AND ur.IDUtente = " . $this->ID . " ORDER BY r.Nome";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($this->UtenteRealta, $row["IDRealta"]);
array_push($this->UtenteNomeRealta, formatTXT($row["Nome"]));
}
}
}
function setArticolo($db)
{
$query = "SELECT ur.IDArticolo, a.Titolo FROM utente_articolo ur INNER JOIN articolo a ON ur.IDArticolo = a.ID WHERE ur.Attivo = 1 AND ur.IDUtente = " . $this->ID . " ORDER BY a.DataPubblicazione";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($this->UtenteArticolo, $row["IDArticolo"]);
array_push($this->UtenteNomeArticolo, formatTXT($row["Titolo"]));
}
}
}
function setZona($db)
{
$query = "SELECT z.ID, z.Nome FROM zona z INNER JOIN utente_zona uz ON z.ID = uz.IDZona WHERE uz.IDUtente = " . $this->ID . " ORDER BY z.Nome";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($this->Zona, $row["ID"]);
array_push($this->ZonaNome, formatTXT($row["Nome"]));
}
}
}
function existLogin($db)
{
$ritorno = $db->getSingleValue("SELECT count(*) FROM utente WHERE UPPER(Login) = '" . strtoupper($this->Login) . "'");
if ($ritorno > 0)
{
return true;
}
else
{
return false;
}
}
function existCodiceFiscale($db)
{
$query = "SELECT count(*) FROM utente WHERE UPPER(CodiceFiscale) = '" . strtoupper($this->CodiceFiscale) . "'";
$ritorno = $db->getSingleValue($query);
if ($ritorno > 0)
{
return true;
}
else
{
return false;
}
}
function existNomeCognome($db)
{
$query = "SELECT count(*) FROM utente WHERE UPPER(Nome) = '" . strtoupper($this->Nome) . "' AND UPPER(Cognome) = '" . strtoupper($this->Cognome) . "' AND Registrato = 0";
$ritorno = $db->getSingleValue($query);
if ($ritorno > 0)
{
return true;
}
else
{
return false;
}
}
function updateUtente($db)
{
$query = "SELECT ID FROM utente WHERE UPPER(Nome) = '" . strtoupper($this->Nome) . "' AND UPPER(Cognome) = '" . strtoupper($this->Cognome) . "' AND Registrato = 0";
$id = $db->getSingleValue($query);
$this->ID = $id;
$query = "UPDATE utente
SET Login = '" . formatSQL($this->Login) . "',
Password = '" . md5($this->Password) . "',
Sesso = '" . $this->Sesso . "',
DataNascita = '" . $this->DataNascita . "',
LuogoNascita = '" . $this->LuogoNascita . "',
CodiceFiscale = '" . $this->CodiceFiscale . "',
Email = '" . formatSQL($this->Email) . "',
IDTipo = 1,
Registrato = 1,
Attivo = 1,
Update_ID = " . $id . ",
Update_DataOra = Now()
WHERE ID = " . $id;
$db->exec($query);
$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 = "Si è registrato un utente già presente nell'archivio.";
while($row = mysql_fetch_assoc($res))
{
sendMail("", $row["Email"], "LiveUs.it -> Nuovo utente", $testoMail);
}
}
}
function insertUtente($db)
{
$query = "SELECT MAX(ID) FROM utente";
$IDUtente = $db->getSingleValue($query) + 1;
$query = "INSERT INTO utente (ID, Login, Password, Nome, Cognome, Sesso, DataNascita, LuogoNascita, CodiceFiscale, Email, IDTipo, Registrato, Attivo, Insert_ID, Insert_DataOra) VALUES (
" . $IDUtente . ",
'" . formatSQL($this->Login) . "',
'" . md5($this->Password) . "',
'" . formatSQL(ucfirst($this->Nome)) . "',
'" . formatSQL(ucfirst($this->Cognome)) . "',
'" . $this->Sesso . "',
'" . $this->DataNascita . "',
'" . $this->LuogoNascita . "',
'" . $this->CodiceFiscale . "',
'" . formatSQL($this->Email) . "',
1,
1,
1,
" . $IDUtente . ",
Now())";
$db->exec($query);
$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 = "Si è registrato l'utente " . ucfirst($this->Nome) . " " . ucfirst($this->Cognome) . "";
while($row = mysql_fetch_assoc($res))
{
sendMail("", $row["Email"], "LiveUs.it -> Nuovo utente", $testoMail);
}
}
}
function modUtentePassword($db, $Password)
{
$query = "UPDATE utente SET Password = '" . md5($Password) . "', Update_ID = " . $_SESSION["UtenteID"] . ", Update_DataOra = Now() WHERE ID = " . $this->ID;
$db->exec($query);
$this->Password = md5($Password);
$_SESSION["UtentePassword"] = md5($Password);
}
function modUtenteData($db, $Descrizione, $Email, $Telefono, $MostraEmail, $ZonaAttiva)
{
$query = "UPDATE utente
SET Descrizione = '" . formatSQL($Descrizione) . "',
Email = '" . formatSQL($Email) . "',
MostraEmail = " . $MostraEmail . ",
ZonaAttiva = " . $ZonaAttiva . ",
Telefono = '" . formatSQL($Telefono) . "',
Update_ID = " . $_SESSION["UtenteID"] . ",
Update_DataOra = Now()
WHERE ID = " . $this->ID;
$db->exec($query);
$this->Descrizione = formatTXT($Descrizione);
$this->Email = formatTXT($Email);
$this->Telefono = formatTXT($Telefono);
$this->MostraEmail = $MostraEmail;
$this->ZonaAttiva = $ZonaAttiva;
$_SESSION["UtenteDescrizione"] = formatTXT($Descrizione);
$_SESSION["UtenteEmail"] = formatTXT($Email);
$_SESSION["UtenteTelefono"] = formatTXT($Telefono);
$_SESSION["MostraEmail"] = $MostraEmail;
$_SESSION["ZonaAttiva"] = $ZonaAttiva;
}
function uploadFoto($db, $foto)
{
saveImage($db, "utente", 200, 200, $foto, $this->ID, $this->Foto, "UtenteFoto", "tb_", false);
saveImage($db, "utente", 800, 800, $foto, $this->ID, $this->Foto, "UtenteFoto", "", true);
}
function getRealtaModerate($db, $tipo)
{
$moderate = " AND z.IDZona IN (";
for ($i = 0; $i < count($this->Zona); $i++)
{
if ($i > 0)
{
$moderate .= ", ";
}
$moderate .= $this->Zona[$i];
}
$moderate .= ") ";
if ($this->IDTipo == 99)
{
$moderate = "";
}
$tipoRealta = "";
switch($tipo)
{
case "a":
$tipoRealta = " tr.IsArtista = 1 ";
break;
case "l":
$tipoRealta = " tr.IsLuogo = 1 ";
break;
case "o":
$tipoRealta = " tr.IsArtista = 0 AND tr.IsLuogo = 0 ";
break;
}
$query = "SELECT r.ID, r.Nome, r.Attivo, p.Nome ProvinciaNazione, tr.Nome TipoNome FROM realta r INNER JOIN provincia p ON r.IDProvincia = p.Sigla INNER JOIN zona_provincia z ON r.IDProvincia = z.IDProvincia INNER JOIN tipo_realta tr ON r.IDTipo = tr.ID WHERE " . $tipoRealta . $moderate;
$query .= "UNION ALL ";
$query .= "SELECT r.ID, r.Nome, r.Attivo, n.Nome ProvinciaNazione, tr.Nome TipoNome FROM realta r INNER JOIN nazione n ON r.IDNazione = n.Sigla INNER JOIN zona_nazione z ON r.IDNazione = z.IDNazione INNER JOIN tipo_realta tr ON r.IDTipo = tr.ID WHERE " . $tipoRealta . $moderate;
$query .= "ORDER BY Nome, ProvinciaNazione";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
$realtaModerata = array();
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($realtaModerata, $row);
}
}
return $realtaModerata;
}
function permettiGestioneRealta($db, $richiedente, $realta, $stato)
{
$ritorno = "";
$query = "SELECT Email FROM utente WHERE ID = " . $richiedente;
$email = $db->getSingleValue($query);
if ($stato == 1)
{
$query = "UPDATE utente_realta SET Attivo = 1 WHERE IDUtente = " . $richiedente . " AND IDRealta = " . $realta;
$db->exec($query);
$testoMail = "Ti è stata confermata la gestione della Realta musicale che hai richiesto.";
sendMail("", $email, "LiveUs.it -> Gestione Realtà musicale", $testoMail);
$ritorno = "Utente aggiunto alla gestione!";
}
else
{
$query = "DELETE FROM utente_realta WHERE IDUtente = " . $richiedente . " AND IDRealta = " . $realta;
$db->exec($query);
$testoMail = "Ti è stata negata la gestione della Realta musicale che hai richiesto.";
sendMail("", $email, "LiveUs.it -> Gestione Realtà musicale", $testoMail);
$ritorno = "Utente rifiutato nella gestione!";
}
return $ritorno;
}
function attiva($db, $attivo)
{
if (is_numeric($attivo))
{
$query = "UPDATE utente SET Attivo = " . (($attivo + 1) % 2) . ", Update_ID = " . $_SESSION["UtenteID"] . ", Update_DataOra = Now() WHERE ID = " . $this->ID;
$db->exec($query);
}
}
function getUtentiModerati($db)
{
$moderate = " AND z.IDZona IN (";
for ($i = 0; $i < count($this->Zona); $i++)
{
if ($i > 0)
{
$moderate .= ", ";
}
$moderate .= $this->Zona[$i];
}
$moderate .= ") ";
if ($this->IDTipo == 99)
{
$moderate = "";
}
$query = "SELECT u.ID, u.Login, u.Nome, u.Cognome, u.Password, u.Attivo FROM utente u INNER JOIN comuni c ON u.LuogoNascita = c.CodCom INNER JOIN zona_provincia z ON c.Provincia = z.IDProvincia WHERE u.Registrato = 1 " . $moderate . " ORDER BY u.Cognome, u.Nome, u.Login";
$res = $db->getRecordset($query);
$num_row = mysql_num_rows($res);
$utentiModerati = array();
if ($num_row > 0)
{
while($row = mysql_fetch_assoc($res))
{
array_push($utentiModerati, $row);
}
}
return $utentiModerati;
}
function getArticoli($db, $forAdmin, $IsModerato)
{
$articoli = array();
$where = "";
if (!$forAdmin)
{
$where = " AND a.Attivo = 1 AND a.Moderato = 1 ";
}
$query = "SELECT a.*, ta.Nome NomeTipo FROM articolo a INNER JOIN utente_articolo ua ON ua.IDArticolo = a.ID AND ua.IDUtente = " . $this->ID . " INNER JOIN tipo_articolo ta ON ta.ID = a.IDTipo WHERE ta.IsAutomatico <= " . $IsModerato . $where . " 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 getNovita($db, $forAdmin, $IsModerato)
{
$articoli = array();
$where = "";
if (!$forAdmin)
{
$where = " AND a.Attivo = 1 AND a.Moderato = 1 ";
}
$query = "SELECT a.*, ta.Nome NomeTipo FROM articolo a INNER JOIN utente_articolo ua ON ua.IDArticolo = a.ID AND ua.IDUtente = " . $this->ID . " INNER JOIN tipo_articolo ta ON ta.ID = a.IDTipo WHERE a.IDTipo = 5 AND ta.IsAutomatico <= " . $IsModerato . $where . " 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;
}
}
?>