Skip to content

Commit

Permalink
Fehler bei Anzeige im Backend behoben (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhunderter authored Jan 19, 2024
1 parent dc3b37d commit 994838f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 47 deletions.
37 changes: 15 additions & 22 deletions application/modules/admin/controllers/admin/Index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @copyright Ilch 2.0
* @package ilch
Expand All @@ -23,11 +24,9 @@ public function indexAction()
{
$moduleMapper = new ModuleMapper();
$modules = $moduleMapper->getKeysInstalledModules();

// Delete selected notifications
if ($this->getRequest()->getPost('action') === 'delete' && $this->getRequest()->getPost('check_notifications')) {
$notificationsMapper = new NotificationsMapper();

foreach ($this->getRequest()->getPost('check_notifications') as $notificationId) {
$notificationsMapper->deleteNotificationById($notificationId);
}
Expand All @@ -36,14 +35,13 @@ public function indexAction()
// Delete all expired authTokens of the remember-me-feature
$authTokenMapper = new \Modules\User\Mappers\AuthToken();
$authTokenMapper->deleteExpiredAuthTokens();

// Check if Ilch is up to date
$update = new \Ilch\Transfer();
$update->setTransferUrl($this->getConfig()->get('updateserver').'updates2.php');
$update->setTransferUrl($this->getConfig()->get('updateserver') . 'updates2.php');
$update->setVersionNow($this->getConfig()->get('version'));
$update->setCurlOpt(CURLOPT_SSL_VERIFYPEER, TRUE);
$update->setCurlOpt(CURLOPT_SSL_VERIFYHOST, 2);
$update->setCurlOpt(CURLOPT_CAINFO, ROOT_PATH.'/certificate/cacert.pem');
$update->setCurlOpt(CURLOPT_SSL_VERIFYPEER, true);
$update->setCurlOpt(CURLOPT_SSL_VERIFYHOST, 2);
$update->setCurlOpt(CURLOPT_CAINFO, ROOT_PATH . '/certificate/cacert.pem');
$update->setCurlOpt(CURLOPT_RETURNTRANSFER, 1);
$update->setCurlOpt(CURLOPT_TIMEOUT, 20);
$update->setCurlOpt(CURLOPT_CONNECTTIMEOUT, 10);
Expand All @@ -55,10 +53,9 @@ public function indexAction()
} else {
// If check for an ilch update didn't already failed then check for module updates
$countOfUpdatesAvailable = 0;
$modulesList = url_get_contents($this->getConfig()->get('updateserver').'modules.php');
$modulesList = url_get_contents($this->getConfig()->get('updateserver') . 'modules.php');
$modulesOnUpdateServer = json_decode($modulesList);
$versionsOfModules = $moduleMapper->getVersionsOfModules();

foreach ($modulesOnUpdateServer as $moduleOnUpdateServer) {
if (in_array($moduleOnUpdateServer->key, $modules) && version_compare($versionsOfModules[$moduleOnUpdateServer->key]['version'], $moduleOnUpdateServer->version, '<')) {
++$countOfUpdatesAvailable;
Expand All @@ -68,18 +65,16 @@ public function indexAction()
$notificationsMapper = new NotificationsMapper();
if ($countOfUpdatesAvailable) {
$notifications = $notificationsMapper->getNotificationsByType('adminModuleUpdatesAvailable');

$currentTime = new Date();
$notificationModel = new NotificationModel();
$notificationModel->setModule('admin');
$notificationModel->setMessage($this->getTranslator()->trans('moduleUpdatesAvailable', $countOfUpdatesAvailable));
$notificationModel->setURL($this->getLayout()->getUrl(['controller' => 'modules', 'action' => 'updates']));
$notificationModel->setType('adminModuleUpdatesAvailable');

if (!$notifications) {
$notificationsMapper->addNotification($notificationModel);
} elseif ((strtotime($currentTime->toDb(true)) - strtotime($notifications[count($notifications)-1]->getTimestamp()) > 86400)) {
$notificationModel->setId($notifications[count($notifications)-1]->getId());
} elseif ((strtotime($currentTime->toDb(true)) - strtotime($notifications[count($notifications) - 1]->getTimestamp()) > 86400)) {
$notificationModel->setId($notifications[count($notifications) - 1]->getId());
$notificationsMapper->updateNotificationById($notificationModel);
}
} else {
Expand All @@ -88,41 +83,39 @@ public function indexAction()
}
}

if ($update->newVersionFound() == true) {
if ($update->newVersionFound()) {
$newVersion = $update->getNewVersion();
$this->getView()->set('foundNewVersions', true);
$this->getView()->set('newVersion', $newVersion);
}

// Check if there are notifications, which need to be shown
$notificationsMapper = new NotificationsMapper();

$this->getView()->set('ilchNewsList', $this->getConfig()->get('updateserver').'ilchNews.php');
$this->getView()->set('ilchNewsList', $this->getConfig()->get('updateserver') . 'ilchNews.php');
$this->getView()->set('version', $this->getConfig()->get('version'));
$this->getView()->set('notifications', $notificationsMapper->getNotifications());
$this->getLayout()->set('accesses', $this->getAccesses());
}

public function deleteAction() {
public function deleteAction()
{
if ($this->getRequest()->isSecure()) {
$notificationsMapper = new NotificationsMapper();
$notificationsMapper->deleteNotificationById($this->getRequest()->getParam('id'));

$this->addMessage('deleteSuccess');
}

$this->redirect(['action' => 'index']);
}

public function revokePermissionAction() {
public function revokePermissionAction()
{
if ($this->getRequest()->isSecure()) {
$notificationPermissionMapper = new NotificationPermissionMapper();
$notificationsMapper = new NotificationsMapper();

$module = $this->getRequest()->getParam('key');

$notificationPermissionMapper->updatePermissionGrantedOfModule($module, false);
$notificationsMapper->deleteNotificationsByModule($module);

$this->addMessage('revokePermissionSuccess');
}

Expand Down
21 changes: 13 additions & 8 deletions application/modules/admin/layouts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,21 @@
$smallIcon = '<img style="padding-right: 5px;" src="' . $this->getStaticUrl('../application/modules/' . $module->getKey() . '/config/' . $module->getIconSmall()) . '" />';
}

if ($module->getSystemModule()) {
$systemModuleHtml .= '<a class="list-group-item" href="' . $this->getUrl(['module' => $module->getKey(), 'controller' => 'index', 'action' => 'index']) . '">

if ($accesses && ($accesses->hasAccess('Admin_' . $module->getKey(), $module->getKey()))) {
if ($module->getSystemModule()) {
$systemModuleHtml .= '<a class="list-group-item" href="' . $this->getUrl(['module' => $module->getKey(), 'controller' => 'index', 'action' => 'index']) . '">
' . $smallIcon . $content['name'] . '
</a>';
} elseif ($module->getLayoutModule()) {
$layoutModuleHtml .= '<a class="list-group-item" href="' . $this->getUrl(['module' => $module->getKey(), 'controller' => 'index', 'action' => 'index']) . '">
} elseif ($module->getLayoutModule()) {
$layoutModuleHtml .= '<a class="list-group-item" href="' . $this->getUrl(['module' => $module->getKey(), 'controller' => 'index', 'action' => 'index']) . '">
' . $smallIcon . $content['name'] . '
</a>';
} else {
$modulesHtml .= '<a class="list-group-item" href="' . $this->getUrl(['module' => $module->getKey(), 'controller' => 'index', 'action' => 'index']) . '">
} else {
$modulesHtml .= '<a class="list-group-item" href="' . $this->getUrl(['module' => $module->getKey(), 'controller' => 'index', 'action' => 'index']) . '">
' . $smallIcon . $content['name'] . '
</a>';
}
}
}
}
Expand All @@ -165,7 +168,9 @@
<div class="list-group list-group-horizontal">
<?=$systemModuleHtml ?>
</div>
<?php if (!empty($modulesHtml) && !empty($systemModuleHtml)) : ?>
<div class="divider"></div>
<?php endif; ?>
<div class="list-group list-group-horizontal">
<?=$modulesHtml ?>
</div>
Expand Down Expand Up @@ -274,8 +279,8 @@
<div class="input-group">
<input type="text" class="form-control" placeholder="<?=$this->getTrans('search') ?>">
<span class="input-group-btn">
<button type="button" class="btn btn-default"><?=$this->getTrans('go') ?></button>
</span>
<button type="button" class="btn btn-default"><?=$this->getTrans('go') ?></button>
</span>
</div>
</div>
</li>
Expand Down
45 changes: 28 additions & 17 deletions application/modules/admin/views/admin/index/index.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
<?php

/** @var \Ilch\View $this */

if ($this->getUser()->getFirstName() != '') {
$name = $this->getUser()->getFirstName().' '.$this->getUser()->getLastName();
$name = $this->getUser()->getFirstName() . ' ' . $this->getUser()->getLastName();
} else {
$name = $this->getUser()->getName();
}

$ilchNewsList = url_get_contents($this->get('ilchNewsList'), true, false, 120);
$ilchNews = json_decode($ilchNewsList);

/** @var \Modules\Admin\Models\Notification[] $notifications */
$notifications = $this->get('notifications');
/** @var string $version */
$version = $this->get('version');

/** @var \Ilch\Accesses $accesses */
$accesses = $this->get('accesses');
?>

<h3><?=$this->getTrans('welcomeBack', $this->escape($name)) ?> !</h3>
<?=$this->getTrans('welcomeBackDescripton') ?>
<br /><br /><br />
<?php if (!empty($notifications)): ?>
<?php if (!empty($notifications)) : ?>
<form class="form-horizontal" method="POST">
<?=$this->getTokenField() ?>
<?=$this->getTokenField() ?>
<?php endif; ?>
<div class="row">
<div class="col-lg-6 col-md-6">
<h1>
<?=$this->getTrans('system') ?>
<?php if ($this->get('foundNewVersions')): ?>
<?php if ($this->get('foundNewVersions')) : ?>
<span class="label label-danger"><?=$this->getTrans('notUpToDate') ?></span>
<?php elseif ($this->get('curlErrorOccured')): ?>
<?php elseif ($this->get('curlErrorOccured')) : ?>
<span class="label label-warning"><?=$this->getTrans('versionQueryFailed') ?></span>
<?php else: ?>
<?php else : ?>
<span class="label label-success"><?=$this->getTrans('upToDate') ?></span>
<?php endif; ?>
</h1>
Expand All @@ -48,16 +57,16 @@
<tr>
<td><?=$this->getTrans('serverVersion') ?></td>
<td>
<?php if ($this->get('newVersion')): ?>
<?php if ($this->get('newVersion')) : ?>
<?=$this->get('newVersion') ?>
<?php elseif ($this->get('curlErrorOccured')): ?>
<?php elseif ($this->get('curlErrorOccured')) : ?>
<?=$this->getTrans('versionNA') ?>
<?php else: ?>
<?php else : ?>
<?=$version ?>
<?php endif; ?>
</td>
</tr>
<?php if ($this->get('foundNewVersions')): ?>
<?php if ($this->get('foundNewVersions')) : ?>
<tr>
<td></td>
<td>
Expand All @@ -68,7 +77,7 @@
</tbody>
</table>
</div>
<?php if (!empty($ilchNews)): ?>
<?php if (!empty($ilchNews)) : ?>
<h1>ilch <?=$this->getTrans('news') ?></h1>
<div class="table-responsive">
<table class="table table-hover table-striped">
Expand All @@ -81,7 +90,7 @@
<th><?=$this->getTrans('title') ?></th>
</thead>
<tbody>
<?php foreach ($ilchNews as $news): ?>
<?php foreach ($ilchNews as $news) : ?>
<?php $date = new \Ilch\Date($news->date); ?>
<tr>
<td><?=$date->format('d.m.Y', true) ?></td>
Expand All @@ -92,7 +101,7 @@
</table>
</div>
<?php endif; ?>
<?php if (!empty($notifications)): ?>
<?php if (!empty($notifications)) : ?>
<h1><?=$this->getTrans('notifications') ?></h1>
<div class="table-responsive">
<table class="table table-hover table-striped">
Expand All @@ -115,8 +124,9 @@
</tr>
</thead>
<tbody>
<?php foreach ($notifications as $notification): ?>
<?php $date = new \Ilch\Date($notification->getTimestamp()); ?>
<?php foreach ($notifications as $notification) : ?>
<?php if (($accesses && $accesses->hasAccess('Admin_' . $notification->getModule(), $notification->getModule()))) : ?>
<?php $date = new \Ilch\Date($notification->getTimestamp()); ?>
<tr>
<td><?=$this->getDeleteCheckbox('check_notifications', $notification->getId()) ?></td>
<td><?=$this->getDeleteIcon(['action' => 'delete', 'id' => $notification->getId()]) ?></td>
Expand All @@ -125,14 +135,15 @@
<td><a href="<?=$notification->getURL() ?>" target="_blank" rel="noopener" title="<?=$this->escape($notification->getModule()) ?>"><?=$this->escape($notification->getModule()) ?></a></td>
<td><?=$this->escape($notification->getMessage()) ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
<?php if (!empty($notifications)): ?>
<?=$this->getListBar(['delete' => 'delete']) ?>
<?php if (!empty($notifications)) : ?>
<?=$this->getListBar(['delete' => 'delete']) ?>
</form>
<?php endif; ?>

0 comments on commit 994838f

Please sign in to comment.