From 4ba7c59d32a19a6c5c3b66f2367534e21cbfb45a Mon Sep 17 00:00:00 2001 From: fredtempez Date: Fri, 12 Feb 2021 18:37:31 +0100 Subject: [PATCH] Stat ok manque le total dans la liste et l'export --- module/download/download.php | 91 +++++++++++++------------ module/download/view/stats/stats.js.php | 22 ++++++ module/download/view/stats/stats.php | 14 ++-- 3 files changed, 75 insertions(+), 52 deletions(-) create mode 100644 module/download/view/stats/stats.js.php diff --git a/module/download/download.php b/module/download/download.php index 17fcead6..830f77c2 100644 --- a/module/download/download.php +++ b/module/download/download.php @@ -28,6 +28,7 @@ class download extends common { 'delete' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR, 'stats' => self::GROUP_MODERATOR, + 'statsDeleteAll' => self::GROUP_MODERATOR, 'index' => self::GROUP_VISITOR, 'rss' => self::GROUP_VISITOR, 'downloadFile' => self::GROUP_VISITOR @@ -795,7 +796,7 @@ class download extends common { $statId = helper::increment(uniqid(), $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats'])); $this->setData(['module', $this->getUrl(0), - 'items', + 'items', $this->getUrl(2), 'fileStats', $statId, [ @@ -832,58 +833,60 @@ class download extends common { */ public function stats() { - // Soumission du formulaire - if($this->isPost()) { - // Jeton incorrect - if ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => 'Action non autorisée' - ]); - } - // L'item n'existe pas - if($this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2)]) === null) { - // Valeurs en sortie - $this->addOutput([ - 'access' => false - ]); - } - } else { + // Construction de la page des statistiques - // Ids des items par ordre de publication + $itemIds = array_keys($this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats'])); + // Pagination + $pagination = helper::pagination($itemIds, $this->getUrl(),$this->getData(['config','itemsperPage'])); - $itemIds = array_keys($this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats'])); - // Pagination - $pagination = helper::pagination($itemIds, $this->getUrl(),$this->getData(['config','itemsperPage'])); + // Liste des pages + self::$pages = $pagination['pages']; - // Liste des pages - self::$pages = $pagination['pages']; + for($i = $pagination['first']; $i < $pagination['last']; $i++) { - for($i = $pagination['first']; $i < $pagination['last']; $i++) { + // Format des variables + $date = mb_detect_encoding(strftime('%d %B %Y - %H:%M', $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'time'])), 'UTF-8', true) + ? strftime('%d %B %Y - %H:%M',$this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'time'])) + : utf8_encode(strftime('%d %B %Y - %H:%M', $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'time']))); - // Format des variables - - echo $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate']); - - $date = mb_detect_encoding(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate'])), 'UTF-8', true) - ? strftime('%d %B %Y',$this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate'])) - : utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate']))); + // Met en forme le tableau + self::$items[] = [ + $date, + $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'ip']) + ]; - // Met en forme le tableau - self::$items[] = [ - $date, - $this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i], 'fileStats', 'ip']) - ]; - - } - die(); + } + $this->addOutput([ + 'title' => 'Statistiques de téléchargement', + 'view' => 'stats' + ]); + } + + public function statsDeleteAll() { + // Validité de la page demandée + if($this->getData(['module', $this->getUrl(0), 'items']) === null) { // Valeurs en sortie $this->addOutput([ - 'title' => 'Statistiques de téléchargement', - 'view' => 'stats' + 'access' => false + ]); + } + // Jeton incorrect + elseif ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0), + 'notification' => 'Action non autorisée' + ]); + } + // Téléchargement + else { + $this->setData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', [] ]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/stats/' . $this->getUrl(2), + 'notification' => 'Purge des statistiques', + 'state' => true ]); - } } } \ No newline at end of file diff --git a/module/download/view/stats/stats.js.php b/module/download/view/stats/stats.js.php new file mode 100644 index 00000000..fbeffea1 --- /dev/null +++ b/module/download/view/stats/stats.js.php @@ -0,0 +1,22 @@ +/** + * This file is part of Zwii. + * + * For full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + * + * @author Rémi Jean + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @license GNU General Public License, version 3 + * @link http://zwiicms.fr/ + */ + + +/** + * Confirmation de suppression + */ +$(".statsDeleteAll").on("click", function() { + var _this = $(this); + return core.confirm("Êtes-vous sûr de vouloir purger les statistiques ?", function() { + $(location).attr("href", _this.attr("href")); + }); +}); \ No newline at end of file diff --git a/module/download/view/stats/stats.php b/module/download/view/stats/stats.php index 9bcc3316..072bdf8b 100644 --- a/module/download/view/stats/stats.php +++ b/module/download/view/stats/stats.php @@ -3,21 +3,19 @@
'buttonGrey', - 'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0), 'items', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/config', 'ico' => 'left', 'value' => 'Retour' ]); ?>
-
+
helper::baseUrl() . $this->getUrl(0) . '/add', - 'ico' => 'plus', - 'value' => 'Item' + 'class' => 'statsDeleteAll buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/statsDeleteAll' . '/' . $this->getUrl(2) . '/'. $_SESSION['csrf'] , + 'ico' => 'cancel', + 'value' => 'Tout effacer' ]); ?>
-
- -