<?php
/*
 *	W-AGORA	4.1
 *	-----------
 *	$Id: users.php,v 1.17 2005/06/10 22:19:16 mdruilhe Exp $
 *	Usage:		Users list
 *	Author:		Syloo (syloo@w-agora.net)
 */

	$bn_action="users";
	$bn_action_mode="L";
	include	("init.inc");


	if ($pattern ==	LABEL_ALL_USERS) {
		unset($pattern);
	}

	$first = (int) getFormVar('first');
	$sort = strip_tags(getFormVar('sort'));

	switch ($sort) {
		case "join":
			$sort_db = "unixdate desc";
			break;
		case "logins":
			$sort_db = "totallogins	desc";
			break;
		case "notes":
			$sort_db = "totalposts desc";
			break;
		case "name":
			$sort_db = "username";
			break;
		case "email":
			$sort_db = "useraddress";
			break;
		case "lastlogin":
			$sort_db = "lastlogin desc";
			break;
		case "id":
		default:
			$sort_db = "userid";
			break;
	}


# Execute before_access	program
# -----------------------------
	if (!empty($before_access)) include $before_access;

	$users = $db->getUsers($site, "", "", $pattern, "U.userid!='guest'", $sort_db);

	$total_users = count($users);

	$first_u = $first +	1;
	$last_u	= ($first_u	+ $nb_users_list - 1 > $total_users)? $total_users : $first_u +	$nb_users_list - 1;
	$int_dsp = LABEL_DISPLAY . ": $first_u - $last_u / $total_users";

	$alpha = array('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',LABEL_ALL_USERS);

	$nav_bar = getNavBar("$WA_SELF?site=$site&pattern=$pattern&sort=$sort&full=$full", $total_users, $first, $nb_users_list);

	display_header (TITLE_USERS_LIST, $header_footer);

	echo "<center>"	. TITLE_USERS_LIST;

	foreach($alpha as $k=>$let) {
		if ($let ==	$pattern) {
			echo "[$let] ";
		} elseif (empty($pattern) && ($let == LABEL_ALL_USERS))	{
			echo "[$let] ";
		} else {
			displayUrl("$WA_SELF?pattern=$let",	'',	'['.$let.']');
		}
	}

	if (!is_array($users)) {
		echo '<p align="center">'	. MSG_NO_USER .	"</p>";
	} else {
		echo '<p align="left">';
		if ($full == 1) {
			displayUrl("$WA_SELF?pattern=$pattern&sort=$sort&full=0&first=$first",	'',	LABEL_SIMPLE_DISPLAY);
		} else {
			displayUrl("$WA_SELF?pattern=$pattern&sort=$sort&full=1&first=$first",	'',	LABEL_FULL_DISPLAY);
		}
		echo '</p>';
		print "<div class=\"navbar\">$int_dsp</div>";
?>
	  <table width="95%" border="0" cellspacing="1" cellpadding="3" align="center" class="list">
		<tr class="light_row">
		  <td>
	       <?php displayUrl("$WA_SELF?pattern=$pattern&sort=id&full=$full&first=$first",	'',	COLUMN_ID);?>
	      </td>
<!--
		  <td>
	       <?php displayUrl("$WA_SELF?pattern=$pattern&sort=name&full=$full&first=$first",	'',	COLUMN_NAME);?>
	      </td>
-->
		  <td>
	       <?php displayUrl("$WA_SELF?pattern=$pattern&sort=join&full=$full&first=$first", '', COLUMN_JOIN_DATE);?>
	      </td>
		  <td>
	       <?php echo COLUMN_ADDRESS;?>
	      </td>
		  <td align="right">
	       <?php displayUrl("$WA_SELF?pattern=$pattern&sort=lastlogin&full=$full&first=$first", '', COLUMN_LAST_LOGIN);?>
	      </td>
		  <td align="right">
	       <?php displayUrl("$WA_SELF?pattern=$pattern&sort=logins&full=$full&first=$first", '', COLUMN_LOGINS);?>
	      </td>
		  <td align="right">
	       <?php displayUrl("$WA_SELF?pattern=$pattern&sort=notes&full=$full&first=$first", '', COLUMN_POSTS);?>
          </td>
<?php
	if ($full) {	?>
			  <td align="right"><?php echo COLUMN_HOME_PAGE?></td>
			  <td align="right"><?php echo COLUMN_ICQ?></td>
			  <td align="right"><?php echo COLUMN_AIM?></td>
			  <td align="right"><?php echo COLUMN_MSN?></td>
			  <td align="right"><?php echo COLUMN_YAHOO?></td>
	<?php
	}//if
	echo "</tr>";
	$i = 0;
	while (($i < $first) &&	(next($users)))	{
		$i++;
	}
	while (($i < $first	+ $nb_users_list) && (list($k,$user) = each($users))) {
		extract($user);
		$user_profile_url =	"profile.$ext?site=$site&showuser=".urlencode($userid);
		$address_link =	(empty($useraddress)) ? " - ": "<a	href=\"mail.$ext?site=$site&userid=".urlencode($userid)."&redirect=users\" class=\"label\">".LABEL_MAIL."</a>";
		$home_link = (empty($homepage))? "-": anchor($homepage,	'',	"<img src='$icon_dir/home.gif' border=0>", COLUMN_HOME_PAGE . ": $homepage");
		$icq_link =	(empty($icq))? "-":	anchor($user_profile_url, '', "<img	src='$icon_dir/icq.gif'	border=0>",	COLUMN_ICQ . ":	$icq");
		$aim_link =	(empty($aim))? "-":	anchor($user_profile_url, '', "<img	src='$icon_dir/aim.gif'	border=0>",	COLUMN_AIM . ":	$aim");
		$msn_link =	(empty($msn))? "-":	anchor($user_profile_url, '', "<img	src='$icon_dir/msnm.gif' border=0>",	COLUMN_MSN . ":	$msn");
		$yahoo_link	= (empty($yahoo))? "-":	anchor($user_profile_url, '', "<img	src='$icon_dir/yim.gif'	border=0>",	COLUMN_YAHOO . ": $yahoo");
		$join_date = (empty($unixdate))? "-" : formated_date($unixdate);
		$last_login_date = (empty($lastlogin))? "-" : formated_date($lastlogin);
		?>
			<tr class="row">
			  <td><?php displayUrl($user_profile_url,	'',	$userid, ALT_PROFILE);?></td>
<!--			  <td class="s_label"><?php  // echo $username?></td> -->
			  <td class="s_label"><?php echo $join_date?></td>
			  <td nowrap="nowrap" class="s_label"><?php echo $address_link?></td>
			  <td align="right" class="s_label"><?php echo $last_login_date?></td>
			  <td align="right" class="s_label"><?php echo $totallogins?></td>
			  <td align="right" class="s_label"><?php echo $totalposts?></td>
<?php
			if ($full) { ?>
			  <td align="right" class="s_label">&nbsp;<?php echo $home_link?></td>
			  <td align="right" class="s_label">&nbsp;<?php echo $icq_link?></td>
			  <td align="right" class="s_label">&nbsp;<?php echo $aim_link?></td>
			  <td align="right" class="s_label">&nbsp;<?php echo $msn_link?></td>
			  <td align="right" class="s_label"	>&nbsp;<?php echo $yahoo_link?></td>
<?php
			}//if
			echo "</tr>";
			$i++;
		}//while
	}//if
	echo "</table>";

	echo "$nav_bar";
	display_footer($header_footer);
?>
