LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-15-2010, 07:36 PM   #1
latino
Member
 
Registered: Aug 2003
Location: Puerto Rico
Distribution: RHEL 5.5
Posts: 141

Rep: Reputation: 15
Question 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.

Last edited by latino; 02-15-2010 at 11:19 PM.
 
Old 02-16-2010, 08:41 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,136

Rep: Reputation: 230Reputation: 230Reputation: 230
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
 
Old 02-16-2010, 05:52 PM   #3
latino
Member
 
Registered: Aug 2003
Location: Puerto Rico
Distribution: RHEL 5.5
Posts: 141

Original Poster
Rep: Reputation: 15
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.


Last edited by latino; 02-16-2010 at 05:59 PM.
 
Old 02-18-2010, 03:23 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,136

Rep: Reputation: 230Reputation: 230Reputation: 230
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Joomla! 1.5: A User's Guide plus Fundamentals of Joomla! Video LXer Syndicated Linux News 0 10-26-2009 11:00 AM
LXer: Creating and Managing User Groups in Joomla! and VirtueMart LXer Syndicated Linux News 0 04-20-2009 05:20 AM
How to create new log file to store details of the accessed files..! hsatish Linux - Newbie 6 01-22-2009 12:22 AM
Good tool to create Joomla! templates? NetRAVEN5000 Linux - Software 4 06-27-2006 07:35 AM
how do I create a chat room using php Bheki Programming 3 02-05-2002 04:36 PM


All times are GMT -5. The time now is 07:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration