// This action will be called every X seconds from the chat page // to post a new message (if there is a new message) // and then fetch the list of un-seen/new messages since the last fetch $newmsg = get_POST_var('newmsg'); $lmsgid = get_POST_var('LMSGID'); $roomid = get_POST_var('ROOMID'); if ($newmsg) { $success = execute_sqlInsert('tbl_ChatRooms', array('saidBy_username' => $USERNAME, 'saidBy_empl_id' => $CURRENT_USERID, 'message_base64' => base64_encode(htmlentities(base64_decode($newmsg), ENT_QUOTES)), 'message_plain_mysqlescaped' => base64_decode($newmsg), 'chatRoom' => $roomid)); } register_LastPingAt(); $newMsgCount = executesql_returnArray("select count(msgid) as newmsgcount from tbl_ChatRooms where chatRoom='{$roomid}' AND msgid > {$lmsgid}"); if (!$newMsgCount) { send_Action_Response('Success', " NEW_MESSAGES = [] ; LASTFETCHEDMSGID = {$lmsgid} ;"); } $TMC = new ManageChatRooms(); $NMFR = $TMC->get_NewMessages_fromRoom(array('condition' => 'NewerThan', 'value' => $lmsgid), $roomid, $CURRENT_USERID); send_Action_Response('Success', " NEW_MESSAGES = " . json_encode($NMFR['NEW_MESSAGES']) . "; LASTFETCHEDMSGID = {$NMFR['LASTFETCHEDMSGID']} ;"); exit; break; case 'post_direct_message': // Post Direct Messages between users $newmsg = get_POST_var('newmsg'); $to_user = get_POST_var('to_user'); if ($newmsg) { $MU = new ManageUsers(); $MU->userId = $_SESSION['empl_id']; $success = $MU->send_DirectMessageTo($to_user, $newmsg); } register_LastPingAt(); send_Action_Response('Success', '1'); exit;
?> " ; var CHAT_USERS = {}; var LASTMSG_10_MIN_INTERVAL = '0000-00-00 00:0' ; var MY_NAME = '<?php echo $CURRENT_USER; ?> '; var lastmsg_user = ''; var umsg_bgclr = ''; <?php // Load last 100 messages into an array NEW_MESSAGES // and get the LASTFETCHEDMSGID $TMC = new ManageChatRooms(); $NMFR = $TMC->get_NewMessages_fromRoom(array('condition' => 'lastXMessages', 'value' => 1500), $rid, $CURRENT_USERID); echo " NEW_MESSAGES = " . json_encode($NMFR['NEW_MESSAGES']) . " ; "; echo " LASTFETCHEDMSGID = {$NMFR['LASTFETCHEDMSGID']} ;"; ?> var append_NEW_MESSAGES = function(){ var jq_div_ml = $("#tbl_messageLog") ; $("#tbl_messageLog TBODY TR.tmpmsg").remove(); var append_message = function( nmsg ){ // nmsg = { msgBy : '' , msgTime : '' , msg_base64 : '' } // show time if first 15 characters (same 10 minute interval) of '2010-10-09 04:31:42' is different than LASTMSG_TIME var thisMsg_10minuteInterval = nmsg.msgTime.substring(0, 15) ; if( thisMsg_10minuteInterval != LASTMSG_10_MIN_INTERVAL ){ var timeStampDiv = "<TR><TD></TD><TD class='msgtime' colspan=2>" + nmsg.msgTime.timestamp_to_Date() + "</TD></TR>";