Skip to content

Commit

Permalink
Extracts HTML from ReplicationGui::getHtmlForReplicationMasterAddSlav…
Browse files Browse the repository at this point in the history
…eUser

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Mar 31, 2019
1 parent 6909dfb commit 63edfe3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 51 deletions.
71 changes: 20 additions & 51 deletions libraries/classes/ReplicationGui.php
Expand Up @@ -414,47 +414,31 @@ public function getUsernameHostnameLength()
*/
public function getHtmlForReplicationMasterAddSlaveUser()
{
$html = '';
list($username_length, $hostname_length)
= $this->getUsernameHostnameLength();
list(
$usernameLength,
$hostnameLength
) = $this->getUsernameHostnameLength();

if (isset($_POST['username']) && strlen($_POST['username']) === 0) {
$GLOBALS['pred_username'] = 'any';
}
$html .= '<div id="master_addslaveuser_gui">';
$html .= '<form autocomplete="off" method="post" ';
$html .= 'action="server_privileges.php"';
$html .= ' onsubmit="return checkAddUser(this);">';
$html .= Url::getHiddenInputs('', '');
$html .= '<fieldset id="fieldset_add_user_login">'
. '<legend>' . __('Add slave replication user') . '</legend>'
. $this->getHtmlForAddUserLoginForm($username_length)
. '<div class="item">'
. '<label for="select_pred_hostname">'
. ' ' . __('Host:')
. '</label>'
. '<span class="options">'
. ' <select name="pred_hostname" id="select_pred_hostname" title="'
. __('Host') . '"';

$_current_user = $GLOBALS['dbi']->fetchValue('SELECT USER();');
if (! empty($_current_user)) {
$thishost = str_replace(
$addUserLoginForm = $this->getHtmlForAddUserLoginForm($usernameLength);

$currentUser = $GLOBALS['dbi']->fetchValue('SELECT USER();');
if (! empty($currentUser)) {
$userHost = str_replace(
"'",
'',
mb_substr(
$_current_user,
mb_strrpos($_current_user, '@') + 1
$currentUser,
mb_strrpos($currentUser, '@') + 1
)
);
if ($thishost != 'localhost' && $thishost != '127.0.0.1') {
$html .= ' data-thishost="' . htmlspecialchars($thishost) . '" ';
} else {
unset($thishost);
if ($userHost !== 'localhost' && $userHost !== '127.0.0.1') {
$thisHost = $userHost;
}
}
$html .= '>' . "\n";
unset($_current_user);

// when we start editing a user, $GLOBALS['pred_hostname'] is not defined
if (! isset($GLOBALS['pred_hostname']) && isset($_POST['hostname'])) {
Expand All @@ -471,30 +455,15 @@ public function getHtmlForReplicationMasterAddSlaveUser()
break;
}
}
$html .= ' <option value="any"'
. ((isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any')
? ' selected="selected"' : '') . '>' . __('Any host')
. '</option>'
. ' <option value="localhost"'
. ((isset($GLOBALS['pred_hostname'])
&& $GLOBALS['pred_hostname'] == 'localhost')
? ' selected="selected"' : '') . '>' . __('Local')
. '</option>';

if (! empty($thishost)) {
$html .= ' <option value="thishost"'
. ((isset($GLOBALS['pred_hostname'])
&& $GLOBALS['pred_hostname'] == 'thishost')
? ' selected="selected"' : '') . '>' . __('This Host')
. '</option>';
}
unset($thishost);

$html .= $this->getHtmlForTableInfoForm($hostname_length);
$html .= '</form>';
$html .= '</div>';
$tableInfoForm = $this->getHtmlForTableInfoForm($hostnameLength);

return $html;
return $this->template->render('server/replication/master_add_slave_user', [
'add_user_login_form' => $addUserLoginForm,
'this_host' => $thisHost ?? null,
'predefined_hostname' => $GLOBALS['pred_hostname'] ?? '',
'table_info_form' => $tableInfoForm,
]);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions templates/server/replication/master_add_slave_user.twig
@@ -0,0 +1,24 @@
<div id="master_addslaveuser_gui">
<form action="server_privileges.php" method="post" autocomplete="off" onsubmit="return checkAddUser(this);">
{{ get_hidden_inputs('', '') }}
<fieldset id="fieldset_add_user_login">
<legend>{% trans 'Add slave replication user' %}</legend>

{{ add_user_login_form|raw }}

<div class="item">
<label for="select_pred_hostname">
{% trans 'Host:' %}
</label>
<span class="options">
<select name="pred_hostname" id="select_pred_hostname" title="{% trans 'Host' %}"
{%- if this_host is not null %} data-thishost="{{ this_host }}"{% endif %}>
<option value="any"{{ predefined_hostname == 'any' ? ' selected' }}>{% trans 'Any host' %}</option>
<option value="localhost"{{ predefined_hostname == 'localhost' ? ' selected' }}>{% trans 'Local' %}</option>
{% if this_host is not null %}
<option value="thishost"{{ predefined_hostname == 'thishost' ? ' selected' }}>{% trans 'This Host' %}</option>
{% endif %}

{{ table_info_form|raw }}
</form>
</div>

0 comments on commit 63edfe3

Please sign in to comment.