<?php

function build_geturl($var)
{
    
$file $_SERVER['SCRIPT_NAME'];
    
$qstrings explode('&'$_SERVER['QUERY_STRING']);
    
$qstring "";
    
$sep '?';
    foreach(
$qstrings as $arg) {
    if(
strpos($arg"$var=") === FALSE) {
        
$qstring .= "$sep$arg";
        if(
$sep == '?'$sep '&';
    }
    }
    return 
"$file$qstring";
}
    
function 
set_order($col)
{
    
$orderby $_GET['order'];
    
    if(
$col == 0$dcol = -1;
    else 
$dcol $col * -1;
    
    print 
"href='";
    print 
build_geturl("order");
    if(
$orderby == $col) print "&order=$dcol'";
    else {
    if(
$col != 0) print "&order=$col'";
    else { print 
"'"$col 1; }
    }

    if(
$orderby 0) {
    
$class " class='alhead'";
    
$orderby *= -1;
    }
    else {
    
$class " class='dlhead'";
    }

    if(
$col 0$col *= -1;

    if(
$orderby == $col) print $class;
    else print 
" class='lhead'";

    print 
" test='$orderby, $col'";
}

function 
appendTime($time$timestr, &$ago)
{
    if(
$time 0) { $ago .= " $time $timestr"; }
        if(
$time 1) { $ago .= "s"; }
}
        
function 
addTabs()
{

    echo    
"<!-- Tabs -->
    <table border='0' cellspacing='0'>
    <tr>
    <td class='emptytab'>&nbsp;</td>
    "
;

    
$tabs[0]['name'] = "Users";
    
$tabs[0]['link'] = "last.php";
    
$tabs[1]['name'] = "Groups";
    
$tabs[1]['link'] = "group.php";
    
$tabs[2]['name'] = "Clans";
    
$tabs[2]['link'] = "clan.php";
    
$tabs[3]['name'] = "Messages";
    
$tabs[3]['link'] = "message.php";

foreach(
$tabs as $tab)
{
    if(
strpos($_SERVER['SCRIPT_NAME'], "/{$tab['link']}") === FALSE) {
    echo 
"
    <td class='tab'><a class='tablink' href='{$tab['link']}'>{$tab['name']}</a></td>
    "
;
    } else {
    echo 
"
    <td class='tabsel'>{$tab['name']}</td>
    "
;
    }
}
    
    echo    
"
    <td class='emptytab' width='50'>&nbsp;</td>
    </tr>
    </table>
    "
;
}

function 
tsToAgo($ts)
{
    
# Make the X time ago format.
    
$tcurtime time();
    
$tago $tcurtime $ts;

    
$year 0$month 0$week 0$day 0$hour 0$min 0;
    while(
$tago 60) {
        if(
$tago >= 31557600) {  $year++; $tago -= 31557600; continue; }
        if(
$tago >= 2678400)  { $month++; $tago -= 2678400;  continue; }
        if(
$tago >= 604800)   {  $week++; $tago -= 604800;   continue; }
        if(
$tago >= 86400)    {   $day++; $tago -= 86400;    continue; }
        if(
$tago >= 3600)     {  $hour++; $tago -= 3600;     continue; }
        if(
$tago >= 60)       {   $min++; $tago -= 60;       continue; }
    }

    
$ago "";
    
appendTime($year"year"$ago);
    
appendTime($month"month"$ago);
    
appendTime($week"week"$ago);
    
appendTime($day"day"$ago);
    
appendTime($hour"hour"$ago);
    
appendTime($min"minute"$ago);
    
appendTime($tago"second"$ago);
    
$ago .= " ago. ";

    return 
$ago;
}

?>