diff --git a/htdocs/energie/EnergieCompteur.class.php b/htdocs/energie/EnergieCompteur.class.php
new file mode 100644
index 00000000000..ee791a27f5f
--- /dev/null
+++ b/htdocs/energie/EnergieCompteur.class.php
@@ -0,0 +1,207 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ *
+ */
+
+/**
+ \file htdocs/energie/EnergieCompteur.class.php
+ \ingroup energie
+ \brief Fichier des classes de compteur
+ \version $Revision$
+*/
+
+
+/**
+ \class Compteur
+ \brief Classe de gestion des compteurs
+*/
+
+class EnergieCompteur
+{
+ var $db ;
+ var $id ;
+ var $user;
+
+ /** \brief Constructeur
+ */
+ function EnergieCompteur($DB, $user)
+ {
+ $this->db = $DB;
+ $this->user = $user;
+
+ $this->energies[1] = "Electricité";
+ $this->energies[2] = "Eau";
+ $this->energies[3] = "Gaz naturel";
+
+ $this->couleurs[1] = "gray";
+ $this->couleurs[2] = "blue";
+ $this->couleurs[3] = "yellow";
+ }
+
+
+ /**
+ * Lecture
+ *
+ */
+ function fetch ($id)
+ {
+ $sql = "SELECT c.rowid, c.libelle, fk_energie";
+ $sql .= " FROM ".MAIN_DB_PREFIX."energie_compteur as c";
+ $sql .= " WHERE c.rowid = ".$id;
+
+ $resql = $this->db->query($sql) ;
+
+ if ( $resql )
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $this->id = $obj->rowid;
+ $this->libelle = $obj->libelle;
+ $this->energie = $obj->fk_energie;
+ $this->db->free();
+
+ return 0;
+ }
+ else
+ {
+ dolibarr_syslog("");
+ return -1;
+ }
+ }
+
+ /**
+ * Lecture
+ *
+ */
+ function Create ($libelle, $energie)
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."energie_compteur";
+ $sql .= " (libelle, datec, fk_user_author, fk_energie, note)";
+ $sql .= " VALUES (";
+ $sql .= "'".trim($libelle)."'";
+ $sql .= ",now()";
+ $sql .= ",'".$this->user->id."'";
+ $sql .= ",'".$energie."'";
+ $sql .= ",'');";
+
+ $resql = $this->db->query($sql) ;
+
+ if ( $resql )
+ {
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."energie_compteur");
+
+ return 0;
+ }
+ else
+ {
+ dolibarr_syslog("EnergieCompteur::Create Erreur 1");
+ dolibarr_syslog($this->db->error());
+ return -1;
+ }
+ }
+
+ /**
+ * Ajout d'une valeur relevée
+ *
+ */
+ function AjoutReleve ($date_releve, $valeur)
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."energie_compteur_releve";
+ $sql .= " (fk_compteur, date_releve, valeur, datec, fk_user_author)";
+ $sql .= " VALUES (";
+ $sql .= "'".$this->id."'";
+ $sql .= ",'".$this->db->idate($date_releve)."'";
+ $sql .= ",'".$valeur."'";
+ $sql .= ",now()";
+ $sql .= ",'".$this->user->id."');";
+
+ $resql = $this->db->query($sql) ;
+
+ if ( $resql )
+ {
+ return 0;
+ }
+ else
+ {
+ dolibarr_syslog("EnergieCompteur::AjoutReleve Erreur 1");
+ dolibarr_syslog($this->db->error());
+ return -1;
+ }
+ }
+ /**
+ * Ajout d'une valeur relevée
+ *
+ */
+ function AddGroup ($groupe)
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."energie_compteur_groupe";
+ $sql .= " (fk_energie_compteur, fk_energie_groupe)";
+ $sql .= " VALUES ('".$this->id."','".$groupe."');";
+
+ $resql = $this->db->query($sql);
+
+ if ( $resql )
+ {
+ return 0;
+ }
+ else
+ {
+ dolibarr_syslog("EnergieCompteur::AddGroup Erreur 1");
+ dolibarr_syslog($this->db->error());
+ return -1;
+ }
+ }
+ /**
+ *
+ *
+ */
+ function GroupsAvailable ()
+ {
+ $this->groups_available = array();
+
+ $sql = "SELECT g.rowid, g.libelle";
+ $sql .= " FROM ".MAIN_DB_PREFIX."energie_groupe as g";
+
+ $resql = $this->db->query($sql) ;
+
+ if ( $resql )
+ {
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+
+ while ($i < $num)
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $this->groups_available[$obj->rowid] = $obj->libelle;
+ $i++;
+ }
+ $this->db->free();
+
+ return 0;
+ }
+ else
+ {
+ dolibarr_syslog("");
+ return -1;
+ }
+ }
+}
+?>
diff --git a/htdocs/energie/compteur.php b/htdocs/energie/compteur.php
new file mode 100644
index 00000000000..6b9d41e575a
--- /dev/null
+++ b/htdocs/energie/compteur.php
@@ -0,0 +1,227 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ *
+ */
+
+/**
+ \file htdocs/energie/compteur.php
+ \ingroup energie
+ \brief Fiche compteur
+ \version $Revision$
+*/
+
+require("./pre.inc.php");
+
+/*
+ *
+ */
+
+if ($_POST["action"] == 'add')
+{
+ $compteur = new EnergieCompteur($db, $user);
+
+ if ( $compteur->create($_POST["libelle"],$_POST["energie"]) == 0)
+ {
+ Header("Location: compteur.php?id=".$compteur->id);
+ }
+ else
+ {
+ Header("Location: compteur.php?action=create");
+ }
+}
+
+
+if ($_POST["action"] == 'addvalue')
+{
+ if ($_POST["releve"] > 0)
+ {
+ $compteur = new EnergieCompteur($db, $user);
+ if ( $compteur->fetch($_GET["id"]) == 0)
+ {
+ $date = mktime(12,
+ 0 ,
+ 0,
+ $_POST["remonth"],
+ $_POST["reday"],
+ $_POST["reyear"]);
+
+ $compteur->AjoutReleve($date, $_POST["releve"]);
+ Header("Location: compteur.php?id=".$_GET["id"]);
+ }
+ }
+}
+/*
+ *
+ */
+
+llxHeader($langs, '',$langs->trans("Compteur"),"Compteur");
+
+/*********************************************************************
+ *
+ * Mode creation
+ *
+ *
+ ************************************************************************/
+if ($_GET["action"] == 'create')
+{
+ $head[0][0] = DOL_URL_ROOT.'/energie/compteur.php?action=create';
+ $head[0][1] = "Nouveau compteur";
+ $h++;
+ $a = 0;
+
+ dolibarr_fiche_head($head, $a, $soc->nom);
+
+ $html = new Form($db);
+ $compteur = new EnergieCompteur($db, $user);
+
+ print '
";
+ print '';
+
+}
+else
+/* *************************************************************************** */
+/* */
+/* Mode vue */
+/* */
+/* *************************************************************************** */
+{
+ if ($_GET["id"] > 0)
+ {
+ $compteur = new EnergieCompteur($db, $user);
+ if ( $compteur->fetch($_GET["id"]) == 0)
+ {
+
+ $head[0][0] = DOL_URL_ROOT.'/energie/compteur.php?id='.$compteur->id;
+ $head[0][1] = "Compteur";
+ $h++;
+ $a = 0;
+
+ $head[$h][0] = DOL_URL_ROOT.'/energie/compteur_graph.php?id='.$compteur->id;
+ $head[$h][1] = "Graph";
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/energie/compteur_groupe.php?id='.$compteur->id;
+ $head[$h][1] = "Groupe";
+ $h++;
+
+ dolibarr_fiche_head($head, $a, $soc->nom);
+
+
+ print '';
+ print "| ".$langs->trans("Compteur")." | ";
+ print '';
+ print $compteur->libelle;
+ print " |
";
+ print "
";
+
+
+ $html = new Form($db);
+ print '
";
+
+ print '';
+
+
+
+ print '';
+ print '';
+ $file = "week.".$compteur->id.".png";
+ print ' ';
+ print ' | ';
+ $file = "month.".$compteur->id.".png";
+ print ' ';
+ print ' |
';
+
+ print '';
+ print '| '.$langs->trans("Date").' | ';
+ print ''.$langs->trans("Relevé").' |
';
+
+ $sql = "SELECT ".$db->pdate("date_releve")." as date_releve, valeur";
+ $sql .= " FROM ".MAIN_DB_PREFIX."energie_compteur_releve as ecr";
+ $sql .= " WHERE ecr.fk_compteur = '".$compteur->id."'";
+ $sql .= " ORDER BY ecr.date_releve DESC LIMIT 5";
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ $var=True;
+ while ($i < $num)
+ {
+ $obj = $db->fetch_object($resql);
+ $var=!$var;
+ print "| ";
+ print strftime("%a %e %B %Y",$obj->date_releve);
+ print ' | '.$obj->valeur.' | ';
+
+ $i++;
+ }
+ }
+ print '
';
+ print "
\n";
+ }
+ else
+ {
+ /* Commande non trouvée */
+ print "Compteur inexistant";
+ }
+ }
+ else
+ {
+ print "Compteur inexistant";
+ }
+}
+
+$db->close();
+
+llxFooter("Dernière modification $Date$ révision $Revision$");
+?>
diff --git a/htdocs/energie/compteur_groupe.php b/htdocs/energie/compteur_groupe.php
new file mode 100644
index 00000000000..0bcf01f9754
--- /dev/null
+++ b/htdocs/energie/compteur_groupe.php
@@ -0,0 +1,114 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ *
+ */
+
+/**
+ \file htdocs/energie/compteur_groupe.php
+ \ingroup energie
+ \brief Fiche de gestion des groupes des compteurs
+ \version $Revision$
+*/
+
+require("./pre.inc.php");
+
+
+if ($_POST["action"] == 'addvalue')
+{
+ $compteur = new EnergieCompteur($db, $user);
+ if ( $compteur->fetch($_GET["id"]) == 0)
+ {
+ if ( $compteur->AddGroup($_POST["groupe"]) == 0)
+ {
+ Header("Location: compteur.php?id=".$_GET["id"]);
+ }
+ }
+}
+/*
+ *
+ */
+
+llxHeader($langs, '',$langs->trans("Compteur"),"Compteur");
+
+if ($_GET["id"] > 0)
+{
+ $compteur = new EnergieCompteur($db, $user);
+ if ( $compteur->fetch($_GET["id"]) == 0)
+ {
+
+ $head[0][0] = DOL_URL_ROOT.'/energie/compteur.php?id='.$compteur->id;
+ $head[0][1] = "Compteur";
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/energie/compteur_graph.php?id='.$compteur->id;
+ $head[$h][1] = "Graph";
+ $h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/energie/compteur_groupe.php?id='.$compteur->id;
+ $head[$h][1] = "Groupe";
+ $h++;
+ $a = 2;
+
+
+ dolibarr_fiche_head($head, $a, $soc->nom);
+
+
+ print '';
+ print "| ".$langs->trans("Compteur")." | ";
+ print '';
+ print $compteur->libelle;
+ print " |
";
+ print "
";
+
+ $html = new Form($db);
+ print '
";
+ print '';
+ print "
\n";
+ }
+ else
+ {
+ /* Commande non trouvée */
+ print "Compteur inexistant";
+ }
+}
+else
+{
+ print "Compteur inexistant";
+}
+
+$db->close();
+
+llxFooter("Dernière modification $Date$ révision $Revision$");
+?>
diff --git a/htdocs/energie/groupe.php b/htdocs/energie/groupe.php
new file mode 100644
index 00000000000..92ba9e6350e
--- /dev/null
+++ b/htdocs/energie/groupe.php
@@ -0,0 +1,157 @@
+
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Id$
+ * $Source$
+ *
+ */
+
+/**
+ \file htdocs/energie/groupe.php
+ \ingroup energie
+ \brief Fiche groupe
+ \version $Revision$
+*/
+
+require("./pre.inc.php");
+
+/*
+ *
+ */
+
+if ($_POST["action"] == 'add')
+{
+ $groupe = new EnergieGroupe($db, $user);
+
+ if ( $groupe->create($_POST["libelle"]) == 0)
+ {
+ Header("Location: groupe.php?id=".$groupe->id);
+ }
+ else
+ {
+ Header("Location: groupe.php?action=create");
+ }
+}
+
+/*
+ *
+ */
+
+llxHeader($langs, '',$langs->trans("Groupe"),"Groupe");
+
+/*********************************************************************
+ *
+ * Mode creation
+ *
+ *
+ ************************************************************************/
+if ($_GET["action"] == 'create')
+{
+ $head[0][0] = DOL_URL_ROOT.'/energie/groupe.php?action=create';
+ $head[0][1] = "Nouveau groupe";
+ $h++;
+ $a = 0;
+
+ dolibarr_fiche_head($head, $a, $soc->nom);
+
+ $html = new Form($db);
+
+ print '
";
+
+ print '';
+
+}
+else
+/* *************************************************************************** */
+/* */
+/* Mode vue */
+/* */
+/* *************************************************************************** */
+{
+ if ($_GET["id"] > 0)
+ {
+ $groupe = new EnergieGroupe($db, $user);
+ if ( $groupe->fetch($_GET["id"]) == 0)
+ {
+
+ $head[0][0] = DOL_URL_ROOT.'/energie/groupe.php?id='.$commande->id;
+ $head[0][1] = "Groupe";
+ $h++;
+ $a = 0;
+
+ dolibarr_fiche_head($head, $a, $soc->nom);
+
+ print '';
+ print "| ".$langs->trans("Groupe")." | ";
+ print '';
+ print $groupe->libelle;
+ print " |
";
+ print "
";
+
+ /*
+ *
+ */
+
+
+ print '';
+
+ print '';
+ $file = "groupe.day.".$groupe->id.".png";
+ print ' ';
+ print ' | ';
+ $file = "groupe.week.".$groupe->id.".png";
+ print ' ';
+ print ' |
';
+
+ print '';
+ $file = "groupe.month.".$groupe->id.".png";
+ print ' ';
+ print ' | ';
+ $file = "groupe.year.".$groupe->id.".png";
+ print ' ';
+ print ' |
';
+
+ print '';
+ print "
\n";
+ }
+ else
+ {
+ /* Commande non trouvée */
+ print "Groupe inexistant";
+ }
+ }
+ else
+ {
+ print "Groupe inexistant";
+ }
+}
+
+$db->close();
+
+llxFooter("Dernière modification $Date$ révision $Revision$");
+?>