$oraA) { $ritorno = $img; } else { $ritorno = substr($img, 0, strlen($img) - 4) . "_bw" . substr($img, strlen($img) - 4); } } else { $ritorno = "null.gif"; } return $ritorno; } function pulisci($str) { $str = trim($str); //$str = mysql_real_escape_string($str); $str = str_replace("'", "''", $str); $str = str_replace("\\", '', $str); $str = str_replace("à", "à", $str); $str = str_replace("è", "è", $str); $str = str_replace("é", "é", $str); $str = str_replace("ì", "ì", $str); $str = str_replace("ò", "ò", $str); $str = str_replace("ù", "ù", $str); $str = str_replace("æ", "æ", $str); $str = str_replace("á", "á", $str); $str = str_replace("’", "''", $str); $str = str_replace("Ü", "Ü", $str); $str = str_replace("ü", "ü", $str); return $str; } function getNomeMese($num) { $nomeMese = ""; switch((int)$num) { case 1: $nomeMese = "Gennaio"; break; case 2: $nomeMese = "Febbraio"; break; case 3: $nomeMese = "Marzo"; break; case 4: $nomeMese = "Aprile"; break; case 5: $nomeMese = "Maggio"; break; case 6: $nomeMese = "Giugno"; break; case 7: $nomeMese = "Luglio"; break; case 8: $nomeMese = "Agosto"; break; case 9: $nomeMese = "Settembre"; break; case 10: $nomeMese = "Ottobre"; break; case 11: $nomeMese = "Novembre"; break; case 12: $nomeMese = "Dicembre"; break; } return $nomeMese; } function checkEmail($email) { if (!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $email)) { return false; } else { return true; } } function formatSQL($testo) { $ritorno = trim($testo); $ritorno = str_replace("\'", "'", $ritorno); $ritorno = str_replace(chr(92) . chr(34), chr(34), $ritorno); $ritorno = str_replace("’", "'", $ritorno); $ritorno = str_replace("'", "''", $ritorno); return $ritorno; } function formatFORM($testo) { $ritorno = trim($testo); $ritorno = str_replace("'", "’", $ritorno); return $ritorno; } function formatTXT($testo) { $ritorno = trim($testo); $ritorno = str_replace("\'", "'", $ritorno); $ritorno = str_replace(chr(92) . chr(34), chr(34), $ritorno); $ritorno = str_replace("’", "'", $ritorno); $ritorno = str_replace("’", "'", $ritorno); return $ritorno; } function passwordCasuale($lunghezza) { $caratteri_disponibili ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; $password = ""; for ($i = 0; $i < $lunghezza; $i++) { $password = $password.substr($caratteri_disponibili,rand(0,strlen($caratteri_disponibili)-1),1); } return $password; } function isValid($str) { if (isset($str)) { if ($str != "") { return true; } else { return false; } } else { return false; } } function saveImage($conn, $table, $maxwidth, $maxheight, $image, $oggettoID, $oggettoFoto, $sessione, $thumb, $saveToDB) { $d_path = "D:\\inetpub\\webs\\liveusit\\public\\" . $table . "\\"; list($width, $height, $type) = getimagesize($image['tmp_name']); if ($width > $maxwidth || $height > $maxheight) { $xscale = $width / $maxwidth; $yscale = $height / $maxheight; if ($yscale > $xscale) { $new_width = round($width * (1 / $yscale)); $new_height = round($height * (1 / $yscale)); } else { $new_width = round($width * (1 / $xscale)); $new_height = round($height * (1 / $xscale)); } } else { $new_width = $width; $new_height = $height; } $imageResized = imagecreatetruecolor($new_width, $new_height); switch($type) { case 1: $imageTmp = imagecreatefromgif($image['tmp_name']); break; case 2: $imageTmp = imagecreatefromjpeg($image['tmp_name']); break; case 3: $imageTmp = imagecreatefrompng($image['tmp_name']); break; } imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $newFotoName = $thumb . $oggettoID . ".jpg"; imagejpeg($imageResized, $d_path . $newFotoName); imagecopymergegray($imageResized, $imageResized, 0, 0, 0, 0, $new_width, $new_height, 0); $newFotoNameBW = $thumb . $oggettoID . "_bw.jpg"; imagejpeg($imageResized, $d_path . $newFotoNameBW); imagedestroy($imageResized); if ($saveToDB) { $query = "UPDATE " . $table . " SET Foto = '" . $newFotoName . "' WHERE ID = " . $oggettoID; $conn->exec($query); $oggettoFoto = formatTXT($newFotoName); if ($sessione != "") { $_SESSION[$sessione] = formatTXT($newFotoName); } } } function sendmail($from, $to, $titolo, $testo) { $header = ""; $header .= "MIME-Version: 1.0\r\n"; $header .= "Content-type: text/html; charset=utf-8\r\n"; if ($from == "") { $from = "webmaster@liveus.it"; } $header .= "From: " . $from . "\r\n"; //echo "HEADER: " . $header . "
FROM: " . $from . "
TO: " . $to . "
TITOLO: " . $titolo . "
TESTO: " . $testo; mail($to, $titolo, $testo, $header); } function getNomeArtistiConcerto($db, $id, $link) { $ritorno = ""; $query = "SELECT e.Nome, e.ID FROM realta_concerto ec INNER JOIN realta e ON ec.IDRealta = e.ID INNER JOIN tipo_realta te ON e.IDTipo = te.ID WHERE te.IsArtista = 1 AND ec.IDConcerto = " . $id . " ORDER BY e.Nome"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { $i = 0; while($row = mysql_fetch_assoc($res)) { if ($i > 0) { $ritorno .= ", "; } if ($link > 0) { $ritorno .= ""; } $ritorno .= $row["Nome"]; if ($link > 0) { $ritorno .= ""; } $i++; } } return $ritorno; } function getNomeOrganizzatoriConcerto($db, $idConcerto, $idLuogo, $link) { $ritorno = ""; $query = "SELECT e.Nome, e.ID FROM realta_concerto ec INNER JOIN realta e ON ec.IDRealta = e.ID INNER JOIN tipo_realta te ON e.IDTipo = te.ID WHERE te.IsArtista = 0 AND ec.IDRealta != " . $idLuogo . " AND ec.IDConcerto = " . $idConcerto . " ORDER BY e.Nome"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { $i = 0; while($row = mysql_fetch_assoc($res)) { if ($i > 0) { $ritorno .= ", "; } if ($link > 0) { $ritorno .= ""; } $ritorno .= $row["Nome"]; if ($link > 0) { $ritorno .= ""; } $i++; } } return $ritorno; } function getNomeArtistiIntervista($db, $id) { $ritorno = ""; $query = "SELECT e.Nome FROM realta_articolo ra INNER JOIN realta e ON ra.IDRealta = e.ID WHERE ra.IDArticolo = " . $id . " ORDER BY e.Nome"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { $i = 0; while($row = mysql_fetch_assoc($res)) { if ($i > 0) { $ritorno .= ", "; } $ritorno .= $row["Nome"]; $i++; } } return $ritorno; } function getLuogoConcerto($db, $id) { $query = "SELECT e.Nome FROM concerto c INNER JOIN realta e ON c.IDLuogo = e.ID WHERE e.ID = " . $id; return $db->getSingleValue($query); } function formatDateFromSQL($dataOra, $tipo) { $ritorno = ""; switch($tipo) { case "dataestesa": $giorno = formatGiorno(date("w", mktime(0, 0, 0, substr($dataOra, 5, 2), substr($dataOra, 8, 2), substr($dataOra, 0, 4)))); $ritorno = $giorno . " " . (int)substr($dataOra, 8, 2) . " " . getNomeMese(substr($dataOra, 5, 2)) . " " . substr($dataOra, 0, 4); break; case "data": $ritorno = substr($dataOra, 8, 2) . "/" . substr($dataOra, 5, 2) . "/" . substr($dataOra, 0, 4); break; case "giorno": $ritorno = substr($dataOra, 8, 2); break; case "mese": $ritorno = substr($dataOra, 5, 2); break; case "anno": $ritorno = substr($dataOra, 0, 4); break; case "ora": $ritorno = substr($dataOra, 11, 5); break; case "oggi": $ritorno = substr($dataOra, 0, 4) . substr($dataOra, 5, 2) . substr($dataOra, 8, 2); break; } return $ritorno; } function formatGiorno($numeroGiorno) { $ritorno = ""; switch($numeroGiorno) { case 1: $ritorno = "Lunedì"; break; case 2: $ritorno = "Martedì"; break; case 3: $ritorno = "Mercoledì"; break; case 4: $ritorno = "Giovedì"; break; case 5: $ritorno = "Venerdì"; break; case 6: $ritorno = "Sabato"; break; case 0: $ritorno = "Domenica"; break; } return $ritorno; } function oggi() { $oggi = getdate(); $ritorno = $oggi["year"] . str_pad($oggi["mon"], 2, "0", STR_PAD_LEFT) . str_pad($oggi["mday"], 2, "0", STR_PAD_LEFT); return $ritorno; } function getConcertiFuturi($db, $order, $limit, $zona, &$concerti, $giorni, $attivo) { if (count($concerti) == 0) { $concerti = array(); } $query = ""; $query .= "SELECT c.*, r.Nome NomeLuogo, IFNULL(r.IDProvincia, r.IDNazione) Sigla, cc.Comune FROM concerto c INNER JOIN realta r ON r.ID = c.IDLuogo LEFT OUTER JOIN comuni cc ON cc.CodCom = r.IDComune "; if ($zona > 0) { if ($zona < 21) { $query .= " INNER JOIN zona_provincia zp ON zp.IDProvincia = r.IDProvincia AND zp.IDZona = " . $zona . " "; } else { $query .= " INNER JOIN zona_nazione zn ON zn.IDNazione = r.IDNazione AND zn.IDZona = " . $zona . " "; } } $query .= "WHERE c.Attivo >= " . $attivo . " AND Date(c.DataOra) >= Curdate() "; if ($giorni > 0) { $query .= " AND Date(c.DataOra) < Curdate() + INTERVAL " . $giorni . " DAY "; } $query .= "ORDER BY DataOra " . $order; if ($limit != "" && $giorni == 0) { $query .= " LIMIT " . $limit; } $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { $contatore = 0; $DataOra = ""; while($row = mysql_fetch_assoc($res)) { $ok = true; if ($limit != "" && $giorni > 0) { if ($contatore > $limit) { if ($DataOra != formatDateFromSQL($row["DataOra"], "oggi")) { $ok = false; } } } if ($ok) { array_push($concerti, $row); $DataOra = formatDateFromSQL($row["DataOra"], "oggi"); } $contatore++; } } } function getConcertiPassati($db, $order, $limit, $zona, &$concerti, $attivo) { if (count($concerti) == 0) { $concerti = array(); } $query = ""; $query .= "SELECT c.*, r.Nome NomeLuogo, IF(r.IDProvincia='', r.IDNazione, r.IDProvincia) Sigla from concerto c INNER JOIN realta r ON r.ID = c.IDLuogo "; if ($zona > 0) { if ($zona < 21) { $query .= " INNER JOIN zona_provincia zp ON zp.IDProvincia = r.IDProvincia AND zp.IDZona = " . $zona . " "; } else { $query .= " INNER JOIN zona_nazione zn ON zn.IDNazione = r.IDNazione AND zn.IDZona = " . $zona . " "; } } $query .= " WHERE c.Attivo >= " . $attivo . " AND Date(c.DataOra) < Curdate() "; $query .= "ORDER BY DataOra " . $order; if($limit != "") { $query .= " LIMIT " . $limit; } $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($concerti, $row); } } } function getUltimeRealta($db, $order, $limit, $zona, $registrato) { $realta = array(); $query = ""; $query .= "SELECT r.*, tr.Nome NomeTipo, IF(r.IDProvincia='', r.IDNazione, r.IDProvincia) Sigla, tr.Icona from realta r INNER JOIN tipo_realta tr ON r.IDTipo = tr.ID "; if ($zona > 0) { if ($zona < 21) { $query .= " INNER JOIN zona_provincia zp ON zp.IDProvincia = r.IDProvincia AND zp.IDZona = " . $zona . " "; } else { $query .= " INNER JOIN zona_nazione zn ON zn.IDNazione = r.IDNazione AND zn.IDZona = " . $zona . " "; } } $query .= "WHERE r.Registrato = " . $registrato . " "; $query .= "ORDER BY IF(r.Update_DataOra > r.Insert_DataOra, r.Update_DataOra, r.Insert_DataOra) " . $order; if($limit != "") { $query .= " LIMIT " . $limit; } $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($realta, $row); } } return $realta; } function getElencoRealta($db, $tipo, $limit, $zona, $registrato, $IDGenere) { $realta = array(); $query = ""; $query .= "SELECT r.*, tr.Nome NomeTipo, IF(r.IDProvincia='', r.IDNazione, r.IDProvincia) Sigla, tr.Icona, cc.Comune FROM realta r INNER JOIN tipo_realta tr ON r.IDTipo = tr.ID LEFT OUTER JOIN comuni cc ON cc.CodCom = r.IDComune "; if ($zona > 0) { if ($zona < 21) { $query .= " INNER JOIN zona_provincia zp ON zp.IDProvincia = r.IDProvincia AND zp.IDZona = " . $zona . " "; } else { $query .= " INNER JOIN zona_nazione zn ON zn.IDNazione = r.IDNazione AND zn.IDZona = " . $zona . " "; } } switch($tipo) { case "a": $query .= "WHERE tr.IsArtista = 1 "; break; case "l": $query .= "WHERE tr.IsLuogo = 1 "; break; case "o": $query .= "WHERE tr.IsArtista = 0 AND tr.IsLuogo = 0 "; break; } if ($IDGenere > 0) { $query .= "AND r.IDGenere = " . $IDGenere . " "; } if ($registrato >= 0) { $query .= "AND r.Registrato = " . $registrato . " "; if ($limit != "") { $query .= "ORDER BY IF(r.Update_DataOra > r.Insert_DataOra, r.Update_DataOra, r.Insert_DataOra) DESC "; } else { $query .= "ORDER BY r.Registrato DESC, r.Nome "; } } else { $query .= "ORDER BY r.Registrato DESC, r.Nome "; } if($limit != "") { $query .= " LIMIT " . $limit; } $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($realta, $row); } } return $realta; } function getIconaTipoRealta($db, $id) { $ritorno = ""; $query = "SELECT tr.Icona FROM realta r INNER JOIN tipo_realta tr ON r.IDTipo = tr.ID WHERE r.ID = " . $id; $ritorno = $db->getSingleValue($query); return $ritorno; } function getRichiesteControlloRealta($db, $IDRealta) { $query = "SELECT count(*) FROM utente_realta WHERE IDRealta = " . $IDRealta . " AND Attivo = 0"; $richieste = $db->getSingleValue($query); return $richieste; } function getDettaglioRichiesteControlloRealta($db, $IDRealta) { $utente = array(); $query = "SELECT u.ID, u.Nome, u.Cognome FROM utente_realta ur INNER JOIN utente u ON ur.IDUtente = u.ID WHERE ur.IDRealta = " . $IDRealta . " AND ur.Attivo = 0"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($utente, $row); } } return $utente; } function getBanner($db) { $query = "SELECT MAX(ID) FROM banner WHERE Attivo = 1"; $max_id = $db->getSingleValue($query); $rand_id = rand(1, $max_id); $query = "SELECT * FROM banner WHERE ID >= " . $rand_id . " AND Attivo = 1 LIMIT 1"; $res = $db->getRecordset($query); $row = mysql_fetch_assoc($res); return $row; } function getRealtaGestite($db, $IDUtente) { $query = "SELECT r.ID, r.Nome, r.Attivo FROM utente_realta ur INNER JOIN realta r ON ur.IDRealta = r.ID WHERE ur.IDUtente = " . $IDUtente . " ORDER BY r.Nome"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); $realtaGestite = array(); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($realtaGestite, $row); } } return $realtaGestite; } function getNomiRealta($db) { $query = "SELECT r.ID, r.Nome, tr.Nome NomeTipo, r.IDProvincia FROM realta r INNER JOIN tipo_realta tr ON r.IDTipo = tr.ID WHERE r.Attivo = 1 ORDER BY tr.Nome, r.Nome"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); $nomiRealta = array(); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($nomiRealta, $row); } } return $nomiRealta; } function spostaRealta($db, $da, $a) { if ($da != "0" && $a != "0") { $query = "UPDATE concerto SET IDLuogo = " . $a . " WHERE IDLuogo = " . $da; $db->exec($query); $query = "UPDATE realta_concerto SET IDRealta = " . $a . " WHERE IDRealta = " . $da; $db->exec($query); $query = "UPDATE realta_link SET IDRealta = " . $a . " WHERE IDRealta = " . $da; $db->exec($query); $query = "UPDATE utente_realta SET IDRealta = " . $a . " WHERE IDRealta = " . $da; $db->exec($query); $query = "UPDATE realta_articolo SET IDRealta = " . $a . " WHERE IDRealta = " . $da; $db->exec($query); $query = "DELETE FROM realta WHERE ID = " . $da; $db->exec($query); } } function getArticoli($db) { $articolo = array(); $query = "SELECT a.* FROM articolo a WHERE a.ID = " . $id; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($articolo, $row); } } } function getElencoArticoli($db, $limit, $zona, $attivo, $tipo, $moderato) { $articoli = array(); $query = ""; $query .= "SELECT a.*, ta.Nome NomeTipo FROM articolo a INNER JOIN tipo_articolo ta ON a.IDTipo = ta.ID "; /*if ($zona > 0) { $query .= " INNER JOIN zona_provincia zp ON zp.IDProvincia = r.IDProvincia AND zp.IDZona = " . $zona . " "; }*/ $query .= "WHERE 1=1 "; if ($tipo > 0) { $query .= "AND a.IDTipo = " . $tipo . " "; } if ($attivo >= 0) { $query .= "AND a.Attivo = " . $attivo . " "; } $query .= "AND a.Moderato >= " . $attivo . " "; $query .= "ORDER BY a.DataPubblicazione DESC, a.Titolo "; if($limit != "") { $query .= " LIMIT " . $limit; } $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 getAutoriArticolo($db, $id, $link) { $ritorno = ""; $query = "SELECT u.ID, u.Nome, u.Cognome FROM utente_articolo ua INNER JOIN articolo a ON ua.IDArticolo = a.ID INNER JOIN utente u ON ua.IDUtente = u.ID WHERE ua.IDArticolo = " . $id . " ORDER BY u.Cognome, u.Nome"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { $i = 0; while($row = mysql_fetch_assoc($res)) { if ($i > 0) { $ritorno .= ", "; } if ($link == 1) { $ritorno .= "" . $row["Nome"] . " " . $row["Cognome"] . ""; } else { $ritorno .= $row["Nome"] . " " . $row["Cognome"]; } $i++; } } return $ritorno; } function getRealtaIndirizzo($db, $id) { $ritorno = array(); $query = "SELECT * FROM vw_realta_indirizzo WHERE ID = " . $id; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { while($row = mysql_fetch_assoc($res)) { array_push($ritorno, $row); } } return $ritorno; } function creaRSS($title, $pubDate, $description, $title, $link, $items) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "" . $title . "\n"; echo "" . $link . "\n"; echo "". $description ."\n"; echo "it\n"; echo "" . date(DATE_RFC822, strtotime($pubDate)) . "\n"; echo "" . date(DATE_RFC822, strtotime($pubDate)) . "\n"; echo "" . $link . "\n"; echo "Copyright: (C) LiveUs.it, http://www.liveus.it/\n"; for ($i = 0; $i < count($items); $i++) { echo "\n"; echo "<![CDATA[ " . $items[$i]["title"] . " ]]>\n"; echo "\n"; echo "" . $items[$i]["link"] . "\n"; echo "" . date(DATE_RFC822, strtotime($items[$i]["pubDate"])) . "\n"; //echo "" . rs(4) . "\n"; echo "" . $items[$i]["link"] . "\n"; echo "\n"; } echo "\n"; echo "\n"; } function pubblicaCommenti($db, $IDTipo, $IDRiferimento) { $width = 650; $query = "SELECT c.DataOra, c.Testo, u.Nome, u.Cognome, u.ID FROM commento c INNER JOIN utente u ON c.IDUtente = u.ID WHERE c.Attivo = 1 AND c.IDTipo = " . $IDTipo . " AND c.IDRiferimento = " . $IDRiferimento . " ORDER BY c.DataOra"; $res = $db->getRecordset($query); $num_row = mysql_num_rows($res); if ($num_row > 0) { echo ""; while($row = mysql_fetch_assoc($res)) { echo ""; echo ""; } echo "
Commento lasciato da " . $row["Nome"] . " " . $row["Cognome"] . ", " . formatDateFromSQL($row["DataOra"], "dataestesa") . " alle ore " . formatDateFromSQL($row["DataOra"], "ora") . "
" . formatTXT($row["Testo"]) . "

"; } $nuovoCommento = "Per lasciare un commento devi essere registrato o fare login.

"; if (isset($_SESSION["UtenteID"])) { if ($_SESSION["UtenteID"] != "") { $nuovoCommento = "Aggiungi un commento:

"; $nuovoCommento .= "
"; $nuovoCommento .= ""; $nuovoCommento .= ""; $nuovoCommento .= ""; $nuovoCommento .= ""; $nuovoCommento .= "

"; } } echo $nuovoCommento; } ?>