<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<!--{hook search_start.htm}-->

<div class="row">
	<div class="col-lg-10 mx-auto">
		
		<div class="card">
			<div class="card-body">
				<form action="<?php echo url('search');?>" id="form">
				
					<div class="input-group mb-3">
						<input type="text" class="form-control" placeholder="<?php echo lang('keyword');?>" name="keyword" value="<?php echo $keyword_decode;?>" autocomplete="off">
						<div class="input-group-append">
							<button class="btn btn-primary" type="submit" id="submit"><?php echo lang('search');?></button>
						</div>
					</div>
				
					<?php if($search_type == 'like' || $search_type == 'fulltext') { ?>
					<div class="form-group">
						<?php if($search_range == 0 || $search_range == 1) { ?>
						<label class="form-check-inline">
						<input class="form-check-input" type="radio" name="range" value="1" <?php echo $range == '1' ? 'checked' : '';?>> 主题贴
						</label>
						<?php } ?>
	
						<?php if($search_range == 0 || $search_range == 2) { ?>
						<label class="form-check-inline">
							<input class="form-check-input" type="radio" name="range" value="0" <?php echo $range == '0' ? 'checked' : '';?>> 所有贴
						</label>
						<?php } ?>
						<!-- TEST By XHSS -->
						<?php if($search_range == 0 || $search_range == 4) { ?>
						<label class="form-check-inline">
						<input class="form-check-input" type="radio" name="range" value="3" <?php echo $range == '3' ? 'checked' : '';?>> 用户
						</label>
						<?php } ?>
					</div>
					<?php } ?>
				</form>
			</div>
		</div>

		<?php if($keyword) { ?>

		<?php if($range == 1) { ?>

		<?php if($threadlist) { ?>
		
		<div class="card">
			<div class="card-header">
				<ul class="nav nav-tabs card-header-tabs">
					<li class="nav-item">
						<a class="nav-link <?php echo $active == 'default' ? 'active' : '';?>" href="./">
							<?php echo lang('thread_list');?>
						</a>
					</li>
					<!--{hook search_thread_list_nav_item_after.htm}-->
				</ul>
			</div>
			<div class="card-body">
				<ul class="list-unstyled threadlist mb-0">
					<!--{hook search_threadlist_before.htm}-->
					<?php include _include(APP_PATH.'view/htm/thread_list.inc.htm');?>
					<!--{hook search_threadlist_after.htm}-->
				</ul>
			</div>
		</div>
		
		<?php } else { ?>
		
		<div class="card">
			<div class="card-body">
				无结果
			</div>
		</div>
		
		<?php } ?>
		
		<?php include _include(APP_PATH.'view/htm/thread_list_mod.inc.htm');?>
		
		<!--{hook search_page_before.htm}-->
		<?php if($pagination) { ?>
		<nav><ul class="pagination justify-content-center"><?php echo $pagination; ?></ul></nav>
		<?php } ?>
		<!--{hook search_page_end.htm}-->
		<!-- TEST By XHSS -->
		<?php } elseif($range == 3) { ?>

		<div class="card">
			<div class="card-body">
				<div class="card-title">
					<div class="media">
						<div>
							为您搜到以下用户
						</div>
					</div>
				</div>
				<!-- <ul class="list-unstyled postlist">
						<?php
						foreach($userslist as $users) {
						    $name = search_keyword_highlight($users['username'], $keyword_arr);
						    $userid = $users['uid'];
						    echo '<div style="width: 80px;height: 90px;float: left;margin: 10px;padding: 3px;font-size: 12px;"><center><a href="./user-' . $userid . '.htm">' . '<img class="avatar-3" src="./upload/avatar/000/' . $userid . '.png"/></center><center>' . $name . '</a></center></div>';
						}
						?>
				</ul> -->
				<ul class="list-unstyled postlist">
					<?php
					foreach($userslist as $users) {
						$name = search_keyword_highlight($users['username'], $keyword_arr);
						$userid = $users['uid'];
						$avatar_path = './upload/avatar/000/' . $userid . '.png';
						
						// 检查用户头像文件是否存在
						if (file_exists($avatar_path)) {
							// 用户头像文件存在
							$avatar_url = $avatar_path;
						} else {
							// 用户头像文件不存在，使用默认图片地址
							$avatar_url = './view/img/avatar.png'; // 默认图片地址
						}
						
						echo '<div style="width: 80px; height: 90px; float: left; margin: 10px; padding: 3px; font-size: 12px;">
							<center>
								<a href="./user-' . $userid . '.htm">
									<img class="avatar-3" src="' . $avatar_url . '"/>
								</center>
								<center>' . $name . '</a>
							</center>
						</div>';
					}
					?>
				</ul>
			</div>
		</div>

		<?php } elseif($range == 0) { ?>

		<div class="card">
			<div class="card-body">
				<div class="card-title">
					<div class="media">
						<div>
							<?php echo lang('post_list');?>
						</div>
						<div class="media-body text-right">
							<!--{hook search_post_list_title_right.htm}-->
						</div>
					</div>
				</div>
				<ul class="list-unstyled postlist">
						<!--{hook search_postlist_before.htm}-->
						<?php include _include(APP_PATH.'view/htm/post_list.inc.htm'); ?>
						<!--{hook search_postlist_before.htm}-->
				</ul>
			</div>
		</div>

		<?php } ?>
		<?php } ?>
	</div>
	<div class="col-lg-3 hidden-sm hidden-md">
		<!--
		<div class="card card-body">
			<h4 class="card-title">筛选条件</h4>
		</div>
		-->
	</div>
</div>

<!--{hook search_end.htm}-->

<?php include _include(APP_PATH.'view/htm/footer.inc.htm');?>

<script>
var jform = $('#form');
var jsubmit = $('#submit');
var jrange = jform.find('input[name="range"]');
var jkeyword = jform.find('input[name="keyword"]');
jform.on('submit', function() {
	var range = jrange.checked();
	var keyword = jkeyword.val();
	window.location = xn.url('search-' + xn.urlencode(keyword) + '-' + range);
	return false;
});

$('#nav_pc li[fid="<?php echo $fid;?>"]').addClass('active');
$('a[data-active="search"]').addClass('active');
</script>



<!--{hook search_js.htm}-->