Skip to content

Commit

Permalink
GH-230 Move entire email change info box to a component
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 10, 2022
1 parent 785ab10 commit 530a04e
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 38 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

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

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

$user = &$props['user'];
$currentTimestamp = $props['currentTimestamp'];

if ($user['email'] == $user['email_2']) {
return [
'componentHTML' => '',
];
}

$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,
];
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<tbody>
<tr>
<td colspan="3" class="c">
{MailChange_Title}
</td>
</tr>
<tr>
<th colspan="3" class="c">
{MailChange_Text}
<br/><br/>
{ChangeProcess_Status}
<form
action="email_change.php?hash=none"
method="post"
style="{ChangeProcess_HideFormStyle}"
>
<input
type="submit"
style="font-weight: bold;"
value="{MailChange_Buto}"
/>
</form>
</th>
</tr>
<tr>
<th class="inv">&nbsp;</th>
</tr>
</tbody>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

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

?>
31 changes: 4 additions & 27 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] .= "<br/><br/><form action=\"email_change.php?hash=none\" method=\"post\"><input type=\"submit\" style=\"font-weight: bold;\" value=\"{$_Lang['MailChange_Buto']}\" /></form>";
}
else
{
$parse['MailChange_Box'] .= "<br/><br/>".sprintf($_Lang['MailChange_Inf2'], date('d.m.Y H:i:s', $ChangeTime));
}
}
else
{
$parse['MailChange_Box'] .= "<br/><br/>{$_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'];
Expand Down
12 changes: 1 addition & 11 deletions templates/default_template/overview_body.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ $(document).ready(function()
<br />
{P_SFBInfobox}
<table width="750">
<tbody style="{MailChange_Hide}">
<tr>
<td colspan="3" class="c">{MailChange_Title}</td>
</tr>
<tr>
<th colspan="3" class="c">{MailChange_Box}</th>
</tr>
<tr>
<th class="inv">&nbsp;</th>
</tr>
</tbody>
{EmailChangeInfoBox}
{VacationModeBox}
{ActivationInfoBox}
{NewUserBox}
Expand Down

0 comments on commit 530a04e

Please sign in to comment.