PDA

View Full Version : 'Sort By' Options in "Who's Online" (online.php)


bira
12-30-2001, 10:00 PM
ok, I wrote this (very small) hack in online.php because I'd rather view the list
sorted by the Last Active time (latest first) than by the sorted by username a-z.
And, sometimes I want to view the list sorted by location - which gives
a very clear and nice picture of where people are currently crowding.

I went on and also added an option to sort by IP address - which allows me
to see if there are users from the same IP at the same time, etc.

This works exactly the same as the Forum Display sorting (where you can
click on "Threads" or "Replies" and the display listing gets sorted by that
field, and the sort/opposite sort arrow 'jumps' next to it).

Installation:

Open online.php and find:


$allusers= $DB_site->query("SELECT user.username,


ABOVE it ADD:


if ($order!='asc') {
$sqlorder='DESC';
} else {
$sqlorder='ASC';
}
if (!$sortby) {
$sortby = "username";
}
switch ($sortby) {
case username:
$sqlsort = "user.username";
break;
case location:
$sqlsort = "session.location";
break;
case time:
$sqlsort = "session.lastactivity";
break;
case host:
$sqlsort = "session.host";
break;
}

$sorturl="online.php?s=$session[sessionhash]";
$oppositesort=iif($order=='asc','desc','asc');

eval("\$sortarrow[$sortby] = \"".gettemplate('whosonline_sortarrow')."\";");


still in online.php, find:


ORDER BY user.username


REPLACE this with:


ORDER BY $sqlsort $sqlorder


Save and upload.

Templates:

ADD NEW templated called whosonline_sortarrow and place in it (remove spaces in { imagesfolder }):


<a href="$sorturl&order=$oppositesort&sortby=$sortby"><img src="{ imagesfolder }/sort$oppositesort.gif" border="0" alt="Reverse Sort Order" align="absmiddle"></a>


save.

OPEN template whosonline

Find (without the spaces in {}):


<td bgcolor="{ tableheadbgcolor }"><smallfont color="{ tableheadtextcolor }"><b>User Name</b></smallfont></td>
<td bgcolor="{ tableheadbgcolor }"><smallfont color="{ tableheadtextcolor }"><b>Location</b></smallfont></td>
<td bgcolor="{ tableheadbgcolor }"><smallfont color="{ tableheadtextcolor }"><b>Last Active</b></smallfont></td>


REPLACE it with (removes spaces in {}):


<td bgcolor="{ tableheadbgcolor }"><a href="$sorturl&order=asc&sortby=username"><smallfont color="{ tableheadtextcolor }"><b>User Name</b></smallfont></a> $sortarrow[username]</td>
<td bgcolor="{ tableheadbgcolor }"><a href="$sorturl&order=asc&sortby=location"><smallfont color="{ tableheadtextcolor }"><b>Location</b></smallfont></a> $sortarrow[location]</td>
<td bgcolor="{ tableheadbgcolor }"><a href="$sorturl&order=desc&sortby=time"><smallfont color="{ tableheadtextcolor }"><b>Last Active</b></smallfont></a> $sortarrow[time]</td>


save.

OPEN template whosonline_ip.

REPLACE the ENTIRE content of the template with (removes spaces in {}):


<td bgcolor="{ tableheadbgcolor }"><a href="$sorturl&order=asc&sortby=host"><smallfont color="{ tableheadtextcolor }"><b>IP</b></smallfont></a> $sortarrow[host]</td>


Save.

That's it.

Cheers,

Bira

XiXora
12-31-2001, 08:31 AM
ohh /me installs :D :up:

squawell
12-31-2001, 09:46 AM
it's great bira~~~:D

but how to move the gif file to the red place??

see my attachment pic~~

Lesane
12-31-2001, 10:30 AM
Nice hack, thanks

bira
12-31-2001, 01:11 PM
Originally posted by squawell
it's great bira~~~:D

but how to move the gif file to the red place??

see my attachment pic~~

You just need to move $sortarrow[XXXXX] to before the text.

For example, change this:


<a href="$sorturl&order=asc&sortby=username"><smallfont color="{ tableheadtextcolor }"><b>User Name</b></smallfont></a> $sortarrow[username]


with this:


$sortarrow[username] <a href="$sorturl&order=asc&sortby=username"><smallfont color="{ tableheadtextcolor }"><b>User Name</b></smallfont></a>

TheComputerGuy
12-31-2001, 01:50 PM
Man Bira is da Woman LOL

Lionel
12-31-2001, 02:28 PM
very handy. Thanks

squawell
12-31-2001, 04:19 PM
thankz bira~:D

it's look better now~~~:D:D

nuno
12-31-2001, 05:02 PM
tx bira

FWC
12-31-2001, 08:15 PM
Very nice, Bira. Another great one! :)

Princeton
12-31-2001, 08:32 PM
kewl ...thank you.

SirSteve
01-01-2002, 06:21 PM
Excellent! Thanks!

Chris Blount
06-08-2002, 05:53 PM
Great hack but I notice that each time the who's online refreshes, it defaults to the names being in reverse alphabetical order. Is there a way to get them back to alphabetical order by default like they were before the hack?

Kars10
06-10-2002, 11:59 AM
Works nice!!
Thanx 4 this great Hack!! :-)

inetd
06-10-2002, 06:14 PM
/me install this hack

Good add-on to Who's Online, bira! :tup:

Brad
09-26-2002, 01:23 AM
Very nice bira. ive had it installed before and it went well under my new 2.2.7 forums.

however im hoping someone can give me a solution for a tiny problem. you see. if you click the link to sort by Last Active, it will sort by user name once WOL is re-loaded.

try it on my forums (guest can view my who's online page) http://www.kousetsu.net/kan/online.php?s=


anyone got any ideas? :ermm:

BigCheeze
10-21-2002, 06:01 PM
Thanks! Works great!!!

Bison
07-08-2003, 10:21 AM
Installed!

julius
08-22-2003, 06:44 AM
Installed.
Thanhs.

gmarik
08-23-2003, 07:45 AM
Fine, fine

/me likes it