first commit
This commit is contained in:
117
include/db.class.php
Normal file
117
include/db.class.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
if ( !isset($site) )
|
||||
{
|
||||
require_once( "config.inc.php" );
|
||||
header( 'Location: ' . $accueil );
|
||||
}
|
||||
|
||||
require_once "config.inc.php";
|
||||
require_once "log.php";
|
||||
|
||||
class dbDolibarr extends dbcore
|
||||
{
|
||||
protected $server = "192.168.1.251";
|
||||
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;
|
||||
|
||||
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 )
|
||||
{
|
||||
|
||||
//log_write( $string );
|
||||
if ( empty( $this->connect ) ) $this->open();
|
||||
|
||||
$this->result = $this->connect->query( $string ) ;
|
||||
$error = $this->connect->error;
|
||||
if ( $this->connect->errno > 0 ) log_error( "Échec de la commande query => " . $error . "<br />" . __file__ . ' ligne ' . __line__ . "\n" . $string, true, false);
|
||||
return $error;
|
||||
}
|
||||
|
||||
|
||||
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';
|
||||
//$query='SELECT EXISTS (SELECT * FROM liste_votants WHERE (SELECT INSTR(idVote, "' . $idVote .'"))';
|
||||
$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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 255;
|
||||
}
|
||||
|
||||
function resultat()
|
||||
{
|
||||
for($i=1;i>$n;$n++)
|
||||
{
|
||||
$query='SELECT idVotant, COUNT(value) as resultat FROM lalis_vote WHERE value="' . $value . '" AND idVote="' . $i . '" ';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user