<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

//설정값 세팅
@include_once($list_skin_path.'/set/set.load.php');

$set = amina_set_list($amina['list_set']);

//출력여부
$is_num = ($set['w_num'] > 0) ? true : false;
$is_thumb = ($set['list_thumb_w'] > 0) ? true : false;
$is_catesubj = ($is_category && $set['list_cate']) ? true : false;
$is_category = ($is_category && $set['list_cate'] != "1" && $set['w_cate'] > 0) ? true : false;
$is_photo = ($set['list_photo'] > 0) ? true : false;
$is_name = ($set['w_name'] > 0) ? true : false;
$is_cmt = ($set['w_cmt'] > 0) ? true : false;
$is_date = ($set['list_date'] && $set['w_date'] > 0) ? true : false;
$is_hit = ($set['w_hit'] > 0) ? true : false;
$is_good = ($is_good && $set['w_good'] > 0) ? true : false;
$is_nogood = ($is_nogood && $set['w_nogood'] > 0) ? true : false;
$is_star = ($amina['star'] && $set['w_star'] > 0) ? true : false;
$is_po_view = ($amina['po_view'] && $set['w_po_view'] > 0) ? true : false;
$is_po_down = ($amina['po_down'] && $set['w_po_down'] > 0) ? true : false;
$is_point = ($amina['cmt_choice'] && $set['w_point'] > 0) ? true : false;
$is_choice = ($amina['cmt_choice'] && $set['w_choice'] > 0) ? true : false;
$is_daum = ($amina['daum_view'] && $set['w_daum'] > 0) ? true : false;

//로고이미지
$is_logo = false;
if($is_thumb && $set['list_thumb_no'] == 'logo') {
	$logo = array();
	$logo = amina_logo($set['list_thumb_no']);
	if (count($logo) > 0) $is_logo = true;
}

//제목 및 목록모양
$list_subj_len = ($set['list_subj_len'] > 0) ? $set['list_subj_len'] : $board['bo_subject_len'];
$set['list_line_height'] = $set['list_line_height'] ? $set['list_line_height'] : '1.6';
$set['list_padding'] = $set['list_padding'] ? $set['list_padding'] : '8px 5px';

//셀합치기
$colspan = 1;

//목록수
$list_num = count($list);

$n = 0;

?>

<link rel="stylesheet" href="<?php echo $list_skin_url.'/'.$amina['list_css']; ?>.css">
<style>
	.list-tbl td{ padding:<?php echo $set['list_padding']; ?>; line-height:<?php echo $set['list_line_height']; ?>; }
	<?php if ($is_name) { ?>
		.list-name { text-align:<?php echo $set['list_name']; ?>; }
	<?php } ?>
</style>
<table border=0 class="list-tbl">
<caption><strong><?php echo $board['bo_subject']; ?> 게시판 게시물 목록</strong></caption>
<thead class="head-tbl">
<tr>
<?php if ($is_checkbox) { $colspan++; ?>
	<th scope="col" width="20"><input onclick="if (this.checked) all_checked(true); else all_checked(false);" type="checkbox"></th>
<?php } ?>
<?php if ($is_num) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_num']; ?>">번호</th>
<?php } ?>
<?php if ($is_thumb) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['list_thumb_w']; ?>">썸네일</th>
<?php } ?>
<?php if ($is_photo) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['list_photo']; ?>">&nbsp;</th>
<?php } ?>
<?php if ($is_category) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_cate']; ?>">분류</th>
<?php } ?>
<th class="head-td" scope="col">제&nbsp;&nbsp;&nbsp;목</th>
<?php if ($is_name) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_name']; ?>">이름</th>
<?php } ?>
<?php if ($is_cmt) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_cmt']; ?>"><?php echo $set['list_cmt']; ?></th>
<?php } ?>
<?php if ($is_date) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_date']; ?>"><?php echo subject_sort_link('wr_datetime', $qstr2, 1);?>날짜</a></th>
<?php } ?>
<?php if ($is_hit) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_hit']; ?>"><?php echo subject_sort_link('wr_hit', $qstr2, 1);?>조회</a></th>
<?php } ?>
<?php if ($is_good) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_good']; ?>"><?php echo subject_sort_link('wr_good', $qstr2, 1);?>추천</a></th>
<?php } ?>
<?php if ($is_nogood) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_nogood']; ?>"><?php echo subject_sort_link('wr_nogood', $qstr2, 1);?>비추</a></th>
<?php } ?>
<?php if ($is_star) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_star']; ?>">별점</th>
<?php } ?>
<?php if ($is_po_view) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_po_view']; ?>">열람</th>
<?php } ?>
<?php if ($is_po_down) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_po_down']; ?>">다운</th>
<?php } ?>
<?php if ($is_point) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_point']; ?>"><?php echo $amina['cmt_choice_txt']; ?></th>
<?php } ?>
<?php if ($is_choice) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_choice']; ?>">상태</th>
<?php } ?>
<?php if ($is_daum) { $colspan++; ?>
	<th scope="col" width="<?php echo $set['w_daum']; ?>">다음뷰</th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php for ($i=0; $i < $list_num; $i++) { 

	//첫페이지만 공지사항 나오도록
	if($list[$i]['is_notice'] && $page > 1) continue;

	//링크 재설정
	$href_target = $thumb_target = '';
	if($set['list_href_blank']) {
		$thumb_target = '_blank';
		$href_target = ' target="_blank"';
	} else {
		$list[$i]['href'] = $list[$i]['href'].$frame_opt;
	}

	//xp 및 모바일 아이콘
	$wr_post = amina_array_write($list[$i]['wr_10']);
	$wr_icon = amina_array_icon($list[$i]['wr_5']);

	//목록타입
	$s_name = $icon_post = '';
	if($set['list_qa'] && !$list[$i]['is_notice']) { //질답형
		if($list[$i]['icon_secret']) {
			$s_name = 's';
			$list[$i]['icon_secret'] = '';
		}
		
		$icon_post = $list[$i]['icon_reply'] ? ' <img src="'.$list_skin_url.'/img/icon_'.$s_name.'a.gif" alt="" /> ' : ' <img src="'.$list_skin_url.'/img/icon_'.$s_name.'q.gif" alt="" /> ';
	} else {
		$icon_post = $list[$i]['icon_reply'] ? ' <img src="'.$list_skin_url.'/img/icon_reply.gif" alt="" /> ' : '';
	}

	//블라인드
	$is_blind = ($list[$i]['wr_9'] == "lock" || $list[$i]['wr_9'] == "shingo") ? true : false;

	//글제목
	if($is_blind) {
		$list[$i]['wr_subject'] = '블라인드 처리된 글입니다.';
		$list[$i]['subject'] = '<span class="blind">'.amina_cut($list[$i]['wr_subject'], $list_subj_len).'</span>';
		$icon_post = '<img src="'.$list_skin_url.'/img/icon_shingo.gif" alt="" />';
	} else {
		if(!$list[$i]['is_notice'] && $is_catesubj) $list[$i]['wr_subject'] = '['.$list[$i]['ca_name'].'] '.$list[$i]['wr_subject'];
		$list[$i]['subject'] = amina_cut($list[$i]['wr_subject'], $list_subj_len);
		if($wr_post['subj_s']) $list[$i]['subject'] = '<del>'.$list[$i]['subject'].'</del>';
		if($wr_post['subj_b']) $list[$i]['subject'] = '<b>'.$list[$i]['subject'].'</b>';
		if($wr_post['subj_i']) $list[$i]['subject'] = '<i>'.$list[$i]['subject'].'</i>';
		if($wr_post['subj_color']) $list[$i]['subject'] = '<span style="color:'.$wr_post['subj_color'].';">'.$list[$i]['subject'].'</span>';
		if(!$is_cmt && $list[$i]['comment_cnt']) $list[$i]['subject'] .= ' <span class="cmt-cnt">'.$list[$i]['comment_cnt'].'</span>';
	}

	if($list[$i]['is_notice']) { //공지글
		if($is_category) {
			$list[$i]['num'] = '*';
			$list[$i]['ca_name'] = '<img src="'.$list_skin_url.'/img/icon_notice.gif" alt="알림" />';
		} else {
			$list[$i]['num'] = '<img src="'.$list_skin_url.'/img/icon_notice.gif" alt="알림" />';
		}
		$bg = ' class="notice"';
		$list[$i]['subject'] = '<b>'.$list[$i]['subject'].'</b>';
	} else {
		$bg = ($set['shell_color'] && $n%2) ? ' class="list"' : '';

		$n++;

		if($list[$i]['wr_id'] == $wr_id) { //현재글
			$bg = ' class="now"';
			$list[$i]['subject'] = '<span class="now-post">'.$list[$i]['subject'].'</span>';
			$list[$i]['num'] = '<span class="now-post">'.$list[$i]['num'].'</span>';
		}
	}

	//답글 들여쓰기
	$reply_m = '';
	if(AMINA && $list[$i]['reply'] > 0) {
		for ($k=0; $k<$list[$i]['reply']; $k++) {
			$reply_m .= ' &nbsp;&nbsp; ';
		}
	} else {
		$reply_m = $list[$i]['reply'];
	}
?>
	<tr<?php echo $bg; ?>>
	<?php if ($is_checkbox) { ?>
		<td class="list-chk"><input type="checkbox" name="chk_wr_id[]" value="<?php echo $list[$i]['wr_id']; ?>"></td>
	<?php  } ?>
	<?php if ($is_num) { ?>
		<td class="list-num"><?php echo $list[$i]['num']; ?></td>
	<?php } ?>
	<?php if ($is_thumb) { if($is_logo) shuffle($logo); ?>
			<td class="list-thumb"><?php echo amina_thumb($list[$i], $set['list_thumb_w'], $set['list_thumb_h'], $set['list_thumb_cut'], $set['list_thumb_no'], $set['list_thumb_icon'], $set['linked_img'], $thumb_target, '', '', $logo[0]); ?></td>
	<?php } ?>
	<?php if($is_photo) {
		$mb_photo = '';
		if($amina['view_photo'] == "3") {
			if($wr_icon['post_icon_mb']) $mb_photo = mb_photo($member['mb_id'], $list[$i]['mb_id'], $set['list_photo'], $set['list_photo'], 'is');
			if(!$mb_photo) {
				if(!file_exists($emo_skin_path.'/'.$wr_icon['post_icon'].'.gif')) $wr_icon['post_icon'] = rand(1,$amina['emo_cnt']);
				$mb_photo = '<img src="'.$emo_skin_url.'/'.$wr_icon['post_icon'].'.gif" width="'.$set['list_photo'].'" height="'.$set['list_photo'].'" alt="회원사진" />';
			}
		} else {
			//회원사진(모두출력)
			$mb_photo = ($amina['view_photo'] == "2") ? mb_photo($member['mb_id'], $list[$i]['mb_id'], $set['list_photo'], $set['list_photo'], 'is') : mb_photo($member['mb_id'], $list[$i]['mb_id'], $set['list_photo'], $set['list_photo']);
		}
	?>
		<td class="list-photo"><?php echo $mb_photo; ?></td>
	<?php } ?>
	<?php if ($is_category) { ?>
		<td class="list-cate"><?php echo $list[$i]['ca_name']; ?></td>
	<?php } ?>
	<td class="list-subject">
		<a href="<?php echo $list[$i]['href']; ?>"<?php echo $href_target;?>>
		<?php 
			$subject = '';
			if($list[$i]['reply']) $subject .= $replay_m.'<img src="'.$list_skin_url.'/img/icon_reply.gif" alt="" /> ';
			$subject .= $icon_post.' ';
			if($list[$i]['icon_secret']) $subject .= '<img src="'.$list_skin_url.'/img/icon_secret.gif" alt="" /> ';
			if($wr_icon['mobile']) $subject .= '<img src="'.$list_skin_url.'/img/icon_mobile.gif" alt="" /> ';
			$subject .= $list[$i]['subject'];
			if(!$set['list_no_icon']) { 
				if($wr_post['video'] == "video") $subject .= ' <img src="'.$list_skin_url.'/img/icon_video.gif" alt="" />';
				if($wr_post['photo'] == 'photo') $subject .= ' <img src="'.$list_skin_url.'/img/icon_image.gif" alt="" />';
				if($wr_post['file'] == "file") $subject .= ' <img src="'.$list_skin_url.'/img/icon_file.gif" alt="" />';
			}
			if($list[$i]['icon_new']) $subject .= ' <img src="'.$list_skin_url.'/img/icon_new.gif" alt="" />';
			if($list[$i]['icon_hot']) $subject .= ' <img src="'.$list_skin_url.'/img/icon_hot.gif" alt="" />';

			echo $subject;
		?>
		</a>
	</td>
	<?php if ($is_name) { 
		$list[$i]['name'] = $is_sideview ? amina_sideview($list[$i]['mb_id'], $list[$i]['wr_name'], $list[$i]['wr_email'], $list[$i]['wr_homepage']) : $list[$i]['name'];
	?>
		<td class="list-name"><?php echo xp_icon($list[$i]['mb_id'], $wr_icon['level']).' '.$list[$i]['name']; ?></td>
	<?php } ?>
	<?php if ($is_cmt) { $cmt_class = $list[$i]['wr_comment'] > 0 ? 'list-cmt-on' : 'list-cmt'; ?>
		<td class="<?php echo $cmt_class; ?>"><?php echo $list[$i]['wr_comment']; ?></td>
	<?php } ?>
	<?php if($is_date) { 
		switch($set['list_date']) {
			case '1'		: $date_class = 'list-date1'; break;
			case '2'		: $list[$i]['datetime2'] = amina_date($list[$i]['wr_datetime']); $date_class = 'list-date2'; break;
			default			: $list[$i]['datetime2'] = date($set['list_date'], strtotime($list[$i]['wr_datetime'])); $date_class = 'list-date3'; break;
		}
	?>
		<td class="list-date <?php echo $date_class; ?>"><?php echo $list[$i]['datetime2']; ?></td>
	<?php } ?>
	<?php if ($is_hit) { ?>
		<td class="list-hit"><?php echo $list[$i]['wr_hit']; ?></td>
	<?php } ?>
	<?php if ($is_good) { ?>
		<td class="list-good"><?php echo $list[$i]['wr_good']; ?></td>
	<?php } ?>
	<?php if ($is_nogood) { ?>
		<td class="list-nogood"><?php echo $list[$i]['wr_nogood']; ?></td>
	<?php } ?>
	<?php if ($is_star) { ?>
		<td class="list-star"><?php echo amina_star_mark($amina['star_color'], $list[$i]['wr_7'], 's'); ?></td>
	<?php } ?>
	<?php if ($is_po_view) { $wr_icon['po_view_point'] = $wr_icon['po_view_point'] > 0 ? number_format($wr_icon['po_view_point']) : '<span class="list-free-view">'.$set['list_free_view'].'</span>'; ?>
		<td class="list-po-view"><?php echo $wr_icon['po_view_point']; ?></td>
	<?php } ?>
	<?php if ($is_po_down) { $wr_icon['po_down_point'] = $wr_icon['po_down_point'] > 0 ? number_format($wr_icon['po_down_point']) : '<span class="list-free-down">'.$set['list_free_down'].'</span>'; ?>
		<td class="list-po-down"><?php echo $wr_icon['po_down_point']; ?></td>
	<?php } ?>
	<?php if ($is_point) { $wr_icon['choice_point'] = $wr_icon['choice_point'] > 0 ? number_format($wr_icon['choice_point']) : '-'; ?>
		<td class="list-point"><?php echo $wr_icon['choice_point']; ?></td>
	<?php } ?>
	<?php if ($is_choice) { 
		if($wr_icon['choice'] == "<choice>") {
			$cho_css = ' class="list-choice"';
			$cho_txt = $set['list_choice'];
		} else {
			if($wr_icon['choice_point'] > 0) {
				$cho_css = ' class="list-nochoice"';
				$cho_txt = $set['list_nochoice'];
			} else {
				$cho_css = ' class="list-choice"';
				$cho_txt = '-';
			}
		}
	?>
		<td<?php echo $cho_css; ?>><?php echo $cho_txt; ?></td>
	<?php } ?>
	<?php if ($is_daum) { $list_daum = $wr_post['daum_view'] ? daum_view($wr_post['daum_view'], $set['list_daum']) : '-'; ?>
		<td class="list-daum"><?php echo $list_daum; ?></td>
	<?php } ?>
	</tr>
<?php } // end for ?>
<?php if ($k == 0) { ?>
	<tr><td colspan="<?php echo $colspan; ?>" class="list-none"><?php echo $no_list; ?></td></tr>
<?php } ?>
</tbody>
</table>
