Hey Everyone,
Here is my current problem. I am working with the chat module and I'm building a module that notifies users via AJAX that they have been invited to a chat. The current table structure for the invites table looks like this:
|-------------------------------------------------------------------------|
| CCID | NID | INVITER_UID | INVITEE_UID | NOTIFIED | ACCEPTED |
|-------------------------------------------------------------------------|
| int | int | int | int | (0 or 1) | (0 or 1) |
|-------------------------------------------------------------------------|
I'm using the periodical updater plug-in for JQuery to continually poll the server to check for invites. When an invite is found, I set the notified from 0 to 1. However, my problem is the periodical updater. When I first see that there is an invite, I notify the user, and set notified to 1. On the next select though, I get the same results before, as if the update didn't work. But, when I got check the database, I can see that it worked just fine. It's as if the query is querying a cache, but I can't figure it out.
My code for the periodical updater is as follows:
window.onload = function() {
var uid = $('a#chat_uid').html();
$.PeriodicalUpdater(
'/steelylib/sites/all/modules/_chat_whos_online/ajax/ajax.php', //url to service
{
method: 'get', //send data via...
data: {uid: uid}, //data to send
minTimeout: '1000', //min time before server is polled (milli-sec.)
maxTimeout: '20000', //max time before server is polled (milli-sec.)
multiplyer: '1.5', //multiply against curretn poll time every time constant data is returned
type: 'text', //type of data recieved (response type)
maxCalls: 0, //max calls to make (0=unlimited)
autoStop: 0 //max calls with constant data (0=unlimited/disabled)
},
function(data) //callback function
{
alert( data ); //for now, until i get it working
}
);
}
And my code for the ajax call is as follows:
<?php
#bootstrap Drupal, and call function, passing current user's uid.
function _create_chat_node_check_invites($uid)
{
cache_clear_all('chatroom_chat_list', 'cache');
$query = "SELECT * FROM {chatroom_chat_invite} WHERE notified=0 AND invitee_uid=%d and accepted=0";
$query_results = db_query( $query, $uid );
$json = '{"invites":[';
while( $row = db_fetch_object($query_results) )
{
var_dump($row);
global $base_url;
$url = $base_url . '/content/privatechat' . $uid .'-' . $row->inviter_uid;
$inviter = db_fetch_object( db_query( "SELECT name FROM {users} WHERE uid = %d", $row->inviter_uid ) );
$invitee = db_fetch_object( db_query( "SELECT name FROM {users} WHERE uid = %d", $row->invitee_uid ) );
#reset table
$query = "UPDATE {chatroom_chat_invite} "
."SET notified=1 "
."WHERE inviter_uid=%d AND invitee_uid=%d";
db_query( $query, $row->inviter_uid, $row->invitee_uid );
$json .= '[';
$json .= '"' . $url . '",';
$json .= '"' . ($inviter->name) . '",';
$json .= '"' . ($invitee->name) . '"' ;
$json .= '],';
}
$json = substr($json, 0, -1);
$json .= ']}';
return $json;
}
?>
I can't figure out what is going wrong, any help is greatly appreciated!