fetch user from database in ajax_chat-0.8.3 software

ajax_chat-0.8.3 software is free and you can download it form the site https://blueimp.net/ajax/ and install it. in this software you get 4 users which is static and if you need dynamic users and fetch that users from the database then you need to do some setting in the code provided by the ajax_chat module.

i will help you to fetch dynamic users in the chat module, once you did this then all your registered user can login in this module and chat with each other.

if you look in the installed directory then there is lib/data/users.php file, if you open this then you get below code

 
<?php
/*
 * @package AJAX_Chat
 * @author Sebastian Tschan
 * @copyright (c) Sebastian Tschan
 * @license GNU Affero General Public License
 * @link https://blueimp.net/ajax/
 */
 
// List containing the registered chat users:
$users = array();
 
// Default guest user (don't delete this one):
$users[0] = array();
$users[0]['userRole'] = AJAX_CHAT_GUEST;
$users[0]['userName'] = null;
$users[0]['password'] = null;
$users[0]['channels'] = array(0);
 
// Sample admin user:
$users[1] = array();
$users[1]['userRole'] = AJAX_CHAT_ADMIN;
$users[1]['userName'] = 'admin';
$users[1]['password'] = 'admin';
$users[1]['channels'] = array(0,1);
 
// Sample moderator user:
$users[2] = array();
$users[2]['userRole'] = AJAX_CHAT_MODERATOR;
$users[2]['userName'] = 'moderator';
$users[2]['password'] = 'moderator';
$users[2]['channels'] = array(0,1);
 
// Sample registered user:
$users[3] = array();
$users[3]['userRole'] = AJAX_CHAT_USER;
$users[3]['userName'] = 'user';
$users[3]['password'] = 'user';
$users[3]['channels'] = array(0,1);
?>

Replace this code with the below code but please do not forgot to set your table name and field names as per your database.

 
<?php
/*
 * @package AJAX_Chat
 * @author Sebastian Tschan
 * @copyright (c) Sebastian Tschan
 * @license GNU Affero General Public License
 * @link https://blueimp.net/ajax/
 */
 
// List containing the registered chat users:
$users = array();
 
$sql = "SELECT * FROM tbl_registered_user";
$result = $this->db->sqlQuery($sql);
if($result->numRows() > 0) {
 $condition = '';
 $i=0;
 while($row = $result->fetch()) 
 {	
	$users[$i] = array();
	$users[$i]['userRole'] = AJAX_CHAT_ADMIN;  // you can assign role as you want
	$users[$i]['userName'] = $row['username'];
	$users[$i]['password'] = $row['password'];
	$users[$i]['channels'] = array(0,1);;
	$i++;
 }
}
?>

same way you can change the channels as well, here channels means the chat room. please let me know if you need help to set the channels in ajax_chat module.

how to change menu in ajax chat module

There is ready made module named ajax chat which is free download from the internet, i used that software and i need some changes in that, if you logged in that chat module then you will see that there is menu with below options

Logout
List online users
List ignored users
List available channels
Describe action
Roll dice
Change username
Enter private room

if you want to change the label text for above menu then you can change it. first go to the folder installedfolder/lib/lang/, here you will find the 35 language files. as per your language setting choose appropriate file. open that file and then you will see the lang array, you can change any label from that file.

if you want to remove any item from the menu then you need to go installedfolder/js/chat.js, in this file find the below code as per my knowledge its on line 1114.

 
menu = '<li><a href="javascript:ajaxChat.sendMessageWrapper(\'/quit\');">'
        + this.lang['userMenuLogout']
        + '</a></li>'
        + '<li><a href="javascript:ajaxChat.sendMessageWrapper(\'/who\');">'
        + this.lang['userMenuWho']
        + '</a></li>'
        + '<li><a href="javascript:ajaxChat.sendMessageWrapper(\'/ignore\');">'
        + this.lang['userMenuIgnoreList']
        + '</a></li>'
        + '<li><a href="javascript:ajaxChat.sendMessageWrapper(\'/list\');">'
        + this.lang['userMenuList']
        + '</a></li>'
        + '<li><a href="javascript:ajaxChat.insertMessageWrapper(\'/action \');">'
        + this.lang['userMenuAction']
        + '</a></li>'
        + '<li><a href="javascript:ajaxChat.insertMessageWrapper(\'/roll \');">'
        + this.lang['userMenuRoll']
        + '</a></li>'
        + '<li><a href="javascript:ajaxChat.insertMessageWrapper(\'/nick \');">'
        + this.lang['userMenuNick']
        + '</a></li>'
        ;

in the above option find the menu item which you want to remove and then remove it from starting li element to end of li elements. save the file and you did it.