premier commit
This commit is contained in:
parent
fe05b7898f
commit
fa971dc6a0
|
@ -0,0 +1,3 @@
|
|||
[Project]
|
||||
Name=atelier
|
||||
Manager=KDevGenericManager
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
require_once("session_init.php");
|
||||
require_once("config.inc.php");
|
||||
require_once("recap.php");
|
||||
|
||||
recap();
|
||||
?>
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
<?php
|
||||
|
||||
date_default_timezone_set("Europe/Paris");
|
||||
|
||||
define( 'EOL', "\n");
|
||||
define( 'TAB', "\t");
|
||||
|
||||
//constantes des niveaux de log
|
||||
define( "INFO", 1);
|
||||
define( "ALERT", 2);
|
||||
define( "ERROR", 3);
|
||||
|
||||
?>
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
require_once("log.php");
|
||||
|
||||
function esp( $s )
|
||||
{
|
||||
return " " . $s . " ";
|
||||
}
|
||||
|
||||
class db
|
||||
{
|
||||
private $server = "localhost";
|
||||
private $port = 3306;
|
||||
private $user = "root";
|
||||
private $passwd = "Lalis_toor";
|
||||
public $database;
|
||||
public $connect;
|
||||
public $result;
|
||||
|
||||
function __construct($database)
|
||||
{
|
||||
$this->database = $database;
|
||||
$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__ . esp( 'ligne' ) . __line__, false, true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function close()
|
||||
{
|
||||
$this->connect->close();
|
||||
$this->connect = 0;
|
||||
}
|
||||
|
||||
function query( $string )
|
||||
{
|
||||
if ( empty( $this->connect ) ) $this->open();
|
||||
|
||||
$this->result = $this->connect->query( $string ) ;
|
||||
if ( $this->connect->error ) log_error( "Échec de la commande query" . " => ". $this->connect->error . "<br />" . __file__ . esp( 'ligne' ) . __line__ . "\n" . $string, false, true );
|
||||
}
|
||||
|
||||
function error()
|
||||
{
|
||||
print_r( $this );
|
||||
$this->error = $this->error;
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
$webmaster= "contact@lalis.fr";
|
||||
$headers = "From: contact@lalis.fr\n";
|
||||
$headers .= "MIME-Version: 1.0\n";
|
||||
$headers .= "Content-type: text/plain; charset=UTF-8\n";
|
||||
$headers .= "DATE: " . date( 'r' ) . "\n";
|
||||
?>
|
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
/*if ( !isset($site) )
|
||||
{
|
||||
require_once( "config.inc.php" );
|
||||
header( 'Location: ' . $accueil );
|
||||
}*/
|
||||
require_once( "db.class.php" );
|
||||
require_once( "entete_mail.php" );
|
||||
|
||||
// $level => INFO, ALERT, ERROR
|
||||
function log_write($log, $level=INFO)
|
||||
{
|
||||
global $table_prefix, $webmaster, $headers;
|
||||
$user = ( !empty( $_SERVER["PHP_AUTH_USER"])?$_SERVER["PHP_AUTH_USER"]:'' );
|
||||
$log_mail = str_replace ( "<br />", "\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":'' );
|
||||
$log_mail .= ( !empty( $_SERVER["HTTP_ACCEPT_LANGUAGE"])?'$_SERVER["HTTP_ACCEPT_LANGUAGE"]' . $_SERVER["HTTP_ACCEPT_LANGUAGE"] . "\n":'' );
|
||||
$log_mail .= ( !empty( $_SERVER["HTTP_USER_AGENT"])?'$_SERVER["HTTP_USER_AGENT"]' . $_SERVER["HTTP_USER_AGENT"] . "\n":'' );
|
||||
$log_mail .= ( !empty( $_SERVER["REMOTE_ADDR"])?'$_SERVER["REMOTE_ADDR"]' . $_SERVER["REMOTE_ADDR"] . "\n":'' );
|
||||
$log_mail .= ( !empty( $_SERVER["REMOTE_HOST"])?'$_SERVER["REMOTE_HOST"]' . $_SERVER["REMOTE_HOST"] . "\n":'' );
|
||||
$log_mail .= ( !empty( $_SERVER["REMOTE_USER"])?'$_SERVER["REMOTE_USER"]' . $_SERVER["REMOTE_USER"] . "\n":'' );
|
||||
$log_mail .= ( !empty( $_SERVER["REQUEST_URI"])?'$_SERVER["REQUEST_URI"]' . $_SERVER["REQUEST_URI"] . "\n":'' );
|
||||
$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":'' );
|
||||
$db1 = new db('log');
|
||||
$db1->open();
|
||||
if( !empty( $db1->connect ) )
|
||||
{
|
||||
$query = 'INSERT INTO ' . $table_prefix . 'logs SET date=NOW(), auteur="' . $db1->protect( $user ) . '", log="' . $db1->protect($log) . '", niveau="' . $level . '"';
|
||||
$db1->query( $query );
|
||||
if ( !$db1->result )
|
||||
{
|
||||
$text = $db1->error() . "\n\n" . $log_mail;
|
||||
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__, $text, $headers );
|
||||
}
|
||||
$db1->close();
|
||||
}else
|
||||
{
|
||||
echo $db1->error();
|
||||
mail( $webmaster, "Erreur écriture logs => " . __file__ . " ligne " . __line__ , $log_mail, $headers );
|
||||
}
|
||||
if ( $level == ALERT )
|
||||
{
|
||||
mail( $webmaster, "Alerte Site Web", $log_mail, $headers );
|
||||
}elseif ( $level == ERROR )
|
||||
{
|
||||
mail( $webmaster, "Erreur Site Web", $log_mail, $headers );
|
||||
}
|
||||
}
|
||||
|
||||
// $db = true -> écrire les logs dans la base (défaut)
|
||||
// $die = true -> execute die()
|
||||
function log_error($log, $w_db=true, $die=false)
|
||||
{
|
||||
global $webmaster, $headers, $accueil, $db;
|
||||
if ( $w_db ) log_write($log, ERROR);
|
||||
echo "$log<br />\n";
|
||||
$log_err = 'erreur dans la requête<br/>un rapport détaillé a été envoyé au webmaster';
|
||||
if ( $die )
|
||||
{
|
||||
echo "\n";
|
||||
die( $log_err );
|
||||
}else
|
||||
{
|
||||
$_SESSION['error'] = $log_err;
|
||||
//header( 'Location: ' . $accueil );
|
||||
}
|
||||
}
|
||||
|
||||
function affich_log( $nl, $np = 1, $level=INFO )
|
||||
{
|
||||
global $table_prefix, $webmaster, $headers, $base_url , $path , $page;
|
||||
if( !empty( $db->open() ) )
|
||||
{
|
||||
$level_s = array( "aucune" , "info" , "alerte" , "erreur" );
|
||||
$query = 'SELECT * FROM ' . $table_prefix . 'logs';
|
||||
if ( $level != 0 )
|
||||
{
|
||||
$query .= " WHERE niveau='" . $level . "'";
|
||||
}
|
||||
$db->query($query) OR log_error($db->error() . "<br />" . __file__ . " ligne " . __line__ );
|
||||
$total_lignes = $db->result->num_rows();
|
||||
if ($total_lignes != 0 )
|
||||
{
|
||||
|
||||
$n_pages = round( $total_lignes / $nl ) +1;
|
||||
|
||||
if ( $np == 0 )
|
||||
{
|
||||
$np = 1;
|
||||
}elseif ( $np > $n_pages )
|
||||
{
|
||||
$np = $n_pages;
|
||||
}
|
||||
echo '<table><tr>';
|
||||
if ( $np > 1 )
|
||||
{
|
||||
echo '<td><a href="logs.php?np=' . ($np - 1) . '">Page précédente</a></td><td>';
|
||||
}
|
||||
echo "\n" . '<form action="none" method="post" enctype="multipart/form-data">';
|
||||
echo 'Page n° <select id="np" name="np" size="0" onchange="window.location.href = \'logs.php?np=\' + document.getElementById(\'np\').value + \'&level=\' + document.getElementById(\'level\').value ;">';
|
||||
for ( $n = 1; $n<= $n_pages; $n++ )
|
||||
{
|
||||
echo '<option value="' . $n . '"';
|
||||
if ( $n == $np )
|
||||
{
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>' . $n . '</option>';
|
||||
}
|
||||
|
||||
echo '</select><noscript><input type="submit" name="submit" Value="none" /></noscript>';
|
||||
echo "</form>\n</td>";
|
||||
if ( $np < $n_pages )
|
||||
{
|
||||
echo '<td><a href="logs.php?np=' . ($np + 1) . '">Page suivante</a></td>';
|
||||
}
|
||||
echo "\n<td>" . '<form action="none" method="post" enctype="multipart/form-data">';
|
||||
echo "niveau de log" . ' <select id="level" size="0" onchange="window.location.href = \'logs.php?np=\' + document.getElementById(\'np\').value + \'&level=\' + document.getElementById(\'level\').value ;">';
|
||||
for ( $n = 0; $n <= count( $level_s ) - 1; $n++ )
|
||||
{
|
||||
echo '<option value="' . $n . '"';
|
||||
if ( $n == $level )
|
||||
{
|
||||
echo ' selected="selected"';
|
||||
}
|
||||
echo '>' . $level_s[ $n ] . '</option>';
|
||||
}
|
||||
|
||||
echo '</select><noscript><input type="submit" name="submit" Value="Envoyer" /></noscript>';
|
||||
echo "</form>\n</td></tr>";
|
||||
$query = 'SELECT * FROM ' . $table_prefix . 'logs';
|
||||
if ( $level != 0 )
|
||||
{
|
||||
$query .= " WHERE niveau='" . $level . "'";
|
||||
}
|
||||
|
||||
$query .= ' ORDER BY date DESC LIMIT ' . ( ( ( $np - 1 ) * $nl ) ) . ',' . $nl;
|
||||
$db->query( $query ) OR log_error( $db->error( ) . "<br />" . __file__ . " ligne " . __line__ );
|
||||
echo "<table border='1' width='90%'><tr><td><b>date</b></td><td><b>auteur</b></td><td><b>log</b></td><td><b>niveau</b></td></tr>\n";
|
||||
while ( $db->connect->mysqli_fetch_array( $db->result ) )
|
||||
{
|
||||
$niveau = $donnees["niveau"];
|
||||
echo "<tr><td>" . $donnees["date"] . "</td><td>" . $donnees["auteur"] . "</td><td>" . $donnees["log"] . "</td><td>" . $level_s[ $niveau ] . "</td></tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
}else
|
||||
{
|
||||
"aucune réponse";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
require_once( "db.class.php" );
|
||||
function recap()
|
||||
{
|
||||
$db = new db("dolibarr");
|
||||
$db2= new db("dolibarr");
|
||||
$query = "SELECT * FROM llx_opensurvey_sondage WHERE status='1' ORDER BY date_fin";
|
||||
$db->query($query);
|
||||
while( $sondage = $db->result->fetch_array() )
|
||||
{
|
||||
// tri des résultats des sondages
|
||||
//print_r($sondage);
|
||||
$tab =array();
|
||||
$nom_atelier = explode( ",", $sondage["sujet"] );
|
||||
$query = "SELECT * FROM llx_opensurvey_user_studs WHERE id_sondage='" . $sondage["id_sondage"] . "'";
|
||||
$id = $sondage["id_sondage"];
|
||||
$db2->query($query);
|
||||
while( $reponse = $db2->result->fetch_array() )
|
||||
{
|
||||
|
||||
$r = str_split( $reponse["reponses"] );
|
||||
$l = count( $r );
|
||||
for ($x=0; $x<$l; $x++)
|
||||
{
|
||||
if ( !isset($tab[$x]) )
|
||||
{
|
||||
$tab[$x] = 0;
|
||||
}
|
||||
$tab[$x] += $r[$x];
|
||||
}
|
||||
}
|
||||
$resultat[$id]["titre"] = $sondage["titre"] . "\n";
|
||||
$resultat[$id]["nom_atelier"] = $nom_atelier;
|
||||
arsort($tab);
|
||||
$x = 0;
|
||||
$resultat[$id]["reponse"][$x] = key($tab);
|
||||
$value = current($tab);
|
||||
echo $resultat[$id]["titre"];
|
||||
while ($r = next($tab))
|
||||
{
|
||||
echo $value . "====>>>" . $r . "\n";
|
||||
if ( ($r == $value) )
|
||||
{
|
||||
$x++;
|
||||
$resultat[$id]["reponse"][$x] = key($tab);
|
||||
}else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
print_r($resultat);
|
||||
|
||||
foreach( $resultat as $resume)
|
||||
{
|
||||
echo $resume["titre"] . "\n";
|
||||
foreach( $resume["reponse"] as $atelier )
|
||||
{
|
||||
echo "\t" . strstr( $resume["nom_atelier"][$atelier] ) . "\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
set_include_path ("include/")
|
||||
?>
|
Reference in New Issue