Location: PHPKode > projects > ProNuke. Postnuke To Oracle > postnuke/html/modules/Members_List/index.php
<?php // $Id: index.php,v 1.28 2001/12/04 00:50:27 gregorrothfuss Exp $ $Name:  $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on Bjorn Sodergrens MyPHPortal Modified Member List.
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// Some code taken from MemberList coded by Paul Joseph Thompson
// of www.slug.okstate.edu
// In memoriam of Members List War ;)
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Francisco Burzi
// Purpose of file: Displays member listings
// ----------------------------------------------------------------------

if (!defined("LOADED_AS_MODULE")) {
         die ("You can't access this file directly...");
     }

include 'mainfile.php';

/* Credits to Edgar Miller -- http://www.bosna.de/ from his post on PHP-Nuke ( http://phpnuke.org/article.php?sid=2010&mode=nested&order=0&thold=0 )
Further Credits go to Djordjevic Nebojsa (nesh) for the fix for the fix */

$ModName = basename( dirname( __FILE__ ) );

modules_get_language();

function alpha() {
    // Creates the list of letters and makes them a link.
    global $sortby, $ModName;
        $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>[ ";
        $counter = 0;
        while (list(, $ltr) = each($alphabet)) {
            echo "<a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=$ModName&amp;file=index&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";
}

function SortLinks($letter) {  // Makes order by links..
        global $sortby, $ModName;
        if ($letter == "front") {
        $letter = _ALL;
    }
        echo "\n<center>\n";
        echo "<font class=\"pn-normal\"><b>"._SORTBY."&nbsp;[</b> </font>";
        if ($sortby == "uname" OR !$sortby) {
            echo "<font class=\"pn-normal\"><b>"._MNICKNAME."&nbsp;|&nbsp;</b></font>";
        } else {
            echo "<a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=uname\"><b>"._MNICKNAME."</b></a><b>&nbsp;|&nbsp;</b>";
        }
        if ($sortby == "name") {
            echo "<font class=\"pn-normal\"><b>"._MREALNAME."&nbsp;|&nbsp;</b></font>";
        } else {
            echo "<a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=name\"><b>"._MREALNAME."</b></a><b>&nbsp;|&nbsp;</b>";
        }
        if ($sortby == "femail") {
            echo "<font class=\"pn-normal\"><b>"._MEMAIL."&nbsp;|&nbsp;</b></font>";
        } else {
            echo "<a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=femail\"><b>"._MEMAIL."</b></a><b>&nbsp;|&nbsp;</b>";
        }
        if ($sortby == "url") {
            echo "<font class=\"pn-normal\"><b>"._MURL."&nbsp;</b></font>";
        } else {
            echo "<a class=\"pn-normal\" href=\"modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=url\"><b>"._MURL."</b></a><b>&nbsp;</b>";
        }
        echo "<b>]</b>\n</center>\n";
}

include("header.php");
    if (!authorised(0, 'Users::', '::', ACCESS_READ)) {
        echo _MODIFYUSERSNOAUTH;
        include 'footer.php';
        return;
    }

$pagesize = 20;

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

// All of the code from here to around line 125 will be optimized a little later
// This is the header section that displays the last registered and who's logged in and whatnot

global $dbconn;
$column = &$pntable['users_column'];
$myquery = buildSimpleQuery ('users', array ('uname'), '', "$column[uid] DESC", 1);
$result = $dbconn->Execute($myquery);
list($lastuser) = $result->fields;
echo "\n\n<!-- MEMBERS LIST -->\n\n";
    OpenTable();
        echo "<center><font class=\"pn-pagetitle\">$sitename "._MEMBERSLIST."</font></center><br><br>\n";
    closetable();
        echo "<br/><font class=\"pn-normal\"><b>"._GREETINGS."</b></font>
     <center><a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$lastuser\"><b>$lastuser</b></a>\n</center>\n<br/><br/>\n";
        $result = $dbconn->Execute("SELECT COUNT(*) FROM $pntable[users]");
        list($numrows) = $result->fields;

        if (authorised(0, 'Users::', '::', ACCESS_COMMENT)){
            $column = &$pntable['session_column'];
            $result2 = $dbconn->Execute("SELECT $column[username] as username,
                                         $column[guest] as guest
                                       FROM $pntable[session]
                                       WHERE $column[guest]=0");
            $member_online_num = $result2->PO_RecordCount();
            $who_online = "<font class=\"pn-normal\">"._ONLINEREG." </font><br><br>";
            $i = 1;
            while(!$result2->EOF) {
                $session = $result2->GetRowAssoc(false);
                $result2->MoveNext();
                if (isset($session["guest"]) and $session["guest"] == 0) {
                    $who_online .= "<a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$session[username]\">$session[username]</a>\n";
                    $who_online .= ($i != $member_online_num ? " - " : "");
                    $i++;
                }
            }
            echo "<center><font class=\"pn-normal\">"._WEHAVE." $numrows "._MREGISTERED." $member_online_num</font>\n";
            echo " <font class=\"pn-normal\">"._MREGONLINE."</font></center><br><br>";
        OpenTable2();
            echo "<center><font class=\"pn-normal\">$who_online</font></center\n";
        CloseTable2();
        echo "<br>";
        } else {
            echo "<center><font class=\"pn-normal\">"._WEHAVE." $numrows "._REGSOFAR."</font></center>\n<br>\n<br>\n";
        }

        alpha();
        SortLinks($letter);

// end of top memberlist section thingie
// This starts the beef...

        $min = $pagesize * ($page - 1); // This is where we start our record set from
        $max = $pagesize; // This is how many rows to select

        $column = &$pntable['users_column'];
        $count = "SELECT COUNT($column[uid]) FROM $pntable[users] "; // Count all the users in the db..

        if ( ( $letter != _OTHER ) AND ( $letter != _ALL ) ) {  // are we listing all or "other" ?
            $where = "UPPER($column[uname]) LIKE UPPER('".$letter."%') "; // I guess we are not..
        } else if ( ( $letter == _OTHER ) AND ( $letter != _ALL ) ) { // But other is numbers ?
            $where = "($column[uname] LIKE '0%'
                          OR $column[uname] LIKE '1%'
                          OR $column[uname] LIKE '2%'
                          OR $column[uname] LIKE '3%'
                          OR $column[uname] LIKE '4%'
                          OR $column[uname] LIKE '5%'
                          OR $column[uname] LIKE '6%'
                          OR $column[uname] LIKE '7%'
                          OR $column[uname] LIKE '8%'
                          OR $column[uname] LIKE '9%'
                          OR $column[uname] LIKE '-%'
                          OR $column[uname] LIKE '.%'
                          OR $column[uname] LIKE '@%'
                          OR $column[uname] LIKE '$%')";

            // fifers: while this is not the most eloquent solution, it is
            // cross database compatible.  We could do an if dbtype is mysql
            // then do the regexp.  consider for performance enhancement.
            //
            // "WHERE $column[uname] REGEXP \"^\[1-9]\" "
            // REGEX :D, although i think its MySQL only
            // Will have to change this later.
            // if you know a better way to match only the first char
            // to be a number in uname, please change it and email
            // hide@address.com the correction
            // or go to post-nuke project page and post
            // your correction there. Thanks, Bjorn.
        } else { // or we are unknown or all..
            $where = ""; // this is to get rid of anoying "undefinied variable" message
        }
        $sort = "$sortby ASC"; //sorty by .....

     // FTO. Count users before executing Query,
     // because Oracle doesn't support Rowcount. This will be for all databases

        if (! empty($where))
              {
               $result = $dbconn->Execute("$count WHERE $where");
              }
        else
              {
           $result = $dbconn->Execute("$count");
              }


        if ($result === false) {
            error_log("Error: " . $dbconn->ErrorNo() . ": " . $dbconn->ErrorMsg());
           PN_DBMsgError($dbconn, __FILE__, __LINE__, "Error accesing to the database");
        }
        list($num_rows_per_order) = $result->fields;
        
     //FTO. And now the query...
     // This is where we get our limit'd result set.
        $myquery = buildSimpleQuery('users', array('uid', 'name', 'uname', 'femail', 'url') ,$where, $sort, $max, $min); //select our data

        $result = $dbconn->Execute($myquery);
        if ($result === false) {
            error_log("Error: " . $dbconn->ErrorNo() . ": " . $dbconn->ErrorMsg());
           PN_DBMsgError($dbconn, __FILE__, __LINE__, "Error accesing to the database");
        }

     //FTO. Not supported by Oracle
     //        $num_rows_per_order = $result->PO_RecordCount();



        echo "<br>";
        if ( $letter != "front" ) {
            echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\"><tr>\n";
            echo "<td BGCOLOR=\"$bgcolor2\" align=\"center\"><font class=\"pn-normal\"><b>"._NICKNAME."</b></font></td>\n";
            echo "<td BGCOLOR=\"$bgcolor2\" align=\"center\"><font class=\"pn-normal\"><b>"._REALNAME."</b></font></td>\n";
            echo "<td BGCOLOR=\"$bgcolor2\" align=\"center\"><font class=\"pn-normal\"><b>"._EMAIL."</b></font></td>\n";
            echo "<td BGCOLOR=\"$bgcolor2\" align=\"center\"><font class=\"pn-normal\"><b>"._HOMEPAGE."</b></font></td>\n";
            $cols = 4;
            if (authorised(0, 'Users::', '::', ACCESS_EDIT)){
                $cols = 5;
                echo "<td bgcolor=\"$bgcolor2\" align=\"center\"><font class=\"pn-normal\"><b>"._FUNCTIONS."</b></font></td>\n";
            }
            echo "</tr>";
            $a = 0;
            $dcolor_A = "$bgcolor3";
            $dcolor_B = "$bgcolor1";

//            $num_users = $result->PO_RecordCount(); //number of users per sorted and limit query
            if ( $num_rows_per_order > 0  ) {
                while(!$result->EOF) {
                    $user = $result->GetRowAssoc(false);
                    $result->MoveNext();
                    $dcolor = ($a == 0 ? $dcolor_A : $dcolor_B);
                    echo "<tr><td bgcolor=\"$dcolor\"><a class=\"pn-normal\" href=\"user.php?op=userinfo&amp;uname=$user[uname]\">$user[uname]</a>&nbsp;</td>\n";
                    echo "<td bgcolor=\"$dcolor\"><font class=\"pn-normal\">$user[name]&nbsp;</font></td>\n";
                    echo "<td bgcolor=\"$dcolor\"><font class=\"pn-normal\">$user[femail]&nbsp;</font></td>\n";
                    echo "<td bgcolor=\"$dcolor\"><a class=\"pn-normal\" href=\"";

                    if($user[url]=='') {
            $user[url]='';
            }
                    else {
            if(!ereg('http://', $user[url])) {
                $user[url]="http://$user[url]";
            }
            }
            echo "$user[url]\" target=new>$user[url]</a>&nbsp;</td>\n";
                    if (authorised(0, 'Users::', '::', ACCESS_EDIT)){
                        echo "<td bgcolor=$dcolor align=center><font class=\"pn-normal\">[ <a class=\"pn-normal\" href=\"admin.php?chng_uid=$user[uid]&amp;op=modifyUser\"><font class=\"pn-normal\">"._EDIT."</font></a><font class=\"pn-sub\"> | </font>\n";
                        echo "<a class=\"pn-normal\" href=\"admin.php?op=delUser&amp;chng_uid=$user[uid]\"><font class=\"pn-normal\">"._DELETE."</font></a> ]</font></td>\n";
                    }
                    echo "</tr>";
                    $a = ($dcolor == $dcolor_A ? 1 : 0);
                }
// start of next/prev/row links.

                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 ( $numrows > $pagesize ) {
                    $total_pages = ceil($numrows / $pagesize); // How many pages are we dealing with here ??
                    $prev_page = $page - 1;

                    if ( $prev_page > 0 ) {
                        echo "<td align='left' width='15%'><a class=\"pn-normal\" href='modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=$sortby&amp;page=$prev_page'>";
                        echo "<img src=\"modules/$ModName/images/left.gif\" border=\"0\" Alt=\""._PREVIOUS." ($prev_page)\"></a></td>";
                    } else {
                        echo "<td width='15%'>&nbsp;</td>\n";
                    }

                    echo "<td align='center' width='70%'>";
                    echo "<font class=\"pn-sub\">$num_rows_per_order "._USERSFOUND." $letter ($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 class=\"pn-normal\" href='modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=$sortby&amp;page=$next_page'>";
                        echo "<img src=\"modules/$ModName/images/right.gif\" border=\"0\" Alt=\"Next Page ($next_page)\"></a></td>";
                    } else {
                        echo "<td width='15%'>&nbsp;</td></tr>\n";
                    }
// Added a numbered page list, only shows up to 50 pages.

                        echo "<tr><td colspan=\"3\" align=\"center\">";
                        echo " <font class=\"pn-sub\">[ </font>";

                        for($n=1; $n < $total_pages; $n++) {


                            if ($n == $page) {
                echo "<font class=\"pn-sub\">$n</font></a>";
                            } else {
                echo "<a class=\"pn-normal\" href='modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=$sortby&amp;page=$n'>";
                echo "<font class=\"pn-sub\">$n</font></a>";
                }
                            if($n >= 50) {  // if more than 50 pages are required, break it at 50.
                                $break = true;
                                break;
                            } else {  // guess not.
                                echo "<font class=\"pn-sub\"> | </font>";
                            }
                        }

                        if(!isset($break)) { // are we supposed to break ?
                if ($n == $page) {
                            echo "<font class=\"pn-sub\">$n</font></a>";
                } else {
                            echo "<a class=\"pn-normal\" href='modules.php?op=modload&amp;name=$ModName&amp;file=index&amp;letter=$letter&amp;sortby=$sortby&amp;page=$total_pages'>";
                            echo "<font class=\"pn-sub\">$n</font></a>";
                }
                        }
                        echo " <font class=\"pn-sub\">]</font> ";
                        echo "</td></tr>";

// This is where it ends

                }else{  // or we dont have any users..
                    echo "<td align='center'>";
                    echo "<font class=\"pn-sub\">$num_rows_per_order "._USERSFOUND." $letter</font>";
                    echo "</td></tr>";
                 }

                 echo "</table>\n";
         CloseTable();
                echo "</td></tr>\n";

// end of next/prev/row links

            } else { // you have no members on this letter, hahaha
                echo "<tr><td bgcolor=\"$dcolor_A\" colspan=\"$cols\" align=\"center\"><br>\n";
                echo "<font class=\"pn-normal\">"._NOMEMBERS." $letter</font>\n";
                echo "<br></td></tr>\n";
            }

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

        include("footer.php");

?>
Return current item: ProNuke. Postnuke To Oracle