LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   How to create table in Joomla and store user at chat (http://www.linuxquestions.org/questions/programming-9/how-to-create-table-in-joomla-and-store-user-at-chat-789341/)

latino 02-15-2010 08:36 PM

How to create table in Joomla and store user at chat
 
Hi:

I need to be able to store users logged at chat server. The chat program stores the login information in a text file (no db). I need a modification so the user info is read from the flat file and stores into a table in Joomla db. I don't have access to source for making the Java Chat Server store the data directly to joomla db is not possible.

Any pointer will be appreciated.

Below if the code that read s the information from Java Chat Server.

Code:

        function chat_getChattersFromLocalServer()
        {
                $room = array();
                $room['connections'] = 0;
                $room['logon_users'] = 0;
                $room['room_numbers'] = 0;
       
                $online_file = $this->chatdatapath."online.txt";

                if (!file_exists($online_file))
                {
                        return $room;
                }
       
                if (!$row = file($online_file))
                {
                        return $room;
                }
       
                $room_data = explode("|", $row[0]);
       
       
                if (count($room_data) == 3)
                {
                        $room['connections'] =        intval($room_data[0]);
                        $room['logon_users'] =        intval($room_data[1]);
                        $room['room_numbers'] = intval($room_data[2]);
                }
                return $room;
        }

The data that I need is username, online (on / off), date. Regarding the db table, I think this could do the trick:
Code:

CREATE TABLE IF NOT EXISTS `#__chatusers` (
                                        `id` int(10) NOT NULL auto_increment,
                                        `userid` int(10) NOT NULL,
                                        `loginstatus` varchar(15) NOT NULL,
                                        `logdate` datetime default NULL,
                                        PRIMARY KEY (`id`)
                                ) TYPE=MyISAM


I need some help because I don't want to mess the db. Also, I am not sure how to make the script store (php) the data into the db. I am not a programmer but can mod this with the guidance and help of LQ.org... I hope someone will help me with this.


Thanks in Advance.

Guttorm 02-16-2010 09:41 AM

Hi

The PHP code you posted doesn't read that information from the text file. What it does is that it tries to get 3 different integer values:
- connections
- logon_users
- room_numbers

It looks for a file called online.txt in "chatdatapath", and if found it reads the file, and skips everything except the first line. If the first line contains two | characters, it returns the numbers in that line, which should be like this: "connections|logon_users|room_numbers". If the file is not found, or the format is different, it returns 0 for all the 3 numbers.

So the information about who is online must be somewhere else. It could be it's below the first line? Can you post it? If the file seems to contain the information you want, it's probably possible to make an SQL statement to fill the table from the text file.

Here's a link that explain the SQL to load data from text files into a database table:

http://dev.mysql.com/doc/refman/5.1/en/load-data.html

latino 02-16-2010 06:52 PM

Hi Guttorm:

I think the code below is the one that actually get the user list (connected to the chat).

Code:

function chat_getChatterListFromLocalServer()
        {
                $userListStr = "";
       
                $d = @dir($this->chatdatapath);
                if(is_object($d))
                {
                        while (false !== ($entry = $d->read()))
                        {
                          $rest = substr($entry, 0, 5);
                          if ($rest == "room_")
                          {
                       
                                if (file_exists($this->chatdatapath.$entry))
                                {
                               
                                        $f_users = file($this->chatdatapath.$entry);
                               
                                        for ($i = 0; $i < count($f_users); $i ++)
                                        {
                                                $f_line = trim($f_users[$i]);
                                       
                                                if ($f_line != "")
                                                {
                                                        $userListStr = ($userListStr == "") ? $f_line : $userListStr. "," . $f_line;
                                                }
                                        }
                                        $userListStr = (empty($userListStr)) ? "None" : $userListStr;       
                                }                 
                          }
       
                        }
                        $d->close();
                }
                $userListStr = ($userListStr == "") ? "None" : $userListStr;
                return $userListStr;
        }

The data that I am looking into placing on a table is username, date and something similar to _published_ (connected) which will be 1 for all users loggin into the chat. This way I will be able to get the conection data displayed at the Activity Stream.

Thanks for your help.

:)

Guttorm 02-18-2010 04:23 AM

Hmm.

I think it would be easier if you just looked at the text files on the server instead of looking at the code. All this code does, is to scan a directory for files which begins with "room_", read them, and return a list of the contents of all the files. It joins the name list with ", " in between the names instead of a newline. If none are found, it returns "None". I think you could get a similar list simply running the command "cat room_*" inside that directory, except the names will be separated with newlines instead of commas.


All times are GMT -5. The time now is 05:09 AM.