<?php
// $Id: user_list.php,v 1.3 2005/10/28 11:56:02 ohwada Exp $

//================================================================
// user list
// 2005-01-20 K.OHWADA
//================================================================

include 'admin_header.php';
include_once $MODULE_ROOT."/class/pagenavi.php";

$MAX_USER = 50;
$max = $MAX_USER;
$index_num = sprintf(_WEBLINKS_USER_MAX, $MAX_USER);
$index_0 = _WEBLINKS_ADMIN_USER_EMAIL.$index_num;
$index_1 = _WEBLINKS_ADMIN_USER_EMAIL._WEBLINKS_USER_ALL;
$index_2 = _WEBLINKS_ADMIN_USER_LINK.$index_num;
$index_3 = _WEBLINKS_ADMIN_USER_NOLINK.$index_num;

xoops_cp_header();
echo "<h3>"._WEBLINKS_ADMIN_USER_MANAGE."</h3>\n";

echo "<table width='80%' border='0' cellspacing='1' class='outer'>";
echo "<tr class='odd'><td>";
echo " - <a href='index.php'>"._WEBLINKS_ADMIN_INDEX."</a>";
echo "<br /><br />\n";
echo " - <b>"._WEBLINKS_ADMIN_USER_MANAGE."</b>";
echo "<br /><br />\n";
echo " --- <a href='user_list.php?sortid=0'>$index_0</a>";
echo "<br /><br />\n";
echo " --- <a href='user_list.php?sortid=1'>$index_1</a>";
echo "<br /><br />\n";
echo " --- <a href='user_list.php?sortid=2'>$index_2</a>";
echo "<br /><br />\n";
echo " --- <a href='user_list.php?sortid=3'>$index_3</a>";
echo "<br /><br />\n";
echo " --- <a href='mail_users.php'>"._WEBLINKS_ADMIN_SENDMAIL."</a>";
echo "<br /><br />\n";
echo"</td></tr></table>\n";
echo"<br /><br />\n";

// pagenavi
$pagenavi = new pagenavi();
$pagenavi->set_max_sortid(3);
$pagenavi->get_get_parm();
$sortid = $pagenavi->get_sortid();

// user list
$lid_user_list   = $tbl_link->get_lid_user_list();
$lid_email_list  = $tbl_link->get_lid_email_list();
$uid_user_list   = $tbl_link->get_uid_user_list();
$xoops_uid_list  = $tbl_link->get_xoops_uid_list();

$uid_use_arr   = array();
$uid_nouse_arr = array();

foreach ($xoops_uid_list as $uid)
{
	if ( isset($uid_user_list[$uid]['use']) && ($uid_user_list[$uid]['use'] == 1) )
	{
		$uid_use_arr[] = $uid;
	}
	else
	{
		$uid_nouse_arr[] = $uid;
	}
}


switch ($sortid)
{
	case 3:
		$title   = $index_3;
		$desc    = _WEBLINKS_ADMIN_USER_LINK_DSC;
		$uid_arr = $uid_nouse_arr;
		$total   = count($uid_arr);
		break;

	case 2:
		$title   = $index_2;
		$desc    = _WEBLINKS_ADMIN_USER_LINK_DSC;
		$uid_arr = $uid_use_arr;
		$total   = count($uid_arr);
		break;

	case 1:
		$title = $index_1;
		$desc  = _WEBLINKS_ADMIN_USER_EMAIL_DSC;
		$total = count($lid_email_list);
		$max   = $total;
		break;

	case 0:
	default:
		$title = $index_0;
		$desc  = _WEBLINKS_ADMIN_USER_EMAIL_DSC;
		$total = count($lid_email_list);
		break;
}

echo "<h4>$title</h4>\n";
echo "$desc<br /><br />\n";

if ($total > 0)
{
	$pagenavi->set_show( $max );
	$pagenavi->set_total($total);
	$start = $pagenavi->get_start();
	$end   = $pagenavi->get_end();

	printf(_WEBLINKS_THERE_ARE_USER, $total);
	echo "<br />\n";
	printf(_WEBLINKS_USER_NUM, $start + 1, $end);
	echo "<br /><br />\n";

	switch ($sortid)
	{
		case 3:
		case 2:
			print_form_uid($uid_arr, $uid_user_list, $lid_user_list, $start, $end);
			break;

		case 1:
		case 0:
		default:
			print_form_lid($lid_email_list, $lid_user_list, $start, $end);
			break;
	}

	if ($total > 1)
	{
		$script = "user_list.php";
		$navi   = $pagenavi->build_navi($script, $total);

		if ($navi == -1)
		{
			echo "system error: script = $script, total = $total <br>\n";
			include XOOPS_ROOT_PATH.'/footer.php';
			exit();
		}

		echo "<div align='center'>$navi</div><br />\n";
	}
}
else
{
	echo "<font color='blue'>"._WEBLINKS_USER_NOFOUND."</font><br />\n";
}

xoops_cp_footer();
exit();


//---------------------------------------------------------
// function
//---------------------------------------------------------
function print_form_lid($lid_email_list, $lid_user_list, $start, $end)
{
	global $myts;

	echo "<form action='mail_users.php' method='post' name='memberslist' id='memberslist'>";
	echo "<table width='100%' border='0' cellspacing='1' cellpadding='4' class='outer'>";
	echo "<tr>";
	echo "<th align='center'><input type='checkbox' name='memberslist_checkall' id='memberslist_checkall' onclick='xoopsCheckAll(\"memberslist\", \"memberslist_checkall\");' /></th>";
	echo "<th align='center'>"._WLS_LINKID."</th>";
	echo "<th align='center'>"._WLS_NAME."</th>";
	echo "<th align='center'>"._WLS_SITETITLE."</th>";
	echo "<th align='center'>"._WLS_EMAIL."</th>";
	echo "<th align='center'>"._WEBLINKS_SUBMITTER."</th>";
	echo "<th align='center'>"._WEBLINKS_UID_EMAIL."</th>";
	echo "</tr>";

	for ($i=$start; $i<$end; $i++)
	{
		$lid = $lid_email_list[$i];

		$uid       = $lid_user_list[$lid]['uid'];
		$name      = $myts->makeTboxData4Show( $lid_user_list[$lid]['name'] );
		$email     = $myts->makeTboxData4Show( $lid_user_list[$lid]['email'] );
		$title     = $myts->makeTboxData4Show( $lid_user_list[$lid]['title'] );
		$url       = $myts->makeTboxData4Show( $lid_user_list[$lid]['url'] );
		$uid_uname = $myts->makeTboxData4Show( $lid_user_list[$lid]['uid_uname'] );
		$uid_email = $myts->makeTboxData4Show( $lid_user_list[$lid]['uid_email'] );

		$link_id  = sprintf("%03d",$lid);
		$modlink  = "link_manage.php?op=modLink&lid=".$lid;
		$userinfo = XOOPS_URL."/userinfo.php?uid=".$uid;

		$title    = $myts->makeTboxData4Show( $lid_user_list[$lid]['title'] );
		$modlink  = "link_manage.php?op=modLink&lid=".$lid;
		$lid_list = "<a href='$modlink'>$title</a><br />";

		if ($i % 2 == 0) 
		{
			$class = 'even';
		}
		else 
		{
			$class = 'odd';
		}

		echo "<tr class='$class'>";
		echo "<td align='center'><input type='checkbox' name='memberslist_id[]' id='memberslist_id[]' value='".$lid."' /></td>";
		echo "<td><a href='$modlink'>$link_id</a></td>";

		echo "<td>$name</td>";

		if ($url)
		{
			echo "<td align='center'><a href='$url' target='_blank'>$title</a></td>";
		}
		else
		{
			echo "<td>$title</td>";
		}

		if ($email)
		{
			echo "<td align='center'><a href='mailto:".$email."'><img src='".XOOPS_URL."/images/icons/email.gif' border='0' alt='mailto' /></a></td>";
		}
		else
		{
			echo "<td></td>";
		}

		if ($uid >1)
		{
			echo "<td><a href='$userinfo'>$uid_uname</a></td>";
		}
		elseif ($uid)
		{
			echo "<td><a href='$userinfo'>$uid_uname</a> ("._WEBLINKS_WEBMASTER.")</td>";
		}
		else
		{
			echo "<td align='center'>---</td>";
		}

		if ($uid_email)
		{
			echo "<td align='center'><a href='mailto:".$uid_email."'><img src='".XOOPS_URL."/images/icons/email.gif' border='0' alt='mailto' /></a></td>";
		}
		else
		{
			echo "<td></td>";
		}

		echo "</tr>";
	}

	echo "<tr class='foot'>";
	echo "<td></td>";
	echo "<td colspan='6'><input type='submit' value='"._WEBLINKS_SENDMAIL."' /></td>";
	echo "</tr>";
	echo "</table>";
	echo "</form>";
	echo "<br />\n";
}

function print_form_uid($uid_arr, $uid_user_list, $lid_user_list, $start, $end)
{
	global $myts;

	$action = XOOPS_URL."/modules/system/admin.php";

	echo "<form action='$action' method='post' name='memberslist' id='memberslist'>";
	echo "<input type='hidden' name='fct' value='mailusers' />";
	echo "<input type='hidden' name='op'  value='delete_many' />";

	echo "<table width='100%' border='0' cellspacing='1' cellpadding='4' class='outer'>";
	echo "<tr>";
	echo "<th align='center'><input type='checkbox' name='memberslist_checkall' id='memberslist_checkall' onclick='xoopsCheckAll(\"memberslist\", \"memberslist_checkall\");' /></th>";
	echo "<th align='center'>"._WLS_NAME."</th>";
	echo "<th align='center'>"._WLS_SITETITLE."</th>";
	echo "<th align='center'>"._WLS_EMAIL."</th>";
	echo "</tr>";

	for ($i=$start; $i<$end; $i++)
	{
		$uid   = $uid_arr[$i];
		$uname = $myts->makeTboxData4Show( $uid_user_list[$uid]['uname'] );
		$email = $myts->makeTboxData4Show( $uid_user_list[$uid]['email'] );

		$userinfo = XOOPS_URL."/userinfo.php?uid=".$uid;

		$lid_list = '';
		if ( isset($uid_user_list[$uid]['lid']) )
		{
			foreach ( $uid_user_list[$uid]['lid'] as $lid )
			{
				$title     = $myts->makeTboxData4Show( $lid_user_list[$lid]['title'] );
				$modlink   = "link_manage.php?op=modLink&lid=".$lid;
				$lid_list .= "<a href='$modlink'>$title</a><br />";
			}
		}

		if ($i % 2 == 0) 
		{
			$class = 'even';
		}
		else 
		{
			$class = 'odd';
		}

		echo "<tr class='$class'>";
		echo "<td align='center'>";
		echo "<input type='checkbox' name='memberslist_id[]' id='memberslist_id[]' value='".$uid."' />";
		echo "<input type='hidden' name='memberslist_uname[".$uid."]' id='memberslist_uname[]' value='".$uname."' />";
		echo "</td>";
		echo "<td><a href='$userinfo'>$uname</a></td>";
		echo "<td>$lid_list</td>";
		echo "<td><a href='mailto:".$email."'><img src='".XOOPS_URL."/images/icons/email.gif' border='0' alt='mailto' /></a></td>";
		echo "</tr>";
	}

	echo "<tr class='foot'>";
	echo "<td></td>";
	echo "<td colspan='5'><input type='submit' value='"._WEBLINKS_SENDMAIL."' /></td>";
	echo "</tr>";
	echo "</table>";
	echo "</form>";
	echo "<br />\n";
}

?>