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

@include_once($list_skin_path.'/set/set.load.php');

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

//순서배열
$od = array();
$od[0] = $set['o_num'];
$od[1] = $set['o_thumb'];
$od[2] = $set['o_cate'];
$od[3] = $set['o_photo'];
$od[4] = $set['o_subject'];
$od[5] = $set['o_name'];
$od[6] = $set['o_cmt'];
$od[7] = $set['o_date'];
$od[8] = $set['o_hit'];
$od[9] = $set['o_good'];
$od[10] = $set['o_nogood'];
$od[11] = $set['o_star'];
$od[12] = $set['o_po_view'];
$od[13] = $set['o_po_down'];
$od[14] = $set['o_point'];
$od[15] = $set['o_choice'];
$od[16] = $set['o_daum'];

//값이 있는 것만 선택
$order = array();
for($i=0; $i < 17; $i++) {
	if((int)$od[$i] > 0) $order[] = $od[$i];
}

if(!$order) {
	$order = array("1","2","3");
	$set['o_subject'] = 1;
	$set['o_name'] = 2;
	$set['o_hit'] = 3;
}

sort($order); //정렬

$logo = array();
$dlist = array();

$o_cnt = 0;
$colspan = 0;

if ($is_checkbox) {
	$dlist[0]['head'] = '<th class="head-td" scope="col"><input onclick="if (this.checked) all_checked(true); else all_checked(false);" type="checkbox"></th>';
	$colspan++;
	$o_cnt++;
}

$is_num = false;
if ($set['o_num'] > 0) {
	$is_num = true;
	list($o_num) = array_keys($order, $set['o_num']);
	$o_num = (int)$o_num + $o_cnt;
	$dlist[$o_num]['css'] = ($set['w_num'] > 0) ? '.list-num { width:'.$set['w_num'].'px; }' : '';
	$dlist[$o_num]['head'] = '<th class="head-td" scope="col">번호</th>';
	$colspan++;
}

//List View Check
$is_thumb = false;
$is_logo = false;
if ($set['list_thumb_w'] > 0 && $set['o_thumb'] > 0) {
	$is_thumb = true;
	list($o_thumb) = array_keys($order, $set['o_thumb']);
	$o_thumb = (int)$o_thumb + $o_cnt;
	$dlist[$o_thumb]['css'] = '.list-thumb { width:'.$set['list_thumb_w'].'px; }';
	$dlist[$o_thumb]['head'] = '<th class="head-td" scope="col">이미지</th>';
	$colspan++;

	if($set['list_thumb_no'] == 'logo') {
		$logo = amina_logo($set['list_thumb_no']);
		if (count($logo) > 0) $is_logo = true;
	}
}

$is_catesubj = false;
if($is_category) {
	if($set['list_cate']) $is_catesubj = true;

	$is_category = false;
	if($set['list_cate'] != 1 && $set['o_cate'] > 0) {
		$is_category = true;
		list($o_cate) = array_keys($order, $set['o_cate']);
		$o_cate = (int)$o_cate + $o_cnt;
		$dlist[$o_cate]['css'] = ($set['w_cate'] > 0) ? '.list-cate { width:'.$set['w_cate'].'px; }' : '';
		$dlist[$o_cate]['head'] = '<th class="head-td" scope="col">분류</th>';
		$colspan++;
	}
}

$is_photo = false;
if ($set['list_photo'] > 0 && $set['o_photo'] > 0) {
	$is_photo = true;
	list($o_photo) = array_keys($order, $set['o_photo']);
	$o_photo = (int)$o_photo + $o_cnt;
	$dlist[$o_photo]['css'] = '.list-photo { width:'.$set['list_photo'].'px; }';
	$dlist[$o_photo]['head'] = '<th class="head-td" scope="col">&nbsp;</th>';
	$colspan++;
}

//subject
$is_subject = false;
if ($set['o_subject'] > 0) {
	$is_subject = true;
	list($o_subject) = array_keys($order, $set['o_subject']);
	$o_subject = (int)$o_subject + $o_cnt;
	$dlist[$o_subject]['head'] = '<th class="head-td" scope="col">제&nbsp;&nbsp;&nbsp;목</th>';

	$list_subj_len = $set['list_subj_len'] > 0 ? $set['list_subj_len'] : $board['bo_subject_len'];

	$colspan++;
}

$is_name = false;
if ($set['o_name'] > 0) {
	$is_name = true;
	list($o_name) = array_keys($order, $set['o_name']);
	$o_name = (int)$o_name + $o_cnt;
	$w_name = ($set['w_num'] > 0) ? ' width:'.$set['w_name'].'px;' : '';
	$dlist[$o_name]['css'] = '.list-name {'.$w_name.' text-align:'.$set['list_name'].';}';
	$dlist[$o_name]['head'] = '<th class="head-td" scope="col">이름</th>';
	$colspan++;
}

$is_cmt = false;
if ($set['o_cmt'] > 0) {
	$is_cmt = true;
	list($o_cmt) = array_keys($order, $set['o_cmt']);
	$o_cmt = (int)$o_cmt + $o_cnt;
	$dlist[$o_cmt]['css'] = ($set['w_cmt'] > 0) ? '.list-cmt { width:'.$set['w_cmt'].'px; }' : '';
	$dlist[$o_cmt]['head'] = '<th class="head-td" scope="col">'.$set['list_cmt'].'</th>';
	$colspan++;
}

$is_date = false;
if ($set['list_date'] && $set['o_date'] > 0) {
	$is_date = true;
	list($o_date) = array_keys($order, $set['o_date']);
	$o_date = (int)$o_date + $o_cnt;
	$dlist[$o_date]['css'] = ($set['w_date'] > 0) ? '.list-date { width:'.$set['w_date'].'px; }' : '';
	$dlist[$o_date]['head'] = '<th class="head-td" scope="col">'.subject_sort_link('wr_datetime', $qstr2, 1).'날짜</a></th>';
	$colspan++;
}

$is_hit = false;
if ($set['o_hit'] > 0) {
	$is_hit = true;
	list($o_hit) = array_keys($order, $set['o_hit']);
	$o_hit = (int)$o_hit + $o_cnt;
	$dlist[$o_hit]['css'] = ($set['w_hit'] > 0) ? '.list-hit { width:'.$set['w_hit'].'px; }' : '';
	$dlist[$o_hit]['head'] = '<th class="head-td" scope="col">'.subject_sort_link('wr_hit', $qstr2, 1).'조회</a></th>';
	$colspan++;
}

if ($is_good && $set['o_good'] > 0) {
	$is_good = true;
	list($o_good) = array_keys($order, $set['o_good']);
	$o_good = (int)$o_good + $o_cnt;
	$dlist[$o_good]['css'] = ($set['w_good'] > 0) ? '.list-good { width:'.$set['w_good'].'px; }' : '';
	$dlist[$o_good]['head'] = '<th class="head-td" scope="col">'.subject_sort_link('wr_good', $qstr2, 1).'추천</a></th>';
	$colspan++;
} else {
	$is_good = false;
}

if ($is_nogood && $set['o_nogood'] > 0) {
	$is_nogood = true;
	list($o_nogood) = array_keys($order, $set['o_nogood']);
	$o_nogood = (int)$o_nogood + $o_cnt;
	$dlist[$o_nogood]['css'] = ($set['w_nogood'] > 0) ? '.list-nogood { width:'.$set['w_nogood'].'px; }' : '';
	$dlist[$o_nogood]['head'] = '<th class="head-td" scope="col">'.subject_sort_link('wr_nogood', $qstr2, 1).'비추</a></th>';
	$colspan++;
} else {
	$is_nogood = false;
}

$is_star = false;
if ($amina['star'] && $set['o_star'] > 0) {
	$is_star = true;
	list($o_star) = array_keys($order, $set['o_star']);
	$o_star = (int)$o_star + $o_cnt;
	$dlist[$o_star]['css'] = '.list-star { width:55px; }';
	$dlist[$o_star]['head'] = '<th class="head-td" scope="col">별점</th>';
	$colspan++;
}

$is_po_view = false;
if ($amina['po_view'] && $set['o_po_view'] > 0) {
	$is_po_view = true;
	list($o_po_view) = array_keys($order, $set['o_po_view']);
	$o_po_view = (int)$o_po_view + $o_cnt;
	$dlist[$o_po_view]['css'] = ($set['w_po_view'] > 0) ? '.list-po-view { width:'.$set['w_po_view'].'px; }' : '';
	$dlist[$o_po_view]['head'] = '<th class="head-td" scope="col">열람</th>';
	$colspan++;
}

$is_po_down = false;
if ($amina['po_down'] && $set['o_po_down'] > 0) {
	$is_po_down = true;
	list($o_po_down) = array_keys($order, $set['o_po_down']);
	$o_po_down = (int)$o_po_down + $o_cnt;
	$dlist[$o_po_down]['css'] = ($set['w_po_down'] > 0) ? '.list-po-down { width:'.$set['w_po_down'].'px; }' : '';
	$dlist[$o_po_down]['head'] = '<th class="head-td" scope="col">다운</th>';
	$colspan++;
}

$is_point = false;
$is_choice = false;
if ($amina['cmt_choice']) {
	if($set['o_point'] > 0) { 
		$is_point = true;
		list($o_point) = array_keys($order, $set['o_point']);
		$o_point = (int)$o_point + $o_cnt;
		$dlist[$o_point]['css'] = ($set['w_point'] > 0) ? '.list-point { width:'.$set['w_point'].'px; }' : '';
		$dlist[$o_point]['head'] = '<th class="head-td" scope="col">'.$amina['cmt_choice_txt'].'</th>';
		$colspan++;
	}

	if($set['o_choice'] > 0) {
		$is_choice = true;
		list($o_choice) = array_keys($order, $set['o_choice']);
		$o_choice = (int)$o_choice + $o_cnt;
		$dlist[$o_choice]['css'] = ($set['w_choice'] > 0) ? '.list-choice, .list-nochoice { width:'.$set['w_choice'].'px; }' : '';
		$dlist[$o_choice]['head'] = '<th class="head-td" scope="col">상태</th>';
		$colspan++;
	}
}

$is_daum = false;
if ($amina['daum_view'] && $set['o_daum'] > 0) {
	$is_daum = true;
	list($o_daum) = array_keys($order, $set['o_daum']);
	$o_daum = (int)$o_daum + $o_cnt;
	$w_daum = ($set['list_daum'] == 'm') ? 76 : 112;
	$dlist[$o_daum]['css'] = '.list-daum { width:'.$w_daum.'px; }';
	$dlist[$o_daum]['head'] = '<th class="head-td" scope="col">다음뷰</th>';
	$colspan++;
}

$o_list = count($order) + $o_cnt;

$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';

$n = 0;

?>
<section>
<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  //CSS 출력
		for($o=0; $o < $o_list; $o++) { 
			if(!$dlist[$o]['css']) continue;
			echo $dlist[$o]['css']."\n";
		}
	?>
</style>
<table border=0 class="list-tbl">
<caption><strong><?php echo $board['bo_subject']; ?> 게시판 게시물 목록</strong></caption>
<thead>
<tr>
<?php //헤드출력
	for($o=0; $o < $o_list; $o++) { 
		echo $dlist[$o]['head']."\n";
	}
?>
</tr>
</thead>
<tbody>
<?php
	for ($i=0; $i<count($list); $i++) { 

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

	//링크 재설정
	$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']);

	//List Type
	$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="" /> ';

	}

	//Blind
	$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>';
	}

	$bg = '';
	if($list[$i]['is_notice']) { //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 {

		if($set['shell_color']) $bg = $n%2 ? ' class="list"' : '';

		//Now Post
		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>';
		}

		$n++;
	}

	//Start List
	echo '<tr'.$bg.'>'."\n";
 
	//Check
	if ($is_checkbox) $dlist[0] = '<td class="list-chk"><input type="checkbox" name="chk_wr_id[]" value="'.$list[$i]['wr_id'].'"></td>';

	//Num
	if ($is_num) $dlist[$o_num] = '<td class="list-num">'.$list[$i]['num'].'</td>';

	//Thumb
	if ($is_thumb) { 
		if($is_logo) shuffle($logo);
		$dlist[$o_thumb] = '<td class="list-thumb">'.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'], '', '', '', $logo[0]).'</td>';
	}

	//Category
	if ($is_category) $dlist[$o_cate] = '<td class="list-cate">'.$list[$i]['ca_name'].'</td>';

	//Subject
	if ($is_subject) {

		$reply_m = '';
		if(AMINA == "g4s" && $list[$i]['reply'] > 0) {
			for ($k=0; $k<$list[$i]['reply']; $k++) {
				$reply_m .= ' &nbsp;&nbsp; ';
			}
		} else {
            $reply_m = $list[$i]['reply'];
		}

		$dlist[$o_subject] = '<td class="list-subject">';
		if($list[$i]['reply']) $dlist[$o_subject] .= $replay_m.$list[$i]['icon_reply'].' ';
		$dlist[$o_subject] .= $icon_post.' ';
		if($list[$i]['icon_secret']) $dlist[$o_subject] .= $list[$i]['icon_secret'].' ';
		if($wr_icon['mobile']) $dlist[$o_subject] .= '<img src="'.$list_skin_url.'/img/icon_mobile.gif" alt="" /> ';
		$dlist[$o_subject] .= '<a href="'.$list[$i]['href'].'">'.$list[$i]['subject'].'</a>' ;
		if(!$set['list_no_icon']) { 
			if($wr_post['video'] == "video") $dlist[$o_subject] .= ' <img src="'.$list_skin_url.'/img/icon_video.gif" alt="" />';
			if($wr_post['photo'] == 'photo') $dlist[$o_subject] .= ' <img src="'.$list_skin_url.'/img/icon_image.gif" alt="" />';
			if($wr_post['file'] == "file") $dlist[$o_subject] .=  ' <img src="'.$list_skin_url.'/img/icon_file.gif" alt="" />';
		}
		if($list[$i]['icon_new']) $dlist[$o_subject] .= ' <img src="'.$list_skin_url.'/img/icon_new.gif" alt="" />';
		if($list[$i]['icon_hot']) $dlist[$o_subject] .= ' <img src="'.$list_skin_url.'/img/icon_hot.gif" alt="" />';
		$dlist[$o_subject] .= '</td>';
	}

 
	//Photo
	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 {
			//회원사진(모두출력)
			if($amina['view_photo'] == "2") {
				$mb_photo = mb_photo($member['mb_id'], $list[$i]['mb_id'], $set['list_photo'], $set['list_photo'], 'is');
			} else {
				$mb_photo = mb_photo($member['mb_id'], $list[$i]['mb_id'], $set['list_photo'], $set['list_photo']);
			}
		}

		$dlist[$o_photo] = '<td class="list-photo">'.$mb_photo.'</td>';
	}

	//Name
	if ($is_name) $dlist[$o_name] = '<td class="list-name">'.xp_icon($list[$i]['mb_id'], $wr_icon['level']).' '.$list[$i]['name'].'</td>';

	if ($is_cmt) { 
			$cmt_class = $list[$i]['wr_comment'] > 0 ? 'list-cmt-on' : 'list-cmt';
			$dlist[$o_cmt] = '<td class="'.$cmt_class.'">'.$list[$i]['wr_comment'].'</td>';
	}

	//Date
	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;
		}

		$dlist[$o_date] = '<td class="list-date '.$date_class.'">'.$list[$i]['datetime2'].'</td>';
	}

	//Hit
	if ($is_hit) $dlist[$o_hit] = '<td class="list-hit">'.$list[$i]['wr_hit'].'</td>';

	//Good
	if ($is_good) $dlist[$o_good] = '<td class="list-good">'.$list[$i]['wr_good'].'</td>';

	//Nogood
	if ($is_nogood) $dlist[$o_nogood] = '<td class="list-nogood">'.$list[$i]['wr_nogood'].'</td>';

	//Star
	if ($is_star) $dlist[$o_star] = '<td class="list-star">'.amina_star_mark($amina['star_color'], $list[$i]['wr_7'], 's').'</td>';

	//Po View
	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>';
		$dlist[$o_po_view] = '<td class="list-po-view">'.$wr_icon['po_view_point'].'</td>';
	}

	//Po Down
	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>';
		$dlist[$o_po_down] = '<td class="list-po-down">'.$wr_icon['po_down_point'].'</td>';
	}

	//Choice Point
	if ($is_point) { 
		$wr_icon['choice_point'] = $wr_icon['choice_point'] > 0 ? number_format($wr_icon['choice_point']) : '-';
		$dlist[$o_point] = '<td class="list-point">'.$wr_icon['choice_point'].'</td>';
	}

	//Choice Statue
	if ($is_choice) { 
		$cho_css = '';
		if($wr_icon['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 = '-';
			}
		}
		$dlist[$o_choice] = '<td'.$cho_css.'>'.$cho_txt.'</td>';
	}

	//Daum View
	if ($is_daum) {
		$list_daum = $wr_post['daum_view'] ? daum_view($wr_post['daum_view'], $set['list_daum']) : '-';
		$dlist[$o_daum] = '<td class="list-daum">'.$list_daum.'</td>';
	}

	//List Output
	for($o=0; $o < $o_list; $o++) { 
		echo $dlist[$o]."\n";
	}

	//List Default
	unset($dlist);

	//End List
	echo '</tr>'."\n";	

} // end for 

// No List
if ($n == 0) echo '<tr><td colspan="'.$colspan.'" class="list-none">'.$no_list.'</td></tr>'."\n";

?>
</tbody>
</table>
</section>