diff --git a/include/config.inc.php b/include/config.inc.php
index 62900c7..bdb69bc 100644
--- a/include/config.inc.php
+++ b/include/config.inc.php
@@ -5,14 +5,14 @@ define( 'EOLH', "
\n" );
define( 'LF', "\r\n" );
define( 'TAB', "\t" );
-//constantes des niveaux de log
+//Log Level constants
define( "INFO", 1 );
define( "ALERT", 2 );
define( "ERROR", 3 );
define( "DATE_MYSQL", "Y-m-d H:i:s" );
-//variables diverses
+//environment variables
$admin = "Daniel";
$webmaster = "contact@lalis.fr";
$site = "Lalis";
diff --git a/include/db.class.php b/include/db.class.php
index 00bcb4c..e9f656c 100644
--- a/include/db.class.php
+++ b/include/db.class.php
@@ -1,4 +1,5 @@
error = 0;
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 . "
" . __file__ . ' ligne ' . __line__ . "\n" . $string, true, false);
- return $error;
+ $this->error = $this->connect->error;
+ if ( $this->connect->errno > 0 ) log_error( "Échec de la commande query => " . $this->error . "
" . __file__ . ' ligne ' . __line__ . "\n" . $string, true, false);
+ return $this->error;
}
@@ -80,7 +80,6 @@ class dbcore
{
$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)))
{
@@ -103,7 +102,7 @@ class dbcore
}
}
}
- return 255;
+ return 'Error ';
}
function resultat()
diff --git a/include/log.php b/include/log.php
index 5cf6cb1..9006187 100644
--- a/include/log.php
+++ b/include/log.php
@@ -10,9 +10,11 @@ require_once 'fonctions.inc.php';
// $level => INFO, ALERT, ERROR
function log_write($log, $level=INFO)
{
- //require_once( "envoi_courriel.inc.php" );
global $table_prefix, $webmaster, $db;
- $user = ( !empty( $_SERVER["PHP_AUTH_USER"])?$_SERVER["PHP_AUTH_USER"]:'' );
+ // actual connected user or user 'script'
+ $user = (!empty( $_SERVER["PHP_AUTH_USER"])?$_SERVER["PHP_AUTH_USER"]:'Intruder?!');
+
+ //mail message
$log_mail = str_replace ( "
", "\n", $log ) . "\n";
$log_mail .= ( !empty( $_SERVER["REQUEST_METHOD"])?'$_SERVER["REQUEST_METHOD"]' . $_SERVER["REQUEST_METHOD"] . "\n":'' );
$log_mail .= ( !empty( $_SERVER["QUERY_STRING"])?'$_SERVER["QUERY_STRING"]' . $_SERVER["QUERY_STRING"] . "\n":'' );
@@ -25,24 +27,26 @@ function log_write($log, $level=INFO)
$log_mail .= "Utilisateur: $user \n";
$log_mail .= ( !empty( $_SERVER["ORIG_PATH_INFO"])?'$_SERVER["ORIG_PATH_INFO"]' . $_SERVER["ORIG_PATH_INFO"] . "\n":'' );
$log_mail .= ( !empty( $_SERVER["PATH_INFO"])?'$_SERVER["PATH_INFO"]' . $_SERVER["PATH_INFO"] . "\n":'' );
- //$db = new db();
- //$db->open();
+
+ // verifying connection to database
if( !empty( $db->connect ) )
{
+ // saving log into database
$query = 'INSERT INTO ' . $db->protect($table_prefix) . 'logs SET date=NOW(), auteur="' . $db->protect( $user ) . '", log="' . $db->protect($log) . '", niveau="' . $db->protect($level) . '"';
$db->query( $query );
if ( !$db->result )
{
+ // send mail in case of query error
$text = $db->error() . "\n\n" . $log_mail;
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text );
}
}else
{
- //echo $db->error();
+ //send mail in case of database connection error
mail( $webmaster, "Erreur de connecxion à la base de données => " . __file__ . " ligne " . __line__ , $log_mail);
}
- //$db->close();
+ // send mail to admin in case of level > INFO
if ( $level == ALERT )
{
mail( $webmaster, "Alerte Site Web", $log_mail );
@@ -52,25 +56,25 @@ function log_write($log, $level=INFO)
}
}
-// $w_db = true -> écrire les logs dans la base (défaut)
-// $die = true -> execute die() -> termine le programme
+// $w_db = true -> write log in database (default)
+// $die = true -> execute die() -> script end
function log_error($log, $w_db=true, $die=false)
{
global $webmaster, $headers, $accueil, $db;
if ( $w_db ) log_write($log, ERROR);
- //echo "$log
\n";
$log_err = 'erreur dans la requête
un rapport détaillé a été envoyé au webmaster';
if ( $die )
{
//echo "\n";
- //die( $log_err );
+ die( $log_err );
}else
{
+ //store error in table session[]
$_SESSION['error'] = $log_err;
- //header( 'Location: ' . $accueil );
}
}
+//diplay logs
function affich_log( $nl, $np = 1, $level=0)
{
global $table_prefix, $base_url, $path, $page;
@@ -136,7 +140,7 @@ function affich_log( $nl, $np = 1, $level=0)
echo "\n";
//////////////////////////////////////////////////////////////
- //////////////// affiche page précédente et page suivante
+ //////////////// display next and previous page
if ( $np > 1 )
{
echo 'Page précédente';
@@ -147,7 +151,7 @@ function affich_log( $nl, $np = 1, $level=0)
}
//////////////////////////////////////////////////////////////////
- /////////////////////// affiche les logs dans un tableau
+ /////////////////////// display logs in table
if ($total_lignes != 0 )
{
$query = 'SELECT * FROM ' . $table_prefix . 'logs';
diff --git a/vote.form.php b/vote.form.php
index 4c1cdbe..09cee20 100644
--- a/vote.form.php
+++ b/vote.form.php
@@ -11,9 +11,10 @@ $idVotation = $_GET["v"];
$dolibarr = new dbDolibarr();
-$query = "SELECT * FROM llx_adherent WHERE login='" . $dolibarr->protect($idVotant) . "'";
-
+$query = "SELECT * FROM llx_adherent as a LEFT JOIN llx_adherent_type as t ON a.fk_adherent_type=t.rowid WHERE a.login='" . $dolibarr->protect($idVotant) . "' AND (DATE(a.datefin)>=CURDATE() OR t.subscription=0) AND t.vote=1";
+print $query .EOLH;
$result = $dolibarr->query($query);
+print_r($dolibarr);
$votant = $dolibarr->result->fetch_array();
print('
@@ -29,7 +30,7 @@ print('
"; //$resultatCandidats = ''; + + $query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=0'; + $result = $db->query($query); + $resultat = $db->result->fetch_array(MYSQLI_ASSOC); + $blanc = $resultat["n"]; + echo 'Votes blancs : ' . $blanc . '-
'; foreach($candidats as $candidat) { $query='SELECT COUNT(*) as n FROM votes WHERE idVotation=' . $db->protect($idVotation) . ' AND idVote=' . $vote["id"] .' AND idCandidat=' . $candidat["id"]; @@ -57,17 +64,25 @@ if ( empty($idVotation)) $resultat = $db->result->fetch_array(MYSQLI_ASSOC); echo $candidat["candidat"] . ' :' . $resultat["n"] . '
'; $resultatCandidats[$candidat['candidat']] = $resultat["n"]; + $total += $resultat["n"]; } array_multisort($resultatCandidats, SORT_DESC, SORT_NUMERIC); reset($resultatCandidats); - print("Remporte le vote : " . key($resultatCandidats)); - unset($resultatCandidats); - print "