<?php

##################################################################################
#    PHP-RESIDENCE
#    Copyright (C) 2001-2009 by Marco Maria Francesco De Santis (marco@digitaldruid.net)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    any later version accepted by Marco Maria Francesco De Santis, which
#    shall act as a proxy as defined in Section 14 of version 3 of the
#    license.
#
#    This program 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
##################################################################################

$pag = "dati_relutenti.php";
$titolo = "dati_rel";

include("./dati/dati_connessione.php");
include("./includes/funzioni_$PHPR_DB_TYPE.php");
$numconnessione = connetti_db($PHPR_DB_NAME,$PHPR_DB_HOST,$PHPR_DB_PORT,$PHPR_DB_USER,$PHPR_DB_PASS,$PHPR_LOAD_EXT);
include("./includes/funzioni.php");
include("./includes/sett_gio.php");
$tablerelutenti = $PHPR_TAB_PRE."relutenti";
$tablenazioni = $PHPR_TAB_PRE."nazioni";
$tableregioni = $PHPR_TAB_PRE."regioni";
$tablecitta = $PHPR_TAB_PRE."citta";
$tabledocumentiid = $PHPR_TAB_PRE."documentiid";
$tableparentele = $PHPR_TAB_PRE."parentele";


$id_utente = controlla_login($numconnessione,$PHPR_TAB_PRE,$id_sessione,$nome_utente_phpr,$password_phpr,$anno);
if ($id_utente) {

if ($id_utente != 1) {
$tableprivilegi = $PHPR_TAB_PRE."privilegi";
$privilegi_annuali_utente = esegui_query("select * from $tableprivilegi where idutente = '$id_utente' and anno = '$anno'");
if (numlin_query($privilegi_annuali_utente) == 0) $anno_utente_attivato = "NO";
else {
$anno_utente_attivato = "SI";
$privilegi_globali_utente = esegui_query("select * from $tableprivilegi where idutente = '$id_utente' and anno = '1'");
$priv_mod_pers = risul_query($privilegi_globali_utente,0,priv_mod_pers);
if (substr($priv_mod_pers,0,1) != "s") $modifica_pers = "NO";
$priv_ins_clienti = risul_query($privilegi_globali_utente,0,priv_ins_clienti);
if (substr($priv_ins_clienti,0,1) == "s") $inserimento_nuovi_clienti = "SI";
else $inserimento_nuovi_clienti = "NO";
$modifica_clienti = "NO";
if (substr($priv_ins_clienti,1,1) == "s") $modifica_clienti = "SI";
if (substr($priv_ins_clienti,1,1) == "p") $modifica_clienti = "PROPRI";
if (substr($priv_ins_clienti,1,1) == "g") $modifica_clienti = "GRUPPI";
} # fine else if (numlin_query($privilegi_annuali_utente) == 0)
} # fine if ($id_utente != 1)
else {
$anno_utente_attivato = "SI";
$modifica_pers = "SI";
$inserimento_nuovi_clienti = "SI";
$modifica_clienti = "SI";
} # fine else if ($id_utente != 1)


if ($anno_utente_attivato == "SI" and ($modifica_pers != "NO" or $inserimento_nuovi_clienti != "NO" or $modifica_clienti != "NO")) {


if ($id_utente != 1) $id_ut_sel = $id_utente;
else $id_ut_sel = aggslashdb($id_ut_sel);


function trova_rel ($rel,&$rel_sing,&$rel_plur,&$tablerel) {
global $tablenazioni,$tableregioni,$tablecitta,$tabledocumentiid,$tableparentele;
$rel_sing = "nazione";
$rel_plur = "nazioni";
$tablerel = $tablenazioni;
if ($rel == "regione") {
$rel_sing = "regione";
$rel_plur = "regioni";
$tablerel = $tableregioni;
} # fine if ($rel == "regione")
if ($rel == "citta") {
$rel_sing = "citta";
$rel_plur = "citta";
$tablerel = $tablecitta;
} # fine if ($rel == "citta")
if ($rel == "documentoid") {
$rel_sing = "documentoid";
$rel_plur = "documentiid";
$tablerel = $tabledocumentiid;
} # fine if ($rel == "documentoid")
if ($rel == "parentela") {
$rel_sing = "parentela";
$rel_plur = "parentele";
$tablerel = $tableparentele;
} # fine if ($rel == "parentela")
} # fine function trova_rel
trova_rel($rel,$rel_sing,$rel_plur,$tablerel);
trova_rel($rel_sup,$rel_sup_sing,$rel_sup_plur,$tablerel_sup);

if (get_magic_quotes_gpc()) $id = stripslashes($id);
$id = htmlspecialchars($id);
$id_sup = esegui_query("select distinct $tablerel_sup.id$rel_sup_plur from $tablerelutenti inner join $tablerel_sup on $tablerelutenti.id$rel_sup_sing = $tablerel_sup.id$rel_sup_plur where $tablerelutenti.idutente = '$id_ut_sel' and $tablerel_sup.nome_$rel_sup_sing = '".aggslashdb($id)."' ");
if (numlin_query($id_sup)) $is_id = "= '".risul_query($id_sup,0,"id$rel_sup_plur",$tablerel_sup)."'";
else $is_id = "is NULL";



echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
        \"http://www.w3.org/TR/html4/strict.dtd\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" >
<title> $titolo </title>
</head>
<body>
<div id=\"dati_rel\">";


$rel_utente = esegui_query("select distinct $tablerel.nome_$rel_sing,$tablerel.codice_$rel_sing from $tablerelutenti inner join $tablerel on $tablerelutenti.id$rel_sing = $tablerel.id$rel_plur where $tablerelutenti.idutente = '$id_ut_sel' and $tablerelutenti.idsup $is_id order by $tablerel.nome_$rel_sing");
$num_rel_utente = numlin_query($rel_utente);
if ($num_rel_utente) {
echo "<select name=\"$cmp\" id=\"$cmp\">";
if ($pieno != "SI") echo "<option value=\"\">------</option>";
for ($num1 = 0 ; $num1 < $num_rel_utente ; $num1++) {
$rel = htmlspecialchars(risul_query($rel_utente,$num1,"nome_$rel_sing",$tablerel));
echo "<option value=\"$rel\">$rel";
if ($mostra_cod) {
$codice = htmlspecialchars(risul_query($rel_utente,$num1,"codice_$rel_sing",$tablerel));
if ($codice) echo " ($codice)";
} # fine if ($mostra_cod)
echo "</option>";
} # fine for $num1
echo "</select>";
} # fine if ($num_rel_utente)
else echo "<input type=\"text\" name=\"$cmp\" id=\"$cmp\" size=\"20\" maxlength=\"50\">";


echo "</div>
</body>
</html>
";



} # fine if ($anno_utente_attivato == "SI" and...
} # fine if ($id_utente)



?>
