(English translation)
Hello
I found some code to display a logon form on all the pages on a site. I'm not the author of this code; I simply found it on a mod; Can't recall which, but it works. Its author will know who he is.
Before the doctype of the document, add the following lines:
<?php
// Add these lines in the very top of your code
define('FORUM_ROOT', './forum/');
require FORUM_ROOT.'include/common.php';
?>
Next, where you want the logon form to be displayed, add the following code. Logged-on members can also see the avatar:
<?php
// If user is logged display some informations about it
if (!$forum_user['is_guest'])
{
require FORUM_ROOT.'lang/'.$forum_user['language'].'/index.php';
if ($forum_config['o_users_online'] == '1')
{
// Fetch users online info and generate strings for output
$query = array(
'SELECT' => 'o.user_id, o.ident',
'FROM' => 'online AS o',
'WHERE' => 'o.idle=0',
'ORDER BY' => 'o.ident'
);
$result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
$num_guests = 0;
$users = array();
while ($forum_user_online = $forum_db->fetch_assoc($result))
{
if ($forum_user_online['user_id'] > 1)
$users[] = '<a href="'.forum_link($forum_url['user'], $forum_user_online['user_id']).'">'.forum_htmlencode($forum_user_online['ident']).'</a>';
else
++$num_guests;
}
// If there are registered users logged in, list them
if (count($users) > 0)
//$users_online = '<p><strong>'.$forum_user['Online'].'</strong> '.implode(', ', $users).'</p>';<!--Décommenter cette ligne pour afficher les utilisateurs en ligne-->
$stats_online[] = 'Membres en ligne: <strong>'.count($users).'</strong><br />';
$stats_online[] = 'Visiteurs en ligne: <strong>'.$num_guests.'</strong>';
}
$avatar = generate_avatar_markup($forum_user['id']);
?>
<?php echo Bienvenue ?>: <strong><?php echo forum_htmlencode($forum_user['username']) ?> </strong> <br />
<?php echo $links['logout'] = '<span id="navlogout"><a href="'.forum_link($forum_url['logout'], array($forum_user['id'], generate_form_token('logout'.$forum_user['id']))).'">'.$lang_common['Logout'].'</a></span> | ';?>
<?php echo $links['profile'] = '<span id="navprofile"'.((substr(FORUM_PAGE, 0, 7) == 'profile') ? ' class="isactive"' : '').'><a href="'.forum_link($forum_url['user'], $forum_user['id']).'">'.$lang_common['Profile'].'</a></span> | ';?>
<?php echo $links['userlist'] = '<span id="navuserlist"'.((FORUM_PAGE == 'userlist') ? ' class="isactive"' : '').'><a href="'.forum_link($forum_url['users']).'">'.$lang_common['User list'].'</a></span>';?>
<?php if ($avatar != '') : ?>
<?php echo $avatar ?>
<?php else : ?>
<?php endif; ?>
<ul class="stats-online">
<?php echo implode("\n\t\t\t", $stats_online) ?>
</ul>
<?php //if (isset($users_online)) : echo $users_online; endif; ?><!--Décommenter cette ligne pour afficher les utilisateurs en ligne-->
<?php
}
// Else user is not logged, display login form
else
{
$cur_panel['title'] = $lang_common['Login'];
require_once FORUM_ROOT.'lang/'.$forum_user['language'].'/login.php';
$form_action = forum_link($forum_url['login']);
?>
<?php echo Bienvenue ?>: <strong><?php echo $lang_login['Guest'] ?></strong> <br />
<?php echo $lang_login['Please login'] ?><br />
<a href="<?php echo forum_link($forum_url['register']) ?>"><?php echo $lang_login['Register'] ?></a>
<a href="<?php echo forum_link($forum_url['request_password']) ?>"><?php echo $lang_login['New password'] ?></a><br />
<form method="post" action="<?php echo $form_action ?>">
<div class="hidden">
<input type="hidden" name="form_sent" value="1" />
<input type="hidden" name="redirect_url" value="<?php echo get_current_url() ?>" />
<input type="hidden" name="csrf_token" value="<?php echo generate_form_token($form_action) ?>" />
</div>
<div class="panel-input">
<?php echo $lang_login['Username'] ?>
<input type="text" name="req_username" size="13" /><br />
</div>
<div class="panel-input">
<?php echo $lang_login['Password'] ?>
<input type="password" name="req_password" size="13" /><br />
</div>
<div>
<label for="fld-remember-me"><span class="fld-label"><?php echo $lang_login['Remember me'] ?></span> <input type="checkbox" id="fld-remember-me" name="save_pass" value="1" /></label>
<span class="submit"><input type="submit" name="login" value="<?php echo $lang_common['Login'] ?>" /></span>
</div>
</form><?php
}
// this variable is also used for display statistics on forums page
unset($stats_list);
?>
Obviously, this code requires adding the extra links contained in the navlinks. Personally, I don't need more than that.
To the login file of your "language pack" (?), add the following lines (translate according to your needs):
'Guest' => 'Visiteur',
'Welcome' => 'Bienvenue',
'Please login' => 'Déjà inscrit? Connectez-vous.',
'Register' => 'S\'enregistrer',
'New password' => 'Redéfinir mot de passe'
Finally, you'll have to create some CSS based on the theme of your site. This code works fine. It could require some thorough code inspection, but I don't know PHP.