Daily Lucky Numbers:
8
11
19
29
40
42

submit box

Started by Fuji, May 03, 2023, 09:45:03 PM

Previous topic - Next topic

Chen Zhen


Do you want the input boxes to be disabled for SMF guests but to remember the data for a user that is logged in if they had entered the info in the past?

Chen Zhen


Try this out....

if (!function_exists('create_db_table_steamblock')) {
function create_db_table_steamblock()
{
global $smcFunc;

if (check_table_exists_steamblock('steam_users_datablock'))
return false;

$smcFunc['db_create_table']('{db_prefix}steam_users_datablock',
array(
array(
'name' => 'id_user',
'type' => 'int',
'size' => '10',
'auto' => false,
),
array(
'name' => 'steam_gamename',
'type' => 'varchar',
'size' => 191,
'default' => '',
),
array(
'name' => 'steam_userid',
'type' => 'varchar',
'size' => 191,
'default' => '',
),
array(
'name' => 'steam_email',
'type' => 'varchar',
'size' => 191,
'default' => '',
),
),
array(
array(
'type' => 'primary',
'columns' => array('id_user')
),
),
array(),
'ignore'
);
}
}
if (!function_exists('check_table_exists_steamblock')) {
function check_table_exists_steamblock($table)
{
global $smcFunc, $db_prefix;

if ($smcFunc['db_list_tables'](false, $db_prefix . $table))
return true;

return false;
}
}

global $context, $user_info, $smcFunc, $txt, $settings;
$sideBlock = false;
$steamblockId = '_php01';
db_extend('packages');
if (!empty($sideBlock))
list($justify, $inputSize) = array('flex-start', '6');
else
list($justify, $inputSize) = array('space-around', '20');

$steam_text = array(
'name' => 'Game Name',
'id' => 'Steam ID',
'email' =>'Email',
'submit' => 'Submit',
'change' => 'Change',
'confirm_submit' => 'Submit new Steam data?',
'confirm_change' => 'Remove old Steam data?',
'missing_data_msg' => !$user_info['is_guest'] ? '<div style="width: 100%;overflow: hidden;text-align: center;box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.034), 0 6.7px 5.3px rgba(0, 0, 0, 0.048), 0 12.5px 10px rgba(0, 0, 0, 0.06), 0 22.3px 17.9px rgba(0, 0, 0, 0.072), 0 41.8px 33.4px rgba(0, 0, 0, 0.086), 0 100px 80px rgba(0, 0, 0, 0.12);">Enter your Steam data</div>' : '',
);
$steamblockOnce = true;
$missingData = !empty($_SESSION['steam_gamename']) && !empty($_SESSION['steam_userid']) && !empty($_SESSION['steam_email']) ? false : true;
$check = isset($_POST['steam_gamename' . $steamblockId]) || isset($_POST['steam_userid' . $steamblockId]) || isset($_POST['steam_email' . $steamblockId]) || isset($_POST['steam_reset' . $steamblockId]) ? true : false;
$filters = array('steam_gamename', 'steam_userid', 'steam_email');
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
$url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$disabled = $user_info['is_guest'] ? ' disabled' : '';
if (!$user_info['is_guest']) {
if ($missingData) {
create_db_table_steamblock();
$request =  $smcFunc['db_query']('','
SELECT id_user, steam_gamename, steam_userid, steam_email
FROM {db_prefix}steam_users_datablock
WHERE id_user = {int:userid}
LIMIT 1',
array(
'userid' => intval($user_info['id']),
)
);
while ($rowx = $smcFunc['db_fetch_assoc']($request)) {
list($_SESSION['steam_gamename'], $_SESSION['steam_userid'], $_SESSION['steam_email']) = array($rowx['steam_gamename'], $rowx['steam_userid'], $rowx['steam_email']);
}

$smcFunc['db_free_result']($request);
$missingData = !empty($_SESSION['steam_gamename']) && !empty($_SESSION['steam_userid']) && !empty($_SESSION['steam_email']) ? false : true;
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $check && !$user_info['is_guest']) {
foreach($_POST as $k => $v)
{
if (in_array($k, $filters, true)) {
$v = trim($v);
$v = preg_replace('/\s+/', '', $v);
$v = filter_var($v, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
$_POST[$k] = $v;
}
}

if (isset($_POST['steam_reset' . $steamblockId]) && $_POST['steam_reset' . $steamblockId] == 'reset') {
list($_SESSION['steam_gamename'], $_SESSION['steam_userid'], $_SESSION['steam_email'], $missingData) = array('', '', '', false);
create_db_table_steamblock();
$smcFunc['db_query']('','
DELETE FROM {db_prefix}steam_users_datablock
WHERE id_user = {int:userid}',
array(
'userid' => intval($user_info['id']),
),
);
}
else {
$_SESSION['steam_gamename'] = isset($_POST['steam_gamename' . $steamblockId]) ? $_POST['steam_gamename' . $steamblockId] : (!empty($_SESSION['steam_gamename']) ? $_SESSION['steam_gamename'] : '');
$_SESSION['steam_userid'] = isset($_POST['steam_userid' . $steamblockId]) ? $_POST['steam_userid' . $steamblockId] : (!empty($_SESSION['steam_userid']) ? $_SESSION['steam_userid'] : '');
$_SESSION['steam_email'] = isset($_POST['steam_email' . $steamblockId]) ? filter_var($_POST['steam_email' . $steamblockId], FILTER_SANITIZE_EMAIL) : (!empty($_SESSION['steam_email']) ? $_SESSION['steam_email'] : '');
foreach (array('steam_gamename', 'steam_userid', 'steam_email') as $input)
$_SESSION[$input] = trim($_SESSION[$input]);
}

// you can hash some of the the steam data if you decide to add a password
$missingData = !empty($_SESSION['steam_gamename']) && !empty($_SESSION['steam_userid']) && !empty($_SESSION['steam_email']) ? false : true;
if (!$missingData) {
create_db_table_steamblock();
$smcFunc['db_query']('','
DELETE FROM {db_prefix}steam_users_datablock
WHERE id_user = {int:userid}',
array(
'userid' => intval($user_info['id']),
),
);
$smcFunc['db_insert']('',
'{db_prefix}steam_users_datablock',
array(
'id_user' => 'int',
'steam_gamename' => 'string',
'steam_userid' => 'string',
'steam_email' => 'string',
),
array(
intval($user_info['id']),
$_SESSION['steam_gamename'],
$_SESSION['steam_userid'],
$_SESSION['steam_email']
),
array('id_user')
);
}
}
echo '
<script>
function steam_reset_confirmation' . $steamblockId . '() {
if (confirm("' . (!empty($missingData) ? $steam_text['confirm_submit'] : $steam_text['confirm_change']) . '") == true) {
document.getElementById("steam_postpage' . $steamblockId . '").submit();
}
else {
return false;
}
}
function ehsteam_onmouseover' . $steamblockId . '(buttonover) {
buttonover.style.backgroundImage = "linear-gradient(to right, #A9A9A9, #F8F8F8)";
buttonover.style.cursor = "pointer";
return false;
}
function ehsteam_onmouseout' . $steamblockId . '(buttonout) {
buttonout.style.backgroundImage = "linear-gradient(to left, #A9A9A9, #F8F8F8)";
buttonout.style.cursor = "normal";
return false;
}
</script>';

if (!empty($missingData)) {
echo '
<div style="display: flex; justify-content: ' . $justify . ';">
<form action="', htmlspecialchars($url), '" id="steam_postpage' . $steamblockId . '" name="steam_postpage' . $steamblockId . '" method="post" accept-charset="', $context['character_set'], '">
<div style="display: table;">
<div style="display: table-row;">
<div style="display: table-cell;" class="sp_left">
<label style="display: flex; justify-content: ' . $justify . ';" for="steam_gamename' . $steamblockId . '">', $steam_text['name'], ':</label>
<div style="display: inline;">' . (empty($_SESSION['steam_gamename']) ? '
<input' . $disabled . ' required placeholder="' . $steam_text['name'] . '" pattern=".*\S.*" type="text" class="steam_gamename" id="steam_gamename' . $steamblockId . '" name="steam_gamename' . $steamblockId . '" size="' . $inputSize . '" style="display: flex;align-items: center;width:100%;font: inherit;padding: 0.25rem 0.5rem;border: 0.125rem solid hsl(30, 76%, 10%);outline: none;" value="' . (!empty($_SESSION['steam_gamename']) ? $_SESSION['steam_gamename'] : '') . '" />' : $_SESSION['steam_gamename']) . '
</div>
</div>
</div>
<div style="display: table-row;">
<div style="display: table-cell;" class="sp_left">
<label style="display: flex; justify-content: ' . $justify . ';" for="steam_userid' . $steamblockId . '">', $steam_text['id'], ':</label>
<div style="display: inline;">' . (empty($_SESSION['steam_userid']) ? '
<input' . $disabled . ' required placeholder="' . $steam_text['id'] . '" pattern=".*\S.*" type="text" class="steam_userid" name="steam_userid' . $steamblockId . '" id="steam_userid' . $steamblockId . '" size="' . $inputSize . '" style="display: flex;align-items: center;width:100%;font: inherit;padding: 0.25rem 0.5rem;border: 0.125rem solid hsl(30, 76%, 10%);outline: none;" value="' . (!empty($_SESSION['steam_userid']) ? $_SESSION['steam_userid'] : '') . '" />' : $_SESSION['steam_userid']) . '
</div>
</div>
</div>
<div style="display: table-row;">
<div style="display: table-cell;" class="sp_left">
<label style="display: flex; justify-content: ' . $justify . ';" for="steam_email' . $steamblockId . '">', $steam_text['email'], ':</label>
<div style="display: inline;">' . (empty($_SESSION['steam_email']) ? '
<input' . $disabled . ' required placeholder="' . $steam_text['email'] . '" pattern=".*\S.*" type="text" class="steam_email" name="steam_email' . $steamblockId . '" id="steam_email' . $steamblockId . '" size="' . $inputSize . '" style="display: flex;align-items: center;width:100%;font: inherit;padding: 0.25rem 0.5rem;border: 0.125rem solid hsl(30, 76%, 10%);outline: none;" value="' . (!empty($_SESSION['steam_email']) ? $_SESSION['steam_email'] : '') . '" />' : $_SESSION['steam_email']) . '
</div>
</div>
</div>
<div style="display: table-row;">
<div style="display: table-cell;" class="sp_left" style="padding-top: 0.2rem;">
<input' . $disabled . ' style="background-image: linear-gradient(to left, #A9A9A9, #F8F8F8);" onmouseout="ehsteam_onmouseout' . $steamblockId . '(this)" onmouseover="ehsteam_onmouseover' . $steamblockId . '(this)" onclick="steam_reset_confirmation' . $steamblockId . '()" id="steamReset' . $steamblockId. '" type="button" value="' . $steam_text['submit'] . '" class="button_submit" />
</div>
</div>
</div>
<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
</form>
</div>
<div style="padding: 0.2rem 0rem 0.2rem 0rem;" class="alert">' . (!empty($missingData) ? $steam_text['missing_data_msg'] : '') . '</div>';
}
else {
echo '
<div style="overflow: hidden;display: flex; justify-content: ' . $justify . ';">
<form action="', htmlspecialchars($url), '" id="steam_postpage' . $steamblockId . '" name="steam_postpage' . $steamblockId . '" method="post" accept-charset="', $context['character_set'], '">
<div>
<div>
<div>
<div style="display: flex; justify-content: ' . $justify . ';">', $steam_text['name'], ':</div>
<div id="steam_gamename' . $steamblockId . '" style="display: inline;">' . $_SESSION['steam_gamename'] . '</div>
</div>
</div>
<div>
<div>
<div style="display: flex; justify-content: ' . $justify . ';">', $steam_text['id'], ':</div>
<div id="steam_userid' . $steamblockId . '" style="display: inline;">' . $_SESSION['steam_userid'] . '</div>
</div>
</div>
<div>
<div>
<div style="display: flex; justify-content: ' . $justify . ';">', $steam_text['email'], ':</div>
<div id="steam_email' . $steamblockId . '" style="display: inline;">' . $_SESSION['steam_email'] . '</div>
</div>
</div>
<div>
<div style="display: flex; justify-content: ' . $justify . ';" class="ehPortal_cell" style="padding-top: 0.2rem;">
<input' . $disabled . ' id="steamReset' . $steamblockId. '" style="background-image: linear-gradient(to left, #A9A9A9, #F8F8F8);" onmouseout="ehsteam_onmouseout' . $steamblockId . '(this)" onmouseover="ehsteam_onmouseover' . $steamblockId . '(this)" onclick="steam_reset_confirmation' . $steamblockId . '()" type="button" value="' . $steam_text['change'] . '" class="button_submit" />
</div>
</div>
</div>
<input type="hidden" id="steam_reset' . $steamblockId . '" name="steam_reset' . $steamblockId . '" value="reset" />
<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
</form>
</div>
<div style="padding: 0.2rem 0rem 0.2rem 0rem;" class="alert">' . (!empty($missingData) ? $steam_text['missing_data_msg'] : '') . '</div>';
}