<?php 

/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.org                                                   */
/*									*/
/* modules/MembersList for PHP-Nuke 6.5 beta 1 thru 5			*/
/* --------------------------------------------------			*/
/* by Paul Laudanski (c) 2003						*/
/* NukeCops.com | ComputerCops.biz					*/
/* January 2003								*/
/*                                                                      */
/* =========================                                            */
/* Based on MyPHPortal Modified MembersList                             */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

/* Some code taken from MemberList coded by Paul Joseph Thompson */
/* of www.slug.okstate.edu                                       */
/* In memoriam of Members List War ;)                            */

if (!eregi("modules.php", $PHP_SELF)) {
    die ("You can't access this file directly...");
}

require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);

function alpha() {
    global $sortby, $module_name;
        $alphabet = array ("All", "A","B","C","D","E","F","G","H","I","J","K","L","M",
                            "N","O","P","Q","R","S","T","U","V","W","X","Y","Z","Other");
        $num = count($alphabet) - 1;
        echo "<center>[ ";
	/* start of HTML */
        $counter = 0;
        while (list(, $ltr) = each($alphabet)) {
            echo "<A HREF=\"modules.php?name=$module_name&amp;letter=$ltr&amp;sortby=$sortby\">$ltr</a>";
            if ( $counter == round($num/2) ) {
                echo " ]\n<br>\n[ "; 
            } elseif ( $counter != $num ) {
                echo "&nbsp;|&nbsp;\n";
            }
            $counter++;
        }
        echo " ]\n</center>\n<br>\n";  // end of HTML
}

function SortLinks($letter) {  // Makes order by links..
        global $sortby, $module_name;
        if ($letter == "front") { 
	    $letter = "All"; 
	}
        echo "\n<center>\n"; // Start of HTML
        echo ""._SORTBY." <b>[</b> ";
        if ($sortby == "username" OR !$sortby) {
            echo ""._MNICKNAME."&nbsp;|&nbsp;";
        } else {
            echo "<A HREF=\"modules.php?name=$module_name&amp;letter=$letter&amp;sortby=username\">"._MNICKNAME."</a>&nbsp;|&nbsp;";
        }
        if ($sortby == "name") {
            echo ""._MREALNAME."&nbsp;|&nbsp;";
        } else {
            echo "<A HREF=\"modules.php?name=$module_name&amp;letter=$letter&amp;sortby=name\">"._MREALNAME."</a>&nbsp;|&nbsp;";
        }
        if ($sortby == "femail") {
            echo ""._MEMAIL."&nbsp;|&nbsp;";
        } else { 
            echo "<A HREF=\"modules.php?name=$module_name&amp;letter=$letter&amp;sortby=femail\">"._MEMAIL."</a>&nbsp;|&nbsp;";
        }
        if ($sortby == "user_website") {
            echo ""._MURL."&nbsp;|&nbsp;";
        } else {
            echo "<A HREF=\"modules.php?name=$module_name&amp;letter=$letter&amp;sortby=user_website\">"._MURL."</a>";
        }
        echo " <b>]</b>\n</center>\n"; // end of HTML
}
        
include("header.php");
$pagesize = 20;

if (!isset($letter)) { $letter = "A"; }
if (!isset($sortby)) { $sortby = "username"; }
if (!isset($page)) { $page = 1; }

$result = sql_query("select username from ".$user_prefix."_users order by user_id DESC limit 0,1", $dbi);
list($lastuser) = sql_fetch_row($result, $dbi);
echo "\n\n<!-- MEMBERS LIST -->\n\n";
	OpenTable();
        echo "<center><b>"._WELCOMETO." $sitename "._MEMBERSLIST."</b><br><br>\n";
        echo ""._GREETINGS." <A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$lastuser\">$lastuser</a>\n</center>\n<br>\n";

        $numrows = sql_num_rows(sql_query("select user_id from ".$user_prefix."_users", $dbi), $dbi);

        if (is_user($user)) {
            $result2 = sql_query("SELECT uname,guest FROM ".$prefix."_session where guest=0", $dbi);
            $member_online_num = sql_num_rows($result2, $dbi);
	    $who_online = "<b>"._ONLINEREG." </b><br><br>";
            $i = 1;
            while ($session = sql_fetch_array($result2, $dbi)) {
                if (isset($session["guest"]) and $session["guest"] == 0) {
                    $who_online .= "<A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$session[uname]\">$session[uname]</a>\n";
                    $who_online .= ($i != $member_online_num ? " - " : "");
                    $i++;
                }
            }
            echo "<center>"._WEHAVE." <b>$numrows</b> "._MREGISTERED." <b>$member_online_num</b>\n";
            echo " "._MREGONLINE."</center><br><br>";
	    OpenTable2();
            echo "<CENTER>$who_online</CENTER>\n";
	    CloseTable2();
	    echo "<br><br>";
        } else {
            echo "<center>"._WEHAVE." <b>$numrows</b> "._REGSOFAR."</center>\n<br>\n<br>\n";
        }

        alpha();
        SortLinks($letter);


        $min = $pagesize * ($page - 1); 
        $max = $pagesize; 
        
	
        $count = "SELECT COUNT(user_id) AS total FROM ".$prefix."_users "; 
        $select = "select user_id, name, username, femail, user_website from ".$prefix."_users "; 
	$where = "where username != 'Anonymous' ";
	if ( ( $letter != "Other" ) AND ( $letter != "All" ) ) {  
            $where .= "AND username like '".$letter."%' "; 
        } else if ( ( $letter == "Other" ) AND ( $letter != "All" ) ) { 
            $where .= "AND username REGEXP \"^\[1-9]\" "; 
        } else { 
            $where .= ""; 
        }
        $sort = "order by $sortby"; 
        $limit = " ASC LIMIT ".$min.", ".$max; 
        $count_result = sql_query($count.$where, $dbi);
        $num_rows_per_order = mysql_result($count_result,0,0);
        
        $result = sql_query($select.$where.$sort.$limit, $dbi) or die('yo'); 


        echo "<br>";
        if ( $letter != "front" ) {
            echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\"><tr>\n";
            echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._NICKNAME."</b></font></td>\n";
            echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._REALNAME."</b></font></td>\n";
            echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._EMAIL."</b></font></td>\n";
            echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._URL."</b></font></td>\n";
            $cols = 4;
            if(is_admin($admin)) {
                $cols = 5;
                echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._FUNCTIONS."</b></font></td>\n";
            }
            echo "</tr>";
            $a = 0;
            $dcolor_A = "#FFFF99";
            $dcolor_B = "$bgcolor1";


            $num_users = sql_num_rows($result, $dbi); 
            if ( $num_rows_per_order > 0  ) {
                while($user = sql_fetch_array($result, $dbi)) {
                    $dcolor = ($a == 0 ? $dcolor_A : $dcolor_B);
                    echo "<tr><td bgcolor=\"$dcolor\"><A HREF=\"modules.php?name=Your_Account&amp;op=userinfo&amp;username=$user[username]\">$user[username]</a>&nbsp;</td>\n";
                    echo "<td bgcolor=\"$dcolor\">$user[name]&nbsp;</td>\n";
                    echo "<td bgcolor=\"$dcolor\">$user[femail]&nbsp;</td>\n";
#echo "<td bgcolor=\"$dcolor\"><font color=\"$textcolor1\">$user[femail]</font>&nbsp;</td>\n";
                    if ($user[user_website] == "") {
			$url2 = "&nbsp;";
		    } else {
			$urlno = eregi_replace("http://","",$user[user_website]);
			$url2 = "<a href=\"http://$urlno\" target=\"new\">"._HOMEPAGE."</a>";
		    }
		    echo "<td bgcolor=\"$dcolor\" align=\"center\">$url2</td>\n";
                    if(is_admin($admin)) {
                        echo "<td bgcolor=$dcolor align=center><font class=\"content\" color=\"$textcolor1\">[ <A HREF=\"admin.php?chng_rid=$user[user_id]&amp;op=modifyUser\">"._EDIT."</a> | \n";
                        echo "<A HREF=\"admin.php?op=delUser&amp;chng_uid=$user[user_id]\">"._DELETE."</a> ]</font></td>\n";
                    }
                    echo "</tr>";
                    $a = ($dcolor == $dcolor_A ? 1 : 0);
                }
                echo "\n<tr><td colspan='$cols' align='right'>\n";
		echo "<br><br>";
		OpenTable();
                echo "\t<table width='100%' cellspacing='0' cellpadding='0' border=0><tr>";
                
                if ( $num_rows_per_order > $pagesize ) { 
                    $total_pages = ceil($num_rows_per_order / $pagesize); 
                    $prev_page = $page - 1;
                    
                    if ( $prev_page > 0 ) {
                        echo "<td align='left' width='15%'><a href='modules.php?name=$module_name&amp;letter=$letter&amp;sortby=$sortby&amp;page=$prev_page'>";
                        echo "<img src=\"images/left.gif\" border=\"0\" alt=\""._PREVIOUS." ($prev_page)\" title=\""._PREVIOUS." ($prev_page)\"></a></td>";
                    } else { 
                        echo "<td width='15%'>&nbsp;</td>\n"; 
                    }
                
                    echo "<td align='center' width='70%'>";
                    echo "<font class=tiny>$num_rows_per_order "._USERSFOUND." <b>$letter</b> ($total_pages "._PAGES.", $num_users "._USERSSHOWN.")</font>";
                    echo "</td>";

                    $next_page = $page + 1;
                    if ( $next_page <= $total_pages ) {
                        echo "<td align='right' width='15%'><a href='modules.php?name=$module_name&amp;letter=$letter&amp;sortby=$sortby&amp;page=$next_page'>";
                        echo "<img src=\"images/right.gif\" border=\"0\" alt=\"Next Page ($next_page)\" title=\"Next Page ($next_page)\"></a></td>";
                    } else {
                        echo "<td width='15%'>&nbsp;</td></tr>\n"; 
                    }
                    
                        echo "<tr><td colspan=\"3\" align=\"center\">";
                        echo " <font class=tiny>[ </font>";
                        
                        for($n=1; $n < $total_pages; $n++) {
                        
                            
                            if ($n == $page) {
				echo "<font class=tiny><b>$n</b></font></a>";
                            } else {
				echo "<a href='modules.php?name=$module_name&amp;letter=$letter&amp;sortby=$sortby&amp;page=$n'>";
				echo "<font class=tiny>$n</font></a>";
			    }
                            if($n >= 50) {  
                                $break = true; 
                                break;
                            } else {  
                                echo "<font class=tiny> | </font>"; 
                            }
                        }
                        
                        if(!isset($break)) { 
			    if ($n == $page) {
                        	echo "<font class=tiny><b>$n</b></font></a>";
			    } else {
                        	echo "<a href='modules.php?name=$module_name&amp;letter=$letter&amp;sortby=$sortby&amp;page=$total_pages'>";
                        	echo "<font class=tiny>$n</font></a>";
			    }
                        }
                        echo " <font class=tiny>]</font> ";
                        echo "</td></tr>";

                }else{  
                    echo "<td align='center'>";
                    echo "<font class=tiny>$num_rows_per_order "._USERSFOUND." $letter</font>";
                    echo "</td></tr>";
                    
                 }
                
                 echo "</table>\n";
		 CloseTable();
                echo "</td></tr>\n";

                
            } else { 
                echo "<tr><td bgcolor=\"$dcolor_A\" colspan=\"$cols\" align=\"center\"><br>\n";
                echo "<b><font color=\"$textcolor1\">"._NOMEMBERS." $letter</font></b>\n";
                echo "<br></td></tr>\n";
            }
            
            echo "\n</table><br>\n";
        }
        
	CloseTable();
        include("footer.php");

?>
