Przeglądaj źródła

Add sql historique

stany.ferer 2 lat temu
rodzic
commit
e7c8a3f8d8
3 zmienionych plików z 87 dodań i 1 usunięć
  1. 1 0
      conf.inc.php
  2. 3 1
      core/class/alert.class.php
  3. 83 0
      core/class/historique.class.php

+ 1 - 0
conf.inc.php

@@ -32,6 +32,7 @@ define("DB_T_EXCEL_PROWEB", "excelProweb");
 define("DB_T_FILES", "files");
 define("DB_T_LOTTERY", "lottery");
 define("DB_T_LOTTERY_INSCRITS", "lottery_salaries");
+define("DB_T_HISTORIQUE", "historique");
 
 define("DEFAUT_PAGE", "rh-liste-salaries");
 define("DEFAUT_PAGE_SOCIAL", "sociale-check-salarie");

+ 3 - 1
core/class/alert.class.php

@@ -109,7 +109,9 @@ class alert
 
     public static function show()
     {
-        if (self::getSuccess() or self::getError()) {
+        historique::recordLogs();
+        
+        if (self::getSuccess() or self::getWarning() or self::getError()) {
 
             echo '<div aria-live="polite" aria-atomic="true" class="position-fixed bottom-0 right-0 p-3"  style="z-index: 5; right: 5px; bottom: 0;">';
 

+ 83 - 0
core/class/historique.class.php

@@ -0,0 +1,83 @@
+<?php
+
+class historique
+{
+    public static function getAll() {
+        db::query("SELECT "
+                . "" . DB_T_HISTORIQUE . ".id, "
+                . "" . DB_T_HISTORIQUE . ".idUser ,"
+                . "" . DB_T_HISTORIQUE . ".idPage, "
+                . "" . DB_T_HISTORIQUE . ".log, "
+                . "" . DB_T_HISTORIQUE . ".addDate "
+                . "FROM " . DB_T_HISTORIQUE);
+        return db::resultset();
+    }
+
+    public static function getByPage(string $_idPage) {
+        db::query("SELECT "
+                . "" . DB_T_HISTORIQUE . ".id, "
+                . "" . DB_T_HISTORIQUE . ".idUser ,"
+                . "" . DB_T_HISTORIQUE . ".log, "
+                . "" . DB_T_HISTORIQUE . ".addDate "
+                . "FROM " . DB_T_HISTORIQUE . " "
+                . "WHERE " . DB_T_HISTORIQUE . ".idPage = :idPage");
+        db::bind(':idPage', $_idPage);
+        return db::resultset();
+    }
+
+    public static function getByUser(int $_idUser) {
+        db::query("SELECT "
+                . "" . DB_T_HISTORIQUE . ".id, "
+                . "" . DB_T_HISTORIQUE . ".idPage, "
+                . "" . DB_T_HISTORIQUE . ".log, "
+                . "" . DB_T_HISTORIQUE . ".addDate "
+                . "FROM " . DB_T_HISTORIQUE . " "
+                . "WHERE " . DB_T_HISTORIQUE . ".idUser = :idUser");
+        db::bind(':idUser', $_idUser);
+        return db::resultset();
+    }
+
+    private static function add(array $_input){
+        db::query("INSERT INTO " . DB_T_HISTORIQUE . " (idUser, idPage, log) VALUES (:idUser, :idPage, :log)");
+        db::bind(':idUser', $_input["idUser"]);
+        db::bind(':idPage', $_input["idPage"]);
+        db::bind(':log', $_input["log"]);
+        try {
+            db::execute();
+        } catch (Exception $ex) {
+            alert::recError("Erreur lors de l'enregistrement de l'historique");
+        }
+    }
+
+    public static function recordLogs(){
+        if(session::isConnect() AND (alert::getSuccess() OR alert::getWarning() OR alert::getError())){
+            $log = NULL;
+
+            if(alert::getSuccess()){
+                foreach (alert::getSuccess() as $value) { 
+                    $log .= "[success] " . $value . "\r\n";
+                }
+            }
+            
+            if(alert::getWarning()){
+                foreach (alert::getWarning() as $value) { 
+                    $log .= "[warning] " . $value . "\r\n";
+                }
+            }
+
+            if(alert::getError()){
+                foreach (alert::getError() as $value) { 
+                    $log .= "[error] " . $value . "\r\n";
+                }
+            }
+
+            $logs = array(
+                "idUser" => session::getId(),
+                "idPage" => $_SERVER["REQUEST_URI"],
+                "log" => $log
+            );
+
+            self::add($logs);
+        }
+    }
+}