getMessage ());
if ($DEBUG == 1)
echo "La base ".$dsn ['database']." est connectée.
";
// COLLECTIVITE
$res = $db -> query ($sql_collectivite);
if (DB :: isError ($res))
die ($res -> getMessage ()." erreur ".$sql_collectivite);
$row =& $res -> fetchRow ();
//while ($row1 =& $res1 -> fetchRow ()){
$ville = $row [1];
$departement =$row[5];
$commune=$row[6];
$circonscription=$row[7];
$res -> free ();
// HEADER HTML
echo "\n";
echo "\t
\n";
include ("../dyn/entete.inc");
echo "\t\n";
echo "\t\n";
echo "";
if($validation==0){
echo "
Transfert bureau à la prefecture";
echo "
";
echo "
";
echo "Code collectivite, departement circonscription a saisir en table collectivie
";
echo "Code depot de liste a remplir en table election_candidat
";
echo "Code prefecture du canton a saisir en table canton
";
echo "
Note prefecture Cantonale";
echo "
Note prefecture Presidentielle";
echo "
Note prefecture legislative";
}else{
echo "indicatif : ".$indicatif."
";
// données election
$sql= "select * from election where election ='".$_SESSION['election']['election']."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow (DB_FETCHMODE_ASSOC);
// type election
if($row['typeelection']== 'MUN')
echo $_SESSION['election']['election']." est une election municipale - voir procedure speciale
";
// correspondance a verifier ***
switch ($row['typeelection']) {
case "CAN":
$scrutin="CN";
break;
case "LEG":
$scrutin="LG"; //***
break;
case "PRE":
$scrutin="PR"; //***
break;
case "REF":
$scrutin="RF"; //***
break;
case "REG":
$scrutin="RG"; //***
break;
case "EUR":
$scrutin="EU"; //***
break;
case "MUN":
$scrutin="MN";
break;
}
// canton
if($scrutin=="CN"){
$sql="select canton_prefecture from canton where canton = '".
$row['election_canton']."'";
$canton = $db -> getOne ($sql);
}else
$canton="";
// ligne1
$ligne1= $scrutin.";";
$ligne1.= substr($row['election_date'],0,4).";";
$ligne1.= $row['election_tour'].";";
$ligne1.= $departement.";"; // code departement collectivite
$ligne1.= $commune.";"; // code insee collectivite
// nombre de candidat
$nbcandidat = str_pad($row['election_nbcandidat'],2,"0", STR_PAD_LEFT);
}
$res -> free ();
// liste prefecture
$sql= "select liste_prefecture from election_candidat where election ='".
$_SESSION['election']['election']."' order by election_candidat_ordre";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$k=1;
while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
$liste[$k]=str_pad($row['liste_prefecture'],3,"0", STR_PAD_LEFT);
$k++;
}
}
$res -> free ();
// resultat
$sql= "select * from resultat where election ='".$_SESSION['election']['election']."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
while ($row=& $res->fetchRow(DB_FETCHMODE_ASSOC)){
$seq++;
$sequence=str_pad($seq,4,"0", STR_PAD_LEFT);
$export.= $sequence.";".$ligne1.str_pad($row['bureau'],4,"0", STR_PAD_LEFT).";";
$export.= str_pad($canton,2,"0", STR_PAD_LEFT).";";
$export.= str_pad($circonscription,2,"0", STR_PAD_LEFT).";";
$export.= $indicatif.";";
$export.= str_pad($row['inscrit'],8,"0", STR_PAD_LEFT).";";
$abstention = $row['inscrit']- $row['votant'];
$export.= str_pad($abstention,8,"0", STR_PAD_LEFT).";";
$export.= str_pad($row['votant'],8,"0", STR_PAD_LEFT).";";
$export.= ";"; // votant fe a vide
$export.= "00000000;"; // nbre de bulletin blanc 8*0
$export.= str_pad($row['nul'],8,"0", STR_PAD_LEFT).";";
$export.= str_pad($row['exprime'],8,"0", STR_PAD_LEFT).";";
// total pour verification
$inscrit=$inscrit+$row['inscrit'];
$votant=$votant+$row['votant'];
$nul=$nul+$row['nul'];
$exprime=$exprime+$row['exprime'];
// candidat
$export.= $nbcandidat.";";
for($i=1;$i<=$nbcandidat;$i++){
$export.= $liste[$i].";";
$export.= str_pad($row['candidat'.$i],8,"0", STR_PAD_LEFT).";"; // code depot de liste ?
$totalcandidat=$totalcandidat+ $row['candidat'.$i];
}
$export=substr($export,0,strlen($export)-1);
$export.="\n";
}
}
$res -> free ();
// ecriture des fichiers en tmp
echo "
verification: |
";
echo "Total inscrits | ".$inscrit." |
";
echo "Total votants | ".$votant." |
";
echo "Total nul | ".$nul." |
";
echo "Total exprime | ".$exprime." |
";
$verif1=$votant-($exprime+$nul);
if($verif1 !=0) echo "*** ATTENTION ERREUR votant/exprime+nul *** |
";
echo "verification : votant - (exprime + nul) = 0 | ".$verif1." |
";
$verif2=$exprime-$totalcandidat;
if($verif2 !=0) echo "*** ATTENTION ERREUR exprime/totalcandidat *** |
";
echo "verification : exprime - totalcandidat = 0 | ".$verif2." |
";
echo "
";
$fichier = "../tmp/".$departement.$commune."_bureau.csv";
$inf = fopen($fichier,"w");
//$export=substr($export,0,strlen($export)-1); // un \n en trop
fwrite($inf,$export);
fclose($inf);
echo "fichier ../tmp/".$departement.$commune."_bureau.csv sauvegarde
";
$affiche= str_replace("\n","
",$export);
echo $affiche;
}//fin validation
//=======================================================================
echo "
";
// DECONNEXION BDD
$db -> disconnect ();
if ($DEBUG == 1) echo "La base ".$dsn ['database']." est déconnectée.