<script type="text/javascript">
	function pageSubmit(val){
		document.contentForm.action = val;
		document.contentForm.method = 'post';
		document.contentForm.submit();
	}
	function setSort(detailId,sortkey,order){
		document.contentForm.Id.value = detailId;
		document.contentForm.sortkey.value = sortkey;
		document.contentForm.newOrder.value = order;
		document.contentForm.action = 'index.php?action=userSearch&op=sort&detailId='+detailId+'&key='+sortkey+'&order='+order;
		document.contentForm.method = 'post';
		document.contentForm.submit();
	}
</script>
<{include file="db:user_header.html"}>
<h3><{$smarty.const._MD_USER_LANG_USERLIST}></h3>

<{if $head}>
<form name="contentForm" method="post">
<table class="outer">
<input type="hidden" name="Id" value="<{$detailId}>"/>
<input type="hidden" name="sortkey" value="<{$sortkey}>"/>
<input type="hidden" name="newOrder" value="<{$order}>"/>
	<tr>
	<{foreach item=position from=$head}>
  		<th align="center"><{$position.name}>
  		<{if $position.list_sort_key eq 1}>
  		<div>
  		<input type="image" src="images/up.gif" alt="<{$smarty.const._ASCENDING}>" title="<{$smarty.const._ASCENDING}>" 
  		onclick="setSort('<{$position.user_detail_id}>','<{$position.column_name}>','ASC');"/>
      	<input type="image" src="images/down.gif" alt="<{$smarty.const._DESCENDING}>" title="<{$smarty.const._DESCENDING}>" 
      	onclick="setSort('<{$position.user_detail_id}>','<{$position.column_name}>','DESC');"/>
      	</div>
      	<{/if}>
      	</th>
	<{/foreach}>
		<th align="center"><{$smarty.const._MD_USER_LANG_ACTION}></th>
	</tr>
	<{if $userslist}>
	<{foreach item=row from=$userslist}>
	<tr class="<{cycle values="odd,even" name="c0" }>">
		<{foreach item=position from=$head}>
			<{assign var='extendFlg' value='true'}>
			<{assign var='rowTag' value=$position.column_name}>
			<!-- userExtendTableName is 'user_user_extend' + extendTable's user_detail_id -->
			<{assign var='extendTbl' value='user_user_extend'|cat:$position.user_detail_id}>
			
			<!-- if the row key include this column_name,extendTable is not exist. -->
			<{foreach key=key item=rowInfo from=$row}>
				<{if $rowTag eq $key}>
					<{assign var='extendFlg' value='false'}>
				<{/if}>
			<{/foreach}>
			
			<!-- if extendTable is exist, show extendTable's content-->
			<td>
			<{if $extendFlg eq 'true'}>
				<table>
					<{foreach item=extendValue from=$row.$extendTbl}>
						<tr>
							<td>
								<{$extendValue}>
							</td>
						</tr>
					<{/foreach}>
				</table>
			<!-- show userTable's content -->
			<{else}>
				<{$row.$rowTag}>	
			<{/if}>
			</td>
		<{/foreach}>
		<td>
			<table>
				<tr>
					<td align="center"><a href="index.php?action=userInfo&uid=<{$row.uid}>"><img src="images/property.gif" alt="<{$smarty.const._VIEW}>" title="<{$smarty.const._VIEW}>" /></a>
					<{if $userId eq $row.uid}>
					<a href="<{$smarty.const.XOOPS_URL}>/edituser.php?uid=<{$row.uid}>"><img src="images/edit.gif" title="<{$smarty.const._EDIT}>" /></a>
					<{/if}>
					<{if $userId eq $row.uid && !$isModerator && $isSelfDelete && $row.uid != 1}>
					<a href="<{$smarty.const.XOOPS_URL}>/user.php?op=delete&uid=<{$row.uid}>"><img src="images/delete.gif" alt="<{$smarty.const._DELETE}>" title="<{$smarty.const._DELETE}>" /></a>
					<{/if}>
					<{if $userId neq $row.uid && $isModerator && $row.activate eq 2}>
					<a href="index.php?op=userSu&uid=<{$row.uid}>"><img src="images/update.gif" alt="<{$smarty.const._MD_USER_LANG_ACCOUNT_CHANGE}>" title="<{$smarty.const._MD_USER_LANG_ACCOUNT_CHANGE}>" /></a></td>
					<{/if}>
				</tr>
			</table>
		</td>
	</tr>
	<{/foreach}>
	<{/if}>
</table>
<{/if}>

<!-- set search data-->
<{if $hiddenData}>
	<{foreach item=hiddenValue key=key from=$hiddenData}>
	<{if is_array($hiddenValue)}>
		<{foreach item=v from=$hiddenValue}>
			<input type="hidden" name="<{$key|cat:'[]'}>" value="<{$v}>">
		<{/foreach}>
	<{else}>
		<input type="hidden" name="<{$key}>" value="<{$hiddenValue}>">
	<{/if}>
	<{/foreach}>
<{/if}>

<!-- page -->
<{if $pagenavi}>
	<table>
		<tr>
			<td align="center">
	<{if $page neq 1}>
		<{foreach item=pageValue key=key from=$pagenavi}>
			<{if $key eq $page-1}>
			<a href="#" onclick="pageSubmit('<{$pageValue}>');">&laquo;</a>
			<{/if}>
		<{/foreach}>
	<{/if}>	
	
	<{assign var='counter' value=1}>	
	<{assign var='offset' value=4}>
	<{assign var='totalPages' value=$pagenavi|@count}>
	<{foreach item=pageValue key=key from=$pagenavi}>
	<{if $counter eq $page}>
		<strong>(<{$key}>)</strong>
	<{elseif ($counter>$page-$offset && $counter<$page+$offset)||$counter eq 1||$counter eq $totalPages}>	
		<{if $counter eq $totalPages && $page<$totalPages-$offset}>
		...
		<{/if}>
		<a href="#" onclick="pageSubmit('<{$pageValue}>');"><{$counter}></a>
		<{if $counter eq 1 && $page>1+$offset}>
		...
		<{/if}>
	<{/if}>
	<{assign var='counter' value=$counter+1}>
	<{/foreach}>
	
	<{if $page neq $pagenavi|@count}>
		<{foreach item=pageValue key=key from=$pagenavi}>
			<{if $key eq $page+1}>
			<a href="#" onclick="pageSubmit('<{$pageValue}>');">&raquo;</a>
			<{/if}>
		<{/foreach}>
	<{/if}>
			</td>		
		</tr>
	</table>
<{/if}>

</form>
<{include file="db:user_footer.html"}>
