2021-10-14 17:58:21 +02:00
< ? php
2021-10-17 15:55:05 +02:00
//test if not directly called
2021-10-14 17:58:21 +02:00
if ( ! isset ( $site ) )
{
require_once ( " config.inc.php " );
header ( 'Location: ' . $accueil );
}
require_once " config.inc.php " ;
require_once " log.php " ;
class dbDolibarr extends dbcore
{
2021-10-17 15:55:05 +02:00
protected $server = " 192.168.1.250 " ;
2021-10-14 17:58:21 +02:00
protected $port = 3306 ;
protected $user = " dolibarr " ;
protected $passwd = " mysql_dolibarr " ;
protected $database = " dolibarr " ;
}
class db extends dbcore
{
protected $server = " localhost " ;
protected $port = 3306 ;
protected $user = " votation " ;
protected $passwd = " Lalis_votation " ;
protected $database = " votations " ;
}
class dbcore
{
public $connect ;
public $result ;
public $id ;
2021-10-17 15:55:05 +02:00
public $error ;
2021-10-14 17:58:21 +02:00
function __construct ()
{
$this -> open ();
}
function open ()
{
if ( ! $this -> connect )
{
$this -> connect = new mysqli ( $this -> server , $this -> user , $this -> passwd , $this -> database );
if ( $this -> connect -> connect_errno )
{
log_error ( " Échec de la connexion : => " . $this -> connect -> connect_error . " <br /> " . __file__ . ' ligne ' . __line__ , false , false );
return false ;
}
}
$this -> connect -> set_charset ( " utf8 " );
return true ;
}
function close ()
{
$this -> connect -> close ();
$this -> connect = 0 ;
}
function protect ( $string )
{
return $this -> connect -> real_escape_string ( $string );
}
function query ( $string )
{
2021-10-17 15:55:05 +02:00
$this -> error = 0 ;
2021-10-14 17:58:21 +02:00
if ( empty ( $this -> connect ) ) $this -> open ();
$this -> result = $this -> connect -> query ( $string ) ;
2021-10-17 15:55:05 +02:00
$this -> error = $this -> connect -> error ;
if ( $this -> connect -> errno > 0 ) log_error ( " Échec de la commande query => " . $this -> error . " <br /> " . __file__ . ' ligne ' . __line__ . " \n " . $string , true , false );
return $this -> error ;
2021-10-14 17:58:21 +02:00
}
function vote ( $idVotation , $idVotant , $idVote , $idCandidat )
{
$flag = 0 ;
$query = 'SELECT IF(identifiant="' . $idVotant . '" AND idVotation="' . $idVotation . '" AND INSTR(idVote, "' . $idVote . '"),TRUE,FALSE) as r FROM liste_votants' ;
$this -> query ( $query );
if ( ( $r = $this -> result -> fetch_array ( MYSQLI_ASSOC )))
{
$query = 'SELECT IF ( id="' . $idVotation . '",TRUE,FALSE) as r FROM liste_votations' ;
$this -> query ( $query );
if ( ( $r = $this -> result -> fetch_array ( MYSQLI_ASSOC )))
{
$query = 'SELECT IF( idVotation="' . $idVotation . '" AND id="' . $idVote . '",TRUE,FALSE) as r FROM liste_votes' ;
$this -> query ( $query );
if ( ( $r = $this -> result -> fetch_array ( MYSQLI_ASSOC )))
{
$query = 'SELECT IF(id="' . $idCandidat . '" AND idVotation="' . $idVotation . '" AND idVote="' . $idVote . '",TRUE,FALSE) FROM liste_candidats' ;
$this -> query ( $query );
if ( ( $r = $this -> result -> fetch_array ( MYSQLI_ASSOC )))
{
$query = 'INSERT INTO votes (idVotant, idVotation, idVote, idCandidat) VALUES ("' . $this -> protect ( $idVotant ) . '", "' . $this -> protect ( $idVotation ) . '", "' . $this -> protect ( $idVote ) . '", "' . $this -> protect ( $idCandidat ) . '")' ;
$error = $this -> query ( $query );
return $error ;
}
}
}
}
2021-10-17 15:55:05 +02:00
return 'Error ' ;
2021-10-14 17:58:21 +02:00
}
function resultat ()
{
for ( $i = 1 ; i > $n ; $n ++ )
{
$query = 'SELECT idVotant, COUNT(value) as resultat FROM lalis_vote WHERE value="' . $value . '" AND idVote="' . $i . '" ' ;
}
}
2022-09-25 18:11:42 +02:00
2022-09-29 11:32:23 +02:00
function queryVotationList ()
2022-09-25 23:06:35 +02:00
{
2022-09-29 11:32:23 +02:00
$query = " SELECT * FROM liste_votations " ;
2022-09-25 23:06:35 +02:00
$this -> query ( $query );
2022-09-29 11:56:52 +02:00
$votationLine = $this -> result -> fetch_all ( MYSQLI_ASSOC );
2022-09-29 11:32:23 +02:00
foreach ( $votationLine as $line )
{
$votationList [ $line [ " id " ]] = $line ;
}
return $votationList ;
2022-09-25 23:06:35 +02:00
}
function queryVotationName ( $idVotation ) : string
2022-09-25 18:11:42 +02:00
{
$query = " SELECT libelle FROM liste_votations WHERE id=' " . $idVotation . " ' " ;
2022-09-25 23:06:35 +02:00
$this -> query ( $query );
$votationLine = $this -> result -> fetch_assoc ();
2022-09-25 18:11:42 +02:00
return $votationLine [ " libelle " ];
}
2022-09-29 11:32:23 +02:00
function queryVoteList ( $idVotation )
{
$query = " SELECT * FROM liste_votes WHERE idVotation = " . idVotation ;
$this -> query ( $query );
2022-09-29 11:56:52 +02:00
$votes = $this -> result -> fetch_all ( MYSQLI_ASSOC );
2022-09-29 11:32:23 +02:00
foreach ( $votes as $line )
{
$votesList [ $line [ " id " ]] = $line ;
}
return $votesList ;
}
function queryVoteName ( $idVote )
{
$query = " SELECT libelle FROM liste_votes WHERE id=' " . $idVote . " ' " ;
$this -> query ( $query );
$voteLine = $this -> result -> fetch_assoc ();
return $voteLine [ " libelle " ];
}
2022-09-25 23:06:35 +02:00
function queryVotes ( $idVotation )
2022-09-25 18:11:42 +02:00
{
2022-09-29 16:40:13 +02:00
$query = " SELECT lv.id, lv.libelle, ms.libelle as methode FROM liste_votes as lv LEFT JOIN methods as ms ON lv.methode=ms.id WHERE idVotation=' " . $idVotation . " ' " ;
2022-09-25 23:06:35 +02:00
$this -> query ( $query );
2022-09-29 11:56:52 +02:00
$votes = $this -> result -> fetch_all ( MYSQLI_ASSOC );
2022-09-25 18:11:42 +02:00
return $votes ;
}
2022-09-25 23:06:35 +02:00
function queryCandidatsList ( $idVotation , $idVote )
{
$query = " SELECT * FROM liste_candidats WHERE idVotation=' " . $idVotation . " ' AND idVote=' " . $idVote . " ' " ;
$this -> query ( $query );
2022-09-26 10:55:16 +02:00
$candidats = $this -> result -> fetch_all ( MYSQLI_ASSOC );
2022-09-29 11:32:23 +02:00
foreach ( $candidats as $line )
{
$candidatsList [ $line [ " id " ]] = $line ;
}
return $candidatsList ;
2022-09-25 23:06:35 +02:00
}
2021-10-14 17:58:21 +02:00
}
2022-09-25 23:06:35 +02:00
function queryCandidatName ( $idCandidat )
{
$query = " SELECT libelle FROM liste_candidats where id=' " . $idCandidat . " ' " ;
$this -> query ( $query );
$line = $this -> result -> fetch_assoc ();
return $line [ " candidat " ];
}
2021-10-14 17:58:21 +02:00
?>