$campo){
if ($key==0) $valori="'$idcns',";
elseif ($key==1) {$valori.= "null"; $oldidg=$campo;}
elseif ($key==6) $valori.= ",0";
elseif($key==4) $valori.=",'".utf8_encode($campo)."'";
elseif($key==7) {if($numcampi==9) $valori.=",0"; $valori.= ",'".$campo."'";}
elseif($key==8) {$valori.=",'".utf8_encode($campo)."'";$isnew=1;}
elseif($key==9) {$valori.=",''";}
else $valori.= ",'".$campo."'";
if ($key==2) $numgruppo= $campo;
}
if (!$isnew and isset($valori)) $valori.=",null,null";
if(isset($valori)){
$sql="insert into ".$prefix."_ele_gruppo values($valori)";
try {
$res_gruppo = $dbi->prepare("$sql");
$res_gruppo->execute();
}
catch(PDOException $e)
{
echo $sql . "
" . $e->getMessage();
}
$sql="select id_gruppo from ".$prefix."_ele_gruppo where num_gruppo='$numgruppo' and id_cons='$idcns'";
$resnew = $dbi->prepare("$sql");
$resnew->execute();
list ($newidg) = $resnew->fetch(PDO::FETCH_NUM);
unset($valori);
if($oldidg)
$_SESSION['gruppi']['idg_'.$oldidg]=$newidg;
}
}
}
function inslista()
{
global $prefix, $dbi;
global $ar_lista,$idcns;
foreach ($ar_lista as $rigalista){
if(!isset($rigalista[3])) continue;
$oldidl=0;
$okl=0;
$oldidg=$rigalista[3];
if(isset($_SESSION['gruppi'])) $newidg=$_SESSION['gruppi']['idg_'.$oldidg]; else $newidg=0;
foreach($rigalista as $key=>$campo){
if ($key==0) $valori=$idcns.",";
elseif ($key==1) {$valori.= "null,";$oldidl=$campo;}
elseif ($key==2) {$valori.="'$campo',";$numlista= $campo;}
elseif ($key==3) {$valori.= "'$newidg',"; if ($campo!=$oldidg) $okl=1;}
elseif ($key==4) $valori.= "0,";
elseif ($key==9 ) $valori.= "'$campo'";
else $valori.="'".utf8_encode($campo)."',";
}
if($key==9){
if ($okl) {$okl=0;continue;}
$sql="insert into ".$prefix."_ele_lista values($valori)";
try {
$res_lista = $dbi->prepare("$sql");
$res_lista->execute();
}
catch(PDOException $e)
{
echo $sql . "
" . $e->getMessage();
}
$sql="select id_lista from ".$prefix."_ele_lista where num_lista='$numlista' and id_cons='$idcns'";
$reslnew = $dbi->prepare("$sql");
$reslnew->execute();
list ($newidl) = $reslnew->fetch(PDO::FETCH_NUM);
unset($valori);
if($oldidl){
$_SESSION['liste']['idl_'.$oldidl]=$newidl;
}
}
}
}
function inscandi()
{
global $prefix, $dbi;
global $ar_candi,$idcns;
foreach ($ar_candi as $rigacandi){
if(!isset($rigacandi[2])) continue;
$okc=0;
$oldidl=$rigacandi[2];
$newidl=$_SESSION['liste']['idl_'.$oldidl];
foreach($rigacandi as $key=>$campo){
if (count($rigacandi)!=9) {unset($valori);continue;}
if ($key==0) $valori= "null,";
elseif ($key==1) $valori.="'$idcns',";
elseif ($key==2) {$valori.= "'$newidl'"; if ($campo!=$oldidl) $okc=1;}
else $valori.= ",'".utf8_encode($campo)."'";
}
if(isset($valori) and $valori!=''){
if ($okc) {$okc=0;continue;}
$sql="insert into ".$prefix."_ele_candidati values($valori)";
try {
$res_lista = $dbi->prepare("$sql");
$res_lista->execute();
}
catch(PDOException $e)
{
echo "
key:$key sql:".$sql . "
" . $e->getMessage();
}
}
}
}
$sql="SELECT t1.id_cons, t2.descrizione FROM ".$prefix."_ele_cons_comune as t1 left join ".$prefix."_ele_consultazione as t2 on t1.id_cons_gen=t2.id_cons_gen where t1.id_comune='$id_comune' and t2.id_cons_gen='$id_cons_gen'";
$res = $dbi->prepare("$sql");
$res->execute();
list($id_cons,$descrizione) = $res->fetch(PDO::FETCH_NUM);
if (!isset($_FILES['datafile']['tmp_name']) or !is_uploaded_file($_FILES['datafile']['tmp_name']))
{
ele();
if (isset($_GET['help'])) $help=intval($_GET['help']);
global $help,$language;
if (isset($help)) include("language/$language/ele_importa.html");
echo "