commit initial mw_actions_logs.0.1
authordj3c1t <dj3c1t@free.fr>
Mon, 20 May 2013 19:05:00 +0000 (21:05 +0200)
committerdj3c1t <dj3c1t@free.fr>
Mon, 20 May 2013 19:05:00 +0000 (21:05 +0200)
app/data/modules/sql/mw_data_actions_logs.php [new file with mode: 0644]
app/mods/admin/actions_logs.php [new file with mode: 0644]
app/observers/mw_observer_actions_logs.php [new file with mode: 0644]
app/out/default/css/actions/admin_actions_logs.css [new file with mode: 0644]
app/out/default/js/actions/admin_actions_logs.js [new file with mode: 0644]
app/out/default/layouts/admin.xml [new file with mode: 0644]
app/out/default/views/admin/actions_logs/config.php [new file with mode: 0644]
app/out/default/views/admin/actions_logs/edit_log_action.php [new file with mode: 0644]
app/out/default/views/admin/actions_logs/historique.php [new file with mode: 0644]
app/out/default/views/admin/actions_logs/logs_actions.php [new file with mode: 0644]
mw_actions_logs.php [new file with mode: 0644]

diff --git a/app/data/modules/sql/mw_data_actions_logs.php b/app/data/modules/sql/mw_data_actions_logs.php
new file mode 100644 (file)
index 0000000..2a7902e
--- /dev/null
@@ -0,0 +1,97 @@
+<?php
+
+  class mw_data_actions_logs extends mw_data{
+
+    // ------------------------------------------------------------------------------------
+    //                                                                               config
+    //
+
+    function get_actions_logs_config(){
+      $env = $this->env();
+      return array(
+        "do_log" => $env->config("actions_logs_do_log") ? true : false,
+        "default_log" => $env->config("actions_logs_default_log") ? true : false,
+        "default_log_get" => $env->config("actions_logs_default_log_get") ? true : false,
+        "default_log_post" => $env->config("actions_logs_default_log_post") ? true : false
+      );
+    }
+
+    function set_actions_logs_config($params = array()){
+      if(isset($params["do_log"])){
+        if(!$this->set_config("actions_logs_do_log", $params["do_log"] ? 1 : 0)){
+          return false;
+        }
+      }
+      if(isset($params["default_log"])){
+        if(!$this->set_config("actions_logs_default_log", $params["default_log"] ? 1 : 0)){
+          return false;
+        }
+      }
+      if(isset($params["default_log_get"])){
+        if(!$this->set_config("actions_logs_default_log_get", $params["default_log_get"] ? 1 : 0)){
+          return false;
+        }
+      }
+      if(isset($params["default_log_post"])){
+        if(!$this->set_config("actions_logs_default_log_post", $params["default_log_post"] ? 1 : 0)){
+          return false;
+        }
+      }
+      return true;
+    }
+
+    // ------------------------------------------------------------------------------------
+    //                                                                              actions
+    //
+
+    function clear_logs_actions(){
+      $sgbd = $this->sgbd();
+      try{
+        $sgbd->query("DELETE FROM #--logs_actions");
+      }
+      catch(Exception $e) { return false; }
+      return true;
+    }
+
+    // ------------------------------------------------------------------------------------
+    //                                                                                 logs
+    //
+
+    function add_action_log($params = array()){
+      $env = $this->env();
+      $sgbd = $this->sgbd();
+      $log = array();
+      $log["action"] = isset($params["action"]) ? $params["action"] : $env->etat("mod")."/".$env->etat("controlleur")."/".$env->etat("action");
+      $user = $env->user();
+      $log["login"] = isset($params["login"]) ? $params["login"] : ($user ? $user["login"] : "");
+      $log["get"] = isset($params["get"]) ? $params["get"] : null;
+      $log["post"] = isset($params["post"]) ? $params["post"] : null;
+      $log["from_ip"] = isset($params["from_ip"]) ? $params["from_ip"] : (isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : "");
+      try{
+        $sql =
+         "INSERT INTO #--actions_logs(`action`, `date_log`, `login`, `from_ip`, `get`, `post`) VALUES("
+        ."  ".$this->eq($log["action"])
+        .", NOW()"
+        .", ".$this->eq($log["login"])
+        .", ".$this->eq($log["from_ip"])
+        .", ".$this->eq($log["get"])
+        .", ".$this->eq($log["post"])
+        .")";
+        $sgbd->query($sql);
+      }
+      catch(Exception $e){ return false; }
+      return true;
+    }
+
+    function clear_actions_logs(){
+      $sgbd = $this->sgbd();
+      try{
+        $sgbd->query("DELETE FROM #--actions_logs");
+      }
+      catch(Exception $e){ return false; }
+      return true;
+    }
+
+  }
+
+?>
\ No newline at end of file
diff --git a/app/mods/admin/actions_logs.php b/app/mods/admin/actions_logs.php
new file mode 100644 (file)
index 0000000..bdf25c1
--- /dev/null
@@ -0,0 +1,177 @@
+<?php
+
+  class mw_admin_actions_logs extends mw_mod{
+
+    function index(&$env){
+      $env->run("admin/actions_logs/historique");
+    }
+
+    function historique(&$env){
+      $env->set_config(array("max_list" => 20));
+      $data = $env->data();
+      if(
+        (
+          $historique = $data->list_actions_logs(
+            array(
+              "index_name" => "id",
+              "order_by" => "date_log",
+              "order" => "DESC",
+              "offset" => isset($_GET[$env->param("start")]) ? $_GET[$env->param("start")] : 0,
+              "limit" => $env->config("max_list") ? $env->config("max_list") : null
+            )
+          )
+        ) === false
+      ){
+        $env->erreur("impossible de lire l'historique des logs");
+        return;
+      }
+      foreach($historique["list"] as $id_log => $log){
+        $historique["list"][$id_log]["get"] = $log["get"] ? @unserialize($log["get"]) : false;
+        $historique["list"][$id_log]["post"] = $log["post"] ? @unserialize($log["post"]) : false;
+      }
+      $env->set_out("historique", $historique);
+    }
+
+    function del_historique(&$env){
+      $data = $env->data();
+      if(!$data->clear_actions_logs()){
+        $env->erreur("impossible de vider l'historique");
+        return;
+      }
+      $env->redirect(
+        $env->url("admin/actions_logs/historique"),
+        "l'historique a été vidé"
+      );
+    }
+
+    function config(&$env){
+      $data = $env->data();
+      if(($actions_logs_config = $data->get_actions_logs_config()) === false){
+        $env->erreur("impossible de lire la configuration");
+        return;
+      }
+      if($_POST){
+        $actions_logs_config["do_log"] = isset($_POST["do_log"]) ? true : false;
+        $actions_logs_config["default_log"] = ($_POST["default_log"] == "1") ? true : false;
+        $actions_logs_config["default_log_get"] = isset($_POST["default_log_get"]) ? true : false;
+        $actions_logs_config["default_log_post"] = isset($_POST["default_log_post"]) ? true : false;
+        if(!$data->set_actions_logs_config($actions_logs_config)){
+          $env->erreur("erreur lors de la mise à jour de la configuration");
+          return;
+        }
+        $env->redirect(
+          $env->url("admin/actions_logs/config"),
+          "la configuration a été mise à jour"
+        );
+      }
+      $env->set_out("actions_logs_config", $actions_logs_config);
+    }
+
+    function logs_actions(&$env){
+      $data = $env->data();
+      if(($actions_logs_config = $data->get_actions_logs_config()) === false){
+        $env->erreur("impossible de lire la configuration");
+        return;
+      }
+      if(($logs_actions = $data->list_logs_actions(array("index_name" => "id", "order_by" => "action"))) === false){
+        $env->erreur("impossible de lire la table #--logs_actions");
+        return;
+      }
+      if($_POST){
+        foreach($_POST as $key => $value){
+          if(substr($key, 0, 14) == "id_log_action_"){
+            $id_log_action = $value;
+            $log_action = array(
+              "log_get" => isset($_POST["log_get_".$id_log_action]) ? 1 : 0,
+              "log_post" => isset($_POST["log_post_".$id_log_action]) ? 1 : 0
+            );
+            if(!$data->set_logs_actions("id", $id_log_action, $log_action)){
+              $env->erreur("erreur lors de l'enregistrement des informations pour les actions");
+              return;
+            }
+          }
+        }
+        $env->redirect(
+          $env->url("admin/actions_logs/logs_actions"),
+          "Les informations ont été enregistrées"
+        );
+      }
+      $env->set_out("actions_logs_config", $actions_logs_config);
+      $env->set_out("logs_actions", $logs_actions);
+    }
+
+    function add_log_action(&$env){
+      $data = $env->data();
+      if(($actions_logs_config = $data->get_actions_logs_config()) === false){
+        $env->erreur("impossible de lire la configuration");
+        return;
+      }
+      $log_action = array(
+        "action" => "",
+        "log_get" => false,
+        "log_post" => false
+      );
+      if($_POST){
+        if($_POST["action"]){
+          if($etat = $env->valid_etat($_POST["action"])){
+            $action = $etat["mod"]."/".$etat["controller"]."/".$etat["action"];
+            if(($exists = $data->get_logs_actions("action", $action)) === false){
+              $env->erreur("impossible de savoir si cette action est déjà dans la liste");
+              return;
+            }
+            if($exists) $env->message("l'action ".$action." est déjà dans la liste");
+            $log_action["action"] = $action;
+          }
+          else $env->message("format d'action invalide");
+        }
+        else $env->message("merci de préciser une action");
+        $log_action["log_get"] = isset($_POST["log_get"]) ? true : false;
+        $log_action["log_post"] = isset($_POST["log_post"]) ? true : false;
+        if(!$env->messages()){
+          if($data->add_logs_actions($log_action)){
+            $env->redirect(
+              $env->url("admin/actions_logs/logs_actions"),
+              "L'action a été ajoutée dans la liste"
+            );
+          }
+          else{
+            $env->erreur("impossible d'ajouter l'action dans la liste");
+            return;
+          }
+        }
+      }
+      $env->set_out("actions_logs_config", $actions_logs_config);
+      $env->set_out("log_action", $log_action);
+    }
+
+    function del_log_action(&$env){
+      $data = $env->data();
+      if(!($log_action = $data->get_logs_actions("id", $_GET[$env->param("id")]))){
+        $env->erreur("impossible de lire les informations de cette action dans la liste");
+        return;
+      }
+      if(!$data->del_logs_actions("id", $log_action["id"])){
+        $env->erreur("impossible d'effacer cette action de la liste");
+        return;
+      }
+      $env->redirect(
+        $env->url("admin/actions_logs/logs_actions"),
+        "l'action a été retirée de la liste"
+      );
+    }
+
+    function del_logs_actions(&$env){
+      $data = $env->data();
+      if(!$data->clear_logs_actions()){
+        $env->erreur("impossible de vider la liste");
+        return;
+      }
+      $env->redirect(
+        $env->url("admin/actions_logs/logs_actions"),
+        "la liste a été vidée"
+      );
+    }
+
+  }
+
+?>
\ No newline at end of file
diff --git a/app/observers/mw_observer_actions_logs.php b/app/observers/mw_observer_actions_logs.php
new file mode 100644 (file)
index 0000000..be84c64
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+  class mw_observer_actions_logs{
+
+    var $config;
+
+    function init_actions_logs(&$env){
+      $data = $env->data();
+      if(($this->config = $data->get_actions_logs_config()) === false) return false;
+      return true;
+    }
+
+    function before_action(&$env){
+      $data = $env->data();
+      $user = $env->user();
+      if(!isset($this->config)) $this->init_actions_logs($env);
+      if($this->config && $this->config["do_log"]){
+        if(($logs_actions = $data->list_logs_actions(array("index_name" => "action"))) !== false){
+          $logs_actions = $logs_actions["list"];
+        }
+        else return;
+        $log = false;
+        $current_action = $env->etat("mod")."/".$env->etat("controller")."/".$env->etat("action");
+        if($this->config["default_log"]){
+          if(!isset($logs_actions[$current_action])){
+            $log = array(
+              "action" => $current_action,
+              "login" => $user ? $user["login"] : "",
+              "from_ip" => isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : "",
+              "get" => $this->config["default_log_get"] ? serialize($_GET) : null,
+              "post" => $this->config["default_log_post"] ? serialize($_POST) : null
+            );
+          }
+        }
+        else{
+          if(isset($logs_actions[$current_action])){
+            $log = array(
+              "action" => $current_action,
+              "login" => $user ? $user["login"] : "",
+              "from_ip" => isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : "",
+              "get" => $logs_actions[$current_action]["log_get"] ? serialize($_GET) : null,
+              "post" => $logs_actions[$current_action]["log_post"] ? serialize($_POST) : null
+            );
+          }
+        }
+        if($log) $data->add_action_log($log);
+      }
+    }
+
+    function after_action(&$env){
+    }
+
+  }
+
+?>
\ No newline at end of file
diff --git a/app/out/default/css/actions/admin_actions_logs.css b/app/out/default/css/actions/admin_actions_logs.css
new file mode 100644 (file)
index 0000000..fa412bd
--- /dev/null
@@ -0,0 +1,42 @@
+#default_log_params{
+  margin: 10px;
+}
+
+td.small{
+  font-size: 0.8em;
+}
+
+.log_params_td{
+  position: relative;
+  width: 65px;
+  text-align: center;
+}
+
+.see_get_content{
+  z-index: 1;
+}
+
+.log_params_content{
+  display: none;
+  position: absolute;
+  border: solid 1px #e5e5e5;
+  box-shadow: 0 0 5px #e5e5e5;
+  background-color: #ffffff;
+  padding: 10px;
+  right: 0;
+  top: 100%;
+  z-index: 2;
+}
+table.admin .log_params_content tr th{
+  font-weight: bold;
+  text-align: right;
+  border-right: solid 1px #e5e5e5;
+}
+.log_params_content td{
+  white-space: nowrap;
+}
+
+table.admin .log_params_content tr td{
+  border: none;
+  text-align: left;
+}
diff --git a/app/out/default/js/actions/admin_actions_logs.js b/app/out/default/js/actions/admin_actions_logs.js
new file mode 100644 (file)
index 0000000..a7a2642
--- /dev/null
@@ -0,0 +1,39 @@
+$(document).ready(
+  function(){
+    init_actions_logs_config();
+  }
+);
+
+function init_actions_logs_config(){
+  $(".see_get_content").click(
+    function(){
+      var id_log = $(this).attr("id").substring(16);
+      $("#get_content_" + id_log).toggle();
+      var a_text = $(this).html();
+      if(a_text == "voir" || a_text == "masquer"){
+        $(this).html(a_text == "voir" ? "masquer" : "voir");
+      }
+    }
+  );
+  $(".see_post_content").click(
+    function(){
+      var id_log = $(this).attr("id").substring(17);
+      $("#post_content_" + id_log).toggle();
+      var a_text = $(this).html();
+      if(a_text == "voir" || a_text == "masquer"){
+        $(this).html(a_text == "voir" ? "masquer" : "voir");
+      }
+      return false;
+    }
+  );
+  $(".default_log_input").click(
+    function(){
+      if($(this).val() == 1){
+        $("#default_log_params").slideDown(200);
+      }
+      else{
+        $("#default_log_params").slideUp(200);
+      }
+    }
+  );
+}
diff --git a/app/out/default/layouts/admin.xml b/app/out/default/layouts/admin.xml
new file mode 100644 (file)
index 0000000..78027d6
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<layout>
+
+  <admin page="admin.php">
+    <actions_logs>
+      <historique content="views/admin/actions_logs/historique.php" />
+      <config content="views/admin/actions_logs/config.php" />
+      <logs_actions content="views/admin/actions_logs/logs_actions.php" />
+      <add_log_action content="views/admin/actions_logs/edit_log_action.php" />
+    </actions_logs>
+  </admin>
+
+</layout>
\ No newline at end of file
diff --git a/app/out/default/views/admin/actions_logs/config.php b/app/out/default/views/admin/actions_logs/config.php
new file mode 100644 (file)
index 0000000..c984edd
--- /dev/null
@@ -0,0 +1,34 @@
+<h2>Configuration des logs</h2>
+
+<form name="config_form" action="<?php echo $this->url("admin/actions_logs/config"); ?>" method="post">
+
+  <fieldset>
+    <ul>
+      <li>
+        <label for="do_log">Enregistrement</label>
+        <div class="form_input">
+          <input type="checkbox" name="do_log" <?php echo $this->out["actions_logs_config"]["do_log"] ? "checked" : ""; ?>/> Activer l'enregistrement des logs
+        </div>
+      </li>
+      <li>
+        <label for="default_log">Pour chaque action</label>
+        <div class="form_input">
+          <input class="default_log_input" type="radio" name="default_log" id="default_log" value="0" <?php echo $this->out["actions_logs_config"]["default_log"] ? "" : "checked"; ?>/>
+          Ne pas enregistrer, sauf si l'action est dans <a href="<?php echo $this->url("admin/actions_logs/logs_actions"); ?>"><strong>la liste</strong></a>.<br />
+          <input class="default_log_input" type="radio" name="default_log" id="default_log" value="1" <?php echo $this->out["actions_logs_config"]["default_log"] ? "checked" : ""; ?>/>
+          Enregistrer, sauf si l'action est dans <a href="<?php echo $this->url("admin/actions_logs/logs_actions"); ?>"><strong>la liste</strong></a>.
+          <div id="default_log_params" <?php echo $this->out["actions_logs_config"]["default_log"] ? "" : "style=\"display: none\""; ?>>
+            <input type="checkbox" name="default_log_get" <?php echo $this->out["actions_logs_config"]["default_log_get"] ? "checked" : ""; ?>/> Enregistrer les paramètres GET<br />
+            <input type="checkbox" name="default_log_post" <?php echo $this->out["actions_logs_config"]["default_log_post"] ? "checked" : ""; ?>/> Enregistrer les paramètres POST
+          </div>
+        </div>
+      </li>
+      <li>
+        <div class="form_buttons">
+          <input type="submit" value="Enregistrer" />
+        </div>
+      </li>
+    </ul>
+  </fieldset>
+
+</form>
diff --git a/app/out/default/views/admin/actions_logs/edit_log_action.php b/app/out/default/views/admin/actions_logs/edit_log_action.php
new file mode 100644 (file)
index 0000000..ab2da8a
--- /dev/null
@@ -0,0 +1,41 @@
+<h2>Ajouter une action dans la liste</h2>
+
+<ul class="buttons">
+  <li><a href="<?php echo $this->url("admin/actions_logs/logs_actions"); ?>">Retour &agrave; la liste des actions</a></li>
+</ul>
+
+<form name="log_action_form" action="<?php echo $this->url("admin/actions_logs/add_log_action"); ?>" method="post">
+  <fieldset>
+    <ul>
+      <li>
+        <label for="action">Action</label>
+        <div class="form_input">
+          <p class="info">au format module/controleur/action</p>
+          <input type="text" size="45" name="action" id="action" value="<?php echo $this->out["log_action"]["action"]; ?>" />
+        </div>
+      </li>
+      <?php if(!$this->out["actions_logs_config"]["default_log"]) : ?>
+      <li>
+        <label>Paramètres</label>
+        <div class="form_input">
+          <ul>
+            <li>
+              <input type="checkbox" name="log_get" <?php echo $this->out["log_action"]["log_get"] ? "checked" : ""; ?> />
+              Enregistrer les paramètres GET
+            </li>
+            <li>
+              <input type="checkbox" name="log_post" <?php echo $this->out["log_action"]["log_post"] ? "checked" : ""; ?> />
+              Enregistrer les paramètres POST
+            </li>
+          </ul>
+        </div>
+      </li>
+      <?php endif; ?>
+      <li>
+        <div class="form_buttons">
+          <input type="submit" value="Ajouter" />
+        </div>
+      </li>
+    </ul>
+  </fieldset>
+</form>
diff --git a/app/out/default/views/admin/actions_logs/historique.php b/app/out/default/views/admin/actions_logs/historique.php
new file mode 100644 (file)
index 0000000..54a7391
--- /dev/null
@@ -0,0 +1,66 @@
+<h2>Historique des actions</h2>
+
+<ul class="buttons">
+  <li><a href="<?php echo $this->url("admin/actions_logs/del_historique"); ?>"
+       class="del"
+       onclick="return confirm('Vider l hitorique ?')">Vider l'historique <img src="<?php echo $this->out_url("icons/del.gif"); ?>"/></a></li>
+</ul>
+
+<?php if($this->out["historique"]["list"]) : ?>
+
+<?php $items = "historique"; $legend = "logs"; require $this->out_file("views/navig.php"); ?>
+
+<table class="admin">
+  <tr>
+    <th>Date</th>
+    <th>Action</th>
+    <th>Login</th>
+    <th>GET</th>
+    <th>POST</th>
+  </tr>
+<?php foreach($this->out["historique"]["list"] as $i => $log) : ?>
+  <tr>
+    <td class="small"><?php echo $log["date_log"]; ?></td>
+    <td class="small"><?php echo $log["action"]; ?></td>
+    <td class="small"><?php echo $log["login"]; ?></td>
+    <td class="log_params_td">
+      <?php if($log["get"]) : ?>
+      <div class="log_params_content" id="get_content_<?php echo $i; ?>">
+        <table>
+          <?php foreach($log["get"] as $key => $value) : ?>
+          <tr>
+            <th><?php echo $key; ?></th>
+            <td><?php echo $value; ?></td>
+          </tr>
+          <?php endforeach; ?>
+        </table>
+      </div>
+      <a class="see_get_content" id="see_get_content_<?php echo $i; ?>" href="#">voir</a>
+      <?php endif; ?>
+    </td>
+    <td class="log_params_td">
+      <?php if($log["post"]) : ?>
+      <div class="log_params_content" id="post_content_<?php echo $i; ?>">
+        <table>
+          <?php foreach($log["post"] as $key => $value) : ?>
+          <tr>
+            <th><?php echo $key; ?></th>
+            <td><?php echo $value; ?></td>
+          </tr>
+          <?php endforeach; ?>
+        </table>
+      </div>
+      <a class="see_post_content" id="see_post_content_<?php echo $i; ?>" href="#">voir</a>
+      <?php endif; ?>
+    </td>
+  </tr>
+<?php endforeach; ?>
+</table>
+
+<?php $items = "historique"; $legend = "logs"; require $this->out_file("views/navig.php"); ?>
+
+<?php else : ?>
+
+<p>Aucun log pour le moment.</p>
+
+<?php endif; ?>
diff --git a/app/out/default/views/admin/actions_logs/logs_actions.php b/app/out/default/views/admin/actions_logs/logs_actions.php
new file mode 100644 (file)
index 0000000..cdd18b3
--- /dev/null
@@ -0,0 +1,79 @@
+<h2>Liste des actions</h2>
+
+<ul class="buttons">
+  <li><a class="add" href="<?php echo $this->url("admin/actions_logs/add_log_action"); ?>">Ajouter une action dans la liste</a></li>
+  <li><a href="<?php echo $this->url("admin/actions_logs/del_logs_actions"); ?>"
+       class="del"
+       onclick="return confirm('Vider la liste ?')">Vider la liste <img src="<?php echo $this->out_url("icons/del.gif"); ?>"/></a></li>
+</ul>
+
+<p>
+  <a href="<?php echo $this->url("admin/actions_logs/config"); ?>"><strong>Configuration actuelle</strong></a> :
+  <strong>
+    <?php if($this->out["actions_logs_config"]["default_log"]) : ?>
+    enregistrer par défaut
+    <?php else : ?>
+    ne pas enregistrer par défaut
+    <?php endif; ?>
+  </strong>
+  (sauf si dans la liste)
+</p>
+
+<?php if($this->out["logs_actions"]["list"]) : ?>
+
+<form name="logs_actions_form" action="<?php echo $this->url("admin/actions_logs/logs_actions"); ?>" method="post">
+
+  <fieldset>
+    <table class="admin" id="logs_actions" <?php echo $this->out["logs_actions"] ? "" : "style=\"display: none\""; ?>>
+      <tr>
+        <th>Action</th>
+        <?php if(!$this->out["actions_logs_config"]["default_log"]) : ?>
+        <th width="65" align="center"><span class="<?php echo $default_log_class; ?>">GET</span></th>
+        <th width="65" align="center"><span class="<?php echo $default_log_class; ?>">POST</span></th>
+        <?php endif; ?>
+        <th>Enlever</th>
+      </tr>
+      <?php foreach($this->out["logs_actions"]["list"] as $id_log_action => $log_action) : ?>
+      <?php $default_log_class = "default_log_".($this->out["actions_logs_config"]["default_log"] ? "on" : "off"); ?>
+      <tr id="log_action_<?php echo $log_action["id"]; ?>" class="hl">
+        <td>
+          <?php echo $log_action["action"]; ?>
+          <input type="hidden" name="id_log_action_<?php echo $log_action["id"]; ?>" value="<?php echo $log_action["id"]; ?>" />
+        </td>
+        <?php if(!$this->out["actions_logs_config"]["default_log"]) : ?>
+        <td align="center">
+          <span class="<?php echo $default_log_class; ?>">
+            <input type="checkbox" name="log_get_<?php echo $log_action["id"]; ?>" <?php echo $log_action["log_get"] ? "checked" : ""; ?> />
+          </span> 
+        </td>
+        <td align="center">
+          <span class="<?php echo $default_log_class; ?>">
+            <input type="checkbox" name="log_post_<?php echo $log_action["id"]; ?>" <?php echo $log_action["log_post"] ? "checked" : ""; ?> />
+          </span>
+        </td>
+        <?php endif; ?>
+        <td align="center">
+          <a href="<?php echo $this->url("admin/actions_logs/del_log_action", array("id" => $log_action["id"])); ?>"
+             class="admin_link del_action"
+             id="del_action_<?php echo $log_action["id"]; ?>"
+             title="Enlever cette action de la liste"><img src="<?php echo $this->out_url("icons/del.gif"); ?>"/></a>
+        </td>
+      </tr>
+      <?php endforeach; ?>
+    </table>
+    <?php if(!$this->out["actions_logs_config"]["default_log"]) : ?>
+    <ul>
+      <li>
+        <div class="form_buttons">
+          <input type="submit" value="Enregistrer les modifications" />
+        </div>
+      </li>
+    </ul>
+    <?php endif; ?>
+  </fieldset>
+
+</form>
+
+<?php else : ?>
+<p>Aucune action listée pour le moment.</p>
+<?php endif; ?>
\ No newline at end of file
diff --git a/mw_actions_logs.php b/mw_actions_logs.php
new file mode 100644 (file)
index 0000000..337866d
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+
+  class mw_actions_logs extends mw_plugin{
+
+    function title(){
+      return "Actions logs";
+    }
+
+    function description(){
+      return "Enregistre un historique des actions sur le site";
+    }
+
+    function init($env){
+      $env->set_link("admin/actions_logs", $env->url("admin/actions_logs/historique"), "Actions logs", 50);
+      $env->set_link("admin/actions_logs/historique", $env->url("admin/actions_logs/historique"), "Historique des actions", 10);
+      $env->set_link("admin/actions_logs/config", $env->url("admin/actions_logs/config"), "Configuration des logs", 20);
+      $env->set_link("admin/actions_logs/logs_actions", $env->url("admin/actions_logs/logs_actions"), "Liste des actions", 30);
+      return true;
+    }
+
+    function enable($env){
+      return true;
+    }
+
+    function disable($env){
+      return true;
+    }
+
+    function install($env){
+      $data = $env->data();
+      $sgbd = $data->sgbd();
+      try{
+        $EXISTS = $sgbd->table_exists("#--actions_logs");
+      }
+      catch(Exception $e){
+        return "impossible de savoir si la table #--actions_logs existe";
+      }
+      if($EXISTS){
+        return "la table #--actions_logs existe deja";
+      }
+      try{
+        $EXISTS = $sgbd->table_exists("#--logs_actions");
+      }
+      catch(Exception $e){
+        return "impossible de savoir si la table #--logs_actions existe";
+      }
+      if($EXISTS){
+        return "la table #--logs_actions existe deja";
+      }
+      try{
+        $sql =
+         "CREATE TABLE `#--actions_logs`("
+        ."  `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY"
+        .", `action` VARCHAR( 255 ) NOT NULL"
+        .", `date_log` DATETIME NOT NULL"
+        .", `login` VARCHAR( 255 ) NOT NULL"
+        .", `from_ip` VARCHAR( 127 ) NOT NULL"
+        .", `get` TEXT NULL"
+        .", `post` TEXT NULL"
+        ." ) ENGINE = InnoDB DEFAULT CHARSET=utf8;";
+        $sgbd->query($sql);
+        $sql =
+         "CREATE TABLE `#--logs_actions`("
+        ."  `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY"
+        .", `action` VARCHAR( 255 ) NOT NULL"
+        .", `log_get` TINYINT NOT NULL"
+        .", `log_post` TINYINT NOT NULL" 
+        ." ) ENGINE = InnoDB DEFAULT CHARSET=utf8;";
+        $sgbd->query($sql);
+      }
+      catch(Exception $e) { return "erreur lors de la creation des tables #--actions_logs et #--logs_actions"; }
+      return true;
+    }
+
+    function uninstall($env){
+      $data = $env->data();
+      $sgbd = $data->sgbd();
+      if(!$this->disable($env)) return "impossible de desactiver le plugin";
+      try{
+        $EXISTS = $sgbd->table_exists("#--actions_logs");
+      }
+      catch(Exception $e){
+        return "impossible de savoir si la table #--actions_logs existe";
+      }
+      if(!$EXISTS){
+        // return "la table #--actions_logs n'existe pas";
+      }
+      else{
+        try{
+          $sgbd->query("DROP TABLE #--actions_logs");
+        }
+        catch(Exception $e){
+          return "imposible de supprimer la table #--actions_logs";
+        }
+      }
+      try{
+        $EXISTS = $sgbd->table_exists("#--logs_actions");
+      }
+      catch(Exception $e){
+        return "impossible de savoir si la table #--logs_actions existe";
+      }
+      if(!$EXISTS){
+        // return "la table #--logs_actions n'existe pas";
+      }
+      else{
+        try{
+          $sgbd->query("DROP TABLE #--logs_actions");
+        }
+        catch(Exception $e){
+          return "imposible de supprimer la table #--logs_actions";
+        }
+      }
+      $data->del_config("actions_logs_do_log");
+      $data->del_config("actions_logs_default_log");
+      $data->del_config("actions_logs_default_log_get");
+      $data->del_config("actions_logs_default_log_post");
+      return true;
+    }
+
+  }
+
+?>
\ No newline at end of file