Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 740683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:32:40+00:00 2026-05-14T08:32:40+00:00

Here is my current problem. I am working with the chat module and I’m

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:32:40+00:00Added an answer on May 14, 2026 at 8:32 am

    Well, it’s been a while and I finally figured out my problem, but I realized that if anyone else found this page and wanted an answer, they were out of luck. So here was the problem.

    Sine the handler for the AJAX call used Drupal functions, I had to bootstrap Drupal (used above, but not shown). However, when I bootstrapped Drupal, I did a full bootstrap. This caused the Chat Module to call a hook that checked for invites. I didn’t realize that this was being called, because in normal use, nothing ever notified me… Anyways, the hook is meant to check for notifications and alert the user (somehow.. i do not know how) and when it checked, it set the notified flag to true.

    So, by the time that my AJAX handler was being called, the invite had already been set to notified by the ChatRoom module. So, my solution was to only to a partial bootstrap. The code for the bootstrap is below. I found the script on someone else’s website, but I’m not sure what it is. Anyways… here’s the code:

    <?php
        #bootstrap drupal to get access to drupal functions
        define('STRIP_LEN', -41); #length of path to use (strip off stuff like /sites/all/...)
        $base_url =  substr(getcwd(), 0, STRIP_LEN);
        chdir($base_url);
        global $base_url;
    
        $base_root = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
    
        $base_url = $base_root .= '://' . preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
    
        if( $dir = trim( dirname( $_SERVER['SCRIPT_NAME'] ), '\,/' ) )
        {
            $base_path = "/$dir";
            $base_url .= $base_path;
        }
        $base_url = substr($base_url, 0, STRIP_LEN);
    
    
        require_once './includes/bootstrap.inc';
        require_once './includes/common.inc';
    
        drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
    
        require_once drupal_get_path('module', '_chat_whos_online') . '/_chat_whos_online.inc';
    
        #END BOOTSTRAPPING
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 438k
  • Answers 438k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, the easiest way would be to expose the bind… May 15, 2026 at 4:30 pm
  • Editorial Team
    Editorial Team added an answer It's potentially less efficient, but it depends on your JVM.… May 15, 2026 at 4:30 pm
  • Editorial Team
    Editorial Team added an answer You are using a reserved word (Date). Set it to… May 15, 2026 at 4:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.