diff --git a/build/api/core/Request.php b/build/api/core/Request.php index 17e0e05..8a05a23 100644 --- a/build/api/core/Request.php +++ b/build/api/core/Request.php @@ -257,11 +257,11 @@ if( $fromAjax ){ - $tmpfname = '/tmp/download_'.uniqid().'.php'; + $tmpfname = '/tmp/download_'.uniqid().'.php'; $bodyfname = __ROOT__.'/tmp/content_'.uniqid().'.php'; /* (1) On crée le fichier temporaire */ - $tmpfnameroot = __ROOT__.$tmpfname; + $tmpfnameroot = __PUBLIC__.$tmpfname; $tmpfile = fopen($tmpfnameroot, 'w'); fwrite($tmpfile, ' Fichier de l'archive (.csv format) + * + */ + public function archive($params){ + extract($params); + + /* [1] Récupération des logs + =========================================================*/ + /* (1) Requête */ + $logs = new Repo('history/getAll', [$_SESSION['WAREHOUSE']['id']]); + + /* (2) Gestion erreur */ + if( $logs->error->get() != Err::Success ) + return [ 'error' => $logs->error ]; + + + /* [2] Création du contenu fichier + =========================================================*/ + $BODY = "TIMESTAMP,MACHINE,UTILISATEUR,ACTION\n"; + + foreach($logs->answer() as $log) + $BODY .= $log['timestamp'].','.$log['machine_name'].','.$log['user_name'].','.$log['action_name']."\n"; + + + /* [3] Renvoi du fichier + =========================================================*/ + return [ + 'headers' => [ + 'Content-Type' => 'text/csv', + 'Content-Disposition' => 'attachment; filename=archive-'.date('dmY').'.csv' + ], + 'body' => $BODY + ]; + } + } diff --git a/config/modules.json b/config/modules.json index 1deb98d..1709491 100755 --- a/config/modules.json +++ b/config/modules.json @@ -537,6 +537,14 @@ "output": { "history": { "description": "Liste des logs correspondant à la recherche.", "type": "array>" } } + }, + + "POST::archive": { + "description": "Archive de l'historique complet.", + "permissions": [["admin"]], + "options": { "download": true }, + "parameters": {}, + "output": {} } } diff --git a/public_html/view/history.php b/public_html/view/history.php index 923af10..9a95ee1 100755 --- a/public_html/view/history.php +++ b/public_html/view/history.php @@ -54,7 +54,7 @@ - /* [1] VIEW -> Liste des acces + /* [2] DETAILS -> Détails d'un log =========================================================*/ if( isset($post[1]) && is_numeric($post[1]) ){ @@ -67,3 +67,23 @@ echo ''; } + + + + + + /* [3] Archive -> Archivage des logs + =========================================================*/ + + echo "
"; + + echo ""; + + echo '
'; + diff --git a/public_html/view/js/history.js b/public_html/view/js/history.js index 79d564d..6350a6d 100644 --- a/public_html/view/js/history.js +++ b/public_html/view/js/history.js @@ -17,7 +17,7 @@ var section = { archive: { text: '#CONTAINER > section[data-sublink="archive"] ', - element: document.querySelector('#CONTAINER > section[data-sublink="archive"]') + element: document.querySelector('#CONTAINER > section[data-sublink="archive"] #archive_clean') }, }; @@ -99,3 +99,36 @@ if( section.view.element != null ){ } + + + + + + + + + + +/* GESTION DE L'ARCHIVAGE +* +*/ +if( section.archive.element != null ){ + + /* (1) Gestion du clic pour archivage */ + section.archive.element.addEventListener('click', function(e){ + + e.preventDefault(); + + api.send({path: 'historyDefault/archive'}, function(result){ + if( result.error == 0 ){ + + document.location = result.link; + + } + }); + + }, false); + +} + +