* @package openmairie
*/
///////////////////////////////////////////////////////////////////////////////
// Inclusions de fichiers
///////////////////////////////////////////////////////////////////////////////
// Session
include ("../dyn/session.inc");
// Liaison DB Pear
require_once "DB.php";
// Connexion BDD
include ("../dyn/connexion.php");
// Variables
if (file_exists ("../dyn/custom/var.inc"))
include ("../dyn/custom/var.inc");
else
include ("../dyn/var.inc");
// CSS lien
if (file_exists ("../dyn/custom/lien.inc"))
include ("../dyn/custom/lien.inc");
else
include ("../dyn/lien.inc");
// CSS général
include ("../dyn/cg.css");
if (file_exists ("../dyn/custom/cg.css"))
include ("../dyn/custom/cg.css");
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Vérification des variables GET
///////////////////////////////////////////////////////////////////////////////
// idx
if (isset ($_GET ['idx']))
$idx = $_GET ['idx'];
else
$idx = "";
// validation
if (isset ($_GET ['validation']))
$validation = $_GET ['validation'];
else
$validation = 0;
$ico = "../img/ico_parametrage.png";
$ent = "Paramétrage -> Archivage";
$obj = "archivage";
// Debug
$DEBUG = 0;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Librairies utilisée(s)
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Connexion à la BDD
///////////////////////////////////////////////////////////////////////////////
$db =& DB :: connect ($dsn, $db_option);
if (DB :: isError ($db))
die ($db -> getMessage ());
else
{
if ($DEBUG == 1)
echo "La base ".$dsn ['database']." est connectée.
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Récupération des informations sur la collectivité
///////////////////////////////////////////////////////////////////////////////
// Exécution de la requête du fichier var.inc
$res = $db -> query ($sql_collectivite);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql_collectivite);
else
while ($row =& $res -> fetchRow ())
{
$ville = $row [0];
$logo = $row [1];
}
$res -> free ();
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Récupération des informations sur les droits de l'utilisateur
///////////////////////////////////////////////////////////////////////////////
$sql = "SELECT profil FROM droit WHERE droit = '".$obj."'";
$droit = $db -> getOne ($sql);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Entête HTML
///////////////////////////////////////////////////////////////////////////////
echo "";
echo "
";
include("../dyn/entete.inc");
echo "";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Tableaux : Entête & Aide
///////////////////////////////////////////////////////////////////////////////
// icone aide
$tmp = $ico;
if (file_exists ("../dyn/custom/img/".$tmp.'"'))
$ico = "../dyn/custom/img/".$tmp;
else
$ico = "../img/".$tmp;
// icone entête
if (ereg ("->", $ent))
if (file_exists ("../dyn/custom/img/fleche_droite.png"))
$ent = str_replace ("->", "", $ent);
else
$ent = str_replace ("->", "", $ent);
// HTML
echo "";
echo "
";
echo "
";
echo "
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// JavaScript
///////////////////////////////////////////////////////////////////////////////
?>
";
if ($_SESSION ['profil'] >= $droit)
{
if($validation == 1)
{
///////////////////////////////////////////////////////////////////////////////
// Table election : nbcandidat
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
$sql = "SELECT election_nbcandidat FROM election WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$nbcandidat = $row [0];
}
unset ($res);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election : election
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
$sql = "SELECT sum(inscrit), sum(votant), sum(exprime), sum(nul) FROM resultat WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$inscrit = $row [0];
$votant = $row [1];
$exprime = $row [2];
$nul = $row [3];
}
unset ($res);
unset ($row);
$cloture = -1;
$sql = "UPDATE election SET
election_cloture = ".$cloture.",
election_nbinscrit = ".$inscrit.",
election_nbvotant = ".$votant.",
election_nbnul = ".$nul.",
election_nbexprime = ".$exprime."
WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
if ($DEBUG == 1)
echo "
Table election : election => OK
";
unset ($res);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election : simulation
///////////////////////////////////////////////////////////////////////////////
$election = $idx."C";
$sql = "SELECT sum(inscrit), sum(votant), sum(exprime), sum(nul) FROM resultat WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$inscrit = $row [0];
$votant = $row [1];
$exprime = $row [2];
$nul = $row [3];
}
unset ($res);
unset ($row);
$cloture = -1;
$sql = "UPDATE election SET
election_cloture = ".$cloture.",
election_nbinscrit = ".$inscrit.",
election_nbvotant = ".$votant.",
election_nbnul = ".$nul.",
election_nbexprime = ".$exprime."
WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
if ($DEBUG == 1)
echo "
Table election : simulation => OK
";
unset ($res);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election_candidat : election
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
for ($i = 1; $i <= $nbcandidat; $i++)
{
$sql = "SELECT sum(exprime), sum(candidat".$i.") FROM resultat WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$voix = $row [1];
if($row[0]>0)
$tx = round($row [1]/$row[0],4);
else
$tx=0;
}
unset ($res);
unset ($row);
$sql = "UPDATE election_candidat SET
election_candidat_resultat = ".$voix.",
election_candidat_tx = ".$tx."
WHERE election = '".$election."' AND election_candidat_ordre = ".$i."";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
if ($DEBUG == 1)
echo "
Table election_candidat : election => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election_candidat : simulation
///////////////////////////////////////////////////////////////////////////////
$election = $idx."C";
for ($i = 1; $i <= $nbcandidat; $i++)
{
$sql = "SELECT sum(exprime), sum(candidat".$i.") FROM resultat WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$voix = $row [1];
if($row[0]>0)
$tx = round($row [1]/$row[0],4);
else
$tx=0;
}
unset ($res);
unset ($row);
$sql = "UPDATE election_candidat SET
election_candidat_resultat = ".$voix.",
election_candidat_tx = ".$tx."
WHERE election = '".$election."' AND election_candidat_ordre = ".$i."";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
if ($DEBUG == 1)
echo "
Table election_candidat : simulation => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election_ resultat : election
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
foreach ($_SESSION ['election']['bureaux'] as $bureau)
{
for ($ordre = 1; $ordre <= $nbcandidat; $ordre++)
{
$sql = "SELECT exprime, candidat".$ordre." FROM resultat WHERE election = '".$election."' AND bureau = ".$bureau ['code']."";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$resultat = $row [1];
if($row[0]>0)
$tx = round($row [1]/$row[0],4);
else
$tx=0;
}
unset ($res);
unset ($row);
$sql = "INSERT INTO election_resultat VALUES ('".$election."', ".$bureau ['code'].", ".$ordre.", ".$_SESSION ['candidat'][$ordre]['candidat'].", ".$resultat.", ".$tx.")";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
}
if ($DEBUG == 1)
echo "
Table election_resultat : election => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election_ resultat : simulation
///////////////////////////////////////////////////////////////////////////////
$election = $idx."C";
foreach ($_SESSION ['election']['bureaux'] as $bureau)
{
for ($ordre = 1; $ordre <= $nbcandidat; $ordre++)
{
$sql = "SELECT exprime, candidat".$ordre." FROM resultat WHERE election = '".$election."' AND bureau = ".$bureau ['code']."";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$resultat = $row [1];
if($row[0]>0)
$tx = round($row [1]/$row[0],4);
else
$tx=0;
}
unset ($res);
unset ($row);
$sql = "INSERT INTO election_resultat VALUES ('".$election."', ".$bureau ['code'].", ".$ordre.", ".$_SESSION ['candidat'][$ordre]['candidat'].", ".$resultat.", ".$tx.")";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
}
if ($DEBUG == 1)
echo "
Table election_resultat : simulation => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election_ bureau : election
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
foreach ($_SESSION ['election']['bureaux'] as $bureau)
{
$sql = "SELECT inscrit, votant, nul, exprime FROM resultat WHERE election = '".$election."' AND bureau = ".$bureau ['code']."";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$inscrit = $row [0];
$votant = $row [1];
$nul = $row [2];
$exprime = $row [3];
if($row[1]>0)
$tx = round($row [3]/$row[1],4);
else
$tx=0;
$message = "ok";
if ($votant != $nul + $exprime)
$message = "votant!=nul+exprime => ".($votant - ($nul + $exprime))."";
}
unset ($res);
unset ($row);
$sql = "INSERT INTO election_bureau (election, bureau, election_bureau_nbinscrit, election_bureau_nbvotant, election_bureau_nbnul, election_bureau_nbexprime, election_bureau_txexprime, election_bureau_message) VALUES ('".$election."', ".$bureau ['code'].", ".$inscrit.", ".$votant.", ".$nul.", ".$exprime.", ".$tx.", '".$message."')";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
if ($DEBUG == 1)
echo "
Table election_bureau : election => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table election_ bureau : simulation
///////////////////////////////////////////////////////////////////////////////
$election = $idx."C";
foreach ($_SESSION ['election']['bureaux'] as $bureau)
{
$sql = "SELECT inscrit, votant, nul, exprime FROM resultat WHERE election = '".$election."' AND bureau = ".$bureau ['code']."";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$inscrit = $row [0];
$votant = $row [1];
$nul = $row [2];
$exprime = $row [3];
if($row[1]>0)
$tx = round($row [3]/$row[1],4);
else
$tx=0;
$message = "ok";
if ($votant != $nul + $exprime)
$message = "votant!=nul+exprime => ".($votant - ($nul + $exprime))."";
}
unset ($res);
unset ($row);
$sql = "INSERT INTO election_bureau (election, bureau, election_bureau_nbinscrit, election_bureau_nbvotant, election_bureau_nbnul, election_bureau_nbexprime, election_bureau_txexprime, election_bureau_message) VALUES ('".$election."', ".$bureau ['code'].", ".$inscrit.", ".$votant.", ".$nul.", ".$exprime.", ".$tx.", '".$message."')";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
if ($DEBUG == 1)
echo "
Table election_ bureau : simulation => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table participation_bureau : election
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
$sql = "select bureau, inscrit from resultat where election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$k=0;
while ($row =& $res -> fetchRow ())
{
$bur [$k]['code'] = $row [0];
$bur [$k]['inscrit'] = $row [1];
$k++;
}
}
unset ($res);
unset ($row);
foreach ($bur as $value)
{
$sql = "select tranche, b".$value ['code']." from participation where election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
while ($row =& $res -> fetchRow ())
{
$tranche = $row [0];
$b = $row [1];
$sql = "INSERT INTO participation_bureau (election, bureau, tranche, participation_bureau_nbvotant, participation_bureau_tx) VALUES ('".$election."', ".$value ['code'].", ".$tranche.", ".$b.", ".round($b/$value ['inscrit'],4).")";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
}
unset ($res);
}
if ($DEBUG == 1)
echo "
Table participation_bureau : election => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Table participation_election : election
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
$sql = "SELECT sum(inscrit) from resultat WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
$row =& $res -> fetchRow ();
$inscrit = $row [0];
}
unset ($res);
unset ($row);
$sql = "select tranche, total from participation where election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
while ($row =& $res -> fetchRow ())
{
$tranche = $row [0];
$total = $row [1];
$sql = "INSERT INTO participation_election (election, tranche, participation_election_nbvotant, participation_election_tx) VALUES ('".$election."', ".$tranche.", ".$total.", ".round($total/$inscrit,4).")";
$res1 = $db -> query ($sql);
if (DB :: isError ($res1))
die ($res1 -> getMessage ()." Erreur ".$sql);
unset ($res1);
}
}
unset ($res);
if ($DEBUG == 1)
echo "
Table participation_election : election => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Suppression table RESULTAT
///////////////////////////////////////////////////////////////////////////////
//version 1.04 pas de suppression de la table resultat
//$election = $idx;
//$sql = "delete from resultat WHERE election = '".$election."' or election = '".$election."C'";
//$res = $db -> query ($sql);
//if (DB :: isError ($res))
// die ($res -> getMessage ()." Erreur ".$sql);
//else
// if ($DEBUG == 1)
// echo "
Suppresion enregistrements Table resultat => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Suppression table PARTICIPATION
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
$sql = "delete from participation WHERE election = '".$election."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
if ($DEBUG == 1)
echo "
Suppresion enregistrements Table participation => OK
";
///////////////////////////////////////////////////////////////////////////////
// Suppression table REGROUPEMENT
///////////////////////////////////////////////////////////////////////////////
$election = $idx;
$sql = "delete from regroupement WHERE election = '".$election."' or election = '".$election."C'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
if ($DEBUG == 1)
echo "
Suppresion enregistrements Table regroupement => OK
";
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
unset ($_SESSION ['election']);
unset ($_SESSION ['candidat']);
echo "
Election archivée.
";
}
else
{
echo "";
echo "";
echo "";
//**************************************************************
if (trim($_SESSION ['election']['election']) != "") {
$sql = "select * from election where election='".$_SESSION ['election']['election']."'";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
{
while ($row =& $res -> fetchRow ())
{
echo "";
echo "".$_SESSION ['election']['election']." - ".$row[3]."
";
echo " ATTENTION L'EDITION DE L'ETAT RESULTAT VOUS SERA IMPOSSIBLE APRES L'ARCHIVAGE. ";
}
}
$res -> free ();
}else{
echo "Il n'y a pas d'election en cours ";
}
///////////////////////////////////////////////////////////////////////////////
// Récupération de la liste des élections en cours
///////////////////////////////////////////////////////////////////////////////
/*$sql = "select election, election_libelle from election where election_cloture=0 and election_simulation=0 order by election_libelle";
$res = $db -> query ($sql);
if (DB :: isError ($res))
die ($res -> getMessage ()." Erreur ".$sql);
else
while ($row =& $res -> fetchRow ())
{
echo "";
echo "".$row[1]."
";
}
$res -> free ();*/
///////////////////////////////////////////////////////////////////////////////
//**************************************************************
echo " | ";
echo "
";
echo "
";
//echo "Sélectionnez l'élection à archiver. Attention l'édition de l'état résultat vous sera impossible après l'archivage.
";
}
}
else
echo "Droits insuffisants ou reconnectez-vous.";
// deconnexion
$db -> disconnect ();
if ($DEBUG == 1)
echo "La base ".$dsn ['database']." est déconnectée.
";
echo "";
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Pied de page HTML & Menu
///////////////////////////////////////////////////////////////////////////////
include ("../dyn/menu.inc");
echo "";
echo "