From 530a04e3b3ca585b5c252d26854d15fc3279a674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Sun, 10 Jul 2022 18:17:08 +0200 Subject: [PATCH] GH-230 Move entire email change info box to a component --- modules/overview/_includes.php | 1 + .../EmailChangeInfo.component.php | 77 +++++++++++++++++++ .../components/EmailChangeInfo/body.tpl | 28 +++++++ .../components/EmailChangeInfo/index.php | 5 ++ overview.php | 31 +------- templates/default_template/overview_body.tpl | 12 +-- 6 files changed, 116 insertions(+), 38 deletions(-) create mode 100644 modules/overview/screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php create mode 100644 modules/overview/screens/Overview/components/EmailChangeInfo/body.tpl create mode 100644 modules/overview/screens/Overview/components/EmailChangeInfo/index.php diff --git a/modules/overview/_includes.php b/modules/overview/_includes.php index f54d75728..4b84e8133 100644 --- a/modules/overview/_includes.php +++ b/modules/overview/_includes.php @@ -25,6 +25,7 @@ include($includePath . './screens/FirstLogin/utils/helpers/getReferrerTasksData.helper.php'); include($includePath . './screens/Overview/components/AdminAlerts/AdminAlerts.component.php'); + include($includePath . './screens/Overview/components/EmailChangeInfo/EmailChangeInfo.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'); diff --git a/modules/overview/screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php b/modules/overview/screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php new file mode 100644 index 000000000..7efaf72e4 --- /dev/null +++ b/modules/overview/screens/Overview/components/EmailChangeInfo/EmailChangeInfo.component.php @@ -0,0 +1,77 @@ + '', + ]; + } + + $getEmailChangeDataQuery = ( + "SELECT " . + "* " . + "FROM {{table}} " . + "WHERE " . + "`UserID` = {$user['id']} AND " . + "`ConfirmType` = 0 " . + "LIMIT 1 " . + ";" + ); + $emailChangeData = doquery($getEmailChangeDataQuery, 'mailchange', true); + + if (!$emailChangeData) { + return [ + 'componentHTML' => '', + ]; + } + + $localTemplateLoader = createLocalTemplateLoader(__DIR__); + + $changeEndTimestamp = $emailChangeData['Date'] + (TIME_DAY * 7); + $hasConfirmedNewAddress = ($emailChangeData['ConfirmHashNew'] == ''); + $hasChangeTimePassed = ($changeEndTimestamp < $currentTimestamp); + + $tplBodyParams = [ + 'ChangeProcess_HideFormStyle' => ( + ($hasConfirmedNewAddress && $hasChangeTimePassed) ? + '' : + 'display: none;' + ), + 'ChangeProcess_Status' => ( + !$hasConfirmedNewAddress ? + $_Lang['MailChange_Inf1'] : + ( + !$hasChangeTimePassed ? + sprintf( + $_Lang['MailChange_Inf2'], + date('d.m.Y H:i:s', $changeEndTimestamp) + ) : + '' + ) + ), + ]; + $tplBodyParams = array_merge($_Lang, $tplBodyParams); + + $componentHTML = parsetemplate( + $localTemplateLoader('body'), + $tplBodyParams + ); + + return [ + 'componentHTML' => $componentHTML, + ]; +} + +?> diff --git a/modules/overview/screens/Overview/components/EmailChangeInfo/body.tpl b/modules/overview/screens/Overview/components/EmailChangeInfo/body.tpl new file mode 100644 index 000000000..241cc2a0b --- /dev/null +++ b/modules/overview/screens/Overview/components/EmailChangeInfo/body.tpl @@ -0,0 +1,28 @@ + + + + {MailChange_Title} + + + + + {MailChange_Text} +

+ {ChangeProcess_Status} +
+ +
+ + + +   + + diff --git a/modules/overview/screens/Overview/components/EmailChangeInfo/index.php b/modules/overview/screens/Overview/components/EmailChangeInfo/index.php new file mode 100644 index 000000000..bc99142d1 --- /dev/null +++ b/modules/overview/screens/Overview/components/EmailChangeInfo/index.php @@ -0,0 +1,5 @@ + diff --git a/overview.php b/overview.php index 72fb4d76d..ce4e668f1 100644 --- a/overview.php +++ b/overview.php @@ -94,33 +94,10 @@ ])['componentHTML']; // --- MailChange Box ------------------------------------------------------------------------------------ - $parse['MailChange_Hide'] = 'display: none;'; - if($_User['email'] != $_User['email_2']) - { - $MailChange = doquery("SELECT * FROM {{table}} WHERE `UserID` = {$_User['id']} AND `ConfirmType` = 0 LIMIT 1;", 'mailchange', true); - if($MailChange['ID'] > 0) - { - $ChangeTime = $MailChange['Date'] + (TIME_DAY * 7); - - $parse['MailChange_Hide'] = ''; - $parse['MailChange_Box'] = sprintf($_Lang['MailChange_Text']); - if($MailChange['ConfirmHashNew'] == '') - { - if($ChangeTime < $Now) - { - $parse['MailChange_Box'] .= "

"; - } - else - { - $parse['MailChange_Box'] .= "

".sprintf($_Lang['MailChange_Inf2'], date('d.m.Y H:i:s', $ChangeTime)); - } - } - else - { - $parse['MailChange_Box'] .= "

{$_Lang['MailChange_Inf1']}"; - } - } - } + $parse['EmailChangeInfoBox'] = Overview\Screens\Overview\Components\EmailChangeInfo\render([ + 'user' => &$_User, + 'currentTimestamp' => $Now, + ])['componentHTML']; // Fleet Blockade Info (here, only for Global Block) $parse['P_SFBInfobox'] = FlightControl\Components\SmartFleetBlockadeInfoBox\render()['componentHTML']; diff --git a/templates/default_template/overview_body.tpl b/templates/default_template/overview_body.tpl index 440f37173..798589d39 100644 --- a/templates/default_template/overview_body.tpl +++ b/templates/default_template/overview_body.tpl @@ -26,17 +26,7 @@ $(document).ready(function()
{P_SFBInfobox} - - - - - - - - - - - + {EmailChangeInfoBox} {VacationModeBox} {ActivationInfoBox} {NewUserBox}
{MailChange_Title}
{MailChange_Box}