function InitPOTable($table,$Base="",$DirEcho=true,$TypEdit="",$co_user="") {
	global $debug, $DBName;
  	if ($Base=="") $Base=$DBName;
	$reqt = db_qr_comprass("select NM_CHAMP FROM DESC_TABLES where NM_TABLE='$table' AND NM_CHAMP!='TABLE0COMM' ORDER BY ORDAFF");
	if (!$reqt) { 
		return(false);
	} else {
		foreach ($reqt as $chp) {
			$CIL[$chp['NM_CHAMP']]=new PYAobj(); // nouvel objet
			$CIL[$chp['NM_CHAMP']]->NmBase=$Base;
			$CIL[$chp['NM_CHAMP']]->NmTable=$table;
			$CIL[$chp['NM_CHAMP']]->NmChamp=$chp['NM_CHAMP'];
			$CIL[$chp['NM_CHAMP']]->TypEdit=$TypEdit;
			$CIL[$chp['NM_CHAMP']]->InitPO();
			if ($DirEcho!=true) $CIL[$chp['NM_CHAMP']]->DirEcho=false;
			if ($co_user!="" && $TypEdit!="C") $CIL[$chp['NM_CHAMP']]->InitAvMaj($co_user);
		}
		return($CIL);
	}
}
			if ($rt != $TBDname) { // pas de test de la table de description
				$err = false;
				echo "<H4>Table $rt </H4>";
				$TbFieldList = db_qr_comprass("SHOW FIELDS FROM ".$rt);
				foreach ($TbFieldList as $InfoField) {
					if (!db_qr_comprass("select * from $TBDname where NM_TABLE='$rt' AND NM_CHAMP ='".$InfoField['Field']."'")) {
						echo "Champ ".$InfoField['Field']." (".$InfoField['Type'].",".$InfoField['Null'].",".$InfoField['Key'].",".$InfoField['Default'].",".$InfoField['Extra'].") absent de $TBDname<br/>";
						$err = true;
					}
					$tbTbChpBdd[$rt][$InfoField['Field']] = 1; // pr la suite
				} // fin boucle sur champs
				if (!$err) echo "==>OK<br/>";
			} // fin si pas table de desc
		} // fin boucle sur tables
		echo "<H3> Test $TBDname -> BDD</H3>";
		$tbd = db_qr_comprass("select * from $TBDname where NM_TABLE NOT LIKE '$id_vtb%' AND NM_CHAMP != 'TABLE0COMM' ORDER BY NM_TABLE,NM_CHAMP");
		
		foreach ($tbd as $InfoField) {
			if ($InfoField['NM_TABLE'] != $tabprec) {
				if ($tabprec!="" && !$err) echo "==>OK<br/>";
				$tabprec = $InfoField['NM_TABLE'];
				$err = false;
				echo "<H4>Table $tabprec </H4>";
			}
			if ($tbTbChpBdd[$tabprec][$InfoField['NM_CHAMP']] != 1) {
				echo "Champ ".$InfoField['NM_CHAMP']." (Libelle:".$InfoField['LIBELLE'].", typeAff:".$InfoField['TYPEAFF'].", Valeurs".$InfoField['VALEURS'].") absent de la BDD<br/>";
				$err = true;
			}
		}
	}
} elseif ($CREATION=="vrai" || $CREATION=="MAJ") {
</TD><TD colspan="4">Serveur : <input type="text" name="dbhost" id="dbhost"/><br/>
	Base : <input type="text" name="dbname" id="dbname"/><br/>
	User : <input type="text" name="dbuser" id="dbuser"/><br/>
	M.d;P : <input type="text" name="dbpwd" id="dbpwd"/><br/>
	</TD></TR>
<TR><TD>Champs FK (multiples), dans la table courante <?php 
echo $_REQUEST['NM_TABLE'];
?>
 <br>
<i><small>Cette information est optionnelle, par défaut c'est le nom du champ courant, <?php 
echo $_REQUEST['NM_CHAMP'];
?>
, qui sera utilisé</small></i></TD>
<TD colspan="4">
<? // LD champs FK de la table locale
$lchptbloc = db_qr_comprass("SELECT NM_CHAMP,LIBELLE FROM $TBDname where NM_TABLE='".$_REQUEST['NM_TABLE']."' AND NM_CHAMP!='$NmChDT' order by ORDAFF");
foreach ($lchptbloc as $chp) {
	$tbchploc[$chp['NM_CHAMP']] = $chp['NM_CHAMP']." (".$chp['LIBELLE'].")";
}
DispLD($tbchploc,"locFKeys",$Mult="yes",$Fccr="LDF");
?>
</TD></TR>
<TR class="THEAD"><td class="th">Variables obligatoires</td><td class="th" colspan="4">Valeur</td></tr>

<? // list de stables 
$tbltab = db_show_tables($DBName);
foreach ($tbltab as $tab) {
	//$lb = RecupLib($TBDname,"NM_TABLE","LIBELLE",$tab,"","NM_CHAMP='$NmChDT'"); // trop long, ça le fait ramer
	$tbltab4ld[$tab] = $tab.($lb ? ' ('.$lb.')': '');
}
 function look4closest($lat, $long, $limit = 5, $type = "%", $addwhere = "", $pointinfo = "")
 {
     $this->tbresult = array();
     // 111.64=2pi/360*6400, rayon de la terre, arrondi à 120 car dist à vol d'oiseau
     if ($this->base2look == "typo3") {
         $rep = db_qr_comprass("select *,sqrt((geo_lat - {$lat})*(geo_lat- {$lat} ) + (geo_long - {$long})*(geo_long - {$long}))*120 as dist from tx_dlcubehn03geomatic_points WHERE type LIKE '{$type}' {$addwhere}  AND deleted=0 AND hidden=0 ORDER BY dist asc LIMIT {$limit}");
     } else {
         if ($type != "" && $type != "%") {
             $whtype = " AND UFO_NUTYPOSTRUCT IN (" . $this->type2typostruct[$type] . ") ";
         }
         $rep = $this->db_qr_comprass_ingdp2("select *,sqrt((LAC_FLLAT - {$lat})*(LAC_FLLAT- {$lat} ) + (LAC_FLLONG - {$long})*(LAC_FLLONG - {$long}))*120 as dist  from zgrh_UNITE_FONCTION,zgrh_LIEU_ACTIVITE WHERE UFO_NULIEUACTIVITE=LAC_NULIEUACT \n\t\t\t AND UFO_COACTIVE='O' AND LAC_FLLAT>0 AND LAC_FLLONG!=0 {$whtype} {$addwhere} ORDER BY dist asc limit {$limit}");
     }
     if ($rep) {
         foreach ($rep as $lrep) {
             $ce = $this->cvlrep2res($lrep);
             $this->tbresult[] = $ce;
             $TSite = $this->GetSiteType($lrep);
             $url = str_replace("NUUNITEAPOINTER", $lrep["UFO_NUUNITE"], $this->tbLinks2SitePages[$TSite]);
             $img = $this->GetSiteImg($TSite);
             $ret .= $this->displayPoint(array("lat" => $ce['lat'], "long" => $ce['long'], "title" => $ce['nom'], "url" => $url, "img" => $img));
         }
     } else {
         $this->tbresult = false;
     }
     // affiche le point demandé avec une pitite maison
     $this->PointInfo = $pointinfo;
     $ret .= $this->centerMap($lat, $long, 8);
     $ret .= $this->displayPoint(array("lat" => $lat, "long" => $long, "title" => "Mon adresse", "img" => $this->HomeImageFile));
     return $ret;
 }
 /**
  * fonction qui cr�e les variables a passer �PSI
  */
 function makepsival()
 {
     // 					<input type="hidden" name="direction"> //
     // 			<input type="hidden" name="compteurPrest" value="1"> // nbr prestations
     // 			<input type="hidden" name="listePrestation.codeAppliAppel" value="HSN"/> // idem
     // 			<input type="hidden" name="listePrestation.payeur" value="<%=oContextConn.getUser()%>"/> //ok
     // 			<input type="hidden" name="listePrestation.langue" value="<%=""+session.getAttribute("langue")%>"/> // FR
     // 			<input type="hidden" name="listePrestation.urlRetour" value="http://www4.haras-nationaux.fr:8080/HARASIRE/utilisateur/redirection_identification_valide.jsp"/>
     // 			<input type="hidden" name="listePrestation.prestations[0].coTyPrestation" value="HSN"/>
     // 			<input type="hidden" name="listePrestation.prestations[0].coSTyPrestation" value="<%=coTyPrestPsi%>"/>
     // 			<input type="hidden" name="listePrestation.prestations[0].nbQuantite" value="1"/>
     // 			<input type="hidden" name="listePrestation.prestations[0].coCircoStat" value="SIR"/> //idem
     // 			<% if(oInfosUser.getAuthentification().equals("FORT")){%> // a tester
     // 				<input type="hidden" name="listePrestation.prestations[0].nuPersoClient" value="<%=oInfosUser.getNuPersoClient()%>"/>
     // 				<input type="hidden" name="listePrestation.prestations[0].nuOrdAdClient" value="<%=oInfosUser.getNuOrdAdClient()%>"/>
     // 			<%}else{%>
     // 			<input type="hidden" name="listePrestation.portalID" value="<%=oContextConn.getUser()%>"/>
     // 			<%}%>
     $ret .= "\n";
     $ret .= rethidchp("direction", "");
     $ret .= rethidchp("listePrestation.codeAppliAppel", "HSN");
     $ret .= rethidchp("listePrestation.payeur", $this->personne->prenom . " " . $this->personne->nom);
     $ret .= rethidchp("listePrestation.langue", "FR");
     $urlParameters['cHash'] = $this->cHash;
     $urlParameters['hnkart_mode'] = "bc4";
     $ret .= rethidchp("listePrestation.urlRetour", $this->absurl . $this->pi_getPageLink($GLOBALS["TSFE"]->id, '', $urlParameters));
     $ret .= rethidchp("listePrestation.montantTotal", $_SESSION["totgen"]);
     $ret .= rethidchp("listePrestation.portalID", $_SESSION["portalId"]);
     //		$ret.=rethidchp("","");
     foreach ($_SESSION['hn_kart'] as $uid => $qte) {
         $tbuid[] = $uid;
     }
     if ($_SESSION['frais_port']) {
         // s'il y a des frais de port
         $tbuid[] = $_SESSION['uidfp'];
         $_SESSION["nbart"]++;
     }
     $ret .= rethidchp("compteurPrest", $_SESSION["nbart"]);
     $tbuid = implode(",", $tbuid);
     $rep = db_qr_comprass("select uid,title,ref,price,tva,cotypresta,cosstypresta from tx_dlcubehnshop_articles where uid IN ({$tbuid})");
     $i = 0;
     foreach ($rep as $tbrep) {
         if ($tbrep['price'] > 0) {
             // il y a des articles gratuits, dont le port, on appelle pas PSI dans ce cas
             $qte = $tbrep['uid'] != $_SESSION['uidfp'] ? $_SESSION['hn_kart'][$tbrep['uid']] : 1;
             // si frais port, tjrs qte=1
             $totl = $tbrep['price'] * $qte;
             if ($tbrep['cotypresta'] == cotypresta_telech && $tbrep['cosstypresta'] == cosstypresta_telech) {
                 $qte = $tbrep['price'] * $qte;
                 // dans la table des presta, le telechargement est a 1 euro
             }
             //$ret.=rethidchp("listePrestation.prestations[$i].nuPrestation",$tbrep['ref']);
             $ret .= rethidchp("listePrestation.prestations[{$i}].coTyPrestation", $tbrep['cotypresta']);
             $ret .= rethidchp("listePrestation.prestations[{$i}].coSTyPrestation", $tbrep['cosstypresta']);
             $ret .= rethidchp("listePrestation.prestations[{$i}].nbQuantite", $qte);
             //$ret.=rethidchp("listePrestation.prestations[$i].mtHtPrestation",$tbrep['price'] / (1 +$tbrep['tva']) );
             //$ret.=rethidchp("listePrestation.prestations[$i].txTvaSTyPrestation",$tbrep['tva']);
             $ret .= rethidchp("listePrestation.prestations[{$i}].llObservation", $tbrep['title']);
             //$ret.=rethidchp("listePrestation.prestations[$i].montantTtc",$totl);
             $ret .= rethidchp("listePrestation.prestations[{$i}].coCircoStat", "SIR");
             if ($this->personne->niveauIdentification == "FORT") {
                 $ret .= rethidchp("listePrestation.prestations[{$i}].nuPersoClient", $this->personne->key->numeroPersonne);
                 $ret .= rethidchp("listePrestation.prestations[{$i}].nuOrdAdClient", $this->personne->key->numeroOrdreAdresse);
             }
             //				$ret.=rethidchp("listePrestation.prestations[$i].",$tbrep['']);
             $i++;
         }
         // fin si pas article gratos
     }
     // fin boucle sur articles
     return $ret;
 }
//include_once("reg_glob.inc");
DBconnect();

$admadm = (int)$_REQUEST['admadm'];

$title=($admadm==1? trad(LT_titleadm) : trad(LT_titleedit))." ".$DBName;
include ("header.php");

// gestion creation/effacement des tables virtuelles
// creation
if (isset($_REQUEST['lc_NM_VTB2C'])) {
// lc_NM_TABLE='+table+'&lc_NM_VTB2C=
// $TBDname $NmChDT'
	if (strstr($_REQUEST['lc_NM_VTB2C'],$id_vtb)) { // verifie que le nom entré contient bien l'id de table virtuelle
		if ($_REQUEST['lc_NM_TABLE'] != "newvtable") {
			$rw=db_qr_comprass("SELECT * FROM $TBDname WHERE NM_TABLE='".$_REQUEST['lc_NM_TABLE']."'");
			foreach($rw as $enr) {
				$enr['NM_TABLE'] = $_REQUEST['lc_NM_VTB2C'];
				
				if ($enr['NM_CHAMP']==$NmChDT) {
					$enr['LIBELLE'].="  ! Alias de la table : ".$_REQUEST['lc_NM_TABLE'];
				} else {
					$enr['VALEURS'] .= "\n".'$physTable='.$_REQUEST['lc_NM_TABLE'];
					$enr['VALEURS'] .= "\n".'$locFKeys='.$enr['NM_CHAMP'];
				}
				foreach ($enr as $chp=>$val) $enr[$chp]="'".addslashes($val)."'";
				db_query("INSERT INTO $TBDname ".tbset2insert($enr));
			}
		} else { // nvlle table virtuelle
			db_query("INSERT INTO $TBDname (NM_TABLE,NM_CHAMP,LIBELLE,TYPAFF_L) VALUES ('".$_REQUEST['lc_NM_VTB2C']."','TABLE0COMM','Nouvelle table virtuelle','AUT')");
		}
 function look4closest($lat, $long, $limit = 5, $type = "%", $addwhere = "", $pointinfo = "")
 {
     $this->tbresult = array();
     // 111.64=2pi/360*6400, rayon de la terre, arrondi à 120 car dist à vol d'oiseau
     $rep = db_qr_comprass("select *,sqrt((geo_lat - {$lat})*(geo_lat- {$lat} ) + (geo_long - {$long})*(geo_long - {$long}))*120 as dist from tx_dlcubehn03geomatic_points WHERE type LIKE '{$type}' {$addwhere}  AND deleted=0 AND hidden=0 ORDER BY dist asc LIMIT {$limit}");
     if ($rep) {
         foreach ($rep as $lrep) {
             $this->tbresult[] = $this->cvlrep2res($lrep);
             $this->PointInfo = $lrep['name'];
             $ret .= $this->displayPoint($lrep['geo_lat'], $lrep['geo_long']);
         }
     } else {
         $this->tbresult = false;
     }
     // affiche le point demandé avec une pitite maison
     $this->PointInfo = $pointinfo;
     $ret .= $this->centerMap($lat, $long, 8);
     $ret .= $this->displayPoint($lat, $long, $this->HomeImageFile);
     return $ret;
 }