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

//럭치포인트 출력문구
$lucky_msg = '<p class="lucky_msg">Congratulation! You win the <span class="lucky_point">[point]</span> Lucky Point!</p>';

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

if(G4_IS_MOBILE) {
	$cmt_css_head = 'm_';
	$cmt_photo_size = 36;
	$cmt_textarea_size = 80;
	$cmt_wr_ment = "<strong>댓글 이야기!</strong> *^^*";
} else {
	$cmt_css_head = '';
	$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">

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

//Best
if($amina['cmt_good'] && $amina['cmt_best'] > 0) {
	$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">
<h2 class="cmt_head">댓글목록</h2>
<?
//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 = ' view_cmt_best_bg';
	} 

	if($row['choice']) $view_cmt_bg = ' view_cmt_choice_bg';

	//CSS
	$reply_css = $reply_div = '';
	$reply_len = strlen($row['wr_comment_reply']);
	if ($reply_len) {
		$reply_css = ' '.$cmt_css_head.'view_cmt_'.$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="article_cmt_line"';
		$view_cmt_line = ' view_cmt_line';	
		if($i > 0) echo '</div>'."\n";
		if($cp_num < $cmt_paging) { 
?>
		<div class="cmt_paging" onclick="amina_show('cmt_paging<?=$cp_num?>')">
			<span class="cmt_paging_cnt left">
				<span class=""><?=number_format($i + 1)?></span> ~ <span class="cmt_paging_cnt"><?=number_format($i + $cmt_paging_num)?></span> 번째 댓글
			</span>
			<span class="right">
				보기
			</span>
			<div class="clear"></div>
		</div>
		<div id="cmt_paging<?=$cp_num?>" style="display:none;">
	<? } else { ?>
		<div class="cmt_paging_last">
			<span class="cmt_paging_cnt"><?=number_format($i + 1)?></span> ~ <span class="cmt_paging_cnt"><?=number_format($cmt_cnt)?></span> 번째 댓글
		</div>
		<div id="cmt_paging<?=$cp_num?>">
	<? 
		} 
	$cp_num++;
	} 
?>
    <article id="c_<?=$row['comment_id']?>"<?=$article_cmt_line?>>
		<a name="c_<?=$row['comment_id']?>"></a>
		<div class="view_cmt<?=$reply_css?><?=$view_cmt_line?><?=$view_cmt_bg?>">
			<h1><?=$row['wr_name']?>님의 댓글</h1>
			<? 
				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_nophoto';
				}
			?>
			<div class="<?=$cmt_css_head?>cmt_content<?=$cmt_nophoto?>">
			<ul>
			<li class="left">
				<span class="cmt_name"><?=$row['cool_txt']?> <?=$row['level_icon']?> <b><?=$row['name']?></b></span>
				<? if(G4_IS_MOBILE) { ?>
					<span class="cmt_mdate"><?=amina_date($row['wr_datetime'])?></span>
				<? } else { ?>
					<span class="cmt_date">
						<time datetime="<?=$row['datetime']?>"><?=$row['datetime']?></time>
						<?=$row['ip']?>
					</span>
				<? } ?>
			<? if($is_admin || $amina['shingo'] > 0) { ?>
				<? if($is_admin) { ?>
					<a href="<?=$row['lock_link']?>"><span class="icon_lock"><span class="none">잠금</span>&nbsp;</span></a>
				<? } ?>
				<? if($amina['shingo'] > 0) { ?>
					<a href="<?=$row['shingo_link']?>"><span class="icon_shingo"><span class="none">신고</span>&nbsp;</span></a>
				<? } ?>
			</li>
			<? } ?>
			<li class="right">
				<? if ($row['is_reply']) { ?>
					<a href="javascript:comment_box('<?=$row['comment_id']?>', 'c');"><img src="<?=$cmt_skin_url?>/img/co_btn_reply.gif" alt="답변" /></a>
				<? } ?>
				<? if ($is_admin || $row['is_edit']) { ?>
					<a href="javascript:comment_box('<?=$row['comment_id']?>', 'cu');"><img src="<?=$cmt_skin_url?>/img/co_btn_modify.gif" alt="수정" /></a>
				<? } ?>
		        <? if ($is_admin || $row['is_del']) { ?>
					<a href="<?=$row['del_link']?>"><img src="<?=$cmt_skin_url?>/img/co_btn_delete.gif" alt="삭제" /></a>
				<? } ?>
				<?=$row['sns']?>
			</li>
			<li class="viewComment">
				<? if($row['mobile']) { ?><img src="<?=$cmt_skin_url?>/img/icon_mobile.gif" alt="" /><? } ?>
				<? if($row['blind_msg']) { ?>
					<p class="cmt_blind"><span class="icon_lock"><?=$row['blind_msg']?></span>
					<? if($is_admin) { ?>&nbsp; [<a href="<?=$row['unlock_link']?>">해제하기</a>]<? } ?>
					</span></p>
				<? } ?>
				<?=$row['content']?>
				<? if(!$row['blind_msg'] && $is_lucky && (int)$row['wr_10'] > 0) { echo str_replace("[point]", $row['wr_10'], $lucky_msg); } ?>
			</li>
			</ul>
			<? if($row['choice']) { ?>
				<span class="tack_blue left margin8"><?=$amina['cmt_choice_txt']?></span>
			<? } ?>
			<? if(!$row['is_blind'] && $is_choice == "select" && ($view['mb_id'] != $row['mb_id'])) { ?>
				<a href="javascript:amina_choice('<?=$row['choice_link']?>','cmt_<?=$wr_id?>');"><span id="cmt_choice<?=$row['comment_id']?>" class="tack_green left margin8"><?=$amina['cmt_choice_txt']?>하기</span></a>
			<? } ?>
			<? if($amina['cmt_good']) { ?>
					<a href="javascript:amina_good('<?=$row['good_link']?>','cmt_good<?=$row['wr_id']?>');"  title="<?=$amina['cmt_good_txt']?>"><span class="btn_good right margin8" id="cmt_good<?=$row['wr_id']?>"><?=$row['wr_good']?></span></a>
				<? if($row['is_best']){?> <span class="tack_red_r right margin86">베플</span><?}?>
			<? } ?>
			<? if(!G4_IS_MOBILE) { ?>
				<div class="cmt_write">
					<span id="edit_<?=$row['comment_id']?>" style="display:none;"></span><!-- 수정 -->
				    <span id="reply_<?=$row['comment_id']?>" style="display:none;"></span><!-- 답변 -->
					<input type="hidden" id="secret_comment_<?=$row['comment_id']?>" value="<?=strstr($row['wr_option'],"secret")?>">
					<textarea id="save_comment_<?=$row['comment_id']?>" style="display:none;"><?=get_text($row['content1'], 0)?></textarea>
				</div>
			<? } ?>
			</div>
		</div>
		<? if(G4_IS_MOBILE) { ?>
			<div class="cmt_write">
				<span id="edit_<?=$row['comment_id']?>" style="display:none;"></span><!-- 수정 -->
			    <span id="reply_<?=$row['comment_id']?>" style="display:none;"></span><!-- 답변 -->
				<input type="hidden" id="secret_comment_<?=$row['comment_id']?>" value="<?=strstr($row['wr_option'],"secret")?>">
				<textarea id="save_comment_<?=$row['comment_id']?>" style="display:none;"><?=get_text($row['content1'], 0)?></textarea>
			</div>
		<? } ?>
	</article>
<? } ?>
<? if($is_cmt_paging) { ?></div><? } ?>
</section>
</div>

<!-- 코멘트 리스트 -->
<aside id="bo_vc_w">
<div id="comment_write" style="display:none;">
	<form id="comment_form<?=$wr_id?>" class="wr_cmt_form" name="fviewcomment" action="./write_comment_update.php" method="post" onsubmit="return fviewcomment_submit(this);" autocomplete="off">
	<input type="hidden" name="w" id="w" value="c">
	<input type="hidden" name="bo_table" value="<?=$bo_table?>">
	<input type="hidden" name="wr_id" value="<?=$wr_id?>">
	<input type="hidden" name="comment_id" id="comment_id" value="">
	<input type="hidden" name="sca" value="<?=$sca?>">
	<input type="hidden" name="sfl" value="<?=$sfl?>">
	<input type="hidden" name="stx" value="<?=$stx?>">
	<input type="hidden" name="spt" value="<?=$spt?>">
	<input type="hidden" name="page" value="<?=$page?>">
	<input type="hidden" name="cwin" value="<?=$cwin?>">
	<input type="hidden" name="go_url" value="<?=$go_url?>">
	<input type="hidden" name="frame" value="<?=$frame?>">
	<input type="hidden" name="bo_it" value="<?=$bo_it?>">
	<input type="hidden" name="bo_linked" value="<?=$bo_linked?>">
	<input type="hidden" name="bo_row" value="<?=$bo_row?>">
	<input type="hidden" name="view_it" value="<?=$view_it?>">
	<input type="hidden" name="is_good" value="">
	<input type="hidden" name="good_frame" value="<?=$good_frame?>">
	<input type="hidden" name="token" value="<?=$token?>">
	<? if($is_cmt_nameless == "hidden") { ?>
		<input type="hidden" name="wr_nameless" value="1">
	<? } ?>
	<fieldset>
		<table border=0 class="wr_cmt_head_tbl">
		<caption>댓글쓰기</caption>
		<tr>
		<td class="wr_cmt_head_left">
			<? 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>
				<? if ($comment_min || $comment_max) { ?><label>(<strong id="char_cnt"><span id="char_count"></span>글자</strong>)</label><? } ?>
			<? } else { ?>
				<?=$cmt_wr_ment?>
				<? if ($comment_min || $comment_max) { ?><label>(<strong id="char_cnt"><span id="char_count"></span>글자</strong>)</label><? } ?>
			<? } ?>
		</td>
		<td class="wr_cmt_head_right">
			<ul>
				<li><a href="javascript:amina_textarea('wr_content', 'down');" title="늘이기"><img src="<?=$cmt_skin_url?>/img/cmt_increase.png" alt="늘이기" /></a></li>
				<li><a href="javascript:amina_textarea('wr_content', <?=$cmt_textarea_size?>);" title="초기화"><img src="<?=$cmt_skin_url?>/img/cmt_original.png" alt="초기화" /></a></li>
				<li><a href="javascript:amina_textarea('wr_content', 'up');" title="줄이기"><img src="<?=$cmt_skin_url?>/img/cmt_decrease.png" alt="줄이기" /></a></li>
				<li id="new_cmt_box"><a href="javascript:comment_box('', 'c', 'refresh');"  title="새댓글 쓰기"><img src="<?=$cmt_skin_url?>/img/cmt_refresh.png" alt="새댓글" /></a></li>
				<? if($member['mb_id']) { ?>
					<li><img src="<?=$cmt_skin_url?>/img/cmt_redo.png" alt="댓글 새로고침" title="댓글 새로고침" <?=$redo_msg?> /></li>
				<? } ?>
			</ul>
			<div class="clear"></div>
		</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">
			<? 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"><?=$amina['cmt_cool_txt']?></label>

					&nbsp;

					<input type="radio" id="post_cool2" name="post_cool" value="<bad>">
					<label for="post_cool2" class="cmt_bad"><?=$amina['cmt_bad_txt']?></label>
				</p>
			<? } ?>
			<textarea id="wr_content" name="wr_content" style="height:<?=$cmt_textarea_size?>px;" itemname="내용" <?=$write_error?>
	        <? if ($comment_min || $comment_max) { ?>onkeyup="check_byte('wr_content', 'char_count');"<?}?>></textarea>
		    <? if ($comment_min || $comment_max) { ?><script> check_byte('wr_content', 'char_count'); </script><?}?>
		</td>
		</tr>
		<tr>
		<td class="wr_cmt_opt">
			<ul id="bo_vc_sns">
			<? if($is_cmt_nameless == "check") { ?>
				<li>
					<label for="wr_nameless"><img src="<?=$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>
			<? } ?>
			<li>
				<label for="wr_secret"><img src="<?=$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>
			<? include_once(AMINA_PATH.'/view_comment_write.sns.skin.php'); ?>
			</ul>
		</td>
		<? 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" <?=$write_error?>>
			댓글등록
			<noscript><input id="btn_comment" type="submit" <?=$write_error?> alt="댓글등록" /></noscript>
		</td>
		</tr>
		<? if ($captcha_html) { ?>
			<tr><td colspan=2 class="wr_cmt_captcha">
				<?=$captcha_html?>
			</td></tr>
		<? } ?>
		</table>
	</fieldset>
	</form>
</div>
</aside>