Gossamer Forum
Home : Products : DBMan : Customization :

Who's Online

Quote Reply
Who's Online
Is there a way to display the list of Who's Online on the html_home page?

----------------
donm

Quote Reply
Re: Who's Online In reply to
Yes. Just take the "guts" of sub html_whos_online and put it into sub html_home.

Code:

opendir (AUTHDIR, "$auth_dir") || &cgierr("unable to open directory in html_home: $auth_dir. Reason: $!");
@files = readdir(AUTHDIR); # Read in list of files in directory..
closedir (AUTHDIR);
FILE: foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next;

# At this point, you can decide what you want to print out. If you have a database that
# has the userid as the key value, you can get the information from the database, using
# %rec = &get_record($username);
# and then print out whatever fields you want to appear on the page. You can have a link
# to the user's record, if you wish.
# Or you can just use the line below to print out the usernames.

print "$username<BR>";
}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
Gosh - finally able to access the forum once again ! This works however, if a person logs in and off several times within 20 minutes - it prints their username each time they logged have logged in as being online.

Also - how could I convert their username to their first and last name - there are fields within the database that contain their names.

Thanks (so glad to I am able to access the forum again !)

----------------
donm

Quote Reply
Re: Who's Online In reply to
I'm sorry. I thought you already had the rest of the mod in place. You need to get the mod at http://www.jpdeni.com/...Mods/whos_online.txt and add/change the code at the beginning of the mod. There's code to add to auth.pl, to your .cfg file and to change the "logoff" function.

In Reply To:
how could I convert their username to their first and last name
You do a search for the username. Do I remember correctly that your userid field is not the key field? Well, I'll give you code for either way and you can choose which one to use. Use the code in green to create a link to the user's record.

If your userid field is the key field:

Code:

($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next;
%rec = &get_record($username);
if (%rec) {

print qq|<a href="$db_script_link_url&view_records=1&$db_cols[$auth_user_field]=$username">$rec{'FirstName'} $rec{'LastName'}</a><BR>|;
}
If your userid field is not the key field:

Code:

($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next;
undef %in;
$in{$db_cols[$auth_user_field]} = $username;
my ($status,@hits) = &query("view");
if ($status eq 'ok') {
%rec = &array_to_hash(0,@hits);

print qq|<a href="$db_script_link_url&view_records=1&$db_cols[$auth_user_field]=$username">$rec{'FirstName'} $rec{'LastName'}</a><BR>|;
}
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
Wow, I can't believe you remember how my script is setup. Well I did already have the Who's online Mod installed - however, I did not add the sub html_who's_online because I only want to use what you have here to so that it will print out on the home page and not have a link in the footer.

I am still getting duplicate names if someone logs on, then off and back within 20 minutes. Is there a way to stop that?

Thanks!

------------
Donm

Quote Reply
Re: Who's Online In reply to
Thanks JPDeni. You told me to check this thread for an answer. Well I have tried both of the codes you provided and each time I get this:

syntax error at complete line 480, near "$rec"
In string, @hits now must be written as \@hits at complete line 480, near "$status,@hits"
syntax error at complete line 490, near "# print q|$rec{'FirstName'} $rec{'LastName'}

My username field is my userID. Email is the keyfield. Any suggestions would be greatly appreciated.
Thank again,
Paul



http://www.fullmoonshining.com for Pearl Jam Fans
Quote Reply
Re: Who's Online In reply to
cranepaul:
I made a mistake when I posted the code above. It should be

print qq|<a href="$db_script_link_url...

I changed it in the post.

However, there seems to be something else going on with your script. Can you post about three lines before and after the code above so I can see if I can figure out what the problem is?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
Don:

In Reply To:
I am still getting duplicate names if someone logs on, then off and back within 20 minutes. Is there a way to stop that?
If you've added the code for logging off, they haven't actually logged off the database. They have just left and come back again.

You could set your $auth_time variable to a smaller number.

But I'll rewrite it so it doesn't show up twice.

Code:

opendir (AUTHDIR, "$auth_dir") || &cgierr("unable to open directory in html_whos_online: $auth_dir. Reason: $!");
@files = readdir(AUTHDIR); # Read in list of files in directory..
closedir (AUTHDIR);
FILE: foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next;
$users{$username} = 1;
}
for each $username (%users) {
print "$username<BR>";
}
That should prevent duplications. Of course, you'll have to put in the code for your names and/or link to the record.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
Thanks JPDeni. I tried adding that last night after I posted it with no results. Anyway here are the first few lines:

FILE: foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next;

And here are the last few lines:

} #end of who's online
&html_page_bottom;
&html_footer;
}

I had to reverse the footer so it would work with my page layout. I might be worth noting that when I changed the codes to qq it displayed nothing.
Thanks alot for all your help,
Paul


http://www.fullmoonshining.com for Pearl Jam Fans
Quote Reply
Re: Who's Online In reply to
So you aren't getting any error message any more, right, Paul? But you're also not getting anything returned?

First, check to see if there are actually any files in your auth directory. That's what the mod is based on.

I don't know why it wouldn't pull the files from the directory.

I hate to ask you to do this, but could you post the whole section of code that opens the directory and prints out the names? I don't know if you have an error or if I gave you an error. Smile

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
Ok, thanks. No more error message, and nothing is being printed. I checked the directory after I logged in as cranepaul and it had an entry for cranepaul. Here's the code:

opendir (AUTHDIR, "$auth_dir") || &cgierr("unable to open directory in html_whos_online: $auth_dir. Reason: $!");
@files = readdir(AUTHDIR); # Read in list of files in directory..
closedir (AUTHDIR);
FILE: foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
($file =~ /^([A-Za-z0-9]+)\.\d+$/) ? ($username = $1) : next;
%rec = &get_record($username);
if (%rec) {
print qq|<a href="$db_script_link_url&view_records=1&$db_cols[$auth_user_field]=$username">$rec{'FirstName'} $rec{'LastName'}</a><BR>|;
}
}
&html_page_bottom;
&html_footer;
}

It's probably something I did. The who's online mod was working fine before I did this though. Thanks for the help.
Paul

http://www.fullmoonshining.com for Pearl Jam Fans
Quote Reply
Re: Who's Online In reply to
Okay. This means that &get_record($username) is not picking up the record.

First, delete or comment out the line in sub get_record --

($restricted = 1) if ($auth_modify_own and !$per_admin);

(I always forget about that.)

See if that works better.

If not, take out the lines in red below.

Code:

if (%rec) {
print qq|<a
href="$db_script_link_url&view_records=1&$db_cols[$auth_user_field]=$username">$rec{'FirstName'}
$rec{'LastName'}</a><BR>|;
}
See if that works better.

If not, we'll have to look at your key value and userids and such to see why get_record isn't pulling up the record.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
Ok I did what you suggested. Still doen't print the hyperlink. I looked at the html source after I logged in and it was displaying this:

<p>Members currently logged into the database:</p></font>
<a href="http://www.fullmoonshining.com/cgi-bin/dbman/db.cgi?db=default&uid=cranepaul.96352933454598&view_records=1&User Name=cranepaul"> </a><BR>

Maybe that'll lend some clues since the hyperlink is there just not all of it. Thanks,
Paul

http://www.fullmoonshining.com for Pearl Jam Fans
Quote Reply
Re: Who's Online In reply to
What are your field names for the first and last names of the user?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
I shouldn't have posted that last one because I think it's working now. I changed the print line to this:

print qq|<a href="$db_script_link_url&view_records=1&$db_cols[$auth_user_field]=$username">$rec{'User Name'}</a><BR>|;
Now it seems to be working like it's supposed to. I clicked on the link and it brought up the record, except it gave me two of them instead of one. I assume that is because of a time. Anyway, is it alright if I leave that deleted stuff out.
Thanks alot for the help,
Paul

http://www.fullmoonshining.com for Pearl Jam Fans
Quote Reply
Re: Who's Online In reply to
I would suggest that you put back at least something to make sure the record was found.

You could use

if ($rec{$db_key}) {

instead of

if (%rec) {

The reason that you want to do that is in case the person has just deleted their record. You'll end up with a blank space.

If you want to avoid having the same name appear twice, you'll need to add the code I gave to Don above.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Who's Online In reply to
Thanks JPDeni. Sorry I had to leave for a little bit. Got it working. Works great!!!Smile Thanks for all your help. Thanks again,
Paul

http://www.fullmoonshining.com for Pearl Jam Fans