Un nouveau code de ce matin !
Créer un fichier info_embedded5.php (puisque le 4 est déjà pris
Il contiendra ceci :
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
/**
If this file is not in the FlashChat root folder, then change this
path to the location of the inc/common.php file.
*/
$GLOBALS['my_file_name'] = 'info_embedded5';
require_once('inc/common.php');
ChatServer::purgeExpired();
/**
Retrieves the number of users who are chatting in any room.
Leave the $room parameter empty to return the number of users in all room.
*/
function numusers( $room = '' )
{
if($room)
{
$stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND userid <> ? AND roomid=?",214);
$rs = $stmt->process( SPY_USERID , $room );
}
else
{
$stmt = new Statement("SELECT COUNT(*) AS numb FROM {$GLOBALS['fc_config']['db']['pref']}connections,{$GLOBALS['fc_config']['db']['pref']}rooms
WHERE userid IS NOT NULL AND userid <> ? AND ispublic IS NOT NULL
AND {$GLOBALS['fc_config']['db']['pref']}connections.roomid = {$GLOBALS['fc_config']['db']['pref']}rooms.id");
$rs = $stmt->process( SPY_USERID );
}
$rec = $rs->next();
return $rec?$rec['numb']:0;
}
/**
Retrieves a list of the users (by login ID) who are in $room.
Leave the $room parameter empty to return a list of all users in all rooms.
*/
function usersinroom( $room = '' )
{
$list = array();
if($room) {
$stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND userid <> ? AND roomid=?");
$rs = $stmt->process( SPY_USERID , $room);
} else {
$stmt = new Statement("SELECT userid, state, color, lang, roomid FROM {$GLOBALS['fc_config']['db']['pref']}connections WHERE userid IS NOT NULL AND userid <> ? ");
$rs = $stmt->process( SPY_USERID );
}
while($rec = $rs->next())
{
$usr = ChatServer::getUser($rec['userid']);
if($usr == null && $GLOBALS['fc_config']['enableBots']) $usr = $GLOBALS['fc_config']['bot']->getUser($rec['userid']);
$list[] = array_merge($usr, $rec);
}
return $list;
}
/**
Retrieves a list of all available rooms, as an array.
*/
function roomlist()
{
$list = array();
// populate $list with the names of all available rooms
$stmt = new Statement('SELECT * FROM '.$GLOBALS['fc_config']['db']['pref'].'rooms WHERE ispublic IS NOT NULL order by ispermanent' , 54 );
$rs = $stmt->process();
while($rec = $rs->next()) $list[] = $rec;
//result will be an array of arrays like ('id' => <room id>, 'updated' = <timestamp>, 'created' => <timestamp>, 'name' => <room name>, 'ispublic' => <public flag>, 'ispermanent' => <autoclose flag>)
return $list;
}
$rooms = roomlist();
$roomnumb = sizeof($rooms);
$usernumb = numusers();
?>
<html>
<head>
<title>Qui est sur le tchat</title>
<meta http-equiv=Content-Type content="text/html; charset=8859-1">
<style type="text/css">
<!--
body { background-color: transparent; margin: 0; padding: 0; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; font-size: 10px;}
.normal {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: normal;
margin: 0; padding: 0;
text-align: left;
}
#roomList { margin: 0; padding: 0; }
#roomList a { color: black; text-decoration: none; }
#roomList a:hover { text-decoration: underline; }
.userList { margin-left: 5px; margin-right: 0; margin-bottom: 0; margin-top: 0; padding: 0; }
-->
</style>
<script type="text/javascript">
</script>
</head>
<body>
<p class="normal"><?php echo $usernumb ?> membre<?php if ($usernumb > 1) echo "s" ?> connecté<?php if ($usernumb > 1) echo "s"; ?>.</p><br />
<ul id="roomList">
<?php if($roomnumb) { ?>
<?php foreach($rooms as $room) { ?>
<form name="form_<?php echo $room['id']; ?>">
<!-- <select name="sel_<?php echo $room['name']; ?>" onchange="location=this.options[this.options.selectedIndex].value"> -->
<select name="sel_<?php echo $room['id']; ?>" onchange="window.open(form_<?php echo $room['id']; ?>.sel_<?php echo $room['id']; ?>.options[selectedIndex].value)">
<?php
echo "<option value='".XOOPS_URL."/chat/flashchat.php' selected>".$room['name']." (".numusers($room['id']).")</option>";
echo "<option value='".XOOPS_URL."/chat/flashchat.php'>Accéder au tchat</option>";
$users = usersinroom($room['id']);
if ($users) {
foreach( $users as $user )
{
echo "<option value="".XOOPS_URL."/userinfo.php?uid=".$user['userid']."">".$user['login']."</option>";
}
}
?> </select><!-- <input type="submit" value="Go" /> --></form>
<?php } ?>
<?php } ?>
</ul>
</body>
</html>
Créer un bloc personnalisé (html), contenant ce code :
<iframe frameborder="0" src="http://votre_site/chat/info_embedded5.php" style="width: 100%; margin: 0; padding: 0; border: 0; overflow: hidden;" scrolling="no" border="0" allowtransparency="true"></iframe>
Pensez à changer l'adresse du site et éventuellement le nom du dossier contenant votre tchat.
Vous aurez le rendu que l'on voit sur les captures d'écran ci-jointes.
Il y a un lien pour accéder au tchat dans chaque menu déroulant (ouvre une nouvelle fenêtre), et on accède au profil d'un membre en sélectionnant son nom dans le menu déroulant (nouvelle fenêtre par défaut, mais j'ai laissé dans le code, ce qu'il faut pour ouvrir le profil dans la fenêtre courante, il suffit de décommenter la ligne 128 et commenter la ligne 129).