From 80e0fcc0c1a33a176459d4be4a3c3d4cd3e6d5e5 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 29 Jul 2017 18:45:24 +0200 Subject: [PATCH] [update] `historyDefault/search` and `history/search` (using username and machine name) --- build/database/repo/history.php | 52 +++++++++++++++++++++++++++++++++ config/modules.json | 12 ++++++++ public_html/view/history.php | 22 ++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/build/database/repo/history.php b/build/database/repo/history.php index 1464b18..059b47e 100755 --- a/build/database/repo/history.php +++ b/build/database/repo/history.php @@ -2,6 +2,8 @@ namespace database\repo; use \database\core\DatabaseDriver; + use \database\core\Repo; + use \error\core\Err; use \orm\core\Table; use \orm\core\Rows; @@ -189,6 +191,56 @@ return $history->fetch(); } + + + + + /* RENVOIE UNE LISTE DE LOGS EN FONCTION D'UN MOT CLE + * + * @id_warehouse UID de l'entrepot + * @keyword Element de recherche + * + * @return logs Retourne les logs trouvees + * + */ + public static function search($id_warehouse, $keyword){ + + $machine_ids = []; + $user_ids = []; + + /* [1] Recherche dans les relations 'machines' + =========================================================*/ + /* (1) On exécute la requête */ + $machines_r = new Repo('machine/search', [$id_warehouse, $keyword]); + + /* (2) Gestion succès */ + if( $machines_r->error->get() == Err::Success ) + foreach($machines_r->answer() as $row) + $machine_ids[] = $row['id_machine']; + + /* [2] Recherche dans les relations 'users' + =========================================================*/ + /* (1) On cherche dans les utilisateurs */ + $users_r = new Repo('user/search', [$id_warehouse, $keyword]); + + /* (2) Gestion succès */ + if( $users_r->error->get() == Err::Success ) + foreach($users_r->answer() as $row) + $user_ids[] = $row['id_user']; + + + /* [3] On rédige/execute la requête + =========================================================*/ + $history_r = DatabaseDriver::getPDO()->prepare("SELECT id_history FROM history + WHERE id_user IN (SELECT id_user FROM user WHERE username LIKE '%$keyword%') + or id_machine IN (SELECT id_machine FROM machine WHERE name LIKE '%$keyword%') + ORDER BY id_history ASC;"); + + $history_r->execute(); + + return DatabaseDriver::delNumeric( $history_r->fetchAll() ); + } + diff --git a/config/modules.json b/config/modules.json index 07b3654..1deb98d 100755 --- a/config/modules.json +++ b/config/modules.json @@ -526,7 +526,19 @@ "output": { "history": { "description": "Données de l'historique", "type": "array" } } + }, + + "POST::search": { + "description": "Recherche une entrée historique par mots-clés.", + "permissions": [["admin"]], + "parameters": { + "keywords": { "description": "Mots-clés de recherche d'entrée historique", "type": "text" } + }, + "output": { + "history": { "description": "Liste des logs correspondant à la recherche.", "type": "array>" } + } } + } } diff --git a/public_html/view/history.php b/public_html/view/history.php index 76afc21..923af10 100755 --- a/public_html/view/history.php +++ b/public_html/view/history.php @@ -16,12 +16,12 @@ Tout afficher - + Détails - + Archiver @@ -49,3 +49,21 @@ $view->view(); echo ''; + + + + + + /* [1] VIEW -> Liste des acces + =========================================================*/ + if( isset($post[1]) && is_numeric($post[1]) ){ + + echo "
"; + + echo "details"; + $view = new Viewer('history.details', []); + $view->view(); + + echo '
'; + + }