<?php
/*
* Created on 28-ott-2006
*
* Il seguente progetto e' stato sviluppato dai programmatori di
* Cingusoft sas
* via lecco 2
* 20124 Milano
*
* CPComuni.php :: funzione di visualizzazione dei comuni
*
* CPComuni version 0.0.1
* copyright (c) 2005 by Cingusoft sas
* http://www.cingusoft.com
*
* CPComuni e' una classe utilizzate per il recupero delle informazioni
* inerenti i comuni e le regioni Italiane, questo sistema permette di
* recuperare le informazioni di tutti i comuni italiani senza dover effettuare
* alcun refresh della pagina.
*
* CPComuni is released under the terms of the LGPL license
* http://www.gnu.org/copyleft/lesser.html#SEC3
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package CPComuni
* @version $Id$
* @copyright Copyright (c) 2005-2006 by Cingusoft sas
* @license http://www.gnu.org/copyleft/lesser.html#SEC3 LGPL License
*/
function getcomuni($arg = null,$provincia = null,$regione = null)
{
/**
* controllo la stringa passata
*/
$arg = ucfirst($arg);
require_once('conf.php');
$objResponse = new xajaxResponse();
//nel seguente caso effettuo la chiamata alla query
if($regione == null && $provincia == null){
//nel seguente caso la ricerca potrebbe risultare troppo grande
//ne coseguen che avviene un controllo della lunghezza dell'argomento passato
if(strlen($arg) < $numSearch){
$objResponse->addAssign("search-results-comuni","style.display","none");
return $objResponse;
}
}
$connessione = mysql_connect($host , $userDB, $passwordDB) or die("Connessione non riuscita: " . mysql_error());
mysql_select_db($database) or die("Selezione del database non riuscita");
$queryC = "SELECT a.codcomune AS codice, a.comune AS comune, b.provincia AS provincia, b.regione AS regione FROM comuni AS a INNER JOIN regioni AS b ON a.provincia = b.codprov WHERE a.comune LIKE '".$arg."%'";
//analizzo i where
$where_add = "";
if(isset($provincia) && $provincia != null){
//effettuo la ricerca per provincia
$provincia = ucfirst($provincia);
$where_add .= " AND b.provincia = '$provincia'";
}
if(isset($regione) && $regione != null){
$regione = strtoupper($regione);
$where_add .= " AND b.regione = '$regione'";
}
$queryC .= $where_add;
$queryC .= " ORDER BY a.comune";
$risultato = mysql_query($queryC) or die("Query fallita: " . mysql_error() );
//carico i risultati dentro in unalista di DIV
$div_totale = "";
while ($div = mysql_fetch_array($risultato, MYSQL_ASSOC)) {
$div_totale .= "<div id=\"risultato\" onmouseover=\"className = 'srs';\" onmouseout=\"className = 'sr';\" class=\"sr\" onclick=\"updTag('".addslashes($div['comune'])."','".addslashes($div['provincia'])."','".addslashes($div['regione'])."');\">";
$div_totale .= '<span class="srt">'.$div['comune'].'</span>';
$div_totale .= '<span class="src">'.$div['provincia'].'</span>';
$div_totale .= '</div>';
}
//add a command to the response to assign the innerHTML attribute of
// the element with id="SomeElementId" to whatever the new content is
$objResponse->addAssign("search-results-comuni","style.display","block");
$objResponse->addAssign("search-results-comuni","innerHTML", $div_totale);
//return the xajaxResponse object
return $objResponse;
}
//visualizzazione delle regioni italiane
function getregioni($arg=null){
/**
* controllo se la stringa passata ha una lunghezza superiore-uguale a 2
*/
//nel seguente caso effettuo la chiamata alla query
require_once('conf.php');
$arg = strtoupper($arg);
$connessione = mysql_connect($host , $userDB, $passwordDB) or die("Connessione non riuscita: " . mysql_error());
mysql_select_db($database) or die("Selezione del database non riuscita");
$queryR = "SELECT DISTINCT(regione) FROM regioni WHERE regione LIKE '".$arg."%'";
$risultatoR = mysql_query($queryR) or die("Query fallita: " . mysql_error() );
//carico i risultati dentro in unalista di DIV
$div_totale_R = "";
while ($div = mysql_fetch_array($risultatoR, MYSQL_ASSOC)) {
$div_totale_R .= "<div id=\"risultato\" onmouseover=\"className = 'srs';\" onmouseout=\"className = 'sr';\" class=\"sr\" onclick=\"updRegioni('".addslashes($div['regione'])."');\">";
$div_totale_R.= '<span class="srt">'.$div['regione'].'</span>';
$div_totale_R .= '<span class="src">Italia</span>';
$div_totale_R .= '</div>';
}
$objResponse = new xajaxResponse();
//add a command to the response to assign the innerHTML attribute of
// the element with id="SomeElementId" to whatever the new content is
$objResponse->addAssign("search-results-regioni","style.display","block");
$objResponse->addAssign("search-results-regioni","innerHTML", $div_totale_R);
//return the xajaxResponse object
return $objResponse;
}
//visualizzazione delle regioni italiane
function getprovince($provincia=null,$regione = null){
/**
* controllo se la stringa passata ha una lunghezza superiore-uguale a 2
*/
//nel seguente caso effettuo la chiamata alla query
require_once('conf.php');
$provincia = ucfirst($provincia);
$connessione = mysql_connect($host , $userDB, $passwordDB) or die("Connessione non riuscita: " . mysql_error());
mysql_select_db($database) or die("Selezione del database non riuscita");
$queryP = "SELECT regione, provincia FROM regioni WHERE provincia LIKE '".$provincia."%'";
$where_add = "";
if($regione != null){
$regione = strtoupper($regione);
//nels eguente caso apporto modifiche al risultato in base alla regione
$where_add = " AND regione = '$regione'";
}
$queryP .= $where_add;
$risultatoP = mysql_query($queryP) or die("Query fallita: " . mysql_error() );
//carico i risultati dentro in unalista di DIV
$div_totale_P = "";
while ($div = mysql_fetch_array($risultatoP, MYSQL_ASSOC)) {
$div_totale_P .= "<div id=\"risultato\" onmouseover=\"className = 'srs';\" onmouseout=\"className = 'sr';\" class=\"sr\" onclick=\"updProvince('".addslashes($div['provincia'])."','".addslashes($div['regione'])."');\">";
$div_totale_P.= '<span class="srt">'.$div['provincia'].'</span>';
$div_totale_P .= '<span class="src">'.$div['regione'].'</span>';
$div_totale_P .= '</div>';
}
$objResponse = new xajaxResponse();
//add a command to the response to assign the innerHTML attribute of
// the element with id="SomeElementId" to whatever the new content is
$objResponse->addAssign("search-results-province","style.display","block");
$objResponse->addAssign("search-results-province","innerHTML", $div_totale_P);
//return the xajaxResponse object
return $objResponse;
}
require('CPComuni.common.php');
$xajax->processRequests();
?>