<?php TPL::output('admin/global/header.tpl.htm'); ?>

<!--left-->
<?php TPL::output('admin/global/left.tpl.htm'); ?>
<!--left-->

<!-- main -->
<div id="main-content">
	<div class="clear"></div>
	<div class="content-box">
		<div class="content-box-header">
			<h3>Members List</h3>
			<ul class="content-box-tabs">
				<li><a href="#tab1" class="default-tab current">Members List</a></li>
				<li><a href="#tab2" class="">Search</a></li>
			</ul>
			<div class="clear"></div>
		</div>
		<div class="content-box-content">
			<div class="tab-content default-tab" id="tab1">
			
				<?php if ($_GET['action'] == 'search') { ?>
					<div style="margin-bottom:5px; padding:3px; height:28px;">There are <?php echo intval($this->total_rows); ?> matching users.
						<div style="float:right; margin-right:10px;">
							<form id="search_save" action="<?php echo $this->search_url; ?>__sort_key-<?php echo $_GET['sort_key']; ?>__order-<?php echo $_GET['order']; ?>" method="post"><input type="hidden" name="action" value="save_users_search"/>Save this user list is:<select id="users_search_id" name="users_search_id"><option value="0">New List</option><?php foreach($this->users_search_list as $key => $val) { ?><option value="<?php echo $val['id']; ?>"><?php echo $val['name']; ?></option><?php } ?></select>&nbsp;&nbsp;<input type="text" name="name" class="text-input" style="width:130px;"/>&nbsp;&nbsp;<input type="button" onclick="ajax_post($('#search_save'), _form_process);" value="Save" class="button">
							</form>
						</div>
					</div>
				<?php } ?>
				
				<?php if ($this->list) { ?>
				
				<table class="list">
					<thead>
						<tr>
							<th>ID</th>
							<th>Avatar</th>
							<th><a href="<?php echo $this->search_url; ?>__sort_key-user_name__order-<?php if ($_GET['sort_key'] == 'user_name' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Username<?php if ($_GET['sort_key'] == 'user_name') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<th><a href="<?php echo $this->search_url; ?>__sort_key-email__order-<?php if ($_GET['sort_key'] == 'email' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Email<?php if ($_GET['sort_key'] == 'email') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<th><a href="<?php echo $this->search_url; ?>__sort_key-group_id__order-<?php if ($_GET['sort_key'] == 'group_id' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Usergroup<?php if ($_GET['sort_key'] == 'group_id') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<th><a href="<?php echo $this->search_url; ?>__sort_key-reg_time__order-<?php if ($_GET['sort_key'] == 'reg_time' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Register time<?php if ($_GET['sort_key'] == 'reg_time') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<th><a href="<?php echo $this->search_url; ?>__sort_key-last_active__order-<?php if ($_GET['sort_key'] == 'last_active' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Last active time<?php if ($_GET['sort_key'] == 'last_active') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<th><a href="<?php echo $this->search_url; ?>__sort_key-online_time__order-<?php if ($_GET['sort_key'] == 'online_time' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Online (min)<?php if ($_GET['sort_key'] == 'online_time') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<th><a href="<?php echo $this->search_url; ?>__sort_key-reputation__order-<?php if ($_GET['sort_key'] == 'reputation' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Reputation<?php if ($_GET['sort_key'] == 'reputation') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<?php if (get_setting('integral_system_enabled') == 'Y') { ?>
								<th><a href="<?php echo $this->search_url; ?>__sort_key-integral__order-<?php if ($_GET['sort_key'] == 'integral' && $_GET['order'] == 'DESC') { ?>ASC<?php }else{ ?>DESC<?php } ?>">Credit<?php if ($_GET['sort_key'] == 'integral') { ?><?php if ($_GET['order'] == 'ASC') { ?><em class="listup">&uarr;</em><?php }else{ ?><em class="listdown">&darr;</em><?php } ?><?php } ?></a></th>
							<?php } ?>
							<th>Operation</th>
						</tr>
					</thead>
					<tbody style="border-bottom: 1px solid #ddd;">
						<?php foreach ($this->list AS $key => $val) { ?>
						<tr>
							<td><?php echo $val['uid']; ?></td>
							<td align="center"><div align="center"><img style="vertical-align: middle;" src="<?php echo get_avatar_url($val['uid'], 'min'); ?>"/></div></td>
							<td><a href="people/<?php echo $val['url_token']; ?>" target="_blank" title="title"><?php echo $val['user_name']; ?></a>
								<?php if ($val['forbidden']) { ?>
								&nbsp;<font color="#FF0000">[Ban]</font>
								<?php }else if (!$val['valid_email']) { ?>
								&nbsp;<font color="#FF0000">[Unverified]</font>
								<?php } ?></td>
							<td><?php echo $val['email']; ?></td>
							<td><?php echo $this->system_group[$val['group_id']]['group_name']; ?></td>
							<td><?php echo date("Y-m-d H:i:s", $val['reg_time']); ?></td>
							<td><?php if ($val['last_active']) { ?><?php echo date("Y-m-d H:i:s", $val['last_active']); ?><?php } ?></td>
							<td><?php echo round($val['online_time']/60); ?></td>
							<td><?php echo $val['reputation']; ?></td>
							<?php if (get_setting('integral_system_enabled') == 'Y') { ?>
								<td><?php echo $val['integral']; ?></td>
							<?php } ?>
							<td><a href="admin/user_manage/edit/uid-<?php echo $val['uid']; ?>" title="Modification"><img src="<?php echo GET_STATIC_URL;?>/admin/images/icons/pencil.png"/></a><?php if ($val['uid'] != $this->user_id) { ?> &nbsp; <a href="javascript:;" onClick="ajax_request(GET_BASE_URL + '/admin/user_manage/forbidden_status_ajax/user_id-<?php echo $val['uid']; ?>__status-<?php echo intval($val['forbidden']) ? 0 : 1; ?>');" title="<?php if ($val['forbidden']) { ?>Unban<?php }else{ ?>Prohibit users<?php } ?>"><img src="<?php echo GET_STATIC_URL;?>/admin/images/icons/<?php if ($val['forbidden']) { ?>lock<?php }else{ ?>unlock<?php } ?>.png"/></a><?php } ?></td>
						</tr>
						<?php } ?>
					</tbody>
					<tfoot>
						<tr>
							<td colspan="<?php if (get_setting('integral_system_enabled') == 'Y') { ?>11<?php }else{ ?>10<?php } ?>"><div class="pagination"> <?php echo $this->pagination; ?> </div>
								<div class="clear"></div></td>
						</tr>
					</tfoot>
				</table>
				<?php } ?>
			</div>
			
			<div class="tab-content" id="tab2" style="display:none;">
				<div style=" float:left; width:35%;">
				<form method="post" action="admin/user_manage/list/" onsubmit="return false;" id="search_form">
				<input name="action" type="hidden" value="search"/>
				<p>
					<label> Username:</label>
					<input type="text" value="<?php echo rawurldecode($_GET['user_name']); ?>" name="user_name" class="text-input normal-input" />
				</p>
				<p>
					<label> Mailbox:</label>
					<input type="text" value="<?php echo rawurldecode($_GET['email']); ?>" name="email" class="text-input normal-input" />
				</p>
				<?php if (!$_GET['action']) { ?>
				<p><a href="javascript:;" onclick="$(this).parent().next().show();$(this).parent().remove();"><b>More Search<em style="display: inline-block; font-size: 12px; width: 15px; vertical-align: top; margin-top: 6px; height: 12px; line-height: 12px;">&darr;</em></b></a></p>
				<?php } ?>
				<div style="display:<?php if ($_GET['action'] == 'search') { ?>block<?php }else{ ?>none<?php } ?>;">
				<p>
					<label> Register time:</label>
					<input type="text" value="<?php echo base64_decode($_GET['reg_date']); ?>" name="reg_date" class="text-input date_picker" style="width:150px;" />
				</p>
				<p>
					<label> Usergroup:</label>
					<select name="group_id" style="float:left; width:200px;">
						<option value=""></option>
						<?php foreach($this->system_group as $skey => $sval) { ?>
							<option value="<?php echo $sval['group_id']; ?>"<?php if ($_GET['group_id'] == $sval['group_id']) { ?> selected=true<?php } ?>><?php echo $sval['group_name']; ?></option>
						<?php } ?>
					</select>
				</p>
				<p style="clear:both;"></p>
				<p>
					<label> Last login time:</label>
					<input type="text" value="<?php echo base64_decode($_GET['last_login_date']); ?>" name="last_login_date" class="text-input date_picker" style="width:150px;" />
				</p>
				<p>
					<label> Last Login IP segment ( Limit C segment, for example: 192.168.20.* ):</label>
					<input type="text" value="<?php echo $_GET['ip']; ?>" name="ip" class="text-input normal-input" />
				</p>
				<p>
					<label> Credit:</label>
					<input type="text" name="integral_min" value="<?php echo $_GET['integral_min']; ?>" class="text-input" style="width:40px;" /> - <input type="text" name="integral_max" value="<?php echo $_GET['integral_max']; ?>" class="text-input" style="width:40px;" />
				</p>
				<p>
					<label> Reputation: </label>
					<input type="text" name="reputation_min" value="<?php echo $_GET['reputation_min']; ?>" class="text-input" style="width:40px;" /> - <input type="text" name="reputation_max" value="<?php echo $_GET['reputation_max']; ?>" class="text-input" style="width:40px;" />
				</p>
				<p>
					<label> Answers:</label>
					<input type="text" name="answer_count_min" value="<?php echo $_GET['answer_count_min']; ?>" class="text-input" style="width:40px;" /> - <input type="text" name="answer_count_max" value="<?php echo $_GET['answer_count_max']; ?>" class="text-input" style="width:40px;" />
				</p>
				<p>
					<label> Profession:</label>
					<select name="job_id" style="float:left; width:200px;">
						<option value="0"></option>
						<?php foreach($this->job_list as $job_id => $job_name) { ?>
							<option value="<?php echo $job_id; ?>"<?php if ($_GET['job_id'] == $job_id) { ?> selected=true<?php } ?>><?php echo $job_name; ?></option>
						<?php } ?>
					</select>
				</p>
				<p style="clear:both;">
					<label> Where do you live:</label>
					<select name="province" class="select_area" style="float:left;"></select>
					<select name="city" class="select_area" style="float:left; margin-left:10px;"></select>
				</p>
				<p>
					<label style="clear:both;"> Birthday:</label>
					<input type="text" value="<?php echo base64_decode($_GET['birthday']); ?>" name="birthday" class="text-input date_picker" style="width:150px;" />
				</p>
				<p>
					<label> User Signature:</label>
					<input type="text" value="<?php echo rawurldecode($_GET['signature']); ?>" name="signature" class="text-input normal-input" />
				</p>
				<p>
					<label> E-mail:</label>
					<input type="text" value="<?php echo $_GET['common_email']; ?>" name="common_email" class="text-input normal-input" />
				</p>
				<p>
					<label> Phone number:</label>
					<input type="text" value="<?php echo $_GET['mobile']; ?>" name="mobile" class="text-input normal-input" />
				</p>
				<p>
					<label> YM ID:</label>
					<input type="text" value="<?php echo $_GET['ym']; ?>" name="ym" class="text-input normal-input" />
				</p>
				<p>
					<label> Website:</label>
					<input type="text" value="<?php echo $_GET['homepage']; ?>" name="homepage" class="text-input normal-input" />
				</p>
				<p>
					<label> School:</label>
					<input type="text" value="<?php echo rawurldecode($_GET['school_name']); ?>" name="school_name" class="text-input normal-input" />
				</p>
				<p>
					<label> Professional (Department):</label>
					<input type="text" value="<?php echo rawurldecode($_GET['departments']); ?>" name="departments" class="text-input normal-input" />
				</p>
				<p>
					<label> Company:</label>
					<input type="text" value="<?php echo rawurldecode($_GET['company_name']); ?>" name="company_name" class="text-input normal-input" />
				</p>
				<p>
					<label> Job position:</label>
					<input type="text" value="<?php echo $_GET['company_job_id']; ?>" name="company_job_id" class="text-input normal-input" />
				</p>
				</div>
				<p style="clear:both;">
					<input type="button" onclick="ajax_post($('#search_form'), _form_process);" value="Search" class="button">
				</p>
				</form>
				</div>
				
				<?php if ($this->users_search_list) { ?>
					<div style="float:left; width:250px;">Search History:
					<ul>
						<?php foreach($this->users_search_list as $val) { ?>
						<li><a href="admin/user_manage/list/action-search__<?php echo $val['search_param']; ?>"><?php echo $val['name']; ?></a>&nbsp;<a href="javascript:;" onclick="delete_users_search($(this), <?php echo $val['id']; ?>);">[x]</a></li>
						<?php } ?>
					</ul>
					</div>
				<?php } ?>
				
			</div>
			
		</div>
		<div class="clear"></div>
		<div id="notf_tip" style="display:none;" class="notification png_bg"> <a href="javascript:;" class="close"><img src="<?php echo GET_STATIC_URL;?>/admin/images/icons/cross_grey_small.png" alt="Close" /></a>
			<div id="notf_cont"></div>
		</div>
	</div>

<!-- footer -->
<?php TPL::output('admin/global/footer.tpl.htm'); ?>
<!-- footer -->

</div>
<!-- main -->

</div>

<script type="text/javascript">
$(document).ready(function () {
	$('.select_area').LocationSelect({
        labels: ["Province", "City"],
        elements: document.getElementsByTagName("select"),
        detector: function () {
            this.select(["<?php echo $_GET['province']; ?>", "<?php echo $_GET['city']; ?>"]);
        },
		dataUrl: GET_BASE_URL + '/account/ajax/areas_json_data/'
    });
	
	$('#users_search_id').change(function ()
	{
		if ($(this).val() == 0)
		{
			$('#search_save input[name=name]').show();
		}
		else
		{
			$('#search_save input[name=name]').hide();
		}
	});
});

function delete_users_search(el, id)
{
	el.parent().remove();
	$.post(GET_BASE_URL + '/admin/user_manage/delete_users_search/', 'id=' + id);
}
</script>

</body>
</html>