Skip to content

Commit

Permalink
GH-230 Move entire admin info box to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 9, 2022
1 parent b20e0a2 commit f511993
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 20 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
include($includePath . './screens/FirstLogin/utils/effects/updateUserOnFirstLogin.effect.php');
include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php');

include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php');
include($includePath . './screens/Overview/components/PlanetsListElement/PlanetsListElement.component.php');
include($includePath . './screens/Overview/components/ResourcesTransport/ResourcesTransport.component.php');
include($includePath . './screens/Overview/components/StatsList/StatsList.component.php');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\Overview\Components\AdminAlerts;

/**
* @param array $props
* @param arrayRef $props['user']
*/
function render($props) {
global $_Lang;

$hasAccess = CheckAuth(
'supportadmin',
AUTHCHECK_NORMAL,
$props['user']
);

if (!$hasAccess) {
return [
'componentHTML' => '',
];
}

$localTemplateLoader = createLocalTemplateLoader(__DIR__);

$getAlertsCountsQuery = (
(
"SELECT " .
"COUNT(*) AS `count`, " .
"'reports' AS `type` " .
"FROM `{{prefix}}reports` " .
"WHERE " .
"`status` = 0 "
) .
"UNION " .
(
"SELECT " .
"COUNT(*) AS `count`, " .
"'declarations' AS `type` " .
"FROM `{{prefix}}declarations` " .
"WHERE " .
"`status` = 0 "
) .
"UNION " .
(
"SELECT " .
"COUNT(*) AS `count`, " .
"'system_alerts' AS `type` " .
"FROM `{{prefix}}system_alerts` " .
"WHERE " .
"`status` = 0 "
)
);
$getAlertsCountsResult = doquery($getAlertsCountsQuery, '');

$alertsCounts = mapQueryResults($getAlertsCountsResult, function ($counter) {
return $counter;
});
$alertsCounts = object_map($alertsCounts, function ($counter) {
return [
$counter['count'],
$counter['type']
];
});
$totalAlertsCount = array_sum($alertsCounts);

if ($totalAlertsCount <= 0) {
return [
'componentHTML' => '',
];
}

$tplBodyParams = [
'content' => sprintf(
$_Lang['AdminAlertsBox'],
$alertsCounts['reports'],
$alertsCounts['declarations'],
$alertsCounts['system_alerts']
),
];
$tplBodyParams = array_merge($_Lang, $tplBodyParams);

$componentHTML = parsetemplate(
$localTemplateLoader('body'),
$tplBodyParams
);

return [
'componentHTML' => $componentHTML,
];
}

?>
12 changes: 12 additions & 0 deletions modules/overview/screens/Overview/components/AdminAlerts/body.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<tr>
<th
style="border-color: #FFA366; background-color: #FF8533; color: black;"
class="c pad2"
colspan="3"
>
{content}
</th>
</tr>
<tr>
<th class="inv">&nbsp;</th>
</tr>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
23 changes: 3 additions & 20 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,9 @@
}

// --- Admin Info Box ------------------------------------------------------------------------------------
if(CheckAuth('supportadmin'))
{
$Query_AdminBoxCheck[] = "SELECT COUNT(*) AS `Count`, 1 AS `Type` FROM `{{prefix}}reports` WHERE `status` = 0";
$Query_AdminBoxCheck[] = "SELECT COUNT(*) AS `Count`, 2 AS `Type` FROM `{{prefix}}declarations` WHERE `status` = 0";
$Query_AdminBoxCheck[] = "SELECT COUNT(*) AS `Count`, 3 AS `Type` FROM `{{prefix}}system_alerts` WHERE `status` = 0";
$Query_AdminBoxCheck = implode(' UNION ', $Query_AdminBoxCheck);
$Result_AdminBoxCheck = doquery($Query_AdminBoxCheck, '');

$AdminBoxTotalCount = 0;
while($AdminBoxData = $Result_AdminBoxCheck->fetch_assoc())
{
$AdminBox[$AdminBoxData['Type']] = $AdminBoxData['Count'];
$AdminBoxTotalCount += $AdminBoxData['Count'];
}
if($AdminBoxTotalCount > 0)
{
$AdminAlerts = sprintf($_Lang['AdminAlertsBox'], $AdminBox[1], $AdminBox[2], $AdminBox[3]);
$parse['AdminInfoBox'] = '<tr><th style="border-color: #FFA366; background-color: #FF8533; color: black;" class="c pad2" colspan="3">'.$AdminAlerts.'</th></tr><tr><th class="inv">&nbsp;</th></tr>';
}
}
$parse['AdminInfoBox'] = Overview\Screens\Overview\Components\AdminAlerts\render([
'user' => &$_User,
])['componentHTML'];

// --- MailChange Box ------------------------------------------------------------------------------------
$parse['MailChange_Hide'] = 'display: none;';
Expand Down

0 comments on commit f511993

Please sign in to comment.