ok here goes nothing

, note that these changes are made in Ajaxchat for J 1.5 version 0.1c.
Also note that I have not made any effort yet to add a switch in the backend, that still have to be made, I also don't allow public access to the chat only registered, I don't know if that crashes something, but I don't think so.
ajaxchat.class.php
- replace the newmessages function
function newMessages($roomid, $recipient, &$sess, $exclude = false) {
global $_COOKIE, $my, $ajaxChat_config;
// make sure there is a session
if (!$sess->session == $_COOKIE['ajax_chat_user']) {
$this->error( 201, 'Session is invalid.');
return false;
}
// select the new messages in the specified room for the user
if (!$exclude) {
$query = "SELECT ac.id AS id, ac.username AS username, u.name AS name, msg, time, DATE_FORMAT(time, '%h%:%i:%s%p')AS f_time , recipient ".
"FROM #__ajax_chat AS ac, #__users AS u WHERE userid = u.id AND ac.id > '".$sess->last_request_id."' AND room_id = '".$roomid."'".
" AND (".
"(recipient = '".$recipient."' AND room_id != '-1') ". // non private messages
"OR (recipient = '".$my->username."' AND ac.username = '".$recipient."') ". // pms sent to user by recipient
"OR (recipient = '".$recipient."' AND ac.username = '".$my->username."')". // pms sent to recipient by user
")".
($ajaxChat_config['_presence'] ? "" : " AND type != 'system'").
" ORDER BY id ASC";
} else {
$query = "SELECT ac.id AS id, ac.username AS username, u.name AS name, msg, time, DATE_FORMAT(time, '%h%:%i:%s%p')AS f_time , recipient ".
"FROM #__ajax_chat AS ac, #__users AS u WHERE userid = u.id AND ac.id > '".$sess->last_request_id."' AND room_id = '".$roomid."'".
" AND (".
"(recipient = '".$recipient."' AND room_id != '-1' AND ac.username != '".$exclude."') ". // non private messages not by me
"OR (recipient = '".$my->username."' AND ac.username = '".$recipient."') ". // pms sent to me
")".
($ajaxChat_config['_presence'] ? "" : " AND type != 'system'").
" ORDER BY id ASC";
}
$this->_db->setQuery( $query );
$msgs = $this->_db->loadObjectList();
// select the last chat msg id, user can only view msgs after this
$msgs_count = count($msgs);
if ($msgs_count > 0) {
$lr_id = $msgs[$msgs_count - 1]->id;
echo '<!-- new messages last id: '.$lr_id.' //-->';
// update the last request id and time
$query = "UPDATE #__ajax_chat_sessions SET ".
"last_request_time = CURRENT_TIMESTAMP(), last_request_id = '".$lr_id."'".
" WHERE session = '".$sess->session."' AND room_id = '".$roomid."'".
" AND recipient = '".$recipient."' LIMIT 1";
$this->_db->setQuery( $query );
$this->_db->query();
return $msgs;
} else {
// update the last request time
$query = "UPDATE #__ajax_chat_sessions SET ".
"last_request_time = CURRENT_TIMESTAMP() ".
" WHERE session = '".$sess->session."' AND room_id = '".$roomid."'".
" AND recipient = '".$recipient."' LIMIT 1";
$this->_db->setQuery( $query );
$this->_db->query();
$this->error('0', 'No new Messages; roomid: '.$roomid.' recipient: '.$recipient.' username: '.$my->username.' ; last request time updated.');
}
}
ajaxchat.xml.php
- replace the show_newmsgs_xml funtion
function show_newmsgs_xml( $msgs ) {
global $database, $Itemid;
//HTML_ajaxchat::debug(count($msgs), 'count of messages');
if (count($msgs) > 0) {
echo '<msgs count="'.count($msgs).'">';
foreach( $msgs as $msg) {
if (showrealnames) { //switch between realnames or usernames
echo '<msg user="'. $msg->name .'" userid="'.$msg->userid.'"'.
' ftime="'.$msg->f_time.'" recipient="'.$msg->recipient.'">';}
else {
echo '<msg user="'. $msg->username .'" userid="'.$msg->userid.'"'.
' ftime="'.$msg->f_time.'" recipient="'.$msg->recipient.'">';}
echo XML_ajaxchat::cAttr($msg->msg);
echo '</msg>'."\n";
}
echo '</msgs>';
} else {
echo '<msgs count="0" />';
}
}
You should now be able to see real names in all chat windows. Now we might want to change the names in the online users screen.
Change the following code.
ajaxchat.php
- replace showchatters function
function showChatters($roomid) { // show chatters.
global $database, $my;
HTML_ajaxchat::send_xmlHeaders(); // sends text/xml header
$auth = new ajc_authentication; // authentication class instance
if (!$session = $auth->authenticateSession($roomid)) { // valid session required
HTML_ajaxchat::show_response_xml('-2', 'Session invalid. (roomid: '.$roomid.')');
return;
}
if ($roomid == '-1') { // stop views to pms
HTML_ajaxchat::show_response_xml('-2', 'You cannot view PM room');
return;
}
// get the list of users in the room todo: online time offset to cfg
$query = "SELECT * FROM #__ajax_chat_sessions, #__users AS u WHERE u.id = userid AND room_id = '".$roomid."' "."
AND last_request_time+1000 > CURRENT_TIMESTAMP() LIMIT 100"; // todo: get in parts
$database->setQuery( $query );
$users_row = $database->loadObjectList();
HTML_ajaxchat::showChatters($users_row, $roomid);
} // show chatters
ajaxchat.xml.php
-replace showchatters function
function showChatters($sessions, $roomid) { // display all users (sessions) in a room
if (count($sessions) > 0) {
echo '<users count="'.count($sessions).'">';
foreach($sessions as $session) { // iterate through users
if (showrealnames) {
echo '<user id="'.$session->userid.'" name="'.$session->username.'" displayname="'.$session->name.'" status="'.$session->status.'" />';
} else {
echo '<user id="'.$session->userid.'" name="'.$session->username.'" displayname="'.$session->username.'" status="'.$session->status.'" />';
}
echo '</users>';
} else {
echo '<users count="'.count($sessions).'" />';
}
} // users func
ajaxchat.functions.js
-replace function getuserlink
-replace function displayusers
function displayUsers(myAJAX) {
try {
if (loggingOut == true) return; // drop on logout
var users_div = document.getElementById('users');
if (myAJAX.readyState == 4) {
if (myAJAX.status == 200) {
if (!users_div) {
// no users div, stop getting users online data
clearTimeout(usersTimer);
usersTimer = null; alert('no users');
return false;
}
var xml = myAJAX.responseXML;
var text = myAJAX.responseText;
logger('Response text/xml: ' + text);
// parse the xml
if (xml) {
if (xml.documentElement) {
var users = xml.documentElement.getElementsByTagName("user");
//logger(messages);
if (users.length > 0) {
var div = '';
users_div.innerHTML = '';
for (var i = 0; i < users.length; i++) {
var userid = users[i].getAttributeNode("id").nodeValue;
var username = users[i].getAttributeNode("name").nodeValue;
var name = users[i].getAttributeNode("displayname").nodeValue;
var userStatus = users[i].getAttributeNode("status").nodeValue;
var userLink = getUserLink(username, name);
if (users_table_row_classname_suffix) // highlight my->username
var sectid = (username == myusername) ? "2" : "1";
else var sectid = '';
if (ajc_users_style != 'default') {
addmsgRow("<b>" + userLink + "</b>", userStatus, users_table_row_classname_suffix+sectid, 'users', ajc_users_style);
} else {
var bgcolor = '';
div += "<tr class=\"" + users_table_row_classname + sectid + "\">";
div += "<td valign=\"top\" bgcolor=\"" + bgcolor + "\">" +
"<b>" + userLink + "</b></td>";
div += "<td width=\"60%\" valign=\"top\" bgcolor=\"" + bgcolor + "\"><i>"
+ userStatus + "</i></td>";
div += "</tr>";
}
}
if (ajc_users_style == 'default') {
users_div.innerHTML = '<table class="'+users_table_classname+'"><tbody>'+div+'</tbody></table>';
}
} else {
logger('no users logged in.');
// make sure we have a connection
validateResponse(xml);
}
}
}
} else {
logger("There was a problem retrieving the XML data:\n" + myAJAX.statusText);
}
requestMode_users = false;
if (_setTimeout_users) {
usersTimer = setTimeout('showUsers(' + roomid + ')', period_users);
} else { _setTimeout_users = true; }
}
} catch(e) { return false; }
} // display users
// write the users link
function getUserLink(username,name) {
if (username == myusername) return name; // no link for self
var linkHtml = '<a href="javascript:;" onclick="privateChat(\''+username+'\');return false;">'+name+'</a>';
return linkHtml;
}
I hope I've posted everything, if it is not working let me know and I will send you a zip of the code.
regards