<?php 
#------------------------------------------------------------------------#
# FILE: q_<sezione>_ric.php
# CREATO DA: Paola Paoloni
# IN DATA: 02/01/2007
# CONTENUTO: 
#    INPUT:  $_SESSION[$sezione.'_valore1_ric'],
#            $_SESSION[$sezione.'_valore2_ric']
#    OUTPUT: $risultato_ric
#------------------------------------------------------------------------#
# VERSIONE: 0.1
# MODIFICATO DA: …
# IN DATA: …
# ->
#------------------------------------------------------------------------#

$trace->trace(3,"INIZIO QUERY: ".__FILE__);

//$risultato_report_quote_ric    = NULL; // OUTPUT
if($anno=="0000")
{
// <if[1]>
   // Se sono in q_<sezione>_<azione>.php non DEVO  
	// avere un $anno != false
   K_eccezione::crea(array("codice"  =>"1.1"   , "tracer" => $trace,
                           "file"   =>__FILE__ , "linea"  =>__LINE__ ));
}
if (!K_eccezione::is_lanciata()) 

{ // <if[2]

	// Trattasi di una SELECT *
	//PER OGNI UTENTE SELEZIONO IL TOTALE QUOTE NON PAGATE
	/*$sql_ric  = " SELECT utenti.nome, utenti.cognome,utenti.id_regione, versamenti_quote.id_socio, versamenti_quote.id_riferimento, versamenti_quote.importo, versamenti_quote.sede, versamenti_quote.cc, versamenti_quote.data, versamenti_quote.stringa_pag, regioni.denominazione as regione, versamenti_quote.id as id_versamenti_quote ";
	$sql_ric .= " FROM  versamenti_quote LEFT JOIN utenti on  utenti.id =  versamenti_quote.id_socio";
	$sql_ric .= " LEFT JOIN regioni on  regioni.id =  utenti.id_regione";
	$sql_ric .= " WHERE ";
	if ($alfabeto!=0)
	$sql_ric .= " utenti.cognome LIKE '$contenitore[$alfabeto]%' ";
	else
	$sql_ric .= " utenti.cognome LIKE '%%' ";
	if ($text_searc != "") 
	$sql_ric .= " AND utenti.cognome LIKE '".$text_searc."%' "; 
	if ($regione != 0) 
	$sql_ric .= " AND utenti.id_regione = ' ".$regione." ' "; 
	$sql_ric .= " AND versamenti_quote.data >= ' 01-01-".($anno)." '";
	$sql_ric .= " ORDER BY utenti.id_regione, utenti.cognome ASC";	*/
	$sql_ric=" SELECT utenti.nome, utenti.cognome,versamenti_quote.data,versamenti_quote.importo as quota1,versamenti_quote_rif.importo as quota2, versamenti_quote.stringa_pag, regioni.denominazione as regione ";
	$sql_ric .= " FROM  versamenti_quote ";
	$sql_ric .= " LEFT JOIN versamenti_quote as versamenti_quote_rif on versamenti_quote.id_riferimento =  versamenti_quote_rif.id ";
	$sql_ric .= " LEFT JOIN utenti on  utenti.id =  versamenti_quote.id_socio";
	$sql_ric .= " LEFT JOIN regioni on  regioni.id =  versamenti_quote.id_regione";
	$sql_ric .= " WHERE ";
	if ($alfabeto!=0)
	$sql_ric .= " utenti.cognome LIKE '$contenitore[$alfabeto]%' ";
	else
	$sql_ric .= " utenti.cognome LIKE '%%' ";
	if ($text_searc != "") 
	$sql_ric .= " AND utenti.cognome LIKE '".$text_searc."%' "; 
	if ($regione != 0) 
	$sql_ric .= " AND versamenti_quote.id_regione = ' ".$regione." ' ";
	else
	$sql_ric .= " AND versamenti_quote.id_regione !=0 "; 
	$sql_ric .= " AND versamenti_quote.data >= ' 01-01-".($anno)." '";
	if ($regione == 0) 
	$sql_ric .= " ORDER BY utenti.id_regione, utenti.cognome ASC";
	else
	$sql_ric .= " ORDER BY utenti.cognome ASC";
	$trace->trace(3,"QUERY: ".$sql_ric);
	$risultato_report_quote_ric = $funzioni -> esegui_query_select($sql_ric);
	//$risultato_report_quote_2_ric = $funzioni -> esegui_query_select($sql_ric);
	// Problemi con il database?
	if (!$risultato_report_quote_ric["valori"]) 
	{ // <if[2.1]>
		$trace->trace(3,"ERRORE QUERY: ".mysql_error());
		K_eccezione::crea(array("codice"  =>"1.1",   "tracer" => $trace,
										"file"   =>__FILE__, "linea"  =>__LINE__ ));
	} // </if[2.1]>

} // </if[2]>

$trace->trace(3,"FINE QUERY: ".__FILE__);
?>