-
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rewritten sessions per day (#2791)
- Loading branch information
Showing
6 changed files
with
99 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* Sessions per day. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* @package phpMyFAQ | ||
* @author Thorsten Rinne <thorsten@phpmyfaq.de> | ||
* @copyright 2003-2024 phpMyFAQ Team | ||
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 | ||
* @link https://www.phpmyfaq.de | ||
* @since 2003-02-24 | ||
*/ | ||
|
||
use phpMyFAQ\Configuration; | ||
use phpMyFAQ\Date; | ||
use phpMyFAQ\Enums\PermissionType; | ||
use phpMyFAQ\Filter; | ||
use phpMyFAQ\Session; | ||
use phpMyFAQ\Template\TwigWrapper; | ||
use phpMyFAQ\Translation; | ||
use phpMyFAQ\User\CurrentUser; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Twig\Extension\CoreExtension; | ||
|
||
if (!defined('IS_VALID_PHPMYFAQ')) { | ||
http_response_code(400); | ||
exit(); | ||
} | ||
|
||
$faqConfig = Configuration::getConfigurationInstance(); | ||
$user = CurrentUser::getCurrentUser($faqConfig); | ||
$request = Request::createFromGlobals(); | ||
|
||
if ($user->perm->hasPermission($user->getUserId(), PermissionType::STATISTICS_VIEWLOGS->value)) { | ||
$perpage = 50; | ||
$day = Filter::filterVar($request->request->get('day'), FILTER_VALIDATE_INT); | ||
$firstHour = mktime(0, 0, 0, date('m', $day), date('d', $day), date('Y', $day)); | ||
$lastHour = mktime(23, 59, 59, date('m', $day), date('d', $day), date('Y', $day)); | ||
|
||
$session = new Session($faqConfig); | ||
$sessionData = $session->getSessionsByDate($firstHour, $lastHour); | ||
$date = new Date($faqConfig); | ||
|
||
$twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates'); | ||
$twig->getExtension(CoreExtension::class)->setDateFormat('Y-m-d H:i', '%d days'); | ||
$template = $twig->loadTemplate('./admin/statistics/sessions.day.twig'); | ||
|
||
$templateVars = [ | ||
'adminHeaderSessionsPerDay' => Translation::get('ad_sess_session'), | ||
'currentDay' => date('Y-m-d', $day), | ||
'msgIpAdress' => Translation::get('ad_sess_ip'), | ||
'msgSessionDate' => Translation::get('ad_sess_s_date'), | ||
'msgSession' => Translation::get('ad_sess_session'), | ||
'sessionData' => $sessionData, | ||
]; | ||
|
||
echo $template->render($templateVars); | ||
} else { | ||
require 'no-permission.php'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,6 @@ | |
]; | ||
|
||
echo $template->render($templateVars); | ||
|
||
} else { | ||
echo Alert::danger('err_NotAuth'); | ||
} |
29 changes: 29 additions & 0 deletions
29
phpmyfaq/assets/templates/admin/statistics/sessions.day.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> | ||
<h1 class="h2"> | ||
<i aria-hidden="true" class="bi bi-tasks"></i> | ||
{{ adminHeaderSessionsPerDay }} {{ currentDay }} | ||
</h1> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<table class="table table-striped align-middle"> | ||
<thead> | ||
<tr> | ||
<th>{{ msgIpAdress }}</th> | ||
<th>{{ msgSessionDate }}</th> | ||
<th>{{ msgSession }}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for sid, data in sessionData %} | ||
<tr> | ||
<td>{{ data.ip }}</td> | ||
<td>{{ data.time | date }}</td> | ||
<td><a href="?action=viewsession&id={{ sid }}">{{ sid }}</a></td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters