<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: memberslist.php,v 1.8.2.11 2004/08/22 14:33:49 kirilt Exp $

$extStyle = 2; // Loads appropriate page stylesheet

//  DEFINE CONSTANTS

// Set Name Of This Script

define( '_DP_MEMBERSLIST' , 'memberslist.php' );

//  Define Db Columns For Plugin Sort Functions

define( '_SC_USER_NAME' , 'uname' );
define( '_SC_USER_FROM' , 'user_from' );
define( '_SC_USER_REGDATE' , 'user_regdate' );
define( '_SC_USER_EMAIL' , 'femail' );
define( '_SC_USER_URL' , 'url' );

// Check Table For Fulltext Index Support

$ftsupport = $_SERVER['F_LIB'] -> checkFTISupport( $mpnTables['users'] );

//  Set Defaults

if ( ! empty( $_REQUEST ) ) { extract( $_REQUEST ); }

if ( isset( $_GET['search'] ) && $_GET['search'] != '' )
{
    $search = base64_decode( $_GET['search'] );
}

if ( ! isset( $letter ) ) { $letter = 'All'; }
if ( ! isset( $page ) ) { $page = 1; }
if ( ! isset( $sortcol ) ) { $sortcol = _SC_USER_NAME; }
if ( ! isset( $sortdir ) ) { $sortdir = 'a'; }  // a=ASCENDING, d=DESCENDING
if ( ! isset( $pagesize ) ) { $pagesize = 20; }

$incoming_sortcol = $sortcol;
$incoming_sortdir = $sortdir;
$min = $pagesize * ( $page - 1 ); // Start Record Set From
$max = $pagesize; // How Many Rows To Select
$dir = ( $sortdir == 'a' ) ? ( 'ASC' ) : ( 'DESC' );
$orderby = " ORDER BY $sortcol $dir LIMIT $min, $max";
$numrows = 0;

$sql = "SELECT COUNT(*) AS total
        FROM " . $mpnTables["users"] . "
        WHERE uid > 1";

list( $total_reg_users )  = ( @mysql_fetch_row( @mysql_query( $sql ) ) );

( include_once __ROOT__ . 'header.php' )
  OR goBack( translate( 'Include Error' ) );

echo "<div id='memberslist'>\n";

echo "\n<!-- START MEMBERLIST -->\n\n";

echo "<h1>" . translate( 'Welcome to' ) . " $sitename " . translate( 'Members List' ) . "</h1>\n";

echo "<h2>" . translate( 'We Currently Have' ) . " <b>$total_reg_users</b> " . translate( 'Registered Members' ) . ".</h2>";

if ( _MPN_USER || _MPN_ADMIN )
{
    $sql = "SELECT username
            FROM " . $mpnTables['session'] . "
            WHERE guest = '0'";

    if ( ! ( $result = @mysql_query( $sql ) ) )
    {
        $mem_online = 0;
    }
    else
    {
        $mem_online = mysql_num_rows( $result );
    }

    if ( $mem_online == 0 )
    {
        echo "<span class='label'>\n";

            echo translate( 'No Members Are Currently Logged In' );

        echo "</span>\n";
    }
    else
    {
        for ( $i = 1; $i <= $mem_online; $i++ )
        {
            $mem_name[ $i ] = mysql_fetch_row( $result );
        }

        echo "<span class='label'>\n";

            echo translate( 'Current Online Members' );

        echo "</span>\n";

        echo "<br /><br />\n";

        echo "<div class='whosonline'>\n";

            foreach( $mem_name AS $key => $v )
            {
                if ( $key > 1 ) { echo ', '; }

                echo "<a href='./user.php?op=userinfo&amp;" . _SC_USER_NAME . "=$v[0]'>$v[0]</a>\n";
            }

        echo "</div>\n";
    }
}

echo "</p><br />\n";

//  DB SEARCH QUERY NUMBER OF RESULTS

if ( isset( $search ) && $search != '' )
{
    $srchret = base64_encode( $search );
    $query = addslashes( $search );

    $sql = "SELECT uid, " . _SC_USER_NAME . ", " . _SC_USER_EMAIL . ", " . _SC_USER_URL . ", " . _SC_USER_REGDATE . ", user_icq, " . _SC_USER_FROM . ", user_aim, user_yim, user_msnm
                FROM " . $mpnTables["users"];

    if ( ! $ftsupport || strlen( $search ) < 4 )
    {
        $sql .= " WHERE ( " . _SC_USER_NAME . " LIKE '%$query%' )
                      || ( " . _SC_USER_FROM . " LIKE '%$query%' )
                      || ( user_intrest LIKE '%$query%' )
                      || ( bio LIKE '%$query%' )
                      && uid > 1 $orderby";
    }
    else
    {
        $sql .= " WHERE ( MATCH(" . _SC_USER_NAME . "," . _SC_USER_FROM . ",user_intrest,bio) AGAINST('%$query%') ) && uid > 1  $orderby";
    }

    @( $result = mysql_query( $sql ) )
      OR goBack( translate( 'Query Failed' ) . '**' . __FILE__ . '***' .  __LINE__ );

    $num_rows_per_order = mysql_num_rows( $result );
}
else
{
    $search = '';

    $count = "SELECT COUNT(uid) AS total
              FROM " . $mpnTables["users"] . "
              WHERE uid > 1
                && uname != ''"; // Count All The Users In The Db

   $select = "SELECT uid, " . _SC_USER_NAME . ", " . _SC_USER_EMAIL . ", " . _SC_USER_URL . ", " . _SC_USER_REGDATE . ", user_icq, " . _SC_USER_FROM . ", user_aim, user_yim, user_msnm
               FROM " . $mpnTables["users"] . "
               WHERE uid > 1
                   && uname != ''";

    // SET CONDITIONS FOR DB QUERY

    if ( ( $letter != 'Other' ) && ( $letter != 'All' ) && ( $search == '' ) )
    {
        $where = " && ( " . _SC_USER_NAME . " LIKE '".$letter."%' ) ";

    }
    else if ( ( $letter == 'Other' ) && ( $letter != 'All' ) && ( $search == '' ) )
    {
        $where = " && ( " . _SC_USER_NAME . " REGEXP '^\[1-9]' ) ";
    }
    else
    {
        $where = '';
    }

    //  SET PARAMETERS FOR DB QUERY

    $count_result = mysql_query( $count . $where );
    $num_rows_per_order = mysql_result( $count_result, 0, 0 );

    if ( $num_rows_per_order > 0 )
    {
        @( $result = mysql_query( $select . $where . $orderby ) );
    }
    else 
    { 
        $result = NULL; 
    }
}

//  DISPLAY TOP NAV, SEARCH, AND PAGE OPTIONS

echo "<div class='navsort'>\n";

    $nb = searchDB( $search, $num_rows_per_order ); // Call Search Plugin

    echo "&nbsp; &nbsp;";

    perPage( $pagesize ); // Option For Listing Number Perpage

    if ( ! empty( $nb ) )
    {
        echo "<br />$nb<br />\n";
    }
    else
    {
        echo "<br /><br />\n";
    }

    alpha(); // Call Function Alpha For Sorting

echo "</div>\n";

echo "<br />";

echo "<b>" . translate ( 'Page' ) . " [ $page ]</b>\n";

echo "<br />\n";

if ( ! $result )
{
    goBack( translate( 'Sorry, The Member You Searched For Could Not Be Found' ), FALSE );
    echo '</div>' . "\n";
    @( include_once __ROOT__ . 'footer.php' )
      OR goBack( translate( 'Include Error' ) );
    exit;
}

echo "<br />\n";

if ( $letter != 'front' )
{
    $dcolor = $bgcolor2;

    echo "<table class='listmembers' width='100%' border='0px' cellspacing='1px' cellpadding='2px'>";

    echo "<tr bgcolor='$dcolor'>\n";

        generate_header_row();

    echo "</tr>\n";

    $num_users = mysql_num_rows( $result ); // Number Of Users Per Sorted And Limit Query

    if ( ( $num_users > 0 ) || ( $num_rows_per_order > 0 ) )
    {
        while ( $usertmp = mysql_fetch_array( $result ) )
        {
            $dcolor = ( $dcolor == $bgcolor2 ) ?  ( $bgcolor1 ) : ( $bgcolor2 );

            echo "<tr bgcolor=$dcolor>";

            echo "<td height='25px' align='center' nowrap>"
                ."<a href='user.$phpEx?op=userinfo&uname={$usertmp['uname']}'>" . $usertmp[ _SC_USER_NAME ] . "</a></td>\n";

            if ( ! isset( $usertmp[ _SC_USER_FROM ] ) )
            {
                echo "<td width='9%' height='25px' align='center' nowrap='nowrap'>&nbsp;</td>\n";
            }
            else
            {
                echo "<td width='150px' height='25px' align='center'>" . $usertmp[ _SC_USER_FROM ] . "</td>\n";
            }

            if ( ! isset( $usertmp[ _SC_USER_REGDATE ] ) )
            {
                echo "<td width='9%' height='25px' align='center' nowrap='nowrap'>&nbsp;</td>\n";
            }
            else
            {
                echo "<td height='25px' align='center' nowrap='nowrap'>" . getDisplayTime( $usertmp['user_regdate'], 'datestring4' ) . "</td>\n";
            }

            if ( ! isset( $usertmp[ _SC_USER_EMAIL ] ) || $usertmp[ _SC_USER_EMAIL ] == '' )
            {
                echo "<td width='9%' height='25px' align='center' nowrap='nowrap'>&nbsp;</td>\n";
            }
           else
            {
                echo "<td width='9%' height='25px' align='center' nowrap='nowrap'>"
                ."<a href='mailto:" . $usertmp[ _SC_USER_EMAIL ] . "'><img src='images/forum/icons/email.gif' border='0px' alt='" . translate( 'Email' ) . " {$usertmp['uname']}' /></a></td>";
            }

            if ( ! isset( $usertmp[ _SC_USER_URL ] ) || $usertmp[ _SC_USER_URL ] == '' )
            {
                echo "<td height='25px' align='center' nowrap='nowrap'>&nbsp;</td>\n";
            }
            else
            {
                echo "<td height='25px' align='center' nowrap='nowrap'>"
                ."<a href=" . $usertmp[ _SC_USER_URL ] . "><img src='images/forum/icons/homepage.gif' border='0px' alt='$usertmp[uname] " . translate( 'Website' ) . "'></a></td>\n";
            }

            if ( ! isset( $usertmp[ _SC_USER_NAME ] ) && ( _MPN_USER || _MPN_ADMIN ) )
            {
                echo "<td height='25px' align='center' nowrap='nowrap'>&nbsp;</td>\n";
            }
            else
            {
                echo "<td height='25px' align='center' nowrap='nowrap'>"
                    ."<a href='replypmsg.$phpEx?send2=1&to_userid=" . $usertmp[ _SC_USER_NAME ] . "'><img src='images/forum/icons/pm_notext.gif' border='0px' alt='" . translate( 'Send Private Message' ) . "'></a></td>\n";
            }

            if ( _MPN_ADMIN )
            {
                echo "<td height='25px' align='center' nowrap='nowrap'>"
                    ."<font size='1'>[ </font><a href='admin.php?chng_uid={$usertmp['uid']}&op=modifyUser'>" . translate( 'Edit' ) . "</a><font size='1'> | </font>\n";
                echo "<a href='admin.$phpEx?op=delUser&chng_uid={$usertmp['uid']}'>" . translate( 'Delete' ) . "</a> <font size='1'> ]</font></td>\n";
            }

            echo "</tr>\n";

        }   // END WHILE

    echo "</table>\n";

    echo "<br /><br />";

// Start Bottom Nav

    echo "<table class='opentable1' width='30%' cellspacing='0px' cellpadding='0px' border='0px' summary='' bgcolor='$bgcolor1'>\n";

        echo "<tr>\n";  //  Table Cells Are Set By Function Pagenav

            if ( $num_rows_per_order > $pagesize )
            {
                $total_pages = ceil( $num_rows_per_order / $pagesize );

                pageNav( $total_pages, $page );

                echo "</tr><tr><td align='center' colspan='4'>\n";

                echo "<font size='1'><b>$num_rows_per_order</b> " . translate( 'users found for listing' ) . " <b>$letter</b><br />( <b>$total_pages</b> " . translate( 'pages' ) . ", <b>$num_users</b> " . translate( 'users shown' ) . " ).</font>";

                echo "</td></tr>\n";

            }
            else // Dont Have Any Users
            {
                echo "<td align='center'>\n";
                echo "<font size=1>$num_rows_per_order " . translate( 'user(s) found' ) . ".</font><br />\n";
                echo "</td>\n";
            }

        echo "</tr>\n";

    echo "</table>\n";
}
else // There Are No Members Under This Letter!
{
    $cols = 7;
    echo "<tr><td bgcolor='$dcolor' colspan='$cols' align='center'><br />\n";

    echo "<b><font color='$textcolor1'>" . translate( 'No Members Found For' ) . " $letter</font></b>\n";

    echo "<br /></td></tr>\n";
}

    echo "</table><br />\n";
}

echo "\n<!-- END MEMBERLIST -->\n\n";

echo "</div>\n";

include './footer.php';


/*################# PLUGIN FUNCTIONS #################*/


function alpha()
{
    global $sortcol, $sortdir, $pagesize;

    $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;
    $counter = 0;

    echo "&#091; ";

    foreach( $alphabet AS $ltr )
    {
        echo "<a href='" . _DP_MEMBERSLIST . "?letter=$ltr&sortcol=$sortcol&sortdir=$sortdir&pagesize=$pagesize'>$ltr</a>";

        if ( $counter == round( $num/2 ) )
        {
            echo "&nbsp;&#093;\n<br /><br />\n&#091;&nbsp;";
        }
        else if ( $counter != $num )
        {
            echo "&nbsp;&#124;&nbsp;\n";
        }

        $counter++;
    }

    echo "&nbsp;&#093;\n";

}  // End Function

function searchDB( $search, $row )
{
    global $sortcol, $sortdir, $pagesize;

    $nb = NULL;

    if ( $search != '' )
    {
        $match = ( $row == 1 ) ? ( translate( 'match' ) ) : ( translate( 'matches' ) );
        $nb = '<br />' . translate( 'Your Query Returned' ). ' <b>' . $row . '</b> ' . $match;
    }

    echo "<form class='makeinline' action='" . _DP_MEMBERSLIST . "' method='post'>\n";

        echo translate( 'Search for a User' ) . ":\n";

        echo '<input type="text" name="search" size="20" value="' . $search . '" />' . "\n"

            ."<input type='hidden' name='sortcol' value='$sortcol' />"
            ."<input type='hidden' name='sortdir' value='$sortdir' />"
            ."<input type='hidden' name='pagesize' value='$pagesize' />";

        echo "<input class='button' type='submit' value='" . translate( 'Go' ) . "'>";

    echo "</form>\n";

    return $nb;

}  // End Function

function pageNav( $total_pages, $page )
{
    global $letter, $sortcol, $sortdir, $srchret, $pagesize;

    $prev_page = $page - 1;

    if ( $prev_page > 0 )
    {
        echo "<td align='left' valign='top' width='75px'>\n";
        echo "<a href='" . _DP_MEMBERSLIST . "?letter=$letter&sortcol=$sortcol&sortdir=$sortdir&search=$srchret&page=$prev_page&pagesize=$pagesize'>";
        echo "<img src='images/download/left.gif' border='0px' alt='" . translate( 'Previous Page' ) . " ( $prev_page )' /></a>&nbsp;Prev</td>\n";
    }
    else
    {
        echo "<td align='left' width='45px'>&nbsp;</td>\n";
    }

    echo "<td align='center' valign='top'>\n";

    echo "<form action='" . _DP_MEMBERSLIST . "' method='get'>";

        echo "<b>" .translate( 'Jump To' ) . "&nbsp;</b>\n";

        echo "<input type='hidden' name='letter' value='$letter' />\n";
        echo "<input type='hidden' name='sortcol' value='$sortcol' />\n";
        echo "<input type='hidden' name='sortdir' value='$sortdir' />\n";
        echo "<input type='hidden' name='pagesize' value='$pagesize' />\n";
        echo "<input type='hidden' name='search' value='$srchret' />\n";

        echo "<select name='page' onChange='submit()'>\n";

        $count = 1;

        for( $n=1; $n <= $total_pages; $n++ )
        {
            if ( $n == $page )
            {
                echo "<option value='$n' selected='selected'>" . translate( 'Page' ) . " $page</option>\n";

            }
            else
            {
                echo "<option value='$n'>" . translate( 'Page' ) . " $count</option>\n";
            }

            $count++;
        }

        echo "</select>&nbsp;\n";

    echo "</form></td>\n";

    $next_page = $page + 1;

    if ( $next_page <= $total_pages )
    {
        echo "<td align='right' valign='top' width='75px'>\n";
        echo "Next&nbsp;<a href='" . _DP_MEMBERSLIST . "?letter=$letter&sortcol=$sortcol&sortdir=$sortdir&search=$srchret&page=$next_page&pagesize=$pagesize'>";
        echo "<img src='images/download/right.gif' border='0px' alt='Next Page ( $next_page )' /></a>\n";
        echo "</td>\n";
    }
    else
    {
        echo "<td align='right' width='45px'>&nbsp;</td>\n";
    }

}  // End Function

function perPage( $pagesize )
{
    global $letter, $sortcol, $sortdir, $srchret;

    $numbers = array( 5, 10, 15, 20, 25, 30, 40, 50 );
    $optn = count( $numbers );

    echo "<form class='makeinline' action='" . _DP_MEMBERSLIST . "' method='get'>\n";

        echo "<i>" .translate("Show") . "&nbsp;</i>";

        echo "<input type='hidden' name='letter' value='$letter'>"
            ."<input type='hidden' name='sortcol' value='$sortcol'>"
            ."<input type='hidden' name='sortdir' value='$sortdir'>"
            ."<input type='hidden' name='search' value='$srchret'>";

        echo "<select name='pagesize' onChange='submit()'>\n";

            for( $x = 0; $x < $optn; $x++ )
            {
                $sel = ( $pagesize == $numbers[ $x ] ) ? ( 'selected="selected"' ) : ( '' );

                echo "<option value='{$numbers[ $x ]}' $sel>{$numbers[ $x ]}</option>";
            }

        echo "</select>\n";

        echo "&nbsp;<i>" . translate( 'Users Per Page' ) . "</i>\n";

    echo "</form>\n";

    return $pagesize;

}  // End Function

function generate_header_row()
{
    $anchor = generate_sort_anchor( _SC_USER_NAME, "<b>" . translate( 'User Name' ) . "</b>" );
    echo $anchor;

    $anchor = generate_sort_anchor( _SC_USER_FROM, "<b>" . translate(' From' ) . "</b>" );
    echo $anchor;

    $anchor = generate_sort_anchor( _SC_USER_REGDATE, "<b>" . translate( 'Date Joined' ) . "</b>" );
    echo $anchor;

    $anchor = generate_sort_anchor( _SC_USER_EMAIL, "<b>" . translate( 'Email' ) . "</b>" );
    echo $anchor;

    $anchor = generate_sort_anchor( _SC_USER_URL, "<b>" . translate( 'URL' ) . "</b>" );
    echo $anchor;

    echo "<th height='25px' nowrap align='center'><b>PM</b></th>\n";

    if ( _MPN_ADMIN ) // Enable admin functions if logged in as admin
    {
        $cols = 11;
        echo "<th height='25px' align='center' nowrap='nowrap'><b>" . translate( 'Functions' ) . "</b></th>\n";
    }

}  // End Function

function generate_sort_anchor( $col, $title )
{
    global $sortcol, $sortdir, $incoming_sortcol, $incoming_sortdir, $letter, $srchret, $pagesize;

    // For Each Column Header, Decide What The Url Should Be

    $core_url = _DP_MEMBERSLIST . '?letter=' . $letter . '&search=' . $srchret . '&pagesize=' . $pagesize;


    if ( $incoming_sortcol == $col )
    {
        $sortcol = $incoming_sortcol;  // Already Sorted By This Column, Reverse The Direction
        $sortdir = ( $incoming_sortdir == 'a' ) ? ( 'd' ) : ( 'a' );
    }
    else
    {
        $sortcol = $col; // Sorted By Some Other Column, Sort Ascending First
        $sortdir = 'a';
    }

    // Generate Column Url Based On Current Sort

    $retval = "<th height='25px' align='center' nowrap='nowrap'><a href='" . $core_url;
    $retval .= '&sortcol=' . $sortcol;
    $retval .= '&sortdir=' . $sortdir . "'>";
    $retval .= $title."</a> ";

    if ( $incoming_sortcol == $col )
    {
        if ( $incoming_sortdir == 'a' ) // Determine Proper Image To Display
        {
            $retval .= "<img src='images/download/up.gif' width='16px' /></th>\n";
        }
        else
        {
            $retval .= "<img src='images/download/down.gif' width='16px' /></th>\n";
        }
    }
    else
    {
        $retval .= "<img src='images/download/dot-clear.gif' width='1px' /></th>\n";
    }

    $sortcol = $incoming_sortcol;
    $sortdir = $incoming_sortdir;

    return $retval;

} // End Function

?>
