<?PHP
/************************************************************************/
/* DUNE by NPDS                                                         */
/* ===========================                                          */
/*                                                                      */
/* Based on PhpNuke 4.x source code                                     */
/*                                                                      */
/* NPDS Copyright (c) 2002-2007 by Philippe Brunier                     */
/*                                                                      */
/* 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.       */
/************************************************************************/
if (!function_exists("Mysql_Connexion")) {
   include ("mainfile.php");
}

// Make Member_list Private or not
if (!AutoReg()) { unset($user); }
if (($member_list==1) AND ($user=="") AND ($admin=="")) {
   Header("Location: index.php");
}

function alpha() {
   global $sortby, $list;
   $alphabet = array ("".translate("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","".translate("Other")."");

   echo "<table width=\"100%\" border=\"0\"><tr><td width=\"50%\" align=\"center\" valign=\"top\">";
   $num = count($alphabet) - 1;
   $counter = 0;
   while (list(, $ltr) = each($alphabet)) {
      echo "<a href=\"memberslist.php?letter=$ltr&amp;sortby=$sortby&amp;list=$list\" class=\"noir\">$ltr</a>";
      if ( $counter == round($num/2) ) {
         echo " ]<br />[ ";
      } elseif ( $counter != $num ) {
         echo "&nbsp;|&nbsp;";
      }
      $counter++;
   }
   echo "</td><td class=\"noir\">";
   echo "<form action=\"memberslist.php\" method=\"post\">";
   echo translate("Search")." : <input class=\"textbox_standard\" type=\"input\" name=\"letter\" size=\"30\" maxlenght=\"60\">";
   echo "<input type=\"hidden\" name=\"list\" value=\"".urldecode($list)."\">";
   echo "<input type=\"hidden\" name=\"TempoSuperCache\" value=\"OFF\">";
   echo "</form>";
   echo "</td></tr></table>";
}

function unique($ibid) {
   while (list(,$to_user) = each($ibid)) {
      if (!$Xto_user[$to_user]) {
         $Xto_user[$to_user]=$to_user;
      }
   }
   return ($Xto_user);
}

function SortLinks($letter) {
   global $sortby, $list, $admin;
   if ($letter == "front") {
      $letter = translate("All");
   }
   $sort=false;
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td align=\"center\">\n";
   echo translate("Sort by:")." ";
   if ($sortby == "uname ASC" OR !$sortby) {
      echo translate("nickname")."&nbsp;|&nbsp;";
      $sort=true;
   } else {
      echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=uname%20ASC&amp;list=$list\" class=\"noir\">".translate("nickname")."</a>&nbsp;|&nbsp;";
   }
   if ($sortby == "name ASC") {
      echo translate("real name")."&nbsp;|&nbsp;";
      $sort=true;
   } else {
      echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=name%20ASC&amp;list=$list\" class=\"noir\">".translate("real name")."</a>&nbsp;|&nbsp;";
   }
   if ($sortby == "user_avatar ASC") {
      echo translate("Avatar")."&nbsp;|&nbsp;";
      $sort=true;
   } else {
      echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=user_avatar%20ASC&amp;list=$list\" class=\"noir\">".translate("Avatar")."</a>&nbsp;|&nbsp;";
   }
   if (($sortby == "femail ASC") or ($sortby == "email ASC")) {
      echo translate("Email")."&nbsp;|&nbsp;";
      $sort=true;
   } else {
      if ($admin) {
         echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=email%20ASC&amp;list=$list\" class=\"noir\">".translate("Email")."</a>&nbsp;|&nbsp;";
      } else {
         echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=femail%20ASC&amp;list=$list\" class=\"noir\">".translate("Email")."</a>&nbsp;|&nbsp;";
      }
   }
   if ($sortby == "user_from ASC") {
      echo translate("Location")."&nbsp;|&nbsp;";
      $sort=true;
   } else {
      echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=user_from%20ASC&amp;list=$list\" class=\"noir\">".translate("Location")."</a>&nbsp;|&nbsp;";
   }
   if ($sortby == "url DESC") {
      echo translate("url")."&nbsp;|&nbsp;";
      $sort=true;
   } else {
      echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=url%20DESC&amp;list=$list\" class=\"noir\">".translate("url")."</a>&nbsp;|&nbsp;";
   }
   if ($sortby == "mns DESC") {
      echo translate("Mini-Web site")."&nbsp;|&nbsp;";
      $sort=true;
   } else {
      echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=mns%20DESC&amp;list=$list\" class=\"noir\">".translate("Mini-Web site")."</a>&nbsp;|&nbsp;";
   }
   if ($sortby == "uid DESC") {
      echo "I.D";
      $sort=true;
   } else {
      echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=uid%20DESC&amp;list=$list\" class=\"noir\">I.D</a>";
   }
   if (!$sort) {$sortby="uname ASC";}

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

function avatar($user_avatar) {
   if (!$user_avatar) {
      $imgtmp="images/forum/avatar/blank.gif";
   } else if (stristr($user_avatar,"users_private")) {
      $imgtmp=$user_avatar;
   } else {
      if ($ibid=theme_image("forum/avatar/$user_avatar")) {$imgtmp=$ibid;} else {$imgtmp="images/forum/avatar/$user_avatar";}
      if (!file_exists($imgtmp)) {$imgtmp="images/forum/avatar/blank.gif";}
   }
   return ($imgtmp);
}

   // OFF temporairement SC pour la recherche
   if ($TempoSuperCache=="OFF") {$SuperCache=false;}

   include("header.php");
   $pagesize = $show_user;

   $letter=removeHack(stripslashes(htmlspecialchars($letter, ENT_QUOTES)));
   $sortby=removeHack($sortby);
   if (!isset($letter)) { $letter = translate("All"); }
   if (!isset($sortby)) { $sortby = "uid DESC"; }
   if (!isset($page)) { $page = 1; }

   if ($list!="") {
      $tempo=unique(explode(",",$list));
      $list=urlencode(implode(",",$tempo));
   }
   $result = sql_query("select uname from ".$NPDS_Prefix."users order by uid DESC limit 0,1");
   list($lastuser) = sql_fetch_row($result);
   echo "<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\" border=\"0\"><tr><td class=\"header\">\n";
   echo translate("Welcome to")." $sitename - ".translate("Members List");
   echo "</td></tr></table>\n";
   opentable();
   echo "<p align=\"center\">".translate("Greetings to our latest registered user:")." <a href=\"user.php?op=userinfo&amp;uname=$lastuser\" class=\"noir\">$lastuser</a></p><br />";
   if (!$admin) {
      if ($SuperCache) {
         $cache_obj = new cacheManager();
         $cache_obj->startCachingPage();
      }
   }
   if (($cache_obj->genereting_output==1) or ($cache_obj->genereting_output==-1) or (!$SuperCache) or ($admin)) {
      alpha();
      SortLinks($letter);

      $min = $pagesize * ($page - 1);
      $max = $pagesize;

      $count = "SELECT COUNT(uid) AS total FROM ".$NPDS_Prefix."users ";
      $select = "select uid, name, uname, femail, url, user_regdate, user_from, email, is_visible, user_viewemail, user_avatar, mns from ".$NPDS_Prefix."users ";
      if ( ( $letter != "".translate("Other")."" ) AND ( $letter != "".translate("All")."" ) ) {
         $where = "where uname like '".$letter."%'";
      } else if ( ( $letter == "".translate("Other")."" ) AND ( $letter != "".translate("All")."" ) ) {
         $where = "where uname REGEXP \"^\[1-9]\" ";
      } else {
         $where = "";
      }
      global $member_invisible;
      if ($member_invisible) {
         if ($admin)
            $and="";
         else {
            if ($where)
               $and="and is_visible=1 ";
            else
               $and="where is_visible=1 ";
         }
      } else {
         $and="";
      }

      $sort = "order by $sortby";
      $limit = " LIMIT ".$min.", ".$max;
      $count_result = sql_query($count.$where);
      list($num_rows_per_order) = sql_fetch_row($count_result);
      $result = sql_query($select.$where.$and.$sort.$limit);
      echo "<br />";
      if ( $letter != "front" ) {
         echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"1\" border=\"0\"><tr class=\"header\">\n";
         echo "<td class=\"box\"><span style=\"font-size: 10px;\"><b>".translate("Nickname")."</b></span></td>\n";
         echo "<td class=\"box\">&nbsp;</td>\n";
         echo "<td class=\"box\" align=\"center\">&nbsp;</td>";
         echo "<td class=\"box\" align=\"center\">&nbsp;</td>";
         echo "<td class=\"box\"><span style=\"font-size: 10px;\"><b>".translate("Real Name")."</b></span></td>\n";
         if ($sortby!="user_from ASC") {
            echo "<td class=\"box\"><span style=\"font-size: 10px;\"><b>".translate("Email")."</b></span></td>\n";
         } else {
            echo "<td class=\"box\"><span style=\"font-size: 10px;\"><b>".translate("Location")."</b></span></td>\n";
         }
         echo "<td class=\"box\"><span style=\"font-size: 10px;\"><b>".translate("URL")."</b></span></td>\n";
         $cols = 7;
         if ($admin) {
            $cols = 9;
            echo "<td class=\"box\" align=\"center\" width=\"12%\"><span style=\"font-size: 10px;\"><b>".translate("Functions")."</b></span></td><td class=\"box\">&nbsp;</td>\n";
         }
         echo "</tr>";
         $a = 0;
         $num_users = sql_num_rows($result);
         if ( $num_rows_per_order > 0  ) {
            global $anonymous, $user;
            while($temp_user = sql_fetch_assoc($result) ) {
               $rowcolor = tablos();
               if ($temp_user[mns]) {$mns="<a href=\"minisite.php?op=$temp_user[uname]\" alt=\"\" title=\"".translate("Mini-Web site")."\" target=\"_blank\" class=\"heada\"><b>(w)</b></a>";} else {$mns="";}
               echo "<tr $rowcolor><td><a href=\"user.php?op=userinfo&amp;uname=$temp_user[uname]\" alt=\"\" title=\"".date(translate("dateinternal"),$temp_user[user_regdate])."\"  class=\"heada\">$temp_user[uname]</a>&nbsp;$mns</td>\n";
               echo "<td valign=\"middle\">";
               if ($ibid_avatar=avatar($temp_user[user_avatar]))
                  echo "<img src=\"".$ibid_avatar."\" width=\"20\" height=\"20\" border=\"0\" alt=\"\" title=\"\" />";
               else
                  echo "&nbsp;";
               echo "</td>";
               if ($temp_user[uname]!=$anonymous) {
                  if ($user) {
                     if ($ibid=theme_image("forum/icons/posticon.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/forum/icons/posticon.gif";}
                     echo "<td><a href=\"replypmsg.php?send=".urlencode($temp_user[uname])."\"><img src=\"$imgtmp\" border=\"0\" alt=\"\" title=\"".translate("Send internal Message")."\" /></a></td>";
                     echo "<td align=\"center\">";
                     echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=$sortby&amp;list=$list".urlencode($temp_user[uname]).",&amp;page=$page\" class=\"heada\">";
                     echo "<b>+</b></a></td>";
                  } else {
                     echo "<td>&nbsp;</td>";
                     echo "<td>&nbsp;</td>";
                  }
               } else {
                  echo "<td>&nbsp;</td>";
                  echo "<td>&nbsp;</td>";
               }
               echo "<td><span style=\"font-size: 10px;\">$temp_user[name]</span>&nbsp;</td>\n";
               if ($sortby!="user_from ASC") {
                  if ($admin) {
                     echo "<td><a href=\"mailto:".anti_spam($temp_user[email])."\" class=\"noir\"><span style=\"font-size: 10px;\">".substr($temp_user[email],0,strpos($temp_user[email],"@"))."</span></a>&nbsp;</td>\n";
                  } else {
                     if ($temp_user[user_viewemail]) {
                        echo "<td><a href=\"mailto:".anti_spam($temp_user[email])."\" class=\"noir\"><span style=\"font-size: 10px;\">".substr($temp_user[email],0,strpos($temp_user[email],"@"))."</span></a>&nbsp;</td>\n";
                     } else {
                        echo "<td><span style=\"font-size: 10px;\">".substr($temp_user[femail],0,strpos($temp_user[femail],"@"))."</span>&nbsp;</td>\n";
                     }
                  }
               } else {
                  echo "<td><span style=\"font-size: 10px;\">$temp_user[user_from]</span>&nbsp;</td>\n";
               }
               echo "<td><a href=\"$temp_user[url]\" target=\"_blank\" class=\"noir\"><span style=\"font-size: 10px;\">$temp_user[url]</span></a>&nbsp;</td>\n";
               if ($admin) {
                  echo "<td align=\"right\"><table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"left\" nowrap=\"nowrap\"><a href=\"admin.php?chng_uid=$temp_user[uid]&amp;op=modifyUser\" class=\"noir\"><span style=\"font-size: 10px;\">".translate("Edit")."</span></a>\n";
                  echo "&nbsp;<a href=\"admin.php?op=delUser&amp;chng_uid=$temp_user[uid]\" class=\"rouge\"><span style=\"font-size: 10px;\">".translate("Delete")."</span></a></td><td>\n";
                  $op_result = sql_query("select open from ".$NPDS_Prefix."users_status where uid='$temp_user[uid]'");
                  list($open_user) = sql_fetch_row($op_result);
                  if ($open_user ==1) {
                     echo "<span style=\"font-size: 10px;\">OK</span></td>";
                  } else {
                     echo "<span style=\"font-size: 10px;\"><b>NOK</b></span></td>";
                  }
                  echo "</tr></table></td><td>";
                  if (!$temp_user[is_visible]) {
                     echo "<span style=\"font-size: 10px;\"><b>[I]</b></span></td>";
                  } else {
                     echo "&nbsp;&nbsp;</td>";
                  }
               }
               echo "</tr>";
            }

            if ($user) {
               echo "<tr><td colspan=\"$cols\" align=\"left\">\n";
               echo "<hr class=\"ongl\"><li>".urldecode($list)."</li><br /><hr noshade class=\"ongl\">";
               echo "[ <a href=\"memberslist.php?letter=$letter&amp;sortby=$sortby&amp;page=$page\" class=\"noir\">".translate("RAZ member's list")."</a> ]";
               if ($list) {
                  echo " - [ <a href=\"replypmsg.php?send=".substr($list,0,strlen($list)-3)."\" class=\"noir\">".translate("Write to the list")."</a> ]";
               }
            }
            echo "</td></tr>\n<tr><td colspan=\"$cols\" align=\"right\">\n";
            echo "<br />";
            echo "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"4\" cols=\"3\" border=\"0\"><tr>";
            if ( $num_rows_per_order > $pagesize ) {
               $total_pages = ceil($num_rows_per_order / $pagesize); // How many pages are we dealing with here ??
               $prev_page = $page - 1;
               if ( $prev_page > 0 ) {
                  echo "<td align=\"right\" width=\"15%\" class=\"header\"><a href=\"memberslist.php?letter=$letter&amp;sortby=$sortby&amp;list=$list&amp;page=$prev_page\">";
                  if ($ibid=theme_image("download/left.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/download/left.gif";}
                  echo "<img src=\"$imgtmp\" border=\"0\" alt=\"".translate("Previous Page")." ($prev_page)\" /></a></td>";
               } else {
                  echo "<td width=\"15%\" class=\"header\">&nbsp;</td>\n";
               }
               echo "<td align=\"center\" width=\"70%\" class=\"header\">";
               echo "$num_rows_per_order ".translate("users found for")." <b>$letter</b> ($total_pages ".translate("pages").", $num_users ".translate("users shown").").";
               echo "</td>";
               $next_page = $page + 1;
               if ( $next_page <= $total_pages ) {
                  echo "<td align=\"left\" width=\"15%\" class=\"header\"><a href=\"memberslist.php?letter=$letter&amp;sortby=$sortby&amp;list=$list&amp;page=$next_page\">";
                  if ($ibid=theme_image("download/right.gif")) {$imgtmp=$ibid;} else {$imgtmp="images/download/right.gif";}
                  echo "<img src=\"$imgtmp\" border=\"0\" alt=\"".translate("Next Page")." ($next_page)\" /></a></td>";
               } else {
                  echo "<td width=\"15%\" class=\"header\">&nbsp;</td></tr>\n";
               }
               echo "<tr><td colspan=\"3\" align=\"center\" class=\"header\">";
               echo "[ ";
               for($n=1; $n < $total_pages; $n++) {
                  if ($n == $page) {
                     echo "<span class=\"rouge\">$n</span>";
                  } else {
                     echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=$sortby&amp;list=$list&amp;page=$n\" class=\"box\">$n</a>";
                  }
                  if ($n >= 150) {  // if more than 150 pages are required, break it at 150.
                     $break = true;
                     break;
                  } else {
                     echo " | ";
                  }
               }
               if (!isset($break)) {
                  if ($n == $page) {
                     echo "<span class=\"rouge\">$n</span>";
                  } else {
                     echo "<a href=\"memberslist.php?letter=$letter&amp;sortby=$sortby&amp;list=$list&amp;page=$total_pages\" class=\"box\">$n</a>";
                  }
               }
               echo " ] ";
               echo "</td></tr>";
            } else {
               echo "<td align=\"center\">";
               echo "$num_rows_per_order ".translate("users found").".";
               echo "</td></tr>";
            }
            echo "</table>\n";
            echo "</td></tr>\n";
         } else {
            echo "<tr><td colspan=\"$cols\" align=\"center\"><br />\n";
            echo "<b>".translate("No Members Found for")." $letter</b>\n";
            echo "<br /></td></tr>\n";
         }
         echo "\n</table>\n";
      }
      closetable();
   }
   if (!$admin) {
      if ($SuperCache) {
         $cache_obj->endCachingPage();
      }
   }
   include("footer.php");
?>