historique.class.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class historique
  3. {
  4. public static function getAll() {
  5. db::query("SELECT "
  6. . "" . DB_T_HISTORIQUE . ".id, "
  7. . "" . DB_T_HISTORIQUE . ".idUser ,"
  8. . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user' ,"
  9. . "" . DB_T_HISTORIQUE . ".idPage, "
  10. . "" . DB_T_HISTORIQUE . ".log, "
  11. . "" . DB_T_HISTORIQUE . ".addDate "
  12. . "FROM " . DB_T_HISTORIQUE . " "
  13. . "INNER JOIN " . DB_T_USER . " ON " . DB_T_HISTORIQUE . ".idUser = " . DB_T_USER . ".id ");
  14. return db::resultset();
  15. }
  16. public static function getByPage(string $_idPage) {
  17. db::query("SELECT "
  18. . "" . DB_T_HISTORIQUE . ".id, "
  19. . "" . DB_T_HISTORIQUE . ".idUser ,"
  20. . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user' ,"
  21. . "" . DB_T_HISTORIQUE . ".log, "
  22. . "" . DB_T_HISTORIQUE . ".addDate "
  23. . "FROM " . DB_T_HISTORIQUE . " "
  24. . "INNER JOIN " . DB_T_USER . " ON " . DB_T_HISTORIQUE . ".idUser = " . DB_T_USER . ".id "
  25. . "WHERE " . DB_T_HISTORIQUE . ".idPage = :idPage");
  26. db::bind(':idPage', $_idPage);
  27. return db::resultset();
  28. }
  29. public static function getByUser(int $_idUser) {
  30. db::query("SELECT "
  31. . "" . DB_T_HISTORIQUE . ".id, "
  32. . "" . DB_T_HISTORIQUE . ".idPage, "
  33. . "" . DB_T_HISTORIQUE . ".log, "
  34. . "" . DB_T_HISTORIQUE . ".addDate "
  35. . "FROM " . DB_T_HISTORIQUE . " "
  36. . "WHERE " . DB_T_HISTORIQUE . ".idUser = :idUser");
  37. db::bind(':idUser', $_idUser);
  38. return db::resultset();
  39. }
  40. private static function add(array $_input){
  41. db::query("INSERT INTO " . DB_T_HISTORIQUE . " (idUser, idPage, log) VALUES (:idUser, :idPage, :log)");
  42. db::bind(':idUser', $_input["idUser"]);
  43. db::bind(':idPage', $_input["idPage"]);
  44. db::bind(':log', $_input["log"]);
  45. try {
  46. db::execute();
  47. } catch (Exception $ex) {
  48. alert::recError("Erreur lors de l'enregistrement de l'historique");
  49. }
  50. }
  51. public static function recordLogs(){
  52. if(session::isConnect() AND (alert::getSuccess() OR alert::getWarning() OR alert::getError())){
  53. $log = NULL;
  54. if(alert::getSuccess()){
  55. foreach (alert::getSuccess() as $value) {
  56. $log .= "[success] " . $value . "\r\n";
  57. }
  58. }
  59. if(alert::getWarning()){
  60. foreach (alert::getWarning() as $value) {
  61. $log .= "[warning] " . $value . "\r\n";
  62. }
  63. }
  64. if(alert::getError()){
  65. foreach (alert::getError() as $value) {
  66. $log .= "[error] " . $value . "\r\n";
  67. }
  68. }
  69. $logs = array(
  70. "idUser" => session::getId(),
  71. "idPage" => $_SERVER["REQUEST_URI"],
  72. "log" => $log
  73. );
  74. self::add($logs);
  75. }
  76. }
  77. }