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

//럭치포인트 출력문구
$lucky_msg = '<p class="lucky-msg"><i class="fa fa-gift fa-lg"></i> Congratulation! You win the <span class="lucky-point">[point]</span> Lucky MP!</p>';

$is_lucky = ($amina['lucky_rate'] > 0 && $amina['lucky_point'] > 0 && $board['bo_comment_point']) ? true : false;

if(G5_IS_MOBILE) {
	$cmt_css_head = 'm-';
	$cmt_photo_size = 36;
	$cmt_textarea_size = 80;
	$cmt_wr_ment = "<strong>댓글 이야기!</strong> *^^*";
} else {
	$cmt_css_head = 'pc-';
	$cmt_photo_size = 56;
	$cmt_textarea_size = 100;
	$cmt_wr_ment = "<strong>댓글 이야기!</strong> 댓글은 자신을 나타내는 '얼굴'입니다. *^^*";
}

//댓글 페이징 - 지정숫자 단위로 댓글 페이징
$cmt_paging_num = $amina['cmt_rows'];

// 페이지여부 체크하기
$cmt_cnt = count($list);
$is_cmt_paging = false;
if($cmt_paging_num > 0 && $cmt_cnt > $cmt_paging_num) {
	$is_cmt_paging = true;
	$cmt_paging  = ceil($cmt_cnt / $cmt_paging_num); 
}

$cp_num = 1;

?>
<!-- 코멘트 리스트 -->
<div id="commentContents">

<?php
if($is_choice == "done") include($cmt_skin_path.'/cmt.skin.choice.php'); //Choice

if($amina['cmt_good'] && $amina['cmt_best'] > 0) { //Best
	$best = sql_fetch(" select count(*) as cnt from $write_table where wr_parent = '$wr_id' and wr_is_comment = 1 and wr_good >= '$amina[cmt_best]' and wr_5 not like '%<choice>%' ");
	if($best['cnt'] > 0) include($cmt_skin_path."/cmt.skin.best.php");
}
?>

<section id="bo_vc">
<?php
//Comment
for ($i=0; $i<$cmt_cnt; $i++) {

	$row = amina_cmt_list($list[$i], $stx, $cmt_photo_size, '');

	//Best
	$view_cmt_bg = '';
	if($row['is_best']) {
		$view_cmt_bg = ' cmt-best-bg';
	} else if($row['choice']) {
		$view_cmt_bg = ' cmt-choice-bg';
	}

	//CSS
	$reply_css = $reply_div = '';
	$reply_len = strlen($row['wr_comment_reply']);
	if ($reply_len) {
		$reply_css = ' '.$cmt_css_head.'cmt-view-'.$reply_len;
		$reply_div = '<div class="cmt-re"></div>'."\n";
	}

	$article_cmt_line = '';
	$view_cmt_line = '';
	if($is_cmt_paging && (($i%$cmt_paging_num)==0)) { 
		$article_cmt_line = ' class="cmt-list-line"';
		$view_cmt_line = ' cmt-line';	
		if($i > 0) echo '</div>'."\n";
		if($cp_num < $cmt_paging) { 
?>
		<div class="cmt-paging" onclick="amina_show('cmt_paging<?php echo $cp_num; ?>')">
			<span class="cmt-paging-cnt left">
				<span class=""><?php echo number_format($i + 1); ?></span> ~ <span class="cmt-paging-cnt"><?php echo number_format($i + $cmt_paging_num); ?></span> 번째 댓글
			</span>
			<span class="right">
				보기
			</span>
			<div class="clear"></div>
		</div>
		<div id="cmt_paging<?php echo $cp_num; ?>" style="display:none;">
	<?php } else { ?>
		<div class="cmt-paging-last">
			<span class="cmt-paging-cnt"><?php echo number_format($i + 1); ?></span> ~ <span class="cmt-paging-cnt"><?php echo number_format($cmt_cnt); ?></span> 번째 댓글
		</div>
		<div id="cmt_paging<?php echo $cp_num; ?>">
	<?php 
		} 
	$cp_num++;
	} 
?>
    <article id="c_<?php echo $row['comment_id']; ?>"<?php echo $article_cmt_line; ?>>
		<a name="c_<?php echo $row['comment_id']; ?>"></a>
		<div class="cmt-view<?php echo $reply_css.$view_cmt_line.$view_cmt_bg; ?>">
			<?php
				echo $reply_div;
				$cmt_nophoto = '';
				if($row['mb_photo']) { 
					echo '<div class="'.$cmt_css_head.'cmt-photo">'.$row['mb_photo'].'</div>'."\n";
				} else {
					$cmt_nophoto = ' '.$cmt_css_head.'cmt-nophoto';
				}
			?>
			<div class="<?php echo $cmt_css_head; ?>cmt-content<?php echo $cmt_nophoto; ?>">
				<div class="cmt-head">
					<div class="cmt-btn">
						<?php if ($row['is_reply']) { ?>
							<a href="javascript:comment_box('<?php echo $row['comment_id']; ?>', 'c');" title="대댓글 달기"><i class="fa fa-comments fa-lg"></i></a>
						<?php } ?>
						<?php if($row['shingo_link']) { ?>
							<a href="<?php echo $row['shingo_link']; ?>" title="신고하기"><i class="fa fa-eye-slash fa-lg"></i></a>
						<?php } ?>
						<?php if ($row['is_edit']) { ?>
							<a href="javascript:comment_box('<?php echo $row['comment_id']; ?>', 'cu');" title="수정하기"><i class="fa fa-plus-circle fa-lg"></i></a>
						<?php } ?>
				        <?php if ($row['is_del']) { ?>
							<a href="<?php echo $row['del_link']; ?>" title="삭제하기"><i class="fa fa-times-circle fa-lg"></i></a>
						<?php } ?>
						<?php if ($row['sns']) { ?>
							<a class="fbox" href="#cmt_sns<?php echo $row['comment_id']; ?>" title="Share SNS"><i class="fa fa-share-square fa-lg"></i></a>
							<div id="cmt_sns<?php echo $row['comment_id']; ?>" class="cmt-sns-box" style="display:none">
								<?php echo $row['sns']; ?>
							</div>
						<?php } ?>
						<?php if($row['lock_link']) { ?>
							<a href="<?php echo $row['lock_link']?>" title="글잠그기"><i class="fa fa-lock fa-lg"></i></a>
						<?php } ?>
					</div>
					<div class="cmt-mb no-wrap">
						<span class="cmt-name"><?php echo $row['cool_txt']; ?> <?php echo $row['level_icon']; ?> <?php echo $row['name']; ?></span>
						<span class="cmt-date">
							<i class="fa fa-clock-o"></i>
							<time datetime="<?php echo $row['datetime']; ?>"><?php echo $row['datetime']; ?></time>
							<?php echo $row['ip']; ?>
						</span>
					</div>
					<div class="clear"></div>
				</div>
				<div class="cmt-content">
					<?php if($row['mobile']) echo '<i class="fa fa-tablet fa-lg"></i> '; ?>
					<?php if($row['blind_msg']) { ?>
						<p><i class="fa fa-eye-slash fa-lg"></i> <b><?php echo $row['blind_msg']; ?></b>
						<?php if($row['unlock_link']) { ?> &nbsp; <a href="<?php echo $row['unlock_link']; ?>"><i class="fa fa-unlock"></i> 해제하기</a><?php } ?>
						</p>
					<?php } ?>
					<?php echo $row['content']; ?>
					<?php if(!$row['blind_msg'] && $is_lucky && (int)$row['wr_10'] > 0) echo str_replace("[point]", $row['wr_10'], $lucky_msg); ?>
					<div class="clear"></div>
				</div>
				<?php if($row['choice']) { ?>
					<span class="tack-blue left margin8"><i class="fa fa-check"></i> <?php echo $amina['cmt_choice_txt']; ?></span>
				<?php } ?>
				<?php if($row['choice_link']) { ?>
					<a href="javascript:amina_choice('<?php echo $row['choice_link']; ?>','cmt_<?php echo $wr_id; ?>');">
						<span id="cmt_choice<?php echo $row['comment_id']; ?>" class="tack-green left margin8"><i class="fa fa-check"></i> <?php echo $amina['cmt_choice_txt']; ?>하기</span>
					</a>
				<?php } ?>
				<?php if($row['good_link']) { ?>
					<a href="javascript:amina_good('<?php echo $row['good_link']; ?>','cmt_good<?php echo $row['comment_id']; ?>');"  title="<?php echo $amina['cmt_good_txt']; ?>"><span class="good-btn right margin8" id="cmt_good<?php echo $row['comment_id']; ?>"><?php echo $row['wr_good']; ?></span></a>
					<?php if($row['is_best']){?> <span class="tack-red-r right margin86"><i class="fa fa-thumbs-up"></i> 베플</span><?php } ?>
				<?php } ?>
				<div class="clear"></div>
			<?php if(G5_IS_MOBILE) echo '</div>'; //Mobile ?>
				<div class="cmt-write">
					<span id="edit_<?php echo $row['comment_id']; ?>" style="display:none;"></span><!-- 수정 -->
				    <span id="reply_<?php echo $row['comment_id']; ?>" style="display:none;"></span><!-- 답변 -->
					<input type="hidden" id="secret_comment_<?php echo $row['comment_id']; ?>" value="<?php echo strstr($row['wr_option'],"secret"); ?>">
					<textarea id="save_comment_<?php echo $row['comment_id']; ?>" style="display:none;"><?php echo get_text($row['content1'], 0); ?></textarea>
				</div>
			<?php if(!G5_IS_MOBILE) echo '</div>'; //PC ?>
		</div>
	</article>
<?php } ?>
<?php if($is_cmt_paging) echo '</div>'; ?>
</section>
</div>

<!-- 코멘트 리스트 -->
<aside id="bo_vc_w">
<a name="redo_cmt"></a>
<div id="comment_write" style="display:none;">
	<form id="comment_form<?php echo $wr_id; ?>" class="wr_cmt_form" name="fviewcomment" action="./write_comment_update.php" method="post" onsubmit="return fviewcomment_submit(this);" autocomplete="off">
	<?php include(AMINA_PATH.'/comment.input.php'); //댓글 공통 input 폼 ?>
	<?php if($is_cmt_nameless == "hidden") { ?>
		<input type="hidden" name="wr_nameless" value="1">
	<?php } ?>
	<fieldset>
		<table border=0 class="wr_cmt_head_tbl">
		<caption>댓글쓰기</caption>
		<tr>
		<td class="wr_cmt_head_left">
			<?php if ($is_guest && !$write_error) { ?>
				<label for="wr_name">이름 <input type="text" maxLength="20" size="12" id="wr_name" name="wr_name" itemname="이름" class="wr_s"></label>
				<label for="wr_password">비번 <input type="password" maxLength="20" size="12" name="wr_password" itemname="패스워드" class="wr_s"></label>
				<?php if ($comment_min || $comment_max) { ?><label>(<strong id="char_cnt"><span id="char_count"></span>글자</strong>)</label><?php } ?>
			<?php } else { ?>
				<span class="no-wrap">
					<?php echo $cmt_wr_ment; ?>
					<?php if ($comment_min || $comment_max) { ?><label>(<strong id="char_cnt"><span id="char_count"></span>글자</strong>)</label><?php } ?>
				</span>
			<?php } ?>
		</td>
		<td class="wr_cmt_head_right">
			<a class="fbox-win" href="<?php echo AMINA_URL.'/tool.php?action=ticon&type=cmt&bo_table='.$bo_table; ?>" target="_blank"><i class="fa fa-meh-o fa-lg" ></i></a>
			<a class="fbox-win" href="<?php echo AMINA_URL.'/tool.php?action=icon&type=cmt&bo_table='.$bo_table; ?>" target="_blank"><i class="fa fa-info-circle fa-lg" ></i></a>
			<a href="javascript:amina_textarea('wr_content', 'down');" title="늘이기"><i class="fa fa-chevron-circle-down fa-lg"></i></a>
			<a href="javascript:amina_textarea('wr_content', <?php echo $cmt_textarea_size; ?>);" title="초기화"><i class="fa fa-minus-circle fa-lg"></i></a>
			<a href="javascript:amina_textarea('wr_content', 'up');" title="줄이기"><i class="fa fa-chevron-circle-up fa-lg"></i></a>
			<span id="new_cmt_box"><a href="javascript:comment_box('', 'c', 'refresh');"  title="새댓글 쓰기"><i class="fa fa-plus-circle fa-lg"></i></a></span>
			<?php if($member['mb_id']) { ?>
				<a href="javascript:<?php echo $redo_script; ?>" title="댓글 새로고침"><i class="fa fa-refresh fa-lg"></i></a>
			<?php } ?>
		</td>
		</tr>
		<tr>
		<td colspan=2 class="wr_cmt_tail">
			<div class="wr_cmt_tail_img"></div>
		</td>
		</tr>
		</table>

		<table border=0 class="wr_cmt_tbl">
		<tr>
		<td colspan=2 class="wr_cmt_content">
			<?php if($amina['cmt_cool']) { ?>
				<p class="wr_cmt_cool">
					<input type="radio" id="post_cool1" name="post_cool" value="<cool>" checked>
					<label for="post_cool1" class="cmt-cool"><?php echo $amina['cmt_cool_txt']; ?></label>
					&nbsp;
					<input type="radio" id="post_cool2" name="post_cool" value="<bad>">
					<label for="post_cool2" class="cmt-bad"><?php echo $amina['cmt_bad_txt']; ?></label>
				</p>
			<?php } ?>
			<textarea id="wr_content" name="wr_content" style="height:<?php echo $cmt_textarea_size; ?>px;" itemname="내용" <?php echo $write_error; ?>
	        <?php if ($comment_min || $comment_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"<?php } ?>></textarea>
		    <?php if ($comment_min || $comment_max) { ?><script> check_byte('wr_content', 'char_count'); </script><?php } ?>
		</td>
		</tr>
		<tr>
		<td class="wr_cmt_opt">
			<ul id="bo_vc_sns">
			<?php if($is_cmt_nameless == "check") { ?>
				<li>
					<label for="wr_nameless"><img src="<?php echo $cmt_skin_url; ?>/img/icon_nameless.png" alt="" title="익명으로 댓글 등록하기" /><span class="none">익명글</span></label><input type="checkbox" id="wr_nameless" name="wr_nameless" value="1">
				</li>
			<?php } ?>
			<li>
				<label for="wr_secret"><img src="<?php echo $cmt_skin_url; ?>/img/icon_secret.png" alt="" title="비밀글로 댓글 등록하기" /><span class="none">비밀글</span></label><input type="checkbox" id="wr_secret" name="wr_secret" value="secret"></li>
			<?php include_once(AMINA_PATH.'/view_comment_write.sns.skin.php'); ?>
			<?php if($is_rid) { //대표아이디로 등록 ?>
			<li>
				<label for="chk_rid"><img src="<?php echo $cmt_skin_url; ?>/img/icon_rid.png" alt="" title="대표아이디로 댓글 등록하기" /><span class="none">대표아이디</span></label><input type="checkbox" id="chk_rid" name="chk_rid" value="1">
			</li>
			<?php } ?>
			</ul>
		</td>
		<?php if(!$write_error) $write_error = "onclick=\"amina_cmt('".AMINA_URL."/comment.php','comment_form".$wr_id."','cmt_".$wr_id."','".$cmt_url."');\""; ?>
		<td id="cmt_submit" class="wr_cmt_submit" <?php echo $write_error; ?>>
			<i class="fa fa-comments"></i> <b>등록</b>
			<noscript><input id="btn_comment" type="submit" <?php echo $write_error; ?> alt="댓글등록" /></noscript>
		</td>
		</tr>
		<?php if ($captcha_html) { ?>
			<tr><td colspan=2 class="wr_cmt_captcha">
				<?php echo $captcha_html; ?>
			</td></tr>
		<?php } ?>
		</table>
	</fieldset>
	</form>
</div>
</aside>
